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

#include <kcheckaccelerators.h>

+ Inheritance diagram for KisKCheckAccelerators:

Public Member Functions

bool eventFilter (QObject *, QEvent *e) override
 
 KisKCheckAccelerators (QObject *parent, int key, bool autoCheck, bool copyWidgetText)
 

Private Slots

void autoCheckSlot ()
 
void slotDisableCheck (bool)
 

Private Member Functions

void checkAccelerators (bool automatic)
 
void createDialog (QWidget *parent, bool automatic)
 

Private Attributes

bool alwaysShow {false}
 
bool autoCheck {false}
 
QTimer autoCheckTimer
 
bool block {false}
 
bool copyWidgetText {false}
 
QString copyWidgetTextCommand
 
QPointer< QDialog > drklash
 
QTextBrowser * drklash_view {nullptr}
 
int key {0}
 

Detailed Description

Definition at line 67 of file kcheckaccelerators.h.

Constructor & Destructor Documentation

◆ KisKCheckAccelerators()

KisKCheckAccelerators::KisKCheckAccelerators ( QObject * parent,
int key,
bool autoCheck,
bool copyWidgetText )

Definition at line 79 of file kcheckaccelerators.cpp.

80 : QObject(parent)
81 , key(key_)
82 , autoCheck(autoCheck_)
83 , copyWidgetText(copyWidgetText_)
84 , drklash(nullptr)
85{
86 setObjectName(QStringLiteral("kapp_accel_filter"));
87
88 KConfigGroup cg(KSharedConfig::openConfig(), "Development");
89 alwaysShow = cg.readEntry("AlwaysShowCheckAccelerators", false);
90 copyWidgetTextCommand = cg.readEntry("CopyWidgetTextCommand", QString());
91
92 parent->installEventFilter(this);
93 connect(&autoCheckTimer, SIGNAL(timeout()), SLOT(autoCheckSlot()));
94}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QPointer< QDialog > drklash
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References connect().

Member Function Documentation

◆ autoCheckSlot

void KisKCheckAccelerators::autoCheckSlot ( )
privateslot

Definition at line 195 of file kcheckaccelerators.cpp.

196{
197 if (block) {
198 autoCheckTimer.setSingleShot(true);
199 autoCheckTimer.start(20);
200 return;
201 }
202 block = true;
204 block = false;
205}
void checkAccelerators(bool automatic)

References alwaysShow, autoCheckTimer, block, and checkAccelerators().

◆ checkAccelerators()

void KisKCheckAccelerators::checkAccelerators ( bool automatic)
private

Definition at line 245 of file kcheckaccelerators.cpp.

246{
247 QWidget *actWin = qApp->activeWindow();
248 if (!actWin) {
249 return;
250 }
251
252 KAcceleratorManager::manage(actWin);
253 QString a, c, r;
254 KAcceleratorManager::last_manage(a, c, r);
255
256 if (automatic) { // for now we only show dialogs on F12 checks
257 return;
258 }
259
260 if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty())) {
261 return;
262 }
263
264 QString s;
265
266 if (! c.isEmpty()) {
267 s += i18n("<h2>Accelerators changed</h2>");
268 s += QStringLiteral("<table border><tr><th><b>");
269 s += i18n("Old Text");
270 s += QStringLiteral("</b></th><th><b>");
271 s += i18n("New Text");
272 s += QStringLiteral("</b></th></tr>");
273 s += c;
274 s += QStringLiteral("</table>");
275 }
276
277 if (! r.isEmpty()) {
278 s += i18n("<h2>Accelerators removed</h2>");
279 s += QStringLiteral("<table border><tr><th><b>");
280 s += i18n("Old Text");
281 s += QStringLiteral("</b></th></tr>");
282 s += r;
283 s += QStringLiteral("</table>");
284 }
285
286 if (! a.isEmpty()) {
287 s += i18n("<h2>Accelerators added (just for your info)</h2>");
288 s += QStringLiteral("<table border><tr><th><b>");
289 s += i18n("New Text");
290 s += QStringLiteral("</b></th></tr>");
291 s += a;
292 s += QStringLiteral("</table>");
293 }
294
295 createDialog(actWin, automatic);
296 drklash_view->setHtml(s);
297 drklash->show();
298 drklash->raise();
299
300 // dlg will be destroyed before returning
301}
void createDialog(QWidget *parent, bool automatic)

