Reworked painting of rotation angle for UBGraphicsDelegateFrame. Now angle showed as mouse cursor.

preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent 0707f90aed
commit 41d8e4e459
  1. 48
      src/domain/UBAngleWidget.cpp
  2. 25
      src/domain/UBAngleWidget.h
  3. 54
      src/domain/UBGraphicsDelegateFrame.cpp
  4. 5
      src/domain/UBGraphicsDelegateFrame.h
  5. 2
      src/domain/domain.pri

@ -1,48 +0,0 @@
#include "UBAngleWidget.h"
#include <QPainter>
#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));
}

@ -1,25 +0,0 @@
#ifndef UBANGLEWIDGET_H
#define UBANGLEWIDGET_H
#include <QWidget>
#include <QBitmap>
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

@ -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();

@ -18,7 +18,6 @@
#include <QtGui>
#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_ */

@ -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

Loading…
Cancel
Save