📄 qplastiquestyle.cpp
字号:
corner = option->palette.highlight(); qBrushSetAlphaF(&corner, 0.5); innerTopLeft = qBrushDark(option->palette.highlight(), 125); innerBottomRight = option->palette.highlight(); qBrushSetAlphaF(&innerBottomRight, 0.65); } else { border = option->palette.shadow(); qBrushSetAlphaF(&border, 0.4); corner = option->palette.shadow(); qBrushSetAlphaF(&corner, 0.25); innerTopLeft = option->palette.shadow(); innerBottomRight = option->palette.shadow(); if (shadow == QFrame::Sunken) { qBrushSetAlphaF(&innerTopLeft, 0.23); qBrushSetAlphaF(&innerBottomRight, 0.075); } else { qBrushSetAlphaF(&innerTopLeft, 0.075); qBrushSetAlphaF(&innerBottomRight, 0.23); } } QLine lines[4]; QPoint points[8]; // Opaque corner lines painter->setPen(QPen(border, 0)); lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top()); lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom()); lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2); lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2); painter->drawLines(lines, 4); // Opaque corner dots points[0] = QPoint(rect.left() + 1, rect.top() + 1); points[1] = QPoint(rect.left() + 1, rect.bottom() - 1); points[2] = QPoint(rect.right() - 1, rect.top() + 1); points[3] = QPoint(rect.right() - 1, rect.bottom() - 1); painter->drawPoints(points, 4); // Shaded corner dots painter->setPen(QPen(corner, 0)); points[0] = QPoint(rect.left(), rect.top() + 1); points[1] = QPoint(rect.left(), rect.bottom() - 1); points[2] = QPoint(rect.left() + 1, rect.top()); points[3] = QPoint(rect.left() + 1, rect.bottom()); points[4] = QPoint(rect.right(), rect.top() + 1); points[5] = QPoint(rect.right(), rect.bottom() - 1); points[6] = QPoint(rect.right() - 1, rect.top()); points[7] = QPoint(rect.right() - 1, rect.bottom()); painter->drawPoints(points, 8); // Shadows if (shadow != QFrame::Plain) { painter->setPen(QPen(innerTopLeft, 0)); lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1); lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2); painter->drawLines(lines, 2); painter->setPen(QPen(innerBottomRight, 0)); lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1); lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2); painter->drawLines(lines, 2); } painter->setPen(oldPen);}static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50){ const int maxFactor = 100; QColor tmp = colorA; tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); return tmp;}static QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size){ QString tmp; const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option); tmp.sprintf("%s-%d-%d-%d-%lld-%dx%d", key.toLatin1().constData(), uint(option->state), option->direction, complexOption ? uint(complexOption->activeSubControls) : uint(0), option->palette.cacheKey(), size.width(), size.height()); return tmp;}static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart, const QColor &gradientStop){ QString gradientName; gradientName.sprintf("%dx%d-%x-%x", rect.width(), rect.height(), gradientStart.rgba(), gradientStop.rgba()); QPixmap cache; if (!UsePixmapCache || !QPixmapCache::find(gradientName, cache)) { cache = QPixmap(rect.size()); cache.fill(Qt::white); QPainter cachePainter(&cache); QRect pixmapRect(0, 0, rect.width(), rect.height()); int x = pixmapRect.center().x(); QLinearGradient gradient(x, pixmapRect.top(), x, pixmapRect.bottom()); gradient.setColorAt(0, gradientStart); gradient.setColorAt(1, gradientStop); cachePainter.fillRect(pixmapRect, gradient); cachePainter.end(); if (UsePixmapCache) QPixmapCache::insert(gradientName, cache); } painter->drawPixmap(rect, cache);}static void qt_plastique_drawFrame(QPainter *painter, const QStyleOption *option, const QWidget *widget){ QRect rect = option->rect; QPen oldPen = painter->pen(); QColor borderColor = option->palette.background().color().darker(178); QColor gradientStartColor = option->palette.button().color().lighter(104); QColor gradientStopColor = option->palette.button().color().darker(105); QColor alphaCornerColor; if (widget) { // ### backgroundrole/foregroundrole should be part of the style option alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor); } else { alphaCornerColor = mergedColors(option->palette.background().color(), borderColor); } QLine lines[4]; QPoint points[8]; // outline / border painter->setPen(borderColor); lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top()); lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom()); lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2); lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2); painter->drawLines(lines, 4); points[0] = QPoint(rect.left() + 1, rect.top() + 1); points[1] = QPoint(rect.right() - 1, rect.top() + 1); points[2] = QPoint(rect.left() + 1, rect.bottom() - 1); points[3] = QPoint(rect.right() - 1, rect.bottom() - 1); painter->drawPoints(points, 4); painter->setPen(alphaCornerColor); points[0] = QPoint(rect.left() + 1, rect.top()); points[1] = QPoint(rect.right() - 1, rect.top()); points[2] = QPoint(rect.left() + 1, rect.bottom()); points[3] = QPoint(rect.right() - 1, rect.bottom()); points[4] = QPoint(rect.left(), rect.top() + 1); points[5] = QPoint(rect.right(), rect.top() + 1); points[6] = QPoint(rect.left(), rect.bottom() - 1); points[7] = QPoint(rect.right(), rect.bottom() - 1); painter->drawPoints(points, 8); // inner border if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) painter->setPen(option->palette.button().color().darker(118)); else painter->setPen(gradientStartColor); lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, option->rect.top() + 1); lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, option->rect.bottom() - 2); painter->drawLines(lines, 2); if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) painter->setPen(option->palette.button().color().darker(110)); else painter->setPen(gradientStopColor.darker(102)); lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1); lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2); painter->drawLines(lines, 2); painter->setPen(oldPen);}static void qt_plastique_drawShadedPanel(QPainter *painter, const QStyleOption *option, bool base, const QWidget *widget){ QRect rect = option->rect; QPen oldPen = painter->pen(); QColor gradientStartColor = option->palette.button().color().lighter(104); QColor gradientStopColor = option->palette.button().color().darker(105); // gradient fill if ((option->state & QStyle::State_Enabled) || !(option->state & QStyle::State_AutoRaise)) { if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) { qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1), option->palette.button().color().darker(114), option->palette.button().color().darker(106)); } else { qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1), base ? option->palette.background().color().lighter(105) : gradientStartColor, base ? option->palette.background().color().darker(102) : gradientStopColor); } } qt_plastique_drawFrame(painter, option, widget); painter->setPen(oldPen);}static void qt_plastique_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken){ if (tmp.isNull()) return; bool active = (option->titleBarState & QStyle::State_Active); // ### use palette colors instead QColor mdiButtonGradientStartColor; QColor mdiButtonGradientStopColor; if (active) { mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x7d8bb1 : 0x55689a); mdiButtonGradientStopColor = QColor((hover || sunken) ? 0x939ebe : 0x7381ab); } else { mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x9e9e9e : 0x818181); mdiButtonGradientStopColor = QColor((hover || sunken) ? 0xababab : 0x929292); } qt_plastique_draw_gradient(painter, tmp.adjusted(1, 1, -1, -1), mdiButtonGradientStartColor, mdiButtonGradientStopColor); QColor mdiButtonBorderColor; if (active) { mdiButtonBorderColor = (hover || sunken) ? QColor(0x627097) : QColor(0x324577); } else { mdiButtonBorderColor = (hover || sunken) ? QColor(0x838383) : QColor(0x5e5e5e); } painter->setPen(QPen(mdiButtonBorderColor, 1)); const QLine lines[4] = { QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()), QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()), QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2), QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2) }; painter->drawLines(lines, 4); const QPoint points[4] = { QPoint(tmp.left() + 1, tmp.top() + 1), QPoint(tmp.right() - 1, tmp.top() + 1), QPoint(tmp.left() + 1, tmp.bottom() - 1), QPoint(tmp.right() - 1, tmp.bottom() - 1) }; painter->drawPoints(points, 4);}#ifndef QT_NO_DOCKWIDGETstatic QString elliditide(const QString &text, const QFontMetrics &fontMetrics, const QRect &rect, int *textWidth = 0){ // Chop and insert ellide into title if text is too wide QString title = text; int width = textWidth ? *textWidth : fontMetrics.width(text); QString ellipsis = QLatin1String("..."); if (width > rect.width()) { QString leftHalf = title.left(title.size() / 2); QString rightHalf = title.mid(leftHalf.size() + 1); while (!leftHalf.isEmpty() && !rightHalf.isEmpty()) { leftHalf.chop(1); int width = fontMetrics.width(leftHalf + ellipsis + rightHalf); if (width < rect.width()) { title = leftHalf + ellipsis + rightHalf; width = width; break; } rightHalf.remove(0, 1); width = fontMetrics.width(leftHalf + ellipsis + rightHalf); if (width < rect.width()) { title = leftHalf + ellipsis + rightHalf; width = width; break; } } } if (textWidth) *textWidth = width; return title;}#endif#if !defined(QT_NO_DOCKWIDGET) || !defined(QT_NO_SPLITTER)static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option, const QRect &rect, Qt::Orientation orientation, const QWidget *widget){ QColor borderColor = option->palette.background().color().darker(178); QColor alphaCornerColor; if (widget) { // ### backgroundrole/foregroundrole should be part of the style option alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor); } else { alphaCornerColor = mergedColors(option->palette.background().color(), borderColor); } QImage handle(qt_simple_toolbarhandle); handle.setColor(1, alphaCornerColor.rgba()); handle.setColor(2, mergedColors(alphaCornerColor, option->palette.base().color()).rgba()); handle.setColor(3, option->palette.base().color().rgba()); const int spacing = 2; if (orientation == Qt::Vertical) { int nchunks = rect.width() / (handle.width() + spacing); for (int i = 0; i < nchunks; ++i) painter->drawImage(QPoint(rect.left() + i * (handle.width() + spacing), rect.top()), handle); } else { int nchunks = rect.height() / (handle.height() + spacing); for (int i = 0; i < nchunks; ++i) painter->drawImage(QPoint(rect.left(), rect.top() + i * (handle.height() + spacing)), handle); }}#endifclass QPlastiqueStylePrivate : public QWindowsStylePrivate{ Q_DECLARE_PUBLIC(QPlastiqueStyle)public: QPlastiqueStylePrivate(); virtual ~QPlastiqueStylePrivate(); void lookupIconTheme() const;#ifndef QT_NO_PROGRESSBAR QList<QProgressBar *> bars; int progressBarAnimateTimer; QTime timer;#endif};/*! \internal */QPlastiqueStylePrivate::QPlastiqueStylePrivate() : QWindowsStylePrivate()#ifndef QT_NO_PROGRESSBAR , progressBarAnimateTimer(0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -