?? qsgistyle.cpp
字號(hào):
/****************************************************************************** $Id: qt/src/widgets/qsgistyle.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 "qsgistyle.h"#ifndef QT_NO_STYLE_SGI#include "qapplication.h"#include "qbutton.h"#include "qpainter.h"#include "qdrawutil.h"#include "qpixmap.h"#include "qpalette.h"#include "qwidget.h"#include "qpushbutton.h"#include "qscrollbar.h"#define INCLUDE_MENUITEM_DEF#include "qpopupmenu.h"#include <limits.h>typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, QColorGroup &, bool, bool);QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);static const int sgiItemFrame = 2; // menu item frame widthstatic const int sgiSepHeight = 1; // separator item heightstatic const int sgiItemHMargin = 3; // menu item hor text marginstatic const int sgiItemVMargin = 2; // menu item ver text marginstatic const int sgiArrowHMargin = 6; // arrow horizontal marginstatic const int sgiCheckMarkSpace = 20;static bool sliderMoving = FALSE;static bool sliderHandleActive = FALSE;static bool repaintByMouseMove = FALSE;static QPalette* lastWidgetPalette = 0;static int activeScrollBarElement = 0;static void* deviceUnderMouse = 0;static QPoint mousePos(-1,-1);struct SliderLastPosition{ SliderLastPosition() : pos(0,-1,0,-1), slider(0) {} QRect pos; QWidget* slider;};static SliderLastPosition sliderLastPosition;/*! \class QSGIStyle qsgistyle.h \brief SGI Look and Feel \ingroup appearance This class implements the SGI look and feel. It tries to resemble a SGI-like GUI style with the QStyle system.*//*! Constructs a QSGIStyle 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. \sa QMotifStyle::useHighlightColors()*/QSGIStyle::QSGIStyle( bool useHighlightCols ) : QMotifStyle( useHighlightCols ), isApplicationStyle( 0 ){ setButtonDefaultIndicatorWidth( 4 ); // ### remove and reimplement virtual function setScrollBarExtent( 21,21 );}/*! Destructs the style*/QSGIStyle::~QSGIStyle(){}/*! \reimp*/int QSGIStyle::defaultFrameWidth() const{ return 2;}/*! Changes some application-wide settings to be SGI like, e.g. sets bold/italic font for the menu-system.*/voidQSGIStyle::polish( QApplication* app){ isApplicationStyle = 1; QMotifStyle::polish( app ); QFont f = QApplication::font(); f.setBold( TRUE ); f.setItalic( TRUE ); QApplication::setFont( f, TRUE, "QPopupMenu" ); QApplication::setFont( f, TRUE, "QMenuBar" ); QApplication::setFont( f, TRUE, "QComboBox" ); QPalette pal = QApplication::palette(); // check this on SGI-Boxes //pal.setColor( QColorGroup::Background, pal.active().midlight() ); if (pal.active().button() == pal.active().background()) pal.setColor( QColorGroup::Button, pal.active().button().dark(120) ); // darker basecolor in list-widgets pal.setColor( QColorGroup::Base, pal.active().base().dark(130) ); if (! useHighlightColors() ) { pal.setColor( QPalette::Active, QColorGroup::Highlight, pal.active().text() ); pal.setColor( QPalette::Active, QColorGroup::HighlightedText, pal.active().base() ); pal.setColor( QPalette::Inactive, QColorGroup::Highlight, pal.inactive().text() ); pal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, pal.inactive().base() ); pal.setColor( QPalette::Disabled, QColorGroup::Highlight, pal.disabled().text() ); pal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, pal.disabled().base() ); } QApplication::setPalette( pal, TRUE ); // different basecolor and highlighting in Q(Multi)LineEdit pal.setColor( QColorGroup::Base, QColor(211,181,181) ); pal.setColor( QPalette::Active, QColorGroup::Highlight, pal.active().midlight() ); pal.setColor( QPalette::Active, QColorGroup::HighlightedText, pal.active().text() ); pal.setColor( QPalette::Inactive, QColorGroup::Highlight, pal.inactive().midlight() ); pal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, pal.inactive().text() ); pal.setColor( QPalette::Disabled, QColorGroup::Highlight, pal.disabled().midlight() ); pal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, pal.disabled().text() ); QApplication::setPalette( pal, TRUE, "QLineEdit" ); QApplication::setPalette( pal, TRUE, "QMultiLineEdit" ); pal = QApplication::palette(); pal.setColor( QColorGroup::Button, pal.active().background() ); QApplication::setPalette( pal, TRUE, "QMenuBar" ); QApplication::setPalette( pal, TRUE, "QToolBar" ); qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &QSGIStyle::drawMenuBarItem);}/*! \reimp*/voidQSGIStyle::unPolish( QApplication* /* app */ ){ QFont f = QApplication::font(); QApplication::setFont( f, TRUE, "QPopupMenu" ); QApplication::setFont( f, TRUE, "QMenuBar" ); QApplication::setFont( f, TRUE, "QComboBox" ); qt_set_draw_menu_bar_impl(0);}/*! Installs eventfilters for several widgets to enable the SGI-effect of glowing buttons.*/voidQSGIStyle::polish( QWidget* w ){ QMotifStyle::polish(w); if ( !isApplicationStyle ) { QPalette sgiPal = QApplication::palette(); sgiPal.setColor( QColorGroup::Background, sgiPal.active().midlight() ); if (sgiPal.active().button() == sgiPal.active().background()) sgiPal.setColor( QColorGroup::Button, sgiPal.active().button().dark(110) ); sgiPal.setColor( QColorGroup::Base, sgiPal.active().base().dark(130) ); if (! useHighlightColors() ) { sgiPal.setColor( QPalette::Active, QColorGroup::Highlight, sgiPal.active().text() ); sgiPal.setColor( QPalette::Active, QColorGroup::HighlightedText, sgiPal.active().base() ); sgiPal.setColor( QPalette::Inactive, QColorGroup::Highlight, sgiPal.inactive().text() ); sgiPal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, sgiPal.inactive().base() ); sgiPal.setColor( QPalette::Disabled, QColorGroup::Highlight, sgiPal.disabled().text() ); sgiPal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, sgiPal.disabled().base() ); } if ( w->inherits("QLineEdit") || w->inherits("QMultiLineEdit") ) { // different basecolor and highlighting in Q(Multi)LineEdit sgiPal.setColor( QColorGroup::Base, QColor(211,181,181) ); sgiPal.setColor( QPalette::Active, QColorGroup::Highlight, sgiPal.active().midlight() ); sgiPal.setColor( QPalette::Active, QColorGroup::HighlightedText, sgiPal.active().text() ); sgiPal.setColor( QPalette::Inactive, QColorGroup::Highlight, sgiPal.inactive().midlight() ); sgiPal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, sgiPal.inactive().text() ); sgiPal.setColor( QPalette::Disabled, QColorGroup::Highlight, sgiPal.disabled().midlight() ); sgiPal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, sgiPal.disabled().text() ); } else if ( w->inherits("QMenuBar") || w->inherits("QToolBar") ) { sgiPal.setColor( QColorGroup::Button, sgiPal.active().midlight() ); } w->setPalette( sgiPal ); } if ( w->inherits("QButton") || w->inherits("QSlider") || w->inherits("QScrollBar") ) { w->installEventFilter( this ); w->setMouseTracking( TRUE ); if ( w->inherits("QToolButton") ) w->setBackgroundMode( QWidget::PaletteBackground ); if ( w->inherits("QScrollBar") ) w->setBackgroundMode( QWidget::NoBackground ); } else if ( w->inherits("QMenuBar") ) { ((QFrame*) w)->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); w->setBackgroundMode( QWidget::PaletteBackground ); } else if ( w->inherits("QPopupMenu") ) { ((QFrame*) w)->setLineWidth( defaultFrameWidth() + 1 ); } else if ( w->inherits("QToolBar") ) { w->setBackgroundMode( QWidget::PaletteBackground ); } else if ( w->inherits("QToolBarSeparator") ) { w->setBackgroundMode( QWidget::PaletteBackground ); }}/*! \reimp*/voidQSGIStyle::unPolish( QWidget* w ){ if ( w == lastWidget ) w->unsetPalette( ); if ( w->inherits("QButton") ) w->removeEventFilter( this );}/*! \reimp*/voidQSGIStyle::polish( QPalette& pal ){ QCommonStyle::polish( pal );}/*! Draws a line to separate parts of the visual interface.*/voidQSGIStyle::drawSeparator( QPainter *p, int x1, int y1, int x2, int y2, const QColorGroup &g, bool sunken, int /*lineWidth*/, int /*midLineWidth*/ ){ QPen oldPen = p->pen(); p->setPen( g.midlight() ); p->drawLine( x1, y1, x2, y2 ); if (sunken) { p->setPen( g.shadow() ); if ( y2-y1 < x2-x1 ) p->drawLine( x1, y1+1, x2, y2+1 ); else p->drawLine( x1+1, y1, x2+1, y2 ); } p->setPen( oldPen );}/*! Draws a SGI-like panel with somewhat rounded edges.*/voidQSGIStyle::drawPanel( QPainter*p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, int lineWidth, const QBrush* fill ){ if( w < 0 ) w = 0; if( h < 0 ) h = 0; QMotifStyle::drawPanel( p, x, y, w, h, g, sunken, ( w > lineWidth && h > lineWidth ) ? lineWidth : 1, fill ); if ( lineWidth <= 1 ) return; // draw extra shadinglines QPen oldPen = p->pen(); p->setPen( g.midlight() ); p->drawLine( x+1, y+h-3, x+1, y+1 ); p->drawLine( x+1, y+1, x+w-3, y+1 ); p->setPen( g.mid() ); p->drawLine( x+1, y+h-2, x+w-2, y+h-2 ); p->drawLine( x+w-2, y+h-2, x+w-2, y+1 ); p->setPen(oldPen);}/*! Draws a press-senstive interface element.*/voidQSGIStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush *fill ){ drawPanel( p, x, y, w, h, g, sunken, defaultFrameWidth(), fill ? fill : (sunken ? &g.brush( QColorGroup::Mid ) : &g.brush( QColorGroup::Button ) ));}/*! Draws a button with a stronger separation from the user interface.*/voidQSGIStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush *fill ){ drawButton( p, x+1, y+1, w-2, h-2, g, sunken, fill ); QPen oldPen = p->pen(); QPointArray a; // draw twocolored rectangle p->setPen( sunken ? g.light() : g.dark().dark(200) ); a.setPoints( 3, x, y+h-1, x+w-1, y+h-1, x+w-1, y ); p->drawPolyline( a ); p->setPen( g.dark() ); a.setPoints( 3, x, y+h-2, x, y, x+w-2, y ); p->drawPolyline( a ); p->setPen( oldPen );}/*! Reimplemented ot be SGI-like.*/voidQSGIStyle::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) ); int diw = buttonDefaultIndicatorWidth(); if ( btn->isDefault() || btn->autoDefault() ) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } QPointArray a; if ( btn->isDefault() ) { if ( diw == 0 ) { a.setPoints( 9, x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1, x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 ); p->setPen( g.shadow() ); p->drawPolyline( a ); x1 += 2; y1 += 2; x2 -= 2; y2 -= 2; } else { qDrawShadePanel( p, btn->rect(), g, TRUE ); } } QBrush fill = g.brush( QColorGroup::Button ); if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) drawBevelButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn() || btn->isDown(), &fill ); if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush );}/*! Reimplemented to be SGI-like.*/voidQSGIStyle::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( 3, 0,-5, -5,4, 4,4 ); break; case DownArrow: a.setPoints( 3, 0,4, -4,-4, 4,-4 ); break; case LeftArrow: a.setPoints( 3, -4,0, 4,-5, 4,4 ); break; case RightArrow: a.setPoints( 3, 4,0, -4,-5, -4,4 ); break; } if ( a.isNull() ) return; QPen savePen = p->pen(); // save current pen if ( fill ) p->fillRect( x, y, w, h, *fill ); p->setPen( NoPen ); if ( enabled ) { a.translate( x+w/2, y+h/2 ); p->setBrush( enabled ? g.dark() : g.light() ); p->drawPolygon( a ); // draw arrow } p->setPen( savePen ); // restore pen}/*! \reimp*/QSizeQSGIStyle::indicatorSize() const{ return QSize(20,20);}/*! Draws a interface element showing the state of choice, used by a checkbox. \sa drawCheckMark()*/voidQSGIStyle::drawIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, int s, bool down, bool enabled ){ QPen oldPen = p->pen(); p->fillRect( x, y, w, h, g.brush( QColorGroup::Background ) );
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -