243 } |
243 } |
244 |
244 |
245 void ConfigDialog::_applyToWidgetOptions (std::function<void (QWidget*, AbstractConfigEntry*)> func) |
245 void ConfigDialog::_applyToWidgetOptions (std::function<void (QWidget*, AbstractConfigEntry*)> func) |
246 { |
246 { |
247 // Apply configuration |
247 // Apply configuration |
248 for (QWidget* wdg : findChildren<QWidget*>()) |
248 for (QWidget* widget : findChildren<QWidget*>()) |
249 { |
249 { |
250 if (not wdg->objectName().startsWith ("config")) |
250 if (not widget->objectName().startsWith ("config")) |
251 continue; |
251 continue; |
252 |
252 |
253 QString confname (wdg->objectName().mid (strlen ("config"))); |
253 QString confname (widget->objectName().mid (strlen ("config"))); |
254 AbstractConfigEntry* conf (Config::FindByName (confname)); |
254 AbstractConfigEntry* conf (Config::FindByName (confname)); |
255 |
255 |
256 if (conf == null) |
256 if (conf == null) |
257 { |
257 { |
258 print ("Couldn't find configuration entry named %1", confname); |
258 print ("Couldn't find configuration entry named %1", confname); |
259 continue; |
259 continue; |
260 } |
260 } |
261 |
261 |
262 func (wdg, conf); |
262 func (widget, conf); |
263 } |
263 } |
264 } |
264 } |
265 |
265 |
266 // |
266 // |
267 // Set the settings based on widget data. |
267 // Set the settings based on widget data. |
268 // |
268 // |
269 void ConfigDialog::applySettings() |
269 void ConfigDialog::applySettings() |
270 { |
270 { |
271 _applyToWidgetOptions ([&](QWidget* wdg, AbstractConfigEntry* conf) |
271 _applyToWidgetOptions ([&](QWidget* widget, AbstractConfigEntry* conf) |
272 { |
272 { |
273 QVariant value (conf->toVariant()); |
273 QVariant value (conf->toVariant()); |
274 QLineEdit* le; |
274 QLineEdit* le; |
275 QSpinBox* spinbox; |
275 QSpinBox* spinbox; |
276 QDoubleSpinBox* doublespinbox; |
276 QDoubleSpinBox* doublespinbox; |
277 QSlider* slider; |
277 QSlider* slider; |
278 QCheckBox* checkbox; |
278 QCheckBox* checkbox; |
279 QPushButton* button; |
279 QPushButton* button; |
280 |
280 |
281 if ((le = qobject_cast<QLineEdit*> (wdg)) != null) |
281 if ((le = qobject_cast<QLineEdit*> (widget)) != null) |
282 value = le->text(); |
282 value = le->text(); |
283 elif ((spinbox = qobject_cast<QSpinBox*> (wdg)) != null) |
283 elif ((spinbox = qobject_cast<QSpinBox*> (widget)) != null) |
284 value = spinbox->value(); |
284 value = spinbox->value(); |
285 elif ((doublespinbox = qobject_cast<QDoubleSpinBox*> (wdg)) != null) |
285 elif ((doublespinbox = qobject_cast<QDoubleSpinBox*> (widget)) != null) |
286 value = doublespinbox->value(); |
286 value = doublespinbox->value(); |
287 elif ((slider = qobject_cast<QSlider*> (wdg)) != null) |
287 elif ((slider = qobject_cast<QSlider*> (widget)) != null) |
288 value = slider->value(); |
288 value = slider->value(); |
289 elif ((checkbox = qobject_cast<QCheckBox*> (wdg)) != null) |
289 elif ((checkbox = qobject_cast<QCheckBox*> (widget)) != null) |
290 value = checkbox->isChecked(); |
290 value = checkbox->isChecked(); |
291 elif ((button = qobject_cast<QPushButton*> (wdg)) != null) |
291 elif ((button = qobject_cast<QPushButton*> (widget)) != null) |
292 value = _buttonColors[button]; |
292 value = _buttonColors[button]; |
293 else |
293 else |
294 print ("Unknown widget of type %1\n", wdg->metaObject()->className()); |
294 print ("Unknown widget of type %1\n", widget->metaObject()->className()); |
295 |
295 |
296 conf->loadFromVariant (value); |
296 conf->loadFromVariant (value); |
297 print ("Value of %1: %2\n", conf->name(), conf->toVariant().toString()); |
|
298 }); |
297 }); |
299 |
298 |
300 // Rebuild the quick color toolbar |
299 // Rebuild the quick color toolbar |
301 g_win->setQuickColors (quickColors); |
300 g_win->setQuickColors (quickColors); |
302 cfg::QuickColorToolbar = quickColorString(); |
301 cfg::QuickColorToolbar = quickColorString(); |
421 LDColor val; |
420 LDColor val; |
422 |
421 |
423 if (not ColorSelector::selectColor (val, defval, this)) |
422 if (not ColorSelector::selectColor (val, defval, this)) |
424 return; |
423 return; |
425 |
424 |
426 if (entry) |
425 if (entry != null) |
427 { |
426 { |
428 entry->setColor (val); |
427 entry->setColor (val); |
429 } |
428 } |
430 else |
429 else |
431 { |
430 { |
432 LDQuickColor entry (val, null); |
431 LDQuickColor entry (val, null); |
433 |
|
434 item = getSelectedQuickColor(); |
432 item = getSelectedQuickColor(); |
435 int idx = (item) ? getItemRow (item, quickColorItems) + 1 : quickColorItems.size(); |
433 int idx = (item) ? getItemRow (item, quickColorItems) + 1 : quickColorItems.size(); |
436 |
|
437 quickColors.insert (idx, entry); |
434 quickColors.insert (idx, entry); |
438 entry = quickColors[idx]; |
435 entry = quickColors[idx]; |
439 } |
436 } |
440 |
437 |
441 updateQuickColorList (entry); |
438 updateQuickColorList (entry); |
508 { |
502 { |
509 print ("setButtonColor: null sender!\n"); |
503 print ("setButtonColor: null sender!\n"); |
510 return; |
504 return; |
511 } |
505 } |
512 |
506 |
513 print ("Color of %1 is %2\n", button, _buttonColors[button].name()); |
507 QColor color = QColorDialog::getColor (_buttonColors[button]); |
514 QColor col = QColorDialog::getColor (_buttonColors[button]); |
508 |
515 |
509 if (color.isValid()) |
516 if (col.isValid()) |
510 { |
517 { |
511 QString colorname; |
518 int r = col.red(); |
512 colorname.sprintf ("#%.2X%.2X%.2X", color.red(), color.green(), color.blue()); |
519 int g = col.green(); |
513 setButtonBackground (button, colorname); |
520 int b = col.blue(); |
|
521 |
|
522 QString colname; |
|
523 colname.sprintf ("#%.2X%.2X%.2X", r, g, b); |
|
524 setButtonBackground (button, colname); |
|
525 } |
514 } |
526 } |
515 } |
527 |
516 |
528 // |
517 // |
529 // Sets background color of a given button. |
518 // Sets background color of a given button. |
532 { |
521 { |
533 button->setIcon (getIcon ("colorselect")); |
522 button->setIcon (getIcon ("colorselect")); |
534 button->setAutoFillBackground (true); |
523 button->setAutoFillBackground (true); |
535 button->setStyleSheet (format ("background-color: %1", value)); |
524 button->setStyleSheet (format ("background-color: %1", value)); |
536 _buttonColors[button] = QColor (value); |
525 _buttonColors[button] = QColor (value); |
537 print ("Color of %1 set to %2\n", button, value); |
|
538 } |
526 } |
539 |
527 |
540 // |
528 // |
541 // Finds the given list widget item in the list of widget items given. |
529 // Finds the given list widget item in the list of widget items given. |
542 // |
530 // |