File indexing completed on 2024-05-12 16:34:23

0001 /* This file is part of the KDE project
0002    Copyright 2011 Silvio Heinrich <plassy@web.de>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "ClippingRect.h"
0021 
0022 ClippingRect::ClippingRect():
0023     top(0),
0024     right(1),
0025     bottom(1),
0026     left(0),
0027     uniform(true),
0028     inverted(false)
0029 {
0030 }
0031 
0032 ClippingRect::ClippingRect(const ClippingRect& rect):
0033     top(rect.top),
0034     right(rect.right),
0035     bottom(rect.bottom),
0036     left(rect.left),
0037     uniform(rect.uniform),
0038     inverted(rect.inverted)
0039 {
0040 }
0041 
0042 ClippingRect::ClippingRect(const QRectF& rect, bool isUniform)
0043 {
0044     setRect(rect, isUniform);
0045 }
0046 
0047 void ClippingRect::scale(const QSizeF& size, bool isUniform)
0048 {
0049     top *= size.height();
0050     right *= size.width();
0051     bottom *= size.height();
0052     left *= size.width();
0053     uniform = isUniform;
0054 }
0055 
0056 void ClippingRect::normalize(const QSizeF& size)
0057 {
0058     if (!uniform) {
0059         scale(QSizeF(1.0/size.width(), 1.0/size.height()), true);
0060     }
0061 
0062     if(inverted) {
0063         right = 1.0 - right;
0064         bottom = 1.0 - bottom;
0065         inverted = false;
0066     }
0067 }
0068 
0069 void ClippingRect::setRect(const QRectF& rect, bool isUniform)
0070 {
0071     top = rect.top();
0072     right = rect.right();
0073     bottom = rect.bottom();
0074     left = rect.left();
0075     uniform = isUniform;
0076     inverted = false;
0077 }
0078 
0079 qreal ClippingRect::width() const
0080 {
0081     return right - left;
0082 }
0083 
0084 qreal ClippingRect::height() const
0085 {
0086     return bottom - top;
0087 }
0088 
0089 QRectF ClippingRect::toRect() const
0090 {
0091     return QRectF(left, top, width(), height());
0092 }