Changeset View
Changeset View
Standalone View
Standalone View
mainWindow/kpMainWindow_Colors.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 56 | { | |||
---|---|---|---|---|---|
65 | d->actionColorsKDE = ac->add <KSelectAction> ("colors_kde"); | 65 | d->actionColorsKDE = ac->add <KSelectAction> ("colors_kde"); | ||
66 | d->actionColorsKDE->setText (i18nc ("@item:inmenu colors", "Use KDE's")); | 66 | d->actionColorsKDE->setText (i18nc ("@item:inmenu colors", "Use KDE's")); | ||
67 | // TODO: Will this slot be called spuriously if there are no colors | 67 | // TODO: Will this slot be called spuriously if there are no colors | ||
68 | // installed? | 68 | // installed? | ||
69 | connect (d->actionColorsKDE, | 69 | connect (d->actionColorsKDE, | ||
70 | static_cast<void (KSelectAction::*)(QAction*)>(&KSelectAction::triggered), | 70 | static_cast<void (KSelectAction::*)(QAction*)>(&KSelectAction::triggered), | ||
71 | this, &kpMainWindow::slotColorsKDE); | 71 | this, &kpMainWindow::slotColorsKDE); | ||
72 | 72 | | |||
73 | foreach (const QString &colName, ::KDEColorCollectionNames ()) | 73 | for (const auto &colName : ::KDEColorCollectionNames ()) { | ||
74 | d->actionColorsKDE->addAction (colName); | 74 | d->actionColorsKDE->addAction (colName); | ||
75 | } | ||||
75 | 76 | | |||
76 | d->actionColorsOpen = ac->addAction ("colors_open"); | 77 | d->actionColorsOpen = ac->addAction ("colors_open"); | ||
77 | d->actionColorsOpen->setText (i18nc ("@item:inmenu colors", "&Open...")); | 78 | d->actionColorsOpen->setText (i18nc ("@item:inmenu colors", "&Open...")); | ||
78 | connect (d->actionColorsOpen, &QAction::triggered, this, &kpMainWindow::slotColorsOpen); | 79 | connect (d->actionColorsOpen, &QAction::triggered, this, &kpMainWindow::slotColorsOpen); | ||
79 | 80 | | |||
80 | d->actionColorsReload = ac->addAction ("colors_reload"); | 81 | d->actionColorsReload = ac->addAction ("colors_reload"); | ||
81 | d->actionColorsReload->setText (i18nc ("@item:inmenu colors", "Reloa&d")); | 82 | d->actionColorsReload->setText (i18nc ("@item:inmenu colors", "Reloa&d")); | ||
82 | connect (d->actionColorsReload, &QAction::triggered, | 83 | connect (d->actionColorsReload, &QAction::triggered, | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | |||||
179 | // private | 180 | // private | ||
180 | bool kpMainWindow::queryCloseColors () | 181 | bool kpMainWindow::queryCloseColors () | ||
181 | { | 182 | { | ||
182 | qCDebug(kpLogMainWindow) << "kpMainWindow::queryCloseColors() colorCells.modified=" | 183 | qCDebug(kpLogMainWindow) << "kpMainWindow::queryCloseColors() colorCells.modified=" | ||
183 | << colorCells ()->isModified (); | 184 | << colorCells ()->isModified (); | ||
184 | 185 | | |||
185 | toolEndShape (); | 186 | toolEndShape (); | ||
186 | 187 | | |||
187 | if (!colorCells ()->isModified ()) | 188 | if (!colorCells ()->isModified ()) { | ||
188 | return true; // ok to close | 189 | return true; // ok to close | ||
190 | } | ||||
189 | 191 | | |||
190 | int result = KMessageBox::Cancel; | 192 | int result = KMessageBox::Cancel; | ||
191 | 193 | | |||
192 | 194 | | |||
193 | if (!colorCells ()->url ().isEmpty ()) | 195 | if (!colorCells ()->url ().isEmpty ()) | ||
194 | { | 196 | { | ||
195 | result = KMessageBox::warningYesNoCancel (this, | 197 | result = KMessageBox::warningYesNoCancel (this, | ||
196 | i18n ("The color palette \"%1\" has been modified.\n" | 198 | i18n ("The color palette \"%1\" has been modified.\n" | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
245 | //--------------------------------------------------------------------- | 247 | //--------------------------------------------------------------------- | ||
246 | 248 | | |||
247 | // private slot | 249 | // private slot | ||
248 | void kpMainWindow::slotColorsDefault () | 250 | void kpMainWindow::slotColorsDefault () | ||
249 | { | 251 | { | ||
250 | // Call just in case. | 252 | // Call just in case. | ||
251 | toolEndShape (); | 253 | toolEndShape (); | ||
252 | 254 | | |||
253 | if (!queryCloseColors ()) | 255 | if (!queryCloseColors ()) { | ||
254 | return; | 256 | return; | ||
257 | } | ||||
255 | 258 | | |||
256 | openDefaultColors (); | 259 | openDefaultColors (); | ||
257 | 260 | | |||
258 | deselectActionColorsKDE (); | 261 | deselectActionColorsKDE (); | ||
259 | } | 262 | } | ||
260 | 263 | | |||
261 | //--------------------------------------------------------------------- | 264 | //--------------------------------------------------------------------- | ||
262 | 265 | | |||
263 | // private | 266 | // private | ||
264 | bool kpMainWindow::openKDEColors (const QString &name) | 267 | bool kpMainWindow::openKDEColors (const QString &name) | ||
265 | { | 268 | { | ||
266 | qCDebug(kpLogMainWindow) << "kpMainWindow::openKDEColors(" << name << ")"; | 269 | qCDebug(kpLogMainWindow) << "kpMainWindow::openKDEColors(" << name << ")"; | ||
267 | 270 | | |||
268 | kpColorCollection colorCol; | 271 | kpColorCollection colorCol; | ||
269 | if (colorCol.openKDE (name, this)) | 272 | if (colorCol.openKDE (name, this)) | ||
270 | { | 273 | { | ||
271 | qCDebug(kpLogMainWindow) << "opened"; | 274 | qCDebug(kpLogMainWindow) << "opened"; | ||
272 | colorCells ()->setColorCollection (colorCol); | 275 | colorCells ()->setColorCollection (colorCol); | ||
273 | return true; | 276 | return true; | ||
274 | } | 277 | } | ||
275 | else | 278 | | ||
276 | { | | |||
277 | qCDebug(kpLogMainWindow) << "failed to open"; | 279 | qCDebug(kpLogMainWindow) << "failed to open"; | ||
278 | return false; | 280 | return false; | ||
279 | } | 281 | } | ||
280 | } | | |||
281 | 282 | | |||
282 | //--------------------------------------------------------------------- | 283 | //--------------------------------------------------------------------- | ||
283 | 284 | | |||
284 | // private slot | 285 | // private slot | ||
285 | void kpMainWindow::slotColorsKDE () | 286 | void kpMainWindow::slotColorsKDE () | ||
286 | { | 287 | { | ||
287 | // Call in case an error dialog appears. | 288 | // Call in case an error dialog appears. | ||
288 | toolEndShape (); | 289 | toolEndShape (); | ||
289 | 290 | | |||
290 | const int curItem = d->actionColorsKDE->currentItem (); | 291 | const int curItem = d->actionColorsKDE->currentItem (); | ||
291 | 292 | | |||
292 | if (!queryCloseColors ()) | 293 | if (!queryCloseColors ()) | ||
293 | { | 294 | { | ||
294 | deselectActionColorsKDE (); | 295 | deselectActionColorsKDE (); | ||
295 | return; | 296 | return; | ||
296 | } | 297 | } | ||
297 | else | 298 | | ||
298 | { | | |||
299 | // queryCloseColors() calls slotColorSave(), which can call | 299 | // queryCloseColors() calls slotColorSave(), which can call | ||
300 | // slotColorSaveAs(), which can call deselectActionColorsKDE(). | 300 | // slotColorSaveAs(), which can call deselectActionColorsKDE(). | ||
301 | d->actionColorsKDE->setCurrentItem (curItem); | 301 | d->actionColorsKDE->setCurrentItem (curItem); | ||
302 | } | | |||
303 | 302 | | |||
304 | const QStringList colNames = ::KDEColorCollectionNames (); | 303 | const QStringList colNames = ::KDEColorCollectionNames (); | ||
305 | const int selected = d->actionColorsKDE->currentItem (); | 304 | const int selected = d->actionColorsKDE->currentItem (); | ||
306 | Q_ASSERT (selected >= 0 && selected < colNames.size ()); | 305 | Q_ASSERT (selected >= 0 && selected < colNames.size ()); | ||
307 | 306 | | |||
308 | if (!openKDEColors (colNames [selected])) | 307 | if (!openKDEColors (colNames [selected])) { | ||
309 | deselectActionColorsKDE (); | 308 | deselectActionColorsKDE (); | ||
310 | } | 309 | } | ||
310 | } | ||||
311 | 311 | | |||
312 | //--------------------------------------------------------------------- | 312 | //--------------------------------------------------------------------- | ||
313 | 313 | | |||
314 | // private | 314 | // private | ||
315 | bool kpMainWindow::openColors (const QUrl &url) | 315 | bool kpMainWindow::openColors (const QUrl &url) | ||
316 | { | 316 | { | ||
317 | if (!colorCells ()->openColorCollection (url)) | 317 | return colorCells ()->openColorCollection (url); | ||
318 | return false; | | |||
319 | | ||||
320 | return true; | | |||
321 | } | 318 | } | ||
322 | 319 | | |||
323 | //--------------------------------------------------------------------- | 320 | //--------------------------------------------------------------------- | ||
324 | 321 | | |||
325 | // private slot | 322 | // private slot | ||
326 | void kpMainWindow::slotColorsOpen () | 323 | void kpMainWindow::slotColorsOpen () | ||
327 | { | 324 | { | ||
328 | // Call due to dialog. | 325 | // Call due to dialog. | ||
329 | toolEndShape (); | 326 | toolEndShape (); | ||
330 | 327 | | |||
331 | QFileDialog fd(this); | 328 | QFileDialog fd(this); | ||
332 | fd.setDirectoryUrl(colorCells ()->url()); | 329 | fd.setDirectoryUrl(colorCells ()->url()); | ||
333 | fd.setWindowTitle(i18nc ("@title:window", "Open Color Palette")); | 330 | fd.setWindowTitle(i18nc ("@title:window", "Open Color Palette")); | ||
334 | 331 | | |||
335 | if (fd.exec ()) | 332 | if (fd.exec ()) | ||
336 | { | 333 | { | ||
337 | if (!queryCloseColors ()) | 334 | if (!queryCloseColors ()) { | ||
338 | return; | 335 | return; | ||
336 | } | ||||
339 | 337 | | |||
340 | QList<QUrl> selected = fd.selectedUrls(); | 338 | QList<QUrl> selected = fd.selectedUrls(); | ||
341 | if ( selected.count() && openColors(selected[0]) ) | 339 | if ( selected.count() && openColors(selected[0]) ) { | ||
342 | deselectActionColorsKDE(); | 340 | deselectActionColorsKDE(); | ||
343 | } | 341 | } | ||
344 | } | 342 | } | ||
343 | } | ||||
345 | 344 | | |||
346 | //--------------------------------------------------------------------- | 345 | //--------------------------------------------------------------------- | ||
347 | 346 | | |||
348 | // private slot | 347 | // private slot | ||
349 | void kpMainWindow::slotColorsReload () | 348 | void kpMainWindow::slotColorsReload () | ||
350 | { | 349 | { | ||
351 | toolEndShape (); | 350 | toolEndShape (); | ||
352 | 351 | | |||
Show All 32 Lines | 382 | i18n ("The default color palette has been modified.\n" | |||
385 | "Are you sure?"), | 384 | "Are you sure?"), | ||
386 | QString ()/*caption*/, | 385 | QString ()/*caption*/, | ||
387 | KGuiItem (i18n ("&Reload"))); | 386 | KGuiItem (i18n ("&Reload"))); | ||
388 | } | 387 | } | ||
389 | } | 388 | } | ||
390 | 389 | | |||
391 | qCDebug(kpLogMainWindow) << "result=" << result | 390 | qCDebug(kpLogMainWindow) << "result=" << result | ||
392 | << "vs KMessageBox::Continue" << KMessageBox::Continue; | 391 | << "vs KMessageBox::Continue" << KMessageBox::Continue; | ||
393 | if (result != KMessageBox::Continue) | 392 | if (result != KMessageBox::Continue) { | ||
394 | return; | 393 | return; | ||
395 | } | 394 | } | ||
395 | } | ||||
396 | 396 | | |||
397 | 397 | | |||
398 | if (!colorCells ()->url ().isEmpty ()) | 398 | if (!colorCells ()->url ().isEmpty ()) | ||
399 | { | 399 | { | ||
400 | openColors (colorCells ()->url ()); | 400 | openColors (colorCells ()->url ()); | ||
401 | } | 401 | } | ||
402 | else | 402 | else | ||
403 | { | 403 | { | ||
404 | const QString name = colorCells ()->colorCollection ()->name (); | 404 | const QString name = colorCells ()->colorCollection ()->name (); | ||
405 | if (!name.isEmpty ()) | 405 | if (!name.isEmpty ()) { | ||
406 | openKDEColors (name); | 406 | openKDEColors (name); | ||
407 | else | 407 | } | ||
408 | else { | ||||
408 | openDefaultColors (); | 409 | openDefaultColors (); | ||
409 | } | 410 | } | ||
410 | } | 411 | } | ||
412 | } | ||||
411 | 413 | | |||
412 | //--------------------------------------------------------------------- | 414 | //--------------------------------------------------------------------- | ||
413 | 415 | | |||
414 | 416 | | |||
415 | // private slot | 417 | // private slot | ||
416 | bool kpMainWindow::slotColorsSave () | 418 | bool kpMainWindow::slotColorsSave () | ||
417 | { | 419 | { | ||
418 | // Call due to dialog. | 420 | // Call due to dialog. | ||
Show All 18 Lines | 435 | { | |||
437 | QFileDialog fd(this); | 439 | QFileDialog fd(this); | ||
438 | fd.setDirectoryUrl(colorCells ()->url()); | 440 | fd.setDirectoryUrl(colorCells ()->url()); | ||
439 | fd.setWindowTitle(i18n("Save Color Palette As")); | 441 | fd.setWindowTitle(i18n("Save Color Palette As")); | ||
440 | fd.setAcceptMode(QFileDialog::AcceptSave); | 442 | fd.setAcceptMode(QFileDialog::AcceptSave); | ||
441 | 443 | | |||
442 | if (fd.exec ()) | 444 | if (fd.exec ()) | ||
443 | { | 445 | { | ||
444 | QList<QUrl> selected = fd.selectedUrls(); | 446 | QList<QUrl> selected = fd.selectedUrls(); | ||
445 | if ( !selected.count() || !colorCells ()->saveColorCollectionAs(selected[0]) ) | 447 | if ( !selected.count() || !colorCells ()->saveColorCollectionAs(selected[0]) ) { | ||
446 | return false; | 448 | return false; | ||
449 | } | ||||
447 | 450 | | |||
448 | // We're definitely using our own color collection now. | 451 | // We're definitely using our own color collection now. | ||
449 | deselectActionColorsKDE (); | 452 | deselectActionColorsKDE (); | ||
450 | 453 | | |||
451 | return true; | 454 | return true; | ||
452 | } | 455 | } | ||
453 | else | 456 | | ||
454 | return false; | 457 | return false; | ||
455 | } | 458 | } | ||
456 | 459 | | |||
457 | //--------------------------------------------------------------------- | 460 | //--------------------------------------------------------------------- | ||
458 | 461 | | |||
459 | // private slot | 462 | // private slot | ||
460 | void kpMainWindow::slotColorsAppendRow () | 463 | void kpMainWindow::slotColorsAppendRow () | ||
461 | { | 464 | { | ||
Show All 18 Lines |