zz_configDialog.cpp

changeset 172
a65547b84ef8
parent 165
88a03c1a52d9
child 173
2368e3c23ef3
equal deleted inserted replaced
171:36165e58e457 172:a65547b84ef8
100 lb_viewBg = new QLabel ("Background color:"); 100 lb_viewBg = new QLabel ("Background color:");
101 pb_viewBg = new QPushButton; 101 pb_viewBg = new QPushButton;
102 setButtonBackground (pb_viewBg, gl_bgcolor.value); 102 setButtonBackground (pb_viewBg, gl_bgcolor.value);
103 connect (pb_viewBg, SIGNAL (clicked ()), 103 connect (pb_viewBg, SIGNAL (clicked ()),
104 this, SLOT (slot_setGLBackground ())); 104 this, SLOT (slot_setGLBackground ()));
105 pb_viewBg->setWhatsThis ("This is the background color for the viewport.");
105 106
106 lb_viewFg = new QLabel ("Foreground color:"); 107 lb_viewFg = new QLabel ("Foreground color:");
107 pb_viewFg = new QPushButton; 108 pb_viewFg = new QPushButton;
108 setButtonBackground (pb_viewFg, gl_maincolor.value); 109 setButtonBackground (pb_viewFg, gl_maincolor.value);
109 connect (pb_viewFg, SIGNAL (clicked ()), 110 connect (pb_viewFg, SIGNAL (clicked ()),
110 this, SLOT (slot_setGLForeground ())); 111 this, SLOT (slot_setGLForeground ()));
112 pb_viewFg->setWhatsThis ("This color is used for the main color.");
111 113
112 // ========================================================================= 114 // =========================================================================
113 // Alpha and line thickness sliders 115 // Alpha and line thickness sliders
114 lb_viewFgAlpha = new QLabel ("Alpha:"); 116 lb_viewFgAlpha = new QLabel ("Alpha:");
115 makeSlider (sl_viewFgAlpha, 1, 10, (gl_maincolor_alpha * 10.0f)); 117 makeSlider (sl_viewFgAlpha, 1, 10, (gl_maincolor_alpha * 10.0f));
118 sl_viewFgAlpha->setWhatsThis ("Opacity of main color in the viewport.");
116 119
117 lb_lineThickness = new QLabel ("Line thickness:"); 120 lb_lineThickness = new QLabel ("Line thickness:");
118 makeSlider (sl_lineThickness, 1, 8, gl_linethickness); 121 makeSlider (sl_lineThickness, 1, 8, gl_linethickness);
122 sl_lineThickness->setWhatsThis ("How thick lines should be drawn in the viewport.");
119 123
120 // ========================================================================= 124 // =========================================================================
121 // Tool bar icon size slider 125 // Tool bar icon size slider
122 lb_iconSize = new QLabel ("Toolbar icon size:"); 126 lb_iconSize = new QLabel ("Toolbar icon size:");
123 makeSlider (sl_iconSize, 1, 5, (gui_toolbar_iconsize - 12) / 4); 127 makeSlider (sl_iconSize, 1, 5, (gui_toolbar_iconsize - 12) / 4);
124 128
125 // ========================================================================= 129 // =========================================================================
126 // List view colorizer and BFC red/green view checkboxes 130 // List view colorizer and BFC red/green view checkboxes
127 cb_colorize = new QCheckBox ("Colorize polygons in list view"); 131 cb_colorize = new QCheckBox ("Colorize polygons in object list");
128 INIT_CHECKBOX (cb_colorize, lv_colorize) 132 cb_colorize->setChecked (lv_colorize);
133 cb_colorize->setWhatsThis ("Makes colored objects (non-16 and 24) appear "
134 "colored in the object list. A red polygon will have its description "
135 "written in red text.");
129 136
130 cb_colorBFC = new QCheckBox ("Red/green BFC view"); 137 cb_colorBFC = new QCheckBox ("Red/green BFC view");
131 INIT_CHECKBOX (cb_colorBFC, gl_colorbfc) 138 cb_colorBFC->setChecked (gl_colorbfc);
139 cb_colorBFC->setWhatsThis ("Polygons' front sides become green and back "
140 "sides red. Not implemented yet.");
132 141
133 cb_selFlash = new QCheckBox ("Selection flash"); 142 cb_selFlash = new QCheckBox ("Selection flash");
134 INIT_CHECKBOX (cb_selFlash, gl_selflash) 143 cb_selFlash->setChecked (gl_selflash);
144 cb_colorBFC->setWhatsThis ("A pulse effect for clearer selection view.");
135 145
136 cb_blackEdges = new QCheckBox ("Black edges"); 146 cb_blackEdges = new QCheckBox ("Black edges");
137 cb_blackEdges->setWhatsThis ("If this is set, all edgelines appear black. If this is " 147 cb_blackEdges->setWhatsThis ("Makes all edgelines appear black. If this is "
138 "not set, edge lines take their color as defined in LDConfig.ldr"); 148 "not set, edge lines take their color as defined in LDConfig.ldr");
139 INIT_CHECKBOX (cb_blackEdges, gl_blackedges) 149 cb_blackEdges->setChecked (gl_blackedges);
140 150
141 cb_schemanticInline = new QCheckBox ("Only insert schemantic objects from a file"); 151 cb_schemanticInline = new QCheckBox ("Schemantic insertion only");
142 INIT_CHECKBOX (cb_schemanticInline, edit_schemanticinline) 152 cb_schemanticInline->setChecked (edit_schemanticinline);
153 cb_colorBFC->setWhatsThis ("When inserting objects through inlining, file "
154 "inserting or through external programs, all non-schemantics (those without "
155 "actual meaning in the part file like comments and such) are filtered out.");
156
157 cb_schemanticInline->setEnabled (false);
158 cb_colorBFC->setEnabled (false);
143 159
144 QGridLayout* layout = new QGridLayout; 160 QGridLayout* layout = new QGridLayout;
145 layout->addWidget (lb_LDrawPath, 0, 0); 161 layout->addWidget (lb_LDrawPath, 0, 0);
146 layout->addLayout (qLDrawPathLayout, 0, 1, 1, 3); 162 layout->addLayout (qLDrawPathLayout, 0, 1, 1, 3);
147 163
185 "and reset to restore the shortcut to its default value.\n" 201 "and reset to restore the shortcut to its default value.\n"
186 "\tShortcut changes apply immediately after closing this dialog." ); 202 "\tShortcut changes apply immediately after closing this dialog." );
187 203
188 // Init table items 204 // Init table items
189 ulong i = 0; 205 ulong i = 0;
190 for (actionmeta meta : g_ActionMeta) { 206 for (actionmeta& info : g_ActionMeta) {
191 QAction* const qAct = *meta.qAct; 207 QAction* const act = *info.qAct;
192 208
193 QListWidgetItem* qItem = new QListWidgetItem; 209 ShortcutListItem* item = new ShortcutListItem;
194 setShortcutText (qItem, meta); 210 setShortcutText (item, info);
195 qItem->setIcon (qAct->icon ()); 211 item->setIcon (act->icon ());
196 212 item->setActionInfo (&info);
197 shortcutItems.push_back (qItem); 213
198 lw_shortcutList->insertItem (i, qItem); 214 // If the action doesn't have a valid icon, use an empty one
199 ++i; 215 // so that the list is kept aligned.
200 } 216 if (act->icon ().isNull ())
217 item->setIcon (getIcon ("empty"));
218
219 lw_shortcutList->insertItem (i++, item);
220 }
221
222 lw_shortcutList->setSortingEnabled (true);
223 lw_shortcutList->sortItems ();
201 224
202 pb_setShortcut = new QPushButton ("Set"); 225 pb_setShortcut = new QPushButton ("Set");
203 pb_resetShortcut = new QPushButton ("Reset"); 226 pb_resetShortcut = new QPushButton ("Reset");
204 pb_clearShortcut = new QPushButton ("Clear"); 227 pb_clearShortcut = new QPushButton ("Clear");
205 228
452 } 475 }
453 476
454 // ============================================================================= 477 // =============================================================================
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
456 // ============================================================================= 479 // =============================================================================
457 void ConfigDialog::makeSlider (QSlider*& qSlider, short int dMin, short int dMax, 480 void ConfigDialog::makeSlider (QSlider*& slider, short min, short max, short defval) {
458 short dDefault) 481 slider = new QSlider (Qt::Horizontal);
459 { 482 slider->setRange (min, max);
460 qSlider = new QSlider (Qt::Horizontal); 483 slider->setSliderPosition (defval);
461 qSlider->setRange (dMin, dMax); 484 slider->setTickPosition (QSlider::TicksAbove);
462 qSlider->setSliderPosition (dDefault); 485 slider->setTickInterval (1);
463 qSlider->setTickPosition (QSlider::TicksAbove);
464 qSlider->setTickInterval (1);
465 } 486 }
466 487
467 // ============================================================================= 488 // =============================================================================
468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 489 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
469 // ============================================================================= 490 // =============================================================================
473 494
474 // ============================================================================= 495 // =============================================================================
475 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 496 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
476 // ============================================================================= 497 // =============================================================================
477 void ConfigDialog::slot_findLDrawPath () { 498 void ConfigDialog::slot_findLDrawPath () {
478 str zDir = QFileDialog::getExistingDirectory (this, "Choose LDraw directory", 499 str dir = QFileDialog::getExistingDirectory (this, "Choose LDraw directory",
479 le_LDrawPath->text()); 500 le_LDrawPath->text());
480 501
481 if (~zDir) 502 if (~dir)
482 le_LDrawPath->setText (zDir.chars()); 503 le_LDrawPath->setText (dir.chars());
483 } 504 }
484 505
485 // ============================================================================= 506 // =============================================================================
486 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
487 // ============================================================================= 508 // =============================================================================
537 558
538 return lw_quickColors->selectedItems ()[0]; 559 return lw_quickColors->selectedItems ()[0];
539 } 560 }
540 561
541 // ============================================================================= 562 // =============================================================================
563 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection () {
564 QList<ShortcutListItem*> out;
565
566 for (QListWidgetItem* entry : lw_shortcutList->selectedItems ())
567 out << static_cast<ShortcutListItem*> (entry);
568
569 return out;
570 }
571
572 // =============================================================================
542 void ConfigDialog::slot_setShortcut () { 573 void ConfigDialog::slot_setShortcut () {
543 QList<QListWidgetItem*> qaSel = lw_shortcutList->selectedItems (); 574 QList<ShortcutListItem*> sel = getShortcutSelection ();
544 575
545 if (qaSel.size() < 1) 576 if (sel.size() < 1)
546 return; 577 return;
547 578
548 QListWidgetItem* qItem = qaSel[0]; 579 ShortcutListItem* item = sel[0];
549 580 if (KeySequenceDialog::staticDialog (*(item->getActionInfo ()), this))
550 // Find the row this object is on. 581 setShortcutText (item, *(item->getActionInfo ()));
551 long idx = getItemRow (qItem, shortcutItems);
552
553 if (KeySequenceDialog::staticDialog (g_ActionMeta[idx], this))
554 setShortcutText (qItem, g_ActionMeta[idx]);
555 } 582 }
556 583
557 // ============================================================================= 584 // =============================================================================
558 void ConfigDialog::slot_resetShortcut () { 585 void ConfigDialog::slot_resetShortcut () {
559 QList<QListWidgetItem*> qaSel = lw_shortcutList->selectedItems (); 586 QList<ShortcutListItem*> sel = getShortcutSelection ();
560 587
561 for (QListWidgetItem* qItem : qaSel) { 588 for (ShortcutListItem* item : sel) {
562 long idx = getItemRow (qItem, shortcutItems); 589 actionmeta* info = item->getActionInfo ();
563 590 keyseqconfig* conf = info->conf;
564 actionmeta meta = g_ActionMeta[idx];
565 keyseqconfig* conf = g_ActionMeta[idx].conf;
566 591
567 conf->reset (); 592 conf->reset ();
568 (*meta.qAct)->setShortcut (*conf); 593 (*info->qAct)->setShortcut (*conf);
569 594
570 setShortcutText (qItem, meta); 595 setShortcutText (item, *info);
571 } 596 }
572 } 597 }
573 598
574 // ============================================================================= 599 // =============================================================================
575 void ConfigDialog::slot_clearShortcut () { 600 void ConfigDialog::slot_clearShortcut () {
576 QList<QListWidgetItem*> qaSel = lw_shortcutList->selectedItems (); 601 QList<ShortcutListItem*> sel = getShortcutSelection ();
577 QKeySequence qDummySeq; 602 QKeySequence dummy;
578 603
579 for (QListWidgetItem* qItem : qaSel) { 604 for (ShortcutListItem* item : sel) {
580 long idx = getItemRow (qItem, shortcutItems); 605 actionmeta* info = item->getActionInfo ();
581 606 keyseqconfig* conf = info->conf;
582 actionmeta meta = g_ActionMeta[idx]; 607 conf->value = dummy;
583 keyseqconfig* conf = g_ActionMeta[idx].conf; 608
584 conf->value = qDummySeq; 609 (*info->qAct)->setShortcut (*conf);
585 610 setShortcutText (item, *info);
586 (*meta.qAct)->setShortcut (*conf);
587 setShortcutText (qItem, meta);
588 } 611 }
589 } 612 }
590 613
591 // ============================================================================= 614 // =============================================================================
592 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 615 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
593 // ============================================================================= 616 // =============================================================================
594 void ConfigDialog::setShortcutText (QListWidgetItem* qItem, actionmeta meta) { 617 void ConfigDialog::setShortcutText (QListWidgetItem* qItem, actionmeta meta) {
595 QAction* const qAct = *meta.qAct; 618 QAction* const act = *meta.qAct;
596 str zLabel = qAct->iconText (); 619 str zLabel = act->iconText ();
597 str zKeybind = qAct->shortcut ().toString (); 620 str zKeybind = act->shortcut ().toString ();
598 621
599 qItem->setText (fmt ("%s (%s)", zLabel.chars () ,zKeybind.chars ()).chars()); 622 qItem->setText (fmt ("%s (%s)", zLabel.chars () ,zKeybind.chars ()).chars());
600 } 623 }
601 624
602 // ============================================================================= 625 // =============================================================================
603 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 626 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
604 // ============================================================================= 627 // =============================================================================
605 str ConfigDialog::makeColorToolBarString () { 628 str ConfigDialog::makeColorToolBarString () {
606 str zVal; 629 str val;
607 630
608 for (quickColorMetaEntry entry : quickColorMeta) { 631 for (quickColorMetaEntry entry : quickColorMeta) {
609 if (~zVal > 0) 632 if (~val > 0)
610 zVal += ':'; 633 val += ':';
611 634
612 if (entry.bSeparator) 635 if (entry.bSeparator)
613 zVal += '|'; 636 val += '|';
614 else 637 else
615 zVal.appendformat ("%d", entry.col->index ()); 638 val.appendformat ("%d", entry.col->index ());
616 } 639 }
617 640
618 return zVal; 641 return val;
619 } 642 }
620 643
621 // ============================================================================= 644 // =============================================================================
622 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 645 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
623 // ============================================================================= 646 // =============================================================================
625 ConfigDialog dlg (g_win); 648 ConfigDialog dlg (g_win);
626 649
627 if (dlg.exec ()) { 650 if (dlg.exec ()) {
628 io_ldpath = dlg.le_LDrawPath->text(); 651 io_ldpath = dlg.le_LDrawPath->text();
629 652
630 APPLY_CHECKBOX (dlg.cb_colorize, lv_colorize) 653 lv_colorize = dlg.cb_colorize->isChecked ();
631 APPLY_CHECKBOX (dlg.cb_colorBFC, gl_colorbfc) 654 gl_colorbfc = dlg.cb_colorBFC->isChecked ();
632 APPLY_CHECKBOX (dlg.cb_selFlash, gl_selflash) 655 gl_selflash = dlg.cb_selFlash->isChecked ();
633 APPLY_CHECKBOX (dlg.cb_schemanticInline, edit_schemanticinline) 656 edit_schemanticinline = dlg.cb_schemanticInline->isChecked ();
634 APPLY_CHECKBOX (dlg.cb_blackEdges, gl_blackedges) 657 gl_blackedges = dlg.cb_blackEdges->isChecked ();
635 658
636 gl_maincolor_alpha = ((double)dlg.sl_viewFgAlpha->value ()) / 10.0f; 659 gl_maincolor_alpha = ((double)dlg.sl_viewFgAlpha->value ()) / 10.0f;
637 gl_linethickness = dlg.sl_lineThickness->value (); 660 gl_linethickness = dlg.sl_lineThickness->value ();
638 gui_toolbar_iconsize = (dlg.sl_iconSize->value () * 4) + 12; 661 gui_toolbar_iconsize = (dlg.sl_iconSize->value () * 4) + 12;
639 662
647 g_GridInfo[i].confs[j]->value = dlg.dsb_gridData[i][j]->value (); 670 g_GridInfo[i].confs[j]->value = dlg.dsb_gridData[i][j]->value ();
648 671
649 // Save the config 672 // Save the config
650 config::save (); 673 config::save ();
651 674
652 // Reload all subfiles 675 // Reload all subfiles as the ldraw path potentially changed.
653 reloadAllSubfiles (); 676 reloadAllSubfiles ();
654 677
655 g_win->R ()->setBackground (); 678 g_win->R ()->setBackground ();
656 g_win->refresh (); 679 g_win->refresh ();
657 g_win->updateToolBars (); 680 g_win->updateToolBars ();

mercurial