{
painter->save();
QColor backgroundColor
= active ? activeBg_
: inactiveBg_;
QColor textColor
= active ? activeFg_
: inactiveFg_;
painter->setBrush(backgroundColor);
const int &width = size.width();
const int &height = size.height();
int arrow = height / 2;
if (arrow % 2 != 0)
{
arrow++;
}
if (index == 0) {
rect
= QRect(x,
0, width, height
);
painter
->setRenderHint
(QPainter::Antialiasing,
true);
painter->drawRoundedRect(rect, 2, 2);
points
[0] = QPoint(width
- 2,
-1);
points
[1] = QPoint(width
- 1,
-1);
points
[2] = QPoint(width
+ arrow, height
/ 2);
points
[3] = QPoint(width
- 1, height
);
points
[4] = QPoint(width
- 2, height
);
painter
->setRenderHint
(QPainter::Antialiasing,
false);
painter->drawPolygon(points, 5);
rect.adjust(0, 0, 5, 0);
} else {
points
[1] = QPoint(x
+ width,
-1);
points
[2] = QPoint(x
+ width
+ arrow, height
/ 2);
points
[3] = QPoint(x
+ width, height
);
points
[4] = QPoint(x, height
);
points
[5] = QPoint(x
+ arrow, height
/ 2);
painter->drawPolygon(points, 6);
rect
= QRect(x
+ arrow
+ 3,
0, width
- arrow, height
);
}
painter->setPen(textColor);
painter->drawText(rect, Qt::AlignCenter, text);
painter->restore();
}
void TabBar::paintBox(QPainter *painter, int x, const QString &text, const QSize &size, int index)
{
painter->save();
QColor backgroundColor = active ? activeBg_ : inactiveBg_;
QColor textColor = active ? activeFg_ : inactiveFg_;
painter->setBrush(backgroundColor);
QRect rect;
QPoint points[6];
const int &width = size.width();
const int &height = size.height();
int arrow = height / 2;
if (arrow % 2 != 0)
{
arrow++;
}
if (index == 0) {
rect = QRect(x, 0, width, height);
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawRoundedRect(rect, 2, 2);
points[0] = QPoint(width - 2, -1);
points[1] = QPoint(width - 1, -1);
points[2] = QPoint(width + arrow, height / 2);
points[3] = QPoint(width - 1, height);
points[4] = QPoint(width - 2, height);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->drawPolygon(points, 5);
rect.adjust(0, 0, 5, 0);
} else {
points[0] = QPoint(x, -1);
points[1] = QPoint(x + width, -1);
points[2] = QPoint(x + width + arrow, height / 2);
points[3] = QPoint(x + width, height);
points[4] = QPoint(x, height);
points[5] = QPoint(x + arrow, height / 2);
painter->drawPolygon(points, 6);
rect = QRect(x + arrow + 3, 0, width - arrow, height);
}
painter->setPen(textColor);
painter->drawText(rect, Qt::AlignCenter, text);
painter->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks