Krita Source Code Documentation
Loading...
Searching...
No Matches
KoToolBoxButton.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Friedrich W. H. Kossebau <kossebau@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "KoToolBoxButton_p.h"
8
9#include <kis_debug.h>
10
11#include <KoToolManager.h>
12#include <QAction>
13#include <QPalette>
14#include <QApplication>
15#include <klocalizedstring.h>
16#include <QKeySequence>
17#include <KoIcon.h>
18
20 : QToolButton(parent)
21 , m_toolAction(toolAction)
22{
23 setObjectName(m_toolAction->id());
24 // ensure same L&F
25 setCheckable(true);
26 setAutoRaise(true);
27 setIcon(kisIcon(m_toolAction->iconName()));
28
29 // only a fallback
30 setToolTip(m_toolAction->toolTip());
31
32 connect(this, SIGNAL(clicked(bool)), m_toolAction, SLOT(trigger()));
33}
34
35void KoToolBoxButton::attachAction(QAction *action)
36{
37 if (!action) {
38 return;
39 }
40
41 connect(action, SIGNAL(changed()), SLOT(slotUpdateActionData()));
43}
44
46{
47 QPalette p = qApp->palette();
48 if (isChecked()) {
49 QPalette palette_highlight(p);
50 QColor c = p.color(QPalette::Highlight);
51 palette_highlight.setColor(QPalette::Button, c);
52 setPalette(palette_highlight);
53 }
54 else {
55 setPalette(p);
56 }
57}
58
60{
61 if (!action) {
62 warnUI << "No tool action available, using fallback!";
63 setToolTip(m_toolAction->toolTip());
64 return;
65 }
66 setToolTip(action->toolTip());
67}
68
70{
71 QAction *action = qobject_cast<QAction*>(sender());
72 if (action) {
74 }
75}
const Params2D p
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QString iconName() const
The icon name of the tool.
QString toolTip() const
The tooltip of the tool.
QString id() const
The id of the tool.
void setDataFromToolAction(QAction *action)
KoToolBoxButton(KoToolAction *toolAction, QWidget *parent)
void attachAction(QAction *action)
KoToolAction * m_toolAction
#define warnUI
Definition kis_debug.h:94
#define kisIcon(name)
Definition kis_icon.h:26