Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / khotkeys / kcontrol / gesturerecordpage.cpp
bloba4622ef5b3c8ee1de3381035d0563d74107f59c9
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 2003 Mike Pilone <mpilone@slac.com>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 Distributed under the terms of the GNU General Public License version 2.
10 ****************************************************************************/
12 #include <QWidget>
13 #include <QLabel>
14 #include <QPushButton>
16 #include <klocale.h>
17 #include <kmessagebox.h>
19 #include "gesturerecordpage.h"
20 #include "gesturerecorder.h"
21 #include "gesturedrawer.h"
23 namespace KHotKeys
26 GestureRecordPage::GestureRecordPage(const QString &gesture,
27 QWidget *parent, const char *name)
28 : KVBox(parent),
29 _recorder(NULL), _resetButton(NULL),
30 _tryOne(NULL), _tryTwo(NULL), _tryThree(NULL), _gest(QString()),
31 _tryCount(1)
33 setObjectName(name);
35 QString message;
37 message = i18n("Draw the gesture you would like to record below. Press "
38 "and hold the left mouse button while drawing, and release "
39 "when you have finished.\n\n"
40 "You will be required to draw the gesture 3 times. After "
41 "each drawing, if they match, the indicators below will "
42 "change to represent which step you are on.\n\n"
43 "If at any point they do not match, you will be required to "
44 "restart. If you want to force a restart, use the reset "
45 "button below.\n\nDraw here:");
47 QLabel *label = new QLabel(message,this);
48 label->setObjectName("label");
49 label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
50 label->setWordWrap( true );
52 _recorder = new GestureRecorder(this, "recorder");
53 _recorder->setMinimumHeight(150);
54 setStretchFactor(_recorder, 1);
55 connect(_recorder, SIGNAL(recorded(const QString &)),
56 this, SLOT(slotRecorded(const QString &)));
58 KHBox *hBox = new KHBox(this);
60 _tryOne = new GestureDrawer(hBox, "tryOne");
61 _tryTwo = new GestureDrawer(hBox, "tryTwo");
62 _tryThree = new GestureDrawer(hBox, "tryThree");
64 QWidget *spacer = new QWidget(hBox);
65 spacer->setObjectName( "spacer" );
66 hBox->setStretchFactor(spacer, 1);
68 _resetButton = new QPushButton(i18n("&Reset"), hBox);
69 _resetButton->setObjectName("resetButton");
71 connect(_resetButton, SIGNAL(clicked()),
72 this, SLOT(slotResetClicked()));
76 // initialize
77 if (!gesture.isNull())
79 slotRecorded(gesture);
80 slotRecorded(gesture);
81 slotRecorded(gesture);
83 else
84 emit gestureRecorded(false);
87 GestureRecordPage::~GestureRecordPage()
91 void GestureRecordPage::slotRecorded(const QString &data)
93 switch (_tryCount)
95 case 1:
97 _gest = data;
98 _tryOne->setData(_gest);
99 _tryCount++;
101 break;
103 case 2:
105 if (_gest == data)
107 _tryTwo->setData(data);
108 _tryCount++;
110 else
112 KMessageBox::sorry(this, i18n("Your gestures did not match."));
113 slotResetClicked();
115 break;
118 case 3:
120 if (_gest == data)
122 _tryThree->setData(data);
123 _tryCount++;
124 emit gestureRecorded(true);
126 else
128 KMessageBox::sorry(this, i18n("Your gestures did not match."));
129 slotResetClicked();
131 break;
133 default:
134 KMessageBox::information(this, i18n("You have already completed the three required drawings. Either press 'Ok' to save or 'Reset' to try again."));
138 void GestureRecordPage::slotResetClicked()
140 _gest.clear();
142 _tryOne->setData(QString());
143 _tryTwo->setData(QString());
144 _tryThree->setData(QString());
146 _tryCount = 1;
148 emit gestureRecorded(false);
151 } // namespace KHotKeys
153 #include "gesturerecordpage.moc"