12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. |
13 * GNU General Public License for more details. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
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/>. |
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. |
17 */ |
21 */ |
18 |
22 |
19 #include <QGridLayout> |
23 #include <QGridLayout> |
20 #include <QFileDialog> |
24 #include <QFileDialog> |
21 #include <QColorDialog> |
25 #include <QColorDialog> |
65 extern_cfg (Bool, prog_intersector_wine); |
68 extern_cfg (Bool, prog_intersector_wine); |
66 extern_cfg (Bool, prog_coverer_wine); |
69 extern_cfg (Bool, prog_coverer_wine); |
67 extern_cfg (Bool, prog_isecalc_wine); |
70 extern_cfg (Bool, prog_isecalc_wine); |
68 extern_cfg (Bool, prog_edger2_wine); |
71 extern_cfg (Bool, prog_edger2_wine); |
69 |
72 |
|
73 #define act(N) extern_cfg (KeySequence, key_##N); |
|
74 #include "actions.h" |
|
75 |
70 const char* g_extProgPathFilter = |
76 const char* g_extProgPathFilter = |
71 #ifdef _WIN32 |
77 #ifdef _WIN32 |
72 "Applications (*.exe)(*.exe);;All files (*.*)(*.*)"; |
78 "Applications (*.exe)(*.exe);;All files (*.*)(*.*)"; |
73 #else |
79 #else |
74 ""; |
80 ""; |
75 #endif |
81 #endif |
76 |
82 |
77 #define act(N) extern_cfg (KeySequence, key_##N); |
|
78 #include "actions.h" |
|
79 |
|
80 // ============================================================================= |
83 // ============================================================================= |
81 // ----------------------------------------------------------------------------- |
84 // ----------------------------------------------------------------------------- |
82 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) : |
85 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) : |
83 QDialog (parent, f) |
86 QDialog (parent, f) |
84 { |
87 { |
85 assert (g_win); |
88 assert (g_win); |
86 ui = new Ui_ConfigUI; |
89 ui = new Ui_ConfigUI; |
87 ui->setupUi (this); |
90 ui->setupUi (this); |
88 |
91 |
89 // Interface tab: |
92 // Interface tab |
90 setButtonBackground (ui->backgroundColorButton, gl_bgcolor); |
93 setButtonBackground (ui->backgroundColorButton, gl_bgcolor); |
91 connect (ui->backgroundColorButton, SIGNAL (clicked()), |
94 connect (ui->backgroundColorButton, SIGNAL (clicked()), |
92 this, SLOT (slot_setGLBackground())); |
95 this, SLOT (slot_setGLBackground())); |
93 |
96 |
94 setButtonBackground (ui->mainColorButton, gl_maincolor.value); |
97 setButtonBackground (ui->mainColorButton, gl_maincolor); |
95 connect (ui->mainColorButton, SIGNAL (clicked()), |
98 connect (ui->mainColorButton, SIGNAL (clicked()), |
96 this, SLOT (slot_setGLForeground())); |
99 this, SLOT (slot_setGLForeground())); |
97 |
100 |
98 ui->mainColorAlpha->setValue (gl_maincolor_alpha * 10.0f); |
101 ui->mainColorAlpha->setValue (gl_maincolor_alpha * 10.0f); |
99 ui->lineThickness->setValue (gl_linethickness); |
102 ui->lineThickness->setValue (gl_linethickness); |
147 ConfigDialog::~ConfigDialog() { |
150 ConfigDialog::~ConfigDialog() { |
148 delete ui; |
151 delete ui; |
149 } |
152 } |
150 |
153 |
151 // ============================================================================= |
154 // ============================================================================= |
|
155 // Adds a shortcut entry to the list of shortcuts. |
152 // ----------------------------------------------------------------------------- |
156 // ----------------------------------------------------------------------------- |
153 void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, ulong& i) { |
157 void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, ulong& i) { |
154 ShortcutListItem* item = new ShortcutListItem; |
158 ShortcutListItem* item = new ShortcutListItem; |
155 item->setIcon (act->icon()); |
159 item->setIcon (act->icon()); |
156 item->setKeyConfig (&cfg); |
160 item->setKeyConfig (&cfg); |
164 |
168 |
165 ui->shortcutsList->insertItem (i++, item); |
169 ui->shortcutsList->insertItem (i++, item); |
166 } |
170 } |
167 |
171 |
168 // ============================================================================= |
172 // ============================================================================= |
|
173 // Initializes the table of grid stuff |
169 // ----------------------------------------------------------------------------- |
174 // ----------------------------------------------------------------------------- |
170 void ConfigDialog::initGrids() { |
175 void ConfigDialog::initGrids() { |
171 QGridLayout* gridlayout = new QGridLayout; |
176 QGridLayout* gridlayout = new QGridLayout; |
172 QLabel* xlabel = new QLabel ("X"), |
177 QLabel* xlabel = new QLabel ("X"), |
173 *ylabel = new QLabel ("Y"), |
178 *ylabel = new QLabel ("Y"), |
229 EXTPROG (Edger2, edger2) |
234 EXTPROG (Edger2, edger2) |
230 #undef EXTPROG |
235 #undef EXTPROG |
231 }; |
236 }; |
232 |
237 |
233 // ============================================================================= |
238 // ============================================================================= |
|
239 // Initializes the stuff in the ext programs tab |
234 // ----------------------------------------------------------------------------- |
240 // ----------------------------------------------------------------------------- |
235 void ConfigDialog::initExtProgs() { |
241 void ConfigDialog::initExtProgs() { |
236 QGridLayout* pathsLayout = new QGridLayout; |
242 QGridLayout* pathsLayout = new QGridLayout; |
237 ulong row = 0; |
243 ulong row = 0; |
238 |
244 |
267 |
273 |
268 ui->extProgs->setLayout (pathsLayout); |
274 ui->extProgs->setLayout (pathsLayout); |
269 } |
275 } |
270 |
276 |
271 // ============================================================================= |
277 // ============================================================================= |
|
278 // Set the settings based on widget data. |
272 // ----------------------------------------------------------------------------- |
279 // ----------------------------------------------------------------------------- |
273 void ConfigDialog::applySettings() { |
280 void ConfigDialog::applySettings() { |
274 // Apply configuration |
281 // Apply configuration |
275 lv_colorize = ui->colorizeObjects->isChecked(); |
282 lv_colorize = ui->colorizeObjects->isChecked(); |
276 gl_colorbfc = ui->colorBFC->isChecked(); |
283 gl_colorbfc = ui->colorBFC->isChecked(); |
277 // edit_schemanticinline = ui->scemanticInlining->isChecked(); |
|
278 gl_blackedges = ui->blackEdges->isChecked(); |
284 gl_blackedges = ui->blackEdges->isChecked(); |
279 gl_maincolor_alpha = ((double) ui->mainColorAlpha->value()) / 10.0f; |
285 gl_maincolor_alpha = ((double) ui->mainColorAlpha->value()) / 10.0f; |
280 gl_linethickness = ui->lineThickness->value(); |
286 gl_linethickness = ui->lineThickness->value(); |
281 gui_implicitfiles = ui->implicitFiles->isChecked(); |
287 gui_implicitfiles = ui->implicitFiles->isChecked(); |
282 net_downloadpath = ui->downloadPath->text(); |
288 net_downloadpath = ui->downloadPath->text(); |
285 gl_logostuds = ui->m_logostuds->isChecked(); |
291 gl_logostuds = ui->m_logostuds->isChecked(); |
286 ld_defaultuser = ui->m_profileUsername->text(); |
292 ld_defaultuser = ui->m_profileUsername->text(); |
287 ld_defaultname = ui->m_profileName->text(); |
293 ld_defaultname = ui->m_profileName->text(); |
288 ld_defaultlicense = ui->m_profileLicense->currentIndex(); |
294 ld_defaultlicense = ui->m_profileLicense->currentIndex(); |
289 |
295 |
|
296 // Ensure '/' postfix to the download path |
290 if (net_downloadpath.value.right (1) != DIRSLASH) |
297 if (net_downloadpath.value.right (1) != DIRSLASH) |
291 net_downloadpath += DIRSLASH; |
298 net_downloadpath += DIRSLASH; |
292 |
299 |
293 // Rebuild the quick color toolbar |
300 // Rebuild the quick color toolbar |
294 g_win->setQuickColors (quickColors); |
301 g_win->setQuickColors (quickColors); |
320 g_win->updateToolBars(); |
327 g_win->updateToolBars(); |
321 g_win->updateFileList(); |
328 g_win->updateFileList(); |
322 } |
329 } |
323 |
330 |
324 // ============================================================================= |
331 // ============================================================================= |
|
332 // A dialog button was clicked |
325 // ----------------------------------------------------------------------------- |
333 // ----------------------------------------------------------------------------- |
326 void ConfigDialog::buttonClicked (QAbstractButton* button) { |
334 void ConfigDialog::buttonClicked (QAbstractButton* button) { |
327 typedef QDialogButtonBox QDDB; |
335 typedef QDialogButtonBox QDDB; |
328 QDialogButtonBox* dbb = ui->buttonBox; |
336 QDialogButtonBox* dbb = ui->buttonBox; |
329 |
337 |
373 } |
382 } |
374 } |
383 } |
375 } |
384 } |
376 |
385 |
377 // ============================================================================= |
386 // ============================================================================= |
|
387 // Quick colors: add or edit button was clicked. |
378 // ----------------------------------------------------------------------------- |
388 // ----------------------------------------------------------------------------- |
379 void ConfigDialog::slot_setColor() { |
389 void ConfigDialog::slot_setColor() { |
380 LDQuickColor* entry = null; |
390 LDQuickColor* entry = null; |
381 QListWidgetItem* item = null; |
391 QListWidgetItem* item = null; |
382 const bool isNew = static_cast<QPushButton*> (sender()) == ui->quickColor_add; |
392 const bool isNew = static_cast<QPushButton*> (sender()) == ui->quickColor_add; |
419 |
429 |
420 updateQuickColorList (entry); |
430 updateQuickColorList (entry); |
421 } |
431 } |
422 |
432 |
423 // ============================================================================= |
433 // ============================================================================= |
|
434 // Remove a quick color |
424 // ----------------------------------------------------------------------------- |
435 // ----------------------------------------------------------------------------- |
425 void ConfigDialog::slot_delColor() { |
436 void ConfigDialog::slot_delColor() { |
426 if (ui->quickColorList->selectedItems().size() == 0) |
437 if (ui->quickColorList->selectedItems().size() == 0) |
427 return; |
438 return; |
428 |
439 |
430 quickColors.erase (getItemRow (item, quickColorItems)); |
441 quickColors.erase (getItemRow (item, quickColorItems)); |
431 updateQuickColorList(); |
442 updateQuickColorList(); |
432 } |
443 } |
433 |
444 |
434 // ============================================================================= |
445 // ============================================================================= |
|
446 // Move a quick color up/down |
435 // ----------------------------------------------------------------------------- |
447 // ----------------------------------------------------------------------------- |
436 void ConfigDialog::slot_moveColor() { |
448 void ConfigDialog::slot_moveColor() { |
437 const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp); |
449 const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp); |
438 |
450 |
439 if (ui->quickColorList->selectedItems().size() == 0) |
451 if (ui->quickColorList->selectedItems().size() == 0) |
452 |
464 |
453 updateQuickColorList (&quickColors[dest]); |
465 updateQuickColorList (&quickColors[dest]); |
454 } |
466 } |
455 |
467 |
456 // ============================================================================= |
468 // ============================================================================= |
|
469 // Add a separator to quick colors |
457 // ----------------------------------------------------------------------------- |
470 // ----------------------------------------------------------------------------- |
458 void ConfigDialog::slot_addColorSeparator() { |
471 void ConfigDialog::slot_addColorSeparator() { |
459 quickColors << LDQuickColor ({null, null, true}); |
472 quickColors << LDQuickColor ({null, null, true}); |
460 updateQuickColorList (&quickColors[quickColors.size() - 1]); |
473 updateQuickColorList (&quickColors[quickColors.size() - 1]); |
461 } |
474 } |
462 |
475 |
463 // ============================================================================= |
476 // ============================================================================= |
|
477 // Clear all quick colors |
464 // ----------------------------------------------------------------------------- |
478 // ----------------------------------------------------------------------------- |
465 void ConfigDialog::slot_clearColors() { |
479 void ConfigDialog::slot_clearColors() { |
466 quickColors.clear(); |
480 quickColors.clear(); |
467 updateQuickColorList(); |
481 updateQuickColorList(); |
468 } |
482 } |
469 |
483 |
470 // ============================================================================= |
484 // ============================================================================= |
|
485 // Pick a color and set the appropriate configuration option. |
471 // ----------------------------------------------------------------------------- |
486 // ----------------------------------------------------------------------------- |
472 void ConfigDialog::pickColor (StringConfig& conf, QPushButton* button) { |
487 void ConfigDialog::pickColor (StringConfig& conf, QPushButton* button) { |
473 QColor col = QColorDialog::getColor (QColor (conf)); |
488 QColor col = QColorDialog::getColor (QColor (conf)); |
474 |
489 |
475 if (col.isValid()) { |
490 if (col.isValid()) { |
492 void ConfigDialog::slot_setGLForeground() { |
507 void ConfigDialog::slot_setGLForeground() { |
493 pickColor (gl_maincolor, ui->mainColorButton); |
508 pickColor (gl_maincolor, ui->mainColorButton); |
494 } |
509 } |
495 |
510 |
496 // ============================================================================= |
511 // ============================================================================= |
|
512 // Sets background color of a given button. |
497 // ----------------------------------------------------------------------------- |
513 // ----------------------------------------------------------------------------- |
498 void ConfigDialog::setButtonBackground (QPushButton* button, str value) { |
514 void ConfigDialog::setButtonBackground (QPushButton* button, str value) { |
499 button->setIcon (getIcon ("colorselect")); |
515 button->setIcon (getIcon ("colorselect")); |
500 button->setAutoFillBackground (true); |
516 button->setAutoFillBackground (true); |
501 button->setStyleSheet (fmt ("background-color: %1", value)); |
517 button->setStyleSheet (fmt ("background-color: %1", value)); |
502 } |
518 } |
503 |
519 |
504 // ============================================================================= |
520 // ============================================================================= |
|
521 // Finds the given list widget item in the list of widget items given. |
505 // ----------------------------------------------------------------------------- |
522 // ----------------------------------------------------------------------------- |
506 int ConfigDialog::getItemRow (QListWidgetItem* item, List<QListWidgetItem*>& haystack) { |
523 int ConfigDialog::getItemRow (QListWidgetItem* item, List<QListWidgetItem*>& haystack) { |
507 int i = 0; |
524 int i = 0; |
508 |
525 |
509 for (QListWidgetItem* it : haystack) { |
526 for (QListWidgetItem* it : haystack) { |
514 } |
531 } |
515 return -1; |
532 return -1; |
516 } |
533 } |
517 |
534 |
518 // ============================================================================= |
535 // ============================================================================= |
|
536 // Which quick color is currently selected? |
519 // ----------------------------------------------------------------------------- |
537 // ----------------------------------------------------------------------------- |
520 QListWidgetItem* ConfigDialog::getSelectedQuickColor() { |
538 QListWidgetItem* ConfigDialog::getSelectedQuickColor() { |
521 if (ui->quickColorList->selectedItems().size() == 0) |
539 if (ui->quickColorList->selectedItems().size() == 0) |
522 return null; |
540 return null; |
523 |
541 |
524 return ui->quickColorList->selectedItems() [0]; |
542 return ui->quickColorList->selectedItems()[0]; |
525 } |
543 } |
526 |
544 |
527 // ============================================================================= |
545 // ============================================================================= |
|
546 // Get the list of shortcuts selected |
528 // ----------------------------------------------------------------------------- |
547 // ----------------------------------------------------------------------------- |
529 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() { |
548 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() { |
530 QList<ShortcutListItem*> out; |
549 QList<ShortcutListItem*> out; |
531 |
550 |
532 for (QListWidgetItem* entry : ui->shortcutsList->selectedItems()) |
551 for (QListWidgetItem* entry : ui->shortcutsList->selectedItems()) |
548 if (KeySequenceDialog::staticDialog (item->keyConfig(), this)) |
568 if (KeySequenceDialog::staticDialog (item->keyConfig(), this)) |
549 setShortcutText (item); |
569 setShortcutText (item); |
550 } |
570 } |
551 |
571 |
552 // ============================================================================= |
572 // ============================================================================= |
|
573 // Reset a shortcut to defaults |
553 // ----------------------------------------------------------------------------- |
574 // ----------------------------------------------------------------------------- |
554 void ConfigDialog::slot_resetShortcut() { |
575 void ConfigDialog::slot_resetShortcut() { |
555 QList<ShortcutListItem*> sel = getShortcutSelection(); |
576 QList<ShortcutListItem*> sel = getShortcutSelection(); |
556 |
577 |
557 for (ShortcutListItem* item : sel) { |
578 for (ShortcutListItem* item : sel) { |
559 setShortcutText (item); |
580 setShortcutText (item); |
560 } |
581 } |
561 } |
582 } |
562 |
583 |
563 // ============================================================================= |
584 // ============================================================================= |
|
585 // Remove the shortcut of an action. |
564 // ----------------------------------------------------------------------------- |
586 // ----------------------------------------------------------------------------- |
565 void ConfigDialog::slot_clearShortcut() { |
587 void ConfigDialog::slot_clearShortcut() { |
566 QList<ShortcutListItem*> sel = getShortcutSelection(); |
588 QList<ShortcutListItem*> sel = getShortcutSelection(); |
567 |
589 |
568 for (ShortcutListItem* item : sel) { |
590 for (ShortcutListItem* item : sel) { |
570 setShortcutText (item); |
592 setShortcutText (item); |
571 } |
593 } |
572 } |
594 } |
573 |
595 |
574 // ============================================================================= |
596 // ============================================================================= |
|
597 // Set the path of an external program |
575 // ----------------------------------------------------------------------------- |
598 // ----------------------------------------------------------------------------- |
576 void ConfigDialog::slot_setExtProgPath() { |
599 void ConfigDialog::slot_setExtProgPath() { |
577 const extProgInfo* info = null; |
600 const extProgInfo* info = null; |
578 |
601 |
579 for (const extProgInfo& it : g_extProgInfo) { |
602 for (const extProgInfo& it : g_extProgInfo) { |
591 |
614 |
592 info->input->setText (fpath); |
615 info->input->setText (fpath); |
593 } |
616 } |
594 |
617 |
595 // ============================================================================= |
618 // ============================================================================= |
|
619 // '...' button pressed for the download path |
596 // ----------------------------------------------------------------------------- |
620 // ----------------------------------------------------------------------------- |
597 void ConfigDialog::slot_findDownloadFolder() { |
621 void ConfigDialog::slot_findDownloadFolder() { |
598 str dpath = QFileDialog::getExistingDirectory(); |
622 str dpath = QFileDialog::getExistingDirectory(); |
599 ui->downloadPath->setText (dpath); |
623 ui->downloadPath->setText (dpath); |
600 } |
624 } |
601 |
625 |
602 // ============================================================================= |
626 // ============================================================================= |
|
627 // Updates the text string for a given shortcut list item |
603 // ----------------------------------------------------------------------------- |
628 // ----------------------------------------------------------------------------- |
604 void ConfigDialog::setShortcutText (ShortcutListItem* item) { |
629 void ConfigDialog::setShortcutText (ShortcutListItem* item) { |
605 QAction* act = item->action(); |
630 QAction* act = item->action(); |
606 str label = act->iconText(); |
631 str label = act->iconText(); |
607 str keybind = item->keyConfig()->value.toString(); |
632 str keybind = item->keyConfig()->value.toString(); |
608 item->setText (fmt ("%1 (%2)", label, keybind)); |
633 item->setText (fmt ("%1 (%2)", label, keybind)); |
609 } |
634 } |
610 |
635 |
611 // ============================================================================= |
636 // ============================================================================= |
|
637 // Gets the configuration string of the quick color toolbar |
612 // ----------------------------------------------------------------------------- |
638 // ----------------------------------------------------------------------------- |
613 str ConfigDialog::quickColorString() { |
639 str ConfigDialog::quickColorString() { |
614 str val; |
640 str val; |
615 |
641 |
616 for (LDQuickColor entry : quickColors) { |
642 for (LDQuickColor entry : quickColors) { |