References createDialog(), drklash, and drklash_view.

◆ createDialog()

void KisKCheckAccelerators::createDialog ( QWidget * parent,
bool automatic )
private

Definition at line 207 of file kcheckaccelerators.cpp.

208{
209 if (drklash) {
210 return;
211 }
212
213 drklash = new QDialog(actWin);
214 drklash->setAttribute(Qt::WA_DeleteOnClose);
215 drklash->setObjectName(QStringLiteral("kapp_accel_check_dlg"));
216 drklash->setWindowTitle(i18nc("@title:window", "Dr. Klash' Accelerator Diagnosis"));
217 drklash->resize(500, 460);
218 QVBoxLayout *layout = new QVBoxLayout(drklash);
219 drklash_view = new QTextBrowser(drklash);
220 layout->addWidget(drklash_view);
221 QCheckBox *disableAutoCheck = 0;
222 if (automatic) {
223 disableAutoCheck = new QCheckBox(i18nc("@option:check", "Disable automatic checking"), drklash);
224 connect(disableAutoCheck, SIGNAL(toggled(bool)), SLOT(slotDisableCheck(bool)));
225 layout->addWidget(disableAutoCheck);
226 }
227 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, drklash);
228 layout->addWidget(buttonBox);
229 connect(buttonBox, SIGNAL(rejected()), drklash, SLOT(close()));
230 if (disableAutoCheck) {
231 disableAutoCheck->setFocus();
232 } else {
233 drklash_view->setFocus();
234 }
235}
QAction * close(const QObject *recvr, const char *slot, QObject *parent)

References connect(), drklash, drklash_view, and slotDisableCheck().

◆ eventFilter()

bool KisKCheckAccelerators::eventFilter ( QObject * obj,
QEvent * e )
override

Re-implemented to filter the parent's events.

Definition at line 96 of file kcheckaccelerators.cpp.

