|
From: Tapio V. <aa...@us...> - 2011-01-07 10:34:25
|
Module: editor
Branch: master
Commit: d78a6ac65ea3b5a832d0e0061a7ddb12b1421f99
Author: Tapio Vierros <tap...@gm...>
Date: Fri Jan 7 10:30:05 2011 +0200
Allow pasting new lyrics from clipboard.
---
editorapp.cc | 18 ++++++++++++++++++
editorapp.hh | 1 +
notegraphwidget.cc | 10 ++++++++++
notegraphwidget.hh | 1 +
4 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 4b74e6c..521bbc4 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -11,6 +11,24 @@ EditorApp::EditorApp(QWidget *parent): QMainWindow(parent)
"I said, young man, pick yourself off the ground.");
}
+void EditorApp::on_actionLyricsFromClipboard_triggered()
+{
+ const QClipboard *clipboard = QApplication::clipboard();
+ const QMimeData *mimeData = clipboard->mimeData();
+
+ if (mimeData->hasText() && !mimeData->text().isEmpty()) {
+ QString text = mimeData->text();
+ QMessageBox::StandardButton b = QMessageBox::question(this, "Replace lyrics",
+ "Pasting lyrics from clipboard will replace the existing ones. Continue?",
+ QMessageBox::Ok | QMessageBox::Cancel);
+ if (b == QMessageBox::Ok) {
+ ui.noteGraph->setLyrics(text);
+ }
+ } else {
+ QMessageBox::warning(this, "No text to paste", "No suitable data on the clipboard.");
+ }
+}
+
void EditorApp::on_actionAbout_triggered()
{
QMessageBox::about(this, "About",
diff --git a/editorapp.hh b/editorapp.hh
index 81bf334..23ee86e 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -10,6 +10,7 @@ public:
EditorApp(QWidget *parent = 0);
public slots:
+ void on_actionLyricsFromClipboard_triggered();
void on_actionAbout_triggered();
void on_actionExit_triggered();
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 3fe99ea..87afe1c 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -10,11 +10,21 @@ NoteGraphWidget::NoteGraphWidget(QWidget *parent)
setAcceptDrops(true);
}
+void NoteGraphWidget::clear()
+{
+ const QObjectList &childlist = children ();
+ for (QObjectList::const_iterator it = childlist.begin(); it != childlist.end(); ++it) {
+ NoteLabel *child = static_cast<NoteLabel*>(*it);
+ child->close();
+ }
+}
+
void NoteGraphWidget::setLyrics(QString lyrics)
{
QTextStream ts(&lyrics, QIODevice::ReadOnly);
int x = 5, y = 5;
+ clear();
while (!ts.atEnd()) {
QString word;
ts >> word;
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 38dfbb3..e261e53 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -7,6 +7,7 @@ class NoteGraphWidget: public QWidget
public:
NoteGraphWidget(QWidget *parent = 0);
+ void clear();
void setLyrics(QString lyrics);
void updateWidth();
|