summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-06 20:54:49 (UTC)
committer sandman <sandman>2002-10-06 20:54:49 (UTC)
commite334186122e512a57bd27026014f01f501db93fc (patch) (side-by-side diff)
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
@@ -17,33 +17,33 @@
#include <qpalette.h>
#include <qbitmap.h>
#include <qtabbar.h>
#include <qpopupmenu.h>
#include <qobjectlist.h>
#include <qimage.h>
#include <qtimer.h>
#include <qpixmapcache.h>
#include <qradiobutton.h>
#include <qcombobox.h>
#include <qdrawutil.h>
#include <qwidgetlist.h>
#include <qtoolbutton.h>
#include <qheader.h>
#include <unistd.h>
#include <qmenubar.h>
-
+#include <qprogressbar.h>
#include <stdio.h>
#include "htmlmasks.h"
#include "embeddata.h"
typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
QColorGroup &, bool, bool);
QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
void TransMenuHandler::stripePixmap(QPixmap &pix, const QColor &color)
{
QImage img(pix.convertToImage());
QImageEffect::fade(img, 0.9, color);
int x, y;
@@ -840,36 +840,33 @@ void LiquidStyle::polish(QWidget *w)
if(w->inherits("QToolBar")){
w->installEventFilter(this);
w->setBackgroundMode(QWidget::PaletteBackground);
w->setBackgroundOrigin(QWidget::WidgetOrigin);
return;
}
if(w->inherits("QPopupMenu"))
w->setBackgroundMode(QWidget::NoBackground);
else if(w-> testWFlags(Qt::WType_Popup) && !w->inherits("QListBox")) {
w->installEventFilter(menuHandler);
}
if(w->isTopLevel()){
return;
}
-
-
-
- if(w->inherits("QComboBox") ||
+ if(w->inherits("QComboBox") || w->inherits("QProgressBar") ||
w->inherits("QLineEdit") || w->inherits("QRadioButton") ||
w->inherits("QCheckBox") || w->inherits("QScrollBar")) {
w->installEventFilter(this);
}
if(w->inherits("QLineEdit")){
QPalette pal = w->palette();
pal.setBrush(QColorGroup::Base, baseBrush);
w->setPalette(pal);
}
if(w->inherits("QPushButton")){
applyCustomAttributes((QPushButton *)w);
w->installEventFilter(this);
}
if(w->inherits("QButton") || w-> inherits("QComboBox")){
w-> setBackgroundMode ( QWidget::PaletteBackground );
w->setBackgroundOrigin ( QWidget::ParentOrigin);
@@ -1022,32 +1019,94 @@ void LiquidStyle::polish(QApplication *app)
// QApplication::qwsSetDecoration ( new LiquidDecoration ( ));
flatTBButtons = config. readBoolEntry ( "FlatToolButtons", false );
}
void LiquidStyle::unPolish(QApplication *app)
{
QWindowsStyle::unPolish(app);
app->setEffectEnabled(UI_AnimateMenu, menuAni);
app->setEffectEnabled(UI_FadeMenu, menuFade);
qt_set_draw_menu_bar_impl ( 0 );
// QApplication::qwsSetDecoration ( new QPEDecoration ( ));
}
+
+/* !! HACK !! Beware
+ *
+ * TT forgot to make the QProgressBar widget styleable in Qt 2.x
+ * So the only way to customize the drawing, is to intercept the
+ * paint event - since we have to use protected functions, we need
+ * to derive a "hack" class from QProgressBar and do the painting
+ * in there.
+ *
+ * - sandman
+ */
+
+class HackProgressBar : public QProgressBar {
+public:
+ HackProgressBar ( );
+
+ void paint ( QPaintEvent *event, const QColorGroup &g, QPixmap *pix )
+ {
+ QPainter p( this );
+
+ if ( !contentsRect().contains( event->rect() ) ) {
+ p.save();
+ p.setClipRegion( event->region().intersect(frameRect()) );
+ drawFrame( &p);
+ p.restore();
+ }
+ if ( event->rect().intersects( contentsRect() )) {
+ p.setClipRegion( event->region().intersect( contentsRect() ) );
+
+ int x, y, w, h;
+ contentsRect ( ). rect ( &x, &y, &w, &h );
+
+ int prog = progress ( );
+ int total = totalSteps ( );
+ if ( prog < 0 )
+ prog = 0;
+ if ( total <= 0 )
+ total = 1;
+ int bw = w * prog / total;
+ if ( bw > w )
+ bw = w;
+
+ p.setPen(g.button().dark(130));
+ p.drawRect(x, y, bw, h);
+ p.setPen(g.button().light(120));
+ p.drawRect(x+1, y+1, bw-2, h-2);
+
+ if(bw >= 4 && h >= 4 && pix)
+ p.drawTiledPixmap(x+2, y+2, bw-4, h-4, *pix);
+
+ if ( progress ( )>= 0 && totalSteps ( ) > 0 ) {
+ QString pstr;
+ pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ());
+ p. setPen ( g.text());//g.highlightedText ( ));
+ p. drawText (x,y,w-1,h-1,AlignCenter,pstr);
+ }
+ }
+ }
+};
+
+
+
/*
* This is a fun method ;-) Here's an overview. KToolBar grabs resize to
* force everything to erase and repaint on resize. This is going away, I'm
* trying to get shaped widgets to work right without masking. QPushButton,
* QComboBox, and Panel applet handles capture mouse enter and leaves in order
* to set the highlightwidget and repaint for mouse hovers. CheckBoxes and
* RadioButtons need to do this differently. Qt buffers these in pixmaps and
* caches them in QPixmapCache, which is bad for doing things like hover
* because the style methods aren't called in paintEvents if everything
* is cached. We use our own Paint event handler instead. Taskbuttons and
* pager buttons draw into a pixmap buffer, so we handle those with palette
* modifications. For QHeader, different header items are actually one widget
* that draws multiple items, so we need to check which ID is hightlighted
* and draw it. Finally, we also check enter and leave events for QLineEdit,
* since if it's inside a combobox we want to highlight the combobox during
* hovering in the edit.
@@ -1227,33 +1286,50 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
QMouseEvent *me = (QMouseEvent *)ev;
int oldHeader = headerHoverID;
headerHoverID = hw->sectionAt(me->x());
if(oldHeader != headerHoverID){
// reset old header
if(oldHeader != -1){
hw->repaint(hw->sectionPos(oldHeader), 0,
hw->sectionSize(oldHeader), hw->height());
}
if(headerHoverID != -1){
hw->repaint(hw->sectionPos(headerHoverID), 0,
hw->sectionSize(headerHoverID), hw->height());
}
}
}
}
- return(false);
+ else if (obj-> inherits( "QProgressBar" )) {
+ if ( ev->type() == QEvent::Paint ) {
+ HackProgressBar *p = (HackProgressBar *) obj;
+ const QColorGroup &g = p-> colorGroup ( );
+
+ QPixmap *pix = bevelFillDict.find(g.button().dark(120).rgb());
+ if(!pix){
+ int h, s, v;
+ g.button().dark(120).hsv(&h, &s, &v);
+ pix = new QPixmap(*bevelFillPix);
+ adjustHSV(*pix, h, s, v);
+ bevelFillDict.insert(g.button().dark(120).rgb(), pix);
+ }
+ p-> paint ((QPaintEvent *) ev, g, pix );
+ return true;
+ }
+ }
+ return false ;
}
void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken,
const QBrush *)
{
drawRoundButton(p, sunken ? g.background() : g.button(), g.background(),
x, y, w, h);
}
void LiquidStyle::drawToolButton(QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken,
const QBrush *)
{
if(p->device()->devType() != QInternal::Widget){
// drawing into a temp pixmap, don't use mask