handling the documents without zero page when using a program set to handle zero pages

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent c601a63984
commit 75b7fd5666
  1. 11
      src/adaptors/UBThumbnailAdaptor.cpp
  2. 222
      src/board/UBFeaturesController.h
  3. 17
      src/core/UBPersistenceManager.cpp
  4. 14
      src/document/UBDocumentController.cpp

@ -45,7 +45,6 @@ QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
int existingPageCount = proxy->pageCount(); int existingPageCount = proxy->pageCount();
QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", existingPageCount); QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", existingPageCount);
QFile thumbFile(thumbFileName); QFile thumbFile(thumbFileName);
if (!thumbFile.exists()) if (!thumbFile.exists())
@ -67,6 +66,16 @@ QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
persistScene(proxy->persistencePath(), scene, i); persistScene(proxy->persistencePath(), scene, i);
} }
else{
if(i==0){
// we are working a document without zero page but on a system that enable it
// we have to create an empty zero scene
scene = new UBGraphicsScene(proxy);
UBSvgSubsetAdaptor::persistScene(proxy,scene,0);
persistScene(proxy->persistencePath(),scene,i);
thumbCount++;
}
}
} }
if (displayMessage && thumbCount > 0) if (displayMessage && thumbCount > 0)

@ -12,128 +12,140 @@
#include <QUrl> #include <QUrl>
#include <QByteArray> #include <QByteArray>
//#include "UBDockPaletteWidget.h"
enum UBFeatureElementType enum UBFeatureElementType
{ {
FEATURE_CATEGORY, FEATURE_CATEGORY,
FEATURE_VIRTUALFOLDER, FEATURE_VIRTUALFOLDER,
FEATURE_FOLDER, FEATURE_FOLDER,
FEATURE_INTERACTIVE, FEATURE_INTERACTIVE,
FEATURE_INTERNAL, FEATURE_INTERNAL,
FEATURE_ITEM, FEATURE_ITEM,
FEATURE_TRASH, FEATURE_TRASH,
FEATURE_FAVORITE, FEATURE_FAVORITE,
FEATURE_SEARCH FEATURE_SEARCH
}; };
class UBFeature class UBFeature
{ {
public: public:
UBFeature() {;} UBFeature() {;}
//UBFeature(const UBFeature &f); //UBFeature(const UBFeature &f);
UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QString &realPath, UBFeatureElementType type = FEATURE_CATEGORY); UBFeature(const QString &url, const QPixmap &icon, const QString &name, const QUrl &realPath, UBFeatureElementType type = FEATURE_CATEGORY);
virtual ~UBFeature() {;} virtual ~UBFeature() {;}
QString getName() const { return mName; } QString getName() const { return mName; }
QPixmap getThumbnail() const {return mThumbnail;} QPixmap getThumbnail() const {return mThumbnail;}
QString getUrl() const { return virtualPath; } QString getVirtualPath() const { return virtualPath; }
//QString getPath() const { return mPath; }; //QString getPath() const { return mPath; };
QString getFullPath() const { return mPath; } QUrl getFullPath() const { return mPath; }
QString getVirtualPath() const { return virtualPath + "/" + mName; } QString getFullVirtualPath() const { return virtualPath + "/" + mName; }
UBFeatureElementType getType() const { return elementType; } QString getUrl() const;
bool isFolder() const; UBFeatureElementType getType() const { return elementType; }
bool isDeletable() const;
bool operator ==( const UBFeature &f )const; bool isFolder() const;
bool operator !=( const UBFeature &f )const; bool isDeletable() const;
private: bool operator ==( const UBFeature &f )const;
QString virtualPath; bool operator !=( const UBFeature &f )const;
QPixmap mThumbnail; const QMap<QString,QString> & getMetadata() const { return metadata; }
QString mName; void setMetadata( const QMap<QString,QString> &data ) { metadata = data; }
QString mPath; private:
UBFeatureElementType elementType; QString virtualPath;
QPixmap mThumbnail;
QString mName;
QUrl mPath;
UBFeatureElementType elementType;
QMap<QString,QString> metadata;
}; };
Q_DECLARE_METATYPE( UBFeature ) Q_DECLARE_METATYPE( UBFeature )
class UBFeaturesController : public QObject class UBFeaturesController : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
UBFeaturesController(QWidget *parentWidget); UBFeaturesController(QWidget *parentWidget);
virtual ~UBFeaturesController(); virtual ~UBFeaturesController();
QList <UBFeature>* getFeatures()const { return featuresList; } QList <UBFeature>* getFeatures()const { return featuresList; }
const QString& getRootPath()const { return rootPath; } const QString& getRootPath()const { return rootPath; }
void addItemToPage(const UBFeature &item); void addItemToPage( const UBFeature &item );
const UBFeature& getCurrentElement()const { return currentElement; } void addItemAsBackground( const UBFeature &item );
void setCurrentElement( const UBFeature &elem ) { currentElement = elem; } const UBFeature& getCurrentElement()const { return currentElement; }
const UBFeature & getTrashElement () const { return trashElement; } void setCurrentElement( const UBFeature &elem ) { currentElement = elem; }
UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination ); const UBFeature & getTrashElement () const { return trashElement; }
UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
void deleteItem( const QUrl &url ); UBFeature addDownloadedFile( const QUrl &sourceUrl, const QByteArray &pData );
bool isTrash( const QUrl &url );
UBFeature newFolder( const QString &name ); UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination );
UBFeature addToFavorite( const QUrl &path ); UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
void removeFromFavorite( const QUrl &path ); void deleteItem( const QUrl &url );
bool isTrash( const QUrl &url );
static QString fileNameFromUrl( const QUrl &url ); UBFeature newFolder( const QString &name );
static QPixmap thumbnailForFile( const QString &path ); UBFeature addToFavorite( const QUrl &path );
static bool isDeletable( const QUrl &url ); void removeFromFavorite( const QUrl &path );
private: UBFeature importImage( const QImage &image, const UBFeature &destination );
void initDirectoryTree();
void fileSystemScan(const QString &currPath, const QString & currVirtualPath); static QString fileNameFromUrl( const QUrl &url );
static QPixmap createThumbnail(const QString &path); static QPixmap thumbnailForFile( const QString &path );
//void addImageToCurrentPage( const QString &path ); static bool isDeletable( const QUrl &url );
void loadFavoriteList(); private:
void saveFavoriteList(); void initDirectoryTree();
UBFeature getDestinationForItem( const QUrl &url ); void fileSystemScan(const QUrl &currPath, const QString & currVirtualPath);
static QPixmap createThumbnail(const QString &path);
static UBFeatureElementType fileTypeFromUrl( const QString &path ); //void addImageToCurrentPage( const QString &path );
void loadFavoriteList();
QList <UBFeature> *featuresList; void saveFavoriteList();
UBFeature *rootElement; UBFeature getDestinationForItem( const QUrl &url );
QString mUserAudioDirectoryPath; static UBFeatureElementType fileTypeFromUrl( const QString &path );
QString mUserVideoDirectoryPath;
QString mUserPicturesDirectoryPath; QList <UBFeature> *featuresList;
QString mUserInteractiveDirectoryPath; UBFeature *rootElement;
QString mUserAnimationDirectoryPath;
QUrl mUserAudioDirectoryPath;
QString libraryPath; QUrl mUserVideoDirectoryPath;
QString mLibAudioDirectoryPath; QUrl mUserPicturesDirectoryPath;
QString mLibVideoDirectoryPath; QUrl mUserInteractiveDirectoryPath;
QString mLibPicturesDirectoryPath; QUrl mUserAnimationDirectoryPath;
QString mLibInteractiveDirectoryPath;
QString mLibAnimationDirectoryPath; QString libraryPath;
QString mLibApplicationsDirectoryPath; QUrl mLibAudioDirectoryPath;
QString mLibShapesDirectoryPath; QUrl mLibVideoDirectoryPath;
QString trashDirectoryPath; QUrl mLibPicturesDirectoryPath;
QString mLibSearchDirectoryPath; QUrl mLibInteractiveDirectoryPath;
QUrl mLibAnimationDirectoryPath;
QString rootPath; QUrl mLibApplicationsDirectoryPath;
QString audiosPath; QUrl mLibShapesDirectoryPath;
QString moviesPath; QUrl trashDirectoryPath;
QString picturesPath; QUrl mLibSearchDirectoryPath;
QString appPath;
QString flashPath; QString rootPath;
QString shapesPath; QString audiosPath;
QString interactPath; QString moviesPath;
QString trashPath; QString picturesPath;
QString favoritePath; QString appPath;
QString flashPath;
int mLastItemOffsetIndex; QString shapesPath;
UBFeature currentElement; QString interactPath;
UBFeature trashElement; QString trashPath;
UBFeature favoriteElement; QString favoritePath;
UBFeature audiosElement;
UBFeature moviesElement; int mLastItemOffsetIndex;
UBFeature picturesElement; UBFeature currentElement;
UBFeature interactElement; UBFeature trashElement;
UBFeature flashElement; UBFeature favoriteElement;
UBFeature shapesElement; UBFeature audiosElement;
UBFeature searchElement; UBFeature moviesElement;
UBFeature picturesElement;
QSet <QString> *favoriteSet; UBFeature interactElement;
UBFeature flashElement;
UBFeature shapesElement;
UBFeature webSearchElement;
QSet <QUrl> *favoriteSet;
}; };

