From 4013d1a167850bb1649d592b24d03f63e19338ef Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 9 Aug 2017 22:50:26 +0200 Subject: Remember main window size --- src/gui_qt.cc | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/gui_qt.cc') 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 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_))); -- cgit v1.2.3-70-g09d2