File indexing completed on 2024-05-12 16:35:43
0001 /* This file is part of the KDE project 0002 Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 Copyright 2006 Robert Knight <robertknight@gmail.com> 0004 Copyright 2006 Inge Wallin <inge@lysator.liu.se> 0005 Copyright 1999-2002,2004 Laurent Montel <montel@kde.org> 0006 Copyright 2002-2005 Ariya Hidayat <ariya@kde.org> 0007 Copyright 1999-2004 David Faure <faure@kde.org> 0008 Copyright 2004-2005 Meni Livne <livne@kde.org> 0009 Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de> 0010 Copyright 2002-2003 Norbert Andres <nandres@web.de> 0011 Copyright 2003 Hamish Rodda <rodda@kde.org> 0012 Copyright 2003 Joseph Wenninger <jowenn@kde.org> 0013 Copyright 2003 Lukas Tinkl <lukas@kde.org> 0014 Copyright 2000-2002 Werner Trobin <trobin@kde.org> 0015 Copyright 2002 Harri Porten <porten@kde.org> 0016 Copyright 2002 John Dailey <dailey@vt.edu> 0017 Copyright 2002 Daniel Naber <daniel.naber@t-online.de> 0018 Copyright 1999-2000 Torben Weis <weis@kde.org> 0019 Copyright 1999-2000 Stephan Kulow <coolo@kde.org> 0020 Copyright 2000 Bernd Wuebben <wuebben@kde.org> 0021 Copyright 2000 Wilco Greven <greven@kde.org> 0022 Copyright 2000 Simon Hausmann <hausmann@kde.org 0023 Copyright 1999 Michael Reiher <michael.reiher@gmx.de> 0024 Copyright 1999 Boris Wedl <boris.wedl@kfunigraz.ac.at> 0025 Copyright 1999 Reginald Stadlbauer <reggie@kde.org> 0026 0027 This library is free software; you can redistribute it and/or 0028 modify it under the terms of the GNU Library General Public 0029 License as published by the Free Software Foundation; either 0030 version 2 of the License, or (at your option) any later version. 0031 0032 This library is distributed in the hope that it will be useful, 0033 but WITHOUT ANY WARRANTY; without even the implied warranty of 0034 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0035 Library General Public License for more details. 0036 0037 You should have received a copy of the GNU Library General Public License 0038 along with this library; see the file COPYING.LIB. If not, write to 0039 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0040 Boston, MA 02110-1301, USA. 0041 */ 0042 0043 // Local 0044 #include "CellTool.h" 0045 0046 #include <QPainter> 0047 0048 #include <KLocalizedString> 0049 0050 #include <KoCanvasBase.h> 0051 #include <KoCanvasController.h> 0052 #include <KoPointerEvent.h> 0053 #include <KoSelection.h> 0054 #include <KoShapeManager.h> 0055 #include <KoViewConverter.h> 0056 0057 #include "SheetsDebug.h" 0058 #include "Cell.h" 0059 #include "Canvas.h" 0060 #include "Doc.h" 0061 #include "calligra_sheets_limits.h" 0062 #include "PrintSettings.h" 0063 #include "Sheet.h" 0064 #include "StyleManager.h" 0065 #include "Util.h" 0066 #include "View.h" 0067 0068 #include "commands/AutoFillCommand.h" 0069 #include "commands/DefinePrintRangeCommand.h" 0070 0071 #include "ui/CellView.h" 0072 #include "ui/Selection.h" 0073 #include "ui/SheetView.h" 0074 0075 using namespace Calligra::Sheets; 0076 0077 class Q_DECL_HIDDEN CellTool::Private 0078 { 0079 public: 0080 CanvasBase* canvas; 0081 }; 0082 0083 CellTool::CellTool(KoCanvasBase* canvas) 0084 : CellToolBase(canvas) 0085 , d(new Private) 0086 { 0087 d->canvas = static_cast<CanvasBase*>(canvas); 0088 0089 QAction* action = 0; 0090 0091 // -- misc actions -- 0092 0093 action = new QAction(i18n("Define Print Range"), this); 0094 addAction("definePrintRange", action); 0095 connect(action, SIGNAL(triggered(bool)), this, SLOT(definePrintRange())); 0096 action->setToolTip(i18n("Define the print range in the current sheet")); 0097 } 0098 0099 CellTool::~CellTool() 0100 { 0101 delete d; 0102 } 0103 0104 void CellTool::paint(QPainter &painter, const KoViewConverter &viewConverter) 0105 { 0106 KoShape::applyConversion(painter, viewConverter); 0107 const double xOffset = viewConverter.viewToDocumentX(canvas()->canvasController()->canvasOffsetX()); 0108 const double yOffset = viewConverter.viewToDocumentY(canvas()->canvasController()->canvasOffsetY()); 0109 // The visible area in document coordinates: 0110 const QRectF paintRect = QRectF(QPointF(-xOffset, -yOffset), size()); 0111 0112 /* paint the selection */ 0113 paintReferenceSelection(painter, paintRect); 0114 paintSelection(painter, paintRect); 0115 } 0116 0117 void CellTool::activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) 0118 { 0119 canvas()->shapeManager()->selection()->deselectAll(); 0120 CellToolBase::activate(toolActivation, shapes); 0121 } 0122 0123 Calligra::Sheets::Selection* CellTool::selection() 0124 { 0125 return d->canvas->selection(); 0126 } 0127 0128 QPointF CellTool::offset() const 0129 { 0130 return QPointF(0.0, 0.0); 0131 } 0132 0133 QSizeF CellTool::size() const 0134 { 0135 return canvas()->viewConverter()->viewToDocument(d->canvas->size()); 0136 } 0137 0138 QPointF CellTool::canvasOffset() const 0139 { 0140 return d->canvas->offset(); 0141 } 0142 0143 int CellTool::maxCol() const 0144 { 0145 return KS_colMax; 0146 } 0147 0148 int CellTool::maxRow() const 0149 { 0150 return KS_rowMax; 0151 } 0152 0153 SheetView* CellTool::sheetView(const Sheet* sheet) const 0154 { 0155 return d->canvas->sheetView(sheet); 0156 } 0157 0158 void CellTool::definePrintRange() 0159 { 0160 DefinePrintRangeCommand* command = new DefinePrintRangeCommand(); 0161 command->setSheet(selection()->activeSheet()); 0162 command->add(*selection()); 0163 d->canvas->doc()->addCommand(command); 0164 }