00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "flat.h"
00022 #include <qpainter.h>
00023 #include <qapplication.h>
00024
00025
00026
00027 static const char * ok_xpm[] = {
00028 "32 32 3 1",
00029 " c None",
00030 ". c #000000",
00031 "+ c #FFFFFF",
00032 " ",
00033 " ",
00034 " ++++++++ ",
00035 " ++++++++++++ ",
00036 " +++++ +++++ ",
00037 " +++ +++ ",
00038 " +++ +++ ",
00039 " +++ +++ ",
00040 " +++ +++ ",
00041 " ++ ++ ",
00042 " ++ +++++ ++ ++ ++ ",
00043 " ++ ++++++++ ++ +++ ++ ",
00044 " +++ +++ +++ ++ +++ +++ ",
00045 " ++ +++ ++ ++ +++ ++ ",
00046 " ++ ++ ++ ++ ++ ++ ",
00047 " ++ ++ ++ +++++ ++ ",
00048 " ++ ++ ++ ++++ ++ ",
00049 " ++ ++ ++ ++ ++ ++ ",
00050 " ++ +++ ++ ++ +++ ++ ",
00051 " +++ +++ +++ ++ +++ +++ ",
00052 " ++ ++++++++ ++ ++ ++ ",
00053 " ++ +++++ ++ ++ ++ ",
00054 " ++ ++ ",
00055 " +++ +++ ",
00056 " +++ +++ ",
00057 " +++ +++ ",
00058 " +++ +++ ",
00059 " +++++ +++++ ",
00060 " ++++++++++++ ",
00061 " ++++++++ ",
00062 " ",
00063 " "};
00064
00065
00066
00067 static const char * close_xpm[] = {
00068 "32 32 3 1",
00069 " c None",
00070 ". c #000000",
00071 "+ c #FFFFFF",
00072 " ",
00073 " ",
00074 " ++++++++ ",
00075 " ++++++++++++ ",
00076 " +++++ +++++ ",
00077 " +++ +++ ",
00078 " +++ +++ ",
00079 " +++ +++ ",
00080 " +++ +++ ",
00081 " ++ ++ ++ ++ ",
00082 " ++ +++ +++ ++ ",
00083 " ++ +++ +++ ++ ",
00084 " +++ +++ +++ +++ ",
00085 " ++ +++ +++ ++ ",
00086 " ++ ++++++ ++ ",
00087 " ++ ++++ ++ ",
00088 " ++ ++++ ++ ",
00089 " ++ ++++++ ++ ",
00090 " ++ +++ +++ ++ ",
00091 " +++ +++ +++ +++ ",
00092 " ++ +++ +++ ++ ",
00093 " ++ +++ +++ ++ ",
00094 " ++ ++ ++ ++ ",
00095 " +++ +++ ",
00096 " +++ +++ ",
00097 " +++ +++ ",
00098 " +++ +++ ",
00099 " +++++ +++++ ",
00100 " ++++++++++++ ",
00101 " ++++++++ ",
00102 " ",
00103 " "};
00104
00105
00106
00107 static const char * help_xpm[] = {
00108 "32 32 3 1",
00109 " c None",
00110 ". c #000000",
00111 "+ c #FFFFFF",
00112 " ",
00113 " ",
00114 " ++++++++ ",
00115 " ++++++++++++ ",
00116 " +++++ +++++ ",
00117 " +++ +++ ",
00118 " +++ +++ ",
00119 " +++ +++ ",
00120 " +++ +++++ +++ ",
00121 " ++ ++++++++ ++ ",
00122 " ++ ++++ ++++ ++ ",
00123 " ++ +++ +++ ++ ",
00124 " +++ +++ +++ +++ ",
00125 " ++ ++++ ++ ",
00126 " ++ +++++ ++ ",
00127 " ++ +++++ ++ ",
00128 " ++ ++++ ++ ",
00129 " ++ ++++ ++ ",
00130 " ++ +++ ++ ",
00131 " +++ +++ +++ ",
00132 " ++ ++ ",
00133 " ++ ++ ",
00134 " ++ +++ ++ ",
00135 " +++ +++ +++ ",
00136 " +++ +++ ",
00137 " +++ +++ ",
00138 " +++ +++ ",
00139 " +++++ +++++ ",
00140 " ++++++++++++ ",
00141 " ++++++++ ",
00142 " ",
00143 " "};
00144
00145
00146
00147 static const char * maximize_xpm[] = {
00148 "32 32 3 1",
00149 " c None",
00150 ". c #000000",
00151 "+ c #FFFFFF",
00152 " ",
00153 " ",
00154 " ++++++++ ",
00155 " ++++++++++++ ",
00156 " +++++ +++++ ",
00157 " +++ +++ ",
00158 " +++ +++ ",
00159 " +++ +++ ",
00160 " +++ ++++++++++++++ +++ ",
00161 " ++ ++++++++++++++ ++ ",
00162 " ++ ++++++++++++++ ++ ",
00163 " ++ +++ +++ ++ ",
00164 " +++ +++ +++ +++ ",
00165 " ++ +++ +++ ++ ",
00166 " ++ +++ +++ ++ ",
00167 " ++ +++ +++ ++ ",
00168 " ++ +++ +++ ++ ",
00169 " ++ +++ +++ ++ ",
00170 " ++ +++ +++ ++ ",
00171 " +++ +++ +++ +++ ",
00172 " ++ +++ +++ ++ ",
00173 " ++ ++++++++++++++ ++ ",
00174 " ++ ++++++++++++++ ++ ",
00175 " +++ ++++++++++++++ +++ ",
00176 " +++ +++ ",
00177 " +++ +++ ",
00178 " +++ +++ ",
00179 " +++++ +++++ ",
00180 " ++++++++++++ ",
00181 " ++++++++ ",
00182 " ",
00183 " "};
00184
00185 static QImage scaleButton( const QImage &img, int height )
00186 {
00187 if ( img.height() != height ) {
00188 return img.smoothScale( img.width()*height/img.height(), height );
00189 } else {
00190 return img;
00191 }
00192 }
00193
00194 static void colorize( QImage &img, const QColor &c, bool rev )
00195 {
00196 for ( int i = 0; i < img.numColors(); i++ ) {
00197 bool sc = (img.color(i) & 0xff000000);
00198 if ( rev ) sc = !sc;
00199 img.setColor(i, sc ? c.rgb() : 0x00000000 );
00200 }
00201 }
00202
00203 FlatDecoration::FlatDecoration() : buttonCache(16)
00204 {
00205 buttonCache.setAutoDelete(TRUE);
00206 }
00207
00208 FlatDecoration::~FlatDecoration()
00209 {
00210 }
00211
00212 int FlatDecoration::metric( Metric m, const WindowData *wd ) const
00213 {
00214 switch ( m ) {
00215 case TopBorder:
00216 return 1;
00217 break;
00218 case LeftBorder:
00219 case RightBorder:
00220 return 2;
00221 case BottomBorder:
00222 return 4;
00223 case TitleHeight:
00224 if ( QApplication::desktop()->height() > 320 )
00225 return 20;
00226 else
00227 return 18;
00228 case OKWidth:
00229 case CloseWidth:
00230 case HelpWidth:
00231 case MaximizeWidth:
00232 return metric(TitleHeight,wd);
00233 break;
00234 default:
00235 return WindowDecorationInterface::metric( m, wd );
00236 break;
00237 }
00238
00239 return 0;
00240 }
00241
00242 void FlatDecoration::drawArea( Area a, QPainter *p, const WindowData *wd ) const
00243 {
00244 int th = metric( TitleHeight, wd );
00245 QRect r = wd->rect;
00246
00247 switch ( a ) {
00248 case Border:
00249 {
00250 const QColorGroup &cg = wd->palette.active();
00251 if ( wd->flags & WindowData::Active ) {
00252 p->setBrush( cg.color(QColorGroup::Highlight) );
00253 } else {
00254 p->setBrush( cg.color(QColorGroup::Background) );
00255 }
00256 p->setPen( cg.foreground() );
00257 int lb = metric(LeftBorder,wd);
00258 int rb = metric(RightBorder,wd);
00259 int tb = metric(TopBorder,wd);
00260 int bb = metric(BottomBorder,wd);
00261 p->drawRect( r.x()-lb, r.y()-tb-th, r.width()+lb+rb,
00262 r.height()+th+tb+bb );
00263 }
00264 break;
00265 case Title:
00266 if ( r.height() < 2 ) {
00267 WindowDecorationInterface::drawArea( a, p, wd );
00268 } else {
00269 const QColorGroup &cg = wd->palette.active();
00270 QColor c;
00271 if ( wd->flags & WindowData::Active )
00272 c = cg.color(QColorGroup::Highlight);
00273 else
00274 c = cg.color(QColorGroup::Background);
00275 p->fillRect( QRect(r.x(),r.y()-th,r.width(),th), c );
00276 }
00277 break;
00278 case TitleText:
00279 p->drawText( r.left()+3+metric(HelpWidth,wd), r.top()-th,
00280 r.width()-metric(HelpWidth,wd)-metric(CloseWidth,wd), th,
00281 Qt::AlignVCenter, wd->caption );
00282 break;
00283 default:
00284 FlatDecoration::drawArea( a, p, wd );
00285 break;
00286 }
00287 }
00288
00289 void FlatDecoration::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
00290 {
00291 QColor c;
00292 const QColorGroup &cg = wd->palette.active();
00293 if ( wd->flags & WindowDecorationInterface::WindowData::Active )
00294 c = cg.color(QColorGroup::HighlightedText);
00295 else
00296 c = cg.color(QColorGroup::Foreground);
00297 bool r = (state & QWSButton::MouseOver) && (state & QWSButton::Clicked);
00298 int th = metric(TitleHeight, wd);
00299
00300 QString key( "%1-%2-%3-%4" );
00301 key = key.arg(b).arg(th).arg(c.name()).arg(r ? "1" : "0");
00302 QImage *img = buttonCache.find( key );
00303 if ( !img ) {
00304 QImage tmp;
00305 switch ( b ) {
00306 case OK:
00307 tmp = QImage( ok_xpm );
00308 break;
00309 case Close:
00310 tmp = QImage( close_xpm );
00311 break;
00312 case Help:
00313 tmp = QImage( help_xpm );
00314 break;
00315 case Maximize:
00316 tmp = QImage( maximize_xpm );
00317 break;
00318 }
00319 colorize( tmp, c, r );
00320 img = new QImage( scaleButton(tmp,th) );
00321 FlatDecoration *that = (FlatDecoration *)this;
00322 that->buttonCache.insert( key, img, 1 );
00323 }
00324
00325 p->drawImage( x, y, *img );
00326 }
00327
00328 QRegion FlatDecoration::mask( const WindowData *wd ) const
00329 {
00330 return WindowDecorationInterface::mask( wd );
00331 }
00332
00333 QString FlatDecoration::name() const
00334 {
00335 return qApp->translate( "Decoration", "Flat" );
00336 }
00337
00338 QPixmap FlatDecoration::icon() const
00339 {
00340 return QPixmap();
00341 }
00342
00343 QRESULT FlatDecoration::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00344 {
00345 *iface = 0;
00346 if ( uuid == IID_QUnknown )
00347 *iface = this;
00348 else if ( uuid == IID_WindowDecoration )
00349 *iface = this;
00350 else
00351 return QS_FALSE;
00352
00353 if ( *iface )
00354 (*iface)->addRef();
00355 return QS_OK;
00356 }
00357
00358 Q_EXPORT_INTERFACE()
00359 {
00360 Q_CREATE_INSTANCE( FlatDecoration )
00361 }
00362