Subversion Repositories Scribus

Rev

Rev 25048 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3 paul 7
/***************************************************************************
8
                          scribusview.h  -  description
9
                             -------------------
10
    begin                : Fre Apr  6 21:47:55 CEST 2001
11
    copyright            : (C) 2001 by Franz Schmid
12
    email                : Franz.Schmid@altmuehlnet.de
13
 ***************************************************************************/
14
 
15
/***************************************************************************
16
 *                                                                         *
17
 *   This program is free software; you can redistribute it and/or modify  *
18
 *   it under the terms of the GNU General Public License as published by  *
19
 *   the Free Software Foundation; either version 2 of the License, or     *
20
 *   (at your option) any later version.                                   *
21
 *                                                                         *
22
 ***************************************************************************/
23
 
24
#ifndef SCRIBUSVIEW_H
25
#define SCRIBUSVIEW_H
26
 
330 Franz 27
#include <vector>
3 paul 28
// include files for QT
8501 cbradney 29
#include <QDragLeaveEvent>
30
#include <QDragEnterEvent>
31
#include <QDragMoveEvent>
32
#include <QDropEvent>
23480 jghali 33
#include <QElapsedTimer>
34
#include <QLabel>
35
#include <QLineEdit>
36
#include <QMap>
8501 cbradney 37
#include <QMouseEvent>
23591 craig 38
#include <QNativeGestureEvent>
8501 cbradney 39
#include <QPaintEvent>
10978 avox 40
#include <QPoint>
23480 jghali 41
#include <QPushButton>
10532 avox 42
#include <QRect>
10701 avox 43
#include <QRectF>
22801 jghali 44
#include <QSize>
23917 jghali 45
#include <QStack>
13805 jghali 46
#include <QTimer>
23480 jghali 47
#include <QScrollArea>
48
#include <QScrollBar>
8501 cbradney 49
#include <QWheelEvent>
10532 avox 50
 
10859 cbradney 51
class QEvent;
23480 jghali 52
class QMenu;
12971 jghali 53
class QMimeData;
10859 cbradney 54
 
3 paul 55
// application specific includes
23917 jghali 56
#include "fpoint.h"
10532 avox 57
#include "observable.h"
2969 craig 58
#include "scribusapi.h"
3 paul 59
#include "scribusdoc.h"
23480 jghali 60
#include "selectionrubberband.h"
17797 fschmid 61
#include "ui/clockwidget.h"
19422 jghali 62
#include "undotransaction.h"
10532 avox 63
 
64
class Canvas;
65
class CanvasMode;
10701 avox 66
class CanvasGesture;
838 cbradney 67
class Hruler;
68
class Vruler;
16729 fschmid 69
class ScPage;
2868 fschmid 70
class RulerMover;
13805 jghali 71
class PageItem;
3054 avox 72
class PageSelector;
13805 jghali 73
class ScribusDoc;
5781 cbradney 74
class ScribusWin;
75
class ScribusMainWindow;
13805 jghali 76
class ScrSpinBox;
77
class Selection;
10532 avox 78
class UndoManager;
13371 jghali 79
class TransactionSettings;
199 Franz 80
 
3 paul 81
/**
1510 tsoots 82
 * This class provides an incomplete base for your application view.
3 paul 83
 */
84
 
