📄 qmotifstyle.cpp
字号:
/****************************************************************************** $Id: qt/src/widgets/qmotifstyle.cpp 2.3.12 edited 2005-10-27 $**** Implementation of Motif-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 "qmotifstyle.h"#ifndef QT_NO_STYLE_MOTIF#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 QMotifStyle qmotifstyle.h \brief Motif Look and Feel \ingroup appearance This class implements the Motif look and feel. It almost completely resembles the original Motif look as defined by the Open Group, but also contains minor improvements. The Motif style is Qt's default GUI style on UNIX platforms.*//*! Constructs a QMotifStyle. If useHighlightCols is FALSE (default value), then the style will polish the application's color palette to emulate the Motif way of highlighting, which is a simple inversion between the base and the text color.*/QMotifStyle::QMotifStyle( bool useHighlightCols ) : QCommonStyle(MotifStyle){ highlightCols = useHighlightCols;#define Q_NICE_MOTIF_DEFAULT_BUTTON#ifdef Q_NICE_MOTIF_DEFAULT_BUTTON setButtonDefaultIndicatorWidth( 3 );#endif#define Q_NICE_MOTIF_SLIDER_THICKNESS#ifdef Q_NICE_MOTIF_SLIDER_THICKNESS setSliderThickness(24);#endif}/*! Destructs the style.*/QMotifStyle::~QMotifStyle(){}/*! If the argument is FALSE, then the style will polish the application's color palette to emulate the Motif way of highlighting, which is a simple inversion between the base and the text color. The effect will show up the next time a application palette is set via QApplication::setPalette(). The current color palette of the application remains unchanged. \sa QStyle::polish( QPalette& ) */void QMotifStyle::setUseHighlightColors( bool arg){ highlightCols = arg;}/*! Returns whether the style treats the highlight colors of the palette Motif-like, which is a simple inversion between the base and the text color. The default is FALSE. */bool QMotifStyle::useHighlightColors() const{ return highlightCols;}/*! \reimp */void QMotifStyle::polish( QPalette& pal){ if ( pal.normal().light() == pal.normal().base() ) { QColor nlight = pal.normal().light().dark(108 ); pal.setColor( QPalette::Active, QColorGroup::Light, nlight ) ; pal.setColor( QPalette::Disabled, QColorGroup::Light, nlight ) ; pal.setColor( QPalette::Inactive, QColorGroup::Light, nlight ) ; } if ( highlightCols ) return; // force the ugly motif way of highlighting *sigh* QColorGroup normal = pal.normal(); QColorGroup disabled = pal.disabled(); QColorGroup active = pal.active(); pal.setColor( QPalette::Active, QColorGroup::Highlight, normal.text() ); pal.setColor( QPalette::Active, QColorGroup::HighlightedText, normal.base()); pal.setColor( QPalette::Disabled, QColorGroup::Highlight, disabled.text() ); pal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, disabled.base() ); pal.setColor( QPalette::Inactive, QColorGroup::Highlight, active.text() ); pal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, active.base() );}/*! \reimp \internal Keep QStyle::polish() visible.*/void QMotifStyle::polish( QWidget* w ){ QStyle::polish(w);}/*! \reimp \internal Keep QStyle::polish() visible.*/void QMotifStyle::polish( QApplication* a ){ QStyle::polish(a);}/*! \reimp */void QMotifStyle::drawIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, int s, bool down, bool /*enabled*/ ){ bool on = s != QButton::Off; bool showUp = !(down ^ on); QBrush fill = showUp || s == QButton::NoChange ? g.brush( QColorGroup::Button ) : g.brush( QColorGroup::Mid ); if ( s == QButton::NoChange ) { qDrawPlainRect( p, x, y, w, h, g.text(), 1, &fill ); p->drawLine(x+w-1,y,x,y+h-1); } else qDrawShadePanel( p, x, y, w, h, g, !showUp, defaultFrameWidth(), &fill );}/*! \reimp */QSizeQMotifStyle::indicatorSize() const{ return QSize(13,13);}#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)/*! \reimp */void QMotifStyle::drawExclusiveIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, bool on, bool down, bool /* enabled */ ){ QCOORD inner_pts[] = { 2,h/2, w/2,2, w-3,h/2, w/2,h-3 }; QCOORD top_pts[] = { 0,h/2, w/2,0 , w-2,h/2-1, w-3,h/2-1, w/2,1, 1,h/2, 2,h/2, w/2,2, w-4,h/2-1 }; QCOORD bottom_pts[] = { 1,h/2+1, w/2,h-1, w-1,h/2, w-2,h/2, w/2,h-2, 2,h/2+1, 3,h/2+1, w/2,h-3, w-3,h/2 }; bool showUp = !(down ^ on ); QPointArray a( QCOORDARRLEN(inner_pts), inner_pts ); p->eraseRect( x, y, w, h ); p->setPen( NoPen ); p->setBrush( showUp ? g.brush( QColorGroup::Button ) : g.brush( QColorGroup::Mid ) ) ; a.translate( x, y ); p->drawPolygon( a ); // clear inner area p->setPen( showUp ? g.light() : g.dark() ); p->setBrush( NoBrush ); a.setPoints( QCOORDARRLEN(top_pts), top_pts ); a.translate( x, y ); p->drawPolyline( a ); // draw top part p->setPen( showUp ? g.dark() : g.light() ); a.setPoints( QCOORDARRLEN(bottom_pts), bottom_pts ); a.translate( x, y ); p->drawPolyline( a ); // draw bottom part}/*! Draws the mask of a mark indicating the state of an exclusive choice*/voidQMotifStyle::drawExclusiveIndicatorMask( QPainter *p, int x, int y, int w, int h, bool /* on */){ p->setBrush( Qt::color1 ); p->setPen( Qt::color1 ); QPointArray a; a.setPoints( 4, 0,h/2, h/2,0, w-2,h/2, w/2,h-1 ); a.translate(x,y); p->drawPolygon( a );}/*! \reimp */QSizeQMotifStyle::exclusiveIndicatorSize() const{ return QSize(13,13);}/*! \reimp */voidQMotifStyle::drawArrow( QPainter *p, ArrowType type, bool down, int x, int y, int w, int h, const QColorGroup &g, bool enabled, const QBrush * /* fill */ ){ // ### may be worth caching these as pixmaps, especially with the // cost of rotate() for vertical arrows. QPointArray bFill; // fill polygon QPointArray bTop; // top shadow. QPointArray bBot; // bottom shadow. QPointArray bLeft; // left shadow. QWMatrix matrix; // xform matrix bool vertical = type == UpArrow || type == DownArrow; bool horizontal = !vertical; int dim = w < h ? w : h; int colspec = 0x0000; // color specification array if ( dim < 2 ) // too small arrow return; // adjust size and center (to fix rotation below) if ( w > dim ) { x += (w-dim)/2; w = dim; } if ( h > dim ) { y += (h-dim)/2; h = dim; } if ( dim > 3 ) { if ( dim > 6 ) bFill.resize( dim & 1 ? 3 : 4 ); bTop.resize( (dim/2)*2 ); bBot.resize( dim & 1 ? dim + 1 : dim ); bLeft.resize( dim > 4 ? 4 : 2 ); bLeft.putPoints( 0, 2, 0,0, 0,dim-1 ); if ( dim > 4 ) bLeft.putPoints( 2, 2, 1,2, 1,dim-3 ); bTop.putPoints( 0, 4, 1,0, 1,1, 2,1, 3,1 ); bBot.putPoints( 0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2 ); for( int i=0; i<dim/2-2 ; i++ ) { bTop.putPoints( i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i ); bBot.putPoints( i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i ); } if ( dim & 1 ) // odd number size: extra line bBot.putPoints( dim-1, 2, dim-3,dim/2, dim-1,dim/2 ); if ( dim > 6 ) { // dim>6: must fill interior bFill.putPoints( 0, 2, 1,dim-3, 1,2 ); if ( dim & 1 ) // if size is an odd number bFill.setPoint( 2, dim - 3, dim / 2 ); else bFill.putPoints( 2, 2, dim-4,dim/2-1, dim-4,dim/2 ); } } else { if ( dim == 3 ) { // 3x3 arrow pattern bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 ); bTop .setPoints( 2, 1,0, 1,0 ); bBot .setPoints( 2, 1,2, 2,1 ); } else { // 2x2 arrow pattern bLeft.setPoints( 2, 0,0, 0,1 ); bTop .setPoints( 2, 1,0, 1,0 ); bBot .setPoints( 2, 1,1, 1,1 ); } } if ( type == UpArrow || type == LeftArrow ) { matrix.translate( x, y ); if ( vertical ) { matrix.translate( 0, h - 1 ); matrix.rotate( -90 ); } else { matrix.translate( w - 1, h - 1 ); matrix.rotate( 180 ); } if ( down ) colspec = horizontal ? 0x2334 : 0x2343; else colspec = horizontal ? 0x1443 : 0x1434; } else if ( type == DownArrow || type == RightArrow ) { matrix.translate( x, y ); if ( vertical ) { matrix.translate( w-1, 0 ); matrix.rotate( 90 ); } if ( down ) colspec = horizontal ? 0x2443 : 0x2434; else colspec = horizontal ? 0x1334 : 0x1343; } QColor *cols[5]; if ( enabled ) { cols[0] = 0; cols[1] = (QColor *)&g.button(); cols[2] = (QColor *)&g.mid(); cols[3] = (QColor *)&g.light(); cols[4] = (QColor *)&g.dark(); } else { cols[0] = 0; cols[1] = (QColor *)&g.button(); cols[2] = (QColor *)&g.button(); cols[3] = (QColor *)&g.button(); cols[4] = (QColor *)&g.button(); }#define CMID *cols[ (colspec>>12) & 0xf ]#define CLEFT *cols[ (colspec>>8) & 0xf ]#define CTOP *cols[ (colspec>>4) & 0xf ]#define CBOT *cols[ colspec & 0xf ] QPen savePen = p->pen(); // save current pen QBrush saveBrush = p->brush(); // save current brush QWMatrix wxm = p->worldMatrix(); QPen pen( NoPen );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -