File indexing completed on 2024-05-12 17:11:40
0001 /*************************************************************************** 0002 * Copyright (C) 2014 by Renaud Guezennec * 0003 * http://www.rolisteam.org/ * 0004 * * 0005 * This file is part of rcse * 0006 * * 0007 * rcse is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 * rcse is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0015 * GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License * 0018 * along with this program; if not, write to the * 0019 * Free Software Foundation, Inc., * 0020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0021 ***************************************************************************/ 0022 #ifndef CANVAS_H 0023 #define CANVAS_H 0024 0025 #include <QGraphicsItem> 0026 #include <QGraphicsPixmapItem> 0027 #include <QGraphicsScene> 0028 #include <QPointer> 0029 #include <QUndoStack> 0030 0031 #include "charactersheet/controllers/fieldcontroller.h" 0032 #include "fieldmodel.h" 0033 0034 class ImageModel; 0035 class EditorController; 0036 class Canvas : public QGraphicsScene 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(int pageId READ pageId WRITE setPageId NOTIFY pageIdChanged) 0040 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged) 0041 public: 0042 enum Tool 0043 { 0044 NONE, 0045 ADDINPUT, 0046 ADDTEXTFIELD, 0047 ADDTEXTAREA, 0048 ADDTABLE, 0049 ADDIMAGE, 0050 ADDLABEL, 0051 ADDSLIDER, 0052 ADDHIDDEN, 0053 ADDFUNCBUTTON, 0054 ADDWEBPAGE, 0055 NEXTPAGE, 0056 PREVIOUSPAGE, 0057 ADDCHECKBOX, 0058 MOVE, 0059 DELETETOOL, 0060 BUTTON 0061 }; 0062 explicit Canvas(EditorController* ctrl, QObject* parent= nullptr); 0063 0064 void setCurrentTool(Canvas::Tool); 0065 FieldModel* model() const; 0066 void setModel(FieldModel* model); 0067 0068 const QPixmap pixmap() const; 0069 0070 void setPixmap(const QPixmap& pix); 0071 int pageId() const; 0072 void setPageId(int pageId); 0073 0074 Canvas::Tool currentTool() const; 0075 0076 void deleteItem(QGraphicsItem* item); 0077 0078 QUndoStack* undoStack() const; 0079 void setUndoStack(QUndoStack* undoStack); 0080 0081 public slots: 0082 void addField(CSItem* itemCtrl); 0083 0084 signals: 0085 void pixmapChanged(); 0086 void dropFileOnCanvas(QUrl url); 0087 void pageIdChanged(); 0088 void performCommand(QUndoCommand* cmd); 0089 0090 protected: 0091 void dragEnterEvent(QGraphicsSceneDragDropEvent* event); 0092 void dropEvent(QGraphicsSceneDragDropEvent* event); 0093 void dragMoveEvent(QGraphicsSceneDragDropEvent* event); 0094 void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent); 0095 void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent); 0096 void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent); 0097 0098 private: 0099 void adjustNewItem(CanvasField* item); 0100 bool forwardEvent(); 0101 0102 private: 0103 QPointer<EditorController> m_ctrl; 0104 QGraphicsPixmapItem* m_bg; 0105 CanvasField* m_currentItem; 0106 Tool m_currentTool= MOVE; 0107 FieldModel* m_model; 0108 int m_pageId; 0109 QList<QGraphicsItem*> m_movingItems; 0110 QList<QPointF> m_oldPos; 0111 }; 0112 0113 #endif // CANVAS_H