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

Jérôme Sonrier jsid at emor3j.fr.eu.org
Mon Jul 13 20:49:56 CEST 2009


SVN commit 996042 by jsonrier:

We can now choose the color of the label when creating a flag.

CCMAIL: kstars-devel at kde.org



 M  +20 -4     skycomponents/flagcomponent.cpp  
 M  +10 -2     skycomponents/flagcomponent.h  
 M  +14 -5     tools/flagmanager.cpp  
 M  +1 -1      tools/flagmanager.h  
 M  +24 -1     tools/flagmanager.ui  


--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/flagcomponent.cpp #996041:996042
@@ -53,7 +53,7 @@
     // Return if flags.dat does not exist
     if ( ! QFile::exists ( KStandardDirs::locateLocal( "appdata", "flags.dat" ) ) ) return;
 
-    // Return if flags.dat cna not be read
+    // Return if flags.dat can not be read
     if ( ! fileReader.open( "flags.dat" ) ) return;
 
     // Read flags.dat
@@ -93,7 +93,17 @@
         if ( ! ( line.size() > 4 ) )
             continue;
 
-        // Read label
+        // Read label and color label
+        // If the last word is a color value, use it to set label color
+        // Else use red
+        QRegExp rxLabelColor( "^#[a-fA-F0-9]{6}$" );
+        if ( rxLabelColor.exactMatch( line.last() ) ) {
+            m_LabelColors.append( QColor( line.last() ) );
+            line.removeLast();
+        } else {
+            m_LabelColors.append( QColor( "red" ) );
+        }
+
         str.clear();
         for ( i=4; i<line.size(); ++i ) {
             str += line.at( i ) + ' ';
@@ -136,7 +146,7 @@
         o.setX( o.x() + 25.0 );
         o.setY( o.y() + 12.0 );
         psky.save();
-        psky.setPen( QColor( 255, 0, 0 ) );
+        psky.setPen( m_LabelColors.at( i ) );
         psky.setFont( QFont( "Courier New", 10, QFont::Bold ) );
         psky.drawText( o, m_Labels.at( i ) );
         psky.restore();
@@ -172,7 +182,7 @@
 
 }
 
-void FlagComponent::add( SkyPoint* flagPoint, QString epoch, QString image, QString label ) {
+void FlagComponent::add( SkyPoint* flagPoint, QString epoch, QString image, QString label, QColor labelColor ) {
     int i;
 
     pointList().append( flagPoint );
@@ -185,6 +195,7 @@
     }
 
     m_Labels.append( label );
+    m_LabelColors.append( labelColor );
 }
 
 void FlagComponent::remove( int index ) {
@@ -192,6 +203,7 @@
     m_Epoch.removeAt( index );
     m_FlagImages.removeAt( index );
     m_Labels.removeAt( index );
+    m_LabelColors.removeAt( index );
 }
 
 void FlagComponent::slotLoadImages( KIO::Job* job, const KIO::UDSEntryList& list ) {
@@ -238,6 +250,10 @@
     return m_Labels.at( index );
 }
 
+QColor FlagComponent::labelColor( int index ) {
+    return m_LabelColors.at( index );
+}
+
 QImage FlagComponent::image( int index ) {
     return m_Images.at( m_FlagImages.at( index ) );
 }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/flagcomponent.h #996041:996042
@@ -40,7 +40,7 @@
  *flags and is read to init FlagComponent
  *
  *@author Jerome SONRIER
- *@version 1.0
+ *@version 1.1
  */
 class FlagComponent: public QObject, public PointListComponent
 {
@@ -81,7 +81,7 @@
      *@param image Image name
      *@param label Label of the flag
      */
-    void add( SkyPoint* flagPoint, QString epoch, QString image, QString label );
+    void add( SkyPoint* flagPoint, QString epoch, QString image, QString label, QColor labelColor );
 
     /**
      *@short Remove a flag.
@@ -116,6 +116,13 @@
     QString label( int index );
 
     /**
+     *@short Get label color.
+     *@return the label color
+     *@param index Index of the flag
+     */
+    QColor labelColor( int index );
+
+    /**
      *@short Get image.
      *@return the image associated with the flag
      *@param index Index of the flag
@@ -163,6 +170,7 @@
     QStringList         m_Epoch;        /**< List of epochs                */
     QList<int>          m_FlagImages;   /**< List of image index           */
     QStringList         m_Labels;       /**< List of label                 */
+    QList<QColor>       m_LabelColors;  /**< List of label colors          */
     QStringList         m_Names;        /**< List of image names           */
     QList<QImage>       m_Images;       /**< List of flag images           */
     KIO::ListJob*       m_Job;          /**< Used to list user's directory */
--- trunk/KDE/kdeedu/kstars/kstars/tools/flagmanager.cpp #996041:996042
@@ -66,12 +66,16 @@
     // Fill the list
     imageList = ks->data()->skyComposite()->flags()->imageList();
     flagNames =  ks->data()->skyComposite()->flags()->getNames();
+
     for ( i=0; i<ks->data()->skyComposite()->flags()->size(); ++i ) {
+        QStandardItem* labelItem = new QStandardItem( ks->data()->skyComposite()->flags()->label( i ) );
+        labelItem->setForeground( QBrush( ks->data()->skyComposite()->flags()->labelColor( i ) ) );
+
         itemList << new QStandardItem( ks->data()->skyComposite()->flags()->pointList().at( i )->ra0()->toHMSString() ) 
                 << new QStandardItem( ks->data()->skyComposite()->flags()->pointList().at( i )->dec0()->toDMSString() ) 
                 << new QStandardItem( ks->data()->skyComposite()->flags()->epoch( i ) ) 
                 << new QStandardItem( QIcon( pixmap->fromImage( ks->data()->skyComposite()->flags()->image( i ) ) ), "" ) 
-                << new QStandardItem( ks->data()->skyComposite()->flags()->label( i ) );
+                << labelItem;
         m_Model->appendRow( itemList );
         itemList.clear();
     }
@@ -121,7 +125,8 @@
                 + str.setNum( flagPoint->dec0()->Degrees() ).toAscii() + ' '
                 + ui->epochBox->text().toAscii() + ' '
                 + ui->flagCombobox->currentText().replace( ' ', '_' ).toAscii() + ' '
-                + ui->flagLabel->text().toAscii() + '\n' );
+                + ui->flagLabel->text().toAscii() + ' '
+                + ui->labelColorcombo->color().name().toAscii() + '\n' );
 
         QFile file( KStandardDirs::locateLocal( "appdata", "flags.dat" ) );
         file.open( QIODevice::Append | QIODevice::Text );
