1 /***************************************************************************
2  *   Copyright (C) 2000-2019 by Johan Maes                                 *
3  *   on4qz@telenet.be                                                      *
4  *   http://users.telenet.be/on4qz                                         *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20  ***************************************************************************/
21 #ifndef EDITORSCENE_H
22 #define EDITORSCENE_H
23 
24 #include <QGraphicsScene>
25 //#include <QGraphicsView>
26 //#include "graphics.h"
27 #include "graphicitems.h"
28 #include "supportfunctions.h"
29 #include "macroexpansion.h"
30 
31 class QGraphicsSceneMouseEvent;
32 
33 #define CHANGECOLOR
34 #define CHANGE
35 
36 
37 
38 
39 
40 class editorScene : public QGraphicsScene
41 {
42   Q_OBJECT
43 
44 public:
45   enum eImageType
46   {
47     NONE,				/*!< no image defined */
48     FLATIMAGE, /*!< loaded image is a simple image (png,jpeg,...) */
49     TEMPLATE    /*!< loaded image is a template file */
50   };
51   enum eMode { MOVE, INSERT};
52   enum doChange {DNOCHANGE = 0, DFILLCOLOR = 1, DLINECOLOR=2, DGRADIENT=4,DTEXT = 8,DFONT=16,DPEN=32,DTRANSFORM=64};
53   Q_DECLARE_FLAGS(changeFlags, doChange);
54   editorScene(QGraphicsView *parent=0);
55   ~editorScene();
56   QColor fillColor;
57   QColor lineColor;
58   QGradient gradient;
59   QColor gradientColor;
60   QFont  font;
61   QString text;
62   QString fl;
63   double penWidth;
64   void apply(changeFlags cf);
65   void clearAll();
66   QRectF border;
67   int rotate;
68   qreal hShear;
69   qreal vShear;
70   bool load(QFile &f);
71   bool save(QFile &f,bool templ);
72   void setImage(QImage *im);
73   eMode mode;
getImageType()74   eImageType getImageType(){return imageType;}
75   QImage *renderImage(int w, int h);
76   macroExpansion mexp;
77   void overlay(QImage *ima);
78   void addBorder(int w,int h);
getImagePtr()79   QImage *getImagePtr() {return localImage;}
80   void addConversion(QChar tag,QString value,bool clear=false);
81 
82   // bool event(QEvent *);
83 
84 public slots:
85   void setMode(eMode m);
86   void setItemType(graphItemBase::egraphType tp);
87   //    void editorLostFocus(DiagramTextItem *item);
88   void slotCopy();
89   void slotPaste();
90   void slotExpand();
91 
92   void slotDeleteItem();
93   void slotLock();
94   void slotUnlock();
95   void slotBringToFront();
96   void slotSendToBack();
97   void slotSendBackward();
98   void slotSendForward();
99   void slotChangeText();
100 #ifndef QT_NO_DEBUG
101   void slotProperties();
102   void dumpItems();
103 #endif
104 
105 
106 signals:
107   //	void itemInserted(graphItemBase *itm);
108   //	void textInserted(graphItemBase *itm);
109   void changeSize(int,int);
110   void itemSelected(graphItemBase *itm);
111   void colorSelected( const QPointF &p);
112 
113 protected:
114   void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
115   void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
116   void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
117 
118 
119 private:
120   graphItemBase *copyItem;
121   graphItemBase::egraphType itemType;
122   bool leftButtonDown;
123 
124   bool pasted;
125   qreal zMax;
126   QPointF startPoint;
127   // Context menus
128   QMenu *contextMenu;
129   QMenu *arrange;
130 
131   void optimizeDepth();
132   void itemSetup(graphItemBase *item);
133   void makeCopy(graphItemBase *it);
134   eImageType imageType;
135   QImage *localImage;
136   void flattenImage(int w,int h);
137   void convertText();
138   //  QString textConversion(QString str);
139   //  QString convertedText;
140   graphItemBase *borderItemPtr;
141   void convertReplayImage();
142 
143 };
144 Q_DECLARE_OPERATORS_FOR_FLAGS(editorScene::changeFlags)
145 
146 #endif
147