This commit is contained in:
Martin Rotter 2016-03-17 11:27:57 +01:00
parent c25371eca7
commit a889db4f6b
14 changed files with 234 additions and 57 deletions

View file

@ -9,6 +9,7 @@ http://goo.gl/forms/GcvPYgS2a8
Added:
▪ Added experimental support for tweakable statusbar. (issue #158)
▪ Opening of download manager when new file download starts is now optional. (issue #165)
Fixed:

View file

@ -35,7 +35,7 @@ BaseToolBar::~BaseToolBar() {
qDebug("Destroying BaseToolBar instance.");
}
QAction *BaseToolBar::findMatchingAction(const QString &action, const QList<QAction*> actions) const {
QAction *BaseBar::findMatchingAction(const QString &action, const QList<QAction*> actions) const {
foreach (QAction *act, actions) {
if (act->objectName() == action) {
return act;

View file

@ -21,14 +21,8 @@
#include <QToolBar>
class BaseToolBar : public QToolBar {
Q_OBJECT
class BaseBar {
public:
// Constructors and destructors.
explicit BaseToolBar(const QString &title, QWidget *parent = 0);
virtual ~BaseToolBar();
// Returns all actions which can be added to the toolbar.
virtual QList<QAction*> availableActions() const = 0;
@ -47,4 +41,13 @@ class BaseToolBar : public QToolBar {
QAction *findMatchingAction(const QString &action, const QList<QAction*> actions) const;
};
class BaseToolBar : public QToolBar, public BaseBar {
Q_OBJECT
public:
// Constructors and destructors.
explicit BaseToolBar(const QString &title, QWidget *parent = 0);
virtual ~BaseToolBar();
};
#endif // TOOLBAR_H

View file

@ -83,6 +83,8 @@ FormMain::FormMain(QWidget *parent, Qt::WindowFlags f)
setupIcons();
loadSize();
m_statusBar->loadChangeableActions();
// Initialize the web factory.
WebFactory::instance()->loadState();
}
@ -475,9 +477,6 @@ void FormMain::saveSize() {
void FormMain::createConnections() {
// Status bar connections.
connect(m_statusBar->fullscreenSwitcher(), SIGNAL(toggled(bool)), m_ui->m_actionFullscreen, SLOT(setChecked(bool)));
connect(m_ui->m_actionFullscreen, SIGNAL(toggled(bool)), m_statusBar->fullscreenSwitcher(), SLOT(setChecked(bool)));
connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu()));
connect(m_ui->m_menuRecycleBin, SIGNAL(aboutToShow()), this, SLOT(updateRecycleBinMenu()));
connect(m_ui->m_menuAccounts, SIGNAL(aboutToShow()), this, SLOT(updateAccountsMenu()));

View file

@ -41,6 +41,7 @@
#include "gui/basetoolbar.h"
#include "gui/messagestoolbar.h"
#include "gui/messagesview.h"
#include "gui/statusbar.h"
#include "gui/dialogs/formmain.h"
#include "dynamic-shortcuts/dynamicshortcuts.h"
@ -803,6 +804,7 @@ void FormSettings::loadInterface() {
// Load toolbars.
m_ui->m_editorFeedsToolbar->loadFromToolBar(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsToolBar());
m_ui->m_editorMessagesToolbar->loadFromToolBar(qApp->mainForm()->tabWidget()->feedMessageViewer()->messagesToolBar());
m_ui->m_editorStatusbar->loadFromToolBar(qApp->mainForm()->statusBar());
}
void FormSettings::saveInterface() {
@ -858,6 +860,7 @@ void FormSettings::saveInterface() {
m_ui->m_editorFeedsToolbar->saveToolBar();
m_ui->m_editorMessagesToolbar->saveToolBar();
m_ui->m_editorStatusbar->saveToolBar();
qApp->mainForm()->tabWidget()->checkTabBarVisibility();
qApp->mainForm()->tabWidget()->feedMessageViewer()->refreshVisualProperties();

View file

@ -88,7 +88,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>7</number>
<number>3</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -417,8 +417,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>782</width>
<height>451</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -495,8 +495,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect>
<x>0</x>
<y>0</y>
<width>208</width>
<height>238</height>
<width>776</width>
<height>425</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -782,6 +782,11 @@ Authors of this application are NOT responsible for lost data.</string>
<string>Toolbar for messages list</string>
</property>
</item>
<item>
<property name="text">
<string>Statusbar</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
@ -833,6 +838,25 @@ Authors of this application are NOT responsible for lost data.</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_pageStatusbar">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="ToolBarEditor" name="m_editorStatusbar" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="0" column="0">

View file

@ -22,6 +22,7 @@
#include <QPainter>
#include <QPaintEvent>
#include <QStyleOption>
#include <QAction>
PlainToolButton::PlainToolButton(QWidget *parent) : QToolButton(parent), m_padding(0) {
@ -39,9 +40,13 @@ void PlainToolButton::paintEvent(QPaintEvent *e) {
// Set padding.
rect.adjust(m_padding, m_padding, -m_padding, -m_padding);
// Paint the icon.
if (underMouse() || isChecked()) {
p.setOpacity(0.7);
if (isEnabled()) {
if (underMouse() || isChecked()) {
p.setOpacity(0.7);
}
}
else {
p.setOpacity(0.3);
}
icon().paint(&p, rect);
@ -60,3 +65,13 @@ void PlainToolButton::setChecked(bool checked) {
QToolButton::setChecked(checked);
repaint();
}
void PlainToolButton::reactOnActionChange(QAction *action) {
QAction *real_action = action == NULL ? qobject_cast<QAction*>(sender()) : action;
setEnabled(real_action->isEnabled());
setCheckable(real_action->isCheckable());
setChecked(real_action->isChecked());
setIcon(real_action->icon());
setToolTip(real_action->toolTip());
}

View file

@ -35,6 +35,7 @@ class PlainToolButton : public QToolButton {
public slots:
void setChecked(bool checked);
void reactOnActionChange(QAction *action = NULL);
protected:
// Custom look.

View file

@ -31,53 +31,146 @@
StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
setSizeGripEnabled(false);
setContentsMargins(0, 0, 0, 0);
setContentsMargins(2, 2, 2, 2);
m_adBlockIcon = new AdBlockIcon(this);
m_adBlockIcon->activate();
m_adBlockIcon->setObjectName(QSL("m_adBlockIcon"));
// Initializations of widgets for status bar.
m_fullscreenSwitcher = new PlainToolButton(this);
m_fullscreenSwitcher->setCheckable(true);
m_fullscreenSwitcher->setIcon(qApp->icons()->fromTheme(QSL("view-fullscreen")));
m_fullscreenSwitcher->setText(tr("Fullscreen mode"));
m_fullscreenSwitcher->setToolTip(tr("Switch application between fulscreen/normal states right from this status bar icon."));
m_adBlockIconAction = new QAction(qApp->icons()->fromTheme("web-adblock"), tr("Adblock"), this);
m_adBlockIconAction->setObjectName(QSL("m_adBlockIconAction"));
m_barProgressFeeds = new QProgressBar(this);
m_barProgressFeeds->setTextVisible(false);
m_barProgressFeeds->setFixedWidth(100);
m_barProgressFeeds->setVisible(false);
m_barProgressFeeds->setObjectName(QSL("m_barProgressFeeds"));
m_barProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("folder-feed")), 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("folder-feed")), 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("download-manager")), 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("download-manager")), tr("File download label"), this);
m_lblProgressDownloadAction->setObjectName(QSL("m_lblProgressDownloadAction"));
m_lblProgressDownload->installEventFilter(this);
m_barProgressDownload->installEventFilter(this);
// Add widgets.
addPermanentWidget(m_lblProgressFeeds);
addPermanentWidget(m_barProgressFeeds);
addPermanentWidget(m_lblProgressDownload);
addPermanentWidget(m_barProgressDownload);
addPermanentWidget(m_adBlockIcon);
addPermanentWidget(m_fullscreenSwitcher);
}
StatusBar::~StatusBar() {
clear();
qDebug("Destroying StatusBar instance.");
}
QList<QAction*> StatusBar::availableActions() const {
QList<QAction*> actions = qApp->userActions();
// Now, add placeholder actions for custom stuff.
actions << m_adBlockIconAction << m_barProgressDownloadAction << m_barProgressFeedsAction <<
m_lblProgressDownloadAction << m_lblProgressFeedsAction;
return actions;
}
QList<QAction*> StatusBar::changeableActions() const {
return actions();
}
void StatusBar::saveChangeableActions(const QStringList &actions) {
qApp->settings()->setValue(GROUP(GUI), GUI::StatusbarActions, actions.join(QSL(",")));
loadChangeableActions(actions);
}
void StatusBar::loadChangeableActions() {
QStringList action_names = qApp->settings()->value(GROUP(GUI), SETTING(GUI::StatusbarActions)).toString().split(',',
QString::SkipEmptyParts);
loadChangeableActions(action_names);
}
void StatusBar::loadChangeableActions(const QStringList &action_names) {
clear();
QList<QAction*> available_actions = availableActions();
// Iterate action names and add respectable actions into the toolbar.
foreach (const QString &action_name, action_names) {
QAction *matching_action = findMatchingAction(action_name, available_actions);
QAction *action_to_add;
QWidget *widget_to_add;
if (matching_action == m_adBlockIconAction) {
widget_to_add = m_adBlockIcon;
action_to_add = m_adBlockIconAction;
widget_to_add->setVisible(true);
}
else if (matching_action == m_barProgressDownloadAction) {
widget_to_add = m_barProgressDownload;
action_to_add = m_barProgressDownloadAction;
widget_to_add->setVisible(false);
}
else if (matching_action == m_barProgressFeedsAction) {
widget_to_add = m_barProgressFeeds;
action_to_add = m_barProgressFeedsAction;
widget_to_add->setVisible(false);
}
else if (matching_action == m_lblProgressDownloadAction) {
widget_to_add = m_lblProgressDownload;
action_to_add = m_lblProgressDownloadAction;
widget_to_add->setVisible(false);
}
else if (matching_action == m_lblProgressFeedsAction) {
widget_to_add = m_lblProgressFeeds;
action_to_add = m_lblProgressFeedsAction;
widget_to_add->setVisible(false);
}
else {
// Add originally toolbar action.
PlainToolButton *tool_button = new PlainToolButton(this);
tool_button->reactOnActionChange(matching_action);
action_to_add = matching_action;
widget_to_add = tool_button;
matching_action->setProperty("should_remove", true);
connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger()));
connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange()));
}
action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add));
addPermanentWidget(widget_to_add);
addAction(action_to_add);
}
}
bool StatusBar::eventFilter(QObject *watched, QEvent *event) {
if (watched == m_lblProgressDownload || watched == m_barProgressDownload) {
if (event->type() == QEvent::MouseButtonPress) {
@ -88,12 +181,33 @@ bool StatusBar::eventFilter(QObject *watched, QEvent *event) {
return false;
}
void StatusBar::showProgressFeeds(int progress, const QString &label) {
m_lblProgressFeeds->setVisible(true);
m_barProgressFeeds->setVisible(true);
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*>()) : NULL;
bool should_remove = act->property("remove_widget").isValid();
m_lblProgressFeeds->setText(label);
m_barProgressFeeds->setValue(progress);
if (widget != NULL) {
removeWidget(widget);
widget->setVisible(false);
if (should_remove) {
widget->deleteLater();
}
}
removeAction(act);
}
}
void StatusBar::showProgressFeeds(int progress, const QString &label) {
if (actions().contains(m_barProgressFeedsAction)) {
m_lblProgressFeeds->setVisible(true);
m_barProgressFeeds->setVisible(true);
m_lblProgressFeeds->setText(label);
m_barProgressFeeds->setValue(progress);
}
}
void StatusBar::clearProgressFeeds() {
@ -102,11 +216,13 @@ void StatusBar::clearProgressFeeds() {
}
void StatusBar::showProgressDownload(int progress, const QString &tooltip) {
m_lblProgressDownload->setVisible(true);
m_barProgressDownload->setVisible(true);
m_barProgressDownload->setValue(progress);
m_barProgressDownload->setToolTip(tooltip);
m_lblProgressDownload->setToolTip(tooltip);
if (actions().contains(m_barProgressDownloadAction)) {
m_lblProgressDownload->setVisible(true);
m_barProgressDownload->setVisible(true);
m_barProgressDownload->setValue(progress);
m_barProgressDownload->setToolTip(tooltip);
m_lblProgressDownload->setToolTip(tooltip);
}
}
void StatusBar::clearProgressDownload() {

View file

@ -20,13 +20,14 @@
#include <QStatusBar>
#include "gui/basetoolbar.h"
class QProgressBar;
class PlainToolButton;
class QLabel;
class AdBlockIcon;
class StatusBar : public QStatusBar {
class StatusBar : public QStatusBar, public BaseBar {
Q_OBJECT
public:
@ -34,13 +35,10 @@ class StatusBar : public QStatusBar {
explicit StatusBar(QWidget *parent = 0);
virtual ~StatusBar();
inline PlainToolButton *fullscreenSwitcher() const {
return m_fullscreenSwitcher;
}
inline AdBlockIcon *adBlockIcon() {
return m_adBlockIcon;
}
QList<QAction*> availableActions() const;
QList<QAction*> changeableActions() const;
void saveChangeableActions(const QStringList &actions);
void loadChangeableActions();
public slots:
// Progress bar operations
@ -54,12 +52,23 @@ class StatusBar : public QStatusBar {
bool eventFilter(QObject *watched, QEvent *event);
private:
void clear();
void loadChangeableActions(const QStringList &action_names);
QProgressBar *m_barProgressFeeds;
QAction *m_barProgressFeedsAction;
QLabel *m_lblProgressFeeds;
QAction *m_lblProgressFeedsAction;
QProgressBar *m_barProgressDownload;
QAction *m_barProgressDownloadAction;
QLabel *m_lblProgressDownload;
PlainToolButton *m_fullscreenSwitcher;
QAction *m_lblProgressDownloadAction;
AdBlockIcon* m_adBlockIcon;
QAction *m_adBlockIconAction;
};
#endif // STATUSBAR_H

View file

@ -49,7 +49,7 @@ ToolBarEditor::~ToolBarEditor() {
qDebug("Destroying ToolBarEditor instance.");
}
void ToolBarEditor::loadFromToolBar(BaseToolBar *tool_bar) {
void ToolBarEditor::loadFromToolBar(BaseBar *tool_bar) {
m_toolBar = tool_bar;
QList<QAction*> activated_actions = m_toolBar->changeableActions();

View file

@ -27,7 +27,7 @@ namespace Ui {
class ToolBarEditor;
}
class BaseToolBar;
class BaseBar;
class ToolBarEditor : public QWidget {
Q_OBJECT
@ -38,7 +38,7 @@ class ToolBarEditor : public QWidget {
virtual ~ToolBarEditor();
// Toolbar operations.
void loadFromToolBar(BaseToolBar *tool_bar);
void loadFromToolBar(BaseBar *tool_bar);
void saveToolBar();
inline QListWidget *activeItemsWidget() const {
@ -68,7 +68,7 @@ class ToolBarEditor : public QWidget {
private:
QScopedPointer<Ui::ToolBarEditor> m_ui;
BaseToolBar *m_toolBar;
BaseBar *m_toolBar;
};
#endif // TOOLBAREDITOR_H

View file

@ -84,6 +84,9 @@ DVALUE(Qt::ToolButtonStyle) GUI::ToolbarStyleDef = Qt::ToolButtonIconOnly;
DKEY GUI::FeedsToolbarActions = "feeds_toolbar";
DVALUE(char*) GUI::FeedsToolbarActionsDef = "m_actionUpdateAllItems,m_actionStopRunningItemsUpdate,m_actionMarkAllItemsRead";
DKEY GUI::StatusbarActions = "status_bar";
DVALUE(char*) GUI::StatusbarActionsDef = "m_lblProgressFeedsAction,m_barProgressFeedsAction,m_actionUpdateAllItems,m_actionUpdateSelectedItems,m_actionStopRunningItemsUpdate,m_adBlockIconAction,m_actionFullscreen,m_actionQuit";
DKEY GUI::MainWindowInitialSize = "window_size";
DKEY GUI::MainWindowInitialPosition = "window_position";

View file

@ -101,6 +101,9 @@ namespace GUI {
KEY FeedsToolbarActions;
VALUE(char*) FeedsToolbarActionsDef;
KEY StatusbarActions;
VALUE(char*) StatusbarActionsDef;
KEY MainWindowInitialSize;
KEY MainWindowInitialPosition;