Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportZoomMode_p.cpp
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "KReportZoomMode_p.h" | 21 | #include "KReportZoomMode_p.h" | ||
22 | 22 | | |||
23 | #include <QCoreApplication> | 23 | #include <QCoreApplication> | ||
24 | 24 | | |||
25 | const char* const KReportZoomMode::modes[] = | 25 | namespace{ | ||
26 | static const char* const s_types[] = | ||||
26 | { | 27 | { | ||
27 | QT_TRANSLATE_NOOP("KReportZoomMode", "%1%"), | 28 | QT_TRANSLATE_NOOP("KReportZoomMode", "%1%"), | ||
28 | QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page Width"), | 29 | QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page Width"), | ||
29 | QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page"), | 30 | QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page"), | ||
30 | nullptr, | 31 | nullptr, | ||
31 | QT_TRANSLATE_NOOP("KReportZoomMode", "Actual Pixels"), | 32 | QT_TRANSLATE_NOOP("KReportZoomMode", "Actual Pixels"), | ||
32 | nullptr, | 33 | nullptr, | ||
33 | nullptr, | 34 | nullptr, | ||
34 | nullptr, | 35 | nullptr, | ||
35 | QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Text Width") | 36 | QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Text Width") | ||
36 | }; | 37 | }; | ||
37 | 38 | | |||
38 | qreal KReportZoomMode::minimumZoomValue = 0.2; | 39 | qreal s_minimumZoomValue = 0.2; | ||
39 | qreal KReportZoomMode::maximumZoomValue = 5.0; | 40 | qreal s_maximumZoomValue = 5.0; | ||
41 | } | ||||
40 | 42 | | |||
41 | QString KReportZoomMode::toString(Mode mode) | 43 | QString KReportZoomMode::toString(Type type) | ||
42 | { | 44 | { | ||
43 | return QCoreApplication::translate("KReportZoomMode", modes[mode]); | 45 | return tr(s_types[static_cast<int>(type)]); | ||
44 | } | 46 | } | ||
45 | 47 | | |||
46 | KReportZoomMode::Mode KReportZoomMode::toMode(const QString& mode) | 48 | KReportZoomMode::Type KReportZoomMode::toType(const QString& string) | ||
47 | { | 49 | { | ||
48 | if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_WIDTH])) | 50 | if(string == toString(Type::Width)) { | ||
49 | return ZOOM_WIDTH; | 51 | return Type::Width; | ||
50 | else | 52 | } else if (string == toString(Type::Page)) { | ||
51 | if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_PAGE])) | 53 | return Type::Page; | ||
52 | return ZOOM_PAGE; | 54 | } else if (string == toString(Type::Pixels)) { | ||
53 | else | 55 | return Type::Pixels; | ||
54 | if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_PIXELS])) | 56 | } else if (string == toString(Type::Text)) { | ||
55 | return ZOOM_PIXELS; | 57 | return Type::Text; | ||
56 | else | 58 | } else { | ||
57 | if(mode == QCoreApplication::translate("KReportZoomMode", modes[ZOOM_TEXT])) | 59 | // we return Constant else because then we can pass '10%' or '15%' | ||
58 | return ZOOM_TEXT; | 60 | // or whatever, it's automatically converted. Constant is | ||
59 | else | | |||
60 | return ZOOM_CONSTANT; | | |||
61 | // we return ZOOM_CONSTANT else because then we can pass '10%' or '15%' | | |||
62 | // or whatever, it's automatically converted. ZOOM_CONSTANT is | | |||
63 | // changeable, whereas all other zoom modes (non-constants) are normal | 61 | // changeable, whereas all other zoom modes (non-constants) are normal | ||
64 | // text like "Fit to xxx". they let the view grow/shrink according | 62 | // text like "Fit to xxx". they let the view grow/shrink according | ||
65 | // to windowsize, hence the term 'non-constant' | 63 | // to windowsize, hence the term 'non-constant' | ||
64 | return Type::Constant; | ||||
65 | } | ||||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | qreal KReportZoomMode::minimumZoom() | 68 | qreal KReportZoomMode::minimumZoom() | ||
69 | { | 69 | { | ||
70 | return minimumZoomValue; | 70 | return s_minimumZoomValue; | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | qreal KReportZoomMode::maximumZoom() | 73 | qreal KReportZoomMode::maximumZoom() | ||
74 | { | 74 | { | ||
75 | return maximumZoomValue; | 75 | return s_maximumZoomValue; | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | qreal KReportZoomMode::clampZoom(qreal zoom) | 78 | qreal KReportZoomMode::clampZoom(qreal zoom) | ||
79 | { | 79 | { | ||
80 | return qMin(maximumZoomValue, qMax(minimumZoomValue, zoom)); | 80 | return qMin(s_maximumZoomValue, qMax(s_minimumZoomValue, zoom)); | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | void KReportZoomMode::setMinimumZoom(qreal zoom) | 83 | void KReportZoomMode::setMinimumZoom(qreal zoom) | ||
84 | { | 84 | { | ||
85 | Q_ASSERT(zoom > 0.0f); | 85 | Q_ASSERT(zoom > 0.0f); | ||
86 | minimumZoomValue = zoom; | 86 | s_minimumZoomValue = zoom; | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | void KReportZoomMode::setMaximumZoom(qreal zoom) | 89 | void KReportZoomMode::setMaximumZoom(qreal zoom) | ||
90 | { | 90 | { | ||
91 | Q_ASSERT(zoom > 0.0f); | 91 | Q_ASSERT(zoom > 0.0f); | ||
92 | maximumZoomValue = zoom; | 92 | s_maximumZoomValue = zoom; | ||
93 | } | 93 | } |