[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: [PATCH] Fifteen puzzle config revamp
From:       "Thomas Coopman" <thomas.coopman () gmail ! com>
Date:       2008-01-22 22:40:42
Message-ID: 72ba78340801221440r1bb096e6nca891b36fb643869 () mail ! gmail ! com
[Download RAW message or body]

Hi,

I also played a bit with the fifteen puzzle code and added support for
changing the text color, you can see an example in the screenshots.
(http://picasaweb.google.be/thomas.coopman/BlogPictures/photo#5158433862374773682,
http://picasaweb.google.be/thomas.coopman/BlogPictures/photo#5158433862374773698)

Because if you couldn't always see the text on some custom images.
The disadvantage of this of course is that there are more options...

If you like it, you can commit it.

I also noticed that it is possible to chose nothing as custom image,
maybe we must control if there is correct input.


--
Thomas Coopman
Thomas.coopman@gmail.com



-- 
Thomas Coopman
Thomas.coopman@gmail.com

["fifteen_puzzle_color_patch.diff" (text/x-diff)]

Index: fifteenPuzzle.h
===================================================================
--- fifteenPuzzle.h	(revision 764946)
+++ fifteenPuzzle.h	(working copy)
@@ -49,6 +49,8 @@
     bool usePlainPieces;
     QString imagePath;
     bool showNumerals;
+    QColor bgColor;
+    QColor fgColor;
 
   private slots:
     void showConfigurationInterface();
Index: fifteen.cpp
===================================================================
--- fifteen.cpp	(revision 764946)
+++ fifteen.cpp	(working copy)
@@ -131,6 +131,15 @@
   updateNumerals();
 }
 
+void Fifteen::setColors(QColor fgColor, QColor bgColor)
+{
+  for (int i = 0; i <16; i++) {
+    m_pieces[i]->setFgColor(fgColor);
+    m_pieces[i]->setBgColor(bgColor);
+  }
+  update();
+}
+
 void Fifteen::setSplitPixmap(QString path)
 {
   m_pixmap = QPixmap(path);
Index: fifteen.h
===================================================================
--- fifteen.h	(revision 764946)
+++ fifteen.h	(working copy)
@@ -37,7 +37,8 @@
     void setIdentical();
     void setNumerals(bool show);
     void shuffle();
-
+    void setColors(QColor fgColor, QColor bgColor);
+    
   private:
     void drawPieces();
     bool isAdjacent(QGraphicsItem *a, QGraphicsItem *b);
@@ -54,4 +55,5 @@
     bool m_numerals;
 };
 
+
 #endif
Index: piece.cpp
===================================================================
--- piece.cpp	(revision 764946)
+++ piece.cpp	(working copy)
@@ -46,6 +46,16 @@
   m_numeral = show;
 }
 
