summaryrefslogtreecommitdiff
path: root/src/gui_qt.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui_qt.cc')
-rw-r--r--src/gui_qt.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/gui_qt.cc b/src/gui_qt.cc
index 17eda8f..9ffdfc9 100644
--- a/src/gui_qt.cc
+++ b/src/gui_qt.cc
@@ -46,6 +46,7 @@
#include "gui_listmodel.hh"
#include "gui_main.hh"
#include "gui_menu.hh"
+#include "gui_message.hh"
#include "gui_statusbar.hh"
#include "gui_textwnd.hh"
#include "looper.hh"
@@ -1334,6 +1335,61 @@ private:
bool applied_;
};
+class QtGuiMessage : public virtual GuiMessage, public QtGuiWindow {
+public:
+ QtGuiMessage(Type type, std::string const& title, std::string const& text)
+ : type_(type), title_(title), text_(text) {
+ }
+
+ void add_listener(GuiMessage::Listener* listener) override {
+ observers_.insert(listener);
+ }
+
+ void remove_listener(GuiMessage::Listener* listener) override {
+ observers_.erase(listener);
+ }
+
+ void set_title(std::string const& title) override {
+ title_ = title;
+ }
+ std::string const& title() const override {
+ return title_;
+ }
+
+ void* impl() const override {
+ return QtGuiWindow::impl();
+ }
+
+ bool showWidget() override {
+ show(QApplication::activeWindow());
+ return true;
+ }
+
+ void show(GuiWindow* parent) override {
+ auto wnd = static_cast<QtGuiWindow*>(parent->impl());
+ show(wnd->widget());
+ }
+
+protected:
+ void show(QWidget* parent) {
+ switch (type_) {
+ case ERROR:
+ QMessageBox::critical(parent, QString::fromStdString(title_),
+ QString::fromStdString(text_));
+ break;
+ case OTHER:
+ QMessageBox::information(parent, QString::fromStdString(title_),
+ QString::fromStdString(text_));
+ break;
+ }
+ }
+
+ Type type_;
+ std::string title_;
+ std::string text_;
+ Observers<GuiMessage::Listener*> observers_;
+};
+
class OptionalCloseWidget : public QWidget {
public:
class Delegate {
@@ -1733,6 +1789,13 @@ GuiFormApply* GuiFormApply::create(std::string const& title,
}
// static
+GuiMessage* GuiMessage::create(Type type,
+ std::string const& title,
+ std::string const& text) {
+ return new QtGuiMessage(type, title, text);
+}
+
+// static
Looper* GuiMain::createLooper() {
return new QtLooper();
}