📄 qmotifstyle.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qmotifstyle.h"#include "qcdestyle.h"#if !defined(QT_NO_STYLE_MOTIF) || defined(QT_PLUGIN)#include "qmenu.h"#include "qapplication.h"#include "qpainter.h"#include "qdrawutil.h"#include "qpixmap.h"#include "qpalette.h"#include "qwidget.h"#include "qpushbutton.h"#include "qscrollbar.h"#include "qtabbar.h"#include "qtabwidget.h"#include "qlistview.h"#include "qsplitter.h"#include "qslider.h"#include "qcombobox.h"#include "qlineedit.h"#include "qprogressbar.h"#include "qimage.h"#include "qfocusframe.h"#include "qdebug.h"#include "qpainterpath.h"#include "qmotifstyle_p.h"#include "qdialogbuttonbox.h"#include <limits.h>#ifdef Q_WS_X11#include "qx11info_x11.h"#endif// old constants that might still be useful...static const int motifItemFrame = 2; // menu item frame widthstatic const int motifSepHeight = 2; // separator item heightstatic const int motifItemHMargin = 3; // menu item hor text marginstatic const int motifItemVMargin = 2; // menu item ver text marginstatic const int motifArrowHMargin = 6; // arrow horizontal marginstatic const int motifTabSpacing = 12; // space between text and tabstatic const int motifCheckMarkHMargin = 2; // horiz. margins of check markstatic const int motifCheckMarkSpace = 16;/*! \class QMotifStyle qmotifstyle.h \brief The QMotifStyle class provides Motif look and feel. \ingroup appearance This class implements the Motif look and feel. It closely resembles the original Motif look as defined by the Open Group, but with some minor improvements. The Motif style is Qt's default GUI style on Unix platforms. \img qmotifstyle.png \sa QWindowsXPStyle, QMacStyle, QWindowsStyle, QPlastiqueStyle, QCDEStyle*//*! \variable QMotifStyle::focus \internal*//*! Constructs a QMotifStyle. If \a useHighlightCols is false (the default), 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(*new QMotifStylePrivate){ focus = 0; highlightCols = useHighlightCols;}/*! \internal*/QMotifStyle::QMotifStyle(QMotifStylePrivate &dd, bool useHighlightColors) : QCommonStyle(dd){ focus = 0; highlightCols = useHighlightColors;}/*! \overload Destroys the style.*/QMotifStyle::~QMotifStyle(){ delete focus;}/*! \internal Animate indeterminate progress bars only when visible*/bool QMotifStyle::eventFilter(QObject *o, QEvent *e){#ifndef QT_NO_PROGRESSBAR Q_D(QMotifStyle); switch(e->type()) { case QEvent::StyleChange: case QEvent::Show: if (QProgressBar *bar = qobject_cast<QProgressBar *>(o)) { d->bars << bar; if (d->bars.size() == 1) { Q_ASSERT(d->animationFps> 0); d->animateTimer = startTimer(1000 / d->animationFps); } } break; case QEvent::Destroy: case QEvent::Hide: // reinterpret_cast because there is no type info when getting // the destroy event. We know that it is a QProgressBar. if (QProgressBar *bar = reinterpret_cast<QProgressBar *>(o)) { d->bars.removeAll(bar); if (d->bars.isEmpty() && d->animateTimer) { killTimer(d->animateTimer); d->animateTimer = 0; } } default: break; }#endif // QT_NO_PROGRESSBAR return QStyle::eventFilter(o, e);}/*! \internal*/QIcon QMotifStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt, const QWidget *widget) const{ return QCommonStyle::standardIconImplementation(standardIcon, opt, widget);}/*! \reimp*/void QMotifStyle::timerEvent(QTimerEvent *event){#ifndef QT_NO_PROGRESSBAR Q_D(QMotifStyle); if (event->timerId() == d->animateTimer) { Q_ASSERT(d->animationFps > 0); d->animateStep = d->startTime.elapsed() / (1000 / d->animationFps); foreach (QProgressBar *bar, d->bars) { if ((bar->minimum() == 0 && bar->maximum() == 0)) bar->update(); } }#endif // QT_NO_PROGRESSBAR event->ignore();}QMotifStylePrivate::QMotifStylePrivate()#ifndef QT_NO_PROGRESSBAR : animationFps(25), animateTimer(0), animateStep(0)#endif{}/*! If \a arg is false, 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 an application palette is set via QApplication::setPalette(). The current color palette of the application remains unchanged. \sa QStyle::polish()*/void QMotifStyle::setUseHighlightColors(bool arg){ highlightCols = arg;}/*! Returns true if the style treats the highlight colors of the palette in a Motif-like manner, which is a simple inversion between the base and the text color; otherwise returns false. The default is false.*/bool QMotifStyle::useHighlightColors() const{ return highlightCols;}/*! \reimp */void QMotifStyle::polish(QPalette& pal){ if (pal.brush(QPalette::Active, QPalette::Light) == pal.brush(QPalette::Active, QPalette::Base)) { QColor nlight = pal.color(QPalette::Active, QPalette::Light).darker(108); pal.setColor(QPalette::Active, QPalette::Light, nlight) ; pal.setColor(QPalette::Disabled, QPalette::Light, nlight) ; pal.setColor(QPalette::Inactive, QPalette::Light, nlight) ; } if (highlightCols) return; // force the ugly motif way of highlighting *sigh* pal.setColor(QPalette::Active, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Text)); pal.setColor(QPalette::Active, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::Base)); pal.setColor(QPalette::Disabled, QPalette::Highlight, pal.color(QPalette::Disabled, QPalette::Text)); pal.setColor(QPalette::Disabled, QPalette::HighlightedText, pal.color(QPalette::Disabled, QPalette::Base)); pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Text)); pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::Base));}/*! \reimp \internal Keep QStyle::polish() visible.*/void QMotifStyle::polish(QWidget* widget){ QStyle::polish(widget);#ifndef QT_NO_PROGRESSBAR if (qobject_cast<QProgressBar *>(widget)) widget->installEventFilter(this);#endif}/*! \reimp \internal Keep QStyle::polish() visible.*/void QMotifStyle::unpolish(QWidget* widget){ QCommonStyle::unpolish(widget);#ifndef QT_NO_PROGRESSBAR if (qobject_cast<QProgressBar *>(widget)) widget->removeEventFilter(this);#endif}/*! \reimp \internal Keep QStyle::polish() visible.*/void QMotifStyle::polish(QApplication* a){ QCommonStyle::polish(a);}/*! \reimp \internal Keep QStyle::polish() visible.*/void QMotifStyle::unpolish(QApplication* a){ QCommonStyle::unpolish(a);}static void rot(QPolygon& a, int n)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -