WSL/SLF GitLab Repository

Commit 4f33f36b authored by Michael Reisecker's avatar Michael Reisecker
Browse files

Move highlighting functionality to Atomic

There were still crashes where a Timer was called on an invalidated
object. Now, this timer is in Atomic and therefore gets destroyed with
the widget.
This way we can have multiple stylings running and it is more logical,
cleaner, and more general purpose.
parent 10f837f5
......@@ -19,6 +19,7 @@
#include "RememberDialog.h"
#include "SectionTab.h"
#include "SectionButton.h"
#include "src/gui_elements/Group.h"
#include "src/main/colors.h"
#include "src/main/inishell.h"
#include "src/main/os.h"
......@@ -64,8 +65,7 @@ Group * ScrollPanel::getGroup() const
*/
SectionTab::SectionTab(QWidget *parent) : QTabWidget(parent)
{
style_timer_.setSingleShot(true);
style_timer_.setInterval(Cst::msg_short_length);
//do nothing
}
/**
......@@ -406,29 +406,11 @@ bool SectionTab::showPanel(const QString &section, const QString &element_key)
(void) panel->getIniValue(section, key);
if (QString::compare(key, element_key, Qt::CaseInsensitive) == 0) {
const QString id( section + Cst::sep + key ); //a frame can also have an (arbitrary) key
QWidget *frame = getMainWindow()->findChild<QGroupBox *>("_primary_" + Atomic::getQtKey(id));
if (frame) { //it's a frame --> flash the border
parent->ensureWidgetVisible(frame); //scroll the ScrollBar until visible
if (frame->property("stylesheet").toString().isEmpty()) //nothing replaced yet --> store original
frame->setProperty("stylesheet", frame->styleSheet()); //(to reset with timer)
QString stylesheet_copy( frame->styleSheet() );
frame->setStyleSheet("* {background-color: " + colors::getQColor("sl_yellow").name() + "}");
frame->setStyleSheet(stylesheet_copy.replace( //flash frame border color
colors::getQColor("frameborder").name(QColor::HexRgb).toLower(),
colors::getQColor("important").name()));
//we can not stop a QTimer::singleShot so we need a persistent QTimer object
connect(&style_timer_, &QTimer::timeout, this,
[=]{ frame->setStyleSheet(frame->property("stylesheet").toString()); });
} else { //it's a widget --> highlight it
auto wid = getMainWindow()->getControlPanel()->getSectionTab()->findChild<Atomic *>(Atomic::getQtKey(id));
if (!wid)
continue;
parent->ensureWidgetVisible(wid); //scroll the ScrollBar until visible
wid->setHighlightedStyle(); //TODO: make it work for Selectors (their keys can not match)
connect(&style_timer_, &QTimer::timeout, this, [wid]{ wid->setHighlightedStyle(false); });
}
style_timer_.start(); //will re-start
auto panel = getMainWindow()->getControlPanel()->getSectionTab()->findChild<Atomic *>(Atomic::getQtKey(id));
if (!panel)
continue;
parent->ensureWidgetVisible(panel); //scroll the ScrollBar until visible
panel->setHighlightedStyle(); //TODO: make it work for Selectors (their keys can not match)
found = true; //at least one was highlighted
}
} //endfor panel_list
......@@ -457,8 +439,6 @@ int SectionTab::getIndex(const QString &section, const Qt::CaseSensitivity &sens
*/
void SectionTab::clear()
{
style_timer_.stop(); //or the timer might try to set a property of deleted object
while (this->count() > 0) {
this->widget(0)->deleteLater();
this->removeTab(0);
......
......@@ -35,7 +35,6 @@
#include <QString>
#include <QStringList>
#include <QTabWidget>
#include <QTimer>
#include <QWidget>
#include <QtXml>
......@@ -81,7 +80,6 @@ class SectionTab : public QTabWidget {
QStringList dynamic_sections_;
QList<QDomNode> dynamic_nodes_;
QList<int> dynamic_running_indices_;
QTimer style_timer_;
};
#endif //SECTIONTAB_H
......@@ -45,6 +45,10 @@ Atomic::Atomic(QString section, QString key, QWidget *parent)
{
ini_ = getMainWindow()->getIni();
createContextMenu();
style_timer_.setSingleShot(true);
style_timer_.setInterval(Cst::msg_short_length);
connect(&style_timer_, &QTimer::timeout, this, [this]{ this->setHighlightedStyle(false); });
}
/**
......@@ -115,13 +119,25 @@ void Atomic::clear(const bool &set_default)
* @brief Set property to highlight this widget.
* @details This is in addition to mandatory and valid styles, and is used
* for example to link to panels.
* @param on
* @param[in] on True to highlight, false for normal.
* @param[in] reset_interval Time after which to reset to normal (ms).
*/
void Atomic::setHighlightedStyle(const bool &on)
void Atomic::setHighlightedStyle(const bool &on, const int &reset_interval)
{
emphasis_widget_->setProperty("highlight", (on? "true" : "false"));
Group *me = qobject_cast<Group *>(this);
if (me) {
QString stylesheet_copy( getEmphasisWidget()->styleSheet() );
getEmphasisWidget()->setStyleSheet(stylesheet_copy.replace( //flash frame border color
colors::getQColor(on? "frameborder" : "important").name(QColor::HexRgb).toLower(),
colors::getQColor(on? "important" : "frameborder").name()));
} else {
emphasis_widget_->setProperty("highlight", (on? "true" : "false"));
}
this->style()->unpolish(emphasis_widget_);
this->style()->polish(emphasis_widget_);
if (reset_interval != -1)
style_timer_.start();
}
/**
......
......@@ -35,6 +35,7 @@
#include <QSpacerItem>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QWidget>
#include <QtXml>
......@@ -53,7 +54,7 @@ class Atomic : public QWidget {
static QString getQtKey(const QString &ini_key);
QString getIniValue(QString &section, QString &key) const noexcept;
virtual void clear(const bool &set_default = true);
void setHighlightedStyle(const bool &on = true);
void setHighlightedStyle(const bool &on = true, const int &reset_interval = 5000);
protected:
void setEmphasisWidget(QWidget *emphasis_widget, const bool &set_object_name = true);
......@@ -89,6 +90,7 @@ class Atomic : public QWidget {
QMenu panel_context_menu_;
INIParser *ini_ = nullptr; //pointer to the main INIParser
QTimer style_timer_;
private slots:
void onTimerBufferedUpdatesEnabled();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment