-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Separating shapes from the core
- Loading branch information
Showing
26 changed files
with
1,227 additions
and
1,172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
src/commands | ||
src/core | ||
src/core/qt_shapes | ||
src/core/rq | ||
src/gui | ||
src/io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
project (qt_shapes) | ||
file(GLOB SOURCES "*.cpp") | ||
add_library (qt_shapes STATIC ${SOURCES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "ellipse.hpp" | ||
|
||
#include <QPainter> | ||
#include <QPen> | ||
|
||
#include <iostream> | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// @Ellipse implementation | ||
// | ||
Ellipse::Ellipse(QRect r, ShapeProperties b) : IShape(ELLIPSE, b), m_waitForSecondClick(false) | ||
{ | ||
m_object = r; | ||
} | ||
|
||
Ellipse *Ellipse::clone() | ||
{ | ||
return new Ellipse(m_object, m_properties); | ||
} | ||
|
||
void Ellipse::draw(QPainter *p) | ||
{ | ||
QPen pen(m_properties.pen_color, m_properties.pen_width, m_properties.pen_style, m_properties.pen_cap_style, | ||
m_properties.pen_join_style); | ||
QBrush brush(m_properties.brush_color, m_properties.brush_style); | ||
p->setBrush(brush); | ||
p->setPen(pen); | ||
p->drawEllipse(m_object); | ||
} | ||
|
||
void Ellipse::reset() | ||
{ | ||
m_object.setRect(0, 0, 0, 0); | ||
m_waitForSecondClick = false; | ||
} | ||
|
||
void Ellipse::setTopLeft(const QPoint &p) | ||
{ | ||
m_object.setTopLeft(p); | ||
} | ||
|
||
void Ellipse::setBottomRight(const QPoint &p) | ||
{ | ||
m_object.setBottomRight(p); | ||
} | ||
|
||
QPoint Ellipse::getTopLeft() const | ||
{ | ||
return m_object.topLeft(); | ||
} | ||
|
||
QPoint Ellipse::getBottomRight() const | ||
{ | ||
return m_object.bottomRight(); | ||
} | ||
|
||
void Ellipse::addPoint(const QPoint &point) | ||
{ | ||
if (m_waitForSecondClick) | ||
{ | ||
m_object.setBottomRight(point); | ||
} | ||
else | ||
{ | ||
m_object.setTopLeft(point); | ||
m_waitForSecondClick = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#pragma once | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Includes | ||
// | ||
#include "../ishape.hpp" | ||
|
||
// Qt | ||
#include <QMouseEvent> | ||
#include <QObject> | ||
#include <QPoint> | ||
#include <QPolygonF> | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// @class ellipse, wrapper for OA/Qt object | ||
// | ||
class Ellipse : public IShape | ||
{ | ||
public: | ||
Ellipse(QRect = QRect(), ShapeProperties = ShapeProperties()); | ||
virtual ~Ellipse() = default; | ||
|
||
public: | ||
Ellipse *clone() override; | ||
void draw(QPainter *) override; | ||
|
||
public: | ||
void reset() override; | ||
void addPoint(const QPoint &) override; | ||
|
||
public: | ||
void setTopLeft(const QPoint &); | ||
void setBottomRight(const QPoint &); | ||
|
||
QPoint getTopLeft() const; | ||
QPoint getBottomRight() const; | ||
|
||
bool contains(const QPoint &point) const | ||
{ | ||
return m_object.contains(point); | ||
} | ||
bool intersects(const QRect &oRect) const | ||
{ | ||
return m_object.intersects(oRect); | ||
} | ||
|
||
virtual ObjectType getType() const override | ||
{ | ||
return ELLIPSE; | ||
} | ||
|
||
virtual void moveCenterToPoint(QPoint &p) | ||
{ | ||
m_object.moveTo(p); | ||
} | ||
|
||
std::vector<QPoint> getPoints() override | ||
{ | ||
return std::vector<QPoint>(2) = {getBottomRight(), getTopLeft()}; | ||
} | ||
|
||
private: | ||
QRect m_object; | ||
bool m_waitForSecondClick; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "line.hpp" | ||
|
||
#include <QPainter> | ||
#include <QPen> | ||
|
||
#include <iostream> | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// @Line implementation | ||
// | ||
Line::Line(QLine l, ShapeProperties p) : IShape(LINE, p), m_waitForSecondClick(false) | ||
{ | ||
m_object = l; | ||
} | ||
|
||
Line *Line::clone() | ||
{ | ||
return new Line(m_object, m_properties); | ||
} | ||
|
||
void Line::draw(QPainter *p) | ||
{ | ||
QPen pen(m_properties.pen_color, m_properties.pen_width, m_properties.pen_style, m_properties.pen_cap_style, | ||
m_properties.pen_join_style); | ||
QBrush brush(m_properties.brush_color, m_properties.brush_style); | ||
p->setBrush(brush); | ||
p->setPen(pen); | ||
p->drawLine(m_object); | ||
} | ||
|
||
void Line::reset() | ||
{ | ||
m_object.setLine(0, 0, 0, 0); | ||
m_waitForSecondClick = false; | ||
} | ||
|
||
void Line::addPoint(const QPoint &point) | ||
{ | ||
if (m_waitForSecondClick) | ||
{ | ||
m_object.setP2(point); | ||
} | ||
else | ||
{ | ||
m_object.setP1(point); | ||
m_waitForSecondClick = true; | ||
} | ||
} | ||
|
||
void Line::setP1(const QPoint &p) | ||
{ | ||
m_object.setP1(p); | ||
} | ||
|
||
void Line::setP2(const QPoint &p) | ||
{ | ||
m_object.setP2(p); | ||
} | ||
|
||
QPoint Line::getP1() const | ||
{ | ||
return m_object.p1(); | ||
} | ||
|
||
QPoint Line::getP2() const | ||
{ | ||
return m_object.p2(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Includes | ||
// | ||
#include "../ishape.hpp" | ||
|
||
// Qt | ||
#include <QLine> | ||
#include <QObject> | ||
|
||
// stl | ||
#include <vector> | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// @class line, wrapper for OA/Qt object | ||
// | ||
class Line : public IShape | ||
{ | ||
public: | ||
Line(QLine = QLine(), ShapeProperties = ShapeProperties()); | ||
virtual ~Line() = default; | ||
|
||
public: | ||
Line *clone() override; | ||
void draw(QPainter *) override; | ||
|
||
public: | ||
void reset() override; | ||
void addPoint(const QPoint &) override; | ||
|
||
private: | ||
void setP1(const QPoint &); | ||
void setP2(const QPoint &); | ||
|
||
public: | ||
QPoint getP1() const; | ||
QPoint getP2() const; | ||
|
||
virtual ObjectType getType() const override | ||
{ | ||
return LINE; | ||
} | ||
|
||
virtual void moveCenterToPoint(QPoint &) | ||
{ | ||
// m_object.moveTo(p); | ||
} | ||
|
||
#ifdef NO_RQ | ||
virtual bool contains(const QPoint &point) const | ||
{ | ||
return false; | ||
} | ||
#endif | ||
|
||
// FIXME need proper fix and member handling | ||
std::vector<QPoint> getPoints() override | ||
{ | ||
return std::vector<QPoint>(2) = {m_object.p1(), m_object.p2()}; | ||
} | ||
|
||
private: | ||
QLine m_object; | ||
bool m_waitForSecondClick; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "polygon.hpp" | ||
|
||
#include <QPainter> | ||
#include <QPen> | ||
|
||
#include <iostream> | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// @polygon implementation | ||
// | ||
Polygon::Polygon(QPolygon p, ShapeProperties b) : IShape(POLYGON, b) | ||
{ | ||
m_object = p; | ||
} | ||
|
||
Polygon *Polygon::clone() | ||
{ | ||
return new Polygon(m_object, m_properties); | ||
} | ||
|
||
void Polygon::draw(QPainter *p) | ||
{ | ||
QPen pen(m_properties.pen_color, m_properties.pen_width, m_properties.pen_style, m_properties.pen_cap_style, | ||
m_properties.pen_join_style); | ||
QBrush brush(m_properties.brush_color, m_properties.brush_style); | ||
p->setBrush(brush); | ||
p->setPen(pen); | ||
p->drawPolygon(m_object); | ||
} | ||
|
||
void Polygon::reset() | ||
{ | ||
QPolygon p; | ||
m_object.swap(p); | ||
} | ||
|
||
void Polygon::addPoint(const QPoint &p) | ||
{ | ||
if (m_first) | ||
m_object << p; | ||
m_object << p; | ||
m_first = false; | ||
} | ||
|
||
void Polygon::movePoint(const QPoint &p) | ||
{ | ||
m_object.setPoint(m_object.size() - 1, p); | ||
} | ||
|
||
QPoint Polygon::getTopLeft() const | ||
{ | ||
return m_object.boundingRect().topLeft(); | ||
} | ||
|
||
QPoint Polygon::getBottomRight() const | ||
{ | ||
return m_object.boundingRect().bottomRight(); | ||
} |
Oops, something went wrong.