10701 avox 85
class SCRIBUS_API ScribusView : public QScrollArea, public Observer<QRectF>
3 paul 86
{
168 Franz 87
        Q_OBJECT
88
 
89
public:
5781 cbradney 90
    ScribusView(QWidget* win=0, ScribusMainWindow* mw=0, ScribusDoc* doc=0);
11190 avox 91
    ~ScribusView();
10532 avox 92
 
12844 jghali 93
        friend class CanvasMode_CopyProperties;
12775 jghali 94
        friend class CanvasMode_Edit;
12770 jghali 95
        friend class CanvasMode_EditGradient;
15024 fschmid 96
        friend class CanvasMode_EditMeshGradient;
16869 fschmid 97
        friend class CanvasMode_EditMeshPatch;
19308 craig 98
        friend class CanvasMode_EditTable;
16926 fschmid 99
        friend class CanvasMode_EditWeldPoint;
16246 fschmid 100
        friend class CanvasMode_EditPolygon;
16215 fschmid 101
        friend class CanvasMode_EditArc;
16311 fschmid 102
        friend class CanvasMode_EditSpiral;
12824 jghali 103
        friend class CanvasMode_FrameLinks;
17735 craig 104
        friend class CanvasMode_ImageImport;
12824 jghali 105
        friend class CanvasMode_Magnifier;
10532 avox 106
        friend class CanvasMode_NodeEdit;
12765 jghali 107
        friend class CanvasMode_Normal;
12971 jghali 108
        friend class CanvasMode_ObjImport;
12633 jghali 109
        friend class CanvasMode_Rotate;
23917 jghali 110
 
111
        struct ViewState
112
        {
113
                int currentPage { 0 };
114
                int contentX { 0 };
115
                int contentY { 0 };
116
                double canvasScale { 1.0 };
117
                FPoint minCanvasCoordinate;
118
                FPoint maxCanvasCoordinate;
119
        };
10532 avox 120
 
121
        void requestMode(int appMode);
10701 avox 122
        void startGesture(CanvasGesture*);
123
        void stopGesture();
10532 avox 124
 
3 paul 125
  /** Vergroesserungseingabefeld */
25024 jghali 126
        RulerMover *rulerMover { nullptr }; //Widget between the two rulers for dragging the ruler origin
127
        Hruler *horizRuler{ nullptr };
128
        Vruler *vertRuler{ nullptr };
129
        ClockWidget *clockLabel{ nullptr };
130
        QPushButton *endEditButton{ nullptr };
456 fschmid 131
  /** Dokument zu dem die Seite gehoert */
23509 craig 132
        ScribusDoc * const m_doc;
10532 avox 133
        Canvas * const m_canvas;
16474 craig 134
        CanvasMode* m_canvasMode; // might be a CanvasGesture FIXME make private
135
        CanvasMode* canvasMode();
23481 jghali 136
        QMap<int, CanvasMode*> modeInstances;
3981 craig 137
        ApplicationPrefs * const Prefs;
138
        UndoManager * const undoManager;
25024 jghali 139
        ScribusMainWindow* m_ScMW{ nullptr };
23509 craig 140
        double OldScale {0.0};
141
        double dragX {0.0};
142
        double dragY {0.0};
143
        double dragW {0.0};
144
        double dragH {0.0};
145
        double oldW {-1.0};
146
        int RotMode {0};
147
        bool HaveSelRect {false};
148
        bool DraggedGroup {false};
149
        bool MidButt {false};
150
        bool updateOn {true};
151
        bool Magnify {false};
5237 fschmid 152
        bool storedFramesShown;
7624 fschmid 153
        bool storedShowControls;
14300 fschmid 154
        int editStrokeGradient;
18590 fschmid 155
        bool m_AnnotChanged;
156
        bool m_EditModeWasOn;
157
        bool m_ChangedState;
18438 craig 158
        SelectionRubberBand *redrawMarker;
24719 jghali 159
        FPoint RCenter { -1.0, -1.0 };
19547 craig 160
        FPoint m_mousePointDoc;
7452 fschmid 161
        void updatesOn(bool on);
3791 cbradney 162
        //CB This MUST now be called AFTER a call to doc->addPage or doc->addMasterPage as it
163
        //does NOT create a page anymore.
16729 fschmid 164
        ScPage* addPage(int nr, bool mov = true);
2355 cbradney 165
 
2880 fschmid 166
        void reformPages(bool moveObjects = true);
17213 craig 167
        void reformPagesView();
2093 cbradney 168
        void showMasterPage(int nr);
169
        void hideMasterPage();
23398 craig 170
        void showSymbolPage(const QString& symbolName);
16029 fschmid 171
        void hideSymbolPage();
17410 fschmid 172
        void showInlinePage(int id);
173
        void hideInlinePage();
23118 jghali 174
 
22147 jghali 175
        QImage PageToPixmap(int Nr, int maxGr, PageToPixmapFlags flags = Pixmap_DrawFrame | Pixmap_DrawBackground);
22607 craig 176
        QImage MPageToPixmap(const QString& name, int maxGr, bool drawFrame = true);
23118 jghali 177
 
3942 cbradney 178
        /**
179
         * Called when the ruler origin is dragged
180
         * @param m mouse event
181
         */
182
        void setNewRulerOrigin(QMouseEvent *m);
7575 cbradney 183
        void getDragRectScreen(double *x, double *y, double *w, double *h);
456 fschmid 184
        void getGroupRectScreen(double *x, double *y, double *w, double *h);
25058 jghali 185
        bool PointOnLine(QPoint start, QPoint end, QRect mArea);
1510 tsoots 186
        void TransformPoly(int mode, int rot = 1, double scaling = 1.0);
456 fschmid 187
        bool slotSetCurs(int x, int y);
23389 craig 188
        // \brief return a resize cursor if the mouse is on a handle.
189
        Qt::CursorShape getResizeCursor(PageItem *currItem, QRect mpo, Qt::CursorShape cursorShape = Qt::ArrowCursor);
23390 craig 190
        void deselectItems(bool prop = true);
191
        void selectItemByNumber(int nr, bool draw = true, bool single = false);
192
        void selectItem(PageItem *pi, bool draw = true, bool single = false);
7571 cbradney 193
        void rememberOldZoomLocation(int mx=0, int my=0);
11490 avox 194
        bool groupTransactionStarted() { return m_groupTransactions > 0; }
195
        void startGroupTransaction(const QString &actionName = "",
196
                                                           const QString &description = "",
197
                                                           QPixmap *actionPixmap = 0,
198
                                                           Selection* customSelection = 0);
199
        void endGroupTransaction();
200
        void cancelGroupTransaction();
25048 jghali 201
        void setScale(double newScale);
10532 avox 202
        double scale() const;
4072 cbradney 203
 
24055 craig 204
        void changed(QRectF re, bool) override;
10701 avox 205
 
206
        void updateCanvas(QRectF box = QRectF());
23631 jghali 207
        void updateCanvas(double x, double y, double width, double height) { updateCanvas(QRectF(x, y, width, height)); }
10701 avox 208
        void setCanvasOrigin(double x, double y);
209
        void setCanvasCenter(double x, double y);
210
        FPoint canvasOrigin() const;
23396 jghali 211
        QRectF visibleCanvasRect() const;
18438 craig 212
        void setRedrawMarkerShown(bool shown);
10532 avox 213
 
10701 avox 214
private:
10532 avox 215
        // legacy:
216
        void updateContents(QRect box = QRect());
217
        void updateContents(int x, int y, int w, int h);
218
        void repaintContents(QRect box);
219
        void resizeContents(int w, int h);
220
        QPoint contentsToViewport(QPoint p);
221
        QPoint viewportToContents(QPoint p);
22801 jghali 222
 
10701 avox 223
public: // for now
10532 avox 224
        int contentsX();
225
        int contentsY();
226
        int contentsWidth();
227
        int contentsHeight();
22801 jghali 228
        int visibleWidth() { return viewport()->size().width(); };
229
        int visibleHeight() { return viewport()->size().height(); };
230
 
231
        void setCanvasPos(double x, double y);
232
        void setCanvasCenterPos(double x, double y);
10532 avox 233
        void setContentsPos(int x, int y);
22801 jghali 234
 
10701 avox 235
        void scrollBy(int x, int y);
22801 jghali 236
        void scrollCanvasBy(double deltaX, double deltaY);
24055 craig 237
        void scrollContentsBy(int dx, int dy) override;
22801 jghali 238
 
11971 jghali 239
        void zoom(double scale = 0.0);
11965 jghali 240
        void zoom(int canvasX, int canvasY, double scale, bool preservePoint);
10532 avox 241
 
23917 jghali 242
        void saveViewState();
243
        void restoreViewState();
244
        const ViewState& topViewState() const { return m_viewStates.top(); }
245
 
3 paul 246
public slots: // Public slots
23474 jghali 247
        void iconSetChange();
2199 cbradney 248
        void languageChange();
19009 craig 249
        void toggleCMS(bool cmsOn);
6549 fschmid 250
        void switchPreviewVisual(int vis);
19009 craig 251
        void togglePreviewEdit(bool edit);
252
        void togglePreview(bool inPreview);
2380 cbradney 253
        void unitChange();
4651 cbradney 254
        void setRulersShown(bool isShown);
3274 fschmid 255
  /** Zooms in or out */
256
        void slotZoom100();
257
  /** Zooms in */
22801 jghali 258
        void slotZoomIn(int mx = 0, int my = 0, bool preservePoint = false);
259
        void slotZoomOut(int mx = 0, int my = 0, bool preservePoint = false);
456 fschmid 260
  /** Redraws everything */
168 Franz 261
        void DrawNew();
23948 jghali 262
        void GotoPa(int pageNumber);
23949 jghali 263
        void GotoLayer(int l);
23948 jghali 264
        void GotoPage(int pageIndex);
168 Franz 265
        void ChgUnit(int art);
13075 subik 266
 
2260 cbradney 267
        void editExtendedImageProperties();
6344 jghali 268
        void RefreshGradient(PageItem *currItem, double dx = 8, double dy = 8);
456 fschmid 269
        void ToPicFrame();
270
        void ToPolyFrame();
271
        void ToTextFrame();
272
        void ToBezierFrame();
2026 cbradney 273
        void ToPathText();
274
        void FromPathText();
456 fschmid 275
        void Bezier2Poly();
11289 fschmid 276
        void PasteToPage();
456 fschmid 277
        void TextToPath();
17519 craig 278
 
23591 craig 279
        //for linking frame after draw new frame
17519 craig 280
private:
281
        PageItem * firstFrame;
282
 
3 paul 283
private: // Private attributes
10532 avox 284
        int m_previousMode;
9800 cbradney 285
        QMenu *pmen3;
286
        QMenu *pmenResolution;
25014 jghali 287
        QPointF m_pressLocation;
23480 jghali 288
        QElapsedTimer m_moveTimer;
10978 avox 289
        QTimer *m_dragTimer;
23509 craig 290
        bool m_dragTimerFired;
291
        bool m_ready {false};
292
        int m_oldZoomX {0};
293
        int m_oldZoomY {0};
22801 jghali 294
        QSize m_oldCanvasSize;
23509 craig 295
        int m_groupTransactions {0};
19422 jghali 296
        UndoTransaction m_groupTransaction;
23509 craig 297
        bool _isGlobalMode {true};
298
        bool linkAfterDraw {false};
299
        bool ImageAfterDraw {false};
23917 jghali 300
        QStack<ViewState> m_viewStates;
1226 tsoots 301
 
3 paul 302
private slots:
4704 cbradney 303
        void setZoom();
3942 cbradney 304
        /**
305
         * Called to update the GUI when the canvas(view) scrollbars are moved
306
         * @param x
307
         * @param y
308
         */
168 Franz 309
        void setRulerPos(int x, int y);
1461 tsoots 310
        void setObjectUndoMode();
311
        void setGlobalUndoMode();
9668 fschmid 312
        void dragTimerTimeOut();
168 Franz 313
 
10532 avox 314
public:
24048 jghali 315
        void wheelEvent(QWheelEvent *ev) override;
316
        void changeEvent(QEvent *e) override;
23591 craig 317
        void nativeGestureEvent(QNativeGestureEvent *e);
24048 jghali 318
        void keyPressEvent(QKeyEvent *k) override;
319
        void keyReleaseEvent(QKeyEvent *k) override;
320
        void inputMethodEvent(QInputMethodEvent * event) override;
321
        QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
16546 jghali 322
 
25014 jghali 323
        inline void registerMousePress(QPointF p);
11576 avox 324
        bool mousePressed();
325
        void resetMousePressed();
25014 jghali 326
        inline QPointF mousePressLocation();
10978 avox 327
        inline bool moveTimerElapsed();
328
        inline void resetMoveTimer();
329
 
330
        inline void startDragTimer();
331
        inline void stopDragTimer();
332
        inline void resetDragTimer();
333
        inline bool dragTimerElapsed();
22801 jghali 334
        void stopAllDrags();
10978 avox 335
 
22516 craig 336
        bool handleObjectImport(QMimeData* mimeData, TransactionSettings* trSettings = nullptr);
12971 jghali 337
 
3 paul 338
protected: // Protected methods
24834 jghali 339
        void enterEvent(QEnterEvent *) override;
24055 craig 340
        void leaveEvent(QEvent *) override;
341
        void resizeEvent(QResizeEvent *event) override;
342
        bool eventFilter(QObject *obj, QEvent *event) override;
10532 avox 343
 
344
        // those appear to be gone from QScrollArea:
456 fschmid 345
        virtual void contentsDragEnterEvent(QDragEnterEvent *e);
346
        virtual void contentsDragMoveEvent(QDragMoveEvent *e);
347
        virtual void contentsDragLeaveEvent(QDragLeaveEvent *e);
348
        virtual void contentsDropEvent(QDropEvent *e);
3 paul 349
        virtual void setHBarGeometry(QScrollBar &bar, int x, int y, int w, int h);
350
        virtual void setVBarGeometry(QScrollBar &bar, int x, int y, int w, int h);
4654 cbradney 351
 
352
        //The width of vertical ruler/height of horizontal ruler, set to 17 in scribusview.cpp
24719 jghali 353
        int m_vhRulerHW { 17 };
168 Franz 354
 
3 paul 355
signals:
23951 jghali 356
        void unitChanged(int);
357
        void layerChanged(int);
19288 jghali 358
        void HaveSel();
456 fschmid 359
        void DocChanged();
16546 jghali 360
        void ItemGeom();
456 fschmid 361
        void PolyOpen();
16546 jghali 362
        void ItemCharStyle(const CharStyle&);
363
        void ItemTextAlign(int);
364
        void ItemTextEffects(int);
456 fschmid 365
        void AddBM(PageItem *);
366
        void DelBM(PageItem *);
367
        void ChBMText(PageItem *);
3743 fschmid 368
        void LoadElem(QString, double, double, bool, bool, ScribusDoc *, ScribusView *);
456 fschmid 369
        void HavePoint(bool, bool);
370
        void ClipPo(double, double);
19071 fschmid 371
        void PolyStatus(int, uint);
456 fschmid 372
        void MousePos(double, double);
3 paul 373
};
10532 avox 374
 
