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

List:       kde-core-devel
Subject:    Re: QPushButton problem with KDE styles
From:       Martijn Klingens <mklingens () yahoo ! com>
Date:       2001-03-21 16:36:14
[Download RAW message or body]

On Tuesday 20 March 2001 21:32, Matthias Ettrich wrote:
> Thanks for bringing that up. The solution is simple: change the
> drawPushButton button functions in the KDE styles according to what the Qt
> styles do (have a look at qwindowsstyle.cpp, for example).

Hmmm... I now have converted the b3, the kstep, the default and the highcolor 
style. But I'm having problems with the remaining three themes in my control 
panel: System++, System-Series and Marble. The themerc files of those themes 
are in a normal rc file format and do not refer to C++ code. How can I 
convert them?

Another question: the Qt code uses explicitly 
iconSet->pixmap(QIconSet::Small) instead of pixmap() or 
pixmap(QIconSet::Automatic) thus forcing small images. Why is this? I'd 
assume the programmer decides the icon size and not the style plugin. In 
order not to distort the size hinting and such I have used the same code, but 
it makes me wonder.

I have attached the current code for review as some people are afraid that I 
might change the look of certain styles. Please review and test, so I can 
commit. To test: add something like

QPushButton *test = new QPushButton( SmallIcon("konqueror" ),
                        "&Caption", this );

to your code.

When I commit this, can I add icons to existing buttons and dialogs when I 
have some time to spare, or should I only use this for my own code?

NOTE: These icons are actually supported since KDE 2.0, it's just that the 
themes didn't show them. There are no compatibility problems when using 
them. The worst that might happen is that the icons are not shown on pre KDE 
2.2 systems.

TIA,

Martijn

P.S.: the kdelibs/kstyles directory is a mess IMHO. There are quite a few 
directories that are _NOT_ used there: kstep-highcolor, pillbox, 
pillbox-highcolor. Also, the themes directory names a theme called 'beos', 
but there is no associated style on my system (although the themerc sais it 
does). And finally the naming convention for directories that actually 
contain something that is used in KDE is not quite the same: highcolor has no 
suffix at all, ksgistyle has the 'style' suffix in the directory name and b3 
for example has 'plugin' as suffix (b3plugin/). Very confusing if you're 
looking for the dir containing a given style.

["kdelibs.diff" (text/x-c++)]