@ -670,6 +670,7 @@ int UBPersistenceManager::sceneCountInDir(const QString& pPath)
{ {
int pageIndex = 0; int pageIndex = 0;
bool moreToProcess = true; bool moreToProcess = true;
bool addedMissingZeroPage = false;
while (moreToProcess) while (moreToProcess)
{ {
@ -683,10 +684,24 @@ int UBPersistenceManager::sceneCountInDir(const QString& pPath)
} }
else else
{ {
moreToProcess = false; if(UBSettings::settings()->teacherGuidePageZeroActivated && pageIndex == 0){
// the document has no zero file but doesn't means that it hasn't any file
// at all. Just importing a document without the first page using a configuartion
// that enables zero page.
pageIndex++;
addedMissingZeroPage = true;
}
else
moreToProcess = false;
} }
} }
if(pageIndex == 1 && addedMissingZeroPage){
// increment is done only to check if there are other pages than the missing zero page
// This situation means -> no pages on the document
return 0;
}
return pageIndex; return pageIndex;
} }

@ -168,7 +168,6 @@ void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurr
mDocumentUI->documentTreeWidget->scrollToItem(selected); mDocumentUI->documentTreeWidget->scrollToItem(selected);
mDocumentThumbs = UBThumbnailAdaptor::load(selectedDocumentProxy()); mDocumentThumbs = UBThumbnailAdaptor::load(selectedDocumentProxy());
qDebug() << mDocumentThumbs.size();
refreshDocumentThumbnailsView(); refreshDocumentThumbnailsView();
mSelectionType = Document; mSelectionType = Document;
@ -291,9 +290,9 @@ void UBDocumentController::refreshDocumentThumbnailsView()
} }
items << pixmapItem; items << pixmapItem;
labels << tr("Page %1").arg(i + 1); labels << tr("Page %1").arg(UBApplication::boardController->pageFromSceneIndex(i));
itemsPath.append(QUrl::fromLocalFile(proxy->persistencePath() + QString("/pages/%1").arg(i + 1))); itemsPath.append(QUrl::fromLocalFile(proxy->persistencePath() + QString("/pages/%1").arg(UBApplication::boardController->pageFromSceneIndex(i))));
} }
} }
@ -307,15 +306,12 @@ void UBDocumentController::refreshDocumentThumbnailsView()
mDocumentUI->thumbnailWidget->ensureVisible(0, 0, 10, 10); mDocumentUI->thumbnailWidget->ensureVisible(0, 0, 10, 10);
if (selection) if (selection) {
{ disconnect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged()));
disconnect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()),
this, SLOT(pageSelectionChanged()));
UBSceneThumbnailPixmap *currentScene = dynamic_cast<UBSceneThumbnailPixmap*>(selection); UBSceneThumbnailPixmap *currentScene = dynamic_cast<UBSceneThumbnailPixmap*>(selection);
if (currentScene) if (currentScene)
mDocumentUI->thumbnailWidget->hightlightItem(currentScene->sceneIndex()); mDocumentUI->thumbnailWidget->hightlightItem(currentScene->sceneIndex());
connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged()));
this, SLOT(pageSelectionChanged()));
} }
emit refreshThumbnails(); emit refreshThumbnails();

Loading…
Cancel
Save