summaryrefslogtreecommitdiff
path: root/attic/muse2-oom/muse2/muse/widgets/combobox.cpp
blob: 9e278376aa0c7c1a660eb7fbbab1ee4638826616 (plain)
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
//=========================================================
//  MusE
//  Linux Music Editor
//    $Id: combobox.cpp,v 1.4 2004/05/06 15:08:07 wschweer Exp $
//  (C) Copyright 2004 Werner Schweer (ws@seh.de)
//=========================================================

#include <QMenu>

#include "combobox.h"

//---------------------------------------------------------
//   ComboBox
//---------------------------------------------------------

ComboBox::ComboBox(QWidget* parent, const char* name)
   : QLabel(parent)
      {
      setObjectName(name);
      _currentItem = 0;
      _id = -1;
      list = new QMenu(0);
      connect(list, SIGNAL(triggered(QAction*)), SLOT(activatedIntern(QAction*)));
      setFrameStyle(QFrame::Panel | QFrame::Raised);
      setLineWidth(2);
      }

ComboBox::~ComboBox()
      {
      delete list;
      }

//---------------------------------------------------------
//   mousePressEvent
//---------------------------------------------------------

void ComboBox::mousePressEvent(QMouseEvent*)
      {
      list->exec(QCursor::pos());
      }

//---------------------------------------------------------
//   activated
//---------------------------------------------------------

void ComboBox::activatedIntern(QAction* act)
      {
      _currentItem = act->data().toInt();
      emit activated(_currentItem, _id);
      setText(act->text());
      }

//---------------------------------------------------------
//   setCurrentItem
//---------------------------------------------------------

void ComboBox::setCurrentItem(int i)
      {
      _currentItem = i;
      // ORCAN - CHECK
      QList<QAction *> actions = list->actions();
      for (QList<QAction *>::iterator it = actions.begin(); it != actions.end(); ++it) {
            QAction* act = *it;
            if (act->data().toInt() == i) {
                  setText(act->text());
                  break;
                  }
            }
      }

//---------------------------------------------------------
//   insertItem
//---------------------------------------------------------

void ComboBox::insertItem(const QString& s, int id)
      {
	QAction *act = list->addAction(s);
	act->setData(id);
      }