src/dialogs/configdialog.cpp

changeset 1217
314e12e23c3a
parent 1215
77a0270352a3
child 1222
34def2630300
equal deleted inserted replaced
1216:12f9ea615cbc 1217:314e12e23c3a
41 #include "configdialog.h" 41 #include "configdialog.h"
42 #include "ui_configdialog.h" 42 #include "ui_configdialog.h"
43 43
44 const char* g_extProgPathFilter = 44 const char* g_extProgPathFilter =
45 #ifdef _WIN32 45 #ifdef _WIN32
46 "Applications (*.exe)(*.exe);;" 46 "Applications(*.exe)(*.exe);;"
47 #endif 47 #endif
48 "All files (*.*)(*.*)"; 48 "All files(*.*)(*.*)";
49 49
50 ShortcutListItem::ShortcutListItem (QListWidget* view, int type) : 50 ShortcutListItem::ShortcutListItem(QListWidget* view, int type) :
51 QListWidgetItem (view, type) {} 51 QListWidgetItem(view, type) {}
52 52
53 QAction* ShortcutListItem::action() const 53 QAction* ShortcutListItem::action() const
54 { 54 {
55 return m_action; 55 return m_action;
56 } 56 }
57 57
58 void ShortcutListItem::setAction (QAction* action) 58 void ShortcutListItem::setAction(QAction* action)
59 { 59 {
60 m_action = action; 60 m_action = action;
61 } 61 }
62 62
63 QKeySequence ShortcutListItem::sequence() const 63 QKeySequence ShortcutListItem::sequence() const
64 { 64 {
65 return m_sequence; 65 return m_sequence;
66 } 66 }
67 67
68 void ShortcutListItem::setSequence (const QKeySequence& sequence) 68 void ShortcutListItem::setSequence(const QKeySequence& sequence)
69 { 69 {
70 m_sequence = sequence; 70 m_sequence = sequence;
71 } 71 }
72 72
73 ConfigDialog::ConfigDialog (QWidget* parent, ConfigDialog::Tab defaulttab, Qt::WindowFlags f) : 73 ConfigDialog::ConfigDialog(QWidget* parent, ConfigDialog::Tab defaulttab, Qt::WindowFlags f) :
74 QDialog (parent, f), 74 QDialog(parent, f),
75 HierarchyElement (parent), 75 HierarchyElement(parent),
76 ui (*new Ui_ConfigDialog), 76 ui(*new Ui_ConfigDialog),
77 m_settings (makeSettings (this)) 77 m_settings(makeSettings(this))
78 { 78 {
79 ui.setupUi (this); 79 ui.setupUi(this);
80 80
81 // Set defaults 81 // Set defaults
82 applyToWidgetOptions ( 82 applyToWidgetOptions(
83 [&](QWidget* widget, QString confname) 83 [&](QWidget* widget, QString confname)
84 { 84 {
85 QVariant value = m_settings->value (confname, config.defaultValueByName (confname)); 85 QVariant value = m_settings->value(confname, config.defaultValueByName(confname));
86 QLineEdit* le; 86 QLineEdit* le;
87 QSpinBox* spinbox; 87 QSpinBox* spinbox;
88 QDoubleSpinBox* doublespinbox; 88 QDoubleSpinBox* doublespinbox;
89 QSlider* slider; 89 QSlider* slider;
90 QCheckBox* checkbox; 90 QCheckBox* checkbox;
91 QPushButton* button; 91 QPushButton* button;
92 92
93 if ((le = qobject_cast<QLineEdit*> (widget))) 93 if ((le = qobject_cast<QLineEdit*>(widget)))
94 { 94 {
95 le->setText (value.toString()); 95 le->setText(value.toString());
96 } 96 }
97 else if ((spinbox = qobject_cast<QSpinBox*> (widget))) 97 else if ((spinbox = qobject_cast<QSpinBox*>(widget)))
98 { 98 {
99 spinbox->setValue (value.toInt()); 99 spinbox->setValue(value.toInt());
100 } 100 }
101 else if ((doublespinbox = qobject_cast<QDoubleSpinBox*> (widget))) 101 else if ((doublespinbox = qobject_cast<QDoubleSpinBox*>(widget)))
102 { 102 {
103 doublespinbox->setValue (value.toDouble()); 103 doublespinbox->setValue(value.toDouble());
104 } 104 }
105 else if ((slider = qobject_cast<QSlider*> (widget))) 105 else if ((slider = qobject_cast<QSlider*>(widget)))
106 { 106 {
107 slider->setValue (value.toInt()); 107 slider->setValue(value.toInt());
108 } 108 }
109 else if ((checkbox = qobject_cast<QCheckBox*> (widget))) 109 else if ((checkbox = qobject_cast<QCheckBox*>(widget)))
110 { 110 {
111 checkbox->setChecked (value.toBool()); 111 checkbox->setChecked(value.toBool());
112 } 112 }
113 else if ((button = qobject_cast<QPushButton*> (widget))) 113 else if ((button = qobject_cast<QPushButton*>(widget)))
114 { 114 {
115 setButtonBackground (button, value.toString()); 115 setButtonBackground(button, value.toString());
116 connect (button, SIGNAL (clicked()), this, SLOT (setButtonColor())); 116 connect(button, SIGNAL(clicked()), this, SLOT(setButtonColor()));
117 } 117 }
118 else 118 else
119 { 119 {
120 print ("Unknown widget of type %1\n", widget->metaObject()->className()); 120 print("Unknown widget of type %1\n", widget->metaObject()->className());
121 } 121 }
122 }); 122 });
123 123
124 m_window->applyToActions ([&](QAction* act) 124 m_window->applyToActions([&](QAction* act)
125 { 125 {
126 addShortcut (act); 126 addShortcut(act);
127 }); 127 });
128 128
129 ui.shortcutsList->setSortingEnabled (true); 129 ui.shortcutsList->setSortingEnabled(true);
130 ui.shortcutsList->sortItems(); 130 ui.shortcutsList->sortItems();
131 quickColors = LoadQuickColorList(); 131 quickColors = LoadQuickColorList();
132 updateQuickColorList(); 132 updateQuickColorList();
133 initExtProgs(); 133 initExtProgs();
134 selectPage (defaulttab); 134 selectPage(defaulttab);
135 connect (ui.shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); 135 connect(ui.shortcut_set, SIGNAL(clicked()), this, SLOT(slot_setShortcut()));
136 connect (ui.shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); 136 connect(ui.shortcut_reset, SIGNAL(clicked()), this, SLOT(slot_resetShortcut()));
137 connect (ui.shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); 137 connect(ui.shortcut_clear, SIGNAL(clicked()), this, SLOT(slot_clearShortcut()));
138 connect (ui.quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); 138 connect(ui.quickColor_add, SIGNAL(clicked()), this, SLOT(slot_setColor()));
139 connect (ui.quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); 139 connect(ui.quickColor_remove, SIGNAL(clicked()), this, SLOT(slot_delColor()));
140 connect (ui.quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor())); 140 connect(ui.quickColor_edit, SIGNAL(clicked()), this, SLOT(slot_setColor()));
141 connect (ui.quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator())); 141 connect(ui.quickColor_addSep, SIGNAL(clicked()), this, SLOT(slot_addColorSeparator()));
142 connect (ui.quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor())); 142 connect(ui.quickColor_moveUp, SIGNAL(clicked()), this, SLOT(slot_moveColor()));
143 connect (ui.quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); 143 connect(ui.quickColor_moveDown, SIGNAL(clicked()), this, SLOT(slot_moveColor()));
144 connect (ui.quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); 144 connect(ui.quickColor_clear, SIGNAL(clicked()), this, SLOT(slot_clearColors()));
145 connect (ui.findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder())); 145 connect(ui.findDownloadPath, SIGNAL(clicked(bool)), this, SLOT(slot_findDownloadFolder()));
146 connect (ui.buttonBox, SIGNAL (clicked (QAbstractButton*)), 146 connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),
147 this, SLOT (buttonClicked (QAbstractButton*))); 147 this, SLOT(buttonClicked(QAbstractButton*)));
148 connect (ui.m_pages, SIGNAL (currentChanged (int)), this, SLOT (selectPage (int))); 148 connect(ui.m_pages, SIGNAL(currentChanged(int)), this, SLOT(selectPage(int)));
149 connect (ui.m_pagelist, SIGNAL (currentRowChanged (int)), this, SLOT (selectPage (int))); 149 connect(ui.m_pagelist, SIGNAL(currentRowChanged(int)), this, SLOT(selectPage(int)));
150 } 150 }
151 151
152 ConfigDialog::~ConfigDialog() 152 ConfigDialog::~ConfigDialog()
153 { 153 {
154 delete &ui; 154 delete &ui;
155 } 155 }
156 156
157 void ConfigDialog::selectPage (int row) 157 void ConfigDialog::selectPage(int row)
158 { 158 {
159 ui.m_pagelist->setCurrentRow (row); 159 ui.m_pagelist->setCurrentRow(row);
160 ui.m_pages->setCurrentIndex (row); 160 ui.m_pages->setCurrentIndex(row);
161 } 161 }
162 162
163 // 163 //
164 // Adds a shortcut entry to the list of shortcuts. 164 // Adds a shortcut entry to the list of shortcuts.
165 // 165 //
166 void ConfigDialog::addShortcut (QAction* act) 166 void ConfigDialog::addShortcut(QAction* act)
167 { 167 {
168 ShortcutListItem* item = new ShortcutListItem; 168 ShortcutListItem* item = new ShortcutListItem;
169 item->setIcon (act->icon()); 169 item->setIcon(act->icon());
170 item->setAction (act); 170 item->setAction(act);
171 item->setSequence (act->shortcut()); 171 item->setSequence(act->shortcut());
172 setShortcutText (item); 172 setShortcutText(item);
173 173
174 // If the action doesn't have a valid icon, use an empty one 174 // If the action doesn't have a valid icon, use an empty one
175 // so that the list is kept aligned. 175 // so that the list is kept aligned.
176 if (act->icon().isNull()) 176 if (act->icon().isNull())
177 item->setIcon (GetIcon ("empty")); 177 item->setIcon(GetIcon("empty"));
178 178
179 ui.shortcutsList->insertItem (ui.shortcutsList->count(), item); 179 ui.shortcutsList->insertItem(ui.shortcutsList->count(), item);
180 } 180 }
181 181
182 // 182 //
183 // Initializes the stuff in the ext programs tab 183 // Initializes the stuff in the ext programs tab
184 // 184 //
189 189
190 for (int i = 0; i < NumExternalPrograms; ++i) 190 for (int i = 0; i < NumExternalPrograms; ++i)
191 { 191 {
192 ExtProgramType program = (ExtProgramType) i; 192 ExtProgramType program = (ExtProgramType) i;
193 ExternalProgramWidgets& widgets = m_externalProgramWidgets[i]; 193 ExternalProgramWidgets& widgets = m_externalProgramWidgets[i];
194 QString name = m_window->externalPrograms()->externalProgramName (program); 194 QString name = m_window->externalPrograms()->externalProgramName(program);
195 QLabel* icon = new QLabel; 195 QLabel* icon = new QLabel;
196 QLabel* progLabel = new QLabel (name); 196 QLabel* progLabel = new QLabel(name);
197 QLineEdit* input = new QLineEdit; 197 QLineEdit* input = new QLineEdit;
198 QPushButton* setPathButton = new QPushButton; 198 QPushButton* setPathButton = new QPushButton;
199 199
200 icon->setPixmap (GetIcon (name.toLower())); 200 icon->setPixmap(GetIcon(name.toLower()));
201 input->setText (m_window->externalPrograms()->getPathSetting (program)); 201 input->setText(m_window->externalPrograms()->getPathSetting(program));
202 setPathButton->setIcon (GetIcon ("folder")); 202 setPathButton->setIcon(GetIcon("folder"));
203 widgets.input = input; 203 widgets.input = input;
204 widgets.setPathButton = setPathButton; 204 widgets.setPathButton = setPathButton;
205 widgets.wineBox = nullptr; 205 widgets.wineBox = nullptr;
206 connect (setPathButton, SIGNAL (clicked()), this, SLOT (slot_setExtProgPath())); 206 connect(setPathButton, SIGNAL(clicked()), this, SLOT(slot_setExtProgPath()));
207 pathsLayout->addWidget (icon, row, 0); 207 pathsLayout->addWidget(icon, row, 0);
208 pathsLayout->addWidget (progLabel, row, 1); 208 pathsLayout->addWidget(progLabel, row, 1);
209 pathsLayout->addWidget (input, row, 2); 209 pathsLayout->addWidget(input, row, 2);
210 pathsLayout->addWidget (setPathButton, row, 3); 210 pathsLayout->addWidget(setPathButton, row, 3);
211 211
212 #ifdef Q_OS_UNIX 212 #ifdef Q_OS_UNIX
213 { 213 {
214 QCheckBox* wineBox = new QCheckBox ("Wine"); 214 QCheckBox* wineBox = new QCheckBox("Wine");
215 wineBox->setChecked (m_window->externalPrograms()->programUsesWine (program)); 215 wineBox->setChecked(m_window->externalPrograms()->programUsesWine(program));
216 widgets.wineBox = wineBox; 216 widgets.wineBox = wineBox;
217 pathsLayout->addWidget (wineBox, row, 4); 217 pathsLayout->addWidget(wineBox, row, 4);
218 } 218 }
219 #endif 219 #endif
220 ++row; 220 ++row;
221 } 221 }
222 ui.extProgs->setLayout (pathsLayout); 222 ui.extProgs->setLayout(pathsLayout);
223 } 223 }
224 224
225 void ConfigDialog::applyToWidgetOptions (std::function<void (QWidget*, QString)> func) 225 void ConfigDialog::applyToWidgetOptions(std::function<void(QWidget*, QString)> func)
226 { 226 {
227 // Apply configuration 227 // Apply configuration
228 for (QWidget* widget : findChildren<QWidget*>()) 228 for (QWidget* widget : findChildren<QWidget*>())
229 { 229 {
230 if (not widget->objectName().startsWith ("config")) 230 if (not widget->objectName().startsWith("config"))
231 continue; 231 continue;
232 232
233 QString optionname (widget->objectName().mid (strlen ("config"))); 233 QString optionname(widget->objectName().mid(strlen("config")));
234 234
235 if (config.existsEntry (optionname)) 235 if (config.existsEntry(optionname))
236 func (widget, optionname); 236 func(widget, optionname);
237 else 237 else
238 print ("Couldn't find configuration entry named %1", optionname); 238 print("Couldn't find configuration entry named %1", optionname);
239 } 239 }
240 } 240 }
241 241
242 // 242 //
243 // Set the settings based on widget data. 243 // Set the settings based on widget data.
244 // 244 //
245 void ConfigDialog::applySettings() 245 void ConfigDialog::applySettings()
246 { 246 {
247 applyToWidgetOptions ([&](QWidget* widget, QString confname) 247 applyToWidgetOptions([&](QWidget* widget, QString confname)
248 { 248 {
249 QVariant value; 249 QVariant value;
250 QLineEdit* le; 250 QLineEdit* le;
251 QSpinBox* spinbox; 251 QSpinBox* spinbox;
252 QDoubleSpinBox* doublespinbox; 252 QDoubleSpinBox* doublespinbox;
253 QSlider* slider; 253 QSlider* slider;
254 QCheckBox* checkbox; 254 QCheckBox* checkbox;
255 QPushButton* button; 255 QPushButton* button;
256 256
257 if ((le = qobject_cast<QLineEdit*> (widget))) 257 if ((le = qobject_cast<QLineEdit*>(widget)))
258 value = le->text(); 258 value = le->text();
259 else if ((spinbox = qobject_cast<QSpinBox*> (widget))) 259 else if ((spinbox = qobject_cast<QSpinBox*>(widget)))
260 value = spinbox->value(); 260 value = spinbox->value();
261 else if ((doublespinbox = qobject_cast<QDoubleSpinBox*> (widget))) 261 else if ((doublespinbox = qobject_cast<QDoubleSpinBox*>(widget)))
262 value = doublespinbox->value(); 262 value = doublespinbox->value();
263 else if ((slider = qobject_cast<QSlider*> (widget))) 263 else if ((slider = qobject_cast<QSlider*>(widget)))
264 value = slider->value(); 264 value = slider->value();
265 else if ((checkbox = qobject_cast<QCheckBox*> (widget))) 265 else if ((checkbox = qobject_cast<QCheckBox*>(widget)))
266 value = checkbox->isChecked(); 266 value = checkbox->isChecked();
267 else if ((button = qobject_cast<QPushButton*> (widget))) 267 else if ((button = qobject_cast<QPushButton*>(widget)))
268 value = m_buttonColors[button]; 268 value = m_buttonColors[button];
269 else 269 else
270 { 270 {
271 print ("Unknown widget of type %1\n", widget->metaObject()->className()); 271 print("Unknown widget of type %1\n", widget->metaObject()->className());
272 return; 272 return;
273 } 273 }
274 274
275 m_settings->setValue (confname, value); 275 m_settings->setValue(confname, value);
276 }); 276 });
277 277
278 // Rebuild the quick color toolbar 278 // Rebuild the quick color toolbar
279 m_window->setQuickColors (quickColors); 279 m_window->setQuickColors(quickColors);
280 config.setQuickColorToolbar (quickColorString()); 280 config.setQuickColorToolbar(quickColorString());
281 281
282 // Ext program settings 282 // Ext program settings
283 for (int i = 0; i < NumExternalPrograms; ++i) 283 for (int i = 0; i < NumExternalPrograms; ++i)
284 { 284 {
285 ExtProgramType program = (ExtProgramType) i; 285 ExtProgramType program = (ExtProgramType) i;
286 ExtProgramToolset* toolset = m_window->externalPrograms(); 286 ExtProgramToolset* toolset = m_window->externalPrograms();
287 ExternalProgramWidgets& widgets = m_externalProgramWidgets[i]; 287 ExternalProgramWidgets& widgets = m_externalProgramWidgets[i];
288 toolset->getPathSetting (program) = widgets.input->text(); 288 toolset->getPathSetting(program) = widgets.input->text();
289 289
290 if (widgets.wineBox) 290 if (widgets.wineBox)
291 toolset->setWineSetting (program, widgets.wineBox->isChecked()); 291 toolset->setWineSetting(program, widgets.wineBox->isChecked());
292 } 292 }
293 293
294 // Apply shortcuts 294 // Apply shortcuts
295 for (int i = 0; i < ui.shortcutsList->count(); ++i) 295 for (int i = 0; i < ui.shortcutsList->count(); ++i)
296 { 296 {
297 auto item = static_cast<ShortcutListItem*> (ui.shortcutsList->item (i)); 297 auto item = static_cast<ShortcutListItem*>(ui.shortcutsList->item(i));
298 item->action()->setShortcut (item->sequence()); 298 item->action()->setShortcut(item->sequence());
299 } 299 }
300 300
301 m_window->syncSettings(); 301 m_window->syncSettings();
302 currentDocument()->reloadAllSubfiles(); 302 currentDocument()->reloadAllSubfiles();
303 m_documents->loadLogoedStuds(); 303 m_documents->loadLogoedStuds();
307 } 307 }
308 308
309 // 309 //
310 // A dialog button was clicked 310 // A dialog button was clicked
311 // 311 //
312 void ConfigDialog::buttonClicked (QAbstractButton* button) 312 void ConfigDialog::buttonClicked(QAbstractButton* button)
313 { 313 {
314 QDialogButtonBox* dbb = ui.buttonBox; 314 QDialogButtonBox* dbb = ui.buttonBox;
315 315
316 if (button == dbb->button (QDialogButtonBox::Ok)) 316 if (button == dbb->button(QDialogButtonBox::Ok))
317 { 317 {
318 applySettings(); 318 applySettings();
319 accept(); 319 accept();
320 } 320 }
321 else if (button == dbb->button (QDialogButtonBox::Apply)) 321 else if (button == dbb->button(QDialogButtonBox::Apply))
322 { 322 {
323 applySettings(); 323 applySettings();
324 } 324 }
325 else if (button == dbb->button (QDialogButtonBox::Cancel)) 325 else if (button == dbb->button(QDialogButtonBox::Cancel))
326 { 326 {
327 reject(); 327 reject();
328 } 328 }
329 } 329 }
330 330
331 // 331 //
332 // Update the list of color toolbar items in the quick color tab. 332 // Update the list of color toolbar items in the quick color tab.
333 // 333 //
334 void ConfigDialog::updateQuickColorList (ColorToolbarItem* sel) 334 void ConfigDialog::updateQuickColorList(ColorToolbarItem* sel)
335 { 335 {
336 for (QListWidgetItem * item : quickColorItems) 336 for (QListWidgetItem * item : quickColorItems)
337 delete item; 337 delete item;
338 338
339 quickColorItems.clear(); 339 quickColorItems.clear();
343 { 343 {
344 QListWidgetItem* item = new QListWidgetItem; 344 QListWidgetItem* item = new QListWidgetItem;
345 345
346 if (entry.isSeparator()) 346 if (entry.isSeparator())
347 { 347 {
348 item->setText ("<hr />"); 348 item->setText("<hr />");
349 item->setIcon (GetIcon ("empty")); 349 item->setIcon(GetIcon("empty"));
350 } 350 }
351 else 351 else
352 { 352 {
353 LDColor color = entry.color(); 353 LDColor color = entry.color();
354 354
355 if (color.isValid()) 355 if (color.isValid())
356 { 356 {
357 item->setText (color.name()); 357 item->setText(color.name());
358 item->setIcon (guiUtilities()->makeColorIcon (color, 16)); 358 item->setIcon(guiUtilities()->makeColorIcon(color, 16));
359 } 359 }
360 else 360 else
361 { 361 {
362 item->setText ("[[unknown color]]"); 362 item->setText("[[unknown color]]");
363 item->setIcon (GetIcon ("error")); 363 item->setIcon(GetIcon("error"));
364 } 364 }
365 } 365 }
366 366
367 ui.quickColorList->addItem (item); 367 ui.quickColorList->addItem(item);
368 quickColorItems << item; 368 quickColorItems << item;
369 369
370 if (sel and &entry == sel) 370 if (sel and &entry == sel)
371 { 371 {
372 ui.quickColorList->setCurrentItem (item); 372 ui.quickColorList->setCurrentItem(item);
373 ui.quickColorList->scrollToItem (item); 373 ui.quickColorList->scrollToItem(item);
374 } 374 }
375 } 375 }
376 } 376 }
377 377
378 // 378 //
380 // 380 //
381 void ConfigDialog::slot_setColor() 381 void ConfigDialog::slot_setColor()
382 { 382 {
383 ColorToolbarItem* entry = nullptr; 383 ColorToolbarItem* entry = nullptr;
384 QListWidgetItem* item = nullptr; 384 QListWidgetItem* item = nullptr;
385 const bool isNew = static_cast<QPushButton*> (sender()) == ui.quickColor_add; 385 const bool isNew = static_cast<QPushButton*>(sender()) == ui.quickColor_add;
386 386
387 if (not isNew) 387 if (not isNew)
388 { 388 {
389 item = getSelectedQuickColor(); 389 item = getSelectedQuickColor();
390 390
391 if (not item) 391 if (not item)
392 return; 392 return;
393 393
394 int i = getItemRow (item, quickColorItems); 394 int i = getItemRow(item, quickColorItems);
395 entry = &quickColors[i]; 395 entry = &quickColors[i];
396 396
397 if (entry->isSeparator() == true) 397 if (entry->isSeparator() == true)
398 return; // don't color separators 398 return; // don't color separators
399 } 399 }
400 400
401 LDColor defaultValue = entry ? entry->color() : LDColor::nullColor(); 401 LDColor defaultValue = entry ? entry->color() : LDColor::nullColor();
402 LDColor value; 402 LDColor value;
403 403
404 if (not ColorSelector::selectColor (this, value, defaultValue)) 404 if (not ColorSelector::selectColor(this, value, defaultValue))
405 return; 405 return;
406 406
407 if (entry) 407 if (entry)
408 { 408 {
409 entry->setColor (value); 409 entry->setColor(value);
410 } 410 }
411 else 411 else
412 { 412 {
413 ColorToolbarItem newentry (value, nullptr); 413 ColorToolbarItem newentry(value, nullptr);
414 item = getSelectedQuickColor(); 414 item = getSelectedQuickColor();
415 int idx = (item) ? getItemRow (item, quickColorItems) + 1 : quickColorItems.size(); 415 int idx = (item) ? getItemRow(item, quickColorItems) + 1 : quickColorItems.size();
416 quickColors.insert (idx, newentry); 416 quickColors.insert(idx, newentry);
417 entry = &quickColors[idx]; 417 entry = &quickColors[idx];
418 } 418 }
419 419
420 updateQuickColorList (entry); 420 updateQuickColorList(entry);
421 } 421 }
422 422
423 // 423 //
424 // Remove a quick color 424 // Remove a quick color
425 // 425 //
427 { 427 {
428 if (ui.quickColorList->selectedItems().isEmpty()) 428 if (ui.quickColorList->selectedItems().isEmpty())
429 return; 429 return;
430 430
431 QListWidgetItem* item = ui.quickColorList->selectedItems() [0]; 431 QListWidgetItem* item = ui.quickColorList->selectedItems() [0];
432 quickColors.removeAt (getItemRow (item, quickColorItems)); 432 quickColors.removeAt(getItemRow(item, quickColorItems));
433 updateQuickColorList(); 433 updateQuickColorList();
434 } 434 }
435 435
436 // 436 //
437 // Move a quick color up/down 437 // Move a quick color up/down
438 // 438 //
439 void ConfigDialog::slot_moveColor() 439 void ConfigDialog::slot_moveColor()
440 { 440 {
441 const bool up = (static_cast<QPushButton*> (sender()) == ui.quickColor_moveUp); 441 const bool up = (static_cast<QPushButton*>(sender()) == ui.quickColor_moveUp);
442 442
443 if (ui.quickColorList->selectedItems().isEmpty()) 443 if (ui.quickColorList->selectedItems().isEmpty())
444 return; 444 return;
445 445
446 QListWidgetItem* item = ui.quickColorList->selectedItems() [0]; 446 QListWidgetItem* item = ui.quickColorList->selectedItems() [0];
447 int idx = getItemRow (item, quickColorItems); 447 int idx = getItemRow(item, quickColorItems);
448 int dest = up ? (idx - 1) : (idx + 1); 448 int dest = up ?(idx - 1) :(idx + 1);
449 449
450 if (dest < 0 or dest >= quickColorItems.size()) 450 if (dest < 0 or dest >= quickColorItems.size())
451 return; // destination out of bounds 451 return; // destination out of bounds
452 452
453 qSwap (quickColors[dest], quickColors[idx]); 453 qSwap(quickColors[dest], quickColors[idx]);
454 updateQuickColorList (&quickColors[dest]); 454 updateQuickColorList(&quickColors[dest]);
455 } 455 }
456 456
457 // 457 //
458 // 458 //
459 // Add a separator to quick colors 459 // Add a separator to quick colors
460 // 460 //
461 void ConfigDialog::slot_addColorSeparator() 461 void ConfigDialog::slot_addColorSeparator()
462 { 462 {
463 quickColors << ColorToolbarItem::makeSeparator(); 463 quickColors << ColorToolbarItem::makeSeparator();
464 updateQuickColorList (&quickColors[quickColors.size() - 1]); 464 updateQuickColorList(&quickColors[quickColors.size() - 1]);
465 } 465 }
466 466
467 // 467 //
468 // 468 //
469 // Clear all quick colors 469 // Clear all quick colors
476 476
477 // 477 //
478 // 478 //
479 void ConfigDialog::setButtonColor() 479 void ConfigDialog::setButtonColor()
480 { 480 {
481 QPushButton* button = qobject_cast<QPushButton*> (sender()); 481 QPushButton* button = qobject_cast<QPushButton*>(sender());
482 482
483 if (button == nullptr) 483 if (button == nullptr)
484 { 484 {
485 print ("setButtonColor: null sender!\n"); 485 print("setButtonColor: null sender!\n");
486 return; 486 return;
487 } 487 }
488 488
489 QColor color = QColorDialog::getColor (m_buttonColors[button]); 489 QColor color = QColorDialog::getColor(m_buttonColors[button]);
490 490
491 if (color.isValid()) 491 if (color.isValid())
492 { 492 {
493 QString colorname; 493 QString colorname;
494 colorname.sprintf ("#%.2X%.2X%.2X", color.red(), color.green(), color.blue()); 494 colorname.sprintf("#%.2X%.2X%.2X", color.red(), color.green(), color.blue());
495 setButtonBackground (button, colorname); 495 setButtonBackground(button, colorname);
496 } 496 }
497 } 497 }
498 498
499 // 499 //
500 // Sets background color of a given button. 500 // Sets background color of a given button.
501 // 501 //
502 void ConfigDialog::setButtonBackground (QPushButton* button, QString value) 502 void ConfigDialog::setButtonBackground(QPushButton* button, QString value)
503 { 503 {
504 button->setIcon (GetIcon ("colorselect")); 504 button->setIcon(GetIcon("colorselect"));
505 button->setAutoFillBackground (true); 505 button->setAutoFillBackground(true);
506 button->setStyleSheet (format ("background-color: %1", value)); 506 button->setStyleSheet(format("background-color: %1", value));
507 m_buttonColors[button] = QColor (value); 507 m_buttonColors[button] = QColor(value);
508 } 508 }
509 509
510 // 510 //
511 // Finds the given list widget item in the list of widget items given. 511 // Finds the given list widget item in the list of widget items given.
512 // 512 //
513 int ConfigDialog::getItemRow (QListWidgetItem* item, QList<QListWidgetItem*>& haystack) 513 int ConfigDialog::getItemRow(QListWidgetItem* item, QList<QListWidgetItem*>& haystack)
514 { 514 {
515 int i = 0; 515 int i = 0;
516 516
517 for (QListWidgetItem* it : haystack) 517 for (QListWidgetItem* it : haystack)
518 { 518 {
542 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() 542 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection()
543 { 543 {
544 QList<ShortcutListItem*> out; 544 QList<ShortcutListItem*> out;
545 545
546 for (QListWidgetItem* entry : ui.shortcutsList->selectedItems()) 546 for (QListWidgetItem* entry : ui.shortcutsList->selectedItems())
547 out << static_cast<ShortcutListItem*> (entry); 547 out << static_cast<ShortcutListItem*>(entry);
548 548
549 return out; 549 return out;
550 } 550 }
551 551
552 // 552 //
559 if (sel.size() < 1) 559 if (sel.size() < 1)
560 return; 560 return;
561 561
562 ShortcutListItem* item = sel[0]; 562 ShortcutListItem* item = sel[0];
563 563
564 if (KeySequenceDialog::staticDialog (item, this)) 564 if (KeySequenceDialog::staticDialog(item, this))
565 setShortcutText (item); 565 setShortcutText(item);
566 } 566 }
567 567
568 // 568 //
569 // Reset a shortcut to defaults 569 // Reset a shortcut to defaults
570 // 570 //
572 { 572 {
573 QList<ShortcutListItem*> sel = getShortcutSelection(); 573 QList<ShortcutListItem*> sel = getShortcutSelection();
574 574
575 for (ShortcutListItem* item : sel) 575 for (ShortcutListItem* item : sel)
576 { 576 {
577 item->setSequence (m_window->defaultShortcut (item->action())); 577 item->setSequence(m_window->defaultShortcut(item->action()));
578 setShortcutText (item); 578 setShortcutText(item);
579 } 579 }
580 } 580 }
581 581
582 // 582 //
583 // Remove the shortcut of an action. 583 // Remove the shortcut of an action.
586 { 586 {
587 QList<ShortcutListItem*> sel = getShortcutSelection(); 587 QList<ShortcutListItem*> sel = getShortcutSelection();
588 588
589 for (ShortcutListItem* item : sel) 589 for (ShortcutListItem* item : sel)
590 { 590 {
591 item->setSequence (QKeySequence()); 591 item->setSequence(QKeySequence());
592 setShortcutText (item); 592 setShortcutText(item);
593 } 593 }
594 } 594 }
595 595
596 // 596 //
597 // Set the path of an external program 597 // Set the path of an external program
611 611
612 if (program != NumExternalPrograms) 612 if (program != NumExternalPrograms)
613 { 613 {
614 ExtProgramToolset* toolset = m_window->externalPrograms(); 614 ExtProgramToolset* toolset = m_window->externalPrograms();
615 ExternalProgramWidgets& widgets = m_externalProgramWidgets[program]; 615 ExternalProgramWidgets& widgets = m_externalProgramWidgets[program];
616 QString filepath = QFileDialog::getOpenFileName (this, 616 QString filepath = QFileDialog::getOpenFileName(this,
617 format ("Path to %1", toolset->externalProgramName (program)), 617 format("Path to %1", toolset->externalProgramName(program)),
618 widgets.input->text(), g_extProgPathFilter); 618 widgets.input->text(), g_extProgPathFilter);
619 619
620 if (filepath.isEmpty()) 620 if (filepath.isEmpty())
621 return; 621 return;
622 622
623 widgets.input->setText (filepath); 623 widgets.input->setText(filepath);
624 } 624 }
625 } 625 }
626 626
627 // 627 //
628 // '...' button pressed for the download path 628 // '...' button pressed for the download path
630 void ConfigDialog::slot_findDownloadFolder() 630 void ConfigDialog::slot_findDownloadFolder()
631 { 631 {
632 QString dpath = QFileDialog::getExistingDirectory(); 632 QString dpath = QFileDialog::getExistingDirectory();
633 633
634 if (not dpath.isEmpty()) 634 if (not dpath.isEmpty())
635 ui.configDownloadFilePath->setText (dpath); 635 ui.configDownloadFilePath->setText(dpath);
636 } 636 }
637 637
638 // 638 //
639 // 639 //
640 // Updates the text string for a given shortcut list item 640 // Updates the text string for a given shortcut list item
641 // 641 //
642 void ConfigDialog::setShortcutText (ShortcutListItem* item) 642 void ConfigDialog::setShortcutText(ShortcutListItem* item)
643 { 643 {
644 QAction* act = item->action(); 644 QAction* act = item->action();
645 QString label = act->iconText(); 645 QString label = act->iconText();
646 QString keybind = item->sequence().toString(); 646 QString keybind = item->sequence().toString();
647 item->setText (format ("%1 (%2)", label, keybind)); 647 item->setText(format("%1(%2)", label, keybind));
648 } 648 }
649 649
650 // 650 //
651 // Gets the configuration string of the quick color toolbar 651 // Gets the configuration string of the quick color toolbar
652 // 652 //
660 val += ':'; 660 val += ':';
661 661
662 if (entry.isSeparator()) 662 if (entry.isSeparator())
663 val += '|'; 663 val += '|';
664 else 664 else
665 val += format ("%1", entry.color().index()); 665 val += format("%1", entry.color().index());
666 } 666 }
667 667
668 return val; 668 return val;
669 } 669 }
670 670
671 // 671 //
672 // 672 //
673 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) : 673 KeySequenceDialog::KeySequenceDialog(QKeySequence seq, QWidget* parent, Qt::WindowFlags f) :
674 QDialog (parent, f), seq (seq) 674 QDialog(parent, f), seq(seq)
675 { 675 {
676 lb_output = new QLabel; 676 lb_output = new QLabel;
677 677
678 bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \ 678 bbx_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \
679 connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept())); \ 679 connect(bbx_buttons, SIGNAL(accepted()), this, SLOT(accept())); \
680 connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject())); \ 680 connect(bbx_buttons, SIGNAL(rejected()), this, SLOT(reject())); \
681 681
682 setWhatsThis (tr ("Into this dialog you can input a key sequence for use as a " 682 setWhatsThis(tr("Into this dialog you can input a key sequence for use as a "
683 "shortcut in LDForge. Use OK to confirm the new shortcut and Cancel to " 683 "shortcut in LDForge. Use OK to confirm the new shortcut and Cancel to "
684 "dismiss.")); 684 "dismiss."));
685 685
686 QVBoxLayout* layout = new QVBoxLayout; 686 QVBoxLayout* layout = new QVBoxLayout;
687 layout->addWidget (lb_output); 687 layout->addWidget(lb_output);
688 layout->addWidget (bbx_buttons); 688 layout->addWidget(bbx_buttons);
689 setLayout (layout); 689 setLayout(layout);
690 690
691 updateOutput(); 691 updateOutput();
692 } 692 }
693 693
694 // 694 //
695 // 695 //
696 bool KeySequenceDialog::staticDialog (ShortcutListItem* item, QWidget* parent) 696 bool KeySequenceDialog::staticDialog(ShortcutListItem* item, QWidget* parent)
697 { 697 {
698 KeySequenceDialog dlg (item->sequence(), parent); 698 KeySequenceDialog dlg(item->sequence(), parent);
699 699
700 if (dlg.exec() == QDialog::Rejected) 700 if (dlg.exec() == QDialog::Rejected)
701 return false; 701 return false;
702 702
703 item->setSequence (dlg.seq); 703 item->setSequence(dlg.seq);
704 return true; 704 return true;
705 } 705 }
706 706
707 // 707 //
708 // 708 //
711 QString shortcut = seq.toString(); 711 QString shortcut = seq.toString();
712 712
713 if (seq == QKeySequence()) 713 if (seq == QKeySequence())
714 shortcut = "&lt;empty&gt;"; 714 shortcut = "&lt;empty&gt;";
715 715
716 QString text = format ("<center><b>%1</b></center>", shortcut); 716 QString text = format("<center><b>%1</b></center>", shortcut);
717 lb_output->setText (text); 717 lb_output->setText(text);
718 } 718 }
719 719
720 // 720 //
721 // 721 //
722 void KeySequenceDialog::keyPressEvent (QKeyEvent* ev) 722 void KeySequenceDialog::keyPressEvent(QKeyEvent* ev)
723 { 723 {
724 seq = ev->key() + ev->modifiers(); 724 seq = ev->key() + ev->modifiers();
725 updateOutput(); 725 updateOutput();
726 } 726 }

mercurial