src/configDialog.cpp

changeset 970
c8aae45afd85
parent 968
4b93b7963456
child 971
c00f9665a9f8
equal deleted inserted replaced
969:b1742ee91d5b 970:c8aae45afd85
37 #include "colors.h" 37 #include "colors.h"
38 #include "dialogs/colorselector.h" 38 #include "dialogs/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, YtruderPath)
43 EXTERN_CFGENTRY (String, RectifierPath)
44 EXTERN_CFGENTRY (String, IntersectorPath)
45 EXTERN_CFGENTRY (String, CovererPath)
46 EXTERN_CFGENTRY (String, IsecalcPath)
47 EXTERN_CFGENTRY (String, Edger2Path)
48 EXTERN_CFGENTRY (Bool, YtruderUsesWine)
49 EXTERN_CFGENTRY (Bool, RectifierUsesWine)
50 EXTERN_CFGENTRY (Bool, IntersectorUsesWine)
51 EXTERN_CFGENTRY (Bool, CovererUsesWine)
52 EXTERN_CFGENTRY (Bool, IsecalcUsesWine)
53 EXTERN_CFGENTRY (Bool, Edger2UsesWine)
54 EXTERN_CFGENTRY (String, QuickColorToolbar)
55
56 const char* g_extProgPathFilter = 42 const char* g_extProgPathFilter =
57 #ifdef _WIN32 43 #ifdef _WIN32
58 "Applications (*.exe)(*.exe);;" 44 "Applications (*.exe)(*.exe);;"
59 #endif 45 #endif
60 "All files (*.*)(*.*)"; 46 "All files (*.*)(*.*)";
61 47
62 // 48 //
63 // 49 //
64 static struct LDExtProgInfo 50 ConfigDialog::ConfigDialog (QWidget* parent, ConfigDialog::Tab defaulttab, Qt::WindowFlags f) :
65 { 51 QDialog (parent, f),
66 QString const name; 52 HierarchyElement (parent)
67 QString const iconname;
68 QString* const path;
69 QLineEdit* input;
70 QPushButton* setPathButton;
71 bool* const wine;
72 QCheckBox* wineBox;
73 } g_LDExtProgInfo[] =
74 {
75 #ifndef _WIN32
76 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::NAME##Path, null, null, \
77 &cfg::NAME##UsesWine, null },
78 #else
79 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::NAME##Path, null, null, null, null },
80 #endif
81 EXTPROG (Ytruder, ytruder)
82 EXTPROG (Rectifier, rectifier)
83 EXTPROG (Intersector, intersector)
84 EXTPROG (Isecalc, isecalc)
85 EXTPROG (Coverer, coverer)
86 EXTPROG (Edger2, edger2)
87 #undef EXTPROG
88 };
89
90 //
91 //
92 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) :
93 QDialog (parent, f)
94 { 53 {
95 ui = new Ui_ConfigUI; 54 ui = new Ui_ConfigUI;
96 ui->setupUi (this); 55 ui->setupUi (this);
97 56
98 // Set defaults 57 // Set defaults
99 m_applyToWidgetOptions ([&](QWidget* wdg, AbstractConfigEntry* conf) 58 applyToWidgetOptions ([&](QWidget* wdg, AbstractConfigEntry* conf)
100 { 59 {
101 QVariant value (conf->toVariant()); 60 QVariant value (conf->toVariant());
102 QLineEdit* le; 61 QLineEdit* le;
103 QSpinBox* spinbox; 62 QSpinBox* spinbox;
104 QDoubleSpinBox* doublespinbox; 63 QDoubleSpinBox* doublespinbox;
135 { 94 {
136 print ("Unknown widget of type %1\n", wdg->metaObject()->className()); 95 print ("Unknown widget of type %1\n", wdg->metaObject()->className());
137 } 96 }
138 }); 97 });
139 98
140 if (g_win) 99 m_window->applyToActions ([&](QAction* act)
141 { 100 {
142 g_win->applyToActions ([&](QAction* act) 101 addShortcut (act);
143 { 102 });
144 addShortcut (act);
145 });
146 }
147 103
148 ui->shortcutsList->setSortingEnabled (true); 104 ui->shortcutsList->setSortingEnabled (true);
149 ui->shortcutsList->sortItems(); 105 ui->shortcutsList->sortItems();
150 quickColors = LoadQuickColorList(); 106 quickColors = LoadQuickColorList();
151 updateQuickColorList(); 107 updateQuickColorList();
152 initExtProgs(); 108 initExtProgs();
153 selectPage (deftab); 109 selectPage (defaulttab);
154 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); 110 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut()));
155 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); 111 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut()));
156 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); 112 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut()));
157 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); 113 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor()));
158 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); 114 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor()));
208 void ConfigDialog::initExtProgs() 164 void ConfigDialog::initExtProgs()
209 { 165 {
210 QGridLayout* pathsLayout = new QGridLayout; 166 QGridLayout* pathsLayout = new QGridLayout;
211 int row = 0; 167 int row = 0;
212 168
213 for (LDExtProgInfo& info : g_LDExtProgInfo) 169 for (int i = 0; i < NumExternalPrograms; ++i)
214 { 170 {
215 QLabel* icon = new QLabel, 171 ExtProgramType program = (ExtProgramType) i;
216 *progLabel = new QLabel (info.name); 172 ExternalProgramWidgets& widgets = m_externalProgramWidgets[i];
173 QString name = m_window->externalPrograms()->externalProgramName (program);
174 QLabel* icon = new QLabel;
175 QLabel* progLabel = new QLabel (name);
217 QLineEdit* input = new QLineEdit; 176 QLineEdit* input = new QLineEdit;
218 QPushButton* setPathButton = new QPushButton; 177 QPushButton* setPathButton = new QPushButton;
219 178
220 icon->setPixmap (GetIcon (info.iconname)); 179 icon->setPixmap (GetIcon (name.toLower()));
221 input->setText (*info.path); 180 input->setText (*info.path);
222 setPathButton->setIcon (GetIcon ("folder")); 181 setPathButton->setIcon (GetIcon ("folder"));
223 info.input = input; 182 widgets.input = input;
224 info.setPathButton = setPathButton; 183 widgets.setPathButton = setPathButton;
225 184 widgets.wineBox = nullptr;
226 connect (setPathButton, SIGNAL (clicked()), this, SLOT (slot_setExtProgPath())); 185 connect (setPathButton, SIGNAL (clicked()), this, SLOT (slot_setExtProgPath()));
227
228 pathsLayout->addWidget (icon, row, 0); 186 pathsLayout->addWidget (icon, row, 0);
229 pathsLayout->addWidget (progLabel, row, 1); 187 pathsLayout->addWidget (progLabel, row, 1);
230 pathsLayout->addWidget (input, row, 2); 188 pathsLayout->addWidget (input, row, 2);
231 pathsLayout->addWidget (setPathButton, row, 3); 189 pathsLayout->addWidget (setPathButton, row, 3);
232 190
233 if (info.wine != null) 191 #ifdef Q_OS_UNIX
234 { 192 {
235 QCheckBox* wineBox = new QCheckBox ("Wine"); 193 QCheckBox* wineBox = new QCheckBox ("Wine");
236 wineBox->setChecked (*info.wine); 194 wineBox->setChecked (m_window->externalPrograms()->programUsesWine (program));
237 info.wineBox = wineBox; 195 widgets.wineBox = wineBox;
238 pathsLayout->addWidget (wineBox, row, 4); 196 pathsLayout->addWidget (wineBox, row, 4);
239 } 197 }
198 #endif
240 199
241 ++row; 200 ++row;
242 } 201 }
243 202
244 ui->extProgs->setLayout (pathsLayout); 203 ui->extProgs->setLayout (pathsLayout);
245 } 204 }
246 205
247 void ConfigDialog::m_applyToWidgetOptions (std::function<void (QWidget*, AbstractConfigEntry*)> func) 206 void ConfigDialog::applyToWidgetOptions (std::function<void (QWidget*, AbstractConfigEntry*)> func)
248 { 207 {
249 // Apply configuration 208 // Apply configuration
250 for (QWidget* widget : findChildren<QWidget*>()) 209 for (QWidget* widget : findChildren<QWidget*>())
251 { 210 {
252 if (not widget->objectName().startsWith ("config")) 211 if (not widget->objectName().startsWith ("config"))
253 continue; 212 continue;
254 213
255 QString confname (widget->objectName().mid (strlen ("config"))); 214 QString confname (widget->objectName().mid (strlen ("config")));
256 AbstractConfigEntry* conf (Config::FindByName (confname)); 215 AbstractConfigEntry* conf (m_config->findByName (confname));
257 216
258 if (conf == null) 217 if (conf == null)
259 { 218 {
260 print ("Couldn't find configuration entry named %1", confname); 219 print ("Couldn't find configuration entry named %1", confname);
261 continue; 220 continue;
268 // 227 //
269 // Set the settings based on widget data. 228 // Set the settings based on widget data.
270 // 229 //
271 void ConfigDialog::applySettings() 230 void ConfigDialog::applySettings()
272 { 231 {
273 m_applyToWidgetOptions ([&](QWidget* widget, AbstractConfigEntry* conf) 232 applyToWidgetOptions ([&](QWidget* widget, AbstractConfigEntry* conf)
274 { 233 {
275 QVariant value (conf->toVariant()); 234 QVariant value (conf->toVariant());
276 QLineEdit* le; 235 QLineEdit* le;
277 QSpinBox* spinbox; 236 QSpinBox* spinbox;
278 QDoubleSpinBox* doublespinbox; 237 QDoubleSpinBox* doublespinbox;
297 256
298 conf->loadFromVariant (value); 257 conf->loadFromVariant (value);
299 }); 258 });
300 259
301 // Rebuild the quick color toolbar 260 // Rebuild the quick color toolbar
302 if (g_win) 261 m_window->setQuickColors (quickColors);
303 g_win->setQuickColors (quickColors); 262 m_config->quickColorToolbar = quickColorString();
304
305 cfg::QuickColorToolbar = quickColorString();
306 263
307 // Ext program settings 264 // Ext program settings
308 for (const LDExtProgInfo& info : g_LDExtProgInfo) 265 for (int i = 0; i < NumExternalPrograms; ++i)
309 { 266 {
310 *info.path = info.input->text(); 267 ExtProgramType program = (ExtProgramType) i;
311 268 ExtProgramToolset* toolset = m_window->externalPrograms();
312 if (info.wine != null) 269 ExternalProgramWidgets& widgets = m_externalProgramWidgets[i];
313 *info.wine = info.wineBox->isChecked(); 270 toolset->getPathSetting (program) = widgets.input->text();
271
272 if (widgets.wineBox)
273 toolset->getWineSetting (program) = widgets.wineBox->isChecked();
314 } 274 }
315 275
316 // Apply shortcuts 276 // Apply shortcuts
317 for (int i = 0; i < ui->shortcutsList->count(); ++i) 277 for (int i = 0; i < ui->shortcutsList->count(); ++i)
318 { 278 {
322 282
323 Config::Save(); 283 Config::Save();
324 LDDocument::current()->reloadAllSubfiles(); 284 LDDocument::current()->reloadAllSubfiles();
325 LoadLogoStuds(); 285 LoadLogoStuds();
326 286
327 if (g_win) 287 m_window->R()->setBackground();
328 { 288 m_window->doFullRefresh();
329 g_win->R()->setBackground(); 289 m_window->updateDocumentList();
330 g_win->doFullRefresh();
331 g_win->updateDocumentList();
332 }
333 } 290 }
334 291
335 // 292 //
336 // A dialog button was clicked 293 // A dialog button was clicked
337 // 294 //
622 // 579 //
623 // Set the path of an external program 580 // Set the path of an external program
624 // 581 //
625 void ConfigDialog::slot_setExtProgPath() 582 void ConfigDialog::slot_setExtProgPath()
626 { 583 {
627 const LDExtProgInfo* info = null; 584 ExtProgramType program = NumExternalPrograms;
628 585
629 for (const LDExtProgInfo& it : g_LDExtProgInfo) 586 for (int i = 0; i < NumExternalPrograms; ++i)
630 { 587 {
631 if (it.setPathButton == sender()) 588 if (m_externalProgramWidgets[i].setPathButton == sender())
632 { 589 {
633 info = &it; 590 program = (ExtProgramType) i;
634 break; 591 break;
635 } 592 }
636 } 593 }
637 594
638 if (info != null) 595 if (program != NumExternalPrograms)
639 { 596 {
597 ExtProgramToolset* toolset = m_window->externalPrograms();
598 ExternalProgramWidgets& widgets = m_externalProgramWidgets[program];
640 QString filepath = QFileDialog::getOpenFileName (this, 599 QString filepath = QFileDialog::getOpenFileName (this,
641 format ("Path to %1", info->name), *info->path, g_extProgPathFilter); 600 format ("Path to %1", toolset->externalProgramName (program)),
601 widgets.input->text(), g_extProgPathFilter);
642 602
643 if (filepath.isEmpty()) 603 if (filepath.isEmpty())
644 return; 604 return;
645 605
646 info->input->setText (filepath); 606 widgets.input->setText (filepath);
647 } 607 }
648 } 608 }
649 609
650 // 610 //
651 // '...' button pressed for the download path 611 // '...' button pressed for the download path

mercurial