Some statusbar cleanups.

This commit is contained in:
Martin Rotter 2020-11-14 18:39:43 +01:00
parent 4c8b4d59e1
commit cc30ef1bd5
9 changed files with 60 additions and 84 deletions

View File

@ -21,7 +21,7 @@ BaseToolBar::~BaseToolBar() {
}
void BaseBar::loadSavedActions() {
loadSpecificActions(getSpecificActions(savedActions()), true);
loadSpecificActions(convertActions(savedActions()), true);
}
QAction* BaseBar::findMatchingAction(const QString& action, const QList<QAction*>& actions) const {

View File

@ -13,19 +13,25 @@ class BaseBar {
// Returns all changeable actions which are currently included
// in the toolbar.
virtual QList<QAction*> changeableActions() const = 0;
virtual QList<QAction*> activatedActions() const = 0;
// Sets new "actions" to the toolbar and perhaps saves the toolbar
// state into the settings.
virtual void saveChangeableActions(const QStringList& actions) = 0;
virtual void saveAndSetActions(const QStringList& actions) = 0;
// Returns list of default actions.
virtual QStringList defaultActions() const = 0;
// Returns list of saved actions.
virtual QStringList savedActions() const = 0;
// Loads the toolbar state from settings.
virtual void loadSavedActions();
virtual QList<QAction*> getSpecificActions(const QStringList& actions) = 0;
// Converts action names to actions.
virtual QList<QAction*> convertActions(const QStringList& actions) = 0;
// Loads list of actions into the bar.
virtual void loadSpecificActions(const QList<QAction*>& actions, bool initial_load = false) = 0;
protected:
@ -36,9 +42,7 @@ class BaseToolBar : public QToolBar, public BaseBar {
Q_OBJECT
public:
// Constructors and destructors.
explicit BaseToolBar(const QString& title, QWidget* parent = 0);
explicit BaseToolBar(const QString& title, QWidget* parent = nullptr);
virtual ~BaseToolBar();
};

View File

@ -20,16 +20,16 @@ QList<QAction*> FeedsToolBar::availableActions() const {
return qApp->userActions();
}
QList<QAction*> FeedsToolBar::changeableActions() const {
QList<QAction*> FeedsToolBar::activatedActions() const {
return actions();
}
void FeedsToolBar::saveChangeableActions(const QStringList& actions) {
void FeedsToolBar::saveAndSetActions(const QStringList& actions) {
qApp->settings()->setValue(GROUP(GUI), GUI::FeedsToolbarActions, actions.join(QSL(",")));
loadSpecificActions(getSpecificActions(actions));
loadSpecificActions(convertActions(actions));
}
QList<QAction*> FeedsToolBar::getSpecificActions(const QStringList& actions) {
QList<QAction*> FeedsToolBar::convertActions(const QStringList& actions) {
QList<QAction*> available_actions = availableActions();
QList<QAction*> spec_actions;

View File

@ -12,10 +12,10 @@ class FeedsToolBar : public BaseToolBar {
explicit FeedsToolBar(const QString& title, QWidget* parent = nullptr);
QList<QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
void saveChangeableActions(const QStringList& actions);
QList<QAction*> activatedActions() const;
void saveAndSetActions(const QStringList& actions);
QList<QAction*> getSpecificActions(const QStringList& actions);
QList<QAction*> convertActions(const QStringList& actions);
void loadSpecificActions(const QList<QAction*>& actions, bool initial_load = false);
QStringList defaultActions() const;

View File

@ -26,21 +26,21 @@ QList<QAction*> MessagesToolBar::availableActions() const {
return available_actions;
}
QList<QAction*> MessagesToolBar::changeableActions() const {
QList<QAction*> MessagesToolBar::activatedActions() const {
return actions();
}
void MessagesToolBar::saveChangeableActions(const QStringList& actions) {
void MessagesToolBar::saveAndSetActions(const QStringList& actions) {
qApp->settings()->setValue(GROUP(GUI), GUI::MessagesToolbarDefaultButtons, actions.join(QSL(",")));
loadSpecificActions(getSpecificActions(actions));
loadSpecificActions(convertActions(actions));
// If user hidden search messages box, then remove the filter.
if (!changeableActions().contains(m_actionSearchMessages)) {
if (!activatedActions().contains(m_actionSearchMessages)) {
m_txtSearchMessages->clear();
}
}
QList<QAction*> MessagesToolBar::getSpecificActions(const QStringList& actions) {
QList<QAction*> MessagesToolBar::convertActions(const QStringList& actions) {
QList<QAction*> available_actions = availableActions();
QList<QAction*> spec_actions;

View File

@ -27,15 +27,15 @@ class MessagesToolBar : public BaseToolBar {
// Implementation of BaseToolBar interface.
QList<QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
void saveChangeableActions(const QStringList& actions);
QList<QAction*> activatedActions() const;
void saveAndSetActions(const QStringList& actions);
// Loads actions as specified by external actions list.
// NOTE: This is used primarily for reloading actions
// when they are changed from settings.
void loadSpecificActions(const QList<QAction*>& actions, bool initial_load = false);
QList<QAction*> getSpecificActions(const QStringList& actions);
QList<QAction*> convertActions(const QStringList& actions);
QStringList defaultActions() const;
QStringList savedActions() const;

View File

@ -12,7 +12,7 @@
#include <QProgressBar>
#include <QToolButton>
StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QMutex::NonRecursive, this)) {
StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent) {
setSizeGripEnabled(false);
setContentsMargins(2, 0, 2, 2);
@ -21,28 +21,36 @@ StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QM
m_barProgressFeeds->setFixedWidth(100);
m_barProgressFeeds->setVisible(false);
m_barProgressFeeds->setObjectName(QSL("m_barProgressFeeds"));
m_barProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update progress bar"), this);
m_barProgressFeedsAction->setObjectName(QSL("m_barProgressFeedsAction"));
m_lblProgressFeeds = new QLabel(this);
m_lblProgressFeeds->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_lblProgressFeeds->setVisible(false);
m_lblProgressFeeds->setObjectName(QSL("m_lblProgressFeeds"));
m_lblProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update label"), this);
m_lblProgressFeedsAction->setObjectName(QSL("m_lblProgressFeedsAction"));
m_barProgressDownload = new QProgressBar(this);
m_barProgressDownload->setTextVisible(true);
m_barProgressDownload->setFixedWidth(100);
m_barProgressDownload->setVisible(false);
m_barProgressDownload->setObjectName(QSL("m_barProgressDownload"));
m_barProgressDownloadAction = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")), tr("File download progress bar"), this);
m_barProgressDownloadAction->setObjectName(QSL("m_barProgressDownloadAction"));
m_lblProgressDownload = new QLabel(this);
m_lblProgressDownload->setText("Downloading files in background");
m_lblProgressDownload->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_lblProgressDownload->setVisible(false);
m_lblProgressDownload->setObjectName(QSL("m_lblProgressDownload"));
m_lblProgressDownloadAction = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")), tr("File download label"), this);
m_lblProgressDownloadAction->setObjectName(QSL("m_lblProgressDownloadAction"));
m_lblProgressDownload->installEventFilter(this);
m_barProgressDownload->installEventFilter(this);
}
@ -62,15 +70,13 @@ QList<QAction*> StatusBar::availableActions() const {
return actions;
}
QList<QAction*> StatusBar::changeableActions() const {
QList<QAction*> StatusBar::activatedActions() const {
return actions();
}
void StatusBar::saveChangeableActions(const QStringList& actions) {
QMutexLocker locker(*m_mutex);
void StatusBar::saveAndSetActions(const QStringList& actions) {
qApp->settings()->setValue(GROUP(GUI), GUI::StatusbarActions, actions.join(QSL(",")));
loadSpecificActions(getSpecificActions(actions));
loadSpecificActions(convertActions(actions));
}
QStringList StatusBar::defaultActions() const {
@ -92,7 +98,7 @@ QStringList StatusBar::savedActions() const {
#endif
}
QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
QList<QAction*> StatusBar::convertActions(const QStringList& actions) {
bool progress_visible = this->actions().contains(m_barProgressFeedsAction) && m_lblProgressFeeds->isVisible() &&
m_barProgressFeeds->isVisible();
QList<QAction*> available_actions = availableActions();
@ -127,19 +133,17 @@ QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
}
else {
if (action_name == SEPARATOR_ACTION_NAME) {
QLabel* lbl = new QLabel(QString::fromUtf8(""));
QLabel* lbl = new QLabel(QString::fromUtf8(""), this);
widget_to_add = lbl;
action_to_add = new QAction(this);
action_to_add->setSeparator(true);
action_to_add->setProperty("should_remove_action", true);
}
else if (action_name == SPACER_ACTION_NAME) {
QLabel* lbl = new QLabel(QSL("\t\t"));
QLabel* lbl = new QLabel(QSL("\t\t"), this);
widget_to_add = lbl;
action_to_add = new QAction(this);
action_to_add->setProperty("should_remove_action", true);
action_to_add->setIcon(qApp->icons()->fromTheme(QSL("system-search")));
action_to_add->setProperty("type", SPACER_ACTION_NAME);
action_to_add->setProperty("name", tr("Toolbar spacer"));
@ -158,10 +162,6 @@ QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
action_to_add = nullptr;
widget_to_add = nullptr;
}
if (action_to_add != nullptr) {
action_to_add->setProperty("should_remove_widget", true);
}
}
if (action_to_add != nullptr && widget_to_add != nullptr) {
@ -174,38 +174,25 @@ QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
}
void StatusBar::loadSpecificActions(const QList<QAction*>& actions, bool initial_load) {
for (QAction* act : this->actions()) {
QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr;
if (widget != nullptr) {
removeWidget(widget);
}
}
if (!initial_load) {
removeWidget(m_barProgressDownload);
removeWidget(m_barProgressFeeds);
removeWidget(m_lblProgressDownload);
removeWidget(m_lblProgressFeeds);
}
clear();
for (QAction* act : actions) {
QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr;
if (initial_load) {
for (QAction* act : actions) {
QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr;
addAction(act);
addAction(act);
// And also add widget.
if (widget != nullptr) {
addPermanentWidget(widget);
// And also add widget.
if (widget != nullptr) {
addPermanentWidget(widget);
}
}
}
}
bool StatusBar::eventFilter(QObject* watched, QEvent* event) {
if (watched == m_lblProgressDownload || watched == m_barProgressDownload) {
if (event->type() == QEvent::MouseButtonPress) {
if (event->type() == QEvent::Type::MouseButtonPress) {
qApp->mainForm()->tabWidget()->showDownloadManager();
}
}
@ -217,24 +204,13 @@ void StatusBar::clear() {
while (!actions().isEmpty()) {
QAction* act = actions().at(0);
QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr;
bool should_remove_widget = act->property("should_remove_widget").isValid();
bool should_remove_action = act->property("should_remove_action").isValid();
removeAction(act);
if (widget != nullptr) {
removeWidget(widget);
widget->setVisible(false);
if (should_remove_widget) {
widget->deleteLater();
act->setProperty("widget", QVariant());
}
if (should_remove_action) {
act->deleteLater();
}
}
removeAction(act);
}
}

View File

@ -8,12 +8,8 @@
#include "gui/basetoolbar.h"
class QProgressBar;
class PlainToolButton;
class QLabel;
class Mutex;
class PlainToolButton;
class StatusBar : public QStatusBar, public BaseBar {
Q_OBJECT
@ -23,11 +19,11 @@ class StatusBar : public QStatusBar, public BaseBar {
virtual ~StatusBar();
QList<QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
void saveChangeableActions(const QStringList& actions);
QList<QAction*> activatedActions() const;
void saveAndSetActions(const QStringList& actions);
QStringList defaultActions() const;
QStringList savedActions() const;
QList<QAction*> getSpecificActions(const QStringList& actions);
QList<QAction*> convertActions(const QStringList& actions);
void loadSpecificActions(const QList<QAction*>& actions, bool initial_load = false);
public slots:
@ -43,7 +39,6 @@ class StatusBar : public QStatusBar, public BaseBar {
private:
void clear();
Mutex* m_mutex;
QProgressBar* m_barProgressFeeds;
QAction* m_barProgressFeedsAction;
QLabel* m_lblProgressFeeds;

View File

@ -38,8 +38,9 @@ ToolBarEditor::ToolBarEditor(QWidget* parent)
void ToolBarEditor::loadFromToolBar(BaseBar* tool_bar) {
m_toolBar = tool_bar;
QList<QAction*> activated_actions = m_toolBar->changeableActions();
QList<QAction*> activated_actions = m_toolBar->activatedActions();
QList<QAction*> available_actions = m_toolBar->availableActions();
loadEditor(activated_actions, available_actions);
}
@ -50,12 +51,12 @@ void ToolBarEditor::saveToolBar() {
action_names.append(m_ui->m_listActivatedActions->item(i)->data(Qt::UserRole).toString());
}
m_toolBar->saveChangeableActions(action_names);
m_toolBar->saveAndSetActions(action_names);
}
void ToolBarEditor::resetToolBar() {
if (m_toolBar != nullptr) {
loadEditor(m_toolBar->getSpecificActions(m_toolBar->defaultActions()), m_toolBar->availableActions());
loadEditor(m_toolBar->convertActions(m_toolBar->defaultActions()), m_toolBar->availableActions());
}
}