src/configDialog.cpp

changeset 493
16766ac1bbd9
parent 491
7d1b5ecd76c0
child 498
791c831c8020
equal deleted inserted replaced
492:e964085e6913 493:16766ac1bbd9
82 // ============================================================================= 82 // =============================================================================
83 // ----------------------------------------------------------------------------- 83 // -----------------------------------------------------------------------------
84 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) : 84 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) :
85 QDialog (parent, f) 85 QDialog (parent, f)
86 { 86 {
87 assert (g_win); 87 assert (g_win != null);
88 ui = new Ui_ConfigUI; 88 ui = new Ui_ConfigUI;
89 ui->setupUi (this); 89 ui->setupUi (this);
90 90
91 // Interface tab 91 // Interface tab
92 setButtonBackground (ui->backgroundColorButton, gl_bgcolor); 92 setButtonBackground (ui->backgroundColorButton, gl_bgcolor);
93 connect (ui->backgroundColorButton, SIGNAL (clicked()), 93 connect (ui->backgroundColorButton, SIGNAL (clicked()),
94 this, SLOT (slot_setGLBackground())); 94 this, SLOT (slot_setGLBackground()));
95 95
96 setButtonBackground (ui->mainColorButton, gl_maincolor); 96 setButtonBackground (ui->mainColorButton, gl_maincolor);
97 connect (ui->mainColorButton, SIGNAL (clicked()), 97 connect (ui->mainColorButton, SIGNAL (clicked()),
98 this, SLOT (slot_setGLForeground())); 98 this, SLOT (slot_setGLForeground()));
99 99
100 ui->mainColorAlpha->setValue (gl_maincolor_alpha * 10.0f); 100 ui->mainColorAlpha->setValue (gl_maincolor_alpha * 10.0f);
101 ui->lineThickness->setValue (gl_linethickness); 101 ui->lineThickness->setValue (gl_linethickness);
102 ui->colorizeObjects->setChecked (lv_colorize); 102 ui->colorizeObjects->setChecked (lv_colorize);
103 ui->colorBFC->setChecked (gl_colorbfc); 103 ui->colorBFC->setChecked (gl_colorbfc);
104 ui->blackEdges->setChecked (gl_blackedges); 104 ui->blackEdges->setChecked (gl_blackedges);
105 ui->implicitFiles->setChecked (gui_implicitfiles); 105 ui->implicitFiles->setChecked (gui_implicitfiles);
106 ui->m_logostuds->setChecked (gl_logostuds); 106 ui->m_logostuds->setChecked (gl_logostuds);
107 107
108 ulong i = 0; 108 ulong i = 0;
109 #define act(N) addShortcut (key_##N, ACTION(N), i); 109 #define act(N) addShortcut (key_##N, ACTION(N), i);
110 #include "actions.h" 110 #include "actions.h"
111 111
112 ui->shortcutsList->setSortingEnabled (true); 112 ui->shortcutsList->setSortingEnabled (true);
113 ui->shortcutsList->sortItems(); 113 ui->shortcutsList->sortItems();
114 114
115 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut())); 115 connect (ui->shortcut_set, SIGNAL (clicked()), this, SLOT (slot_setShortcut()));
116 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut())); 116 connect (ui->shortcut_reset, SIGNAL (clicked()), this, SLOT (slot_resetShortcut()));
117 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut())); 117 connect (ui->shortcut_clear, SIGNAL (clicked()), this, SLOT (slot_clearShortcut()));
118 118
119 quickColors = quickColorsFromConfig(); 119 quickColors = quickColorsFromConfig();
120 updateQuickColorList(); 120 updateQuickColorList();
121 121
122 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor())); 122 connect (ui->quickColor_add, SIGNAL (clicked()), this, SLOT (slot_setColor()));
123 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor())); 123 connect (ui->quickColor_remove, SIGNAL (clicked()), this, SLOT (slot_delColor()));
124 connect (ui->quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor())); 124 connect (ui->quickColor_edit, SIGNAL (clicked()), this, SLOT (slot_setColor()));
125 connect (ui->quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator())); 125 connect (ui->quickColor_addSep, SIGNAL (clicked()), this, SLOT (slot_addColorSeparator()));
126 connect (ui->quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor())); 126 connect (ui->quickColor_moveUp, SIGNAL (clicked()), this, SLOT (slot_moveColor()));
127 connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor())); 127 connect (ui->quickColor_moveDown, SIGNAL (clicked()), this, SLOT (slot_moveColor()));
128 connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors())); 128 connect (ui->quickColor_clear, SIGNAL (clicked()), this, SLOT (slot_clearColors()));
129 129
130 ui->downloadPath->setText (net_downloadpath); 130 ui->downloadPath->setText (net_downloadpath);
131 ui->guessNetPaths->setChecked (net_guesspaths); 131 ui->guessNetPaths->setChecked (net_guesspaths);
132 ui->autoCloseNetPrompt->setChecked (net_autoclose); 132 ui->autoCloseNetPrompt->setChecked (net_autoclose);
133 connect (ui->findDownloadPath, SIGNAL (clicked(bool)), this, SLOT (slot_findDownloadFolder())); 133 connect (ui->findDownloadPath, SIGNAL (clicked (bool)), this, SLOT (slot_findDownloadFolder()));
134 134
135 ui->m_profileName->setText (ld_defaultname); 135 ui->m_profileName->setText (ld_defaultname);
136 ui->m_profileUsername->setText (ld_defaultuser); 136 ui->m_profileUsername->setText (ld_defaultuser);
137 ui->m_profileLicense->setCurrentIndex (ld_defaultlicense); 137 ui->m_profileLicense->setCurrentIndex (ld_defaultlicense);
138 ui->tabs->setCurrentIndex (deftab); 138 ui->tabs->setCurrentIndex (deftab);
139 139
140 initGrids(); 140 initGrids();
141 initExtProgs(); 141 initExtProgs();
142 142
143 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), 143 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)),
144 this, SLOT (buttonClicked(QAbstractButton*))); 144 this, SLOT (buttonClicked (QAbstractButton*)));
145 } 145 }
146 146
147 // ============================================================================= 147 // =============================================================================
148 // ----------------------------------------------------------------------------- 148 // -----------------------------------------------------------------------------
149 ConfigDialog::~ConfigDialog() { 149 ConfigDialog::~ConfigDialog()
150 delete ui; 150 { delete ui;
151 } 151 }
152 152
153 // ============================================================================= 153 // =============================================================================
154 // Adds a shortcut entry to the list of shortcuts. 154 // Adds a shortcut entry to the list of shortcuts.
155 // ----------------------------------------------------------------------------- 155 // -----------------------------------------------------------------------------
156 void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, ulong& i) { 156 void ConfigDialog::addShortcut (KeySequenceConfig& cfg, QAction* act, ulong& i)
157 ShortcutListItem* item = new ShortcutListItem; 157 { ShortcutListItem* item = new ShortcutListItem;
158 item->setIcon (act->icon()); 158 item->setIcon (act->icon());
159 item->setKeyConfig (&cfg); 159 item->setKeyConfig (&cfg);
160 item->setAction (act); 160 item->setAction (act);
161 setShortcutText (item); 161 setShortcutText (item);
162 162
163 // If the action doesn't have a valid icon, use an empty one 163 // If the action doesn't have a valid icon, use an empty one
164 // so that the list is kept aligned. 164 // so that the list is kept aligned.
165 if (act->icon().isNull()) 165 if (act->icon().isNull())
166 item->setIcon (getIcon ("empty")); 166 item->setIcon (getIcon ("empty"));
167 167
168 ui->shortcutsList->insertItem (i++, item); 168 ui->shortcutsList->insertItem (i++, item);
169 } 169 }
170 170
171 // ============================================================================= 171 // =============================================================================
172 // Initializes the table of grid stuff 172 // Initializes the table of grid stuff
173 // ----------------------------------------------------------------------------- 173 // -----------------------------------------------------------------------------
174 void ConfigDialog::initGrids() { 174 void ConfigDialog::initGrids()
175 QGridLayout* gridlayout = new QGridLayout; 175 { QGridLayout* gridlayout = new QGridLayout;
176 QLabel* xlabel = new QLabel ("X"), 176 QLabel* xlabel = new QLabel ("X"),
177 *ylabel = new QLabel ("Y"), 177 *ylabel = new QLabel ("Y"),
178 *zlabel = new QLabel ("Z"), 178 *zlabel = new QLabel ("Z"),
179 *anglabel = new QLabel ("Angle"); 179 *anglabel = new QLabel ("Angle");
180 short i = 1; 180 short i = 1;
181 181
182 for (QLabel* label : initlist<QLabel*> ({ xlabel, ylabel, zlabel, anglabel })) { 182 for (QLabel * label : initlist<QLabel*> ( { xlabel, ylabel, zlabel, anglabel }))
183 label->setAlignment (Qt::AlignCenter); 183 { label->setAlignment (Qt::AlignCenter);
184 gridlayout->addWidget (label, 0, i++); 184 gridlayout->addWidget (label, 0, i++);
185 } 185 }
186 186
187 for (int i = 0; i < g_NumGrids; ++i) { 187 for (int i = 0; i < g_NumGrids; ++i)
188 // Icon 188 { // Icon
189 lb_gridIcons[i] = new QLabel; 189 lb_gridIcons[i] = new QLabel;
190 lb_gridIcons[i]->setPixmap (getIcon (fmt ("grid-%1", str (g_GridInfo[i].name).toLower()))); 190 lb_gridIcons[i]->setPixmap (getIcon (fmt ("grid-%1", str (g_GridInfo[i].name).toLower())));
191 191
192 // Text label 192 // Text label
193 lb_gridLabels[i] = new QLabel (fmt ("%1:", g_GridInfo[i].name)); 193 lb_gridLabels[i] = new QLabel (fmt ("%1:", g_GridInfo[i].name));
194 194
195 QHBoxLayout* labellayout = new QHBoxLayout; 195 QHBoxLayout* labellayout = new QHBoxLayout;
196 labellayout->addWidget (lb_gridIcons[i]); 196 labellayout->addWidget (lb_gridIcons[i]);
197 labellayout->addWidget (lb_gridLabels[i]); 197 labellayout->addWidget (lb_gridLabels[i]);
198 gridlayout->addLayout (labellayout, i + 1, 0); 198 gridlayout->addLayout (labellayout, i + 1, 0);
199 199
200 // Add the widgets 200 // Add the widgets
201 for (int j = 0; j < 4; ++j) { 201 for (int j = 0; j < 4; ++j)
202 dsb_gridData[i][j] = new QDoubleSpinBox; 202 { dsb_gridData[i][j] = new QDoubleSpinBox;
203 dsb_gridData[i][j]->setValue (g_GridInfo[i].confs[j]->value); 203 dsb_gridData[i][j]->setValue (g_GridInfo[i].confs[j]->value);
204 gridlayout->addWidget (dsb_gridData[i][j], i + 1, j + 1); 204 gridlayout->addWidget (dsb_gridData[i][j], i + 1, j + 1);
205 } 205 }
206 } 206 }
207 207
208 ui->grids->setLayout (gridlayout); 208 ui->grids->setLayout (gridlayout);
209 } 209 }
210 210
211 // ============================================================================= 211 // =============================================================================
212 // ----------------------------------------------------------------------------- 212 // -----------------------------------------------------------------------------
213 static const struct extProgInfo { 213 static const struct extProgInfo
214 const str name, iconname; 214 { const str name, iconname;
215 StringConfig* const path; 215 StringConfig* const path;
216 mutable QLineEdit* input; 216 mutable QLineEdit* input;
217 mutable QPushButton* setPathButton; 217 mutable QPushButton* setPathButton;
218 #ifndef _WIN32 218 #ifndef _WIN32
219 BoolConfig* const wine; 219 BoolConfig* const wine;
220 mutable QCheckBox* wineBox; 220 mutable QCheckBox* wineBox;
221 #endif // _WIN32 221 #endif // _WIN32
222 } g_extProgInfo[] = { 222 } g_extProgInfo[] =
223 {
223 #ifndef _WIN32 224 #ifndef _WIN32
224 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null, &prog_##LOWNAME##_wine, null }, 225 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null, &prog_##LOWNAME##_wine, null },
225 #else 226 #else
226 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null }, 227 # define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &prog_##LOWNAME, null, null },
227 #endif 228 #endif
235 }; 236 };
236 237
237 // ============================================================================= 238 // =============================================================================
238 // Initializes the stuff in the ext programs tab 239 // Initializes the stuff in the ext programs tab
239 // ----------------------------------------------------------------------------- 240 // -----------------------------------------------------------------------------
240 void ConfigDialog::initExtProgs() { 241 void ConfigDialog::initExtProgs()
241 QGridLayout* pathsLayout = new QGridLayout; 242 { QGridLayout* pathsLayout = new QGridLayout;
242 ulong row = 0; 243 ulong row = 0;
243 244
244 for (const extProgInfo & info : g_extProgInfo) { 245 for (const extProgInfo & info : g_extProgInfo)
245 QLabel* icon = new QLabel, 246 { QLabel* icon = new QLabel,
246 *progLabel = new QLabel (info.name); 247 *progLabel = new QLabel (info.name);
247 QLineEdit* input = new QLineEdit; 248 QLineEdit* input = new QLineEdit;
248 QPushButton* setPathButton = new QPushButton; 249 QPushButton* setPathButton = new QPushButton;
249 250
250 icon->setPixmap (getIcon (info.iconname)); 251 icon->setPixmap (getIcon (info.iconname));
251 input->setText (info.path->value); 252 input->setText (info.path->value);
252 setPathButton->setIcon (getIcon ("folder")); 253 setPathButton->setIcon (getIcon ("folder"));
253 info.input = input; 254 info.input = input;
254 info.setPathButton = setPathButton; 255 info.setPathButton = setPathButton;
255 256
256 connect (setPathButton, SIGNAL (clicked()), this, SLOT (slot_setExtProgPath())); 257 connect (setPathButton, SIGNAL (clicked()), this, SLOT (slot_setExtProgPath()));
257 258
258 pathsLayout->addWidget (icon, row, 0); 259 pathsLayout->addWidget (icon, row, 0);
259 pathsLayout->addWidget (progLabel, row, 1); 260 pathsLayout->addWidget (progLabel, row, 1);
260 pathsLayout->addWidget (input, row, 2); 261 pathsLayout->addWidget (input, row, 2);
261 pathsLayout->addWidget (setPathButton, row, 3); 262 pathsLayout->addWidget (setPathButton, row, 3);
262 263
263 #ifndef _WIN32 264 #ifndef _WIN32
264 QCheckBox* wineBox = new QCheckBox ("Wine"); 265 QCheckBox* wineBox = new QCheckBox ("Wine");
265 wineBox->setChecked (*info.wine); 266 wineBox->setChecked (*info.wine);
266 info.wineBox = wineBox; 267 info.wineBox = wineBox;
267 pathsLayout->addWidget (wineBox, row, 4); 268 pathsLayout->addWidget (wineBox, row, 4);
268 #endif 269 #endif
269 270
270 ++row; 271 ++row;
271 } 272 }
272 273
273 ui->extProgs->setLayout (pathsLayout); 274 ui->extProgs->setLayout (pathsLayout);
274 } 275 }
275 276
276 // ============================================================================= 277 // =============================================================================
277 // Set the settings based on widget data. 278 // Set the settings based on widget data.
278 // ----------------------------------------------------------------------------- 279 // -----------------------------------------------------------------------------
279 void ConfigDialog::applySettings() { 280 void ConfigDialog::applySettings()
280 // Apply configuration 281 { // Apply configuration
281 lv_colorize = ui->colorizeObjects->isChecked(); 282 lv_colorize = ui->colorizeObjects->isChecked();
282 gl_colorbfc = ui->colorBFC->isChecked(); 283 gl_colorbfc = ui->colorBFC->isChecked();
283 gl_blackedges = ui->blackEdges->isChecked(); 284 gl_blackedges = ui->blackEdges->isChecked();
284 gl_maincolor_alpha = ((double) ui->mainColorAlpha->value()) / 10.0f; 285 gl_maincolor_alpha = ( (double) ui->mainColorAlpha->value()) / 10.0f;
285 gl_linethickness = ui->lineThickness->value(); 286 gl_linethickness = ui->lineThickness->value();
286 gui_implicitfiles = ui->implicitFiles->isChecked(); 287 gui_implicitfiles = ui->implicitFiles->isChecked();
287 net_downloadpath = ui->downloadPath->text(); 288 net_downloadpath = ui->downloadPath->text();
288 net_guesspaths = ui->guessNetPaths->isChecked(); 289 net_guesspaths = ui->guessNetPaths->isChecked();
289 net_autoclose = ui->autoCloseNetPrompt->isChecked(); 290 net_autoclose = ui->autoCloseNetPrompt->isChecked();
290 gl_logostuds = ui->m_logostuds->isChecked(); 291 gl_logostuds = ui->m_logostuds->isChecked();
291 ld_defaultuser = ui->m_profileUsername->text(); 292 ld_defaultuser = ui->m_profileUsername->text();
292 ld_defaultname = ui->m_profileName->text(); 293 ld_defaultname = ui->m_profileName->text();
293 ld_defaultlicense = ui->m_profileLicense->currentIndex(); 294 ld_defaultlicense = ui->m_profileLicense->currentIndex();
294 295
295 // Rebuild the quick color toolbar 296 // Rebuild the quick color toolbar
296 g_win->setQuickColors (quickColors); 297 g_win->setQuickColors (quickColors);
297 gui_colortoolbar = quickColorString(); 298 gui_colortoolbar = quickColorString();
298 299
299 // Set the grid settings 300 // Set the grid settings
300 for (int i = 0; i < g_NumGrids; ++i) 301 for (int i = 0; i < g_NumGrids; ++i)
301 for (int j = 0; j < 4; ++j) 302 for (int j = 0; j < 4; ++j)
302 g_GridInfo[i].confs[j]->value = dsb_gridData[i][j]->value(); 303 g_GridInfo[i].confs[j]->value = dsb_gridData[i][j]->value();
303 304
304 // Apply key shortcuts 305 // Apply key shortcuts
305 #define act(N) ACTION(N)->setShortcut (key_##N); 306 #define act(N) ACTION(N)->setShortcut (key_##N);
306 #include "actions.h" 307 #include "actions.h"
307 308
308 // Ext program settings 309 // Ext program settings
309 for (const extProgInfo & info : g_extProgInfo) { 310 for (const extProgInfo & info : g_extProgInfo)
310 *info.path = info.input->text(); 311 { *info.path = info.input->text();
311 312
312 #ifndef _WIN32 313 #ifndef _WIN32
313 *info.wine = info.wineBox->isChecked(); 314 *info.wine = info.wineBox->isChecked();
314 #endif // _WIN32 315 #endif // _WIN32
315 } 316 }
316 317
317 Config::save(); 318 Config::save();
318 reloadAllSubfiles(); 319 reloadAllSubfiles();
319 loadLogoedStuds(); 320 loadLogoedStuds();
320 g_win->R()->setBackground(); 321 g_win->R()->setBackground();
321 g_win->fullRefresh(); 322 g_win->fullRefresh();
324 } 325 }
325 326
326 // ============================================================================= 327 // =============================================================================
327 // A dialog button was clicked 328 // A dialog button was clicked
328 // ----------------------------------------------------------------------------- 329 // -----------------------------------------------------------------------------
329 void ConfigDialog::buttonClicked (QAbstractButton* button) { 330 void ConfigDialog::buttonClicked (QAbstractButton* button)
330 typedef QDialogButtonBox QDDB; 331 { typedef QDialogButtonBox QDDB;
331 QDialogButtonBox* dbb = ui->buttonBox; 332 QDialogButtonBox* dbb = ui->buttonBox;
332 333
333 if (button == dbb->button (QDDB::Ok)) { 334 if (button == dbb->button (QDDB::Ok))
334 applySettings(); 335 { applySettings();
335 accept(); 336 accept();
336 } elif (button == dbb->button (QDDB::Apply)) { 337 } elif (button == dbb->button (QDDB::Apply))
337 applySettings(); 338
338 } elif (button == dbb->button (QDDB::Cancel)) { 339 { applySettings();
339 reject(); 340 } elif (button == dbb->button (QDDB::Cancel))
341 { reject();
340 } 342 }
341 } 343 }
342 344
343 // ============================================================================= 345 // =============================================================================
344 // Update the list of color toolbar items in the quick color tab. 346 // Update the list of color toolbar items in the quick color tab.
345 // ----------------------------------------------------------------------------- 347 // -----------------------------------------------------------------------------
346 void ConfigDialog::updateQuickColorList (LDQuickColor* sel) { 348 void ConfigDialog::updateQuickColorList (LDQuickColor* sel)
347 for (QListWidgetItem* item : quickColorItems) 349 { for (QListWidgetItem * item : quickColorItems)
348 delete item; 350 delete item;
349 351
350 quickColorItems.clear(); 352 quickColorItems.clear();
351 353
352 // Init table items 354 // Init table items
353 for (LDQuickColor& entry : quickColors) { 355 for (LDQuickColor & entry : quickColors)
354 QListWidgetItem* item = new QListWidgetItem; 356 { QListWidgetItem* item = new QListWidgetItem;
355 357
356 if (entry.isSeparator()) { 358 if (entry.isSeparator())
357 item->setText ("--------"); 359 { item->setText ("--------");
358 item->setIcon (getIcon ("empty")); 360 item->setIcon (getIcon ("empty"));
359 } else { 361 }
360 LDColor* col = entry.color(); 362 else
361 363 { LDColor* col = entry.color();
362 if (col == null) { 364
363 item->setText ("[[unknown color]]"); 365 if (col == null)
366 { item->setText ("[[unknown color]]");
364 item->setIcon (getIcon ("error")); 367 item->setIcon (getIcon ("error"));
365 } else { 368 }
366 item->setText (col->name); 369 else
370 { item->setText (col->name);
367 item->setIcon (makeColorIcon (col, 16)); 371 item->setIcon (makeColorIcon (col, 16));
368 } 372 }
369 } 373 }
370 374
371 ui->quickColorList->addItem (item); 375 ui->quickColorList->addItem (item);
372 quickColorItems << item; 376 quickColorItems << item;
373 377
374 if (sel && &entry == sel) { 378 if (sel && &entry == sel)
375 ui->quickColorList->setCurrentItem (item); 379 { ui->quickColorList->setCurrentItem (item);
376 ui->quickColorList->scrollToItem (item); 380 ui->quickColorList->scrollToItem (item);
377 } 381 }
378 } 382 }
379 } 383 }
380 384
381 // ============================================================================= 385 // =============================================================================
382 // Quick colors: add or edit button was clicked. 386 // Quick colors: add or edit button was clicked.
383 // ----------------------------------------------------------------------------- 387 // -----------------------------------------------------------------------------
384 void ConfigDialog::slot_setColor() { 388 void ConfigDialog::slot_setColor()
385 LDQuickColor* entry = null; 389 { LDQuickColor* entry = null;
386 QListWidgetItem* item = null; 390 QListWidgetItem* item = null;
387 const bool isNew = static_cast<QPushButton*> (sender()) == ui->quickColor_add; 391 const bool isNew = static_cast<QPushButton*> (sender()) == ui->quickColor_add;
388 392
389 if (isNew == false) { 393 if (isNew == false)
390 item = getSelectedQuickColor(); 394 { item = getSelectedQuickColor();
391 395
392 if (!item) 396 if (!item)
393 return; 397 return;
394 398
395 ulong i = getItemRow (item, quickColorItems); 399 ulong i = getItemRow (item, quickColorItems);
396 entry = &quickColors[i]; 400 entry = &quickColors[i];
397 401
398 if (entry->isSeparator() == true) 402 if (entry->isSeparator() == true)
399 return; // don't color separators 403 return; // don't color separators
400 } 404 }
401 405
402 short defval = entry ? entry->color()->index : -1; 406 short defval = entry ? entry->color()->index : -1;
403 short val; 407 short val;
404 408
405 if (ColorSelector::getColor (val, defval, this) == false) 409 if (ColorSelector::getColor (val, defval, this) == false)
406 return; 410 return;
407 411
408 if (entry) 412 if (entry)
409 entry->setColor (getColor (val)); 413 entry->setColor (getColor (val));
410 else { 414 else
411 LDQuickColor entry (getColor (val), null); 415 { LDQuickColor entry (getColor (val), null);
412 416
413 item = getSelectedQuickColor(); 417 item = getSelectedQuickColor();
414 ulong idx; 418 ulong idx;
415 419
416 if (item) 420 if (item)
417 idx = getItemRow (item, quickColorItems) + 1; 421 idx = getItemRow (item, quickColorItems) + 1;
418 else 422 else
419 idx = quickColorItems.size(); 423 idx = quickColorItems.size();
420 424
421 quickColors.insert (idx, entry); 425 quickColors.insert (idx, entry);
422 entry = quickColors[idx]; 426 entry = quickColors[idx];
423 } 427 }
424 428
425 updateQuickColorList (entry); 429 updateQuickColorList (entry);
426 } 430 }
427 431
428 // ============================================================================= 432 // =============================================================================
429 // Remove a quick color 433 // Remove a quick color
430 // ----------------------------------------------------------------------------- 434 // -----------------------------------------------------------------------------
431 void ConfigDialog::slot_delColor() { 435 void ConfigDialog::slot_delColor()
432 if (ui->quickColorList->selectedItems().size() == 0) 436 { if (ui->quickColorList->selectedItems().size() == 0)
433 return; 437 return;
434 438
435 QListWidgetItem* item = ui->quickColorList->selectedItems() [0]; 439 QListWidgetItem* item = ui->quickColorList->selectedItems() [0];
436 quickColors.erase (getItemRow (item, quickColorItems)); 440 quickColors.erase (getItemRow (item, quickColorItems));
437 updateQuickColorList(); 441 updateQuickColorList();
438 } 442 }
439 443
440 // ============================================================================= 444 // =============================================================================
441 // Move a quick color up/down 445 // Move a quick color up/down
442 // ----------------------------------------------------------------------------- 446 // -----------------------------------------------------------------------------
443 void ConfigDialog::slot_moveColor() { 447 void ConfigDialog::slot_moveColor()
444 const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp); 448 { const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp);
445 449
446 if (ui->quickColorList->selectedItems().size() == 0) 450 if (ui->quickColorList->selectedItems().size() == 0)
447 return; 451 return;
448 452
449 QListWidgetItem* item = ui->quickColorList->selectedItems() [0]; 453 QListWidgetItem* item = ui->quickColorList->selectedItems() [0];
450 int idx = getItemRow (item, quickColorItems); 454 int idx = getItemRow (item, quickColorItems);
451 int dest = up ? (idx - 1) : (idx + 1); 455 int dest = up ? (idx - 1) : (idx + 1);
452 456
453 if (dest < 0 || (ulong) dest >= quickColorItems.size()) 457 if (dest < 0 || (ulong) dest >= quickColorItems.size())
454 return; // destination out of bounds 458 return; // destination out of bounds
455 459
456 LDQuickColor tmp = quickColors[dest]; 460 LDQuickColor tmp = quickColors[dest];
457 quickColors[dest] = quickColors[idx]; 461 quickColors[dest] = quickColors[idx];
458 quickColors[idx] = tmp; 462 quickColors[idx] = tmp;
459 463
460 updateQuickColorList (&quickColors[dest]); 464 updateQuickColorList (&quickColors[dest]);
461 } 465 }
462 466
463 // ============================================================================= 467 // =============================================================================
464 // Add a separator to quick colors 468 // Add a separator to quick colors
465 // ----------------------------------------------------------------------------- 469 // -----------------------------------------------------------------------------
466 void ConfigDialog::slot_addColorSeparator() { 470 void ConfigDialog::slot_addColorSeparator()
467 quickColors << LDQuickColor::getSeparator(); 471 { quickColors << LDQuickColor::getSeparator();
468 updateQuickColorList (&quickColors[quickColors.size() - 1]); 472 updateQuickColorList (&quickColors[quickColors.size() - 1]);
469 } 473 }
470 474
471 // ============================================================================= 475 // =============================================================================
472 // Clear all quick colors 476 // Clear all quick colors
473 // ----------------------------------------------------------------------------- 477 // -----------------------------------------------------------------------------
474 void ConfigDialog::slot_clearColors() { 478 void ConfigDialog::slot_clearColors()
475 quickColors.clear(); 479 { quickColors.clear();
476 updateQuickColorList(); 480 updateQuickColorList();
477 } 481 }
478 482
479 // ============================================================================= 483 // =============================================================================
480 // Pick a color and set the appropriate configuration option. 484 // Pick a color and set the appropriate configuration option.
481 // ----------------------------------------------------------------------------- 485 // -----------------------------------------------------------------------------
482 void ConfigDialog::pickColor (StringConfig& conf, QPushButton* button) { 486 void ConfigDialog::pickColor (StringConfig& conf, QPushButton* button)
483 QColor col = QColorDialog::getColor (QColor (conf)); 487 { QColor col = QColorDialog::getColor (QColor (conf));
484 488
485 if (col.isValid()) { 489 if (col.isValid())
486 uchar r = col.red(), 490 { uchar r = col.red(),
487 g = col.green(), 491 g = col.green(),
488 b = col.blue(); 492 b = col.blue();
489 conf.value.sprintf ("#%.2X%.2X%.2X", r, g, b); 493 conf.value.sprintf ("#%.2X%.2X%.2X", r, g, b);
490 setButtonBackground (button, conf.value); 494 setButtonBackground (button, conf.value);
491 } 495 }
492 } 496 }
493 497
494 // ============================================================================= 498 // =============================================================================
495 // ----------------------------------------------------------------------------- 499 // -----------------------------------------------------------------------------
496 void ConfigDialog::slot_setGLBackground() { 500 void ConfigDialog::slot_setGLBackground()
497 pickColor (gl_bgcolor, ui->backgroundColorButton); 501 { pickColor (gl_bgcolor, ui->backgroundColorButton);
498 } 502 }
499 503
500 // ============================================================================= 504 // =============================================================================
501 // ----------------------------------------------------------------------------- 505 // -----------------------------------------------------------------------------
502 void ConfigDialog::slot_setGLForeground() { 506 void ConfigDialog::slot_setGLForeground()
503 pickColor (gl_maincolor, ui->mainColorButton); 507 { pickColor (gl_maincolor, ui->mainColorButton);
504 } 508 }
505 509
506 // ============================================================================= 510 // =============================================================================
507 // Sets background color of a given button. 511 // Sets background color of a given button.
508 // ----------------------------------------------------------------------------- 512 // -----------------------------------------------------------------------------
509 void ConfigDialog::setButtonBackground (QPushButton* button, str value) { 513 void ConfigDialog::setButtonBackground (QPushButton* button, str value)
510 button->setIcon (getIcon ("colorselect")); 514 { button->setIcon (getIcon ("colorselect"));
511 button->setAutoFillBackground (true); 515 button->setAutoFillBackground (true);
512 button->setStyleSheet (fmt ("background-color: %1", value)); 516 button->setStyleSheet (fmt ("background-color: %1", value));
513 } 517 }
514 518
515 // ============================================================================= 519 // =============================================================================
516 // Finds the given list widget item in the list of widget items given. 520 // Finds the given list widget item in the list of widget items given.
517 // ----------------------------------------------------------------------------- 521 // -----------------------------------------------------------------------------
518 int ConfigDialog::getItemRow (QListWidgetItem* item, List<QListWidgetItem*>& haystack) { 522 int ConfigDialog::getItemRow (QListWidgetItem* item, List<QListWidgetItem*>& haystack)
519 int i = 0; 523 { int i = 0;
520 524
521 for (QListWidgetItem* it : haystack) { 525 for (QListWidgetItem * it : haystack)
522 if (it == item) 526 { if (it == item)
523 return i; 527 return i;
524 528
525 ++i; 529 ++i;
526 } 530 }
531
527 return -1; 532 return -1;
528 } 533 }
529 534
530 // ============================================================================= 535 // =============================================================================
531 // Which quick color is currently selected? 536 // Which quick color is currently selected?
532 // ----------------------------------------------------------------------------- 537 // -----------------------------------------------------------------------------
533 QListWidgetItem* ConfigDialog::getSelectedQuickColor() { 538 QListWidgetItem* ConfigDialog::getSelectedQuickColor()
534 if (ui->quickColorList->selectedItems().size() == 0) 539 { if (ui->quickColorList->selectedItems().size() == 0)
535 return null; 540 return null;
536 541
537 return ui->quickColorList->selectedItems()[0]; 542 return ui->quickColorList->selectedItems() [0];
538 } 543 }
539 544
540 // ============================================================================= 545 // =============================================================================
541 // Get the list of shortcuts selected 546 // Get the list of shortcuts selected
542 // ----------------------------------------------------------------------------- 547 // -----------------------------------------------------------------------------
543 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection() { 548 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection()
544 QList<ShortcutListItem*> out; 549 { QList<ShortcutListItem*> out;
545 550
546 for (QListWidgetItem* entry : ui->shortcutsList->selectedItems()) 551 for (QListWidgetItem * entry : ui->shortcutsList->selectedItems())
547 out << static_cast<ShortcutListItem*> (entry); 552 out << static_cast<ShortcutListItem*> (entry);
548 553
549 return out; 554 return out;
550 } 555 }
551 556
552 // ============================================================================= 557 // =============================================================================
553 // Edit the shortcut of a given action. 558 // Edit the shortcut of a given action.
554 // ----------------------------------------------------------------------------- 559 // -----------------------------------------------------------------------------
555 void ConfigDialog::slot_setShortcut() { 560 void ConfigDialog::slot_setShortcut()
556 QList<ShortcutListItem*> sel = getShortcutSelection(); 561 { QList<ShortcutListItem*> sel = getShortcutSelection();
557 562
558 if (sel.size() < 1) 563 if (sel.size() < 1)
559 return; 564 return;
560 565
561 ShortcutListItem* item = sel[0]; 566 ShortcutListItem* item = sel[0];
562 567
563 if (KeySequenceDialog::staticDialog (item->keyConfig(), this)) 568 if (KeySequenceDialog::staticDialog (item->keyConfig(), this))
564 setShortcutText (item); 569 setShortcutText (item);
565 } 570 }
566 571
567 // ============================================================================= 572 // =============================================================================
568 // Reset a shortcut to defaults 573 // Reset a shortcut to defaults
569 // ----------------------------------------------------------------------------- 574 // -----------------------------------------------------------------------------
570 void ConfigDialog::slot_resetShortcut() { 575 void ConfigDialog::slot_resetShortcut()
571 QList<ShortcutListItem*> sel = getShortcutSelection(); 576 { QList<ShortcutListItem*> sel = getShortcutSelection();
572 577
573 for (ShortcutListItem* item : sel) { 578 for (ShortcutListItem * item : sel)
574 item->keyConfig()->reset(); 579 { item->keyConfig()->reset();
575 setShortcutText (item); 580 setShortcutText (item);
576 } 581 }
577 } 582 }
578 583
579 // ============================================================================= 584 // =============================================================================
580 // Remove the shortcut of an action. 585 // Remove the shortcut of an action.
581 // ----------------------------------------------------------------------------- 586 // -----------------------------------------------------------------------------
582 void ConfigDialog::slot_clearShortcut() { 587 void ConfigDialog::slot_clearShortcut()
583 QList<ShortcutListItem*> sel = getShortcutSelection(); 588 { QList<ShortcutListItem*> sel = getShortcutSelection();
584 589
585 for (ShortcutListItem* item : sel) { 590 for (ShortcutListItem * item : sel)
586 item->keyConfig()->value = QKeySequence(); 591 { item->keyConfig()->value = QKeySequence();
587 setShortcutText (item); 592 setShortcutText (item);
588 } 593 }
589 } 594 }
590 595
591 // ============================================================================= 596 // =============================================================================
592 // Set the path of an external program 597 // Set the path of an external program
593 // ----------------------------------------------------------------------------- 598 // -----------------------------------------------------------------------------
594 void ConfigDialog::slot_setExtProgPath() { 599 void ConfigDialog::slot_setExtProgPath()
595 const extProgInfo* info = null; 600 { const extProgInfo* info = null;
596 601
597 for (const extProgInfo& it : g_extProgInfo) { 602 for (const extProgInfo & it : g_extProgInfo)
598 if (it.setPathButton == sender()) { 603 { if (it.setPathButton == sender())
599 info = &it; 604 { info = &it;
600 break; 605 break;
601 } 606 }
602 } 607 }
603 608
604 assert (info != null); 609 assert (info != null);
605 str fpath = QFileDialog::getOpenFileName (this, fmt ("Path to %1", info->name), *info->path, g_extProgPathFilter); 610 str fpath = QFileDialog::getOpenFileName (this, fmt ("Path to %1", info->name), *info->path, g_extProgPathFilter);
606 611
607 if (fpath.isEmpty()) 612 if (fpath.isEmpty())
608 return; 613 return;
609 614
610 info->input->setText (fpath); 615 info->input->setText (fpath);
611 } 616 }
612 617
613 // ============================================================================= 618 // =============================================================================
614 // '...' button pressed for the download path 619 // '...' button pressed for the download path
615 // ----------------------------------------------------------------------------- 620 // -----------------------------------------------------------------------------
616 void ConfigDialog::slot_findDownloadFolder() { 621 void ConfigDialog::slot_findDownloadFolder()
617 str dpath = QFileDialog::getExistingDirectory(); 622 { str dpath = QFileDialog::getExistingDirectory();
618 ui->downloadPath->setText (dpath); 623 ui->downloadPath->setText (dpath);
619 } 624 }
620 625
621 // ============================================================================= 626 // =============================================================================
622 // Updates the text string for a given shortcut list item 627 // Updates the text string for a given shortcut list item
623 // ----------------------------------------------------------------------------- 628 // -----------------------------------------------------------------------------
624 void ConfigDialog::setShortcutText (ShortcutListItem* item) { 629 void ConfigDialog::setShortcutText (ShortcutListItem* item)
625 QAction* act = item->action(); 630 { QAction* act = item->action();
626 str label = act->iconText(); 631 str label = act->iconText();
627 str keybind = item->keyConfig()->value.toString(); 632 str keybind = item->keyConfig()->value.toString();
628 item->setText (fmt ("%1 (%2)", label, keybind)); 633 item->setText (fmt ("%1 (%2)", label, keybind));
629 } 634 }
630 635
631 // ============================================================================= 636 // =============================================================================
632 // Gets the configuration string of the quick color toolbar 637 // Gets the configuration string of the quick color toolbar
633 // ----------------------------------------------------------------------------- 638 // -----------------------------------------------------------------------------
634 str ConfigDialog::quickColorString() { 639 str ConfigDialog::quickColorString()
635 str val; 640 { str val;
636 641
637 for (const LDQuickColor& entry : quickColors) { 642 for (const LDQuickColor & entry : quickColors)
638 if (val.length() > 0) 643 { if (val.length() > 0)
639 val += ':'; 644 val += ':';
640 645
641 if (entry.isSeparator()) 646 if (entry.isSeparator())
642 val += '|'; 647 val += '|';
643 else 648 else
644 val += fmt ("%1", entry.color()->index); 649 val += fmt ("%1", entry.color()->index);
645 } 650 }
646 651
647 return val; 652 return val;
648 } 653 }
649 654
650 // ========================================================================================================================= 655 // =========================================================================================================================
651 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 656 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
653 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 658 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
654 // ========================================================================================================================= 659 // =========================================================================================================================
655 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 660 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
656 // ========================================================================================================================= 661 // =========================================================================================================================
657 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) : 662 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) :
658 QDialog (parent, f), seq (seq) { 663 QDialog (parent, f), seq (seq)
659 lb_output = new QLabel; 664 { lb_output = new QLabel;
660 IMPLEMENT_DIALOG_BUTTONS 665 IMPLEMENT_DIALOG_BUTTONS
661 666
662 setWhatsThis ("Into this dialog you can input a key sequence for use as a " 667 setWhatsThis ("Into this dialog you can input a key sequence for use as a "
663 "shortcut in LDForge. Use OK to confirm the new shortcut and Cancel to " 668 "shortcut in LDForge. Use OK to confirm the new shortcut and Cancel to "
664 "dismiss."); 669 "dismiss.");
665 670
666 QVBoxLayout* layout = new QVBoxLayout; 671 QVBoxLayout* layout = new QVBoxLayout;
667 layout->addWidget (lb_output); 672 layout->addWidget (lb_output);
668 layout->addWidget (bbx_buttons); 673 layout->addWidget (bbx_buttons);
669 setLayout (layout); 674 setLayout (layout);
670 675
671 updateOutput(); 676 updateOutput();
672 } 677 }
673 678
674 // ============================================================================= 679 // =============================================================================
675 // ----------------------------------------------------------------------------- 680 // -----------------------------------------------------------------------------
676 bool KeySequenceDialog::staticDialog (KeySequenceConfig* cfg, QWidget* parent) { 681 bool KeySequenceDialog::staticDialog (KeySequenceConfig* cfg, QWidget* parent)
677 KeySequenceDialog dlg (cfg->value, parent); 682 { KeySequenceDialog dlg (cfg->value, parent);
678 683
679 if (dlg.exec() == false) 684 if (dlg.exec() == false)
680 return false; 685 return false;
681 686
682 cfg->value = dlg.seq; 687 cfg->value = dlg.seq;
683 return true; 688 return true;
684 } 689 }
685 690
686 // ============================================================================= 691 // =============================================================================
687 // ----------------------------------------------------------------------------- 692 // -----------------------------------------------------------------------------
688 void KeySequenceDialog::updateOutput() { 693 void KeySequenceDialog::updateOutput()
689 str shortcut = seq.toString(); 694 { str shortcut = seq.toString();
690 695
691 if (seq == QKeySequence()) 696 if (seq == QKeySequence())
692 shortcut = "&lt;empty&gt;"; 697 shortcut = "&lt;empty&gt;";
693 698
694 str text = fmt ("<center><b>%1</b></center>", shortcut); 699 str text = fmt ("<center><b>%1</b></center>", shortcut);
695 lb_output->setText (text); 700 lb_output->setText (text);
696 } 701 }
697 702
698 // ============================================================================= 703 // =============================================================================
699 // ----------------------------------------------------------------------------- 704 // -----------------------------------------------------------------------------
700 void KeySequenceDialog::keyPressEvent (QKeyEvent* ev) { 705 void KeySequenceDialog::keyPressEvent (QKeyEvent* ev)
701 seq = ev->key() + ev->modifiers(); 706 { seq = ev->key() + ev->modifiers();
702 updateOutput(); 707 updateOutput();
703 } 708 }
704 #include "moc_configDialog.cpp" 709 #include "moc_configDialog.cpp"

mercurial