1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
|
/****************************************************************************
** $Id: attalStyle.cpp,v 1.2 2003/09/27 11:25:50 audoux Exp $
**
** Copyright (C) 1992-2000 Troll Tech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "attalStyle.h"
// generic include files
// include files for QT
#include <qapplication.h>
#include <qtextstream.h>
#include <qpainter.h>
#include <qdrawutil.h> // for now
#include <qpixmap.h> // for now
#include <qpalette.h> // for now
#include <qwidget.h>
#include <qlabel.h>
#include <qimage.h>
#include <qpushbutton.h>
#include <qwidget.h>
#include <qrangecontrol.h>
#include <qscrollbar.h>
#include <limits.h>
#include <qcolor.h>
#include <qfile.h>
// application specific include
#include "conf.h"
#include "libCommon/log.h"
extern QString IMAGE_PATH;
AttalStyle::AttalStyle( QString colorFile, int sbext ) : QWindowsStyle()
{
init( colorFile );
if ( sbext >= 0 ) {
// XXX: obsolete in qt 3...
//scrollBarExtent( sbext );
}
}
bool AttalStyle::init( QString colorFile )
{
QFile f( colorFile );
if (! f.open(IO_ReadOnly) ) {
logEE("Could not open file %s for reading\n", colorFile.latin1() );
return false;
}
QTextStream ts( &f );
while( ! ts.eof() ) {
int colR, colG, colB;
ts >> colR;
ts >> colG;
ts >> colB;
_textColor.setRgb( colR, colG, colB );
ts >> colR;
ts >> colG;
ts >> colB;
_borderColor.setRgb( colR, colG, colB );
}
f.close();
return true;
}
/*!
Reimplementation from QStyle
\sa QStyle
*/
void AttalStyle::polish( QApplication *app)
{
oldPalette = app->palette();
// we simply create a nice QColorGroup with a couple of fancy wood
// pixmaps here and apply to it all widgets
QImage img( IMAGE_PATH + "misc/background.png" );
QImage orig = img;
orig.detach();
QPixmap button;
button.convertFromImage(img);
int i;
for (i=0; i<img.numColors(); i++) {
QRgb rgb = img.color(i);
QColor c(rgb);
rgb = c.dark(120).rgb();
img.setColor(i,rgb);
}
QPixmap mid;
mid.convertFromImage(img);
img = orig;
img.detach();
for (i=0; i<img.numColors(); i++) {
QRgb rgb = img.color(i);
QColor c(rgb);
rgb = c.light(180).rgb();
img.setColor(i,rgb);
}
QPixmap light;
light.convertFromImage(img);
img = orig;
img.detach();
for (i=0; i<img.numColors(); i++) {
QRgb rgb = img.color(i);
QColor c(rgb);
rgb = c.dark(180).rgb();
img.setColor(i,rgb);
}
QPixmap dark;
dark.convertFromImage(img);
QImage bgimage( IMAGE_PATH + "misc/background.png" );
QPixmap background;
background.convertFromImage(bgimage);
img = bgimage;
img.detach();
for (i=0; i<img.numColors(); i++) {
QRgb rgb = img.color(i);
QColor c(rgb);
rgb = c.dark(180).rgb();
img.setColor(i,rgb);
}
sunkenDark = new QPixmap;
sunkenDark->convertFromImage(img);
img = bgimage;
img.detach();
for (i=0; i<img.numColors(); i++) {
QRgb rgb = img.color(i);
QColor c(rgb);
rgb = c.light(130).rgb();
img.setColor(i,rgb);
}
sunkenLight= new QPixmap;
sunkenLight->convertFromImage(img);
QPalette op(QColor(212,140,95));
QColorGroup active;
active.setBrush( QColorGroup::Foreground , op.normal().foreground() );
active.setBrush( QColorGroup::Button , QBrush(op.normal().button(), button) );
active.setBrush( QColorGroup::Background , QBrush(op.normal().background(), background) );
active.setBrush( QColorGroup::Light , QBrush(op.normal().light(), light) );
active.setBrush( QColorGroup::Mid , QBrush(op.normal().mid(), mid) );
active.setBrush( QColorGroup::Dark , QBrush(op.normal().dark(), dark) );
active.setColor( QColorGroup::Base , QColor(212,140,95) );
active.setColor( QColorGroup::Text , white );
active.setColor( QColorGroup::BrightText , white );
active.setColor( QColorGroup::Foreground , _borderColor );
active.setColor( QColorGroup::Highlight , black );
active.setColor( QColorGroup::HighlightedText , white );
active.setColor( QColorGroup::ButtonText , _textColor );
app->setPalette(QPalette(active, active , active), TRUE );
}
void AttalStyle::unPolish( QApplication *app)
{
app->setPalette(oldPalette, TRUE);
}
/*!
Reimplementation from QStyle
\sa QStyle
*/
void AttalStyle::polish( QWidget* w)
{
// the polish function sets some widgets to transparent mode and
// some to translate background mode in order to get the full
// benefit from the nice pixmaps in the color group.
if (w->inherits("QTipLabel") || w->inherits("QLCDNumber") ){
return;
}
if ( !w->isTopLevel() ) {
if ( w->inherits("QPushButton")
|| w->inherits("QToolButton")
|| w->inherits("QGroupBox")
|| w->inherits("QTabWidget")
|| w->inherits("QComboBox") ) {
w->setAutoMask( TRUE );
return;
}
if (w->inherits("QLabel")
|| w->inherits("QButton") ) {
w->setBackgroundOrigin( QWidget::ParentOrigin );
}
}
}
void AttalStyle::unPolish( QWidget* w)
{
// the polish function sets some widgets to transparent mode and
// some to translate background mode in order to get the full
// benefit from the nice pixmaps in the color group.
if (w->inherits("QTipLabel") || w->inherits("QLCDNumber") ){
return;
}
if ( !w->isTopLevel() ) {
if ( w->inherits("QPushButton")
|| w->inherits("QToolButton")
|| w->inherits("QGroupBox")
|| w->inherits("QTabWidget")
|| w->inherits("QComboBox") ) {
w->setAutoMask( FALSE );
return;
}
if (w->inherits("QLabel")
|| w->inherits("QButton") ) {
w->setBackgroundOrigin( QWidget::WidgetOrigin );
}
}
}
void AttalStyle::drawPanel( QPainter * p, int x, int y, int w, int h,
const QColorGroup & ,
bool ,
int ,
const QBrush * )
{
p->fillRect( x,y,w,h, _textColor );
}
/*
void AttalStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb,
int sliderStart, uint controls,
uint activeControl )
{
QWindowsStyle::drawScrollBarControls( p, sb, sliderStart, controls & ~(AddLine|SubLine),
activeControl & ~(AddLine|SubLine) );
bool horz = sb->orientation() == QScrollBar::Horizontal;
int b = 2;
int w = horz ? sb->height() : sb->width();
QColorGroup g = sb->colorGroup();
if ( controls & AddLine ) {
bool sunken = activeControl & AddLine;
QRect r( b, b, w-2*b, w-2*b ) ;
if ( horz ) {
r.moveBy( sb->width() - w, 0 );
drawSemicircleButton( p, r, PointRight, sunken, g );
} else {
r.moveBy( 0, sb->height() - w );
drawSemicircleButton( p, r, PointDown, sunken, g );
}
}
if ( controls & SubLine ) {
bool sunken = activeControl & SubLine;
QRect r( b, b, w-2*b, w-2*b ) ;
if ( horz ) {
drawSemicircleButton( p, r, PointLeft, sunken, g );
} else {
drawSemicircleButton( p, r, PointUp, sunken, g );
}
}
}
*/
static inline int buttonthickness( int d )
{ return d > 20 ? 5 : ( d < 10 ? 2: 3 ); }
void AttalStyle::drawButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool /*sunken*/, const QBrush* fill)
{
int d = QMIN(w,h)/2;
int b = buttonthickness( d );
QRegion internR = QRect(x+b, y+b, w-2*b, h-2*b);
// qDrawShadePanel( p, x, y, w, h, g, sunken, 5);
QPen oldPen = p->pen();
QBrush brush( fill ? *fill : g.brush( QColorGroup::Button ));
p->setClipRegion( internR );
p->fillRect( x, y, w, h, brush );
int e = QMIN( w, h )/2;
QPoint p2(x+w-1-e,y+e);
QPoint p3(x+e, y+h-1-e);
QPointArray a;
a.setPoints( 5, x,y, x+w-1, y, p2.x(),p2.y(), p3.x(),p3.y(), x, y+h-1 );
p->setClipRegion( QRegion( a )- internR );
p->fillRect( x,y,w,h, g.brush( QColorGroup::Light ) );
a.setPoint( 0, x+w-1, y+w-1 );
p->setClipRegion( QRegion( a ) - internR );
p->fillRect( x,y,w,h, g.brush( QColorGroup::Dark ));
p->setClipRegion( internR );
p->setClipping( FALSE );
p->setPen( g.foreground() );
p->drawRect( x, y, w, h );
p->setPen( oldPen );
}
void AttalStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup & /*g*/, bool, const QBrush* /*fill*/)
{
p->fillRect( x,y, w,h, red );
}
void AttalStyle::drawPushButton( QPushButton* btn, QPainter *p)
{
QColorGroup g = btn->colorGroup();
int x1, y1, x2, y2;
btn->rect().coords( &x1, &y1, &x2, &y2 ); // get coordinates
p->setPen( g.foreground() );
p->setBrush( QBrush(g.button(),NoBrush) );
QBrush fill;
fill = g.brush( QColorGroup::Button );
if( ! btn->isDown() )
drawButton( p, x1, y1, x2-x1-1, y2-y1-1, g, btn->isOn() || btn->isDown(), &fill);
else
drawButton( p, x1+1, y1+1, x2-x1-1, y2-y1-1, g, btn->isOn() || btn->isDown(), &fill);
if ( btn->isDefault() ) {
QPen pen( _textColor, 4 , SolidLine);
pen.setCapStyle( Qt::SquareCap );
pen.setJoinStyle( Qt::MiterJoin );
p->setPen( pen );
p->drawRect( x1-1, y1-1, x2-x1+3, y2-y1+3 );
}
if ( btn->isMenuButton() ) {
int dx = (y1-y2-4)/3;
#if QT_VERSION >= 300
QRect rec = QRect( x2 - dx, dx, y1, y2 - y1 );
drawPrimitive( PE_ArrowDown, p, rec, g );
#else
drawArrow( p, DownArrow, FALSE,
x2 - dx, dx, y1, y2 - y1,
g, btn->isEnabled() );
#endif
}
if ( p->brush().style() != NoBrush )
p->setBrush( NoBrush );
}
void AttalStyle::drawPushButtonLabel( QPushButton* btn, QPainter *p)
{
QRect r = pushButtonContentsRect( btn );
int x,y, w,h;
r.rect( &x, &y, &w, &h );
if( btn->isDown() ) {
x += 1;
y += 1;
}
#if QT_VERSION >= 300
drawItem( p, r /*x, y, w, h,*/,
AlignCenter|ShowPrefix,
btn->colorGroup(), btn->isEnabled(),
btn->pixmap(), btn->text(), -1,
&btn->colorGroup().buttonText());
#else
drawItem( p, x, y, w, h,
AlignCenter|ShowPrefix,
btn->colorGroup(), btn->isEnabled(),
btn->pixmap(), btn->text(), -1,
&btn->colorGroup().buttonText());
#endif
}
QRect AttalStyle::pushButtonContentsRect( QPushButton *btn )
{
QRect r = btn->rect();
int x,y, w,h;
r.rect( &x, &y, &w, &h );
return QRect( x,y, w-2,h-2 );
}
|