~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/widgets/nentry.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-08-12 11:16:41 UTC
  • mto: (1.1.9) (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20110812111641-72iatqb9jomjejko
ImportĀ upstreamĀ versionĀ 2.0~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//=========================================================
2
2
//  MusE
3
3
//  Linux Music Editor
4
 
//    $Id: nentry.cpp,v 1.1.1.1 2003/10/27 18:54:56 wschweer Exp $
 
4
//    $Id: nentry.cpp,v 1.1.1.1.2.1 2008/05/21 00:28:54 terminator356 Exp $
5
5
//  (C) Copyright 1999 Werner Schweer (ws@seh.de)
6
6
//=========================================================
7
7
 
8
 
#include <qlayout.h>
9
 
#include <qlabel.h>
 
8
#include <QApplication>
 
9
#include <QHBoxLayout>
 
10
#include <QLabel>
 
11
#include <QLineEdit>
 
12
#include <QMouseEvent>
 
13
#include <QTimer>
 
14
 
10
15
#include "nentry.h"
11
 
#include <stdio.h>
12
 
#include <qtimer.h>
13
 
#include <qevent.h>
14
 
#include "globals.h"
15
 
#include <qapplication.h>
16
 
#include <qcursor.h>
17
16
 
18
17
#define TIMER1    400
19
18
#define TIMER2    200
62
61
      if (event->type() == QEvent::KeyPress) {
63
62
            return e->keyPress((QKeyEvent*)event);
64
63
            }
 
64
      if (event->type() == QEvent::ContextMenu) {
 
65
            return e->contextMenu((QContextMenuEvent*)event);
 
66
            }
65
67
      return false;
66
68
      }
67
69
 
84
86
 
85
87
      connect(timer, SIGNAL(timeout()), SLOT(repeat()));
86
88
      connect(edit, SIGNAL(returnPressed()), SLOT(endEdit()));
87
 
      edit->setCursor(QCursor(arrowCursor));
 
89
      edit->setCursor(QCursor(Qt::ArrowCursor));
88
90
//      edit->setFont(font3);
89
91
      val = 0;
90
92
      layout = new QHBoxLayout(this);
91
93
      if (txt == "") {
92
 
            layout->addWidget(edit, 1, AlignHCenter);
 
94
            layout->addWidget(edit, 1, Qt::AlignHCenter);
93
95
            }
94
96
      else {
95
97
            label = new QLabel(txt, this);
103
105
                  layout->addStretch(5);
104
106
                  }
105
107
            else {
106
 
                  label->setAlignment(AlignLeft);
107
 
                  layout->addWidget(edit, 0, AlignRight);
 
108
                  label->setAlignment(Qt::AlignLeft);
 
109
                  layout->addWidget(edit, 0, Qt::AlignRight);
108
110
                  layout->addSpacing(5);
109
 
                  layout->addWidget(label, 100, AlignRight|AlignVCenter);
 
111
                  layout->addWidget(label, 100, Qt::AlignRight|Qt::AlignVCenter);
110
112
                  }
111
113
            }
112
114
      if (dark) {
113
115
            setDark();
114
116
            }
115
 
      edit->setFocusPolicy(NoFocus);
 
117
      edit->setFocusPolicy(Qt::NoFocus);
116
118
      }
117
119
 
118
 
void Nentry::setFocusPolicy(FocusPolicy policy)
 
120
void Nentry::setFocusPolicy(Qt::FocusPolicy policy)
119
121
      {
120
122
      edit->setFocusPolicy(policy);
121
123
      }
123
125
void Nentry::setDark()
124
126
      {
125
127
      const QPalette& oldpalette = edit->palette();
126
 
      QColorGroup cg1 = oldpalette.active();
127
 
      cg1.setColor(QColorGroup::Base, cg1.background());
128
 
      QPalette newpalette(cg1, cg1, cg1);
 
128
 
 
129
      const QColor& newcolor = oldpalette.color(QPalette::Window);
 
130
      QPalette newpalette(oldpalette);
 
131
      newpalette.setColor(QPalette::Base, newcolor);
 
132
 
129
133
      edit->setPalette(newpalette);
130
134
      }
131
135
 
162
166
 