+void Piece::setFgColor(QColor fgColor)
+{
+  m_fgColor = fgColor;
+}
+
+void Piece::setBgColor(QColor bgColor)
+{
+  m_bgColor = bgColor;
+}
+
 void Piece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                   QWidget *widget)
 {
@@ -69,13 +79,13 @@
 
   QPen pen = painter->pen();
 
-  pen.setColor(QColor(0, 0, 0, 90));
+  pen.setColor(m_bgColor);
   painter->setPen(pen);
   painter->drawText(((m_size / 2) - m.width(text) / 2) + 2,
                     ((m_size / 2) + m.ascent() / 2) + 2,
                     text);
 
-  pen.setColor(QColor(Qt::white));
+  pen.setColor(m_fgColor);
   painter->setPen(pen);
   painter->drawText((m_size / 2) - m.width(text) / 2,
                     (m_size / 2) + m.ascent() / 2,
Index: fifteenPuzzle.cpp
===================================================================
--- fifteenPuzzle.cpp	(revision 764946)
+++ fifteenPuzzle.cpp	(working copy)
@@ -36,6 +36,8 @@
   usePlainPieces = cg.readEntry("UsePlainPieces", true);
   imagePath = cg.readEntry("ImagePath", QString());
   showNumerals = cg.readEntry("ShowNumerals", true);
+  bgColor = cg.readEntry("background", QColor(33,174, 220));
+  fgColor = cg.readEntry("foreground", QColor(10, 10, 110));
 
   // make sure nobody messed up with the config file
   if (!usePlainPieces &&
@@ -93,10 +95,14 @@
   usePlainPieces = configDialog->ui.rb_identical->isChecked();
   imagePath = configDialog->ui.urlRequester->url().path();
   showNumerals = configDialog->ui.cb_showNumerals->isChecked();
+  bgColor = configDialog->ui.colorBtn_background->color();
+  fgColor = configDialog->ui.colorBtn_foreground->color();
 
   cg.writeEntry("UsePlainPieces", usePlainPieces);
   cg.writeEntry("ImagePath", imagePath);
   cg.writeEntry("ShowNumerals", showNumerals);
+  cg.writeEntry("background",bgColor);
+  cg.writeEntry("foreground", fgColor);
 
   updateBoard();
 
@@ -112,6 +118,7 @@
     board->setSplitPixmap(imagePath);
     board->setNumerals(showNumerals);
   }
+  board->setColors(fgColor, bgColor);
 }
 
 void FifteenPuzzle::createMenu()
Index: piece.h
===================================================================
--- piece.h	(revision 764946)
+++ piece.h	(working copy)
@@ -32,11 +32,15 @@
     int getId();
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
     void showNumeral(bool show);
+    void setFgColor(QColor fgColor);
+    void setBgColor(QColor bgColor);
 
   private:
     int m_id;
     int m_size;
     bool m_numeral;
+    QColor m_fgColor;
+    QColor m_bgColor;
 
   protected:
     void mousePressEvent(QGraphicsSceneMouseEvent *event);
Index: fifteenPuzzleConfig.ui
===================================================================
--- fifteenPuzzleConfig.ui	(revision 764946)
+++ fifteenPuzzleConfig.ui	(working copy)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>278</width>
-    <height>254</height>
+    <width>342</width>
+    <height>388</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -70,6 +70,60 @@
         </property>
        </widget>
       </item>
+      <item>
+       <layout class="QHBoxLayout" >
+        <item>
+         <widget class="QLabel" name="lbl_foregroundColor" >
+          <property name="text" >
+           <string>Text color</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer>
+          <property name="orientation" >
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" >
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="KColorButton" name="colorBtn_foreground" />
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" >
+        <item>
+         <widget class="QLabel" name="lbl_backgroundColor" >
+          <property name="text" >
+           <string>Shadow color</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer>
+          <property name="orientation" >
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" >
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="KColorButton" name="colorBtn_background" />
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>
@@ -81,7 +135,7 @@
      <property name="flat" >
       <bool>true</bool>
      </property>
-     <layout class="QVBoxLayout" >
+     <layout class="QHBoxLayout" >
       <item>
        <widget class="QPushButton" name="pb_shuffle" >
         <property name="text" >
@@ -92,23 +146,15 @@
      </layout>
     </widget>
    </item>
-   <item>
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeHint" >
-      <size>
-       <width>20</width>
-       <height>0</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
+   <class>KColorButton</class>
+   <extends>QPushButton</extends>
+   <header>kcolorbutton.h</header>
+  </customwidget>
+  <customwidget>
    <class>KUrlRequester</class>
    <extends>QFrame</extends>
    <header>kurlrequester.h</header>
@@ -119,7 +165,7 @@
   <connection>
    <sender>rb_split</sender>
    <signal>toggled(bool)</signal>
-   <receiver>cb_showNumerals</receiver>
+   <receiver>lbl_image</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
@@ -127,15 +173,15 @@
      <y>81</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>146</x>
-     <y>146</y>
+     <x>52</x>
+     <y>114</y>
     </hint>
    </hints>
   </connection>
   <connection>
    <sender>rb_split</sender>
    <signal>toggled(bool)</signal>
-   <receiver>lbl_image</receiver>
+   <receiver>urlRequester</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
@@ -143,7 +189,7 @@
      <y>81</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>52</x>
+     <x>171</x>
      <y>114</y>
     </hint>
    </hints>
@@ -151,7 +197,7 @@
   <connection>
    <sender>rb_split</sender>
    <signal>toggled(bool)</signal>
-   <receiver>urlRequester</receiver>
+   <receiver>cb_showNumerals</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
@@ -159,8 +205,8 @@
      <y>81</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>171</x>
-     <y>114</y>
+     <x>146</x>
+     <y>146</y>
     </hint>
    </hints>
   </connection>


_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic