File indexing completed on 2024-05-12 16:02:14

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2005 Johannes Schaub <litb_devel@web.de>
0003    SPDX-FileCopyrightText: 2011 Arjen Hiemstra <ahiemstra@heimr.nl>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "KoZoomMode.h"
0009 #include <klocalizedstring.h>
0010 
0011 const char* const KoZoomMode::modes[] =
0012 {
0013     I18N_NOOP("%1%"),
0014     I18N_NOOP("Fit Page Width"),
0015     I18N_NOOP("Fit Page"),
0016     0,
0017     I18N_NOOP("Actual Pixels"),
0018     0,
0019     0,
0020     0,
0021     I18N_NOOP("Fit Text Width"),
0022     0,
0023     0,
0024     0,
0025     0,
0026     0,
0027     0,
0028     0,
0029     I18N_NOOP("Fit Page Height")
0030 };
0031 
0032 qreal KoZoomMode::minimumZoomValue = 0.2;
0033 qreal KoZoomMode::maximumZoomValue = 5.0;
0034 
0035 QString KoZoomMode::toString(Mode mode)
0036 {
0037     return i18n(modes[mode]);
0038 }
0039 
0040 KoZoomMode::Mode KoZoomMode::toMode(const QString& mode)
0041 {
0042     if (mode == i18n(modes[ZOOM_WIDTH]))
0043         return ZOOM_WIDTH;
0044     else
0045         if (mode == i18n(modes[ZOOM_PAGE]))
0046             return ZOOM_PAGE;
0047         else
0048             if (mode == i18n(modes[ZOOM_PIXELS]))
0049                 return ZOOM_PIXELS;
0050             else
0051                 if (mode == i18n(modes[ZOOM_HEIGHT]))
0052                     return ZOOM_HEIGHT;
0053                 else
0054                     return ZOOM_CONSTANT;
0055     // we return ZOOM_CONSTANT else because then we can pass '10%' or '15%'
0056     // or whatever, it's automatically converted. ZOOM_CONSTANT is
0057     // changeable, whereas all other zoom modes (non-constants) are normal
0058     // text like "Fit to xxx". they let the view grow/shrink according
0059     // to windowsize, hence the term 'non-constant'
0060 }
0061 
0062 qreal KoZoomMode::minimumZoom()
0063 {
0064     return minimumZoomValue;
0065 }
0066 
0067 qreal KoZoomMode::maximumZoom()
0068 {
0069     return maximumZoomValue;
0070 }
0071 
0072 void KoZoomMode::setMinimumZoom(qreal zoom)
0073 {
0074     Q_ASSERT(zoom > 0.0f);
0075     minimumZoomValue = zoom;
0076 }
0077 
0078 void KoZoomMode::setMaximumZoom(qreal zoom)
0079 {
0080     Q_ASSERT(zoom > 0.0f);
0081     maximumZoomValue = zoom;
0082 }