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

📄 qwindowsvistastyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** 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 "qwindowsvistastyle.h"#include "qwindowsvistastyle_p.h"#if !defined(QT_NO_STYLE_WINDOWSVISTA) || defined(QT_PLUGIN)static const int windowsItemFrame        =  2; // menu item frame widthstatic const int windowsItemHMargin      =  3; // menu item hor text marginstatic const int windowsItemVMargin      =  4; // menu item ver text marginstatic const int windowsArrowHMargin     =  6; // arrow horizontal marginstatic const int windowsRightBorder      = 15; // right border on windows#ifndef TMT_CONTENTMARGINS#  define TMT_CONTENTMARGINS 3602#endif                               #ifndef TMT_SIZINGMARGINS            #  define TMT_SIZINGMARGINS 3601#endif          #ifndef BP_COMMANDLINK#  define BP_COMMANDLINK 6#  define BP_COMMANDLINKGLYPH 7#  define CMDLGS_NORMAL 1#  define CMDLGS_HOT 2#  define CMDLGS_PRESSED 3#  define CMDLGS_DISABLED 4#endif        // Runtime resolved theme engine function callstypedef HRESULT (WINAPI *PtrGetThemePartSize)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, OPTIONAL RECT *prc, enum THEMESIZE eSize, OUT SIZE *psz);typedef HTHEME (WINAPI *PtrOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);typedef HTHEME (WINAPI *PtrOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);typedef HRESULT (WINAPI *PtrCloseThemeData)(HTHEME hTheme);typedef HRESULT (WINAPI *PtrDrawThemeBackground)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect);typedef HRESULT (WINAPI *PtrDrawThemeBackgroundEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const DTBGOPTS *pOptions);typedef HRESULT (WINAPI *PtrGetCurrentThemeName)(OUT LPWSTR pszThemeFileName, int cchMaxNameChars, OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars, OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars);typedef HRESULT (WINAPI *PtrGetThemeBool)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT BOOL *pfVal);typedef HRESULT (WINAPI *PtrGetThemeColor)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT COLORREF *pColor);typedef HRESULT (WINAPI *PtrGetThemeEnumValue)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT int *piVal);typedef HRESULT (WINAPI *PtrGetThemeFilename)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT LPWSTR pszThemeFileName, int cchMaxBuffChars);typedef HRESULT (WINAPI *PtrGetThemeFont)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OUT LOGFONT *pFont);typedef HRESULT (WINAPI *PtrGetThemeInt)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT int *piVal);typedef HRESULT (WINAPI *PtrGetThemeIntList)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT INTLIST *pIntList);typedef HRESULT (WINAPI *PtrGetThemeMargins)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OPTIONAL RECT *prc, OUT MARGINS *pMargins);typedef HRESULT (WINAPI *PtrGetThemeMetric)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OUT int *piVal);typedef HRESULT (WINAPI *PtrGetThemePartSize)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, OPTIONAL RECT *prc, enum THEMESIZE eSize, OUT SIZE *psz);typedef HRESULT (WINAPI *PtrGetThemePosition)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT POINT *pPoint);typedef HRESULT (WINAPI *PtrGetThemeRect)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT RECT *pRect);typedef HRESULT (WINAPI *PtrGetThemeString)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars);typedef HRESULT (WINAPI *PtrGetThemeTransitionDuration)(HTHEME hTheme, int iPartId, int iStateFromId, int iStateToId, int iPropId, int *pDuration);typedef HRESULT (WINAPI *PtrIsThemePartDefined)(HTHEME hTheme, int iPartId, int iStateId);typedef HRESULT (WINAPI *PtrSetWindowTheme)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);typedef HRESULT (WINAPI *PtrGetThemePropertyOrigin)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT enum PROPERTYORIGIN *pOrigin);static PtrIsThemePartDefined pIsThemePartDefined = 0;static PtrOpenThemeData pOpenThemeData = 0;static PtrCloseThemeData pCloseThemeData = 0;static PtrDrawThemeBackground pDrawThemeBackground = 0;static PtrDrawThemeBackgroundEx pDrawThemeBackgroundEx = 0;static PtrGetCurrentThemeName pGetCurrentThemeName = 0;static PtrGetThemeBool pGetThemeBool = 0;static PtrGetThemeColor pGetThemeColor = 0;static PtrGetThemeEnumValue pGetThemeEnumValue = 0;static PtrGetThemeFilename pGetThemeFilename = 0;static PtrGetThemeFont pGetThemeFont = 0;static PtrGetThemeInt pGetThemeInt = 0;static PtrGetThemeIntList pGetThemeIntList = 0;static PtrGetThemeMargins pGetThemeMargins = 0;static PtrGetThemeMetric pGetThemeMetric = 0;static PtrGetThemePartSize pGetThemePartSize = 0;static PtrGetThemePosition pGetThemePosition = 0;static PtrGetThemeRect pGetThemeRect = 0;static PtrGetThemeString pGetThemeString = 0;static PtrGetThemeTransitionDuration pGetThemeTransitionDuration= 0;static PtrSetWindowTheme pSetWindowTheme = 0;static PtrGetThemePropertyOrigin pGetThemePropertyOrigin = 0;/* \internal    Checks if we should use Vista style , or if we should    fall back to Windows style.*/bool QWindowsVistaStylePrivate::useVista(){    return (QWindowsVistaStylePrivate::useXP() &&            (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA &&             QSysInfo::WindowsVersion < QSysInfo::WV_NT_based));}/*!  \class QWindowsVistaStyle  \brief The QWindowsVistaStyle class provides a look and feel suitable for applications on Microsoft Windows Vista.  \since 4.3  \ingroup appearance  \warning This style is only available on the Windows Vista platform  because it makes use of Windows Vista's style engine.  \sa QMacStyle, QWindowsXPStyle, QPlastiqueStyle, QCleanlooksStyle, QMotifStyle*//*!  Constructs a QWindowsVistaStyle object.*/QWindowsVistaStyle::QWindowsVistaStyle()    : QWindowsXPStyle(*new QWindowsVistaStylePrivate){}//convert Qt state flags to uxtheme button statesint buttonStateId(int flags, int partId){    int stateId = 0;    if (partId == BP_RADIOBUTTON || partId == BP_CHECKBOX) {        if (!(flags & QStyle::State_Enabled))            stateId = RBS_UNCHECKEDDISABLED;        else if (flags & QStyle::State_Sunken)            stateId = RBS_UNCHECKEDPRESSED;        else if (flags & QStyle::State_MouseOver)            stateId = RBS_UNCHECKEDHOT;        else            stateId = RBS_UNCHECKEDNORMAL;        if (flags & QStyle::State_On)            stateId += RBS_CHECKEDNORMAL-1;    } else if (partId == BP_PUSHBUTTON) {        if (!(flags & QStyle::State_Enabled))            stateId = PBS_DISABLED;        else if (flags & (QStyle::State_Sunken | QStyle::State_On))            stateId = PBS_PRESSED;        else if (flags & QStyle::State_MouseOver)            stateId = PBS_HOT;        else            stateId = PBS_NORMAL;    } else {        Q_ASSERT(1);    }    return stateId;}void Animation::paint(QPainter *painter, const QStyleOption *option){    Q_UNUSED(option);    Q_UNUSED(painter);}/** ! \internal** Helperfunction to paint the current transition state* between two animation frames.** The result is a blended image consisting of* ((alpha)*_primaryImage) + ((1-alpha)*_secondaryImage)**/void Animation::drawBlendedImage(QPainter *painter, QRect rect, float alpha) {    if (_secondaryImage.isNull() || _primaryImage.isNull())        return;    if (_tempImage.isNull())        _tempImage = _secondaryImage;    const int a = qRound(alpha*256);    const int ia = 256 - a;    const int sw = _primaryImage.width();    const int sh = _primaryImage.height();    const int bpl = _primaryImage.bytesPerLine();    switch(_primaryImage.depth()) {    case 32:        {            uchar *mixed_data = _tempImage.bits();            const uchar *back_data = _primaryImage.bits();            const uchar *front_data = _secondaryImage.bits();            for (int sy = 0; sy < sh; sy++) {                quint32* mixed = (quint32*)mixed_data;                const quint32* back = (const quint32*)back_data;                const quint32* front = (const quint32*)front_data;                for (int sx = 0; sx < sw; sx++) {                    quint32 bp = back[sx];                    quint32 fp = front[sx];                    mixed[sx] =  qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8,                                        (qGreen(bp)*ia + qGreen(fp)*a)>>8,                                        (qBlue(bp)*ia + qBlue(fp)*a)>>8,                                        (qAlpha(bp)*ia + qAlpha(fp)*a)>>8);                }                mixed_data += bpl;                back_data += bpl;                front_data += bpl;            }        }    default:        break;    }    painter->drawImage(rect, _tempImage);}/** ! \internal** Paints a transition state. The result will be a mix between the* initial and final state of the transition, depending on the* time difference between _startTime and current time.*/void Transition::paint(QPainter *painter, const QStyleOption *option){    float alpha = 1.0;    if (_duration > 0) {        QTime current = QTime::currentTime();        if (_startTime > current)            _startTime = current;        int timeDiff = _startTime.msecsTo(current);        alpha = timeDiff/(float)_duration;        if (timeDiff > _duration) {            _running = false;            alpha = 1.0;        }    }    else {        _running = false;    }    drawBlendedImage(painter, option->rect, alpha);}/** ! \internal** Paints a pulse. The result will be a mix between the* primary and secondary pulse images depending on the* time difference between _startTime and current time.*/void Pulse::paint(QPainter *painter, const QStyleOption *option){    float alpha = 1.0;    if (_duration > 0) {        QTime current = QTime::currentTime();                if (_startTime > current)            _startTime = current;        int timeDiff = _startTime.msecsTo(current) % _duration*2;        if (timeDiff > _duration)            timeDiff = _duration*2 - timeDiff;        alpha = timeDiff/(float)_duration;

⌨️ 快捷键说明

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