@ -1,7 +1,7 @@
/*
/*
* This program is free software : you can redistribute it and / or modify
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 2 of the License , or
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
* ( at your option ) any later version .
*
*
* This program is distributed in the hope that it will be useful ,
* This program is distributed in the hope that it will be useful ,
@ -72,9 +72,8 @@
//#include <typeinfo>
//#include <typeinfo>
UBBoardController : : UBBoardController ( UBMainWindow * mainWindow )
UBBoardController : : UBBoardController ( UBMainWindow * mainWindow )
: QObject ( mainWindow - > centralWidget ( ) )
: UBDocumentContainer ( mainWindow - > centralWidget ( ) )
, mMainWindow ( mainWindow )
, mMainWindow ( mainWindow )
, mActiveDocument ( 0 )
, mActiveScene ( 0 )
, mActiveScene ( 0 )
, mActiveSceneIndex ( - 1 )
, mActiveSceneIndex ( - 1 )
, mPaletteManager ( 0 )
, mPaletteManager ( 0 )
@ -88,7 +87,6 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow)
, mIsClosing ( false )
, mIsClosing ( false )
, mSystemScaleFactor ( 1.0 )
, mSystemScaleFactor ( 1.0 )
, mCleanupDone ( false )
, mCleanupDone ( false )
, mCacheWidgetIsEnabled ( false )
{
{
mZoomFactor = UBSettings : : settings ( ) - > boardZoomFactor - > get ( ) . toDouble ( ) ;
mZoomFactor = UBSettings : : settings ( ) - > boardZoomFactor - > get ( ) . toDouble ( ) ;
@ -107,17 +105,17 @@ void UBBoardController::init()
setupViews ( ) ;
setupViews ( ) ;
setupToolbar ( ) ;
setupToolbar ( ) ;
connect ( UBPersistenceManager : : persistenceManager ( ) , SIGNAL ( documentWillBeDeleted ( UBDocumentProxy * ) )
//connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentWillBeDeleted(UBDocumentProxy*))
, this , SLOT ( documentWillBeDeleted ( UBDocumentProxy * ) ) ) ;
// , this, SLOT(documentWillBeDeleted(UBDocumentProxy*)));
connect ( UBPersistenceManager : : persistenceManager ( ) , SIGNAL ( documentSceneCreated ( UBDocumentProxy * , int ) )
//connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneCreated(UBDocumentProxy*, int))
, this , SLOT ( documentSceneChanged ( UBDocumentProxy * , int ) ) ) ;
// , this, SLOT(documentSceneChanged(UBDocumentProxy*, int)));
connect ( UBPersistenceManager : : persistenceManager ( ) , SIGNAL ( documentSceneDeleted ( UBDocumentProxy * , int ) )
//connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneDeleted(UBDocumentProxy*, int))
, this , SLOT ( documentSceneChanged ( UBDocumentProxy * , int ) ) ) ;
// , this, SLOT(documentSceneChanged(UBDocumentProxy*, int)));
connect ( UBPersistenceManager : : persistenceManager ( ) , SIGNAL ( documentSceneMoved ( UBDocumentProxy * , int ) )
//connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneMoved(UBDocumentProxy*, int))
, this , SLOT ( documentSceneChanged ( UBDocumentProxy * , int ) ) ) ;
// , this, SLOT(documentSceneChanged(UBDocumentProxy*, int)));
connect ( UBApplication : : undoStack , SIGNAL ( canUndoChanged ( bool ) )
connect ( UBApplication : : undoStack , SIGNAL ( canUndoChanged ( bool ) )
, this , SLOT ( undoRedoStateChange ( bool ) ) ) ;
, this , SLOT ( undoRedoStateChange ( bool ) ) ) ;
@ -160,20 +158,6 @@ int UBBoardController::currentPage()
return mActiveSceneIndex + 1 ;
return mActiveSceneIndex + 1 ;
}
}
int UBBoardController : : pageFromSceneIndex ( int sceneIndex )
{
if ( UBSettings : : settings ( ) - > teacherGuidePageZeroActivated - > get ( ) . toBool ( ) )
return sceneIndex ;
return sceneIndex + 1 ;
}
int UBBoardController : : sceneIndexFromPage ( int page )
{
if ( UBSettings : : settings ( ) - > teacherGuidePageZeroActivated - > get ( ) . toBool ( ) )
return page - 1 ;
return page ;
}
void UBBoardController : : setupViews ( )
void UBBoardController : : setupViews ( )
{
{
mControlContainer = new QWidget ( mMainWindow - > centralWidget ( ) ) ;
mControlContainer = new QWidget ( mMainWindow - > centralWidget ( ) ) ;
@ -400,11 +384,6 @@ void UBBoardController::stopScript()
freezeW3CWidgets ( true ) ;
freezeW3CWidgets ( true ) ;
}
}
bool UBBoardController : : cacheIsVisible ( )
{
return mCacheWidgetIsEnabled ;
}
void UBBoardController : : initToolbarTexts ( )
void UBBoardController : : initToolbarTexts ( )
{
{
QList < QAction * > allToolbarActions ;
QList < QAction * > allToolbarActions ;
@ -480,12 +459,12 @@ void UBBoardController::addScene()
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
UBPersistenceManager : : persistenceManager ( ) - > createDocumentSceneAt ( mActiveDocument , mActiveSceneIndex + 1 ) ;
UBDocumentContainer : : addPage ( mActiveSceneIndex + 1 ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
setActiveDocumentScene ( mActiveDocument , mActive SceneIndex + 1 ) ;
setActiveDocumentScene ( mActiveSceneIndex + 1 ) ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : restoreOverrideCursor ( ) ;
emit newPageAdded ( ) ;
}
}
@ -495,12 +474,12 @@ void UBBoardController::addScene(UBGraphicsScene* scene, bool replaceActiveIfEmp
{
{
UBGraphicsScene * clone = scene - > sceneDeepCopy ( ) ;
UBGraphicsScene * clone = scene - > sceneDeepCopy ( ) ;
if ( scene - > document ( ) & & ( scene - > document ( ) ! = mActiveDocument ) )
if ( scene - > document ( ) & & ( scene - > document ( ) ! = selectedDocument ( ) ) )
{
{
foreach ( QUrl relativeFile , scene - > relativeDependencies ( ) )
foreach ( QUrl relativeFile , scene - > relativeDependencies ( ) )
{
{
QString source = scene - > document ( ) - > persistencePath ( ) + " / " + relativeFile . toString ( ) ;
QString source = scene - > document ( ) - > persistencePath ( ) + " / " + relativeFile . toString ( ) ;
QString target = mActiveDocument - > persistencePath ( ) + " / " + relativeFile . toString ( ) ;
QString target = selectedDocument ( ) - > persistencePath ( ) + " / " + relativeFile . toString ( ) ;
QFileInfo fi ( target ) ;
QFileInfo fi ( target ) ;
QDir d = fi . dir ( ) ;
QDir d = fi . dir ( ) ;
@ -512,17 +491,16 @@ void UBBoardController::addScene(UBGraphicsScene* scene, bool replaceActiveIfEmp
if ( replaceActiveIfEmpty & & mActiveScene - > isEmpty ( ) )
if ( replaceActiveIfEmpty & & mActiveScene - > isEmpty ( ) )
{
{
UBPersistenceManager : : persistenceManager ( ) - > persistDocumentScene ( mActiveDocument , clone , mActiveSceneIndex ) ;
setActiveDocumentScene ( mActiveSceneIndex ) ;
setActiveDocumentScene ( mActiveDocument , mActiveSceneIndex ) ;
}
}
else
else
{
{
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
UBPersistenceManager : : persistenceManager ( ) - > insertDocumentSceneAt ( mActiveDocument , clone , mActiveSceneIndex + 1 ) ;
UBPersistenceManager : : persistenceManager ( ) - > insertDocumentSceneAt ( selectedDocument ( ) , clone , mActiveSceneIndex + 1 ) ;
setActiveDocumentScene ( mActiveDocument , mActive SceneIndex + 1 ) ;
setActiveDocumentScene ( mActiveSceneIndex + 1 ) ;
}
}
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
}
}
}
}
@ -537,22 +515,48 @@ void UBBoardController::addScene(UBDocumentProxy* proxy, int sceneIndex, bool re
}
}
}
}
void UBBoardController : : duplicateScene ( int nIndex )
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
QList < int > scIndexes ;
scIndexes < < nIndex ;
duplicatePages ( scIndexes ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
setActiveDocumentScene ( nIndex + 1 ) ;
QApplication : : restoreOverrideCursor ( ) ;
emit pageChanged ( ) ;
}
void UBBoardController : : duplicateScene ( )
void UBBoardController : : duplicateScene ( )
{
{
if ( UBApplication : : applicationController - > displayMode ( ) ! = UBApplicationController : : Board )
if ( UBApplication : : applicationController - > displayMode ( ) ! = UBApplicationController : : Board )
return ;
return ;
duplicateScene ( mActiveSceneIndex ) ;
}
void UBBoardController : : deleteScene ( int nIndex )
{
if ( selectedDocument ( ) - > pageCount ( ) > 2 )
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
UBPersistenceManager : : persistenceManager ( ) - > duplicateDocumentScene ( mActiveDocument , mActiveSceneIndex ) ;
QList < int > scIndexes ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
scIndexes < < nIndex ;
deletePages ( scIndexes ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
setActiveDocumentScene ( mActiveDocument , mActiveSceneIndex + 1 ) ;
QApplication : : restoreOverrideCursor ( ) ;
emit pageChanged ( ) ;
if ( nIndex > = pageCount ( ) )
nIndex = pageCount ( ) - 1 ;
setActiveDocumentScene ( nIndex ) ;
QApplication : : restoreOverrideCursor ( ) ;
}
}
}
@ -598,7 +602,7 @@ void UBBoardController::clearSceneBackground()
void UBBoardController : : showDocumentsDialog ( )
void UBBoardController : : showDocumentsDialog ( )
{
{
if ( mActiveDocument )
if ( selectedDocument ( ) )
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
UBApplication : : mainWindow - > actionLibrary - > setChecked ( false ) ;
UBApplication : : mainWindow - > actionLibrary - > setChecked ( false ) ;
@ -725,7 +729,7 @@ void UBBoardController::previousScene()
{
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
setActiveDocumentScene ( mActiveDocument , mActive SceneIndex - 1 ) ;
setActiveDocumentScene ( mActiveSceneIndex - 1 ) ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : restoreOverrideCursor ( ) ;
}
}
@ -736,11 +740,11 @@ void UBBoardController::previousScene()
void UBBoardController : : nextScene ( )
void UBBoardController : : nextScene ( )
{
{
if ( mActiveSceneIndex < mActiveDocument - > pageCount ( ) - 1 )
if ( mActiveSceneIndex < selectedDocument ( ) - > pageCount ( ) - 1 )
{
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
setActiveDocumentScene ( mActiveDocument , mActive SceneIndex + 1 ) ;
setActiveDocumentScene ( mActiveSceneIndex + 1 ) ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : restoreOverrideCursor ( ) ;
}
}
@ -755,7 +759,7 @@ void UBBoardController::firstScene()
{
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
setActiveDocumentScene ( mActiveDocument , 0 ) ;
setActiveDocumentScene ( 0 ) ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : restoreOverrideCursor ( ) ;
}
}
@ -766,11 +770,11 @@ void UBBoardController::firstScene()
void UBBoardController : : lastScene ( )
void UBBoardController : : lastScene ( )
{
{
if ( mActiveSceneIndex < mActiveDocument - > pageCount ( ) - 1 )
if ( mActiveSceneIndex < selectedDocument ( ) - > pageCount ( ) - 1 )
{
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
persistCurrentScene ( ) ;
persistCurrentScene ( ) ;
setActiveDocumentScene ( mActiveDocument , mActiveDocument - > pageCount ( ) - 1 ) ;
setActiveDocumentScene ( selectedDocument ( ) - > pageCount ( ) - 1 ) ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : restoreOverrideCursor ( ) ;
}
}
@ -855,13 +859,9 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
void UBBoardController : : downloadFinished ( bool pSuccess , QUrl sourceUrl , QString pContentTypeHeader , QByteArray pData , QPointF pPos , QSize pSize , bool isBackground )
void UBBoardController : : downloadFinished ( bool pSuccess , QUrl sourceUrl , QString pContentTypeHeader , QByteArray pData , QPointF pPos , QSize pSize , bool isBackground )
{
{
QGraphicsItem * oldBackgroundObject = NULL ;
if ( isBackground )
oldBackgroundObject = mActiveScene - > backgroundObject ( ) ;
QString mimeType = pContentTypeHeader ;
QString mimeType = pContentTypeHeader ;
// In some cases "image/jpeg;charset=" is returned by the drag-n-drop. That is
// In some cases "image/jpeg;charset=" is retourned by the drag-n-drop. That is
// why we will check if an ; exists and take the first part (the standard allows this kind of mimetype)
// why we will check if an ; exists and take the first part (the standard allows this kind of mimetype)
int position = mimeType . indexOf ( " ; " ) ;
int position = mimeType . indexOf ( " ; " ) ;
if ( position ! = - 1 )
if ( position ! = - 1 )
@ -977,7 +977,7 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
QUuid uuid = QUuid : : createUuid ( ) ;
QUuid uuid = QUuid : : createUuid ( ) ;
QUrl url = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
QUrl url = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
- > addVideoFileToDocument ( mActiveDocument , sourceUrl , pData , uuid ) ) ;
- > addVideoFileToDocument ( selectedDocument ( ) , sourceUrl , pData , uuid ) ) ;
mediaVideoItem = mActiveScene - > addMedia ( url , false , pPos ) ;
mediaVideoItem = mActiveScene - > addMedia ( url , false , pPos ) ;
@ -1006,9 +1006,10 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
QUuid uuid = QUuid : : createUuid ( ) ;
QUuid uuid = QUuid : : createUuid ( ) ;
QUrl url = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
QUrl url = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
- > addVideoFileToDocument ( mActiveDocument , sourceUrl , pData , uuid ) ) ;
- > addVideoFileToDocument ( selectedDocument ( ) , sourceUrl , pData , uuid ) ) ;
audioMediaItem = mActiveScene - > addMedia ( url , false , pPos ) ;
audioMediaItem = mActiveScene - > addMedia ( url , false , pPos ) ;
audioMediaItem - > setSourceUrl ( sourceUrl ) ;
audioMediaItem - > setSourceUrl ( sourceUrl ) ;
audioMediaItem - > setUuid ( uuid ) ;
audioMediaItem - > setUuid ( uuid ) ;
}
}
@ -1079,20 +1080,20 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
int result = 0 ;
int result = 0 ;
if ( ! sourceUrl . isEmpty ( ) ) {
if ( ! sourceUrl . isEmpty ( ) ) {
QFile sourceFile ( sourceUrl . toLocalFile ( ) ) ;
QFile sourceFile ( sourceUrl . toLocalFile ( ) ) ;
result = UBDocumentManager : : documentManager ( ) - > addFileToDocument ( mActiveDocument , sourceFile ) ;
result = UBDocumentManager : : documentManager ( ) - > addFileToDocument ( selectedDocument ( ) , sourceFile ) ;
}
}
else if ( pData . size ( ) ) {
else if ( pData . size ( ) ) {
QTemporaryFile pdfFile ( " XXXXXX.pdf " ) ;
QTemporaryFile pdfFile ( " XXXXXX.pdf " ) ;
if ( pdfFile . open ( ) )
if ( pdfFile . open ( ) )
{
{
pdfFile . write ( pData ) ;
pdfFile . write ( pData ) ;
result = UBDocumentManager : : documentManager ( ) - > addFileToDocument ( mActiveDocument , pdfFile ) ;
result = UBDocumentManager : : documentManager ( ) - > addFileToDocument ( selectedDocument ( ) , pdfFile ) ;
pdfFile . close ( ) ;
pdfFile . close ( ) ;
}
}
}
}
if ( result ) {
if ( result ) {
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
}
}
}
}
else if ( mimeType . startsWith ( " application/vnd.mnemis-uniboard-tool " ) )
else if ( mimeType . startsWith ( " application/vnd.mnemis-uniboard-tool " ) )
@ -1197,23 +1198,18 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString
UBApplication : : showMessage ( tr ( " Unknown content type %1 " ) . arg ( pContentTypeHeader ) ) ;
UBApplication : : showMessage ( tr ( " Unknown content type %1 " ) . arg ( pContentTypeHeader ) ) ;
qWarning ( ) < < " ignoring mime type " < < pContentTypeHeader ;
qWarning ( ) < < " ignoring mime type " < < pContentTypeHeader ;
}
}
if ( isBackground & & oldBackgroundObject ! = mActiveScene - > backgroundObject ( ) )
{
if ( mActiveScene - > isURStackIsEnabled ( ) ) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( mActiveScene , oldBackgroundObject , mActiveScene - > backgroundObject ( ) ) ;
UBApplication : : undoStack - > push ( uc ) ;
}
}
}
}
void UBBoardController : : setActiveDocumentScene ( int pSceneIndex )
{
setActiveDocumentScene ( selectedDocument ( ) , pSceneIndex ) ;
}
void UBBoardController : : setActiveDocumentScene ( UBDocumentProxy * pDocumentProxy , const int pSceneIndex )
void UBBoardController : : setActiveDocumentScene ( UBDocumentProxy * pDocumentProxy , const int pSceneIndex , bool forceReload )
{
{
saveViewState ( ) ;
saveViewState ( ) ;
bool documentChange = mActiveDocument ! = pDocumentProxy ;
bool documentChange = selectedDocument ( ) ! = pDocumentProxy ;
int index = pSceneIndex ;
int index = pSceneIndex ;
int sceneCount = pDocumentProxy - > pageCount ( ) ;
int sceneCount = pDocumentProxy - > pageCount ( ) ;
@ -1231,11 +1227,14 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
if ( sceneChange )
if ( sceneChange )
emit activeSceneWillChange ( ) ;
emit activeSceneWillChange ( ) ;
persistCurrentScene ( ) ;
ClearUndoStack ( ) ;
ClearUndoStack ( ) ;
mActiveScene = targetScene ;
mActiveScene = targetScene ;
mActiveDocument = pDocumentProxy ;
mActiveSceneIndex = index ;
mActiveSceneIndex = index ;
setDocument ( pDocumentProxy , forceReload ) ;
updateSystemScaleFactor ( ) ;
updateSystemScaleFactor ( ) ;
@ -1260,9 +1259,6 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
if ( documentChange )
if ( documentChange )
{
{
emit activeDocumentChanged ( ) ;
// Notify the navigator palette that the document has changed
emit setDocOnPageNavigator ( pDocumentProxy ) ;
UBGraphicsTextItem : : lastUsedTextColor = QColor ( ) ;
UBGraphicsTextItem : : lastUsedTextColor = QColor ( ) ;
}
}
@ -1274,6 +1270,22 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
}
}
}
}
void UBBoardController : : moveSceneToIndex ( int source , int target )
{
if ( selectedDocument ( ) )
{
persistCurrentScene ( ) ;
UBDocumentContainer : : movePageToIndex ( source , target ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
UBMetadataDcSubsetAdaptor : : persist ( selectedDocument ( ) ) ;
setActiveDocumentScene ( target ) ;
}
}
void UBBoardController : : ClearUndoStack ( )
void UBBoardController : : ClearUndoStack ( )
{
{
QSet < QGraphicsItem * > uniqueItems ;
QSet < QGraphicsItem * > uniqueItems ;
@ -1331,7 +1343,7 @@ void UBBoardController::adjustDisplayViews()
if ( UBApplication : : applicationController )
if ( UBApplication : : applicationController )
{
{
UBApplication : : applicationController - > adjustDisplayView ( ) ;
UBApplication : : applicationController - > adjustDisplayView ( ) ;
UBApplication : : applicationController - > adjustPreviousViews ( mActiveSceneIndex , mActiveDocument ) ;
UBApplication : : applicationController - > adjustPreviousViews ( mActiveSceneIndex , selectedDocument ( ) ) ;
}
}
}
}
@ -1381,7 +1393,7 @@ void UBBoardController::boardViewResized(QResizeEvent* event)
void UBBoardController : : documentWillBeDeleted ( UBDocumentProxy * pProxy )
void UBBoardController : : documentWillBeDeleted ( UBDocumentProxy * pProxy )
{
{
if ( mActiveDocument = = pProxy )
if ( selectedDocument ( ) = = pProxy )
{
{
if ( ! mIsClosing )
if ( ! mIsClosing )
setActiveDocumentScene ( UBPersistenceManager : : persistenceManager ( ) - > createDocument ( ) ) ;
setActiveDocumentScene ( UBPersistenceManager : : persistenceManager ( ) - > createDocument ( ) ) ;
@ -1411,6 +1423,7 @@ void UBBoardController::setDisabled(bool disable)
void UBBoardController : : selectionChanged ( )
void UBBoardController : : selectionChanged ( )
{
{
updateActionStates ( ) ;
updateActionStates ( ) ;
emit pageSelectionChanged ( activeSceneIndex ( ) ) ;
}
}
@ -1427,18 +1440,12 @@ void UBBoardController::undoRedoStateChange(bool canUndo)
void UBBoardController : : updateActionStates ( )
void UBBoardController : : updateActionStates ( )
{
{
mMainWindow - > actionBack - > setEnabled ( mActiveDocument & & ( mActiveSceneIndex > 0 ) ) ;
mMainWindow - > actionBack - > setEnabled ( selectedDocument ( ) & & ( mActiveSceneIndex > 0 ) ) ;
mMainWindow - > actionForward - > setEnabled ( mActiveDocument & & ( mActiveSceneIndex < mActiveDocument - > pageCount ( ) - 1 ) ) ;
mMainWindow - > actionForward - > setEnabled ( selectedDocument ( ) & & ( mActiveSceneIndex < selectedDocument ( ) - > pageCount ( ) - 1 ) ) ;
mMainWindow - > actionErase - > setEnabled ( mActiveScene & & ! mActiveScene - > isEmpty ( ) ) ;
mMainWindow - > actionErase - > setEnabled ( mActiveScene & & ! mActiveScene - > isEmpty ( ) ) ;
}
}
UBDocumentProxy * UBBoardController : : activeDocument ( ) const
{
return mActiveDocument ;
}
UBGraphicsScene * UBBoardController : : activeScene ( ) const
UBGraphicsScene * UBBoardController : : activeScene ( ) const
{
{
return mActiveScene ;
return mActiveScene ;
@ -1455,9 +1462,9 @@ void UBBoardController::documentSceneChanged(UBDocumentProxy* pDocumentProxy, in
{
{
Q_UNUSED ( pIndex ) ;
Q_UNUSED ( pIndex ) ;
if ( mActiveDocument = = pDocumentProxy )
if ( selectedDocument ( ) = = pDocumentProxy )
{
{
setActiveDocumentScene ( mActiveDocument , mActive SceneIndex ) ;
setActiveDocumentScene ( mActiveSceneIndex ) ;
}
}
}
}
@ -1472,9 +1479,9 @@ void UBBoardController::lastWindowClosed()
{
{
if ( ! mCleanupDone )
if ( ! mCleanupDone )
{
{
if ( mActiveDocument - > pageCount ( ) = = 1 & & ( ! mActiveScene | | mActiveScene - > isEmpty ( ) ) )
if ( selectedDocument ( ) - > pageCount ( ) = = 1 & & ( ! mActiveScene | | mActiveScene - > isEmpty ( ) ) )
{
{
UBPersistenceManager : : persistenceManager ( ) - > deleteDocument ( mActiveDocument ) ;
UBPersistenceManager : : persistenceManager ( ) - > deleteDocument ( selectedDocument ( ) ) ;
}
}
else
else
{
{
@ -1597,13 +1604,14 @@ void UBBoardController::show()
void UBBoardController : : persistCurrentScene ( )
void UBBoardController : : persistCurrentScene ( )
{
{
if ( UBPersistenceManager : : persistenceManager ( )
if ( UBPersistenceManager : : persistenceManager ( )
& & mActiveDocument & & mActiveScene
& & selectedDocument ( ) & & mActiveScene
& & ( mActiveSceneIndex > = 0 ) )
& & ( mActiveSceneIndex > = 0 )
& & mActiveScene - > isModified ( ) )
{
{
emit activeSceneWillBePersisted ( ) ;
emit activeSceneWillBePersisted ( ) ;
UBPersistenceManager : : persistenceManager ( ) - > persistDocumentScene ( mActiveDocument , mActiveScene , mActiveSceneIndex ) ;
UBPersistenceManager : : persistenceManager ( ) - > persistDocumentScene ( selectedDocument ( ) , mActiveScene , mActiveSceneIndex ) ;
UBMetadataDcSubsetAdaptor : : persist ( mActiveDocument ) ;
updatePage ( mActiveSceneIndex ) ;
}
}
}
}
@ -1688,7 +1696,7 @@ void UBBoardController::setPageSize(QSize newSize)
updateSystemScaleFactor ( ) ;
updateSystemScaleFactor ( ) ;
updatePageSizeState ( ) ;
updatePageSizeState ( ) ;
adjustDisplayViews ( ) ;
adjustDisplayViews ( ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
UBSettings : : settings ( ) - > pageSize - > set ( newSize ) ;
UBSettings : : settings ( ) - > pageSize - > set ( newSize ) ;
}
}
@ -1704,8 +1712,6 @@ void UBBoardController::notifyCache(bool visible)
{
{
emit cacheDisabled ( ) ;
emit cacheDisabled ( ) ;
}
}
mCacheWidgetIsEnabled = visible ;
}
}
void UBBoardController : : updatePageSizeState ( )
void UBBoardController : : updatePageSizeState ( )
@ -1811,7 +1817,7 @@ void UBBoardController::grabScene(const QRectF& pSceneRect)
mActiveScene - > setRenderingQuality ( UBItem : : RenderingQualityNormal ) ;
mActiveScene - > setRenderingQuality ( UBItem : : RenderingQualityNormal ) ;
mPaletteManager - > addItem ( QPixmap : : fromImage ( image ) ) ;
mPaletteManager - > addItem ( QPixmap : : fromImage ( image ) ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
}
}
}
}
@ -1839,11 +1845,16 @@ UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st
QUuid uuid = QUuid : : createUuid ( ) ;
QUuid uuid = QUuid : : createUuid ( ) ;
QUrl concreteUrl = pSourceUrl ;
QUrl concreteUrl = pSourceUrl ;
concreteUrl = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
# ifdef Q_WS_X11
concreteUrl = QUrl : : fromLocalFile ( mActiveDocument - > persistencePath ( ) + " / " + UBPersistenceManager : : persistenceManager ( )
- > addVideoFileToDocument ( mActiveDocument , pSourceUrl . toLocalFile ( ) , uuid ) ) ;
- > addVideoFileToDocument ( mActiveDocument , pSourceUrl . toLocalFile ( ) , uuid ) ) ;
# else
concreteUrl = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
- > addVideoFileToDocument ( selectedDocument ( ) , pSourceUrl . toLocalFile ( ) , uuid ) ) ;
# endif
UBGraphicsMediaItem * vi = mActiveScene - > addMedia ( concreteUrl , startPlay , pos ) ;
UBGraphicsMediaItem * vi = mActiveScene - > addMedia ( concreteUrl , startPlay , pos ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
if ( vi ) {
if ( vi ) {
vi - > setUuid ( uuid ) ;
vi - > setUuid ( uuid ) ;
@ -1859,11 +1870,16 @@ UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool st
QUuid uuid = QUuid : : createUuid ( ) ;
QUuid uuid = QUuid : : createUuid ( ) ;
QUrl concreteUrl = pSourceUrl ;
QUrl concreteUrl = pSourceUrl ;
concreteUrl = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
# ifdef Q_WS_X11
concreteUrl = QUrl : : fromLocalFile ( mActiveDocument - > persistencePath ( ) + " / " + UBPersistenceManager : : persistenceManager ( )
- > addAudioFileToDocument ( mActiveDocument , pSourceUrl . toLocalFile ( ) , uuid ) ) ;
- > addAudioFileToDocument ( mActiveDocument , pSourceUrl . toLocalFile ( ) , uuid ) ) ;
# else
concreteUrl = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( )
- > addAudioFileToDocument ( selectedDocument ( ) , pSourceUrl . toLocalFile ( ) , uuid ) ) ;
# endif
UBGraphicsMediaItem * ai = mActiveScene - > addMedia ( concreteUrl , startPlay , pos ) ;
UBGraphicsMediaItem * ai = mActiveScene - > addMedia ( concreteUrl , startPlay , pos ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
if ( ai ) {
if ( ai ) {
ai - > setUuid ( uuid ) ;
ai - > setUuid ( uuid ) ;
@ -1881,7 +1897,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP
QUuid uuid = QUuid : : createUuid ( ) ;
QUuid uuid = QUuid : : createUuid ( ) ;
QUrl newUrl = pUrl ;
QUrl newUrl = pUrl ;
newUrl = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( ) - > addGraphicsWidgteToDocument ( mActiveDocument , pUrl . toLocalFile ( ) , uuid ) ) ;
newUrl = QUrl : : fromLocalFile ( UBPersistenceManager : : persistenceManager ( ) - > addGraphicsWidgteToDocument ( selectedDocument ( ) , pUrl . toLocalFile ( ) , uuid ) ) ;
w3cWidgetItem = mActiveScene - > addW3CWidget ( newUrl , pos ) ;
w3cWidgetItem = mActiveScene - > addW3CWidget ( newUrl , pos ) ;
@ -1891,14 +1907,15 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP
w3cWidgetItem - > setSourceUrl ( pUrl ) ;
w3cWidgetItem - > setSourceUrl ( pUrl ) ;
QString struuid = UBStringUtils : : toCanonicalUuid ( uuid ) ;
QString struuid = UBStringUtils : : toCanonicalUuid ( uuid ) ;
QString snapshotPath = mActiveDocument - > persistencePath ( ) + " / " + UBPersistenceManager : : widgetDirectory + " / " + struuid + " .png " ;
QString snapshotPath = selectedDocument ( ) - > persistencePath ( ) + " / " + UBPersistenceManager : : widgetDirectory + " / " + struuid + " .png " ;
w3cWidgetItem - > setSnapshotPath ( QUrl : : fromLocalFile ( snapshotPath ) ) ;
w3cWidgetItem - > setSnapshotPath ( QUrl : : fromLocalFile ( snapshotPath ) ) ;
UBGraphicsWidgetItem * tmpItem = dynamic_cast < UBGraphicsWidgetItem * > ( w3cWidgetItem ) ;
UBGraphicsWidgetItem * tmpItem = dynamic_cast < UBGraphicsWidgetItem * > ( w3cWidgetItem ) ;
if ( tmpItem )
if ( tmpItem )
tmpItem - > widgetWebView ( ) - > takeSnapshot ( ) . save ( snapshotPath , " PNG " ) ;
tmpItem - > widgetWebView ( ) - > takeSnapshot ( ) . save ( snapshotPath , " PNG " ) ;
}
}
return w3cWidgetItem ;
return 0 ;
}
}
void UBBoardController : : cut ( )
void UBBoardController : : cut ( )
@ -1937,7 +1954,7 @@ void UBBoardController::cut()
mimeGi - > setData ( UBApplication : : mimeTypeUniboardPageItem , QByteArray ( ) ) ;
mimeGi - > setData ( UBApplication : : mimeTypeUniboardPageItem , QByteArray ( ) ) ;
clipboard - > setMimeData ( mimeGi ) ;
clipboard - > setMimeData ( mimeGi ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
}
}
//---------------------------------------------------------//
//---------------------------------------------------------//
@ -1975,7 +1992,7 @@ void UBBoardController::paste()
QPointF pos ( 0 , 0 ) ;
QPointF pos ( 0 , 0 ) ;
processMimeData ( clipboard - > mimeData ( ) , pos ) ;
processMimeData ( clipboard - > mimeData ( ) , pos ) ;
mActiveDocument - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
selectedDocument ( ) - > setMetaData ( UBSettings : : documentUpdatedAt , UBStringUtils : : toUtcIsoDateTime ( QDateTime : : currentDateTime ( ) ) ) ;
}
}
@ -1988,15 +2005,15 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if ( mimeData )
if ( mimeData )
{
{
int previousActiveSceneIndex = activeSceneIndex ( ) ;
int previousActiveSceneIndex = activeSceneIndex ( ) ;
int previousPageCount = active Document( ) - > pageCount ( ) ;
int previousPageCount = selected Document( ) - > pageCount ( ) ;
foreach ( UBMimeDataItem sourceItem , mimeData - > items ( ) )
foreach ( UBMimeDataItem sourceItem , mimeData - > items ( ) )
addScene ( sourceItem . documentProxy ( ) , sourceItem . sceneIndex ( ) , true ) ;
addScene ( sourceItem . documentProxy ( ) , sourceItem . sceneIndex ( ) , true ) ;
if ( active Document( ) - > pageCount ( ) < previousPageCount + mimeData - > items ( ) . count ( ) )
if ( selected Document( ) - > pageCount ( ) < previousPageCount + mimeData - > items ( ) . count ( ) )
setActiveDocumentScene ( activeDocument ( ) , previousActiveSceneIndex ) ;
setActiveDocumentScene ( previousActiveSceneIndex ) ;
else
else
setActiveDocumentScene ( activeDocument ( ) , previousActiveSceneIndex + 1 ) ;
setActiveDocumentScene ( previousActiveSceneIndex + 1 ) ;
return ;
return ;
}
}
@ -2031,13 +2048,9 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if ( " " ! = url )
if ( " " ! = url )
{
{
downloadURL ( url , pPos ) ;
downloadURL ( url , pPos ) ;
}
else
{
mActiveScene - > addTextHtml ( qsHtml , pPos ) ;
}
return ;
return ;
}
}
}
if ( pMimeData - > hasUrls ( ) )
if ( pMimeData - > hasUrls ( ) )
{
{
@ -2072,11 +2085,11 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if ( " " ! = pMimeData - > text ( ) ) {
if ( " " ! = pMimeData - > text ( ) ) {
// Sometimes, it is possible to have an URL as text. we check here if it is the case
// Sometimes, it is possible to have an URL as text. we check here if it is the case
QString qsTmp = pMimeData - > text ( ) . remove ( QRegExp ( " [ \\ 0] " ) ) ;
QString qsTmp = pMimeData - > text ( ) . remove ( QRegExp ( " [ \\ 0] " ) ) ;
if ( qsTmp . startsWith ( " http:// " ) | | qsTmp . startsWith ( " https:// " ) ) {
if ( qsTmp . startsWith ( " http " ) ) {
downloadURL ( QUrl ( qsTmp ) , pPos ) ;
downloadURL ( QUrl ( qsTmp ) , pPos ) ;
}
}
else {
else {
mActiveScene - > addTextHtml ( pMimeData - > text ( ) , pPos ) ;
mActiveScene - > addTextHtml ( pMimeData - > html ( ) , pPos ) ;
}
}
}
}
else {
else {
@ -2196,11 +2209,11 @@ void UBBoardController::addItem()
void UBBoardController : : importPage ( )
void UBBoardController : : importPage ( )
{
{
int pageCount = mActiveDocument - > pageCount ( ) ;
int pageCount = selectedDocument ( ) - > pageCount ( ) ;
if ( UBApplication : : documentController - > addFileToDocument ( mActiveDocument ) )
if ( UBApplication : : documentController - > addFileToDocument ( selectedDocument ( ) ) )
{
{
setActiveDocumentScene ( mActiveDocument , pageCount ) ;
setActiveDocumentScene ( pageCount ) ;
}
}
}
}