diff options
| author | Joel Klinghed <the_jk@yahoo.com> | 2017-08-09 22:50:26 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@yahoo.com> | 2017-08-09 22:50:26 +0200 |
| commit | 4013d1a167850bb1649d592b24d03f63e19338ef (patch) | |
| tree | 4fd38f1b8f1bb63c0d4a22756c0ad7ee4b8009ca /src/gui_qt.cc | |
| parent | 5f760687a4e81edf3dc4011129688a2eddf8b697 (diff) | |
Remember main window size
Diffstat (limited to 'src/gui_qt.cc')
| -rw-r--r-- | src/gui_qt.cc | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/gui_qt.cc b/src/gui_qt.cc index 4ad04e8..16102d6 100644 --- a/src/gui_qt.cc +++ b/src/gui_qt.cc @@ -556,6 +556,18 @@ public: observers_.erase(listener); } + void resize(uint32_t width, uint32_t height) override { + if (width == width_ && height == height_) return; + width_ = width; + height_ = height; + auto w = widget(); + if (w) { + w->resize(width_, height_); + } else { + notify_resize(); + } + } + void set_title(std::string const& title) override { title_ = title; QtGuiWindow::set_title(title); @@ -641,6 +653,13 @@ private: return true; } + void notify_resize() { + auto it = observers_.notify(); + while (it.has_next()) { + it.next()->resize(width_, height_); + } + } + void notify_selected_row(size_t row) { auto it = observers_.notify(); while (it.has_next()) { @@ -1802,6 +1821,22 @@ private: QProgressBar* progress_; }; +class QNotifyResizeMainWindow : public QMainWindow { +public: + typedef std::function<void(uint32_t,uint32_t)> ResizeCallback; + + explicit QNotifyResizeMainWindow(ResizeCallback const& callback) + : callback_(callback) { + } + + void resizeEvent(QResizeEvent* event) override { + callback_(event->size().width(), event->size().height()); + } + +private: + ResizeCallback const callback_; +}; + bool QtGuiMain::run(int argc, char** argv) { QApplication app(argc, argv); app.setApplicationName(QString::fromStdString(title_)); @@ -1816,7 +1851,12 @@ bool QtGuiMain::run(int argc, char** argv) { parser.process(app); app.setStyleSheet("QStatusBar::item { border: 0px }"); - main_.reset(new QMainWindow()); + main_.reset(new QNotifyResizeMainWindow( + [=](uint32_t width, uint32_t height) { + width_ = width; + height_ = height; + notify_resize(); + })); main_->setWindowTitle(QString::fromStdString(title_)); center_.reset(new QWidget()); layout_.reset(new SizeHintLayout(center_.get(), QSize(width_, height_))); |
