File indexing completed on 2024-04-21 03:50:56
0001 #ifndef CONTAINER_H 0002 #define CONTAINER_H 0003 0004 #include "core/markedclass.h" 0005 #include "core/markedobject.h" 0006 0007 #include <memory> 0008 0009 #include <QGraphicsView> 0010 #include <QVector> 0011 0012 class Painter; 0013 0014 /** Annotation container. */ 0015 class Container : public QGraphicsView 0016 { 0017 Q_OBJECT 0018 0019 friend class Painter; 0020 0021 public: 0022 explicit Container(QWidget* parent = nullptr); 0023 ~Container() override; 0024 0025 public: 0026 /** Represents the possible types of a Painter. */ 0027 enum class PainterType { 0028 None, 0029 Image, 0030 Text 0031 }; 0032 0033 /** Filter events in the container, if it is a mouse event treat it, otherwise ignore. 0034 * @param watched - watched object. 0035 * @param event - event to treat. 0036 */ 0037 bool eventFilter(QObject* watched, QEvent* event); 0038 0039 /** @return pointer of the current Painter. */ 0040 Painter* painter() const { return m_painter.get(); } 0041 0042 public: 0043 /** Set MarkedClass of the current object. 0044 * @param objClass - Class to define. 0045 */ 0046 void setObjClass(MarkedClass* objClass); 0047 0048 public: 0049 /** @return saved annotated objects. */ 0050 QVector<MarkedObject*>& savedObjects() { return m_savedObjects; } 0051 0052 /** @return pointer of current MarkedObject. */ 0053 MarkedObject* currentObject() { return m_currentObject; } 0054 0055 /** Append MarkedObject instance to savedObjects. */ 0056 void appendObject(MarkedObject* object); 0057 0058 /** Set current object. 0059 * @param currentObject - object to set as current object. 0060 */ 0061 void setCurrentObject(MarkedObject* currentObject) { m_currentObject = currentObject; } 0062 0063 /** Load given item/file. 0064 * @param itemPath - Path of the item. 0065 */ 0066 void changeItem(const QString& filepath); 0067 0068 /** Repaint annotated objects. */ 0069 void repaint(); 0070 0071 /** Clear all visual elements of Container. */ 0072 void clear(); 0073 0074 /** Paint given object. 0075 * @param object - object to paint. 0076 */ 0077 void paintObject(MarkedObject* object); 0078 0079 /** Load given objects. 0080 * @param objects - Vector of annotated object to load. 0081 */ 0082 bool importObjects(QVector<MarkedObject*> objects); 0083 0084 public slots: 0085 /** Undo last action. */ 0086 void undo(); 0087 0088 /** Delete a MarkedObject's instance. */ 0089 void deleteObject(); 0090 0091 /** Delete all annotated objects. */ 0092 void reset(); 0093 0094 signals: 0095 0096 void painterChanged(PainterType painterType); 0097 0098 void savedObjectsChanged(); 0099 0100 protected: 0101 MarkedObject* m_currentObject; 0102 QVector<MarkedObject*> m_savedObjects; 0103 0104 PainterType m_painterType; 0105 std::unique_ptr<Painter> m_painter; 0106 }; 0107 0108 #endif // CONTAINER_H