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.
This commit is contained in:
2021-10-04 16:52:57 +02:00
parent aa81278cfb
commit c9efac0665
4 changed files with 38 additions and 28 deletions

View File

@@ -202,13 +202,12 @@ void CHintBox::init( const std::string& Text,
CHintBox::~CHintBox() CHintBox::~CHintBox()
{ {
enable_timeout_bar = false; clearTimeOutBar();
disableTimeOutBar();
} }
void CHintBox::enableTimeOutBar(bool enable) void CHintBox::initTimeOutBar(bool do_init)
{ {
if (!enable_timeout_bar || !enable) if (!do_init)
{ {
if(timeout_pb_timer){ if(timeout_pb_timer){
delete timeout_pb_timer; timeout_pb_timer = NULL; delete timeout_pb_timer; timeout_pb_timer = NULL;
@@ -220,10 +219,8 @@ void CHintBox::enableTimeOutBar(bool enable)
timeout_pb->kill(); timeout_pb->kill();
delete timeout_pb; timeout_pb = NULL; delete timeout_pb; timeout_pb = NULL;
} }
return;
} }
else
if (enable_timeout_bar && enable)
{ {
if(timeout_pb){ if(timeout_pb){
timeout_pb->setValues(timeout_pb->getValue()+1, 10*timeout); timeout_pb->setValues(timeout_pb->getValue()+1, 10*timeout);
@@ -259,7 +256,7 @@ int CHintBox::exec()
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(timeout); 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 ) ) ) while ( ! ( res & ( messages_return::cancel_info | messages_return::cancel_all ) ) )
{ {
@@ -304,7 +301,7 @@ int CHintBox::exec()
} }
} }
disableTimeOutBar(); clearTimeOutBar();
return res; return res;
} }
@@ -459,7 +456,7 @@ int ShowHint(const char * const Caption, const char * const Text, const int Widt
int res = messages_return::none; int res = messages_return::none;
CHintBox hintBox(Caption, Text, Width, Icon, Picon, header_buttons); CHintBox hintBox(Caption, Text, Width, Icon, Picon, header_buttons);
hintBox.setTimeOut(timeout); hintBox.setTimeOut(timeout, true);
hintBox.paint(); hintBox.paint();
res = hintBox.exec(); res = hintBox.exec();
hintBox.hide(); hintBox.hide();
@@ -498,7 +495,7 @@ int ShowHintS(const char * const Text, int timeout, bool show_background)
{ {
int res = messages_return::none; int res = messages_return::none;
CHint hint(Text, show_background); CHint hint(Text, show_background);
hint.setTimeOut(timeout); hint.setTimeOut(timeout, false);
hint.paint(); hint.paint();
res = hint.exec(); res = hint.exec();
hint.hide(); hint.hide();
@@ -523,7 +520,7 @@ int ShowHintS(const char * const Text, const sigc::slot<void> &Slot, int timeout
sigc::signal<void> OnCall; sigc::signal<void> OnCall;
OnCall.connect(Slot); OnCall.connect(Slot);
CHint hint(Text, show_background); CHint hint(Text, show_background);
hint.setTimeOut(timeout); hint.setTimeOut(timeout, false);
hint.paint(); hint.paint();
OnCall(); OnCall();
res = hint.exec(); res = hint.exec();

View File

@@ -91,7 +91,7 @@ class CHintBox : public CComponentsWindow
const int& frame_width); const int& frame_width);
virtual void ReSize(); virtual void ReSize();
void showTimeOutBar(){enableTimeOutBar();} void showTimeOutBar(){initTimeOutBar();}
int getMaxWidth(const std::string& Text, const std::string& Title, Font *font, const int& minWidth); int getMaxWidth(const std::string& Text, const std::string& Title, Font *font, const int& minWidth);
public: public:
@@ -209,23 +209,36 @@ class CHintBox : public CComponentsWindow
* Timeout is enabled with parameter1 = DEFAULT_TIMEOUT (-1) or any other value > 0 * Timeout is enabled with parameter1 = DEFAULT_TIMEOUT (-1) or any other value > 0
* To disable timeout use NO_TIMEOUT (0) * To disable timeout use NO_TIMEOUT (0)
* @param[in] Timeout as int as seconds * @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 * enable/disable visualized timeout as progressbar under titlebar
* @param[in] enable * @param[in] enable
* @li optional: expects type bool, default = true * @li expects type bool, default = true
*/ */
void enableTimeOutBar(bool enable = true); void enableTimeOutBar(bool enable = true){enable_timeout_bar = enable;}
/** /**
* disable visualized timeout as progressbar * disable visualized timeout as progressbar under titlebar
* @see enableTimeOutBar * @see enableTimeOutBar()
*/ */
void disableTimeOutBar(){enableTimeOutBar(false);} 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 ! * scroll handler for text objects: NOTE: exec() must be called !
* @param[in] hint_id * @param[in] hint_id
@@ -377,7 +390,7 @@ class CHint : public CHintBox
{ {
if (delay) if (delay)
{ {
setTimeOut(delay); setTimeOut(delay, false);
exec(); exec();
} }
}; };

View File

@@ -73,7 +73,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &)
int timeout = 10; int timeout = 10;
CHintBox hintbox(name, LOCALE_KEYCHOOSER_TEXT, HINTBOX_MIN_WIDTH, NEUTRINO_ICON_SETTINGS, NEUTRINO_ICON_HINT_KEYS); 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(); hintbox.paint();
CFrameBuffer::getInstance()->blit(); CFrameBuffer::getInstance()->blit();
@@ -84,7 +84,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &)
timeoutEnd = CRCInput::calcTimeoutEnd(timeout); timeoutEnd = CRCInput::calcTimeoutEnd(timeout);
get_Message: get_Message:
hintbox.enableTimeOutBar(); hintbox.initTimeOutBar();
g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
if (msg != CRCInput::RC_timeout) if (msg != CRCInput::RC_timeout)

View File

@@ -278,7 +278,7 @@ int CMsgBox::exec()
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(timeout); uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(timeout);
if (timeout > 0) if (timeout > 0)
enableTimeOutBar(); initTimeOutBar();
bool loop = true; bool loop = true;
while (loop) while (loop)
@@ -364,7 +364,7 @@ int CMsgBox::exec()
} }
} }
disableTimeOutBar(); clearTimeOutBar();
return res; return res;
} }