@ -902,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 ;
}
}
@ -1071,106 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const
return sceneDeepCopy ( ) ;
}
void UBGraphicsScene : : clearItemsAndAnnotations ( )
{
deselectAllItems ( ) ;
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
foreach ( QGraphicsItem * item , sceneItems )
{
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 ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
foreach ( QGraphicsItem * item , sceneItems )
{
bool isGroup = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item ) ! = NULL ;
bool isPolygon = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ! = NULL ;
bool isStrokesGroup = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ! = NULL ;
if ( ! isGroup & & ! isPolygon & & ! isStrokesGroup & & ! 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 ) ;
}
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 ;
}
setDocumentUpdated ( ) ;
}
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 ;
}
void UBGraphicsScene : : clearAnnotations ( )
{
QSet < QGraphicsItem * > emptyList ;
QSet < QGraphicsItem * > removedItems ;
if ( shouldDelete ) {
if ( itemGroup ) {
itemGroup - > removeFromGroup ( item ) ;
if ( itemGroup - > childItems ( ) . count ( ) = = 1 ) {
itemGroup - > destroy ( ) ;
}
itemGroup - > Delegate ( ) - > update ( ) ;
}
QList < QGraphicsItem * > sceneItems = items ( ) ;
foreach ( QGraphicsItem * item , sceneItems )
{
UBGraphicsStrokesGroup * pi = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ;
if ( pi )
{
removeItem ( item ) ;
removedItems < < 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 : : 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,8 +1323,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con
UBGraphicsGroupContainerItem * UBGraphicsScene : : createGroup ( QList < QGraphicsItem * > items )
{
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
addItem ( groupItem ) ;
addItem ( groupItem ) ;
foreach ( QGraphicsItem * item , items ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type ) {
QList < QGraphicsItem * > childItems = item - > childItems ( ) ;