diff options
Diffstat (limited to 'doc/src/snippets/code/src_qtestlib_qtestcase.cpp')
0 files changed, 0 insertions, 0 deletions
![]() |
index : qt/qtbase.git | |
| Qt Base (Core, Gui, Widgets, Network, ...) |
| summaryrefslogtreecommitdiffstats |
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtGui>
#include "javastyle.h"
#include <math.h>
static const int windowsItemFrame = 2;
static const int windowsSepHeight = 2;
static const int windowsItemHMargin = 3;
static const int windowsItemVMargin = 2;
static const int windowsArrowHMargin = 6;
static const int windowsTabSpacing = 12;
static const int windowsCheckMarkHMargin = 2;
static const int windowsRightBorder = 15;
static const int windowsCheckMarkWidth = 12;
JavaStyle::JavaStyle()
{
qApp->setPalette(standardPalette());
}
inline QPoint JavaStyle::adjustScrollPoint(const QPoint &point,
Qt::Orientation orientation,
bool add) const
{
int adder = add ? -1 : 1;
QPoint retPoint;
if (orientation == Qt::Horizontal) {
retPoint = QPoint(point.y() * adder, point.x());
} else {
retPoint = QPoint(point.x(), point.y() * adder);
}
return retPoint;
}
QPalette JavaStyle::standardPalette() const
{
QPalette palette = QCommonStyle::standardPalette();
palette.setBrush(QPalette::Active, QPalette::Button,
QColor(184, 207, 229));
palette.setBrush(QPalette::Active, QPalette::WindowText,
Qt::black);
palette.setBrush(QPalette::Active, QPalette::Background,
QColor(238, 238, 238));
palette.setBrush(QPalette::Active, QPalette::Window,
QColor(238 ,238, 238));
palette.setBrush(QPalette::Active, QPalette::Base, Qt::white);
palette.setBrush(QPalette::Active, QPalette::AlternateBase, QColor(238, 238, 238));
palette.setBrush(QPalette::Active, QPalette::Text, Qt::black);
palette.setBrush(QPalette::Active, QPalette::BrightText, Qt::white);
palette.setBrush(QPalette::Active, QPalette::Light, QColor(163, 184, 204)); // focusFrameColor
palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(99, 130, 191)); // tabBarBorderColor
palette.setBrush(QPalette::Active, QPalette::Dark, QColor(106, 104, 100));
palette.setBrush(QPalette::Active, QPalette::Mid, QColor(122, 138, 153)); //defaultFrameColor
palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(122, 138, 153)); // defaultFrame
palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(184, 207, 229));
palette.setBrush(QPalette::Active, QPalette::HighlightedText, Qt::black);
palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(184, 207, 229));
palette.setBrush(QPalette::Inactive, QPalette::HighlightedText, Qt::black);
palette.setBrush(QPalette::Disabled, QPalette::Button,
QColor(238, 238, 238));
palette.setBrush(QPalette::Disabled, QPalette::WindowText,
QColor(153, 153, 153));
palette.setBrush(QPalette::Disabled, QPalette::Background, QColor(238, 238, 238));
palette.setBrush(QPalette::Inactive, QPalette::Button,
QColor(184, 207, 229));
palette.setBrush(QPalette::Inactive, QPalette::Background,
QColor(238, 238, 238));
palette.setBrush(QPalette::Inactive, QPalette::Window,
QColor(238 ,238, 238));
palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(163, 184, 204)); // focusFrameColor
palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(99, 130, 191)); // tabBarBorderColor
palette.setBrush(QPalette::Inactive, QPalette::Dark,QColor(106, 104, 100));
palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(122, 138, 153)); //defaultFrame
palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(122, 138, 153)); // defaultFrame
return palette;
}
inline void JavaStyle::drawScrollBarArrow(const QRect &rect, QPainter *painter,
const QStyleOptionSlider *option,
bool add) const
{
painter->save();
Qt::Orientation orient = option->orientation;
QPoint offset;
if (add) {
if (orient == Qt::Vertical) {
offset = rect.bottomLeft();
} else {
offset = rect.topRight();
}
} else {
offset = rect.topLeft();
}
QPainterPath arrow;
arrow.moveTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add));
arrow.lineTo(offset + adjustScrollPoint(QPoint(7, 5), orient, add));
arrow.lineTo(offset + adjustScrollPoint(QPoint(8, 5), orient, add));
arrow.lineTo(offset + adjustScrollPoint(QPoint(11, 8), orient, add));
arrow.lineTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add));
QColor fillColor;
if (option->state & State_Sunken)
fillColor = QColor(option->palette.color(QPalette::Button));
else
fillColor = option->palette.color(QPalette::Background);
painter->fillRect(rect, fillColor);
painter->setPen(option->palette.color(QPalette::Base));
int adjust = option->state & State_Sunken ? 0 : 1;
painter->drawRect(rect.adjusted(adjust, adjust, -1, -1));
painter->setPen(option->palette.color(QPalette::Mid));
painter->drawRect(rect.adjusted(0, 0, -1, -1));
painter->setPen(option->palette.color(QPalette::WindowText));
painter->setBrush(option->palette.color(QPalette::WindowText));
painter->drawPath(arrow);
painter->restore();
}
inline QPoint JavaStyle::adjustScrollHandlePoint(Qt::Orientation orig,
const QPoint &point) const
{
QPoint retPoint;
if (orig == Qt::Vertical)
retPoint = point;
else
retPoint = QPoint(point.y(), point.x());
return retPoint;
}
void JavaStyle::drawControl(ControlElement control, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
painter->save();
switch (control) {
case CE_ToolBoxTabShape: {
const QStyleOptionToolBox *box =
qstyleoption_cast<const QStyleOptionToolBox *>(option);
painter->save();
if (box->direction == Qt::RightToLeft) {
painter->rotate(1);
painter->translate(box->rect.width(), -box->rect.height());
}
int textWidth = box->fontMetrics.horizontalAdvance(box->text) + 20;
QPolygon innerLine;
innerLine << (box->rect.topLeft() + QPoint(0, 1)) <<
(box->rect.topLeft() + QPoint(textWidth, 1)) <<
(box->rect.bottomLeft() + QPoint(textWidth + 15, -3)) <<
(box->rect.bottomRight() + QPoint(0, -3)) <<
box->rect.bottomRight() <<
box->rect.bottomLeft() <<
box->rect.topLeft();
painter->setPen(box->palette.color(QPalette::Base));
painter->setBrush(QColor(200, 221, 242));
painter->drawPolygon(innerLine);
QPolygon outerLine;
outerLine << (box->rect.bottomRight() + QPoint(0, -3)) <<
box->rect.bottomRight() <<
box->rect.bottomLeft() <<
box->rect.topLeft() <<
(box->rect.topLeft() + QPoint(textWidth, 0)) <<
(box->rect.bottomLeft() + QPoint(textWidth + 15, -4)) <<
(box->rect.bottomRight() + QPoint(0, -4));
painter->setPen(box->palette.color(QPalette::Midlight));
painter->setBrush(Qt::NoBrush);
painter->drawPolyline(outerLine);
painter->restore();
break;
}
case CE_DockWidgetTitle: {
const QStyleOptionDockWidget *docker =
qstyleoption_cast<const QStyleOptionDockWidget *>(option);
QRect rect = docker->rect;
QRect titleRect = rect;
if (docker->verticalTitleBar) {
QRect r = rect.transposed();
titleRect = QRect(r.left() + rect.bottom()
- titleRect.bottom(),
r.top() + titleRect.left() - rect.left(),
titleRect.height(), titleRect.width());
painter->translate(r.left(), r.top() + r.width());
painter->rotate(-90);
painter->translate(-r.left(), -r.top());
rect = r;
}
QLinearGradient gradient(rect.topLeft(),
rect.bottomLeft());
gradient.setColorAt(1.0, QColor(191, 212, 231));
gradient.setColorAt(0.3, Qt::white);
gradient.setColorAt(0.0, QColor(221, 232, 243));
painter->setPen(Qt::NoPen);
painter->setBrush(gradient);
painter->drawRect(rect.adjusted(0, 0, -1, -1));
if (!docker->title.isEmpty()) {
QRect textRect = docker->fontMetrics.boundingRect(docker->title);
textRect.moveCenter(rect.center());
QFont font = painter->font();
font.setPointSize(font.pointSize() - 1);
painter->setFont(font);
painter->setPen(docker->palette.text().color());
painter->drawText(textRect, docker->title,
QTextOption(Qt::AlignHCenter |
Qt::AlignVCenter));
}
break;
}
case CE_RubberBand: {
painter->setPen(option->palette.color(QPalette::Active,
QPalette::WindowText));
painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
break;
}
case CE_SizeGrip: {
break;
}
case CE_HeaderSection: {
const QStyleOptionHeader *header =
qstyleoption_cast<const QStyleOptionHeader *>(option);
painter->setPen(Qt::NoPen);
painter->setBrush(option->palette.color(QPalette::Active,
QPalette::Background));
painter->drawRect(option->rect);
painter->setPen(header->palette.color(QPalette::Mid));
if (header->orientation == Qt::Horizontal) {
if (header->position == QStyleOptionHeader::Beginning ||
header->position == QStyleOptionHeader::OnlyOneSection) {
painter->drawRect(header->rect.adjusted(0, 0, -1, -1));
painter->setPen(header->palette.color(QPalette::Base));
painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
header->rect.topLeft() + QPoint(1, 1));
painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
header->rect.topRight() + QPoint(-1, 1));
} else {
painter->drawLine(header->rect.bottomRight(),
header->rect.topRight());
painter->drawLine(header->rect.topLeft(),
header->rect.topRight());
painter->drawLine(header->rect.bottomLeft(),
header->rect.bottomRight());
painter->setPen(option->palette.color(QPalette::Base));
painter->drawLine(header->rect.bottomLeft() + QPoint(0, -1),
header->rect.topLeft() + QPoint(0, 1));
painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
header->rect.topRight() + QPoint(-1, 1));
}
} else { // Vertical
if (header->position == QStyleOptionHeader::Beginning ||
header->position == QStyleOptionHeader::OnlyOneSection) {
painter->drawRect(header->rect.adjusted(0, 0, -1, -1));
painter->setPen(header->palette.color(QPalette::Base));
painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
header->rect.topLeft() + QPoint(1, 1));
painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
header->rect.topRight() + QPoint(-1, 1));
} else {
painter->drawLine(header->rect.bottomLeft(),
header->rect.bottomRight());
painter->drawLine(header->rect.topLeft(),
header->rect.bottomLeft());
painter->drawLine(header->rect.topRight(),
header->rect.bottomRight());
painter->setPen(header->palette.color(QPalette::Base));
painter->drawLine(header->rect.topLeft(),
header->rect.topRight() + QPoint(-1, 0));
painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
header->rect.topLeft() + QPoint(1, 0));
}
}
break;
}
case CE_ToolBar: {
QRect rect = option->rect;
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
gradient.setColorAt(1.0, QColor(221, 221, 221));
gradient.setColorAt(0.0, QColor(241, 241, 241));
if (option->state & State_Horizontal) {
painter->setPen(QColor(204, 204, 204));
painter->setBrush(gradient);
} else {
painter->setPen(Qt::NoPen);
painter->setBrush(option->palette.color(QPalette::Background));
}
painter->drawRect(rect.adjusted(0, 0, -1, -1));
break;
}
case CE_ProgressBar: {
const QStyleOptionProgressBar *bar =
qstyleoption_cast<const QStyleOptionProgressBar *>(option);
QRect rect = bar->rect;
if (bar->orientation == Qt::Vertical) {
rect = QRect(rect.left(), rect.top(), rect.height(), rect.width());
QTransform m;
m.translate(rect.height()-1, 0);
m.rotate(90.0);
painter->setTransform(m);
}
painter->setPen(bar->palette.color(QPalette::Mid));
painter->drawRect(rect.adjusted(0, 0, -1, -1));
QRect grooveRect = subElementRect(SE_ProgressBarGroove, bar,
widget);
if (bar->orientation == Qt::Vertical) {
grooveRect = QRect(grooveRect.left(), grooveRect.top(),
grooveRect.height(), grooveRect.width());
}
QStyleOptionProgressBar grooveBar = *bar;
grooveBar.rect = grooveRect;
drawControl(CE_ProgressBarGroove, &grooveBar, painter, widget);
QRect progressRect = subElementRect(SE_ProgressBarContents, bar,
widget);
if (bar->orientation == Qt::Vertical) {
progressRect = QRect(progressRect.left(), progressRect.top(),
progressRect.height(), progressRect.width());
progressRect.adjust(0, 0, 0, -1);
}
QStyleOptionProgressBar progressOpt = *bar;
progressOpt.rect = progressRect;
drawControl(CE_ProgressBarContents, &progressOpt, painter, widget);
QRect labelRect = subElementRect(SE_ProgressBarLabel, bar, widget);
if (bar->orientation == Qt::Vertical) {
labelRect = QRect(labelRect.left(), labelRect.top(),
labelRect.height(), labelRect.width());
}
QStyleOptionProgressBar subBar = *bar;
subBar.rect = labelRect;
if (bar->textVisible)
drawControl(CE_ProgressBarLabel, &subBar, painter, widget);
break;
}
case CE_ProgressBarGroove: {
painter->setBrush(option->palette.color(QPalette::Background));
painter->setPen(Qt::NoPen);
painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
painter->setPen(option->palette.color(QPalette::Button));
painter->drawLine(option->rect.topLeft() + QPoint(0, 0),
option->rect.topRight() + QPoint(0, 0));
break;
}
case CE_ProgressBarContents: {
const QStyleOptionProgressBar *bar =
qstyleoption_cast<const QStyleOptionProgressBar *>(option);
int progress = int((double(bar->progress) /
double(bar->maximum - bar->minimum)) *
bar->rect.width());
painter->setBrush(bar->palette.color(QPalette::Light));
painter->setPen(Qt::NoPen);
QRect progressRect = QRect(bar->rect.topLeft(), QPoint(progress,
bar->rect.bottom()));
painter->drawRect(progressRect);
painter->setPen(bar->palette.color(QPalette::Midlight));
painter->setBrush(Qt::NoBrush);
painter->drawLine(bar->rect.bottomLeft(), bar->rect.topLeft());
painter->drawLine(bar->rect.topLeft(), QPoint(progress,
bar->rect.top()));
break;
}
case CE_ProgressBarLabel: {
painter->save();
const QStyleOptionProgressBar *bar =
qstyleoption_cast<const QStyleOptionProgressBar *>(option);
QRect rect = bar->rect;
QRect leftRect;
int progressIndicatorPos = int((double(bar->progress) /
double(bar->maximum - bar->minimum)) *
bar->rect.width());
QFont font;
font.setBold(true);
painter->setFont(font);
painter->setPen(bar->palette.color(QPalette::Midlight));
if (progressIndicatorPos >= 0 &&
progressIndicatorPos <= rect.width()) {
leftRect = QRect(bar->rect.topLeft(),
QPoint(progressIndicatorPos,
bar->rect.bottom()));
} else if (progressIndicatorPos > rect.width()) {
painter->setPen(bar->palette.color(QPalette::Base));
} else {
painter->setPen(bar->palette.color(QPalette::Midlight));
}
QRect textRect = QFontMetrics(font).boundingRect(bar->text);
textRect.moveCenter(option->rect.center());
painter->drawText(textRect, bar->text,
QTextOption(Qt::AlignCenter));
if (!leftRect.isNull()) {
painter->setPen(bar->palette.color(QPalette::Base));
painter->setClipRect(leftRect, Qt::IntersectClip);
painter->drawText(textRect, bar->text,
QTextOption(Qt::AlignCenter));
}
painter->restore();
break;
}
case CE_MenuBarEmptyArea: {
QRect emptyArea = option->rect.adjusted(0, 0, -1, -1);
QLinearGradient gradient(emptyArea.topLeft(), emptyArea.bottomLeft()
- QPoint(0, 1));
gradient.setColorAt(0.0, option->palette.color(QPalette::Base));
gradient.setColorAt(1.0, QColor(223, 223, 223));
painter->setPen(QColor(238, 238, 238));
painter->setBrush(gradient);
painter->drawRect(emptyArea.adjusted(0, 0, 0, -1));
break;
}
case CE_MenuBarItem: {
if (!(option->state & State_Sunken)) {
QLinearGradient gradient(option->rect.topLeft(),
option->rect.bottomLeft());
gradient.setColorAt(0.0, Qt::white);
gradient.setColorAt(1.0, QColor(223, 223, 223));
painter->setPen(Qt::NoPen);
painter->setBrush(gradient);
} else {
painter->setBrush(option->palette.color(QPalette::Light));
}
painter->drawRect(option->rect);
if (option->state & State_Sunken) {
painter->setPen(option->palette.color(QPalette::Mid));
painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
painter->setPen(option->palette.color(QPalette::Base));
painter->setBrush(Qt::NoBrush);
painter->drawLine(option->rect.bottomRight() + QPoint(0, -1),
option->rect.topRight() + QPoint(0, -1));
}
QCommonStyle::drawControl(control, option, painter, widget);
break;
}
case CE_MenuItem: {
const QStyleOptionMenuItem *menuItem =
qstyleoption_cast<const QStyleOptionMenuItem *>(option);
bool selected = menuItem->state & State_Selected;
bool checkable = menuItem->checkType !=
QStyleOptionMenuItem::NotCheckable;
bool checked = menuItem->checked;
if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
QPoint center = menuItem->rect.center();
painter->setPen(menuItem->palette.color(QPalette::Midlight));
painter->drawLine(QPoint(menuItem->rect.left() - 2, center.y()),
QPoint(menuItem->rect.right(), center.y()));
painter->setPen(menuItem->palette.color(QPalette::Base));
painter->drawLine(QPoint(menuItem->rect.left() - 2,
center.y() + 1),
QPoint(menuItem->rect.right(),
center.y() + 1));
break;
}
if (selected) {
painter->setBrush(menuItem->palette.color(QPalette::Light));
painter->setPen(Qt::NoPen);
painter->drawRect(menuItem->rect);
painter->setPen(menuItem->palette.color(QPalette::Midlight));
painter->drawLine(menuItem->rect.topLeft(),
menuItem->rect.topRight());
painter->setPen(menuItem->palette.color(QPalette::Base));
painter->drawLine(menuItem->rect.bottomLeft(),
menuItem->rect.bottomRight());
}
if (checkable) {
QRect checkRect(option->rect.left() + 5,
option->rect.center().y() - 5, 10, 10);
if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
QStyleOptionButton button;
button.rect = checkRect;
button.state = menuItem->state;
if (button.state & State_Sunken)
button.state ^= State_Sunken;
if (checked)
button.state |= State_On;
button.palette = menuItem->palette;
drawPrimitive(PE_IndicatorRadioButton, &button, painter,
widget);
} else {
QBrush buttonBrush = gradientBrush(option->rect);
painter->setBrush(buttonBrush);
painter->setPen(option->palette.color(QPalette::Mid));
painter->drawRect(checkRect);
if (checked) {
QImage image(":/images/checkboxchecked.png");
painter->drawImage(QPoint(option->rect.left() + 5,
option->rect.center().y() - 8), image);
}
}
}
bool dis = !(menuItem->state & State_Enabled);
bool act = menuItem->state & State_Selected;
const QStyleOption *opt = option;
const QStyleOptionMenuItem *menuitem = menuItem;
int checkcol = qMax(menuitem->maxIconWidth, 20);
if (menuItem->icon.isNull())
checkcol = 0;
QPainter *p = painter;
QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
QRect(menuitem->rect.x(),
menuitem->rect.y(),
checkcol, menuitem->rect.height()));
if (!menuItem->icon.isNull()) {
QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
if (act && !dis)
mode = QIcon::Active;
QPixmap pixmap;
if (checked)
pixmap = menuItem->icon.pixmap(
pixelMetric(PM_SmallIconSize), mode, QIcon::On);
else
pixmap = menuItem->icon.pixmap(
pixelMetric(PM_SmallIconSize), mode);
int pixw = pixmap.width();
int pixh = pixmap.height();
int adjustedIcon = checkable ? 15 : 0;
QRect pmr(0, 0, pixw, pixh);
pmr.moveCenter(vCheckRect.center());
painter->setPen(menuItem->palette.text().color());
if (checkable && checked)
painter->drawPixmap(QPoint(pmr.left() +
adjustedIcon, pmr.top() + 1), pixmap);
else
painter->drawPixmap(pmr.topLeft() +
QPoint(adjustedIcon, 0), pixmap);
}
if (selected) {
painter->setPen(menuItem->palette.highlightedText().color());
} else {
painter->setPen(menuItem->palette.text().color());
}
int x, y, w, h;
menuitem->rect.getRect(&x, &y, &w, &h);
int tab = menuitem->tabWidth;
QColor discol;
if (dis) {
discol = menuitem->palette.text().color();
p->setPen(discol);
}
int xm = windowsItemFrame + checkcol + windowsItemHMargin;
int xpos = menuitem->rect.x() + xm;
QRect textRect;
if (!menuItem->icon.isNull())
textRect.setRect(xpos, y + windowsItemVMargin, w - xm -
windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
else
textRect.setRect(menuItem->rect.left() + 9,
y + windowsItemVMargin,
w - xm - windowsRightBorder - tab,
h - 2 * windowsItemVMargin);
if (checkable)
textRect.adjust(10, 0, 10, 0);
QRect vTextRect = visualRect(opt->direction, menuitem->rect,
textRect);
QString s = menuitem->text;
if (!s.isEmpty()) {
qsizetype t = s.indexOf(u'\t');
int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic |
Qt::TextDontClip | Qt::TextSingleLine;
if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
text_flags |= Qt::TextHideMnemonic;
text_flags |= Qt::AlignLeft;
if (t >= 0) {
QRect vShortcutRect = visualRect(opt->direction,
menuitem->rect,
QRect(textRect.topRight(),
QPoint(menuitem->rect.right(), textRect.bottom())));
if (dis && !act) {
p->setPen(menuitem->palette.light().color());
p->drawText(vShortcutRect.adjusted(1, 1, 1, 1),
text_flags,
s.mid(t + 1));
p->setPen(discol);
}
p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
s = s.left(t);
}
QFont font = menuitem->font;
if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
font.setBold(true);
p->setFont(font);
if (dis && !act) {
p->setPen(menuitem->palette.light().color());
p->drawText(vTextRect.adjusted(1,1,1,1), text_flags,
s.left(t));
p->setPen(discol);
}
p->drawText(vTextRect, text_flags, s.left(t));
}
if (menuItem->menuItemType & QStyleOptionMenuItem::SubMenu) {
QPoint center = menuItem->rect.center();
QPoint drawStart(menuItem->rect.right() - 6, center.y() + 4);
QPainterPath arrow;
arrow.moveTo(drawStart);
arrow.lineTo(drawStart + QPoint(0, -8));
arrow.lineTo(drawStart + QPoint(4, -5));
arrow.lineTo(drawStart + QPoint(4, -4));
arrow.lineTo(drawStart + QPoint(0, 0));
painter->save();
painter->setBrush(menuItem->palette.color(QPalette::Text));
painter->setPen(Qt::NoPen);
painter->drawPath(arrow);
painter->restore();
}
break;
}
case CE_MenuVMargin: {
break;
}
case CE_MenuHMargin: {
break;
}
case CE_Splitter: {
drawSplitter(option, painter, option->state & State_Horizontal);
break;
}
case CE_ScrollBarAddPage: {
case CE_ScrollBarSubPage:
const QStyleOptionSlider *scrollBar =
qstyleoption_cast<const QStyleOptionSlider *>(option);
QRect myRect;
if (scrollBar->orientation == Qt::Horizontal) {
myRect = QRect(option->rect.topLeft(),
option->rect.bottomRight()).adjusted(0, 0, 1, -1);
} else {
myRect = option->rect;
}
painter->setPen(Qt::NoPen);
painter->setBrush(option->palette.color(QPalette::Background));
painter->drawRect(myRect);
painter->setBrush(Qt::NoBrush);
painter->setPen(scrollBar->palette.color(QPalette::Mid));
painter->drawRect(myRect.adjusted(0, 0, -1, 0));
painter->setPen(scrollBar->palette.color(QPalette::Button));
painter->drawLine(myRect.bottomLeft() + QPoint(1, 0),
myRect.topLeft() + QPoint(1, 1));
painter->drawLine(myRect.topLeft() + QPoint(1, 1),
myRect.topRight() + QPoint(-1, 1));
break;
}
case CE_ScrollBarSubLine: {
const QStyleOptionSlider *scrollBar =
qstyleoption_cast<const QStyleOptionSlider *>(option);
int scrollBarExtent = pixelMetric(PM_ScrollBarExtent);
QRect scrollBarSubLine = option->rect;
QRect button1;
QRect button2;
if (scrollBar->orientation == Qt::Horizontal) {
button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(),
16, scrollBarExtent);
button2.setRect(scrollBarSubLine.right() - 15,
scrollBarSubLine.top(), 16, scrollBarExtent);
} else {
button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(),
scrollBarExtent, 16);
button2.setRect(scrollBarSubLine.left(),
scrollBarSubLine.bottom() - 15, scrollBarExtent, 16);
}
painter->fillRect(button2, Qt::blue);
drawScrollBarArrow(button1, painter, scrollBar);
drawScrollBarArrow(button2, painter, scrollBar);
break;
}
case CE_ScrollBarAddLine: {
const QStyleOptionSlider *scrollBar =
qstyleoption_cast<const QStyleOptionSlider *>(option);
QRect button(option->rect.left(), option->rect.top(), 16, 16);
drawScrollBarArrow(button, painter, scrollBar, true);
break;
}
case CE_ScrollBarSlider: {
const QStyleOptionSlider *scrollBar =
qstyleoption_cast<const QStyleOptionSlider *>(option);
painter->setPen(scrollBar->palette.color(QPalette::Midlight));
painter->drawRect(scrollBar->rect.adjusted(-1, 0, -3, -1));
QPoint g1, g2;
if (scrollBar->orientation == Qt::Horizontal) {
g1 = option->rect.topLeft();
g2 = option->rect.bottomLeft();
} else {
g1 = option->rect.topLeft();
g2 = option->rect.topRight();
}
if (scrollBar->state & State_Enabled) {
QLinearGradient gradient(g1, g2);
gradient.setColorAt(1.0, QColor(188, 210, 230));
gradient.setColorAt(0.3, Qt::white);
gradient.setColorAt(0.0, QColor(223, 233, 243));
painter->setBrush(gradient);
} else {
painter->setPen(scrollBar->palette.buttonText().color());
painter->setBrush(scrollBar->palette.button());
}
painter->drawRect(scrollBar->rect.adjusted(0, 0, -1, -1));
int sliderLength = option->rect.height();
int drawPos = scrollBar->orientation == Qt::Vertical ?
(sliderLength / 2) + 1 : 1 - ((option->rect.width() / 2));
QPoint origin;
if (scrollBar->orientation == Qt::Vertical)
origin = option->rect.bottomLeft();
else
origin = option->rect.topLeft();
painter->setPen(scrollBar->palette.color(QPalette::Base));
painter->drawLine(origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(4, -drawPos)),
origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(13, -drawPos)));
painter->drawLine(origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(4, 2 - drawPos)),
origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(13, 2 - drawPos)));
painter->drawLine(origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(4, 4 - drawPos)),
origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(13, 4 - drawPos)));
painter->setPen(option->palette.color(QPalette::Midlight));
painter->drawLine(origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(3, -(drawPos + 1))),
origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(12, -(drawPos + 1))));
painter->drawLine(origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(3, 1 - drawPos)),
origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(12, 1 - drawPos)));
painter->drawLine(origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(3, 3 - drawPos)),
origin + adjustScrollHandlePoint(
scrollBar->orientation,
QPoint(12, 3 - drawPos)));
break;
}
case CE_TabBarTabLabel: {
QStyleOptionTab copy =
*qstyleoption_cast<const QStyleOptionTab *>(option);
if (copy.state & State_HasFocus)
copy.state ^= State_HasFocus;
painter->setBrush(Qt::NoBrush);
QCommonStyle::drawControl(CE_TabBarTabLabel, ©, painter,
widget);
break;
}
case CE_TabBarTabShape: {
const QStyleOptionTab *tab =
qstyleoption_cast<const QStyleOptionTab *>(option);
QRect myRect = option->rect;
QPoint bottomLeft, bottomRight, topLeft, topRight;
if ((tab->position == QStyleOptionTab::Beginning) ||
(tab->position == QStyleOptionTab::OnlyOneTab)) {
if (tab->shape == QTabBar::RoundedSouth ||
tab->shape == QTabBar::RoundedNorth) {
myRect = myRect.adjusted(2, 0, 0, 0);
} else {
myRect = myRect.adjusted(0, 2, 0, 0);
}
}
switch (tab->shape) {
case QTabBar::RoundedNorth:
topLeft = myRect.topLeft();
topRight = myRect.topRight();
bottomLeft = myRect.bottomLeft();
bottomRight = myRect.bottomRight();
break;
case QTabBar::RoundedSouth:
topLeft = myRect.bottomLeft();
topRight = myRect.bottomRight();
bottomLeft = myRect.topLeft();
bottomRight = myRect.topRight();
break;
case QTabBar::RoundedWest:
topLeft = myRect.topLeft();
topRight = myRect.bottomLeft();
bottomLeft = myRect.topRight();
bottomRight = myRect.bottomRight();
break;
case QTabBar::RoundedEast:
topLeft = myRect.topRight();
topRight = myRect.bottomRight();
bottomLeft = myRect.topLeft();
bottomRight = myRect.bottomLeft();
break;
default:
;
}
QPainterPath outerPath;
outerPath.moveTo(bottomLeft + adjustTabPoint(QPoint(0, -2),
tab->shape));
outerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(0, -14),
tab->shape));
outerPath.lineTo(topLeft + adjustTabPoint(QPoint(6 , 0),
tab->shape));
outerPath.lineTo(topRight + adjustTabPoint(QPoint(0, 0),
tab->shape));
outerPath.lineTo(bottomRight + adjustTabPoint(QPoint(0, -2),
tab->shape));
if (tab->state & State_Selected ||
tab->position == QStyleOptionTab::OnlyOneTab) {
QPainterPath innerPath;
innerPath.moveTo(topLeft + adjustTabPoint(QPoint(6, 2),
tab->shape));
innerPath.lineTo(topRight + adjustTabPoint(QPoint(-1, 2),
tab->shape));
innerPath.lineTo(bottomRight + adjustTabPoint(QPoint(-1 , -2),
tab->shape));
innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -2),
tab->shape));
innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -14),
tab->shape));
innerPath.lineTo(topLeft + adjustTabPoint(QPoint(6, 2),
tab->shape));
QPainterPath whitePath;
whitePath.moveTo(bottomLeft + adjustTabPoint(QPoint(1, -2),
tab->shape));
whitePath.lineTo(bottomLeft + adjustTabPoint(QPoint(1, -14),
tab->shape));
whitePath.lineTo(topLeft + adjustTabPoint(QPoint(6, 1),
tab->shape));
whitePath.lineTo(topRight + adjustTabPoint(QPoint(-1, 1),
tab->shape));
painter->setPen(tab->palette.color(QPalette::Midlight));
painter->setBrush(QColor(200, 221, 242));
painter->drawPath(outerPath);
painter->setPen(QColor(200, 221, 242));
painter->drawRect(QRect(bottomLeft + adjustTabPoint(
QPoint(2, -3), tab->shape),
bottomRight + adjustTabPoint(
QPoint(-2, 0), tab->shape)));
painter->setPen(tab->palette.color(QPalette::Base));
painter->setBrush(Qt::NoBrush);
painter->drawPath(whitePath);
if (option->state & State_HasFocus) {
painter->setPen(option->palette.color(QPalette::Mid));
painter->drawPath(innerPath);
}
} else {
painter->setPen(tab->palette.color(QPalette::Mid));
painter->drawPath(outerPath);
}
break;
}
case CE_PushButtonLabel:
painter->save();
if (const QStyleOptionButton *button =
qstyleoption_cast<const QStyleOptionButton *>(option)) {
QRect ir = button->rect;
uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
if (!styleHint(SH_UnderlineShortcut, button, widget))
tf |= Qt::TextHideMnemonic;
if (!button->icon.isNull()) {
QPoint point;
QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
: QIcon::Disabled;
if (mode == QIcon::Normal && button->state & State_HasFocus)
mode = QIcon::Active;
QIcon::State state = QIcon::Off;
if (button->state & State_On)
state = QIcon::On;
QPixmap pixmap = button->icon.pixmap(button->iconSize, mode,
state);
int w = pixmap.width();
int h = pixmap.height();
if (!button->text.isEmpty())
w += button->fontMetrics.horizontalAdvance(button->text) + 2;
point = QPoint(ir.x() + ir.width() / 2 - w / 2,
ir.y() + ir.height() / 2 - h / 2);