2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2016-05-13 17:40:36 +00:00
|
|
|
Copyright 2006-2016 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-11-18 00:22:19 +00:00
|
|
|
#include "configdialog.h"
|
2012-06-29 05:21:32 +00:00
|
|
|
#include "configpages.h"
|
2007-11-18 00:22:19 +00:00
|
|
|
#include "qetapp.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param parent QWidget parent
|
|
|
|
*/
|
|
|
|
ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
|
|
|
|
// liste des pages
|
|
|
|
pages_list = new QListWidget();
|
|
|
|
pages_list -> setViewMode(QListView::IconMode);
|
2009-04-03 19:30:25 +00:00
|
|
|
pages_list -> setIconSize(QSize(110, 110));
|
2007-11-18 00:22:19 +00:00
|
|
|
pages_list -> setMovement(QListView::Static);
|
2009-11-22 16:12:22 +00:00
|
|
|
pages_list -> setMinimumWidth(150);
|
|
|
|
pages_list -> setMaximumWidth(150);
|
2007-11-18 00:22:19 +00:00
|
|
|
pages_list -> setSpacing(4);
|
|
|
|
|
|
|
|
// pages
|
|
|
|
pages_widget = new QStackedWidget();
|
|
|
|
|
|
|
|
// boutons
|
|
|
|
buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
|
|
|
|
|
|
|
|
// layouts
|
|
|
|
QHBoxLayout *hlayout1 = new QHBoxLayout();
|
|
|
|
hlayout1 -> addWidget(pages_list);
|
|
|
|
hlayout1 -> addWidget(pages_widget);
|
|
|
|
|
|
|
|
QVBoxLayout *vlayout1 = new QVBoxLayout();
|
|
|
|
vlayout1 -> addLayout(hlayout1);
|
|
|
|
vlayout1 -> addWidget(buttons);
|
|
|
|
setLayout(vlayout1);
|
|
|
|
|
|
|
|
// connexion signaux / slots
|
|
|
|
connect(buttons, SIGNAL(accepted()), this, SLOT(applyConf()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
2014-08-15 13:16:58 +00:00
|
|
|
connect(pages_list, SIGNAL(currentRowChanged(int)), pages_widget, SLOT(setCurrentIndex(int)));
|
2012-06-29 05:21:39 +00:00
|
|
|
|
2015-03-02 20:14:56 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2012-06-29 05:21:39 +00:00
|
|
|
if (parent) {
|
|
|
|
setWindowFlags(Qt::Sheet);
|
|
|
|
}
|
|
|
|
#endif
|
2007-11-18 00:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destructeur
|
|
|
|
ConfigDialog::~ConfigDialog() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Construit la liste des pages sur la gauche
|
|
|
|
*/
|
|
|
|
void ConfigDialog::buildPagesList() {
|
|
|
|
pages_list -> clear();
|
|
|
|
foreach(ConfigPage *page, pages) {
|
2012-06-29 05:21:32 +00:00
|
|
|
addPageToList(page);
|
2007-11-18 00:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 05:21:32 +00:00
|
|
|
/**
|
|
|
|
Add the \a page ConfigPage to this configuration dialog.
|
|
|
|
*/
|
|
|
|
void ConfigDialog::addPageToList(ConfigPage *page) {
|
|
|
|
QListWidgetItem *new_button = new QListWidgetItem(pages_list);
|
|
|
|
new_button -> setIcon(page -> icon());
|
|
|
|
new_button -> setText(page -> title());
|
|
|
|
new_button -> setTextAlignment(Qt::AlignHCenter);
|
|
|
|
new_button -> setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
|
|
}
|
|
|
|
|
2007-11-18 00:22:19 +00:00
|
|
|
/**
|
|
|
|
Applique la configuration de toutes les pages
|
|
|
|
*/
|
|
|
|
void ConfigDialog::applyConf() {
|
|
|
|
foreach(ConfigPage *page, pages) {
|
|
|
|
page -> applyConf();
|
|
|
|
}
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ajoute une page au dialogue de configuration
|
|
|
|
*/
|
|
|
|
void ConfigDialog::addPage(ConfigPage *page) {
|
|
|
|
if (!page || pages.contains(page)) return;
|
|
|
|
pages << page;
|
|
|
|
pages_widget -> addWidget(page);
|
2012-06-29 05:21:32 +00:00
|
|
|
addPageToList(page);
|
2007-11-18 00:22:19 +00:00
|
|
|
}
|
2014-08-15 13:16:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConfigDialog::setCurrentPage
|
|
|
|
* Set the current index to @index
|
|
|
|
* @param index
|
|
|
|
*/
|
|
|
|
void ConfigDialog::setCurrentPage(const int index) {
|
|
|
|
pages_list->setCurrentRow(index);
|
|
|
|
}
|