File indexing completed on 2024-04-28 04:42:12
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 "KReportZoomMode_p.h" 0022 0023 #include <QCoreApplication> 0024 0025 namespace{ 0026 static const char* const s_types[] = 0027 { 0028 QT_TRANSLATE_NOOP("KReportZoomMode", "%1%"), 0029 QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page Width"), 0030 QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Page"), 0031 nullptr, 0032 QT_TRANSLATE_NOOP("KReportZoomMode", "Actual Pixels"), 0033 nullptr, 0034 nullptr, 0035 nullptr, 0036 QT_TRANSLATE_NOOP("KReportZoomMode", "Fit Text Width") 0037 }; 0038 0039 qreal s_minimumZoomValue = 0.2; 0040 qreal s_maximumZoomValue = 5.0; 0041 } 0042 0043 QString KReportZoomMode::toString(Type type) 0044 { 0045 return tr(s_types[static_cast<int>(type)]); 0046 } 0047 0048 KReportZoomMode::Type KReportZoomMode::toType(const QString& string) 0049 { 0050 if(string == toString(Type::Width)) { 0051 return Type::Width; 0052 } else if (string == toString(Type::Page)) { 0053 return Type::Page; 0054 } else if (string == toString(Type::Pixels)) { 0055 return Type::Pixels; 0056 } else if (string == toString(Type::Text)) { 0057 return Type::Text; 0058 } else { 0059 // we return Constant else because then we can pass '10%' or '15%' 0060 // or whatever, it's automatically converted. Constant is 0061 // changeable, whereas all other zoom modes (non-constants) are normal 0062 // text like "Fit to xxx". they let the view grow/shrink according 0063 // to windowsize, hence the term 'non-constant' 0064 return Type::Constant; 0065 } 0066 } 0067 0068 qreal KReportZoomMode::minimumZoom() 0069 { 0070 return s_minimumZoomValue; 0071 } 0072 0073 qreal KReportZoomMode::maximumZoom() 0074 { 0075 return s_maximumZoomValue; 0076 } 0077 0078 qreal KReportZoomMode::clampZoom(qreal zoom) 0079 { 0080 return qMin(s_maximumZoomValue, qMax(s_minimumZoomValue, zoom)); 0081 } 0082 0083 void KReportZoomMode::setMinimumZoom(qreal zoom) 0084 { 0085 Q_ASSERT(zoom > 0.0f); 0086 s_minimumZoomValue = zoom; 0087 } 0088 0089 void KReportZoomMode::setMaximumZoom(qreal zoom) 0090 { 0091 Q_ASSERT(zoom > 0.0f); 0092 s_maximumZoomValue = zoom; 0093 }