File indexing completed on 2024-04-28 04:32:07

0001 /*
0002  * Copyright (C) 2010-2015 by Stephen Allewell
0003  * steve.allewell@gmail.com
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2 of the License, or
0008  * (at your option) any later version.
0009  */
0010 
0011 #ifndef SelectArea_H
0012 #define SelectArea_H
0013 
0014 #include <QList>
0015 #include <QMap>
0016 #include <QRect>
0017 #include <QWidget>
0018 
0019 class QMouseEvent;
0020 class QPaintEvent;
0021 
0022 class Document;
0023 class PatternElement;
0024 
0025 class SelectArea : public QWidget
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     SelectArea(QWidget *, PatternElement *, Document *, const QMap<int, QList<QRect>> &);
0031     virtual ~SelectArea() = default;
0032 
0033     QRect patternRect() const;
0034     void setPatternRect(const QRect &);
0035 
0036 protected:
0037     virtual void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
0038     virtual void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
0039     virtual void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
0040     virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
0041 
0042 private:
0043     QPoint contentsToCell(const QPoint &) const;
0044     QRect cellToRect(const QPoint &) const;
0045 
0046     PatternElement *m_patternElement;
0047     PatternElement *m_fullPatternElement;
0048 
0049     Document *m_document;
0050     int m_width;
0051     int m_height;
0052     QRect m_patternRect;
0053     QMap<int, QList<QRect>> m_patternRects;
0054 
0055     QPoint m_cellStart;
0056     QPoint m_cellTracking;
0057     QPoint m_cellEnd;
0058 
0059     QRect m_rubberBand;
0060 };
0061 
0062 #endif // SelectArea_H