src/ConfigurationDialog.cc

changeset 629
b75c6cce02e2
child 632
63e6243b880c
equal deleted inserted replaced
628:6b13e4c2e97b 629:b75c6cce02e2
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013, 2014 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * =====================================================================
18 *
19 * configDialog.cpp: Settings dialog and everything related to it.
20 * Actual configuration core is in config.cpp.
21 */
22
23 #include <QGridLayout>
24 #include <QFileDialog>
25 #include <QColorDialog>
26 #include <QBoxLayout>
27 #include <QKeyEvent>
28 #include <QGroupBox>
29 #include <QDoubleSpinBox>
30 #include <QLineEdit>
31 #include <QCheckBox>
32 #include "Main.h"
33 #include "ConfigurationDialog.h"
34 #include "Document.h"
35 #include "Configuration.h"
36 #include "Misc.h"
37 #include "Colors.h"
38 #include "ColorSelector.h"
39 #include "GLRenderer.h"
40 #include "ui_config.h"
41 #include "moc_ConfigurationDialog.cpp"
42
43 extern_cfg (String, gl_bgcolor);
44 extern_cfg (String, gl_maincolor);
45 extern_cfg (Bool, lv_colorize);
46 extern_cfg (Bool, gl_colorbfc);
47 extern_cfg (Float, gl_maincolor_alpha);
48 extern_cfg (Int, gl_linethickness);
49 extern_cfg (String, gui_colortoolbar);
50 extern_cfg (Bool, edit_schemanticinline);
51 extern_cfg (Bool, gl_blackedges);
52 extern_cfg (Bool, gl_aa);
53 extern_cfg (Bool, gui_implicitfiles);
54 extern_cfg (String, net_downloadpath);
55 extern_cfg (Bool, net_guesspaths);
56 extern_cfg (Bool, net_autoclose);
57 extern_cfg (Bool, gl_logostuds);
58 extern_cfg (Bool, gl_linelengths);
59 extern_cfg (String, ld_defaultname);
60 extern_cfg (String, ld_defaultuser);
61 extern_cfg (Int, ld_defaultlicense);
62 extern_cfg (String, gl_selectcolor);
63 extern_cfg (String, prog_ytruder);
64 extern_cfg (String, prog_rectifier);
65 extern_cfg (String, prog_intersector);
66 extern_cfg (String, prog_coverer);
67 extern_cfg (String, prog_isecalc);
68 extern_cfg (String, prog_edger2);
69 extern_cfg (Bool, prog_ytruder_wine);
70 extern_cfg (Bool, prog_rectifier_wine);
71 extern_cfg (Bool, prog_intersector_wine);
72 extern_cfg (Bool, prog_coverer_wine);
73 extern_cfg (Bool, prog_isecalc_wine);
74 extern_cfg (Bool, prog_edger2_wine);
75
76 const char* g_extProgPathFilter =
77 #ifdef _WIN32
78 "Applications (*.exe)(*.exe);;All files (*.*)(*.*)";
79 #else
80 "";
81 #endif
82
83 // =============================================================================
84 // -----------------------------------------------------------------------------
85 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) :
86 QDialog (parent, f)
87 {
88 assert (g_win != null);
89 ui = new Ui_ConfigUI;
90 ui->setupUi (this);
91
92 // Interface tab
93 setButtonBackground (ui->backgroundColorButton, gl_bgcolor);
94 connect (ui->backgroundColorButton, SIGNAL (clicked()),
95 this, SLOT (slot_setGLBackground()));
96
97 setButtonBackground (ui->mainColorButton, gl_maincolor);
98 connect (ui->mainColorButton, SIGNAL (clicked()),
99 this, SLOT (slot_setGLForeground()));
100
101 setButtonBackground (ui->selColorButton, gl_selectcolor);
102 connect (ui->selColorButton, SIGNAL (clicked()),
103 this, SLOT (slot_setGLSelectColor()));
104
105 ui->mainColorAlpha->setValue (gl_maincolor_alpha * 10.0f);
106 ui->lineThickness->setValue (gl_linethickness);
107 ui->colorizeObjects->setChecked (lv_colorize);
108 ui->colorBFC->setChecked (gl_colorbfc);
109 ui->blackEdges->setChecked (gl_blackedges);
110 ui->m_aa->setChecked (gl_aa);
111 ui->implicitFiles->setChecked (gui_implicitfiles);
112 ui->m_logostuds->setChecked (gl_logostuds);
113 ui->linelengths->setChecked (gl_linelengths);
114
115 int i = 0;
116
117 for (QAction* act : g_win->findChildren<QAction*>())
118 {
119 KeySequenceConfig* cfg = g_win->shortcutForAction (act);
120
121 if (cfg)
122 addShortcut (*cfg, act, i);
123 }
124
125 ui->shortcutsList->setSortingEnabled (true);
126 ui->shortcutsList->sortItems();
127
128 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut()));
129 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut()));
130 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut()));
131
132 quickColors = quickColorsFromConfig();
133 updateQuickColorList();
134
135 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor()));
136 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor()));
137 connect (ui->quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor()));
138 connect (ui->quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator()));
139 connect (ui->quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor()));
140 connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor()));
141 connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors()));
142
143 ui->downloadPath->setText (net_downloadpath);
144 ui->guessNetPaths->setChecked (net_guesspaths);
145 ui->autoCloseNetPrompt->setChecked (net_autoclose);
146 connect (ui->findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder()));
147
148 ui->m_profileName->setText (ld_defaultname);
149 ui->m_profileUsername->setText (ld_defaultuser);
150 ui->m_profileLicense->setCurrentIndex (ld_defaultlicense);
151
152 initGrids();
153 initExtProgs();
154 selectPage (deftab);
155
156 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)),
157 this, SLOT (buttonClicked (QAbstractButton*)));
158
159 connect (ui->m_pages, SIGNAL (currentChanged (int)),
160 this, SLOT (selectPage (int)));
161
162 connect (ui->m_pagelist, SIGNAL (currentRowChanged (int)),
163 this, SLOT (selectPage (int)));
164 }
165
166 // =============================================================================
167 // -----------------------------------------------------------------------------
168 ConfigDialog::~ConfigDialog()
169 {
170 delete ui;
171 }
172
173 // =============================================================================
174 // -----------------------------------------------------------------------------
175 void ConfigDialog::selectPage (int row)
176 {
177 ui->m_pagelist->setCurrentRow (row);
178 ui->m_pages->setCurrentIndex (row);
179 }
180
181 // =============================================================================
182 // Adds a shortcut entry to the list of shortcuts.
183 // -----------------------------------------------------------------------------
184 void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, int& i)
185 {
186 ShortcutListItem* item = new ShortcutListItem;
187 item->setIcon (act->icon());
188 item->setKeyConfig (&cfg);
189 item->setAction (act);
190 setShortcutText (item);
191
192 // If the action doesn't have a valid icon, use an empty one
193 // so that the list is kept aligned.
194 if (act->icon().isNull())
195 item->setIcon (getIcon ("empty"));
196
197 ui->shortcutsList->insertItem (i++, item);
198 }
199
200 // =============================================================================
201 // Initializes the table of grid stuff
202 // -----------------------------------------------------------------------------
203 void ConfigDialog::initGrids()
204 {
205 QGridLayout* gridlayout = new QGridLayout;
206 QLabel* xlabel = new QLabel ("X"),
207 *ylabel = new QLabel ("Y"),
208 *zlabel = new QLabel ("Z"),
209 *anglabel = new QLabel ("Angle");
210 int i = 1;
211
212 for (QLabel* label : initlist<QLabel*> ({xlabel, ylabel, zlabel, anglabel}))
213 {
214 label->setAlignment (Qt::AlignCenter);
215 gridlayout->addWidget (label, 0, i++);
216 }
217
218 for (int i = 0; i < g_NumGrids; ++i)
219 {
220 // Icon
221 lb_gridIcons[i] = new QLabel;
222 lb_gridIcons[i]->setPixmap (getIcon (fmt ("grid-%1", QString (g_GridInfo[i].name).toLower())));
223
224 // Text label
225 lb_gridLabels[i] = new QLabel (fmt ("%1:", g_GridInfo[i].name));
226
227 QHBoxLayout* labellayout = new QHBoxLayout;
228 labellayout->addWidget (lb_gridIcons[i]);
229 labellayout->addWidget (lb_gridLabels[i]);
230 gridlayout->addLayout (labellayout, i + 1, 0);
231
232 // Add the widgets
233 for (int j = 0; j < 4; ++j)
234 {
235 dsb_gridData[i][j] = new QDoubleSpinBox;
236
237 // Set the maximum angle
238 if (j == 3)
239 dsb_gridData[i][j]->setMaximum (360);
240
241 dsb_gridData[i][j]->setValue (*g_GridInfo[i].confs[j]);
242 gridlayout->addWidget (dsb_gridData[i][j], i + 1, j + 1);
243 }
244 }
245
246 ui->grids->setLayout (gridlayout);
247 }
248
249 // =============================================================================
250 // -----------------------------------------------------------------------------
251 static struct LDExtProgInfo
252 {
253 const QString name,
254 iconname;
255 QString* const path;
256 QLineEdit* input;
257 QPushButton* setPathButton;
258 #ifndef _WIN32
259 bool* const wine;
260 QCheckBox* wineBox;
261 #endif // _WIN32
262 } g_LDExtProgInfo[] =
263 {
264 #ifndef _WIN32
265 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null, &prog_##LOWNAME##_wine, null },
266 #else
267 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null },
268 #endif
269 EXTPROG (Ytruder, ytruder)
270 EXTPROG (Rectifier, rectifier)
271 EXTPROG (Intersector, intersector)
272 EXTPROG (Isecalc, isecalc)
273 EXTPROG (Coverer, coverer)
274 EXTPROG (Edger2, edger2)
275 #undef EXTPROG
276 };
277
278 // =============================================================================
279 // Initializes the stuff in the ext programs tab
280 // -----------------------------------------------------------------------------
281 void ConfigDialog::initExtProgs()
282 {
283 QGridLayout* pathsLayout = new QGridLayout;
284 int row = 0;
285
286 for (LDExtProgInfo& info : g_LDExtProgInfo)
287 {
288 QLabel* icon = new QLabel,
289 *progLabel = new QLabel (info.name);
290 QLineEdit* input = new QLineEdit;
291 QPushButton* setPathButton = new QPushButton;
292
293 icon->setPixmap (getIcon (info.iconname));
294 input->setText (*info.path);
295 setPathButton->setIcon (getIcon ("folder"));
296 info.input = input;
297 info.setPathButton = setPathButton;
298
299 connect (setPathButton, SIGNAL (clicked()), this, SLOT (slot_setExtProgPath()));
300
301 pathsLayout->addWidget (icon, row, 0);
302 pathsLayout->addWidget (progLabel, row, 1);
303 pathsLayout->addWidget (input, row, 2);
304 pathsLayout->addWidget (setPathButton, row, 3);
305
306 #ifndef _WIN32
307 QCheckBox* wineBox = new QCheckBox ("Wine");
308 wineBox->setChecked (*info.wine);
309 info.wineBox = wineBox;
310 pathsLayout->addWidget (wineBox, row, 4);
311 #endif
312
313 ++row;
314 }
315
316 ui->extProgs->setLayout (pathsLayout);
317 }
318
319 // =============================================================================
320 // Set the settings based on widget data.
321 // -----------------------------------------------------------------------------
322 void ConfigDialog::applySettings()
323 {
324 // Apply configuration
325 lv_colorize = ui->colorizeObjects->isChecked();
326 gl_colorbfc = ui->colorBFC->isChecked();
327 gl_blackedges = ui->blackEdges->isChecked();
328 gl_maincolor_alpha = ( (double) ui->mainColorAlpha->value()) / 10.0f;
329 gl_linethickness = ui->lineThickness->value();
330 gui_implicitfiles = ui->implicitFiles->isChecked();
331 net_downloadpath = ui->downloadPath->text();
332 net_guesspaths = ui->guessNetPaths->isChecked();
333 net_autoclose = ui->autoCloseNetPrompt->isChecked();
334 gl_logostuds = ui->m_logostuds->isChecked();
335 gl_linelengths = ui->linelengths->isChecked();
336 ld_defaultuser = ui->m_profileUsername->text();
337 ld_defaultname = ui->m_profileName->text();
338 ld_defaultlicense = ui->m_profileLicense->currentIndex();
339 gl_aa = ui->m_aa->isChecked();
340
341 // Rebuild the quick color toolbar
342 g_win->setQuickColors (quickColors);
343 gui_colortoolbar = quickColorString();
344
345 // Set the grid settings
346 for (int i = 0; i < g_NumGrids; ++i)
347 for (int j = 0; j < 4; ++j)
348 *g_GridInfo[i].confs[j] = dsb_gridData[i][j]->value();
349
350 // Apply key shortcuts
351 g_win->updateActionShortcuts();
352
353 // Ext program settings
354 for (const LDExtProgInfo& info : g_LDExtProgInfo)
355 {
356 *info.path = info.input->text();
357
358 #ifndef _WIN32
359 *info.wine = info.wineBox->isChecked();
360 #endif // _WIN32
361 }
362
363 Config::save();
364 reloadAllSubfiles();
365 loadLogoedStuds();
366 g_win->R()->setBackground();
367 g_win->doFullRefresh();
368 g_win->updateToolBars();
369 g_win->updateDocumentList();
370 }
371
372 // =============================================================================
373 // A dialog button was clicked
374 // -----------------------------------------------------------------------------
375 void ConfigDialog::buttonClicked (QAbstractButton* button)
376 {
377 typedef QDialogButtonBox QDDB;
378 QDialogButtonBox* dbb = ui->buttonBox;
379
380 if (button == dbb->button (QDDB::Ok))
381 {
382 applySettings();
383 accept();
384 } elif (button == dbb->button (QDDB::Apply))
385 {
386 applySettings();
387 } elif (button == dbb->button (QDDB::Cancel))
388 {
389 reject();
390 }
391 }
392
393 // =============================================================================
394 // Update the list of color toolbar items in the quick color tab.
395 // -----------------------------------------------------------------------------
396 void ConfigDialog::updateQuickColorList (LDQuickColor* sel)
397 {
398 for (QListWidgetItem * item : quickColorItems)
399 delete item;
400
401 quickColorItems.clear();
402
403 // Init table items
404 for (LDQuickColor& entry : quickColors)
405 {
406 QListWidgetItem* item = new QListWidgetItem;
407
408 if (entry.isSeparator())
409 {
410 item->setText ("--------");
411 item->setIcon (getIcon ("empty"));
412 }
413 else
414 {
415 LDColor* col = entry.getColor();
416
417 if (col == null)
418 {
419 item->setText ("[[unknown color]]");
420 item->setIcon (getIcon ("error"));
421 }
422 else
423 {
424 item->setText (col->name);
425 item->setIcon (makeColorIcon (col, 16));
426 }
427 }
428
429 ui->quickColorList->addItem (item);
430 quickColorItems << item;
431
432 if (sel && &entry == sel)
433 {
434 ui->quickColorList->setCurrentItem (item);
435 ui->quickColorList->scrollToItem (item);
436 }
437 }
438 }
439
440 // =============================================================================
441 // Quick colors: add or edit button was clicked.
442 // -----------------------------------------------------------------------------
443 void ConfigDialog::slot_setColor()
444 {
445 LDQuickColor* entry = null;
446 QListWidgetItem* item = null;
447 const bool isNew = static_cast<QPushButton*> (sender()) == ui->quickColor_add;
448
449 if (isNew == false)
450 {
451 item = getSelectedQuickColor();
452
453 if (!item)
454 return;
455
456 int i = getItemRow (item, quickColorItems);
457 entry = &quickColors[i];
458
459 if (entry->isSeparator() == true)
460 return; // don't color separators
461 }
462
463 int defval = entry ? entry->getColor()->index : -1;
464 int val;
465
466 if (ColorSelector::selectColor (val, defval, this) == false)
467 return;
468
469 if (entry)
470 entry->setColor (getColor (val));
471 else
472 {
473 LDQuickColor entry (getColor (val), null);
474
475 item = getSelectedQuickColor();
476 int idx = (item) ? getItemRow (item, quickColorItems) + 1 : quickColorItems.size();
477
478 quickColors.insert (idx, entry);
479 entry = quickColors[idx];
480 }
481
482 updateQuickColorList (entry);
483 }
484
485 // =============================================================================
486 // Remove a quick color
487 // -----------------------------------------------------------------------------
488 void ConfigDialog::slot_delColor()
489 {
490 if (ui->quickColorList->selectedItems().isEmpty())
491 return;
492
493 QListWidgetItem* item = ui->quickColorList->selectedItems() [0];
494 quickColors.removeAt (getItemRow (item, quickColorItems));
495 updateQuickColorList();
496 }
497
498 // =============================================================================
499 // Move a quick color up/down
500 // -----------------------------------------------------------------------------
501 void ConfigDialog::slot_moveColor()
502 {
503 const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp);
504
505 if (ui->quickColorList->selectedItems().isEmpty())
506 return;
507
508 QListWidgetItem* item = ui->quickColorList->selectedItems() [0];
509 int idx = getItemRow (item, quickColorItems);
510 int dest = up ? (idx - 1) : (idx + 1);
511
512 if (dest < 0 || dest >= quickColorItems.size())
513 return; // destination out of bounds
514
515 LDQuickColor tmp = quickColors[dest];
516 quickColors[dest] = quickColors[idx];
517 quickColors[idx] = tmp;
518
519 updateQuickColorList (&quickColors[dest]);
520 }
521
522 // =============================================================================
523 // Add a separator to quick colors
524 // -----------------------------------------------------------------------------
525 void ConfigDialog::slot_addColorSeparator()
526 {
527 quickColors << LDQuickColor::getSeparator();
528 updateQuickColorList (&quickColors[quickColors.size() - 1]);
529 }
530
531 // =============================================================================
532 // Clear all quick colors
533 // -----------------------------------------------------------------------------
534 void ConfigDialog::slot_clearColors()
535 {
536 quickColors.clear();
537 updateQuickColorList();
538 }
539
540 // =============================================================================
541 // Pick a color and set the appropriate configuration option.
542 // -----------------------------------------------------------------------------
543 void ConfigDialog::pickColor (QString& conf, QPushButton* button)
544 {
545 QColor col = QColorDialog::getColor (QColor (conf));
546
547 if (col.isValid())
548 {
549 int r = col.red(),
550 g = col.green(),
551 b = col.blue();
552
553 QString colname;
554 colname.sprintf ("#%.2X%.2X%.2X", r, g, b);
555 conf = colname;
556 setButtonBackground (button, colname);
557 }
558 }
559
560 // =============================================================================
561 // -----------------------------------------------------------------------------
562 void ConfigDialog::slot_setGLBackground()
563 {
564 pickColor (gl_bgcolor, ui->backgroundColorButton);
565 }
566
567 // =============================================================================
568 // -----------------------------------------------------------------------------
569 void ConfigDialog::slot_setGLForeground()
570 {
571 pickColor (gl_maincolor, ui->mainColorButton);
572 }
573
574 // =============================================================================
575 // -----------------------------------------------------------------------------
576 void ConfigDialog::slot_setGLSelectColor()
577 {
578 pickColor (gl_selectcolor, ui->selColorButton);
579 }
580
581 // =============================================================================
582 // Sets background color of a given button.
583 // -----------------------------------------------------------------------------
584 void ConfigDialog::setButtonBackground (QPushButton* button, QString value)
585 {
586 button->setIcon (getIcon ("colorselect"));
587 button->setAutoFillBackground (true);
588 button->setStyleSheet (fmt ("background-color: %1", value));
589 }
590
591 // =============================================================================
592 // Finds the given list widget item in the list of widget items given.
593 // -----------------------------------------------------------------------------
594 int ConfigDialog::getItemRow (QListWidgetItem* item, QList<QListWidgetItem*>& haystack)
595 {
596 int i = 0;
597
598 for (QListWidgetItem* it : haystack)
599 {
600 if (it == item)
601 return i;
602
603 ++i;
604 }
605
606 return -1;
607 }
608
609 // =============================================================================
610 // Which quick color is currently selected?
611 // -----------------------------------------------------------------------------
612 QListWidgetItem* ConfigDialog::getSelectedQuickColor()
613 {
614 if (ui->quickColorList->selectedItems().isEmpty())
615 return null;
616
617 return ui->quickColorList->selectedItems() [0];
618 }
619
620 // =============================================================================
621 // Get the list of shortcuts selected
622 // -----------------------------------------------------------------------------
623 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection()
624 {
625 QList<ShortcutListItem*> out;
626
627 for (QListWidgetItem* entry : ui->shortcutsList->selectedItems())
628 out << static_cast<ShortcutListItem*> (entry);
629
630 return out;
631 }
632
633 // =============================================================================
634 // Edit the shortcut of a given action.
635 // -----------------------------------------------------------------------------
636 void ConfigDialog::slot_setShortcut()
637 {
638 QList<ShortcutListItem*> sel = getShortcutSelection();
639
640 if (sel.size() < 1)
641 return;
642
643 ShortcutListItem* item = sel[0];
644
645 if (KeySequenceDialog::staticDialog (item->getKeyConfig(), this))
646 setShortcutText (item);
647 }
648
649 // =============================================================================
650 // Reset a shortcut to defaults
651 // -----------------------------------------------------------------------------
652 void ConfigDialog::slot_resetShortcut()
653 {
654 QList<ShortcutListItem*> sel = getShortcutSelection();
655
656 for (ShortcutListItem* item : sel)
657 {
658 item->getKeyConfig()->reset();
659 setShortcutText (item);
660 }
661 }
662
663 // =============================================================================
664 // Remove the shortcut of an action.
665 // -----------------------------------------------------------------------------
666 void ConfigDialog::slot_clearShortcut()
667 {
668 QList<ShortcutListItem*> sel = getShortcutSelection();
669
670 for (ShortcutListItem* item : sel)
671 {
672 item->getKeyConfig()->setValue (QKeySequence());
673 setShortcutText (item);
674 }
675 }
676
677 // =============================================================================
678 // Set the path of an external program
679 // -----------------------------------------------------------------------------
680 void ConfigDialog::slot_setExtProgPath()
681 {
682 const LDExtProgInfo* info = null;
683
684 for (const LDExtProgInfo& it : g_LDExtProgInfo)
685 {
686 if (it.setPathButton == sender())
687 {
688 info = &it;
689 break;
690 }
691 }
692
693 assert (info != null);
694 QString fpath = QFileDialog::getOpenFileName (this, fmt ("Path to %1", info->name), *info->path, g_extProgPathFilter);
695
696 if (fpath.isEmpty())
697 return;
698
699 info->input->setText (fpath);
700 }
701
702 // =============================================================================
703 // '...' button pressed for the download path
704 // -----------------------------------------------------------------------------
705 void ConfigDialog::slot_findDownloadFolder()
706 {
707 QString dpath = QFileDialog::getExistingDirectory();
708 ui->downloadPath->setText (dpath);
709 }
710
711 // =============================================================================
712 // Updates the text string for a given shortcut list item
713 // -----------------------------------------------------------------------------
714 void ConfigDialog::setShortcutText (ShortcutListItem* item)
715 {
716 QAction* act = item->getAction();
717 QString label = act->iconText();
718 QString keybind = item->getKeyConfig()->getValue().toString();
719 item->setText (fmt ("%1 (%2)", label, keybind));
720 }
721
722 // =============================================================================
723 // Gets the configuration string of the quick color toolbar
724 // -----------------------------------------------------------------------------
725 QString ConfigDialog::quickColorString()
726 {
727 QString val;
728
729 for (const LDQuickColor& entry : quickColors)
730 {
731 if (val.length() > 0)
732 val += ':';
733
734 if (entry.isSeparator())
735 val += '|';
736 else
737 val += fmt ("%1", entry.getColor()->index);
738 }
739
740 return val;
741 }
742
743 // ===============================================================================================
744 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
745 // ===============================================================================================
746 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
747 // ===============================================================================================
748 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
749 // ===============================================================================================
750 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) :
751 QDialog (parent, f), seq (seq)
752 {
753 lb_output = new QLabel;
754 IMPLEMENT_DIALOG_BUTTONS
755
756 setWhatsThis (tr ("Into this dialog you can input a key sequence for use as a "
757 "shortcut in LDForge. Use OK to confirm the new shortcut and Cancel to "
758 "dismiss."));
759
760 QVBoxLayout* layout = new QVBoxLayout;
761 layout->addWidget (lb_output);
762 layout->addWidget (bbx_buttons);
763 setLayout (layout);
764
765 updateOutput();
766 }
767
768 // =============================================================================
769 // -----------------------------------------------------------------------------
770 bool KeySequenceDialog::staticDialog (KeySequenceConfig* cfg, QWidget* parent)
771 {
772 KeySequenceDialog dlg (cfg->getValue(), parent);
773
774 if (dlg.exec() == false)
775 return false;
776
777 cfg->setValue (dlg.seq);
778 return true;
779 }
780
781 // =============================================================================
782 // -----------------------------------------------------------------------------
783 void KeySequenceDialog::updateOutput()
784 {
785 QString shortcut = seq.toString();
786
787 if (seq == QKeySequence())
788 shortcut = "&lt;empty&gt;";
789
790 QString text = fmt ("<center><b>%1</b></center>", shortcut);
791 lb_output->setText (text);
792 }
793
794 // =============================================================================
795 // -----------------------------------------------------------------------------
796 void KeySequenceDialog::keyPressEvent (QKeyEvent* ev)
797 {
798 seq = ev->key() + ev->modifiers();
799 updateOutput();
800 }

mercurial