src/ConfigurationDialog.cc

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

mercurial