src/configDialog.cpp

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

mercurial