coloringcanvas.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef COLORINGCANVAS_H
  2. #define COLORINGCANVAS_H
  3. #include <QtDeclarative/QDeclarativeItem>
  4. #include <QtGui>
  5. class ColoringCanvas : public QDeclarativeItem
  6. {
  7. Q_OBJECT
  8. Q_DISABLE_COPY(ColoringCanvas)
  9. Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
  10. Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
  11. public:
  12. explicit ColoringCanvas(QDeclarativeItem *parent = 0);
  13. void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
  14. QColor color() const { return color_; };
  15. QString source() const { return source_; };
  16. signals:
  17. void colorChanged();
  18. void sourceChanged();
  19. public slots:
  20. void setSource(const QString& newSource);
  21. void setColor(const QColor newColor);
  22. void click(int x, int y);
  23. protected:
  24. bool test(const QPoint& point, const QRgb& color);
  25. void floodFill(const QPoint& point, const QRgb& fillColor);
  26. void drawHorizontalLine(const QPoint & p1, const QPoint & p2, const QRgb& fillColor);
  27. // Checks if point has ignore color and puts a valid point in valid
  28. // returns false if no valid point found
  29. bool check(const QPoint& point, QPoint& valid);
  30. private:
  31. QColor color_;
  32. QString source_;
  33. QColor ignore_;
  34. QImage image_;
  35. };
  36. QML_DECLARE_TYPE(ColoringCanvas)
  37. #endif // COLORINGCANVAS_H