Qtshapes.cpp

#include "qtshapes.h"

QtRectangle::QtRectangle(const Vector2D& p1, const Vector2D& p2)

: Rectangle(p1, p2)

{}

void QtRectangle::draw(QPainter &painter) const

{

Vector2D tl = Rectangle::center - Rectangle::size * 0.5;

Color p = getStyle().lineColor;

Color f = getStyle().fillColor;

if (isSelected()) f.alpha = 0.5;

painter.setPen(QColor(p.red * 255, p.green * 255, p.blue * 255, p.alpha * 255));

painter.setBrush(QBrush(QColor(f.red * 255, f.green * 255, f.blue * 255, f.alpha * 255)));

painter.drawRect(tl[X], tl[Y], Rectangle::size[X], Rectangle::size[Y]);

}

void QtRectangle::select(bool sel)

{

QtShape2D::select(sel);

}

bool QtRectangle::isSelected() const

{

return QtShape2D::isSelected();

}

DrawStyle& QtRectangle::getStyle()

{

return Rectangle::getStyle();

}

const DrawStyle& QtRectangle::getStyle() const

{

return Rectangle::getStyle();

}

Vector2D QtRectangle::getCenter() const

{

return Rectangle::getCenter();

}

Vector2D QtRectangle::getSize() const

{

return Rectangle::getSize();

}

void QtRectangle::setBounds(const Vector2D& p1, const Vector2D& p2)

{

Rectangle::setBounds(p1, p2);

}

void QtRectangle::move(const Vector2D& destination)

{

Rectangle::move(destination);

}

bool QtRectangle::belongs(const Vector2D& p)

{

return Rectangle::belongs(p);

}

Додаток В-3. Код області рисування CanvasWidget

Canvaswidget.h

#ifndef CANVASWIDGET_H

#define CANVASWIDGET_H

#include

#include

#include

#include

#include "qtshapes.h"

class CanvasWidget : public QWidget

{

Q_OBJECT

public:

explicit CanvasWidget(QWidget *parent = 0);

~CanvasWidget();

std::vector shapes;

QtShape2D* selected;

signals:

public slots:

protected:

virtual void mousePressEvent (QMouseEvent * event);



virtual void mouseMoveEvent (QMouseEvent * event);

virtual void mouseReleaseEvent (QMouseEvent * event);

virtual void paintEvent (QPaintEvent * event);

Vector2D pressedPoint;

bool creating;

};

#endif // CANVASWIDGET_H


0003380871154479.html
0003473054542030.html

0003380871154479.html
0003473054542030.html
    PR.RU™