31
31
#include <klocale.h>
36
36
StatusBarToolButton::StatusBarToolButton(QWidget* parent)
37
37
: QToolButton(parent)
38
, mGroupPosition(NotGrouped) {
39
setToolButtonStyle(Qt::ToolButtonTextOnly);
40
setFocusPolicy(Qt::NoFocus);
41
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
45
QSize StatusBarToolButton::minimumSizeHint() const {
50
QSize StatusBarToolButton::sizeHint() const {
51
QSize sh = QToolButton::sizeHint();
52
sh.setHeight(fontMetrics().height());
57
void StatusBarToolButton::setGroupPosition(StatusBarToolButton::GroupPosition groupPosition) {
58
mGroupPosition = groupPosition;
62
void StatusBarToolButton::paintEvent(QPaintEvent* event) {
63
if (mGroupPosition == NotGrouped) {
64
QToolButton::paintEvent(event);
67
QStylePainter painter(this);
68
QStyleOptionToolButton opt;
69
initStyleOption(&opt);
70
QStyleOptionToolButton panelOpt = opt;
73
QRect& panelRect = panelOpt.rect;
74
switch (mGroupPosition) {
76
panelRect.setWidth(panelRect.width() * 2);
79
panelRect.setLeft(panelRect.left() - panelRect.width());
80
panelRect.setWidth(panelRect.width() * 3);
83
panelRect.setLeft(panelRect.left() - panelRect.width());
88
painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt);
91
const int y1 = opt.rect.top() + 6;
92
const int y2 = opt.rect.bottom() - 6;
93
if (mGroupPosition & GroupRight) {
94
const int x = opt.rect.left();
95
painter.setPen(opt.palette.color(QPalette::Light));
96
painter.drawLine(x, y1, x, y2);
98
if (mGroupPosition & GroupLeft) {
99
const int x = opt.rect.right();
100
painter.setPen(opt.palette.color(QPalette::Mid));
101
painter.drawLine(x, y1, x, y2);
105
painter.drawControl(QStyle::CE_ToolButtonLabel, opt);
107
// Filtering message on tooltip text for CJK to remove accelerators.
108
// Quoting ktoolbar.cpp:
110
// CJK languages use more verbose accelerator marker: they add a Latin
111
// letter in parenthesis, and put accelerator on that. Hence, the default
112
// removal of ampersand only may not be enough there, instead the whole
113
// parenthesis construct should be removed. Provide these filtering i18n
114
// messages so that translators can use Transcript for custom removal.
116
if (!actions().isEmpty()) {
117
QAction* action = actions().first();
118
setToolTip(i18nc("@info:tooltip of custom toolbar button", "%1", action->toolTip()));
38
, mGroupPosition(NotGrouped)
40
setToolButtonStyle(Qt::ToolButtonTextOnly);
41
setFocusPolicy(Qt::NoFocus);
42
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
45
QSize StatusBarToolButton::minimumSizeHint() const
50
QSize StatusBarToolButton::sizeHint() const
52
QSize sh = QToolButton::sizeHint();
53
sh.setHeight(fontMetrics().height());
57
void StatusBarToolButton::setGroupPosition(StatusBarToolButton::GroupPosition groupPosition)
59
mGroupPosition = groupPosition;
62
void StatusBarToolButton::paintEvent(QPaintEvent* event)
64
if (mGroupPosition == NotGrouped) {
65
QToolButton::paintEvent(event);
68
QStylePainter painter(this);
69
QStyleOptionToolButton opt;
70
initStyleOption(&opt);
71
QStyleOptionToolButton panelOpt = opt;
74
QRect& panelRect = panelOpt.rect;
75
switch (mGroupPosition) {
77
panelRect.setWidth(panelRect.width() * 2);
80
panelRect.setLeft(panelRect.left() - panelRect.width());
81
panelRect.setWidth(panelRect.width() * 3);
84
panelRect.setLeft(panelRect.left() - panelRect.width());
89
painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt);
92
const int y1 = opt.rect.top() + 6;
93
const int y2 = opt.rect.bottom() - 6;
94
if (mGroupPosition & GroupRight) {
95
const int x = opt.rect.left();
96
painter.setPen(opt.palette.color(QPalette::Light));
97
painter.drawLine(x, y1, x, y2);
99
if (mGroupPosition & GroupLeft) {
100
const int x = opt.rect.right();
101
painter.setPen(opt.palette.color(QPalette::Mid));
102
painter.drawLine(x, y1, x, y2);
106
painter.drawControl(QStyle::CE_ToolButtonLabel, opt);
108
// Filtering message on tooltip text for CJK to remove accelerators.
109
// Quoting ktoolbar.cpp:
111
// CJK languages use more verbose accelerator marker: they add a Latin
112
// letter in parenthesis, and put accelerator on that. Hence, the default
113
// removal of ampersand only may not be enough there, instead the whole
114
// parenthesis construct should be removed. Provide these filtering i18n
115
// messages so that translators can use Transcript for custom removal.
117
if (!actions().isEmpty()) {
118
QAction* action = actions().first();
119
setToolTip(i18nc("@info:tooltip of custom toolbar button", "%1", action->toolTip()));