Changeset View
Changeset View
Standalone View
Standalone View
widgets/kpDocumentSaveOptionsWidget.cpp
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 80 | { | |||
---|---|---|---|---|---|
100 | m_previewButton->setCheckable (true); | 100 | m_previewButton->setCheckable (true); | ||
101 | 101 | | |||
102 | 102 | | |||
103 | m_colorDepthLabel->setBuddy (m_colorDepthCombo); | 103 | m_colorDepthLabel->setBuddy (m_colorDepthCombo); | ||
104 | 104 | | |||
105 | m_qualityLabel->setBuddy (m_qualityInput); | 105 | m_qualityLabel->setBuddy (m_qualityInput); | ||
106 | 106 | | |||
107 | 107 | | |||
108 | QHBoxLayout *lay = new QHBoxLayout (this); | 108 | auto *lay = new QHBoxLayout (this); | ||
109 | lay->setContentsMargins(0, 0, 0, 0); | 109 | lay->setContentsMargins(0, 0, 0, 0); | ||
110 | 110 | | |||
111 | lay->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); | 111 | lay->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); | ||
112 | lay->addWidget (m_colorDepthCombo, 0/*stretch*/); | 112 | lay->addWidget (m_colorDepthCombo, 0/*stretch*/); | ||
113 | 113 | | |||
114 | lay->addWidget (m_colorDepthSpaceWidget, 1/*stretch*/); | 114 | lay->addWidget (m_colorDepthSpaceWidget, 1/*stretch*/); | ||
115 | 115 | | |||
116 | lay->addWidget (m_qualityLabel, 0/*stretch*/, Qt::AlignLeft); | 116 | lay->addWidget (m_qualityLabel, 0/*stretch*/, Qt::AlignLeft); | ||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | 238 | qCDebug(kpLogWidgets) << "\tsetting colorDepthCombo to max item since" | |||
241 | << " out of range"; | 241 | << " out of range"; | ||
242 | 242 | | |||
243 | m_colorDepthCombo->setCurrentIndex (m_colorDepthCombo->count () - 1); | 243 | m_colorDepthCombo->setCurrentIndex (m_colorDepthCombo->count () - 1); | ||
244 | } | 244 | } | ||
245 | } | 245 | } | ||
246 | 246 | | |||
247 | m_baseDocumentSaveOptions.setMimeType (string); | 247 | m_baseDocumentSaveOptions.setMimeType (string); | ||
248 | 248 | | |||
249 | if (mimeTypeHasConfigurableColorDepth ()) | 249 | if (mimeTypeHasConfigurableColorDepth ()) { | ||
250 | setMode (ColorDepth); | 250 | setMode (ColorDepth); | ||
251 | else if (mimeTypeHasConfigurableQuality ()) | 251 | } | ||
252 | else if (mimeTypeHasConfigurableQuality ()) { | ||||
252 | setMode (Quality); | 253 | setMode (Quality); | ||
253 | else | 254 | } | ||
255 | else { | ||||
254 | setMode (None); | 256 | setMode (None); | ||
257 | } | ||||
255 | 258 | | |||
256 | updatePreview (); | 259 | updatePreview (); | ||
257 | } | 260 | } | ||
258 | 261 | | |||
259 | 262 | | |||
260 | // public | 263 | // public | ||
261 | int kpDocumentSaveOptionsWidget::colorDepth () const | 264 | int kpDocumentSaveOptionsWidget::colorDepth () const | ||
262 | { | 265 | { | ||
Show All 27 Lines | |||||
290 | // public | 293 | // public | ||
291 | bool kpDocumentSaveOptionsWidget::dither () const | 294 | bool kpDocumentSaveOptionsWidget::dither () const | ||
292 | { | 295 | { | ||
293 | if (mode () & ColorDepth) | 296 | if (mode () & ColorDepth) | ||
294 | { | 297 | { | ||
295 | return (m_colorDepthCombo->currentIndex () == 1 || | 298 | return (m_colorDepthCombo->currentIndex () == 1 || | ||
296 | m_colorDepthCombo->currentIndex () == 3); | 299 | m_colorDepthCombo->currentIndex () == 3); | ||
297 | } | 300 | } | ||
298 | else | 301 | | ||
299 | { | | |||
300 | return m_baseDocumentSaveOptions.dither (); | 302 | return m_baseDocumentSaveOptions.dither (); | ||
301 | } | 303 | } | ||
302 | } | | |||
303 | 304 | | |||
304 | // protected static | 305 | // protected static | ||
305 | int kpDocumentSaveOptionsWidget::colorDepthComboItemFromColorDepthAndDither ( | 306 | int kpDocumentSaveOptionsWidget::colorDepthComboItemFromColorDepthAndDither ( | ||
306 | int depth, bool dither) | 307 | int depth, bool dither) | ||
307 | { | 308 | { | ||
308 | if (depth == 1) | 309 | switch (depth) { | ||
309 | { | 310 | case 1: | ||
310 | if (!dither) | 311 | if (!dither) { | ||
311 | { | | |||
312 | return 0; | 312 | return 0; | ||
313 | } | 313 | } | ||
314 | else | | |||
315 | { | | |||
316 | return 1; | 314 | return 1; | ||
317 | } | 315 | | ||
318 | } | 316 | case 8: | ||
319 | else if (depth == 8) | 317 | if (!dither) { | ||
320 | { | | |||
321 | if (!dither) | | |||
322 | { | | |||
323 | return 2; | 318 | return 2; | ||
324 | } | 319 | } | ||
325 | else | | |||
326 | { | | |||
327 | return 3; | 320 | return 3; | ||
328 | } | 321 | | ||
329 | } | 322 | case 32: | ||
330 | else if (depth == 32) | | |||
331 | { | | |||
332 | return 4; | 323 | return 4; | ||
333 | } | 324 | | ||
334 | else | 325 | default: | ||
335 | { | | |||
336 | return -1; | 326 | return -1; | ||
337 | } | 327 | } | ||
338 | } | 328 | } | ||
339 | 329 | | |||
340 | // public slots | 330 | // public slots | ||
341 | void kpDocumentSaveOptionsWidget::setColorDepthDither (int newDepth, bool newDither) | 331 | void kpDocumentSaveOptionsWidget::setColorDepthDither (int newDepth, bool newDither) | ||
342 | { | 332 | { | ||
343 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setColorDepthDither(" | 333 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setColorDepthDither(" | ||
344 | << "depth=" << newDepth | 334 | << "depth=" << newDepth | ||
345 | << ",dither=" << newDither | 335 | << ",dither=" << newDither | ||
346 | << ")"; | 336 | << ")"; | ||
347 | 337 | | |||
348 | m_baseDocumentSaveOptions.setColorDepth (newDepth); | 338 | m_baseDocumentSaveOptions.setColorDepth (newDepth); | ||
349 | m_baseDocumentSaveOptions.setDither (newDither); | 339 | m_baseDocumentSaveOptions.setDither (newDither); | ||
350 | 340 | | |||
351 | 341 | | |||
352 | const int comboItem = colorDepthComboItemFromColorDepthAndDither ( | 342 | const int comboItem = colorDepthComboItemFromColorDepthAndDither ( | ||
353 | newDepth, newDither); | 343 | newDepth, newDither); | ||
354 | // TODO: Ignoring when comboItem >= m_colorDepthCombo->count() is wrong. | 344 | // TODO: Ignoring when comboItem >= m_colorDepthCombo->count() is wrong. | ||
355 | // This happens if this mimeType has configurable colour depth | 345 | // This happens if this mimeType has configurable colour depth | ||
356 | // and an incorrect maximum colour depth (less than a QImage of | 346 | // and an incorrect maximum colour depth (less than a QImage of | ||
357 | // this mimeType, opened by kpDocument). | 347 | // this mimeType, opened by kpDocument). | ||
358 | if (comboItem >= 0 && comboItem < m_colorDepthCombo->count ()) | 348 | if (comboItem >= 0 && comboItem < m_colorDepthCombo->count ()) { | ||
359 | m_colorDepthCombo->setCurrentIndex (comboItem); | 349 | m_colorDepthCombo->setCurrentIndex (comboItem); | ||
350 | } | ||||
360 | 351 | | |||
361 | 352 | | |||
362 | slotColorDepthSelected (); | 353 | slotColorDepthSelected (); | ||
363 | } | 354 | } | ||
364 | 355 | | |||
365 | 356 | | |||
366 | // protected slot | 357 | // protected slot | ||
367 | void kpDocumentSaveOptionsWidget::slotColorDepthSelected () | 358 | void kpDocumentSaveOptionsWidget::slotColorDepthSelected () | ||
Show All 19 Lines | |||||
387 | 378 | | |||
388 | // public | 379 | // public | ||
389 | int kpDocumentSaveOptionsWidget::quality () const | 380 | int kpDocumentSaveOptionsWidget::quality () const | ||
390 | { | 381 | { | ||
391 | if (mode () & Quality) | 382 | if (mode () & Quality) | ||
392 | { | 383 | { | ||
393 | return m_qualityInput->value (); | 384 | return m_qualityInput->value (); | ||
394 | } | 385 | } | ||
395 | else | 386 | | ||
396 | { | | |||
397 | return m_baseDocumentSaveOptions.quality (); | 387 | return m_baseDocumentSaveOptions.quality (); | ||
398 | } | 388 | } | ||
399 | } | | |||
400 | 389 | | |||
401 | // public | 390 | // public | ||
402 | void kpDocumentSaveOptionsWidget::setQuality (int newQuality) | 391 | void kpDocumentSaveOptionsWidget::setQuality (int newQuality) | ||
403 | { | 392 | { | ||
404 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setQuality(" | 393 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setQuality(" | ||
405 | << newQuality << ")"; | 394 | << newQuality << ")"; | ||
406 | 395 | | |||
407 | m_baseDocumentSaveOptions.setQuality (newQuality); | 396 | m_baseDocumentSaveOptions.setQuality (newQuality); | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 446 | { | |||
479 | // to move but the first instance of the text doesn't get erased. | 468 | // to move but the first instance of the text doesn't get erased. | ||
480 | // Qt bug. | 469 | // Qt bug. | ||
481 | QTimer::singleShot (0, this, SLOT (repaintLabels())); | 470 | QTimer::singleShot (0, this, SLOT (repaintLabels())); | ||
482 | } | 471 | } | ||
483 | 472 | | |||
484 | // protected slot | 473 | // protected slot | ||
485 | void kpDocumentSaveOptionsWidget::repaintLabels () | 474 | void kpDocumentSaveOptionsWidget::repaintLabels () | ||
486 | { | 475 | { | ||
487 | if (mode () != Quality) | 476 | if (mode () != Quality) { | ||
488 | m_colorDepthLabel->repaint (); | 477 | m_colorDepthLabel->repaint (); | ||
489 | if (mode () == Quality) | 478 | } | ||
479 | if (mode () == Quality) { | ||||
490 | m_qualityLabel->repaint (); | 480 | m_qualityLabel->repaint (); | ||
491 | } | 481 | } | ||
482 | } | ||||
492 | 483 | | |||
493 | 484 | | |||
494 | // protected slot | 485 | // protected slot | ||
495 | void kpDocumentSaveOptionsWidget::showPreview (bool yes) | 486 | void kpDocumentSaveOptionsWidget::showPreview (bool yes) | ||
496 | { | 487 | { | ||
497 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::showPreview(" << yes << ")" | 488 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::showPreview(" << yes << ")" | ||
498 | << " m_previewDialog=" << bool (m_previewDialog); | 489 | << " m_previewDialog=" << bool (m_previewDialog); | ||
499 | 490 | | |||
500 | if (yes == bool (m_previewDialog)) | 491 | if (yes == bool (m_previewDialog)) { | ||
501 | return; | 492 | return; | ||
493 | } | ||||
502 | 494 | | |||
503 | if (!m_visualParent) | 495 | if (!m_visualParent) { | ||
504 | return; | 496 | return; | ||
497 | } | ||||
505 | 498 | | |||
506 | if (yes) | 499 | if (yes) | ||
507 | { | 500 | { | ||
508 | m_previewDialog = new kpDocumentSaveOptionsPreviewDialog( m_visualParent ); | 501 | m_previewDialog = new kpDocumentSaveOptionsPreviewDialog( m_visualParent ); | ||
509 | m_previewDialog->setObjectName( QLatin1String( "previewSaveDialog" ) ); | 502 | m_previewDialog->setObjectName( QLatin1String( "previewSaveDialog" ) ); | ||
510 | updatePreview (); | 503 | updatePreview (); | ||
511 | 504 | | |||
512 | connect (m_previewDialog, &kpDocumentSaveOptionsPreviewDialog::finished, | 505 | connect (m_previewDialog, &kpDocumentSaveOptionsPreviewDialog::finished, | ||
513 | this, &kpDocumentSaveOptionsWidget::hidePreview); | 506 | this, &kpDocumentSaveOptionsWidget::hidePreview); | ||
514 | 507 | | |||
515 | 508 | | |||
516 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | 509 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | ||
517 | 510 | | |||
518 | if (cfg.hasKey (kpSettingPreviewSaveUpdateDelay)) | 511 | if (cfg.hasKey (kpSettingPreviewSaveUpdateDelay)) | ||
519 | { | 512 | { | ||
520 | m_updatePreviewDelay = cfg.readEntry (kpSettingPreviewSaveUpdateDelay, 0); | 513 | m_updatePreviewDelay = cfg.readEntry (kpSettingPreviewSaveUpdateDelay, 0); | ||
521 | } | 514 | } | ||
522 | else | 515 | else | ||
523 | { | 516 | { | ||
524 | cfg.writeEntry (kpSettingPreviewSaveUpdateDelay, m_updatePreviewDelay); | 517 | cfg.writeEntry (kpSettingPreviewSaveUpdateDelay, m_updatePreviewDelay); | ||
525 | cfg.sync (); | 518 | cfg.sync (); | ||
526 | } | 519 | } | ||
527 | 520 | | |||
528 | if (m_updatePreviewDelay < 0) | 521 | if (m_updatePreviewDelay < 0) { | ||
529 | m_updatePreviewDelay = 0; | 522 | m_updatePreviewDelay = 0; | ||
530 | qCDebug(kpLogWidgets) << "\tread cfg preview dialog update delay=" | 523 | } | ||
531 | << m_updatePreviewDelay; | 524 | qCDebug(kpLogWidgets) << "\tread cfg preview dialog update delay=" << m_updatePreviewDelay; | ||
532 | 525 | | |||
533 | 526 | | |||
534 | if (m_previewDialogLastRelativeGeometry.isEmpty ()) | 527 | if (m_previewDialogLastRelativeGeometry.isEmpty ()) | ||
535 | { | 528 | { | ||
536 | qCDebug(kpLogWidgets) << "\tread cfg preview dialog last rel geometry"; | 529 | qCDebug(kpLogWidgets) << "\tread cfg preview dialog last rel geometry"; | ||
537 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | 530 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | ||
538 | 531 | | |||
539 | m_previewDialogLastRelativeGeometry = cfg.readEntry ( | 532 | m_previewDialogLastRelativeGeometry = cfg.readEntry ( | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 590 | { | |||
613 | m_previewDialog->deleteLater (); | 606 | m_previewDialog->deleteLater (); | ||
614 | m_previewDialog = nullptr; | 607 | m_previewDialog = nullptr; | ||
615 | } | 608 | } | ||
616 | } | 609 | } | ||
617 | 610 | | |||
618 | // protected slot | 611 | // protected slot | ||
619 | void kpDocumentSaveOptionsWidget::hidePreview () | 612 | void kpDocumentSaveOptionsWidget::hidePreview () | ||
620 | { | 613 | { | ||
621 | if (m_previewButton->isChecked ()) | 614 | if (m_previewButton->isChecked ()) { | ||
622 | m_previewButton->toggle (); | 615 | m_previewButton->toggle (); | ||
623 | } | 616 | } | ||
617 | } | ||||
624 | 618 | | |||
625 | 619 | | |||
626 | // protected slot | 620 | // protected slot | ||
627 | void kpDocumentSaveOptionsWidget::updatePreviewDelayed () | 621 | void kpDocumentSaveOptionsWidget::updatePreviewDelayed () | ||
628 | { | 622 | { | ||
629 | // (single shot) | 623 | // (single shot) | ||
630 | m_updatePreviewTimer->start (m_updatePreviewDelay); | 624 | m_updatePreviewTimer->start (m_updatePreviewDelay); | ||
631 | } | 625 | } | ||
632 | 626 | | |||
633 | // protected slot | 627 | // protected slot | ||
634 | void kpDocumentSaveOptionsWidget::updatePreview () | 628 | void kpDocumentSaveOptionsWidget::updatePreview () | ||
635 | { | 629 | { | ||
636 | if (!m_previewDialog || !m_documentPixmap) | 630 | if (!m_previewDialog || !m_documentPixmap) { | ||
637 | return; | 631 | return; | ||
632 | } | ||||
638 | 633 | | |||
639 | 634 | | |||
640 | m_updatePreviewTimer->stop (); | 635 | m_updatePreviewTimer->stop (); | ||
641 | 636 | | |||
642 | 637 | | |||
643 | QApplication::setOverrideCursor (Qt::WaitCursor); | 638 | QApplication::setOverrideCursor (Qt::WaitCursor); | ||
644 | 639 | | |||
645 | QByteArray data; | 640 | QByteArray data; | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 680 | { | |||
688 | 683 | | |||
689 | if (m_previewDialog && m_previewDialog->isVisible ()) | 684 | if (m_previewDialog && m_previewDialog->isVisible ()) | ||
690 | { | 685 | { | ||
691 | m_previewDialogLastRelativeGeometry = | 686 | m_previewDialogLastRelativeGeometry = | ||
692 | kpWidgetMapper::fromGlobal (m_visualParent, | 687 | kpWidgetMapper::fromGlobal (m_visualParent, | ||
693 | QRect (m_previewDialog->x (), m_previewDialog->y (), | 688 | QRect (m_previewDialog->x (), m_previewDialog->y (), | ||
694 | m_previewDialog->width (), m_previewDialog->height ())); | 689 | m_previewDialog->width (), m_previewDialog->height ())); | ||
695 | qCDebug(kpLogWidgets) << "\tcaching pos = " | 690 | qCDebug(kpLogWidgets) << "\tcaching pos = " | ||
696 | << m_previewDialogLastRelativeGeometry | 691 | << m_previewDialogLastRelativeGeometry; | ||
697 | << endl; | | |||
698 | } | 692 | } | ||
699 | else | 693 | else | ||
700 | { | 694 | { | ||
701 | qCDebug(kpLogWidgets) << "\tnot visible - ignoring geometry"; | 695 | qCDebug(kpLogWidgets) << "\tnot visible - ignoring geometry"; | ||
702 | } | 696 | } | ||
703 | } | 697 | } |