-
Notifications
You must be signed in to change notification settings - Fork 25
/
editdialog.cpp
233 lines (216 loc) · 8.82 KB
/
editdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**************************************************************************
* Copyright (c) 2012-2015 Raffaele Pertile <[email protected]>
* This file is part of touchegg-gce.
*
* touchegg-gce 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 3 of the License, or
* (at your option) any later version.
*
* touchegg-gce 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 touchegg-gce. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "editdialog.h"
#include "ui_editdialog.h"
#include "gui.h"
#include "lists.h"
#include "button.h"
#include <QCheckBox>
#include "sendkeys.h"
#include <QLineEdit>
EditDialog::EditDialog(Gesture *gesture, QWidget *parent) :
QDialog(parent),
ui(new Ui::EditDialog)
{
ui->setupUi(this);
this->gesture = gesture;
QObject *gui = parent;
while(gui->objectName() != "Gui") gui = gui->parent();
connect(this, SIGNAL(done(Gesture*)), gui, SLOT(editDialogFinished(Gesture*)));
connect(this, SIGNAL(deleteGesture(Gesture *)), gui, SLOT(gestureDeleted(Gesture*)));
}
EditDialog::EditDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditDialog)
{
ui->setupUi(this);
this->gesture = NULL;
QObject *gui = parent;
while(gui->objectName() != "Gui") gui = gui->parent();
connect(this, SIGNAL(done(Gesture*)), gui, SLOT(editDialogFinished(Gesture*)));
}
EditDialog::~EditDialog()
{
delete ui;
}
Gesture* EditDialog::getGesture(){
return gesture;
}
void EditDialog::setUp(bool fullEditable){
fingSpin = findChild<QSpinBox *>("fingers");
gesType = findChild<QComboBox *>("gesture");
gesDirection = findChild<QComboBox *>("direction");
actionList = findChild<QComboBox*>("actionList");
actionList->addItems(Lists::actionList());
gesType->addItems(Lists::gestureTypes());
fingSpin->setMaximum(5);
fingSpin->setMinimum(1);
if (!fullEditable){
fingSpin->setValue(b->bLabel.fingers->text().toInt());
gesType->setCurrentIndex(gesType->findText(b->bLabel.gesture->text()));
gesDirection->addItems(Lists::gestureDirections(Lists::toGT(b->bLabel.gesture->text())));
gesDirection->setCurrentIndex(gesDirection->findText(b->bLabel.direction->text()));
actionList->setCurrentIndex(actionList->findText(b->bLabel.action->text()));
gesDirection->setEnabled(false);
gesType->setEnabled(false);
fingSpin->setEnabled(false);
}
else if (b != 0){
fingSpin->setValue(b->bLabel.fingers->text().toInt());
gesType->setCurrentIndex(gesType->findText(b->bLabel.gesture->text()));
gesDirection->addItems(Lists::gestureDirections(Lists::toGT(b->bLabel.gesture->text())));
gesDirection->setCurrentIndex(gesDirection->findText(b->bLabel.direction->text()));
actionList->setCurrentIndex(actionList->findText(b->bLabel.action->text()));
gesDirection->addItems(Lists::gestureDirections(Lists::toGT(gesType->currentText())));
}
else{
gesDirection->addItems(Lists::gestureDirections(Lists::toGT(gesType->currentText())));
}
}
void EditDialog::cleanLayout(QLayout* l){
QLayoutItem *wItem;
while ((wItem = l->takeAt(0)) != 0){
delete wItem->widget();
delete wItem;
}
}
void EditDialog::on_actionList_currentIndexChanged(const QString &arg1)
{
QGridLayout *actionArea = findChild<QGridLayout *>("actionArea");
cleanLayout(actionArea);
int lines = 0;
switch(Lists::toAT(arg1)){
case Lists::CLOSE_WINDOW:
case Lists::MOVE_WINDOW:
case Lists::RESIZE_WINDOW:
case Lists::CHANGE_DESKTOP:
case Lists::CHANGE_VIEWPORT:
case Lists::MINIMIZE_WINDOW:
case Lists::MAXIMIZE_RESTORE_WINDOW:
case Lists::SHOW_DESKTOP:
case Lists::NO_ACTION: break;
case Lists::DRAG_AND_DROP:
case Lists::MOUSE_CLICK:{
actionArea->addWidget(new QLabel(tr("Button:"),this),0,0);
QSpinBox *box = new QSpinBox(this);
box->setObjectName("buttonSpin");
box->setMinimum(1);
box->setMaximum(7);
if(b != NULL && (b->bLabel.action->text() == Lists::toString(Lists::MOUSE_CLICK) || b->bLabel.action->text() == Lists::toString(Lists::DRAG_AND_DROP)))
box->setValue(getGesture()->getAction()->getParamValue("BUTTON").toInt());
actionArea->addWidget(box,0,1);
lines = 1;
break;}
case Lists::SCROLL:{
actionArea->addWidget(new QLabel(tr("Speed:"),this),0,0);
QSpinBox *box = new QSpinBox(this);
box->setObjectName("speedSpin");
box->setMinimum(1);
if(b != NULL && b->bLabel.action->text() == Lists::toString(Lists::SCROLL))
box->setValue(getGesture()->getAction()->getParamValue("SPEED").toInt());
actionArea->addWidget(box,0,1);
actionArea->addWidget(new QLabel(tr("Inverted:"),this),1,0);
QCheckBox *box2 = new QCheckBox(this);
box2->setObjectName("invertedCombo");
if(b != NULL && b->bLabel.action->text() == Lists::toString(Lists::SCROLL))
box2->setChecked(getGesture()->getAction()->getParamValue("INVERTED").toLower() == "true");
actionArea->addWidget(box2,1,1);
lines = 2;
break;}
case Lists::SEND_KEYS:{
SendKeys *box = new SendKeys();
box->setObjectName("keysEditor");
if(b != NULL && b->bLabel.action->text() == Lists::toString(Lists::SEND_KEYS))
box->setKeys(gesture->getAction()->getParamKeys().first());
actionArea->addWidget(box,0,0);
lines = 1;
break;}
case Lists::RUN_COMMAND:{
actionArea->addWidget(new QLabel(tr("Command:"),this),0,0);
QLineEdit *box = new QLineEdit();
box->setObjectName("commandLine");
if(b != NULL && b->bLabel.action->text() == Lists::toString(Lists::RUN_COMMAND))
box->setText(gesture->getAction()->getParamKeys().first());
actionArea->addWidget(box,0,1);
lines = 1;
break;}
}
actionArea->addItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding),lines,0);
}
void EditDialog::on_buttonBox_rejected()
{
delete this;
}
void EditDialog::on_buttonBox_accepted()
{
Gesture *old = gesture;
if (fingSpin->isEnabled()){
gesture = new Gesture(fingSpin->value(), Lists::toGT(gesType->currentText()), Lists::toGD(gesDirection->currentText()), NULL);
}
QComboBox *actionCombo = findChild<QComboBox *>("actionList");
Lists::ActionType act = Lists::toAT(actionCombo->currentText());
switch(act){
case Lists::CLOSE_WINDOW:
case Lists::MOVE_WINDOW:
case Lists::RESIZE_WINDOW:
case Lists::CHANGE_DESKTOP:
case Lists::CHANGE_VIEWPORT:
case Lists::MINIMIZE_WINDOW:
case Lists::MAXIMIZE_RESTORE_WINDOW:
case Lists::SHOW_DESKTOP:
case Lists::NO_ACTION:
gesture->setAction(new Action(act));
break;
case Lists::DRAG_AND_DROP:
case Lists::MOUSE_CLICK:{
QSpinBox *box = findChild<QSpinBox*>("buttonSpin");
Action *newAct = new Action(act);
newAct->addParam("BUTTON",QString::number(box->value()));
gesture->setAction(newAct);
break;}
case Lists::SCROLL:{
QSpinBox *box = findChild<QSpinBox*>("speedSpin");
QCheckBox *box2 = findChild<QCheckBox*>("invertedCombo");
Action *newAct = new Action(act);
newAct->addParam("SPEED",QString::number(box->value()));
newAct->addParam("INVERTED",box2->isChecked()?"true":"false");
gesture->setAction(newAct);
break;}
case Lists::SEND_KEYS:{
SendKeys *box = findChild<SendKeys *>("keysEditor");
Action *newAct = new Action(act);
newAct->addParam(box->getKeys());
gesture->setAction(newAct);
break;}
case Lists::RUN_COMMAND:{
QLineEdit *box = findChild<QLineEdit*>("commandLine");
Action *newAct = new Action(act);
newAct->addParam(box->text());
gesture->setAction(newAct);
break;}
}
if(fingSpin->isEnabled() && b != 0) emit deleteGesture(old);
if(fingSpin->isEnabled())emit done(gesture);
else emit done(NULL);
deleteLater();
}
void EditDialog::on_gesture_currentIndexChanged(const QString &arg1)
{
gesDirection->clear();
gesDirection->addItems(Lists::gestureDirections(Lists::toGT(arg1)));
}