just unselect 'listen ...' entry when edited by user
[presencevnc] / src / keymenu.cpp
1 /*
2     Presence VNC
3     Copyright (C) 2010 Christian Pulvermacher
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "keymenu.h"
21
22
23 KeyMenu::KeyMenu(QWidget *parent):
24         QDialog(parent)
25 {
26         setWindowTitle(tr("Additional Keys"));
27         QTabWidget *tabwidget = new QTabWidget(this);
28
29         //modifiers
30         ActionTab *mod_tab = new ActionTab(this);
31         QAction *win = new QAction(tr("Win"), this);
32         win->setShortcut(Qt::META);
33         win->setCheckable(true);
34         mod_tab->addAction(win);
35         QAction *alt = new QAction(tr("Alt"), this);
36         alt->setShortcut(Qt::ALT);
37         alt->setCheckable(true);
38         mod_tab->addAction(alt);
39         tabwidget->addTab(mod_tab, tr("Modifiers"));
40
41         //movement/text editing keys
42         ActionTab *other_tab = new ActionTab(this);
43         other_tab->addAction(tr("Insert"), Qt::Key_Insert);
44         other_tab->addAction(tr("Delete"), Qt::Key_Delete);
45         other_tab->addAction(tr("Backspace"), Qt::Key_Backspace);
46         other_tab->addAction(tr("Home"), Qt::Key_Home);
47         other_tab->addAction(tr("End"), Qt::Key_End);
48         tabwidget->addTab(other_tab, tr("Editing"));
49
50         //F1-F12
51         ActionTab *fx_tab = new ActionTab(this);
52         for(int i = 1; i<=12; i++)
53                 fx_tab->addAction(tr("F%1").arg(i), QString("F%1").arg(i));
54         tabwidget->addTab(fx_tab, tr("F1-F12"));
55
56         //Misc
57         ActionTab *misc_tab = new ActionTab(this);
58         misc_tab->addAction(tr("Pause"), QString("Pause"));
59         misc_tab->addAction(tr("Print"), QString("print"));
60         misc_tab->addAction(tr("Menu"), QString("Menu"));
61         misc_tab->addAction(tr("Ctrl+Alt+Del"), QString("Ctrl+Alt+Delete"));
62         misc_tab->addAction(tr("Ctrl+Alt+Backspace"), QString("Ctrl+Alt+Backspace"));
63         tabwidget->addTab(misc_tab, tr("Misc"));
64
65         QVBoxLayout *layout = new QVBoxLayout();
66         layout->addWidget(tabwidget);
67         setLayout(layout);
68 }
69
70 void KeyMenu::accept()
71 {
72         QAction* selected_action = qobject_cast<QAction* >(sender());
73         if(!selected_action) {
74                 keysequence = QKeySequence();
75         } else {
76                 keysequence = selected_action->shortcut();
77         }
78
79         QDialog::accept();
80 }
81
82 ActionTab::ActionTab(KeyMenu *parent):
83         QScrollArea(parent),
84         keymenu(parent)
85 {
86         setWidgetResizable(true);
87         setWidget(&widget);
88         widget.setLayout(&layout);
89 }
90
91 void ActionTab::addAction(QString text, QKeySequence keysequence)
92 {
93         QAction *action = new QAction(text, this);
94         action->setShortcut(keysequence);
95
96         addAction(action);
97 }
98
99 void ActionTab::addAction(QAction *action)
100 {
101         connect(action, SIGNAL(triggered()),
102                 keymenu, SLOT(accept()));
103
104         QToolButton *button = new QToolButton();
105         button->setDefaultAction(action);
106         layout.addWidget(button);
107 }