⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwindowsstyle.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** 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 "qwindowsstyle.h"#include "qwindowsstyle_p.h"#if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN)#include "qapplication.h"#include "qbitmap.h"#include "qdockwidget.h"#include "qdrawutil.h" // for now#include "qevent.h"#include "qmenu.h"#include "qmenubar.h"#include "qpaintengine.h"#include "qpainter.h"#include "qprogressbar.h"#include "qrubberband.h"#include "qstyleoption.h"#include "qtabbar.h"#include "qwidget.h"#include "qdebug.h"#include "qmainwindow.h"#if defined(Q_WS_WIN)#include "qt_windows.h"#  ifndef COLOR_GRADIENTACTIVECAPTION#    define COLOR_GRADIENTACTIVECAPTION     27#  endif#  ifndef COLOR_GRADIENTINACTIVECAPTION#    define COLOR_GRADIENTINACTIVECAPTION   28#  endif#endif#include <limits.h>static const int windowsItemFrame        =  2; // menu item frame widthstatic const int windowsSepHeight        =  9; // separator item heightstatic const int windowsItemHMargin      =  3; // menu item hor text marginstatic const int windowsItemVMargin      =  2; // menu item ver text marginstatic const int windowsArrowHMargin	 =  6; // arrow horizontal marginstatic const int windowsTabSpacing	 = 12; // space between text and tabstatic const int windowsCheckMarkHMargin =  2; // horiz. margins of check markstatic const int windowsRightBorder      = 15; // right border on windowsstatic const int windowsCheckMarkWidth   = 12; // checkmarks width on windowsstatic bool use2000style = true;enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };/*    \internal*/QWindowsStylePrivate::QWindowsStylePrivate()    : alt_down(false), menuBarTimer(0), animationFps(10), animateTimer(0), animateStep(0){}// Returns true if the toplevel parent of \a widget has seen the Alt-keybool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const{    widget = widget->window();    return seenAlt.contains(widget);}/*!    \reimp*/void QWindowsStyle::timerEvent(QTimerEvent *event){#ifndef QT_NO_PROGRESSBAR    Q_D(QWindowsStyle);    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();}/*!    \reimp*/bool QWindowsStyle::eventFilter(QObject *o, QEvent *e){    // Records Alt- and Focus events    if (!o->isWidgetType())        return QObject::eventFilter(o, e);    QWidget *widget = ::qobject_cast<QWidget*>(o);    Q_D(QWindowsStyle);    switch(e->type()) {    case QEvent::KeyPress:        if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {            widget = widget->window();            // Alt has been pressed - find all widgets that care            QList<QWidget *> l = qFindChildren<QWidget *>(widget);            for (int pos=0 ; pos < l.size() ; ++pos) {                QWidget *w = l.at(pos);                if (w->isWindow() || !w->isVisible() ||                    w->style()->styleHint(SH_UnderlineShortcut, 0, w))                    l.removeAt(pos);            }            // Update states before repainting            d->seenAlt.append(widget);            d->alt_down = true;            // Repaint all relevant widgets            for (int pos = 0; pos < l.size(); ++pos)                l.at(pos)->update();        }        break;    case QEvent::KeyRelease:	if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {	    widget = widget->window();	    // Update state and repaint the menubars.	    d->alt_down = false;#ifndef QT_NO_MENUBAR            QList<QMenuBar *> l = qFindChildren<QMenuBar *>(widget);            for (int i = 0; i < l.size(); ++i)                l.at(i)->update();#endif	}	break;    case QEvent::Close:        // Reset widget when closing        d->seenAlt.removeAll(widget);        d->seenAlt.removeAll(widget->window());        break;#ifndef QT_NO_PROGRESSBAR    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;            }        }        break;#endif // QT_NO_PROGRESSBAR    default:        break;    }    return QCommonStyle::eventFilter(o, e);}/*!    \class QWindowsStyle qwindowsstyle.h    \brief The QWindowsStyle class provides a Microsoft Windows-like look and feel.    \ingroup appearance    This style is Qt's default GUI style on Windows.    \img qwindowsstyle.png    \sa QWindowsXPStyle, QMacStyle, QPlastiqueStyle, QCDEStyle, QMotifStyle*//*!    Constructs a QWindowsStyle object.*/QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate){#if defined(Q_OS_WIN32)    use2000style = QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95;#endif}/*!    \internal    Constructs a QWindowsStyle object.*/QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd){#if defined(Q_OS_WIN32)    use2000style = QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95;#endif}/*! Destroys the QWindowsStyle object. */QWindowsStyle::~QWindowsStyle(){}#ifdef Q_WS_WINstatic inline QRgb colorref2qrgb(COLORREF col){    return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));}#endif/*! \reimp */void QWindowsStyle::polish(QApplication *app){    QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func());    // We only need the overhead when shortcuts are sometimes hidden    if (!styleHint(SH_UnderlineShortcut, 0) && app)        app->installEventFilter(this);    d->activeCaptionColor = app->palette().highlight().color();    d->activeGradientCaptionColor = app->palette().highlight() .color();    d->inactiveCaptionColor = app->palette().dark().color();    d->inactiveGradientCaptionColor = app->palette().dark().color();    d->inactiveCaptionText = app->palette().background().color();#if defined(Q_WS_WIN) //fetch native titlebar colors    if(app->desktopSettingsAware()){        DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION);        DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION);        DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION);        DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);        DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT);        d->activeCaptionColor = colorref2qrgb(activeCaption);        d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption);        d->inactiveCaptionColor = colorref2qrgb(inactiveCaption);        d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption);        d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText);    }#endif}/*! \reimp */void QWindowsStyle::unpolish(QApplication *app){    app->removeEventFilter(this);}/*! \reimp */void QWindowsStyle::polish(QWidget *widget){    QCommonStyle::polish(widget);#ifndef QT_NO_PROGRESSBAR    if (qobject_cast<QProgressBar *>(widget))        widget->installEventFilter(this);#endif}/*! \reimp */void QWindowsStyle::unpolish(QWidget *widget){    QCommonStyle::unpolish(widget);#ifndef QT_NO_PROGRESSBAR    if (qobject_cast<QProgressBar *>(widget))        widget->removeEventFilter(this);#endif}/*! \reimp */void QWindowsStyle::polish(QPalette &pal){    QCommonStyle::polish(pal);}/*!  \reimp*/int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const{    int ret;    switch (pm) {    case PM_ButtonDefaultIndicator:    case PM_ButtonShiftHorizontal:    case PM_ButtonShiftVertical:        ret = 1;        break;#ifndef QT_NO_TABBAR    case PM_TabBarTabShiftHorizontal:        ret = 0;        break;    case PM_TabBarTabShiftVertical:        ret = 2;        break;#endif    case PM_MaximumDragDistance:        ret = 60;        break;#ifndef QT_NO_SLIDER    case PM_SliderLength:        ret = 11;        break;        // Returns the number of pixels to use for the business part of the        // slider (i.e., the non-tickmark portion). The remaining space is shared        // equally between the tickmark regions.    case PM_SliderControlThickness:        if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {            int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();            int ticks = sl->tickPosition;            int n = 0;            if (ticks & QSlider::TicksAbove)                ++n;            if (ticks & QSlider::TicksBelow)                ++n;            if (!n) {                ret = space;                break;            }            int thick = 6;        // Magic constant to get 5 + 16 + 5            if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)                thick += pixelMetric(PM_SliderLength, sl, widget) / 4;            space -= thick;            if (space > 0)                thick += (space * 2) / (n + 2);            ret = thick;        } else {            ret = 0;        }        break;#endif // QT_NO_SLIDER#ifndef QT_NO_MENU    case PM_MenuBarHMargin:        ret = 0;        break;    case PM_MenuBarVMargin:        ret = 0;        break;    case PM_MenuBarPanelWidth:        ret = 0;        break;    case PM_SmallIconSize:        ret = 16;        break;    case PM_LargeIconSize:        ret = 32;        break;    case PM_IconViewIconSize:        ret = pixelMetric(PM_LargeIconSize, opt, widget);        break;    case PM_ToolBarIconSize:        ret = 24;        break;    case PM_DockWidgetTitleMargin:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -