summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-06 20:54:49 (UTC)
committer sandman <sandman>2002-10-06 20:54:49 (UTC)
commite334186122e512a57bd27026014f01f501db93fc (patch) (unidiff)
tree218c24647dbf6ce15fda1d1ef987ab70e6964570
parente28318681d10236fe06cc478d329b4d000c2a48a (diff)
downloadopie-e334186122e512a57bd27026014f01f501db93fc.zip
opie-e334186122e512a57bd27026014f01f501db93fc.tar.gz
opie-e334186122e512a57bd27026014f01f501db93fc.tar.bz2
QProgressBar widget are now also painted in liquid style -- this is only
possible by intercepting the paint events, since TT forgot to make this widget styleable.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/liquid/liquid.cpp88
1 files changed, 82 insertions, 6 deletions
diff --git a/noncore/styles/liquid/liquid.cpp b/noncore/styles/liquid/liquid.cpp
index 259f6af..4013981 100644
--- a/noncore/styles/liquid/liquid.cpp
+++ b/noncore/styles/liquid/liquid.cpp
@@ -1,97 +1,97 @@
1/*- 1/*-
2 * Copyright (C)QPL 2001 Daniel M. Duley. All rights reserved. 2 * Copyright (C)QPL 2001 Daniel M. Duley. All rights reserved.
3 */ 3 */
4 4
5 5
6 6
7#ifndef INCLUDE_MENUITEM_DEF 7#ifndef INCLUDE_MENUITEM_DEF
8#define INCLUDE_MENUITEM_DEF 8#define INCLUDE_MENUITEM_DEF
9#endif 9#endif
10 10
11#include <qmenudata.h> 11#include <qmenudata.h>
12#include "liquid.h" 12#include "liquid.h"
13//#include "liquiddeco.h" 13//#include "liquiddeco.h"
14#include <qapplication.h> 14#include <qapplication.h>
15#include <qpe/config.h> 15#include <qpe/config.h>
16#include "effects.h" 16#include "effects.h"
17#include <qpalette.h> 17#include <qpalette.h>
18#include <qbitmap.h> 18#include <qbitmap.h>
19#include <qtabbar.h> 19#include <qtabbar.h>
20#include <qpopupmenu.h> 20#include <qpopupmenu.h>
21#include <qobjectlist.h> 21#include <qobjectlist.h>
22#include <qimage.h> 22#include <qimage.h>
23#include <qtimer.h> 23#include <qtimer.h>
24#include <qpixmapcache.h> 24#include <qpixmapcache.h>
25#include <qradiobutton.h> 25#include <qradiobutton.h>
26#include <qcombobox.h> 26#include <qcombobox.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qwidgetlist.h> 28#include <qwidgetlist.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30#include <qheader.h> 30#include <qheader.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <qmenubar.h> 32#include <qmenubar.h>
33 33#include <qprogressbar.h>
34 34
35#include <stdio.h> 35#include <stdio.h>
36 36
37#include "htmlmasks.h" 37#include "htmlmasks.h"
38#include "embeddata.h" 38#include "embeddata.h"
39 39
40typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, 40typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
41 QColorGroup &, bool, bool); 41 QColorGroup &, bool, bool);
42 42
43QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl); 43QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
44 44
45void TransMenuHandler::stripePixmap(QPixmap &pix, const QColor &color) 45void TransMenuHandler::stripePixmap(QPixmap &pix, const QColor &color)
46{ 46{
47 QImage img(pix.convertToImage()); 47 QImage img(pix.convertToImage());
48 QImageEffect::fade(img, 0.9, color); 48 QImageEffect::fade(img, 0.9, color);
49 int x, y; 49 int x, y;
50 int r, g, b; 50 int r, g, b;
51 for(y=0; y < img.height(); y+=3){ 51 for(y=0; y < img.height(); y+=3){
52 unsigned int *data = (unsigned int *) img.scanLine(y); 52 unsigned int *data = (unsigned int *) img.scanLine(y);
53 for(x=0; x < img.width(); ++x){ 53 for(x=0; x < img.width(); ++x){
54 r = qRed(data[x]); 54 r = qRed(data[x]);
55 g = qGreen(data[x]); 55 g = qGreen(data[x]);
56 b = qBlue(data[x]); 56 b = qBlue(data[x]);
57 if(r-10) 57 if(r-10)
58 r-=10; 58 r-=10;
59 if(g-10) 59 if(g-10)
60 g-=10; 60 g-=10;
61 if(b-10) 61 if(b-10)
62 b-=10; 62 b-=10;
63 data[x] = qRgb(r, g, b); 63 data[x] = qRgb(r, g, b);
64 } 64 }
65 } 65 }
66 pix.convertFromImage(img); 66 pix.convertFromImage(img);
67} 67}
68 68
69TransMenuHandler::TransMenuHandler(QObject *parent) 69TransMenuHandler::TransMenuHandler(QObject *parent)
70 : QObject(parent) 70 : QObject(parent)
71{ 71{
72 pixDict.setAutoDelete(true); 72 pixDict.setAutoDelete(true);
73 reloadSettings(); 73 reloadSettings();
74} 74}
75 75
76void TransMenuHandler::reloadSettings() 76void TransMenuHandler::reloadSettings()
77{ 77{
78 pixDict.clear(); 78 pixDict.clear();
79 79
80 Config config ( "qpe" ); 80 Config config ( "qpe" );
81 config. setGroup ( "Liquid-Style" ); 81 config. setGroup ( "Liquid-Style" );
82 82
83 type = config. readNumEntry("Type", TransStippleBg); 83 type = config. readNumEntry("Type", TransStippleBg);
84 color = QColor ( config. readEntry("Color", QApplication::palette().active().button().name())); 84 color = QColor ( config. readEntry("Color", QApplication::palette().active().button().name()));
85 fgColor = QColor ( config. readEntry("TextColor", QApplication::palette().active().text().name())); 85 fgColor = QColor ( config. readEntry("TextColor", QApplication::palette().active().text().name()));
86 opacity = config. readNumEntry("Opacity", 10); 86 opacity = config. readNumEntry("Opacity", 10);
87 if ( opacity < -20 ) 87 if ( opacity < -20 )
88 opacity = 20; 88 opacity = 20;
89 else if ( opacity > 20 ) 89 else if ( opacity > 20 )
90 opacity = 20; 90 opacity = 20;
91 91
92 shadowText = config. readBoolEntry("ShadowText", true); 92 shadowText = config. readBoolEntry("ShadowText", true);
93} 93}
94 94
95bool TransMenuHandler::eventFilter(QObject *obj, QEvent *ev) 95bool TransMenuHandler::eventFilter(QObject *obj, QEvent *ev)
96{ 96{
97 QWidget *p = (QWidget *)obj; 97 QWidget *p = (QWidget *)obj;
@@ -792,132 +792,129 @@ void LiquidStyle::polish(QPalette &appPal)
792 painter.begin(&wallPaper); 792 painter.begin(&wallPaper);
793 for(i=0; i < 32; i+=4){ 793 for(i=0; i < 32; i+=4){
794 painter.setPen(c.dark(100 + contrast)); 794 painter.setPen(c.dark(100 + contrast));
795 painter.drawLine(0, i, 32, i); 795 painter.drawLine(0, i, 32, i);
796 painter.setPen(c.dark(100 + 3 * contrast / 5 ) ); 796 painter.setPen(c.dark(100 + 3 * contrast / 5 ) );
797 painter.drawLine(0, i+1, 32, i+1); 797 painter.drawLine(0, i+1, 32, i+1);
798 }; 798 };
799 painter.end(); 799 painter.end();
800 bgBrush.setColor(c); 800 bgBrush.setColor(c);
801 bgBrush.setPixmap(wallPaper); 801 bgBrush.setPixmap(wallPaper);
802 appPal.setBrush(QColorGroup::Background, bgBrush); 802 appPal.setBrush(QColorGroup::Background, bgBrush);
803 803
804 // lineedits 804 // lineedits
805 c = /*QColor ( config. readEntry("Base", ( Qt::white). name ( )));*/ appPal. color ( QPalette::Active, QColorGroup::Base ); 805 c = /*QColor ( config. readEntry("Base", ( Qt::white). name ( )));*/ appPal. color ( QPalette::Active, QColorGroup::Base );
806 QPixmap basePix; 806 QPixmap basePix;
807 basePix.resize(32, 32); 807 basePix.resize(32, 32);
808 basePix.fill(c.rgb()); 808 basePix.fill(c.rgb());
809 painter.begin(&basePix); 809 painter.begin(&basePix);
810 painter.setPen(c.dark(105)); 810 painter.setPen(c.dark(105));
811 for(i=0; i < 32; i+=4){ 811 for(i=0; i < 32; i+=4){
812 painter.drawLine(0, i, 32, i); 812 painter.drawLine(0, i, 32, i);
813 painter.drawLine(0, i+1, 32, i+1); 813 painter.drawLine(0, i+1, 32, i+1);
814 }; 814 };
815 painter.end(); 815 painter.end();
816 baseBrush.setColor(c); 816 baseBrush.setColor(c);
817 baseBrush.setPixmap(basePix); 817 baseBrush.setPixmap(basePix);
818 it.toFirst(); 818 it.toFirst();
819 while ((w=it.current()) != 0 ){ 819 while ((w=it.current()) != 0 ){
820 ++it; 820 ++it;
821 if(w->inherits("QLineEdit")){ 821 if(w->inherits("QLineEdit")){
822 QPalette pal = w->palette(); 822 QPalette pal = w->palette();
823 pal.setBrush(QColorGroup::Base, baseBrush); 823 pal.setBrush(QColorGroup::Base, baseBrush);
824 w->setPalette(pal); 824 w->setPalette(pal);
825 } 825 }
826 else if(w->inherits("QPushButton")){ 826 else if(w->inherits("QPushButton")){
827 applyCustomAttributes((QPushButton *)w); 827 applyCustomAttributes((QPushButton *)w);
828 } 828 }
829 } 829 }
830} 830}
831 831
832void LiquidStyle::polish(QWidget *w) 832void LiquidStyle::polish(QWidget *w)
833{ 833{
834 if(w->inherits("QMenuBar")){ 834 if(w->inherits("QMenuBar")){
835 //((QFrame*)w)->setLineWidth(0); 835 //((QFrame*)w)->setLineWidth(0);
836 w->setBackgroundMode(QWidget::PaletteBackground); 836 w->setBackgroundMode(QWidget::PaletteBackground);
837 w->setBackgroundOrigin(QWidget::ParentOrigin); 837 w->setBackgroundOrigin(QWidget::ParentOrigin);
838 return; 838 return;
839 } 839 }
840 if(w->inherits("QToolBar")){ 840 if(w->inherits("QToolBar")){
841 w->installEventFilter(this); 841 w->installEventFilter(this);
842 w->setBackgroundMode(QWidget::PaletteBackground); 842 w->setBackgroundMode(QWidget::PaletteBackground);
843 w->setBackgroundOrigin(QWidget::WidgetOrigin); 843 w->setBackgroundOrigin(QWidget::WidgetOrigin);
844 return; 844 return;
845 } 845 }
846 if(w->inherits("QPopupMenu")) 846 if(w->inherits("QPopupMenu"))
847 w->setBackgroundMode(QWidget::NoBackground); 847 w->setBackgroundMode(QWidget::NoBackground);
848 else if(w-> testWFlags(Qt::WType_Popup) && !w->inherits("QListBox")) { 848 else if(w-> testWFlags(Qt::WType_Popup) && !w->inherits("QListBox")) {
849 w->installEventFilter(menuHandler); 849 w->installEventFilter(menuHandler);
850 } 850 }
851 851
852 if(w->isTopLevel()){ 852 if(w->isTopLevel()){
853 return; 853 return;
854 } 854 }
855 855
856 856 if(w->inherits("QComboBox") || w->inherits("QProgressBar") ||
857
858
859 if(w->inherits("QComboBox") ||
860 w->inherits("QLineEdit") || w->inherits("QRadioButton") || 857 w->inherits("QLineEdit") || w->inherits("QRadioButton") ||
861 w->inherits("QCheckBox") || w->inherits("QScrollBar")) { 858 w->inherits("QCheckBox") || w->inherits("QScrollBar")) {
862 w->installEventFilter(this); 859 w->installEventFilter(this);
863 } 860 }
864 if(w->inherits("QLineEdit")){ 861 if(w->inherits("QLineEdit")){
865 QPalette pal = w->palette(); 862 QPalette pal = w->palette();
866 pal.setBrush(QColorGroup::Base, baseBrush); 863 pal.setBrush(QColorGroup::Base, baseBrush);
867 w->setPalette(pal); 864 w->setPalette(pal);
868 } 865 }
869 if(w->inherits("QPushButton")){ 866 if(w->inherits("QPushButton")){
870 applyCustomAttributes((QPushButton *)w); 867 applyCustomAttributes((QPushButton *)w);
871 w->installEventFilter(this); 868 w->installEventFilter(this);
872 } 869 }
873 if(w->inherits("QButton") || w-> inherits("QComboBox")){ 870 if(w->inherits("QButton") || w-> inherits("QComboBox")){
874 w-> setBackgroundMode ( QWidget::PaletteBackground ); 871 w-> setBackgroundMode ( QWidget::PaletteBackground );
875 w->setBackgroundOrigin ( QWidget::ParentOrigin); 872 w->setBackgroundOrigin ( QWidget::ParentOrigin);
876 } 873 }
877 874
878 bool isViewport = qstrcmp(w->name(), "qt_viewport") == 0 || 875 bool isViewport = qstrcmp(w->name(), "qt_viewport") == 0 ||
879 qstrcmp(w->name(), "qt_clipped_viewport") == 0; 876 qstrcmp(w->name(), "qt_clipped_viewport") == 0;
880 bool isViewportChild = w->parent() && 877 bool isViewportChild = w->parent() &&
881 ((qstrcmp(w->parent()->name(), "qt_viewport") == 0) || 878 ((qstrcmp(w->parent()->name(), "qt_viewport") == 0) ||
882 (qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0)); 879 (qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0));
883 880
884 if(isViewport && w->parent() && qstrcmp(w->parent()->name(), "proxyview") == 0){ 881 if(isViewport && w->parent() && qstrcmp(w->parent()->name(), "proxyview") == 0){
885 w->setBackgroundMode(QWidget::X11ParentRelative); 882 w->setBackgroundMode(QWidget::X11ParentRelative);
886 return; 883 return;
887 } 884 }
888 if(isViewportChild){ 885 if(isViewportChild){
889 if(w->inherits("QButton") || w->inherits("QComboBox")){ 886 if(w->inherits("QButton") || w->inherits("QComboBox")){
890 if(w->parent()){ // heh, only way to test for KHTML children ;-) 887 if(w->parent()){ // heh, only way to test for KHTML children ;-)
891 if(w->parent()->parent()){ 888 if(w->parent()->parent()){
892 if(w->parent()->parent()->parent() && 889 if(w->parent()->parent()->parent() &&
893 w->parent()->parent()->parent()->inherits("KHTMLView")){ 890 w->parent()->parent()->parent()->inherits("KHTMLView")){
894 w->setAutoMask(true); 891 w->setAutoMask(true);
895 w->setBackgroundMode(QWidget::NoBackground); 892 w->setBackgroundMode(QWidget::NoBackground);
896 } 893 }
897 } 894 }
898 } 895 }
899 return; 896 return;
900 } 897 }
901 } 898 }
902 if(w->inherits("QHeader")){ 899 if(w->inherits("QHeader")){
903 w->setMouseTracking(true); 900 w->setMouseTracking(true);
904 w->installEventFilter(this); 901 w->installEventFilter(this);
905 } 902 }
906 if(w-> inherits("QToolButton")&&w->parent()->inherits("QToolBar")) { 903 if(w-> inherits("QToolButton")&&w->parent()->inherits("QToolBar")) {
907 ((QToolButton*)w)->setAutoRaise (flatTBButtons); 904 ((QToolButton*)w)->setAutoRaise (flatTBButtons);
908 if ( flatTBButtons ) 905 if ( flatTBButtons )
909 w->setBackgroundOrigin(QWidget::ParentOrigin); 906 w->setBackgroundOrigin(QWidget::ParentOrigin);
910 } 907 }
911 if(w-> inherits("QToolBarSeparator")&&w->parent()->inherits("QToolBar")) { 908 if(w-> inherits("QToolBarSeparator")&&w->parent()->inherits("QToolBar")) {
912 ((QFrame *) w)-> setFrameShape ( QFrame::NoFrame ); 909 ((QFrame *) w)-> setFrameShape ( QFrame::NoFrame );
913 } 910 }
914 if(w->ownPalette() && !w->inherits("QButton") && !w->inherits("QComboBox")){ 911 if(w->ownPalette() && !w->inherits("QButton") && !w->inherits("QComboBox")){
915 return; 912 return;
916 } 913 }
917 914
918 if(w->parent() && w->parent()->isWidgetType() && !((QWidget*)w->parent())-> 915 if(w->parent() && w->parent()->isWidgetType() && !((QWidget*)w->parent())->
919 palette().active().brush(QColorGroup::Background).pixmap()){ 916 palette().active().brush(QColorGroup::Background).pixmap()){
920 qWarning("No parent pixmap for child widget %s", w->className()); 917 qWarning("No parent pixmap for child widget %s", w->className());
921 return; 918 return;
922 } 919 }
923 if(!isViewport && !isViewportChild && !w->testWFlags(WType_Popup) && 920 if(!isViewport && !isViewportChild && !w->testWFlags(WType_Popup) &&
@@ -974,128 +971,190 @@ void LiquidStyle::unPolish(QWidget *w)
974 971
975 if(w->inherits("QPushButton")){ 972 if(w->inherits("QPushButton")){
976 unapplyCustomAttributes((QPushButton *)w); 973 unapplyCustomAttributes((QPushButton *)w);
977 w->removeEventFilter(this); 974 w->removeEventFilter(this);
978 } 975 }
979/* 976/*
980 if(w->inherits("QPushButton") || w-> inherits("QComboBox")){ 977 if(w->inherits("QPushButton") || w-> inherits("QComboBox")){
981 w-> setBackgroundMode ( PaletteBackground ); 978 w-> setBackgroundMode ( PaletteBackground );
982 } 979 }
983*/ 980*/
984 if(w->inherits("QComboBox") || 981 if(w->inherits("QComboBox") ||
985 w->inherits("QLineEdit") || w->inherits("QRadioButton") || 982 w->inherits("QLineEdit") || w->inherits("QRadioButton") ||
986 w->inherits("QCheckBox") || w->inherits("QScrollBar")) { 983 w->inherits("QCheckBox") || w->inherits("QScrollBar")) {
987 w->removeEventFilter(this); 984 w->removeEventFilter(this);
988 } 985 }
989 if(w->inherits("QButton") || w->inherits("QComboBox")){ 986 if(w->inherits("QButton") || w->inherits("QComboBox")){
990 if(w->parent() && w->parent()->inherits("KHTMLPart")){ 987 if(w->parent() && w->parent()->inherits("KHTMLPart")){
991 w->setAutoMask(false); 988 w->setAutoMask(false);
992 } 989 }
993 } 990 }
994 if(w->inherits("QToolBar")){ 991 if(w->inherits("QToolBar")){
995 w->removeEventFilter(this); 992 w->removeEventFilter(this);
996 w->setBackgroundMode(QWidget::PaletteBackground); 993 w->setBackgroundMode(QWidget::PaletteBackground);
997 return; 994 return;
998 } 995 }
999 if(w->inherits("QHeader")){ 996 if(w->inherits("QHeader")){
1000 w->setMouseTracking(false); 997 w->setMouseTracking(false);
1001 w->removeEventFilter(this); 998 w->removeEventFilter(this);
1002 } 999 }
1003} 1000}
1004 1001
1005void LiquidStyle::polish(QApplication *app) 1002void LiquidStyle::polish(QApplication *app)
1006{ 1003{
1007 1004
1008 QWindowsStyle::polish(app); 1005 QWindowsStyle::polish(app);
1009 menuAni = app->isEffectEnabled(UI_AnimateMenu); 1006 menuAni = app->isEffectEnabled(UI_AnimateMenu);
1010 menuFade = app->isEffectEnabled(UI_FadeMenu); 1007 menuFade = app->isEffectEnabled(UI_FadeMenu);
1011 if(menuAni) 1008 if(menuAni)
1012 app->setEffectEnabled(UI_AnimateMenu, false); 1009 app->setEffectEnabled(UI_AnimateMenu, false);
1013 if(menuFade) 1010 if(menuFade)
1014 app->setEffectEnabled(UI_FadeMenu, false); 1011 app->setEffectEnabled(UI_FadeMenu, false);
1015 1012
1016 qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &LiquidStyle::drawMenuBarItem); 1013 qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &LiquidStyle::drawMenuBarItem);
1017 1014
1018 Config config ( "qpe" ); 1015 Config config ( "qpe" );
1019 config. setGroup ( "Liquid-Style" ); 1016 config. setGroup ( "Liquid-Style" );
1020 1017
1021 // if ( config. readBoolEntry ( "WinDecoration", true )) 1018 // if ( config. readBoolEntry ( "WinDecoration", true ))
1022 // QApplication::qwsSetDecoration ( new LiquidDecoration ( )); 1019 // QApplication::qwsSetDecoration ( new LiquidDecoration ( ));
1023 1020
1024 flatTBButtons = config. readBoolEntry ( "FlatToolButtons", false ); 1021 flatTBButtons = config. readBoolEntry ( "FlatToolButtons", false );
1025} 1022}
1026 1023
1027void LiquidStyle::unPolish(QApplication *app) 1024void LiquidStyle::unPolish(QApplication *app)
1028{ 1025{
1029 QWindowsStyle::unPolish(app); 1026 QWindowsStyle::unPolish(app);
1030 app->setEffectEnabled(UI_AnimateMenu, menuAni); 1027 app->setEffectEnabled(UI_AnimateMenu, menuAni);
1031 app->setEffectEnabled(UI_FadeMenu, menuFade); 1028 app->setEffectEnabled(UI_FadeMenu, menuFade);
1032 1029
1033 qt_set_draw_menu_bar_impl ( 0 ); 1030 qt_set_draw_menu_bar_impl ( 0 );
1034 1031
1035// QApplication::qwsSetDecoration ( new QPEDecoration ( )); 1032// QApplication::qwsSetDecoration ( new QPEDecoration ( ));
1036} 1033}
1037 1034
1035
1036/* !! HACK !! Beware
1037 *
1038 * TT forgot to make the QProgressBar widget styleable in Qt 2.x
1039 * So the only way to customize the drawing, is to intercept the
1040 * paint event - since we have to use protected functions, we need
1041 * to derive a "hack" class from QProgressBar and do the painting
1042 * in there.
1043 *
1044 * - sandman
1045 */
1046
1047class HackProgressBar : public QProgressBar {
1048public:
1049 HackProgressBar ( );
1050
1051 void paint ( QPaintEvent *event, const QColorGroup &g, QPixmap *pix )
1052 {
1053 QPainter p( this );
1054
1055 if ( !contentsRect().contains( event->rect() ) ) {
1056 p.save();
1057 p.setClipRegion( event->region().intersect(frameRect()) );
1058 drawFrame( &p);
1059 p.restore();
1060 }
1061 if ( event->rect().intersects( contentsRect() )) {
1062 p.setClipRegion( event->region().intersect( contentsRect() ) );
1063
1064 int x, y, w, h;
1065 contentsRect ( ). rect ( &x, &y, &w, &h );
1066
1067 int prog = progress ( );
1068 int total = totalSteps ( );
1069 if ( prog < 0 )
1070 prog = 0;
1071 if ( total <= 0 )
1072 total = 1;
1073 int bw = w * prog / total;
1074 if ( bw > w )
1075 bw = w;
1076
1077 p.setPen(g.button().dark(130));
1078 p.drawRect(x, y, bw, h);
1079 p.setPen(g.button().light(120));
1080 p.drawRect(x+1, y+1, bw-2, h-2);
1081
1082 if(bw >= 4 && h >= 4 && pix)
1083 p.drawTiledPixmap(x+2, y+2, bw-4, h-4, *pix);
1084
1085 if ( progress ( )>= 0 && totalSteps ( ) > 0 ) {
1086 QString pstr;
1087 pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ());
1088 p. setPen ( g.text());//g.highlightedText ( ));
1089 p. drawText (x,y,w-1,h-1,AlignCenter,pstr);
1090 }
1091 }
1092 }
1093};
1094
1095
1096
1038/* 1097/*
1039 * This is a fun method ;-) Here's an overview. KToolBar grabs resize to 1098 * This is a fun method ;-) Here's an overview. KToolBar grabs resize to
1040 * force everything to erase and repaint on resize. This is going away, I'm 1099 * force everything to erase and repaint on resize. This is going away, I'm
1041 * trying to get shaped widgets to work right without masking. QPushButton, 1100 * trying to get shaped widgets to work right without masking. QPushButton,
1042 * QComboBox, and Panel applet handles capture mouse enter and leaves in order 1101 * QComboBox, and Panel applet handles capture mouse enter and leaves in order
1043 * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and 1102 * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and
1044 * RadioButtons need to do this differently. Qt buffers these in pixmaps and 1103 * RadioButtons need to do this differently. Qt buffers these in pixmaps and
1045 * caches them in QPixmapCache, which is bad for doing things like hover 1104 * caches them in QPixmapCache, which is bad for doing things like hover
1046 * because the style methods aren't called in paintEvents if everything 1105 * because the style methods aren't called in paintEvents if everything
1047 * is cached. We use our own Paint event handler instead. Taskbuttons and 1106 * is cached. We use our own Paint event handler instead. Taskbuttons and
1048 * pager buttons draw into a pixmap buffer, so we handle those with palette 1107 * pager buttons draw into a pixmap buffer, so we handle those with palette
1049 * modifications. For QHeader, different header items are actually one widget 1108 * modifications. For QHeader, different header items are actually one widget
1050 * that draws multiple items, so we need to check which ID is hightlighted 1109 * that draws multiple items, so we need to check which ID is hightlighted
1051 * and draw it. Finally, we also check enter and leave events for QLineEdit, 1110 * and draw it. Finally, we also check enter and leave events for QLineEdit,
1052 * since if it's inside a combobox we want to highlight the combobox during 1111 * since if it's inside a combobox we want to highlight the combobox during
1053 * hovering in the edit. 1112 * hovering in the edit.
1054 */ 1113 */
1055bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev) 1114bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
1056{ 1115{
1057 if(obj->inherits("QToolBar")){ 1116 if(obj->inherits("QToolBar")){
1058 if(ev->type() == QEvent::Resize){ 1117 if(ev->type() == QEvent::Resize){
1059 const QObjectList *tbChildList = obj->children(); 1118 const QObjectList *tbChildList = obj->children();
1060 QObjectListIt it(*tbChildList); 1119 QObjectListIt it(*tbChildList);
1061 QObject *child; 1120 QObject *child;
1062 while((child = it.current()) != NULL){ 1121 while((child = it.current()) != NULL){
1063 ++it; 1122 ++it;
1064 if(child->isWidgetType()) 1123 if(child->isWidgetType())
1065 ((QWidget *)child)->repaint(true); 1124 ((QWidget *)child)->repaint(true);
1066 } 1125 }
1067 1126
1068 } 1127 }
1069 } 1128 }
1070 else if(obj->inherits("QPushButton") || obj->inherits("QComboBox")){ 1129 else if(obj->inherits("QPushButton") || obj->inherits("QComboBox")){
1071 QWidget *btn = (QWidget *)obj; 1130 QWidget *btn = (QWidget *)obj;
1072 if(ev->type() == QEvent::Enter){ 1131 if(ev->type() == QEvent::Enter){
1073 if(btn->isEnabled()){ 1132 if(btn->isEnabled()){
1074 highlightWidget = btn; 1133 highlightWidget = btn;
1075 btn->repaint(false); 1134 btn->repaint(false);
1076 } 1135 }
1077 } 1136 }
1078 else if(ev->type() == QEvent::Leave){ 1137 else if(ev->type() == QEvent::Leave){
1079 if(btn == highlightWidget){ 1138 if(btn == highlightWidget){
1080 highlightWidget = NULL; 1139 highlightWidget = NULL;
1081 btn->repaint(false); 1140 btn->repaint(false);
1082 } 1141 }
1083 } 1142 }
1084 } 1143 }
1085 else if(obj->inherits("QToolButton")){ 1144 else if(obj->inherits("QToolButton")){
1086 QToolButton *btn = (QToolButton *)btn; 1145 QToolButton *btn = (QToolButton *)btn;
1087 if(!btn->autoRaise()){ 1146 if(!btn->autoRaise()){
1088 if(btn->isEnabled()){ 1147 if(btn->isEnabled()){
1089 highlightWidget = btn; 1148 highlightWidget = btn;
1090 btn->repaint(false); 1149 btn->repaint(false);
1091 } 1150 }
1092 } 1151 }
1093 else if(ev->type() == QEvent::Leave){ 1152 else if(ev->type() == QEvent::Leave){
1094 QWidget *btn = (QWidget *)obj; 1153 QWidget *btn = (QWidget *)obj;
1095 if(btn == highlightWidget){ 1154 if(btn == highlightWidget){
1096 highlightWidget = NULL; 1155 highlightWidget = NULL;
1097 btn->repaint(false); 1156 btn->repaint(false);
1098 } 1157 }
1099 } 1158 }
1100 else 1159 else
1101 highlightWidget = NULL; 1160 highlightWidget = NULL;
@@ -1179,129 +1238,146 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
1179 return(true); 1238 return(true);
1180 } 1239 }
1181 // for hover, just redraw the indicator (not the text) 1240 // for hover, just redraw the indicator (not the text)
1182 else if((ev->type() == QEvent::Enter && btn->isEnabled()) || 1241 else if((ev->type() == QEvent::Enter && btn->isEnabled()) ||
1183 (ev->type() == QEvent::Leave && btn == highlightWidget)){ 1242 (ev->type() == QEvent::Leave && btn == highlightWidget)){
1184 QButton *btn = (QButton *)obj; 1243 QButton *btn = (QButton *)obj;
1185 bool isRadio = obj->inherits("QRadioButton"); 1244 bool isRadio = obj->inherits("QRadioButton");
1186 1245
1187 if(ev->type() == QEvent::Enter) 1246 if(ev->type() == QEvent::Enter)
1188 highlightWidget = btn; 1247 highlightWidget = btn;
1189 else 1248 else
1190 highlightWidget = NULL; 1249 highlightWidget = NULL;
1191 QFontMetrics fm = btn->fontMetrics(); 1250 QFontMetrics fm = btn->fontMetrics();
1192 QSize lsz = fm.size(ShowPrefix, btn->text()); 1251 QSize lsz = fm.size(ShowPrefix, btn->text());
1193 QSize sz = isRadio ? exclusiveIndicatorSize() 1252 QSize sz = isRadio ? exclusiveIndicatorSize()
1194 : indicatorSize(); 1253 : indicatorSize();
1195 int x = 0; 1254 int x = 0;
1196 int y = (btn->height()-lsz.height()+fm.height()-sz.height())/2; 1255 int y = (btn->height()-lsz.height()+fm.height()-sz.height())/2;
1197 //if(btn->autoMask()) 1256 //if(btn->autoMask())
1198 // btn->erase(x+1, y+1, sz.width()-2, sz.height()-2); 1257 // btn->erase(x+1, y+1, sz.width()-2, sz.height()-2);
1199 QPainter p; 1258 QPainter p;
1200 p.begin(btn); 1259 p.begin(btn);
1201 if(isRadio) 1260 if(isRadio)
1202 drawExclusiveIndicator(&p, x, y, sz.width(), sz.height(), 1261 drawExclusiveIndicator(&p, x, y, sz.width(), sz.height(),
1203 btn->colorGroup(), btn->isOn(), 1262 btn->colorGroup(), btn->isOn(),
1204 btn->isDown(), btn->isEnabled()); 1263 btn->isDown(), btn->isEnabled());
1205 else 1264 else
1206 drawIndicator(&p, x, y, sz.width(), sz.height(), 1265 drawIndicator(&p, x, y, sz.width(), sz.height(),
1207 btn->colorGroup(), btn->state(), btn->isDown(), 1266 btn->colorGroup(), btn->state(), btn->isDown(),
1208 btn->isEnabled()); 1267 btn->isEnabled());
1209 p.end(); 1268 p.end();
1210 } 1269 }
1211 } 1270 }
1212 else if(obj->inherits("QHeader")){ 1271 else if(obj->inherits("QHeader")){
1213 QHeader *hw = (QHeader *)obj; 1272 QHeader *hw = (QHeader *)obj;
1214 if(ev->type() == QEvent::Enter){ 1273 if(ev->type() == QEvent::Enter){
1215 currentHeader = hw; 1274 currentHeader = hw;
1216 headerHoverID = -1; 1275 headerHoverID = -1;
1217 } 1276 }
1218 else if(ev->type() == QEvent::Leave){ 1277 else if(ev->type() == QEvent::Leave){
1219 currentHeader = NULL; 1278 currentHeader = NULL;
1220 if(headerHoverID != -1){ 1279 if(headerHoverID != -1){
1221 hw->repaint(hw->sectionPos(headerHoverID), 0, 1280 hw->repaint(hw->sectionPos(headerHoverID), 0,
1222 hw->sectionSize(headerHoverID), hw->height()); 1281 hw->sectionSize(headerHoverID), hw->height());
1223 } 1282 }
1224 headerHoverID = -1; 1283 headerHoverID = -1;
1225 } 1284 }
1226 else if(ev->type() == QEvent::MouseMove){ 1285 else if(ev->type() == QEvent::MouseMove){
1227 QMouseEvent *me = (QMouseEvent *)ev; 1286 QMouseEvent *me = (QMouseEvent *)ev;
1228 int oldHeader = headerHoverID; 1287 int oldHeader = headerHoverID;
1229 headerHoverID = hw->sectionAt(me->x()); 1288 headerHoverID = hw->sectionAt(me->x());
1230 if(oldHeader != headerHoverID){ 1289 if(oldHeader != headerHoverID){
1231 // reset old header 1290 // reset old header
1232 if(oldHeader != -1){ 1291 if(oldHeader != -1){
1233 hw->repaint(hw->sectionPos(oldHeader), 0, 1292 hw->repaint(hw->sectionPos(oldHeader), 0,
1234 hw->sectionSize(oldHeader), hw->height()); 1293 hw->sectionSize(oldHeader), hw->height());
1235 } 1294 }
1236 if(headerHoverID != -1){ 1295 if(headerHoverID != -1){
1237 hw->repaint(hw->sectionPos(headerHoverID), 0, 1296 hw->repaint(hw->sectionPos(headerHoverID), 0,
1238 hw->sectionSize(headerHoverID), hw->height()); 1297 hw->sectionSize(headerHoverID), hw->height());
1239 } 1298 }
1240 } 1299 }
1241 } 1300 }
1242 } 1301 }
1243 return(false); 1302 else if (obj-> inherits( "QProgressBar" )) {
1303 if ( ev->type() == QEvent::Paint ) {
1304 HackProgressBar *p = (HackProgressBar *) obj;
1305 const QColorGroup &g = p-> colorGroup ( );
1306
1307 QPixmap *pix = bevelFillDict.find(g.button().dark(120).rgb());
1308 if(!pix){
1309 int h, s, v;
1310 g.button().dark(120).hsv(&h, &s, &v);
1311 pix = new QPixmap(*bevelFillPix);
1312 adjustHSV(*pix, h, s, v);
1313 bevelFillDict.insert(g.button().dark(120).rgb(), pix);
1314 }
1315 p-> paint ((QPaintEvent *) ev, g, pix );
1316 return true;
1317 }
1318 }
1319 return false ;
1244} 1320}
1245 1321
1246void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h, 1322void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h,
1247 const QColorGroup &g, bool sunken, 1323 const QColorGroup &g, bool sunken,
1248 const QBrush *) 1324 const QBrush *)
1249{ 1325{
1250 drawRoundButton(p, sunken ? g.background() : g.button(), g.background(), 1326 drawRoundButton(p, sunken ? g.background() : g.button(), g.background(),
1251 x, y, w, h); 1327 x, y, w, h);
1252} 1328}
1253 1329
1254void LiquidStyle::drawToolButton(QPainter *p, int x, int y, int w, int h, 1330void LiquidStyle::drawToolButton(QPainter *p, int x, int y, int w, int h,
1255 const QColorGroup &g, bool sunken, 1331 const QColorGroup &g, bool sunken,
1256 const QBrush *) 1332 const QBrush *)
1257{ 1333{
1258 if(p->device()->devType() != QInternal::Widget){ 1334 if(p->device()->devType() != QInternal::Widget){
1259 // drawing into a temp pixmap, don't use mask 1335 // drawing into a temp pixmap, don't use mask
1260 QColor c = sunken ? g.button() : g.background(); 1336 QColor c = sunken ? g.button() : g.background();
1261 p->setPen(c.dark(130)); 1337 p->setPen(c.dark(130));
1262 p->drawRect(x, y, w, h); 1338 p->drawRect(x, y, w, h);
1263 p->setPen(c.light(105)); 1339 p->setPen(c.light(105));
1264 p->drawRect(x+1, y+1, w-2, h-2); 1340 p->drawRect(x+1, y+1, w-2, h-2);
1265 1341
1266 1342
1267 // fill 1343 // fill
1268 QPixmap *pix = bevelFillDict.find(c.rgb()); 1344 QPixmap *pix = bevelFillDict.find(c.rgb());
1269 if(!pix){ 1345 if(!pix){
1270 int h, s, v; 1346 int h, s, v;
1271 c.hsv(&h, &s, &v); 1347 c.hsv(&h, &s, &v);
1272 pix = new QPixmap(*bevelFillPix); 1348 pix = new QPixmap(*bevelFillPix);
1273 adjustHSV(*pix, h, s, v); 1349 adjustHSV(*pix, h, s, v);
1274 bevelFillDict.insert(c.rgb(), pix); 1350 bevelFillDict.insert(c.rgb(), pix);
1275 } 1351 }
1276 1352
1277 p->drawTiledPixmap(x+2, y+2, w-4, h-4, *pix); 1353 p->drawTiledPixmap(x+2, y+2, w-4, h-4, *pix);
1278 } 1354 }
1279 else{ 1355 else{
1280 drawClearBevel(p, x, y, w, h, sunken ? g.button() : 1356 drawClearBevel(p, x, y, w, h, sunken ? g.button() :
1281 highlightWidget == p->device() ? g.button().light(110) : 1357 highlightWidget == p->device() ? g.button().light(110) :
1282 g.background(), g.background()); 1358 g.background(), g.background());
1283 } 1359 }
1284} 1360}
1285 1361
1286void LiquidStyle::drawPushButton(QPushButton *btn, QPainter *p) 1362void LiquidStyle::drawPushButton(QPushButton *btn, QPainter *p)
1287{ 1363{
1288 QRect r = btn->rect(); 1364 QRect r = btn->rect();
1289 bool sunken = btn->isOn() || btn->isDown(); 1365 bool sunken = btn->isOn() || btn->isDown();
1290 QColorGroup g = btn->colorGroup(); 1366 QColorGroup g = btn->colorGroup();
1291 1367
1292 1368
1293 //int dw = buttonDefaultIndicatorWidth(); 1369 //int dw = buttonDefaultIndicatorWidth();
1294 if(btn->hasFocus() || btn->isDefault()){ 1370 if(btn->hasFocus() || btn->isDefault()){
1295 QColor c = btn->hasFocus() ? g.button().light(110) : g.background(); 1371 QColor c = btn->hasFocus() ? g.button().light(110) : g.background();
1296 QPixmap *pix = bevelFillDict.find(c.rgb()); 1372 QPixmap *pix = bevelFillDict.find(c.rgb());
1297 if(!pix){ 1373 if(!pix){
1298 int h, s, v; 1374 int h, s, v;
1299 c.hsv(&h, &s, &v); 1375 c.hsv(&h, &s, &v);
1300 pix = new QPixmap(*bevelFillPix); 1376 pix = new QPixmap(*bevelFillPix);
1301 adjustHSV(*pix, h, s, v); 1377 adjustHSV(*pix, h, s, v);
1302 bevelFillDict.insert(c.rgb(), pix); 1378 bevelFillDict.insert(c.rgb(), pix);
1303 } 1379 }
1304 p->setPen(c.dark(150)); 1380 p->setPen(c.dark(150));
1305 p->drawLine(r.x()+1, r.y(), r.right()-1, r.y()); 1381 p->drawLine(r.x()+1, r.y(), r.right()-1, r.y());
1306 p->drawLine(r.x(), r.y()+1, r.x(), r.bottom()-1); 1382 p->drawLine(r.x(), r.y()+1, r.x(), r.bottom()-1);
1307 p->drawLine(r.right(), r.y()+1, r.right(), r.bottom()-1); 1383 p->drawLine(r.right(), r.y()+1, r.right(), r.bottom()-1);