File indexing completed on 2024-05-12 16:35:13

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005 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 #ifndef CALLIGRA_SHEETS_ROW_COLUMN_MANIPULATORS
0021 #define CALLIGRA_SHEETS_ROW_COLUMN_MANIPULATORS
0022 
0023 #include <QSizeF>
0024 
0025 #include <Style.h>
0026 
0027 #include "AbstractRegionCommand.h"
0028 
0029 namespace Calligra
0030 {
0031 namespace Sheets
0032 {
0033 class ColumnFormat;
0034 class RowFormat;
0035 
0036 /**
0037  * \class ResizeColumnManipulator
0038  * \ingroup Commands
0039  * \brief Resizes a column.
0040  */
0041 class ResizeColumnManipulator : public AbstractRegionCommand
0042 {
0043 public:
0044     explicit ResizeColumnManipulator(KUndo2Command *parent = 0);
0045     ~ResizeColumnManipulator() override;
0046 
0047     void setSize(double size) {
0048         m_newSize = size;
0049     }
0050 
0051 protected:
0052     bool process(Element*) override;
0053 
0054 private:
0055     double m_newSize;
0056     QHash<int, double> m_oldSizes;
0057 };
0058 
0059 
0060 /**
0061  * \class ResizeRowManipulator
0062  * \ingroup Commands
0063  * \brief Resizes a row.
0064  */
0065 class ResizeRowManipulator : public AbstractRegionCommand
0066 {
0067 public:
0068     explicit ResizeRowManipulator(KUndo2Command *parent = 0);
0069     ~ResizeRowManipulator() override;
0070 
0071     void setSize(double size) {
0072         m_newSize = size;
0073     }
0074 
0075 protected:
0076     bool process(Element*) override;
0077 
0078 private:
0079     double m_newSize;
0080     QHash<int, double> m_oldSizes;
0081 };
0082 
0083 
0084 /**
0085  * \class AdjustColumnRowManipulator
0086  * \ingroup Commands
0087  * \brief Optimizes the height and the width of rows and columns, respectively.
0088  */
0089 class AdjustColumnRowManipulator : public AbstractRegionCommand
0090 {
0091 public:
0092     explicit AdjustColumnRowManipulator(KUndo2Command *parent = 0);
0093     ~AdjustColumnRowManipulator() override;
0094 
0095     bool process(Element*) override;
0096     bool preProcessing() override;
0097     bool postProcessing() override;
0098 
0099     void setAdjustColumn(bool state) {
0100         m_adjustColumn = state;
0101     }
0102     void setAdjustRow(bool state) {
0103         m_adjustRow = state;
0104     }
0105 
0106 protected:
0107     KUndo2MagicString name() const;
0108 
0109     QSizeF textSize(const QString& text, const Style& style) const;
0110     double adjustColumnHelper(const Cell& cell);
0111     double adjustRowHelper(const Cell& cell);
0112 
0113 private:
0114     bool m_adjustColumn : 1;
0115     bool m_adjustRow    : 1;
0116     QMap<int, double> m_newWidths;
0117     QMap<int, double> m_oldWidths;
0118     QMap<int, double> m_newHeights;
0119     QMap<int, double> m_oldHeights;
0120 };
0121 
0122 
0123 
0124 /**
0125  * \class HideShowManipulator
0126  * \ingroup Commands
0127  * \brief Hides/Shows columns and/or rows.
0128  */
0129 class HideShowManipulator : public AbstractRegionCommand
0130 {
0131 public:
0132     explicit HideShowManipulator(KUndo2Command *parent = 0);
0133     ~HideShowManipulator() override;
0134 
0135     bool process(Element*) override;
0136     bool preProcessing() override;
0137     bool postProcessing() override;
0138 
0139     void setManipulateColumns(bool state) {
0140         m_manipulateColumns = state;
0141     }
0142     void setManipulateRows(bool state) {
0143         m_manipulateRows = state;
0144     }
0145 
0146 protected:
0147     KUndo2MagicString name() const;
0148 
0149 private:
0150     bool m_manipulateColumns : 1;
0151     bool m_manipulateRows    : 1;
0152 };
0153 
0154 
0155 
0156 /**
0157  * \class InsertDeleteColumnManipulator
0158  * \ingroup Commands
0159  * \brief Inserts/Removes columns.
0160  */
0161 class InsertDeleteColumnManipulator : public AbstractRegionCommand
0162 {
0163 public:
0164     explicit InsertDeleteColumnManipulator(KUndo2Command *parent = 0);
0165     ~InsertDeleteColumnManipulator() override;
0166 
0167     void setTemplate(const ColumnFormat &columnFormat);
0168     void setReverse(bool reverse) override;
0169 
0170 protected:
0171     bool process(Element*) override;
0172     bool preProcessing() override;
0173     bool mainProcessing() override;
0174     bool postProcessing() override;
0175 
0176 private:
0177     enum Mode { Insert, Delete };
0178     Mode m_mode;
0179     ColumnFormat *m_template;
0180 };
0181 
0182 
0183 
0184 /**
0185  * \class InsertDeleteRowManipulator
0186  * \ingroup Commands
0187  * \brief Inserts/Removes rows.
0188  */
0189 class InsertDeleteRowManipulator : public AbstractRegionCommand
0190 {
0191 public:
0192     explicit InsertDeleteRowManipulator(KUndo2Command *parent = 0);
0193     ~InsertDeleteRowManipulator() override;
0194 
0195     void setTemplate(const RowFormat &rowFormat);
0196     void setReverse(bool reverse) override;
0197 
0198 protected:
0199     bool process(Element*) override;
0200     bool preProcessing() override;
0201     bool mainProcessing() override;
0202     bool postProcessing() override;
0203 
0204 private:
0205     enum Mode { Insert, Delete };
0206     Mode m_mode;
0207     RowFormat *m_template;
0208 };
0209 
0210 } // namespace Sheets
0211 } // namespace Calligra
0212 
0213 #endif // CALLIGRA_SHEETS_ROW_COLUMN_MANIPULATORS