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
@@ -1,81 +1,81 @@
/*-
* Copyright (C)QPL 2001 Daniel M. Duley. All rights reserved.
*/
#ifndef INCLUDE_MENUITEM_DEF
#define INCLUDE_MENUITEM_DEF
#endif
#include <qmenudata.h>
#include "liquid.h"
//#include "liquiddeco.h"
#include <qapplication.h>
#include <qpe/config.h>
#include "effects.h"
#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;
int r, g, b;
for(y=0; y < img.height(); y+=3){
unsigned int *data = (unsigned int *) img.scanLine(y);
for(x=0; x < img.width(); ++x){
r = qRed(data[x]);
g = qGreen(data[x]);
b = qBlue(data[x]);
if(r-10)
r-=10;
if(g-10)
g-=10;
if(b-10)
b-=10;
data[x] = qRgb(r, g, b);
}
}
pix.convertFromImage(img);
}
TransMenuHandler::TransMenuHandler(QObject *parent)
: QObject(parent)
{
pixDict.setAutoDelete(true);
reloadSettings();
}
void TransMenuHandler::reloadSettings()
{
pixDict.clear();
Config config ( "qpe" );
config. setGroup ( "Liquid-Style" );
@@ -808,100 +808,97 @@ void LiquidStyle::polish(QPalette &appPal)
basePix.fill(c.rgb());
painter.begin(&basePix);
painter.setPen(c.dark(105));
for(i=0; i < 32; i+=4){
painter.drawLine(0, i, 32, i);
painter.drawLine(0, i+1, 32, i+1);
};
painter.end();
baseBrush.setColor(c);
baseBrush.setPixmap(basePix);
it.toFirst();
while ((w=it.current()) != 0 ){
++it;
if(w->inherits("QLineEdit")){
QPalette pal = w->palette();
pal.setBrush(QColorGroup::Base, baseBrush);
w->setPalette(pal);
}
else if(w->inherits("QPushButton")){
applyCustomAttributes((QPushButton *)w);
}
}
}
void LiquidStyle::polish(QWidget *w)
{
if(w->inherits("QMenuBar")){
//((QFrame*)w)->setLineWidth(0);
w->setBackgroundMode(QWidget::PaletteBackground);
w->setBackgroundOrigin(QWidget::ParentOrigin);
return;
}
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);
}
bool isViewport = qstrcmp(w->name(), "qt_viewport") == 0 ||
qstrcmp(w->name(), "qt_clipped_viewport") == 0;
bool isViewportChild = w->parent() &&
((qstrcmp(w->parent()->name(), "qt_viewport") == 0) ||
(qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0));
if(isViewport && w->parent() && qstrcmp(w->parent()->name(), "proxyview") == 0){
w->setBackgroundMode(QWidget::X11ParentRelative);
return;
}
if(isViewportChild){
if(w->inherits("QButton") || w->inherits("QComboBox")){
if(w->parent()){ // heh, only way to test for KHTML children ;-)
if(w->parent()->parent()){
if(w->parent()->parent()->parent() &&
w->parent()->parent()->parent()->inherits("KHTMLView")){
w->setAutoMask(true);
w->setBackgroundMode(QWidget::NoBackground);
}
}
}
return;
}
}
if(w->inherits("QHeader")){
w->setMouseTracking(true);
w->installEventFilter(this);
}
if(w-> inherits("QToolButton")&&w->parent()->inherits("QToolBar")) {
((QToolButton*)w)->setAutoRaise (flatTBButtons);
@@ -990,96 +987,158 @@ void LiquidStyle::unPolish(QWidget *w)
if(w->parent() && w->parent()->inherits("KHTMLPart")){
w->setAutoMask(false);
}
}
if(w->inherits("QToolBar")){
w->removeEventFilter(this);
w->setBackgroundMode(QWidget::PaletteBackground);
return;
}
if(w->inherits("QHeader")){
w->setMouseTracking(false);
w->removeEventFilter(this);
}
}
void LiquidStyle::polish(QApplication *app)
{
QWindowsStyle::polish(app);
menuAni = app->isEffectEnabled(UI_AnimateMenu);
menuFade = app->isEffectEnabled(UI_FadeMenu);
if(menuAni)
app->setEffectEnabled(UI_AnimateMenu, false);
if(menuFade)
app->setEffectEnabled(UI_FadeMenu, false);
qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &LiquidStyle::drawMenuBarItem);
Config config ( "qpe" );
config. setGroup ( "Liquid-Style" );
// if ( config. readBoolEntry ( "WinDecoration", true ))
// 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.
*/
bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
{
if(obj->inherits("QToolBar")){
if(ev->type() == QEvent::Resize){
const QObjectList *tbChildList = obj->children();
QObjectListIt it(*tbChildList);
QObject *child;
while((child = it.current()) != NULL){
++it;
if(child->isWidgetType())
((QWidget *)child)->repaint(true);
}
}
}
else if(obj->inherits("QPushButton") || obj->inherits("QComboBox")){
QWidget *btn = (QWidget *)obj;
if(ev->type() == QEvent::Enter){
if(btn->isEnabled()){
highlightWidget = btn;
btn->repaint(false);
}
}
else if(ev->type() == QEvent::Leave){
if(btn == highlightWidget){
highlightWidget = NULL;
btn->repaint(false);
}
}
}
else if(obj->inherits("QToolButton")){
@@ -1195,97 +1254,114 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
int x = 0;
int y = (btn->height()-lsz.height()+fm.height()-sz.height())/2;
//if(btn->autoMask())
// btn->erase(x+1, y+1, sz.width()-2, sz.height()-2);
QPainter p;
p.begin(btn);
if(isRadio)
drawExclusiveIndicator(&p, x, y, sz.width(), sz.height(),
btn->colorGroup(), btn->isOn(),
btn->isDown(), btn->isEnabled());
else
drawIndicator(&p, x, y, sz.width(), sz.height(),
btn->colorGroup(), btn->state(), btn->isDown(),
btn->isEnabled());
p.end();
}
}
else if(obj->inherits("QHeader")){
QHeader *hw = (QHeader *)obj;
if(ev->type() == QEvent::Enter){
currentHeader = hw;
headerHoverID = -1;
}
else if(ev->type() == QEvent::Leave){
currentHeader = NULL;
if(headerHoverID != -1){
hw->repaint(hw->sectionPos(headerHoverID), 0,
hw->sectionSize(headerHoverID), hw->height());
}
headerHoverID = -1;
}
else if(ev->type() == QEvent::MouseMove){
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
QColor c = sunken ? g.button() : g.background();
p->setPen(c.dark(130));
p->drawRect(x, y, w, h);
p->setPen(c.light(105));
p->drawRect(x+1, y+1, w-2, h-2);
// fill
QPixmap *pix = bevelFillDict.find(c.rgb());
if(!pix){
int h, s, v;
c.hsv(&h, &s, &v);
pix = new QPixmap(*bevelFillPix);
adjustHSV(*pix, h, s, v);
bevelFillDict.insert(c.rgb(), pix);
}
p->drawTiledPixmap(x+2, y+2, w-4, h-4, *pix);
}
else{
drawClearBevel(p, x, y, w, h, sunken ? g.button() :
highlightWidget == p->device() ? g.button().light(110) :
g.background(), g.background());
}
}
void LiquidStyle::drawPushButton(QPushButton *btn, QPainter *p)
{
QRect r = btn->rect();
bool sunken = btn->isOn() || btn->isDown();
QColorGroup g = btn->colorGroup();