00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "metal.h"
00027
00028 #ifndef QT_NO_STYLE_WINDOWS
00029
00030 #include "qapplication.h"
00031 #include "qcombobox.h"
00032 #include "qpainter.h"
00033 #include "qdrawutil.h"
00034 #include "qpixmap.h"
00035 #include "qpalette.h"
00036 #include "qwidget.h"
00037 #include "qlabel.h"
00038 #include "qimage.h"
00039 #include "qpushbutton.h"
00040 #include "qwidget.h"
00041 #include "qrangecontrol.h"
00042 #include "qscrollbar.h"
00043 #include "qslider.h"
00044 #include "limits.h"
00045
00046
00048 #include "Go4GUI/images/stonedark.xpm"
00049 #include "Go4GUI/images/stone1.xpm"
00050 #include "Go4GUI/images/marble.xpm"
00052
00053
00054
00055 MetalStyle::MetalStyle() : QWindowsStyle() { }
00056
00060 void MetalStyle::polish( QApplication *app)
00061 {
00062 oldPalette = app->palette();
00063
00064
00065
00066
00067 QFont f("times", app->font().pointSize() );
00068 f.setBold( TRUE );
00069 f.setItalic( TRUE );
00070 app->setFont( f, TRUE, "QMenuBar");
00071 app->setFont( f, TRUE, "QPopupMenu");
00072
00073
00074
00075
00076
00077 QColor gold("#B9B9A5A54040");
00078 QPixmap button( 1, 1 ); button.fill( gold );
00079
00080 QPixmap background(marble_xpm);
00081 QPixmap dark( 1, 1 ); dark.fill( red.dark() );
00082 QPixmap mid( stone1_xpm );
00083 QPixmap light( stone1_xpm );
00084
00085 QPalette op = app->palette();
00086
00087 QColor backCol( 227,227,227 );
00088
00089
00090 QColorGroup active (op.active().foreground(),
00091 QBrush(op.active().button(),button),
00092 QBrush(op.active().light(), light),
00093 QBrush(op.active().dark(), dark),
00094 QBrush(op.active().mid(), mid),
00095 op.active().text(),
00096 Qt::white,
00097 op.active().base(),
00098 QBrush(backCol, background)
00099 );
00100 active.setColor( QColorGroup::ButtonText, Qt::white );
00101 active.setColor( QColorGroup::Shadow, Qt::black );
00102 QColorGroup disabled (op.disabled().foreground(),
00103 QBrush(op.disabled().button(),button),
00104 QBrush(op.disabled().light(), light),
00105 op.disabled().dark(),
00106 QBrush(op.disabled().mid(), mid),
00107 op.disabled().text(),
00108 Qt::white,
00109 op.disabled().base(),
00110 QBrush(backCol, background)
00111 );
00112
00113 QPalette newPalette( active, disabled, active );
00114 app->setPalette( newPalette, TRUE );
00115 }
00116
00120 void MetalStyle::unPolish( QApplication *app)
00121 {
00122 app->setPalette(oldPalette, TRUE);
00123 app->setFont( app->font(), TRUE );
00124 }
00125
00129 void MetalStyle::polish( QWidget* w)
00130 {
00131
00132
00133
00134
00135
00136 if (w->inherits("QPushButton")){
00137 w->setBackgroundMode( QWidget::NoBackground );
00138 return;
00139 }
00140
00141 if ( !w->isTopLevel() ) {
00142 if ( w->backgroundPixmap() )
00143 w->setBackgroundOrigin( QWidget::WindowOrigin );
00144 }
00145 }
00146
00147 void MetalStyle::unPolish( QWidget* w)
00148 {
00149
00150
00151
00152
00153
00154 if (w->inherits("QPushButton")){
00155 w->setBackgroundMode( QWidget::PaletteButton );
00156 return;
00157 }
00158 if ( !w->isTopLevel() ) {
00159 if ( w->backgroundPixmap() )
00160 w->setBackgroundOrigin( QWidget::WidgetOrigin );
00161 }
00162
00163 }
00164
00165 void MetalStyle::drawPrimitive( PrimitiveElement pe,
00166 QPainter *p,
00167 const QRect &r,
00168 const QColorGroup &cg,
00169 SFlags flags, const QStyleOption& opt ) const
00170 {
00171 switch( pe ) {
00172 case PE_HeaderSection:
00173 if ( flags & Style_Sunken )
00174 flags ^= Style_Sunken | Style_Raised;
00175
00176 case PE_ButtonBevel:
00177 case PE_ButtonCommand:
00178 drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
00179 (flags & (Style_Sunken|Style_On|Style_Down)),
00180 TRUE, !(flags & Style_Raised) );
00181 break;
00182 case PE_PanelMenuBar:
00183 drawMetalFrame( p, r.x(), r.y(), r.width(), r.height() );
00184 break;
00185 case PE_ScrollBarAddLine:
00186 drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
00187 flags & Style_Down, !( flags & Style_Horizontal ) );
00188 drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowRight :PE_ArrowDown,
00189 p, r, cg, flags, opt );
00190 break;
00191 case PE_ScrollBarSubLine:
00192 drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
00193 flags & Style_Down, !( flags & Style_Horizontal ) );
00194 drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp,
00195 p, r, cg, flags, opt );
00196 break;
00197
00198
00199 case PE_ScrollBarSlider:
00200 drawMetalButton( p, r.x(), r.y(), r.width(), r.height(), FALSE,
00201 flags & Style_Horizontal );
00202 break;
00203 default:
00204 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt );
00205 break;
00206 }
00207 }
00208
00209 void MetalStyle::drawControl( ControlElement element,
00210 QPainter *p,
00211 const QWidget *widget,
00212 const QRect &r,
00213 const QColorGroup &cg,
00214 SFlags how,
00215 const QStyleOption& opt ) const
00216 {
00217 switch( element ) {
00218 case CE_PushButton:
00219 {
00220 const QPushButton *btn;
00221 btn = (const QPushButton*)widget;
00222 int x1, y1, x2, y2;
00223
00224 r.coords( &x1, &y1, &x2, &y2 );
00225
00226 p->setPen( cg.foreground() );
00227 p->setBrush( QBrush(cg.button(), NoBrush) );
00228
00229
00230 QBrush fill;
00231 if ( btn->isDown() )
00232 fill = cg.brush( QColorGroup::Mid );
00233 else if ( btn->isOn() )
00234 fill = QBrush( cg.mid(), Dense4Pattern );
00235 else
00236 fill = cg.brush( QColorGroup::Button );
00237
00238 if ( btn->isDefault() ) {
00239 QPointArray a;
00240 a.setPoints( 9,
00241 x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
00242 x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
00243 p->setPen( Qt::black );
00244 p->drawPolyline( a );
00245 x1 += 2;
00246 y1 += 2;
00247 x2 -= 2;
00248 y2 -= 2;
00249 }
00250 SFlags flags = Style_Default;
00251 if ( btn->isOn() )
00252 flags |= Style_On;
00253 if ( btn->isDown() )
00254 flags |= Style_Down;
00255 if ( !btn->isFlat() && !btn->isDown() )
00256 flags |= Style_Raised;
00257 drawPrimitive( PE_ButtonCommand, p,
00258 QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1),
00259 cg, flags, opt );
00260
00261 if ( btn->isMenuButton() ) {
00262 flags = Style_Default;
00263 if ( btn->isEnabled() )
00264 flags |= Style_Enabled;
00265
00266 int dx = ( y1 - y2 - 4 ) / 3;
00267 drawPrimitive( PE_ArrowDown, p,
00268 QRect(x2 - dx, dx, y1, y2 - y1),
00269 cg, flags, opt );
00270 }
00271 if ( p->brush().style() != NoBrush )
00272 p->setBrush( NoBrush );
00273 break;
00274 }
00275 case CE_PushButtonLabel:
00276 {
00277 const QPushButton *btn;
00278 btn = (const QPushButton*)widget;
00279 int x, y, w, h;
00280 r.rect( &x, &y, &w, &h );
00281
00282 int x1, y1, x2, y2;
00283 r.coords( &x1, &y1, &x2, &y2 );
00284 int dx = 0;
00285 int dy = 0;
00286 if ( btn->isMenuButton() )
00287 dx = ( y2 - y1 ) / 3;
00288 if ( btn->isOn() || btn->isDown() ) {
00289 dx--;
00290 dy--;
00291 }
00292 if ( dx || dy )
00293 p->translate( dx, dy );
00294 x += 2;
00295 y += 2;
00296 w -= 4;
00297 h -= 4;
00298 drawItem( p, QRect( x, y, w, h ),
00299 AlignCenter|ShowPrefix,
00300 cg, btn->isEnabled(),
00301 btn->pixmap(), btn->text(), -1,
00302 (btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() );
00303 if ( dx || dy )
00304 p->translate( -dx, -dy );
00305 break;
00306 }
00307 default:
00308 QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
00309 break;
00310 }
00311 }
00312 void MetalStyle::drawComplexControl( ComplexControl cc,
00313 QPainter *p,
00314 const QWidget *widget,
00315 const QRect &r,
00316 const QColorGroup &cg,
00317 SFlags how,
00318 SCFlags sub,
00319 SCFlags subActive,
00320 const QStyleOption& opt ) const
00321 {
00322 switch ( cc ) {
00323 case CC_Slider:
00324 {
00325 const QSlider *slider = ( const QSlider* ) widget;
00326 QRect handle = querySubControlMetrics( CC_Slider, widget,
00327 SC_SliderHandle, opt);
00328 if ( sub & SC_SliderGroove )
00329 QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how,
00330 SC_SliderGroove, subActive, opt );
00331 if ( (sub & SC_SliderHandle) && handle.isValid() )
00332 drawMetalButton( p, handle.x(), handle.y(), handle.width(),
00333 handle.height(), FALSE,
00334 slider->orientation() == QSlider::Horizontal);
00335 break;
00336 }
00337 case CC_ComboBox:
00338 {
00339
00340 const QComboBox *cmb = ( const QComboBox* ) widget;
00341
00342 qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), cg, TRUE,
00343 cmb->isEnabled() ? &cg.brush( QColorGroup::Base ) :
00344 &cg.brush( QColorGroup::Background ) );
00345 drawMetalButton( p, r.x() + r.width() - 2 - 16, r.y() + 2, 16, r.height() - 4,
00346 how & Style_Sunken, TRUE );
00347 drawPrimitive( PE_ArrowDown, p,
00348 QRect( r.x() + r.width() - 2 - 16 + 2,
00349 r.y() + 2 + 2, 16 - 4, r.height() - 4 -4 ),
00350 cg,
00351 cmb->isEnabled() ? Style_Enabled : Style_Default,
00352 opt );
00353 break;
00354 }
00355 default:
00356 QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how, sub, subActive,
00357 opt );
00358 break;
00359 }
00360 }
00361
00362
00368 void MetalStyle::drawMetalButton( QPainter *p, int x, int y, int w, int h,
00369 bool sunken, bool horz, bool flat ) const
00370 {
00371
00372 drawMetalFrame( p, x, y, w, h );
00373 drawMetalGradient( p, x, y, w, h, sunken, horz, flat );
00374 }
00375
00376
00377
00378
00379 void MetalStyle::drawMetalFrame( QPainter *p, int x, int y, int w, int h ) const
00380 {
00381 QColor top1("#878769691515");
00382 QColor top2("#C6C6B4B44949");
00383
00384 QColor bot2("#70705B5B1414");
00385 QColor bot1("#56564A4A0E0E");
00386
00387
00388 int x2 = x + w - 1;
00389 int y2 = y + h - 1;
00390
00391
00392
00393 p->setPen( top1 );
00394 p->drawLine( x, y2, x, y );
00395 p->drawLine( x, y, x2-1, y );
00396 p->setPen( top2 );
00397 p->drawLine( x+1, y2 -1, x+1, y+1 );
00398 p->drawLine( x+1, y+1 , x2-2, y+1 );
00399
00400 p->setPen( bot1 );
00401 p->drawLine( x+1, y2, x2, y2 );
00402 p->drawLine( x2, y2, x2, y );
00403 p->setPen( bot2 );
00404 p->drawLine( x+1, y2-1, x2-1, y2-1 );
00405 p->drawLine( x2-1, y2-1, x2-1, y+1 );
00406
00407
00408 }
00409
00410
00411 void MetalStyle::drawMetalGradient( QPainter *p, int x, int y, int w, int h,
00412 bool sunken, bool horz, bool flat ) const
00413
00414 {
00415 QColor highlight("#E8E8DDDD6565");
00416 QColor subh1("#CECEBDBD5151");
00417 QColor subh2("#BFBFACAC4545");
00418
00419 QColor topgrad("#B9B9A5A54040");
00420 QColor botgrad("#89896C6C1A1A");
00421
00422
00423
00424 if ( flat && !sunken ) {
00425 p->fillRect( x + 2, y + 2, w - 4,h -4, topgrad );
00426 } else {
00427
00428 int i = 0;
00429 int x1 = x + 2;
00430 int y1 = y + 2;
00431 int x2 = x + w - 1;
00432 int y2 = y + h - 1;
00433 if ( horz )
00434 x2 = x2 - 2;
00435 else
00436 y2 = y2 - 2;
00437
00438 #define DRAWLINE if (horz) \
00439 p->drawLine( x1, y1+i, x2, y1+i ); \
00440 else \
00441 p->drawLine( x1+i, y1, x1+i, y2 ); \
00442 i++;
00443
00444 if ( !sunken ) {
00445 p->setPen( highlight );
00446 DRAWLINE;
00447 DRAWLINE;
00448 p->setPen( subh1 );
00449 DRAWLINE;
00450 p->setPen( subh2 );
00451 DRAWLINE;
00452 }
00453
00454 int ng = (horz ? h : w) - 8;
00455
00456 int h1, h2, s1, s2, v1, v2;
00457 if ( !sunken ) {
00458 topgrad.hsv( &h1, &s1, &v1 );
00459 botgrad.hsv( &h2, &s2, &v2 );
00460 } else {
00461 botgrad.hsv( &h1, &s1, &v1 );
00462 topgrad.hsv( &h2, &s2, &v2 );
00463 }
00464
00465 if ( ng > 1 ) {
00466 for ( int j =0; j < ng; j++ ) {
00467 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1),
00468 s1 + ((s2-s1)*j)/(ng-1),
00469 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
00470 DRAWLINE;
00471 }
00472 } else if ( ng == 1 ) {
00473 p->setPen( QColor((h1+h2)/2, (s1+s2)/2, (v1+v2)/2, QColor::Hsv) );
00474 DRAWLINE;
00475 }
00476 if ( sunken ) {
00477 p->setPen( subh2 );
00478 DRAWLINE;
00479
00480 p->setPen( subh1 );
00481 DRAWLINE;
00482
00483 p->setPen( highlight );
00484 DRAWLINE;
00485 DRAWLINE;
00486 }
00487 }
00488 }
00489
00490
00491
00492 int MetalStyle::pixelMetric( PixelMetric metric, const QWidget *w ) const
00493 {
00494 switch ( metric ) {
00495 case PM_MenuBarFrameWidth:
00496 return 2;
00497 default:
00498 return QWindowsStyle::pixelMetric( metric, w );
00499 }
00500 }
00501
00502 #endif
00503
00504
00505
00506
00507