~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to lib/statusbartoolbutton.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
2
2
/*
3
3
Gwenview: an image viewer
4
4
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
30
30
// KDE
31
31
#include <klocale.h>
32
32
 
33
 
namespace Gwenview {
34
 
 
 
33
namespace Gwenview
 
34
{
35
35
 
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);
42
 
}
43
 
 
44
 
 
45
 
QSize StatusBarToolButton::minimumSizeHint() const {
46
 
        return sizeHint();
47
 
}
48
 
 
49
 
 
50
 
QSize StatusBarToolButton::sizeHint() const {
51
 
        QSize sh = QToolButton::sizeHint();
52
 
        sh.setHeight(fontMetrics().height());
53
 
        return sh;
54
 
}
55
 
 
56
 
 
57
 
void StatusBarToolButton::setGroupPosition(StatusBarToolButton::GroupPosition groupPosition) {
58
 
        mGroupPosition = groupPosition;
59
 
}
60
 
 
61
 
 
62
 
void StatusBarToolButton::paintEvent(QPaintEvent* event) {
63
 
        if (mGroupPosition == NotGrouped) {
64
 
                QToolButton::paintEvent(event);
65
 
                return;
66
 
        }
67
 
        QStylePainter painter(this);
68
 
        QStyleOptionToolButton opt;
69
 
        initStyleOption(&opt);
70
 
        QStyleOptionToolButton panelOpt = opt;
71
 
 
72
 
        // Panel
73
 
        QRect& panelRect = panelOpt.rect;
74
 
        switch (mGroupPosition) {
75
 
        case GroupLeft:
76
 
                panelRect.setWidth(panelRect.width() * 2);
77
 
                break;
78
 
        case GroupCenter:
79
 
                panelRect.setLeft(panelRect.left() - panelRect.width());
80
 
                panelRect.setWidth(panelRect.width() * 3);
81
 
                break;
82
 
        case GroupRight:
83
 
                panelRect.setLeft(panelRect.left() - panelRect.width());
84
 
                break;
85
 
        case NotGrouped:
86
 
                Q_ASSERT(0);
87
 
        }
88
 
        painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt);
89
 
 
90
 
        // Separator
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);
97
 
        }
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);
102
 
        }
103
 
 
104
 
        // Text
105
 
        painter.drawControl(QStyle::CE_ToolButtonLabel, opt);
106
 
 
107
 
        // Filtering message on tooltip text for CJK to remove accelerators.
108
 
        // Quoting ktoolbar.cpp:
109
 
        // """
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.
115
 
        // """
116
 
        if (!actions().isEmpty()) {
117
 
                QAction* action = actions().first();
118
 
                setToolTip(i18nc("@info:tooltip of custom toolbar button", "%1", action->toolTip()));
119
 
        }
120
 
}
121
 
 
 
38
, mGroupPosition(NotGrouped)
 
39
{
 
40
    setToolButtonStyle(Qt::ToolButtonTextOnly);
 
41
    setFocusPolicy(Qt::NoFocus);
 
42
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
 
43
}
 
44
 
 
45
QSize StatusBarToolButton::minimumSizeHint() const
 
46
{
 
47
    return sizeHint();
 
48
}
 
49
 
 
50
QSize StatusBarToolButton::sizeHint() const
 
51
{
 
52
    QSize sh = QToolButton::sizeHint();
 
53
    sh.setHeight(fontMetrics().height());
 
54
    return sh;
 
55
}
 
56
 
 
57
void StatusBarToolButton::setGroupPosition(StatusBarToolButton::GroupPosition groupPosition)
 
58
{
 
59
    mGroupPosition = groupPosition;
 
60
}
 
61
 
 
62
void StatusBarToolButton::paintEvent(QPaintEvent* event)
 
63
{
 
64
    if (mGroupPosition == NotGrouped) {
 
65
        QToolButton::paintEvent(event);
 
66
        return;
 
67
    }
 
68
    QStylePainter painter(this);
 
69
    QStyleOptionToolButton opt;
 
70
    initStyleOption(&opt);
 
71
    QStyleOptionToolButton panelOpt = opt;
 
72
 
 
73
    // Panel
 
74
    QRect& panelRect = panelOpt.rect;
 
75
    switch (mGroupPosition) {
 
76
    case GroupLeft:
 
77
        panelRect.setWidth(panelRect.width() * 2);
 
78
        break;
 
79
    case GroupCenter:
 
80
        panelRect.setLeft(panelRect.left() - panelRect.width());
 
81
        panelRect.setWidth(panelRect.width() * 3);
 
82
        break;
 
83
    case GroupRight:
 
84
        panelRect.setLeft(panelRect.left() - panelRect.width());
 
85
        break;
 
86
    case NotGrouped:
 
87
        Q_ASSERT(0);
 
88
    }
 
89
    painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt);
 
90
 
 
91
    // Separator
 
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);
 
98
    }
 
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);
 
103
    }
 
104
 
 
105
    // Text
 
106
    painter.drawControl(QStyle::CE_ToolButtonLabel, opt);
 
107
 
 
108
    // Filtering message on tooltip text for CJK to remove accelerators.
 
109
    // Quoting ktoolbar.cpp:
 
110
    // """
 
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.
 
116
    // """
 
117
    if (!actions().isEmpty()) {
 
118
        QAction* action = actions().first();
 
119
        setToolTip(i18nc("@info:tooltip of custom toolbar button", "%1", action->toolTip()));
 
120
    }
 
121
}
122
122
 
123
123
} // namespace