diff --git a/src/Editor/KSLineTool.cpp b/src/Editor/KSLineTool.cpp index 2bff712..949ed40 100644 --- a/src/Editor/KSLineTool.cpp +++ b/src/Editor/KSLineTool.cpp @@ -1,60 +1,66 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KSLineTool.h" KSLineTool::KSLineTool(QQuickItem *parent) : QQuickPaintedItem(parent), p1(0, 0), p2(0, 0), mLineColor(Qt::black), mLineWidth(1) { setAntialiasing(true); } void KSLineTool::paint(QPainter *painter) { painter->save(); QPen pen; pen.setColor(mLineColor); pen.setWidth(mLineWidth); - painter->setPen(pen); - painter->drawLine(p1, p2); + + QLineF line(p1, p2); + painter->drawLine(line); painter->restore(); } +void drawArrow(QPainter *painter, QLineF line) +{ + +} + // property accessors int KSLineTool::x1() const { return p1.x(); } int KSLineTool::y1() const { return p1.y(); } int KSLineTool::x2() const { return p2.x(); } int KSLineTool::y2() const { return p2.y(); } int KSLineTool::lineWidth() const { return mLineWidth; } QColor KSLineTool::lineColor() const { return mLineColor; } // property mutators void KSLineTool::setX1(const int &x1) { p1.setX(x1); update(); } void KSLineTool::setY1(const int &y1) { p1.setY(y1); update(); } void KSLineTool::setX2(const int &x2) { p2.setX(x2); update(); } void KSLineTool::setY2(const int &y2) { p2.setY(y2); update(); } void KSLineTool::setLineWidth(const int &lineWidth) { mLineWidth = lineWidth; update(); } void KSLineTool::setLineColor(const QColor &lineColor) { mLineColor = lineColor; update(); } diff --git a/src/Editor/KSLineTool.h b/src/Editor/KSLineTool.h index e6bc4a3..a02f16b 100644 --- a/src/Editor/KSLineTool.h +++ b/src/Editor/KSLineTool.h @@ -1,77 +1,78 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KSLINETOOL_H #define KSLINETOOL_H #include #include #include #include +#include class KSLineTool : public QQuickPaintedItem { Q_OBJECT Q_PROPERTY(int x1 READ x1 WRITE setX1 NOTIFY x1Changed) Q_PROPERTY(int y1 READ y1 WRITE setY1 NOTIFY y1Changed) Q_PROPERTY(int x2 READ x2 WRITE setX2 NOTIFY x2Changed) Q_PROPERTY(int y2 READ y2 WRITE setY2 NOTIFY y2Changed) Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth NOTIFY lineWidthChanged) Q_PROPERTY(QColor lineColor READ lineColor WRITE setLineColor NOTIFY lineColorChanged) public: explicit KSLineTool(QQuickItem *parent = 0); void paint(QPainter *painter) Q_DECL_OVERRIDE; int x1() const; int y1() const; int x2() const; int y2() const; int lineWidth() const; QColor lineColor() const; public slots: void setX1(const int &x1); void setY1(const int &y1); void setX2(const int &x2); void setY2(const int &y2); void setLineWidth(const int &lineWidth); void setLineColor(const QColor &lineColor); signals: void x1Changed(const int x1); void y1Changed(const int y1); void x2Changed(const int x2); void y2Changed(const int y2); void lineWidthChanged(const int lineWidth); void lineColorChanged(const QColor lineColor); private: QPoint p1; QPoint p2; QColor mLineColor; int mLineWidth; }; #endif // KSLINETOOL_H