Saving toolbars...
This commit is contained in:
parent
2f683e88ce
commit
69354c91a2
@ -64,8 +64,8 @@
|
|||||||
#define STARTUP_UPDATE_DELAY 1500
|
#define STARTUP_UPDATE_DELAY 1500
|
||||||
#define TIMEZONE_OFFSET_LIMIT 6
|
#define TIMEZONE_OFFSET_LIMIT 6
|
||||||
#define CHANGE_EVENT_DELAY 250
|
#define CHANGE_EVENT_DELAY 250
|
||||||
#define SPACER_OBJECT_NAME "spacer"
|
|
||||||
#define FILTER_OBJECT_NAME "filter"
|
#define FILTER_OBJECT_NAME "filter"
|
||||||
|
#define SPACER_ACTION_NAME "spacer"
|
||||||
#define SEPARATOR_ACTION_NAME "separator"
|
#define SEPARATOR_ACTION_NAME "separator"
|
||||||
#define FILTER_WIDTH 150
|
#define FILTER_WIDTH 150
|
||||||
#define FILTER_RIGHT_MARGIN 5
|
#define FILTER_RIGHT_MARGIN 5
|
||||||
|
@ -12,8 +12,10 @@ class BaseToolBar : public QToolBar {
|
|||||||
explicit BaseToolBar(const QString &title, QWidget *parent = 0);
|
explicit BaseToolBar(const QString &title, QWidget *parent = 0);
|
||||||
virtual ~BaseToolBar();
|
virtual ~BaseToolBar();
|
||||||
|
|
||||||
|
virtual QList<QAction*> availableActions() const = 0;
|
||||||
virtual QList<QAction*> changeableActions() const = 0;
|
virtual QList<QAction*> changeableActions() const = 0;
|
||||||
virtual void saveChangeableActions() const = 0;
|
virtual void saveChangeableActions() const = 0;
|
||||||
|
virtual void saveChangeableActions(const QStringList &actions) = 0;
|
||||||
virtual void loadChangeableActions() = 0;
|
virtual void loadChangeableActions() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -833,6 +833,9 @@ void FormSettings::saveInterface() {
|
|||||||
settings->setValue(APP_CFG_GUI, "hide_tabbar_one_tab",
|
settings->setValue(APP_CFG_GUI, "hide_tabbar_one_tab",
|
||||||
m_ui->m_hideTabBarIfOneTabVisible->isChecked());
|
m_ui->m_hideTabBarIfOneTabVisible->isChecked());
|
||||||
|
|
||||||
|
|
||||||
|
m_ui->widget->saveToolBar();
|
||||||
|
|
||||||
FormMain::instance()->tabWidget()->checkTabBarVisibility();
|
FormMain::instance()->tabWidget()->checkTabBarVisibility();
|
||||||
FormMain::instance()->tabWidget()->feedMessageViewer()->refreshVisualProperties();
|
FormMain::instance()->tabWidget()->feedMessageViewer()->refreshVisualProperties();
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,13 @@
|
|||||||
|
|
||||||
MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
|
MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
|
||||||
: BaseToolBar(title, parent),
|
: BaseToolBar(title, parent),
|
||||||
m_spacer(new QWidget(this)),
|
|
||||||
m_txtFilter(new BaseLineEdit(this)) {
|
m_txtFilter(new BaseLineEdit(this)) {
|
||||||
m_spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
m_txtFilter->setFixedWidth(FILTER_WIDTH);
|
m_txtFilter->setFixedWidth(FILTER_WIDTH);
|
||||||
m_txtFilter->setPlaceholderText(tr("Filter messages"));
|
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"));
|
||||||
|
|
||||||
// Update right margin of filter textbox.
|
// Update right margin of filter textbox.
|
||||||
QMargins margins = contentsMargins();
|
QMargins margins = contentsMargins();
|
||||||
@ -25,24 +27,14 @@ MessagesToolBar::MessagesToolBar(const QString &title, QWidget *parent)
|
|||||||
MessagesToolBar::~MessagesToolBar() {
|
MessagesToolBar::~MessagesToolBar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QAction*> MessagesToolBar::availableActions() const {
|
||||||
|
QList<QAction*> available_actions = FormMain::instance()->allActions().values();
|
||||||
|
available_actions.append(m_actionFilter);
|
||||||
|
return available_actions;
|
||||||
|
}
|
||||||
|
|
||||||
QList<QAction*> MessagesToolBar::changeableActions() const {
|
QList<QAction*> MessagesToolBar::changeableActions() const {
|
||||||
// TODO: Vracet akce, ktere muze uzivatel upravovat v tomto toolbaru.
|
return actions();
|
||||||
// nebudou se tedy vracet spacer widgety nebo lineedity a tak podobně,
|
|
||||||
// proste jen akce ktere sou uzivatelsky upravitelne
|
|
||||||
// http://stackoverflow.com/questions/5364957/in-qt-4-7-how-can-a-pop-up-menu-be-added-to-a-qtoolbar-button
|
|
||||||
QList<QAction*> changeable_actions;
|
|
||||||
|
|
||||||
// Iterates all actions present in the toolbar and
|
|
||||||
// returns actions which can be replaced by user.
|
|
||||||
foreach (QAction *action, actions()) {
|
|
||||||
QString action_name = action->objectName();
|
|
||||||
|
|
||||||
if (action_name != FILTER_OBJECT_NAME && action_name != SPACER_OBJECT_NAME) {
|
|
||||||
changeable_actions.append(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return changeable_actions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesToolBar::saveChangeableActions() const {
|
void MessagesToolBar::saveChangeableActions() const {
|
||||||
@ -51,38 +43,59 @@ void MessagesToolBar::saveChangeableActions() const {
|
|||||||
// Iterates all actions present in the toolbar and
|
// Iterates all actions present in the toolbar and
|
||||||
// returns actions which can be replaced by user.
|
// returns actions which can be replaced by user.
|
||||||
foreach (QAction *action, actions()) {
|
foreach (QAction *action, actions()) {
|
||||||
QString action_name = action->objectName();
|
if (action->isSeparator()) {
|
||||||
|
// This action is separator, add its "name" to settings.
|
||||||
if (action_name != FILTER_OBJECT_NAME && action_name != SPACER_OBJECT_NAME) {
|
|
||||||
action_names.append(action->objectName());
|
|
||||||
}
|
|
||||||
else if (action->isSeparator()) {
|
|
||||||
action_names.append(SEPARATOR_ACTION_NAME);
|
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(","));
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesToolBar::loadChangeableActions() {
|
void MessagesToolBar::loadChangeableActions() {
|
||||||
QHash<QString, QAction*> available_actions = FormMain::instance()->allActions();
|
QHash<QString, QAction*> available_actions = FormMain::instance()->allActions();
|
||||||
QStringList action_names = Settings::instance()->value(APP_CFG_GUI,
|
QStringList action_names = Settings::instance()->value(APP_CFG_GUI,
|
||||||
"messages_toolbar",
|
"messages_toolbar",
|
||||||
"m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages").toString().split(',',
|
"m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages,spacer,filter").toString().split(',',
|
||||||
QString::SkipEmptyParts);
|
QString::SkipEmptyParts);
|
||||||
|
|
||||||
actions().clear();
|
clear();
|
||||||
|
|
||||||
// Iterate action names and add respectable actions into the toolbar.
|
// Iterate action names and add respectable actions into the toolbar.
|
||||||
foreach (const QString &action_name, action_names) {
|
foreach (const QString &action_name, action_names) {
|
||||||
if (available_actions.contains(action_name)) {
|
if (available_actions.contains(action_name)) {
|
||||||
|
// Add existing standard action.
|
||||||
addAction(available_actions.value(action_name));
|
addAction(available_actions.value(action_name));
|
||||||
}
|
}
|
||||||
else if (action_name == SEPARATOR_ACTION_NAME) {
|
else if (action_name == SEPARATOR_ACTION_NAME) {
|
||||||
|
// Add new separator.
|
||||||
addSeparator();
|
addSeparator();
|
||||||
}
|
}
|
||||||
}
|
else if (action_name == FILTER_OBJECT_NAME) {
|
||||||
|
// Add filter.
|
||||||
|
addAction(m_actionFilter);
|
||||||
|
}
|
||||||
|
else if (action_name == SPACER_ACTION_NAME) {
|
||||||
|
// Add new spacer.
|
||||||
|
QWidget *spacer = new QWidget(this);
|
||||||
|
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
addWidget(m_spacer)->setObjectName(SPACER_OBJECT_NAME);
|
QAction *action = addWidget(spacer);
|
||||||
addWidget(m_txtFilter)->setObjectName(FILTER_OBJECT_NAME);
|
action->setProperty("type", SPACER_ACTION_NAME);
|
||||||
|
action->setProperty("name", tr("spacer"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class BaseLineEdit;
|
class BaseLineEdit;
|
||||||
|
class QWidgetAction;
|
||||||
|
|
||||||
class MessagesToolBar : public BaseToolBar {
|
class MessagesToolBar : public BaseToolBar {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -15,8 +16,10 @@ class MessagesToolBar : public BaseToolBar {
|
|||||||
virtual ~MessagesToolBar();
|
virtual ~MessagesToolBar();
|
||||||
|
|
||||||
// Operations with changeable actions.
|
// Operations with changeable actions.
|
||||||
|
QList<QAction*> availableActions() const;
|
||||||
QList<QAction*> changeableActions() const;
|
QList<QAction*> changeableActions() const;
|
||||||
void saveChangeableActions() const;
|
void saveChangeableActions() const;
|
||||||
|
void saveChangeableActions(const QStringList &actions);
|
||||||
void loadChangeableActions();
|
void loadChangeableActions();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -24,7 +27,7 @@ class MessagesToolBar : public BaseToolBar {
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_spacer;
|
QWidgetAction *m_actionFilter;
|
||||||
BaseLineEdit *m_txtFilter;
|
BaseLineEdit *m_txtFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,13 +19,24 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
|
|||||||
m_toolBar = tool_bar;
|
m_toolBar = tool_bar;
|
||||||
|
|
||||||
QList<QAction*> activated_actions = m_toolBar->changeableActions();
|
QList<QAction*> activated_actions = m_toolBar->changeableActions();
|
||||||
QList<QAction*> available_actions = FormMain::instance()->allActions().values();
|
QList<QAction*> available_actions = m_toolBar->availableActions();
|
||||||
|
|
||||||
foreach (QAction *action, activated_actions) {
|
foreach (QAction *action, activated_actions) {
|
||||||
QListWidgetItem *action_item = new QListWidgetItem(action->icon(),
|
QListWidgetItem *action_item = new QListWidgetItem(action->icon(),
|
||||||
action->text().replace('&', ""),
|
action->text().replace('&', ""),
|
||||||
m_ui->m_listActivatedActions);
|
m_ui->m_listActivatedActions);
|
||||||
action_item->setData(Qt::UserRole, QVariant::fromValue((intptr_t) action));
|
|
||||||
|
if (action->isSeparator()) {
|
||||||
|
action_item->setData(Qt::UserRole, SEPARATOR_ACTION_NAME);
|
||||||
|
action_item->setText(tr("separator"));
|
||||||
|
}
|
||||||
|
else if (action->property("type").isValid()) {
|
||||||
|
action_item->setData(Qt::UserRole, action->property("type").toString());
|
||||||
|
action_item->setText(action->property("name").toString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
action_item->setData(Qt::UserRole, action->objectName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QAction *action, available_actions) {
|
foreach (QAction *action, available_actions) {
|
||||||
@ -33,7 +44,18 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
|
|||||||
QListWidgetItem *action_item = new QListWidgetItem(action->icon(),
|
QListWidgetItem *action_item = new QListWidgetItem(action->icon(),
|
||||||
action->text().replace('&', ""),
|
action->text().replace('&', ""),
|
||||||
m_ui->m_listAvailableActions);
|
m_ui->m_listAvailableActions);
|
||||||
action_item->setData(Qt::UserRole, QVariant::fromValue((intptr_t) action));
|
|
||||||
|
if (action->isSeparator()) {
|
||||||
|
action_item->setData(Qt::UserRole, SEPARATOR_ACTION_NAME);
|
||||||
|
action_item->setText(tr("separator"));
|
||||||
|
}
|
||||||
|
else if (action->property("type").isValid()) {
|
||||||
|
action_item->setData(Qt::UserRole, action->property("type").toString());
|
||||||
|
action_item->setText(action->property("name").toString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
action_item->setData(Qt::UserRole, action->objectName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,4 +63,11 @@ void ToolBarEditor::loadFromToolBar(BaseToolBar* tool_bar) {
|
|||||||
void ToolBarEditor::saveToolBar() {
|
void ToolBarEditor::saveToolBar() {
|
||||||
// TODO: ulozit actiony nastaveny v tomdl
|
// TODO: ulozit actiony nastaveny v tomdl
|
||||||
// e nastavovacim dialogu do prirazenyho toolbaru
|
// e nastavovacim dialogu do prirazenyho toolbaru
|
||||||
|
QStringList action_names;
|
||||||
|
|
||||||
|
for (int i = 0; i < m_ui->m_listActivatedActions->count(); i++) {
|
||||||
|
action_names.append(m_ui->m_listActivatedActions->item(i)->data(Qt::UserRole).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_toolBar->saveChangeableActions(action_names);
|
||||||
}
|
}
|
||||||
|
@ -91,27 +91,20 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QPushButton" name="pushButton_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>PushButton</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="m_btnInsertSeparator">
|
||||||
<property name="text">
|
|
||||||
<string>PushButton</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QPushButton" name="pushButton_3">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Insert separator</string>
|
<string>Insert separator</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="m_btnInsertSpacer">
|
||||||
|
<property name="text">
|
||||||
|
<string>Insert spacer</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user