src/dialogs/configdialog.cpp

changeset 976
b7aac3606b65
parent 975
24ba5aa3393f
child 978
4603d8fd063e
equal deleted inserted replaced
975:24ba5aa3393f 976:b7aac3606b65
47 "All files (*.*)(*.*)"; 47 "All files (*.*)(*.*)";
48 48
49 ConfigDialog::ConfigDialog (QWidget* parent, ConfigDialog::Tab defaulttab, Qt::WindowFlags f) : 49 ConfigDialog::ConfigDialog (QWidget* parent, ConfigDialog::Tab defaulttab, Qt::WindowFlags f) :
50 QDialog (parent, f), 50 QDialog (parent, f),
51 HierarchyElement (parent), 51 HierarchyElement (parent),
52 ui (*new Ui_ConfigDialog),
52 m_settings (m_window->makeSettings (this)) 53 m_settings (m_window->makeSettings (this))
53 { 54 {
54 ui = new Ui_ConfigDialog; 55 ui.setupUi (this);
55 ui->setupUi (this);
56 56
57 // Set defaults 57 // Set defaults
58 applyToWidgetOptions ( 58 applyToWidgetOptions (
59 [&](QWidget* widget, QString confname) 59 [&](QWidget* widget, QString confname)
60 { 60 {
100 m_window->applyToActions ([&](QAction* act) 100 m_window->applyToActions ([&](QAction* act)
101 { 101 {
102 addShortcut (act); 102 addShortcut (act);
103 }); 103 });
104 104
105 ui->shortcutsList->setSortingEnabled (true); 105 ui.shortcutsList->setSortingEnabled (true);
106 ui->shortcutsList->sortItems(); 106 ui.shortcutsList->sortItems();
107 quickColors = LoadQuickColorList(); 107 quickColors = LoadQuickColorList();
108 updateQuickColorList(); 108 updateQuickColorList();
109 initExtProgs(); 109 initExtProgs();
110 selectPage (defaulttab); 110 selectPage (defaulttab);
111 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); 111 connect (ui.shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut()));
112 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); 112 connect (ui.shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut()));
113 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); 113 connect (ui.shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut()));
114 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); 114 connect (ui.quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor()));
115 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); 115 connect (ui.quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor()));
116 connect (ui->quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor())); 116 connect (ui.quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor()));
117 connect (ui->quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator())); 117 connect (ui.quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator()));
118 connect (ui->quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor())); 118 connect (ui.quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor()));
119 connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); 119 connect (ui.quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor()));
120 connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); 120 connect (ui.quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors()));
121 connect (ui->findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); 121 connect (ui.findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder()));
122 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), 122 connect (ui.buttonBox, SIGNAL (clicked (QAbstractButton*)),
123 this, SLOT (buttonClicked (QAbstractButton*))); 123 this, SLOT (buttonClicked (QAbstractButton*)));
124 connect (ui->m_pages, SIGNAL (currentChanged (int)), this, SLOT (selectPage (int))); 124 connect (ui.m_pages, SIGNAL (currentChanged (int)), this, SLOT (selectPage (int)));
125 connect (ui->m_pagelist, SIGNAL (currentRowChanged (int)), this, SLOT (selectPage (int))); 125 connect (ui.m_pagelist, SIGNAL (currentRowChanged (int)), this, SLOT (selectPage (int)));
126 } 126 }
127 127
128 ConfigDialog::~ConfigDialog() 128 ConfigDialog::~ConfigDialog()
129 { 129 {
130 delete ui; 130 delete &ui;
131 } 131 }
132 132
133 void ConfigDialog::selectPage (int row) 133 void ConfigDialog::selectPage (int row)
134 { 134 {
135 ui->m_pagelist->setCurrentRow (row); 135 ui.m_pagelist->setCurrentRow (row);
136 ui->m_pages->setCurrentIndex (row); 136 ui.m_pages->setCurrentIndex (row);
137 } 137 }
138 138
139 // 139 //
140 // Adds a shortcut entry to the list of shortcuts. 140 // Adds a shortcut entry to the list of shortcuts.
141 // 141 //
150 // If the action doesn't have a valid icon, use an empty one 150 // If the action doesn't have a valid icon, use an empty one
151 // so that the list is kept aligned. 151 // so that the list is kept aligned.
152 if (act->icon().isNull()) 152 if (act->icon().isNull())
153 item->setIcon (GetIcon ("empty")); 153 item->setIcon (GetIcon ("empty"));
154 154
155 ui->shortcutsList->insertItem (ui->shortcutsList->count(), item); 155 ui.shortcutsList->insertItem (ui.shortcutsList->count(), item);
156 } 156 }
157 157
158 // 158 //
159 // Initializes the stuff in the ext programs tab 159 // Initializes the stuff in the ext programs tab
160 // 160 //
193 pathsLayout->addWidget (wineBox, row, 4); 193 pathsLayout->addWidget (wineBox, row, 4);
194 } 194 }
195 #endif 195 #endif
196 ++row; 196 ++row;
197 } 197 }
198 ui->extProgs->setLayout (pathsLayout); 198 ui.extProgs->setLayout (pathsLayout);
199 } 199 }
200 200
201 void ConfigDialog::applyToWidgetOptions (std::function<void (QWidget*, QString)> func) 201 void ConfigDialog::applyToWidgetOptions (std::function<void (QWidget*, QString)> func)
202 { 202 {
203 // Apply configuration 203 // Apply configuration
266 if (widgets.wineBox) 266 if (widgets.wineBox)
267 toolset->setWineSetting (program, widgets.wineBox->isChecked()); 267 toolset->setWineSetting (program, widgets.wineBox->isChecked());
268 } 268 }
269 269
270 // Apply shortcuts 270 // Apply shortcuts
271 for (int i = 0; i < ui->shortcutsList->count(); ++i) 271 for (int i = 0; i < ui.shortcutsList->count(); ++i)
272 { 272 {
273 auto item = static_cast<ShortcutListItem*> (ui->shortcutsList->item (i)); 273 auto item = static_cast<ShortcutListItem*> (ui.shortcutsList->item (i));
274 item->action()->setShortcut (item->sequence()); 274 item->action()->setShortcut (item->sequence());
275 } 275 }
276 276
277 m_window->syncSettings(); 277 m_window->syncSettings();
278 LDDocument::current()->reloadAllSubfiles(); 278 LDDocument::current()->reloadAllSubfiles();
286 // 286 //
287 // A dialog button was clicked 287 // A dialog button was clicked
288 // 288 //
289 void ConfigDialog::buttonClicked (QAbstractButton* button) 289 void ConfigDialog::buttonClicked (QAbstractButton* button)
290 { 290 {
291 QDialogButtonBox* dbb = ui->buttonBox; 291 QDialogButtonBox* dbb = ui.buttonBox;
292 292
293 if (button == dbb->button (QDialogButtonBox::Ok)) 293 if (button == dbb->button (QDialogButtonBox::Ok))
294 { 294 {
295 applySettings(); 295 applySettings();
296 accept(); 296 accept();
339 item->setText ("[[unknown color]]"); 339 item->setText ("[[unknown color]]");
340 item->setIcon (GetIcon ("error")); 340 item->setIcon (GetIcon ("error"));
341 } 341 }
342 } 342 }
343 343
344 ui->quickColorList->addItem (item); 344 ui.quickColorList->addItem (item);
345 quickColorItems << item; 345 quickColorItems << item;
346 346
347 if (sel and &entry == sel) 347 if (sel and &entry == sel)
348 { 348 {
349 ui->quickColorList->setCurrentItem (item); 349 ui.quickColorList->setCurrentItem (item);
350 ui->quickColorList->scrollToItem (item); 350 ui.quickColorList->scrollToItem (item);
351 } 351 }
352 } 352 }
353 } 353 }
354 354
355 // 355 //
357 // 357 //
358 void ConfigDialog::slot_setColor() 358 void ConfigDialog::slot_setColor()
359 { 359 {
360 LDQuickColor* entry = null; 360 LDQuickColor* entry = null;
361 QListWidgetItem* item = null; 361 QListWidgetItem* item = null;
362 const bool isNew = static_cast<QPushButton*> (sender()) == ui->quickColor_add; 362 const bool isNew = static_cast<QPushButton*> (sender()) == ui.quickColor_add;
363 363
364 if (not isNew) 364 if (not isNew)
365 { 365 {
366 item = getSelectedQuickColor(); 366 item = getSelectedQuickColor();
367 367
400 // 400 //
401 // Remove a quick color 401 // Remove a quick color
402 // 402 //
403 void ConfigDialog::slot_delColor() 403 void ConfigDialog::slot_delColor()
404 { 404 {
405 if (ui->quickColorList->selectedItems().isEmpty()) 405 if (ui.quickColorList->selectedItems().isEmpty())
406 return; 406 return;
407 407
408 QListWidgetItem* item = ui->quickColorList->selectedItems() [0]; 408 QListWidgetItem* item = ui.quickColorList->selectedItems() [0];
409 quickColors.removeAt (getItemRow (item, quickColorItems)); 409 quickColors.removeAt (getItemRow (item, quickColorItems));
410 updateQuickColorList(); 410 updateQuickColorList();
411 } 411 }
412 412
413 // 413 //
414 // Move a quick color up/down 414 // Move a quick color up/down
415 // 415 //
416 void ConfigDialog::slot_moveColor() 416 void ConfigDialog::slot_moveColor()
417 { 417 {
418 const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp); 418 const bool up = (static_cast<QPushButton*> (sender()) == ui.quickColor_moveUp);
419 419
420 if (ui->quickColorList->selectedItems().isEmpty()) 420 if (ui.quickColorList->selectedItems().isEmpty())
421 return; 421 return;
422 422
423 QListWidgetItem* item = ui->quickColorList->selectedItems() [0]; 423 QListWidgetItem* item = ui.quickColorList->selectedItems() [0];
424 int idx = getItemRow (item, quickColorItems); 424 int idx = getItemRow (item, quickColorItems);
425 int dest = up ? (idx - 1) : (idx + 1); 425 int dest = up ? (idx - 1) : (idx + 1);
426 426
427 if (dest < 0 or dest >= quickColorItems.size()) 427 if (dest < 0 or dest >= quickColorItems.size())
428 return; // destination out of bounds 428 return; // destination out of bounds
505 // 505 //
506 // Which quick color is currently selected? 506 // Which quick color is currently selected?
507 // 507 //
508 QListWidgetItem* ConfigDialog::getSelectedQuickColor() 508 QListWidgetItem* ConfigDialog::getSelectedQuickColor()
509 { 509 {
510 if (ui->quickColorList->selectedItems().isEmpty()) 510 if (ui.quickColorList->selectedItems().isEmpty())
511 return null; 511 return null;
512 512
513 return ui->quickColorList->selectedItems() [0]; 513 return ui.quickColorList->selectedItems() [0];
514 } 514 }
515 515
516 // 516 //
517 // Get the list of shortcuts selected 517 // Get the list of shortcuts selected
518 // 518 //
519 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() 519 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection()
520 { 520 {
521 QList<ShortcutListItem*> out; 521 QList<ShortcutListItem*> out;
522 522
523 for (QListWidgetItem* entry : ui->shortcutsList->selectedItems()) 523 for (QListWidgetItem* entry : ui.shortcutsList->selectedItems())
524 out << static_cast<ShortcutListItem*> (entry); 524 out << static_cast<ShortcutListItem*> (entry);
525 525
526 return out; 526 return out;
527 } 527 }
528 528
607 void ConfigDialog::slot_findDownloadFolder() 607 void ConfigDialog::slot_findDownloadFolder()
608 { 608 {
609 QString dpath = QFileDialog::getExistingDirectory(); 609 QString dpath = QFileDialog::getExistingDirectory();
610 610
611 if (not dpath.isEmpty()) 611 if (not dpath.isEmpty())
612 ui->configDownloadFilePath->setText (dpath); 612 ui.configDownloadFilePath->setText (dpath);
613 } 613 }
614 614
615 // 615 //
616 // 616 //
617 // Updates the text string for a given shortcut list item 617 // Updates the text string for a given shortcut list item

mercurial