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

0001 /* This file is part of the KDE project
0002    Copyright 2006-2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
0004    Copyright 2002-2004 Ariya Hidayat <ariya@kde.org>
0005    Copyright 1999-2003 Laurent Montel <montel@kde.org>
0006    Copyright 2002-2003 Norbert Andres <nandres@web.de>
0007    Copyright 2002-2003 Philipp Mueller <philipp.mueller@gmx.de>
0008    Copyright 2002-2003 John Dailey <dailey@vt.edu>
0009    Copyright 1999-2003 David Faure <faure@kde.org>
0010    Copyright 1999-2001 Simon Hausmann <hausmann@kde.org>
0011    Copyright 1998-2000 Torben Weis <weis@kde.org>
0012 
0013    This library is free software; you can redistribute it and/or
0014    modify it under the terms of the GNU Library General Public
0015    License as published by the Free Software Foundation; either
0016    version 2 of the License, or (at your option) any later version.
0017 
0018    This library is distributed in the hope that it will be useful,
0019    but WITHOUT ANY WARRANTY; without even the implied warranty of
0020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0021    Library General Public License for more details.
0022 
0023    You should have received a copy of the GNU Library General Public License
0024    along with this library; see the file COPYING.LIB.  If not, write to
0025    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0026    Boston, MA 02110-1301, USA.
0027 */
0028 
0029 #ifndef CALLIGRA_SHEETS_CELL_TOOL_BASE
0030 #define CALLIGRA_SHEETS_CELL_TOOL_BASE
0031 
0032 #include <KoInteractionTool.h>
0033 
0034 #include <sheets/Cell.h>
0035 #include "sheets_common_export.h"
0036 #include "Selection.h"
0037 
0038 class KoColor;
0039 
0040 namespace Calligra
0041 {
0042 namespace Sheets
0043 {
0044 class ExternalEditor;
0045 class SheetView;
0046 class CellEditorBase;
0047 
0048 /**
0049  * Abstract tool providing actions acting on cell ranges.
0050  */
0051 class CALLIGRA_SHEETS_COMMON_EXPORT CellToolBase : public KoInteractionTool
0052 {
0053     Q_OBJECT
0054 
0055 public:
0056     /**
0057      * The editor type.
0058      */
0059     enum Editor {
0060         EmbeddedEditor,  ///< the embedded editor appearing in a cell
0061         ExternalEditor   ///< the external editor located in the tool options
0062     };
0063 
0064     /**
0065      * Constructor.
0066      */
0067     explicit CellToolBase(KoCanvasBase *canvas);
0068 
0069     /**
0070      * Destructor.
0071      */
0072     ~CellToolBase() override;
0073 
0074     void paint(QPainter &painter, const KoViewConverter &converter) override;
0075     void paintReferenceSelection(QPainter &painter, const QRectF &paintRect);
0076     void paintSelection(QPainter &painter, const QRectF &paintRect);
0077 
0078     void mousePressEvent(KoPointerEvent* event) override;
0079     void mouseMoveEvent(KoPointerEvent* event) override;
0080     void mouseReleaseEvent(KoPointerEvent* event) override;
0081     void mouseDoubleClickEvent(KoPointerEvent* event) override;
0082     void keyPressEvent(QKeyEvent* event) override;
0083     void inputMethodEvent(QInputMethodEvent * event) override;
0084 
0085     Selection* selection() override = 0;
0086 
0087     void deleteSelection() override;
0088 
0089     virtual bool createEditor(bool clear = true, bool focus = true, bool captureArrows = false);
0090     virtual CellEditorBase* editor() const;
0091 
0092     /**
0093      * Sets the editor \p type, which had the focus at last.
0094      */
0095     void setLastEditorWithFocus(Editor type);
0096 
0097     /**
0098      * Sets an external editor to be associated with the internal editor of this tool.
0099      */
0100     void setExternalEditor(Calligra::Sheets::ExternalEditor* editor);
0101 
0102     /**
0103      * The shape offset in document coordinates.
0104      */
0105     virtual QPointF offset() const = 0;
0106     virtual QSizeF size() const = 0;
0107 
0108 public Q_SLOTS:
0109     /**
0110      * Scrolls to the cell located at \p location.
0111      */
0112     void scrollToCell(const QPoint &location);
0113 
0114     void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) override;
0115     void deactivate() override;
0116     virtual void deleteEditor(bool saveChanges, bool expandMatrix = false);
0117     void populateWordCollection();
0118 
0119 protected:
0120     void init();
0121     QList<QPointer<QWidget> > createOptionWidgets() override;
0122     void applyUserInput(const QString &userInput, bool expandMatrix = false);
0123     KoInteractionStrategy* createStrategy(KoPointerEvent* event) override;
0124 
0125     /**
0126      * The canvas scrolling offset in document coordinates.
0127      */
0128     virtual QPointF canvasOffset() const = 0;
0129     virtual int maxCol() const = 0;
0130     virtual int maxRow() const = 0;
0131     virtual SheetView* sheetView(const Sheet* sheet) const = 0;
0132 
0133 protected Q_SLOTS:
0134     void selectionChanged(const Region&);
0135     void activeSheetChanged(Sheet*);
0136     void updateEditor();
0137     void focusEditorRequested();
0138     void documentReadWriteToggled(bool enable);
0139     void sheetProtectionToggled(bool enable);
0140 
0141     // -- cell style actions --
0142     void cellStyle();
0143     void setDefaultStyle();
0144     void styleDialog();
0145     void setStyle(const QString& name);
0146     void createStyleFromCell();
0147     // -- font actions --
0148     void bold(bool enable);
0149     void italic(bool enable);
0150     void underline(bool enable);
0151     void strikeOut(bool enable);
0152     void font(const QString& font);
0153     void fontSize(int size);
0154     void increaseFontSize();
0155     void decreaseFontSize();
0156     void changeTextColor(const KoColor &);
0157     // -- horizontal alignment actions --
0158     void alignLeft(bool enable);
0159     void alignRight(bool enable);
0160     void alignCenter(bool enable);
0161     // -- vertical alignment actions --
0162     void alignTop(bool enable);
0163     void alignMiddle(bool enable);
0164     void alignBottom(bool enable);
0165     // -- border actions --
0166     void borderLeft();
0167     void borderRight();
0168     void borderTop();
0169     void borderBottom();
0170     void borderAll();
0171     void borderRemove();
0172     void borderOutline();
0173     void borderColor(const KoColor &);
0174     // -- text layout actions --
0175     void wrapText(bool enable);
0176     void verticalText(bool enable);
0177     void increaseIndentation();
0178     void decreaseIndentation();
0179     void changeAngle();
0180     // -- value format actions --
0181     void percent(bool enable);
0182     void currency(bool enable);
0183     void increasePrecision();
0184     void decreasePrecision();
0185     // -- misc style attribute actions --
0186     void toUpperCase();
0187     void toLowerCase();
0188     void firstLetterToUpperCase();
0189     void changeBackgroundColor(const KoColor &);
0190     // -- cell merging actions --
0191     void mergeCells();
0192     void mergeCellsHorizontal();
0193     void mergeCellsVertical();
0194     void dissociateCells();
0195     // -- column & row actions --
0196     void resizeColumn();
0197     void insertColumn();
0198     void deleteColumn();
0199     void hideColumn();
0200     void showColumn();
0201     void slotShowColumnDialog();
0202     void equalizeColumn();
0203     void adjustColumn();
0204     void resizeRow();
0205     void insertRow();
0206     void deleteRow();
0207     void hideRow();
0208     void showRow();
0209     void slotShowRowDialog();
0210     void equalizeRow();
0211     void adjustRow();
0212     void adjust();
0213     // -- cell insert/remove actions --
0214     void insertCells();
0215     void deleteCells();
0216     // -- cell content actions --
0217     void clearAll();
0218     void clearContents();
0219     void comment();
0220     void clearComment();
0221     void conditional();
0222     void clearConditionalStyles();
0223     void insertHyperlink();
0224     void clearHyperlink();
0225     void validity();
0226     void clearValidity();
0227     // -- sorting/filtering action --
0228     void sort();
0229     void sortInc();
0230     void sortDec();
0231     void autoFilter();
0232     // -- fill actions --
0233     void fillLeft();
0234     void fillRight();
0235     void fillUp();
0236     void fillDown();
0237     void autoSum();
0238     // -- data insert actions --
0239     void insertSeries();
0240     void insertFormula();
0241     void insertSpecialChar();
0242     void specialChar(QChar character, const QString& fontName);
0243     void specialCharDialogClosed();
0244     void insertFromDatabase();
0245     void insertFromTextfile();
0246     void insertFromClipboard();
0247     void textToColumns();
0248     void sortList();
0249     void consolidate();
0250     void goalSeek();
0251     void subtotals();
0252     void pivot();
0253     void setAreaName();
0254     void namedAreaDialog();
0255     void formulaSelection(const QString& expression);
0256     // -- general editing actions --
0257     void edit();
0258     void cut() override;
0259     void copy() const override;
0260     bool paste() override;
0261     void specialPaste();
0262     void pasteWithInsertion();
0263     void selectAll();
0264     void find();
0265     void findNext();
0266     void findPrevious();
0267     void replace();
0268     void initFindReplace();
0269     Cell findNextCell();
0270     /**
0271      * Called by find/replace (findNext) when it found a match
0272      */
0273     void slotHighlight(const QString &text, int matchingIndex, int matchedLength);
0274     /**
0275      * Called when replacing text in a cell
0276      */
0277     void slotReplace(const QString &newText, int, int, int);
0278     Cell nextFindValidCell(int col, int row);
0279     // -- misc actions --
0280     void gotoCell();
0281     void spellCheck();
0282     void inspector();
0283     void qTableView();
0284     void sheetFormat();
0285     void listChoosePopupMenu();
0286     void listChooseItemSelected(QAction*);
0287     void documentSettingsDialog();
0288     void breakBeforeColumn(bool);
0289     void breakBeforeRow(bool);
0290 
0291 private:
0292     Q_DISABLE_COPY(CellToolBase)
0293 
0294     class Private;
0295     Private * const d;
0296 };
0297 
0298 } // namespace Sheets
0299 } // namespace Calligra
0300 
0301 #endif // CALLIGRA_SHEETS_CELL_TOOL_BASE