|
From: Tapio V. <aa...@us...> - 2011-02-22 09:01:01
|
Author: Tapio Vierros <tap...@gm...>
Date: Tue Feb 22 11:00:26 2011 +0200
Added a busy dialog to give user feedback when an operation takes long.
---
busydialog.hh | 36 ++++++++++++++++++++++++++++++++++++
editorapp.cc | 3 +++
notegraphwidget.cc | 3 +++
3 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/busydialog.hh b/busydialog.hh
new file mode 100644
index 0000000..f5b8fd2
--- /dev/null
+++ b/busydialog.hh
@@ -0,0 +1,36 @@
+#pragma once
+#include <QApplication>
+#include <QDialog>
+#include <QCloseEvent>
+#include <QProgressBar>
+#include <QVBoxLayout>
+#include <QElapsedTimer>
+
+class BusyDialog: public QDialog {
+public:
+ BusyDialog(QWidget *parent = NULL, int eventsInterval = 30): QDialog(parent), timer(), interval(eventsInterval), count() {
+ QProgressBar *progress = new QProgressBar(this);
+ progress->setRange(0,0);
+ setWindowTitle(tr("Working..."));
+ QVBoxLayout *vb = new QVBoxLayout(this);
+ vb->addWidget(progress);
+ setLayout(vb);
+ timer.start();
+ }
+ void operator()() {
+ if (count == 0) // Let's not process events all the time
+ QApplication::processEvents();
+ count = (count + 1) % interval;
+ // Only show the dialog after certainamount of time
+ if (timer.isValid() && timer.elapsed() > 1500) {
+ open();
+ timer.invalidate();
+ }
+ }
+protected:
+ void closeEvent(QCloseEvent* event) { event->ignore(); }
+private:
+ QElapsedTimer timer;
+ int interval;
+ int count;
+};
diff --git a/editorapp.cc b/editorapp.cc
index 162ca82..366a290 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -20,6 +20,7 @@
#include "songwriter.hh"
#include "textcodecselector.hh"
#include "gettingstarted.hh"
+#include "busydialog.hh"
namespace {
static const QString PROJECT_SAVE_FILE_EXTENSION = "songproject"; // FIXME: Nice extension here
@@ -163,11 +164,13 @@ void EditorApp::operationDone(const Operation &op)
void EditorApp::doOpStack()
{
+ BusyDialog busy(this);
noteGraph->clearNotes();
QString newMusic = "";
// Re-apply all operations in the stack
for (OperationStack::const_iterator opit = opStack.begin(); opit != opStack.end(); ++opit) {
//std::cout << "Doing op: " << opit->dump() << std::endl;
+ busy();
try {
if (opit->op() == "META") {
// META ops are handled differently:
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index e0e9e22..b8b1122 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -13,6 +13,7 @@
#include "notegraphwidget.hh"
#include "song.hh"
#include "util.hh"
+#include "busydialog.hh"
namespace {
@@ -56,11 +57,13 @@ NoteGraphWidget::NoteGraphWidget(QWidget *parent)
void NoteGraphWidget::setLyrics(QString lyrics)
{
+ BusyDialog busy(this, 5);
QTextStream ts(&lyrics, QIODevice::ReadOnly);
doOperation(Operation("CLEAR"));
bool firstNote = true;
while (!ts.atEnd()) {
+ busy();
// We want to loop one line at the time to insert line breaks
bool sentenceStart = true;
QString sentence = ts.readLine();
|