Good progress for changeable toolbars.
This commit is contained in:
parent
69354c91a2
commit
12685b2df6
resources/graphics/icons/mini-kfaenza
src
BIN
resources/graphics/icons/mini-kfaenza/application-search.png
Normal file
BIN
resources/graphics/icons/mini-kfaenza/application-search.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 310 B |
BIN
resources/graphics/icons/mini-kfaenza/view-separator.png
Normal file
BIN
resources/graphics/icons/mini-kfaenza/view-separator.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.8 KiB |
BIN
resources/graphics/icons/mini-kfaenza/view-spacer.png
Normal file
BIN
resources/graphics/icons/mini-kfaenza/view-spacer.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 1.8 KiB |
@ -64,7 +64,7 @@
|
||||
#define STARTUP_UPDATE_DELAY 1500
|
||||
#define TIMEZONE_OFFSET_LIMIT 6
|
||||
#define CHANGE_EVENT_DELAY 250
|
||||
#define FILTER_OBJECT_NAME "filter"
|
||||
#define SEACRH_MESSAGES_ACTION_NAME "filter"
|
||||
#define SPACER_ACTION_NAME "spacer"
|
||||
#define SEPARATOR_ACTION_NAME "separator"
|
||||
#define FILTER_WIDTH 150
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "gui/formmain.h"
|
||||
#include "miscellaneous/settings.h"
|
||||
|
||||
#include <QWidgetAction>
|
||||
|
||||
|
||||
BaseToolBar::BaseToolBar(const QString &title, QWidget *parent)
|
||||
: QToolBar(title, parent) {
|
||||
|
@ -12,16 +12,19 @@ class BaseToolBar : public QToolBar {
|
||||
explicit BaseToolBar(const QString &title, QWidget *parent = 0);
|
||||
virtual ~BaseToolBar();
|
||||
|
||||
virtual QList<QAction*> availableActions() const = 0;
|
||||
// Returns all actions which can be added to the toolbar.
|
||||
virtual QHash<QString, QAction*> availableActions() const = 0;
|
||||
|
||||
// Returns all changeable actions which are currently included
|
||||
// in the toolbar.
|
||||
virtual QList<QAction*> changeableActions() const = 0;
|
||||
virtual void saveChangeableActions() const = 0;
|
||||
|
||||
// Sets new "actions" to the toolbar and perhaps saves the toolbar
|
||||
// state into the settings.
|
||||
virtual void saveChangeableActions(const QStringList &actions) = 0;
|
||||
|
||||
// Loads the toolbar state from settings.
|
||||
virtual void loadChangeableActions() = 0;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // TOOLBAR_H
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "definitions/definitions.h"
|
||||
#include "gui/baselineedit.h"
|
||||
#include "gui/formmain.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/settings.h"
|
||||
|
||||
#include <QWidgetAction>
|
||||
@ -10,13 +11,17 @@
|
||||
|
||||
MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
|
||||
: BaseToolBar(title, parent),
|
||||
m_txtFilter(new BaseLineEdit(this)) {
|
||||
m_txtFilter->setFixedWidth(FILTER_WIDTH);
|
||||
m_txtFilter->setPlaceholderText(tr("Filter messages"));
|
||||
m_actionFilter = new QWidgetAction(this);
|
||||
m_actionFilter->setDefaultWidget(m_txtFilter);
|
||||
m_actionFilter->setProperty("type", FILTER_OBJECT_NAME);
|
||||
m_actionFilter->setProperty("name", tr("message filter"));
|
||||
m_txtSearchMessages(new BaseLineEdit(this)) {
|
||||
|
||||
m_txtSearchMessages->setFixedWidth(FILTER_WIDTH);
|
||||
m_txtSearchMessages->setPlaceholderText(tr("Filter messages"));
|
||||
|
||||
// Setup wrapping action for search box.
|
||||
m_actionSearchMessages = new QWidgetAction(this);
|
||||
m_actionSearchMessages->setDefaultWidget(m_txtSearchMessages);
|
||||
m_actionSearchMessages->setIcon(IconFactory::instance()->fromTheme("view-spacer"));
|
||||
m_actionSearchMessages->setProperty("type", SEACRH_MESSAGES_ACTION_NAME);
|
||||
m_actionSearchMessages->setProperty("name", tr("Message search box"));
|
||||
|
||||
// Update right margin of filter textbox.
|
||||
QMargins margins = contentsMargins();
|
||||
@ -27,9 +32,9 @@ MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
|
||||
MessagesToolBar::~MessagesToolBar() {
|
||||
}
|
||||
|
||||
QList<QAction*> MessagesToolBar::availableActions() const {
|
||||
QList<QAction*> available_actions = FormMain::instance()->allActions().values();
|
||||
available_actions.append(m_actionFilter);
|
||||
QHash<QString, QAction*> MessagesToolBar::availableActions() const {
|
||||
QHash<QString, QAction*> available_actions = FormMain::instance()->allActions();
|
||||
available_actions.insert(SEACRH_MESSAGES_ACTION_NAME, m_actionSearchMessages);
|
||||
return available_actions;
|
||||
}
|
||||
|
||||
@ -37,45 +42,18 @@ QList<QAction*> MessagesToolBar::changeableActions() const {
|
||||
return actions();
|
||||
}
|
||||
|
||||
void MessagesToolBar::saveChangeableActions() const {
|
||||
QStringList action_names;
|
||||
|
||||
// Iterates all actions present in the toolbar and
|
||||
// returns actions which can be replaced by user.
|
||||
foreach (QAction *action, actions()) {
|
||||
if (action->isSeparator()) {
|
||||
// This action is separator, add its "name" to settings.
|
||||
action_names.append(SEPARATOR_ACTION_NAME);
|
||||
}
|
||||
else if (action->property("type").isValid()) {
|
||||
// This action is extra widget or spacer.
|
||||
action_names.append(action->property("type").toString());
|
||||
}
|
||||
else {
|
||||
// This action is normal action.
|
||||
action_names.append(action->objectName());
|
||||
}
|
||||
}
|
||||
|
||||
Settings::instance()->setValue(APP_CFG_GUI, "messages_toolbar", action_names.join(","));
|
||||
}
|
||||
|
||||
void MessagesToolBar::saveChangeableActions(const QStringList& actions) {
|
||||
Settings::instance()->setValue(APP_CFG_GUI, "messages_toolbar", actions.join(","));
|
||||
loadChangeableActions();
|
||||
loadChangeableActions(actions);
|
||||
}
|
||||
|
||||
void MessagesToolBar::loadChangeableActions() {
|
||||
QHash<QString, QAction*> available_actions = FormMain::instance()->allActions();
|
||||
QStringList action_names = Settings::instance()->value(APP_CFG_GUI,
|
||||
"messages_toolbar",
|
||||
"m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages,spacer,filter").toString().split(',',
|
||||
QString::SkipEmptyParts);
|
||||
void MessagesToolBar::loadChangeableActions(const QStringList& actions) {
|
||||
QHash<QString, QAction*> available_actions = availableActions();
|
||||
|
||||
clear();
|
||||
|
||||
// Iterate action names and add respectable actions into the toolbar.
|
||||
foreach (const QString &action_name, action_names) {
|
||||
foreach (const QString &action_name, actions) {
|
||||
if (available_actions.contains(action_name)) {
|
||||
// Add existing standard action.
|
||||
addAction(available_actions.value(action_name));
|
||||
@ -84,9 +62,9 @@ void MessagesToolBar::loadChangeableActions() {
|
||||
// Add new separator.
|
||||
addSeparator();
|
||||
}
|
||||
else if (action_name == FILTER_OBJECT_NAME) {
|
||||
// Add filter.
|
||||
addAction(m_actionFilter);
|
||||
else if (action_name == SEACRH_MESSAGES_ACTION_NAME) {
|
||||
// Add search box.
|
||||
addAction(m_actionSearchMessages);
|
||||
}
|
||||
else if (action_name == SPACER_ACTION_NAME) {
|
||||
// Add new spacer.
|
||||
@ -94,8 +72,18 @@ void MessagesToolBar::loadChangeableActions() {
|
||||
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
QAction *action = addWidget(spacer);
|
||||
action->setIcon(IconFactory::instance()->fromTheme("application-search"));
|
||||
action->setProperty("type", SPACER_ACTION_NAME);
|
||||
action->setProperty("name", tr("spacer"));
|
||||
action->setProperty("name", tr("Toolbar spacer"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesToolBar::loadChangeableActions() {
|
||||
QStringList action_names = Settings::instance()->value(APP_CFG_GUI,
|
||||
"messages_toolbar",
|
||||
"m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages,spacer,filter").toString().split(',',
|
||||
QString::SkipEmptyParts);
|
||||
|
||||
loadChangeableActions(action_names);
|
||||
}
|
||||
|
@ -15,20 +15,24 @@ class MessagesToolBar : public BaseToolBar {
|
||||
explicit MessagesToolBar(const QString &title, QWidget *parent = 0);
|
||||
virtual ~MessagesToolBar();
|
||||
|
||||
// Operations with changeable actions.
|
||||
QList<QAction*> availableActions() const;
|
||||
// Implementation of BaseToolBar interface.
|
||||
QHash<QString, QAction*> availableActions() const;
|
||||
QList<QAction*> changeableActions() const;
|
||||
void saveChangeableActions() const;
|
||||
void saveChangeableActions(const QStringList &actions);
|
||||
void loadChangeableActions();
|
||||
|
||||
// Loads actions as specified by external actions list.
|
||||
// NOTE: This is used primarily for reloading actions
|
||||
// when they are changed from settings.
|
||||
void loadChangeableActions(const QStringList &actions);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QWidgetAction *m_actionFilter;
|
||||
BaseLineEdit *m_txtFilter;
|
||||
QWidgetAction *m_actionSearchMessages;
|
||||
BaseLineEdit *m_txtSearchMessages;
|
||||
};
|
||||
|
||||
#endif // NEWSTOOLBAR_H
|
||||
|
@ -9,6 +9,10 @@
|
||||
ToolBarEditor::ToolBarEditor(QWidget *parent)
|
||||
: QWidget(parent), m_ui(new Ui::ToolBarEditor) {
|
||||
m_ui->setupUi(this);
|
||||
|
||||
// Create connections.
|
||||
connect(m_ui->m_btnInsertSeparator, SIGNAL(clicked()), this, SLOT(insertSeparator()));
|
||||
connect(m_ui->m_btnInsertSpacer, SIGNAL(clicked()), this, SLOT(insertSpacer()));
|
||||
}
|
||||
|
||||
ToolBarEditor::~ToolBarEditor() {
|
||||
@ -19,7 +23,7 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
|
||||
m_toolBar = tool_bar;
|
||||
|
||||
QList<QAction*> activated_actions = m_toolBar->changeableActions();
|
||||
QList<QAction*> available_actions = m_toolBar->availableActions();
|
||||
QList<QAction*> available_actions = m_toolBar->availableActions().values();
|
||||
|
||||
foreach (QAction *action, activated_actions) {
|
||||
QListWidgetItem *action_item = new QListWidgetItem(action->icon(),
|
||||
@ -28,7 +32,8 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
|
||||
|
||||
if (action->isSeparator()) {
|
||||
action_item->setData(Qt::UserRole, SEPARATOR_ACTION_NAME);
|
||||
action_item->setText(tr("separator"));
|
||||
action_item->setIcon(IconFactory::instance()->fromTheme("view-separator"));
|
||||
action_item->setText(tr("Separator"));
|
||||
}
|
||||
else if (action->property("type").isValid()) {
|
||||
action_item->setData(Qt::UserRole, action->property("type").toString());
|
||||
@ -47,7 +52,8 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
|
||||
|
||||
if (action->isSeparator()) {
|
||||
action_item->setData(Qt::UserRole, SEPARATOR_ACTION_NAME);
|
||||
action_item->setText(tr("separator"));
|
||||
action_item->setText(tr("Separator"));
|
||||
action_item->setIcon(IconFactory::instance()->fromTheme("view-separator"));
|
||||
}
|
||||
else if (action->property("type").isValid()) {
|
||||
action_item->setData(Qt::UserRole, action->property("type").toString());
|
||||
@ -71,3 +77,33 @@ void ToolBarEditor::saveToolBar() {
|
||||
|
||||
m_toolBar->saveChangeableActions(action_names);
|
||||
}
|
||||
|
||||
void ToolBarEditor::insertSpacer() {
|
||||
int current_row = m_ui->m_listActivatedActions->currentRow();
|
||||
|
||||
QListWidgetItem *item = new QListWidgetItem(tr("Toolbar spacer"));
|
||||
item->setIcon(IconFactory::instance()->fromTheme("application-search"));
|
||||
item->setData(Qt::UserRole, SPACER_ACTION_NAME);
|
||||
|
||||
if (current_row >= 0) {
|
||||
m_ui->m_listActivatedActions->insertItem(current_row + 1, item);
|
||||
}
|
||||
else {
|
||||
m_ui->m_listActivatedActions->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBarEditor::insertSeparator() {
|
||||
int current_row = m_ui->m_listActivatedActions->currentRow();
|
||||
|
||||
QListWidgetItem *item = new QListWidgetItem(tr("Separator"));
|
||||
item->setData(Qt::UserRole, SEPARATOR_ACTION_NAME);
|
||||
item->setIcon(IconFactory::instance()->fromTheme("view-separator"));
|
||||
|
||||
if (current_row >= 0) {
|
||||
m_ui->m_listActivatedActions->insertItem(current_row + 1, item);
|
||||
}
|
||||
else {
|
||||
m_ui->m_listActivatedActions->addItem(item);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ class ToolBarEditor : public QWidget {
|
||||
void loadFromToolBar(BaseToolBar *tool_bar);
|
||||
void saveToolBar();
|
||||
|
||||
private slots:
|
||||
void insertSpacer();
|
||||
void insertSeparator();
|
||||
|
||||
private:
|
||||
Ui::ToolBarEditor *m_ui;
|
||||
BaseToolBar *m_toolBar;
|
||||
|
Loading…
x
Reference in New Issue
Block a user