@ -263,7 +263,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
, mCrossedBackground ( false )
, mCrossedBackground ( false )
, mIsDesktopMode ( false )
, mIsDesktopMode ( false )
, mZoomFactor ( 1 )
, mZoomFactor ( 1 )
, mIsModified ( true )
, mBackgroundObject ( 0 )
, mBackgroundObject ( 0 )
, mPreviousWidth ( 0 )
, mPreviousWidth ( 0 )
, mInputDeviceIsPressed ( false )
, mInputDeviceIsPressed ( false )
@ -305,7 +304,10 @@ UBGraphicsScene::~UBGraphicsScene()
{
{
if ( mCurrentStroke )
if ( mCurrentStroke )
if ( mCurrentStroke - > polygons ( ) . empty ( ) )
if ( mCurrentStroke - > polygons ( ) . empty ( ) )
{
delete mCurrentStroke ;
delete mCurrentStroke ;
mCurrentStroke = NULL ;
}
if ( mZLayerController )
if ( mZLayerController )
delete mZLayerController ;
delete mZLayerController ;
@ -433,6 +435,11 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
}
}
}
}
if ( mCurrentStroke & & mCurrentStroke - > polygons ( ) . empty ( ) ) {
delete mCurrentStroke ;
mCurrentStroke = NULL ;
}
return accepted ;
return accepted ;
}
}
@ -474,6 +481,10 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
UBCoreGraphicsScene : : removeItemFromDeletion ( mpLastPolygon ) ;
UBCoreGraphicsScene : : removeItemFromDeletion ( mpLastPolygon ) ;
mAddedItems . remove ( mpLastPolygon ) ;
mAddedItems . remove ( mpLastPolygon ) ;
mCurrentStroke - > remove ( mpLastPolygon ) ;
mCurrentStroke - > remove ( mpLastPolygon ) ;
if ( mCurrentStroke - > polygons ( ) . empty ( ) ) {
delete mCurrentStroke ;
mCurrentStroke = NULL ;
}
removeItem ( mpLastPolygon ) ;
removeItem ( mpLastPolygon ) ;
mPreviousPolygonItems . removeAll ( mpLastPolygon ) ;
mPreviousPolygonItems . removeAll ( mpLastPolygon ) ;
}
}
@ -891,25 +902,18 @@ void UBGraphicsScene::recolorAllItems()
view - > setViewportUpdateMode ( QGraphicsView : : NoViewportUpdate ) ;
view - > setViewportUpdateMode ( QGraphicsView : : NoViewportUpdate ) ;
}
}
for ( int i = 0 ; i < mFastAccessItems . size ( ) ; i + + )
bool currentIslight = isLightBackground ( ) ;
{
foreach ( QGraphicsItem * item , items ( ) ) {
UBGraphicsPolygonItem * polygonItem = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( mFastAccessItems . at ( i ) ) ;
if ( item - > type ( ) = = UBGraphicsStrokesGroup : : Type ) {
UBGraphicsStrokesGroup * curGroup = static_cast < UBGraphicsStrokesGroup * > ( item ) ;
if ( polygonItem )
QColor compareColor = curGroup - > color ( currentIslight ? UBGraphicsStrokesGroup : : colorOnDarkBackground
{
: UBGraphicsStrokesGroup : : colorOnLightBackground ) ;
QColor color ;
if ( mDarkBackground )
if ( curGroup - > color ( ) = = compareColor ) {
{
QColor newColor = curGroup - > color ( ! currentIslight ? UBGraphicsStrokesGroup : : colorOnDarkBackground
color = polygonItem - > colorOnDarkBackground ( ) ;
: UBGraphicsStrokesGroup : : colorOnLightBackground ) ;
}
curGroup - > setColor ( newColor ) ;
else
{
color = polygonItem - > colorOnLightBackground ( ) ;
}
}
polygonItem - > setColor ( color ) ;
continue ;
}
}
}
}
@ -1060,116 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const
return sceneDeepCopy ( ) ;
return sceneDeepCopy ( ) ;
}
}
void UBGraphicsScene : : clearItemsAndAnnotations ( )
void UBGraphicsScene : : clearContent ( clearCase pCase )
{
{
deselectAllItems ( ) ;
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QSet < QGraphicsItem * > removedItems ;
QListIterator < QGraphicsItem * > itItems ( mFastAccessItems ) ;
switch ( pCase ) {
case clearBackground :
while ( itItems . hasNext ( ) )
removeItem ( mBackgroundObject ) ;
{
removedItems < < mBackgroundObject ;
QGraphicsItem * item = itItems . next ( ) ;
break ;
if ( ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) )
{
removeItem ( item ) ;
removedItems < < item ;
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
case clearItemsAndAnnotations :
update ( sceneRect ( ) ) ;
case clearItems :
case clearAnnotations :
foreach ( QGraphicsItem * item , items ( ) ) {
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
bool isGroup = item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ;
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
bool isStrokesGroup = item - > type ( ) = = UBGraphicsStrokesGroup : : Type ;
UBApplication : : undoStack - > push ( uc ) ;
}
setDocumentUpdated ( ) ;
UBGraphicsGroupContainerItem * itemGroup = item - > parentItem ( )
? qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item - > parentItem ( ) )
: 0 ;
UBGraphicsItemDelegate * curDelegate = UBGraphicsItem : : Delegate ( item ) ;
if ( ! curDelegate ) {
continue ;
}
}
void UBGraphicsScene : : clearItems ( )
bool shouldDelete = false ;
{
switch ( static_cast < int > ( pCase ) ) {
deselectAllItems ( ) ;
case clearAnnotations :
shouldDelete = isStrokesGroup ;
QSet < QGraphicsItem * > emptyList ;
break ;
QSet < QGraphicsItem * > removedItems ;
case clearItems :
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) & & ! isStrokesGroup ;
QListIterator < QGraphicsItem * > itItems ( mFastAccessItems ) ;
break ;
case clearItemsAndAnnotations :
while ( itItems . hasNext ( ) )
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) ;
{
break ;
QGraphicsItem * item = itItems . next ( ) ;
if ( ! item - > parentItem ( ) )
{
UBGraphicsPolygonItem * pi = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
if ( ! pi & & ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) )
{
removeItem ( item ) ;
removedItems < < item ;
}
}
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
if ( shouldDelete ) {
update ( sceneRect ( ) ) ;
if ( itemGroup ) {
itemGroup - > removeFromGroup ( item ) ;
if ( itemGroup - > childItems ( ) . count ( ) = = 1 ) {
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
itemGroup - > destroy ( ) ;
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
}
itemGroup - > Delegate ( ) - > update ( ) ;
setDocumentUpdated ( ) ;
}
}
void UBGraphicsScene : : clearAnnotations ( )
curDelegate - > remove ( false ) ;
{
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QListIterator < QGraphicsItem * > itItems ( mFastAccessItems ) ;
while ( itItems . hasNext ( ) )
{
QGraphicsItem * item = itItems . next ( ) ;
UBGraphicsStrokesGroup * pi = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ;
if ( pi )
{
removeItem ( item ) ;
removedItems < < item ;
removedItems < < item ;
}
}
}
}
break ;
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
update ( sceneRect ( ) ) ;
update ( sceneRect ( ) ) ;
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , emptyList ) ;
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , removedItems , QSet < QGraphicsItem * > ( ) ) ;
UBApplication : : undoStack - > push ( uc ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
}
setDocumentUpdated ( ) ;
if ( pCase = = clearBackground ) {
}
void UBGraphicsScene : : clearBackground ( )
{
if ( mBackgroundObject ) {
removeItem ( mBackgroundObject ) ;
if ( enableUndoRedoStack ) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , mBackgroundObject , NULL ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
mBackgroundObject = 0 ;
mBackgroundObject = 0 ;
}
}
update ( sceneRect ( ) ) ;
setDocumentUpdated ( ) ;
setDocumentUpdated ( ) ;
}
}
@ -1364,6 +1324,7 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
{
{
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
addItem ( groupItem ) ;
foreach ( QGraphicsItem * item , items ) {
foreach ( QGraphicsItem * item , items ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ) {
QList < QGraphicsItem * > childItems = item - > childItems ( ) ;
QList < QGraphicsItem * > childItems = item - > childItems ( ) ;
@ -1373,13 +1334,14 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
}
}
foreach ( QGraphicsItem * chItem , childItems ) {
foreach ( QGraphicsItem * chItem , childItems ) {
groupItem - > addToGroup ( chItem ) ;
groupItem - > addToGroup ( chItem ) ;
mFastAccessItems . removeAll ( chItem ) ;
}
}
} else {
} else {
groupItem - > addToGroup ( item ) ;
groupItem - > addToGroup ( item ) ;
mFastAccessItems . removeAll ( item ) ;
}
}
}
}
addItem ( groupItem ) ;
groupItem - > setVisible ( true ) ;
groupItem - > setVisible ( true ) ;
groupItem - > setFocus ( ) ;
groupItem - > setFocus ( ) ;
@ -1396,6 +1358,15 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
void UBGraphicsScene : : addGroup ( UBGraphicsGroupContainerItem * groupItem )
void UBGraphicsScene : : addGroup ( UBGraphicsGroupContainerItem * groupItem )
{
{
addItem ( groupItem ) ;
addItem ( groupItem ) ;
for ( int i = 0 ; i < groupItem - > childItems ( ) . count ( ) ; i + + )
{
QGraphicsItem * it = qgraphicsitem_cast < QGraphicsItem * > ( groupItem - > childItems ( ) . at ( i ) ) ;
if ( it )
{
mFastAccessItems . removeAll ( it ) ;
}
}
groupItem - > setVisible ( true ) ;
groupItem - > setVisible ( true ) ;
groupItem - > setFocus ( ) ;
groupItem - > setFocus ( ) ;
@ -1564,7 +1535,6 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const Q
void UBGraphicsScene : : addItem ( QGraphicsItem * item )
void UBGraphicsScene : : addItem ( QGraphicsItem * item )
{
{
setModified ( true ) ;
UBCoreGraphicsScene : : addItem ( item ) ;
UBCoreGraphicsScene : : addItem ( item ) ;
UBGraphicsItem : : assignZValue ( item , mZLayerController - > generateZLevel ( item ) ) ;
UBGraphicsItem : : assignZValue ( item , mZLayerController - > generateZLevel ( item ) ) ;
@ -1577,8 +1547,6 @@ void UBGraphicsScene::addItem(QGraphicsItem* item)
void UBGraphicsScene : : addItems ( const QSet < QGraphicsItem * > & items )
void UBGraphicsScene : : addItems ( const QSet < QGraphicsItem * > & items )
{
{
setModified ( true ) ;
foreach ( QGraphicsItem * item , items ) {
foreach ( QGraphicsItem * item , items ) {
UBCoreGraphicsScene : : addItem ( item ) ;
UBCoreGraphicsScene : : addItem ( item ) ;
UBGraphicsItem : : assignZValue ( item , mZLayerController - > generateZLevel ( item ) ) ;
UBGraphicsItem : : assignZValue ( item , mZLayerController - > generateZLevel ( item ) ) ;
@ -1591,7 +1559,7 @@ void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
void UBGraphicsScene : : removeItem ( QGraphicsItem * item )
void UBGraphicsScene : : removeItem ( QGraphicsItem * item )
{
{
setModified ( tru e) ;
item - > setSelected ( fals e) ;
UBCoreGraphicsScene : : removeItem ( item ) ;
UBCoreGraphicsScene : : removeItem ( item ) ;
UBApplication : : boardController - > freezeW3CWidget ( item , true ) ;
UBApplication : : boardController - > freezeW3CWidget ( item , true ) ;
@ -1603,8 +1571,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
void UBGraphicsScene : : removeItems ( const QSet < QGraphicsItem * > & items )
void UBGraphicsScene : : removeItems ( const QSet < QGraphicsItem * > & items )
{
{
setModified ( true ) ;
foreach ( QGraphicsItem * item , items )
foreach ( QGraphicsItem * item , items )
UBCoreGraphicsScene : : removeItem ( item ) ;
UBCoreGraphicsScene : : removeItem ( item ) ;
@ -1762,7 +1728,6 @@ void UBGraphicsScene::addRuler(QPointF center)
addItem ( ruler ) ;
addItem ( ruler ) ;
ruler - > setVisible ( true ) ;
ruler - > setVisible ( true ) ;
setModified ( true ) ;
}
}
void UBGraphicsScene : : addProtractor ( QPointF center )
void UBGraphicsScene : : addProtractor ( QPointF center )
@ -1780,7 +1745,6 @@ void UBGraphicsScene::addProtractor(QPointF center)
protractor - > moveBy ( center . x ( ) - itemSceneCenter . x ( ) , center . y ( ) - itemSceneCenter . y ( ) ) ;
protractor - > moveBy ( center . x ( ) - itemSceneCenter . x ( ) , center . y ( ) - itemSceneCenter . y ( ) ) ;
protractor - > setVisible ( true ) ;
protractor - > setVisible ( true ) ;
setModified ( true ) ;
}
}
void UBGraphicsScene : : addTriangle ( QPointF center )
void UBGraphicsScene : : addTriangle ( QPointF center )
@ -1798,7 +1762,6 @@ void UBGraphicsScene::addTriangle(QPointF center)
triangle - > moveBy ( center . x ( ) - itemSceneCenter . x ( ) , center . y ( ) - itemSceneCenter . y ( ) ) ;
triangle - > moveBy ( center . x ( ) - itemSceneCenter . x ( ) , center . y ( ) - itemSceneCenter . y ( ) ) ;
triangle - > setVisible ( true ) ;
triangle - > setVisible ( true ) ;
setModified ( true ) ;
}
}
void UBGraphicsScene : : addMagnifier ( UBMagnifierParams params )
void UBGraphicsScene : : addMagnifier ( UBMagnifierParams params )
@ -1857,6 +1820,7 @@ void UBGraphicsScene::moveMagnifier()
{
{
QPoint magnifierPos = QPoint ( magniferControlViewWidget - > pos ( ) . x ( ) + magniferControlViewWidget - > size ( ) . width ( ) / 2 , magniferControlViewWidget - > pos ( ) . y ( ) + magniferControlViewWidget - > size ( ) . height ( ) / 2 ) ;
QPoint magnifierPos = QPoint ( magniferControlViewWidget - > pos ( ) . x ( ) + magniferControlViewWidget - > size ( ) . width ( ) / 2 , magniferControlViewWidget - > pos ( ) . y ( ) + magniferControlViewWidget - > size ( ) . height ( ) / 2 ) ;
moveMagnifier ( magnifierPos , true ) ;
moveMagnifier ( magnifierPos , true ) ;
setModified ( true ) ;
}
}
}
}
@ -1889,6 +1853,7 @@ void UBGraphicsScene::moveMagnifier(QPoint newPos, bool forceGrab)
void UBGraphicsScene : : closeMagnifier ( )
void UBGraphicsScene : : closeMagnifier ( )
{
{
DisposeMagnifierQWidgets ( ) ;
DisposeMagnifierQWidgets ( ) ;
setModified ( true ) ;
}
}
void UBGraphicsScene : : zoomInMagnifier ( )
void UBGraphicsScene : : zoomInMagnifier ( )
@ -1906,6 +1871,7 @@ void UBGraphicsScene::zoomOutMagnifier()
{
{
magniferControlViewWidget - > setZoom ( magniferControlViewWidget - > params . zoom - 0.5 ) ;
magniferControlViewWidget - > setZoom ( magniferControlViewWidget - > params . zoom - 0.5 ) ;
magniferDisplayViewWidget - > setZoom ( magniferDisplayViewWidget - > params . zoom - 0.5 ) ;
magniferDisplayViewWidget - > setZoom ( magniferDisplayViewWidget - > params . zoom - 0.5 ) ;
setModified ( true ) ;
}
}
}
}
@ -1917,6 +1883,7 @@ void UBGraphicsScene::resizedMagnifier(qreal newPercent)
magniferControlViewWidget - > grabPoint ( ) ;
magniferControlViewWidget - > grabPoint ( ) ;
magniferDisplayViewWidget - > setSize ( newPercent ) ;
magniferDisplayViewWidget - > setSize ( newPercent ) ;
magniferDisplayViewWidget - > grabPoint ( ) ;
magniferDisplayViewWidget - > grabPoint ( ) ;
setModified ( true ) ;
}
}
}
}
@ -1932,7 +1899,6 @@ void UBGraphicsScene::addCompass(QPointF center)
compass - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Tool ) ) ;
compass - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Tool ) ) ;
compass - > setVisible ( true ) ;
compass - > setVisible ( true ) ;
setModified ( true ) ;
}
}
void UBGraphicsScene : : addCache ( )
void UBGraphicsScene : : addCache ( )
@ -1962,7 +1928,6 @@ void UBGraphicsScene::addMask(const QPointF ¢er)
curtain - > setRect ( rect ) ;
curtain - > setRect ( rect ) ;
curtain - > setVisible ( true ) ;
curtain - > setVisible ( true ) ;
curtain - > setSelected ( true ) ;
curtain - > setSelected ( true ) ;
setModified ( true ) ;
}
}
void UBGraphicsScene : : setRenderingQuality ( UBItem : : RenderingQuality pRenderingQuality )
void UBGraphicsScene : : setRenderingQuality ( UBItem : : RenderingQuality pRenderingQuality )
@ -2212,7 +2177,6 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
default :
default :
{
{
item - > setSelected ( false ) ;
UBGraphicsItem * ubgi = dynamic_cast < UBGraphicsItem * > ( item ) ;
UBGraphicsItem * ubgi = dynamic_cast < UBGraphicsItem * > ( item ) ;
if ( 0 ! = ubgi )
if ( 0 ! = ubgi )
ubgi - > remove ( ) ;
ubgi - > remove ( ) ;
@ -2274,6 +2238,11 @@ void UBGraphicsScene::setToolCursor(int tool)
{
{
deselectAllItems ( ) ;
deselectAllItems ( ) ;
}
}
if ( mCurrentStroke & & mCurrentStroke - > polygons ( ) . empty ( ) ) {
delete mCurrentStroke ;
}
mCurrentStroke = NULL ;
}
}
void UBGraphicsScene : : initStroke ( ) {
void UBGraphicsScene : : initStroke ( ) {