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(); |
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 |
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 // |