97{
98 if (block) {
99 return false;
100 }
101
102 switch (e->type()) { // just simplify debugging
103 case QEvent::ShortcutOverride:
104 if (key && (static_cast<QKeyEvent *>(e)->key() == key)) {
105 block = true;
106 checkAccelerators(false);
107 block = false;
108 e->accept();
109 return true;
110 }
111 break;
112 case QEvent::ChildAdded:
113 case QEvent::ChildRemoved:
114 // Only care about widgets; this also avoids starting the timer in other threads
115 if (!static_cast<QChildEvent *>(e)->child()->isWidgetType()) {
116 break;
117 }
118 Q_FALLTHROUGH();
119 case QEvent::Resize:
120 case QEvent::LayoutRequest:
121 case QEvent::WindowActivate:
122 case QEvent::WindowDeactivate:
123 if (autoCheck) {
124 autoCheckTimer.setSingleShot(true);
125 autoCheckTimer.start(20); // 20 ms
126 }
127 break;
128 //case QEvent::MouseButtonDblClick:
129 case QEvent::MouseButtonPress:
130 if (copyWidgetText && static_cast<QMouseEvent *>(e)->button() == Qt::MiddleButton) {
131 //kWarning()<<"obj"<<obj;
132 QWidget *w = static_cast<QWidget *>(obj)->childAt(static_cast<QMouseEvent *>(e)->pos());
133 if (!w) {
134 w = static_cast<QWidget *>(obj);
135 }
136 if (!w) {
137 return false;
138 }
139 //kWarning()<<"MouseButtonDblClick"<<w;
140 QString text;
141 if (qobject_cast<QLabel *>(w)) {
142 text = static_cast<QLabel *>(w)->text();
143 } else if (qobject_cast<QAbstractButton *>(w)) {
144 text = static_cast<QAbstractButton *>(w)->text();
145 } else if (qobject_cast<QComboBox *>(w)) {
146 text = static_cast<QComboBox *>(w)->currentText();
147 } else if (qobject_cast<QTabBar *>(w)) {
148 text = static_cast<QTabBar *>(w)->tabText(static_cast<QTabBar *>(w)->tabAt(static_cast<QMouseEvent *>(e)->pos()));
149 } else if (qobject_cast<QGroupBox *>(w)) {
150 text = static_cast<QGroupBox *>(w)->title();
151 } else if (qobject_cast<QMenu *>(obj)) {
152 QAction *a = static_cast<QMenu *>(obj)->actionAt(static_cast<QMouseEvent *>(e)->pos());
153 if (!a) {
154 return false;
155 }
156 text = a->text();
157 if (text.isEmpty()) {
158 text = a->iconText();
159 }
160 }
161 if (text.isEmpty()) {
162 return false;
163 }
164
165 if (static_cast<QMouseEvent *>(e)->modifiers() == Qt::ControlModifier) {
166 text.remove(QChar::fromLatin1('&'));
167 }
168
169 //kWarning()<<KGlobal::activeComponent().catalogName()<<text;
170 if (copyWidgetTextCommand.isEmpty()) {
171 QClipboard *clipboard = QApplication::clipboard();
172 clipboard->setText(text);
173 } else {
174 QProcess *script = new QProcess(this);
175 script->start(copyWidgetTextCommand.arg(text, QFile::decodeName(KLocalizedString::applicationDomain())), QStringList());
176 connect(script, SIGNAL(finished(int,QProcess::ExitStatus)), script, SLOT(deleteLater()));
177 }
178 e->accept();
179 return true;
180
181 //kWarning()<<"MouseButtonDblClick"<<static_cast<QWidget*>(obj)->childAt(static_cast<QMouseEvent*>(e)->globalPos());
182 }
183 return false;
184 case QEvent::Timer:
185 case QEvent::MouseMove:
186 case QEvent::Paint:
187 return false;
188 default:
189 // qDebug() << "KisKCheckAccelerators::eventFilter " << e->type() << " " << autoCheck;
190 break;
191 }
192 return false;
193}
QString button(const QWheelEvent &ev)

References autoCheck, autoCheckTimer, block, button(), checkAccelerators(), connect(), copyWidgetText, copyWidgetTextCommand, and key.

◆ slotDisableCheck

void KisKCheckAccelerators::slotDisableCheck ( bool on)
privateslot

Definition at line 237 of file kcheckaccelerators.cpp.

238{
239 autoCheck = !on;
240 if (!on) {
242 }
243}

References autoCheck, and autoCheckSlot().

Member Data Documentation

◆ alwaysShow

bool KisKCheckAccelerators::alwaysShow {false}
private

Definition at line 81 of file kcheckaccelerators.h.

81{false};

◆ autoCheck

bool KisKCheckAccelerators::autoCheck {false}
private

Definition at line 82 of file kcheckaccelerators.h.

82{false};

◆ autoCheckTimer

QTimer KisKCheckAccelerators::autoCheckTimer
private

Definition at line 87 of file kcheckaccelerators.h.

◆ block

bool KisKCheckAccelerators::block {false}
private

Definition at line 80 of file kcheckaccelerators.h.

80{false};

◆ copyWidgetText

bool KisKCheckAccelerators::copyWidgetText {false}
private

Definition at line 84 of file kcheckaccelerators.h.

84{false};

◆ copyWidgetTextCommand

QString KisKCheckAccelerators::copyWidgetTextCommand
private

Definition at line 85 of file kcheckaccelerators.h.

◆ drklash

QPointer<QDialog> KisKCheckAccelerators::drklash
private

Definition at line 89 of file kcheckaccelerators.h.

◆ drklash_view

QTextBrowser* KisKCheckAccelerators::drklash_view {nullptr}
private

Definition at line 90 of file kcheckaccelerators.h.

90{nullptr};

◆ key

int KisKCheckAccelerators::key {0}
private

Definition at line 79 of file kcheckaccelerators.h.

79{0};

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