00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "polished.h"
00022 #include <qpainter.h>
00023 #include <qapplication.h>
00024
00025 PolishedDecoration::PolishedDecoration()
00026 {
00027 }
00028
00029 PolishedDecoration::~PolishedDecoration()
00030 {
00031 }
00032
00033 int PolishedDecoration::metric( Metric m, const WindowData *wd ) const
00034 {
00035 switch ( m ) {
00036 case TopBorder:
00037 return 1;
00038 break;
00039 case LeftBorder:
00040 case RightBorder:
00041 return 2;
00042 case BottomBorder:
00043 return 6;
00044 case TitleHeight:
00045 if ( QApplication::desktop()->height() > 320 )
00046 return 20;
00047 else
00048 return 18;
00049 default:
00050 return WindowDecorationInterface::metric( m, wd );
00051 break;
00052 }
00053
00054 return 0;
00055 }
00056
00057 void PolishedDecoration::drawArea( Area a, QPainter *p, const WindowData *wd ) const
00058 {
00059 int th = metric( TitleHeight, wd );
00060 QRect r = wd->rect;
00061
00062 switch ( a ) {
00063 case Border:
00064 {
00065 const QColorGroup &cg = wd->palette.active();
00066 QColor c;
00067 if ( wd->flags & WindowData::Active ) {
00068 c = cg.color(QColorGroup::Highlight);
00069 } else {
00070 c = cg.color(QColorGroup::Background);
00071 }
00072 drawBlend( p, QRect(r.x(),r.bottom()+1,r.width(),metric(BottomBorder,wd)), c.dark(180), c.light() );
00073 int lb = metric(LeftBorder,wd);
00074 int rb = metric(RightBorder,wd);
00075 int tb = metric(TopBorder,wd);
00076 int bb = metric(BottomBorder,wd);
00077 p->fillRect( r.x()-lb, r.y()-th-tb, lb,
00078 r.height()+th+tb+bb, c.dark(180) );
00079 p->fillRect( r.right()+1, r.y()-th-tb, rb,
00080 r.height()+th+tb+bb, c.dark(180) );
00081 p->fillRect( r.left(), r.y()-th-tb, r.width(),
00082 tb, c.dark(180) );
00083 }
00084 break;
00085 case Title:
00086 if ( r.height() < 2 ) {
00087 WindowDecorationInterface::drawArea( a, p, wd );
00088 } else {
00089 const QColorGroup &cg = wd->palette.active();
00090 QColor c1, c2;
00091 if ( wd->flags & WindowData::Active ) {
00092 c1 = cg.color(QColorGroup::Highlight).light();
00093 c2 = cg.color(QColorGroup::Highlight).dark(180);
00094 } else {
00095 c1 = cg.color(QColorGroup::Background);
00096 c2 = cg.color(QColorGroup::Background).dark(180);
00097 }
00098 drawBlend( p, QRect(r.x(),r.y()-th,r.width(),th), c2, c1 );
00099 }
00100 break;
00101 case TitleText:
00102 p->drawText( r.left()+5+metric(HelpWidth,wd), r.top()-th, r.width(), th,
00103 Qt::AlignVCenter, wd->caption );
00104 break;
00105 default:
00106 PolishedDecoration::drawArea( a, p, wd );
00107 break;
00108 }
00109 }
00110
00111 void PolishedDecoration::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int w, int h, QWSButton::State state ) const
00112 {
00113 WindowDecorationInterface::drawButton( b, p, wd, x, y, w, h, state );
00114 }
00115
00116 QRegion PolishedDecoration::mask( const WindowData *wd ) const
00117 {
00118 return WindowDecorationInterface::mask( wd );
00119 }
00120
00121 QString PolishedDecoration::name() const
00122 {
00123 return qApp->translate( "Decoration", "Polished" );
00124 }
00125
00126 QPixmap PolishedDecoration::icon() const
00127 {
00128 return QPixmap();
00129 }
00130
00131 void PolishedDecoration::drawBlend( QPainter *p, const QRect &r, const QColor &c1, const QColor &c2 ) const
00132 {
00133 int h1, h2, s1, s2, v1, v2;
00134 c1.hsv( &h1, &s1, &v1 );
00135 c2.hsv( &h2, &s2, &v2 );
00136
00137 int split = r.height()/3;
00138
00139 for ( int j = 0; j < split; j++ ) {
00140 p->setPen( QColor( h1 + ((h2-h1)*(j+split))/(2*split-1),
00141 s1 + ((s2-s1)*(j+split))/(2*split-1),
00142 v1 + ((v2-v1)*(j+split))/(2*split-1), QColor::Hsv ) );
00143 p->drawLine( r.x(), r.y()+j, r.right(), r.y()+j );
00144 }
00145
00146 for ( int j = 0; j < r.height()-split; j++ ) {
00147 p->setPen( QColor( h1 + ((h2-h1)*j)/(r.height()-split-1),
00148 s1 + ((s2-s1)*j)/(r.height()-split-1),
00149 v1 + ((v2-v1)*j)/(r.height()-split-1), QColor::Hsv ) );
00150 p->drawLine( r.x(), r.bottom()-j, r.right(), r.bottom()-j );
00151 }
00152 }
00153
00154 QRESULT PolishedDecoration::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00155 {
00156 *iface = 0;
00157 if ( uuid == IID_QUnknown )
00158 *iface = this;
00159 else if ( uuid == IID_WindowDecoration )
00160 *iface = this;
00161 else
00162 return QS_FALSE;
00163
00164 if ( *iface )
00165 (*iface)->addRef();
00166 return QS_OK;
00167 }
00168
00169 Q_EXPORT_INTERFACE()
00170 {
00171 Q_CREATE_INSTANCE( PolishedDecoration )
00172 }
00173