summaryrefslogtreecommitdiff
path: root/src/gui_qt.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-08-06 22:27:09 +0200
committerJoel Klinghed <the_jk@yahoo.com>2017-08-06 22:28:12 +0200
commitea8148077fa28964e3b582cd6e0bb9cfea850b66 (patch)
tree1c8679be716830d6f1835aaa50d7f18b55528c1e /src/gui_qt.cc
parent178bb3a1ceab88f29aa7d0ceb453e76de172fd27 (diff)
Add support for protocols in monitor-gui
Diffstat (limited to 'src/gui_qt.cc')
-rw-r--r--src/gui_qt.cc160
1 files changed, 152 insertions, 8 deletions
diff --git a/src/gui_qt.cc b/src/gui_qt.cc
index fe9d1c4..1d81bd6 100644
--- a/src/gui_qt.cc
+++ b/src/gui_qt.cc
@@ -48,6 +48,7 @@
#include "gui_main.hh"
#include "gui_menu.hh"
#include "gui_message.hh"
+#include "gui_progress.hh"
#include "gui_statusbar.hh"
#include "gui_textwnd.hh"
#include "looper.hh"
@@ -522,8 +523,27 @@ public:
} else {
package_.clear();
}
- if (bottom_) {
- bottom_->setHtml(QString::fromStdString(package_));
+ if (bottom_package_) {
+ bottom_package_->setHtml(QString::fromStdString(package_));
+ }
+ }
+
+ void set_content(std::string const& name, AttributedText* text) override {
+ if (text) {
+ content_ = "<span style=\"font-family: monospace;\">"
+ + static_cast<HtmlAttributedText*>(text)->html() + "</span>";
+ content_name_ = name;
+ } else {
+ content_.clear();
+ content_name_.clear();
+ }
+ if (bottom_content_) {
+ bottom_content_->setHtml(QString::fromStdString(content_));
+ bottom_->setTabText(1, QString::fromStdString(content_name_));
+ bottom_->setTabEnabled(1, !content_.empty());
+ if (text && content_last_active_) {
+ bottom_->setCurrentIndex(1);
+ }
}
}
@@ -658,6 +678,8 @@ private:
QtGuiStatusBar* statusbar_;
std::unique_ptr<QGuiListModel> listmodel_;
std::string package_;
+ std::string content_;
+ std::string content_name_;
Observers<GuiMain::Listener*> observers_;
std::unique_ptr<QMainWindow> main_;
std::unique_ptr<SizeHintLayout> layout_;
@@ -665,9 +687,12 @@ private:
std::unique_ptr<QtGuiConfig> config_;
QSplitter* splitter_;
QWidget* top_;
- QTextEdit* bottom_;
+ QTextEdit* bottom_package_;
+ QTextEdit* bottom_content_;
+ QTabWidget* bottom_;
bool started_;
std::vector<RunWhenStartedCallback> run_when_started_;
+ bool content_last_active_;
};
class QtChildGuiMenu : public QtCommonMenu {
@@ -1408,8 +1433,7 @@ private:
}
assert(!progress_);
progress_ = new QProgressBar();
- progress_->setMinimum(0);
- progress_->setMaximum(0);
+ progress_->setRange(0, 0);
layout->addWidget(progress_, row++, 0, 1, columns);
progress_->hide();
return row;
@@ -1677,6 +1701,106 @@ private:
QTextEdit* view_;
};
+
+class QtGuiProgress : public virtual GuiProgress, public QtGuiWindow,
+ public virtual OptionalCloseDialog::Delegate {
+private:
+ static const int UNIT = 100000;
+public:
+ QtGuiProgress(std::string const& title, std::string const& text,
+ float min, float max)
+ : title_(title), text_(text), min_(min), max_(max), value_(min),
+ progress_(nullptr) {
+ }
+
+ ~QtGuiProgress() override {
+ }
+
+ void add_listener(GuiProgress::Listener* listener) override {
+ observers_.insert(listener);
+ }
+
+ void remove_listener(GuiProgress::Listener* listener) override {
+ observers_.erase(listener);
+ }
+
+ void set_title(std::string const& title) override {
+ title_ = title;
+ QtGuiWindow::set_title(title);
+ }
+ std::string const& title() const override {
+ return title_;
+ }
+
+ void set_progress(float value) override {
+ value_ = value;
+ if (progress_) progress_->setValue(value_ * UNIT);
+ }
+
+ QWidget* widget() const override {
+ return dialog_.get();
+ }
+
+ 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());
+ }
+
+ bool about_to_close() override {
+ return notify_about_to_close();
+ }
+
+private:
+ void show(QWidget* parent) {
+ if (dialog_) {
+ assert(false);
+ dialog_->raise();
+ dialog_->activateWindow();
+ return;
+ }
+
+ progress_ = new QProgressBar();
+ progress_->setRange(min_ * UNIT, max_ * UNIT);
+ progress_->setValue(value_ * UNIT);
+
+ dialog_.reset(new OptionalCloseDialog(parent, this));
+ dialog_->setWindowTitle(QString::fromStdString(title_));
+ auto layout = new QVBoxLayout();
+ auto text = new QLabel(QString::fromStdString(text_));
+ layout->addWidget(text);
+ layout->addWidget(progress_);
+ dialog_->setLayout(layout);
+ dialog_->setModal(true);
+ dialog_->show();
+ }
+
+ bool notify_about_to_close() {
+ auto it = observers_.notify();
+ while (it.has_next()) {
+ if (!it.next()->about_to_close(this)) return false;
+ }
+ return true;
+ }
+
+ std::string title_;
+ std::string text_;
+ float min_;
+ float max_;
+ float value_;
+ Observers<GuiProgress::Listener*> observers_;
+ std::unique_ptr<QDialog> dialog_;
+ QProgressBar* progress_;
+};
+
bool QtGuiMain::run(int argc, char** argv) {
QApplication app(argc, argv);
app.setApplicationName(QString::fromStdString(title_));
@@ -1722,9 +1846,22 @@ bool QtGuiMain::run(int argc, char** argv) {
top_ = new QWidget();
}
splitter_->addWidget(top_);
- bottom_ = new QTextEdit();
- bottom_->setReadOnly(true);
- bottom_->setHtml(QString::fromStdString(package_));
+ bottom_package_ = new QTextEdit();
+ bottom_package_->setReadOnly(true);
+ bottom_package_->setHtml(QString::fromStdString(package_));
+ bottom_content_ = new QTextEdit();
+ bottom_content_->setReadOnly(true);
+ bottom_content_->setHtml(QString::fromStdString(content_));
+ bottom_ = new QTabWidget();
+ bottom_->addTab(bottom_package_, "Package");
+ bottom_->addTab(bottom_content_, QString::fromStdString(content_name_));
+ bottom_->setTabEnabled(1, !content_.empty());
+ content_last_active_ = false;
+ QObject::connect(bottom_, &QTabWidget::tabBarClicked,
+ [=](int index) {
+ if (index < 0) return;
+ content_last_active_ = index == 1;
+ });
splitter_->addWidget(bottom_);
main_->setCentralWidget(center_.get());
if (menu_) {
@@ -1978,3 +2115,10 @@ GuiTextWindow* GuiTextWindow::create(std::string const& title,
AttributedText const* text) {
return new QtGuiTextWindow(title, width, height, text);
}
+
+// static
+GuiProgress* GuiProgress::create(std::string const& title,
+ std::string const& text,
+ float min, float max) {
+ return new QtGuiProgress(title, text, min, max);
+}