?? qplatinumstyle.cpp
字號:
/****************************************************************************** $Id: qt/src/widgets/qplatinumstyle.cpp 2.3.12 edited 2005-10-27 $**** Implementation of Platinum-like style class**** Created : 981231**** Copyright (C) 1998-2000 Trolltech AS. All rights reserved.**** This file is part of the widgets module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qplatinumstyle.h"#ifndef QT_NO_STYLE_PLATINUM#include "qapplication.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>// NOT REVISED/*! \class QPlatinumStyle qplatinumstyle.h \brief Platinum Look and Feel \ingroup appearance This class implements the Platinum look and feel. It's an experimental class that tries to resemble a Macintosh-like GUI style with the QStyle system. The emulation is, however, far from being perfect yet.*//*! Constructs a QPlatinumStyle*/QPlatinumStyle::QPlatinumStyle(){ setButtonDefaultIndicatorWidth( 3 );}/*! Destructs the style.*/QPlatinumStyle::~QPlatinumStyle(){}/*! \reimp */void QPlatinumStyle::drawPopupPanel( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int lineWidth, const QBrush *fill ){ QWindowsStyle::drawPopupPanel( p, x, y, w, h, g, lineWidth, fill );}/*! Draws a press-sensitive shape.*/void QPlatinumStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ QPen oldPen = p->pen(); if (!sunken) { p->fillRect(x+3, y+3, w-6, h-6,fill ? *fill : g.brush( QColorGroup::Button )); // the bright side p->setPen(g.shadow()); p->drawLine(x, y, x+w-1, y); p->drawLine(x, y, x, y+h-1); p->setPen(g.button()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); p->setPen(g.light()); p->drawLine(x+2, y+2, x+2, y+h-2); p->drawLine(x+2, y+2, x+w-2, y+2); // the dark side! p->setPen(g.mid()); p->drawLine(x+3, y+h-3 ,x+w-3, y+h-3); p->drawLine(x+w-3, y+3, x+w-3, y+h-3); p->setPen(g.dark()); p->drawLine(x+2, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+2, x+w-2, y+h-2); p->setPen(g.shadow()); p->drawLine(x+1, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y, x+w-1, y+h-1); // top left corner: p->setPen(g.background()); p->drawPoint(x, y); p->drawPoint(x+1, y); p->drawPoint(x, y+1); p->setPen(g.shadow()); p->drawPoint(x+1, y+1); p->setPen(g.button()); p->drawPoint(x+2, y+2); p->setPen(white); p->drawPoint(x+3, y+3); // bottom left corner: p->setPen(g.background()); p->drawPoint(x, y+h-1); p->drawPoint(x+1, y+h-1); p->drawPoint(x, y+h-2); p->setPen(g.shadow()); p->drawPoint(x+1, y+h-2); p->setPen(g.dark()); p->drawPoint(x+2, y+h-3); // top right corner: p->setPen(g.background()); p->drawPoint(x+w-1, y); p->drawPoint(x+w-2, y); p->drawPoint(x+w-1, y+1); p->setPen(g.shadow()); p->drawPoint(x+w-2, y+1); p->setPen(g.dark()); p->drawPoint(x+w-3, y+2); // bottom right corner: p->setPen(g.background()); p->drawPoint(x+w-1, y+h-1); p->drawPoint(x+w-2, y+h-1); p->drawPoint(x+w-1, y+h-2); p->setPen(g.shadow()); p->drawPoint(x+w-2, y+h-2); p->setPen(g.dark()); p->drawPoint(x+w-3, y+h-3); p->setPen(g.mid()); p->drawPoint(x+w-4, y+h-4); } else { p->fillRect(x+2, y+2, w-4, h-4,fill ? *fill : g.brush( QColorGroup::Dark )); // the dark side p->setPen(g.shadow()); p->drawLine(x, y, x+w-1, y); p->drawLine(x, y, x, y+h-1); p->setPen(g.dark().dark()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); // the bright side! p->setPen(g.button()); p->drawLine(x+1, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+1, x+w-2, y+h-2); p->setPen(g.dark()); p->drawLine(x, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y, x+w-1, y+h-1); // top left corner: p->setPen(g.background()); p->drawPoint(x, y); p->drawPoint(x+1, y); p->drawPoint(x, y+1); p->setPen(g.shadow()); p->drawPoint(x+1, y+1); p->setPen(g.dark().dark()); p->drawPoint(x+3, y+3); // bottom left corner: p->setPen(g.background()); p->drawPoint(x, y+h-1); p->drawPoint(x+1, y+h-1); p->drawPoint(x, y+h-2); p->setPen(g.shadow()); p->drawPoint(x+1, y+h-2); // top right corner: p->setPen(g.background()); p->drawPoint(x+w-1, y); p->drawPoint(x+w-2, y); p->drawPoint(x+w-1, y+1); p->setPen(g.shadow()); p->drawPoint(x+w-2, y+1); // bottom right corner: p->setPen(g.background()); p->drawPoint(x+w-1, y+h-1); p->drawPoint(x+w-2, y+h-1); p->drawPoint(x+w-1, y+h-2); p->setPen(g.shadow()); p->drawPoint(x+w-2, y+h-2); p->setPen(g.dark()); p->drawPoint(x+w-3, y+h-3); p->setPen(g.mid()); p->drawPoint(x+w-4, y+h-4); } // // top left corner:// p->setPen(g.background());// p->drawPoint(x, y);// p->drawPoint(x, y); p->setPen(oldPen);}/*! \reimp */QRect QPlatinumStyle::buttonRect( int x, int y, int w, int h){ QRect r = QCommonStyle::buttonRect(x,y,w,h); r.setTop( r.top()+1); r.setLeft( r.left()+1); r.setBottom( r.bottom()-1); r.setRight( r.right()-1); return r;}/*! mixes two colors to a new colors */QColor QPlatinumStyle::mixedColor(const QColor &c1, const QColor &c2){ int h1,s1,v1,h2,s2,v2; c1.hsv(&h1,&s1,&v1); c2.hsv(&h2,&s2,&v2); return QColor( (h1+h2)/2, (s1+s2)/2, (v1+v2)/2, QColor::Hsv );}/*! \reimp */void QPlatinumStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ QPen oldPen = p->pen(); // small or non-square bevel buttons are drawn in a small style, others in a big style. if ( w * h < 1600 || QABS(w-h) > 10) { // small buttons if (!sunken) { p->fillRect(x+2, y+2, w-4, h-4,fill ? *fill : g.brush( QColorGroup::Button )); // the bright side p->setPen(g.dark()); p->drawLine(x, y, x+w-1, y); p->drawLine(x, y, x, y+h-1); p->setPen(g.light()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); // the dark side! p->setPen(g.mid()); p->drawLine(x+2, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+2, x+w-2, y+h-3); p->setPen(g.dark().dark()); p->drawLine(x+1, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y+1, x+w-1, y+h-2); } else { p->fillRect(x+2, y+2, w-4, h-4,fill ? *fill : g.brush( QColorGroup::Mid )); // the dark side p->setPen(g.dark().dark()); p->drawLine(x, y, x+w-1, y); p->drawLine(x, y, x, y+h-1); p->setPen(g.mid().dark()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); // the bright side! p->setPen(g.button()); p->drawLine(x+1, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+1, x+w-2, y+h-2); p->setPen(g.dark()); p->drawLine(x, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y, x+w-1, y+h-1); } } else { // big ones if (!sunken) { p->fillRect(x+3, y+3, w-6, h-6,fill ? * fill : g.brush( QColorGroup::Button )); // the bright side p->setPen(g.button().dark()); p->drawLine(x, y, x+w-1, y); p->drawLine(x, y, x, y+h-1); p->setPen(g.button()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); p->setPen(g.light()); p->drawLine(x+2, y+2, x+2, y+h-2); p->drawLine(x+2, y+2, x+w-2, y+2); // the dark side! p->setPen(g.mid()); p->drawLine(x+3, y+h-3 ,x+w-3, y+h-3); p->drawLine(x+w-3, y+3, x+w-3, y+h-3); p->setPen(g.dark()); p->drawLine(x+2, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+2, x+w-2, y+h-2); p->setPen(g.dark().dark()); p->drawLine(x+1, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y+1, x+w-1, y+h-1); } else { p->fillRect(x+3, y+3, w-6, h-6,fill ? *fill : g.brush( QColorGroup::Mid )); // the dark side p->setPen(g.dark().dark().dark()); p->drawLine(x, y, x+w-1, y); p->drawLine(x, y, x, y+h-1); p->setPen(g.dark().dark()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); p->setPen(g.mid().dark()); p->drawLine(x+2, y+2, x+2, y+w-2); p->drawLine(x+2, y+2, x+w-2, y+2); // the bright side! p->setPen(g.button()); p->drawLine(x+2, y+h-3 ,x+w-3, y+h-3); p->drawLine(x+w-3, y+3, x+w-3, y+h-3); p->setPen(g.midlight()); p->drawLine(x+1, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+1, x+w-2, y+h-2); p->setPen(g.dark()); p->drawLine(x, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y, x+w-1, y+h-1); // corners p->setPen( mixedColor(g.dark().dark().dark(), g.dark()) ); p->drawPoint( x, y+h-1 ); p->drawPoint( x+w-1, y); p->setPen( mixedColor(g.dark().dark(), g.midlight() ) ); p->drawPoint( x+1, y+h-2 ); p->drawPoint( x+w-2, y+1); p->setPen( mixedColor(g.mid().dark(), g.button() ) ); p->drawPoint( x+2, y+h-3 ); p->drawPoint( x+w-3, y+2); } } p->setPen(oldPen);}/*! \reimp */voidQPlatinumStyle::drawPushButton( QPushButton* btn, QPainter *p){ QColorGroup g = btn->colorGroup(); int x1, y1, x2, y2; bool useBevelButton; btn->rect().coords( &x1, &y1, &x2, &y2 ); // get coordinates p->setPen( g.foreground() ); p->setBrush( QBrush(g.button(),NoBrush) ); QBrush fill; if ( btn->isDown() ) fill = g.brush( QColorGroup::Dark ); else if ( btn->isOn() ) fill = QBrush( g.mid(), Dense4Pattern ); else fill = g.brush( QColorGroup::Button ); // small or square image buttons as well as toggle buttons are // bevel buttons (what a heuristic....) if ( btn->isToggleButton() || ( btn->pixmap() && (btn->width() * btn->height() < 1600 || QABS( btn->width() - btn->height()) < 10 )) ) useBevelButton = TRUE; else useBevelButton = FALSE; int diw = buttonDefaultIndicatorWidth(); if (btn->isDefault() ) { x1 += 1; y1 += 1; x2 -= 1; y2 -= 1; QColorGroup g2( g ); g2.setColor( QColorGroup::Button, g.mid() ); if( useBevelButton ) drawBevelButton( p, x1, y1, x2-x1+1, y2-y1+1, g, FALSE, &fill ); else drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g2, FALSE, &fill ); } if ( btn->isDefault() || btn->autoDefault() ) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) { if( useBevelButton) drawBevelButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn() || btn->isDown(), &fill ); else drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn() || btn->isDown(), &fill ); } if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush );}/*! \reimp */void QPlatinumStyle::drawPushButtonLabel( QPushButton* btn, QPainter *p){ bool on = btn->isDown() || btn->isOn(); QRect r = pushButtonContentsRect( btn ); int x, y, w, h; r.rect( &x, &y, &w, &h ); if ( btn->isMenuButton() ) { int dx = menuButtonIndicatorWidth( btn->height() ); QColorGroup g( btn->colorGroup() ); int xx = x+w-dx-4; int yy = y-3; int hh = h+6; if ( !on ) { p->setPen( g.mid() ); p->drawLine(xx, yy+2, xx, yy+hh-3); p->setPen( g.button() ); p->drawLine(xx+1, yy+1, xx+1, yy+hh-2); p->setPen( g.light() ); p->drawLine(xx+2, yy+2, xx+2, yy+hh-2); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -