Commit 3d8301cc authored by Yimgo's avatar Yimgo

introduced aristo tool.

TODO:
 * nice icon
 * nice brush
 * fix draw with marker
parent b94b8629
......@@ -166,6 +166,7 @@
<file>images/toolPalette/triangleTool.png</file>
<file>images/toolPalette/protractorTool.png</file>
<file>images/toolPalette/compassTool.png</file>
<file>images/toolPalette/aristoTool.png</file>
<file>images/toolPalette/maskTool.png</file>
<file>images/toolPalette/magnifierTool.png</file>
<file>images/extraPalette/blackout.png</file>
......
......@@ -1276,6 +1276,11 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
mActiveScene->addMask(pPos);
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
}
else if (sourceUrl.toString() == UBToolsManager::manager()->aristo.id)
{
mActiveScene->addAristo(pPos);
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
}
else
{
showMessage(tr("Unknown tool type %1").arg(sourceUrl.toString()));
......
......@@ -145,6 +145,7 @@ struct UBGraphicsItemType
TriangleItemType,
MagnifierItemType,
cacheItemType,
AristoItemType,
groupContainerType,
ToolWidgetItemType
};
......
......@@ -39,6 +39,7 @@
#include "tools/UBGraphicsTriangle.h"
#include "tools/UBGraphicsCurtainItem.h"
#include "tools/UBGraphicsCache.h"
#include "tools/UBGraphicsAristo.h"
#include "document/UBDocumentProxy.h"
......@@ -2071,6 +2072,22 @@ void UBGraphicsScene::addCompass(QPointF center)
setModified(true);
}
void UBGraphicsScene::addAristo(QPointF center)
{
UBGraphicsAristo* aristo = new UBGraphicsAristo();
mTools << aristo;
aristo->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
addItem(aristo);
QPointF itemSceneCenter = aristo->sceneBoundingRect().center();
aristo->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y());
aristo->setVisible(true);
setModified(true);
}
void UBGraphicsScene::addCache()
{
UBGraphicsCache* cache = new UBGraphicsCache();
......
......@@ -220,6 +220,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void addCompass(QPointF center);
void addTriangle(QPointF center);
void addMagnifier(UBMagnifierParams params);
void addAristo(QPointF center);
void addMask(const QPointF &center = QPointF());
void addCache();
......
This diff is collapsed.
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGRAPHICSARISTO_H_
#define UBGRAPHICSARISTO_H_
#include <QtGui>
#include <QtSvg>
#include <QGraphicsPolygonItem>
#include "core/UB.h"
#include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class UBGraphicsScene;
class UBItem;
class UBGraphicsAristo : public UBAbstractDrawRuler, public QGraphicsPolygonItem, public UBItem
{
Q_OBJECT
public:
UBGraphicsAristo();
virtual ~UBGraphicsAristo();
enum { Type = UBGraphicsItemType::AristoItemType };
enum Tool {None, Move, Resize, Rotate, Close, MoveMarker, HorizontalFlip};
virtual int type() const
{
return Type;
}
virtual UBItem* deepCopy(void) const;
virtual void copyItemParameters(UBItem *copy) const;
virtual void StartLine(const QPointF& scenePos, qreal width);
virtual void DrawLine(const QPointF& position, qreal width);
virtual void EndLine();
enum UBGraphicsAristoOrientation
{
Bottom = 0,
Top
};
static UBGraphicsAristoOrientation orientationFromStr(QStringRef& str)
{
if (str == "Bottom") return Bottom;
if (str == "Top") return Top;
return sDefaultOrientation;
}
static QString orientationToStr(UBGraphicsAristoOrientation orientation)
{
QString result;
if (orientation == 0) result = "Bottom";
else if (orientation == 1) result = "Top";
return result;
}
void setRect(const QRectF &rect, UBGraphicsAristoOrientation orientation)
{
setRect(rect.x(), rect.y(), rect.width(), rect.height(), orientation);
}
void setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsAristoOrientation orientation);
void setOrientation(UBGraphicsAristoOrientation orientation);
UBGraphicsAristoOrientation getOrientation() const {return mOrientation;}
QRectF rect() const {return boundingRect();}
UBGraphicsScene* scene() const;
protected:
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget);
virtual QPainterPath shape() const;
virtual void rotateAroundCenter(qreal angle);
virtual void resize(qreal factor);
virtual QPointF rotationCenter() const;
virtual QRectF closeButtonRect() const;
QRectF resizeButtonRect () const;
QRectF hFlipRect() const;
QRectF rotateRect() const;
QRectF markerButtonRect() const;
QCursor flipCursor() const;
QCursor resizeCursor() const;
QCursor markerCursor() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private:
UBGraphicsAristo::Tool toolFromPos(QPointF pos);
QTransform calculateRotationTransform();
qreal angle;
void rotateAroundCenter(QTransform& transform, QPointF center);
bool mResizing;
bool mRotating;
bool mMarking;
QRect lastRect;
qreal mSpan;
// Coordinates are transformed....
QPoint lastPos;
QGraphicsSvgItem* mHFlipSvgItem;
QGraphicsSvgItem* mRotateSvgItem;
QGraphicsSvgItem* mResizeSvgItem;
QGraphicsSvgItem* mMarkerSvgItem;
qreal mStartAngle;
qreal mCurrentAngle;
static const QRect sDefaultRect;
static const UBGraphicsAristoOrientation sDefaultOrientation;
void paintGraduations(QPainter *painter);
void paintRulerGraduations(QPainter *painter);
void paintProtractorGraduations(QPainter* painter);
void paintMarker(QPainter *painter);
inline qreal radius () const
{
return sqrt(((B.x() - A.x())*(B.x() - A.x()))+((B.y() - A.y())*(B.y() - A.y()))) * 9 / 16 - 20;
}
UBGraphicsAristoOrientation mOrientation;
void calculatePoints(const QRectF& rect);
QPointF A, B, C;
static const int d = 70; // width of triangle border
static const int sArrowLength = 30;
static const int sMinWidth = 380;
static const int sMinHeight = 200;
static const int sArcAngleMargin = 5;
};
#endif /* UBGRAPHICSARISTO_H_ */
......@@ -91,6 +91,12 @@ UBToolsManager::UBToolsManager(QObject *parent)
mDescriptors << cache;
// --------------------------------------------------------------------------------
aristo.id = "uniboardTool://uniboard.mnemis.com/aristo";
aristo.icon = QPixmap(":/images/toolPalette/aristoTool.png");
aristo.label = tr("Aristo");
aristo.version = "1.0";
mToolsIcon.insert(aristo.id, ":/images/toolPalette/aristoTool.png");
mDescriptors << aristo;
}
UBToolsManager::~UBToolsManager()
......
......@@ -76,6 +76,7 @@ class UBToolsManager : public QObject
UBToolDescriptor triangle;
UBToolDescriptor magnifier;
UBToolDescriptor cache;
UBToolDescriptor aristo;
QString iconFromToolId(QString id) { return mToolsIcon.value(id);}
......
HEADERS += src/tools/UBGraphicsRuler.h \
src/tools/UBGraphicsTriangle.h \
HEADERS += src/tools/UBGraphicsRuler.h \
src/tools/UBGraphicsTriangle.h \
src/tools/UBGraphicsProtractor.h \
src/tools/UBGraphicsCompass.h \
src/tools/UBGraphicsAristo.h \
src/tools/UBToolsManager.h \
src/tools/UBGraphicsCurtainItem.h \
src/tools/UBGraphicsCurtainItemDelegate.h \
src/tools/UBAbstractDrawRuler.h \
src/tools/UBGraphicsCache.h
SOURCES += src/tools/UBGraphicsRuler.cpp \
src/tools/UBGraphicsTriangle.cpp \
src/tools/UBGraphicsCache.h
SOURCES += src/tools/UBGraphicsRuler.cpp \
src/tools/UBGraphicsTriangle.cpp \
src/tools/UBGraphicsProtractor.cpp \
src/tools/UBGraphicsCompass.cpp \
src/tools/UBGraphicsAristo.cpp \
src/tools/UBToolsManager.cpp \
src/tools/UBGraphicsCurtainItem.cpp \
src/tools/UBGraphicsCurtainItemDelegate.cpp \
src/tools/UBAbstractDrawRuler.cpp \
src/tools/UBGraphicsCache.cpp
src/tools/UBGraphicsCache.cpp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment