Changeset View
Changeset View
Standalone View
Standalone View
dialogs/kpDocumentSaveOptionsPreviewDialog.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
55 | kpDocumentSaveOptionsPreviewDialog::kpDocumentSaveOptionsPreviewDialog ( | 55 | kpDocumentSaveOptionsPreviewDialog::kpDocumentSaveOptionsPreviewDialog ( | ||
56 | QWidget *parent ) | 56 | QWidget *parent ) | ||
57 | : kpSubWindow (parent), | 57 | : kpSubWindow (parent), | ||
58 | m_filePixmap (nullptr), | 58 | m_filePixmap (nullptr), | ||
59 | m_fileSize (0) | 59 | m_fileSize (0) | ||
60 | { | 60 | { | ||
61 | setWindowTitle (i18nc ("@title:window", "Save Preview")); | 61 | setWindowTitle (i18nc ("@title:window", "Save Preview")); | ||
62 | 62 | | |||
63 | QWidget *baseWidget = this;//new QWidget (this); | 63 | auto *baseWidget = this;//new QWidget (this); | ||
64 | //setMainWidget (baseWidget); | 64 | //setMainWidget (baseWidget); | ||
65 | 65 | | |||
66 | 66 | | |||
67 | QGridLayout *lay = new QGridLayout ( baseWidget ); | 67 | auto *lay = new QGridLayout ( baseWidget ); | ||
68 | 68 | | |||
69 | m_filePixmapLabel = new kpResizeSignallingLabel (baseWidget); | 69 | m_filePixmapLabel = new kpResizeSignallingLabel (baseWidget); | ||
70 | m_fileSizeLabel = new QLabel (baseWidget); | 70 | m_fileSizeLabel = new QLabel (baseWidget); | ||
71 | 71 | | |||
72 | 72 | | |||
73 | m_filePixmapLabel->setMinimumSize (s_pixmapLabelMinimumSize); | 73 | m_filePixmapLabel->setMinimumSize (s_pixmapLabelMinimumSize); | ||
74 | 74 | | |||
75 | 75 | | |||
Show All 12 Lines | |||||
88 | { | 88 | { | ||
89 | delete m_filePixmap; | 89 | delete m_filePixmap; | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | 92 | | |||
93 | // public | 93 | // public | ||
94 | QSize kpDocumentSaveOptionsPreviewDialog::preferredMinimumSize () const | 94 | QSize kpDocumentSaveOptionsPreviewDialog::preferredMinimumSize () const | ||
95 | { | 95 | { | ||
96 | const int contentsWidth = 180; | 96 | const auto contentsWidth = 180; | ||
97 | const int totalMarginsWidth = fontMetrics ().height (); | 97 | const auto totalMarginsWidth = fontMetrics ().height (); | ||
98 | 98 | | |||
99 | return QSize (contentsWidth + totalMarginsWidth, | 99 | return {contentsWidth + totalMarginsWidth, contentsWidth * 3 / 4 + totalMarginsWidth}; | ||
100 | contentsWidth * 3 / 4 + totalMarginsWidth); | | |||
101 | } | 100 | } | ||
102 | 101 | | |||
103 | 102 | | |||
104 | // public slot | 103 | // public slot | ||
105 | void kpDocumentSaveOptionsPreviewDialog::setFilePixmapAndSize (const QImage &pixmap, | 104 | void kpDocumentSaveOptionsPreviewDialog::setFilePixmapAndSize (const QImage &pixmap, | ||
106 | qint64 fileSize) | 105 | qint64 fileSize) | ||
107 | { | 106 | { | ||
108 | delete m_filePixmap; | 107 | delete m_filePixmap; | ||
Show All 9 Lines | |||||
118 | const int percent = pixmapSize ? | 117 | const int percent = pixmapSize ? | ||
119 | qMax (1, | 118 | qMax (1, | ||
120 | static_cast<int> (static_cast<kpCommandSize::SizeType> (fileSize * 100 / pixmapSize))) : | 119 | static_cast<int> (static_cast<kpCommandSize::SizeType> (fileSize * 100 / pixmapSize))) : | ||
121 | 0; | 120 | 0; | ||
122 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsPreviewDialog::setFilePixmapAndSize()" | 121 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsPreviewDialog::setFilePixmapAndSize()" | ||
123 | << " pixmapSize=" << pixmapSize | 122 | << " pixmapSize=" << pixmapSize | ||
124 | << " fileSize=" << fileSize | 123 | << " fileSize=" << fileSize | ||
125 | << " raw fileSize/pixmapSize%=" | 124 | << " raw fileSize/pixmapSize%=" | ||
126 | << (pixmapSize ? (kpCommandSize::SizeType) fileSize * 100 / pixmapSize : 0) | 125 | << (pixmapSize ? (kpCommandSize::SizeType) fileSize * 100 / pixmapSize : 0); | ||
127 | << endl; | | |||
128 | 126 | | |||
129 | m_fileSizeLabel->setText (i18np ("1 byte (approx. %2%)", "%1 bytes (approx. %2%)", | 127 | m_fileSizeLabel->setText (i18np ("1 byte (approx. %2%)", "%1 bytes (approx. %2%)", | ||
130 | m_fileSize, percent)); | 128 | m_fileSize, percent)); | ||
131 | } | 129 | } | ||
132 | 130 | | |||
133 | // public slot | 131 | // public slot | ||
134 | void kpDocumentSaveOptionsPreviewDialog::updatePixmapPreview () | 132 | void kpDocumentSaveOptionsPreviewDialog::updatePixmapPreview () | ||
135 | { | 133 | { | ||
136 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsPreviewDialog::updatePreviewPixmap()" | 134 | qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsPreviewDialog::updatePreviewPixmap()" | ||
137 | << " filePixmapLabel.size=" << m_filePixmapLabel->size () | 135 | << " filePixmapLabel.size=" << m_filePixmapLabel->size () | ||
138 | << " filePixmap.size=" << m_filePixmap->size () | 136 | << " filePixmap.size=" << m_filePixmap->size (); | ||
139 | << endl; | | |||
140 | 137 | | |||
141 | if (m_filePixmap) | 138 | if (m_filePixmap) | ||
142 | { | 139 | { | ||
143 | int maxNewWidth = qMin (m_filePixmap->width (), | 140 | int maxNewWidth = qMin (m_filePixmap->width (), | ||
144 | m_filePixmapLabel->width ()), | 141 | m_filePixmapLabel->width ()), | ||
145 | maxNewHeight = qMin (m_filePixmap->height (), | 142 | maxNewHeight = qMin (m_filePixmap->height (), | ||
146 | m_filePixmapLabel->height ()); | 143 | m_filePixmapLabel->height ()); | ||
147 | 144 | | |||
148 | double keepsAspect = kpTransformPreviewDialog::aspectScale ( | 145 | double keepsAspect = kpTransformPreviewDialog::aspectScale ( | ||
149 | maxNewWidth, maxNewHeight, | 146 | maxNewWidth, maxNewHeight, | ||
150 | m_filePixmap->width (), m_filePixmap->height ()); | 147 | m_filePixmap->width (), m_filePixmap->height ()); | ||
151 | qCDebug(kpLogDialogs) << "\tmaxNewWidth=" << maxNewWidth | 148 | qCDebug(kpLogDialogs) << "\tmaxNewWidth=" << maxNewWidth | ||
152 | << " maxNewHeight=" << maxNewHeight | 149 | << " maxNewHeight=" << maxNewHeight | ||
153 | << " keepsAspect=" << keepsAspect | 150 | << " keepsAspect=" << keepsAspect; | ||
154 | << endl; | | |||
155 | 151 | | |||
156 | 152 | | |||
157 | const int newWidth = kpTransformPreviewDialog::scaleDimension ( | 153 | const int newWidth = kpTransformPreviewDialog::scaleDimension ( | ||
158 | m_filePixmap->width (), | 154 | m_filePixmap->width (), | ||
159 | keepsAspect, | 155 | keepsAspect, | ||
160 | 1, | 156 | 1, | ||
161 | maxNewWidth); | 157 | maxNewWidth); | ||
162 | const int newHeight = kpTransformPreviewDialog::scaleDimension ( | 158 | const int newHeight = kpTransformPreviewDialog::scaleDimension ( | ||
163 | m_filePixmap->height (), | 159 | m_filePixmap->height (), | ||
164 | keepsAspect, | 160 | keepsAspect, | ||
165 | 1, | 161 | 1, | ||
166 | maxNewHeight); | 162 | maxNewHeight); | ||
167 | qCDebug(kpLogDialogs) << "\tnewWidth=" << newWidth | 163 | qCDebug(kpLogDialogs) << "\tnewWidth=" << newWidth | ||
168 | << " newHeight=" << newHeight | 164 | << " newHeight=" << newHeight; | ||
169 | << endl; | | |||
170 | 165 | | |||
171 | 166 | | |||
172 | QImage transformedPixmap = | 167 | QImage transformedPixmap = | ||
173 | kpPixmapFX::scale (*m_filePixmap, | 168 | kpPixmapFX::scale (*m_filePixmap, | ||
174 | newWidth, newHeight); | 169 | newWidth, newHeight); | ||
175 | 170 | | |||
176 | 171 | | |||
177 | QImage labelPixmap (m_filePixmapLabel->width (), | 172 | QImage labelPixmap (m_filePixmapLabel->width (), | ||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |