1 /*
2 Copyright 2006-2019 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "configdialog.h"
19 #include "configpages.h"
20 #include "qetapp.h"
21
22 /**
23 Constructeur
24 @param parent QWidget parent
25 */
ConfigDialog(QWidget * parent)26 ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
27 // liste des pages
28 pages_list = new QListWidget();
29 pages_list -> setViewMode(QListView::IconMode);
30 pages_list -> setIconSize(QSize(128, 128));
31 pages_list -> setMovement(QListView::Static);
32 pages_list -> setMinimumWidth(168);
33 pages_list -> setMaximumWidth(168);
34 pages_list -> setSpacing(16);
35 pages_list -> setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
36
37 // pages
38 pages_widget = new QStackedWidget();
39
40 // boutons
41 buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
42
43 // layouts
44 QHBoxLayout *hlayout1 = new QHBoxLayout();
45 hlayout1 -> addWidget(pages_list);
46 hlayout1 -> addWidget(pages_widget);
47
48 QVBoxLayout *vlayout1 = new QVBoxLayout();
49 vlayout1 -> addLayout(hlayout1);
50 vlayout1 -> addWidget(buttons);
51 setLayout(vlayout1);
52
53 // connexion signaux / slots
54 connect(buttons, SIGNAL(accepted()), this, SLOT(applyConf()));
55 connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
56 connect(pages_list, SIGNAL(currentRowChanged(int)), pages_widget, SLOT(setCurrentIndex(int)));
57
58 #ifdef Q_OS_MAC
59 if (parent) {
60 setWindowFlags(Qt::Sheet);
61 }
62 #endif
63 }
64
65 /// Destructeur
~ConfigDialog()66 ConfigDialog::~ConfigDialog() {
67 }
68
69 /**
70 Construit la liste des pages sur la gauche
71 */
buildPagesList()72 void ConfigDialog::buildPagesList() {
73 pages_list -> clear();
74 foreach(ConfigPage *page, pages) {
75 addPageToList(page);
76 }
77 }
78
79 /**
80 Add the \a page ConfigPage to this configuration dialog.
81 */
addPageToList(ConfigPage * page)82 void ConfigDialog::addPageToList(ConfigPage *page) {
83 QListWidgetItem *new_button = new QListWidgetItem(pages_list);
84 new_button -> setIcon(page -> icon());
85 new_button -> setText(page -> title());
86 new_button -> setTextAlignment(Qt::AlignHCenter);
87 new_button -> setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
88 }
89
90 /**
91 Applique la configuration de toutes les pages
92 */
applyConf()93 void ConfigDialog::applyConf() {
94 foreach(ConfigPage *page, pages) {
95 page -> applyConf();
96 }
97 accept();
98 }
99
100 /**
101 Ajoute une page au dialogue de configuration
102 */
addPage(ConfigPage * page)103 void ConfigDialog::addPage(ConfigPage *page) {
104 if (!page || pages.contains(page)) return;
105 pages << page;
106 pages_widget -> addWidget(page);
107 addPageToList(page);
108 }
109
110 /**
111 * @brief ConfigDialog::setCurrentPage
112 * Set the current index to @index
113 * @param index
114 */
setCurrentPage(const int index)115 void ConfigDialog::setCurrentPage(const int index) {
116 pages_list->setCurrentRow(index);
117 }
118