File indexing completed on 2024-05-05 17:09:09

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * Copyright (C) 2013 Shantanu Tushar <shantanu@kde.org>
0005  * Copyright (C) 2013 Sujith Haridasan <sujith.h@gmail.com>
0006  * Copyright (C) 2013 Arjen Hiemstra <ahiemstra@heimr.nl>
0007  *
0008  * This library is free software; you can redistribute it and/or
0009  * modify it under the terms of the GNU Library General Public
0010  * License as published by the Free Software Foundation; either
0011  * version 2 of the License, or (at your option) any later version.
0012  *
0013  * This library is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016  * Library General Public License for more details.
0017  *
0018  * You should have received a copy of the GNU Library General Public License
0019  * along with this library; see the file COPYING.LIB.  If not, write to
0020  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021  * Boston, MA 02110-1301, USA.
0022  *
0023  */
0024 
0025 #ifndef CQTEXTDOCUMENTCANVAS_H
0026 #define CQTEXTDOCUMENTCANVAS_H
0027 
0028 #include "CQCanvasBase.h"
0029 
0030 class KWDocument;
0031 class KoDocument;
0032 class KoCanvasController;
0033 class KoCanvasBase;
0034 class KoFindMatch;
0035 
0036 class CQTextDocumentCanvas : public CQCanvasBase
0037 {
0038     Q_OBJECT
0039     Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm NOTIFY searchTermChanged)
0040     Q_PROPERTY(QObject* documentModel READ documentModel NOTIFY documentModelChanged)
0041     Q_PROPERTY(QObject* document READ doc NOTIFY documentModelChanged);
0042     Q_PROPERTY(QSize documentSize READ documentSize NOTIFY documentSizeChanged)
0043     Q_PROPERTY(int currentPageNumber READ currentPageNumber WRITE setCurrentPageNumber NOTIFY currentPageNumberChanged)
0044     Q_PROPERTY(QObjectList linkTargets READ linkTargets NOTIFY linkTargetsChanged)
0045     Q_PROPERTY(QObject* textEditor READ textEditor NOTIFY textEditorChanged)
0046     Q_PROPERTY(QObject* notes READ notes NOTIFY notesChanged)
0047 
0048     Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged)
0049     Q_PROPERTY(QRectF selectionStartPos READ selectionStartPos NOTIFY selectionChanged)
0050     Q_PROPERTY(QRectF selectionEndPos READ selectionEndPos NOTIFY selectionChanged)
0051     Q_PROPERTY(QObject* zoomAction READ zoomAction NOTIFY zoomActionChanged)
0052 
0053     Q_PROPERTY(QSizeF thumbnailSize READ thumbnailSize WRITE setThumbnailSize NOTIFY thumbnailSizeChanged)
0054 public:
0055     explicit CQTextDocumentCanvas(QDeclarativeItem* parent = 0);
0056     virtual ~CQTextDocumentCanvas();
0057 
0058     int currentPageNumber() const;
0059     void setCurrentPageNumber(const int &currentPageNumber);
0060     int cameraY() const;
0061     void setCameraY (int cameraY);
0062 
0063     QString searchTerm() const;
0064     void setSearchTerm(const QString &term);
0065 
0066     QObject *documentModel() const;
0067     QSize documentSize() const;
0068 
0069     virtual void render(QPainter* painter, const QRectF& target);
0070 
0071     KWDocument* document() const;
0072     Q_INVOKABLE QObject* doc() const;
0073     Q_INVOKABLE QObject* part() const;
0074 
0075     QObjectList linkTargets() const;
0076 
0077     Q_INVOKABLE qreal pagePosition( int page );
0078 
0079     virtual qreal shapeTransparency() const;
0080     virtual void setShapeTransparency(qreal newTransparency);
0081 
0082     QObject* textEditor();
0083     // Deselects any text selection present in the document, and deselects all shapes
0084     // This is highly useful, as it makes navigation prettier.
0085     Q_INVOKABLE void deselectEverything();
0086 
0087     // A list model of notes as created using addSticker(QString) and addNote(QString, QColor)
0088     QObject* notes() const;
0089     // Adds a sticker (simply an SVG) to the position indicated by the center of the viewport.
0090     Q_INVOKABLE void addSticker(const QString& imageUrl);
0091     // Adds a note to the position indicated by the center of the viewport. Color is the color
0092     // the text and the background sticker should have.
0093     Q_INVOKABLE void addNote(const QString& text, const QString& color, const QString& imageUrl);
0094 
0095     bool hasSelection() const;
0096     QRectF selectionStartPos() const;
0097     QRectF selectionEndPos() const;
0098 
0099     QObject* zoomAction() const;
0100 
0101     QSizeF thumbnailSize() const;
0102     void setThumbnailSize(const QSizeF& newSize);
0103 Q_SIGNALS:
0104     void searchTermChanged();
0105     void documentModelChanged();
0106     void documentSizeChanged();
0107     void currentPageNumberChanged();
0108     void cameraYChanged();
0109     void linkTargetsChanged();
0110     void textEditorChanged();
0111     void notesChanged();
0112     void selectionChanged();
0113     void zoomActionChanged();
0114     void thumbnailSizeChanged();
0115 
0116 protected:
0117     virtual bool event( QEvent* event );
0118     virtual void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
0119     virtual void openFile(const QString& uri);
0120     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
0121     virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
0122     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
0123     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e);
0124 
0125 private Q_SLOTS:
0126     void findNoMatchFound();
0127     void findMatchFound(const KoFindMatch& match);
0128     void updateCanvas();
0129     void findPrevious();
0130     void findNext();
0131     void updateDocumentSize(const QSize &size);
0132     void currentToolChanged(KoCanvasController* controller, int uniqueToolId);
0133 
0134 private:
0135     void createAndSetCanvasControllerOn(KoCanvasBase *canvas);
0136     void createAndSetZoomController(KoCanvasBase *canvas);
0137     void updateZoomControllerAccordingToDocument(const KoDocument *document);
0138     void alignTopWith(int y);
0139     void gotoPage(int pageNumber, KoDocument *document);
0140 
0141     class Private;
0142     Private * const d;
0143 };
0144 #endif // CQTEXTDOCUMENTCANVAS_H