Warning, file /office/calligra/libs/widgets/KoZoomMode.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005 Johannes Schaub <litb_devel@web.de>
0003    Copyright (C) 2011 Arjen Hiemstra <ahiemstra@heimr.nl>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "KoZoomMode.h"
0022 #include <klocalizedstring.h>
0023 
0024 const char* const KoZoomMode::modes[] =
0025 {
0026     I18N_NOOP("%1%"),
0027     I18N_NOOP("Fit Page Width"),
0028     I18N_NOOP("Fit Page"),
0029     nullptr,
0030     I18N_NOOP("Actual Pixels"),
0031     nullptr,
0032     nullptr,
0033     nullptr,
0034     I18N_NOOP("Fit Text Width")
0035 };
0036 
0037 qreal KoZoomMode::minimumZoomValue = 0.2;
0038 qreal KoZoomMode::maximumZoomValue = 5.0;
0039 
0040 QString KoZoomMode::toString(Mode mode)
0041 {
0042     return i18n(modes[mode]);
0043 }
0044 
0045 KoZoomMode::Mode KoZoomMode::toMode(const QString& mode)
0046 {
0047     if(mode == i18n(modes[ZOOM_WIDTH]))
0048         return ZOOM_WIDTH;
0049     else if(mode == i18n(modes[ZOOM_PAGE]))
0050         return ZOOM_PAGE;
0051     else if(mode == i18n(modes[ZOOM_PIXELS]))
0052         return ZOOM_PIXELS;
0053     else if(mode == i18n(modes[ZOOM_TEXT]))
0054         return ZOOM_TEXT;
0055     else
0056        return ZOOM_CONSTANT;
0057     // we return ZOOM_CONSTANT else because then we can pass '10%' or '15%'
0058     // or whatever, it's automatically converted. ZOOM_CONSTANT is
0059     // changeable, whereas all other zoom modes (non-constants) are normal
0060     // text like "Fit to xxx". they let the view grow/shrink according
0061     // to windowsize, hence the term 'non-constant'
0062 }
0063 
0064 qreal KoZoomMode::minimumZoom()
0065 {
0066     return minimumZoomValue;
0067 }
0068 
0069 qreal KoZoomMode::maximumZoom()
0070 {
0071     return maximumZoomValue;
0072 }
0073 
0074 qreal KoZoomMode::clampZoom(qreal zoom)
0075 {
0076     return qMin(maximumZoomValue, qMax(minimumZoomValue, zoom));
0077 }
0078 
0079 void KoZoomMode::setMinimumZoom(qreal zoom)
0080 {
0081     Q_ASSERT(zoom > 0.0f);
0082     minimumZoomValue = zoom;
0083 }
0084 
0085 void KoZoomMode::setMaximumZoom(qreal zoom)
0086 {
0087     Q_ASSERT(zoom > 0.0f);
0088     maximumZoomValue = zoom;
0089 }