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

0001 /* This file is part of the KDE project
0002    Copyright 2006 - Robert Knight <robertknight@gmail.com>
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_HEADERS
0021 #define CALLIGRA_SHEETS_HEADERS
0022 
0023 #include <QWidget>
0024 
0025 #include "sheets_common_export.h"
0026 
0027 class QLabel;
0028 class KoPointerEvent;
0029 
0030 namespace Calligra
0031 {
0032 namespace Sheets
0033 {
0034 class CanvasBase;
0035 class Selection;
0036 
0037 /**
0038  * Base class for the widget above the cells showing the column headers.
0039  */
0040 class CALLIGRA_SHEETS_COMMON_EXPORT ColumnHeader
0041 {
0042 public:
0043     explicit ColumnHeader(CanvasBase *_canvas);
0044     virtual ~ColumnHeader();
0045 
0046     int markerColumn() const {
0047         return  m_iSelectionAnchor;
0048     }
0049     void equalizeColumn(double resize);
0050 
0051     virtual void updateColumns(int from, int to) = 0;
0052     virtual QSizeF size() const = 0;
0053     qreal width() const { return size().width(); }
0054     qreal height() const { return size().height(); }
0055     virtual void setCursor(const QCursor& cursor) = 0;
0056     virtual void scroll(qreal dx, qreal dy) = 0;
0057     virtual QPalette palette() const = 0;
0058     virtual void update() = 0;
0059 
0060     void setHeaderFont(const QFont& font);
0061     QFont headerFont() const;
0062 protected:
0063     void paint(QPainter* painter, const QRectF& painterRect);
0064     void mousePress(KoPointerEvent* _ev);
0065     void mouseRelease(KoPointerEvent* _ev);
0066     void mouseDoubleClick(KoPointerEvent* _ev);
0067     void mouseMove(KoPointerEvent* _ev);
0068     void focusOut(QFocusEvent* ev);
0069     void resize(const QSizeF& size, const QSizeF& oldSize);
0070     virtual void paintSizeIndicator(int mouseX) = 0;
0071     virtual void removeSizeIndicator() = 0;
0072     
0073     void doToolChanged(const QString& toolId);
0074 
0075 protected:
0076     CanvasBase *m_pCanvas;
0077 
0078     /**
0079      * Flag that indicates whether the user wants to mark columns.
0080      * The user may mark columns by dragging the mouse around in th XBorder widget.
0081      * If the user is doing that right now, this flag is true. Mention that the user may
0082      * also resize columns by dragging the mouse. This case is not covered by this flag.
0083      */
0084     bool m_bSelection;
0085 
0086     /**
0087      * The column over which the user pressed the mouse button.
0088      * If the user marks columns in the XBorder widget, then this is the initial
0089      * column on which the user pressed the mouse button.
0090      */
0091     int m_iSelectionAnchor;
0092 
0093     /**
0094      * Flag that indicates whether the user resizes a column
0095      * The user may resize columns by dragging the mouse around in the ColumnHeader widget.
0096      * If the user is doing that right now, this flag is true.
0097      */
0098     bool m_bResize;
0099 
0100     /**
0101      * The column over which the user pressed the mouse button.
0102      * The user may resize columns by dragging the mouse around the XBorder widget.
0103      * This is the column over which the user pressed the mouse button. This column is going
0104      * to be resized.
0105       */
0106     int m_iResizedColumn;
0107 
0108     /**
0109      * Last position of the mouse, when resizing.
0110      */
0111     int m_iResizePos;
0112 
0113     /**
0114      * The label used for showing the current size, when resizing
0115      */
0116     QLabel *m_lSize;
0117 
0118     /**
0119      * True when the mouse button is pressed
0120      */
0121     bool m_bMousePressed;
0122 
0123     bool m_cellToolIsActive;
0124 
0125     QFont m_font;
0126 };
0127 
0128 
0129 
0130 /**
0131  * Base class for the widget left to the cells showing the row headers.
0132  */
0133 class CALLIGRA_SHEETS_COMMON_EXPORT RowHeader
0134 {
0135 public:
0136     explicit RowHeader(CanvasBase *_canvas);
0137     virtual ~RowHeader();
0138 
0139     int markerRow() const {
0140         return  m_iSelectionAnchor;
0141     }
0142     void equalizeRow(double resize);
0143     
0144     virtual void updateRows(int from, int to) = 0;
0145     virtual QSizeF size() const = 0;
0146     qreal width() const { return size().width(); }
0147     qreal height() const { return size().height(); }
0148     virtual void setCursor(const QCursor& cursor) = 0;
0149     virtual void scroll(qreal dx, qreal dy) = 0;
0150     virtual QPalette palette() const = 0;
0151     virtual void update() = 0;
0152 
0153     void setHeaderFont(const QFont& font);
0154     QFont headerFont() const;
0155 protected:
0156     void paint(QPainter* painter, const QRectF& painterRect);
0157     void mousePress(KoPointerEvent* _ev);
0158     void mouseRelease(KoPointerEvent* _ev);
0159     void mouseDoubleClick(KoPointerEvent* _ev);
0160     void mouseMove(KoPointerEvent* _ev);
0161     void focusOut(QFocusEvent* ev);
0162     virtual void paintSizeIndicator(int mouseX) = 0;
0163     virtual void removeSizeIndicator() = 0;
0164 
0165     void doToolChanged(const QString& toolId);
0166 protected:
0167     CanvasBase *m_pCanvas;
0168 
0169     bool m_bSelection;
0170     int m_iSelectionAnchor;
0171     bool m_bResize;
0172     int m_iResizedRow;
0173     int m_iResizePos;
0174     /**
0175      * The label used for showing the current size, when resizing
0176      */
0177     QLabel *m_lSize;
0178 
0179     /**
0180      * True when the mouse button is pressed
0181      */
0182     bool m_bMousePressed;
0183 
0184     bool m_cellToolIsActive;
0185 
0186     QFont m_font;
0187 };
0188 
0189 
0190 
0191 /**
0192  * Base class for the widget in the top left corner of the canvas,
0193  * responsible for selecting all cells in a sheet.
0194  */
0195 class SelectAllButton
0196 {
0197 public:
0198     explicit SelectAllButton(CanvasBase* canvasBase);
0199     virtual ~SelectAllButton();
0200 
0201     virtual QPalette palette() const = 0;
0202     virtual void update() = 0;
0203 protected:
0204     void paint(QPainter* painter, const QRectF& painterRect);
0205     void mousePress(KoPointerEvent* event);
0206     void mouseRelease(KoPointerEvent* event);
0207     void doToolChanged(const QString& toolId);
0208 
0209 protected:
0210     CanvasBase* m_canvasBase;
0211     bool m_mousePressed;
0212     bool m_cellToolIsActive;
0213 };
0214 
0215 } // namespace Sheets
0216 } // namespace Calligra
0217 
0218 #endif