375
 
376
 
10978 avox 377
 
25014 jghali 378
inline void ScribusView::registerMousePress(QPointF p)
10978 avox 379
{
380
        m_pressLocation = p;
381
        m_moveTimer.start();
382
        m_dragTimerFired = false;
383
}
384
 
385
 
25014 jghali 386
inline QPointF ScribusView::mousePressLocation()
10978 avox 387
{
388
        return m_pressLocation;
389
}
390
 
391
 
10532 avox 392
inline bool ScribusView::moveTimerElapsed()
393
{
13876 cbradney 394
        return (m_moveTimer.elapsed() > Prefs->uiPrefs.mouseMoveTimeout);
10532 avox 395
}
396
 
397
 
10978 avox 398
inline void ScribusView::resetMoveTimer()
399
{
400
        m_moveTimer.start();
401
}
402
 
403
 
404
inline void ScribusView::startDragTimer()
405
{
406
        m_dragTimerFired = false;
407
        m_dragTimer->setSingleShot(true);
408
        m_dragTimer->start(1000);                       // set Timeout for starting a Drag operation to 1 sec.
409
}
410
 
411
inline void ScribusView::stopDragTimer()
412
{
413
        m_dragTimer->stop();
414
}
415
 
416
 
417
inline void ScribusView::resetDragTimer()
418
{
419
        m_dragTimerFired = false;
420
}
421
 
422
 
423
inline bool ScribusView::dragTimerElapsed()
424
{
425
        return m_dragTimerFired;
426
}
427
 
16474 craig 428
inline CanvasMode* ScribusView::canvasMode()
429
{
430
        return m_canvasMode;
431
}
432
 
3 paul 433
#endif