127 addShortcut (act); |
127 addShortcut (act); |
128 }); |
128 }); |
129 |
129 |
130 ui.shortcutsList->setSortingEnabled (true); |
130 ui.shortcutsList->setSortingEnabled (true); |
131 ui.shortcutsList->sortItems(); |
131 ui.shortcutsList->sortItems(); |
132 quickColors = guiUtilities()->loadQuickColorList(); |
|
133 updateQuickColorList(); |
|
134 initExtProgs(); |
132 initExtProgs(); |
135 selectPage (defaulttab); |
133 selectPage (defaulttab); |
136 connect (ui.shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); |
134 connect (ui.shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); |
137 connect (ui.shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); |
135 connect (ui.shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); |
138 connect (ui.shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); |
136 connect (ui.shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); |
139 connect (ui.quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); |
|
140 connect (ui.quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); |
|
141 connect (ui.quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor())); |
|
142 connect (ui.quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator())); |
|
143 connect (ui.quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor())); |
|
144 connect (ui.quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); |
|
145 connect (ui.quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); |
|
146 connect (ui.findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); |
137 connect (ui.findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); |
147 connect (ui.buttonBox, SIGNAL (clicked (QAbstractButton*)), |
138 connect (ui.buttonBox, SIGNAL (clicked (QAbstractButton*)), |
148 this, SLOT (buttonClicked (QAbstractButton*))); |
139 this, SLOT (buttonClicked (QAbstractButton*))); |
149 connect (ui.m_pages, SIGNAL (currentChanged (int)), this, SLOT (selectPage (int))); |
140 connect (ui.m_pages, SIGNAL (currentChanged (int)), this, SLOT (selectPage (int))); |
150 connect (ui.m_pagelist, SIGNAL (currentRowChanged (int)), this, SLOT (selectPage (int))); |
141 connect (ui.m_pagelist, SIGNAL (currentRowChanged (int)), this, SLOT (selectPage (int))); |
367 } |
353 } |
368 else if (button == dbb->button (QDialogButtonBox::Cancel)) |
354 else if (button == dbb->button (QDialogButtonBox::Cancel)) |
369 { |
355 { |
370 reject(); |
356 reject(); |
371 } |
357 } |
372 } |
|
373 |
|
374 // |
|
375 // Update the list of color toolbar items in the quick color tab. |
|
376 // |
|
377 void ConfigDialog::updateQuickColorList (ColorToolbarItem* sel) |
|
378 { |
|
379 for (QListWidgetItem * item : quickColorItems) |
|
380 delete item; |
|
381 |
|
382 quickColorItems.clear(); |
|
383 |
|
384 // Init table items |
|
385 for (ColorToolbarItem& entry : quickColors) |
|
386 { |
|
387 QListWidgetItem* item = new QListWidgetItem; |
|
388 |
|
389 if (entry.isSeparator()) |
|
390 { |
|
391 item->setText ("<hr />"); |
|
392 item->setIcon (MainWindow::getIcon ("empty")); |
|
393 } |
|
394 else |
|
395 { |
|
396 LDColor color = entry.color(); |
|
397 |
|
398 if (color.isValid()) |
|
399 { |
|
400 item->setText (color.name()); |
|
401 item->setIcon (makeColorIcon (color, 16)); |
|
402 } |
|
403 else |
|
404 { |
|
405 item->setText ("[[unknown color]]"); |
|
406 item->setIcon (MainWindow::getIcon ("error")); |
|
407 } |
|
408 } |
|
409 |
|
410 ui.quickColorList->addItem (item); |
|
411 quickColorItems << item; |
|
412 |
|
413 if (sel and &entry == sel) |
|
414 { |
|
415 ui.quickColorList->setCurrentItem (item); |
|
416 ui.quickColorList->scrollToItem (item); |
|
417 } |
|
418 } |
|
419 } |
|
420 |
|
421 // |
|
422 // Quick colors: add or edit button was clicked. |
|
423 // |
|
424 void ConfigDialog::slot_setColor() |
|
425 { |
|
426 ColorToolbarItem* entry = nullptr; |
|
427 QListWidgetItem* item = nullptr; |
|
428 const bool isNew = static_cast<QPushButton*> (sender()) == ui.quickColor_add; |
|
429 |
|
430 if (not isNew) |
|
431 { |
|
432 item = getSelectedQuickColor(); |
|
433 |
|
434 if (not item) |
|
435 return; |
|
436 |
|
437 int i = getItemRow (item, quickColorItems); |
|
438 entry = &quickColors[i]; |
|
439 |
|
440 if (entry->isSeparator() == true) |
|
441 return; // don't color separators |
|
442 } |
|
443 |
|
444 LDColor defaultValue = entry ? entry->color() : LDColor::nullColor; |
|
445 LDColor value; |
|
446 |
|
447 if (not ColorSelector::selectColor (this, value, defaultValue)) |
|
448 return; |
|
449 |
|
450 if (entry) |
|
451 { |
|
452 entry->setColor (value); |
|
453 } |
|
454 else |
|
455 { |
|
456 ColorToolbarItem newentry {value}; |
|
457 item = getSelectedQuickColor(); |
|
458 int idx = (item) ? getItemRow (item, quickColorItems) + 1 : countof(quickColorItems); |
|
459 quickColors.insert(idx, newentry); |
|
460 entry = &quickColors[idx]; |
|
461 } |
|
462 |
|
463 updateQuickColorList (entry); |
|
464 } |
|
465 |
|
466 // |
|
467 // Remove a quick color |
|
468 // |
|
469 void ConfigDialog::slot_delColor() |
|
470 { |
|
471 if (ui.quickColorList->selectedItems().isEmpty()) |
|
472 return; |
|
473 |
|
474 QListWidgetItem* item = ui.quickColorList->selectedItems() [0]; |
|
475 quickColors.removeAt (getItemRow (item, quickColorItems)); |
|
476 updateQuickColorList(); |
|
477 } |
|
478 |
|
479 // |
|
480 // Move a quick color up/down |
|
481 // |
|
482 void ConfigDialog::slot_moveColor() |
|
483 { |
|
484 const bool up = (static_cast<QPushButton*> (sender()) == ui.quickColor_moveUp); |
|
485 |
|
486 if (ui.quickColorList->selectedItems().isEmpty()) |
|
487 return; |
|
488 |
|
489 QListWidgetItem* item = ui.quickColorList->selectedItems() [0]; |
|
490 int idx = getItemRow (item, quickColorItems); |
|
491 int dest = up ? (idx - 1) : (idx + 1); |
|
492 |
|
493 if (dest < 0 or dest >= countof(quickColorItems)) |
|
494 return; // destination out of bounds |
|
495 |
|
496 qSwap (quickColors[dest], quickColors[idx]); |
|
497 updateQuickColorList (&quickColors[dest]); |
|
498 } |
|
499 |
|
500 // |
|
501 // |
|
502 // Add a separator to quick colors |
|
503 // |
|
504 void ConfigDialog::slot_addColorSeparator() |
|
505 { |
|
506 quickColors << ColorToolbarItem::makeSeparator(); |
|
507 updateQuickColorList (&quickColors[countof(quickColors) - 1]); |
|
508 } |
|
509 |
|
510 // |
|
511 // |
|
512 // Clear all quick colors |
|
513 // |
|
514 void ConfigDialog::slot_clearColors() |
|
515 { |
|
516 quickColors.clear(); |
|
517 updateQuickColorList(); |
|
518 } |
358 } |
519 |
359 |
520 // |
360 // |
521 // |
361 // |
522 void ConfigDialog::setButtonColor() |
362 void ConfigDialog::setButtonColor() |
689 QString keybind = item->sequence().toString(); |
518 QString keybind = item->sequence().toString(); |
690 item->setText (format ("%1 (%2)", label, keybind)); |
519 item->setText (format ("%1 (%2)", label, keybind)); |
691 } |
520 } |
692 |
521 |
693 // |
522 // |
694 // Gets the configuration string of the quick color toolbar |
|
695 // |
|
696 QString ConfigDialog::quickColorString() |
|
697 { |
|
698 QString val; |
|
699 |
|
700 for (const ColorToolbarItem& entry : quickColors) |
|
701 { |
|
702 if (not val.isEmpty()) |
|
703 val += ':'; |
|
704 |
|
705 if (entry.isSeparator()) |
|
706 val += '|'; |
|
707 else |
|
708 val += format ("%1", entry.color().index()); |
|
709 } |
|
710 |
|
711 return val; |
|
712 } |
|
713 |
|
714 // |
|
715 // |
523 // |
716 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) : |
524 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) : |
717 QDialog (parent, f), seq (seq) |
525 QDialog (parent, f), seq (seq) |
718 { |
526 { |
719 lb_output = new QLabel; |
527 lb_output = new QLabel; |