Krita Source Code Documentation
Loading...
Searching...
No Matches
KoGroupButton Class Reference

#include <KoGroupButton.h>

+ Inheritance diagram for KoGroupButton:

Public Types

enum  GroupPosition { NoGroup , GroupLeft , GroupRight , GroupCenter }
 

Public Member Functions

KoGroupButton::GroupPosition groupPosition () const
 
 KoGroupButton (GroupPosition position, QWidget *parent=0)
 
 KoGroupButton (QWidget *parent=0)
 
 Private (KoGroupButton *qq, const GroupPosition position)
 
void setGroupPosition (KoGroupButton::GroupPosition groupPosition)
 
 ~KoGroupButton () override
 
- Public Member Functions inherited from KisHighlightedToolButton
void changeEvent (QEvent *event) override
 
 KisHighlightedToolButton (QWidget *parent=0)
 

Public Attributes

GroupPosition groupPosition
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 
- Protected Member Functions inherited from KisHighlightedToolButton
void checkStateSet () override
 
void nextCheckState () override
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

A thin tool button which can be visually grouped with other buttons.

The group can thus look like one solid bar: ( button1 | button2 | button3 )

For grouping layout can be used. For exclusive checkable behaviour assign QButtonGroup on the buttons.

Definition at line 16 of file KoGroupButton.cpp.

Member Enumeration Documentation

◆ GroupPosition

Position of the button within the button group what affects the appearance.

Enumerator
NoGroup 

No particular position, gives the button unchanged appearance.

GroupLeft 

The button is at the left of the group, so it would have rounded the left part.

GroupRight 

The button is at the right of the group, so it would have rounded the right part.

GroupCenter 

The button is on the center of the group, so it would have separators on both sides.

Definition at line 31 of file KoGroupButton.h.

31 {
32 NoGroup,
33 GroupLeft,
36 };
@ GroupLeft
The button is at the left of the group, so it would have rounded the left part.
@ GroupRight
The button is at the right of the group, so it would have rounded the right part.
@ GroupCenter
The button is on the center of the group, so it would have separators on both sides.
@ NoGroup
No particular position, gives the button unchanged appearance.

Constructor & Destructor Documentation

◆ KoGroupButton() [1/2]

KoGroupButton::KoGroupButton ( GroupPosition position,
QWidget * parent = 0 )
explicit

Definition at line 28 of file KoGroupButton.cpp.

29 : KisHighlightedToolButton(parent), d(new Private(this, position))
30{
31}
KisHighlightedToolButton(QWidget *parent=0)
Private *const d

◆ KoGroupButton() [2/2]

KoGroupButton::KoGroupButton ( QWidget * parent = 0)
explicit

Creates button with no NoGroup position.

Definition at line 33 of file KoGroupButton.cpp.

34 : KisHighlightedToolButton(parent), d(new Private(this, NoGroup))
35{
36}

◆ ~KoGroupButton()

KoGroupButton::~KoGroupButton ( )
override

Definition at line 38 of file KoGroupButton.cpp.

39{
40 delete d;
41}

References d.

Member Function Documentation

◆ groupPosition()

KoGroupButton::GroupPosition KoGroupButton::groupPosition ( ) const

◆ paintEvent()

void KoGroupButton::paintEvent ( QPaintEvent * event)
overrideprotected
Todo
make specific fixes for styles such as Cleanlooks if there's practical no alternative

Definition at line 53 of file KoGroupButton.cpp.

