krita/ui

kis_bookmarked_configurations_editor.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_bookmarked_configurations_editor.h"
00020 #include "ui_wdgbookmarkedconfigurationseditor.h"
00021 
00022 #include "kis_bookmarked_configurations_model.h"
00023 
00024 struct KisBookmarkedConfigurationsEditor::Private {
00025     Ui_WdgBookmarkedConfigurationsEditor editorUi;
00026     KisBookmarkedConfigurationsModel* model;
00027     const KisSerializableConfiguration* currentConfig;
00028 };
00029 
00030 
00031 KisBookmarkedConfigurationsEditor::KisBookmarkedConfigurationsEditor(QWidget* parent, KisBookmarkedConfigurationsModel* model, const KisSerializableConfiguration* currentConfig) : QDialog(parent), d(new Private)
00032 {
00033     d->editorUi.setupUi(this);
00034     d->model = model;
00035     d->currentConfig = currentConfig;
00036     d->editorUi.listConfigurations->setModel(d->model);
00037     connect(d->editorUi.pushButtonClose, SIGNAL(pressed()), SLOT(accept()));
00038 
00039     connect(d->editorUi.listConfigurations->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
00040             this, SLOT(currentConfigChanged(const QItemSelection&, const QItemSelection&)));
00041     currentConfigChanged(d->editorUi.listConfigurations->selectionModel()->selection(),
00042                          d->editorUi.listConfigurations->selectionModel()->selection());
00043 
00044     connect(d->editorUi.pushButtonDelete, SIGNAL(pressed()), SLOT(deleteConfiguration()));
00045     connect(d->editorUi.pushButtonBookmarkCurrent, SIGNAL(pressed()), SLOT(addCurrentConfiguration()));
00046 
00047     if (!d->currentConfig) {
00048         d->editorUi.pushButtonBookmarkCurrent->setEnabled(false);
00049     }
00050 }
00051 
00052 KisBookmarkedConfigurationsEditor::~KisBookmarkedConfigurationsEditor()
00053 {
00054     delete d;
00055 }
00056 
00057 void KisBookmarkedConfigurationsEditor::currentConfigChanged(const QItemSelection& selected, const QItemSelection&)
00058 {
00059     if (d->model) {
00060         d->editorUi.pushButtonDelete->setEnabled(!(selected.indexes().isEmpty()) ?
00061                 d->model->isIndexDeletable(selected.indexes().first()) :
00062                 false);
00063     }
00064 }
00065 
00066 void KisBookmarkedConfigurationsEditor::addCurrentConfiguration()
00067 {
00068     if (d->model) {
00069         d->model->newConfiguration(ki18n("New configuration %1"), d->currentConfig);
00070     }
00071 }
00072 
00073 void KisBookmarkedConfigurationsEditor::deleteConfiguration()
00074 {
00075     if (d->model) {
00076         d->model->deleteIndex(d->editorUi.listConfigurations->currentIndex());
00077     }
00078 }
00079 
00080 #include "kis_bookmarked_configurations_editor.moc"