37 #include "colors.h" |
37 #include "colors.h" |
38 #include "colorSelector.h" |
38 #include "colorSelector.h" |
39 #include "glRenderer.h" |
39 #include "glRenderer.h" |
40 #include "ui_config.h" |
40 #include "ui_config.h" |
41 |
41 |
42 EXTERN_CFGENTRY (String, BackgroundColor); |
42 EXTERN_CFGENTRY (String, YtruderPath) |
43 EXTERN_CFGENTRY (String, MainColor); |
43 EXTERN_CFGENTRY (String, RectifierPath) |
44 EXTERN_CFGENTRY (Bool, ColorizeObjectsList); |
44 EXTERN_CFGENTRY (String, IntersectorPath) |
45 EXTERN_CFGENTRY (Bool, BfcRedGreenView); |
45 EXTERN_CFGENTRY (String, CovererPath) |
46 EXTERN_CFGENTRY (Float, MainColorAlpha); |
46 EXTERN_CFGENTRY (String, IsecalcPath) |
47 EXTERN_CFGENTRY (Int, LineThickness); |
47 EXTERN_CFGENTRY (String, Edger2Path) |
48 EXTERN_CFGENTRY (String, QuickColorToolbar); |
48 EXTERN_CFGENTRY (Bool, YtruderUsesWine) |
49 EXTERN_CFGENTRY (Bool, BlackEdges); |
49 EXTERN_CFGENTRY (Bool, RectifierUsesWine) |
50 EXTERN_CFGENTRY (Bool, AntiAliasedLines); |
50 EXTERN_CFGENTRY (Bool, IntersectorUsesWine) |
51 EXTERN_CFGENTRY (Bool, ListImplicitFiles); |
51 EXTERN_CFGENTRY (Bool, CovererUsesWine) |
52 EXTERN_CFGENTRY (String, DownloadFilePath); |
52 EXTERN_CFGENTRY (Bool, IsecalcUsesWine) |
53 EXTERN_CFGENTRY (Bool, GuessDownloadPaths); |
53 EXTERN_CFGENTRY (Bool, Edger2UsesWine) |
54 EXTERN_CFGENTRY (Bool, AutoCloseDownloadDialog); |
54 EXTERN_CFGENTRY (String, QuickColorToolbar) |
55 EXTERN_CFGENTRY (Bool, UseLogoStuds); |
|
56 EXTERN_CFGENTRY (Bool, DrawLineLengths); |
|
57 EXTERN_CFGENTRY (String, DefaultName); |
|
58 EXTERN_CFGENTRY (String, DefaultUser); |
|
59 EXTERN_CFGENTRY (Bool, UseCALicense); |
|
60 EXTERN_CFGENTRY (String, SelectColorBlend); |
|
61 EXTERN_CFGENTRY (String, YtruderPath); |
|
62 EXTERN_CFGENTRY (String, RectifierPath); |
|
63 EXTERN_CFGENTRY (String, IntersectorPath); |
|
64 EXTERN_CFGENTRY (String, CovererPath); |
|
65 EXTERN_CFGENTRY (String, IsecalcPath); |
|
66 EXTERN_CFGENTRY (String, Edger2Path); |
|
67 EXTERN_CFGENTRY (Bool, YtruderUsesWine); |
|
68 EXTERN_CFGENTRY (Bool, RectifierUsesWine); |
|
69 EXTERN_CFGENTRY (Bool, IntersectorUsesWine); |
|
70 EXTERN_CFGENTRY (Bool, CovererUsesWine); |
|
71 EXTERN_CFGENTRY (Bool, IsecalcUsesWine); |
|
72 EXTERN_CFGENTRY (Bool, Edger2UsesWine); |
|
73 EXTERN_CFGENTRY (Float, GridCoarseCoordinateSnap); |
|
74 EXTERN_CFGENTRY (Float, GridCoarseAngleSnap); |
|
75 EXTERN_CFGENTRY (Float, GridMediumCoordinateSnap); |
|
76 EXTERN_CFGENTRY (Float, GridMediumAngleSnap); |
|
77 EXTERN_CFGENTRY (Float, GridFineCoordinateSnap); |
|
78 EXTERN_CFGENTRY (Float, GridFineAngleSnap); |
|
79 EXTERN_CFGENTRY (Bool, HighlightObjectBelowCursor) |
|
80 EXTERN_CFGENTRY (Int, RoundPosition) |
|
81 EXTERN_CFGENTRY (Int, RoundMatrix) |
|
82 |
55 |
83 const char* g_extProgPathFilter = |
56 const char* g_extProgPathFilter = |
84 #ifdef _WIN32 |
57 #ifdef _WIN32 |
85 "Applications (*.exe)(*.exe);;" |
58 "Applications (*.exe)(*.exe);;" |
86 #endif |
59 #endif |
121 { |
94 { |
122 assert (g_win != null); |
95 assert (g_win != null); |
123 ui = new Ui_ConfigUI; |
96 ui = new Ui_ConfigUI; |
124 ui->setupUi (this); |
97 ui->setupUi (this); |
125 |
98 |
126 // Interface tab |
99 // Set defaults |
127 setButtonBackground (ui->backgroundColorButton, cfg::BackgroundColor); |
100 _applyToWidgetOptions ([&](QWidget* wdg, AbstractConfigEntry* conf) |
128 connect (ui->backgroundColorButton, SIGNAL (clicked()), |
101 { |
129 this, SLOT (slot_setGLBackground())); |
102 QVariant value (conf->toVariant()); |
130 |
103 QLineEdit* le; |
131 setButtonBackground (ui->mainColorButton, cfg::MainColor); |
104 QSpinBox* spinbox; |
132 connect (ui->mainColorButton, SIGNAL (clicked()), |
105 QDoubleSpinBox* doublespinbox; |
133 this, SLOT (slot_setGLForeground())); |
106 QSlider* slider; |
134 |
107 QCheckBox* checkbox; |
135 setButtonBackground (ui->selColorButton, cfg::SelectColorBlend); |
108 QPushButton* button; |
136 connect (ui->selColorButton, SIGNAL (clicked()), |
109 |
137 this, SLOT (slot_setGLSelectColor())); |
110 if ((le = qobject_cast<QLineEdit*> (wdg)) != null) |
138 |
111 { |
139 ui->mainColorAlpha->setValue (cfg::MainColorAlpha * 10.0f); |
112 le->setText (value.toString()); |
140 ui->lineThickness->setValue (cfg::LineThickness); |
113 } |
141 ui->colorizeObjects->setChecked (cfg::ColorizeObjectsList); |
114 elif ((spinbox = qobject_cast<QSpinBox*> (wdg)) != null) |
142 ui->colorBFC->setChecked (cfg::BfcRedGreenView); |
115 { |
143 ui->blackEdges->setChecked (cfg::BlackEdges); |
116 spinbox->setValue (value.toInt()); |
144 ui->m_aa->setChecked (cfg::AntiAliasedLines); |
117 } |
145 ui->implicitFiles->setChecked (cfg::ListImplicitFiles); |
118 elif ((doublespinbox = qobject_cast<QDoubleSpinBox*> (wdg)) != null) |
146 ui->m_logostuds->setChecked (cfg::UseLogoStuds); |
119 { |
147 ui->linelengths->setChecked (cfg::DrawLineLengths); |
120 doublespinbox->setValue (value.toDouble()); |
148 |
121 } |
149 ui->roundPosition->setValue (cfg::RoundPosition); |
122 elif ((slider = qobject_cast<QSlider*> (wdg)) != null) |
150 ui->roundMatrix->setValue (cfg::RoundMatrix); |
123 { |
|
124 slider->setValue (value.toInt()); |
|
125 } |
|
126 elif ((checkbox = qobject_cast<QCheckBox*> (wdg)) != null) |
|
127 { |
|
128 checkbox->setChecked (value.toBool()); |
|
129 } |
|
130 elif ((button = qobject_cast<QPushButton*> (wdg)) != null) |
|
131 { |
|
132 setButtonBackground (button, value.toString()); |
|
133 connect (button, SIGNAL (clicked()), this, SLOT (setButtonColor())); |
|
134 } |
|
135 else |
|
136 { |
|
137 print ("Unknown widget of type %1\n", wdg->metaObject()->className()); |
|
138 } |
|
139 }); |
151 |
140 |
152 g_win->applyToActions ([&](QAction* act) |
141 g_win->applyToActions ([&](QAction* act) |
153 { |
142 { |
154 addShortcut (act); |
143 addShortcut (act); |
155 }); |
144 }); |
156 |
145 |
157 ui->shortcutsList->setSortingEnabled (true); |
146 ui->shortcutsList->setSortingEnabled (true); |
158 ui->shortcutsList->sortItems(); |
147 ui->shortcutsList->sortItems(); |
159 |
148 quickColors = quickColorsFromConfig(); |
|
149 updateQuickColorList(); |
|
150 initExtProgs(); |
|
151 selectPage (deftab); |
160 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); |
152 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); |
161 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); |
153 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); |
162 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); |
154 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); |
163 |
|
164 quickColors = quickColorsFromConfig(); |
|
165 updateQuickColorList(); |
|
166 |
|
167 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); |
155 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); |
168 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); |
156 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); |
169 connect (ui->quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor())); |
157 connect (ui->quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor())); |
170 connect (ui->quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator())); |
158 connect (ui->quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator())); |
171 connect (ui->quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor())); |
159 connect (ui->quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor())); |
172 connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); |
160 connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); |
173 connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); |
161 connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); |
174 |
|
175 ui->downloadPath->setText (cfg::DownloadFilePath); |
|
176 ui->guessNetPaths->setChecked (cfg::GuessDownloadPaths); |
|
177 ui->autoCloseNetPrompt->setChecked (cfg::AutoCloseDownloadDialog); |
|
178 connect (ui->findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); |
162 connect (ui->findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); |
179 |
|
180 ui->m_profileName->setText (cfg::DefaultName); |
|
181 ui->m_profileUsername->setText (cfg::DefaultUser); |
|
182 ui->UseCALicense->setChecked (cfg::UseCALicense); |
|
183 ui->gridCoarseCoordinateSnap->setValue (cfg::GridCoarseCoordinateSnap); |
|
184 ui->gridCoarseAngleSnap->setValue (cfg::GridCoarseAngleSnap); |
|
185 ui->gridMediumCoordinateSnap->setValue (cfg::GridMediumCoordinateSnap); |
|
186 ui->gridMediumAngleSnap->setValue (cfg::GridMediumAngleSnap); |
|
187 ui->gridFineCoordinateSnap->setValue (cfg::GridFineCoordinateSnap); |
|
188 ui->gridFineAngleSnap->setValue (cfg::GridFineAngleSnap); |
|
189 ui->highlightObjectBelowCursor->setChecked (cfg::HighlightObjectBelowCursor); |
|
190 |
|
191 initExtProgs(); |
|
192 selectPage (deftab); |
|
193 |
|
194 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), |
163 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), |
195 this, SLOT (buttonClicked (QAbstractButton*))); |
164 this, SLOT (buttonClicked (QAbstractButton*))); |
196 |
165 connect (ui->m_pages, SIGNAL (currentChanged (int)), this, SLOT (selectPage (int))); |
197 connect (ui->m_pages, SIGNAL (currentChanged (int)), |
166 connect (ui->m_pagelist, SIGNAL (currentRowChanged (int)), this, SLOT (selectPage (int))); |
198 this, SLOT (selectPage (int))); |
|
199 |
|
200 connect (ui->m_pagelist, SIGNAL (currentRowChanged (int)), |
|
201 this, SLOT (selectPage (int))); |
|
202 } |
167 } |
203 |
168 |
204 // |
169 // |
205 // |
170 // |
206 ConfigDialog::~ConfigDialog() |
171 ConfigDialog::~ConfigDialog() |
275 } |
240 } |
276 |
241 |
277 ui->extProgs->setLayout (pathsLayout); |
242 ui->extProgs->setLayout (pathsLayout); |
278 } |
243 } |
279 |
244 |
|
245 void ConfigDialog::_applyToWidgetOptions (std::function<void (QWidget*, AbstractConfigEntry*)> func) |
|
246 { |
|
247 // Apply configuration |
|
248 for (QWidget* wdg : findChildren<QWidget*>()) |
|
249 { |
|
250 if (not wdg->objectName().startsWith ("config")) |
|
251 continue; |
|
252 |
|
253 QString confname (wdg->objectName().mid (strlen ("config"))); |
|
254 AbstractConfigEntry* conf (Config::FindByName (confname)); |
|
255 |
|
256 if (conf == null) |
|
257 { |
|
258 print ("Couldn't find configuration entry named %1", confname); |
|
259 continue; |
|
260 } |
|
261 |
|
262 func (wdg, conf); |
|
263 } |
|
264 } |
|
265 |
280 // |
266 // |
281 // Set the settings based on widget data. |
267 // Set the settings based on widget data. |
282 // |
268 // |
283 void ConfigDialog::applySettings() |
269 void ConfigDialog::applySettings() |
284 { |
270 { |
285 // Apply configuration |
271 _applyToWidgetOptions ([&](QWidget* wdg, AbstractConfigEntry* conf) |
286 cfg::ColorizeObjectsList = ui->colorizeObjects->isChecked(); |
272 { |
287 cfg::BfcRedGreenView = ui->colorBFC->isChecked(); |
273 QVariant value (conf->toVariant()); |
288 cfg::BlackEdges = ui->blackEdges->isChecked(); |
274 QLineEdit* le; |
289 cfg::MainColorAlpha = ((double) ui->mainColorAlpha->value()) / 10.0; |
275 QSpinBox* spinbox; |
290 cfg::LineThickness = ui->lineThickness->value(); |
276 QDoubleSpinBox* doublespinbox; |
291 cfg::ListImplicitFiles = ui->implicitFiles->isChecked(); |
277 QSlider* slider; |
292 cfg::DownloadFilePath = ui->downloadPath->text(); |
278 QCheckBox* checkbox; |
293 cfg::GuessDownloadPaths = ui->guessNetPaths->isChecked(); |
279 QPushButton* button; |
294 cfg::AutoCloseDownloadDialog = ui->autoCloseNetPrompt->isChecked(); |
280 |
295 cfg::UseLogoStuds = ui->m_logostuds->isChecked(); |
281 if ((le = qobject_cast<QLineEdit*> (wdg)) != null) |
296 cfg::DrawLineLengths = ui->linelengths->isChecked(); |
282 value = le->text(); |
297 cfg::DefaultUser = ui->m_profileUsername->text(); |
283 elif ((spinbox = qobject_cast<QSpinBox*> (wdg)) != null) |
298 cfg::DefaultName = ui->m_profileName->text(); |
284 value = spinbox->value(); |
299 cfg::UseCALicense = ui->UseCALicense->isChecked(); |
285 elif ((doublespinbox = qobject_cast<QDoubleSpinBox*> (wdg)) != null) |
300 cfg::AntiAliasedLines = ui->m_aa->isChecked(); |
286 value = doublespinbox->value(); |
301 cfg::HighlightObjectBelowCursor = ui->highlightObjectBelowCursor->isChecked(); |
287 elif ((slider = qobject_cast<QSlider*> (wdg)) != null) |
302 cfg::RoundPosition = ui->roundPosition->value(); |
288 value = slider->value(); |
303 cfg::RoundMatrix = ui->roundMatrix->value(); |
289 elif ((checkbox = qobject_cast<QCheckBox*> (wdg)) != null) |
|
290 value = checkbox->isChecked(); |
|
291 elif ((button = qobject_cast<QPushButton*> (wdg)) != null) |
|
292 value = _buttonColors[button]; |
|
293 else |
|
294 print ("Unknown widget of type %1\n", wdg->metaObject()->className()); |
|
295 |
|
296 conf->loadFromVariant (value); |
|
297 }); |
304 |
298 |
305 // Rebuild the quick color toolbar |
299 // Rebuild the quick color toolbar |
306 g_win->setQuickColors (quickColors); |
300 g_win->setQuickColors (quickColors); |
307 cfg::QuickColorToolbar = quickColorString(); |
301 cfg::QuickColorToolbar = quickColorString(); |
308 |
|
309 // Set the grid settings |
|
310 cfg::GridCoarseCoordinateSnap = ui->gridCoarseCoordinateSnap->value(); |
|
311 cfg::GridCoarseAngleSnap = ui->gridCoarseAngleSnap->value(); |
|
312 cfg::GridMediumCoordinateSnap = ui->gridMediumCoordinateSnap->value(); |
|
313 cfg::GridMediumAngleSnap = ui->gridMediumAngleSnap->value(); |
|
314 cfg::GridFineCoordinateSnap = ui->gridFineCoordinateSnap->value(); |
|
315 cfg::GridFineAngleSnap = ui->gridFineAngleSnap->value(); |
|
316 |
302 |
317 // Ext program settings |
303 // Ext program settings |
318 for (const LDExtProgInfo& info : g_LDExtProgInfo) |
304 for (const LDExtProgInfo& info : g_LDExtProgInfo) |
319 { |
305 { |
320 *info.path = info.input->text(); |
306 *info.path = info.input->text(); |
508 updateQuickColorList(); |
497 updateQuickColorList(); |
509 } |
498 } |
510 |
499 |
511 // |
500 // |
512 // |
501 // |
513 // Pick a color and set the appropriate configuration option. |
502 void ConfigDialog::setButtonColor() |
514 // |
503 { |
515 void ConfigDialog::pickColor (QString& conf, QPushButton* button) |
504 QPushButton* button = qobject_cast<QPushButton*> (sender()); |
516 { |
505 |
517 QColor col = QColorDialog::getColor (QColor (conf)); |
506 if (button == null) |
|
507 { |
|
508 print ("setButtonColor: null sender!\n"); |
|
509 return; |
|
510 } |
|
511 |
|
512 QColor col = QColorDialog::getColor (_buttonColors[button]); |
518 |
513 |
519 if (col.isValid()) |
514 if (col.isValid()) |
520 { |
515 { |
521 int r = col.red(), |
516 int r = col.red(); |
522 g = col.green(), |
517 int g = col.green(); |
523 b = col.blue(); |
518 int b = col.blue(); |
524 |
519 |
525 QString colname; |
520 QString colname; |
526 colname.sprintf ("#%.2X%.2X%.2X", r, g, b); |
521 colname.sprintf ("#%.2X%.2X%.2X", r, g, b); |
527 conf = colname; |
|
528 setButtonBackground (button, colname); |
522 setButtonBackground (button, colname); |
529 } |
523 } |
530 } |
|
531 |
|
532 // |
|
533 // |
|
534 void ConfigDialog::slot_setGLBackground() |
|
535 { |
|
536 pickColor (cfg::BackgroundColor, ui->backgroundColorButton); |
|
537 } |
|
538 |
|
539 // |
|
540 // |
|
541 void ConfigDialog::slot_setGLForeground() |
|
542 { |
|
543 pickColor (cfg::MainColor, ui->mainColorButton); |
|
544 } |
|
545 |
|
546 // |
|
547 // |
|
548 void ConfigDialog::slot_setGLSelectColor() |
|
549 { |
|
550 pickColor (cfg::SelectColorBlend, ui->selColorButton); |
|
551 } |
524 } |
552 |
525 |
553 // |
526 // |
554 // Sets background color of a given button. |
527 // Sets background color of a given button. |
555 // |
528 // |
556 void ConfigDialog::setButtonBackground (QPushButton* button, QString value) |
529 void ConfigDialog::setButtonBackground (QPushButton* button, QString value) |
557 { |
530 { |
558 button->setIcon (getIcon ("colorselect")); |
531 button->setIcon (getIcon ("colorselect")); |
559 button->setAutoFillBackground (true); |
532 button->setAutoFillBackground (true); |
560 button->setStyleSheet (format ("background-color: %1", value)); |
533 button->setStyleSheet (format ("background-color: %1", value)); |
|
534 _buttonColors[button] = QColor (value); |
561 } |
535 } |
562 |
536 |
563 // |
537 // |
564 // Finds the given list widget item in the list of widget items given. |
538 // Finds the given list widget item in the list of widget items given. |
565 // |
539 // |