QElectroTech  0.70
configdialog.cpp
Go to the documentation of this file.
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 
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 
67 }
68 
73  pages_list -> clear();
74  foreach(ConfigPage *page, pages) {
75  addPageToList(page);
76  }
77 }
78 
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 
94  foreach(ConfigPage *page, pages) {
95  page -> applyConf();
96  }
97  accept();
98 }
99 
104  if (!page || pages.contains(page)) return;
105  pages << page;
106  pages_widget -> addWidget(page);
107  addPageToList(page);
108 }
109 
115 void ConfigDialog::setCurrentPage(const int index) {
116  pages_list->setCurrentRow(index);
117 }
void setCurrentPage(const int index)
ConfigDialog::setCurrentPage Set the current index to .
void applyConf()
QStackedWidget * pages_widget
Definition: configdialog.h:57
QListWidget * pages_list
Definition: configdialog.h:56
ConfigDialog(QWidget *=nullptr)
QDialogButtonBox * buttons
Definition: configdialog.h:58
void addPage(ConfigPage *)
~ConfigDialog() override
Destructeur.
void buildPagesList()
QList< ConfigPage * > pages
Definition: configdialog.h:41
QIcon Cancel
Definition: qeticons.cpp:34
void addPageToList(ConfigPage *)