|
From: Tapio V. <aa...@us...> - 2011-01-27 08:22:20
|
Module: editor
Branch: master
Commit: 4f2f6dfbdd509958b16348cc44ce3f2d962b9074
Author: Tapio Vierros <tap...@gm...>
Date: Thu Jan 27 09:39:52 2011 +0200
Added dummy NoteLabel context menu.
---
notegraphwidget.cc | 4 ++--
notelabel.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
notelabel.hh | 8 ++++++--
3 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 3d6b9ca..0f981fe 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -321,7 +321,7 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
child->createPixmap(child->size());
// Right Click
- } else if (event->button() == Qt::RightButton) {
+/* } else if (event->button() == Qt::RightButton) {
// Cut the text in a position proportional to the click point
float relRatio = float(hotSpot.x()) / child->width();
@@ -339,7 +339,7 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
Operation combiner("COMBINER"); combiner << 3; // This will combine the previous ones to one undo action
doOperation(new1); doOperation(new2); doOperation(del); doOperation(combiner);
- m_selectedNote = NULL;
+ m_selectedNote = NULL;*/
}
}
diff --git a/notelabel.cc b/notelabel.cc
index f2ada34..ea0627e 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -2,6 +2,7 @@
#include <QResizeEvent>
#include <QToolTip>
#include <QPainter>
+#include <QMenu>
#include <iostream>
#include "notelabel.hh"
#include "notegraphwidget.hh"
@@ -23,6 +24,9 @@ NoteLabel::NoteLabel(const Note ¬e, QWidget *parent, const QPoint &position,
setMouseTracking(true);
setMinimumSize(min_width, 10);
setAttribute(Qt::WA_DeleteOnClose);
+ // Context menu
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));
show();
}
@@ -161,3 +165,46 @@ void NoteLabel::updateNote()
.arg(QString::number(m_note.end))
);
}
+
+
+void NoteLabel::showContextMenu(const QPoint &pos)
+{
+ QAction *actionSplit = new QAction(this);
+ QAction *actionFloating = new QAction(this);
+ actionFloating->setCheckable(true);
+ QAction *actionLineBreak = new QAction(this);
+ actionLineBreak->setCheckable(this);
+ QAction *actionNormal = new QAction(this);
+ QAction *actionGolden = new QAction(this);
+ QAction *actionFreestyle = new QAction(this);
+ QAction *actionDelete = new QAction(this);
+
+ QMenu *menuContext = new QMenu(this);
+ QMenu *menuType = new QMenu(menuContext);
+
+ menuContext->addAction(actionSplit);
+ menuContext->addSeparator();
+ menuContext->addAction(actionFloating);
+ menuContext->addAction(actionLineBreak);
+ menuContext->addAction(menuType->menuAction());
+ menuContext->addSeparator();
+ menuContext->addAction(actionDelete);
+ menuType->addAction(actionNormal);
+ menuType->addAction(actionGolden);
+ menuType->addAction(actionFreestyle);
+
+ actionSplit->setText(tr("Split"));
+ actionFloating->setText(tr("Floating"));
+ actionLineBreak->setText(tr("Line break"));
+ actionNormal->setText(tr("Normal"));
+ actionGolden->setText(tr("Golden"));
+ actionFreestyle->setText(tr("Freestyle"));
+ actionDelete->setText(tr("Delete"));
+ menuType->setTitle(tr("Type"));
+
+ QPoint globalPos = mapToGlobal(pos);
+ QAction *selectedItem = menuContext->exec(globalPos);
+ if (selectedItem) {
+ std::cout<< selectedItem->text().toStdString();
+ }
+}
diff --git a/notelabel.hh b/notelabel.hh
index 44c290c..62aed85 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -37,11 +37,15 @@ public:
void startResizing(int dir);
void startDragging(const QPoint& point);
+ bool operator<(const NoteLabel &rhs) const { return x() < rhs.x(); }
+
+public slots:
+ void showContextMenu(const QPoint &pos);
+
+protected:
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
- bool operator<(const NoteLabel &rhs) const { return x() < rhs.x(); }
-
private:
Note m_note;
bool m_selected;
|