summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-12-21 10:41:15 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2012-12-21 10:41:15 +0100
commitfc0e7683878ac10eb9a4675f61e6443a13ced946 (patch)
tree317a57f0b1f7a1654d39c6bed4378c46934777cb
parent01ea1cb9ca4547c406ce0ed72b3f5f6ce18d91d9 (diff)
Implemented new shortcut key system. Fade in/out shortcut tooltips. Close pcpviewer on window close due to commit/nocommit/discard actions.
-rw-r--r--client/client.pro2
-rw-r--r--client/macrowindow.h4
-rw-r--r--client/mainwindow.cc8
-rw-r--r--client/pracro.ini2
-rw-r--r--client/shortcuttooltip.cc98
-rw-r--r--client/shortcuttooltip.h50
-rw-r--r--client/widgets/altcombobox.cc4
-rw-r--r--client/widgets/button.cc20
-rw-r--r--client/widgets/button.h1
-rw-r--r--client/widgets/checkbox.cc10
-rw-r--r--client/widgets/checkbox.h2
-rw-r--r--client/widgets/checkgroupbox.cc18
-rw-r--r--client/widgets/combobox.cc8
-rw-r--r--client/widgets/datetime.cc2
-rw-r--r--client/widgets/frame.cc2
-rw-r--r--client/widgets/groupbox.cc2
-rw-r--r--client/widgets/label.cc2
-rw-r--r--client/widgets/lineedit.cc7
-rw-r--r--client/widgets/listbox.cc2
-rw-r--r--client/widgets/metawidget.cc2
-rw-r--r--client/widgets/multilist.cc5
-rw-r--r--client/widgets/radiobutton.cc5
-rw-r--r--client/widgets/radiobutton.h1
-rw-r--r--client/widgets/radiobuttons.cc2
-rw-r--r--client/widgets/textedit.cc7
-rw-r--r--client/widgets/widget.cc91
-rw-r--r--client/widgets/widget.h16
-rw-r--r--client/widgets/window.cc16
28 files changed, 345 insertions, 44 deletions
diff --git a/client/client.pro b/client/client.pro
index 893d25d..b41c835 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -51,6 +51,7 @@ HEADERS += \
praxisd.h \
resumewidget.h \
template.h \
+ shortcuttooltip.h \
widgets.h \
expandbutton.h \
aboutbox.h \
@@ -99,6 +100,7 @@ SOURCES += \
praxisd.cc \
resumewidget.cc \
template.cc \
+ shortcuttooltip.cc \
expandbutton.cc \
aboutbox.cc \
pcpviewer/pcpviewer.cc \
diff --git a/client/macrowindow.h b/client/macrowindow.h
index 65a0d87..a5a81c5 100644
--- a/client/macrowindow.h
+++ b/client/macrowindow.h
@@ -93,8 +93,10 @@ private:
bool is_static;
- MacroDrawer *drawer;
QWidget *scrollarea;
+
+public:
+ MacroDrawer *drawer;
};
#endif/*__PRACRO_MACROWINDOW_H__*/
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index 9436f41..bd8055e 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -122,10 +122,13 @@ MainWindow::MainWindow(QString patientid, QString title, QString course,
QToolBar *toolbar = addToolBar("controls");
toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QAction *close_commit = toolbar->addAction(tr("Close and commit"));
+ close_commit->setShortcut(QKeySequence(tr("Ctrl+Alt+S")));
close_commit->setIcon(QPixmap(":icons/icon_close_commit.png"));
QAction *close_no_commit = toolbar->addAction(tr("Close no commit"));
close_no_commit->setIcon(QPixmap(":icons/icon_close_no_commit.png"));
+ close_no_commit->setShortcut(QKeySequence(tr("Ctrl+Alt+X")));
+
/*
QAction *close_discard = toolbar->addAction("Close discard");
close_discard->setIcon(QPixmap(":icons/icon_discard.png"));
@@ -233,6 +236,11 @@ void MainWindow::closeDiscard()
void MainWindow::closeEvent(QCloseEvent *event)
{
+ if(closing) {
+ emit isClosing();
+ return;
+ }
+
if(hasOpen(NULL)) {
MessageBox::warning(this, "Close first.", "Close open macros first.");
event->ignore();
diff --git a/client/pracro.ini b/client/pracro.ini
index 25fd0bf..ff929c0 100644
--- a/client/pracro.ini
+++ b/client/pracro.ini
@@ -1,4 +1,4 @@
[server]
-#host=pracserv.j.auh.dk
host=localhost
+#host=pracrod.j.auh.dk
port=12345
diff --git a/client/shortcuttooltip.cc b/client/shortcuttooltip.cc
new file mode 100644
index 0000000..f88ddcd
--- /dev/null
+++ b/client/shortcuttooltip.cc
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * shortcuttooltip.cc
+ *
+ * Thu Dec 20 14:17:03 CET 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "shortcuttooltip.h"
+
+#include <QPalette>
+
+ShortcutTooltip::ShortcutTooltip(QString label, QWidget *parent)
+ : QLabel(label, parent)
+{
+ resize(minimumSizeHint());
+ // shortcut_label->setWindowFlags(Qt::ToolTip);
+ QFont f = font();
+ f.setPixelSize(9);
+ setFont(f);
+
+ setAutoFillBackground(true);
+ // shortcut_label->setMargin(4);
+
+ alpha = 0;
+
+ QPalette pal = palette();
+ pal.setColor(foregroundRole(), QColor(0,0,0, alpha));
+ pal.setColor(backgroundRole(), QColor(255,255,170,alpha));
+ setPalette(pal);
+
+ //shortcut_label->move(0, 0);
+ setVisible(false);
+
+ connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.setSingleShot(true);
+}
+
+void ShortcutTooltip::setShow(bool s)
+{
+ if(s) {
+ modifier = 0.3;
+ raise();
+ setVisible(true);
+ timer.start(25);
+ } else {
+ modifier = -0.4;
+ timer.start(25);
+ }
+}
+
+void ShortcutTooltip::timeout()
+{
+ alpha += modifier;
+
+ if(modifier > 0) {
+
+ if(alpha > 1.0) {
+ alpha = 1.0;
+ } else {
+ timer.start(25);
+ }
+
+ } else {
+
+ if(alpha < 0.0) {
+ setVisible(false);
+ alpha = 0;
+ } else {
+ timer.start(25);
+ }
+
+ }
+
+ QPalette pal = palette();
+ pal.setColor(foregroundRole(), QColor(0,0,0, 255 * alpha));
+ pal.setColor(backgroundRole(), QColor(255,255,170, 150 * alpha));
+ setPalette(pal);
+}
diff --git a/client/shortcuttooltip.h b/client/shortcuttooltip.h
new file mode 100644
index 0000000..632779c
--- /dev/null
+++ b/client/shortcuttooltip.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * shortcuttooltip.h
+ *
+ * Thu Dec 20 14:46:43 CET 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_SHORTCUTTOOLTIP_H__
+#define __PRACRO_SHORTCUTTOOLTIP_H__
+
+#include <QLabel>
+#include <QTimer>
+
+class ShortcutTooltip : public QLabel {
+Q_OBJECT
+public:
+ ShortcutTooltip(QString label, QWidget *parent);
+
+ void setShow(bool s);
+
+private slots:
+ void timeout();
+
+private:
+ double alpha;
+ double modifier;
+ QTimer timer;
+};
+
+#endif/*__PRACRO_SHORTCUTTOOLTIP_H__*/
diff --git a/client/widgets/altcombobox.cc b/client/widgets/altcombobox.cc
index 082601a..37df5bf 100644
--- a/client/widgets/altcombobox.cc
+++ b/client/widgets/altcombobox.cc
@@ -42,9 +42,9 @@
AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
: ComboBox(node, macrowindow)
{
- combobox = (QComboBox*)widget;
+ combobox = (QComboBox*)getWidget();
frame = new QFrame();
- widget = frame;
+ setWidget(frame);
hideChildren = true;
diff --git a/client/widgets/button.cc b/client/widgets/button.cc
index 6ef6ac8..06bf594 100644
--- a/client/widgets/button.cc
+++ b/client/widgets/button.cc
@@ -30,6 +30,7 @@
#include <QPushButton>
#include "common.h"
+#include "debug.h"
#include "macrowindow.h"
@@ -37,7 +38,7 @@ Button::Button(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
button = new QPushButton();
- widget = button;
+ setWidget(button);
setCommonAttributes(button, node);
@@ -61,6 +62,17 @@ Button::Button(QDomNode &node, MacroWindow *macrowindow)
connect(this, SIGNAL(act_cancel()), macrowindow, SLOT(cancel()));
connect(macrowindow, SIGNAL(macroHasChanged()), this, SLOT(do_enable()));
}
+
+ if(elem.attribute("action") == "commit") {
+ QList<QKeySequence> lst;
+ lst << QKeySequence("Ctrl+Enter");
+ lst << QKeySequence("Ctrl+Return");
+ QAction *a = new QAction(widget_name, this);
+ a->setShortcuts(lst);
+ button->addAction(a);
+ connect(a, SIGNAL(triggered()),
+ this, SLOT(shortcutActivated()));
+ }
}
Button::~Button()
@@ -82,3 +94,9 @@ void Button::do_enable()
{
button->setEnabled(true);
}
+
+void Button::shortcutActivated()
+{
+ setKeyboardFocus();
+ button->click();
+}
diff --git a/client/widgets/button.h b/client/widgets/button.h
index d9053a6..959ecc3 100644
--- a/client/widgets/button.h
+++ b/client/widgets/button.h
@@ -63,6 +63,7 @@ public slots:
void commit();
void cancel();
void do_enable();
+ void shortcutActivated();
signals:
void act_commit();
diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc
index 7d81b1a..45f59c6 100644
--- a/client/widgets/checkbox.cc
+++ b/client/widgets/checkbox.cc
@@ -28,6 +28,8 @@
#include <QCheckBox>
+#include "debug.h"
+
#include "common.h"
#include "luawidget.h"
@@ -35,7 +37,7 @@ CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
checkbox = new QCheckBox();
- widget = checkbox;
+ setWidget(checkbox);
changedByUser = true;
@@ -128,6 +130,12 @@ void CheckBox::setWdgValid(bool valid)
checkbox->setPalette(palette);
}
+void CheckBox::shortcutActivated()
+{
+ setKeyboardFocus();
+ checkbox->click();//setChecked(!checked());
+}
+
int chk_checked(lua_State *L)
{
wdg_userdata *wdgu;
diff --git a/client/widgets/checkbox.h b/client/widgets/checkbox.h
index 5fef7cb..b888bde 100644
--- a/client/widgets/checkbox.h
+++ b/client/widgets/checkbox.h
@@ -71,6 +71,8 @@ public:
public slots:
void state_change(int);
+ void shortcutActivated();
+
private:
QString truevalue;
diff --git a/client/widgets/checkgroupbox.cc b/client/widgets/checkgroupbox.cc
index fa662e1..c118e36 100644
--- a/client/widgets/checkgroupbox.cc
+++ b/client/widgets/checkgroupbox.cc
@@ -37,7 +37,7 @@
CheckGroupBox::CheckGroupBox(QDomNode &node, MacroWindow *macrowindow)
: CheckBox(node, macrowindow)
{
- checkbox = (QCheckBox*)widget;
+ checkbox = (QCheckBox*)getWidget();
connect(this, SIGNAL(wasChanged()), this, SLOT(cgb_state_change()));
QDomElement elem = node.toElement();
@@ -46,33 +46,33 @@ CheckGroupBox::CheckGroupBox(QDomNode &node, MacroWindow *macrowindow)
if(type == "framed") {
QGroupBox *gb = new QGroupBox();
gb->setTitle(" ");
- widget = gb;
+ setWidget(gb);
} else if(type == "simple") {
- widget = new QWidget();
+ setWidget(new QWidget());
} else {
ERROR(checkgroupbox, "Illegal value of attribute 'type'\n");
return;
}
- setCommonLayout(widget, node);
- setCommonAttributes(widget, node);
+ setCommonLayout(getWidget(), node);
+ setCommonAttributes(getWidget(), node);
- checkbox->setParent(widget);
+ checkbox->setParent(getWidget());
checkbox->resize(checkbox->sizeHint().width(), 32);
checkbox->show();
if(type == "framed") {
- widget->setContentsMargins(0, 10, 0, 0);
+ getWidget()->setContentsMargins(0, 10, 0, 0);
checkbox->move(5, -9);
checkbox->setAutoFillBackground(true);
}
if(type == "simple") {
- widget->setContentsMargins(checkbox->sizeHint().width(), 0, 0, 0);
+ getWidget()->setContentsMargins(checkbox->sizeHint().width(), 0, 0, 0);
checkbox->move(0, 3);
}
- addChildren(node, widget->layout());
+ addChildren(node, getWidget()->layout());
}
CheckGroupBox::~CheckGroupBox()
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc
index 935f620..53a80e2 100644
--- a/client/widgets/combobox.cc
+++ b/client/widgets/combobox.cc
@@ -36,6 +36,7 @@
#include <QCoreApplication>
#include <QEvent>
+#include <QKeyEvent>
#include <QWheelEvent>
#include "common.h"
@@ -63,7 +64,7 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
combobox = new MyQComboBox();
- widget = combobox;
+ setWidget(combobox);
ignoreChangeEvents = false;
@@ -215,10 +216,9 @@ void ComboBox::changed()
emit eventOnChange();
}
-#include <QKeyEvent>
bool ComboBox::eventFilter(QObject *obj, QEvent *event)
{
- if(ignoreChangeEvents == true) return false;
+ if(ignoreChangeEvents == true) return Widget::eventFilter(obj, event);
if(combotype == SELECT) {
if(event->type() == QEvent::MouseButtonRelease) {
@@ -235,7 +235,7 @@ bool ComboBox::eventFilter(QObject *obj, QEvent *event)
}
}
- return QObject::eventFilter(obj, event);
+ return Widget::eventFilter(obj, event);
}
void ComboBox::changeEvent(QEvent *event)
diff --git a/client/widgets/datetime.cc b/client/widgets/datetime.cc
index f7780e2..be17278 100644
--- a/client/widgets/datetime.cc
+++ b/client/widgets/datetime.cc
@@ -34,7 +34,7 @@ DateTime::DateTime(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
datetimeedit = new QDateTimeEdit();
- widget = datetimeedit;
+ setWidget(datetimeedit);
changedByUser = true;
setCommonAttributes(datetimeedit, node);
diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc
index 076816a..23f542f 100644
--- a/client/widgets/frame.cc
+++ b/client/widgets/frame.cc
@@ -36,7 +36,7 @@ Frame::Frame(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
frame = new QFrame();
- widget = frame;
+ setWidget(frame);
setCommonAttributes(frame, node);
setCommonLayout(frame, node);
diff --git a/client/widgets/groupbox.cc b/client/widgets/groupbox.cc
index 0d720ea..ef9a7e8 100644
--- a/client/widgets/groupbox.cc
+++ b/client/widgets/groupbox.cc
@@ -38,7 +38,7 @@ GroupBox::GroupBox(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
groupbox = new QGroupBox();
- widget = groupbox;
+ setWidget(groupbox);
setCommonAttributes(groupbox, node);
setCommonLayout(groupbox, node);
diff --git a/client/widgets/label.cc b/client/widgets/label.cc
index d9a5814..453d26d 100644
--- a/client/widgets/label.cc
+++ b/client/widgets/label.cc
@@ -35,7 +35,7 @@ Label::Label(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
label = new QLabel();
- widget = label;
+ setWidget(label);
QDomElement elem = node.toElement();
diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc
index 10f1199..0dfa904 100644
--- a/client/widgets/lineedit.cc
+++ b/client/widgets/lineedit.cc
@@ -43,7 +43,7 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
lineedit = new QLineEdit();
- widget = lineedit;
+ setWidget(lineedit);
setCommonAttributes(lineedit, node);
@@ -109,7 +109,7 @@ void LineEdit::setValue(QString value, QString source)
// setInitialValue(value);
}
-bool LineEdit::eventFilter(QObject *, QEvent *event)
+bool LineEdit::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
@@ -119,7 +119,8 @@ bool LineEdit::eventFilter(QObject *, QEvent *event)
QCoreApplication::sendEvent(lineedit, &tabevent);
}
}
- return false;
+
+ return Widget::eventFilter(obj, event);
}
void LineEdit::changeEvent(QEvent *event)
diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc
index 3000f35..a301c30 100644
--- a/client/widgets/listbox.cc
+++ b/client/widgets/listbox.cc
@@ -75,7 +75,7 @@ ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
listwidget = new QListWidget();
- widget = listwidget;
+ setWidget(listwidget);
valueIsChangingByComputer = false;
diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc
index a866445..4516fa1 100644
--- a/client/widgets/metawidget.cc
+++ b/client/widgets/metawidget.cc
@@ -40,7 +40,7 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
frame = new QFrame();
- widget = frame;
+ setWidget(frame);
setCommonAttributes(frame, node);
setCommonLayout(frame, node);
diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc
index e261b52..24d3355 100644
--- a/client/widgets/multilist.cc
+++ b/client/widgets/multilist.cc
@@ -44,7 +44,7 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
frame = new QFrame();
- widget = frame;
+ setWidget(frame);
hideChildren = true;
@@ -223,7 +223,8 @@ bool MultiList::eventFilter(QObject *obj, QEvent *event)
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Delete) remove();
}
- return QObject::eventFilter(obj, event);
+
+ return Widget::eventFilter(obj, event);
}
void MultiList::setWdgValid(bool valid)
diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc
index a315577..47930d2 100644
--- a/client/widgets/radiobutton.cc
+++ b/client/widgets/radiobutton.cc
@@ -50,3 +50,8 @@ QString RadioButton::getValue()
{
return value;
}
+
+void RadioButton::shortcutActivated()
+{
+ click();
+}
diff --git a/client/widgets/radiobutton.h b/client/widgets/radiobutton.h
index 6dbae7e..1dc707e 100644
--- a/client/widgets/radiobutton.h
+++ b/client/widgets/radiobutton.h
@@ -41,6 +41,7 @@ public:
public slots:
QString getValue();
+ void shortcutActivated();
private:
QString value;
diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc
index f8b036f..c2febed 100644
--- a/client/widgets/radiobuttons.cc
+++ b/client/widgets/radiobuttons.cc
@@ -38,7 +38,7 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
frame = new QFrame();
- widget = frame;
+ setWidget(frame);
setCommonAttributes(frame, node);
setCommonLayout(frame, node);
diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc
index 96783d9..14cd0ea 100644
--- a/client/widgets/textedit.cc
+++ b/client/widgets/textedit.cc
@@ -36,7 +36,7 @@ TextEdit::TextEdit(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
textedit = new QPlainTextEdit();
- widget = textedit;
+ setWidget(textedit);
setCommonAttributes(textedit, node);
@@ -81,7 +81,7 @@ void TextEdit::setValue(QString value, QString source)
// setInitialValue(value);
}
-bool TextEdit::eventFilter(QObject *, QEvent *event)
+bool TextEdit::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
@@ -91,7 +91,8 @@ bool TextEdit::eventFilter(QObject *, QEvent *event)
}
if(keyEvent->text() != "") emit wasChanged();
}
- return false;
+
+ return Widget::eventFilter(obj, event);
}
void TextEdit::setWdgValid(bool valid)
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index a57eb78..eaf1c9c 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -28,10 +28,13 @@
#include "macrowindow.h"
#include "luawidget.h"
-
+#include "macrodrawer.h"
#include "../widgets.h"
+
#include <QLayout>
#include <QObject>
+#include <QKeySequence>
+#include <QApplication>
#include "debug.h"
@@ -69,6 +72,23 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow)
hasOnInitEvent = elem.hasAttribute("onInit");
onInitEventScript = elem.attribute("onInit", "");
+ important =
+ elem.hasAttribute("important") && elem.attribute("important") == "true";
+
+ shortcut_label = NULL;
+ shortcut_action = NULL;
+ if(elem.hasAttribute("shortcut")) {
+ QString shortcut = elem.attribute("shortcut", "");
+ DEBUG(shortcut, "New shortcut: %s [%s]\n",
+ widget_name.toStdString().c_str(),
+ shortcut.toStdString().c_str());
+ shortcut_action = new QAction(widget_name, this);
+ shortcut_action->setShortcut(QKeySequence(shortcut));
+ // addAction(a);
+ connect(shortcut_action, SIGNAL(triggered()),
+ this, SLOT(shortcutActivated()));
+ }
+
is_valid = true;
connect(this, SIGNAL(eventOnChange()),
@@ -103,6 +123,69 @@ Widget::~Widget()
delete widget;
widget = NULL;
}
+
+ if(shortcut_label) delete shortcut_label;
+}
+
+void Widget::setWidget(QWidget *widget)
+{
+ this->widget = widget;
+ if(!this->widget) return;
+
+ if(important) {
+ this->widget->setProperty("important", QString("true"));
+ }
+
+ if(shortcut_action) {
+ this->widget->addAction(shortcut_action);
+
+ QString lbl = shortcut_action->shortcut().toString();
+ shortcut_label = new ShortcutTooltip(lbl, macrowindow);
+
+ // Catch shortcut label show/hide and ESC for cancel
+ macrowindow->drawer->installEventFilter(this);
+ }
+}
+
+bool Widget::eventFilter(QObject *, QEvent *event)
+{
+ // The function of this 'p' is to determine if this particular event has
+ // been used to issue a close action.
+ // If this is in fact the case then we should not do it gain until a new
+ // event is received.
+ // It might be considered a hack, but it works...
+ static void *p = NULL;
+ if(p != event) p = NULL;
+
+ if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
+ QKeyEvent *kevent = (QKeyEvent*)event;
+
+ if(shortcut_label) {
+ bool visible =
+ (kevent->modifiers() & Qt::ControlModifier ||
+ kevent->modifiers() & Qt::AltModifier) &&
+ widget->isVisible();
+
+ shortcut_label->setShow(visible);
+ if(visible) {
+ shortcut_label->move(widget->mapTo(macrowindow, QPoint(-5,-5)));
+ }
+ }
+
+ if(event->type() == QEvent::KeyPress && kevent->key() == Qt::Key_Escape) {
+ if(!p) { // See comment above.
+ macrowindow->cancel();
+ p = event;
+ }
+ }
+ }
+
+ return false;
+}
+
+QWidget *Widget::getWidget()
+{
+ return this->widget;
}
QString Widget::name()
@@ -311,6 +394,12 @@ bool Widget::hidden()
return widget->isHidden();
}
+void Widget::shortcutActivated()
+{
+ DEBUG(shortcut, "Shortcut [%s] activated\n", name().toStdString().c_str());
+ setKeyboardFocus();
+}
+
bool Widget::setKeyboardFocus()
{
if((widget->focusPolicy() & Qt::TabFocus) != 0) {
diff --git a/client/widgets/widget.h b/client/widgets/widget.h
index f2bf278..1af20af 100644
--- a/client/widgets/widget.h
+++ b/client/widgets/widget.h
@@ -33,6 +33,8 @@
#include <QObject>
#include <QVector>
#include <QFrame>
+#include <QAction>
+#include "shortcuttooltip.h"
#include "lua.h"
@@ -130,6 +132,8 @@ public:
virtual void setValues();
+ bool eventFilter(QObject *obj, QEvent *event);
+
signals:
void wasChanged();
@@ -143,9 +147,12 @@ public slots:
void childWasChanged();
void runEventOnChange(bool deep = false);
void runEventOnInit(bool deep = false);
+ virtual void shortcutActivated();
protected:
- QWidget *widget;
+ void setWidget(QWidget *widget);
+ QWidget *getWidget();
+
bool hideChildren;
// Implement in subclasses to be able to block commits.
@@ -180,7 +187,14 @@ protected:
bool hasOnInitEvent;
QString onInitEventScript;
+ QAction *shortcut_action;
+
QFrame *replwidget;
+
+private:
+ QWidget *widget;
+ bool important;
+ ShortcutTooltip *shortcut_label;
};
/***
diff --git a/client/widgets/window.cc b/client/widgets/window.cc
index 7aa6374..6f879a8 100644
--- a/client/widgets/window.cc
+++ b/client/widgets/window.cc
@@ -33,29 +33,29 @@
Window::Window(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
- widget = new QWidget(NULL);
+ setWidget(new QWidget(NULL));
- widget->setWindowFlags(Qt::WindowContextHelpButtonHint |
+ getWidget()->setWindowFlags(Qt::WindowContextHelpButtonHint |
Qt::WindowSystemMenuHint);
- widget->setWindowIcon(QIcon(":/icons/icon.png"));
+ getWidget()->setWindowIcon(QIcon(":/icons/icon.png"));
- setCommonAttributes(widget, node);
- setCommonLayout(widget, node);
+ setCommonAttributes(getWidget(), node);
+ setCommonLayout(getWidget(), node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("fixed")) {
if(elem.attribute("fixed") == "true") {
- widget->setFixedSize(widget->width(), widget->height());
+ getWidget()->setFixedSize(getWidget()->width(), getWidget()->height());
}
}
if(elem.hasAttribute("caption")) {
- widget->setWindowTitle(elem.attribute("caption"));
+ getWidget()->setWindowTitle(elem.attribute("caption"));
}
- addChildren(node, widget->layout());
+ addChildren(node, getWidget()->layout());
}
Window::~Window()