diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-04-16 21:33:38 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-04-16 21:33:38 +0200 |
commit | 14c76e247f982b153adba005283826a2b722f89f (patch) | |
tree | 4482b81f0cd812571183a244b40b06c978bfc056 /plugingui | |
parent | 41a34f74ed1cf16428533724c5eb6f381d813850 (diff) |
Hacky filebrowser-as-a-Dialog implementation.
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/filebrowser.cc | 21 | ||||
-rw-r--r-- | plugingui/filebrowser.h | 12 | ||||
-rw-r--r-- | plugingui/tests/filebrowsertest.cc | 20 |
3 files changed, 52 insertions, 1 deletions
diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 50e34c3..3d3df99 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -69,6 +69,8 @@ FileBrowser::FileBrowser(Widget* parent) CONNECT(&lineedit, enterPressedNotifier, this, &FileBrowser::handleKeyEvent); CONNECT(&listbox, selectionNotifier, this, &FileBrowser::listSelectionChanged); + CONNECT(this, fileSelectNotifier, + this, &FileBrowser::select); btn_sel.setText("Select"); CONNECT(&btn_sel, clickNotifier, this, &FileBrowser::selectButtonClicked); @@ -166,6 +168,15 @@ void FileBrowser::handleKeyEvent() void FileBrowser::cancel() { + has_filename = false; + hide(); + fileSelectCancelNotifier(); +} + +void FileBrowser::select(const std::string& file) +{ + has_filename = true; + filename = file; hide(); } @@ -255,4 +266,14 @@ void FileBrowser::changeDir() listbox.addItems(items); } +std::string FileBrowser::getFilename() const +{ + return filename; +} + +bool FileBrowser::hasFilename() const +{ + return has_filename; +} + } // GUI:: diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index 7b31864..ff8a7e8 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -49,12 +49,20 @@ public: void setPath(const std::string& path); Notifier<const std::string&> fileSelectNotifier; // (const std::string& path) + Notifier<> fileSelectCancelNotifier; // From Widget: bool isFocusable() override { return true; } virtual void repaintEvent(RepaintEvent* repaintEvent) override; virtual void resize(std::size_t width, std::size_t height) override; + //! Return the filename selected in the browser. + std::string getFilename() const; + + //! Returns true if the filebrowser has a selection, false if the window was + //! closed or the cancel button was clicked. + bool hasFilename() const; + private: void listSelectionChanged(); void selectButtonClicked(); @@ -68,6 +76,7 @@ private: #endif void cancel(); + void select(const std::string& file); void changeDir(); Label lbl_path; @@ -79,6 +88,9 @@ private: Button btn_esc; Image back; + + bool has_filename{false}; + std::string filename; }; } // GUI:: diff --git a/plugingui/tests/filebrowsertest.cc b/plugingui/tests/filebrowsertest.cc index cfe5aa2..c558fab 100644 --- a/plugingui/tests/filebrowsertest.cc +++ b/plugingui/tests/filebrowsertest.cc @@ -53,6 +53,14 @@ public: CONNECT(file_browser.eventHandler(), closeNotifier, this, &TestWindow::dialogCloseEventHandler); + + CONNECT(&file_browser, fileSelectNotifier, + this, &TestWindow::fileSelected); + + CONNECT(&file_browser, fileSelectCancelNotifier, + this, &TestWindow::fileCanceled); + + button.move(0, 0); button.resize(120, 30); button.setText("Browse..."); @@ -65,6 +73,16 @@ public: this, &TestWindow::dialogShow); } + void fileSelected(const std::string& filename) + { + label.setText(filename); + } + + void fileCanceled() + { + label.setText("[Canceled]"); + } + void closeEventHandler() { closing = true; @@ -78,7 +96,7 @@ public: void dialogShow() { file_browser.show(); - //file_browser.resize(300, 300); + file_browser.resize(300, 300); } bool processEvents() |