diff --git a/src/domain/UBAngleWidget.cpp b/src/domain/UBAngleWidget.cpp deleted file mode 100644 index 7be0bf39..00000000 --- a/src/domain/UBAngleWidget.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "UBAngleWidget.h" -#include - -#include "core/memcheck.h" - -UBAngleWidget::UBAngleWidget(QWidget *parent) - : QWidget(parent) -{ - this->setFixedSize(45,30); - this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - this->setAttribute(Qt::WA_TranslucentBackground); - - QImage mask_img(width(), height(), QImage::Format_Mono); - mask_img.fill(0xff); - QPainter mask_ptr(&mask_img); - mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); - mask_ptr.drawRoundedRect(0,0,this->geometry().width() - 6,this->geometry().height() - 6,1,1); - bmpMask = QBitmap::fromImage(mask_img); - this->setMask(bmpMask); -} - -UBAngleWidget::~UBAngleWidget() -{ - -} - -void UBAngleWidget::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - - this->move(this->cursor().pos().x(), this->cursor().pos().y() - 30); - - QPainter painter(this); - painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QBrush brush(Qt::white); - painter.setBrush(brush); - painter.drawRoundedRect(1,1,this->geometry().width() - 10,this->geometry().height() - 10,1,1); - - painter.setPen(QColor(85,50,127)); - painter.setFont(QFont("Arial", 10)); - painter.drawText(1,1,this->geometry().width() - 10,this->geometry().height() - 10, Qt::AlignCenter, text); -} - -void UBAngleWidget::setText(QString newText) -{ - text = newText; - text.append(QChar(176)); -} \ No newline at end of file diff --git a/src/domain/UBAngleWidget.h b/src/domain/UBAngleWidget.h deleted file mode 100644 index 20b09431..00000000 --- a/src/domain/UBAngleWidget.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef UBANGLEWIDGET_H -#define UBANGLEWIDGET_H - -#include -#include - -class UBAngleWidget : public QWidget -{ - Q_OBJECT - -public: - UBAngleWidget(QWidget *parent = 0); - ~UBAngleWidget(); - - void setText(QString); - -protected: - void paintEvent(QPaintEvent *event); - -private: - QString text; - QBitmap bmpMask; -}; - -#endif // UBANGLEWIDGET_H diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 031999b3..e2181020 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -21,6 +21,9 @@ #include "core/UBApplication.h" #include "core/UBSettings.h" +#include "board/UBBoardController.h" +#include "board/UBBoardView.h" + #include "domain/UBGraphicsItemDelegate.h" #include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsProxyWidget.h" @@ -90,14 +93,11 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega positionHandles(); this->setAcceptHoverEvents(true); - - angleWidget = new UBAngleWidget(); } UBGraphicsDelegateFrame::~UBGraphicsDelegateFrame() { -delete angleWidget; // NOOP } @@ -226,10 +226,46 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) mInitialTransform = buildTransform(); mCurrentTool = toolFromPos(event->pos()); - + setCursorFromAngle(QString("")); event->accept(); } +void UBGraphicsDelegateFrame::setCursorFromAngle(QString angle) +{ + if (mCurrentTool == Rotate) + { + QWidget *controlViewport = UBApplication::boardController->controlView()->viewport(); + + QSize cursorSize(45,30); + + + QImage mask_img(cursorSize, QImage::Format_Mono); + mask_img.fill(0xff); + QPainter mask_ptr(&mask_img); + mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); + mask_ptr.drawRoundedRect(0,0, cursorSize.width()-1, cursorSize.height()-1, 6, 6); + QBitmap bmpMask = QBitmap::fromImage(mask_img); + + + QPixmap pixCursor(cursorSize); + pixCursor.fill(QColor(Qt::white)); + + QPainter painter(&pixCursor); + + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + painter.setBrush(QBrush(Qt::white)); + painter.setPen(QPen(QColor(Qt::black))); + painter.drawRoundedRect(1,1,cursorSize.width()-2,cursorSize.height()-2,6,6); + painter.setFont(QFont("Arial", 10)); + painter.drawText(1,1,cursorSize.width(),cursorSize.height(), Qt::AlignCenter, angle.append(QChar(176))); + painter.end(); + + pixCursor.setMask(bmpMask); + controlViewport->setCursor(pixCursor); + } +} + + bool UBGraphicsDelegateFrame::canResizeBottomRight(qreal width, qreal height, qreal scaleFactor) { bool res = false; @@ -427,12 +463,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } - if (!angleWidget->isVisible()) - angleWidget->show(); - - angleWidget->setText(QString::number((int)mAngle % 360)); - angleWidget->update(); - + setCursorFromAngle(QString::number((int)mAngle % 360)); } else if (moving()) { @@ -525,9 +556,6 @@ QTransform UBGraphicsDelegateFrame::buildTransform() void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (angleWidget->isVisible()) - angleWidget->hide(); - updateResizeCursors(); mDelegate->commitUndoStep(); diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 8ffac3e7..b08ae219 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -18,7 +18,6 @@ #include #include "core/UB.h" -#include "domain/UBAngleWidget.h" class QGraphicsSceneMouseEvent; class UBGraphicsItemDelegate; @@ -65,6 +64,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject inline bool resizingTop () const { return mCurrentTool == ResizeTop; } inline bool rotating () const { return mCurrentTool == Rotate; } inline bool moving () const { return mCurrentTool == Move; } + void setCursorFromAngle(QString angle); bool canResizeBottomRight(qreal width, qreal height, qreal scaleFactor); QTransform buildTransform (); @@ -120,8 +120,5 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject bool mResizing; bool mMirroredXAtStart; bool mMirroredYAtStart; - - UBAngleWidget *angleWidget; - }; #endif /* UBGRAPHICSDELEGATEFRAME_H_ */ diff --git a/src/domain/domain.pri b/src/domain/domain.pri index fb6cd717..d66c72ec 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -18,7 +18,6 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsStroke.h \ src/domain/UBGraphicsMediaItem.h \ src/domain/UBAbstractUndoCommand.h\ - src/domain/UBAngleWidget.h \ src/domain/UBGraphicsGroupContainerItem.h \ src/domain/UBGraphicsGroupContainerItemDelegate.h \ src/domain/UBGraphicsStrokesGroup.h @@ -50,7 +49,6 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsStroke.cpp \ src/domain/UBGraphicsMediaItem.cpp \ src/domain/UBAbstractUndoCommand.cpp \ - src/domain/UBAngleWidget.cpp \ src/domain/ubgraphicsgroupcontaineritem.cpp \ src/domain/ubgraphicsgroupcontaineritemdelegate.cpp \ src/domain/UBGraphicsStrokesGroup.cpp