File indexing completed on 2024-05-12 16:35:49
0001 /* This file is part of the KDE project 0002 Copyright 2006-2007 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_VIEW 0030 #define CALLIGRA_SHEETS_VIEW 0031 0032 #include <QList> 0033 #include <QPoint> 0034 #include <QString> 0035 #include <QStringList> 0036 #include <QPrinter> 0037 0038 #include <QPointF> 0039 #include <KoView.h> 0040 #include <KoZoomMode.h> 0041 #include <KoPart.h> 0042 #include "sheets_common_export.h" 0043 0044 class QKeyEvent; 0045 class QScrollBar; 0046 0047 class KoCanvasController; 0048 class KoZoomHandler; 0049 0050 namespace Calligra 0051 { 0052 namespace Sheets 0053 { 0054 class Cell; 0055 class ColumnHeaderWidget; 0056 class Damage; 0057 class Sheet; 0058 class Canvas; 0059 class Doc; 0060 class Region; 0061 class Selection; 0062 class SheetView; 0063 class RowHeaderWidget; 0064 class View; 0065 class TabBar; 0066 0067 /** 0068 * @class View 0069 * @brief The View class displays a Calligra Sheets document. 0070 * View is used to display a spreadsheet document and provide 0071 * the interface for the user to perform editing and data analysis. 0072 * 0073 * A view consists of several parts: 0074 * \li canvas to display cells in a sheet 0075 * \li column header to show columns 0076 * \li row header to show rows 0077 * \li corner button to select all cells 0078 * \li horizontal and vertical scrollbars for navigation 0079 * \li tab bar to select active worksheet 0080 * \li status bar to show status messages 0081 * 0082 * 0083 * KPART_TODO: when we have mdi again, we need to have an equivalent of guiActivateEvent 0084 * that sets the initalPosition() and calls calcStatusBarOp(). 0085 */ 0086 class CALLIGRA_SHEETS_COMMON_EXPORT View : public KoView 0087 { 0088 Q_OBJECT 0089 0090 public: 0091 /** Creates a new view displaying \p document and with \p parent as parent. */ 0092 View(KoPart *part, QWidget *parent, Doc *document); 0093 0094 /** Destroys the view */ 0095 ~View() override; 0096 0097 /** \return the document this view displays. */ 0098 Doc* doc() const; 0099 0100 /** \return the canvas of the view */ 0101 Canvas* canvasWidget() const; 0102 0103 /** \return the canvas controller of the view */ 0104 KoCanvasController* canvasController() const; 0105 0106 /** \return the column header */ 0107 ColumnHeaderWidget* columnHeader() const; 0108 0109 /** \return the row header */ 0110 RowHeaderWidget* rowHeader() const; 0111 0112 /** \return the horizontal scrollbar */ 0113 QScrollBar* horzScrollBar() const; 0114 0115 /** \return the vertical scrollbar */ 0116 QScrollBar* vertScrollBar() const; 0117 0118 /** \return the tab bar */ 0119 TabBar* tabBar() const; 0120 0121 /** \return the zoom handler */ 0122 KoZoomHandler* zoomHandler() const; 0123 0124 /** \return the sheet, that is currently displayed */ 0125 Sheet* activeSheet() const; 0126 0127 /** 0128 * \return the SheetView for \p sheet 0129 */ 0130 SheetView* sheetView(const Sheet* sheet) const; 0131 0132 /** Loads the view settings. */ 0133 void initConfig(); 0134 0135 /** Initializes the on-the-fly calculation method. */ 0136 void initCalcMenu(); 0137 0138 /** Changes the maximum number of entries in the recent files menu. */ 0139 void changeNbOfRecentFiles(int _nb); 0140 0141 /** Updates the state of the 'Show Page Borders' action (for DBus). */ 0142 void updateBorderButton(); 0143 0144 /** \return the color for cell borders \deprecated */ 0145 QColor borderColor() const; 0146 0147 /** 0148 * \return the current cell selection. 0149 */ 0150 Selection* selection() const; 0151 0152 /** 0153 * Updates the action, that unhides a hidden sheet. 0154 * If there are no hidden sheets or the map is protected, 0155 * the show sheet action will be disabled. 0156 */ 0157 void updateShowSheetMenu(); 0158 0159 /** 0160 * @return marker for @p sheet 0161 */ 0162 QPoint markerFromSheet(Sheet* sheet) const; 0163 0164 /** 0165 * @return scroll offset for @p sheet 0166 */ 0167 QPointF offsetFromSheet(Sheet* sheet) const; 0168 0169 /** 0170 * Save current sheet selection. 0171 * Call when we change sheet, or before save in OpenDocument format. 0172 */ 0173 void saveCurrentSheetSelection(); 0174 0175 /** 0176 * The state of the 'View loading' process. 0177 * Useful to suppress the painting of the canvas and setting the initial 0178 * scrolling and selection positions, which need a fully built View. 0179 * \return \c true if the view is not being fully created yet. 0180 */ 0181 bool isLoading() const; 0182 0183 public Q_SLOTS: 0184 /** Clears all visual cached data. */ 0185 void refreshSheetViews(); 0186 0187 /** Invalidates all visual cached data for the cells in \p region. */ 0188 void refreshSelection(const Region& region); 0189 0190 void finishLoading(); 0191 /** 0192 * Prepares this view for a modification of \p region, e.g. closes the cell 0193 * editor. 0194 */ 0195 void aboutToModify(const Region& region); 0196 0197 /** Sets the initial scrolling offset and selection after loading. */ 0198 void initialPosition(); 0199 0200 //BEGIN Actions 0201 void createTemplate(); 0202 void recalcWorkBook(); 0203 void recalcWorkSheet(); 0204 void paperLayoutDlg(); 0205 void resetPrintRange(); 0206 void togglePageOutline(bool); 0207 void toggleProtectSheet(bool); 0208 void toggleProtectDoc(bool); 0209 void viewZoom(KoZoomMode::Mode mode, qreal zoom); 0210 0211 void insertSheet(); 0212 void duplicateSheet(); 0213 void deleteSheet(); 0214 void hideSheet(); 0215 void showSheet(); 0216 0217 void optionsNotifications(); 0218 void preference(); 0219 0220 void copyAsText(); // DBus related 0221 0222 void moveSheet(unsigned sheet, unsigned target); 0223 0224 /** 0225 * Shows the sheet properties dialog. 0226 */ 0227 void sheetProperties(); 0228 //END Actions 0229 0230 /** 0231 * Sets the currently displayed \p sheet. 0232 * \param sheet the sheet 0233 * \param updateTabBar if \c true, updates the tab bar 0234 */ 0235 void setActiveSheet(Sheet* sheet, bool updateTabBar = true); 0236 0237 /** 0238 * Switch the active sheet to the name. This slot is connected to the tab bar 0239 * and activated when the user selects a new sheet in the tab bar. 0240 */ 0241 void changeSheet(const QString& _name); 0242 0243 /** 0244 * Switch the active sheet to the next visible sheet. Does nothing if the current 0245 * active sheet is the last visible sheet in the workbook. 0246 */ 0247 void nextSheet(); 0248 0249 /** 0250 * Switch the active sheet to the previous visible sheet. Does nothing if the current 0251 * active sheet is the first visible sheet in the workbook. 0252 */ 0253 void previousSheet(); 0254 0255 /** 0256 * Switch the active sheet to the first visible sheet in the workbook. Does nothing 0257 * if the current active sheet is already the first one. 0258 */ 0259 void firstSheet(); 0260 0261 /** 0262 * Switch the active sheet to the last visible sheet in the workbook. Does nothing 0263 * if the current active sheet is already the last one. 0264 */ 0265 void lastSheet(); 0266 0267 /** 0268 * Switches the shape anchoring. 0269 * Shapes can either be anchored to cells or to the sheet/page. 0270 * \param mode string indicating cell or sheet anchoring 0271 */ 0272 void setShapeAnchoring(const QString& mode); 0273 0274 /** Shows the context menu for the on-the-fly calculation method. */ 0275 void statusBarClicked(const QPoint& pos); 0276 0277 /** Updates the on-the-fly calculation method menu. */ 0278 void menuCalc(bool); 0279 0280 /** 0281 * Shows the column header, if \p enable is \c true, otherwise it will be hidden. 0282 */ 0283 void showColumnHeader(bool enable); 0284 0285 /** 0286 * Shows the column header, if \p enable is \c true, otherwise it will be hidden. 0287 */ 0288 void showRowHeader(bool enable); 0289 0290 /** 0291 * Shows the horizontal scrollbar, if \p enable is \c true, otherwise it will be hidden. 0292 */ 0293 void showHorizontalScrollBar(bool enable); 0294 0295 /** 0296 * Shows the vertical scrollbar, if \p enable is \c true, otherwise it will be hidden. 0297 */ 0298 void showVerticalScrollBar(bool enable); 0299 0300 /** 0301 * Shows the status bar if b is true, otherwise the status bar will be hidden. 0302 */ 0303 void showStatusBar(bool b); 0304 0305 /** 0306 * Shows the tab bar if b is true, otherwise the tab bar will be hidden. 0307 */ 0308 void showTabBar(bool b); 0309 0310 /** 0311 * Shows context menu when tabbar is double-clicked. 0312 */ 0313 void popupTabBarMenu(const QPoint&); 0314 0315 /** 0316 * \ingroup Damages 0317 * Handles damages that need visual updates. 0318 */ 0319 void handleDamages(const QList<Damage*>& damages); 0320 0321 /** 0322 * write in statusBar result of calc (Min, or Max, average, sum, count) 0323 */ 0324 void calcStatusBarOp(); 0325 0326 protected Q_SLOTS: 0327 /** Renames the active sheet. */ 0328 void slotRename(); 0329 0330 public Q_SLOTS: 0331 /** Reacts on selection changes. */ 0332 void slotChangeSelection(const Region&); 0333 0334 /** Reacts on reference selection changes. */ 0335 void slotScrollChoice(const Region&); 0336 0337 /** Updates the shape anchoring action. */ 0338 void shapeSelectionChanged(); 0339 0340 /** Calls KoToolProxy::deleteSelection(). */ 0341 void editDeleteSelection(); 0342 0343 void updateAccessedCellRange(Sheet* sheet, const QPoint& location); 0344 0345 public: // reimplementations 0346 // KoView interface 0347 virtual QWidget *canvas() const; 0348 0349 public: 0350 /** 0351 * Retrieves the left border width that is displayed around the content if 0352 * the view is active. 0353 * 0354 * In a spread sheet this border is for example used to display the 0355 * rows, while a top border is used to display the names of the cells 0356 * and a right and bottom border is used to display scrollbars. If the view 0357 * becomes inactive, then this stuff is not displayed anymore. 0358 */ 0359 virtual int leftBorder() const; 0360 virtual int rightBorder() const; 0361 virtual int topBorder() const; 0362 virtual int bottomBorder() const; 0363 0364 /** 0365 * Sets up so that autoScroll signals are emitted when the mouse pointer is outside the view 0366 */ 0367 void enableAutoScroll(); 0368 0369 /** 0370 * Stops the emitting of autoScroll signals 0371 */ 0372 void disableAutoScroll(); 0373 0374 0375 protected: // reimplementations 0376 // QWidget interface 0377 void keyPressEvent(QKeyEvent * _ev) override; 0378 // KoView interface 0379 void updateReadWrite(bool readwrite) override; 0380 KoPrintJob * createPrintJob() override; 0381 public: 0382 KoZoomController *zoomController() const override; 0383 0384 Q_SIGNALS: 0385 /** Indicates that the document's read/write state has changed. */ 0386 void documentReadWriteToggled(bool readwrite); 0387 0388 /** Indicates that the sheet's protection state has changed. */ 0389 void sheetProtectionToggled(bool protect); 0390 0391 void autoScroll(const QPoint &scrollDistance); 0392 0393 private Q_SLOTS: 0394 /** Adds \p sheet to the displayed sheets. */ 0395 void addSheet(Sheet *sheet); 0396 0397 /** Removes \p sheet from the displayed sheets. */ 0398 void removeSheet(Sheet* sheet); 0399 0400 /** Called if a Sheet-instance is deleted to proper clean-up internal pointers. */ 0401 void sheetDestroyed(QObject* obj); 0402 0403 void slotAutoScroll(); 0404 0405 private: 0406 Q_DISABLE_COPY(View) 0407 0408 0409 int autoScrollAcceleration(int offset) const; 0410 0411 class Private; 0412 Private * const d; 0413 0414 /** Creates and initializes the canvas and other child widgets. */ 0415 void initView(); 0416 0417 /** Sets the column/row headers minima according to the zoom level. */ 0418 void setHeaderMinima(); 0419 }; 0420 0421 } // namespace Sheets 0422 } // namespace Calligra 0423 0424 #endif // CALLIGRA_SHEETS_VIEW