1 /* This file is part of the KDE project 2 * Copyright (C) 2005-2007, 2009, 2010 Thomas Zander <zander@kde.org> 3 * Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA 19 */ 20 21 #ifndef KWVIEW_H 22 #define KWVIEW_H 23 24 #include "words_export.h" 25 #include "KWPage.h" 26 #include "./dockers/KWStatisticsWidget.h" 27 #include "./dockers/KWStatisticsDocker.h" 28 29 #include <KoView.h> 30 #include <KoViewConverter.h> 31 #include <KoZoomHandler.h> 32 #include <KoFindMatch.h> 33 34 #include <QWidget> 35 36 class KWDocument; 37 class KWCanvas; 38 class KWFrame; 39 class KWGui; 40 41 class KoPart; 42 class KoCanvasBase; 43 class KoZoomController; 44 class KoFindText; 45 46 class QPushButton; 47 #ifdef SHOULD_BUILD_RDF 48 class KoRdfBasicSemanticItem; 49 typedef QExplicitlySharedDataPointer<KoRdfBasicSemanticItem> hKoRdfBasicSemanticItem; 50 #endif 51 52 class KToggleAction; 53 /** 54 * Words' view class. Following the broad model-view-controller idea this class 55 * shows you one view on the document. There can be multiple views of the same document each 56 * in with independent settings for viewMode and zoom etc. 57 */ 58 class WORDS_EXPORT KWView : public KoView 59 { 60 Q_OBJECT 61 62 public: 63 static const qreal AnnotationAreaWidth; 64 65 /** 66 * Construct a new view on the words document. 67 * The view will have a canvas as a member which does all the actual painting, the view will 68 * be responsible for handling the actions. The View is technically speaking the controller 69 * class in the MVC design. 70 * @param part a KoPart 71 * @param document the document we show. 72 * @param parent a parent widget we show ourselves in. 73 */ 74 KWView(KoPart *part, KWDocument *document, QWidget *parent); 75 ~KWView() override; 76 77 /** 78 * return the KWDocument that owns this view. 79 * @see KoView::document() 80 */ kwdocument()81 KWDocument *kwdocument() const { 82 return m_document; 83 } 84 85 /// reimplemented from superclass 86 void addImages(const QVector<QImage> &imageList, const QPoint &insertAt) override; 87 88 // interface KoView 89 /// reimplemented method from superclass 90 void updateReadWrite(bool readWrite) override; 91 /// reimplemented method from superclass 92 virtual QWidget *canvas() const; 93 94 /// returns true if this view has the snap-to-grid enabled. snapToGrid()95 bool snapToGrid() const { 96 return m_snapToGrid; 97 } 98 99 /** 100 * Return the current canvas; much like canvas(), but this one does not downcast. 101 */ 102 KoCanvasBase *canvasBase() const; 103 104 /// Return the view converter for this view. viewConverter()105 KoViewConverter *viewConverter() { 106 return &m_zoomHandler; 107 } 108 109 /// show a popup on the view, adding to it a list of actions 110 void popupContextMenu(const QPoint &globalPosition, const QList<QAction*> &actions); 111 112 const KWPage currentPage() const; 113 void setCurrentPage(const KWPage &page); 114 115 /// go to page 116 void goToPage(const KWPage &page); 117 zoomController()118 KoZoomController *zoomController() const override { return m_zoomController; } 119 minPageNumber()120 int minPageNumber() const { return m_minPageNum; } maxPageNumber()121 int maxPageNumber() const { return m_maxPageNum; } 122 123 void viewMouseMoveEvent(QMouseEvent *e); 124 125 126 Q_SIGNALS: 127 void shownPagesChanged(); 128 129 public Q_SLOTS: 130 void offsetInDocumentMoved(int yOffset); 131 132 /// displays the KWPageSettingsDialog that allows to change properties of the entire page 133 void formatPage(); 134 135 /// turns the border display on/off 136 void toggleViewFrameBorders(bool on); 137 /// toggle the display of non-printing characters 138 void setShowFormattingChars(bool on); 139 /// toggle the display of field shadings 140 void setShowInlineObjectVisualization(bool on); 141 /// toggle the display of table borders 142 void setShowTableBorders(bool on); 143 /// toggle the display of section bounds 144 void setShowSectionBounds(bool on); 145 /// go to previous page 146 void goToPreviousPage(Qt::KeyboardModifiers modifiers = Qt::NoModifier); 147 /// go to next page 148 void goToNextPage(Qt::KeyboardModifiers modifiers = Qt::NoModifier); 149 /// Call when "Exit Fullscreen Mode" in status bar clicked. 150 void exitFullscreenMode(); 151 152 protected: 153 /// reimplemented method from superclass 154 void showEvent(QShowEvent *event) override; 155 bool event(QEvent* event) override; 156 157 private: 158 void setupActions(); 159 KoPrintJob *createPrintJob() override; 160 /// loops over the selected shapes and returns the top level shapes. 161 QList<KoShape *> selectedShapes() const; 162 KoShape *selectedShape() const; 163 164 private Q_SLOTS: 165 /// create a template from document 166 void createTemplate(); 167 /// displays the KWFrameDialog that allows to alter the frameset properties 168 void editFrameProperties(); 169 /// called if another shape got selected 170 void selectionChanged(); 171 /// enable document headers 172 void enableHeader(); 173 /// enable document footers 174 void enableFooter(); 175 /// snap to grid 176 void toggleSnapToGrid(); 177 /// displays libs/main/rdf/SemanticStylesheetsEditor to edit Rdf stylesheets 178 void editSemanticStylesheets(); 179 /// called if the zoom changed 180 void zoomChanged(KoZoomMode::Mode mode, qreal zoom); 181 /// shows or hides the rulers 182 void showRulers(bool visible); 183 /// shows or hides the status bar 184 void showStatusBar(bool); 185 /// calls delete on the active tool 186 void editDeleteSelection(); 187 /** decide if we enable or disable the action "delete_page" uppon m_document->page_count() */ 188 void updateStatusBarAction(); 189 /// show guides menu option uses this 190 void setGuideVisibility(bool on); 191 /// open the configure dialog. 192 void configure(); 193 #ifdef SHOULD_BUILD_RDF 194 /// A semantic item was updated and should have it's text refreshed. 195 void semanticObjectViewSiteUpdated(hKoRdfBasicSemanticItem item, const QString &xmlid); 196 #endif 197 /// A match was found when searching. 198 void findMatchFound(KoFindMatch match); 199 /// This is used to update the text that can be searched. 200 void refreshFindTexts(); 201 /// The KWPageSettingsDialog was closed. 202 void pageSettingsDialogFinished(); 203 /// user wants to past data from the clipboard 204 void pasteRequested(); 205 /// Call when the user want to show/hide the WordsCount in the statusbar 206 void showWordCountInStatusBar(bool doShow); 207 /// Show annotations ("notes" in the UI) on the canvas - this is the user view menu visibility change 208 void showNotes(bool show); 209 /// "hasAnnotations" has changed ("notes" in the UI) - will cause showNotes above to change too 210 void hasNotes(bool has); 211 /** 212 * Set view into fullscreen mode, hide menu bar, status bar, tool bar, dockers 213 * and set view into full screen mode. 214 */ 215 void setFullscreenMode(bool); /// Call after 4 seconds, user doesn't move cursor. 216 void hideCursor(); 217 /// Hide status bar and scroll bars after seconds in fullscreen mode. 218 void hideUI(); 219 220 private: 221 KWGui *m_gui; 222 KWCanvas *m_canvas; 223 KWDocument *m_document; 224 KoZoomHandler m_zoomHandler; 225 KoZoomController *m_zoomController; 226 KWPage m_currentPage; 227 KoFindText *m_find; 228 229 QAction *m_actionCreateTemplate; 230 QAction *m_actionFormatFrameSet; 231 QAction *m_actionInsertFrameBreak; 232 QAction *m_actionFormatFont; 233 QAction *m_actionEditDelFrame; 234 QAction *m_actionRaiseFrame; 235 QAction *m_actionLowerFrame; 236 QAction *m_actionBringToFront; 237 QAction *m_actionSendBackward; 238 KToggleAction *m_actionFormatBold; 239 KToggleAction *m_actionFormatItalic; 240 KToggleAction *m_actionFormatUnderline; 241 KToggleAction *m_actionFormatStrikeOut; 242 QAction *m_actionViewHeader; 243 QAction *m_actionViewFooter; 244 KToggleAction *m_actionViewSnapToGrid; 245 246 bool m_snapToGrid; 247 QString m_lastPageSettingsTab; 248 249 QSizeF m_pageSize; // The max size of the pages we currently show. Prevents endless loop 250 qreal m_textMinX; // The min x value where text can appear we currently show. Prevents endless loop 251 qreal m_textMaxX; // The max x value where text can appear we currently show. Prevents endless loop 252 int m_minPageNum; 253 int m_maxPageNum; 254 255 //Word count stuff for display in status bar 256 void buildAssociatedWidget(); 257 KWStatisticsWidget *wordCount; 258 259 bool m_isFullscreenMode; 260 QTimer *m_hideCursorTimer; 261 // The button will add to status bar in fullscreen mode to let user come 262 // back to standard view. 263 QPushButton *m_dfmExitButton; 264 }; 265 266 #endif 267