rssguard/src/gui/feedstoolbar.cpp

106 lines
3.5 KiB
C++
Raw Normal View History

// This file is part of RSS Guard.
//
2017-03-25 10:11:18 +01:00
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
2014-04-07 08:21:55 +02:00
#include "gui/feedstoolbar.h"
2014-08-22 09:27:01 +02:00
#include "miscellaneous/application.h"
2014-04-07 08:21:55 +02:00
#include "miscellaneous/settings.h"
2014-08-22 09:27:01 +02:00
#include "miscellaneous/iconfactory.h"
2014-04-07 08:21:55 +02:00
2017-06-16 12:31:42 +02:00
#include <QWidgetAction>
2014-04-07 08:21:55 +02:00
FeedsToolBar::FeedsToolBar(const QString &title, QWidget *parent) : BaseToolBar(title, parent) {
// Update right margin of filter textbox.
QMargins margins = contentsMargins();
margins.setRight(margins.right() + FILTER_RIGHT_MARGIN);
setContentsMargins(margins);
}
FeedsToolBar::~FeedsToolBar() {
}
QList<QAction*> FeedsToolBar::availableActions() const {
return qApp->userActions();
2014-04-07 08:21:55 +02:00
}
2014-07-26 14:52:16 +02:00
QList<QAction*> FeedsToolBar::changeableActions() const {
2014-04-07 08:21:55 +02:00
return actions();
}
void FeedsToolBar::saveChangeableActions(const QStringList &actions) {
2015-06-24 09:10:43 +02:00
qApp->settings()->setValue(GROUP(GUI), GUI::FeedsToolbarActions, actions.join(QSL(",")));
2017-06-16 12:31:42 +02:00
loadSpecificActions(getSpecificActions(actions));
2014-04-07 08:21:55 +02:00
}
2017-06-16 12:31:42 +02:00
QList<QAction*> FeedsToolBar::getSpecificActions(const QStringList &actions) {
QList<QAction*> available_actions = availableActions();
2017-06-16 12:31:42 +02:00
QList<QAction*> spec_actions;
2014-04-07 08:21:55 +02:00
// Iterate action names and add respectable actions into the toolbar.
foreach (const QString &action_name, actions) {
QAction *matching_action = findMatchingAction(action_name, available_actions);
2016-06-20 07:58:29 +02:00
if (matching_action != nullptr) {
2014-04-07 08:21:55 +02:00
// Add existing standard action.
2017-06-16 12:31:42 +02:00
spec_actions.append(matching_action);
2014-04-07 08:21:55 +02:00
}
else if (action_name == SEPARATOR_ACTION_NAME) {
// Add new separator.
2017-06-16 12:31:42 +02:00
QAction *act = new QAction(this);
act->setSeparator(true);
spec_actions.append(act);
2014-04-07 08:21:55 +02:00
}
else if (action_name == SPACER_ACTION_NAME) {
// Add new spacer.
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
2017-06-16 12:31:42 +02:00
QWidgetAction *action = new QWidgetAction(this);
action->setDefaultWidget(spacer);
2016-05-01 20:48:04 +02:00
action->setIcon(qApp->icons()->fromTheme(QSL("system-search")));
2014-04-07 08:21:55 +02:00
action->setProperty("type", SPACER_ACTION_NAME);
action->setProperty("name", tr("Toolbar spacer"));
2017-06-16 12:31:42 +02:00
spec_actions.append(action);
2014-04-07 08:21:55 +02:00
}
}
2017-06-16 12:31:42 +02:00
return spec_actions;
}
void FeedsToolBar::loadSpecificActions(const QList<QAction*> &actions) {
clear();
foreach (QAction *act, actions) {
addAction(act);
}
}
QStringList FeedsToolBar::defaultActions() const {
return QString(GUI::FeedsToolbarActionsDef).split(',',
QString::SkipEmptyParts);
}
QStringList FeedsToolBar::savedActions() const {
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::FeedsToolbarActions)).toString().split(',',
QString::SkipEmptyParts);
2014-04-07 08:21:55 +02:00
}