src/configDialog.cpp

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

mercurial