File indexing completed on 2024-05-12 16:37:15

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2005-2007, 2009, 2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA
0019  */
0020 
0021 #ifndef KWVIEW_H
0022 #define KWVIEW_H
0023 
0024 #include "words_export.h"
0025 #include "KWPage.h"
0026 #include "./dockers/KWStatisticsWidget.h"
0027 #include "./dockers/KWStatisticsDocker.h"
0028 
0029 #include <KoView.h>
0030 #include <KoViewConverter.h>
0031 #include <KoZoomHandler.h>
0032 #include <KoFindMatch.h>
0033 
0034 #include <QWidget>
0035 
0036 class KWDocument;
0037 class KWCanvas;
0038 class KWFrame;
0039 class KWGui;
0040 
0041 class KoPart;
0042 class KoCanvasBase;
0043 class KoZoomController;
0044 class KoFindText;
0045 
0046 class QPushButton;
0047 #ifdef SHOULD_BUILD_RDF
0048 class KoRdfBasicSemanticItem;
0049 typedef QExplicitlySharedDataPointer<KoRdfBasicSemanticItem> hKoRdfBasicSemanticItem;
0050 #endif
0051 
0052 class KToggleAction;
0053 /**
0054  * Words' view class. Following the broad model-view-controller idea this class
0055  * shows you one view on the document. There can be multiple views of the same document each
0056  * in with independent settings for viewMode and zoom etc.
0057  */
0058 class WORDS_EXPORT KWView : public KoView
0059 {
0060     Q_OBJECT
0061 
0062 public:
0063     static const qreal AnnotationAreaWidth;
0064 
0065     /**
0066      * Construct a new view on the words document.
0067      * The view will have a canvas as a member which does all the actual painting, the view will
0068      * be responsible for handling the actions.  The View is technically speaking the controller
0069      * class in the MVC design.
0070      * @param part a KoPart
0071      * @param document the document we show.
0072      * @param parent a parent widget we show ourselves in.
0073      */
0074     KWView(KoPart *part, KWDocument *document, QWidget *parent);
0075     ~KWView() override;
0076 
0077     /**
0078      * return the KWDocument that owns this view.
0079      * @see KoView::document()
0080      */
0081     KWDocument *kwdocument() const {
0082         return m_document;
0083     }
0084 
0085     /// reimplemented from superclass
0086     void addImages(const QVector<QImage> &imageList, const QPoint &insertAt) override;
0087 
0088     // interface KoView
0089     /// reimplemented method from superclass
0090     void updateReadWrite(bool readWrite) override;
0091     /// reimplemented method from superclass
0092     virtual QWidget *canvas() const;
0093 
0094     /// returns true if this view has the snap-to-grid enabled.
0095     bool snapToGrid() const {
0096         return m_snapToGrid;
0097     }
0098 
0099     /**
0100      * Return the current canvas; much like canvas(), but this one does not downcast.
0101      */
0102     KoCanvasBase *canvasBase() const;
0103 
0104     /// Return the view converter for this view.
0105     KoViewConverter *viewConverter() {
0106         return &m_zoomHandler;
0107     }
0108 
0109     /// show a popup on the view, adding to it a list of actions
0110     void popupContextMenu(const QPoint &globalPosition, const QList<QAction*> &actions);
0111 
0112     const KWPage currentPage() const;
0113     void setCurrentPage(const KWPage &page);
0114 
0115     /// go to page
0116     void goToPage(const KWPage &page);
0117 
0118     KoZoomController *zoomController() const override { return m_zoomController; }
0119 
0120     int minPageNumber() const { return m_minPageNum; }
0121     int maxPageNumber() const { return m_maxPageNum; }
0122 
0123     void viewMouseMoveEvent(QMouseEvent *e);
0124 
0125 
0126 Q_SIGNALS:
0127     void shownPagesChanged();
0128 
0129 public Q_SLOTS:
0130     void offsetInDocumentMoved(int yOffset);
0131 
0132     /// displays the KWPageSettingsDialog that allows to change properties of the entire page
0133     void formatPage();
0134 
0135     /// turns the border display on/off
0136     void toggleViewFrameBorders(bool on);
0137     /// toggle the display of non-printing characters
0138     void setShowFormattingChars(bool on);
0139     /// toggle the display of field shadings
0140     void setShowInlineObjectVisualization(bool on);
0141     /// toggle the display of table borders
0142     void setShowTableBorders(bool on);
0143     /// toggle the display of section bounds
0144     void setShowSectionBounds(bool on);
0145     /// go to previous page
0146     void goToPreviousPage(Qt::KeyboardModifiers modifiers = Qt::NoModifier);
0147     /// go to next page
0148     void goToNextPage(Qt::KeyboardModifiers modifiers = Qt::NoModifier);
0149     /// Call when "Exit Fullscreen Mode" in status bar clicked.
0150     void exitFullscreenMode();
0151 
0152 protected:
0153     /// reimplemented method from superclass
0154     void showEvent(QShowEvent *event) override;
0155     bool event(QEvent* event) override;
0156 
0157 private:
0158     void setupActions();
0159     KoPrintJob *createPrintJob() override;
0160     /// loops over the selected shapes and returns the top level shapes.
0161     QList<KoShape *> selectedShapes() const;
0162     KoShape *selectedShape() const;
0163 
0164 private Q_SLOTS:
0165     /// create a template from document
0166     void createTemplate();
0167     /// displays the KWFrameDialog that allows to alter the frameset properties
0168     void editFrameProperties();
0169     /// called if another shape got selected
0170     void selectionChanged();
0171     /// enable document headers
0172     void enableHeader();
0173     /// enable document footers
0174     void enableFooter();
0175     /// snap to grid
0176     void toggleSnapToGrid();
0177     /// displays libs/main/rdf/SemanticStylesheetsEditor to edit Rdf stylesheets
0178     void editSemanticStylesheets();
0179     /// called if the zoom changed
0180     void zoomChanged(KoZoomMode::Mode mode, qreal zoom);
0181     /// shows or hides the rulers
0182     void showRulers(bool visible);
0183     /// shows or hides the status bar
0184     void showStatusBar(bool);
0185     /// calls delete on the active tool
0186     void editDeleteSelection();
0187     /** decide if we enable or disable the action "delete_page" uppon m_document->page_count() */
0188     void updateStatusBarAction();
0189     /// show guides menu option uses this
0190     void setGuideVisibility(bool on);
0191     /// open the configure dialog.
0192     void configure();
0193 #ifdef SHOULD_BUILD_RDF
0194     /// A semantic item was updated and should have it's text refreshed.
0195     void semanticObjectViewSiteUpdated(hKoRdfBasicSemanticItem item, const QString &xmlid);
0196 #endif
0197     /// A match was found when searching.
0198     void findMatchFound(KoFindMatch match);
0199     /// This is used to update the text that can be searched.
0200     void refreshFindTexts();
0201     /// The KWPageSettingsDialog was closed.
0202     void pageSettingsDialogFinished();
0203     /// user wants to past data from the clipboard
0204     void pasteRequested();
0205     /// Call when the user want to show/hide the WordsCount in the statusbar
0206     void showWordCountInStatusBar(bool doShow);
0207     /// Show annotations ("notes" in the UI) on the canvas - this is the user view menu visibility change
0208     void showNotes(bool show);
0209     /// "hasAnnotations" has changed ("notes" in the UI) - will cause showNotes above to change too
0210     void hasNotes(bool has);
0211     /**
0212      * Set view into fullscreen mode, hide menu bar, status bar, tool bar, dockers
0213      * and set view into  full screen mode.
0214      */
0215     void setFullscreenMode(bool); /// Call after 4 seconds, user doesn't move cursor.
0216     void hideCursor();
0217     /// Hide status bar and scroll bars after seconds in fullscreen mode.
0218     void hideUI();
0219 
0220 private:
0221     KWGui *m_gui;
0222     KWCanvas *m_canvas;
0223     KWDocument *m_document;
0224     KoZoomHandler m_zoomHandler;
0225     KoZoomController *m_zoomController;
0226     KWPage m_currentPage;
0227     KoFindText *m_find;
0228 
0229     QAction *m_actionCreateTemplate;
0230     QAction *m_actionFormatFrameSet;
0231     QAction *m_actionInsertFrameBreak;
0232     QAction *m_actionFormatFont;
0233     QAction *m_actionEditDelFrame;
0234     QAction *m_actionRaiseFrame;
0235     QAction *m_actionLowerFrame;
0236     QAction *m_actionBringToFront;
0237     QAction *m_actionSendBackward;
0238     KToggleAction *m_actionFormatBold;
0239     KToggleAction *m_actionFormatItalic;
0240     KToggleAction *m_actionFormatUnderline;
0241     KToggleAction *m_actionFormatStrikeOut;
0242     QAction *m_actionViewHeader;
0243     QAction *m_actionViewFooter;
0244     KToggleAction *m_actionViewSnapToGrid;
0245 
0246     bool m_snapToGrid;
0247     QString m_lastPageSettingsTab;
0248 
0249     QSizeF m_pageSize; // The max size of the pages we currently show. Prevents endless loop
0250     qreal m_textMinX; // The min x value where text can appear we currently show. Prevents endless loop
0251     qreal m_textMaxX; // The max x value where text can appear we currently show. Prevents endless loop
0252     int m_minPageNum;
0253     int m_maxPageNum;
0254 
0255     //Word count stuff for display in status bar
0256     void buildAssociatedWidget();
0257     KWStatisticsWidget *wordCount;
0258 
0259     bool m_isFullscreenMode;
0260     QTimer *m_hideCursorTimer;
0261     // The button will add to status bar in fullscreen mode to let user come
0262     // back to standard view.
0263     QPushButton *m_dfmExitButton;
0264 };
0265 
0266 #endif