From 26ae8fb2d6cf16bde7c6b7f594c6c9205e3f968a Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Wed, 18 Apr 2012 12:29:14 +0300 Subject: [PATCH] System dependant rubberband created --- src/board/UBBoardView.cpp | 22 ++++++++++++++++++++-- src/board/UBBoardView.h | 3 +++ src/gui/UBRubberBand.cpp | 5 +++++ src/gui/UBRubberBand.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 1e493cc2..9bddf89e 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -117,6 +117,7 @@ UBBoardView::init () mUsingTabletEraser = false; mIsCreatingTextZone = false; mRubberBand = 0; + mUBRubberBand = 0; mVirtualKeyboardActive = false; @@ -414,10 +415,19 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) } else if (currentTool == UBStylusTool::Selector) { - QSet existingTools = scene()->tools(); +// QSet existingTools = scene()->tools(); why do we need to get tools here? movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint())); + if (!movingItem) { + // Rubberband selection implementation + if (!mUBRubberBand) { + mUBRubberBand = new UBRubberBand(QRubberBand::Rectangle, this); + } + mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); + mUBRubberBand->show(); + } + if (!movingItem || movingItem->isSelected() || movingItem->type() == UBGraphicsDelegateFrame::Type @@ -443,6 +453,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); // удалить } + event->accept(); } else if (currentTool == UBStylusTool::Text) @@ -470,7 +481,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) if (!mRubberBand) mRubberBand = new UBRubberBand (QRubberBand::Rectangle, this); - mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); mRubberBand->show (); mIsCreatingTextZone = true; @@ -533,6 +543,10 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) return; } + if (mUBRubberBand && mUBRubberBand->isVisible()) { + mUBRubberBand->setGeometry(QRect(mMouseDownPos, event->pos()).normalized()); + } + if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed)) { QPointF scenePos = mapToScene(event->pos()); @@ -598,6 +612,10 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) suspendedMousePressEvent = NULL; } + if (mUBRubberBand && mUBRubberBand->isVisible()) { + mUBRubberBand->hide(); + } + QGraphicsView::mouseReleaseEvent (event); } else if (currentTool == UBStylusTool::Text) diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 1d54ed36..a0d0e838 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -24,6 +24,7 @@ class UBBoardController; class UBAppleWidget; class UBGraphicsScene; class UBGraphicsWidgetItem; +class UBRubberBand; class UBBoardView : public QGraphicsView { @@ -123,6 +124,8 @@ class UBBoardView : public QGraphicsView QGraphicsItem *movingItem; QMouseEvent *suspendedMousePressEvent; + UBRubberBand *mUBRubberBand; + private slots: void settingChanged(QVariant newValue); diff --git a/src/gui/UBRubberBand.cpp b/src/gui/UBRubberBand.cpp index 3d33fe18..6417104e 100644 --- a/src/gui/UBRubberBand.cpp +++ b/src/gui/UBRubberBand.cpp @@ -16,6 +16,8 @@ #include "UBRubberBand.h" #include +#include +#include #ifdef Q_WS_MAC #include @@ -32,10 +34,13 @@ UBRubberBand::UBRubberBand(Shape s, QWidget * p) customStyle = new QWindowsXPStyle(); #elif defined(Q_WS_MAC) customStyle = new QMacStyle(); +#elif defined(Q_WS_X11) + customStyle = QStyleFactory::create("oxygen"); #endif if (customStyle) QRubberBand::setStyle(customStyle); + } UBRubberBand::~UBRubberBand() diff --git a/src/gui/UBRubberBand.h b/src/gui/UBRubberBand.h index 5b251c15..e95e10bb 100644 --- a/src/gui/UBRubberBand.h +++ b/src/gui/UBRubberBand.h @@ -25,6 +25,7 @@ class UBRubberBand : public QRubberBand public: UBRubberBand(Shape s, QWidget * p = 0); virtual ~UBRubberBand(); + private: QStyle* customStyle; };