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 {
|
|
|
|
|
|
|
|
|
|
OptionsDialog::OptionsDialog(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
ui(new Ui::OptionsDialog)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2016-04-25 17:20:51 +02:00
|
|
|
ui->keywordsList->setIconSize(QSize(16, 16));
|
2015-05-18 22:47:20 +03:00
|
|
|
setKeywordsButtonsEnabled();
|
2016-06-05 22:34:47 +03:00
|
|
|
connect(ui->addKeywordButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &OptionsDialog::addKeywordButtonClicked);
|
|
|
|
|
connect(ui->removeKeywordButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &OptionsDialog::removeKeywordButtonClicked);
|
|
|
|
|
connect(ui->editKeywordButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &OptionsDialog::editKeywordButtonClicked);
|
|
|
|
|
connect(ui->resetKeywordsButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &OptionsDialog::resetKeywordsButtonClicked);
|
|
|
|
|
connect(ui->keywordsList, &QListWidget::itemDoubleClicked,
|
|
|
|
|
this, &OptionsDialog::keywordDoubleClicked);
|
|
|
|
|
connect(ui->keywordsList, &QListWidget::itemSelectionChanged,
|
|
|
|
|
this, &OptionsDialog::setKeywordsButtonsEnabled);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OptionsDialog::~OptionsDialog()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::keywordDoubleClicked(QListWidgetItem *item)
|
2012-07-06 10:50:59 +02:00
|
|
|
{
|
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
|
|
|
void OptionsDialog::setSettings(const Settings &settings)
|
|
|
|
|
{
|
|
|
|
|
uiFromSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::addToKeywordsList(const Keyword &keyword)
|
|
|
|
|
{
|
2015-10-19 12:55:13 +02:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(
|
2015-11-16 16:45:05 +01:00
|
|
|
icon(keyword.iconType), keyword.name);
|
|
|
|
|
item->setData(Qt::UserRole, static_cast<int>(keyword.iconType));
|
2017-01-05 17:13:42 +01:00
|
|
|
item->setTextColor(keyword.color);
|
2011-10-25 23:14:27 +03:00
|
|
|
ui->keywordsList->addItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-15 18:51:52 +03:00
|
|
|
QSet<QString> OptionsDialog::keywordNames()
|
|
|
|
|
{
|
|
|
|
|
KeywordList keywords = settingsFromUi().keywords;
|
|
|
|
|
|
|
|
|
|
QSet<QString> result;
|
|
|
|
|
foreach (const Keyword &keyword, keywords)
|
|
|
|
|
result << keyword.name;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
Settings OptionsDialog::settings()
|
|
|
|
|
{
|
|
|
|
|
return settingsFromUi();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
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());
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = item->textColor();
|
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));
|
2017-01-05 17:13:42 +01:00
|
|
|
item->setTextColor(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
|
|
|
{
|
2015-05-18 22:47:20 +03: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();
|
|
|
|
|
uiFromSettings(newSettings);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::setKeywordsButtonsEnabled()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
|
|
|
|
bool isSomethingSelected = ui->keywordsList->selectedItems().count() != 0;
|
2015-05-18 22:47:20 +03:00
|
|
|
ui->removeKeywordButton->setEnabled(isSomethingSelected);
|
|
|
|
|
ui->editKeywordButton->setEnabled(isSomethingSelected);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void OptionsDialog::uiFromSettings(const Settings &settings)
|
|
|
|
|
{
|
|
|
|
|
ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile);
|
|
|
|
|
ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject);
|
2015-05-30 08:54:39 +02:00
|
|
|
ui->scanInSubprojectRadioButton->setChecked(settings.scanningScope == ScanningScopeSubProject);
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
ui->keywordsList->clear();
|
|
|
|
|
foreach (const Keyword &keyword, settings.keywords)
|
|
|
|
|
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
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
if (ui->scanInCurrentFileRadioButton->isChecked())
|
|
|
|
|
settings.scanningScope = ScanningScopeCurrentFile;
|
2015-05-30 08:54:39 +02:00
|
|
|
else if (ui->scanInSubprojectRadioButton->isChecked())
|
|
|
|
|
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();
|
|
|
|
|
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());
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = item->textColor();
|
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
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Todo
|