Backup of the lines as objects

preferencesAboutTextFull
shibakaneki 13 years ago
parent 0bfa298344
commit 75a7c9ea24
  1. 7
      src/board/UBBoardView.cpp
  2. 11
      src/board/UBDrawingController.cpp
  3. 8
      src/board/UBDrawingController.h
  4. 2
      src/core/UBApplicationController.cpp
  5. 97
      src/domain/UBGraphicsScene.cpp
  6. 1
      src/domain/UBGraphicsScene.h
  7. 7
      src/domain/UBGraphicsStroke.cpp
  8. 2
      src/domain/UBGraphicsStroke.h
  9. 86
      src/domain/UBGraphicsStrokesGroup.cpp
  10. 28
      src/domain/UBGraphicsStrokesGroup.h
  11. 6
      src/domain/domain.pri
  12. 6
      src/frameworks/UBCoreGraphicsScene.cpp
  13. 1
      src/frameworks/UBCoreGraphicsScene.h

@ -312,7 +312,6 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
} }
QPointF scenePos = viewportTransform ().inverted ().map (tabletPos); QPointF scenePos = viewportTransform ().inverted ().map (tabletPos);
qDebug() << "scene Pos " << scenePos;
qreal pressure = 1.0; qreal pressure = 1.0;
if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line) if (((currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Line)
@ -325,16 +324,12 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
switch (event->type ()) { switch (event->type ()) {
case QEvent::TabletPress: { case QEvent::TabletPress: {
qDebug() << "TabletPress";
mTabletStylusIsPressed = true; mTabletStylusIsPressed = true;
scene()->inputDevicePress (scenePos, pressure); scene()->inputDevicePress (scenePos, pressure);
break; break;
} }
case QEvent::TabletMove: { case QEvent::TabletMove: {
qDebug() << "TabletMove";
if (mTabletStylusIsPressed) if (mTabletStylusIsPressed)
scene ()->inputDeviceMove (scenePos, pressure); scene ()->inputDeviceMove (scenePos, pressure);
@ -344,8 +339,6 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
} }
case QEvent::TabletRelease: { case QEvent::TabletRelease: {
qDebug() << "TabletRelease";
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool (); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool ();
scene ()->setToolCursor (currentTool); scene ()->setToolCursor (currentTool);
setToolCursor (currentTool); setToolCursor (currentTool);

@ -45,6 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
, mActiveRuler(NULL) , mActiveRuler(NULL)
, mStylusTool((UBStylusTool::Enum)-1) , mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1) , mLatestDrawingTool((UBStylusTool::Enum)-1)
//, mDrawingMode(eDrawingMode_Vector)
{ {
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged())); connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));
@ -387,3 +388,13 @@ void UBDrawingController::captureToolSelected(bool checked)
if (checked) if (checked)
setStylusTool(UBStylusTool::Capture); setStylusTool(UBStylusTool::Capture);
} }
void UBDrawingController::setDrawingMode(eDrawingMode mode)
{
mDrawingMode = mode;
}
eDrawingMode UBDrawingController::drawingMode()
{
return mDrawingMode;
}

@ -22,6 +22,11 @@
class UBAbstractDrawRuler; class UBAbstractDrawRuler;
typedef enum{
eDrawingMode_Artistic,
eDrawingMode_Vector
}eDrawingMode;
class UBDrawingController : public QObject class UBDrawingController : public QObject
{ {
Q_OBJECT; Q_OBJECT;
@ -49,6 +54,8 @@ class UBDrawingController : public QObject
void setPenColor(bool onDarkBackground, const QColor& color, int pIndex); void setPenColor(bool onDarkBackground, const QColor& color, int pIndex);
void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex); void setMarkerColor(bool onDarkBackground, const QColor& color, int pIndex);
void setMarkerAlpha(qreal alpha); void setMarkerAlpha(qreal alpha);
void setDrawingMode(eDrawingMode mode);
eDrawingMode drawingMode();
UBAbstractDrawRuler* mActiveRuler; UBAbstractDrawRuler* mActiveRuler;
@ -69,6 +76,7 @@ class UBDrawingController : public QObject
private: private:
UBStylusTool::Enum mStylusTool; UBStylusTool::Enum mStylusTool;
UBStylusTool::Enum mLatestDrawingTool; UBStylusTool::Enum mLatestDrawingTool;
eDrawingMode mDrawingMode;
static UBDrawingController* sDrawingController; static UBDrawingController* sDrawingController;

@ -462,6 +462,7 @@ void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
UBPlatformUtils::bringPreviousProcessToFront(); UBPlatformUtils::bringPreviousProcessToFront();
} }
UBDrawingController::drawingController()->setDrawingMode(eDrawingMode_Artistic);
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
@ -605,6 +606,7 @@ void UBApplicationController::checkUpdateRequest()
void UBApplicationController::hideDesktop() void UBApplicationController::hideDesktop()
{ {
mDisplayManager->adjustScreens(-1); mDisplayManager->adjustScreens(-1);
UBDrawingController::drawingController()->setDrawingMode(eDrawingMode_Vector);
if (mMainMode == Board) if (mMainMode == Board)
{ {

@ -54,6 +54,7 @@
#include "UBGraphicsWidgetItem.h" #include "UBGraphicsWidgetItem.h"
#include "UBGraphicsPDFItem.h" #include "UBGraphicsPDFItem.h"
#include "UBGraphicsTextItem.h" #include "UBGraphicsTextItem.h"
#include "UBGraphicsStrokesGroup.h"
#include "UBAppleWidget.h" #include "UBAppleWidget.h"
#include "UBW3CWidget.h" #include "UBW3CWidget.h"
@ -269,8 +270,9 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
, magniferDisplayViewWidget(0) , magniferDisplayViewWidget(0)
, mZLayerController(new UBZLayerController(this)) , mZLayerController(new UBZLayerController(this))
, mIsDesktopMode(false) , mIsDesktopMode(false)
, mpLastPolygon(NULL)
{ {
UBCoreGraphicsScene::setObjectName("BoardScene");
#ifdef __ppc__ #ifdef __ppc__
mShouldUseOMP = false; mShouldUseOMP = false;
#elif defined(Q_WS_MAC) #elif defined(Q_WS_MAC)
@ -342,19 +344,29 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
if (UBDrawingController::drawingController()->isDrawingTool()) if (UBDrawingController::drawingController()->isDrawingTool())
{ {
// -----------------------------------------------------------------
// We fall here if we are using the Pen, the Marker or the Line tool
// -----------------------------------------------------------------
qreal width = 0; qreal width = 0;
// delete current stroke, if not assigned to any polygon // delete current stroke, if not assigned to any polygon
if (mCurrentStroke) if (mCurrentStroke && mCurrentStroke->polygons().empty()){
if (mCurrentStroke->polygons().empty()) delete mCurrentStroke;
delete mCurrentStroke; mCurrentStroke = NULL;
}
// ---------------------------------------------------------------
// Create a new Stroke. A Stroke is a collection of QGraphicsLines
// ---------------------------------------------------------------
mCurrentStroke = new UBGraphicsStroke(); mCurrentStroke = new UBGraphicsStroke();
if (currentTool != UBStylusTool::Line) if (currentTool != UBStylusTool::Line){
// Handle the pressure
width = UBDrawingController::drawingController()->currentToolWidth() * pressure; width = UBDrawingController::drawingController()->currentToolWidth() * pressure;
else }else{
width = UBDrawingController::drawingController()->currentToolWidth(); //ignore pressure for line tool // Ignore pressure for the line tool
width = UBDrawingController::drawingController()->currentToolWidth();
}
width /= UBApplication::boardController->systemScaleFactor(); width /= UBApplication::boardController->systemScaleFactor();
width /= UBApplication::boardController->currentZoom(); width /= UBApplication::boardController->currentZoom();
@ -364,14 +376,12 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
if (UBDrawingController::drawingController()->mActiveRuler) if (UBDrawingController::drawingController()->mActiveRuler)
{ {
UBDrawingController::drawingController()->mActiveRuler->StartLine( UBDrawingController::drawingController()->mActiveRuler->StartLine(scenePos, width);
scenePos, width);
} }
else else
{ {
moveTo(scenePos); moveTo(scenePos);
drawLineTo(scenePos, width, drawLineTo(scenePos, width, UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
} }
accepted = true; accepted = true;
} }
@ -422,10 +432,13 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
{ {
qreal width = 0; qreal width = 0;
if (currentTool != UBStylusTool::Line) if (currentTool != UBStylusTool::Line){
// Handle the pressure
width = dc->currentToolWidth() * pressure; width = dc->currentToolWidth() * pressure;
else }else{
width = dc->currentToolWidth();//ignore pressure for line tool // Ignore pressure for line tool
width = dc->currentToolWidth();
}
width /= UBApplication::boardController->systemScaleFactor(); width /= UBApplication::boardController->systemScaleFactor();
width /= UBApplication::boardController->currentZoom(); width /= UBApplication::boardController->currentZoom();
@ -437,10 +450,20 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
else else
{ {
if (currentTool == UBStylusTool::Line) if (currentTool == UBStylusTool::Line)
{ {
// TODO: Verify this beautiful implementation and check if if(NULL != mpLastPolygon && NULL != mCurrentStroke && mAddedItems.size() > 0){
// it is possible to optimize it UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon);
QLineF radius(mPreviousPoint, position); mAddedItems.remove(mpLastPolygon);
mCurrentStroke->remove(mpLastPolygon);
removeItem(mpLastPolygon);
mPreviousPolygonItems.removeAll(mpLastPolygon);
}
// ------------------------------------------------------------------------
// Here we wanna make sure that the Line will 'grip' at i*45, i*90 degrees
// ------------------------------------------------------------------------
QLineF radius(mPreviousPoint, position);
qreal angle = radius.angle(); qreal angle = radius.angle();
angle = qRound(angle / 45) * 45; angle = qRound(angle / 45) * 45;
qreal radiusLength = radius.length(); qreal radiusLength = radius.length();
@ -452,8 +475,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
position = newPosition; position = newPosition;
} }
drawLineTo(position, width, drawLineTo(position, width, UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
} }
} }
else if (currentTool == UBStylusTool::Eraser) else if (currentTool == UBStylusTool::Eraser)
@ -492,8 +514,6 @@ bool UBGraphicsScene::inputDeviceRelease()
bool accepted = false; bool accepted = false;
if (mPointer) if (mPointer)
{ {
mPointer->hide(); mPointer->hide();
@ -505,10 +525,32 @@ bool UBGraphicsScene::inputDeviceRelease()
{ {
if (mCurrentStroke) if (mCurrentStroke)
{ {
if (mCurrentStroke->polygons().empty()) if(eDrawingMode_Vector == dc->drawingMode()){
UBGraphicsStrokesGroup* pStrokes = new UBGraphicsStrokesGroup();
// Remove the strokes that were just drawn here and replace them by a stroke item
foreach(UBGraphicsPolygonItem* poly, mCurrentStroke->polygons()){
mPreviousPolygonItems.removeAll(poly);
removeItem(poly);
UBCoreGraphicsScene::removeItemFromDeletion(poly);
pStrokes->addToGroup(poly);
}
// TODO LATER : Generate well pressure-interpolated polygons and create the line group with them
mAddedItems.clear();
// Add the groupItem in mAddedItem
mAddedItems << pStrokes;
addItem(pStrokes);
}
if (mCurrentStroke->polygons().empty()){
delete mCurrentStroke; delete mCurrentStroke;
mCurrentStroke = 0; mCurrentStroke = 0;
} }
}
} }
if (mRemovedItems.size() > 0 || mAddedItems.size() > 0) if (mRemovedItems.size() > 0 || mAddedItems.size() > 0)
@ -619,6 +661,9 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
if (!polygonItem->brush().isOpaque()) if (!polygonItem->brush().isOpaque())
{ {
// -------------------------------------------------------------------------------------
// Here we substract the polygons that are overlapping in order to keep the transparency
// -------------------------------------------------------------------------------------
for (int i = 0; i < mPreviousPolygonItems.size(); i++) for (int i = 0; i < mPreviousPolygonItems.size(); i++)
{ {
UBGraphicsPolygonItem* previous = mPreviousPolygonItems.value(i); UBGraphicsPolygonItem* previous = mPreviousPolygonItems.value(i);
@ -638,6 +683,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
mAddedItems.clear(); mAddedItems.clear();
} }
mpLastPolygon = polygonItem;
mAddedItems.insert(polygonItem); mAddedItems.insert(polygonItem);
if (mCurrentStroke) if (mCurrentStroke)
@ -645,6 +691,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
polygonItem->setStroke(mCurrentStroke); polygonItem->setStroke(mCurrentStroke);
} }
// Here we add the item to the scene
addItem(polygonItem); addItem(polygonItem);
mPreviousPolygonItems.append(polygonItem); mPreviousPolygonItems.append(polygonItem);

@ -395,6 +395,7 @@ public slots:
UBMagnifier *magniferDisplayViewWidget; UBMagnifier *magniferDisplayViewWidget;
UBZLayerController *mZLayerController; UBZLayerController *mZLayerController;
UBGraphicsPolygonItem* mpLastPolygon;
}; };

@ -86,3 +86,10 @@ bool UBGraphicsStroke::hasAlpha() const
} }
} }
void UBGraphicsStroke::clear()
{
if(!mPolygons.empty()){
mPolygons.clear();
}
}

@ -41,6 +41,8 @@ class UBGraphicsStroke
bool hasAlpha() const; bool hasAlpha() const;
void clear();
protected: protected:
void addPolygon(UBGraphicsPolygonItem* pol); void addPolygon(UBGraphicsPolygonItem* pol);

@ -0,0 +1,86 @@
#include "UBGraphicsStrokesGroup.h"
UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent):QGraphicsItemGroup(parent)
{
mDelegate = new UBGraphicsItemDelegate(this, 0, true, true);
mDelegate->init();
mDelegate->setFlippable(true);
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsMovable, true);
}
UBGraphicsStrokesGroup::~UBGraphicsStrokesGroup()
{
if(mDelegate){
delete mDelegate;
}
}
void UBGraphicsStrokesGroup::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mousePressEvent(event))
{
//NOOP
}
else
{
// QGraphicsItemGroup::mousePressEvent(event);
}
}
void UBGraphicsStrokesGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mouseMoveEvent(event))
{
// NOOP;
}
else
{
QGraphicsItemGroup::mouseMoveEvent(event);
}
}
void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mDelegate->mouseReleaseEvent(event);
QGraphicsItemGroup::mouseReleaseEvent(event);
}
UBItem* UBGraphicsStrokesGroup::deepCopy() const
{
UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup();
copy->setPos(this->pos());
copy->setTransform(this->transform());
copy->setFlag(QGraphicsItem::ItemIsMovable, true);
copy->setFlag(QGraphicsItem::ItemIsSelectable, true);
copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType));
copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked));
return copy;
}
void UBGraphicsStrokesGroup::remove()
{
if (mDelegate)
mDelegate->remove(true);
}
void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// Never draw the rubber band, we draw our custom selection with the DelegateFrame
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
styleOption.state &= ~QStyle::State_Selected;
QGraphicsItemGroup::paint(painter, &styleOption, widget);
}
QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value)
{
QVariant newValue = mDelegate->itemChange(change, value);
return QGraphicsItemGroup::itemChange(change, newValue);
}

@ -0,0 +1,28 @@
#ifndef UBGRAPHICSSTROKESGROUP_H
#define UBGRAPHICSSTROKESGROUP_H
#include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent>
#include "core/UB.h"
#include "UBItem.h"
class UBGraphicsStrokesGroup : public QObject, public QGraphicsItemGroup, public UBItem, public UBGraphicsItem
{
Q_OBJECT
public:
UBGraphicsStrokesGroup(QGraphicsItem* parent = 0);
~UBGraphicsStrokesGroup();
virtual UBItem* deepCopy() const;
virtual void remove();
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;}
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};
#endif // UBGRAPHICSSTROKESGROUP_H

@ -23,7 +23,8 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBGraphicsAudioItem.h \ src/domain/UBGraphicsAudioItem.h \
src/domain/UBGraphicsAudioItemDelegate.h \ src/domain/UBGraphicsAudioItemDelegate.h \
src/domain/UBAbstractUndoCommand.h\ src/domain/UBAbstractUndoCommand.h\
src/domain/UBAngleWidget.h src/domain/UBAngleWidget.h \
src/domain/UBGraphicsStrokesGroup.h
HEADERS += src/domain/UBGraphicsItemDelegate.h \ HEADERS += src/domain/UBGraphicsItemDelegate.h \
src/domain/UBGraphicsVideoItemDelegate.h \ src/domain/UBGraphicsVideoItemDelegate.h \
@ -56,7 +57,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBGraphicsAudioItem.cpp \ src/domain/UBGraphicsAudioItem.cpp \
src/domain/UBGraphicsAudioItemDelegate.cpp \ src/domain/UBGraphicsAudioItemDelegate.cpp \
src/domain/UBAbstractUndoCommand.cpp \ src/domain/UBAbstractUndoCommand.cpp \
src/domain/UBAngleWidget.cpp src/domain/UBAngleWidget.cpp \
src/domain/UBGraphicsStrokesGroup.cpp
SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ SOURCES += src/domain/UBGraphicsItemDelegate.cpp \
src/domain/UBGraphicsVideoItemDelegate.cpp \ src/domain/UBGraphicsVideoItemDelegate.cpp \

@ -87,3 +87,9 @@ bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item)
return false; return false;
} }
void UBCoreGraphicsScene::removeItemFromDeletion(QGraphicsItem *item)
{
if(NULL != item){
mItemsToDelete.remove(item);
}
}

@ -30,6 +30,7 @@ class UBCoreGraphicsScene : public QGraphicsScene
virtual bool deleteItem(QGraphicsItem* item); virtual bool deleteItem(QGraphicsItem* item);
void removeItemFromDeletion(QGraphicsItem* item);
private: private:
QSet<QGraphicsItem*> mItemsToDelete; QSet<QGraphicsItem*> mItemsToDelete;

Loading…
Cancel
Save