2011-10-25 23:14:27 +03:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (c) 2012 Dmitry Savchenko
|
|
|
|
|
** Copyright (c) 2010 Vasiliy Sorokin
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-10-25 23:14:27 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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);
|
|
|
|
|
setButtonsEnabled();
|
|
|
|
|
connect(ui->addButton, SIGNAL(clicked()), SLOT(addButtonClicked()));
|
|
|
|
|
connect(ui->removeButton, SIGNAL(clicked()), SLOT(removeButtonClicked()));
|
|
|
|
|
connect(ui->editButton, SIGNAL(clicked()), SLOT(editButtonClicked()));
|
|
|
|
|
connect(ui->resetButton, SIGNAL(clicked()), SLOT(resetButtonClicked()));
|
2012-07-06 10:50:59 +02:00
|
|
|
connect(ui->keywordsList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(itemDoubleClicked(QListWidgetItem*)));
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OptionsDialog::~OptionsDialog()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-06 10:50:59 +02:00
|
|
|
void OptionsDialog::itemDoubleClicked(QListWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
editItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void OptionsDialog::setSettings(const Settings &settings)
|
|
|
|
|
{
|
|
|
|
|
uiFromSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::addToKeywordsList(const Keyword &keyword)
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(QIcon(keyword.iconResource), keyword.name);
|
|
|
|
|
item->setData(Qt::UserRole, keyword.iconResource);
|
|
|
|
|
item->setBackgroundColor(keyword.color);
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::addButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
Keyword keyword;
|
2012-03-15 18:51:52 +03:00
|
|
|
KeywordDialog *keywordDialog = new KeywordDialog(keyword, keywordNames(), this);
|
|
|
|
|
if (keywordDialog->exec() == QDialog::Accepted) {
|
|
|
|
|
keyword = keywordDialog->keyword();
|
2011-10-25 23:14:27 +03:00
|
|
|
addToKeywordsList(keyword);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::editButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem *item = ui->keywordsList->currentItem();
|
2012-07-06 10:50:59 +02:00
|
|
|
editItem(item);
|
|
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2012-07-06 10:50:59 +02:00
|
|
|
void OptionsDialog::editItem(QListWidgetItem *item)
|
|
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
Keyword keyword;
|
|
|
|
|
keyword.name = item->text();
|
|
|
|
|
keyword.iconResource = item->data(Qt::UserRole).toString();
|
|
|
|
|
keyword.color = item->backgroundColor();
|
|
|
|
|
|
2012-03-15 18:51:52 +03:00
|
|
|
QSet<QString> keywordNamesButThis = keywordNames();
|
|
|
|
|
keywordNamesButThis.remove(keyword.name);
|
|
|
|
|
|
|
|
|
|
KeywordDialog *keywordDialog = new KeywordDialog(keyword, keywordNamesButThis, this);
|
|
|
|
|
if (keywordDialog->exec() == QDialog::Accepted) {
|
|
|
|
|
keyword = keywordDialog->keyword();
|
2011-10-25 23:14:27 +03:00
|
|
|
item->setIcon(QIcon(keyword.iconResource));
|
|
|
|
|
item->setText(keyword.name);
|
|
|
|
|
item->setData(Qt::UserRole, keyword.iconResource);
|
|
|
|
|
item->setBackgroundColor(keyword.color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::removeButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
ui->keywordsList->takeItem(ui->keywordsList->currentRow());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::resetButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
Settings newSettings;
|
|
|
|
|
newSettings.setDefault();
|
|
|
|
|
uiFromSettings(newSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::setButtonsEnabled()
|
|
|
|
|
{
|
|
|
|
|
bool isSomethingSelected = ui->keywordsList->selectedItems().count() != 0;
|
|
|
|
|
ui->removeButton->setEnabled(isSomethingSelected);
|
|
|
|
|
ui->editButton->setEnabled(isSomethingSelected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsDialog::uiFromSettings(const Settings &settings)
|
|
|
|
|
{
|
|
|
|
|
ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile);
|
|
|
|
|
ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject);
|
|
|
|
|
|
|
|
|
|
ui->keywordsList->clear();
|
|
|
|
|
foreach (const Keyword &keyword, settings.keywords)
|
|
|
|
|
addToKeywordsList(keyword);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Settings OptionsDialog::settingsFromUi()
|
|
|
|
|
{
|
|
|
|
|
Settings settings;
|
|
|
|
|
|
|
|
|
|
if (ui->scanInCurrentFileRadioButton->isChecked())
|
|
|
|
|
settings.scanningScope = ScanningScopeCurrentFile;
|
|
|
|
|
else
|
|
|
|
|
settings.scanningScope = ScanningScopeProject;
|
|
|
|
|
|
|
|
|
|
settings.keywords.clear();
|
|
|
|
|
for (int i = 0; i < ui->keywordsList->count(); ++i) {
|
|
|
|
|
QListWidgetItem *item = ui->keywordsList->item(i);
|
|
|
|
|
|
|
|
|
|
Keyword keyword;
|
|
|
|
|
keyword.name = item->text();
|
|
|
|
|
keyword.iconResource = item->data(Qt::UserRole).toString();
|
|
|
|
|
keyword.color = item->backgroundColor();
|
|
|
|
|
|
|
|
|
|
settings.keywords << keyword;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Todo
|