|
From: Tapio V. <aa...@us...> - 2011-01-10 13:17:59
|
Module: editor
Branch: master
Commit: 85606b771203bfcd1544e1788a8ac43530aafe94
Author: Tapio Vierros <tap...@gm...>
Date: Mon Jan 10 15:17:16 2011 +0200
Initial connection between note tab and note graph.
* Custom signal/slot
* Only from NoteGraph to UI for now
* Buggy
---
CMakeLists.txt | 2 +-
editorapp.cc | 24 ++++++++++++++++++++++++
editorapp.hh | 10 +++++++---
notegraphwidget.cc | 20 +++++++++++++++-----
notegraphwidget.hh | 7 +++++++
5 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a0714df..b5c77c4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,7 @@ find_package(Qt4 REQUIRED) # find and setup Qt4 for this project
include(${QT_USE_FILE})
# Headers that need MOC need to be defined separately
-file(GLOB MOC_HEADER_FILES "editorapp.hh")
+file(GLOB MOC_HEADER_FILES "editorapp.hh" "notegraphwidget.hh")
file(GLOB SOURCE_FILES "*.cc")
file(GLOB HEADER_FILES "*.hh")
diff --git a/editorapp.cc b/editorapp.cc
index 80b49fe..b604913 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -1,6 +1,7 @@
#include <QtGui>
#include <cstdlib>
#include "editorapp.hh"
+#include "notelabel.hh"
EditorApp::EditorApp(QWidget *parent): QMainWindow(parent)
@@ -9,6 +10,29 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent)
// Splitter sizes cannot be set through designer :(
QList<int> ss; ss.push_back(700); ss.push_back(300); // Proportions, not pixels
ui.splitter->setSizes(ss);
+
+ // Custom signals/slots
+ connect(ui.noteGraph, SIGNAL(updateNoteInfo(NoteLabel*)), this, SLOT(updateNoteInfo(NoteLabel*)));
+ updateNoteInfo(NULL);
+}
+
+
+void EditorApp::updateNoteInfo(NoteLabel *note)
+{
+ if (note) {
+ ui.valNoteBegin->setText(QString::number(note->x()));
+ ui.valNoteEnd->setText(QString::number(note->x() + note->width()));
+ ui.valNoteDuration->setText(QString::number(note->width()));
+ ui.valNote->setText(QString::number(note->y() / NoteGraphWidget::noteYStep));
+ ui.chkFloating->setEnabled(true);
+ ui.chkFloating->setChecked(note->isFloating());
+ } else {
+ ui.valNoteBegin->setText("-");
+ ui.valNoteEnd->setText("-");
+ ui.valNoteDuration->setText("-");
+ ui.valNote->setText("-");
+ ui.chkFloating->setEnabled(false);
+ }
}
void EditorApp::on_actionNew_triggered()
diff --git a/editorapp.hh b/editorapp.hh
index c692b93..fd2ec2d 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -2,6 +2,8 @@
#include "ui_editor.h"
+class NoteLabel;
+
class EditorApp: public QMainWindow
{
Q_OBJECT
@@ -10,16 +12,18 @@ public:
EditorApp(QWidget *parent = 0);
public slots:
- // File
+ void updateNoteInfo(NoteLabel* note);
+
+ // File menu
void on_actionNew_triggered();
void on_actionExit_triggered();
- // Insert
+ // Insert menu
void on_actionMusicFile_triggered();
void on_actionLyricsFromFile_triggered();
void on_actionLyricsFromClipboard_triggered();
- // Help
+ // Help menu
void on_actionAbout_triggered();
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 4eb1fd4..b0493e5 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -13,6 +13,20 @@ NoteGraphWidget::NoteGraphWidget(QWidget *parent)
{
setFocusPolicy(Qt::StrongFocus);
setLyrics("Please add music file and lyrics text.");
+ emit updateNoteInfo(NULL);
+}
+
+void NoteGraphWidget::selectNote(NoteLabel* note)
+{
+ if (m_selectedNote) // Reset old pixmap
+ m_selectedNote->setSelected(false);
+ // Assign new selection
+ m_selectedNote = note;
+ if (m_selectedNote)
+ m_selectedNote->setSelected();
+ else m_selectedAction = NONE;
+ // Signal UI about the change
+ emit updateNoteInfo(m_selectedNote);
}
void NoteGraphWidget::clear()
@@ -114,11 +128,7 @@ 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();
+ selectNote(child);
// Determine if it is drag or resize
if (hotSpot.x() < NoteLabel::resize_margin || hotSpot.x() > child->width() - NoteLabel::resize_margin) {
// Start a resize
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 2ed17e4..8d4b1d4 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -8,6 +8,8 @@ typedef std::list<NoteLabel*> NoteLabels;
class NoteGraphWidget: public QWidget
{
+ Q_OBJECT
+
public:
static const int noteYStep;
@@ -20,6 +22,11 @@ public:
void updateNotes();
void rebuildNoteList();
+ void selectNote(NoteLabel* note);
+
+signals:
+ void updateNoteInfo(NoteLabel*);
+
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
|