Seamly2D
Code documentation
preferencesgraphicsviewpage.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file PreferencesGraphicsViewPage.cpp
4  ** @author DS Caskey
5  ** @date 10.17.2020
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2017 Seamly2D project
12  ** All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
30 #include "ui_preferencesgraphicsviewpage.h"
31 #include "../../core/vapplication.h"
32 #include "../vpatterndb/pmsystems.h"
33 #include "../vmisc/logging.h"
34 #include "../vtools/tools/vabstracttool.h"
35 #include "../vwidgets/vmaingraphicsview.h"
36 
37 #include <Qt>
38 #include <QDir>
39 #include <QDirIterator>
40 #include <QMessageBox>
41 #include <QTimer>
42 #include <QtDebug>
43 #include <QDoubleSpinBox>
44 #include <QCheckBox>
45 #include <QFontComboBox>
46 #include <QPixmap>
47 
48 
49 Q_LOGGING_CATEGORY(vGraphicsViewConfig, "vgraphicsviewconfig")
50 //---------------------------------------------------------------------------------------------------------------------
52  : QWidget(parent)
54  , m_zrbPositiveColorChanged(false)
55  , m_zrbNegativeColorChanged(false)
56  , m_pointNameColorChanged(false)
57  , m_pointNameHoverColorChanged(false)
58  , m_orginAxisColorChanged(false)
59  , m_primarySupportColorChanged(false)
60  , m_secondarySupportColorChanged(false)
61  , m_tertiarySupportColorChanged(false)
62 {
63  ui->setupUi(this);
64 // Appearance preferences
65  // Toolbar
66  ui->toolBarStyle_CheckBox->setChecked(qApp->Seamly2DSettings()->getToolBarStyle());
67  ui->toolsToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowToolsToolBar());
68  ui->pointToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowPointToolBar());
69  ui->lineToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowLineToolBar());
70  ui->curveToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowCurveToolBar());
71  ui->arcToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowArcToolBar());
72  ui->operationToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowOpsToolBar());
73  ui->pieceToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowPieceToolBar());
74  ui->detailsToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowDetailsToolBar());
75  ui->layoutToolbar_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowLayoutToolBar());
76 
77  // Antialiasing
78  ui->graphicsOutput_CheckBox->setChecked(qApp->Seamly2DSettings()->GetGraphicalOutput());
79 
80  ui->primarySupportColor_ComboBox->setItems(VAbstractTool::supportColorsList());
81  ui->secondarySupportColor_ComboBox->setItems(VAbstractTool::supportColorsList());
82  ui->tertiarySupportColor_ComboBox->setItems(VAbstractTool::supportColorsList());
83 
84  /*
85  QPixmap pixmap = VAbstractTool::createColorIcon(ui->primarySupportColor_ComboBox->getIconWidth(),
86  ui->primarySupportColor_ComboBox->getIconHeight(),
87  "magenta");
88  ui->primarySupportColor_ComboBox->addItem(QIcon(pixmap), tr("Magenta"), "magenta");
89  ui->primarySupportColor_ComboBox->model()->sort(0, Qt::AscendingOrder);
90  ui->secondarySupportColor_ComboBox->addItem(QIcon(pixmap), tr("Magenta"), "magenta");
91  ui->secondarySupportColor_ComboBox->model()->sort(0, Qt::AscendingOrder);
92  ui->tertiarySupportColor_ComboBox->addItem(QIcon(pixmap), tr("Magenta"), "magenta");
93  ui->tertiarySupportColor_ComboBox->model()->sort(0, Qt::AscendingOrder);
94  */
95 
96 // Color preferences
97  // Zoom Rubberband colors
98  int index = ui->zrbPositiveColor_ComboBox->findText(qApp->Seamly2DSettings()->getZoomRBPositiveColor());
99  if (index != -1)
100  {
101  ui->zrbPositiveColor_ComboBox->setCurrentIndex(index);
102  }
103  connect(ui->zrbPositiveColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
104  {
105  m_zrbPositiveColorChanged = true;
106  });
107 
108  index = ui->zrbNegativeColor_ComboBox->findText(qApp->Seamly2DSettings()->getZoomRBNegativeColor());
109  if (index != -1)
110  {
111  ui->zrbNegativeColor_ComboBox->setCurrentIndex(index);
112  }
113  connect(ui->zrbNegativeColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
114  {
115  m_zrbNegativeColorChanged = true;
116  });
117 
118  index = ui->pointNameColor_ComboBox->findText(qApp->Seamly2DSettings()->getPointNameColor());
119  if (index != -1)
120  {
121  ui->pointNameColor_ComboBox->setCurrentIndex(index);
122  }
123  connect(ui->pointNameColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
124  {
125  m_pointNameColorChanged = true;
126  });
127 
128  index = ui->pointNameHoverColor_ComboBox->findText(qApp->Seamly2DSettings()->getPointNameHoverColor());
129  if (index != -1)
130  {
131  ui->pointNameHoverColor_ComboBox->setCurrentIndex(index);
132  }
133  connect(ui->pointNameHoverColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
134  {
135  m_pointNameHoverColorChanged = true;
136  });
137 
138  //----------------------- Axis Orgin Color
139  index = ui->axisOrginColor_ComboBox->findText(qApp->Seamly2DSettings()->getAxisOrginColor());
140  if (index != -1)
141  {
142  ui->axisOrginColor_ComboBox->setCurrentIndex(index);
143  }
144  connect(ui->axisOrginColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
145  {
146  m_orginAxisColorChanged = true;
147  });
148 
149  //----------------------- Selection Support Colors
150  index = ui->primarySupportColor_ComboBox->findText(qApp->Seamly2DSettings()->getPrimarySupportColor());
151  if (index != -1)
152  {
153  ui->primarySupportColor_ComboBox->setCurrentIndex(index);
154  }
155  connect(ui->primarySupportColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
156  {
157  m_primarySupportColorChanged = true;
158  });
159 
160  index = ui->secondarySupportColor_ComboBox->findText(qApp->Seamly2DSettings()->getSecondarySupportColor());
161  if (index != -1)
162  {
163  ui->secondarySupportColor_ComboBox->setCurrentIndex(index);
164  }
165  connect(ui->secondarySupportColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
166  {
167  m_secondarySupportColorChanged = true;
168  });
169 
170  index = ui->tertiarySupportColor_ComboBox->findText(qApp->Seamly2DSettings()->getTertiarySupportColor());
171  if (index != -1)
172  {
173  ui->tertiarySupportColor_ComboBox->setCurrentIndex(index);
174  }
175  connect(ui->tertiarySupportColor_ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
176  {
177  m_tertiarySupportColorChanged = true;
178  });
179 
180 // Navigation preferences
181  // Show Scroll Bars
182  ui->showScrollBars_CheckBox->setChecked(qApp->Seamly2DSettings()->getShowScrollBars());
183 
184  // Scroll Bar Width
185  ui->scrollBarWidth_SpinBox->setValue(qApp->Seamly2DSettings()->getScrollBarWidth());
186 
187  ui->scrollDuration_SpinBox->setValue(qApp->Seamly2DSettings()->getScrollDuration());
188  ui->scrollUpdateInterval_SpinBox->setValue(qApp->Seamly2DSettings()->getScrollUpdateInterval());
189  ui->scrollSpeedFactor_Slider->setValue(qApp->Seamly2DSettings()->getScrollSpeedFactor());
190 
191  // Zoom Modifier Key
192  ui->zoomModKey_CheckBox->setChecked(qApp->Seamly2DSettings()->getZoomModKey());
193 
194  // Zoom Speed
195  ui->zoomSpeedFactor_Slider->setValue(qApp->Seamly2DSettings()->getZoomSpeedFactor());
196 
197  // Export Quality
198  ui->quality_Slider->setValue(qApp->Seamly2DSettings()->getExportQuality());
199 
200 // Behavior preferences
201  // Constrain Angle Value & Modifier Key
202  ui->constrainValue_DoubleSpinBox->setValue(qApp->Seamly2DSettings()->getConstrainValue());
203  ui->constrainModKey_CheckBox->setChecked(qApp->Seamly2DSettings()->getConstrainModKey());
204 
205  // Zoom double mouse click to selected IsTestModeEnabled
206  ui->zoomDoubleClick_CheckBox->setChecked(qApp->Seamly2DSettings()->isZoomDoubleClick());
207 
208  // Pan Zoom while Space Key pressed
209  ui->panActiveSpacePressed_CheckBox->setChecked(qApp->Seamly2DSettings()->isPanActiveSpaceKey());
210 
211 // Font preferences
212  // Pattern piece labels font
213  //QFont labelFont = qApp->Seamly2DSettings()->getLabelFont();
214  //ui->labelFont_ComboBox->setCurrentFont(labelFont);
215  ui->labelFont_ComboBox->setCurrentFont(qApp->Seamly2DSettings()->getLabelFont());
216 
217 /* labelFont.setPointSize(12);
218  ui->label_Label->setFont(labelFont);
219 
220  connect(ui->labelFont_ComboBox,
221  static_cast<void(QFontComboBox::*)(const QFont &)>(&QFontComboBox::currentFontChanged),
222  this, [this](QFont labelFont)
223  {
224  labelFont.setPointSize(12);
225  ui->label_Label->setFont(labelFont);
226  });
227 */
228  // Point name font
229  QFont nameFont = qApp->Seamly2DSettings()->getPointNameFont();
230  ui->pointNameFont_ComboBox->setCurrentFont(nameFont);
231  nameFont.setPointSize(12);
232  ui->pointName_Label->setFont(nameFont);
233 
234  connect(ui->pointNameFont_ComboBox,
235  static_cast<void(QFontComboBox::*)(const QFont &)>(&QFontComboBox::currentFontChanged),
236  this, [this](QFont nameFont)
237  {
238  nameFont.setPointSize(12);
239  ui->pointName_Label->setFont(nameFont);
240  });
241 
242  index = ui->pointNameFontSize_ComboBox->findText(QString().setNum(qApp->Seamly2DSettings()->getPointNameSize()));
243  if (index != -1)
244  {
245  ui->pointNameFontSize_ComboBox->setCurrentIndex(index);
246  }
247 
248  // GUI font
249  QFont guiFont = qApp->Seamly2DSettings()->getGuiFont();
250  ui->guiFont_ComboBox->setCurrentFont(guiFont);
251  guiFont.setPointSize(12);
252  ui->gui_Label->setFont(guiFont);
253 
254  connect(ui->guiFont_ComboBox,
255  static_cast<void(QFontComboBox::*)(const QFont &)>(&QFontComboBox::currentFontChanged),
256  this, [this](QFont guiFont)
257  {
258  guiFont.setPointSize(12);
259  ui->gui_Label->setFont(guiFont);
260  });
261 
262  index = ui->guiFontSize_ComboBox->findText(QString().setNum(qApp->Seamly2DSettings()->getGuiFontSize()));
263  if (index != -1)
264  {
265  ui->guiFontSize_ComboBox->setCurrentIndex(index);
266  }
267 }
268 
269 //---------------------------------------------------------------------------------------------------------------------
271 {
272  delete ui;
273 }
274 
275 //---------------------------------------------------------------------------------------------------------------------
277 {
278  VSettings *settings = qApp->Seamly2DSettings();
279 
280  settings->setToolBarStyle(ui->toolBarStyle_CheckBox->isChecked());
281  settings->setShowToolsToolBar(ui->toolsToolbar_CheckBox->isChecked());
282  settings->setShowPointToolBar(ui->pointToolbar_CheckBox->isChecked());
283  settings->setShowLineToolBar(ui->lineToolbar_CheckBox->isChecked());
284  settings->setShowCurveToolBar(ui->curveToolbar_CheckBox->isChecked());
285  settings->setShowArcToolBar(ui->arcToolbar_CheckBox->isChecked());
286  settings->setShowOpsToolBar(ui->operationToolbar_CheckBox->isChecked());
287  settings->setShowPieceToolBar(ui->pieceToolbar_CheckBox->isChecked());
288  settings->setShowDetailsToolBar(ui->detailsToolbar_CheckBox->isChecked());
289  settings->setShowLayoutToolBar(ui->layoutToolbar_CheckBox->isChecked());
290 
291  // Appearance preferences
292  // Toolbar
293  // Scene antialiasing
294  settings->SetGraphicalOutput(ui->graphicsOutput_CheckBox->isChecked());
295  qApp->getSceneView()->setRenderHint(QPainter::Antialiasing, ui->graphicsOutput_CheckBox->isChecked());
296  qApp->getSceneView()->setRenderHint(QPainter::SmoothPixmapTransform, ui->graphicsOutput_CheckBox->isChecked());
297 
298  // Color preferences
299  // Zoom Rubberband colors
301  {
302  settings->setZoomRBPositiveColor(ui->zrbPositiveColor_ComboBox->currentText());
304  }
305 
307  {
308  settings->setZoomRBNegativeColor(ui->zrbNegativeColor_ComboBox->currentText());
310  }
311 
312  // Point Name colors
314  {
315  settings->setPointNameColor(ui->pointNameColor_ComboBox->currentText());
316  m_pointNameColorChanged = false;
317  }
318 
320  {
321  settings->setPointNameHoverColor(ui->pointNameHoverColor_ComboBox->currentText());
323  }
324 
326  {
327  settings->setAxisOrginColor(ui->axisOrginColor_ComboBox->currentText());
328  m_orginAxisColorChanged = false;
329  }
330 
332  {
333  settings->setPrimarySupportColor(ui->primarySupportColor_ComboBox->currentText());
335  }
336 
338  {
339  settings->setSecondarySupportColor(ui->secondarySupportColor_ComboBox->currentText());
341  }
342 
344  {
345  settings->setTertiarySupportColor(ui->tertiarySupportColor_ComboBox->currentText());
347  }
348 
349  // Navigation preferences
350  // Scroll Bars
351  settings->setShowScrollBars(ui->showScrollBars_CheckBox->isChecked());
352  settings->setScrollBarWidth(ui->scrollBarWidth_SpinBox->value());
353  settings->setScrollDuration(ui->scrollDuration_SpinBox->value());
354  settings->setScrollUpdateInterval(ui->scrollUpdateInterval_SpinBox->value());
355  settings->setScrollSpeedFactor(ui->scrollSpeedFactor_Slider->value());
356 
357  // Zoom
358  settings->setZoomModKey(ui->zoomModKey_CheckBox->isChecked());
359  settings->setZoomSpeedFactor(ui->zoomSpeedFactor_Slider->value());
360 
361  // Export Quality
362  settings->setExportQuality(ui->quality_Slider->value());
363 
364  // Behavior preferences
365  // Constrain Angle Value & Modifier Key
366  settings->setConstrainValue(ui->constrainValue_DoubleSpinBox->value());
367  settings->setConstrainModKey(ui->constrainModKey_CheckBox->isChecked());
368 
369  // Zoom double mouse click to selected IsTestModeEnabled
370  settings->setZoomDoubleClick(ui->zoomDoubleClick_CheckBox->isChecked());
371 
372  // Pan Zoom while Space key pressed
373  settings->setPanActiveSpaceKey(ui->panActiveSpacePressed_CheckBox->isChecked());
374 
375  //Fonts
376  settings->setLabelFont(ui->labelFont_ComboBox->currentFont());
377 
378  settings->setGuiFont(ui->guiFont_ComboBox->currentFont());
379  settings->setGuiFontSize(ui->guiFontSize_ComboBox->currentText().toInt());
380 
381  settings->setPointNameFont(ui->pointNameFont_ComboBox->currentFont());
382  settings->setPointNameSize(ui->pointNameFontSize_ComboBox->currentText().toInt());
383 }
Ui::PreferencesGraphicsViewPage * ui
static QMap< QString, QString > supportColorsList()
void setPointNameSize(int value)
void setScrollUpdateInterval(const int &interval)
void setShowCurveToolBar(const bool &value)
void setShowOpsToolBar(const bool &value)
void setGuiFont(const QFont &f)
void setZoomModKey(const bool &value)
void setPointNameColor(const QString &value)
void setZoomRBNegativeColor(const QString &value)
void setPanActiveSpaceKey(const bool &value)
void setToolBarStyle(const bool &value)
void setScrollSpeedFactor(const int &factor)
void setSecondarySupportColor(const QString &value)
void setScrollBarWidth(const int &width)
void setTertiarySupportColor(const QString &value)
void setAxisOrginColor(const QString &value)
void setShowToolsToolBar(const bool &value)
void setPointNameHoverColor(const QString &value)
void setScrollDuration(const int &duration)
void setShowLineToolBar(const bool &value)
void setLabelFont(const QFont &f)
void setZoomSpeedFactor(const int &factor)
void setPrimarySupportColor(const QString &value)
void setConstrainModKey(const bool &value)
void setShowPointToolBar(const bool &value)
void setShowDetailsToolBar(const bool &value)
void setShowScrollBars(const bool &value)
void setGuiFontSize(int value)
void setConstrainValue(const qreal &value)
void setShowPieceToolBar(const bool &value)
void setZoomRBPositiveColor(const QString &value)
void setExportQuality(const int &value)
void setShowLayoutToolBar(const bool &value)
void setPointNameFont(const QFont &f)
void setShowArcToolBar(const bool &value)
void setZoomDoubleClick(const bool &value)
void SetGraphicalOutput(const bool &value)
Definition: vsettings.cpp:182
#define qApp
Definition: vapplication.h:67