📄 qplastiquestyle.cpp
字号:
if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) painter->setPen(option->palette.button().color().dark(110)); else painter->setPen(gradientStopColor.dark(102)); painter->drawLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1); painter->drawLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 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().light(104); QColor gradientStopColor = option->palette.button().color().dark(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().dark(114), option->palette.button().color().dark(106)); } else { qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1), base ? option->palette.background().color().light(105) : gradientStartColor, base ? option->palette.background().color().dark(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){ if (tmp.isNull()) return; bool active = (option->titleBarState & QStyle::State_Active); // ### use palette colors instead QColor mdiButtonGradientStartColor; QColor mdiButtonGradientStopColor; if (active) { mdiButtonGradientStartColor = QColor(hover ? 0x7d8bb1 : 0x55689a); mdiButtonGradientStopColor = QColor(hover ? 0x939ebe : 0x7381ab); } else { mdiButtonGradientStartColor = QColor(hover ? 0x9e9e9e : 0x818181); mdiButtonGradientStopColor = QColor(hover ? 0xababab : 0x929292); } qt_plastique_draw_gradient(painter, tmp.adjusted(1, 1, -1, -1), mdiButtonGradientStartColor, mdiButtonGradientStopColor); QColor mdiButtonBorderColor; if (active) { mdiButtonBorderColor = hover ? QColor(0x627097) : QColor(0x324577); } else { mdiButtonBorderColor = hover ? QColor(0x838383) : QColor(0x5e5e5e); } painter->setPen(QPen(mdiButtonBorderColor, 1)); painter->drawLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()); painter->drawLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()); painter->drawLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2); painter->drawLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2); painter->drawPoint(tmp.left() + 1, tmp.top() + 1); painter->drawPoint(tmp.right() - 1, tmp.top() + 1); painter->drawPoint(tmp.left() + 1, tmp.bottom() - 1); painter->drawPoint(tmp.right() - 1, tmp.bottom() - 1);}#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 // QT_NO_DOCKWIDGET#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().dark(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: QPlastiqueStylePrivate(QPlastiqueStyle *qq); virtual ~QPlastiqueStylePrivate();#ifndef QT_NO_PROGRESSBAR QList<QProgressBar *> bars; int progressBarAnimateTimer; QTime timer; int animateStep;#endif QPlastiqueStyle *q;};/*! \internal */QPlastiqueStylePrivate::QPlastiqueStylePrivate(QPlastiqueStyle *qq) :#ifndef QT_NO_PROGRESSBAR progressBarAnimateTimer(0), animateStep(0),#endif q(qq){}/*! \internal */QPlastiqueStylePrivate::~QPlastiqueStylePrivate(){}/*! \class QPlastiqueStyle \brief The QPlastiqueStyle class provides a widget style similar to the Plastik style available in KDE. The Plastique style provides a default look and feel for widgets on X11 that closely resembles the Plastik style, introduced by Sandro Giessl in KDE 3.2. \img qplastiquestyle.png \sa QWindowsXPStyle, QMacStyle, QWindowsStyle, QCDEStyle, QMotifStyle*//*! Constructs a QPlastiqueStyle object.*/QPlastiqueStyle::QPlastiqueStyle() : QWindowsStyle(), d(new QPlastiqueStylePrivate(this)){}/*! Destructs the QPlastiqueStyle object.*/QPlastiqueStyle::~QPlastiqueStyle(){ delete d;}/*! \reimp*/void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const{ Q_ASSERT(option); QColor borderColor = option->palette.background().color().dark(178); QColor gradientStartColor = option->palette.button().color().light(104); QColor gradientStopColor = option->palette.button().color().dark(105); QColor baseGradientStartColor = option->palette.base().color().dark(101); QColor baseGradientStopColor = option->palette.base().color().dark(106); QColor highlightedGradientStartColor = option->palette.button().color().light(101); QColor highlightedGradientStopColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 85); QColor highlightedBaseGradientStartColor = option->palette.base().color(); QColor highlightedBaseGradientStopColor = mergedColors(option->palette.base().color().dark(105), option->palette.highlight().color(), 70); QColor highlightedDarkInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 35); QColor highlightedLightInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 58); 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); } QColor alphaInnerColor = mergedColors(highlightedLightInnerBorderColor, gradientStartColor); QColor alphaInnerColorNoHover = mergedColors(borderColor, gradientStartColor); QColor alphaTextColor = mergedColors(option->palette.background().color(), option->palette.text().color()); QColor alphaLightTextColor = mergedColors(option->palette.background().color().light(250), option->palette.text().color().light(250)); QColor lightShadow = option->palette.button().color().light(105); QColor shadowGradientStartColor = option->palette.button().color().dark(115); QColor shadow = shadowGradientStartColor; switch (element) { case PE_IndicatorButtonDropDown: drawPrimitive(PE_PanelButtonTool, option, painter, widget); break; case PE_FrameDefaultButton: // Draws the frame around a default button (drawn in // PE_PanelButtonCommand). break;#ifndef QT_NO_TABWIDGET case PE_FrameTabWidget: if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) { if (twf->shape != QTabBar::RoundedNorth && twf->shape != QTabBar::RoundedWest && twf->shape != QTabBar::RoundedSouth && twf->shape != QTabBar::RoundedEast) { QWindowsStyle::drawPrimitive(element, option, painter, widget); break; } int borderThickness = pixelMetric(PM_TabBarBaseOverlap, twf, widget); bool reverse = (twf->direction == Qt::RightToLeft); painter->save(); QRect tabBarRect; switch (twf->shape) { case QTabBar::RoundedNorth: if (reverse) tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1, twf->rect.top(), twf->tabBarSize.width(), borderThickness); else tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(), twf->rect.top(), twf->tabBarSize.width(), borderThickness); break ; case QTabBar::RoundedWest: tabBarRect = QRect(twf->rect.left(), twf->rect.top() + twf->leftCornerWidgetSize.height(), borderThickness, twf->tabBarSize.height()); break ; case QTabBar::RoundedEast: tabBarRect = QRect(twf->rect.right() - borderThickness + 1, twf->rect.top() + twf->leftCornerWidgetSize.height(), borderThickness, twf->tabBarSize.height()); break ; case QTabBar::RoundedSouth: if (reverse) tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1, twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness); else tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(), twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness); break ; default: break; } QRegion region(twf->rect); region -= tabBarRect; painter->setClipRegion(region); // Outer border QLine leftLine = QLine(twf->rect.topLeft() + QPoint(0, 2), twf->rect.bottomLeft() - QPoint(0, 2)); QLine rightLine = QLine(twf->rect.topRight() + QPoint(0, 2), twf->rect.bottomRight() - QPoint(0, 2)); QLine bottomLine = QLine(twf->rect.bottomLeft() + QPoint(2, 0), twf->rect.bottomRight() - QPoint(2, 0)); QLine topLine = QLine(twf->rect.topLeft() + QPoint(2, 0), twf->rect.topRight() - QPoint(2, 0)); painter->setPen(borderColor); painter->drawLine(topLine); // Inner border QLine innerLeftLine = QLine(leftLine.p1() + QPoint(1, 0), leftLine.p2() + QPoint(1, 0)); QLine innerRightLine = QLine(rightLine.p1() - QPoint(1, 0), rightLine.p2() - QPoint(1, 0)); QLine innerBottomLine = QLine(bottomLine.p1() - QPoint(0, 1), bottomLine.p2() - QPoint(0, 1)); QLine innerTopLine = QLine(topLine.p1() + QPoint(0, 1), topLine.p2() + QPoint(0, 1)); // Rounded Corner
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -