Commit ff90ddf3 authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

SANKORE-78

parent bff3e834
/* /*
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBBoardView.h" #include "UBBoardView.h"
#include <QtGui> #include <QtGui>
#include <QtXml> #include <QtXml>
#include "UBDrawingController.h" #include "UBDrawingController.h"
#include "frameworks/UBGeometryUtils.h" #include "frameworks/UBGeometryUtils.h"
#include "frameworks/UBPlatformUtils.h" #include "frameworks/UBPlatformUtils.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBMimeData.h" #include "core/UBMimeData.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBSetting.h" #include "core/UBSetting.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "network/UBHttpGet.h" #include "network/UBHttpGet.h"
#include "gui/UBStylusPalette.h" #include "gui/UBStylusPalette.h"
#include "gui/UBRubberBand.h" #include "gui/UBRubberBand.h"
#include "gui/UBToolWidget.h" #include "gui/UBToolWidget.h"
#include "gui/UBResources.h" #include "gui/UBResources.h"
#include "gui/UBMainWindow.h" #include "gui/UBMainWindow.h"
#include "gui/UBMediaPlayer.h" #include "gui/UBMediaPlayer.h"
#include "gui/UBThumbnailWidget.h" #include "gui/UBThumbnailWidget.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsPixmapItem.h" #include "domain/UBGraphicsPixmapItem.h"
#include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "customWidgets/UBDraggableLabel.h" #include "customWidgets/UBDraggableLabel.h"
#include "customWidgets/UBDraggableMedia.h" #include "customWidgets/UBDraggableMedia.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent)
: QGraphicsView (pParent) : QGraphicsView (pParent)
, mController (pController) , mController (pController)
, mIsCreatingTextZone (false) , mIsCreatingTextZone (false)
, mIsCreatingSceneGrabZone (false) , mIsCreatingSceneGrabZone (false)
, mOkOnWidget(false) , mOkOnWidget(false)
{ , suspendedMousePressEvent(NULL)
init (); {
init ();
mFilterZIndex = false;
} mFilterZIndex = false;
}
UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent)
: QGraphicsView (pParent) UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent)
, mController (pController) : QGraphicsView (pParent)
{ , mController (pController)
init (); , suspendedMousePressEvent(NULL)
{
mStartLayer = pStartLayer; init ();
mEndLayer = pEndLayer;
mStartLayer = pStartLayer;
mFilterZIndex = true; mEndLayer = pEndLayer;
}
mFilterZIndex = true;
UBBoardView::~UBBoardView () { }
//NOOP
} UBBoardView::~UBBoardView () {
//NOOP
void if (suspendedMousePressEvent)
UBBoardView::init () delete suspendedMousePressEvent;
{ }
connect (UBSettings::settings ()->boardPenPressureSensitive, SIGNAL (changed (QVariant)),
this, SLOT (settingChanged (QVariant))); void
UBBoardView::init ()
connect (UBSettings::settings ()->boardMarkerPressureSensitive, SIGNAL (changed (QVariant)), {
this, SLOT (settingChanged (QVariant))); connect (UBSettings::settings ()->boardPenPressureSensitive, SIGNAL (changed (QVariant)),
this, SLOT (settingChanged (QVariant)));
connect (UBSettings::settings ()->boardUseHighResTabletEvent, SIGNAL (changed (QVariant)),
this, SLOT (settingChanged (QVariant))); connect (UBSettings::settings ()->boardMarkerPressureSensitive, SIGNAL (changed (QVariant)),
this, SLOT (settingChanged (QVariant)));
setWindowFlags (Qt::FramelessWindowHint);
setFrameStyle (QFrame::NoFrame); connect (UBSettings::settings ()->boardUseHighResTabletEvent, SIGNAL (changed (QVariant)),
setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); this, SLOT (settingChanged (QVariant)));
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); setWindowFlags (Qt::FramelessWindowHint);
setAcceptDrops (true); setFrameStyle (QFrame::NoFrame);
setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
setOptimizationFlag (QGraphicsView::IndirectPainting); // enable UBBoardView::drawItems filter setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
mTabletStylusIsPressed = false; setAcceptDrops (true);
mMouseButtonIsPressed = false;
mPendingStylusReleaseEvent = false; setOptimizationFlag (QGraphicsView::IndirectPainting); // enable UBBoardView::drawItems filter
setCacheMode (QGraphicsView::CacheBackground); mTabletStylusIsPressed = false;
mMouseButtonIsPressed = false;
mUsingTabletEraser = false; mPendingStylusReleaseEvent = false;
mIsCreatingTextZone = false;
mRubberBand = 0; setCacheMode (QGraphicsView::CacheBackground);
mVirtualKeyboardActive = false; mUsingTabletEraser = false;
mIsCreatingTextZone = false;
settingChanged (QVariant ()); mRubberBand = 0;
unsetCursor(); mVirtualKeyboardActive = false;
}
settingChanged (QVariant ());
UBGraphicsScene*
UBBoardView::scene () unsetCursor();
{
return qobject_cast<UBGraphicsScene*> (QGraphicsView::scene ()); movingItem = NULL;
} mWidgetMoved = false;
}
void
UBBoardView::hideEvent (QHideEvent * event) UBGraphicsScene*
{ UBBoardView::scene ()
Q_UNUSED (event); {
emit hidden (); return qobject_cast<UBGraphicsScene*> (QGraphicsView::scene ());
} }
void void
UBBoardView::showEvent (QShowEvent * event) UBBoardView::hideEvent (QHideEvent * event)
{ {
Q_UNUSED (event); Q_UNUSED (event);
emit shown (); emit hidden ();
} }
void void
UBBoardView::keyPressEvent (QKeyEvent *event) UBBoardView::showEvent (QShowEvent * event)
{ {
// send to the scene anyway Q_UNUSED (event);
QApplication::sendEvent (scene (), event); emit shown ();
}
if (!event->isAccepted ())
{ void
switch (event->key ()) UBBoardView::keyPressEvent (QKeyEvent *event)
{ {
case Qt::Key_Up: // send to the scene anyway
case Qt::Key_PageUp: QApplication::sendEvent (scene (), event);
case Qt::Key_Left:
{ if (!event->isAccepted ())
mController->previousScene (); {
break; switch (event->key ())
} {
case Qt::Key_Up:
case Qt::Key_Down: case Qt::Key_PageUp:
case Qt::Key_PageDown: case Qt::Key_Left:
case Qt::Key_Right: {
case Qt::Key_Space: mController->previousScene ();
{ break;
mController->nextScene (); }
break;
} case Qt::Key_Down:
case Qt::Key_PageDown:
case Qt::Key_Home: case Qt::Key_Right:
{ case Qt::Key_Space:
mController->firstScene (); {
break; mController->nextScene ();
} break;
case Qt::Key_End: }
{
mController->lastScene (); case Qt::Key_Home:
break; {
} mController->firstScene ();
case Qt::Key_Insert: break;
{ }
mController->addScene (); case Qt::Key_End:
break; {
} mController->lastScene ();
} break;
}
case Qt::Key_Insert:
if (event->modifiers () & Qt::ControlModifier) // keep only ctrl/cmd keys {
{ mController->addScene ();
switch (event->key ()) break;
{ }
case Qt::Key_Plus: }
case Qt::Key_I:
{
mController->zoomIn (); if (event->modifiers () & Qt::ControlModifier) // keep only ctrl/cmd keys
event->accept (); {
break; switch (event->key ())
} {
case Qt::Key_Minus: case Qt::Key_Plus:
case Qt::Key_O: case Qt::Key_I:
{ {
mController->zoomOut (); mController->zoomIn ();
event->accept (); event->accept ();
break; break;
} }
case Qt::Key_0: case Qt::Key_Minus:
{ case Qt::Key_O:
mController->zoomRestore (); {
event->accept (); mController->zoomOut ();
break; event->accept ();
} break;
case Qt::Key_Left: }
{ case Qt::Key_0:
mController->handScroll (-100, 0); {
event->accept (); mController->zoomRestore ();
break; event->accept ();
} break;
case Qt::Key_Right: }
{ case Qt::Key_Left:
mController->handScroll (100, 0); {
event->accept (); mController->handScroll (-100, 0);
break; event->accept ();
} break;
case Qt::Key_Up: }
{ case Qt::Key_Right:
mController->handScroll (0, -100); {
event->accept (); mController->handScroll (100, 0);
break; event->accept ();
} break;
case Qt::Key_Down: }
{ case Qt::Key_Up:
mController->handScroll (0, 100); {
event->accept (); mController->handScroll (0, -100);
break; event->accept ();
} break;
default: }
{ case Qt::Key_Down:
// NOOP {
} mController->handScroll (0, 100);
} event->accept ();
} break;
} }
} default:
{
bool // NOOP
UBBoardView::event (QEvent * e) }
{ }
if (e->type () == QEvent::Gesture) }
{ }
QGestureEvent *gestureEvent = dynamic_cast<QGestureEvent *> (e); }
if (gestureEvent)
{ bool
QSwipeGesture* swipe = dynamic_cast<QSwipeGesture*> (gestureEvent->gesture (Qt::SwipeGesture)); UBBoardView::event (QEvent * e)
{
if (swipe) if (e->type () == QEvent::Gesture)
{ {
if (swipe->horizontalDirection () == QSwipeGesture::Left) QGestureEvent *gestureEvent = dynamic_cast<QGestureEvent *> (e);
{ if (gestureEvent)
mController->previousScene (); {
gestureEvent->setAccepted (swipe, true); QSwipeGesture* swipe = dynamic_cast<QSwipeGesture*> (gestureEvent->gesture (Qt::SwipeGesture));
}
if (swipe)
if (swipe->horizontalDirection () == QSwipeGesture::Right) {
{ if (swipe->horizontalDirection () == QSwipeGesture::Left)
mController->nextScene (); {
gestureEvent->setAccepted (swipe, true); mController->previousScene ();
} gestureEvent->setAccepted (swipe, true);
} }
}
} if (swipe->horizontalDirection () == QSwipeGesture::Right)
{
return QGraphicsView::event (e); mController->nextScene ();
} gestureEvent->setAccepted (swipe, true);
}
void UBBoardView::tabletEvent (QTabletEvent * event) }
{ }
if (!mUseHighResTabletEvent) { }
event->setAccepted (false);
return; return QGraphicsView::event (e);
} }
qDebug() << "tableEvent position " << event->pos(); void UBBoardView::tabletEvent (QTabletEvent * event)
qDebug() << "tableEvent global position " << event->globalPos(); {
if (!mUseHighResTabletEvent) {
event->setAccepted (false);
UBDrawingController *dc = UBDrawingController::drawingController (); return;
}
QPointF tabletPos = event->pos();
qDebug() << "tableEvent position " << event->pos();
qDebug() << "tabletPos " << tabletPos; qDebug() << "tableEvent global position " << event->globalPos();
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool (); UBDrawingController *dc = UBDrawingController::drawingController ();
if (event->type () == QEvent::TabletPress || event->type () == QEvent::TabletEnterProximity) { QPointF tabletPos = event->pos();
if (event->pointerType () == QTabletEvent::Eraser) {
dc->setStylusTool (UBStylusTool::Eraser); qDebug() << "tabletPos " << tabletPos;
mUsingTabletEraser = true;
}
else { UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool ();
if (mUsingTabletEraser && currentTool == UBStylusTool::Eraser)
dc->setStylusTool (dc->latestDrawingTool ()); if (event->type () == QEvent::TabletPress || event->type () == QEvent::TabletEnterProximity) {
if (event->pointerType () == QTabletEvent::Eraser) {
mUsingTabletEraser = false; dc->setStylusTool (UBStylusTool::Eraser);
} mUsingTabletEraser = true;
} }
else {
// if event are not Pen events, we drop the tablet stuff and route everything through mouse event if (mUsingTabletEraser && currentTool == UBStylusTool::Eraser)
if (currentTool != UBStylusTool::Pen && currentTool != UBStylusTool::Line && currentTool != UBStylusTool::Marker && !mMarkerPressureSensitive){ dc->setStylusTool (dc->latestDrawingTool ());
event->setAccepted (false);
return; mUsingTabletEraser = false;
} }
}
QPointF scenePos = viewportTransform ().inverted ().map (tabletPos);
qDebug() << "scene Pos " << scenePos; // if event are not Pen events, we drop the tablet stuff and route everything through mouse event
if (currentTool != UBStylusTool::Pen && currentTool != UBStylusTool::Line && currentTool != UBStylusTool::Marker && !mMarkerPressureSensitive){
qreal pressure = 1.0; event->setAccepted (false);
if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line) return;
&& mPenPressureSensitive) }
|| (currentTool == UBStylusTool::Marker && mMarkerPressureSensitive))
pressure = event->pressure (); QPointF scenePos = viewportTransform ().inverted ().map (tabletPos);
qDebug() << "scene Pos " << scenePos;
bool acceptEvent = true; qreal pressure = 1.0;
if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line)
switch (event->type ()) { && mPenPressureSensitive)
case QEvent::TabletPress: { || (currentTool == UBStylusTool::Marker && mMarkerPressureSensitive))
qDebug() << "TabletPress"; pressure = event->pressure ();
mTabletStylusIsPressed = true;
scene()->inputDevicePress (scenePos, pressure); bool acceptEvent = true;
break; switch (event->type ()) {
} case QEvent::TabletPress: {
case QEvent::TabletMove: { qDebug() << "TabletPress";
qDebug() << "TabletMove";
mTabletStylusIsPressed = true;
if (mTabletStylusIsPressed) scene()->inputDevicePress (scenePos, pressure);
scene ()->inputDeviceMove (scenePos, pressure);
break;
acceptEvent = false; // rerouted to mouse move }
case QEvent::TabletMove: {
break; qDebug() << "TabletMove";
} if (mTabletStylusIsPressed)
case QEvent::TabletRelease: { scene ()->inputDeviceMove (scenePos, pressure);
qDebug() << "TabletRelease";
acceptEvent = false; // rerouted to mouse move
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool ();
scene ()->setToolCursor (currentTool); break;
setToolCursor (currentTool);
}
scene ()->inputDeviceRelease (); case QEvent::TabletRelease: {
qDebug() << "TabletRelease";
mPendingStylusReleaseEvent = false;
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool ();
mTabletStylusIsPressed = false; scene ()->setToolCursor (currentTool);
mMouseButtonIsPressed = false; setToolCursor (currentTool);
break; scene ()->inputDeviceRelease ();
}
default: { mPendingStylusReleaseEvent = false;
//NOOP - avoid compiler warning
} mTabletStylusIsPressed = false;
} mMouseButtonIsPressed = false;
// ignore mouse press and mouse move tablet event so that it is rerouted to mouse events, break;
// documented in QTabletEvent Class Reference: }
/* The event handler QWidget::tabletEvent() receives all three types of tablet events. default: {
Qt will first send a tabletEvent then, if it is not accepted, it will send a mouse event. */ //NOOP - avoid compiler warning
// }
// This is a workaround to the fact that tablet event are not delivered to child widget (like palettes) }
//
// ignore mouse press and mouse move tablet event so that it is rerouted to mouse events,
event->setAccepted (acceptEvent); // documented in QTabletEvent Class Reference:
/* The event handler QWidget::tabletEvent() receives all three types of tablet events.
} Qt will first send a tabletEvent then, if it is not accepted, it will send a mouse event. */
//
void // This is a workaround to the fact that tablet event are not delivered to child widget (like palettes)
UBBoardView::mousePressEvent (QMouseEvent *event) //
{
if (isAbsurdPoint (event->pos ())) event->setAccepted (acceptEvent);
{
event->accept (); }
return;
} void
UBBoardView::mousePressEvent (QMouseEvent *event)
mMouseDownPos = event->pos (); {
if (isAbsurdPoint (event->pos ()))
if (event->button () == Qt::LeftButton && isInteractive ()) {
{ event->accept ();
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); return;
}
if (!mTabletStylusIsPressed)
mMouseButtonIsPressed = true; mMouseDownPos = event->pos ();
if (currentTool == UBStylusTool::ZoomIn) if (event->button () == Qt::LeftButton && isInteractive ())
{ {
mController->zoomIn (mapToScene (event->pos ())); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
event->accept ();
} if (!mTabletStylusIsPressed)
else if (currentTool == UBStylusTool::ZoomOut) mMouseButtonIsPressed = true;
{
mController->zoomOut (mapToScene (event->pos ())); if (currentTool == UBStylusTool::ZoomIn)
event->accept (); {
} mController->zoomIn (mapToScene (event->pos ()));
else if (currentTool == UBStylusTool::Hand) event->accept ();
{ }
viewport ()->setCursor (QCursor (Qt::ClosedHandCursor)); else if (currentTool == UBStylusTool::ZoomOut)
mPreviousPoint = event->posF (); {
event->accept (); mController->zoomOut (mapToScene (event->pos ()));
} event->accept ();
else if (currentTool == UBStylusTool::Selector) }
{ else if (currentTool == UBStylusTool::Hand)
QGraphicsView::mousePressEvent (event); {
} viewport ()->setCursor (QCursor (Qt::ClosedHandCursor));
else if (currentTool == UBStylusTool::Text) mPreviousPoint = event->posF ();
{ event->accept ();
int frameWidth = UBSettings::settings ()->objectFrameWidth; }
QRectF fuzzyRect (0, 0, frameWidth * 4, frameWidth * 4); else if (currentTool == UBStylusTool::Selector)
fuzzyRect.moveCenter (mapToScene (mMouseDownPos)); {
movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
UBGraphicsTextItem* foundTextItem = 0;
QListIterator<QGraphicsItem *> it (scene ()->items (fuzzyRect)); if (!movingItem ||
movingItem->isSelected() ||
while (it.hasNext () && !foundTextItem) (movingItem->type() == UBGraphicsDelegateFrame::Type ||
{ movingItem->type() == DelegateButton::Type))
foundTextItem = qgraphicsitem_cast<UBGraphicsTextItem*>(it.next ()); {
} movingItem = NULL;
QGraphicsView::mousePressEvent (event);
if (foundTextItem)
{ }
mIsCreatingTextZone = false; else
QGraphicsView::mousePressEvent (event); {
} mLastPressedMousePos = mapToScene(event->pos());
else if (suspendedMousePressEvent)
{ {
scene ()->deselectAllItems (); delete suspendedMousePressEvent;
}
if (!mRubberBand) suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); //
mRubberBand = new UBRubberBand (QRubberBand::Rectangle, this); }
mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); event->accept();
mRubberBand->show (); }
mIsCreatingTextZone = true; else if (currentTool == UBStylusTool::Text)
{
event->accept (); int frameWidth = UBSettings::settings ()->objectFrameWidth;
} QRectF fuzzyRect (0, 0, frameWidth * 4, frameWidth * 4);
} fuzzyRect.moveCenter (mapToScene (mMouseDownPos));
else if (currentTool == UBStylusTool::Capture)
{ UBGraphicsTextItem* foundTextItem = 0;
scene ()->deselectAllItems (); QListIterator<QGraphicsItem *> it (scene ()->items (fuzzyRect));
if (!mRubberBand) while (it.hasNext () && !foundTextItem)
mRubberBand = new UBRubberBand (QRubberBand::Rectangle, this); {
foundTextItem = qgraphicsitem_cast<UBGraphicsTextItem*>(it.next ());
mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); }
mRubberBand->show ();
mIsCreatingSceneGrabZone = true; if (foundTextItem)
{
event->accept (); mIsCreatingTextZone = false;
} QGraphicsView::mousePressEvent (event);
else }
{ else
if(UBDrawingController::drawingController()->mActiveRuler==NULL) {
{ scene ()->deselectAllItems ();
viewport()->setCursor (QCursor (Qt::BlankCursor));
} if (!mRubberBand)
mRubberBand = new UBRubberBand (QRubberBand::Rectangle, this);
if (scene () && !mTabletStylusIsPressed)
{ mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ()));
scene ()->inputDevicePress (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ()))); mRubberBand->show ();
} mIsCreatingTextZone = true;
event->accept ();
} event->accept ();
} }
} }
else if (currentTool == UBStylusTool::Capture)
void {
UBBoardView::mouseMoveEvent (QMouseEvent *event) scene ()->deselectAllItems ();
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); if (!mRubberBand)
mRubberBand = new UBRubberBand (QRubberBand::Rectangle, this);
if (isAbsurdPoint (event->pos ()))
{ mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ()));
event->accept (); mRubberBand->show ();
return; mIsCreatingSceneGrabZone = true;
}
event->accept ();
if (currentTool == UBStylusTool::Hand && (mMouseButtonIsPressed || mTabletStylusIsPressed)) }
{ else
QPointF eventPosition = event->posF (); {
qreal dx = eventPosition.x () - mPreviousPoint.x (); if(UBDrawingController::drawingController()->mActiveRuler==NULL)
qreal dy = eventPosition.y () - mPreviousPoint.y (); {
mController->handScroll (dx, dy); viewport()->setCursor (QCursor (Qt::BlankCursor));
mPreviousPoint = eventPosition; }
event->accept ();
} if (scene () && !mTabletStylusIsPressed)
else if (currentTool == UBStylusTool::Selector) {
{ scene ()->inputDevicePress (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())));
QGraphicsView::mouseMoveEvent (event); }
} event->accept ();
else if ((UBDrawingController::drawingController()->isDrawingTool()) }
&& !mMouseButtonIsPressed) }
{ }
QGraphicsView::mouseMoveEvent (event);
} void
else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture) UBBoardView::mouseMoveEvent (QMouseEvent *event)
{ {
if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone)) UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
{
mRubberBand->setGeometry (QRect (mMouseDownPos, event->pos ()).normalized ()); if (isAbsurdPoint (event->pos ()))
event->accept (); {
} event->accept ();
else return;
{ }
QGraphicsView::mouseMoveEvent (event);
} if (currentTool == UBStylusTool::Hand && (mMouseButtonIsPressed || mTabletStylusIsPressed))
} {
else QPointF eventPosition = event->posF ();
{ qreal dx = eventPosition.x () - mPreviousPoint.x ();
if (!mTabletStylusIsPressed && scene ()) qreal dy = eventPosition.y () - mPreviousPoint.y ();
{ mController->handScroll (dx, dy);
scene ()->inputDeviceMove (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())), mMouseButtonIsPressed); mPreviousPoint = eventPosition;
} event->accept ();
event->accept (); }
} else if (currentTool == UBStylusTool::Selector)
} {
if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) {
void return;
UBBoardView::mouseReleaseEvent (QMouseEvent *event) }
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed))
{
scene ()->setToolCursor (currentTool); QPointF scenePos = mapToScene(event->pos());
setToolCursor (currentTool); QPointF newPos = movingItem->pos() + scenePos - mLastPressedMousePos;
movingItem->setPos(newPos);
// first propagate device release to the scene mLastPressedMousePos = scenePos;
if (scene ()) mWidgetMoved = true;
scene ()->inputDeviceRelease (); event->accept();
}
if (currentTool == UBStylusTool::Selector) else QGraphicsView::mouseMoveEvent (event);
{ }
QGraphicsView::mouseReleaseEvent (event); else if ((UBDrawingController::drawingController()->isDrawingTool())
} && !mMouseButtonIsPressed)
else if (currentTool == UBStylusTool::Text) {
{ QGraphicsView::mouseMoveEvent (event);
if (mRubberBand) }
mRubberBand->hide (); else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture)
{
if (scene () && mRubberBand && mIsCreatingTextZone) if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone))
{ {
QRect rubberRect = mRubberBand->geometry (); mRubberBand->setGeometry (QRect (mMouseDownPos, event->pos ()).normalized ());
event->accept ();
UBGraphicsTextItem* textItem = scene()->addTextHtml ("", mapToScene (rubberRect.topLeft ())); }
event->accept (); else
{
UBDrawingController::drawingController ()->setStylusTool (UBStylusTool::Selector); QGraphicsView::mouseMoveEvent (event);
}
textItem->setSelected (true); }
} else
else {
{ if (!mTabletStylusIsPressed && scene ())
QGraphicsView::mouseReleaseEvent (event); {
} scene ()->inputDeviceMove (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())), mMouseButtonIsPressed);
}
mIsCreatingTextZone = false; event->accept ();
} }
else if (currentTool == UBStylusTool::Capture) }
{
if (mRubberBand) void
mRubberBand->hide (); UBBoardView::mouseReleaseEvent (QMouseEvent *event)
{
if (scene () && mRubberBand && mIsCreatingSceneGrabZone && mRubberBand->geometry ().width () > 16) UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
{
QRect rect = mRubberBand->geometry (); scene ()->setToolCursor (currentTool);
QPointF sceneTopLeft = mapToScene (rect.topLeft ()); setToolCursor (currentTool);
QPointF sceneBottomRight = mapToScene (rect.bottomRight ());
QRectF sceneRect (sceneTopLeft, sceneBottomRight); // first propagate device release to the scene
if (scene ())
mController->grabScene (sceneRect); scene ()->inputDeviceRelease ();
event->accept (); if (currentTool == UBStylusTool::Selector)
} {
else if (mWidgetMoved)
{ {
QGraphicsView::mouseReleaseEvent (event); mWidgetMoved = false;
} movingItem = NULL;
}
mIsCreatingSceneGrabZone = false; else if (movingItem && suspendedMousePressEvent)
} {
else QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop
{ movingItem = NULL;
if (mPendingStylusReleaseEvent || mMouseButtonIsPressed) delete suspendedMousePressEvent;
{ suspendedMousePressEvent = NULL;
event->accept (); }
}
} QGraphicsView::mouseReleaseEvent (event);
}
mMouseButtonIsPressed = false; else if (currentTool == UBStylusTool::Text)
mPendingStylusReleaseEvent = false; {
mTabletStylusIsPressed = false; if (mRubberBand)
mRubberBand->hide ();
}
if (scene () && mRubberBand && mIsCreatingTextZone)
void {
UBBoardView::forcedTabletRelease () QRect rubberRect = mRubberBand->geometry ();
{
UBGraphicsTextItem* textItem = scene()->addTextHtml ("", mapToScene (rubberRect.topLeft ()));
if (mMouseButtonIsPressed || mTabletStylusIsPressed || mPendingStylusReleaseEvent) event->accept ();
{
qWarning () << "dirty mouse/tablet state:"; UBDrawingController::drawingController ()->setStylusTool (UBStylusTool::Selector);
qWarning () << "mMouseButtonIsPressed =" << mMouseButtonIsPressed;
qWarning () << "mTabletStylusIsPressed = " << mTabletStylusIsPressed; textItem->setSelected (true);
qWarning () << "mPendingStylusReleaseEvent" << mPendingStylusReleaseEvent; }
qWarning () << "forcing device release"; else
{
scene ()->inputDeviceRelease (); QGraphicsView::mouseReleaseEvent (event);
}
mMouseButtonIsPressed = false;
mTabletStylusIsPressed = false; mIsCreatingTextZone = false;
mPendingStylusReleaseEvent = false; }
} else if (currentTool == UBStylusTool::Capture)
} {
if (mRubberBand)
void mRubberBand->hide ();
UBBoardView::mouseDoubleClickEvent (QMouseEvent *event)
{ if (scene () && mRubberBand && mIsCreatingSceneGrabZone && mRubberBand->geometry ().width () > 16)
// We don't want a double click, we want two clicks {
mousePressEvent (event); QRect rect = mRubberBand->geometry ();
} QPointF sceneTopLeft = mapToScene (rect.topLeft ());
QPointF sceneBottomRight = mapToScene (rect.bottomRight ());
void QRectF sceneRect (sceneTopLeft, sceneBottomRight);
UBBoardView::wheelEvent (QWheelEvent *wheelEvent)
{ mController->grabScene (sceneRect);
if (isInteractive () && wheelEvent->orientation () == Qt::Vertical)
{ event->accept ();
// Too many wheelEvent are sent, how should we handle them to "smoothly" zoom ? }
// something like zoom( pow(zoomFactor, event->delta() / 120) ) else
{
// use DateTime man, store last event time, and if if less than 300ms than this is one big scroll QGraphicsView::mouseReleaseEvent (event);
// and move scroll with one const speed. }
// so, you no will related with scroll event count
} mIsCreatingSceneGrabZone = false;
}
QList<QGraphicsItem *> selItemsList = scene()->selectedItems(); else
// if NO have selected items, than no need process mouse wheel. just exist {
if( selItemsList.count() > 0 ) if (mPendingStylusReleaseEvent || mMouseButtonIsPressed)
{ {
// only one selected item possible, so we will work with first item only event->accept ();
QGraphicsItem * selItem = selItemsList[0]; }
}
// get items list under mouse cursor
QPointF scenePos = mapToScene(wheelEvent->pos()); mMouseButtonIsPressed = false;
QList<QGraphicsItem *> itemsList = scene()->items(scenePos); mPendingStylusReleaseEvent = false;
mTabletStylusIsPressed = false;
QBool isSlectedAndMouseHower = itemsList.contains(selItem);
if(isSlectedAndMouseHower) }
{
QGraphicsView::wheelEvent(wheelEvent); void
wheelEvent->accept(); UBBoardView::forcedTabletRelease ()
} {
} if (mMouseButtonIsPressed || mTabletStylusIsPressed || mPendingStylusReleaseEvent)
{
} qWarning () << "dirty mouse/tablet state:";
qWarning () << "mMouseButtonIsPressed =" << mMouseButtonIsPressed;
void qWarning () << "mTabletStylusIsPressed = " << mTabletStylusIsPressed;
UBBoardView::leaveEvent (QEvent * event) qWarning () << "mPendingStylusReleaseEvent" << mPendingStylusReleaseEvent;
{ qWarning () << "forcing device release";
if (scene ())
scene ()->leaveEvent (event); scene ()->inputDeviceRelease ();
QGraphicsView::leaveEvent (event); mMouseButtonIsPressed = false;
} mTabletStylusIsPressed = false;
mPendingStylusReleaseEvent = false;
void }
UBBoardView::drawItems (QPainter *painter, int numItems, }
QGraphicsItem* items[],
const QStyleOptionGraphicsItem options[]) void
{ UBBoardView::mouseDoubleClickEvent (QMouseEvent *event)
if (!mFilterZIndex) {
{ // We don't want a double click, we want two clicks
QGraphicsView::drawItems (painter, numItems, items, options); mousePressEvent (event);
} }
else
{ void
int count = 0; UBBoardView::wheelEvent (QWheelEvent *wheelEvent)
{
QGraphicsItem** itemsFiltered = new QGraphicsItem*[numItems]; if (isInteractive () && wheelEvent->orientation () == Qt::Vertical)
QStyleOptionGraphicsItem *optionsFiltered = new QStyleOptionGraphicsItem[numItems]; {
// Too many wheelEvent are sent, how should we handle them to "smoothly" zoom ?
for (int i = 0; i < numItems; i++) // something like zoom( pow(zoomFactor, event->delta() / 120) )
{
if (shouldDisplayItem (items[i])) // use DateTime man, store last event time, and if if less than 300ms than this is one big scroll
{ // and move scroll with one const speed.
itemsFiltered[count] = items[i]; // so, you no will related with scroll event count
optionsFiltered[count] = options[i]; }
count++;
} QList<QGraphicsItem *> selItemsList = scene()->selectedItems();
} // if NO have selected items, than no need process mouse wheel. just exist
if( selItemsList.count() > 0 )
QGraphicsView::drawItems (painter, count, itemsFiltered, optionsFiltered); {
// only one selected item possible, so we will work with first item only
delete[] optionsFiltered; QGraphicsItem * selItem = selItemsList[0];
delete[] itemsFiltered;
} // get items list under mouse cursor
} QPointF scenePos = mapToScene(wheelEvent->pos());
QList<QGraphicsItem *> itemsList = scene()->items(scenePos);
//void UBBoardView::dragEnterEvent (QDragEnterEvent *event)
//{ QBool isSlectedAndMouseHower = itemsList.contains(selItem);
// // TODO UB 4.x be smarter with drag accept code .... we cannot handle everything ... if(isSlectedAndMouseHower)
// event->acceptProposedAction (); {
//} QGraphicsView::wheelEvent(wheelEvent);
wheelEvent->accept();
void UBBoardView::dragMoveEvent (QDragMoveEvent *event) }
{
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); }
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
}
if (graphicsWidget) {
if (graphicsWidget->acceptDrops()) { void
if (!mOkOnWidget) { UBBoardView::leaveEvent (QEvent * event)
if (!graphicsWidget->isDropableData(event->mimeData())) { {
mOkOnWidget = false; if (scene ())
event->ignore(); scene ()->leaveEvent (event);
return;
} else { QGraphicsView::leaveEvent (event);
mOkOnWidget = true; }
}
} void
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); UBBoardView::drawItems (QPainter *painter, int numItems,
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); QGraphicsItem* items[],
QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent); const QStyleOptionGraphicsItem options[])
} else { {
mOkOnWidget = false; if (!mFilterZIndex)
event->ignore(); {
} QGraphicsView::drawItems (painter, numItems, items, options);
} else { }
event->acceptProposedAction(); else
mOkOnWidget = false; {
} int count = 0;
}
QGraphicsItem** itemsFiltered = new QGraphicsItem*[numItems];
void UBBoardView::dropEvent (QDropEvent *event) QStyleOptionGraphicsItem *optionsFiltered = new QStyleOptionGraphicsItem[numItems];
{
mOkOnWidget = false; for (int i = 0; i < numItems; i++)
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); {
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos); if (shouldDisplayItem (items[i]))
{
if (graphicsWidget && graphicsWidget->acceptDrops()) { itemsFiltered[count] = items[i];
optionsFiltered[count] = options[i];
graphicsWidget->processDropEvent(event); count++;
event->acceptProposedAction(); }
}
} else if (!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source())
|| dynamic_cast<QWebView*>(event->source()) || dynamic_cast<UBDraggableMediaPlayer *>(event->source()) QGraphicsView::drawItems (painter, count, itemsFiltered, optionsFiltered);
|| dynamic_cast<UBDraggableLabel *>(event->source()) || dynamic_cast<UBDraggableMedia *>(event->source())) {
delete[] optionsFiltered;
mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); delete[] itemsFiltered;
event->acceptProposedAction(); }
} }
}
//void UBBoardView::dragEnterEvent (QDragEnterEvent *event)
void //{
UBBoardView::resizeEvent (QResizeEvent * event) // // TODO UB 4.x be smarter with drag accept code .... we cannot handle everything ...
{ // event->acceptProposedAction ();
const qreal maxWidth = width () * 10; //}
const qreal maxHeight = height () * 10;
void UBBoardView::dragMoveEvent (QDragMoveEvent *event)
setSceneRect (-(maxWidth / 2), -(maxHeight / 2), maxWidth, maxHeight); {
centerOn (0, 0); QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y());
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
emit resized (event);
} if (graphicsWidget) {
if (graphicsWidget->acceptDrops()) {
void if (!mOkOnWidget) {
UBBoardView::drawBackground (QPainter *painter, const QRectF &rect) if (!graphicsWidget->isDropableData(event->mimeData())) {
{ mOkOnWidget = false;
if (testAttribute (Qt::WA_TranslucentBackground)) event->ignore();
{ return;
QGraphicsView::drawBackground (painter, rect); } else {
return; mOkOnWidget = true;
} }
}
bool darkBackground = scene () && scene ()->isDarkBackground (); QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint());
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
if (darkBackground) QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent);
{ } else {
painter->fillRect (rect, QBrush (QColor (Qt::black))); mOkOnWidget = false;
} event->ignore();
else }
{ } else {
painter->fillRect (rect, QBrush (QColor (Qt::white))); event->acceptProposedAction();
} mOkOnWidget = false;
}
if (transform ().m11 () > 0.5) }
{
QColor bgCrossColor; void UBBoardView::dropEvent (QDropEvent *event)
{
if (darkBackground) mOkOnWidget = false;
bgCrossColor = UBSettings::crossDarkBackground; QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y());
else UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
bgCrossColor = UBSettings::crossLightBackground;
if (graphicsWidget && graphicsWidget->acceptDrops()) {
if (transform ().m11 () < 1.0)
{ graphicsWidget->processDropEvent(event);
int alpha = 255 * transform ().m11 () / 2; event->acceptProposedAction();
bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms
} } else if (!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source())
|| dynamic_cast<QWebView*>(event->source()) || dynamic_cast<UBDraggableMediaPlayer *>(event->source())
painter->setPen (bgCrossColor); || dynamic_cast<UBDraggableLabel *>(event->source()) || dynamic_cast<UBDraggableMedia *>(event->source())) {
if (scene () && scene ()->isCrossedBackground ()) mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
{ event->acceptProposedAction();
qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; }
}
for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize)
{ void
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); UBBoardView::resizeEvent (QResizeEvent * event)
} {
const qreal maxWidth = width () * 10;
qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; const qreal maxHeight = height () * 10;
for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) setSceneRect (-(maxWidth / 2), -(maxHeight / 2), maxWidth, maxHeight);
{ centerOn (0, 0);
painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
} emit resized (event);
} }
}
void
if (!mFilterZIndex && scene ()) UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
{ {
QSize pageNominalSize = scene ()->nominalSize (); if (testAttribute (Qt::WA_TranslucentBackground))
{
if (pageNominalSize.isValid ()) QGraphicsView::drawBackground (painter, rect);
{ return;
qreal penWidth = 8.0 / transform ().m11 (); }
QRectF pageRect (pageNominalSize.width () / -2, pageNominalSize.height () / -2 bool darkBackground = scene () && scene ()->isDarkBackground ();
, pageNominalSize.width (), pageNominalSize.height ());
if (darkBackground)
pageRect.adjust (-penWidth / 2, -penWidth / 2, penWidth / 2, penWidth / 2); {
painter->fillRect (rect, QBrush (QColor (Qt::black)));
QColor docSizeColor; }
else
if (darkBackground) {
docSizeColor = UBSettings::documentSizeMarkColorDarkBackground; painter->fillRect (rect, QBrush (QColor (Qt::white)));
else }
docSizeColor = UBSettings::documentSizeMarkColorLightBackground;
if (transform ().m11 () > 0.5)
QPen pen (docSizeColor); {
pen.setWidth (penWidth); QColor bgCrossColor;
painter->setPen (pen);
painter->drawRect (pageRect); if (darkBackground)
} bgCrossColor = UBSettings::crossDarkBackground;
} else
} bgCrossColor = UBSettings::crossLightBackground;
void if (transform ().m11 () < 1.0)
UBBoardView::settingChanged (QVariant newValue) {
{ int alpha = 255 * transform ().m11 () / 2;
Q_UNUSED (newValue); bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms
}
mPenPressureSensitive = UBSettings::settings ()->boardPenPressureSensitive->get ().toBool ();
mMarkerPressureSensitive = UBSettings::settings ()->boardMarkerPressureSensitive->get ().toBool (); painter->setPen (bgCrossColor);
mUseHighResTabletEvent = UBSettings::settings ()->boardUseHighResTabletEvent->get ().toBool ();
} if (scene () && scene ()->isCrossedBackground ())
{
void UBBoardView::virtualKeyboardActivated(bool b) qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize;
{
UBPlatformUtils::setWindowNonActivableFlag(this, b); for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize)
mVirtualKeyboardActive = b; {
setInteractive(!b); painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
} }
qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize;
// Apple remote desktop sends funny events when the transmission is bad
for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize)
bool {
UBBoardView::isAbsurdPoint (QPoint point) painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
{ }
QDesktopWidget *desktop = qApp->desktop (); }
bool isValidPoint = false; }
for (int i = 0; i < desktop->numScreens (); i++) if (!mFilterZIndex && scene ())
{ {
QRect screenRect = desktop->screenGeometry (i); QSize pageNominalSize = scene ()->nominalSize ();
isValidPoint = isValidPoint || screenRect.contains (point);
} if (pageNominalSize.isValid ())
{
return !isValidPoint; qreal penWidth = 8.0 / transform ().m11 ();
}
QRectF pageRect (pageNominalSize.width () / -2, pageNominalSize.height () / -2
void , pageNominalSize.width (), pageNominalSize.height ());
UBBoardView::focusOutEvent (QFocusEvent * event)
{ pageRect.adjust (-penWidth / 2, -penWidth / 2, penWidth / 2, penWidth / 2);
Q_UNUSED (event);
} QColor docSizeColor;
void if (darkBackground)
UBBoardView::setToolCursor (int tool) docSizeColor = UBSettings::documentSizeMarkColorDarkBackground;
{ else
QWidget *controlViewport = viewport (); docSizeColor = UBSettings::documentSizeMarkColorLightBackground;
switch (tool)
{ QPen pen (docSizeColor);
case UBStylusTool::Pen: pen.setWidth (penWidth);
controlViewport->setCursor (UBResources::resources ()->penCursor); painter->setPen (pen);
break; painter->drawRect (pageRect);
case UBStylusTool::Eraser: }
controlViewport->setCursor (UBResources::resources ()->eraserCursor); }
break; }
case UBStylusTool::Marker:
controlViewport->setCursor (UBResources::resources ()->markerCursor); void
break; UBBoardView::settingChanged (QVariant newValue)
case UBStylusTool::Pointer: {
controlViewport->setCursor (UBResources::resources ()->pointerCursor); Q_UNUSED (newValue);
break;
case UBStylusTool::Hand: mPenPressureSensitive = UBSettings::settings ()->boardPenPressureSensitive->get ().toBool ();
controlViewport->setCursor (UBResources::resources ()->handCursor); mMarkerPressureSensitive = UBSettings::settings ()->boardMarkerPressureSensitive->get ().toBool ();
break; mUseHighResTabletEvent = UBSettings::settings ()->boardUseHighResTabletEvent->get ().toBool ();
case UBStylusTool::ZoomIn: }
controlViewport->setCursor (UBResources::resources ()->zoomInCursor);
break; void UBBoardView::virtualKeyboardActivated(bool b)
case UBStylusTool::ZoomOut: {
controlViewport->setCursor (UBResources::resources ()->zoomOutCursor); UBPlatformUtils::setWindowNonActivableFlag(this, b);
break; mVirtualKeyboardActive = b;
case UBStylusTool::Selector: setInteractive(!b);
controlViewport->setCursor (UBResources::resources ()->arrowCursor); }
break;
case UBStylusTool::Line:
controlViewport->setCursor (UBResources::resources ()->penCursor); // Apple remote desktop sends funny events when the transmission is bad
break;
case UBStylusTool::Text: bool
controlViewport->setCursor (UBResources::resources ()->textCursor); UBBoardView::isAbsurdPoint (QPoint point)
break; {
case UBStylusTool::Capture: QDesktopWidget *desktop = qApp->desktop ();
controlViewport->setCursor (UBResources::resources ()->penCursor); bool isValidPoint = false;
break;
default: for (int i = 0; i < desktop->numScreens (); i++)
Q_ASSERT (false); {
//failsafe QRect screenRect = desktop->screenGeometry (i);
controlViewport->setCursor (UBResources::resources ()->penCursor); isValidPoint = isValidPoint || screenRect.contains (point);
} }
}
return !isValidPoint;
}
void
UBBoardView::focusOutEvent (QFocusEvent * event)
{
Q_UNUSED (event);
}
void
UBBoardView::setToolCursor (int tool)
{
QWidget *controlViewport = viewport ();
switch (tool)
{
case UBStylusTool::Pen:
controlViewport->setCursor (UBResources::resources ()->penCursor);
break;
case UBStylusTool::Eraser:
controlViewport->setCursor (UBResources::resources ()->eraserCursor);
break;
case UBStylusTool::Marker:
controlViewport->setCursor (UBResources::resources ()->markerCursor);
break;
case UBStylusTool::Pointer:
controlViewport->setCursor (UBResources::resources ()->pointerCursor);
break;
case UBStylusTool::Hand:
controlViewport->setCursor (UBResources::resources ()->handCursor);
break;
case UBStylusTool::ZoomIn:
controlViewport->setCursor (UBResources::resources ()->zoomInCursor);
break;
case UBStylusTool::ZoomOut:
controlViewport->setCursor (UBResources::resources ()->zoomOutCursor);
break;
case UBStylusTool::Selector:
controlViewport->setCursor (UBResources::resources ()->arrowCursor);
break;
case UBStylusTool::Line:
controlViewport->setCursor (UBResources::resources ()->penCursor);
break;
case UBStylusTool::Text:
controlViewport->setCursor (UBResources::resources ()->textCursor);
break;
case UBStylusTool::Capture:
controlViewport->setCursor (UBResources::resources ()->penCursor);
break;
default:
Q_ASSERT (false);
//failsafe
controlViewport->setCursor (UBResources::resources ()->penCursor);
}
}
/* /*
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBBOARDVIEW_H_ #ifndef UBBOARDVIEW_H_
#define UBBOARDVIEW_H_ #define UBBOARDVIEW_H_
#include <QtGui> #include <QtGui>
#include "core/UB.h" #include "core/UB.h"
#include "domain/UBGraphicsDelegateFrame.h"
class UBBoardController;
class UBAppleWidget; class UBBoardController;
class UBGraphicsScene; class UBAppleWidget;
class UBGraphicsWidgetItem; class UBGraphicsScene;
class UBGraphicsWidgetItem;
class UBBoardView : public QGraphicsView
{ class UBBoardView : public QGraphicsView
Q_OBJECT; {
Q_OBJECT;
public:
public:
UBBoardView(UBBoardController* pController, QWidget* pParent = 0);
UBBoardView(UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent = 0); UBBoardView(UBBoardController* pController, QWidget* pParent = 0);
virtual ~UBBoardView(); UBBoardView(UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent = 0);
virtual ~UBBoardView();
UBGraphicsScene* scene();
UBGraphicsScene* scene();
void forcedTabletRelease();
void forcedTabletRelease();
void setToolCursor(int tool);
void setToolCursor(int tool);
signals:
signals:
void resized(QResizeEvent* event);
void hidden(); void resized(QResizeEvent* event);
void shown(); void hidden();
void shown();
protected:
protected:
virtual bool event (QEvent * e);
virtual bool event (QEvent * e);
virtual void keyPressEvent(QKeyEvent *event);
virtual void tabletEvent(QTabletEvent * event); virtual void keyPressEvent(QKeyEvent *event);
virtual void mouseDoubleClickEvent(QMouseEvent *event); virtual void tabletEvent(QTabletEvent * event);
virtual void mousePressEvent(QMouseEvent *event); virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void leaveEvent ( QEvent * event); virtual void wheelEvent(QWheelEvent *event);
virtual void leaveEvent ( QEvent * event);
virtual void focusOutEvent ( QFocusEvent * event );
virtual void focusOutEvent ( QFocusEvent * event );
virtual void drawItems(QPainter *painter, int numItems,
QGraphicsItem *items[], virtual void drawItems(QPainter *painter, int numItems,
const QStyleOptionGraphicsItem options[]); QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[]);
// virtual void dragEnterEvent(QDragEnterEvent * event);
virtual void dropEvent(QDropEvent *event); // virtual void dragEnterEvent(QDragEnterEvent * event);
virtual void dragMoveEvent(QDragMoveEvent *event); virtual void dropEvent(QDropEvent *event);
virtual void dragMoveEvent(QDragMoveEvent *event);
virtual void resizeEvent(QResizeEvent * event);
virtual void resizeEvent(QResizeEvent * event);
virtual void drawBackground(QPainter *painter, const QRectF &rect);
virtual void drawBackground(QPainter *painter, const QRectF &rect);
virtual void showEvent(QShowEvent * event);
virtual void hideEvent(QHideEvent * event); virtual void showEvent(QShowEvent * event);
virtual void hideEvent(QHideEvent * event);
private:
private:
void init();
void init();
inline bool shouldDisplayItem(QGraphicsItem *item)
{ inline bool shouldDisplayItem(QGraphicsItem *item)
bool ok; {
int itemLayerType = item->data(UBGraphicsItemData::ItemLayerType).toInt(&ok); bool ok;
return (ok && (itemLayerType >= mStartLayer && itemLayerType <= mEndLayer)); int itemLayerType = item->data(UBGraphicsItemData::ItemLayerType).toInt(&ok);
} return (ok && (itemLayerType >= mStartLayer && itemLayerType <= mEndLayer));
}
QList<QUrl> processMimeData(const QMimeData* pMimeData);
QList<QUrl> processMimeData(const QMimeData* pMimeData);
UBBoardController* mController;
UBBoardController* mController;
int mStartLayer, mEndLayer;
bool mFilterZIndex; int mStartLayer, mEndLayer;
bool mFilterZIndex;
bool mTabletStylusIsPressed;
bool mUsingTabletEraser; bool mTabletStylusIsPressed;
bool mUsingTabletEraser;
bool mPendingStylusReleaseEvent;
bool mPendingStylusReleaseEvent;
bool mMouseButtonIsPressed;
QPointF mPreviousPoint; bool mMouseButtonIsPressed;
QPoint mMouseDownPos; QPointF mPreviousPoint;
QPoint mMouseDownPos;
bool mPenPressureSensitive;
bool mMarkerPressureSensitive; bool mPenPressureSensitive;
bool mUseHighResTabletEvent; bool mMarkerPressureSensitive;
bool mUseHighResTabletEvent;
QRubberBand *mRubberBand;
bool mIsCreatingTextZone; QRubberBand *mRubberBand;
bool mIsCreatingSceneGrabZone; bool mIsCreatingTextZone;
bool mIsCreatingSceneGrabZone;
bool isAbsurdPoint(QPoint point);
bool isAbsurdPoint(QPoint point);
bool mVirtualKeyboardActive;
bool mOkOnWidget; bool mVirtualKeyboardActive;
bool mOkOnWidget;
private slots:
bool mWidgetMoved;
void settingChanged(QVariant newValue); QPointF mLastPressedMousePos;
QGraphicsItem *movingItem;
public slots: QMouseEvent *suspendedMousePressEvent;
void virtualKeyboardActivated(bool b); private slots:
}; void settingChanged(QVariant newValue);
#endif /* UBBOARDVIEW_H_ */ public slots:
void virtualKeyboardActivated(bool b);
};
#endif /* UBBOARDVIEW_H_ */
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