Seamly2D
Code documentation
dialogpreferences.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file dialogpreferences.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 4, 2017
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2017 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "dialogpreferences.h"
53 #include "ui_dialogpreferences.h"
54 #include "../core/vapplication.h"
59 
60 #include <QPushButton>
61 
62 //---------------------------------------------------------------------------------------------------------------------
64  : QDialog(parent)
65  , ui(new Ui::DialogPreferences)
66  , m_isInitialized(false)
67  , m_configurePage(new PreferencesConfigurationPage)
68  , m_patternPage(new PreferencesPatternPage)
69  , m_pathPage(new PreferencesPathPage)
70  , m_graphicsPage(new PreferencesGraphicsViewPage)
71 {
72  ui->setupUi(this);
73  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
74 
75  qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
76 
77  QPushButton *ok_Button = ui->buttonBox->button(QDialogButtonBox::Ok);
78  SCASSERT(ok_Button != nullptr)
79  connect(ok_Button, &QPushButton::clicked, this, &DialogPreferences::Ok);
80 
81  QPushButton *apply_Button = ui->buttonBox->button(QDialogButtonBox::Apply);
82  SCASSERT(apply_Button != nullptr)
83  connect(apply_Button, &QPushButton::clicked, this, &DialogPreferences::Apply);
84 
85  ui->pages_StackedWidget->insertWidget(0, m_configurePage);
86  ui->pages_StackedWidget->insertWidget(1, m_patternPage);
87  ui->pages_StackedWidget->insertWidget(2, m_pathPage);
88  ui->pages_StackedWidget->insertWidget(3, m_graphicsPage);
89 
90 
91  connect(ui->contents_ListWidget, &QListWidget::currentItemChanged, this, &DialogPreferences::pageChanged);
92  ui->pages_StackedWidget->setCurrentIndex(0);
93 }
94 
95 //---------------------------------------------------------------------------------------------------------------------
97 {
98  delete ui;
99 }
100 
101 //---------------------------------------------------------------------------------------------------------------------
102 void DialogPreferences::showEvent(QShowEvent *event)
103 {
104  QDialog::showEvent( event );
105  if ( event->spontaneous() )
106  {
107  return;
108  }
109 
110  if (m_isInitialized)
111  {
112  return;
113  }
114  // do your init stuff here
115 
116  setMinimumSize(size());
117 
118  QSize sz = qApp->Settings()->getPreferenceDialogSize();
119  if (sz.isEmpty() == false)
120  {
121  resize(sz);
122  }
123 
124  m_isInitialized = true;//first show windows are held
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
128 void DialogPreferences::resizeEvent(QResizeEvent *event)
129 {
130  Q_UNUSED(event)
131  // remember the size for the next time this dialog is opened, but only
132  // if widget was already initialized, which rules out the resize at
133  // dialog creating, which would
134  if (m_isInitialized)
135  {
136  qApp->Settings()->setPreferenceDialogSize(size());
137  }
138 }
139 
140 //---------------------------------------------------------------------------------------------------------------------
141 void DialogPreferences::pageChanged(QListWidgetItem *current, QListWidgetItem *previous)
142 {
143  if (current == nullptr)
144  {
145  current = previous;
146  }
147  int rowIndex = ui->contents_ListWidget->row(current);
148  ui->pages_StackedWidget->setCurrentIndex(rowIndex);
149 }
150 
151 //---------------------------------------------------------------------------------------------------------------------
153 {
155  m_patternPage->Apply();
156  m_pathPage->Apply();
158 
160 
161  qApp->Seamly2DSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
162  emit updateProperties();
163  setResult(QDialog::Accepted);
164 }
165 
166 //---------------------------------------------------------------------------------------------------------------------
168 {
169  Apply();
170  done(QDialog::Accepted);
171 }
void pageChanged(QListWidgetItem *current, QListWidgetItem *previous)
PreferencesPathPage * m_pathPage
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
DialogPreferences(QWidget *parent=nullptr)
PreferencesGraphicsViewPage * m_graphicsPage
PreferencesConfigurationPage * m_configurePage
Ui::DialogPreferences * ui
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
PreferencesPatternPage * m_patternPage
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67