RubberBand is moveble and resizable by PlayTool.

Items can be moved by RubberBand.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent 6b85418aa4
commit de18bf794e
  1. 56
      src/board/UBBoardView.cpp
  2. 6
      src/board/UBBoardView.h
  3. 199
      src/gui/UBRubberBand.cpp
  4. 24
      src/gui/UBRubberBand.h

@ -613,6 +613,37 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event)
}
}
void UBBoardView::rubberItems()
{
if (mUBRubberBand)
mRubberedItems = items(mUBRubberBand->geometry());
}
void UBBoardView::moveRubberedItems(QPointF movingVector)
{
// QRect bandRect = mUBRubberBand->geometry();
//
QRectF invalidateRect = scene()->itemsBoundingRect();
// QList<QGraphicsItem *> rubberItems = items(bandRect);
foreach (QGraphicsItem *item, mRubberedItems)
{
if (item->type() == UBGraphicsW3CWidgetItem::Type
|| item->type() == UBGraphicsPixmapItem::Type
|| item->type() == UBGraphicsMediaItem::Type
|| item->type() == UBGraphicsSvgItem::Type
|| item->type() == UBGraphicsTextItem::Type
|| item->type() == UBGraphicsStrokesGroup::Type
|| item->type() == UBGraphicsGroupContainerItem::Type)
{
item->setPos(item->pos()+movingVector);
}
}
scene()->invalidate(invalidateRect);
}
void UBBoardView::mousePressEvent (QMouseEvent *event)
{
if (isAbsurdPoint (event->pos ()))
@ -649,7 +680,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
mPreviousPoint = event->posF ();
event->accept ();
}
else if (currentTool == UBStylusTool::Selector)
else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
{
movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
@ -662,14 +693,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
mUBRubberBand->show();
}
handleItemMousePress(event);
event->accept();
}
else if (currentTool == UBStylusTool::Play)
{
movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
handleItemMousePress(event);
event->accept();
}
@ -754,14 +777,16 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
mPreviousPoint = eventPosition;
event->accept ();
}
else if (currentTool == UBStylusTool::Selector)
else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
{
if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) {
return;
}
if (mUBRubberBand && mUBRubberBand->isVisible()) {
if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) {
QRect bandRect(mMouseDownPos, event->pos());
bandRect = bandRect.normalized();
mUBRubberBand->setGeometry(bandRect);
@ -773,6 +798,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
mJustSelectedItems.remove(item);
}
}
if (currentTool == UBStylusTool::Selector)
foreach (QGraphicsItem *item, items(bandRect)) {
if (item->type() == UBGraphicsW3CWidgetItem::Type
@ -793,10 +820,6 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
handleItemMouseMove(event);
}
else if (currentTool == UBStylusTool::Play)
{
handleItemMouseMove(event);
}
else if ((UBDrawingController::drawingController()->isDrawingTool())
&& !mMouseButtonIsPressed)
{
@ -859,7 +882,8 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
if (mUBRubberBand && mUBRubberBand->isVisible()) {
mUBRubberBand->hide();
}
QGraphicsView::mouseReleaseEvent (event);
QGraphicsView::mouseReleaseEvent (event);
}
else if (currentTool == UBStylusTool::Play)
{

@ -42,6 +42,9 @@ class UBBoardView : public QGraphicsView
void setToolCursor(int tool);
void rubberItems();
void moveRubberedItems(QPointF movingVector);
signals:
void resized(QResizeEvent* event);
@ -133,7 +136,10 @@ class UBBoardView : public QGraphicsView
QGraphicsItem *movingItem;
QMouseEvent *suspendedMousePressEvent;
bool moveRubberBand;
UBRubberBand *mUBRubberBand;
QList<QGraphicsItem *> mRubberedItems;
QSet<QGraphicsItem*> mJustSelectedItems;
private slots:

@ -23,10 +23,18 @@
#include <QtGui/QMacStyle>
#endif
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBBoardView.h"
#include "core/memcheck.h"
UBRubberBand::UBRubberBand(Shape s, QWidget * p)
: QRubberBand(s, p)
, mResizingMode(None)
, mMouseIsPressed(false)
, mLastPressedPoint(QPoint())
, mResizingBorderHeight(20)
{
customStyle = NULL;
@ -41,6 +49,8 @@ UBRubberBand::UBRubberBand(Shape s, QWidget * p)
if (customStyle)
QRubberBand::setStyle(customStyle);
setAttribute(Qt::WA_TransparentForMouseEvents, false);
setMouseTracking(true);
}
UBRubberBand::~UBRubberBand()
@ -48,3 +58,192 @@ UBRubberBand::~UBRubberBand()
if (customStyle)
delete customStyle;
}
UBRubberBand::enm_resizingMode UBRubberBand::determineResizingMode(QPoint pos)
{
if (mMouseIsPressed)
return mResizingMode;
QRect resizerTop (mResizingBorderHeight , 0 , rect().width()-2*mResizingBorderHeight, mResizingBorderHeight );
QRect resizerBottom (mResizingBorderHeight , rect().height() - mResizingBorderHeight, rect().width()-2*mResizingBorderHeight, mResizingBorderHeight );
QRect resizerLeft (0 , mResizingBorderHeight , mResizingBorderHeight , rect().height() - 2*mResizingBorderHeight);
QRect resizerRight (rect().width()-mResizingBorderHeight, mResizingBorderHeight , mResizingBorderHeight , rect().height() - 2*mResizingBorderHeight);
QRect resizerTopLeft (0 , 0 , mResizingBorderHeight, mResizingBorderHeight);
QRect resizerTopRight (rect().width()-mResizingBorderHeight, 0 , mResizingBorderHeight, mResizingBorderHeight);
QRect resizerBottomLeft (0 , rect().height() - mResizingBorderHeight, mResizingBorderHeight, mResizingBorderHeight);
QRect resizerBottomRight(rect().width()-mResizingBorderHeight, rect().height() - mResizingBorderHeight, mResizingBorderHeight, mResizingBorderHeight);
enm_resizingMode resizingMode;
QTransform cursorTransrofm;
if (resizerTop.contains(pos))
{
resizingMode = Top;
cursorTransrofm.rotate(90);
}
else
if (resizerBottom.contains(pos))
{
resizingMode = Bottom;
cursorTransrofm.rotate(90);
}
else
if (resizerLeft.contains(pos))
{
resizingMode = Left;
}
else
if (resizerRight.contains(pos))
{
resizingMode = Right;
}
else
if (resizerTopLeft.contains(pos))
{
resizingMode = TopLeft;
cursorTransrofm.rotate(45);
}
else
if (resizerTopRight.contains(pos))
{
resizingMode = TopRight;
cursorTransrofm.rotate(-45);
}
else
if (resizerBottomLeft.contains(pos))
{
resizingMode = BottomLeft;
cursorTransrofm.rotate(-45);
}
else
if (resizerBottomRight.contains(pos))
{
resizingMode = BottomRight;
cursorTransrofm.rotate(45);
}
else
resizingMode = None;
if (None != resizingMode)
{
QPixmap pix(":/images/cursors/resize.png");
QCursor resizeCursor = QCursor(pix.transformed(cursorTransrofm, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
setCursor(resizeCursor);
}
else
unsetCursor();
return resizingMode;
}
void UBRubberBand::mousePressEvent(QMouseEvent *event)
{
mResizingMode = determineResizingMode(event->pos());
mMouseIsPressed = true;
mLastPressedPoint = event->pos();
mLastMousePos = event->pos();
if (None == mResizingMode)
{
UBApplication::boardController->controlView()->rubberItems();
setCursor(QCursor(Qt::SizeAllCursor));
}
}
void UBRubberBand::mouseMoveEvent(QMouseEvent *event)
{
determineResizingMode(event->pos());
if (mMouseIsPressed)
{
UBBoardView *view = UBApplication::boardController->controlView();
QRect currentGeometry = geometry();
QPoint pressPoint(event->pos());
QPoint pressPointGlobal(view->mapToGlobal(pressPoint));
QPoint prevPressPointGlobal(view->mapToGlobal(mLastPressedPoint));
QPoint movePointGlogal = (view->mapToGlobal(mLastMousePos));
QPoint topLeftResizeVector(pressPointGlobal - prevPressPointGlobal);
QPoint rightBottomResizeVector(pressPointGlobal - movePointGlogal);
bool bGeometryChange = true;
switch(mResizingMode)
{
case None:
{
QPointF itemsMoveVector(view->mapToScene(pressPointGlobal) - view->mapToScene(prevPressPointGlobal));
move(pos()+pressPointGlobal - prevPressPointGlobal);
view->moveRubberedItems(itemsMoveVector);
bGeometryChange = false;
break;
}
case Top:
{
currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y());
}break;
case Bottom:
{
currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y());
}break;
case Left:
{
currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x());
}break;
case Right:
{
currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x());
}break;
case TopLeft:
{
currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x());
currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y());
}break;
case TopRight:
{
currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y());
currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x());
}
break;
case BottomLeft:
{
currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x());
currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y());
}break;
case BottomRight:
{
currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x());
currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y());
}break;
}
if(bGeometryChange)
{
setGeometry(currentGeometry);
}
mLastMousePos = event->pos();
}
QRubberBand::mouseMoveEvent(event);
}
void UBRubberBand::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
mMouseIsPressed = false;
unsetCursor();
}

@ -26,8 +26,32 @@ class UBRubberBand : public QRubberBand
UBRubberBand(Shape s, QWidget * p = 0);
virtual ~UBRubberBand();
private:
enum enm_resizingMode
{
None,
Top,
TopLeft,
TopRight,
Bottom,
BottomLeft,
BottomRight,
Left,
Right
};
enm_resizingMode determineResizingMode(QPoint pos);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
private:
QStyle* customStyle;
enm_resizingMode mResizingMode;
int mResizingBorderHeight;
bool mMouseIsPressed;
QPoint mLastPressedPoint;
QPoint mLastMousePos;
};
#endif /* UBRUBBERBAND_H_ */

Loading…
Cancel
Save