@ -902,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 ;
}
}
}
}
@ -1071,106 +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 ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
switch ( pCase ) {
foreach ( QGraphicsItem * item , sceneItems )
case clearBackground :
{
removeItem ( mBackgroundObject ) ;
if ( ! mTools . contains ( item ) & & ! isBackgroundObject ( item ) )
removedItems < < mBackgroundObject ;
{
break ;
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 ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
break ;
foreach ( QGraphicsItem * item , sceneItems )
case clearItemsAndAnnotations :
{
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) ;
bool isGroup = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item ) ! = NULL ;
break ;
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
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 ;
QList < QGraphicsItem * > sceneItems = items ( ) ;
foreach ( QGraphicsItem * item , sceneItems )
{
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,8 +1323,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con
UBGraphicsGroupContainerItem * UBGraphicsScene : : createGroup ( QList < QGraphicsItem * > items )
UBGraphicsGroupContainerItem * UBGraphicsScene : : createGroup ( QList < QGraphicsItem * > items )
{
{
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
UBGraphicsGroupContainerItem * groupItem = new UBGraphicsGroupContainerItem ( ) ;
addItem ( groupItem ) ;
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 ( ) ;