|
From: Tapio V. <aa...@us...> - 2011-01-07 18:50:33
|
Module: editor
Branch: master
Commit: 5e67c9f5418a0f57b8a1a1f40a61d4402298bedf
Author: Tapio Vierros <tap...@gm...>
Date: Fri Jan 7 20:50:13 2011 +0200
Implemented note selection (not very useful yet).
---
editor.ui | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
notegraphwidget.cc | 24 +++++++++++++-----------
notegraphwidget.hh | 4 ++--
notelabel.cc | 8 ++++++--
notelabel.hh | 3 +++
5 files changed, 71 insertions(+), 20 deletions(-)
diff --git a/editor.ui b/editor.ui
index 53efc92..df72752 100644
--- a/editor.ui
+++ b/editor.ui
@@ -169,10 +169,10 @@
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
- <x>360</x>
+ <x>600</x>
<y>10</y>
- <width>70</width>
- <height>18</height>
+ <width>41</width>
+ <height>31</height>
</rect>
</property>
<property name="text">
@@ -182,10 +182,10 @@
<widget class="QComboBox" name="comboNoteType">
<property name="geometry">
<rect>
- <x>440</x>
+ <x>650</x>
<y>10</y>
<width>92</width>
- <height>28</height>
+ <height>31</height>
</rect>
</property>
<property name="editable">
@@ -207,6 +207,48 @@
</property>
</item>
</widget>
+ <widget class="QLabel" name="label_8">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>70</y>
+ <width>70</width>
+ <height>18</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Note</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="valNote">
+ <property name="geometry">
+ <rect>
+ <x>120</x>
+ <y>70</y>
+ <width>70</width>
+ <height>18</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>XXX</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="chkFloating">
+ <property name="geometry">
+ <rect>
+ <x>610</x>
+ <y>60</y>
+ <width>131</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>Floating note</string>
+ </property>
+ </widget>
</widget>
<widget class="QWidget" name="tabSong">
<attribute name="title">
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index f458cb4..4c6bc82 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -5,7 +5,7 @@
#include "notegraphwidget.hh"
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
- : QWidget(parent), m_resizingNote(), m_movingNote()
+ : QWidget(parent), m_selectedNote(), m_selectedAction(NONE)
{
setLyrics("Please add music file and lyrics text.");
}
@@ -105,20 +105,25 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
// Left Click
if (event->button() == Qt::LeftButton) {
+ if (m_selectedNote) // Reset old pixmap
+ m_selectedNote->setSelected(false);
+ // Assign new selection
+ m_selectedNote = child;
+ m_selectedNote->setSelected();
// Determine if it is drag or resize
if (hotSpot.x() < NoteLabel::resize_margin || hotSpot.x() > child->width() - NoteLabel::resize_margin) {
// Start a resize
- m_resizingNote = child;
+ m_selectedAction = RESIZE;
child->startResizing( (hotSpot.x() < NoteLabel::resize_margin) ? -1 : 1 );
child->disableFloating();
} else {
// Start a drag
- m_movingNote = child;
+ m_selectedAction = MOVE;
child->startDragging(hotSpot);
child->disableFloating();
- child->createPixmap(child->size());
}
+ child->createPixmap(child->size());
// Right Click
} else if (event->button() == Qt::RightButton) {
@@ -141,13 +146,10 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
void NoteGraphWidget::mouseReleaseEvent(QMouseEvent *event)
{
(void)*event;
- if (m_resizingNote) {
- m_resizingNote->startResizing(0);
- m_resizingNote = NULL;
- }
- if (m_movingNote) {
- m_movingNote->startDragging(QPoint());
- m_movingNote = NULL;
+ if (m_selectedAction != NONE) {
+ m_selectedNote->startResizing(0);
+ m_selectedNote->startDragging(QPoint());
+ m_selectedAction = NONE;
}
updateNotes();
}
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index ff4e1f0..e0f464a 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -25,8 +25,8 @@ protected:
private:
int m_requiredWidth;
- NoteLabel* m_resizingNote;
- NoteLabel* m_movingNote;
+ NoteLabel* m_selectedNote;
+ enum NoteAction { NONE, RESIZE, MOVE } m_selectedAction;
NoteLabels m_notes;
};
diff --git a/notelabel.cc b/notelabel.cc
index 7deb3cc..7dab1f5 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -9,7 +9,7 @@ namespace {
const int NoteLabel::resize_margin = 5; // How many pixels is the resize area
NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &position, const QSize &size, bool floating)
- : QLabel(parent), m_labelText(text), m_floating(floating), m_resizing(0), m_hotspot()
+ : QLabel(parent), m_labelText(text), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
{
createPixmap(size);
if (!position.isNull())
@@ -40,7 +40,11 @@ void NoteLabel::createPixmap(QSize size)
QLinearGradient gradient(0, 0, 0, image.height()-1);
gradient.setColorAt(0.0, Qt::white);
- if (m_floating) {
+ if (m_selected) {
+ gradient.setColorAt(0.2, QColor(100, 180, 100));
+ gradient.setColorAt(0.8, QColor(100, 180, 100));
+ gradient.setColorAt(1.0, QColor(100, 120, 100));
+ } else if (m_floating) {
gradient.setColorAt(0.2, QColor(160, 160, 180));
gradient.setColorAt(0.8, QColor(160, 160, 180));
gradient.setColorAt(1.0, QColor(100, 100, 120));
diff --git a/notelabel.hh b/notelabel.hh
index 2a0f3a8..6607df9 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -13,6 +13,8 @@ public:
QString getText() const;
void setText(const QString &text);
+ void setSelected(bool state = true) { m_selected = state; createPixmap(size()); }
+
bool isFloating() const { return m_floating; }
void disableFloating() { m_floating = false; }
@@ -26,6 +28,7 @@ public:
private:
QString m_labelText;
+ bool m_selected;
bool m_floating;
int m_resizing;
QPoint m_hotspot;
|