~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to khotkeys/kcontrol/gesturerecordpage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 
 
3
 KHotKeys
 
4
 
 
5
 Copyright (C) 2003 Mike Pilone <mpilone@slac.com>
 
6
 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
 
7
 
 
8
 Distributed under the terms of the GNU General Public License version 2.
 
9
 
 
10
****************************************************************************/
 
11
 
 
12
#include <QWidget>
 
13
#include <QLabel>
 
14
#include <QPushButton>
 
15
 
 
16
#include <klocale.h>
 
17
#include <kmessagebox.h>
 
18
 
 
19
#include "gesturerecordpage.h"
 
20
#include "gesturerecorder.h"
 
21
#include "gesturedrawer.h"
 
22
 
 
23
namespace KHotKeys
 
24
{
 
25
 
 
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)
 
32
    {
 
33
    setObjectName(name);
 
34
 
 
35
    QString message;
 
36
 
 
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:");
 
46
 
 
47
    QLabel *label = new QLabel(message,this);
 
48
    label->setObjectName("label");
 
49
    label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
 
50
    label->setWordWrap( true );
 
51
 
 
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 &)));
 
57
 
 
58
    KHBox *hBox = new KHBox(this);
 
59
 
 
60
    _tryOne = new GestureDrawer(hBox, "tryOne");
 
61
    _tryTwo = new GestureDrawer(hBox, "tryTwo");
 
62
    _tryThree = new GestureDrawer(hBox, "tryThree");
 
63
 
 
64
    QWidget *spacer = new QWidget(hBox);
 
65
    spacer->setObjectName( "spacer" );
 
66
    hBox->setStretchFactor(spacer, 1);
 
67
 
 
68
    _resetButton = new QPushButton(i18n("&Reset"), hBox);
 
69
    _resetButton->setObjectName("resetButton");
 
70
 
 
71
    connect(_resetButton, SIGNAL(clicked()),
 
72
            this, SLOT(slotResetClicked()));
 
73
 
 
74
 
 
75
 
 
76
  // initialize
 
77
    if (!gesture.isNull())
 
78
        {
 
79
        slotRecorded(gesture);
 
80
        slotRecorded(gesture);
 
81
        slotRecorded(gesture);
 
82
        }
 
83
    else
 
84
        emit gestureRecorded(false);
 
85
    }
 
86
 
 
87
GestureRecordPage::~GestureRecordPage()
 
88
    {
 
89
    }
 
90
 
 
91
void GestureRecordPage::slotRecorded(const QString &data)
 
92
    {
 
93
    switch (_tryCount)
 
94
        {
 
95
        case 1:
 
96
            {
 
97
            _gest = data;
 
98
            _tryOne->setData(_gest);
 
99
            _tryCount++;
 
100
            }
 
101
        break;
 
102
 
 
103
    case 2:
 
104
            {
 
105
            if (_gest == data)
 
106
                {
 
107
                _tryTwo->setData(data);
 
108
                _tryCount++;
 
109
                }
 
110
            else
 
111
                {
 
112
                KMessageBox::sorry(this, i18n("Your gestures did not match."));
 
113
                slotResetClicked();
 
114
                }
 
115
            break;
 
116
            }
 
117
 
 
118
        case 3:
 
119
            {
 
120
            if (_gest == data)
 
121
                {
 
122
                _tryThree->setData(data);
 
123
                _tryCount++;
 
124
                emit gestureRecorded(true);
 
125
                }
 
126
            else
 
127
                {
 
128
                KMessageBox::sorry(this, i18n("Your gestures did not match."));
 
129
                slotResetClicked();
 
130
                }
 
131
            break;
 
132
            }
 
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."));
 
135
        }
 
136
    }
 
137
 
 
138
void GestureRecordPage::slotResetClicked()
 
139
    {
 
140
    _gest.clear();
 
141
 
 
142
    _tryOne->setData(QString());
 
143
    _tryTwo->setData(QString());
 
144
    _tryThree->setData(QString());
 
145
 
 
146
    _tryCount = 1;
 
147
 
 
148
    emit gestureRecorded(false);
 
149
    }
 
150
 
 
151
} // namespace KHotKeys
 
152
 
 
153
#include "gesturerecordpage.moc"