00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qapplication.h>
00022 #include <qstyle.h>
00023 #include <qwidget.h>
00024 #include <qpainter.h>
00025 #include <qtimer.h>
00026 #include <qwhatsthis.h>
00027 #include <qpe/qcopenvelope_qws.h>
00028 #include <qpe/qpedecoration_qws.h>
00029 #include <qdialog.h>
00030 #include <qdrawutil.h>
00031 #include <qgfx_qws.h>
00032 #include <qpe/qpeapplication.h>
00033 #include <qpe/resource.h>
00034 #include <qpe/global.h>
00035 #include <qfile.h>
00036 #include <qsignal.h>
00037
00038 #include "liquiddeco.h"
00039
00040 #include <stdlib.h>
00041
00042 extern QRect qt_maxWindowRect;
00043
00044 class HackWidget : public QWidget
00045 {
00046 public:
00047 bool needsOk()
00048 {
00049 return ( getWState() & WState_Reserved1 );
00050 }
00051 };
00052
00053
00054 LiquidDecoration::LiquidDecoration()
00055 : QPEDecoration()
00056 {}
00057
00058 LiquidDecoration::~LiquidDecoration()
00059 {}
00060
00061 int LiquidDecoration::getTitleHeight( const QWidget * )
00062 {
00063 return 15;
00064 }
00065
00066
00067 void LiquidDecoration::paint( QPainter *painter, const QWidget *widget )
00068 {
00069 int titleWidth = getTitleWidth( widget );
00070 int titleHeight = getTitleHeight( widget );
00071
00072 QRect rect( widget->rect() );
00073
00074
00075 QRect br( rect.left() - BORDER_WIDTH,
00076 rect.top() - BORDER_WIDTH - titleHeight,
00077 rect.width() + 2 * BORDER_WIDTH,
00078 rect.height() + BORDER_WIDTH + BOTTOM_BORDER_WIDTH + titleHeight );
00079
00080
00081 QRect tr;
00082
00083 tr = QRect( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
00084
00085 QRegion oldClip = painter->clipRegion();
00086 painter->setClipRegion( oldClip - QRegion( tr ) );
00087
00088 bool isActive = ( widget == qApp->activeWindow() );
00089
00090 QColorGroup cg = QApplication::palette().active();
00091 if ( isActive )
00092 cg. setBrush ( QColorGroup::Button, cg. brush ( QColorGroup::Highlight ) );
00093
00094 qDrawWinPanel( painter, br.x(), br.y(), br.width(),
00095 br.height() - 4, cg, FALSE,
00096 &cg.brush( QColorGroup::Background ) );
00097
00098 painter->setClipRegion( oldClip );
00099
00100 if ( titleWidth > 0 ) {
00101 painter->setPen( cg.midlight() );
00102 painter->drawLine( rect.left() - BORDER_WIDTH + 2,
00103 rect.bottom() + 1, rect.right() + BORDER_WIDTH - 2,
00104 rect.bottom() + 1 );
00105
00106 QRect t ( rect.left() - 2, rect.top() - titleHeight - 2, rect.width() + 3, titleHeight + 2 );
00107
00108
00109
00110 QApplication::style().drawBevelButton( painter, t.x(), t.y(), t.width(), t.height(), cg, isActive );
00111
00112 t .setLeft ( t. left ( ) + 4 );
00113 t .setRight ( t. right ( ) - 2 );
00114
00115 QFont f ( QApplication::font ( ));
00116 f. setWeight ( QFont::Bold );
00117
00118 painter-> setFont ( f );
00119
00120 QColor textcol = cg.color( isActive ? QColorGroup::HighlightedText : QColorGroup::Text );
00121 QColor shadecol = ( qGray ( textcol. rgb ( ) ) > 128 ) ? textcol. dark ( 230 ) : textcol.light( 300 );
00122
00123 if ( textcol == shadecol ) {
00124 if ( qGray ( shadecol. rgb ( ) ) < 128 )
00125 shadecol = QColor ( 225, 225, 225 );
00126 else
00127 shadecol = QColor ( 30, 30, 30 );
00128 }
00129
00130 painter-> setPen( shadecol );
00131 painter-> drawText( t.x() + 1, t.y() + 1, t.width(), t.height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, widget->caption() );
00132 painter-> setPen( textcol );
00133 painter-> drawText( t.x(), t.y(), t.width(), t.height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, widget->caption() );
00134 }
00135
00136 #ifndef MINIMIZE_HELP_HACK
00137 paintButton( painter, widget, ( QWSDecoration::Region ) Help, 0 );
00138 #endif
00139 }
00140
00141 void LiquidDecoration::paintButton( QPainter *painter, const QWidget *w,
00142 QWSDecoration::Region type, int state )
00143 {
00144 const QColorGroup & cg = w->palette().active();
00145
00146 QRect brect( region( w, w->rect(), type ).boundingRect() );
00147
00148 const QImage *img = 0;
00149
00150 switch ( ( int ) type ) {
00151 case Close:
00152 img = &imageClose;
00153 break;
00154 case Minimize:
00155 if ( ( ( HackWidget * ) w ) ->needsOk() ||
00156 ( w->inherits( "QDialog" ) && !w->inherits( "QMessageBox" ) ) )
00157 img = &imageOk;
00158 else if ( helpExists )
00159 img = &imageHelp;
00160 break;
00161 case Help:
00162 img = &imageHelp;
00163 break;
00164 default:
00165 return ;
00166 }
00167
00168 if ( img ) {
00169 if ( ( state & QWSButton::MouseOver ) && ( state & QWSButton::Clicked ) )
00170 painter->drawImage( brect.x() + 1, brect.y() + 3, *img );
00171 else
00172 painter->drawImage( brect.x(), brect.y() + 2, *img );
00173 }
00174 }
00175
00176
00177