54{
55 if (groupPosition() == NoGroup) {
56 QToolButton::paintEvent(event);
57 return;
58 }
59 QStylePainter painter(this);
60 QStyleOptionToolButton opt;
61 initStyleOption(&opt);
62 QStyleOptionToolButton panelOpt = opt;
63
64 // Panel
65 QRect& panelRect = panelOpt.rect;
66 switch (groupPosition()) {
67 case GroupLeft:
68 panelRect.setWidth(panelRect.width() * 2);
69 break;
70 case GroupCenter:
71 panelRect.setLeft(panelRect.left() - panelRect.width());
72 panelRect.setWidth(panelRect.width() * 3);
73 break;
74 case GroupRight:
75 panelRect.setLeft(panelRect.left() - panelRect.width());
76 break;
77 case NoGroup:
78 Q_ASSERT(0);
79 }
80 if (autoRaise()) {
81 if (!isChecked() && !isDown() && !(panelOpt.state & QStyle::State_MouseOver)) {
82 // Use 'pushed' appearance for all buttons, but those that are not really pushed
83 // are drawn with less contrast and are toned down.
84 panelOpt.state |= (QStyle::State_On | QStyle::State_Sunken);
85 QPalette panelPal(panelOpt.palette);
86 QColor c;
87 c = panelPal.color(QPalette::Button);
88 c.setAlpha(50);
89 panelPal.setColor(QPalette::Button, c);
90 c = panelPal.color(QPalette::Window);
91 c.setAlpha(50);
92 panelPal.setColor(QPalette::Window, c);
93 panelOpt.palette = panelPal;
94 painter.setOpacity(0.5);
95 }
96 } else {
97
98 if (!isChecked() && !isDown() && !(panelOpt.state & QStyle::State_MouseOver)) {
99
100 } else {
101 // only highlight the selected item
102 panelOpt.state |= (QStyle::State_On | QStyle::State_Sunken);
103 QPalette panelPal(panelOpt.palette);
104 QColor c;
105 c = panelPal.color(QPalette::Button);
106 c.setAlpha(50);
107 panelPal.setColor(QPalette::Button, c);
108 c = panelPal.color(QPalette::Window);
109 c.setAlpha(50);
110 panelPal.setColor(QPalette::Window, c);
111 panelOpt.palette = panelPal;
112 painter.setOpacity(0.5);
113 }
114 }
115
116
117 painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt);
118 painter.setOpacity(1.0);
119
120 // Separator
122 const int y1 = opt.rect.top() + 1;
123 const int y2 = opt.rect.bottom() - 1;
124 painter.setOpacity(0.4);
125 if (d->groupPosition != GroupRight) {
126 const int x = opt.rect.right();
127 painter.setPen(QPen(opt.palette.color(QPalette::Dark), 0));
128 painter.drawLine(x, y1, x, y2);
129 }
130 painter.setOpacity(1.0);
131
132 // Text
133 painter.drawControl(QStyle::CE_ToolButtonLabel, opt);
134
135 // Filtering message on tooltip text for CJK to remove accelerators.
136 // Quoting ktoolbar.cpp:
137 // """
138 // CJK languages use more verbose accelerator marker: they add a Latin
139 // letter in parenthesis, and put accelerator on that. Hence, the default
140 // removal of ampersand only may not be enough there, instead the whole
141 // parenthesis construct should be removed. Provide these filtering i18n
142 // messages so that translators can use Transcript for custom removal.
143 // """
144 if (!actions().isEmpty()) {
145 QAction* action = actions().first();
146 setToolTip(i18nc("@info:tooltip of custom triple button", "%1", action->toolTip()));
147 }
148}
GroupPosition groupPosition

References d, GroupCenter, GroupLeft, groupPosition, GroupRight, and NoGroup.

◆ Private()

KoGroupButton::Private ( KoGroupButton * qq,
const GroupPosition position )
inline

Definition at line 19 of file KoGroupButton.cpp.

19 : groupPosition(position)
20 {
21 // Make the policy closer to QPushButton's default but horizontal shouldn't be Fixed,
22 // otherwise spacing gets broken
23 qq->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
24 }

◆ setGroupPosition()

void KoGroupButton::setGroupPosition ( KoGroupButton::GroupPosition groupPosition)

Definition at line 43 of file KoGroupButton.cpp.

44{
45 d->groupPosition = groupPosition;
46}

References d, and groupPosition.

Member Data Documentation

◆ d

Private* const KoGroupButton::d
private

Definition at line 56 of file KoGroupButton.h.

◆ groupPosition

GroupPosition KoGroupButton::groupPosition
readwrite

Definition at line 25 of file KoGroupButton.cpp.


The documentation for this class was generated from the following files: