1 #include "pushbutton.hpp"
2
3 #include <QMouseEvent>
4 #include <QKeyEvent>
5
6 #include "../../model/prefs/state.hpp"
7 #include "../../model/prefs/shortcutmanager.hpp"
8
processShortcuts()9 void CSVWidget::PushButton::processShortcuts()
10 {
11 mProcessedToolTip = CSMPrefs::State::get().getShortcutManager().processToolTip(mToolTip);
12 }
13
setExtendedToolTip()14 void CSVWidget::PushButton::setExtendedToolTip()
15 {
16 QString tooltip = mProcessedToolTip;
17
18 if (tooltip.isEmpty())
19 tooltip = "(Tool tip not implemented yet)";
20
21 switch (mType)
22 {
23 case Type_TopMode:
24
25 tooltip +=
26 "<p>(left click to change mode)";
27
28 break;
29
30 case Type_TopAction:
31
32 break;
33
34 case Type_Mode:
35
36 tooltip +=
37 "<p>(left click to activate,"
38 "<br>shift-left click to activate and keep panel open)";
39
40 break;
41
42 case Type_Toggle:
43
44 tooltip += "<p>(left click to ";
45 tooltip += isChecked() ? "disable" : "enable";
46 tooltip += "<p>shift-left click to ";
47 tooltip += isChecked() ? "disable" : "enable";
48 tooltip += " and keep panel open)";
49
50 break;
51 }
52
53 setToolTip (tooltip);
54 }
55
keyPressEvent(QKeyEvent * event)56 void CSVWidget::PushButton::keyPressEvent (QKeyEvent *event)
57 {
58 if (event->key()!=Qt::Key_Shift)
59 mKeepOpen = false;
60
61 QPushButton::keyPressEvent (event);
62 }
63
keyReleaseEvent(QKeyEvent * event)64 void CSVWidget::PushButton::keyReleaseEvent (QKeyEvent *event)
65 {
66 if (event->key()==Qt::Key_Space)
67 mKeepOpen = event->modifiers() & Qt::ShiftModifier;
68
69 QPushButton::keyReleaseEvent (event);
70 }
71
mouseReleaseEvent(QMouseEvent * event)72 void CSVWidget::PushButton::mouseReleaseEvent (QMouseEvent *event)
73 {
74 mKeepOpen = event->button()==Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier);
75 QPushButton::mouseReleaseEvent (event);
76 }
77
PushButton(const QIcon & icon,Type type,const QString & tooltip,QWidget * parent)78 CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const QString& tooltip,
79 QWidget *parent)
80 : QPushButton (icon, "", parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
81 {
82 if (type==Type_Mode || type==Type_Toggle)
83 {
84 setCheckable (true);
85 connect (this, SIGNAL (toggled (bool)), this, SLOT (checkedStateChanged (bool)));
86 }
87 setCheckable (type==Type_Mode || type==Type_Toggle);
88 processShortcuts();
89 setExtendedToolTip();
90
91 connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
92 this, SLOT (settingChanged (const CSMPrefs::Setting *)));
93 }
94
PushButton(Type type,const QString & tooltip,QWidget * parent)95 CSVWidget::PushButton::PushButton (Type type, const QString& tooltip, QWidget *parent)
96 : QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
97 {
98 setCheckable (type==Type_Mode || type==Type_Toggle);
99 processShortcuts();
100 setExtendedToolTip();
101 }
102
hasKeepOpen() const103 bool CSVWidget::PushButton::hasKeepOpen() const
104 {
105 return mKeepOpen;
106 }
107
getBaseToolTip() const108 QString CSVWidget::PushButton::getBaseToolTip() const
109 {
110 return mProcessedToolTip;
111 }
112
getType() const113 CSVWidget::PushButton::Type CSVWidget::PushButton::getType() const
114 {
115 return mType;
116 }
117
checkedStateChanged(bool checked)118 void CSVWidget::PushButton::checkedStateChanged (bool checked)
119 {
120 setExtendedToolTip();
121 }
122
settingChanged(const CSMPrefs::Setting * setting)123 void CSVWidget::PushButton::settingChanged (const CSMPrefs::Setting *setting)
124 {
125 if (setting->getParent()->getKey() == "Key Bindings")
126 {
127 processShortcuts();
128 setExtendedToolTip();
129 }
130 }
131