Merge branch 'master' of github.com:Sankore/Sankore-3.1

preferencesAboutTextFull
unknown 12 years ago
commit 4e884672fe
  1. 4
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 4
      src/adaptors/UBSvgSubsetAdaptor.cpp
  3. 416
      src/adaptors/UBThumbnailAdaptor.cpp
  4. 81
      src/adaptors/UBThumbnailAdaptor.h
  5. 1648
      src/adaptors/publishing/UBDocumentPublisher.cpp
  6. 261
      src/adaptors/publishing/UBDocumentPublisher.h
  7. 2
      src/api/UBWidgetUniboardAPI.cpp
  8. 4509
      src/board/UBBoardController.cpp
  9. 30
      src/board/UBBoardController.h
  10. 6
      src/board/UBBoardPaletteManager.cpp
  11. 2
      src/board/UBLibraryController.cpp
  12. 2
      src/core/UBApplication.cpp
  13. 3
      src/core/UBApplicationController.cpp
  14. 4
      src/core/UBPersistenceManager.cpp
  15. 127
      src/document/UBDocumentContainer.cpp
  16. 67
      src/document/UBDocumentContainer.h
  17. 3356
      src/document/UBDocumentController.cpp
  18. 287
      src/document/UBDocumentController.h
  19. 464
      src/document/UBDocumentProxy.cpp
  20. 194
      src/document/UBDocumentProxy.h
  21. 4
      src/document/document.pri
  22. 4
      src/domain/UBGraphicsMediaItem.cpp
  23. 3
      src/frameworks/UBFileSystemUtils.cpp
  24. 657
      src/gui/UBDocumentNavigator.cpp
  25. 156
      src/gui/UBDocumentNavigator.h
  26. 631
      src/gui/UBDocumentThumbnailWidget.cpp
  27. 912
      src/gui/UBDocumentTreeWidget.cpp
  28. 311
      src/gui/UBNavigatorPalette.cpp
  29. 130
      src/gui/UBNavigatorPalette.h
  30. 379
      src/gui/UBPageNavigationWidget.cpp
  31. 146
      src/gui/UBPageNavigationWidget.h
  32. 14
      src/gui/UBTeacherGuideWidget.cpp
  33. 8
      src/gui/UBTeacherGuideWidgetsTools.cpp
  34. 19
      src/gui/UBThumbnailWidget.cpp
  35. 8
      src/gui/UBThumbnailWidget.h

@ -1078,7 +1078,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::persistCurrentScene()
{ {
if (mCurrentScene != 0 && mCurrentScene->isModified()) if (mCurrentScene != 0 && mCurrentScene->isModified())
{ {
UBThumbnailAdaptor::persistScene(mProxy->persistencePath(), mCurrentScene, mProxy->pageCount() - 1); UBThumbnailAdaptor::persistScene(mProxy, mCurrentScene, mProxy->pageCount() - 1);
UBSvgSubsetAdaptor::persistScene(mProxy, mCurrentScene, mProxy->pageCount() - 1); UBSvgSubsetAdaptor::persistScene(mProxy, mCurrentScene, mProxy->pageCount() - 1);
mCurrentScene->setModified(false); mCurrentScene->setModified(false);
@ -1102,7 +1102,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::persistScenes()
UBSvgSubsetAdaptor::persistScene(mProxy, mCurrentScene, i); UBSvgSubsetAdaptor::persistScene(mProxy, mCurrentScene, i);
UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i); UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i);
tmpScene->setModified(true); tmpScene->setModified(true);
UBThumbnailAdaptor::persistScene(mProxy->persistencePath(), tmpScene, i); UBThumbnailAdaptor::persistScene(mProxy, tmpScene, i);
delete tmpScene; delete tmpScene;
mCurrentScene->setModified(false); mCurrentScene->setModified(false);

@ -56,6 +56,8 @@
#include "interfaces/IDataStorage.h" #include "interfaces/IDataStorage.h"
#include "document/UBDocumentContainer.h"
#include "pdf/PDFRenderer.h" #include "pdf/PDFRenderer.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -313,7 +315,7 @@ QString UBSvgSubsetAdaptor::readTeacherGuideNode(int sceneIndex)
{ {
QString result; QString result;
QString fileName = UBApplication::boardController->activeDocument()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", sceneIndex); QString fileName = UBApplication::boardController->selectedDocument()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", sceneIndex);
QFile file(fileName); QFile file(fileName);
file.open(QIODevice::ReadOnly); file.open(QIODevice::ReadOnly);
QByteArray fileByteArray=file.readAll(); QByteArray fileByteArray=file.readAll();

@ -1,186 +1,230 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBThumbnailAdaptor.h" #include "UBThumbnailAdaptor.h"
#include <QtCore> #include <QtCore>
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "UBSvgSubsetAdaptor.h" #include "UBSvgSubsetAdaptor.h"
#include "core/memcheck.h" #include "core/memcheck.h"
void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy) void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy)
{ {
int existingPageCount = proxy->pageCount(); int existingPageCount = proxy->pageCount();
for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo) for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo)
{ {
QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo); QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo);
QFile thumbFile(thumbFileName); QFile thumbFile(thumbFileName);
if (!thumbFile.exists()) if (!thumbFile.exists())
{ {
bool displayMessage = (existingPageCount > 5); bool displayMessage = (existingPageCount > 5);
int thumbCount = 0; int thumbCount = 0;
UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo); UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo);
if (scene) if (scene)
{ {
thumbCount++; thumbCount++;
if (displayMessage && thumbCount == 1) if (displayMessage && thumbCount == 1)
UBApplication::showMessage(tr("Generating preview thumbnails ...")); UBApplication::showMessage(tr("Generating preview thumbnails ..."));
persistScene(proxy->persistencePath(), scene, iPageNo); persistScene(proxy, scene, iPageNo);
} }
if (displayMessage && thumbCount > 0) if (displayMessage && thumbCount > 0)
UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount)); UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount));
} }
} }
} }
QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy) const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex)
{ {
QList<QPixmap> thumbnails; QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
if (!proxy || proxy->persistencePath().isEmpty()) QFile file(fileName);
return thumbnails; if (!file.exists())
{
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails generateMissingThumbnails(proxy);
generateMissingThumbnails(proxy); }
//end compatibility with older format QPixmap* pix = new QPixmap();
if (file.exists())
bool moreToProcess = true; {
int pageCount = UBApplication::boardController->sceneIndexFromPage(0); //Warning. Works only with modified Qt
#ifdef Q_WS_X11
while (moreToProcess) { pix->load(fileName, 0, Qt::AutoColor);
pageCount++; #else
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageCount); pix->load(fileName, 0, Qt::AutoColor, false);
#endif
QFile file(fileName); }
if (file.exists()) { return pix;
QPixmap pix; }
//Warning. Works only with modified Qt
#ifdef Q_WS_X11 void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList<const QPixmap*>& list)
//pix.load(fileName, 0, Qt::AutoColor); {
pix.load(fileName, 0); generateMissingThumbnails(proxy);
#else
pix.load(fileName, 0, Qt::AutoColor, false); foreach(const QPixmap* pm, list)
#endif delete pm;
thumbnails.append(pix); list.clear();
} else { for(int i=0; i<proxy->pageCount(); i++)
moreToProcess = false; list.append(get(proxy, i));
} }
}
return thumbnails;
} /*
QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
QPixmap UBThumbnailAdaptor::load(UBDocumentProxy* proxy, int index) {
{ QList<QPixmap> thumbnails;
int existingPageCount = proxy->pageCount();
qDebug() << "Loadinf thumbnails for " << proxy->name();
if (!proxy || proxy->persistencePath().size() == 0 || index < 0 || index > existingPageCount)
return QPixmap(); if (!proxy || proxy->persistencePath().isEmpty())
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails return thumbnails;
generateMissingThumbnails(proxy);
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails
//end compatibility with older format generateMissingThumbnails(proxy);
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index);
//end compatibility with older format
QFile file(fileName);
if (file.exists()) bool moreToProcess = true;
{ int pageCount = UBApplication::boardController->sceneIndexFromPage(0);
QPixmap pix;
//Warning. Works only with modified Qt while (moreToProcess) {
#ifdef Q_WS_X11 pageCount++;
pix.load(fileName, 0, Qt::AutoColor); QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageCount);
#else
pix.load(fileName, 0, Qt::AutoColor, false); QFile file(fileName);
#endif if (file.exists()) {
return pix; QPixmap pix;
} //Warning. Works only with modified Qt
return QPixmap(); #ifdef Q_WS_X11
} //pix.load(fileName, 0, Qt::AutoColor);
pix.load(fileName, 0);
void UBThumbnailAdaptor::persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified) #else
{ pix.load(fileName, 0, Qt::AutoColor, false);
QString fileName = pDocPath + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); #endif
thumbnails.append(pix);
QFile thumbFile(fileName); } else {
moreToProcess = false;
if (pScene->isModified() || overrideModified || !thumbFile.exists()) }
{ }
qreal nominalWidth = pScene->nominalSize().width(); return thumbnails;
qreal nominalHeight = pScene->nominalSize().height(); }
qreal ratio = nominalWidth / nominalHeight;
QRectF sceneRect = pScene->normalizedSceneRect(ratio); QPixmap UBThumbnailAdaptor::load(UBDocumentProxy* proxy, int index)
{
qreal width = UBSettings::maxThumbnailWidth; qDebug() << "Loadinf thumbnails for " << proxy->name();
qreal height = width / ratio;
int existingPageCount = proxy->pageCount();
QImage thumb(width, height, QImage::Format_ARGB32);
if (!proxy || proxy->persistencePath().size() == 0 || index < 0 || index > existingPageCount)
QRectF imageRect(0, 0, width, height); return QPixmap();
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails
QPainter painter(&thumb); generateMissingThumbnails(proxy);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true); //end compatibility with older format
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index);
if (pScene->isDarkBackground())
{ QFile file(fileName);
painter.fillRect(imageRect, Qt::black); if (file.exists())
} {
else QPixmap pix;
{ //Warning. Works only with modified Qt
painter.fillRect(imageRect, Qt::white); #ifdef Q_WS_X11
} pix.load(fileName, 0, Qt::AutoColor);
#else
pScene->setRenderingContext(UBGraphicsScene::NonScreen); pix.load(fileName, 0, Qt::AutoColor, false);
pScene->setRenderingQuality(UBItem::RenderingQualityHigh); #endif
return pix;
pScene->render(&painter, imageRect, sceneRect, Qt::KeepAspectRatio); }
return QPixmap();
pScene->setRenderingContext(UBGraphicsScene::Screen); }
pScene->setRenderingQuality(UBItem::RenderingQualityNormal); */
thumb.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(fileName, "JPG"); void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified)
} {
}
qDebug() << "Persiste scene on path " << proxy->persistencePath() << ", index " << pageIndex;
QUrl UBThumbnailAdaptor::thumbnailUrl(UBDocumentProxy* proxy, int pageIndex) QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); QFile thumbFile(fileName);
return QUrl::fromLocalFile(fileName); if (pScene->isModified() || overrideModified || !thumbFile.exists())
} {
qreal nominalWidth = pScene->nominalSize().width();
qreal nominalHeight = pScene->nominalSize().height();
qreal ratio = nominalWidth / nominalHeight;
QRectF sceneRect = pScene->normalizedSceneRect(ratio);
qreal width = UBSettings::maxThumbnailWidth;
qreal height = width / ratio;
QImage thumb(width, height, QImage::Format_ARGB32);
QRectF imageRect(0, 0, width, height);
QPainter painter(&thumb);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
if (pScene->isDarkBackground())
{
painter.fillRect(imageRect, Qt::black);
}
else
{
painter.fillRect(imageRect, Qt::white);
}
pScene->setRenderingContext(UBGraphicsScene::NonScreen);
pScene->setRenderingQuality(UBItem::RenderingQualityHigh);
pScene->render(&painter, imageRect, sceneRect, Qt::KeepAspectRatio);
pScene->setRenderingContext(UBGraphicsScene::Screen);
pScene->setRenderingQuality(UBItem::RenderingQualityNormal);
thumb.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(fileName, "JPG");
}
}
QUrl UBThumbnailAdaptor::thumbnailUrl(UBDocumentProxy* proxy, int pageIndex)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
return QUrl::fromLocalFile(fileName);
}

@ -1,39 +1,42 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBTHUMBNAILADAPTOR_H #ifndef UBTHUMBNAILADAPTOR_H
#define UBTHUMBNAILADAPTOR_H #define UBTHUMBNAILADAPTOR_H
#include <QtCore> #include <QtCore>
class UBDocument; class UBDocument;
class UBDocumentProxy; class UBDocumentProxy;
class UBGraphicsScene; class UBGraphicsScene;
class UBThumbnailAdaptor //static class class UBThumbnailAdaptor //static class
{ {
Q_DECLARE_TR_FUNCTIONS(UBThumbnailAdaptor) Q_DECLARE_TR_FUNCTIONS(UBThumbnailAdaptor)
private: UBThumbnailAdaptor() {} public:
public: static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex);
static void persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false);
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false);
static void generateMissingThumbnails(UBDocumentProxy* proxy);
static QList<QPixmap> load(UBDocumentProxy* proxy); static const QPixmap* get(UBDocumentProxy* proxy, int index);
static QPixmap load(UBDocumentProxy* proxy, int index); static void load(UBDocumentProxy* proxy, QList<const QPixmap*>& list);
static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex); private:
}; static void generateMissingThumbnails(UBDocumentProxy* proxy);
#endif // UBTHUMBNAILADAPTOR_H UBThumbnailAdaptor() {}
};
#endif // UBTHUMBNAILADAPTOR_H

File diff suppressed because it is too large Load Diff

@ -1,128 +1,133 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBDOCUMENTPUBLISHER_H #ifndef UBDOCUMENTPUBLISHER_H
#define UBDOCUMENTPUBLISHER_H #define UBDOCUMENTPUBLISHER_H
#include <QtGui> #include <QtGui>
#include <QtNetwork> #include <QtNetwork>
#include "ui_webPublishing.h" #include "ui_webPublishing.h"
#define DOCPUBLICATION_URL "http://planete.sankore.org/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain" #define DOCPUBLICATION_URL "http://planete.sankore.org/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain"
typedef struct typedef struct
{ {
QString title; QString title;
QString description; QString description;
} sDocumentInfos; } sDocumentInfos;
class UBDocumentProxy; class UBDocumentProxy;
class UBServerXMLHttpRequest; class UBServerXMLHttpRequest;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class QWebView; class QWebView;
class UBProxyLoginDlg : public QDialog class UBProxyLoginDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
UBProxyLoginDlg(QWidget* parent=0, const char* name="ProxyLoginDlg"); UBProxyLoginDlg(QWidget* parent=0, const char* name="ProxyLoginDlg");
~UBProxyLoginDlg(); ~UBProxyLoginDlg();
QString username(){return mpUsername->text();} QString username(){return mpUsername->text();}
QString password(){return mpPassword->text();} QString password(){return mpPassword->text();}
private: private:
QVBoxLayout* mpLayout; QVBoxLayout* mpLayout;
QHBoxLayout* mpUserLayout; QHBoxLayout* mpUserLayout;
QHBoxLayout* mpPasswordLayout; QHBoxLayout* mpPasswordLayout;
QDialogButtonBox* mpButtons; QDialogButtonBox* mpButtons;
QLabel* mpUserLabel; QLabel* mpUserLabel;
QLabel* mpPasswordLabel; QLabel* mpPasswordLabel;
QLineEdit* mpUsername; QLineEdit* mpUsername;
QLineEdit* mpPassword; QLineEdit* mpPassword;
}; };
class UBPublicationDlg : public QDialog class UBPublicationDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
UBPublicationDlg(QWidget* parent=0, const char* name="UBPublicationDlg"); UBPublicationDlg(QWidget* parent=0, const char* name="UBPublicationDlg");
~UBPublicationDlg(); ~UBPublicationDlg();
QString title(){return mpTitle->text();} QString title(){return mpTitle->text();}
QString description(){return mpDescription->document()->toPlainText();} QString description(){return mpDescription->document()->toPlainText();}
private slots: private slots:
void onTextChanged(); void onTextChanged();
private: private:
QVBoxLayout* mpLayout; QVBoxLayout* mpLayout;
QHBoxLayout* mpTitleLayout; QHBoxLayout* mpTitleLayout;
QLabel* mpTitleLabel; QLabel* mpTitleLabel;
QLineEdit* mpTitle; QLineEdit* mpTitle;
QLabel* mpDescLabel; QLabel* mpDescLabel;
QTextEdit* mpDescription; QTextEdit* mpDescription;
QDialogButtonBox* mpButtons; QDialogButtonBox* mpButtons;
}; };
class UBDocumentPublisher : public QObject class UBDocumentPublisher : public QObject
{ {
Q_OBJECT; Q_OBJECT;
public: public:
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0); explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0);
virtual ~UBDocumentPublisher(); virtual ~UBDocumentPublisher();
void publish(); void publish();
signals: signals:
void loginDone(); void loginDone();
protected: protected:
virtual void updateGoogleMapApiKey(); virtual void updateGoogleMapApiKey();
virtual void rasterizeScenes(); virtual void rasterizeScenes();
virtual void upgradeDocumentForPublishing(); virtual void upgradeDocumentForPublishing();
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber); virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
private slots: private slots:
void onFinished(QNetworkReply* reply); void onFinished(QNetworkReply* reply);
private: private:
UBDocumentProxy *mSourceDocument; UBDocumentProxy *mSourceDocument;
UBDocumentProxy *mPublishingDocument;
void init(); //UBDocumentProxy *mPublishingDocument;
void sendUbw(QString username, QString password); QString mPublishingPath;
QString getBase64Of(QString stringToEncode); int mPublishingSize;
QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr; void init();
QNetworkCookieJar* mpCookieJar; void sendUbw(QString username, QString password);
QString mUsername; QString getBase64Of(QString stringToEncode);
QString mPassword;
QString mCrlf; QHBoxLayout* mpLayout;
bool bLoginCookieSet; QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar;
void buildUbwFile(); QString mUsername;
QString mTmpZipFile; QString mPassword;
QList<QNetworkCookie> mCookies; QString mCrlf;
sDocumentInfos mDocInfos; bool bLoginCookieSet;
}; void buildUbwFile();
#endif // UBDOCUMENTPUBLISHER_H QString mTmpZipFile;
QList<QNetworkCookie> mCookies;
sDocumentInfos mDocInfos;
};
#endif // UBDOCUMENTPUBLISHER_H

@ -346,7 +346,7 @@ QString UBWidgetUniboardAPI::pageThumbnail(const int pageNumber)
if (UBApplication::boardController->activeScene() != mScene) if (UBApplication::boardController->activeScene() != mScene)
return ""; return "";
UBDocumentProxy *doc = UBApplication::boardController->activeDocument(); UBDocumentProxy *doc = UBApplication::boardController->selectedDocument();
if (!doc) if (!doc)
return ""; return "";

File diff suppressed because it is too large Load Diff

@ -19,6 +19,7 @@
#include <QtGui> #include <QtGui>
#include <QObject> #include <QObject>
#include "document/UBDocumentContainer.h"
class UBMainWindow; class UBMainWindow;
class UBApplication; class UBApplication;
@ -40,7 +41,7 @@ class UBGraphicsWidgetItem;
class UBBoardPaletteManager; class UBBoardPaletteManager;
class UBBoardController : public QObject class UBBoardController : public UBDocumentContainer
{ {
Q_OBJECT Q_OBJECT
@ -50,7 +51,7 @@ class UBBoardController : public QObject
void init(); void init();
void setupLayout(); void setupLayout();
UBDocumentProxy* activeDocument() const;
UBGraphicsScene* activeScene() const; UBGraphicsScene* activeScene() const;
int activeSceneIndex() const; int activeSceneIndex() const;
QSize displayViewport(); QSize displayViewport();
@ -60,14 +61,6 @@ class UBBoardController : public QObject
int currentPage(); int currentPage();
int pageFromSceneIndex(int sceneIndex);
int sceneIndexFromPage(int page);
UBDocumentProxy* activeDocument()
{
return mActiveDocument;
}
QWidget* controlContainer() QWidget* controlContainer()
{ {
return mControlContainer; return mControlContainer;
@ -158,10 +151,17 @@ class UBBoardController : public QObject
void displayMetaData(QMap<QString, QString> metadatas); void displayMetaData(QMap<QString, QString> metadatas);
void ClearUndoStack(); void ClearUndoStack();
void emitScrollSignal() { emit scrollToSelectedPage(); }
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0, bool forceReload = false);
void setActiveDocumentScene(int pSceneIndex);
void moveSceneToIndex(int source, int target);
void duplicateScene(int index);
void deleteScene(int index);
bool cacheIsVisible() {return mCacheWidgetIsEnabled;}
public slots: public slots:
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0);
void showDocumentsDialog(); void showDocumentsDialog();
void showKeyboard(bool show); void showKeyboard(bool show);
void togglePodcast(bool checked); void togglePodcast(bool checked);
@ -222,14 +222,12 @@ class UBBoardController : public QObject
void freezeW3CWidget(QGraphicsItem* item, bool freeze); void freezeW3CWidget(QGraphicsItem* item, bool freeze);
void startScript(); void startScript();
void stopScript(); void stopScript();
bool cacheIsVisible();
signals: signals:
void newPageAdded(); void newPageAdded();
void activeSceneWillBePersisted(); void activeSceneWillBePersisted();
void activeSceneWillChange(); void activeSceneWillChange();
void activeSceneChanged(); void activeSceneChanged();
void activeDocumentChanged();
void zoomChanged(qreal pZoomFactor); void zoomChanged(qreal pZoomFactor);
void systemScaleFactorChanged(qreal pSystemScaleFactor); void systemScaleFactorChanged(qreal pSystemScaleFactor);
void penColorChanged(); void penColorChanged();
@ -238,10 +236,9 @@ class UBBoardController : public QObject
void cacheEnabled(); void cacheEnabled();
void cacheDisabled(); void cacheDisabled();
void pageChanged(); void pageChanged();
void setDocOnPageNavigator(UBDocumentProxy* doc);
void documentReorganized(int index); void documentReorganized(int index);
void displayMetadata(QMap<QString, QString> metadata); void displayMetadata(QMap<QString, QString> metadata);
void scrollToSelectedPage(); void pageSelectionChanged(int index);
protected: protected:
void setupViews(); void setupViews();
@ -263,7 +260,6 @@ class UBBoardController : public QObject
void adjustDisplayViews(); void adjustDisplayViews();
UBMainWindow *mMainWindow; UBMainWindow *mMainWindow;
UBDocumentProxy* mActiveDocument;
UBGraphicsScene* mActiveScene; UBGraphicsScene* mActiveScene;
int mActiveSceneIndex; int mActiveSceneIndex;
UBBoardPaletteManager *mPaletteManager; UBBoardPaletteManager *mPaletteManager;

@ -134,8 +134,6 @@ void UBBoardPaletteManager::setupDockPaletteWidgets()
//------------------------------------------------// //------------------------------------------------//
// Create the widgets for the dock palettes // Create the widgets for the dock palettes
mpPageNavigWidget = new UBPageNavigationWidget();
#ifdef USE_WEB_WIDGET #ifdef USE_WEB_WIDGET
mpLibWidget = new UBLibWidget(); mpLibWidget = new UBLibWidget();
#endif #endif
@ -352,7 +350,7 @@ void UBBoardPaletteManager::pagePaletteButtonReleased()
QList<QAction*>pageActions; QList<QAction*>pageActions;
pageActions << UBApplication::mainWindow->actionNewPage; pageActions << UBApplication::mainWindow->actionNewPage;
UBBoardController* boardController = UBApplication::boardController; UBBoardController* boardController = UBApplication::boardController;
if(UBApplication::documentController->pageCanBeDuplicated(boardController->pageFromSceneIndex(boardController->activeSceneIndex()))) if(UBApplication::documentController->pageCanBeDuplicated(UBDocumentContainer::pageFromSceneIndex(boardController->activeSceneIndex())))
pageActions << UBApplication::mainWindow->actionDuplicatePage; pageActions << UBApplication::mainWindow->actionDuplicatePage;
pageActions << UBApplication::mainWindow->actionImportPage; pageActions << UBApplication::mainWindow->actionImportPage;
@ -568,7 +566,7 @@ void UBBoardPaletteManager::activeSceneChanged()
if (mpPageNavigWidget) if (mpPageNavigWidget)
{ {
mpPageNavigWidget->setPageNumber(UBApplication::boardController->pageFromSceneIndex(pageIndex), activeScene->document()->pageCount()); mpPageNavigWidget->setPageNumber(UBDocumentContainer::pageFromSceneIndex(pageIndex), activeScene->document()->pageCount());
} }
if (mZoomPalette) if (mZoomPalette)

@ -562,7 +562,7 @@ void UBLibraryController::removeBackground()
UBGraphicsScene* UBLibraryController::activeScene() UBGraphicsScene* UBLibraryController::activeScene()
{ {
if (mBoardController->activeDocument()) if (mBoardController->selectedDocument())
return mBoardController->activeScene(); return mBoardController->activeScene();
return 0; return 0;

@ -317,8 +317,6 @@ int UBApplication::exec(const QString& pFileToImport)
connect(mainWindow->actionHideApplication, SIGNAL(triggered()), this, SLOT(showMinimized())); connect(mainWindow->actionHideApplication, SIGNAL(triggered()), this, SLOT(showMinimized()));
#endif #endif
connect(documentController, SIGNAL(movedToIndex(int)), boardController, SIGNAL(documentReorganized(int)));
mPreferencesController = new UBPreferencesController(mainWindow); mPreferencesController = new UBPreferencesController(mainWindow);
connect(mainWindow->actionPreferences, SIGNAL(triggered()), mPreferencesController, SLOT(show())); connect(mainWindow->actionPreferences, SIGNAL(triggered()), mPreferencesController, SLOT(show()));

@ -340,8 +340,7 @@ void UBApplicationController::showBoard()
int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex(); int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex();
if (selectedSceneIndex != -1) if (selectedSceneIndex != -1)
{ {
UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->getCurrentDocument(), selectedSceneIndex); UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex, true);
UBApplication::boardController->emitScrollSignal();
} }
} }

@ -608,10 +608,10 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
if (pScene->isModified()) if (pScene->isModified())
{ {
UBThumbnailAdaptor::persistScene(pDocumentProxy->persistencePath(), pScene, pSceneIndex);
UBSvgSubsetAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex); UBSvgSubsetAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
pScene->setModified(false); pScene->setModified(false);
} }

@ -0,0 +1,127 @@
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBDocumentContainer.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "core/UBPersistenceManager.h"
#include "core/memcheck.h"
UBDocumentContainer::UBDocumentContainer(QObject * parent)
:QObject(parent)
,mCurrentDocument(NULL)
{}
UBDocumentContainer::~UBDocumentContainer()
{
foreach(const QPixmap* pm, mDocumentThumbs)
delete pm;
}
void UBDocumentContainer::setDocument(UBDocumentProxy* document, bool forceReload)
{
if (mCurrentDocument != document || forceReload)
{
mCurrentDocument = document;
reloadThumbnails();
emit documentSet(mCurrentDocument);
}
}
void UBDocumentContainer::duplicatePages(QList<int>& pageIndexes)
{
int offset = 0;
foreach(int sceneIndex, pageIndexes)
{
UBPersistenceManager::persistenceManager()->duplicateDocumentScene(mCurrentDocument, sceneIndex + offset);
insertThumbPage(sceneIndex + offset);
offset++;
}
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::movePageToIndex(int source, int target)
{
UBPersistenceManager::persistenceManager()->moveSceneToIndex(mCurrentDocument, source, target);
deleteThumbPage(source);
insertThumbPage(target);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
{
UBPersistenceManager::persistenceManager()->deleteDocumentScenes(mCurrentDocument, pageIndexes);
int offset = 0;
foreach(int index, pageIndexes)
{
deleteThumbPage(index - offset);
offset++;
}
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::addPage(int index)
{
UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mCurrentDocument, index);
insertThumbPage(index);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::updatePage(int index)
{
updateThumbPage(index);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::deleteThumbPage(int index)
{
mDocumentThumbs.removeAt(index);
emit documentPageDeleted(index);
}
void UBDocumentContainer::updateThumbPage(int index)
{
mDocumentThumbs[index] = UBThumbnailAdaptor::get(mCurrentDocument, index);
emit documentPageUpdated(index);
}
void UBDocumentContainer::insertThumbPage(int index)
{
mDocumentThumbs.insert(index, UBThumbnailAdaptor::get(mCurrentDocument, index));
emit documentPageAdded(index);
}
void UBDocumentContainer::reloadThumbnails()
{
if (mCurrentDocument)
{
UBThumbnailAdaptor::load(mCurrentDocument, mDocumentThumbs);
emit documentThumbnailsUpdated(this);
}
}
int UBDocumentContainer::pageFromSceneIndex(int sceneIndex)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool())
return sceneIndex;
return sceneIndex+1;
}
int UBDocumentContainer::sceneIndexFromPage(int page)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool())
return page;
return page-1;
}

@ -0,0 +1,67 @@
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOCUMENTCONTAINER_H_
#define UBDOCUMENTCONTAINER_H_
#include <QtGui>
#include "UBDocumentProxy.h"
class UBDocumentContainer : public QObject
{
Q_OBJECT
public:
UBDocumentContainer(QObject * parent = 0);
virtual ~UBDocumentContainer();
void setDocument(UBDocumentProxy* document, bool forceReload = false);
UBDocumentProxy* selectedDocument(){return mCurrentDocument;}
int pageCount(){return mDocumentThumbs.size();}
const QPixmap* pageAt(int index){return mDocumentThumbs[index];}
static int pageFromSceneIndex(int sceneIndex);
static int sceneIndexFromPage(int sceneIndex);
void duplicatePages(QList<int>& pageIndexes);
void movePageToIndex(int source, int target);
void deletePages(QList<int>& pageIndexes);
void addPage(int index);
void updatePage(int index);
private:
void deleteThumbPage(int index);
void updateThumbPage(int index);
void insertThumbPage(int index);
UBDocumentProxy* mCurrentDocument;
QList<const QPixmap*> mDocumentThumbs;
protected:
void reloadThumbnails();
signals:
void documentSet(UBDocumentProxy* document);
void documentPageAdded(int index);
void documentPageDeleted(int index);
void documentPageUpdated(int index);
void documentThumbnailsUpdated(UBDocumentContainer* source);
};
#endif /* UBDOCUMENTPROXY_H_ */

File diff suppressed because it is too large Load Diff

@ -1,145 +1,142 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBDOCUMENTCONTROLLER_H_ #ifndef UBDOCUMENTCONTROLLER_H_
#define UBDOCUMENTCONTROLLER_H_ #define UBDOCUMENTCONTROLLER_H_
#include <QtGui> #include <QtGui>
#include "document/UBDocumentContainer.h"
namespace Ui
{ namespace Ui
class documents; {
} class documents;
}
#include "gui/UBMessageWindow.h"
#include "gui/UBMessageWindow.h"
class UBGraphicsScene;
class QDialog; class UBGraphicsScene;
class UBDocumentProxy; class QDialog;
class UBBoardController; class UBDocumentProxy;
class UBThumbnailsScene; class UBBoardController;
class UBDocumentGroupTreeItem; class UBThumbnailsScene;
class UBDocumentProxyTreeItem; class UBDocumentGroupTreeItem;
class UBMainWindow; class UBDocumentProxyTreeItem;
class UBDocumentToolsPalette; class UBMainWindow;
class UBDocumentToolsPalette;
class UBDocumentController : public QObject
{ class UBDocumentController : public UBDocumentContainer
Q_OBJECT; {
Q_OBJECT;
public:
UBDocumentController(UBMainWindow* mainWindow); public:
virtual ~UBDocumentController(); UBDocumentController(UBMainWindow* mainWindow);
virtual ~UBDocumentController();
void closing();
QWidget* controlView(); void closing();
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy); QWidget* controlView();
bool addFileToDocument(UBDocumentProxy* document); UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy);
UBDocumentProxy* getCurrentDocument() { return mCurrentDocument; }; bool addFileToDocument(UBDocumentProxy* document);
void deletePages(QList<QGraphicsItem*> itemsToDelete); void deletePages(QList<QGraphicsItem*> itemsToDelete);
int getSelectedItemIndex(); int getSelectedItemIndex();
bool pageCanBeMovedUp(int page); bool pageCanBeMovedUp(int page);
bool pageCanBeMovedDown(int page); bool pageCanBeMovedDown(int page);
bool pageCanBeDuplicated(int page); bool pageCanBeDuplicated(int page);
bool pageCanBeDeleted(int page); bool pageCanBeDeleted(int page);
signals: signals:
void refreshThumbnails(); //void refreshThumbnails();
void exportDone(); void exportDone();
void movedToIndex(int index); //void movedToIndex(int index);
public slots: public slots:
void createNewDocument(); void createNewDocument();
void createNewDocumentGroup(); void createNewDocumentGroup();
void deleteSelectedItem(); void deleteSelectedItem();
void renameSelectedItem(); void renameSelectedItem();
void openSelectedItem(); void openSelectedItem();
void duplicateSelectedItem(); void duplicateSelectedItem();
void importFile(); void importFile();
void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target); void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target);
void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true); void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true);
void show(); void show();
void hide(); void hide();
void showMessage(const QString& message, bool showSpinningWheel); void showMessage(const QString& message, bool showSpinningWheel);
void hideMessage(); void hideMessage();
void toggleDocumentToolsPalette(); void toggleDocumentToolsPalette();
void cut(); void cut();
void copy(); void copy();
void paste(); void paste();
void focusChanged(QWidget *old, QWidget *current); void focusChanged(QWidget *old, QWidget *current);
void reloadThumbs(); //void reloadThumbs();
protected: protected:
virtual void setupViews(); virtual void setupViews();
virtual void setupToolbar(); virtual void setupToolbar();
void setupPalettes(); void setupPalettes();
bool isOKToOpenDocument(UBDocumentProxy* proxy); bool isOKToOpenDocument(UBDocumentProxy* proxy);
UBGraphicsScene* activeScene(); UBDocumentProxy* selectedDocumentProxy();
UBDocumentProxy* selectedDocumentProxy(); UBDocumentProxyTreeItem* selectedDocumentProxyTreeItem();
UBDocumentProxyTreeItem* selectedDocumentProxyTreeItem(); UBDocumentGroupTreeItem* selectedDocumentGroupTreeItem();
UBDocumentGroupTreeItem* selectedDocumentGroupTreeItem(); QStringList allGroupNames();
QStringList allGroupNames();
enum LastSelectedElementType
enum LastSelectedElementType {
{ None = 0, Folder, Document, Page
None = 0, Folder, Document, Page };
};
LastSelectedElementType mSelectionType;
LastSelectedElementType mSelectionType;
private:
private: QWidget *mParentWidget;
QWidget *mParentWidget; UBBoardController *mBoardController;
UBBoardController *mBoardController; Ui::documents* mDocumentUI;
Ui::documents* mDocumentUI; UBMainWindow* mMainWindow;
UBMainWindow* mMainWindow; QWidget *mDocumentWidget;
QWidget *mDocumentWidget; QPointer<UBMessageWindow> mMessageWindow;
QPointer<UBMessageWindow> mMessageWindow; QAction* mAddFolderOfImagesAction;
QAction* mAddFolderOfImagesAction; QAction* mAddFileToDocumentAction;
QAction* mAddFileToDocumentAction; QAction* mAddImagesAction;
QAction* mAddImagesAction; bool mIsClosing;
bool mIsClosing; UBDocumentToolsPalette *mToolsPalette;
UBDocumentToolsPalette *mToolsPalette; bool mToolsPalettePositionned;
bool mToolsPalettePositionned; UBDocumentGroupTreeItem* mTrashTi;
UBDocumentGroupTreeItem* mTrashTi;
UBDocumentProxy* mCurrentDocument; private slots:
QList<QPixmap> mDocumentThumbs; void documentZoomSliderValueChanged (int value);
void loadDocumentProxies();
private slots: void itemSelectionChanged();
void documentZoomSliderValueChanged (int value); void exportDocument();
void loadDocumentProxies(); void itemChanged(QTreeWidgetItem * item, int column);
void itemSelectionChanged(); void thumbnailViewResized();
void refreshDocumentThumbnailsView(); void pageSelectionChanged();
void exportDocument(); void selectionChanged();
void itemChanged(QTreeWidgetItem * item, int column); void documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex);
void thumbnailViewResized(); void pageDoubleClicked(QGraphicsItem* item, int index);
void pageSelectionChanged(); void pageClicked(QGraphicsItem* item, int index);
void selectionChanged(); void itemClicked(QTreeWidgetItem * item, int column );
void documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex); void addToDocument();
void pageDoubleClicked(QGraphicsItem* item, int index); void addDocumentInTree(UBDocumentProxy* pDocument);
void pageClicked(QGraphicsItem* item, int index); void updateDocumentInTree(UBDocumentProxy* pDocument);
void itemClicked(QTreeWidgetItem * item, int column ); void addFolderOfImages();
void addToDocument(); void addFileToDocument();
void addDocumentInTree(UBDocumentProxy* pDocument); void addImages();
void updateDocumentInTree(UBDocumentProxy* pDocument);
void addFolderOfImages(); void refreshDocumentThumbnailsView(UBDocumentContainer* source);
void addFileToDocument(); };
void addImages();
};
#endif /* UBDOCUMENTCONTROLLER_H_ */
#endif /* UBDOCUMENTCONTROLLER_H_ */

@ -1,232 +1,232 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBDocumentProxy.h" #include "UBDocumentProxy.h"
#include "frameworks/UBStringUtils.h" #include "frameworks/UBStringUtils.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBDocumentManager.h" #include "core/UBDocumentManager.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBDocumentProxy::UBDocumentProxy() UBDocumentProxy::UBDocumentProxy()
: mPageCount(0) : mPageCount(0)
{ {
init(); init();
} }
UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath) UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath)
: mPageCount(0) : mPageCount(0)
{ {
init(); init();
setPersistencePath(pPersistancePath); setPersistencePath(pPersistancePath);
} }
void UBDocumentProxy::init() void UBDocumentProxy::init()
{ {
setMetaData(UBSettings::documentGroupName, ""); setMetaData(UBSettings::documentGroupName, "");
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate)); setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate));
setUuid(QUuid::createUuid()); setUuid(QUuid::createUuid());
setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize()); setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize());
//teacherGuide metadata //teacherGuide metadata
setMetaData(UBSettings::sessionTitle,""); setMetaData(UBSettings::sessionTitle,"");
setMetaData(UBSettings::sessionAuthors,""); setMetaData(UBSettings::sessionAuthors,"");
setMetaData(UBSettings::sessionObjectives,""); setMetaData(UBSettings::sessionObjectives,"");
setMetaData(UBSettings::sessionKeywords,""); setMetaData(UBSettings::sessionKeywords,"");
setMetaData(UBSettings::sessionGradeLevel,""); setMetaData(UBSettings::sessionGradeLevel,"");
setMetaData(UBSettings::sessionSubjects,""); setMetaData(UBSettings::sessionSubjects,"");
setMetaData(UBSettings::sessionType,""); setMetaData(UBSettings::sessionType,"");
setMetaData(UBSettings::sessionLicence,""); setMetaData(UBSettings::sessionLicence,"");
} }
UBDocumentProxy::~UBDocumentProxy() UBDocumentProxy::~UBDocumentProxy()
{ {
// NOOP // NOOP
} }
int UBDocumentProxy::pageCount() int UBDocumentProxy::pageCount()
{ {
return mPageCount; return mPageCount;
} }
void UBDocumentProxy::setPageCount(int pPageCount) void UBDocumentProxy::setPageCount(int pPageCount)
{ {
mPageCount = pPageCount; mPageCount = pPageCount;
} }
int UBDocumentProxy::incPageCount() int UBDocumentProxy::incPageCount()
{ {
if (mPageCount <= 0) if (mPageCount <= 0)
{ {
mPageCount = 1; mPageCount = 1;
} }
else else
{ {
mPageCount++; mPageCount++;
} }
return mPageCount; return mPageCount;
} }
int UBDocumentProxy::decPageCount() int UBDocumentProxy::decPageCount()
{ {
mPageCount --; mPageCount --;
if (mPageCount < 0) if (mPageCount < 0)
{ {
mPageCount = 0; mPageCount = 0;
} }
return mPageCount; return mPageCount;
} }
QString UBDocumentProxy::persistencePath() const QString UBDocumentProxy::persistencePath() const
{ {
return mPersistencePath; return mPersistencePath;
} }
void UBDocumentProxy::setPersistencePath(const QString& pPersistencePath) void UBDocumentProxy::setPersistencePath(const QString& pPersistencePath)
{ {
if (pPersistencePath != mPersistencePath) if (pPersistencePath != mPersistencePath)
{ {
mIsModified = true; mIsModified = true;
mPersistencePath = pPersistencePath; mPersistencePath = pPersistencePath;
} }
} }
void UBDocumentProxy::setMetaData(const QString& pKey, const QVariant& pValue) void UBDocumentProxy::setMetaData(const QString& pKey, const QVariant& pValue)
{ {
if (mMetaDatas.contains(pKey) && mMetaDatas.value(pKey) == pValue) if (mMetaDatas.contains(pKey) && mMetaDatas.value(pKey) == pValue)
return; return;
else else
{ {
mIsModified = true; mIsModified = true;
mMetaDatas.insert(pKey, pValue); mMetaDatas.insert(pKey, pValue);
if (pKey == UBSettings::documentUpdatedAt) if (pKey == UBSettings::documentUpdatedAt)
{ {
UBDocumentManager *documentManager = UBDocumentManager::documentManager(); UBDocumentManager *documentManager = UBDocumentManager::documentManager();
if (documentManager) if (documentManager)
documentManager->emitDocumentUpdated(this); documentManager->emitDocumentUpdated(this);
} }
} }
} }
QVariant UBDocumentProxy::metaData(const QString& pKey) const QVariant UBDocumentProxy::metaData(const QString& pKey) const
{ {
if (mMetaDatas.contains(pKey)) if (mMetaDatas.contains(pKey))
{ {
return mMetaDatas.value(pKey); return mMetaDatas.value(pKey);
} }
else else
{ {
qDebug() << "Unknown metadata key" << pKey; qDebug() << "Unknown metadata key" << pKey;
return QString(""); // failsafe return QString(""); // failsafe
} }
} }
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const QHash<QString, QVariant> UBDocumentProxy::metaDatas() const
{ {
return mMetaDatas; return mMetaDatas;
} }
QString UBDocumentProxy::name() const QString UBDocumentProxy::name() const
{ {
return metaData(UBSettings::documentName).toString(); return metaData(UBSettings::documentName).toString();
} }
QString UBDocumentProxy::groupName() const QString UBDocumentProxy::groupName() const
{ {
return metaData(UBSettings::documentGroupName).toString(); return metaData(UBSettings::documentGroupName).toString();
} }
QSize UBDocumentProxy::defaultDocumentSize() const QSize UBDocumentProxy::defaultDocumentSize() const
{ {
if (mMetaDatas.contains(UBSettings::documentSize)) if (mMetaDatas.contains(UBSettings::documentSize))
return metaData(UBSettings::documentSize).toSize(); return metaData(UBSettings::documentSize).toSize();
else else
return UBSettings::settings()->pageSize->get().toSize(); return UBSettings::settings()->pageSize->get().toSize();
} }
void UBDocumentProxy::setDefaultDocumentSize(QSize pSize) void UBDocumentProxy::setDefaultDocumentSize(QSize pSize)
{ {
if (defaultDocumentSize() != pSize) if (defaultDocumentSize() != pSize)
{ {
setMetaData(UBSettings::documentSize, QVariant(pSize)); setMetaData(UBSettings::documentSize, QVariant(pSize));
emit defaultDocumentSizeChanged(); emit defaultDocumentSizeChanged();
mIsModified = true; mIsModified = true;
} }
} }
void UBDocumentProxy::setDefaultDocumentSize(int pWidth, int pHeight) void UBDocumentProxy::setDefaultDocumentSize(int pWidth, int pHeight)
{ {
setDefaultDocumentSize(QSize(pWidth, pHeight)); setDefaultDocumentSize(QSize(pWidth, pHeight));
} }
QUuid UBDocumentProxy::uuid() const QUuid UBDocumentProxy::uuid() const
{ {
QString id = metaData(UBSettings::documentIdentifer).toString(); QString id = metaData(UBSettings::documentIdentifer).toString();
QString sUuid = id.replace(UBSettings::uniboardDocumentNamespaceUri + "/", ""); QString sUuid = id.replace(UBSettings::uniboardDocumentNamespaceUri + "/", "");
return QUuid(sUuid); return QUuid(sUuid);
} }
void UBDocumentProxy::setUuid(const QUuid& uuid) void UBDocumentProxy::setUuid(const QUuid& uuid)
{ {
setMetaData(UBSettings::documentIdentifer, setMetaData(UBSettings::documentIdentifer,
UBSettings::uniboardDocumentNamespaceUri + "/" + UBStringUtils::toCanonicalUuid(uuid)); UBSettings::uniboardDocumentNamespaceUri + "/" + UBStringUtils::toCanonicalUuid(uuid));
} }
QDateTime UBDocumentProxy::documentDate() QDateTime UBDocumentProxy::documentDate()
{ {
if(mMetaDatas.contains(UBSettings::documentDate)) if(mMetaDatas.contains(UBSettings::documentDate))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString()); return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString());
return QDateTime::currentDateTime(); return QDateTime::currentDateTime();
} }
QDateTime UBDocumentProxy::lastUpdate() QDateTime UBDocumentProxy::lastUpdate()
{ {
if(mMetaDatas.contains(UBSettings::documentUpdatedAt)) if(mMetaDatas.contains(UBSettings::documentUpdatedAt))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentUpdatedAt).toString()); return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentUpdatedAt).toString());
return QDateTime().currentDateTime(); return QDateTime().currentDateTime();
} }
bool UBDocumentProxy::isModified() const bool UBDocumentProxy::isModified() const
{ {
return mIsModified; return mIsModified;
} }

@ -1,95 +1,99 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBDOCUMENTPROXY_H_ #ifndef UBDOCUMENTPROXY_H_
#define UBDOCUMENTPROXY_H_ #define UBDOCUMENTPROXY_H_
#include <QtGui> #include <QtGui>
#include "frameworks/UBStringUtils.h" #include "frameworks/UBStringUtils.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
class UBGraphicsScene; class UBGraphicsScene;
class UBDocumentProxy : public QObject class UBDocumentProxy : public QObject
{ {
Q_OBJECT; Q_OBJECT
public: friend class UBPersistenceManager;
UBDocumentProxy(); public:
UBDocumentProxy(const QString& pPersistencePath);
UBDocumentProxy();
virtual ~UBDocumentProxy(); UBDocumentProxy(const QString& pPersistencePath);
QString persistencePath() const; virtual ~UBDocumentProxy();
void setPersistencePath(const QString& pPersistencePath); QString persistencePath() const;
void setMetaData(const QString& pKey , const QVariant& pValue); void setPersistencePath(const QString& pPersistencePath);
QVariant metaData(const QString& pKey) const;
QHash<QString, QVariant> metaDatas() const; void setMetaData(const QString& pKey , const QVariant& pValue);
QVariant metaData(const QString& pKey) const;
QString name() const; QHash<QString, QVariant> metaDatas() const;
QString groupName() const;
QDateTime documentDate(); QString name() const;
QString groupName() const;
QDateTime lastUpdate(); QDateTime documentDate();
QDateTime lastUpdate();
QSize defaultDocumentSize() const;
void setDefaultDocumentSize(QSize pSize);
void setDefaultDocumentSize(int pWidth, int pHeight); QSize defaultDocumentSize() const;
void setDefaultDocumentSize(QSize pSize);
QUuid uuid() const; void setDefaultDocumentSize(int pWidth, int pHeight);
void setUuid(const QUuid& uuid);
QUuid uuid() const;
bool isModified() const; void setUuid(const QUuid& uuid);
int pageCount(); bool isModified() const;
void setPageCount(int pPageCount);
int incPageCount(); int pageCount();
int decPageCount();
protected:
signals: void setPageCount(int pPageCount);
void defaultDocumentSizeChanged(); int incPageCount();
int decPageCount();
private:
signals:
void init(); void defaultDocumentSizeChanged();
QString mPersistencePath; private:
QHash<QString, QVariant> mMetaDatas; void init();
bool mIsModified; QString mPersistencePath;
int mPageCount; QHash<QString, QVariant> mMetaDatas;
}; bool mIsModified;
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2) int mPageCount;
{
return proxy1.persistencePath() == proxy2.persistencePath(); };
}
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2)
inline uint qHash(const UBDocumentProxy &key) {
{ return proxy1.persistencePath() == proxy2.persistencePath();
return qHash(key.persistencePath()); }
}
inline uint qHash(const UBDocumentProxy &key)
{
#endif /* UBDOCUMENTPROXY_H_ */ return qHash(key.persistencePath());
}
#endif /* UBDOCUMENTPROXY_H_ */

@ -1,6 +1,8 @@
HEADERS += src/document/UBDocumentController.h \ HEADERS += src/document/UBDocumentController.h \
src/document/UBDocumentContainer.h \
src/document/UBDocumentProxy.h src/document/UBDocumentProxy.h
SOURCES += src/document/UBDocumentController.cpp \ SOURCES += src/document/UBDocumentController.cpp \
src/document/UBDocumentContainer.cpp \
src/document/UBDocumentProxy.cpp src/document/UBDocumentProxy.cpp

@ -142,8 +142,8 @@ void UBGraphicsMediaItem::clearSource()
{ {
QString path = mediaFileUrl().toLocalFile(); QString path = mediaFileUrl().toLocalFile();
//if path is absolute clean duplicated path string //if path is absolute clean duplicated path string
if (!path.contains(UBApplication::boardController->activeDocument()->persistencePath())) if (!path.contains(UBApplication::boardController->selectedDocument()->persistencePath()))
path = UBApplication::boardController->activeDocument()->persistencePath() + "/" + path; path = UBApplication::boardController->selectedDocument()->persistencePath() + "/" + path;
if (!UBFileSystemUtils::deleteFile(path)) if (!UBFileSystemUtils::deleteFile(path))
qDebug() << "cannot delete file: " << path; qDebug() << "cannot delete file: " << path;

@ -20,6 +20,7 @@
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "document/UBDocumentContainer.h"
#include "globals/UBGlobals.h" #include "globals/UBGlobals.h"
@ -334,7 +335,7 @@ QString UBFileSystemUtils::normalizeFilePath(const QString& pFilePath)
QString UBFileSystemUtils::digitFileFormat(const QString& s, int digit) QString UBFileSystemUtils::digitFileFormat(const QString& s, int digit)
{ {
int pageDigit = UBApplication::boardController->pageFromSceneIndex(digit); int pageDigit = UBDocumentContainer::pageFromSceneIndex(digit);
return s.arg(pageDigit, 3, 10, QLatin1Char('0')); return s.arg(pageDigit, 3, 10, QLatin1Char('0'));
} }

@ -1,384 +1,273 @@
/* /*
* 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QList> #include <QList>
#include <QPointF> #include <QPointF>
#include <QPixmap> #include <QPixmap>
#include <QTransform> #include <QTransform>
#include <QScrollBar> #include <QScrollBar>
#include <QFontMetrics> #include <QFontMetrics>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "UBDocumentNavigator.h" #include "UBDocumentNavigator.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "adaptors/UBThumbnailAdaptor.h" #include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h" #include "adaptors/UBSvgSubsetAdaptor.h"
#include "document/UBDocumentController.h" #include "document/UBDocumentController.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "board/UBBoardPaletteManager.h" #include "board/UBBoardPaletteManager.h"
#include "core/UBApplicationController.h" #include "core/UBApplicationController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
/** /**
* \brief Constructor * \brief Constructor
* @param parent as the parent widget * @param parent as the parent widget
* @param name as the object name * @param name as the object name
*/ */
UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGraphicsView(parent) UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGraphicsView(parent)
, mScene(NULL) , mScene(NULL)
, mCrntItem(NULL) , mNbColumns(1)
, mCrntDoc(NULL) , mThumbnailWidth(0)
, mNbColumns(1) , mThumbnailMinWidth(100)
, mThumbnailWidth(0) {
, mThumbnailMinWidth(100) setObjectName(name);
, bNavig(false) mScene = new QGraphicsScene(this);
{ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setObjectName(name); setScene(mScene);
mScene = new QGraphicsScene(this); mThumbnailWidth = width() - 2*border();
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(mScene); setFrameShadow(QFrame::Plain);
mThumbnailWidth = width() - 2*border();
connect(UBApplication::boardController, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(generateThumbnails(UBDocumentContainer*)));
setFrameShadow(QFrame::Plain); connect(UBApplication::boardController, SIGNAL(documentPageUpdated(int)), this, SLOT(updateSpecificThumbnail(int)));
connect(UBApplication::boardController, SIGNAL(pageSelectionChanged(int)), this, SLOT(onScrollToSelectedPage(int)));
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(generateThumbnails())); }
connect(UBApplication::boardController, SIGNAL(newPageAdded()), this, SLOT(addNewPage()));
connect(mScene, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); /**
connect(UBApplication::boardController, SIGNAL(documentReorganized(int)), this, SLOT(onMovedToIndex(int))); * \brief Destructor
connect(UBApplication::boardController, SIGNAL(scrollToSelectedPage()), this, SLOT(onScrollToSelectedPage())); */
} UBDocumentNavigator::~UBDocumentNavigator()
{
/** if(NULL != mScene)
* \brief Destructor {
*/ delete mScene;
UBDocumentNavigator::~UBDocumentNavigator() mScene = NULL;
{ }
if(NULL != mCrntItem) }
{
delete mCrntItem; /**
mCrntItem = NULL; * \brief Generate the thumbnails
} */
void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
if(NULL != mScene) {
{
delete mScene; mThumbsWithLabels.clear();
mScene = NULL; foreach(QGraphicsItem* it, mScene->items())
} {
} mScene->removeItem(it);
delete it;
/** }
* \brief Set the current document
* @param document as the new document for(int i = 0; i < source->selectedDocument()->pageCount(); i++)
*/ {
void UBDocumentNavigator::setDocument(UBDocumentProxy *document) const QPixmap* pix = source->pageAt(i);
{ UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i);
// Here we set a new document to the navigator. We must clear the current UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(tr("Page %0").arg(UBDocumentContainer::pageFromSceneIndex(i)));
// content and add all the pages of the given document.
if(document) UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem);
{ thumbWithText.setBorder(border());
mCrntDoc = document; mThumbsWithLabels.append(thumbWithText);
}
} mScene->addItem(pixmapItem);
mScene->addItem(labelItem);
/** }
* \brief Generate the thumbnails
*/ // Draw the items
void UBDocumentNavigator::generateThumbnails() refreshScene();
{ }
// Get the thumbnails
QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc); void UBDocumentNavigator::onScrollToSelectedPage(int index)
{
mThumbsWithLabels.clear(); qDebug() << "Selection in widet: " << index;
foreach(QGraphicsItem* it, mScene->items()) int c = 0;
{ foreach(UBImgTextThumbnailElement el, mThumbsWithLabels)
mScene->removeItem(it); {
delete it; if (c==index)
} {
el.getThumbnail()->setSelected(true);
for(int i = 0; i < thumbs.count(); i++) }
{ else
QPixmap pix = thumbs.at(i); {
QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, i); el.getThumbnail()->setSelected(false);
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(tr("Page %0").arg(UBApplication::boardController->pageFromSceneIndex(i))); }
c++;
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem); }
thumbWithText.setBorder(border()); centerOn(mThumbsWithLabels[index].getThumbnail());
mThumbsWithLabels.append(thumbWithText); }
mScene->addItem(pixmapItem); /**
mScene->addItem(labelItem); * \brief Refresh the given thumbnail
* @param iPage as the given page related thumbnail
// Get the selected item */
if(UBApplication::boardController->activeSceneIndex() == i) void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
{ {
mCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pixmapItem); // Generate the new thumbnail
mCrntItem->setSelected(true); //UBGraphicsScene* pScene = UBApplication::boardController->activeScene();
}
} const QPixmap* pix = UBApplication::boardController->pageAt(iPage);
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix,
// Draw the items UBApplication::boardController->selectedDocument(), iPage);
refreshScene();
} // Get the old thumbnail
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail();
/** if(NULL != oldItem)
* \brief Refresh the given thumbnail {
* @param iPage as the given page related thumbnail mScene->removeItem(oldItem);
*/ mScene->addItem(newItem);
void UBDocumentNavigator::updateSpecificThumbnail(int iPage) mThumbsWithLabels[iPage].setThumbnail(newItem);
{ delete oldItem;
// Generate the new thumbnail }
UBGraphicsScene* pScene = UBApplication::boardController->activeScene();
}
if(NULL != pScene)
{ /**
// Save the current state of the scene * \brief Put the element in the right place in the scene.
pScene->setModified(true); */
if(UBApplication::boardController) void UBDocumentNavigator::refreshScene()
{ {
UBApplication::boardController->persistCurrentScene(); qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio;
}else
{ for(int i = 0; i < mThumbsWithLabels.size(); i++)
UBThumbnailAdaptor::persistScene(mCrntDoc->persistencePath(), pScene, iPage); {
} // Get the item
UBImgTextThumbnailElement& item = mThumbsWithLabels[i];
// Load it int columnIndex = i % mNbColumns;
QPixmap pix = UBThumbnailAdaptor::load(mCrntDoc, iPage); int rowIndex = i / mNbColumns;
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage); item.Place(rowIndex, columnIndex, mThumbnailWidth, thumbnailHeight);
if(pixmapItem) }
{ }
// Get the old thumbnail
QGraphicsItem* pItem = mThumbsWithLabels.at(iPage).getThumbnail(); /**
if(NULL != pItem) * \brief Set the number of thumbnails columns
{ * @param nbColumns as the number of columns
mScene->removeItem(pItem); */
mScene->addItem(pixmapItem); void UBDocumentNavigator::setNbColumns(int nbColumns)
mThumbsWithLabels[iPage].setThumbnail(pixmapItem); {
delete pItem; mNbColumns = nbColumns;
} }
}
} /**
} * \brief Get the number of columns
* @return the number of thumbnails columns
/** */
* \brief Add a new page to the thumbnails list int UBDocumentNavigator::nbColumns()
* {
* This method is called automatically by the board controller each time the user return mNbColumns;
* adds a new page, duplicates a page or imports a document. }
*/
void UBDocumentNavigator::addNewPage() /**
{ * \brief Set the thumbnails minimum width
if(!bNavig) * @param width as the minimum width
{ */
generateThumbnails(); void UBDocumentNavigator::setThumbnailMinWidth(int width)
if(NULL != mCrntItem) {
{ mThumbnailMinWidth = width;
mCrntItem->setSelected(true); }
}
} /**
} * \brief Get the thumbnails minimum width
* @return the minimum thumbnails width
/** */
* \brief Put the element in the right place in the scene. int UBDocumentNavigator::thumbnailMinWidth()
*/ {
void UBDocumentNavigator::refreshScene() return mThumbnailMinWidth;
{ }
qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio;
/**
for(int i = 0; i < mThumbsWithLabels.size(); i++) * \brief Get the border size
{ * @return the border size in pixels
// Get the item */
UBImgTextThumbnailElement& item = mThumbsWithLabels[i]; int UBDocumentNavigator::border()
int columnIndex = i % mNbColumns; {
int rowIndex = i / mNbColumns; return 20;
item.Place(rowIndex, columnIndex, mThumbnailWidth, thumbnailHeight); }
}
} /**
* \brief Handle the resize event
/** * @param event as the resize event
* \brief Set the number of thumbnails columns */
* @param nbColumns as the number of columns void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
*/ {
void UBDocumentNavigator::setNbColumns(int nbColumns) Q_UNUSED(event);
{
mNbColumns = nbColumns; // Update the thumbnails width
} mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth;
/** // Refresh the scene
* \brief Get the number of columns refreshScene();
* @return the number of thumbnails columns }
*/
int UBDocumentNavigator::nbColumns() /**
{ * \brief Handle the mouse press event
return mNbColumns; * @param event as the mouse event
} */
void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
/** {
* \brief Set the thumbnails minimum width QGraphicsItem* pClickedItem = itemAt(event->pos());
* @param width as the minimum width if(NULL != pClickedItem)
*/ {
void UBDocumentNavigator::setThumbnailMinWidth(int width)
{ // First, select the clicked item
mThumbnailMinWidth = width; UBSceneThumbnailNavigPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pClickedItem);
}
if(NULL == pCrntItem)
/** {
* \brief Get the thumbnails minimum width // If we fall here we may have clicked on the label instead of the thumbnail
* @return the minimum thumbnails width UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem);
*/ if(NULL != pTextItem)
int UBDocumentNavigator::thumbnailMinWidth() {
{ for(int i = 0; i < mThumbsWithLabels.size(); i++)
return mThumbnailMinWidth; {
} const UBImgTextThumbnailElement& el = mThumbsWithLabels.at(i);
if(el.getCaption() == pTextItem)
/** {
* \brief Get the border size pCrntItem = el.getThumbnail();
* @return the border size in pixels break;
*/ }
int UBDocumentNavigator::border() }
{ }
return 20; }
}
int index = 0;
/** for(int i = 0; i < mThumbsWithLabels.size(); i++)
* \brief Handle the resize event {
* @param event as the resize event if (mThumbsWithLabels.at(i).getThumbnail() == pCrntItem)
*/ {
void UBDocumentNavigator::resizeEvent(QResizeEvent *event) index = i;
{ break;
Q_UNUSED(event); }
}
// Update the thumbnails width qDebug() << "Selected Scene: " << index;
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; UBApplication::boardController->setActiveDocumentScene(index);
}
// Refresh the scene QGraphicsView::mousePressEvent(event);
refreshScene(); }
}
void UBDocumentNavigator::mouseReleaseEvent(QMouseEvent *event)
/** {
* \brief Handle the mouse press event event->accept();
* @param event as the mouse event }
*/
void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
{
QGraphicsItem* pClickedItem = itemAt(event->pos());
if(NULL != pClickedItem)
{
bNavig = true;
// First, select the clicked item
UBSceneThumbnailNavigPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pClickedItem);
if(NULL == pCrntItem)
{
// If we fall here we may have clicked on the label instead of the thumbnail
UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem);
if(NULL != pTextItem)
{
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
const UBImgTextThumbnailElement& el = mThumbsWithLabels.at(i);
if(el.getCaption() == pTextItem)
{
pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(el.getThumbnail());
break;
}
}
}
}
else
{
if(NULL != mCrntItem && mCrntItem != pCrntItem)
{
// Unselect the previous item
mCrntItem->setSelected(false);
int iOldPage = -1;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
if (mThumbsWithLabels.at(i).getThumbnail() == mCrntItem)
{
iOldPage = i;
break;
}
updateSpecificThumbnail(iOldPage);
mCrntItem = pCrntItem;
// Then display the related page
emit changeCurrentPage();
refreshScene();
}
}
bNavig = false;
}
QGraphicsView::mousePressEvent(event);
}
/**
* \brief Get the selected page number
* @return the selected page number
*/
int UBDocumentNavigator::selectedPageNumber()
{
int nbr = NO_PAGESELECTED;
if(NULL != mCrntItem)
{
for(int i = 0; i < mThumbsWithLabels.size(); i++)
if (mThumbsWithLabels.at(i).getThumbnail() == mCrntItem)
{
nbr = i;
break;
}
}
return nbr;
}
/**
* \brief Get the current document
* @return the current document
*/
UBDocumentProxy* UBDocumentNavigator::currentDoc()
{
return mCrntDoc;
}
/**
* \brief Occurs when the selection changed
*/
void UBDocumentNavigator::onSelectionChanged()
{
// QList<QGraphicsItem*> qlItems = mScene->selectedItems();
// qDebug() << "The number of selected items is " << qlItems.count();
}
/**
* \brief Occurs when a page has been moved to another index in the document
* @param index as the new index
*/
void UBDocumentNavigator::onMovedToIndex(int index)
{
if(index < mThumbsWithLabels.size()){
UBSceneThumbnailNavigPixmap* pItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(mThumbsWithLabels.at(index).getThumbnail());
if(NULL != pItem)
{
if(mCrntItem) mCrntItem->setSelected(false);//deselecting previous one
mCrntItem = pItem;
mCrntItem->setSelected(true);
centerOn(mCrntItem);
}
}
}

@ -1,84 +1,72 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBDOCUMENTNAVIGATOR_H #ifndef UBDOCUMENTNAVIGATOR_H
#define UBDOCUMENTNAVIGATOR_H #define UBDOCUMENTNAVIGATOR_H
#include <QResizeEvent> #include <QResizeEvent>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QMouseEvent> #include <QMouseEvent>
#include <QThread> #include <QThread>
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "UBThumbnailWidget.h" #include "document/UBDocumentContainer.h"
#include "UBThumbnailWidget.h"
#define NO_PAGESELECTED -1
#define NO_PAGESELECTED -1
class UBDocumentNavigator : public QGraphicsView
{ class UBDocumentNavigator : public QGraphicsView
Q_OBJECT {
public: Q_OBJECT
UBDocumentNavigator(QWidget* parent=0, const char* name="documentNavigator"); public:
~UBDocumentNavigator(); UBDocumentNavigator(QWidget* parent=0, const char* name="documentNavigator");
~UBDocumentNavigator();
void setDocument(UBDocumentProxy* document);
void setNbColumns(int nbColumns); void setNbColumns(int nbColumns);
int nbColumns(); int nbColumns();
void setThumbnailMinWidth(int width); void setThumbnailMinWidth(int width);
int thumbnailMinWidth(); int thumbnailMinWidth();
int selectedPageNumber();
UBDocumentProxy* currentDoc(); public slots:
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
signals: void generateThumbnails(UBDocumentContainer* source);
void changeCurrentPage(); void updateSpecificThumbnail(int iPage);
public slots: protected:
void onMovedToIndex(int index); virtual void resizeEvent(QResizeEvent *event);
void onScrollToSelectedPage() { centerOn(mCrntItem); } virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
protected:
virtual void resizeEvent(QResizeEvent *event); private:
virtual void mousePressEvent(QMouseEvent *event);
void refreshScene();
private slots: int border();
void addNewPage();
void onSelectionChanged();
void generateThumbnails(); /** The scene */
QGraphicsScene* mScene;
private: /** The current selected item */
void refreshScene(); //UBSceneThumbnailNavigPixmap* mCrntItem;
void updateSpecificThumbnail(int iPage); /** The list of current thumbnails with labels*/
int border(); QList<UBImgTextThumbnailElement> mThumbsWithLabels;
/** The current number of columns */
int mNbColumns;
/** The scene */ /** The current thumbnails width */
QGraphicsScene* mScene; int mThumbnailWidth;
/** The current selected item */ /** The current thumbnails minimum width */
UBSceneThumbnailNavigPixmap* mCrntItem; int mThumbnailMinWidth;
/** The current document */ };
UBDocumentProxy* mCrntDoc;
/** The list of current thumbnails with labels*/ #endif // UBDOCUMENTNAVIGATOR_H
QList<UBImgTextThumbnailElement> mThumbsWithLabels;
/** The current number of columns */
int mNbColumns;
/** The current thumbnails width */
int mThumbnailWidth;
/** The current thumbnails minimum width */
int mThumbnailMinWidth;
/** A flag indicating that a thumbnail refresh is in progress */
bool bNavig;
};
#endif // UBDOCUMENTNAVIGATOR_H

@ -1,316 +1,315 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBDocumentThumbnailWidget.h" #include "UBDocumentThumbnailWidget.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBMimeData.h" #include "core/UBMimeData.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "document/UBDocumentController.h" #include "document/UBDocumentController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent) UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent)
: UBThumbnailWidget(parent) : UBThumbnailWidget(parent)
, mDropCaretRectItem(0) , mDropCaretRectItem(0)
, mClosestDropItem(0) , mClosestDropItem(0)
, mDragEnabled(true) , mDragEnabled(true)
, mScrollMagnitude(0) , mScrollMagnitude(0)
{ {
bCanDrag = false; bCanDrag = false;
mScrollTimer = new QTimer(this); mScrollTimer = new QTimer(this);
connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll())); connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll()));
} }
UBDocumentThumbnailWidget::~UBDocumentThumbnailWidget() UBDocumentThumbnailWidget::~UBDocumentThumbnailWidget()
{ {
// NOOP // NOOP
} }
void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event) void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
{ {
if (!dragEnabled()) if (!dragEnabled())
{ {
event->ignore(); event->ignore();
return; return;
} }
if (!(event->buttons() & Qt::LeftButton)) if (!(event->buttons() & Qt::LeftButton))
return; return;
if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance()) if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance())
return; return;
QList<QGraphicsItem*> graphicsItems = items(mMousePressPos); QList<QGraphicsItem*> graphicsItems = items(mMousePressPos);
UBSceneThumbnailPixmap* sceneItem = 0; UBSceneThumbnailPixmap* sceneItem = 0;
while (!graphicsItems.isEmpty() && !sceneItem) while (!graphicsItems.isEmpty() && !sceneItem)
sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst()); sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst());
if (sceneItem) if (sceneItem)
{ {
int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneItem->sceneIndex()); int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex());
if(pageIndex != 0){ if(pageIndex != 0){
QDrag *drag = new QDrag(this); QDrag *drag = new QDrag(this);
QList<UBMimeDataItem> mimeDataItems; QList<UBMimeDataItem> mimeDataItems;
foreach (QGraphicsItem *item, selectedItems()) foreach (QGraphicsItem *item, selectedItems())
mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item))); mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item)));
UBMimeData *mime = new UBMimeData(mimeDataItems); UBMimeData *mime = new UBMimeData(mimeDataItems);
drag->setMimeData(mime); drag->setMimeData(mime);
drag->setPixmap(sceneItem->pixmap().scaledToWidth(100)); drag->setPixmap(sceneItem->pixmap().scaledToWidth(100));
drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2)); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2));
drag->exec(Qt::MoveAction); drag->exec(Qt::MoveAction);
} }
} }
UBThumbnailWidget::mouseMoveEvent(event); UBThumbnailWidget::mouseMoveEvent(event);
} }
void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event) void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event)
{ {
if (!event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) if (!event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{ {
event->setDropAction(Qt::IgnoreAction); event->setDropAction(Qt::IgnoreAction);
event->ignore(); event->ignore();
return; return;
} }
UBThumbnailWidget::dragEnterEvent(event); UBThumbnailWidget::dragEnterEvent(event);
} }
void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event) void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if (mScrollTimer->isActive()) if (mScrollTimer->isActive())
{ {
mScrollMagnitude = 0; mScrollMagnitude = 0;
mScrollTimer->stop(); mScrollTimer->stop();
} }
deleteDropCaret(); deleteDropCaret();
UBThumbnailWidget::dragLeaveEvent(event); UBThumbnailWidget::dragLeaveEvent(event);
} }
void UBDocumentThumbnailWidget::autoScroll() void UBDocumentThumbnailWidget::autoScroll()
{ {
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
} }
void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event)
{ {
QRect boundingFrame = frameRect(); QRect boundingFrame = frameRect();
//setting up automatic scrolling //setting up automatic scrolling
const int SCROLL_DISTANCE = 16; const int SCROLL_DISTANCE = 16;
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y();
if(qAbs(bottomDist) <= SCROLL_DISTANCE) if(qAbs(bottomDist) <= SCROLL_DISTANCE)
{ {
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
} }
else if(qAbs(topDist) <= SCROLL_DISTANCE) else if(qAbs(topDist) <= SCROLL_DISTANCE)
{ {
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
} }
else else
{ {
mScrollMagnitude = 0; mScrollMagnitude = 0;
mScrollTimer->stop(); mScrollTimer->stop();
} }
QList<UBSceneThumbnailPixmap*> pixmapItems; QList<UBSceneThumbnailPixmap*> pixmapItems;
foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame))) foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame)))
{ {
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item); UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item);
if (sceneItem) if (sceneItem)
pixmapItems.append(sceneItem); pixmapItems.append(sceneItem);
} }
int minDistance = 0; int minDistance = 0;
QGraphicsItem *underlyingItem = itemAt(event->pos()); QGraphicsItem *underlyingItem = itemAt(event->pos());
mClosestDropItem = dynamic_cast<UBSceneThumbnailPixmap*>(underlyingItem); mClosestDropItem = dynamic_cast<UBSceneThumbnailPixmap*>(underlyingItem);
int pageIndex = -1; int pageIndex = -1;
if(mClosestDropItem){ if(mClosestDropItem){
pageIndex = UBApplication::boardController->pageFromSceneIndex(mClosestDropItem->sceneIndex()); pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex());
if(pageIndex == 0){ if(pageIndex == 0){
event->acceptProposedAction(); event->acceptProposedAction();
return; return;
} }
} }
if (!mClosestDropItem) if (!mClosestDropItem)
{ {
foreach (UBSceneThumbnailPixmap *item, pixmapItems) foreach (UBSceneThumbnailPixmap *item, pixmapItems)
{ {
qreal scale = item->transform().m11(); qreal scale = item->transform().m11();
QPointF itemCenter( QPointF itemCenter(
item->pos().x() + item->boundingRect().width() * scale / 2, item->pos().x() + item->boundingRect().width() * scale / 2,
item->pos().y() + item->boundingRect().height() * scale / 2); item->pos().y() + item->boundingRect().height() * scale / 2);
int distance = (itemCenter.toPoint() - mapToScene(event->pos()).toPoint()).manhattanLength(); int distance = (itemCenter.toPoint() - mapToScene(event->pos()).toPoint()).manhattanLength();
if (!mClosestDropItem || distance < minDistance) if (!mClosestDropItem || distance < minDistance)
{ {
mClosestDropItem = item; mClosestDropItem = item;
minDistance = distance; minDistance = distance;
pageIndex = UBApplication::boardController->pageFromSceneIndex(mClosestDropItem->sceneIndex()); pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex());
} }
} }
} }
if (mClosestDropItem && pageIndex != 0) if (mClosestDropItem && pageIndex != 0)
{ {
qreal scale = mClosestDropItem->transform().m11(); qreal scale = mClosestDropItem->transform().m11();
QPointF itemCenter( QPointF itemCenter(
mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale / 2, mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale / 2,
mClosestDropItem->pos().y() + mClosestDropItem->boundingRect().height() * scale / 2); mClosestDropItem->pos().y() + mClosestDropItem->boundingRect().height() * scale / 2);
mDropIsRight = mapToScene(event->pos()).x() > itemCenter.x(); mDropIsRight = mapToScene(event->pos()).x() > itemCenter.x();
if (!mDropCaretRectItem && selectedItems().count() < mGraphicItems.count()) if (!mDropCaretRectItem && selectedItems().count() < mGraphicItems.count())
{ {
mDropCaretRectItem = new QGraphicsRectItem(0, scene()); mDropCaretRectItem = new QGraphicsRectItem(0, scene());
mDropCaretRectItem->setPen(QPen(Qt::darkGray)); mDropCaretRectItem->setPen(QPen(Qt::darkGray));
mDropCaretRectItem->setBrush(QBrush(Qt::lightGray)); mDropCaretRectItem->setBrush(QBrush(Qt::lightGray));
} }
QRectF dropCaretRect( QRectF dropCaretRect(
mDropIsRight ? mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale + spacing() / 2 - 1 : mClosestDropItem->pos().x() - spacing() / 2 - 1, mDropIsRight ? mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale + spacing() / 2 - 1 : mClosestDropItem->pos().x() - spacing() / 2 - 1,
mClosestDropItem->pos().y(), mClosestDropItem->pos().y(),
3, 3,
mClosestDropItem->boundingRect().height() * scale); mClosestDropItem->boundingRect().height() * scale);
if (mDropCaretRectItem) if (mDropCaretRectItem)
mDropCaretRectItem->setRect(dropCaretRect); mDropCaretRectItem->setRect(dropCaretRect);
} }
event->acceptProposedAction(); event->acceptProposedAction();
} }
void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event)
{ {
if (mScrollTimer->isActive()) if (mScrollTimer->isActive())
{ {
mScrollMagnitude = 0; mScrollMagnitude = 0;
mScrollTimer->stop(); mScrollTimer->stop();
} }
deleteDropCaret(); deleteDropCaret();
if (mClosestDropItem) if (mClosestDropItem)
{ {
int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem); int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem);
if(UBApplication::boardController->pageFromSceneIndex(targetIndex) == 0){ if(UBDocumentContainer::pageFromSceneIndex(targetIndex) == 0){
event->ignore(); event->ignore();
return; return;
} }
QList<UBMimeDataItem> mimeDataItems; QList<UBMimeDataItem> mimeDataItems;
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{ {
const UBMimeData* mimeData = qobject_cast<const UBMimeData*>(event->mimeData()); const UBMimeData* mimeData = qobject_cast<const UBMimeData*>(event->mimeData());
if (mimeData) if (mimeData)
mimeDataItems = mimeData->items(); mimeDataItems = mimeData->items();
} }
if (1 == mimeDataItems.count() && if (1 == mimeDataItems.count() &&
(mimeDataItems.at(0).sceneIndex() == mGraphicItems.indexOf(mClosestDropItem) || (mimeDataItems.at(0).sceneIndex() == mGraphicItems.indexOf(mClosestDropItem) ||
targetIndex == mimeDataItems.at(0).sceneIndex() || targetIndex == mimeDataItems.at(0).sceneIndex() ||
targetIndex == mimeDataItems.at(0).sceneIndex() + 1)) targetIndex == mimeDataItems.at(0).sceneIndex() + 1))
{ {
return; return;
} }
int sourceIndexOffset = 0; int sourceIndexOffset = 0;
int actualTargetIndex = targetIndex; int actualTargetIndex = targetIndex;
for (int i = mimeDataItems.count() - 1; i >= 0; i--) for (int i = mimeDataItems.count() - 1; i >= 0; i--)
{ {
UBMimeDataItem sourceItem = mimeDataItems.at(i); UBMimeDataItem sourceItem = mimeDataItems.at(i);
int actualSourceIndex = sourceItem.sceneIndex(); int actualSourceIndex = sourceItem.sceneIndex();
if (sourceItem.sceneIndex() >= targetIndex) if (sourceItem.sceneIndex() >= targetIndex)
actualSourceIndex += sourceIndexOffset; actualSourceIndex += sourceIndexOffset;
//event->acceptProposedAction(); //event->acceptProposedAction();
if (sourceItem.sceneIndex() < targetIndex) if (sourceItem.sceneIndex() < targetIndex)
{ {
if (actualSourceIndex != actualTargetIndex - 1) if (actualSourceIndex != actualTargetIndex - 1)
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex - 1); emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex - 1);
actualTargetIndex -= 1; actualTargetIndex -= 1;
} }
else else
{ {
if (actualSourceIndex != actualTargetIndex) if (actualSourceIndex != actualTargetIndex)
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex); emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex);
sourceIndexOffset += 1; sourceIndexOffset += 1;
} }
} }
} }
UBThumbnailWidget::dropEvent(event); UBThumbnailWidget::dropEvent(event);
} }
void UBDocumentThumbnailWidget::deleteDropCaret() void UBDocumentThumbnailWidget::deleteDropCaret()
{ {
if (mDropCaretRectItem && scene()) if (mDropCaretRectItem && scene())
{ {
scene()->removeItem(mDropCaretRectItem); scene()->removeItem(mDropCaretRectItem);
delete mDropCaretRectItem; delete mDropCaretRectItem;
mDropCaretRectItem = 0; mDropCaretRectItem = 0;
} }
} }
void UBDocumentThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems,
void UBDocumentThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels,
const QList<QUrl>& pItemPaths, const QStringList pLabels, const QString& pMimeType)
const QString& pMimeType) {
{ deleteDropCaret();
deleteDropCaret();
UBThumbnailWidget::setGraphicsItems(pGraphicsItems, pItemPaths, pLabels, pMimeType);
UBThumbnailWidget::setGraphicsItems(pGraphicsItems, pItemPaths, pLabels, pMimeType); }
}
void UBDocumentThumbnailWidget::setDragEnabled(bool enabled)
void UBDocumentThumbnailWidget::setDragEnabled(bool enabled) {
{ mDragEnabled = enabled;
mDragEnabled = enabled; }
}
bool UBDocumentThumbnailWidget::dragEnabled() const
bool UBDocumentThumbnailWidget::dragEnabled() const {
{ return mDragEnabled;
return mDragEnabled; }
}
void UBDocumentThumbnailWidget::hightlightItem(int index)
void UBDocumentThumbnailWidget::hightlightItem(int index) {
{ if (0 <= index && index < mLabelsItems.length())
if (0 <= index && index < mLabelsItems.length()) {
{ mLabelsItems.at(index)->highlight();
mLabelsItems.at(index)->highlight(); }
} if (0 <= index && index < mGraphicItems.length())
if (0 <= index && index < mGraphicItems.length()) {
{ UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(index));
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(index)); if (thumbnail)
if (thumbnail) thumbnail->highlight();
thumbnail->highlight(); }
}
selectItemAt(index);
selectItemAt(index); }
}

@ -1,455 +1,457 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBDocumentTreeWidget.h" #include "UBDocumentTreeWidget.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBMimeData.h" #include "core/UBMimeData.h"
#include "core/UBApplicationController.h" #include "core/UBApplicationController.h"
#include "core/UBDocumentManager.h" #include "core/UBDocumentManager.h"
#include "document/UBDocumentController.h" #include "document/UBDocumentController.h"
#include "adaptors/UBThumbnailAdaptor.h" #include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h" #include "adaptors/UBSvgSubsetAdaptor.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent) UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent)
: QTreeWidget(parent) : QTreeWidget(parent)
, mSelectedProxyTi(0) , mSelectedProxyTi(0)
, mDropTargetProxyTi(0) , mDropTargetProxyTi(0)
{ {
setDragDropMode(QAbstractItemView::InternalMove); setDragDropMode(QAbstractItemView::InternalMove);
setAutoScroll(true); setAutoScroll(true);
mScrollTimer = new QTimer(this); mScrollTimer = new QTimer(this);
connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*)) connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*))
, this, SLOT(documentUpdated(UBDocumentProxy*))); , this, SLOT(documentUpdated(UBDocumentProxy*)));
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)) connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int))
, this, SLOT(itemChangedValidation(QTreeWidgetItem *, int))); , this, SLOT(itemChangedValidation(QTreeWidgetItem *, int)));
connect(mScrollTimer, SIGNAL(timeout()) connect(mScrollTimer, SIGNAL(timeout())
, this, SLOT(autoScroll())); , this, SLOT(autoScroll()));
} }
UBDocumentTreeWidget::~UBDocumentTreeWidget() UBDocumentTreeWidget::~UBDocumentTreeWidget()
{ {
// NOOP // NOOP
} }
void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int column) void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int column)
{ {
if (column == 0) if (column == 0)
{ {
UBDocumentGroupTreeItem *group = dynamic_cast< UBDocumentGroupTreeItem *>(item); UBDocumentGroupTreeItem *group = dynamic_cast< UBDocumentGroupTreeItem *>(item);
if (group) if (group)
{ {
QString name = group->text(0); QString name = group->text(0);
for(int i = 0; i < topLevelItemCount (); i++) for(int i = 0; i < topLevelItemCount (); i++)
{ {
QTreeWidgetItem *someTopLevelItem = topLevelItem(i); QTreeWidgetItem *someTopLevelItem = topLevelItem(i);
if (someTopLevelItem != group && if (someTopLevelItem != group &&
someTopLevelItem->text(0) == name) someTopLevelItem->text(0) == name)
{ {
group->setText(0, tr("%1 (copy)").arg(name)); group->setText(0, tr("%1 (copy)").arg(name));
} }
} }
} }
} }
} }
Qt::DropActions UBDocumentTreeWidget::supportedDropActions() const Qt::DropActions UBDocumentTreeWidget::supportedDropActions() const
{ {
return Qt::MoveAction | Qt::CopyAction; return Qt::MoveAction | Qt::CopyAction;
} }
void UBDocumentTreeWidget::mousePressEvent(QMouseEvent *event) void UBDocumentTreeWidget::mousePressEvent(QMouseEvent *event)
{ {
QTreeWidgetItem* twItem = this->itemAt(event->pos()); QTreeWidgetItem* twItem = this->itemAt(event->pos());
mSelectedProxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(twItem); mSelectedProxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(twItem);
QTreeWidget::mousePressEvent(event); QTreeWidget::mousePressEvent(event);
} }
void UBDocumentTreeWidget::dragEnterEvent(QDragEnterEvent *event) void UBDocumentTreeWidget::dragEnterEvent(QDragEnterEvent *event)
{ {
event->acceptProposedAction(); event->acceptProposedAction();
} }
void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event) void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if (mScrollTimer->isActive()) if (mScrollTimer->isActive())
{ {
mScrollMagnitude = 0; mScrollMagnitude = 0;
mScrollTimer->stop(); mScrollTimer->stop();
} }
if (mDropTargetProxyTi) if (mDropTargetProxyTi)
{ {
mDropTargetProxyTi->setBackground(0, mBackground); mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0; mDropTargetProxyTi = 0;
} }
} }
void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event) void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event)
{ {
QRect boundingFrame = frameRect(); QRect boundingFrame = frameRect();
//setting up automatic scrolling //setting up automatic scrolling
const int SCROLL_DISTANCE = 4; const int SCROLL_DISTANCE = 4;
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y();
if(qAbs(bottomDist) <= SCROLL_DISTANCE) if(qAbs(bottomDist) <= SCROLL_DISTANCE)
{ {
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
} }
else if(qAbs(topDist) <= SCROLL_DISTANCE) else if(qAbs(topDist) <= SCROLL_DISTANCE)
{ {
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
} }
else else
{ {
mScrollMagnitude = 0; mScrollMagnitude = 0;
mScrollTimer->stop(); mScrollTimer->stop();
} }
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); QTreeWidgetItem* underlyingItem = this->itemAt(event->pos());
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{ {
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingItem); UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingItem);
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi) if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{ {
event->setDropAction(Qt::CopyAction); event->setDropAction(Qt::CopyAction);
event->accept(); event->accept();
} }
else else
{ {
event->ignore(); event->ignore();
} }
} }
else else
{ {
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem); UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem);
if (groupItem && mSelectedProxyTi && groupItem != mSelectedProxyTi->parent()) if (groupItem && mSelectedProxyTi && groupItem != mSelectedProxyTi->parent())
event->acceptProposedAction(); event->acceptProposedAction();
else else
event->ignore(); event->ignore();
} }
if (event->isAccepted()) if (event->isAccepted())
{ {
if (mDropTargetProxyTi) if (mDropTargetProxyTi)
{ {
if (underlyingItem != mDropTargetProxyTi) if (underlyingItem != mDropTargetProxyTi)
{ {
mBackground = underlyingItem->background(0); mBackground = underlyingItem->background(0);
mDropTargetProxyTi->setBackground(0, mBackground); mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = underlyingItem; mDropTargetProxyTi = underlyingItem;
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5"))); mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5")));
} }
} }
else else
{ {
mBackground = underlyingItem->background(0); mBackground = underlyingItem->background(0);
mDropTargetProxyTi = underlyingItem; mDropTargetProxyTi = underlyingItem;
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5"))); mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5")));
} }
} }
else if (mDropTargetProxyTi) else if (mDropTargetProxyTi)
{ {
mDropTargetProxyTi->setBackground(0, mBackground); mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0; mDropTargetProxyTi = 0;
} }
} }
void UBDocumentTreeWidget::focusInEvent(QFocusEvent *event) void UBDocumentTreeWidget::focusInEvent(QFocusEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
itemSelectionChanged(); // Tolik
QTreeWidget::focusInEvent(event); //itemSelectionChanged();
}
QTreeWidget::focusInEvent(event);
}
void UBDocumentTreeWidget::dropEvent(QDropEvent *event)
{
if (mDropTargetProxyTi) void UBDocumentTreeWidget::dropEvent(QDropEvent *event)
{ {
mDropTargetProxyTi->setBackground(0, mBackground); if (mDropTargetProxyTi)
mDropTargetProxyTi = 0; {
} mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); }
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem); QTreeWidgetItem* underlyingItem = this->itemAt(event->pos());
if (groupItem && mSelectedProxyTi && mSelectedProxyTi->proxy()) UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem);
{
UBDocumentGroupTreeItem *sourceGroupItem = dynamic_cast<UBDocumentGroupTreeItem*>(mSelectedProxyTi->parent()); if (groupItem && mSelectedProxyTi && mSelectedProxyTi->proxy())
bool isTrashItem = sourceGroupItem && sourceGroupItem->isTrashFolder(); {
if ((isTrashItem && !groupItem->isTrashFolder()) || UBDocumentGroupTreeItem *sourceGroupItem = dynamic_cast<UBDocumentGroupTreeItem*>(mSelectedProxyTi->parent());
(!isTrashItem && mSelectedProxyTi->proxy()->groupName() != groupItem->groupName())) bool isTrashItem = sourceGroupItem && sourceGroupItem->isTrashFolder();
{ if ((isTrashItem && !groupItem->isTrashFolder()) ||
QString groupName; (!isTrashItem && mSelectedProxyTi->proxy()->groupName() != groupItem->groupName()))
if (groupItem->isTrashFolder()) {
{ QString groupName;
QString oldGroupName = mSelectedProxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); if (groupItem->isTrashFolder())
groupName = UBSettings::trashedDocumentGroupNamePrefix + oldGroupName; {
} QString oldGroupName = mSelectedProxyTi->proxy()->metaData(UBSettings::documentGroupName).toString();
else groupName = UBSettings::trashedDocumentGroupNamePrefix + oldGroupName;
{ }
if (groupItem->groupName() == UBSettings::defaultDocumentGroupName) else
groupName = ""; {
else if (groupItem->groupName() == UBSettings::defaultDocumentGroupName)
groupName = groupItem->groupName(); groupName = "";
} else
mSelectedProxyTi->proxy()->setMetaData(UBSettings::documentGroupName, groupName); groupName = groupItem->groupName();
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mSelectedProxyTi->proxy()); }
mSelectedProxyTi->proxy()->setMetaData(UBSettings::documentGroupName, groupName);
mSelectedProxyTi->parent()->removeChild(mSelectedProxyTi); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mSelectedProxyTi->proxy());
int i = 0; mSelectedProxyTi->parent()->removeChild(mSelectedProxyTi);
for (i = 0; i < groupItem->childCount(); i++)
{ int i = 0;
QTreeWidgetItem *ti = groupItem->child(i); for (i = 0; i < groupItem->childCount(); i++)
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); {
if (pi) QTreeWidgetItem *ti = groupItem->child(i);
{ UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) if (pi)
{ {
break; if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
} {
} break;
} }
groupItem->insertChild(i, mSelectedProxyTi); }
}
if (isTrashItem) groupItem->insertChild(i, mSelectedProxyTi);
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() | Qt::ItemIsEditable);
if (isTrashItem)
if (groupItem->isTrashFolder()) mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() | Qt::ItemIsEditable);
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() ^ Qt::ItemIsEditable);
if (groupItem->isTrashFolder())
//clearSelection(); mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() ^ Qt::ItemIsEditable);
expandItem(groupItem);
scrollToItem(mSelectedProxyTi); //clearSelection();
expandItem(groupItem);
// disabled, as those 2 calls are buggy on windows, the item disappears if we selected them scrollToItem(mSelectedProxyTi);
//
setCurrentItem(mSelectedProxyTi); // disabled, as those 2 calls are buggy on windows, the item disappears if we selected them
mSelectedProxyTi->setSelected(true); //
setCurrentItem(mSelectedProxyTi);
event->setDropAction(Qt::IgnoreAction); mSelectedProxyTi->setSelected(true);
event->accept();
} event->setDropAction(Qt::IgnoreAction);
} event->accept();
else }
{ }
QTreeWidgetItem* underlyingTreeItem = this->itemAt(event->pos()); else
{
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingTreeItem); QTreeWidgetItem* underlyingTreeItem = this->itemAt(event->pos());
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{ UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingTreeItem);
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{ {
event->setDropAction(Qt::CopyAction); if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
event->accept(); {
event->setDropAction(Qt::CopyAction);
const UBMimeData *mimeData = qobject_cast <const UBMimeData*>(event->mimeData()); event->accept();
if (mimeData && mimeData->items().size() > 0) const UBMimeData *mimeData = qobject_cast <const UBMimeData*>(event->mimeData());
{
int count = 0; if (mimeData && mimeData->items().size() > 0)
int total = mimeData->items().size(); {
int count = 0;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); int total = mimeData->items().size();
foreach (UBMimeDataItem sourceItem, mimeData->items()) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
{
count++; foreach (UBMimeDataItem sourceItem, mimeData->items())
{
UBApplication::applicationController->showMessage(tr("Copying page %1/%2").arg(count).arg(total), true); count++;
// TODO UB 4.x Move following code to some controller class UBApplication::applicationController->showMessage(tr("Copying page %1/%2").arg(count).arg(total), true);
UBGraphicsScene *scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(sourceItem.documentProxy(), sourceItem.sceneIndex());
if (scene) // TODO UB 4.x Move following code to some controller class
{ UBGraphicsScene *scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(sourceItem.documentProxy(), sourceItem.sceneIndex());
UBGraphicsScene* sceneClone = scene->sceneDeepCopy(); if (scene)
{
UBDocumentProxy *targetDocProxy = targetProxyTreeItem->proxy(); UBGraphicsScene* sceneClone = scene->sceneDeepCopy();
foreach (QUrl relativeFile, scene->relativeDependencies()) UBDocumentProxy *targetDocProxy = targetProxyTreeItem->proxy();
{
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString(); foreach (QUrl relativeFile, scene->relativeDependencies())
QString target = targetDocProxy->persistencePath() + "/" + relativeFile.toString(); {
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString();
QFileInfo fi(target); QString target = targetDocProxy->persistencePath() + "/" + relativeFile.toString();
QDir d = fi.dir();
QFileInfo fi(target);
d.mkpath(d.absolutePath()); QDir d = fi.dir();
QFile::copy(source, target);
} d.mkpath(d.absolutePath());
QFile::copy(source, target);
UBPersistenceManager::persistenceManager()->insertDocumentSceneAt(targetDocProxy, sceneClone, targetDocProxy->pageCount()); }
//due to incorrect generation of thumbnails of invisible scene I've used direct copying of thumbnail files UBPersistenceManager::persistenceManager()->insertDocumentSceneAt(targetDocProxy, sceneClone, targetDocProxy->pageCount());
//it's not universal and good way but it's faster
QString from = sourceItem.documentProxy()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceItem.sceneIndex()); //due to incorrect generation of thumbnails of invisible scene I've used direct copying of thumbnail files
QString to = targetDocProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", targetDocProxy->pageCount()); //it's not universal and good way but it's faster
QFile::remove(to); QString from = sourceItem.documentProxy()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceItem.sceneIndex());
QFile::copy(from, to); QString to = targetDocProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", targetDocProxy->pageCount());
} QFile::remove(to);
} QFile::copy(from, to);
}
QApplication::restoreOverrideCursor(); }
UBApplication::applicationController->showMessage(tr("%1 pages copied", "", total).arg(total), false); QApplication::restoreOverrideCursor();
}
} UBApplication::applicationController->showMessage(tr("%1 pages copied", "", total).arg(total), false);
else }
{ }
event->setDropAction(Qt::IgnoreAction); else
event->ignore(); {
} event->setDropAction(Qt::IgnoreAction);
} event->ignore();
} }
} }
}
}
void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument)
{
UBDocumentProxyTreeItem *treeItem = UBApplication::documentController->findDocument(pDocument); void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument)
if (treeItem) {
{ UBDocumentProxyTreeItem *treeItem = UBApplication::documentController->findDocument(pDocument);
QTreeWidgetItem * parent = treeItem->parent(); if (treeItem)
{
if (parent) QTreeWidgetItem * parent = treeItem->parent();
{
for (int i = 0; i < parent->indexOfChild(treeItem); i++) if (parent)
{ {
QTreeWidgetItem *ti = parent->child(i); for (int i = 0; i < parent->indexOfChild(treeItem); i++)
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); {
if (pi) QTreeWidgetItem *ti = parent->child(i);
{ UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) if (pi)
{ {
bool selected = treeItem->isSelected(); if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
parent->removeChild(treeItem); {
parent->insertChild(i, treeItem); bool selected = treeItem->isSelected();
for (int j = 0; j < selectedItems().count(); j++) parent->removeChild(treeItem);
selectedItems().at(j)->setSelected(false); parent->insertChild(i, treeItem);
if (selected) for (int j = 0; j < selectedItems().count(); j++)
treeItem->setSelected(true); selectedItems().at(j)->setSelected(false);
break; if (selected)
} treeItem->setSelected(true);
} break;
} }
} }
} }
} }
}
}
UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDocumentProxy* proxy, bool isEditable)
: QTreeWidgetItem()
, mProxy(proxy) UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDocumentProxy* proxy, bool isEditable)
{ : QTreeWidgetItem()
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled; , mProxy(proxy)
{
if (isEditable) Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
flags |= Qt::ItemIsEditable;
if (isEditable)
setFlags(flags); flags |= Qt::ItemIsEditable;
int i = 0; setFlags(flags);
for (i = 0; i < parent->childCount(); i++)
{ int i = 0;
QTreeWidgetItem *ti = parent->child(i); for (i = 0; i < parent->childCount(); i++)
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); {
if (pi) QTreeWidgetItem *ti = parent->child(i);
{ UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) if (pi)
{ {
break; if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
} {
} break;
} }
parent->insertChild(i, this); }
} }
parent->insertChild(i, this);
}
UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable)
: QTreeWidgetItem(parent)
{ UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable)
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; : QTreeWidgetItem(parent)
if (isEditable) {
flags |= Qt::ItemIsEditable; Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
setFlags(flags); if (isEditable)
} flags |= Qt::ItemIsEditable;
setFlags(flags);
}
UBDocumentGroupTreeItem::~UBDocumentGroupTreeItem()
{
// NOOP UBDocumentGroupTreeItem::~UBDocumentGroupTreeItem()
} {
// NOOP
}
void UBDocumentGroupTreeItem::setGroupName(const QString& groupName)
{
setText(0, groupName); void UBDocumentGroupTreeItem::setGroupName(const QString& groupName)
} {
setText(0, groupName);
}
QString UBDocumentGroupTreeItem::groupName() const
{
return text(0); QString UBDocumentGroupTreeItem::groupName() const
} {
return text(0);
}
bool UBDocumentGroupTreeItem::isTrashFolder() const
{
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::documentTrashGroupName); bool UBDocumentGroupTreeItem::isTrashFolder() const
} {
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::documentTrashGroupName);
bool UBDocumentGroupTreeItem::isDefaultFolder() const }
{
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::defaultDocumentGroupName); bool UBDocumentGroupTreeItem::isDefaultFolder() const
} {
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::defaultDocumentGroupName);
}
void UBDocumentTreeWidget::autoScroll()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); void UBDocumentTreeWidget::autoScroll()
} {
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
}

