Changeset View
Changeset View
Standalone View
Standalone View
dialogs/kpDocumentSaveOptionsDialog.cpp
- This file was moved from widgets/kpDocumentSaveOptionsWidget.cpp.
Context not available. | |||||
27 | 27 | | |||
---|---|---|---|---|---|
28 | #define DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET 0 | 28 | #define DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET 0 | ||
29 | 29 | | |||
30 | 30 | #include "commands/kpCommandSize.h" | |||
31 | #include "widgets/kpDocumentSaveOptionsWidget.h" | | |||
32 | | ||||
33 | #include "kpDefs.h" | | |||
34 | #include "document/kpDocument.h" | | |||
35 | #include "dialogs/kpDocumentSaveOptionsPreviewDialog.h" | | |||
36 | #include "pixmapfx/kpPixmapFX.h" | | |||
37 | #include "generic/widgets/kpResizeSignallingLabel.h" | | |||
38 | #include "dialogs/imagelib/transforms/kpTransformPreviewDialog.h" | 31 | #include "dialogs/imagelib/transforms/kpTransformPreviewDialog.h" | ||
32 | #include "dialogs/kpDocumentSaveOptionsDialog.h" | ||||
33 | #include "document/kpDocument.h" | ||||
39 | #include "generic/kpWidgetMapper.h" | 34 | #include "generic/kpWidgetMapper.h" | ||
40 | 35 | #include "generic/widgets/kpResizeSignallingLabel.h" | |||
36 | #include "kpDefs.h" | ||||
41 | #include "kpLogCategories.h" | 37 | #include "kpLogCategories.h" | ||
38 | #include "pixmapfx/kpPixmapFX.h" | ||||
39 | | ||||
42 | #include <KSharedConfig> | 40 | #include <KSharedConfig> | ||
43 | #include <KConfigGroup> | 41 | #include <KConfigGroup> | ||
44 | 42 | #include <kconfig.h> | |||
45 | #include <qapplication.h> | 43 | #include <KLocalizedString> | ||
46 | #include <qboxlayout.h> | 44 | | ||
47 | #include <qbuffer.h> | 45 | #include <QApplication> | ||
48 | #include <qcombobox.h> | 46 | #include <QBoxLayout> | ||
49 | #include <qevent.h> | 47 | #include <QBuffer> | ||
50 | #include <qgridlayout.h> | 48 | #include <QComboBox> | ||
51 | #include <qimage.h> | 49 | #include <QDialogButtonBox> | ||
52 | #include <qlabel.h> | 50 | #include <QEvent> | ||
53 | #include <qlayout.h> | 51 | #include <QGridLayout> | ||
54 | #include <qpushbutton.h> | 52 | #include <QImage> | ||
55 | #include <qspinbox.h> | 53 | #include <QLabel> | ||
56 | #include <qtimer.h> | 54 | #include <QLayout> | ||
57 | 55 | #include <QPixmap> | |||
58 | 56 | #include <QPushButton> | |||
59 | kpDocumentSaveOptionsWidget::kpDocumentSaveOptionsWidget ( | 57 | #include <QSpinBox> | ||
58 | #include <QTimer> | ||||
59 | | ||||
60 | kpDocumentSaveOptionsDialog::kpDocumentSaveOptionsDialog ( | ||||
60 | const QImage &docPixmap, | 61 | const QImage &docPixmap, | ||
61 | const kpDocumentSaveOptions &saveOptions, | 62 | const kpDocumentSaveOptions &saveOptions, | ||
62 | const kpDocumentMetaInfo &metaInfo, | 63 | const kpDocumentMetaInfo &metaInfo, | ||
63 | QWidget *parent) | 64 | QWidget *parent) | ||
64 | : QWidget (parent), | 65 | : QDialog (parent), | ||
65 | m_visualParent (parent) | 66 | m_visualParent (parent) | ||
66 | { | 67 | { | ||
67 | init (); | 68 | init (); | ||
Context not available. | |||||
70 | setDocumentMetaInfo (metaInfo); | 71 | setDocumentMetaInfo (metaInfo); | ||
71 | } | 72 | } | ||
72 | 73 | | |||
73 | kpDocumentSaveOptionsWidget::kpDocumentSaveOptionsWidget ( | 74 | kpDocumentSaveOptionsDialog::kpDocumentSaveOptionsDialog ( | ||
74 | QWidget *parent) | 75 | QWidget *parent) | ||
75 | : QWidget (parent), | 76 | : QDialog (parent), | ||
76 | m_visualParent (parent) | 77 | m_visualParent (parent) | ||
77 | { | 78 | { | ||
78 | init (); | 79 | init (); | ||
79 | } | 80 | } | ||
80 | 81 | | |||
81 | // private | 82 | // private | ||
82 | void kpDocumentSaveOptionsWidget::init () | 83 | void kpDocumentSaveOptionsDialog::init () | ||
83 | { | 84 | { | ||
84 | m_documentPixmap = nullptr; | 85 | m_documentPixmap = nullptr; | ||
85 | m_previewDialog = nullptr; | 86 | m_filePixmap = nullptr; | ||
86 | m_visualParent = nullptr; | 87 | m_visualParent = nullptr; | ||
87 | 88 | | |||
89 | setWindowTitle (i18nc("@title:window", "Save Options")); | ||||
88 | 90 | | |||
89 | m_colorDepthLabel = new QLabel (i18n ("Convert &to:"), this); | 91 | m_colorDepthLabel = new QLabel (i18n ("Convert &to:"), this); | ||
90 | m_colorDepthCombo = new QComboBox (this); | 92 | m_colorDepthCombo = new QComboBox (this); | ||
Context not available. | |||||
99 | // TODO: 100 quality is also misleading since that implies perfect quality. | 101 | // TODO: 100 quality is also misleading since that implies perfect quality. | ||
100 | m_qualityInput->setRange (1, 100); | 102 | m_qualityInput->setRange (1, 100); | ||
101 | 103 | | |||
102 | m_previewButton = new QPushButton (i18n ("&Preview"), this); | | |||
103 | m_previewButton->setCheckable (true); | | |||
104 | | ||||
105 | | ||||
106 | m_colorDepthLabel->setBuddy (m_colorDepthCombo); | 104 | m_colorDepthLabel->setBuddy (m_colorDepthCombo); | ||
107 | 105 | | |||
108 | m_qualityLabel->setBuddy (m_qualityInput); | 106 | m_qualityLabel->setBuddy (m_qualityInput); | ||
109 | 107 | | |||
108 | m_filePixmapLabel = new kpResizeSignallingLabel (this); | ||||
109 | m_filePixmapLabel->setMinimumSize (250, 210); | ||||
110 | m_fileSizeLabel = new QLabel (this); | ||||
111 | | ||||
112 | connect (m_filePixmapLabel, SIGNAL (resized()), | ||||
113 | this, SLOT (updatePixmapPreview())); | ||||
114 | | ||||
115 | QDialogButtonBox *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | | ||||
116 | QDialogButtonBox::Cancel, this); | ||||
117 | connect (buttons, &QDialogButtonBox::accepted, this, &kpDocumentSaveOptionsDialog::accept); | ||||
118 | connect (buttons, &QDialogButtonBox::rejected, this, &kpDocumentSaveOptionsDialog::reject); | ||||
119 | | ||||
120 | QVBoxLayout *lay = new QVBoxLayout (this); | ||||
121 | lay->setMargin(10); | ||||
110 | 122 | | |||
111 | QHBoxLayout *lay = new QHBoxLayout (this); | 123 | QHBoxLayout *layH = new QHBoxLayout (); | ||
112 | lay->setMargin(0); | 124 | layH->setMargin(0); | ||
113 | 125 | | |||
114 | lay->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); | 126 | layH->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); | ||
115 | lay->addWidget (m_colorDepthCombo, 0/*stretch*/); | 127 | layH->addWidget (m_colorDepthCombo, 0/*stretch*/); | ||
116 | 128 | | |||
117 | lay->addWidget (m_colorDepthSpaceWidget, 1/*stretch*/); | 129 | layH->addWidget (m_colorDepthSpaceWidget, 1/*stretch*/); | ||
118 | 130 | | |||
119 | lay->addWidget (m_qualityLabel, 0/*stretch*/, Qt::AlignLeft); | 131 | layH->addWidget (m_qualityLabel, 0/*stretch*/, Qt::AlignLeft); | ||
120 | lay->addWidget (m_qualityInput, 2/*stretch*/); | 132 | layH->addWidget (m_qualityInput, 2/*stretch*/); | ||
121 | 133 | | |||
122 | lay->addWidget (m_previewButton, 0/*stretch*/, Qt::AlignRight); | 134 | lay->addLayout (layH); | ||
123 | 135 | | |||
136 | lay->addWidget (m_filePixmapLabel, 2/*stretch*/); | ||||
137 | lay->addWidget (m_fileSizeLabel); | ||||
138 | | ||||
139 | lay->addWidget (buttons); | ||||
124 | 140 | | |||
125 | connect (m_colorDepthCombo, SIGNAL (activated(int)), | 141 | connect (m_colorDepthCombo, SIGNAL (activated(int)), | ||
126 | this, SLOT (slotColorDepthSelected())); | 142 | this, SLOT (slotColorDepthSelected())); | ||
Context not available. | |||||
130 | connect (m_qualityInput, SIGNAL (valueChanged(int)), | 146 | connect (m_qualityInput, SIGNAL (valueChanged(int)), | ||
131 | this, SLOT (updatePreviewDelayed())); | 147 | this, SLOT (updatePreviewDelayed())); | ||
132 | 148 | | |||
133 | connect (m_previewButton, SIGNAL (toggled(bool)), | | |||
134 | this, SLOT (showPreview(bool))); | | |||
135 | | ||||
136 | | ||||
137 | m_updatePreviewDelay = 200/*ms*/; | 149 | m_updatePreviewDelay = 200/*ms*/; | ||
138 | 150 | | |||
139 | m_updatePreviewTimer = new QTimer (this); | 151 | m_updatePreviewTimer = new QTimer (this); | ||
Context not available. | |||||
141 | connect (m_updatePreviewTimer, SIGNAL (timeout()), | 153 | connect (m_updatePreviewTimer, SIGNAL (timeout()), | ||
142 | this, SLOT (updatePreview())); | 154 | this, SLOT (updatePreview())); | ||
143 | 155 | | |||
144 | m_updatePreviewDialogLastRelativeGeometryTimer = new QTimer (this); | | |||
145 | connect (m_updatePreviewDialogLastRelativeGeometryTimer, SIGNAL (timeout()), | | |||
146 | this, SLOT (updatePreviewDialogLastRelativeGeometry())); | | |||
147 | | ||||
148 | | ||||
149 | setMode (None); | 156 | setMode (None); | ||
150 | 157 | | |||
151 | slotColorDepthSelected (); | 158 | slotColorDepthSelected (); | ||
152 | } | 159 | } | ||
153 | 160 | | |||
154 | kpDocumentSaveOptionsWidget::~kpDocumentSaveOptionsWidget () | 161 | kpDocumentSaveOptionsDialog::~kpDocumentSaveOptionsDialog () | ||
155 | { | 162 | { | ||
156 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 163 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
157 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::<dtor>()"; | 164 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsDialog::<dtor>()"; | ||
158 | #endif | 165 | #endif | ||
159 | hidePreview (); | | |||
160 | | ||||
161 | delete m_documentPixmap; | 166 | delete m_documentPixmap; | ||
162 | } | 167 | } | ||
163 | 168 | | |||
164 | 169 | | |||
165 | // public | 170 | // public | ||
166 | void kpDocumentSaveOptionsWidget::setVisualParent (QWidget *visualParent) | 171 | void kpDocumentSaveOptionsDialog::setVisualParent (QWidget *visualParent) | ||
167 | { | 172 | { | ||
168 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 173 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
169 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setVisualParent(" | 174 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsDialog::setVisualParent(" | ||
170 | << visualParent << ")" << endl; | 175 | << visualParent << ")" << endl; | ||
171 | #endif | 176 | #endif | ||
172 | 177 | | |||
Context not available. | |||||
175 | 180 | | |||
176 | 181 | | |||
177 | // protected | 182 | // protected | ||
178 | bool kpDocumentSaveOptionsWidget::mimeTypeHasConfigurableColorDepth () const | 183 | bool kpDocumentSaveOptionsDialog::mimeTypeHasConfigurableColorDepth () const | ||
179 | { | 184 | { | ||
180 | return kpDocumentSaveOptions::mimeTypeHasConfigurableColorDepth (mimeType ()); | 185 | return kpDocumentSaveOptions::mimeTypeHasConfigurableColorDepth (mimeType ()); | ||
181 | } | 186 | } | ||
182 | 187 | | |||
183 | // protected | 188 | // protected | ||
184 | bool kpDocumentSaveOptionsWidget::mimeTypeHasConfigurableQuality () const | 189 | bool kpDocumentSaveOptionsDialog::mimeTypeHasConfigurableQuality () const | ||
185 | { | 190 | { | ||
186 | return kpDocumentSaveOptions::mimeTypeHasConfigurableQuality (mimeType ()); | 191 | return kpDocumentSaveOptions::mimeTypeHasConfigurableQuality (mimeType ()); | ||
187 | } | 192 | } | ||
188 | 193 | | |||
189 | 194 | | |||
190 | // public | 195 | // public | ||
191 | QString kpDocumentSaveOptionsWidget::mimeType () const | 196 | QString kpDocumentSaveOptionsDialog::mimeType () const | ||
192 | { | 197 | { | ||
193 | return m_baseDocumentSaveOptions.mimeType (); | 198 | return m_baseDocumentSaveOptions.mimeType (); | ||
194 | } | 199 | } | ||
195 | 200 | | |||
196 | // public slots | 201 | // public slots | ||
197 | void kpDocumentSaveOptionsWidget::setMimeType (const QString &string) | 202 | void kpDocumentSaveOptionsDialog::setMimeType (const QString &string) | ||
198 | { | 203 | { | ||
199 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 204 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
200 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setMimeType(" << string | 205 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsDialog::setMimeType(" << string | ||
201 | << ") maxColorDepth=" | 206 | << ") maxColorDepth=" | ||
202 | << kpDocumentSaveOptions::mimeTypeMaximumColorDepth (string) | 207 | << kpDocumentSaveOptions::mimeTypeMaximumColorDepth (string) | ||
203 | << endl; | 208 | << endl; | ||
Context not available. | |||||
272 | 277 | | |||
273 | 278 | | |||
274 | // public | 279 | // public | ||
275 | int kpDocumentSaveOptionsWidget::colorDepth () const | 280 | int kpDocumentSaveOptionsDialog::colorDepth () const | ||
276 | { | 281 | { | ||
277 | if (mode () & ColorDepth) | 282 | if (mode () & ColorDepth) | ||
278 | { | 283 | { | ||
Context not available. | |||||
302 | } | 307 | } | ||
303 | 308 | | |||
304 | // public | 309 | // public | ||
305 | bool kpDocumentSaveOptionsWidget::dither () const | 310 | bool kpDocumentSaveOptionsDialog::dither () const | ||
306 | { | 311 | { | ||
307 | if (mode () & ColorDepth) | 312 | if (mode () & ColorDepth) | ||
308 | { | 313 | { | ||
Context not available. | |||||
316 | } | 321 | } | ||
317 | 322 | | |||
318 | // protected static | 323 | // protected static | ||
319 | int kpDocumentSaveOptionsWidget::colorDepthComboItemFromColorDepthAndDither ( | 324 | int kpDocumentSaveOptionsDialog::colorDepthComboItemFromColorDepthAndDither ( | ||
320 | int depth, bool dither) | 325 | int depth, bool dither) | ||
321 | { | 326 | { | ||
322 | if (depth == 1) | 327 | if (depth == 1) | ||
Context not available. | |||||
352 | } | 357 | } | ||
353 | 358 | | |||
354 | // public slots | 359 | // public slots | ||
355 | void kpDocumentSaveOptionsWidget::setColorDepthDither (int newDepth, bool newDither) | 360 | void kpDocumentSaveOptionsDialog::setColorDepthDither (int newDepth, bool newDither) | ||
356 | { | 361 | { | ||
357 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 362 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
358 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setColorDepthDither(" | 363 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsDialog::setColorDepthDither(" | ||
359 | << "depth=" << newDepth | 364 | << "depth=" << newDepth | ||
360 | << ",dither=" << newDither | 365 | << ",dither=" << newDither | ||
361 | << ")" << endl; | 366 | << ")" << endl; | ||
Context not available. | |||||
380 | 385 | | |||
381 | 386 | | |||
382 | // protected slot | 387 | // protected slot | ||
383 | void kpDocumentSaveOptionsWidget::slotColorDepthSelected () | 388 | void kpDocumentSaveOptionsDialog::slotColorDepthSelected () | ||
384 | { | 389 | { | ||
385 | if (mode () & ColorDepth) | 390 | if (mode () & ColorDepth) | ||
386 | { | 391 | { | ||
Context not available. | |||||
395 | } | 400 | } | ||
396 | 401 | | |||
397 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 402 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
398 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::slotColorDepthSelected()" | 403 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsDialog::slotColorDepthSelected()" | ||
399 | << " mode&ColorDepth=" << (mode () & ColorDepth) | 404 | << " mode&ColorDepth=" << (mode () & ColorDepth) | ||
400 | << " colorDepthComboLastSelectedItem=" | 405 | << " colorDepthComboLastSelectedItem=" | ||
401 | << m_colorDepthComboLastSelectedItem | 406 | << m_colorDepthComboLastSelectedItem | ||
Context not available. | |||||
405 | 410 | | |||
406 | 411 | | |||
407 | // public | 412 | // public | ||
408 | int kpDocumentSaveOptionsWidget::quality () const | 413 | int kpDocumentSaveOptionsDialog::quality () const | ||
409 | { | 414 | { | ||
410 | if (mode () & Quality) | 415 | if (mode () & Quality) | ||
411 | { | 416 | { | ||
Context not available. | |||||
418 | } | 423 | } | ||
419 | 424 | | |||
420 | // public | 425 | // public | ||
421 | void kpDocumentSaveOptionsWidget::setQuality (int newQuality) | 426 | void kpDocumentSaveOptionsDialog::setQuality (int newQuality) | ||
422 | { | 427 | { | ||
423 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 428 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
424 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setQuality(" | 429 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsDialog::setQuality(" | ||
425 | << newQuality << ")" << endl; | 430 | << newQuality << ")" << endl; | ||
426 | #endif | 431 | #endif | ||
427 | 432 | | |||
Context not available. | |||||
433 | 438 | | |||
434 | 439 | | |||
435 | // public | 440 | // public | ||
436 | kpDocumentSaveOptions kpDocumentSaveOptionsWidget::documentSaveOptions () const | 441 | kpDocumentSaveOptions kpDocumentSaveOptionsDialog::documentSaveOptions () const | ||
437 | { | 442 | { | ||
438 | return kpDocumentSaveOptions (mimeType (), colorDepth (), dither (), quality ()); | 443 | return kpDocumentSaveOptions (mimeType (), colorDepth (), dither (), quality ()); | ||
439 | } | 444 | } | ||
440 | 445 | | |||
441 | // public | 446 | // public | ||
442 | void kpDocumentSaveOptionsWidget::setDocumentSaveOptions ( | 447 | void kpDocumentSaveOptionsDialog::setDocumentSaveOptions ( | ||
443 | const kpDocumentSaveOptions &saveOptions) | 448 | const kpDocumentSaveOptions &saveOptions) | ||
444 | { | 449 | { | ||
445 | setMimeType (saveOptions.mimeType ()); | 450 | setMimeType (saveOptions.mimeType ()); | ||
Context not available. | |||||
449 | 454 | | |||
450 | 455 | | |||
451 | // public | 456 | // public | ||
452 | void kpDocumentSaveOptionsWidget::setDocumentPixmap (const QImage &documentPixmap) | 457 | void kpDocumentSaveOptionsDialog::setDocumentPixmap (const QImage &documentPixmap) | ||
453 | { | 458 | { | ||
454 | delete m_documentPixmap; | 459 | delete m_documentPixmap; | ||
455 | m_documentPixmap = new QImage (documentPixmap); | 460 | m_documentPixmap = new QImage (documentPixmap); | ||
Context not available. | |||||
458 | } | 463 | } | ||
459 | 464 | | |||
460 | // public | 465 | // public | ||
461 | void kpDocumentSaveOptionsWidget::setDocumentMetaInfo ( | 466 | void kpDocumentSaveOptionsDialog::setDocumentMetaInfo ( | ||
462 | const kpDocumentMetaInfo &metaInfo) | 467 | const kpDocumentMetaInfo &metaInfo) | ||
463 | { | 468 | { | ||
464 | m_documentMetaInfo = metaInfo; | 469 | m_documentMetaInfo = metaInfo; | ||
Context not available. | |||||
468 | 473 | | |||
469 | 474 | | |||
470 | // public | 475 | // public | ||
471 | kpDocumentSaveOptionsWidget::Mode kpDocumentSaveOptionsWidget::mode () const | 476 | kpDocumentSaveOptionsDialog::Mode kpDocumentSaveOptionsDialog::mode () const | ||
472 | { | 477 | { | ||
473 | return m_mode; | 478 | return m_mode; | ||
474 | } | 479 | } | ||
475 | 480 | | |||
476 | // public | 481 | // public | ||
477 | void kpDocumentSaveOptionsWidget::setMode (Mode mode) | 482 | void kpDocumentSaveOptionsDialog::setMode (Mode mode) | ||
478 | { | 483 | { | ||
479 | m_mode = mode; | 484 | m_mode = mode; | ||
480 | 485 | | |||
Context not available. | |||||
503 | } | 508 | } | ||
504 | 509 | | |||
505 | // protected slot | 510 | // protected slot | ||
506 | void kpDocumentSaveOptionsWidget::repaintLabels () | 511 | void kpDocumentSaveOptionsDialog::repaintLabels () | ||
507 | { | 512 | { | ||
508 | if (mode () != Quality) | 513 | if (mode () != Quality) | ||
509 | m_colorDepthLabel->repaint (); | 514 | m_colorDepthLabel->repaint (); | ||
Context not available. | |||||
513 | 518 | | |||
514 | 519 | | |||
515 | // protected slot | 520 | // protected slot | ||
516 | void kpDocumentSaveOptionsWidget::showPreview (bool yes) | 521 | void kpDocumentSaveOptionsDialog::updatePreviewDelayed () | ||
517 | { | | |||
518 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
519 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::showPreview(" << yes << ")" | | |||
520 | << " m_previewDialog=" << bool (m_previewDialog) | | |||
521 | << endl; | | |||
522 | #endif | | |||
523 | | ||||
524 | if (yes == bool (m_previewDialog)) | | |||
525 | return; | | |||
526 | | ||||
527 | if (!m_visualParent) | | |||
528 | return; | | |||
529 | | ||||
530 | if (yes) | | |||
531 | { | | |||
532 | m_previewDialog = new kpDocumentSaveOptionsPreviewDialog( m_visualParent ); | | |||
533 | m_previewDialog->setObjectName( QLatin1String( "previewSaveDialog" ) ); | | |||
534 | updatePreview (); | | |||
535 | | ||||
536 | connect (m_previewDialog, SIGNAL (finished()), | | |||
537 | this, SLOT (hidePreview())); | | |||
538 | | ||||
539 | | ||||
540 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | | |||
541 | | ||||
542 | if (cfg.hasKey (kpSettingPreviewSaveUpdateDelay)) | | |||
543 | { | | |||
544 | m_updatePreviewDelay = cfg.readEntry (kpSettingPreviewSaveUpdateDelay, 0); | | |||
545 | } | | |||
546 | else | | |||
547 | { | | |||
548 | cfg.writeEntry (kpSettingPreviewSaveUpdateDelay, m_updatePreviewDelay); | | |||
549 | cfg.sync (); | | |||
550 | } | | |||
551 | | ||||
552 | if (m_updatePreviewDelay < 0) | | |||
553 | m_updatePreviewDelay = 0; | | |||
554 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
555 | qCDebug(kpLogWidgets) << "\tread cfg preview dialog update delay=" | | |||
556 | << m_updatePreviewDelay | | |||
557 | << endl; | | |||
558 | #endif | | |||
559 | | ||||
560 | | ||||
561 | if (m_previewDialogLastRelativeGeometry.isEmpty ()) | | |||
562 | { | | |||
563 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
564 | qCDebug(kpLogWidgets) << "\tread cfg preview dialog last rel geometry"; | | |||
565 | #endif | | |||
566 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | | |||
567 | | ||||
568 | m_previewDialogLastRelativeGeometry = cfg.readEntry ( | | |||
569 | kpSettingPreviewSaveGeometry, QRect ()); | | |||
570 | } | | |||
571 | | ||||
572 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
573 | qCDebug(kpLogWidgets) << "\tpreviewDialogLastRelativeGeometry=" | | |||
574 | << m_previewDialogLastRelativeGeometry | | |||
575 | << " visualParent->rect()=" << m_visualParent->rect () | | |||
576 | << endl; | | |||
577 | #endif | | |||
578 | | ||||
579 | QRect relativeGeometry; | | |||
580 | if (!m_previewDialogLastRelativeGeometry.isEmpty () && | | |||
581 | m_visualParent->rect ().intersects (m_previewDialogLastRelativeGeometry)) | | |||
582 | { | | |||
583 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
584 | qCDebug(kpLogWidgets) << "\tok"; | | |||
585 | #endif | | |||
586 | relativeGeometry = m_previewDialogLastRelativeGeometry; | | |||
587 | } | | |||
588 | else | | |||
589 | { | | |||
590 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
591 | qCDebug(kpLogWidgets) << "\t\tinvalid"; | | |||
592 | #endif | | |||
593 | const int margin = 20; | | |||
594 | | ||||
595 | relativeGeometry = | | |||
596 | QRect (m_visualParent->width () - | | |||
597 | m_previewDialog->preferredMinimumSize ().width () - | | |||
598 | margin, | | |||
599 | margin * 2, // Avoid folder combo | | |||
600 | m_previewDialog->preferredMinimumSize ().width (), | | |||
601 | m_previewDialog->preferredMinimumSize ().height ()); | | |||
602 | } | | |||
603 | | ||||
604 | | ||||
605 | const QRect globalGeometry = | | |||
606 | kpWidgetMapper::toGlobal (m_visualParent, | | |||
607 | relativeGeometry); | | |||
608 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
609 | qCDebug(kpLogWidgets) << "\trelativeGeometry=" << relativeGeometry | | |||
610 | << " globalGeometry=" << globalGeometry | | |||
611 | << endl; | | |||
612 | #endif | | |||
613 | | ||||
614 | m_previewDialog->resize (globalGeometry.size ()); | | |||
615 | m_previewDialog->move (globalGeometry.topLeft ()); | | |||
616 | | ||||
617 | | ||||
618 | m_previewDialog->show (); | | |||
619 | | ||||
620 | | ||||
621 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
622 | qCDebug(kpLogWidgets) << "\tgeometry after show=" | | |||
623 | << QRect (m_previewDialog->x (), m_previewDialog->y (), | | |||
624 | m_previewDialog->width (), m_previewDialog->height ()) | | |||
625 | << endl; | | |||
626 | #endif | | |||
627 | | ||||
628 | updatePreviewDialogLastRelativeGeometry (); | | |||
629 | | ||||
630 | connect (m_previewDialog, SIGNAL (moved()), | | |||
631 | this, SLOT (updatePreviewDialogLastRelativeGeometry())); | | |||
632 | connect (m_previewDialog, SIGNAL (resized()), | | |||
633 | this, SLOT (updatePreviewDialogLastRelativeGeometry())); | | |||
634 | | ||||
635 | m_updatePreviewDialogLastRelativeGeometryTimer->start (200/*ms*/); | | |||
636 | } | | |||
637 | else | | |||
638 | { | | |||
639 | m_updatePreviewDialogLastRelativeGeometryTimer->stop (); | | |||
640 | | ||||
641 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); | | |||
642 | | ||||
643 | cfg.writeEntry (kpSettingPreviewSaveGeometry, m_previewDialogLastRelativeGeometry); | | |||
644 | cfg.sync (); | | |||
645 | | ||||
646 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | | |||
647 | qCDebug(kpLogWidgets) << "\tsaving preview geometry " | | |||
648 | << m_previewDialogLastRelativeGeometry | | |||
649 | << " (Qt would have us believe " | | |||
650 | << kpWidgetMapper::fromGlobal (m_visualParent, | | |||
651 | QRect (m_previewDialog->x (), m_previewDialog->y (), | | |||
652 | m_previewDialog->width (), m_previewDialog->height ())) | | |||
653 | << ")" | | |||
654 | << endl; | | |||
655 | #endif | | |||
656 | | ||||
657 | m_previewDialog->deleteLater (); | | |||
658 | m_previewDialog = nullptr; | | |||
659 | } | | |||
660 | } | | |||
661 | | ||||
662 | // protected slot | | |||
663 | void kpDocumentSaveOptionsWidget::hidePreview () | | |||
664 | { | | |||
665 | if (m_previewButton->isChecked ()) | | |||
666 | m_previewButton->toggle (); | | |||
667 | } | | |||
668 | | ||||
669 | | ||||
670 | // protected slot | | |||
671 | void kpDocumentSaveOptionsWidget::updatePreviewDelayed () | | |||
672 | { | 522 | { | ||
673 | // (single shot) | 523 | // (single shot) | ||
674 | m_updatePreviewTimer->start (m_updatePreviewDelay); | 524 | m_updatePreviewTimer->start (m_updatePreviewDelay); | ||
675 | } | 525 | } | ||
676 | 526 | | |||
677 | // protected slot | 527 | // protected slot | ||
678 | void kpDocumentSaveOptionsWidget::updatePreview () | 528 | void kpDocumentSaveOptionsDialog::updatePreview () | ||
679 | { | 529 | { | ||
680 | if (!m_previewDialog || !m_documentPixmap) | 530 | if (!m_documentPixmap) | ||
681 | return; | 531 | return; | ||
682 | 532 | | |||
683 | 533 | | |||
Context not available. | |||||
715 | { | 565 | { | ||
716 | // Leave <image> as invalid. | 566 | // Leave <image> as invalid. | ||
717 | // TODO: This code path has not been well tested. | 567 | // TODO: This code path has not been well tested. | ||
718 | // Will we trigger divide by zero errors in "m_previewDialog"? | 568 | // Will we trigger divide by zero errors in "m_previewWidget"? | ||
719 | } | 569 | } | ||
720 | 570 | | |||
721 | // REFACTOR: merge with kpDocument::getPixmapFromFile() | 571 | // REFACTOR: merge with kpDocument::getPixmapFromFile() | ||
722 | m_previewDialog->setFilePixmapAndSize (image, data.size ()); | 572 | setFilePixmapAndSize (image, data.size ()); | ||
723 | 573 | | |||
724 | QApplication::restoreOverrideCursor (); | 574 | QApplication::restoreOverrideCursor (); | ||
725 | } | 575 | } | ||
726 | 576 | | |||
727 | // protected slot | 577 | | ||
728 | void kpDocumentSaveOptionsWidget::updatePreviewDialogLastRelativeGeometry () | 578 | // protected static | ||
579 | const QSize kpDocumentSaveOptionsDialog::s_pixmapLabelMinimumSize (25, 25); | ||||
580 | | ||||
581 | // public | ||||
582 | QSize kpDocumentSaveOptionsDialog::preferredMinimumSize () const | ||||
583 | { | ||||
584 | const int contentsWidth = 180; | ||||
585 | const int totalMarginsWidth = fontMetrics ().height (); | ||||
586 | | ||||
587 | return QSize (contentsWidth + totalMarginsWidth, | ||||
588 | contentsWidth * 3 / 4 + totalMarginsWidth); | ||||
589 | } | ||||
590 | | ||||
591 | | ||||
592 | // public slot | ||||
593 | void kpDocumentSaveOptionsDialog::setFilePixmapAndSize (const QImage &pixmap, | ||||
594 | qint64 fileSize) | ||||
595 | { | ||||
596 | delete m_filePixmap; | ||||
597 | m_filePixmap = new QImage (pixmap); | ||||
598 | | ||||
599 | updatePixmapPreview (); | ||||
600 | | ||||
601 | m_fileSize = fileSize; | ||||
602 | | ||||
603 | const kpCommandSize::SizeType pixmapSize = kpCommandSize::PixmapSize (pixmap); | ||||
604 | // (int cast is safe as long as the file size is not more than 20 million | ||||
605 | // -- i.e. INT_MAX / 100 -- times the pixmap size) | ||||
606 | const int percent = pixmapSize ? | ||||
607 | qMax (1, | ||||
608 | (int) ((kpCommandSize::SizeType) fileSize * 100 / pixmapSize)) : | ||||
609 | 0; | ||||
610 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||||
611 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsDialog::setFilePixmapAndSize()" | ||||
612 | << " pixmapSize=" << pixmapSize | ||||
613 | << " fileSize=" << fileSize | ||||
614 | << " raw fileSize/pixmapSize%=" | ||||
615 | << (pixmapSize ? (kpCommandSize::SizeType) fileSize * 100 / pixmapSize : 0) | ||||
616 | << endl; | ||||
617 | #endif | ||||
618 | | ||||
619 | m_fileSizeLabel->setText (i18np ("1 byte (approx. %2%)", "%1 bytes (approx. %2%)", | ||||
620 | m_fileSize, percent)); | ||||
621 | } | ||||
622 | | ||||
623 | // public slot | ||||
624 | void kpDocumentSaveOptionsDialog::updatePixmapPreview () | ||||
729 | { | 625 | { | ||
730 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 626 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
731 | qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::" | 627 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsDialog::updatePreviewPixmap()" | ||
732 | << "updatePreviewDialogLastRelativeGeometry()" | 628 | << " filePixmapLabel.size=" << m_filePixmapLabel->size () | ||
629 | << " filePixmap.size=" << m_filePixmap->size () | ||||
733 | << endl; | 630 | << endl; | ||
734 | #endif | 631 | #endif | ||
735 | 632 | | |||
736 | if (m_previewDialog && m_previewDialog->isVisible ()) | 633 | if (m_filePixmap) | ||
737 | { | 634 | { | ||
738 | m_previewDialogLastRelativeGeometry = | 635 | int maxNewWidth = qMin (m_filePixmap->width (), | ||
739 | kpWidgetMapper::fromGlobal (m_visualParent, | 636 | m_filePixmapLabel->width ()), | ||
740 | QRect (m_previewDialog->x (), m_previewDialog->y (), | 637 | maxNewHeight = qMin (m_filePixmap->height (), | ||
741 | m_previewDialog->width (), m_previewDialog->height ())); | 638 | m_filePixmapLabel->height ()); | ||
639 | | ||||
640 | double keepsAspect = kpTransformPreviewDialog::aspectScale ( | ||||
641 | maxNewWidth, maxNewHeight, | ||||
642 | m_filePixmap->width (), m_filePixmap->height ()); | ||||
742 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 643 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||
743 | qCDebug(kpLogWidgets) << "\tcaching pos = " | 644 | qCDebug(kpLogDialogs) << "\tmaxNewWidth=" << maxNewWidth | ||
744 | << m_previewDialogLastRelativeGeometry | 645 | << " maxNewHeight=" << maxNewHeight | ||
646 | << " keepsAspect=" << keepsAspect | ||||
745 | << endl; | 647 | << endl; | ||
746 | #endif | 648 | #endif | ||
649 | | ||||
650 | | ||||
651 | const int newWidth = kpTransformPreviewDialog::scaleDimension ( | ||||
652 | m_filePixmap->width (), | ||||
653 | keepsAspect, | ||||
654 | 1, | ||||
655 | maxNewWidth); | ||||
656 | const int newHeight = kpTransformPreviewDialog::scaleDimension ( | ||||
657 | m_filePixmap->height (), | ||||
658 | keepsAspect, | ||||
659 | 1, | ||||
660 | maxNewHeight); | ||||
661 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||||
662 | qCDebug(kpLogDialogs) << "\tnewWidth=" << newWidth | ||||
663 | << " newHeight=" << newHeight | ||||
664 | << endl; | ||||
665 | #endif | ||||
666 | | ||||
667 | | ||||
668 | QImage transformedPixmap = | ||||
669 | kpPixmapFX::scale (*m_filePixmap, | ||||
670 | newWidth, newHeight); | ||||
671 | | ||||
672 | | ||||
673 | QImage labelPixmap (m_filePixmapLabel->width (), | ||||
674 | m_filePixmapLabel->height (), QImage::Format_ARGB32_Premultiplied); | ||||
675 | labelPixmap.fill(QColor(Qt::transparent).rgba()); | ||||
676 | kpPixmapFX::setPixmapAt (&labelPixmap, | ||||
677 | (labelPixmap.width () - transformedPixmap.width ()) / 2, | ||||
678 | (labelPixmap.height () - transformedPixmap.height ()) / 2, | ||||
679 | transformedPixmap); | ||||
680 | | ||||
681 | | ||||
682 | m_filePixmapLabel->setPixmap (QPixmap::fromImage(labelPixmap)); | ||||
747 | } | 683 | } | ||
748 | else | 684 | else | ||
749 | { | 685 | { | ||
750 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | 686 | m_filePixmapLabel->setPixmap (QPixmap ()); | ||
751 | qCDebug(kpLogWidgets) << "\tnot visible - ignoring geometry"; | | |||
752 | #endif | | |||
753 | } | 687 | } | ||
754 | } | 688 | } | ||
755 | 689 | | |||
756 | 690 | | |||
691 | // protected virtual [base QDialog] | ||||
692 | void kpDocumentSaveOptionsDialog::resizeEvent (QResizeEvent *e) | ||||
693 | { | ||||
694 | #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET | ||||
695 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsDialog::resizeEvent()"; | ||||
696 | #endif | ||||
697 | | ||||
698 | QDialog::resizeEvent (e); | ||||
699 | | ||||
700 | emit resized (); | ||||
701 | } | ||||
Context not available. |