summaryrefslogtreecommitdiff
path: root/noncore/styles/liquid/liquid.cpp
Unidiff
Diffstat (limited to 'noncore/styles/liquid/liquid.cpp') (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
@@ -9,49 +9,49 @@
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)
@@ -832,52 +832,49 @@ void LiquidStyle::polish(QPalette &appPal)
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
@@ -1014,48 +1011,110 @@ void LiquidStyle::polish(QApplication *app)
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;
@@ -1219,49 +1278,66 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
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