|
From: Tapio V. <aa...@us...> - 2011-01-07 15:08:04
|
Module: editor
Branch: master
Commit: 9ea0dceff9a4f6ce3f2868dd28be7a6720c8ad48
Author: Tapio Vierros <tap...@gm...>
Date: Fri Jan 7 17:07:41 2011 +0200
Implement (partially) some menu items.
* on_actionNew_triggered()
* on_actionMusicFile_triggered()
* on_actionLyricsFromFile_triggered()
---
editor.ui | 16 ++++++++-
editorapp.cc | 95 ++++++++++++++++++++++++++++++++++++++++-----------
editorapp.hh | 11 +++++-
notegraphwidget.cc | 4 ++-
4 files changed, 102 insertions(+), 24 deletions(-)
diff --git a/editor.ui b/editor.ui
index e3c0bc9..53efc92 100644
--- a/editor.ui
+++ b/editor.ui
@@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>778</width>
- <height>353</height>
+ <height>351</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@@ -233,6 +233,20 @@
<item row="1" column="1">
<widget class="QLineEdit" name="txtArtist"/>
</item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>Music</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="valMusicFile">
+ <property name="text">
+ <string>No music</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
diff --git a/editorapp.cc b/editorapp.cc
index 0dcbd94..d21a41f 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -6,9 +6,80 @@
EditorApp::EditorApp(QWidget *parent): QMainWindow(parent)
{
ui.setupUi(this);
- // FIXME: Should not set any lyrics here
- ui.noteGraph->setLyrics("Young man, there's no need to feel down. "
- "I said, young man, pick yourself off the ground.");
+}
+
+void EditorApp::on_actionNew_triggered()
+{
+ // TODO: Check if a save prompt is in order
+ if (true) {
+ QMessageBox::StandardButton b = QMessageBox::question(this, "Unsaved changes",
+ "There are unsaved changes. Do you wish to save before creating a new project?",
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ switch(b) {
+ case QMessageBox::Yes:
+ // TODO: Save
+ case QMessageBox::No:
+ ui.noteGraph->clear(); break;
+ default: break;
+ }
+ } else {
+ ui.noteGraph->clear();
+ }
+}
+
+void EditorApp::on_actionExit_triggered()
+{
+ // TODO: Check if a save prompt is in order
+ if (false) {
+ QMessageBox::StandardButton b = QMessageBox::question(this, "Unsaved changes",
+ "There are unsaved changes. Do you wish to save before quitting?",
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ switch(b) {
+ case QMessageBox::Yes:
+ // TODO: Save
+ case QMessageBox::No:
+ close(); break;
+ default: break;
+ }
+ } else {
+ close();
+ }
+}
+
+void EditorApp::on_actionMusicFile_triggered()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
+ "",
+ tr("Music files (*.mp3 *.ogg)"));
+
+ if (!fileName.isNull()) {
+ ui.valMusicFile->setText(fileName);
+ ui.tabWidget->setCurrentIndex(1);
+ // TODO: Do something the file
+ }
+}
+
+void EditorApp::on_actionLyricsFromFile_triggered()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
+ "",
+ tr("Text files (*.txt)"));
+
+ if (!fileName.isNull()) {
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return;
+
+ QTextStream in(&file);
+ QString text = "";
+ while (!in.atEnd()) {
+ text += in.readLine();
+ if (!in.atEnd()) text += " "; // TODO: Some kind of line separator here
+ }
+
+ if (text != "")
+ ui.noteGraph->setLyrics(text);
+ }
}
void EditorApp::on_actionLyricsFromClipboard_triggered()
@@ -36,21 +107,3 @@ void EditorApp::on_actionAbout_triggered()
);
}
-void EditorApp::on_actionExit_triggered()
-{
- // TODO: Check if a save prompt is in order
- if (false) {
- QMessageBox::StandardButton b = QMessageBox::question(this, "Unsaved changes",
- "There are unsaved changes. Do you wish to save before quitting?",
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
- switch(b) {
- case QMessageBox::Yes:
- // TODO: Save
- case QMessageBox::No:
- close(); break;
- default: break;
- }
- } else {
- close();
- }
-}
diff --git a/editorapp.hh b/editorapp.hh
index 23ee86e..c692b93 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -10,9 +10,18 @@ public:
EditorApp(QWidget *parent = 0);
public slots:
+ // File
+ void on_actionNew_triggered();
+ void on_actionExit_triggered();
+
+ // Insert
+ void on_actionMusicFile_triggered();
+ void on_actionLyricsFromFile_triggered();
void on_actionLyricsFromClipboard_triggered();
+
+ // Help
void on_actionAbout_triggered();
- void on_actionExit_triggered();
+
private:
Ui::EditorApp ui;
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 99a6381..aa87b97 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -7,7 +7,7 @@
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
: QWidget(parent), m_resizingNote(), m_movingNote()
{
- setAcceptDrops(true);
+ setLyrics("Please add music file and lyrics text.");
}
void NoteGraphWidget::clear()
@@ -53,6 +53,8 @@ void NoteGraphWidget::updateWidth()
void NoteGraphWidget::updateNotes()
{
+ // Here happens the magic that adjusts the floating
+ // notes according to the fixed ones.
FloatingGap gap(0);
rebuildNoteList();
// Determine gaps between non-floating notes
|