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