1 /* This file is part of the KDE project
2    Copyright (C) 2005 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17    Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef CALLIGRA_SHEETS_ROW_COLUMN_MANIPULATORS
21 #define CALLIGRA_SHEETS_ROW_COLUMN_MANIPULATORS
22 
23 #include <QSizeF>
24 
25 #include <Style.h>
26 
27 #include "AbstractRegionCommand.h"
28 
29 namespace Calligra
30 {
31 namespace Sheets
32 {
33 class ColumnFormat;
34 class RowFormat;
35 
36 /**
37  * \class ResizeColumnManipulator
38  * \ingroup Commands
39  * \brief Resizes a column.
40  */
41 class ResizeColumnManipulator : public AbstractRegionCommand
42 {
43 public:
44     explicit ResizeColumnManipulator(KUndo2Command *parent = 0);
45     ~ResizeColumnManipulator() override;
46 
setSize(double size)47     void setSize(double size) {
48         m_newSize = size;
49     }
50 
51 protected:
52     bool process(Element*) override;
53 
54 private:
55     double m_newSize;
56     QHash<int, double> m_oldSizes;
57 };
58 
59 
60 /**
61  * \class ResizeRowManipulator
62  * \ingroup Commands
63  * \brief Resizes a row.
64  */
65 class ResizeRowManipulator : public AbstractRegionCommand
66 {
67 public:
68     explicit ResizeRowManipulator(KUndo2Command *parent = 0);
69     ~ResizeRowManipulator() override;
70 
setSize(double size)71     void setSize(double size) {
72         m_newSize = size;
73     }
74 
75 protected:
76     bool process(Element*) override;
77 
78 private:
79     double m_newSize;
80     QHash<int, double> m_oldSizes;
81 };
82 
83 
84 /**
85  * \class AdjustColumnRowManipulator
86  * \ingroup Commands
87  * \brief Optimizes the height and the width of rows and columns, respectively.
88  */
89 class AdjustColumnRowManipulator : public AbstractRegionCommand
90 {
91 public:
92     explicit AdjustColumnRowManipulator(KUndo2Command *parent = 0);
93     ~AdjustColumnRowManipulator() override;
94 
95     bool process(Element*) override;
96     bool preProcessing() override;
97     bool postProcessing() override;
98 
setAdjustColumn(bool state)99     void setAdjustColumn(bool state) {
100         m_adjustColumn = state;
101     }
setAdjustRow(bool state)102     void setAdjustRow(bool state) {
103         m_adjustRow = state;
104     }
105 
106 protected:
107     KUndo2MagicString name() const;
108 
109     QSizeF textSize(const QString& text, const Style& style) const;
110     double adjustColumnHelper(const Cell& cell);
111     double adjustRowHelper(const Cell& cell);
112 
113 private:
114     bool m_adjustColumn : 1;
115     bool m_adjustRow    : 1;
116     QMap<int, double> m_newWidths;
117     QMap<int, double> m_oldWidths;
118     QMap<int, double> m_newHeights;
119     QMap<int, double> m_oldHeights;
120 };
121 
122 
123 
124 /**
125  * \class HideShowManipulator
126  * \ingroup Commands
127  * \brief Hides/Shows columns and/or rows.
128  */
129 class HideShowManipulator : public AbstractRegionCommand
130 {
131 public:
132     explicit HideShowManipulator(KUndo2Command *parent = 0);
133     ~HideShowManipulator() override;
134 
135     bool process(Element*) override;
136     bool preProcessing() override;
137     bool postProcessing() override;
138 
setManipulateColumns(bool state)139     void setManipulateColumns(bool state) {
140         m_manipulateColumns = state;
141     }
setManipulateRows(bool state)142     void setManipulateRows(bool state) {
143         m_manipulateRows = state;
144     }
145 
146 protected:
147     KUndo2MagicString name() const;
148 
149 private:
150     bool m_manipulateColumns : 1;
151     bool m_manipulateRows    : 1;
152 };
153 
154 
155 
156 /**
157  * \class InsertDeleteColumnManipulator
158  * \ingroup Commands
159  * \brief Inserts/Removes columns.
160  */
161 class InsertDeleteColumnManipulator : public AbstractRegionCommand
162 {
163 public:
164     explicit InsertDeleteColumnManipulator(KUndo2Command *parent = 0);
165     ~InsertDeleteColumnManipulator() override;
166 
167     void setTemplate(const ColumnFormat &columnFormat);
168     void setReverse(bool reverse) override;
169 
170 protected:
171     bool process(Element*) override;
172     bool preProcessing() override;
173     bool mainProcessing() override;
174     bool postProcessing() override;
175 
176 private:
177     enum Mode { Insert, Delete };
178     Mode m_mode;
179     ColumnFormat *m_template;
180 };
181 
182 
183 
184 /**
185  * \class InsertDeleteRowManipulator
186  * \ingroup Commands
187  * \brief Inserts/Removes rows.
188  */
189 class InsertDeleteRowManipulator : public AbstractRegionCommand
190 {
191 public:
192     explicit InsertDeleteRowManipulator(KUndo2Command *parent = 0);
193     ~InsertDeleteRowManipulator() override;
194 
195     void setTemplate(const RowFormat &rowFormat);
196     void setReverse(bool reverse) override;
197 
198 protected:
199     bool process(Element*) override;
200     bool preProcessing() override;
201     bool mainProcessing() override;
202     bool postProcessing() override;
203 
204 private:
205     enum Mode { Insert, Delete };
206     Mode m_mode;
207     RowFormat *m_template;
208 };
209 
210 } // namespace Sheets
211 } // namespace Calligra
212 
213 #endif // CALLIGRA_SHEETS_ROW_COLUMN_MANIPULATORS
214