Index: kdecore/kdestyle.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kdestyle.cpp,v
retrieving revision 1.28
diff -b -u -p -r1.28 kdestyle.cpp
--- kdecore/kdestyle.cpp	2001/03/12 19:29:08	1.28
+++ kdecore/kdestyle.cpp	2001/03/21 16:28:26
@@ -290,6 +290,7 @@ void KDEStyle::drawPushButton(QPushButto
     int y = r.y();
     int w = r.width();
     int h = r.height();
+    
     if(btn->isDefault()){
         int x2 = r.right();
         int y2 = r.bottom();
@@ -314,30 +315,48 @@ void KDEStyle::drawPushButton(QPushButto
 
 void KDEStyle::drawPushButtonLabel(QPushButton *btn, QPainter *p)
 {
-    int x1, y1, x2, y2;
+    int x1, y1, x2, y2, w, h;
     btn->rect().coords(&x1, &y1, &x2, &y2);
+    w = btn->width();
+    h = btn->height();
 
     bool act = btn->isOn() || btn->isDown();
     if(act){
         ++x1, ++y1;
     }
 
+    // Draw iconset first, if any
+    if ( btn->iconSet() && !btn->iconSet()->isNull() )
+    {
+	QIconSet::Mode mode = btn->isEnabled()
+			      ? QIconSet::Normal : QIconSet::Disabled;
+	if ( mode == QIconSet::Normal && btn->hasFocus() )
+	    mode = QIconSet::Active;
+	QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );
+	int pixw = pixmap.width();
+	int pixh = pixmap.height();
+
+	p->drawPixmap( x1+6, y1+h/2-pixh/2, pixmap );
+	x1 += pixw + 8;
+	w -= pixw + 8;
+    }
+    
     if(act || btn->isDefault()){
         QFont font = btn->font();
         font.setBold(true);
         p->setFont(font);
-        drawItem(p, x1+1, y1+1, btn->width(), btn->height(),
+        drawItem( p, x1 + 1, y1 + 1, w, h,
                  AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
                  btn->pixmap(), btn->text(), -1, act ?
                  &btn->colorGroup().dark() : &btn->colorGroup().mid());
 
-        drawItem(p, x1, y1, btn->width(), btn->height(),
+        drawItem( p, x1, y1, w, h,
                  AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
                  btn->pixmap(), btn->text(), -1, act ?
                  &btn->colorGroup().light() : &btn->colorGroup().buttonText());
     }
     else{
-        drawItem(p, x1+act?1:0, y1+act?1:0, btn->width(), btn->height(),
+        drawItem( p, x1 + ( act ? 1 : 0 ), y1 + ( act ? 1 : 0 ), w, h,
                  AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
                  btn->pixmap(), btn->text(), -1,
                  act ? &btn->colorGroup().light() : &btn->colorGroup().buttonText());
Index: kstyles/highcolor/hcstyle.cpp
===================================================================
RCS file: /home/kde/kdelibs/kstyles/highcolor/hcstyle.cpp,v
retrieving revision 1.38
diff -b -u -p -r1.38 hcstyle.cpp
--- kstyles/highcolor/hcstyle.cpp	2001/01/29 22:14:18	1.38
+++ kstyles/highcolor/hcstyle.cpp	2001/03/21 16:29:10
@@ -483,33 +483,53 @@ void HCStyle::drawPushButton(QPushButton
 
 void HCStyle::drawPushButtonLabel(QPushButton *btn, QPainter *p)
 {
-    int x1, y1, x2, y2;
+    int x1, y1, x2, y2, w, h;
     btn->rect().coords(&x1, &y1, &x2, &y2);
+    w = btn->width();
+    h = btn->height();
 
     bool act = btn->isOn() || btn->isDown();
     if(act){
         ++x1, ++y1;
     }
 
+    // Draw iconset first, if any
+    if ( btn->iconSet() && !btn->iconSet()->isNull() )
+    {
+	QIconSet::Mode mode = btn->isEnabled()
+			      ? QIconSet::Normal : QIconSet::Disabled;
+	if ( mode == QIconSet::Normal && btn->hasFocus() )
+	    mode = QIconSet::Active;
+	QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );
+	int pixw = pixmap.width();
+	int pixh = pixmap.height();
+
+	p->drawPixmap( x1+6, y1+h/2-pixh/2, pixmap );
+	x1 += pixw + 8;
+	w -= pixw + 8;
+    }
+    
     if(act || btn->isDefault()){
         QFont font = btn->font();
         font.setBold(true);
         p->setFont(font);
-        drawItem(p, x1+1, y1+1, btn->width(), btn->height(),
+        drawItem( p, x1+1, y1+1, w, h,
                  AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
                  btn->pixmap(), btn->text(), -1, act ?
                  &btn->colorGroup().dark() : &btn->colorGroup().mid());
 
-        drawItem(p, x1, y1, btn->width(), btn->height(),
+        drawItem( p, x1, y1, w, h,
                  AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
                  btn->pixmap(), btn->text(), -1, act ?
                  &btn->colorGroup().light() : &btn->colorGroup().text());
     }
     else{
-        drawItem(p, x1+act?1:0, y1+act?1:0, btn->width(), btn->height(),
-                 AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
+        drawItem( p, x1 + ( act ? 1 : 0 ), y1 + ( act ? 1 : 0 ), w, h,
+                  AlignCenter | ShowPrefix,
+		  btn->colorGroup(), btn->isEnabled(),
                  btn->pixmap(), btn->text(), -1,
-                 act ? &btn->colorGroup().light() : &btn->colorGroup().buttonText());
+                  act ? &btn->colorGroup().light()
+		      : &btn->colorGroup().buttonText());
     }
 }
 
@@ -1908,5 +1928,5 @@ void HCStyle::drawKickerTaskButton(QPain
 
 
 #include "hcstyle.moc"
-
 
+/* vim: set noet sw=8 ts=8: */
Index: kstyles/kstep-highcolor/kstep.cpp
===================================================================
RCS file: /home/kde/kdelibs/kstyles/kstep-highcolor/kstep.cpp,v
retrieving revision 1.8
diff -b -u -p -r1.8 kstep.cpp
--- kstyles/kstep-highcolor/kstep.cpp	2000/10/20 20:02:43	1.8
+++ kstyles/kstep-highcolor/kstep.cpp	2001/03/21 16:29:18
@@ -246,8 +246,11 @@ void KStepStyle::drawPushButton(QPushBut
 
 void KStepStyle::drawPushButtonLabel(QPushButton *btn, QPainter *p)
 {
-    int x1, y1, x2, y2;
+    int x1, y1, x2, y2, w, h;
     btn->rect().coords(&x1, &y1, &x2, &y2);
+    w = btn->width();
+    h = btn->height();
+    
     bool act = btn->isOn() || btn->isDown();
     if (arrowLightBmp.isNull())
     {
@@ -259,6 +262,22 @@ void KStepStyle::drawPushButtonLabel(QPu
         arrowMidBmp.setMask(arrowMidBmp);
     }
     
+    // Draw iconset first, if any
+    if ( btn->iconSet() && !btn->iconSet()->isNull() )
+    {
+	QIconSet::Mode mode = btn->isEnabled()
+			      ? QIconSet::Normal : QIconSet::Disabled;
+	if ( mode == QIconSet::Normal && btn->hasFocus() )
+	    mode = QIconSet::Active;
+	QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );
+	int pixw = pixmap.width();
+	int pixh = pixmap.height();
+
+	p->drawPixmap( x1+6, y1+h/2-pixh/2, pixmap );
+	x1 += pixw + 8;
+	w -= pixw + 8;
+    }
+    
     if (btn->isDefault()) {
 
       // If this is a default button, we have a 4 pixel border which is
@@ -275,15 +294,14 @@ void KStepStyle::drawPushButtonLabel(QPu
 
         
         drawItem(p,
-          (x1+act?1:0) + 6, y1+act?1:0,
-          btn->width() - 26, btn->height(),
+          ( x1 + ( act ? 1 : 0 ) ) + 6, y1 + ( act ? 1 : 0 ), w - 26, h,
           AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
           btn->pixmap(), btn->text(), -1,
           act ? &btn->colorGroup().light() : &btn->colorGroup().buttonText());
 
     } else {
      
-        drawItem(p, x1+act?1:0, y1+act?1:0, btn->width(), btn->height(),
+        drawItem( p, x1 + ( act ? 1 : 0 ), y1 + ( act ? 1 : 0 ), w, h,
           AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
           btn->pixmap(), btn->text(), -1,
           act ? &btn->colorGroup().light() : &btn->colorGroup().buttonText());
Index: kstyles/stepplugin/kstep.cpp
===================================================================
RCS file: /home/kde/kdelibs/kstyles/stepplugin/kstep.cpp,v
retrieving revision 1.28
diff -b -u -p -r1.28 kstep.cpp
--- kstyles/stepplugin/kstep.cpp	2001/01/18 08:11:47	1.28
+++ kstyles/stepplugin/kstep.cpp	2001/03/21 16:29:24
@@ -86,8 +86,11 @@ void KStepStyle::drawPushButton(QPushBut
 
 void KStepStyle::drawPushButtonLabel(QPushButton *btn, QPainter *p)
 {
-    int x1, y1, x2, y2;
+    int x1, y1, x2, y2, w, h;
     btn->rect().coords(&x1, &y1, &x2, &y2);
+    w = btn->width();
+    h = btn->height();
+
     bool act = btn->isOn() || btn->isDown();
     if (arrowLightBmp.isNull())
     {
@@ -99,6 +102,22 @@ void KStepStyle::drawPushButtonLabel(QPu
         arrowMidBmp.setMask(arrowMidBmp);
     }
 
+    // Draw iconset first, if any
+    if ( btn->iconSet() && !btn->iconSet()->isNull() )
+    {
+	QIconSet::Mode mode = btn->isEnabled()
+			      ? QIconSet::Normal : QIconSet::Disabled;
+	if ( mode == QIconSet::Normal && btn->hasFocus() )
+	    mode = QIconSet::Active;
+	QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );
+	int pixw = pixmap.width();
+	int pixh = pixmap.height();
+
+	p->drawPixmap( x1+6, y1+h/2-pixh/2, pixmap );
+	x1 += pixw + 8;
+	w -= pixw + 8;
+    }
+    
     if (btn->isDefault()) {
 
       // If this is a default button, we have a 4 pixel border which is
@@ -114,16 +133,15 @@ void KStepStyle::drawPushButtonLabel(QPu
                       NULL, &arrowDarkBmp, NULL, NULL);
 
 
-        drawItem(p,
-          (x1+act?1:0) + 6, y1+act?1:0,
-          btn->width() - 26, btn->height(),
+        drawItem( p,
+          ( x1 + ( act ? 1 : 0 ) ) + 6, y1 + ( act ? 1 : 0 ), w - 26, h,
           AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
           btn->pixmap(), btn->text(), -1,
           act ? &btn->colorGroup().light() : &btn->colorGroup().buttonText());
 
     } else {
 
-        drawItem(p, x1+act?1:0, y1+act?1:0, btn->width(), btn->height(),
+        drawItem( p, x1 + ( act ? 1 : 0 ), y1 + ( act ? 1 : 0 ), w, h,
           AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
           btn->pixmap(), btn->text(), -1,
           act ? &btn->colorGroup().light() : &btn->colorGroup().buttonText());


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

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