@@ -129,16 +134,19 @@
         file.close();
 
         // Add flag in FlagComponent
-        m_Ks->data()->skyComposite()->flags()->add( flagPoint, ui->epochBox->text(), ui->flagCombobox->currentText(), ui->flagLabel->text() );
+        m_Ks->data()->skyComposite()->flags()->add( flagPoint, ui->epochBox->text(), ui->flagCombobox->currentText(), ui->flagLabel->text(), ui->labelColorcombo->color() );
 
         // Add flag in the list 
         pixmap = new QPixmap();
 
+        QStandardItem* labelItem = new QStandardItem( ui->flagLabel->text() );
+        labelItem->setForeground( QBrush( ui->labelColorcombo->color() ) );
+
         itemList << new QStandardItem( flagPoint->ra0()->toHMSString() ) 
                 << new QStandardItem( flagPoint->dec0()->toDMSString() ) 
                 << new QStandardItem( ui->epochBox->text() ) 
                 << new QStandardItem( QIcon( pixmap->fromImage( m_Ks->data()->skyComposite()->flags()->image( m_Ks->data()->skyComposite()->flags()->size()-1 ) ) ), "" )
-                << new QStandardItem( ui->flagLabel->text() );
+                << labelItem;
         m_Model->appendRow( itemList );
 
         // Redraw map
@@ -165,7 +173,8 @@
                 + str.setNum( m_Ks->data()->skyComposite()->flags()->pointList().at( i )->dec0()->Degrees() ).toAscii() + ' '
                 + m_Ks->data()->skyComposite()->flags()->epoch( i ).toAscii() + ' '
                 + m_Ks->data()->skyComposite()->flags()->imageName( i ).replace( ' ', '_' ).toAscii() + ' '
-                + m_Ks->data()->skyComposite()->flags()->label( i ).toAscii() + '\n' );
+                + m_Ks->data()->skyComposite()->flags()->label( i ).toAscii() + ' '
+                + m_Ks->data()->skyComposite()->flags()->labelColor( i ).name().toAscii() + '\n' );
 
         file.write( line );
         line.clear();
--- trunk/KDE/kdeedu/kstars/kstars/tools/flagmanager.h #996041:996042
@@ -43,7 +43,7 @@
  *@short Flag manager
  *Dialog box to add and remove flags
  *
- *@version 1.0
+ *@version 1.1
  *@author Jerome SONRIER
  */
 class FlagManager : public KDialog
--- trunk/KDE/kdeedu/kstars/kstars/tools/flagmanager.ui #996041:996042
@@ -92,15 +92,33 @@
           </widget>
          </item>
          <item row="4" column="0">
+          <widget class="QLabel" name="label_4">
+           <property name="text">
+            <string>Label color:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="5" column="0">
           <widget class="QLabel" name="label_2">
            <property name="text">
             <string>Icon:</string>
            </property>
           </widget>
          </item>
-         <item row="4" column="1">
+         <item row="5" column="1">
           <widget class="KComboBox" name="flagCombobox"/>
          </item>
+         <item row="4" column="1">
+          <widget class="KColorCombo" name="labelColorcombo">
+           <property name="color">
+            <color>
+             <red>255</red>
+             <green>0</green>
+             <blue>0</blue>
+            </color>
+           </property>
+          </widget>
+         </item>
         </layout>
        </item>
        <item>
@@ -214,6 +232,11 @@
    <header>klineedit.h</header>
   </customwidget>
   <customwidget>
+   <class>KColorCombo</class>
+   <extends>QComboBox</extends>
+   <header>kcolorcombo.h</header>
+  </customwidget>
+  <customwidget>
    <class>KComboBox</class>
    <extends>QComboBox</extends>
    <header>kcombobox.h</header>


More information about the Kstars-devel mailing list