163
167
void Nentry::endEdit()
164
168
      {
165
 
      if (edit->edited()) {
 
169
      if (edit->isModified()) {
166
170
            if (setSValue(edit->text())) {
167
171
                  setString(val, false);
168
172
                  return;
169
173
                  }
170
 
            edit->setEdited(false);
 
174
            edit->setModified(false);
171
175
            }
172
176
      if (focusW)
173
177
            focusW->setFocus();
179
183
      }
180
184
 
181
185
//---------------------------------------------------------
 
186
//   contextMenuEvent
 
187
//---------------------------------------------------------
 
188
 
 
189
bool Nentry::contextMenu(QContextMenuEvent *e)
 
190
{
 
191
  e->accept();
 
192
  return true;
 
193
}
 
194
//---------------------------------------------------------
182
195
//   mousePress
183
196
//---------------------------------------------------------
184
197
 
187
200
      button = event->button();
188
201
      starty = event->y();
189
202
      evx    = event->x();
190
 
      if (event->button() == QMouseEvent::LeftButton) {
 
203
      if (event->button() == Qt::LeftButton) {
191
204
            focusW = qApp->focusWidget();
192
205
            edit->setFocus();
193
206
            edit->setFrame(true);
223
236
            }
224
237
 
225
238
      switch (button) {
226
 
            case QMouseEvent::LeftButton:
 
239
            case Qt::LeftButton:
227
240
                  return;
228
 
            case QMouseEvent::MidButton:
 
241
            case Qt::MidButton:
229
242
                  decValue(evx);
230
243
                  break;
231
 
            case QMouseEvent::RightButton:
 
244
            case Qt::RightButton:
232
245
                  incValue(evx);
233
246
                  break;
234
247
            default:
245
258
 
246
259
void Nentry::mouseRelease(QMouseEvent* event)
247
260
      {
248
 
      button = QMouseEvent::NoButton;
 
261
      button = Qt::NoButton;
249
262
      timer->stop();
250
 
      if (event->button() != QMouseEvent::LeftButton) {
 
263
      if (event->button() != Qt::LeftButton) {
251
264
            if (focusW)
252
265
                  focusW->setFocus();
253
266
            edit->clearFocus();
261
274
void Nentry::mouseMove(QMouseEvent*)
262
275
      {
263
276
      switch (button) {
264
 
            case QMouseEvent::LeftButton:
265
 
                  break;
266
 
            case QMouseEvent::MidButton:
267
 
                  break;
268
 
            case QMouseEvent::RightButton:
 
277
            case Qt::LeftButton:
 
278
                  break;
 
279
            case Qt::MidButton:
 
280
                  break;
 
281
            case Qt::RightButton:
269
282
                  break;
270
283
            default:
271
284
                  break;
278
291
 
279
292
void Nentry::mouseDoubleClick(QMouseEvent* event)
280
293
      {
281
 
      if (event->button() != QMouseEvent::LeftButton) {
 
294
      if (event->button() != Qt::LeftButton) {
282
295
            mousePress(event);
283
296
            return;
284
297
            }
323
336
 
324
337
bool Nentry::keyPress(QKeyEvent* event)
325
338
      {
326
 
      bool shift = event->state() & ShiftButton;
327
 
      bool ctrl  = event->state() & ControlButton;
 
339
      bool shift = event->modifiers() & Qt::ShiftModifier;
 
340
      bool ctrl  = event->modifiers() & Qt::ControlModifier;
328
341
      int key    = event->key();
329
342
 
330
343
      if (shift) {
331
344
            switch(key) {
332
 
                  case Key_Left:
333
 
                  case Key_Right:
 
345
                  case Qt::Key_Left:
 
346
                  case Qt::Key_Right:
334
347
                        return false;
335
348
                  default:
336
349
                        return true;
339
352
            }
340
353
      if (ctrl) {
341
354
            switch(key) {
342
 
                  case Key_A:
343
 
                  case Key_B:
344
 
                  case Key_C:
345
 
                  case Key_D:
346
 
                  case Key_E:
347
 
                  case Key_F:
348
 
                  case Key_H:
349
 
                  case Key_V:
350
 
                  case Key_X:
351
 
                  case Key_Z:
352
 
                  case Key_Y:
 
355
                  case Qt::Key_A:
 
356
                  case Qt::Key_B:
 
357
                  case Qt::Key_C:
 
358
                  case Qt::Key_D:
 
359
                  case Qt::Key_E:
 
360
                  case Qt::Key_F:
 
361
                  case Qt::Key_H:
 
362
                  case Qt::Key_V:
 
363
                  case Qt::Key_X:
 
364
                  case Qt::Key_Z:
 
365
                  case Qt::Key_Y:
353
366
                        return false;
354
367
                  default:
355
368
                        return true;
356
369
                  }
357
370
            return true;
358
371
            }
359
 
      if (event->state())
 
372
      if (event->modifiers())
360
373
            return true;
361
374
      switch (key) {
362
 
            case Key_Up:   incValue(0); return true;
363
 
            case Key_Down: decValue(0); return true;
 
375
            case Qt::Key_Up:   incValue(0); return true;
 
376
            case Qt::Key_Down: decValue(0); return true;
364
377
            case 0x30:
365
378
            case 0x31:
366
379
            case 0x32:
371
384
            case 0x37:
372
385
            case 0x38:
373
386
            case 0x39:
374
 
            case Key_Minus:
375
 
            case Key_Left:
376
 
            case Key_Right:
377
 
            case Key_Backspace:
378
 
            case Key_Home:
379
 
            case Key_End:
380
 
            case Key_Delete:
381
 
            case Key_Return:
 
387
            case Qt::Key_Minus:
 
388
            case Qt::Key_Left:
 
389
            case Qt::Key_Right:
 
390
            case Qt::Key_Backspace:
 
391
            case Qt::Key_Home:
 
392
            case Qt::Key_End:
 
393
            case Qt::Key_Delete:
 
394
            case Qt::Key_Return:
382
395
                  return false;
383
396
            default:
384
397
                  break;