document.h Example File | Qt 4.8 (original) (raw)

demos/undo/document.h

#ifndef DOCUMENT_H #define DOCUMENT_H

#include

QT_FORWARD_DECLARE_CLASS(QUndoStack) QT_FORWARD_DECLARE_CLASS(QTextStream)

class Shape { public: enum Type { Rectangle, Circle, Triangle };

Shape(Type type = Rectangle, const [QColor](qcolor.html) &color = [Qt](qt-module.html)::red, const [QRect](qrect.html) &rect = [QRect](qrect.html)());

Type type() const;
[QString](qstring.html) name() const;
[QRect](qrect.html) rect() const;
[QRect](qrect.html) resizeHandle() const;
[QColor](qcolor.html) color() const;

static [QString](qstring.html) typeToString(Type type);
static Type stringToType(const [QString](qstring.html) &s, bool *ok = 0);

static const [QSize](qsize.html) minSize;

private: Type m_type; QRect m_rect; QColor m_color; QString m_name;

friend class Document;

};

class Document : public QWidget { Q_OBJECT

public: Document(QWidget *parent = 0);

[QString](qstring.html) addShape(const Shape &shape);
void deleteShape(const [QString](qstring.html) &shapeName);
Shape shape(const [QString](qstring.html) &shapeName) const;
[QString](qstring.html) currentShapeName() const;

void setShapeRect(const [QString](qstring.html) &shapeName, const [QRect](qrect.html) &rect);
void setShapeColor(const [QString](qstring.html) &shapeName, const [QColor](qcolor.html) &color);

bool load([QTextStream](qtextstream.html) &stream);
void save([QTextStream](qtextstream.html) &stream);

[QString](qstring.html) fileName() const;
void setFileName(const [QString](qstring.html) &fileName);

[QUndoStack](qundostack.html) *undoStack() const;

signals: void currentShapeChanged(const QString &shapeName);

protected: void paintEvent(QPaintEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);

private: void setCurrentShape(int index); int indexOf(const QString &shapeName) const; int indexAt(const QPoint &pos) const; QString uniqueName(const QString &name) const;

[QList](qlist.html)<Shape> m_shapeList;
int m_currentIndex;
int m_mousePressIndex;
[QPoint](qpoint.html) m_mousePressOffset;
bool m_resizeHandlePressed;
[QString](qstring.html) m_fileName;

[QUndoStack](qundostack.html) *m_undoStack;

};

#endif // DOCUMENT_H

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.