@ -1,167 +1,144 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBNavigatorPalette.h" #include "UBNavigatorPalette.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
/** /**
* \brief Constructor * \brief Constructor
* @param parent as the parent widget * @param parent as the parent widget
* @param name as the object name * @param name as the object name
*/ */
UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name): UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name):
UBDockPalette(eUBDockPaletteType_LEFT, parent, name) UBDockPalette(eUBDockPaletteType_LEFT, parent, name)
, mNavigator(NULL) , mNavigator(NULL)
, mLayout(NULL) , mLayout(NULL)
, mHLayout(NULL) , mHLayout(NULL)
, mPageNbr(NULL) , mPageNbr(NULL)
, mClock(NULL) , mClock(NULL)
{ {
// Build the gui // Build the gui
mLayout = new QVBoxLayout(this); mLayout = new QVBoxLayout(this);
mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin()); mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin());
setLayout(mLayout); setLayout(mLayout);
mNavigator = new UBDocumentNavigator(this); mNavigator = new UBDocumentNavigator(this);
mNavigator->setStyleSheet(QString("background-color : transparent;")); mNavigator->setStyleSheet(QString("background-color : transparent;"));
mLayout->addWidget(mNavigator, 1); mLayout->addWidget(mNavigator, 1);
mHLayout = new QHBoxLayout(); mHLayout = new QHBoxLayout();
mLayout->addLayout(mHLayout, 0); mLayout->addLayout(mHLayout, 0);
mPageNbr = new QLabel(this); mPageNbr = new QLabel(this);
mClock = new QLabel(this); mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr); mHLayout->addWidget(mPageNbr);
mHLayout->addWidget(mClock); mHLayout->addWidget(mClock);
// Configure the page number indicator // Configure the page number indicator
mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }")); mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0); setPageNumber(0, 0);
mPageNbr->setAlignment(Qt::AlignHCenter); mPageNbr->setAlignment(Qt::AlignHCenter);
// Configure the clock // Configure the clock
mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}")); mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat); mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
mClock->setAlignment(Qt::AlignHCenter); mClock->setAlignment(Qt::AlignHCenter);
//strip seconds //strip seconds
mTimeFormat = mTimeFormat.remove(":ss"); mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s"); mTimeFormat = mTimeFormat.remove(":s");
mTimerID = startTimer(1000); mTimerID = startTimer(1000);
connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage())); }
}
/**
/** * \brief Destructor
* \brief Destructor */
*/ UBNavigatorPalette::~UBNavigatorPalette()
UBNavigatorPalette::~UBNavigatorPalette() {
{ killTimer(mTimerID);
killTimer(mTimerID);
if(NULL != mClock)
if(NULL != mClock) {
{ delete mClock;
delete mClock; mClock = NULL;
mClock = NULL; }
} if(NULL != mPageNbr)
if(NULL != mPageNbr) {
{ delete mPageNbr;
delete mPageNbr; mPageNbr = NULL;
mPageNbr = NULL; }
} if(NULL != mHLayout)
if(NULL != mHLayout) {
{ delete mHLayout;
delete mHLayout; mHLayout = NULL;
mHLayout = NULL; }
} if(NULL != mLayout)
if(NULL != mLayout) {
{ delete mLayout;
delete mLayout; mLayout = NULL;
mLayout = NULL; }
} if(NULL != mNavigator)
if(NULL != mNavigator) {
{ delete mNavigator;
delete mNavigator; mNavigator = NULL;
mNavigator = NULL; }
} }
}
/**
/** * \brief Set the current document in the navigator
* \brief Set the current document in the navigator * @param document as the given document
* @param document as the given document */
*/
void UBNavigatorPalette::setDocument(UBDocumentProxy *document) /**
{ * \brief Refresh the thumbnails widget
if(mNavigator->currentDoc() != document) */
{ void UBNavigatorPalette::refresh()
mNavigator->setDocument(document); {
} }
}
/**
/** * \brief Handle the resize event
* \brief Change the current page * @param event as the resize event
*/ */
void UBNavigatorPalette::changeCurrentPage() void UBNavigatorPalette::resizeEvent(QResizeEvent *event)
{ {
// Get the index of the page to display UBDockPalette::resizeEvent(event);
int iPage = mNavigator->selectedPageNumber(); if(NULL != mNavigator)
if(NO_PAGESELECTED != iPage) {
{ mNavigator->setMinimumHeight(height() - 2*border());
// Display the selected page }
UBApplication::boardController->setActiveDocumentScene(mNavigator->currentDoc(), iPage); }
}
} void UBNavigatorPalette::timerEvent(QTimerEvent *event)
{
/** Q_UNUSED(event);
* \brief Refresh the thumbnails widget updateTime();
*/ }
void UBNavigatorPalette::refresh()
{ void UBNavigatorPalette::updateTime()
mNavigator->setDocument(UBApplication::boardController->activeDocument()); {
} if (mClock)
{
/** mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
* \brief Handle the resize event }
* @param event as the resize event }
*/
void UBNavigatorPalette::resizeEvent(QResizeEvent *event) void UBNavigatorPalette::setPageNumber(int current, int total)
{ {
UBDockPalette::resizeEvent(event); mPageNbr->setText(QString("%1 / %2").arg(current).arg(total));
if(NULL != mNavigator) }
{
mNavigator->setMinimumHeight(height() - 2*border());
}
}
void UBNavigatorPalette::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
updateTime();
}
void UBNavigatorPalette::updateTime()
{
if (mClock)
{
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
}
}
void UBNavigatorPalette::setPageNumber(int current, int total)
{
mPageNbr->setText(QString("%1 / %2").arg(current).arg(total));
}

@ -1,66 +1,64 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBNAVIGATORPALETTE_H #ifndef UBNAVIGATORPALETTE_H
#define UBNAVIGATORPALETTE_H #define UBNAVIGATORPALETTE_H
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QMouseEvent> #include <QMouseEvent>
#include <QResizeEvent> #include <QResizeEvent>
#include <QTimerEvent> #include <QTimerEvent>
#include <QLabel> #include <QLabel>
#include <QString> #include <QString>
#include "UBDockPalette.h" #include "UBDockPalette.h"
#include "UBDocumentNavigator.h" #include "UBDocumentNavigator.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
class UBNavigatorPalette : public UBDockPalette class UBNavigatorPalette : public UBDockPalette
{ {
Q_OBJECT Q_OBJECT
public: public:
UBNavigatorPalette(QWidget* parent=0, const char* name="navigatorPalette"); UBNavigatorPalette(QWidget* parent=0, const char* name="navigatorPalette");
~UBNavigatorPalette(); ~UBNavigatorPalette();
void setDocument(UBDocumentProxy* document); void setDocument(UBDocumentProxy* document);
void refresh(); void refresh();
public slots: public slots:
void setPageNumber(int current, int total); void setPageNumber(int current, int total);
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
virtual void timerEvent(QTimerEvent *event); virtual void timerEvent(QTimerEvent *event);
private: private:
void updateTime(); void updateTime();
/** The thumbnails navigator widget */ /** The thumbnails navigator widget */
UBDocumentNavigator* mNavigator; UBDocumentNavigator* mNavigator;
/** The layout */ /** The layout */
QVBoxLayout* mLayout; QVBoxLayout* mLayout;
QHBoxLayout* mHLayout; QHBoxLayout* mHLayout;
QLabel* mPageNbr; QLabel* mPageNbr;
QLabel* mClock; QLabel* mClock;
QString mTimeFormat; QString mTimeFormat;
int mTimerID; int mTimerID;
private slots: };
void changeCurrentPage();
};
#endif // UBNAVIGATORPALETTE_H
#endif // UBNAVIGATORPALETTE_H

@ -1,206 +1,173 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBPageNavigationWidget.h" #include "UBPageNavigationWidget.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "globals/UBGlobals.h" #include "document/UBDocumentContainer.h"
#include "core/memcheck.h" #include "globals/UBGlobals.h"
/** #include "core/memcheck.h"
* \brief Constructor
* @param parent as the parent widget /**
* @param name as the object name * \brief Constructor
*/ * @param parent as the parent widget
UBPageNavigationWidget::UBPageNavigationWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) * @param name as the object name
, mNavigator(NULL) */
, mLayout(NULL) UBPageNavigationWidget::UBPageNavigationWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent)
, mHLayout(NULL) , mNavigator(NULL)
, mPageNbr(NULL) , mLayout(NULL)
, mClock(NULL) , mHLayout(NULL)
{ , mPageNbr(NULL)
setObjectName(name); , mClock(NULL)
mName = "PageNavigator"; {
mVisibleState = true; setObjectName(name);
mName = "PageNavigator";
SET_STYLE_SHEET(); mVisibleState = true;
mIconToRight = QPixmap(":images/pages_open.png"); SET_STYLE_SHEET();
mIconToLeft = QPixmap(":images/pages_close.png");
mIconToRight = QPixmap(":images/pages_open.png");
// Build the gui mIconToLeft = QPixmap(":images/pages_close.png");
mLayout = new QVBoxLayout(this);
setLayout(mLayout); // Build the gui
mLayout = new QVBoxLayout(this);
mNavigator = new UBDocumentNavigator(this); setLayout(mLayout);
mLayout->addWidget(mNavigator, 1);
mNavigator = new UBDocumentNavigator(this);
mHLayout = new QHBoxLayout(); mLayout->addWidget(mNavigator, 1);
mLayout->addLayout(mHLayout, 0);
mHLayout = new QHBoxLayout();
mPageNbr = new QLabel(this); mLayout->addLayout(mHLayout, 0);
mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr); mPageNbr = new QLabel(this);
mHLayout->addWidget(mClock); mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr);
// Configure the page number indicator mHLayout->addWidget(mClock);
mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0); // Configure the page number indicator
mPageNbr->setAlignment(Qt::AlignHCenter); mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0);
// Configure the clock mPageNbr->setAlignment(Qt::AlignHCenter);
mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat); // Configure the clock
mClock->setAlignment(Qt::AlignHCenter); mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
//strip seconds mClock->setAlignment(Qt::AlignHCenter);
mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s"); //strip seconds
mTimerID = startTimer(1000); mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s");
connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage())); mTimerID = startTimer(1000);
connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(onSetDocOnPageNavigator(UBDocumentProxy*)));
} //connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage()));
//connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(onSetDocOnPageNavigator(UBDocumentProxy*)));
/** }
* \brief Destructor
*/ /**
UBPageNavigationWidget::~UBPageNavigationWidget() * \brief Destructor
{ */
killTimer(mTimerID); UBPageNavigationWidget::~UBPageNavigationWidget()
{
if(NULL != mClock) killTimer(mTimerID);
{
delete mClock; if(NULL != mClock)
mClock = NULL; {
} delete mClock;
if(NULL != mPageNbr) mClock = NULL;
{ }
delete mPageNbr; if(NULL != mPageNbr)
mPageNbr = NULL; {
} delete mPageNbr;
if(NULL != mHLayout) mPageNbr = NULL;
{ }
delete mHLayout; if(NULL != mHLayout)
mHLayout = NULL; {
} delete mHLayout;
if(NULL != mLayout) mHLayout = NULL;
{ }
delete mLayout; if(NULL != mLayout)
mLayout = NULL; {
} delete mLayout;
if(NULL != mNavigator) mLayout = NULL;
{ }
delete mNavigator; if(NULL != mNavigator)
mNavigator = NULL; {
} delete mNavigator;
} mNavigator = NULL;
}
/** }
* \brief Set the current document in the navigator
* @param document as the given document
*/ /**
void UBPageNavigationWidget::setDocument(UBDocumentProxy *document) * \brief Refresh the thumbnails widget
{ */
if(mNavigator->currentDoc() != document) void UBPageNavigationWidget::refresh()
{ {
mNavigator->setDocument(document); // TOLIK!!!
} // mNavigator->setDocument(UBApplication::boardController->activeDocument());
} }
/** /**
* \brief Change the current page * \brief Notify a timer event
*/ * @param event as the timer event
void UBPageNavigationWidget::changeCurrentPage() */
{ void UBPageNavigationWidget::timerEvent(QTimerEvent *event)
// Get the index of the page to display {
int iPage = mNavigator->selectedPageNumber(); Q_UNUSED(event);
if(NO_PAGESELECTED != iPage) updateTime();
{ }
// Display the selected page
UBApplication::boardController->setActiveDocumentScene(mNavigator->currentDoc(), iPage); /**
* \brief Update the current time
// emit here the signal to indicate that page change */
UBApplication::boardController->notifyPageChanged(); void UBPageNavigationWidget::updateTime()
} {
} if (mClock)
{
/** mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
* \brief Refresh the thumbnails widget }
*/ }
void UBPageNavigationWidget::refresh()
{ /**
mNavigator->setDocument(UBApplication::boardController->activeDocument()); * \brief Set the page number
} * @param current as the current page
* @param total as the total number of pages
/** */
* \brief Notify a timer event void UBPageNavigationWidget::setPageNumber(int current, int total)
* @param event as the timer event {
*/ mPageNbr->setText(QString("%1 / %2").arg(current).arg(UBDocumentContainer::sceneIndexFromPage(total)));
void UBPageNavigationWidget::timerEvent(QTimerEvent *event) }
{
Q_UNUSED(event); /**
updateTime(); * \brief Get the custom margin value
} * @return the custom margin value
*/
/** int UBPageNavigationWidget::customMargin()
* \brief Update the current time {
*/ return 5;
void UBPageNavigationWidget::updateTime() }
{
if (mClock) /**
{ * \brief Get the border value
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat)); * @return the border value
} */
} int UBPageNavigationWidget::border()
{
/** return 15;
* \brief Set the page number }
* @param current as the current page
* @param total as the total number of pages
*/
void UBPageNavigationWidget::setPageNumber(int current, int total)
{
mPageNbr->setText(QString("%1 / %2").arg(current).arg(UBApplication::boardController->sceneIndexFromPage(total)));
}
/**
* \brief Get the custom margin value
* @return the custom margin value
*/
int UBPageNavigationWidget::customMargin()
{
return 5;
}
/**
* \brief Get the border value
* @return the border value
*/
int UBPageNavigationWidget::border()
{
return 15;
}
/**
* \brief Set the current document
* @param doc as the current document
*/
void UBPageNavigationWidget::onSetDocOnPageNavigator(UBDocumentProxy *doc)
{
setDocument(doc);
}

@ -1,75 +1,71 @@
/* /*
* 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 2 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,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBPAGENAVIGATIONWIDGET_H #ifndef UBPAGENAVIGATIONWIDGET_H
#define UBPAGENAVIGATIONWIDGET_H #define UBPAGENAVIGATIONWIDGET_H
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QMouseEvent> #include <QMouseEvent>
#include <QResizeEvent> #include <QResizeEvent>
#include <QTimerEvent> #include <QTimerEvent>
#include <QLabel> #include <QLabel>
#include <QString> #include <QString>
#include "UBDocumentNavigator.h" #include "UBDocumentNavigator.h"
#include "UBDockPaletteWidget.h" #include "UBDockPaletteWidget.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
class UBPageNavigationWidget : public UBDockPaletteWidget class UBPageNavigationWidget : public UBDockPaletteWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
UBPageNavigationWidget(QWidget* parent=0, const char* name="UBPageNavigationWidget"); UBPageNavigationWidget(QWidget* parent=0, const char* name="UBPageNavigationWidget");
~UBPageNavigationWidget(); ~UBPageNavigationWidget();
void setDocument(UBDocumentProxy* document); //void setDocument(UBDocumentProxy* document);
void refresh(); void refresh();
bool visibleInMode(eUBDockPaletteWidgetMode mode) bool visibleInMode(eUBDockPaletteWidgetMode mode)
{ {
return mode == eUBDockPaletteWidget_BOARD; return mode == eUBDockPaletteWidget_BOARD;
} }
signals: signals:
void resizeRequest(QResizeEvent* event); void resizeRequest(QResizeEvent* event);
public slots: public slots:
void setPageNumber(int current, int total); void setPageNumber(int current, int total);
protected: protected:
virtual void timerEvent(QTimerEvent *event); virtual void timerEvent(QTimerEvent *event);
private slots:
void onSetDocOnPageNavigator(UBDocumentProxy* doc); private:
void updateTime();
private: int customMargin();
void updateTime(); int border();
int customMargin();
int border(); /** The thumbnails navigator widget */
UBDocumentNavigator* mNavigator;
/** The thumbnails navigator widget */ /** The layout */
UBDocumentNavigator* mNavigator; QVBoxLayout* mLayout;
/** The layout */ QHBoxLayout* mHLayout;
QVBoxLayout* mLayout; QLabel* mPageNbr;
QHBoxLayout* mHLayout; QLabel* mClock;
QLabel* mPageNbr; QString mTimeFormat;
QLabel* mClock; int mTimerID;
QString mTimeFormat;
int mTimerID; };
private slots: #endif // UBPAGENAVIGATIONWIDGET_H
void changeCurrentPage();
};
#endif // UBPAGENAVIGATIONWIDGET_H

@ -245,7 +245,7 @@ void UBTeacherGuideEditionWidget::onActiveSceneChanged()
cleanData(); cleanData();
load(UBSvgSubsetAdaptor::readTeacherGuideNode(UBApplication::boardController->activeSceneIndex())); load(UBSvgSubsetAdaptor::readTeacherGuideNode(UBApplication::boardController->activeSceneIndex()));
mpPageNumberLabel->setText(tr("Page: %0").arg(currentPage)); mpPageNumberLabel->setText(tr("Page: %0").arg(currentPage));
UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument();
if(mpDocumentTitle) if(mpDocumentTitle)
mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString());
} }
@ -483,7 +483,7 @@ void UBTeacherGuidePresentationWidget::onActiveSceneChanged()
{ {
cleanData(); cleanData();
mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage())); mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage()));
UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument();
if(mpDocumentTitle) if(mpDocumentTitle)
mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); mpDocumentTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString());
} }
@ -535,9 +535,9 @@ void UBTeacherGuidePresentationWidget::showData(QVector<tUBGEElementNode*> data)
newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11))); newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11)));
QString mimeTypeString; QString mimeTypeString;
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
mimeTypeString = QUrl::fromLocalFile(UBApplication::boardController->activeDocument()->persistencePath()+ "/" + element->attributes.value("relativePath")).toString(); mimeTypeString = QUrl::fromLocalFile(UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + element->attributes.value("relativePath")).toString();
#else #else
mimeTypeString = UBApplication::boardController->activeDocument()->persistencePath()+ "/" + element->attributes.value("relativePath"); mimeTypeString = UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + element->attributes.value("relativePath");
#endif #endif
newWidgetItem->setData(0, TG_USER_ROLE_MIME_TYPE, mimeTypeString); newWidgetItem->setData(0, TG_USER_ROLE_MIME_TYPE, mimeTypeString);
newWidgetItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable); newWidgetItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
@ -882,7 +882,7 @@ void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel)
void UBTeacherGuidePageZeroWidget::onActiveSceneChanged() void UBTeacherGuidePageZeroWidget::onActiveSceneChanged()
{ {
UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument();
if(documentProxy && UBApplication::boardController->currentPage() == 0){ if(documentProxy && UBApplication::boardController->currentPage() == 0){
QDateTime creationDate = documentProxy->documentDate(); QDateTime creationDate = documentProxy->documentDate();
mpCreationLabel->setText(tr("Created the:\n") + creationDate.toString(Qt::DefaultLocaleShortDate)); mpCreationLabel->setText(tr("Created the:\n") + creationDate.toString(Qt::DefaultLocaleShortDate));
@ -901,7 +901,7 @@ void UBTeacherGuidePageZeroWidget::hideEvent ( QHideEvent * event )
void UBTeacherGuidePageZeroWidget::loadData() void UBTeacherGuidePageZeroWidget::loadData()
{ {
UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument();
mpSessionTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString()); mpSessionTitle->setText(documentProxy->metaData(UBSettings::sessionTitle).toString());
mpAuthors->setText(documentProxy->metaData(UBSettings::sessionAuthors).toString()); mpAuthors->setText(documentProxy->metaData(UBSettings::sessionAuthors).toString());
mpObjectives->setText(documentProxy->metaData(UBSettings::sessionObjectives).toString()); mpObjectives->setText(documentProxy->metaData(UBSettings::sessionObjectives).toString());
@ -925,7 +925,7 @@ void UBTeacherGuidePageZeroWidget::persistData()
// check necessary because at document closing hide event is send after boardcontroller set // check necessary because at document closing hide event is send after boardcontroller set
// to NULL // to NULL
if(UBApplication::boardController){ if(UBApplication::boardController){
UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); UBDocumentProxy* documentProxy = UBApplication::boardController->selectedDocument();
documentProxy->setMetaData(UBSettings::sessionTitle,mpSessionTitle->text()); documentProxy->setMetaData(UBSettings::sessionTitle,mpSessionTitle->text());
documentProxy->setMetaData(UBSettings::sessionAuthors, mpAuthors->text()); documentProxy->setMetaData(UBSettings::sessionAuthors, mpAuthors->text());
documentProxy->setMetaData(UBSettings::sessionObjectives,mpObjectives->text()); documentProxy->setMetaData(UBSettings::sessionObjectives,mpObjectives->text());

@ -316,7 +316,7 @@ UBTGMediaWidget::UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget, QWi
, mIsInitializationMode(false) , mIsInitializationMode(false)
{ {
setObjectName(name); setObjectName(name);
mMediaPath = UBApplication::boardController->activeDocument()->persistencePath()+ "/" + mediaPath; mMediaPath = UBApplication::boardController->selectedDocument()->persistencePath()+ "/" + mediaPath;
setAcceptDrops(false); setAcceptDrops(false);
createWorkWidget(); createWorkWidget();
setFixedHeight(200); setFixedHeight(200);
@ -340,7 +340,7 @@ void UBTGMediaWidget::initializeWithDom(QDomElement element)
{ {
mIsInitializationMode = true; mIsInitializationMode = true;
setAcceptDrops(false); setAcceptDrops(false);
mMediaPath = UBApplication::boardController->activeDocument()->persistencePath() + "/" + element.attribute("relativePath"); mMediaPath = UBApplication::boardController->selectedDocument()->persistencePath() + "/" + element.attribute("relativePath");
qDebug() << mMediaPath; qDebug() << mMediaPath;
createWorkWidget(); createWorkWidget();
setFixedHeight(200); setFixedHeight(200);
@ -377,7 +377,7 @@ tUBGEElementNode* UBTGMediaWidget::saveData()
return 0; return 0;
tUBGEElementNode* result = new tUBGEElementNode(); tUBGEElementNode* result = new tUBGEElementNode();
QString relativePath = mMediaPath; QString relativePath = mMediaPath;
relativePath = relativePath.replace(UBApplication::boardController->activeDocument()->persistencePath()+"/",""); relativePath = relativePath.replace(UBApplication::boardController->selectedDocument()->persistencePath()+"/","");
result->name = "media"; result->name = "media";
result->attributes.insert("title",mpTitle->text()); result->attributes.insert("title",mpTitle->text());
result->attributes.insert("relativePath",relativePath); result->attributes.insert("relativePath",relativePath);
@ -394,7 +394,7 @@ void UBTGMediaWidget::createWorkWidget()
{ {
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mMediaPath); QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mMediaPath);
bool setMedia = true; bool setMedia = true;
UBDocumentProxy* proxyDocument = UBApplication::boardController->activeDocument(); UBDocumentProxy* proxyDocument = UBApplication::boardController->selectedDocument();
if(mimeType.contains("audio") || mimeType.contains("video")){ if(mimeType.contains("audio") || mimeType.contains("video")){
mMediaType = mimeType.contains("audio")? "audio":"movie"; mMediaType = mimeType.contains("audio")? "audio":"movie";
mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); mpMediaWidget = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video);

@ -211,7 +211,7 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event)
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(itemAt(mMousePressPos)); UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(itemAt(mMousePressPos));
if(sceneItem){ if(sceneItem){
int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneItem->sceneIndex()); int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex());
if(pageIndex == 0){ if(pageIndex == 0){
event->ignore(); event->ignore();
return; return;
@ -761,7 +761,7 @@ UBSceneThumbnailNavigPixmap::UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBD
, bCanMoveDown(false) , bCanMoveDown(false)
, bCanDuplicate(false) , bCanDuplicate(false)
{ {
if(0 <= UBApplication::boardController->pageFromSceneIndex(pSceneIndex)){ if(0 <= UBDocumentContainer::pageFromSceneIndex(pSceneIndex)){
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
} }
@ -839,7 +839,7 @@ void UBSceneThumbnailNavigPixmap::updateButtonsState()
bCanDuplicate = false; bCanDuplicate = false;
if(proxy()){ if(proxy()){
int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneIndex()); int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneIndex());
UBDocumentController* documentController = UBApplication::documentController; UBDocumentController* documentController = UBApplication::documentController;
bCanDelete = documentController->pageCanBeDeleted(pageIndex); bCanDelete = documentController->pageCanBeDeleted(pageIndex);
bCanMoveUp = documentController->pageCanBeMovedUp(pageIndex); bCanMoveUp = documentController->pageCanBeMovedUp(pageIndex);
@ -853,25 +853,24 @@ void UBSceneThumbnailNavigPixmap::updateButtonsState()
void UBSceneThumbnailNavigPixmap::deletePage() void UBSceneThumbnailNavigPixmap::deletePage()
{ {
QList<QGraphicsItem*> itemsToDelete; UBApplication::boardController->deleteScene(sceneIndex());
itemsToDelete << this;
UBApplication::documentController->deletePages(itemsToDelete);
} }
void UBSceneThumbnailNavigPixmap::duplicatePage() void UBSceneThumbnailNavigPixmap::duplicatePage()
{ {
UBApplication::boardController->duplicateScene(); UBApplication::boardController->duplicateScene(sceneIndex());
} }
void UBSceneThumbnailNavigPixmap::moveUpPage() void UBSceneThumbnailNavigPixmap::moveUpPage()
{ {
UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() - 1); if (sceneIndex()!=0)
UBApplication::boardController->moveSceneToIndex(sceneIndex(), sceneIndex() - 1);
} }
void UBSceneThumbnailNavigPixmap::moveDownPage() void UBSceneThumbnailNavigPixmap::moveDownPage()
{ {
UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() + 1); if (sceneIndex() < UBApplication::boardController->selectedDocument()->pageCount()-1)
UBApplication::boardController->moveSceneToIndex(sceneIndex(), sceneIndex() + 1);
} }
void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal height) void UBImgTextThumbnailElement::Place(int row, int col, qreal width, qreal height)

@ -400,19 +400,19 @@ class UBThumbnailTextItem : public QGraphicsTextItem
class UBImgTextThumbnailElement class UBImgTextThumbnailElement
{ {
private: private:
QGraphicsItem* thumbnail; UBSceneThumbnailNavigPixmap* thumbnail;
UBThumbnailTextItem* caption; UBThumbnailTextItem* caption;
int border; int border;
public: public:
UBImgTextThumbnailElement(QGraphicsItem* thumb, UBThumbnailTextItem* text): border(0) UBImgTextThumbnailElement(UBSceneThumbnailNavigPixmap* thumb, UBThumbnailTextItem* text): border(0)
{ {
this->thumbnail = thumb; this->thumbnail = thumb;
this->caption = text; this->caption = text;
} }
QGraphicsItem* getThumbnail() const { return this->thumbnail; } UBSceneThumbnailNavigPixmap* getThumbnail() const { return this->thumbnail; }
void setThumbnail(QGraphicsItem* newGItem) { this->thumbnail = newGItem; } void setThumbnail(UBSceneThumbnailNavigPixmap* newGItem) { this->thumbnail = newGItem; }
UBThumbnailTextItem* getCaption() const { return this->caption; } UBThumbnailTextItem* getCaption() const { return this->caption; }
void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; } void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }

Loading…
Cancel
Save