File indexing completed on 2024-05-12 16:36:09

0001 /* This file is part of the KDE project
0002    Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
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 "RightToLeftPaintingStrategy.h"
0021 
0022 #include <QPainter>
0023 #include <QGraphicsWidget>
0024 #include <QWidget>
0025 
0026 #include <KoCanvasBase.h>
0027 #include <KoCanvasController.h>
0028 #include <KoShape.h>
0029 #include <KoShapeManager.h>
0030 #include <KoViewConverter.h>
0031 
0032 using namespace Calligra::Sheets;
0033 
0034 class RightToLeftPaintingStrategy::Private
0035 {
0036 public:
0037     KoCanvasBase *canvas;
0038 };
0039 
0040 
0041 RightToLeftPaintingStrategy::RightToLeftPaintingStrategy(KoShapeManager *shapeManager, KoCanvasBase *canvas)
0042         : KoShapeManagerPaintingStrategy(shapeManager)
0043         , d(new Private)
0044 {
0045     d->canvas = canvas;
0046 }
0047 
0048 RightToLeftPaintingStrategy::~RightToLeftPaintingStrategy()
0049 {
0050     delete d;
0051 }
0052 
0053 void RightToLeftPaintingStrategy::paint(KoShape *shape, QPainter &painter,
0054                                         const KoViewConverter &converter, KoShapePaintingContext &paintContext)
0055 {
0056     painter.save();
0057     const double width = d->canvas->canvasWidget() ? d->canvas->canvasWidget()->width() :
0058                          dynamic_cast<QGraphicsWidget*>(d->canvas->canvasItem()) ? dynamic_cast<QGraphicsWidget*>(d->canvas->canvasItem())->size().width() : 0;
0059 //    const double offsetX = d->canvas->canvasController()->canvasOffsetX();
0060     painter.translate(/*-2 * offsetX*/ + width, 0);
0061 //     painter.scale(-1, 1);
0062 
0063     painter.setTransform(shape->absoluteTransformation(&converter) * painter.transform());
0064 
0065     if (shapeManager()) {
0066         shapeManager()->paintShape(shape, painter, converter, paintContext);
0067     }
0068 
0069     painter.restore();  // for the matrix
0070 }
0071 
0072 void RightToLeftPaintingStrategy::adapt(KoShape *shape, QRectF &rect)
0073 {
0074     Q_UNUSED(shape)
0075     Q_UNUSED(rect)
0076     /*    const double width = d->canvas->canvasWidget()->width();
0077         const double offsetX = d->canvas->canvasController()->canvasOffsetX();
0078         const qreal left = width - rect.right();
0079         const qreal right = width - rect.left();
0080         rect.setLeft(left);
0081         rect.setRight(right);*/
0082 //     rect.translate(/*-2 * offsetX +*/ width, 0);
0083 }