From c9efac0665cfb459d3f5d27f9d4a69521e3eff2f Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Mon, 4 Oct 2021 16:52:57 +0200 Subject: [PATCH] hintbox: try to fix logic for enable/disable timeout bar. Timeout bar could not be switched off, is now disabled for CHint TODO: find a better solution to vizualize timeout for CHint. It looks not so good on the top of the hintbox, especially with round corners or frameless window. --- src/gui/widget/hintbox.cpp | 21 +++++++++----------- src/gui/widget/hintbox.h | 37 +++++++++++++++++++++++------------ src/gui/widget/keychooser.cpp | 4 ++-- src/gui/widget/msgbox.cpp | 4 ++-- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/gui/widget/hintbox.cpp b/src/gui/widget/hintbox.cpp index 18387bb3f..88dce77a0 100644 --- a/src/gui/widget/hintbox.cpp +++ b/src/gui/widget/hintbox.cpp @@ -202,13 +202,12 @@ void CHintBox::init( const std::string& Text, CHintBox::~CHintBox() { - enable_timeout_bar = false; - disableTimeOutBar(); + clearTimeOutBar(); } -void CHintBox::enableTimeOutBar(bool enable) +void CHintBox::initTimeOutBar(bool do_init) { - if (!enable_timeout_bar || !enable) + if (!do_init) { if(timeout_pb_timer){ delete timeout_pb_timer; timeout_pb_timer = NULL; @@ -220,10 +219,8 @@ void CHintBox::enableTimeOutBar(bool enable) timeout_pb->kill(); delete timeout_pb; timeout_pb = NULL; } - return; } - - if (enable_timeout_bar && enable) + else { if(timeout_pb){ timeout_pb->setValues(timeout_pb->getValue()+1, 10*timeout); @@ -259,7 +256,7 @@ int CHintBox::exec() uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(timeout); - enableTimeOutBar(timeout > 0); + initTimeOutBar(enable_timeout_bar && timeout > 0); while ( ! ( res & ( messages_return::cancel_info | messages_return::cancel_all ) ) ) { @@ -304,7 +301,7 @@ int CHintBox::exec() } } - disableTimeOutBar(); + clearTimeOutBar(); return res; } @@ -459,7 +456,7 @@ int ShowHint(const char * const Caption, const char * const Text, const int Widt int res = messages_return::none; CHintBox hintBox(Caption, Text, Width, Icon, Picon, header_buttons); - hintBox.setTimeOut(timeout); + hintBox.setTimeOut(timeout, true); hintBox.paint(); res = hintBox.exec(); hintBox.hide(); @@ -498,7 +495,7 @@ int ShowHintS(const char * const Text, int timeout, bool show_background) { int res = messages_return::none; CHint hint(Text, show_background); - hint.setTimeOut(timeout); + hint.setTimeOut(timeout, false); hint.paint(); res = hint.exec(); hint.hide(); @@ -523,7 +520,7 @@ int ShowHintS(const char * const Text, const sigc::slot &Slot, int timeout sigc::signal OnCall; OnCall.connect(Slot); CHint hint(Text, show_background); - hint.setTimeOut(timeout); + hint.setTimeOut(timeout, false); hint.paint(); OnCall(); res = hint.exec(); diff --git a/src/gui/widget/hintbox.h b/src/gui/widget/hintbox.h index 1f4d6460c..d5a84a522 100644 --- a/src/gui/widget/hintbox.h +++ b/src/gui/widget/hintbox.h @@ -91,7 +91,7 @@ class CHintBox : public CComponentsWindow const int& frame_width); virtual void ReSize(); - void showTimeOutBar(){enableTimeOutBar();} + void showTimeOutBar(){initTimeOutBar();} int getMaxWidth(const std::string& Text, const std::string& Title, Font *font, const int& minWidth); public: @@ -209,23 +209,36 @@ class CHintBox : public CComponentsWindow * Timeout is enabled with parameter1 = DEFAULT_TIMEOUT (-1) or any other value > 0 * To disable timeout use NO_TIMEOUT (0) * @param[in] Timeout as int as seconds - * @param[in] enable_Timeout_Bar as bool, default = true + * @param[in] enable_Timeout_Bar as bool */ - virtual void setTimeOut(const int& Timeout, const bool& enable_Timeout_Bar = true){timeout = Timeout; enable_timeout_bar = enable_Timeout_Bar;} + virtual void setTimeOut(const int& Timeout, const bool& enable_Timeout_Bar){timeout = Timeout; enable_timeout_bar = enable_Timeout_Bar;} /** - * enable/disable visualized timeout as progressbar under titlebar - * @param[in] enable - * @li optional: expects type bool, default = true - */ - void enableTimeOutBar(bool enable = true); + * enable/disable visualized timeout as progressbar under titlebar + * @param[in] enable + * @li expects type bool, default = true + */ + void enableTimeOutBar(bool enable = true){enable_timeout_bar = enable;} /** - * disable visualized timeout as progressbar - * @see enableTimeOutBar - */ + * disable visualized timeout as progressbar under titlebar + * @see enableTimeOutBar() + */ void disableTimeOutBar(){enableTimeOutBar(false);} + /** + * init or unload visualized timeout as progressbar under titlebar + * @param[in] do_init + * @li type bool, default = true + */ + void initTimeOutBar(bool do_init = true); + + /** + * unload visualized timeout as progressbar + * @see initTimeOutBar + */ + void clearTimeOutBar(){initTimeOutBar(false);} + /** * scroll handler for text objects: NOTE: exec() must be called ! * @param[in] hint_id @@ -377,7 +390,7 @@ class CHint : public CHintBox { if (delay) { - setTimeOut(delay); + setTimeOut(delay, false); exec(); } }; diff --git a/src/gui/widget/keychooser.cpp b/src/gui/widget/keychooser.cpp index 09131937a..84f07fdba 100644 --- a/src/gui/widget/keychooser.cpp +++ b/src/gui/widget/keychooser.cpp @@ -73,7 +73,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &) int timeout = 10; CHintBox hintbox(name, LOCALE_KEYCHOOSER_TEXT, HINTBOX_MIN_WIDTH, NEUTRINO_ICON_SETTINGS, NEUTRINO_ICON_HINT_KEYS); - hintbox.setTimeOut(timeout); + hintbox.setTimeOut(timeout, true); hintbox.paint(); CFrameBuffer::getInstance()->blit(); @@ -84,7 +84,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &) timeoutEnd = CRCInput::calcTimeoutEnd(timeout); get_Message: - hintbox.enableTimeOutBar(); + hintbox.initTimeOutBar(); g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); if (msg != CRCInput::RC_timeout) diff --git a/src/gui/widget/msgbox.cpp b/src/gui/widget/msgbox.cpp index 70c1c68a8..daab83791 100644 --- a/src/gui/widget/msgbox.cpp +++ b/src/gui/widget/msgbox.cpp @@ -278,7 +278,7 @@ int CMsgBox::exec() uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(timeout); if (timeout > 0) - enableTimeOutBar(); + initTimeOutBar(); bool loop = true; while (loop) @@ -364,7 +364,7 @@ int CMsgBox::exec() } } - disableTimeOutBar(); + clearTimeOutBar(); return res; }