2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Dmitry Savchenko
|
|
|
|
|
** Copyright (C) 2016 Vasiliy Sorokin
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
#include "optionsdialog.h"
|
|
|
|
|
#include "ui_optionsdialog.h"
|
|
|
|
|
#include "keyworddialog.h"
|
2012-02-24 09:43:52 +01:00
|
|
|
#include "keyword.h"
|
|
|
|
|
#include "settings.h"
|
2011-10-25 23:14:27 +03:00
|
|
|
#include "constants.h"
|
|
|
|
|
|
|
|
|
|
namespace Todo {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2020-02-07 17:50:21 +01:00
|
|
|
class OptionsDialog final : public Core::IOptionsPageWidget
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Todo::Internal::TodoOptionsPage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
OptionsDialog(Settings *settings, const std::function<void ()> &onApply);
|
|
|
|
|
|
|
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
void setSettings(const Settings &settings);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void addKeywordButtonClicked();
|
|
|
|
|
void editKeywordButtonClicked();
|
|
|
|
|
void removeKeywordButtonClicked();
|
|
|
|
|
void resetKeywordsButtonClicked();
|
|
|
|
|
void setKeywordsButtonsEnabled();
|
|
|
|
|
Settings settingsFromUi();
|
|
|
|
|
void addToKeywordsList(const Keyword &keyword);
|
|
|
|
|
void editKeyword(QListWidgetItem *item);
|
|
|
|
|
QSet<QString> keywordNames();
|
|
|
|
|
|
|
|
|
|
Ui::OptionsDialog ui;
|
|
|
|
|
Settings *m_settings = nullptr;
|
|
|
|
|
std::function<void()> m_onApply;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OptionsDialog::OptionsDialog(Settings *settings, const std::function<void ()> &onApply)
|
|
|
|
|
: m_settings(settings), m_onApply(onApply)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
ui.keywordsList->setIconSize(QSize(16, 16));
|
2015-05-18 22:47:20 +03:00
|
|
|
setKeywordsButtonsEnabled();
|
2020-02-07 17:50:21 +01:00
|
|
|
connect(ui.addKeywordButton, &QAbstractButton::clicked,
|
2016-06-05 22:34:47 +03:00
|
|
|
this, &OptionsDialog::addKeywordButtonClicked);
|
2020-02-07 17:50:21 +01:00
|
|
|
connect(ui.removeKeywordButton, &QAbstractButton::clicked,
|
2016-06-05 22:34:47 +03:00
|
|
|
this, &OptionsDialog::removeKeywordButtonClicked);
|
2020-02-07 17:50:21 +01:00
|
|
|
connect(ui.editKeywordButton, &QAbstractButton::clicked,
|
2016-06-05 22:34:47 +03:00
|
|
|
this, &OptionsDialog::editKeywordButtonClicked);
|
2020-02-07 17:50:21 +01:00
|
|
|
connect(ui.resetKeywordsButton, &QAbstractButton::clicked,
|
2016-06-05 22:34:47 +03:00
|
|
|
this, &OptionsDialog::resetKeywordsButtonClicked);
|
2020-02-07 17:50:21 +01:00
|
|
|
connect(ui.keywordsList, &QListWidget::itemDoubleClicked,
|
|
|
|
|
this, &OptionsDialog::editKeyword);
|
|
|
|
|
connect(ui.keywordsList, &QListWidget::itemSelectionChanged,
|
2016-06-05 22:34:47 +03:00
|
|
|
this, &OptionsDialog::setKeywordsButtonsEnabled);
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2020-02-07 17:50:21 +01:00
|
|
|
setSettings(*m_settings);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::addToKeywordsList(const Keyword &keyword)
|
|
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
auto item = new QListWidgetItem(icon(keyword.iconType), keyword.name);
|
2015-11-16 16:45:05 +01:00
|
|
|
item->setData(Qt::UserRole, static_cast<int>(keyword.iconType));
|
2019-07-22 15:37:47 +02:00
|
|
|
item->setForeground(keyword.color);
|
2020-02-07 17:50:21 +01:00
|
|
|
ui.keywordsList->addItem(item);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
2012-03-15 18:51:52 +03:00
|
|
|
QSet<QString> OptionsDialog::keywordNames()
|
|
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
const KeywordList keywords = settingsFromUi().keywords;
|
2012-03-15 18:51:52 +03:00
|
|
|
|
|
|
|
|
QSet<QString> result;
|
2020-02-07 17:50:21 +01:00
|
|
|
for (const Keyword &keyword : keywords)
|
2012-03-15 18:51:52 +03:00
|
|
|
result << keyword.name;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::addKeywordButtonClicked()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
|
|
|
|
Keyword keyword;
|
2017-02-20 17:37:32 +01:00
|
|
|
KeywordDialog keywordDialog(keyword, keywordNames(), this);
|
|
|
|
|
if (keywordDialog.exec() == QDialog::Accepted) {
|
|
|
|
|
keyword = keywordDialog.keyword();
|
2011-10-25 23:14:27 +03:00
|
|
|
addToKeywordsList(keyword);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::editKeywordButtonClicked()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
QListWidgetItem *item = ui.keywordsList->currentItem();
|
2015-05-18 22:47:20 +03:00
|
|
|
editKeyword(item);
|
2012-07-06 10:50:59 +02:00
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::editKeyword(QListWidgetItem *item)
|
2012-07-06 10:50:59 +02:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
Keyword keyword;
|
|
|
|
|
keyword.name = item->text();
|
2015-11-16 16:45:05 +01:00
|
|
|
keyword.iconType = static_cast<IconType>(item->data(Qt::UserRole).toInt());
|
2019-07-05 12:02:41 +02:00
|
|
|
keyword.color = item->foreground().color();
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2012-03-15 18:51:52 +03:00
|
|
|
QSet<QString> keywordNamesButThis = keywordNames();
|
|
|
|
|
keywordNamesButThis.remove(keyword.name);
|
|
|
|
|
|
2017-02-20 17:37:32 +01:00
|
|
|
KeywordDialog keywordDialog(keyword, keywordNamesButThis, this);
|
|
|
|
|
if (keywordDialog.exec() == QDialog::Accepted) {
|
|
|
|
|
keyword = keywordDialog.keyword();
|
2015-11-16 16:45:05 +01:00
|
|
|
item->setIcon(icon(keyword.iconType));
|
2011-10-25 23:14:27 +03:00
|
|
|
item->setText(keyword.name);
|
2015-11-16 16:45:05 +01:00
|
|
|
item->setData(Qt::UserRole, static_cast<int>(keyword.iconType));
|
2019-07-05 12:02:41 +02:00
|
|
|
item->setForeground(keyword.color);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::removeKeywordButtonClicked()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
delete ui.keywordsList->takeItem(ui.keywordsList->currentRow());
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::resetKeywordsButtonClicked()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
|
|
|
|
Settings newSettings;
|
|
|
|
|
newSettings.setDefault();
|
2020-02-07 17:50:21 +01:00
|
|
|
setSettings(newSettings);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::setKeywordsButtonsEnabled()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
const bool isSomethingSelected = !ui.keywordsList->selectedItems().isEmpty();
|
|
|
|
|
ui.removeKeywordButton->setEnabled(isSomethingSelected);
|
|
|
|
|
ui.editKeywordButton->setEnabled(isSomethingSelected);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
2020-02-07 17:50:21 +01:00
|
|
|
void OptionsDialog::setSettings(const Settings &settings)
|
2015-05-18 22:47:20 +03:00
|
|
|
{
|
2020-02-07 17:50:21 +01:00
|
|
|
ui.scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile);
|
|
|
|
|
ui.scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject);
|
|
|
|
|
ui.scanInSubprojectRadioButton->setChecked(settings.scanningScope == ScanningScopeSubProject);
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2020-02-07 17:50:21 +01:00
|
|
|
ui.keywordsList->clear();
|
|
|
|
|
for (const Keyword &keyword : qAsConst(settings.keywords))
|
2015-05-18 22:47:20 +03:00
|
|
|
addToKeywordsList(keyword);
|
|
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
Settings OptionsDialog::settingsFromUi()
|
|
|
|
|
{
|
|
|
|
|
Settings settings;
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2020-02-07 17:50:21 +01:00
|
|
|
if (ui.scanInCurrentFileRadioButton->isChecked())
|
2015-05-18 22:47:20 +03:00
|
|
|
settings.scanningScope = ScanningScopeCurrentFile;
|
2020-02-07 17:50:21 +01:00
|
|
|
else if (ui.scanInSubprojectRadioButton->isChecked())
|
2015-05-30 08:54:39 +02:00
|
|
|
settings.scanningScope = ScanningScopeSubProject;
|
2015-05-18 22:47:20 +03:00
|
|
|
else
|
|
|
|
|
settings.scanningScope = ScanningScopeProject;
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
settings.keywords.clear();
|
2020-02-07 17:50:21 +01:00
|
|
|
for (int i = 0; i < ui.keywordsList->count(); ++i) {
|
|
|
|
|
QListWidgetItem *item = ui.keywordsList->item(i);
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
Keyword keyword;
|
|
|
|
|
keyword.name = item->text();
|
2015-11-16 16:45:05 +01:00
|
|
|
keyword.iconType = static_cast<IconType>(item->data(Qt::UserRole).toInt());
|
2019-07-22 15:37:47 +02:00
|
|
|
keyword.color = item->foreground().color();
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
settings.keywords << keyword;
|
|
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
return settings;
|
|
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2020-02-07 17:50:21 +01:00
|
|
|
void OptionsDialog::apply()
|
|
|
|
|
{
|
|
|
|
|
Settings newSettings = settingsFromUi();
|
|
|
|
|
|
|
|
|
|
// "apply" itself is interpreted as "use these keywords, also for other themes".
|
|
|
|
|
newSettings.keywordsEdited = true;
|
|
|
|
|
|
|
|
|
|
if (newSettings == *m_settings)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
*m_settings = newSettings;
|
|
|
|
|
m_onApply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TodoOptionsPage
|
|
|
|
|
|
|
|
|
|
TodoOptionsPage::TodoOptionsPage(Settings *settings, const std::function<void ()> &onApply)
|
|
|
|
|
{
|
|
|
|
|
setId("TodoSettings");
|
|
|
|
|
setDisplayName(OptionsDialog::tr("To-Do"));
|
|
|
|
|
setCategory("To-Do");
|
|
|
|
|
setDisplayCategory(OptionsDialog::tr("To-Do"));
|
|
|
|
|
setCategoryIconPath(":/todoplugin/images/settingscategory_todo.png");
|
|
|
|
|
setWidgetCreator([settings, onApply] { return new OptionsDialog(settings, onApply); });
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Todo
|