📄 qmotifstyle.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2006 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://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** 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 <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 progressbars 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: d->bars.removeAll(reinterpret_cast<QProgressBar *>(o)); break; case QEvent::Hide: if (QProgressBar *bar = qobject_cast<QProgressBar *>(o)) { d->bars.removeAll(bar); if (d->bars.isEmpty()) { killTimer(d->animateTimer); d->animateTimer = 0; } } default: break; }#endif // QT_NO_PROGRESSBAR return QStyle::eventFilter(o, e);}/*! \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).dark(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){ QPolygon r(a.size()); for (int i = 0; i < (int)a.size(); i++) { switch (n) { case 1: r.setPoint(i,-a[i].y(),a[i].x()); break; case 2: r.setPoint(i,-a[i].x(),-a[i].y()); break; case 3: r.setPoint(i,a[i].y(),-a[i].x()); break; } } a = r;}/*! \reimp*/void QMotifStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const{ switch(pe) { case PE_Q3CheckListExclusiveIndicator: if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) { if (lv->items.isEmpty())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -