?? qcommonstyle.cpp
字號(hào):
/****************************************************************************** $Id: qt/src/widgets/qcommonstyle.cpp 2.3.12 edited 2005-10-27 $**** Implementation of the QCommonStyle 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 "qcommonstyle.h"#if !defined(QT_NO_STYLE_WINDOWS) || !defined(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 "qtabbar.h"#include "qscrollbar.h"#include "qtoolbutton.h"#include <limits.h>#define INCLUDE_MENUITEM_DEF#include "qmenudata.h" // for now// #undef INCLUDE_MENUITEM_DEF#include "qmotifplusstyle.h" // fo rnowtypedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, QColorGroup &, bool, bool);static QDrawMenuBarItemImpl draw_menu_bar_impl = 0;QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl){ QDrawMenuBarItemImpl old_impl = draw_menu_bar_impl; draw_menu_bar_impl = impl; return old_impl;}// NOT REVISED/*! \class QCommonStyle qcommonstyle.h \brief Encapsulates common Look and Feel of a GUI. \ingroup appearance This abstract class implements some of the widget's look and feel that is common to all GUI styles provided and shipped as part of Qt.*//*! Constructs a QCommonStyle that provides the style \a s. This determines the default behavior of the virtual functions.*/QCommonStyle::QCommonStyle(GUIStyle s) : QStyle(s){} /*! Destructs the style.*/QCommonStyle::~QCommonStyle(){}/*! \reimp */void QCommonStyle::drawComboButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, bool /* editable */, bool /*enabled */, const QBrush *fill ){ drawButton(p, x, y, w, h, g, sunken, fill);}/*! \reimp */QRect QCommonStyle::comboButtonRect( int x, int y, int w, int h){ return buttonRect(x, y, w-21, h);}/*! \reimp */QRect QCommonStyle::comboButtonFocusRect( int x, int y, int w, int h){ return buttonRect(x+2, y+2, w-4-21, h-4);}/*! \reimp*/void QCommonStyle::drawComboButtonMask( QPainter *p, int x, int y, int w, int h){ drawButtonMask(p, x, y, w, h);}/*!\reimp */void QCommonStyle::drawPushButtonLabel( QPushButton* btn, QPainter *p){#ifndef QT_NO_PUSHBUTTON QRect r = pushButtonContentsRect( btn ); if ( btn->isDown() || btn->isOn() ){ int sx = 0; int sy = 0; getButtonShift(sx, sy); r.moveBy( sx, sy ); } int x, y, w, h; r.rect( &x, &y, &w, &h ); if ( btn->isMenuButton() ) { int dx = menuButtonIndicatorWidth( btn->height() ); drawArrow( p, DownArrow, FALSE, x+w-dx, y+2, dx-4, h-4, btn->colorGroup(), btn->isEnabled() ); w -= dx; } if ( btn->iconSet() && !btn->iconSet()->isNull() ) { QIconSet::Mode mode = btn->isEnabled() ? QIconSet::Normal : QIconSet::Disabled; if ( mode == QIconSet::Normal && btn->hasFocus() ) mode = QIconSet::Active; QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); p->drawPixmap( x+2, y+h/2-pixh/2, pixmap ); x += pixw + 4; w -= pixw + 4; } drawItem( p, x, y, w, h, AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(), btn->pixmap(), btn->text(), -1, &btn->colorGroup().buttonText() );#endif}/*!\reimp */void QCommonStyle::getButtonShift( int &x, int &y){ x = 0; y = 0;}/*!\reimp */int QCommonStyle::defaultFrameWidth() const{ return 2;}/*!\reimp */void QCommonStyle::tabbarMetrics( const QTabBar* t, int& hframe, int& vframe, int& overlap){#ifndef QT_NO_TABBAR overlap = 3; hframe = 24; vframe = 0; if ( t->shape() == QTabBar::RoundedAbove || t->shape() == QTabBar::RoundedBelow ) vframe += 10;#endif}/*!\reimp */void QCommonStyle::drawTab( QPainter* p, const QTabBar* tb, QTab* t , bool selected ){#ifndef QT_NO_TABBAR if ( tb->shape() == QTabBar::TriangularAbove || tb->shape() == QTabBar::TriangularBelow ) { // triangular, above or below int y; int x; QPointArray a( 10 ); a.setPoint( 0, 0, -1 ); a.setPoint( 1, 0, 0 ); y = t->r.height()-2; x = y/3; a.setPoint( 2, x++, y-1 ); a.setPoint( 3, x++, y ); a.setPoint( 3, x++, y++ ); a.setPoint( 4, x, y ); int i; int right = t->r.width() - 1; for ( i = 0; i < 5; i++ ) a.setPoint( 9-i, right - a.point( i ).x(), a.point( i ).y() ); if ( tb->shape() == QTabBar::TriangularAbove ) for ( i = 0; i < 10; i++ ) a.setPoint( i, a.point(i).x(), t->r.height() - 1 - a.point( i ).y() ); a.translate( t->r.left(), t->r.top() ); if ( selected ) p->setBrush( tb->colorGroup().base() ); else p->setBrush( tb->colorGroup().background() ); p->setPen( tb->colorGroup().foreground() ); p->drawPolygon( a ); p->setBrush( NoBrush ); }#endif}/*!\reimp */void QCommonStyle::drawTabMask( QPainter* p, const QTabBar* /* tb*/ , QTab* t, bool /* selected */ ){#ifndef QT_NO_TABBAR p->drawRect( t->r );#endif}/*!\reimp */QStyle::ScrollControl QCommonStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p ){#ifndef QT_NO_SCROLLBAR if ( !sb->rect().contains( p ) ) return NoScroll; int sliderMin, sliderMax, sliderLength, buttonDim, pos; scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); pos = (sb->orientation() == QScrollBar::Horizontal)? p.x() : p.y(); if ( pos < sliderMin ) return SubLine; if ( pos < sliderStart ) return SubPage; if ( pos < sliderStart + sliderLength ) return Slider; if ( pos < sliderMax + sliderLength ) return AddPage; return AddLine;#else return NoScroll;#endif}/*!\reimp */voidQCommonStyle::drawSliderMask( QPainter *p, int x, int y, int w, int h, Orientation, bool, bool ){ p->fillRect(x, y, w, h, color1);}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -