[Kstars-devel] KDE/kdeedu/kstars/kstars

Akarsh Simha akarshsimha at gmail.com
Mon Nov 2 02:43:26 CET 2009


SVN commit 1043623 by asimha:

Show name labels for deep-sky objects. 

I've tried to implement all the ideas that were posted as comments in
the wishlist report. Thanks for the report, and the ideas.

It looks like the slider for controlling density of DSO labels isn't
working. Other TODOs are - the colors for the labels are not editable
at the moment, if I amn't wrong. I'm keeping them for the next weekend.

CCMAIL: kstars-devel at kde.org
FEATURE: 207798



 M  +1 -0      colorscheme.cpp  
 M  +25 -0     kstars.kcfg  
 M  +5 -0      options/opscatalog.cpp  
 M  +169 -4    options/opscatalog.ui  
 M  +50 -0     skycomponents/deepskycomponent.cpp  
 M  +25 -0     skycomponents/deepskycomponent.h  
 M  +1 -0      skycomponents/skymapcomposite.cpp  
 M  +18 -0     skyobjects/deepskyobject.cpp  
 M  +2 -0      skyobjects/deepskyobject.h  


--- trunk/KDE/kdeedu/kstars/kstars/colorscheme.cpp #1043622:1043623
@@ -46,6 +46,7 @@
     appendItem("HSTColor",
                i18nc("Object with extra attached URLs", "Object w/ Links"), "#930000");
     appendItem("SNameColor",       i18n("Star Name"),              "#577d7d");
+    appendItem("DSNameColor",      i18n("Deep Sky Object Name"),   "#75759c");
     appendItem("PNameColor",       i18n("Planet Name"),            "#ac9800");
     appendItem("CNameColor",
                i18nc("Constellation Name", "Constell. Name"),      "#718488");
--- trunk/KDE/kdeedu/kstars/kstars/kstars.kcfg #1043622:1043623
@@ -538,6 +538,16 @@
 			<whatsthis>Toggle whether star name labels are shown in the sky map.</whatsthis>
 			<default>true</default>
 		</entry>
+		<entry name="ShowDeepSkyMagnitudes" type="Bool">
+			<label>Label deep-sky object magnitudes in the sky map?</label>
+			<whatsthis>Toggle whether deep-sky object magnitude (brightness) labels are shown in the sky map.</whatsthis>
+			<default>true</default>
+		</entry>
+		<entry name="ShowDeepSkyNames" type="Bool">
+			<label>Label deep-sky objects in the sky map?</label>
+			<whatsthis>Toggle whether deep-sky object name labels are shown in the sky map.</whatsthis>
+			<default>true</default>
+		</entry>
 		<entry name="SlewTimeScale" type="Double">
 			<label>Minimum timescale for forced-slewing mode</label>
 			<whatsthis>The timescale above which slewing mode is forced on at all times.</whatsthis>
@@ -673,6 +683,16 @@
 			<whatsthis>The relative density for drawing star name and magnitude labels.</whatsthis>
 			<default>2.0</default>
 		</entry>
+		<entry name="DeepSkyLabelDensity" type="Double">
+			<label>Relative density for deep-sky object name labels and/or magnitudes</label>
+			<whatsthis>The relative density for drawing deep-sky object name and magnitude labels.</whatsthis>
+			<default>2.0</default>
+		</entry>
+		<entry name="DeepSkyLongLabels" type="Bool">
+			<label>Show long names in deep-sky object name labels?</label>
+			<whatsthis>If true, long names (common names) for deep-sky objects are shown in the labels.</whatsthis>
+			<default>false</default>
+		</entry>
 		<entry name="MaxRadCometName" type="Double">
 			<label>Maximum distance from Sun for labeling comets, in AU</label>
 			<whatsthis>The maximum solar distance for drawing comets.</whatsthis>
@@ -793,6 +813,11 @@
 			<whatsthis>The color for star name labels.</whatsthis>
 			<default>#7AA</default>
 		</entry>
+		<entry name="DeepSkyNameColor" type="String">
+			<label>Color of deep-sky object name labels</label>
+			<whatsthis>The color for deep-sky object name labels.</whatsthis>
+			<default>#7AA</default>
+		</entry>
 		<entry name="PlanetNameColor" type="String">
 			<label>Color of planet name labels</label>
 			<whatsthis>The color for solar system object labels.</whatsthis>
--- trunk/KDE/kdeedu/kstars/kstars/options/opscatalog.cpp #1043622:1043623
@@ -104,6 +104,7 @@
     */
     connect( kcfg_ShowStars, SIGNAL( toggled(bool) ), SLOT( slotStarWidgets(bool) ) );
     connect( kcfg_ShowDeepSky, SIGNAL( toggled(bool) ), SLOT( slotDeepSkyWidgets(bool) ) );
+    connect( kcfg_ShowDeepSkyNames, SIGNAL( toggled(bool) ), kcfg_DeepSkyLongLabels, SLOT( setEnabled(bool) ) );
     connect( m_ConfigDialog, SIGNAL( applyClicked() ), SLOT( slotApply() ) );
     connect( m_ConfigDialog, SIGNAL( okClicked() ), SLOT( slotApply() ) );
     connect( m_ConfigDialog, SIGNAL( cancelClicked() ), SLOT( slotCancel() ) );
@@ -295,6 +296,10 @@
     LabelMagDeepSkyZoomOut->setEnabled( on );
     kcfg_MagLimitDrawDeepSky->setEnabled( on );
     kcfg_MagLimitDrawDeepSkyZoomOut->setEnabled( on );
+    kcfg_ShowDeepSkyNames->setEnabled( on );
+    kcfg_ShowDeepSkyMagnitudes->setEnabled( on );
+    kcfg_DeepSkyLabelDensity->setEnabled( on );
+    kcfg_DeepSkyLongLabels->setEnabled( on );
     LabelMag3->setEnabled( on );
     LabelMag4->setEnabled( on );
     if ( on ) {
--- trunk/KDE/kdeedu/kstars/kstars/options/opscatalog.ui #1043622:1043623
@@ -218,11 +218,176 @@
        <number>8</number>
       </property>
       <item>
-       <widget class="QCheckBox" name="kcfg_ShowDeepSky">
-        <property name="text">
-         <string>Deep-Sky Catalogs</string>
+       <layout class="QVBoxLayout" name="verticalLayout_2">
+        <property name="topMargin">
+         <number>0</number>
         </property>
-       </widget>
+        <property name="bottomMargin">
+         <number>0</number>
+        </property>
+        <item>
+         <widget class="QCheckBox" name="kcfg_ShowDeepSky">
+          <property name="text">
+           <string>Deep-Sky Catalogs</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <layout class="QFormLayout" name="formLayout">
+          <property name="fieldGrowthPolicy">
+           <enum>QFormLayout::ExpandingFieldsGrow</enum>
+          </property>
+          <property name="topMargin">
+           <number>0</number>
+          </property>
+          <item row="0" column="0">
+           <spacer name="horizontalSpacer_4">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeType">
+             <enum>QSizePolicy::Fixed</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>16</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item row="0" column="1">
+           <widget class="QCheckBox" name="kcfg_ShowDeepSkyNames">
+            <property name="text">
+             <string>Show na&amp;me</string>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="0">
+           <spacer name="horizontalSpacer_5">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeType">
+             <enum>QSizePolicy::Fixed</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>16</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item row="1" column="1">
+           <widget class="QCheckBox" name="kcfg_ShowDeepSkyMagnitudes">
+            <property name="text">
+             <string>Show magni&amp;tude</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <layout class="QHBoxLayout" name="horizontalLayout_3">
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <spacer name="horizontalSpacer_9">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeType">
+             <enum>QSizePolicy::Fixed</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="kcfg_DeepSkyLongLabels">
+            <property name="text">
+             <string>Show &amp;long names</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer_8">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <layout class="QHBoxLayout" name="horizontalLayout_2">
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <spacer name="horizontalSpacer_7">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeType">
+             <enum>QSizePolicy::Fixed</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="QLabel" name="DeepSkyLabelDensityLabel">
+            <property name="text">
+             <string>Label density:</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QSlider" name="kcfg_DeepSkyLabelDensity">
+            <property name="maximum">
+             <number>20</number>
+            </property>
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer_6">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeType">
+             <enum>QSizePolicy::Expanding</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </item>
+       </layout>
       </item>
       <item>
        <layout class="QHBoxLayout">
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.cpp #1043622:1043623
@@ -30,9 +30,12 @@
 #include "kstarsdata.h"
 #include "ksutils.h"
 #include "skymap.h"
+#include "skylabel.h"
+#include "skylabeler.h"
 #include "Options.h"
 #include "skymesh.h"
 
+
 DeepSkyComponent::DeepSkyComponent( SkyComponent *parent )
         : SkyComponent(parent)
 {
@@ -43,6 +46,11 @@
     m_OtherList = QList<DeepSkyObject*>();
 
     m_skyMesh = SkyMesh::Instance();
+
+    // Add labels
+    for ( int i = 0; i <= MAX_LINENUMBER_MAG; i++ )
+        m_labelList[ i ] = new LabelList;
+
 }
 
 DeepSkyComponent::~DeepSkyComponent()
@@ -327,6 +335,10 @@
     QColor color        = data->colorScheme()->colorNamed( colorString );
     QColor colorExtra = data->colorScheme()->colorNamed( "HSTColor" );
 
+    m_hideLabels =  ( map->isSlewing() && Options::hideLabels() ) ||
+                    ! ( Options::showDeepSkyMagnitudes() || Options::showDeepSkyNames() );
+
+
     double maglim = Options::magLimitDrawDeepSky();
 
     //adjust maglimit for ZoomLevel
@@ -335,7 +347,13 @@
     double lgz = log10(Options::zoomFactor());
     if ( lgz <= 0.75 * lgmax ) 
         maglim -= (Options::magLimitDrawDeepSky() - Options::magLimitDrawDeepSkyZoomOut() )*(0.75*lgmax - lgz)/(0.75*lgmax - lgmin);
+    m_zoomMagLimit = maglim;
 
+    double labelMagLim = Options::deepSkyLabelDensity() / 3.0;
+    labelMagLim += ( Options::magLimitDrawDeepSky() - labelMagLim ) * ( lgz - lgmin) / (lgmax - lgmin );
+    if ( labelMagLim > Options::magLimitDrawDeepSky() ) labelMagLim = Options::magLimitDrawDeepSky();
+
+
     //DrawID drawID = m_skyMesh->drawID();
     MeshIterator region( m_skyMesh, DRAW_BUF );
 
@@ -399,6 +417,10 @@
                         psky.setPen( color );
                     }
                 }
+
+                if ( !( drawObject || drawImage )  && ( m_hideLabels || mag > labelMagLim ) ) continue;
+            
+                addLabel( o, obj );
             }
             else { //Object failed checkVisible(); delete it's Image pointer, if it exists.
                 if ( obj->image() ) {
@@ -409,7 +431,35 @@
     }
 }
 
+void DeepSkyComponent::addLabel( const QPointF& p, DeepSkyObject *obj )
+{
+    int idx = int( obj->mag() * 10.0 );
+    if ( idx < 0 ) idx = 0;
+    if ( idx > MAX_LINENUMBER_MAG ) idx = MAX_LINENUMBER_MAG;
+    m_labelList[ idx ]->append( SkyLabel( p, obj ) );
+}
 
+void DeepSkyComponent::drawLabels( QPainter& psky )
+{
+    if ( m_hideLabels ) return;
+
+    psky.setPen( QColor( KStarsData::Instance()->colorScheme()->colorNamed( "DSNameColor" ) ) );
+
+    int max = int( m_zoomMagLimit * 10.0 );
+    if ( max < 0 ) max = 0;
+    if ( max > MAX_LINENUMBER_MAG ) max = MAX_LINENUMBER_MAG;
+
+    for ( int i = 0; i <= max; i++ ) {
+        LabelList* list = m_labelList[ i ];
+        for ( int j = 0; j < list->size(); j++ ) {
+            list->at(j).obj->drawNameLabel( psky, list->at(j).o );
+        }
+        list->clear();
+    }
+
+}
+
+
 SkyObject* DeepSkyComponent::findByName( const QString &name ) {
 
     return nameHash[ name.toLower() ];
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.h #1043622:1043623
@@ -22,6 +22,7 @@
 
 #include <QObject>
 #include "skycomponent.h"
+#include "skylabel.h"
 
 #define NNGCFILES 14
 
@@ -31,7 +32,13 @@
 class DeepSkyObject;
 class SkyPoint;
 class SkyMesh;
+class SkyLabeler;
 
+// NOTE: Although the following symbol has nothing to do with line
+// number in any file, we use this name to keep consistency in naming
+// conventions with StarComponent
+#define MAX_LINENUMBER_MAG 90
+
 typedef QVector< DeepSkyObject*>    DeepSkyList;
 typedef QHash< int, DeepSkyList*>   DeepSkyIndex;
 
@@ -54,6 +61,12 @@
 
     virtual void draw( QPainter& psky );
 
+    /* @short draw all the labels in the prioritized LabelLists and then
+     * clear the LabelLists.
+     */
+    void drawLabels( QPainter& psky );
+
+
     /**
     	*@short Read the ngcic.dat deep-sky database.
     	*Parse all lines from the deep-sky object catalog files. Construct a DeepSkyObject
@@ -126,6 +139,11 @@
     QList<DeepSkyObject*> m_ICList;
     QList<DeepSkyObject*> m_OtherList;
 
+    LabelList*     m_labelList[  MAX_LINENUMBER_MAG + 1 ];
+    bool           m_hideLabels;
+    double         m_zoomMagLimit;
+
+
     SkyMesh* m_skyMesh;
     DeepSkyIndex m_DeepSkyIndex;
     DeepSkyIndex m_MessierIndex;
@@ -137,6 +155,13 @@
     void appendIndex( DeepSkyObject *o, DeepSkyIndex* dsIndex, Trixel trixel );
 
     QHash<QString, DeepSkyObject*> nameHash;
+
+    /**
+     *@short adds a label to the lists of labels to be drawn prioritized
+     *by magnitude.
+     */
+    void addLabel( const QPointF& p, DeepSkyObject *obj );
+
 };
 
 #endif
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.cpp #1043622:1043623
@@ -257,6 +257,7 @@
     m_skyLabeler->drawQueuedLabels( psky );
     m_CNames->draw( psky );
     m_Stars->drawLabels( psky );
+    m_DeepSky->drawLabels( psky );
 
     m_Flags->draw( psky );
 
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/deepskyobject.cpp #1043622:1043623
@@ -395,7 +395,25 @@
     return 0.5*size + 4.;
 }
 
+QString DeepSkyObject::labelString() const {
+    QString oName;
+    if( Options::showDeepSkyNames() ) {
+        if( Options::deepSkyLongLabels() && translatedLongName() != translatedName() )
+            oName = translatedLongName() + " (" + translatedName() + ')';
+        else
+            oName = translatedName();
+    }
 
+    if( Options::showDeepSkyMagnitudes() ) {
+        if( Options::showDeepSkyNames() )
+            oName += "; ";
+        oName += KGlobal::locale()->formatNumber( mag(), 1 );
+    }
+
+    return oName;
+}
+
+
 SkyObject::UID DeepSkyObject::getUID() const
 {
     // mag takes 10 bit
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/deepskyobject.h #1043622:1043623
@@ -92,6 +92,8 @@
      */
     DeepSkyObject(const DeepSkyObject &o );
 
+    QString labelString() const;
+
     virtual DeepSkyObject* clone() const;
     virtual SkyObject::UID getUID() const;
     


More information about the Kstars-devel mailing list