Seamly2D
Code documentation
dialogseamlymepreferences.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 dialogseamlymepreferences.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 
53 #include "ui_dialogseamlymepreferences.h"
54 #include "../mapplication.h"
57 
58 #include <QPushButton>
59 #include <QShowEvent>
60 
61 //---------------------------------------------------------------------------------------------------------------------
63  :QDialog(parent),
65  m_isInitialized(false),
66  m_configurationPage(new SeamlyMePreferencesConfigurationPage),
67  m_pathPage(new SeamlyMePreferencesPathPage)
68 {
69  ui->setupUi(this);
70 
71  qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
72 
73  QPushButton *ok_Button = ui->buttonBox->button(QDialogButtonBox::Ok);
74  SCASSERT(ok_Button != nullptr)
75  connect(ok_Button, &QPushButton::clicked, this, &DialogSeamlyMePreferences::Ok);
76 
77  QPushButton *apply_Button = ui->buttonBox->button(QDialogButtonBox::Apply);
78  SCASSERT(apply_Button != nullptr)
79  connect(apply_Button, &QPushButton::clicked, this, &DialogSeamlyMePreferences::Apply);
80 
81  ui->pagesWidget->insertWidget(0, m_configurationPage);
82  ui->pagesWidget->insertWidget(1, m_pathPage);
83 
84  connect(ui->contentsWidget, &QListWidget::currentItemChanged, this, &DialogSeamlyMePreferences::PageChanged);
85  ui->pagesWidget->setCurrentIndex(0);
86 }
87 
88 //---------------------------------------------------------------------------------------------------------------------
90 {
91  delete ui;
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
95 void DialogSeamlyMePreferences::showEvent(QShowEvent *event)
96 {
97  QDialog::showEvent( event );
98  if ( event->spontaneous() )
99  {
100  return;
101  }
102 
103  if (m_isInitialized)
104  {
105  return;
106  }
107  // do your init stuff here
108 
109  setMinimumSize(size());
110 
111  QSize sz = qApp->Settings()->getPreferenceDialogSize();
112  if (sz.isEmpty() == false)
113  {
114  resize(sz);
115  }
116 
117  m_isInitialized = true;//first show windows are held
118 }
119 
120 //---------------------------------------------------------------------------------------------------------------------
121 void DialogSeamlyMePreferences::resizeEvent(QResizeEvent *event)
122 {
123  Q_UNUSED(event)
124  // remember the size for the next time this dialog is opened, but only
125  // if widget was already initialized, which rules out the resize at
126  // dialog creating, which would
127  if (m_isInitialized)
128  {
129  qApp->Settings()->setPreferenceDialogSize(size());
130  }
131 }
132 
133 //---------------------------------------------------------------------------------------------------------------------
135 {
137  m_pathPage->Apply();
138 
139  qApp->SeamlyMeSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
140  emit updateProperties();
141  setResult(QDialog::Accepted);
142 }
143 
144 //---------------------------------------------------------------------------------------------------------------------
146 {
147  Apply();
148  done(QDialog::Accepted);
149 }
150 
151 //---------------------------------------------------------------------------------------------------------------------
152 void DialogSeamlyMePreferences::PageChanged(QListWidgetItem *current, QListWidgetItem *previous)
153 {
154  if (current == nullptr)
155  {
156  current = previous;
157  }
158  int rowIndex = ui->contentsWidget->row(current);
159  ui->pagesWidget->setCurrentIndex(rowIndex);
160 }
SeamlyMePreferencesPathPage * m_pathPage
Ui::DialogSeamlyMePreferences * ui
DialogSeamlyMePreferences(QWidget *parent=nullptr)
void PageChanged(QListWidgetItem *current, QListWidgetItem *previous)
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
SeamlyMePreferencesConfigurationPage * m_configurationPage
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67