?? qwindowsstyle.cpp
字號(hào):
/****************************************************************************** $Id: qt/src/widgets/qwindowsstyle.cpp 2.3.12 edited 2005-10-27 $**** Implementation of Windows-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 "qwindowsstyle.h"#ifndef QT_NO_STYLE_WINDOWS#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 "qtabbar.h"#define INCLUDE_MENUITEM_DEF#include "qpopupmenu.h"#include <limits.h>// NOT REVISED/*! \class QWindowsStyle qwindowsstyle.h \brief Windows Look and Feel \ingroup appearance This class implements the look and feel known from the Windows platform. Naturally it is also Qt's default GUI style on Windows.*/#if defined(_WS_WIN32_)extern Qt::WindowsVersion qt_winver;#endif/*! Constructs a QWindowsStyle*/QWindowsStyle::QWindowsStyle() : QCommonStyle(WindowsStyle){ setButtonDefaultIndicatorWidth( 1 );}/*! Destructs the style.*/QWindowsStyle::~QWindowsStyle(){}/*! \reimp */void QWindowsStyle::drawIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, int s, bool down, bool enabled ){#ifndef QT_NO_BUTTON QBrush fill; if ( s == QButton::NoChange ) { QBrush b = p->brush(); QColor c = p->backgroundColor(); p->setBackgroundMode( TransparentMode ); p->setBackgroundColor( green ); fill = QBrush(g.base(), Dense4Pattern); p->setBackgroundColor( c ); p->setBrush( b ); } else if ( down ) fill = g.brush( QColorGroup::Button ); else fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background ); qDrawWinPanel( p, x, y, w, h, g, TRUE, &fill ); if ( s != QButton::Off ) { QPointArray a( 7*2 ); int i, xx, yy; xx = x+3; yy = y+5; for ( i=0; i<3; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy++; } yy -= 2; for ( i=3; i<7; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy--; } if ( s == QButton::NoChange ) { p->setPen( g.dark() ); } else { p->setPen( g.text() ); } p->drawLineSegments( a ); }#endif}/*! \reimp */void QWindowsStyle::drawFocusRect( QPainter* p, const QRect& r, const QColorGroup &, const QColor* bg, bool){ if (!bg) p->drawWinFocusRect( r ); else p->drawWinFocusRect( r, *bg );}/*! This function draws a rectangle with two pixel line width. It is called from qDrawWinButton() and qDrawWinPanel(). c1..c4 and fill are used: 1 1 1 1 1 2 1 3 3 3 4 2 1 3 F F 4 2 1 3 F F 4 2 1 4 4 4 4 2 2 2 2 2 2 2*/void QWindowsStyle::drawWinShades( QPainter *p, int x, int y, int w, int h, const QColor &c1, const QColor &c2, const QColor &c3, const QColor &c4, const QBrush *fill ){ if ( w < 2 || h < 2 ) // nothing to draw return; QPen oldPen = p->pen(); QPointArray a( 3 ); a.setPoint( 0, x, y+h-2 ); a.setPoint( 1, x, y ); a.setPoint( 2, x+w-2, y ); p->setPen( c1 ); p->drawPolyline( a ); a.setPoint( 0, x, y+h-1 ); a.setPoint( 1, x+w-1, y+h-1 ); a.setPoint( 2, x+w-1, y ); p->setPen( c2 ); p->drawPolyline( a ); if ( w > 4 && h > 4 ) { a.setPoint( 0, x+1, y+h-3 ); a.setPoint( 1, x+1, y+1 ); a.setPoint( 2, x+w-3, y+1 ); p->setPen( c3 ); p->drawPolyline( a ); a.setPoint( 0, x+1, y+h-2 ); a.setPoint( 1, x+w-2, y+h-2 ); a.setPoint( 2, x+w-2, y+1 ); p->setPen( c4 ); p->drawPolyline( a ); if ( fill ) { QBrush oldBrush = p->brush(); p->setBrush( *fill ); p->setPen( NoPen ); p->drawRect( x+2, y+2, w-4, h-4 ); p->setBrush( oldBrush ); } } p->setPen( oldPen );}/*! \reimp */voidQWindowsStyle::drawPanel( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, int lineWidth, const QBrush* fill){ if ( lineWidth == 2 ) { if (sunken) drawWinShades( p, x, y, w, h, g.dark(), g.light(), g.shadow(), g.midlight(), fill ); else drawWinShades( p, x, y, w, h, g.light(), g.shadow(), g.midlight(), g.dark(), fill ); } else QStyle::drawPanel( p, x, y, w, h, g, sunken, lineWidth, fill );}/*! \reimp */voidQWindowsStyle::drawPopupPanel( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int /* lineWidth */, const QBrush *fill ){ qDrawWinPanel( p, x, y, w, h, g, FALSE, fill );}/*! \reimp */voidQWindowsStyle::drawArrow( QPainter *p, ArrowType type, bool down, int x, int y, int w, int h, const QColorGroup &g, bool enabled, const QBrush *fill ){ QPointArray a; // arrow polygon switch ( type ) { case UpArrow: a.setPoints( 7, -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2 ); break; case DownArrow: a.setPoints( 7, -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1 ); break; case LeftArrow: a.setPoints( 7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0 ); break; case RightArrow: a.setPoints( 7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0 ); break; } if ( a.isNull() ) return; if ( down ) { x++; y++; } QPen savePen = p->pen(); // save current pen if (down) p->setBrushOrigin(p->brushOrigin() + QPoint(1,1)); if ( fill ) p->fillRect( x, y, w, h, *fill ); if (down) p->setBrushOrigin(p->brushOrigin() - QPoint(1,1)); if ( enabled ) { a.translate( x+w/2, y+h/2 ); p->setPen( g.buttonText() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } else { a.translate( x+w/2+1, y+h/2+1 ); p->setPen( g.light() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); a.translate( -1, -1 ); p->setPen( g.mid() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } p->setPen( savePen ); // restore pen}/*! \reimp */QSizeQWindowsStyle::indicatorSize() const{ return QSize(13,13);}#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)/*! \reimp */void QWindowsStyle::drawExclusiveIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, bool on, bool down, bool enabled ){ static const QCOORD pts1[] = { // dark lines 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; static const QCOORD pts2[] = { // black lines 2,8, 1,7, 1,4, 2,3, 2,2, 3,2, 4,1, 7,1, 8,2, 9,2 }; static const QCOORD pts3[] = { // background lines 2,9, 3,9, 4,10, 7,10, 8,9, 9,9, 9,8, 10,7, 10,4, 9,3 }; static const QCOORD pts4[] = { // white lines 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 11,4, 10,3, 10,2 }; static const QCOORD pts5[] = { // inner fill 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; p->eraseRect( x, y, w, h ); QPointArray a( QCOORDARRLEN(pts1), pts1 ); a.translate( x, y ); p->setPen( g.dark() ); p->drawPolyline( a ); a.setPoints( QCOORDARRLEN(pts2), pts2 ); a.translate( x, y ); p->setPen( g.shadow() ); p->drawPolyline( a ); a.setPoints( QCOORDARRLEN(pts3), pts3 ); a.translate( x, y ); p->setPen( g.midlight() ); p->drawPolyline( a ); a.setPoints( QCOORDARRLEN(pts4), pts4 ); a.translate( x, y ); p->setPen( g.light() ); p->drawPolyline( a ); a.setPoints( QCOORDARRLEN(pts5), pts5 ); a.translate( x, y ); QColor fillColor = ( down || !enabled ) ? g.button() : g.base(); p->setPen( fillColor ); p->setBrush( fillColor ) ; p->drawPolygon( a ); if ( on ) { p->setPen( NoPen ); p->setBrush( g.text() ); p->drawRect( x+5, y+4, 2, 4 ); p->drawRect( x+4, y+5, 4, 2 ); }}/*! Draws the mask of a mark indicating the state of an exclusive choice*/voidQWindowsStyle::drawExclusiveIndicatorMask( QPainter *p, int x, int y, int w, int h, bool /* on */){ QColorGroup g(color1, color1, color1, color1, color1, color1, color1, color1, color0); drawExclusiveIndicator(p , x, y, w, h, g, FALSE, FALSE, FALSE );}/*!\reimp */QSizeQWindowsStyle::exclusiveIndicatorSize() const{ return QSize(12,12);}/*! Draws a press-sensitive shape.*/void QWindowsStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ if (sunken) drawWinShades( p, x, y, w, h, g.shadow(), g.light(), g.dark(), g.button(), fill?fill: &g.brush( QColorGroup::Button ) ); else drawWinShades( p, x, y, w, h, g.light(), g.shadow(), g.button(), g.dark(), fill?fill:&g.brush( QColorGroup::Button ) );}/*!\reimp */void QWindowsStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ QWindowsStyle::drawButton(p, x, y, w, h, g, sunken, fill);}/*!\reimp */voidQWindowsStyle::drawPushButton( QPushButton* btn, QPainter *p){#ifndef QT_NO_PUSHBUTTON 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) ); int diw = buttonDefaultIndicatorWidth(); if ( btn->isDefault() || btn->autoDefault() ) { if ( btn->isDefault() ) { p->setPen( g.shadow() ); p->drawRect( x1, y1, x2-x1+1, y2-y1+1 ); } x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } bool clearButton = TRUE; if ( btn->isDown() ) { if ( btn->isDefault() ) { p->setPen( g.dark() ); p->drawRect( x1, y1, x2-x1+1, y2-y1+1 ); } else { drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE, &g.brush( QColorGroup::Button ) ); } } else { if ( btn->isToggleButton() && btn->isOn() && btn->isEnabled() ) { QBrush fill(g.light(), Dense4Pattern ); drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE, &fill ); clearButton = FALSE; } else { if ( !btn->isFlat() ) drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn(), &g.brush( QColorGroup::Button ) ); } } if ( clearButton ) { if (btn->isDown())
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -