summaryrefslogtreecommitdiff
path: root/muse2/muse/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/muse/widgets')
-rw-r--r--muse2/muse/widgets/combobox.cpp64
-rw-r--r--muse2/muse/widgets/combobox.h24
2 files changed, 50 insertions, 38 deletions
diff --git a/muse2/muse/widgets/combobox.cpp b/muse2/muse/widgets/combobox.cpp
index 9e278376..bd78d6f2 100644
--- a/muse2/muse/widgets/combobox.cpp
+++ b/muse2/muse/widgets/combobox.cpp
@@ -6,6 +6,8 @@
//=========================================================
#include <QMenu>
+#include <QSignalMapper>
+#include <QWheelEvent>
#include "combobox.h"
@@ -14,67 +16,75 @@
//---------------------------------------------------------
ComboBox::ComboBox(QWidget* parent, const char* name)
- : QLabel(parent)
+ : QToolButton(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);
+
+ menu = new QMenu(this);
+
+ autoTypeSignalMapper = new QSignalMapper(this);
+ connect(autoTypeSignalMapper, SIGNAL(mapped(int)), this, SLOT(activatedIntern(int)));
}
ComboBox::~ComboBox()
{
- delete list;
+ delete menu;
}
//---------------------------------------------------------
// mousePressEvent
//---------------------------------------------------------
-void ComboBox::mousePressEvent(QMouseEvent*)
+void ComboBox::mousePressEvent(QMouseEvent* /*ev*/)
+ {
+ menu->exec(QCursor::pos());
+ }
+
+//---------------------------------------------------------
+// wheelEvent
+//---------------------------------------------------------
+
+void ComboBox::wheelEvent(QWheelEvent* ev)
{
- list->exec(QCursor::pos());
+ int i = itemlist.indexOf(_currentItem);
+ int len = itemlist.count();
+ if (ev->delta() > 0 && i > 0)
+ activatedIntern(_currentItem-1);
+ else if (ev->delta() < 0 && -1 < i && i < len - 1)
+ activatedIntern(_currentItem+1);
}
//---------------------------------------------------------
// activated
//---------------------------------------------------------
-void ComboBox::activatedIntern(QAction* act)
+void ComboBox::activatedIntern(int id)
{
- _currentItem = act->data().toInt();
- emit activated(_currentItem, _id);
- setText(act->text());
+ setCurrentItem(id);
+ emit activated(id);
}
//---------------------------------------------------------
// setCurrentItem
//---------------------------------------------------------
-void ComboBox::setCurrentItem(int i)
+void ComboBox::setCurrentItem(int id)
{
- _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;
- }
- }
+ QAction* act = (QAction*) autoTypeSignalMapper->mapping(id);
+ _currentItem = id;
+ setText(act->text());
}
//---------------------------------------------------------
// insertItem
//---------------------------------------------------------
-void ComboBox::insertItem(const QString& s, int id)
+void ComboBox::addAction(const QString& s, int id)
{
- QAction *act = list->addAction(s);
- act->setData(id);
+ QAction *act = menu->addAction(s);
+ connect(act, SIGNAL(triggered()), autoTypeSignalMapper, SLOT(map()));
+ autoTypeSignalMapper->setMapping(act, id);
+ itemlist << id;
}
diff --git a/muse2/muse/widgets/combobox.h b/muse2/muse/widgets/combobox.h
index 305ad0b3..c099b3ce 100644
--- a/muse2/muse/widgets/combobox.h
+++ b/muse2/muse/widgets/combobox.h
@@ -8,36 +8,38 @@
#ifndef __COMBOBOX_H__
#define __COMBOBOX_H__
-#include <QLabel>
+#include <QToolButton>
class QMenu;
+class QSignalMapper;
//---------------------------------------------------------
// ComboBox
//---------------------------------------------------------
-class ComboBox : public QLabel {
+class ComboBox : public QToolButton {
Q_OBJECT
- Q_PROPERTY( int id READ id WRITE setId )
- int _id;
int _currentItem;
- QMenu* list;
+ QList<int> itemlist;
+
+ QMenu* menu;
virtual void mousePressEvent(QMouseEvent*);
+ virtual void wheelEvent(QWheelEvent*);
+
+ QSignalMapper* autoTypeSignalMapper;
private slots:
- void activatedIntern(QAction*);
+ void activatedIntern(int id);
signals:
- void activated(int val, int id);
+ void activated(int id);
public:
- ComboBox(QWidget* parent, const char* name = 0);
+ ComboBox(QWidget* parent = 0, const char* name = 0);
~ComboBox();
void setCurrentItem(int);
- void insertItem(const QString& s, int id = -1);
- int id() const { return _id; }
- void setId(int i) { _id = i; }
+ void addAction(const QString& s, int id = -1);
};
#endif