commit
4e884672fe
@ -1,186 +1,230 @@ |
||||
/*
|
||||
* 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 2 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 "UBThumbnailAdaptor.h" |
||||
|
||||
#include <QtCore> |
||||
|
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBApplication.h" |
||||
#include "core/UBSettings.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "domain/UBGraphicsScene.h" |
||||
|
||||
#include "UBSvgSubsetAdaptor.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy) |
||||
{ |
||||
int existingPageCount = proxy->pageCount(); |
||||
|
||||
for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo) |
||||
{ |
||||
QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo); |
||||
|
||||
QFile thumbFile(thumbFileName); |
||||
|
||||
if (!thumbFile.exists()) |
||||
{ |
||||
bool displayMessage = (existingPageCount > 5); |
||||
|
||||
int thumbCount = 0; |
||||
|
||||
UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo); |
||||
|
||||
if (scene) |
||||
{ |
||||
thumbCount++; |
||||
|
||||
if (displayMessage && thumbCount == 1) |
||||
UBApplication::showMessage(tr("Generating preview thumbnails ...")); |
||||
|
||||
persistScene(proxy->persistencePath(), scene, iPageNo); |
||||
} |
||||
|
||||
if (displayMessage && thumbCount > 0) |
||||
UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount)); |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy) |
||||
{ |
||||
QList<QPixmap> thumbnails; |
||||
|
||||
if (!proxy || proxy->persistencePath().isEmpty()) |
||||
return thumbnails; |
||||
|
||||
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails
|
||||
generateMissingThumbnails(proxy); |
||||
|
||||
//end compatibility with older format
|
||||
|
||||
bool moreToProcess = true; |
||||
int pageCount = UBApplication::boardController->sceneIndexFromPage(0); |
||||
|
||||
while (moreToProcess) { |
||||
pageCount++; |
||||
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageCount); |
||||
|
||||
QFile file(fileName); |
||||
if (file.exists()) { |
||||
QPixmap pix; |
||||
//Warning. Works only with modified Qt
|
||||
#ifdef Q_WS_X11 |
||||
//pix.load(fileName, 0, Qt::AutoColor);
|
||||
pix.load(fileName, 0); |
||||
#else |
||||
pix.load(fileName, 0, Qt::AutoColor, false); |
||||
#endif |
||||
thumbnails.append(pix); |
||||
} else { |
||||
moreToProcess = false; |
||||
} |
||||
} |
||||
return thumbnails; |
||||
} |
||||
|
||||
QPixmap UBThumbnailAdaptor::load(UBDocumentProxy* proxy, int index) |
||||
{ |
||||
int existingPageCount = proxy->pageCount(); |
||||
|
||||
if (!proxy || proxy->persistencePath().size() == 0 || index < 0 || index > existingPageCount) |
||||
return QPixmap(); |
||||
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails
|
||||
generateMissingThumbnails(proxy); |
||||
|
||||
//end compatibility with older format
|
||||
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index); |
||||
|
||||
QFile file(fileName); |
||||
if (file.exists()) |
||||
{ |
||||
QPixmap pix; |
||||
//Warning. Works only with modified Qt
|
||||
#ifdef Q_WS_X11 |
||||
pix.load(fileName, 0, Qt::AutoColor); |
||||
#else |
||||
pix.load(fileName, 0, Qt::AutoColor, false); |
||||
#endif |
||||
return pix; |
||||
} |
||||
return QPixmap(); |
||||
} |
||||
|
||||
void UBThumbnailAdaptor::persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified) |
||||
{ |
||||
QString fileName = pDocPath + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); |
||||
|
||||
QFile thumbFile(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); |
||||
} |
||||
/*
|
||||
* 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 2 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 "UBThumbnailAdaptor.h" |
||||
|
||||
#include <QtCore> |
||||
|
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBApplication.h" |
||||
#include "core/UBSettings.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "domain/UBGraphicsScene.h" |
||||
|
||||
#include "UBSvgSubsetAdaptor.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy) |
||||
{ |
||||
int existingPageCount = proxy->pageCount(); |
||||
|
||||
for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo) |
||||
{ |
||||
QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo); |
||||
|
||||
QFile thumbFile(thumbFileName); |
||||
|
||||
if (!thumbFile.exists()) |
||||
{ |
||||
bool displayMessage = (existingPageCount > 5); |
||||
|
||||
int thumbCount = 0; |
||||
|
||||
UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo); |
||||
|
||||
if (scene) |
||||
{ |
||||
thumbCount++; |
||||
|
||||
if (displayMessage && thumbCount == 1) |
||||
UBApplication::showMessage(tr("Generating preview thumbnails ...")); |
||||
|
||||
persistScene(proxy, scene, iPageNo); |
||||
} |
||||
|
||||
if (displayMessage && thumbCount > 0) |
||||
UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount)); |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex) |
||||
{ |
||||
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); |
||||
|
||||
QFile file(fileName); |
||||
if (!file.exists()) |
||||
{ |
||||
generateMissingThumbnails(proxy); |
||||
} |
||||
|
||||
QPixmap* pix = new QPixmap(); |
||||
if (file.exists()) |
||||
{ |
||||
//Warning. Works only with modified Qt
|
||||
#ifdef Q_WS_X11 |
||||
pix->load(fileName, 0, Qt::AutoColor); |
||||
#else |
||||
pix->load(fileName, 0, Qt::AutoColor, false); |
||||
#endif |
||||
} |
||||
return pix; |
||||
} |
||||
|
||||
void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList<const QPixmap*>& list) |
||||
{ |
||||
generateMissingThumbnails(proxy); |
||||
|
||||
foreach(const QPixmap* pm, list) |
||||
delete pm; |
||||
list.clear(); |
||||
for(int i=0; i<proxy->pageCount(); i++) |
||||
list.append(get(proxy, i)); |
||||
} |
||||
|
||||
|
||||
/*
|
||||
QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy) |
||||
{ |
||||
QList<QPixmap> thumbnails; |
||||
|
||||
qDebug() << "Loadinf thumbnails for " << proxy->name(); |
||||
|
||||
if (!proxy || proxy->persistencePath().isEmpty()) |
||||
return thumbnails; |
||||
|
||||
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails
|
||||
generateMissingThumbnails(proxy); |
||||
|
||||
//end compatibility with older format
|
||||
|
||||
bool moreToProcess = true; |
||||
int pageCount = UBApplication::boardController->sceneIndexFromPage(0); |
||||
|
||||
while (moreToProcess) { |
||||
pageCount++; |
||||
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageCount); |
||||
|
||||
QFile file(fileName); |
||||
if (file.exists()) { |
||||
QPixmap pix; |
||||
//Warning. Works only with modified Qt
|
||||
#ifdef Q_WS_X11 |
||||
//pix.load(fileName, 0, Qt::AutoColor);
|
||||
pix.load(fileName, 0); |
||||
#else |
||||
pix.load(fileName, 0, Qt::AutoColor, false); |
||||
#endif |
||||
thumbnails.append(pix); |
||||
} else { |
||||
moreToProcess = false; |
||||
} |
||||
} |
||||
return thumbnails; |
||||
} |
||||
|
||||
QPixmap UBThumbnailAdaptor::load(UBDocumentProxy* proxy, int index) |
||||
{ |
||||
qDebug() << "Loadinf thumbnails for " << proxy->name(); |
||||
|
||||
int existingPageCount = proxy->pageCount(); |
||||
|
||||
if (!proxy || proxy->persistencePath().size() == 0 || index < 0 || index > existingPageCount) |
||||
return QPixmap(); |
||||
//compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails
|
||||
generateMissingThumbnails(proxy); |
||||
|
||||
//end compatibility with older format
|
||||
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index); |
||||
|
||||
QFile file(fileName); |
||||
if (file.exists()) |
||||
{ |
||||
QPixmap pix; |
||||
//Warning. Works only with modified Qt
|
||||
#ifdef Q_WS_X11 |
||||
pix.load(fileName, 0, Qt::AutoColor); |
||||
#else |
||||
pix.load(fileName, 0, Qt::AutoColor, false); |
||||
#endif |
||||
return pix; |
||||
} |
||||
return QPixmap(); |
||||
} |
||||
*/ |
||||
|
||||
void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified) |
||||
{ |
||||
|
||||
qDebug() << "Persiste scene on path " << proxy->persistencePath() << ", index " << pageIndex; |
||||
|
||||
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex); |
||||
|
||||
QFile thumbFile(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 |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 2 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 UBTHUMBNAILADAPTOR_H |
||||
#define UBTHUMBNAILADAPTOR_H |
||||
|
||||
#include <QtCore> |
||||
|
||||
class UBDocument; |
||||
class UBDocumentProxy; |
||||
class UBGraphicsScene; |
||||
|
||||
class UBThumbnailAdaptor //static class
|
||||
{ |
||||
Q_DECLARE_TR_FUNCTIONS(UBThumbnailAdaptor) |
||||
|
||||
private: UBThumbnailAdaptor() {} |
||||
public: |
||||
static void persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false); |
||||
|
||||
static void generateMissingThumbnails(UBDocumentProxy* proxy); |
||||
static QList<QPixmap> load(UBDocumentProxy* proxy); |
||||
static QPixmap load(UBDocumentProxy* proxy, int index); |
||||
|
||||
static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex); |
||||
}; |
||||
|
||||
#endif // UBTHUMBNAILADAPTOR_H
|
||||
/*
|
||||
* 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 2 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 UBTHUMBNAILADAPTOR_H |
||||
#define UBTHUMBNAILADAPTOR_H |
||||
|
||||
#include <QtCore> |
||||
|
||||
class UBDocument; |
||||
class UBDocumentProxy; |
||||
class UBGraphicsScene; |
||||
|
||||
class UBThumbnailAdaptor //static class
|
||||
{ |
||||
Q_DECLARE_TR_FUNCTIONS(UBThumbnailAdaptor) |
||||
|
||||
public: |
||||
static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex); |
||||
|
||||
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false); |
||||
|
||||
static const QPixmap* get(UBDocumentProxy* proxy, int index); |
||||
static void load(UBDocumentProxy* proxy, QList<const QPixmap*>& list); |
||||
|
||||
private: |
||||
static void generateMissingThumbnails(UBDocumentProxy* proxy); |
||||
|
||||
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 |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 2 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 UBDOCUMENTPUBLISHER_H |
||||
#define UBDOCUMENTPUBLISHER_H |
||||
|
||||
#include <QtGui> |
||||
#include <QtNetwork> |
||||
|
||||
#include "ui_webPublishing.h" |
||||
|
||||
#define DOCPUBLICATION_URL "http://planete.sankore.org/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain"
|
||||
|
||||
typedef struct |
||||
{ |
||||
QString title; |
||||
QString description; |
||||
} sDocumentInfos; |
||||
|
||||
class UBDocumentProxy; |
||||
class UBServerXMLHttpRequest; |
||||
class UBGraphicsW3CWidgetItem; |
||||
class QWebView; |
||||
|
||||
class UBProxyLoginDlg : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBProxyLoginDlg(QWidget* parent=0, const char* name="ProxyLoginDlg"); |
||||
~UBProxyLoginDlg(); |
||||
|
||||
QString username(){return mpUsername->text();} |
||||
QString password(){return mpPassword->text();} |
||||
|
||||
private: |
||||
QVBoxLayout* mpLayout; |
||||
QHBoxLayout* mpUserLayout; |
||||
QHBoxLayout* mpPasswordLayout; |
||||
QDialogButtonBox* mpButtons; |
||||
QLabel* mpUserLabel; |
||||
QLabel* mpPasswordLabel; |
||||
QLineEdit* mpUsername; |
||||
QLineEdit* mpPassword; |
||||
}; |
||||
|
||||
class UBPublicationDlg : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBPublicationDlg(QWidget* parent=0, const char* name="UBPublicationDlg"); |
||||
~UBPublicationDlg(); |
||||
|
||||
QString title(){return mpTitle->text();} |
||||
QString description(){return mpDescription->document()->toPlainText();} |
||||
|
||||
private slots: |
||||
void onTextChanged(); |
||||
|
||||
private: |
||||
QVBoxLayout* mpLayout; |
||||
QHBoxLayout* mpTitleLayout; |
||||
QLabel* mpTitleLabel; |
||||
QLineEdit* mpTitle; |
||||
QLabel* mpDescLabel; |
||||
QTextEdit* mpDescription; |
||||
QDialogButtonBox* mpButtons; |
||||
}; |
||||
|
||||
|
||||
class UBDocumentPublisher : public QObject |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0); |
||||
virtual ~UBDocumentPublisher(); |
||||
|
||||
void publish(); |
||||
|
||||
signals: |
||||
|
||||
void loginDone(); |
||||
|
||||
protected: |
||||
|
||||
virtual void updateGoogleMapApiKey(); |
||||
virtual void rasterizeScenes(); |
||||
virtual void upgradeDocumentForPublishing(); |
||||
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber); |
||||
|
||||
private slots: |
||||
|
||||
void onFinished(QNetworkReply* reply); |
||||
|
||||
private: |
||||
|
||||
UBDocumentProxy *mSourceDocument; |
||||
UBDocumentProxy *mPublishingDocument; |
||||
void init(); |
||||
void sendUbw(QString username, QString password); |
||||
QString getBase64Of(QString stringToEncode); |
||||
|
||||
QHBoxLayout* mpLayout; |
||||
QNetworkAccessManager* mpNetworkMgr; |
||||
QNetworkCookieJar* mpCookieJar; |
||||
QString mUsername; |
||||
QString mPassword; |
||||
QString mCrlf; |
||||
bool bLoginCookieSet; |
||||
|
||||
void buildUbwFile(); |
||||
QString mTmpZipFile; |
||||
QList<QNetworkCookie> mCookies; |
||||
sDocumentInfos mDocInfos; |
||||
|
||||
}; |
||||
#endif // UBDOCUMENTPUBLISHER_H
|
||||
/*
|
||||
* 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 2 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 UBDOCUMENTPUBLISHER_H |
||||
#define UBDOCUMENTPUBLISHER_H |
||||
|
||||
#include <QtGui> |
||||
#include <QtNetwork> |
||||
|
||||
#include "ui_webPublishing.h" |
||||
|
||||
#define DOCPUBLICATION_URL "http://planete.sankore.org/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain"
|
||||
|
||||
typedef struct |
||||
{ |
||||
QString title; |
||||
QString description; |
||||
} sDocumentInfos; |
||||
|
||||
class UBDocumentProxy; |
||||
class UBServerXMLHttpRequest; |
||||
class UBGraphicsW3CWidgetItem; |
||||
class QWebView; |
||||
|
||||
class UBProxyLoginDlg : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBProxyLoginDlg(QWidget* parent=0, const char* name="ProxyLoginDlg"); |
||||
~UBProxyLoginDlg(); |
||||
|
||||
QString username(){return mpUsername->text();} |
||||
QString password(){return mpPassword->text();} |
||||
|
||||
private: |
||||
QVBoxLayout* mpLayout; |
||||
QHBoxLayout* mpUserLayout; |
||||
QHBoxLayout* mpPasswordLayout; |
||||
QDialogButtonBox* mpButtons; |
||||
QLabel* mpUserLabel; |
||||
QLabel* mpPasswordLabel; |
||||
QLineEdit* mpUsername; |
||||
QLineEdit* mpPassword; |
||||
}; |
||||
|
||||
class UBPublicationDlg : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBPublicationDlg(QWidget* parent=0, const char* name="UBPublicationDlg"); |
||||
~UBPublicationDlg(); |
||||
|
||||
QString title(){return mpTitle->text();} |
||||
QString description(){return mpDescription->document()->toPlainText();} |
||||
|
||||
private slots: |
||||
void onTextChanged(); |
||||
|
||||
private: |
||||
QVBoxLayout* mpLayout; |
||||
QHBoxLayout* mpTitleLayout; |
||||
QLabel* mpTitleLabel; |
||||
QLineEdit* mpTitle; |
||||
QLabel* mpDescLabel; |
||||
QTextEdit* mpDescription; |
||||
QDialogButtonBox* mpButtons; |
||||
}; |
||||
|
||||
|
||||
class UBDocumentPublisher : public QObject |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0); |
||||
virtual ~UBDocumentPublisher(); |
||||
|
||||
void publish(); |
||||
|
||||
signals: |
||||
|
||||
void loginDone(); |
||||
|
||||
protected: |
||||
|
||||
virtual void updateGoogleMapApiKey(); |
||||
virtual void rasterizeScenes(); |
||||
virtual void upgradeDocumentForPublishing(); |
||||
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber); |
||||
|
||||
private slots: |
||||
|
||||
void onFinished(QNetworkReply* reply); |
||||
|
||||
private: |
||||
|
||||
UBDocumentProxy *mSourceDocument; |
||||
|
||||
//UBDocumentProxy *mPublishingDocument;
|
||||
QString mPublishingPath; |
||||
int mPublishingSize; |
||||
|
||||
|
||||
void init(); |
||||
void sendUbw(QString username, QString password); |
||||
QString getBase64Of(QString stringToEncode); |
||||
|
||||
QHBoxLayout* mpLayout; |
||||
QNetworkAccessManager* mpNetworkMgr; |
||||
QNetworkCookieJar* mpCookieJar; |
||||
QString mUsername; |
||||
QString mPassword; |
||||
QString mCrlf; |
||||
bool bLoginCookieSet; |
||||
|
||||
void buildUbwFile(); |
||||
QString mTmpZipFile; |
||||
QList<QNetworkCookie> mCookies; |
||||
sDocumentInfos mDocInfos; |
||||
|
||||
}; |
||||
#endif // UBDOCUMENTPUBLISHER_H
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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 |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 2 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 UBDOCUMENTCONTROLLER_H_ |
||||
#define UBDOCUMENTCONTROLLER_H_ |
||||
|
||||
#include <QtGui> |
||||
|
||||
namespace Ui |
||||
{ |
||||
class documents; |
||||
} |
||||
|
||||
#include "gui/UBMessageWindow.h" |
||||
|
||||
class UBGraphicsScene; |
||||
class QDialog; |
||||
class UBDocumentProxy; |
||||
class UBBoardController; |
||||
class UBThumbnailsScene; |
||||
class UBDocumentGroupTreeItem; |
||||
class UBDocumentProxyTreeItem; |
||||
class UBMainWindow; |
||||
class UBDocumentToolsPalette; |
||||
|
||||
class UBDocumentController : public QObject |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
UBDocumentController(UBMainWindow* mainWindow); |
||||
virtual ~UBDocumentController(); |
||||
|
||||
void closing(); |
||||
QWidget* controlView(); |
||||
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy); |
||||
bool addFileToDocument(UBDocumentProxy* document); |
||||
UBDocumentProxy* getCurrentDocument() { return mCurrentDocument; }; |
||||
void deletePages(QList<QGraphicsItem*> itemsToDelete); |
||||
int getSelectedItemIndex(); |
||||
|
||||
bool pageCanBeMovedUp(int page); |
||||
bool pageCanBeMovedDown(int page); |
||||
bool pageCanBeDuplicated(int page); |
||||
bool pageCanBeDeleted(int page); |
||||
|
||||
signals: |
||||
void refreshThumbnails(); |
||||
void exportDone(); |
||||
void movedToIndex(int index); |
||||
|
||||
public slots: |
||||
void createNewDocument(); |
||||
void createNewDocumentGroup(); |
||||
void deleteSelectedItem(); |
||||
void renameSelectedItem(); |
||||
void openSelectedItem(); |
||||
void duplicateSelectedItem(); |
||||
void importFile(); |
||||
void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target); |
||||
void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true); |
||||
void show(); |
||||
void hide(); |
||||
void showMessage(const QString& message, bool showSpinningWheel); |
||||
void hideMessage(); |
||||
void toggleDocumentToolsPalette(); |
||||
void cut(); |
||||
void copy(); |
||||
void paste(); |
||||
void focusChanged(QWidget *old, QWidget *current); |
||||
void reloadThumbs(); |
||||
|
||||
protected: |
||||
virtual void setupViews(); |
||||
virtual void setupToolbar(); |
||||
void setupPalettes(); |
||||
bool isOKToOpenDocument(UBDocumentProxy* proxy); |
||||
UBGraphicsScene* activeScene(); |
||||
UBDocumentProxy* selectedDocumentProxy(); |
||||
UBDocumentProxyTreeItem* selectedDocumentProxyTreeItem(); |
||||
UBDocumentGroupTreeItem* selectedDocumentGroupTreeItem(); |
||||
QStringList allGroupNames(); |
||||
|
||||
enum LastSelectedElementType |
||||
{ |
||||
None = 0, Folder, Document, Page |
||||
}; |
||||
|
||||
LastSelectedElementType mSelectionType; |
||||
|
||||
private: |
||||
QWidget *mParentWidget; |
||||
UBBoardController *mBoardController; |
||||
Ui::documents* mDocumentUI; |
||||
UBMainWindow* mMainWindow; |
||||
QWidget *mDocumentWidget; |
||||
QPointer<UBMessageWindow> mMessageWindow; |
||||
QAction* mAddFolderOfImagesAction; |
||||
QAction* mAddFileToDocumentAction; |
||||
QAction* mAddImagesAction; |
||||
bool mIsClosing; |
||||
UBDocumentToolsPalette *mToolsPalette; |
||||
bool mToolsPalettePositionned; |
||||
UBDocumentGroupTreeItem* mTrashTi; |
||||
UBDocumentProxy* mCurrentDocument; |
||||
QList<QPixmap> mDocumentThumbs; |
||||
|
||||
private slots: |
||||
void documentZoomSliderValueChanged (int value); |
||||
void loadDocumentProxies(); |
||||
void itemSelectionChanged(); |
||||
void refreshDocumentThumbnailsView(); |
||||
void exportDocument(); |
||||
void itemChanged(QTreeWidgetItem * item, int column); |
||||
void thumbnailViewResized(); |
||||
void pageSelectionChanged(); |
||||
void selectionChanged(); |
||||
void documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex); |
||||
void pageDoubleClicked(QGraphicsItem* item, int index); |
||||
void pageClicked(QGraphicsItem* item, int index); |
||||
void itemClicked(QTreeWidgetItem * item, int column ); |
||||
void addToDocument(); |
||||
void addDocumentInTree(UBDocumentProxy* pDocument); |
||||
void updateDocumentInTree(UBDocumentProxy* pDocument); |
||||
void addFolderOfImages(); |
||||
void addFileToDocument(); |
||||
void addImages(); |
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
#endif /* UBDOCUMENTCONTROLLER_H_ */ |
||||
/*
|
||||
* 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 2 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 UBDOCUMENTCONTROLLER_H_ |
||||
#define UBDOCUMENTCONTROLLER_H_ |
||||
|
||||
#include <QtGui> |
||||
#include "document/UBDocumentContainer.h" |
||||
|
||||
namespace Ui |
||||
{ |
||||
class documents; |
||||
} |
||||
|
||||
#include "gui/UBMessageWindow.h" |
||||
|
||||
class UBGraphicsScene; |
||||
class QDialog; |
||||
class UBDocumentProxy; |
||||
class UBBoardController; |
||||
class UBThumbnailsScene; |
||||
class UBDocumentGroupTreeItem; |
||||
class UBDocumentProxyTreeItem; |
||||
class UBMainWindow; |
||||
class UBDocumentToolsPalette; |
||||
|
||||
class UBDocumentController : public UBDocumentContainer |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
UBDocumentController(UBMainWindow* mainWindow); |
||||
virtual ~UBDocumentController(); |
||||
|
||||
void closing(); |
||||
QWidget* controlView(); |
||||
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy); |
||||
bool addFileToDocument(UBDocumentProxy* document); |
||||
void deletePages(QList<QGraphicsItem*> itemsToDelete); |
||||
int getSelectedItemIndex(); |
||||
|
||||
bool pageCanBeMovedUp(int page); |
||||
bool pageCanBeMovedDown(int page); |
||||
bool pageCanBeDuplicated(int page); |
||||
bool pageCanBeDeleted(int page); |
||||
|
||||
signals: |
||||
//void refreshThumbnails();
|
||||
void exportDone(); |
||||
//void movedToIndex(int index);
|
||||
|
||||
public slots: |
||||
void createNewDocument(); |
||||
void createNewDocumentGroup(); |
||||
void deleteSelectedItem(); |
||||
void renameSelectedItem(); |
||||
void openSelectedItem(); |
||||
void duplicateSelectedItem(); |
||||
void importFile(); |
||||
void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target); |
||||
void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true); |
||||
void show(); |
||||
void hide(); |
||||
void showMessage(const QString& message, bool showSpinningWheel); |
||||
void hideMessage(); |
||||
void toggleDocumentToolsPalette(); |
||||
void cut(); |
||||
void copy(); |
||||
void paste(); |
||||
void focusChanged(QWidget *old, QWidget *current); |
||||
//void reloadThumbs();
|
||||
|
||||
protected: |
||||
virtual void setupViews(); |
||||
virtual void setupToolbar(); |
||||
void setupPalettes(); |
||||
bool isOKToOpenDocument(UBDocumentProxy* proxy); |
||||
UBDocumentProxy* selectedDocumentProxy(); |
||||
UBDocumentProxyTreeItem* selectedDocumentProxyTreeItem(); |
||||
UBDocumentGroupTreeItem* selectedDocumentGroupTreeItem(); |
||||
QStringList allGroupNames(); |
||||
|
||||
enum LastSelectedElementType |
||||
{ |
||||
None = 0, Folder, Document, Page |
||||
}; |
||||
|
||||
LastSelectedElementType mSelectionType; |
||||
|
||||
private: |
||||
QWidget *mParentWidget; |
||||
UBBoardController *mBoardController; |
||||
Ui::documents* mDocumentUI; |
||||
UBMainWindow* mMainWindow; |
||||
QWidget *mDocumentWidget; |
||||
QPointer<UBMessageWindow> mMessageWindow; |
||||
QAction* mAddFolderOfImagesAction; |
||||
QAction* mAddFileToDocumentAction; |
||||
QAction* mAddImagesAction; |
||||
bool mIsClosing; |
||||
UBDocumentToolsPalette *mToolsPalette; |
||||
bool mToolsPalettePositionned; |
||||
UBDocumentGroupTreeItem* mTrashTi; |
||||
|
||||
private slots: |
||||
void documentZoomSliderValueChanged (int value); |
||||
void loadDocumentProxies(); |
||||
void itemSelectionChanged(); |
||||
void exportDocument(); |
||||
void itemChanged(QTreeWidgetItem * item, int column); |
||||
void thumbnailViewResized(); |
||||
void pageSelectionChanged(); |
||||
void selectionChanged(); |
||||
void documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex); |
||||
void pageDoubleClicked(QGraphicsItem* item, int index); |
||||
void pageClicked(QGraphicsItem* item, int index); |
||||
void itemClicked(QTreeWidgetItem * item, int column ); |
||||
void addToDocument(); |
||||
void addDocumentInTree(UBDocumentProxy* pDocument); |
||||
void updateDocumentInTree(UBDocumentProxy* pDocument); |
||||
void addFolderOfImages(); |
||||
void addFileToDocument(); |
||||
void addImages(); |
||||
|
||||
void refreshDocumentThumbnailsView(UBDocumentContainer* source); |
||||
}; |
||||
|
||||
|
||||
|
||||
#endif /* UBDOCUMENTCONTROLLER_H_ */ |
||||
|
@ -1,232 +1,232 @@ |
||||
/*
|
||||
* 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 2 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 "UBDocumentProxy.h" |
||||
|
||||
#include "frameworks/UBStringUtils.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBSettings.h" |
||||
#include "core/UBDocumentManager.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBDocumentProxy::UBDocumentProxy() |
||||
: mPageCount(0) |
||||
{ |
||||
init(); |
||||
} |
||||
|
||||
|
||||
UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath) |
||||
: mPageCount(0) |
||||
{ |
||||
init(); |
||||
setPersistencePath(pPersistancePath); |
||||
} |
||||
|
||||
|
||||
void UBDocumentProxy::init() |
||||
{ |
||||
setMetaData(UBSettings::documentGroupName, ""); |
||||
|
||||
QDateTime now = QDateTime::currentDateTime(); |
||||
setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate)); |
||||
|
||||
setUuid(QUuid::createUuid()); |
||||
|
||||
setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize()); |
||||
|
||||
//teacherGuide metadata
|
||||
setMetaData(UBSettings::sessionTitle,""); |
||||
setMetaData(UBSettings::sessionAuthors,""); |
||||
setMetaData(UBSettings::sessionObjectives,""); |
||||
setMetaData(UBSettings::sessionKeywords,""); |
||||
setMetaData(UBSettings::sessionGradeLevel,""); |
||||
setMetaData(UBSettings::sessionSubjects,""); |
||||
setMetaData(UBSettings::sessionType,""); |
||||
setMetaData(UBSettings::sessionLicence,""); |
||||
} |
||||
|
||||
|
||||
UBDocumentProxy::~UBDocumentProxy() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
int UBDocumentProxy::pageCount() |
||||
{ |
||||
return mPageCount; |
||||
} |
||||
|
||||
|
||||
void UBDocumentProxy::setPageCount(int pPageCount) |
||||
{ |
||||
mPageCount = pPageCount; |
||||
} |
||||
|
||||
|
||||
int UBDocumentProxy::incPageCount() |
||||
{ |
||||
if (mPageCount <= 0) |
||||
{ |
||||
mPageCount = 1; |
||||
} |
||||
else |
||||
{ |
||||
mPageCount++; |
||||
} |
||||
|
||||
return mPageCount; |
||||
|
||||
} |
||||
|
||||
|
||||
int UBDocumentProxy::decPageCount() |
||||
{ |
||||
mPageCount --; |
||||
|
||||
if (mPageCount < 0) |
||||
{ |
||||
mPageCount = 0; |
||||
} |
||||
|
||||
return mPageCount; |
||||
} |
||||
|
||||
QString UBDocumentProxy::persistencePath() const |
||||
{ |
||||
return mPersistencePath; |
||||
} |
||||
|
||||
void UBDocumentProxy::setPersistencePath(const QString& pPersistencePath) |
||||
{ |
||||
if (pPersistencePath != mPersistencePath) |
||||
{ |
||||
mIsModified = true; |
||||
mPersistencePath = pPersistencePath; |
||||
} |
||||
} |
||||
|
||||
void UBDocumentProxy::setMetaData(const QString& pKey, const QVariant& pValue) |
||||
{ |
||||
if (mMetaDatas.contains(pKey) && mMetaDatas.value(pKey) == pValue) |
||||
return; |
||||
else |
||||
{ |
||||
mIsModified = true; |
||||
mMetaDatas.insert(pKey, pValue); |
||||
if (pKey == UBSettings::documentUpdatedAt) |
||||
{ |
||||
UBDocumentManager *documentManager = UBDocumentManager::documentManager(); |
||||
if (documentManager) |
||||
documentManager->emitDocumentUpdated(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
QVariant UBDocumentProxy::metaData(const QString& pKey) const |
||||
{ |
||||
if (mMetaDatas.contains(pKey)) |
||||
{ |
||||
return mMetaDatas.value(pKey); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "Unknown metadata key" << pKey; |
||||
return QString(""); // failsafe
|
||||
} |
||||
} |
||||
|
||||
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const |
||||
{ |
||||
return mMetaDatas; |
||||
} |
||||
|
||||
QString UBDocumentProxy::name() const |
||||
{ |
||||
return metaData(UBSettings::documentName).toString(); |
||||
} |
||||
|
||||
QString UBDocumentProxy::groupName() const |
||||
{ |
||||
return metaData(UBSettings::documentGroupName).toString(); |
||||
} |
||||
|
||||
QSize UBDocumentProxy::defaultDocumentSize() const |
||||
{ |
||||
if (mMetaDatas.contains(UBSettings::documentSize)) |
||||
return metaData(UBSettings::documentSize).toSize(); |
||||
else |
||||
return UBSettings::settings()->pageSize->get().toSize(); |
||||
} |
||||
|
||||
void UBDocumentProxy::setDefaultDocumentSize(QSize pSize) |
||||
{ |
||||
if (defaultDocumentSize() != pSize) |
||||
{ |
||||
setMetaData(UBSettings::documentSize, QVariant(pSize)); |
||||
emit defaultDocumentSizeChanged(); |
||||
|
||||
mIsModified = true; |
||||
} |
||||
} |
||||
|
||||
void UBDocumentProxy::setDefaultDocumentSize(int pWidth, int pHeight) |
||||
{ |
||||
setDefaultDocumentSize(QSize(pWidth, pHeight)); |
||||
} |
||||
|
||||
|
||||
QUuid UBDocumentProxy::uuid() const |
||||
{ |
||||
QString id = metaData(UBSettings::documentIdentifer).toString(); |
||||
QString sUuid = id.replace(UBSettings::uniboardDocumentNamespaceUri + "/", ""); |
||||
|
||||
return QUuid(sUuid); |
||||
} |
||||
|
||||
void UBDocumentProxy::setUuid(const QUuid& uuid) |
||||
{ |
||||
setMetaData(UBSettings::documentIdentifer, |
||||
UBSettings::uniboardDocumentNamespaceUri + "/" + UBStringUtils::toCanonicalUuid(uuid)); |
||||
} |
||||
|
||||
|
||||
QDateTime UBDocumentProxy::documentDate() |
||||
{ |
||||
if(mMetaDatas.contains(UBSettings::documentDate)) |
||||
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString()); |
||||
return QDateTime::currentDateTime(); |
||||
} |
||||
|
||||
QDateTime UBDocumentProxy::lastUpdate() |
||||
{ |
||||
if(mMetaDatas.contains(UBSettings::documentUpdatedAt)) |
||||
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentUpdatedAt).toString()); |
||||
return QDateTime().currentDateTime(); |
||||
} |
||||
|
||||
bool UBDocumentProxy::isModified() const |
||||
{ |
||||
return mIsModified; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 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 2 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 "UBDocumentProxy.h" |
||||
|
||||
#include "frameworks/UBStringUtils.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBSettings.h" |
||||
#include "core/UBDocumentManager.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBDocumentProxy::UBDocumentProxy() |
||||
: mPageCount(0) |
||||
{ |
||||
init(); |
||||
} |
||||
|
||||
|
||||
UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath) |
||||
: mPageCount(0) |
||||
{ |
||||
init(); |
||||
setPersistencePath(pPersistancePath); |
||||
} |
||||
|
||||
|
||||
void UBDocumentProxy::init() |
||||
{ |
||||
setMetaData(UBSettings::documentGroupName, ""); |
||||
|
||||
QDateTime now = QDateTime::currentDateTime(); |
||||
setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate)); |
||||
|
||||
setUuid(QUuid::createUuid()); |
||||
|
||||
setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize()); |
||||
|
||||
//teacherGuide metadata
|
||||
setMetaData(UBSettings::sessionTitle,""); |
||||
setMetaData(UBSettings::sessionAuthors,""); |
||||
setMetaData(UBSettings::sessionObjectives,""); |
||||
setMetaData(UBSettings::sessionKeywords,""); |
||||
setMetaData(UBSettings::sessionGradeLevel,""); |
||||
setMetaData(UBSettings::sessionSubjects,""); |
||||
setMetaData(UBSettings::sessionType,""); |
||||
setMetaData(UBSettings::sessionLicence,""); |
||||
} |
||||
|
||||
|
||||
UBDocumentProxy::~UBDocumentProxy() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
int UBDocumentProxy::pageCount() |
||||
{ |
||||
return mPageCount; |
||||
} |
||||
|
||||
|
||||
void UBDocumentProxy::setPageCount(int pPageCount) |
||||
{ |
||||
mPageCount = pPageCount; |
||||
} |
||||
|
||||
|
||||
int UBDocumentProxy::incPageCount() |
||||
{ |
||||
if (mPageCount <= 0) |
||||
{ |
||||
mPageCount = 1; |
||||
} |
||||
else |
||||
{ |
||||
mPageCount++; |
||||
} |
||||
|
||||
return mPageCount; |
||||
|
||||
} |
||||
|
||||
|
||||
int UBDocumentProxy::decPageCount() |
||||
{ |
||||
mPageCount --; |
||||
|
||||
if (mPageCount < 0) |
||||
{ |
||||
mPageCount = 0; |
||||
} |
||||
|
||||
return mPageCount; |
||||
} |
||||
|
||||
QString UBDocumentProxy::persistencePath() const |
||||
{ |
||||
return mPersistencePath; |
||||
} |
||||
|
||||
void UBDocumentProxy::setPersistencePath(const QString& pPersistencePath) |
||||
{ |
||||
if (pPersistencePath != mPersistencePath) |
||||
{ |
||||
mIsModified = true; |
||||
mPersistencePath = pPersistencePath; |
||||
} |
||||
} |
||||
|
||||
void UBDocumentProxy::setMetaData(const QString& pKey, const QVariant& pValue) |
||||
{ |
||||
if (mMetaDatas.contains(pKey) && mMetaDatas.value(pKey) == pValue) |
||||
return; |
||||
else |
||||
{ |
||||
mIsModified = true; |
||||
mMetaDatas.insert(pKey, pValue); |
||||
if (pKey == UBSettings::documentUpdatedAt) |
||||
{ |
||||
UBDocumentManager *documentManager = UBDocumentManager::documentManager(); |
||||
if (documentManager) |
||||
documentManager->emitDocumentUpdated(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
QVariant UBDocumentProxy::metaData(const QString& pKey) const |
||||
{ |
||||
if (mMetaDatas.contains(pKey)) |
||||
{ |
||||
return mMetaDatas.value(pKey); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "Unknown metadata key" << pKey; |
||||
return QString(""); // failsafe
|
||||
} |
||||
} |
||||
|
||||
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const |
||||
{ |
||||
return mMetaDatas; |
||||
} |
||||
|
||||
QString UBDocumentProxy::name() const |
||||
{ |
||||
return metaData(UBSettings::documentName).toString(); |
||||
} |
||||
|
||||
QString UBDocumentProxy::groupName() const |
||||
{ |
||||
return metaData(UBSettings::documentGroupName).toString(); |
||||
} |
||||
|
||||
QSize UBDocumentProxy::defaultDocumentSize() const |
||||
{ |
||||
if (mMetaDatas.contains(UBSettings::documentSize)) |
||||
return metaData(UBSettings::documentSize).toSize(); |
||||
else |
||||
return UBSettings::settings()->pageSize->get().toSize(); |
||||
} |
||||
|
||||
void UBDocumentProxy::setDefaultDocumentSize(QSize pSize) |
||||
{ |
||||
if (defaultDocumentSize() != pSize) |
||||
{ |
||||
setMetaData(UBSettings::documentSize, QVariant(pSize)); |
||||
emit defaultDocumentSizeChanged(); |
||||
|
||||
mIsModified = true; |
||||
} |
||||
} |
||||
|
||||
void UBDocumentProxy::setDefaultDocumentSize(int pWidth, int pHeight) |
||||
{ |
||||
setDefaultDocumentSize(QSize(pWidth, pHeight)); |
||||
} |
||||
|
||||
|
||||
QUuid UBDocumentProxy::uuid() const |
||||
{ |
||||
QString id = metaData(UBSettings::documentIdentifer).toString(); |
||||
QString sUuid = id.replace(UBSettings::uniboardDocumentNamespaceUri + "/", ""); |
||||
|
||||
return QUuid(sUuid); |
||||
} |
||||
|
||||
void UBDocumentProxy::setUuid(const QUuid& uuid) |
||||
{ |
||||
setMetaData(UBSettings::documentIdentifer, |
||||
UBSettings::uniboardDocumentNamespaceUri + "/" + UBStringUtils::toCanonicalUuid(uuid)); |
||||
} |
||||
|
||||
|
||||
QDateTime UBDocumentProxy::documentDate() |
||||
{ |
||||
if(mMetaDatas.contains(UBSettings::documentDate)) |
||||
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString()); |
||||
return QDateTime::currentDateTime(); |
||||
} |
||||
|
||||
QDateTime UBDocumentProxy::lastUpdate() |
||||
{ |
||||
if(mMetaDatas.contains(UBSettings::documentUpdatedAt)) |
||||
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentUpdatedAt).toString()); |
||||
return QDateTime().currentDateTime(); |
||||
} |
||||
|
||||
bool UBDocumentProxy::isModified() const |
||||
{ |
||||
return mIsModified; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,95 +1,99 @@ |
||||
/*
|
||||
* 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 2 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 UBDOCUMENTPROXY_H_ |
||||
#define UBDOCUMENTPROXY_H_ |
||||
|
||||
#include <QtGui> |
||||
|
||||
#include "frameworks/UBStringUtils.h" |
||||
|
||||
#include "core/UBSettings.h" |
||||
|
||||
class UBGraphicsScene; |
||||
|
||||
class UBDocumentProxy : public QObject |
||||
{ |
||||
Q_OBJECT; |
||||
|
||||
public: |
||||
|
||||
UBDocumentProxy(); |
||||
UBDocumentProxy(const QString& pPersistencePath); |
||||
|
||||
virtual ~UBDocumentProxy(); |
||||
|
||||
QString persistencePath() const; |
||||
|
||||
void setPersistencePath(const QString& pPersistencePath); |
||||
|
||||
void setMetaData(const QString& pKey , const QVariant& pValue); |
||||
QVariant metaData(const QString& pKey) const; |
||||
QHash<QString, QVariant> metaDatas() const; |
||||
|
||||
QString name() const; |
||||
QString groupName() const; |
||||
QDateTime documentDate(); |
||||
|
||||
QDateTime lastUpdate(); |
||||
|
||||
|
||||
QSize defaultDocumentSize() const; |
||||
void setDefaultDocumentSize(QSize pSize); |
||||
void setDefaultDocumentSize(int pWidth, int pHeight); |
||||
|
||||
QUuid uuid() const; |
||||
void setUuid(const QUuid& uuid); |
||||
|
||||
bool isModified() const; |
||||
|
||||
int pageCount(); |
||||
void setPageCount(int pPageCount); |
||||
int incPageCount(); |
||||
int decPageCount(); |
||||
|
||||
signals: |
||||
void defaultDocumentSizeChanged(); |
||||
|
||||
private: |
||||
|
||||
void init(); |
||||
|
||||
QString mPersistencePath; |
||||
|
||||
QHash<QString, QVariant> mMetaDatas; |
||||
|
||||
bool mIsModified; |
||||
|
||||
int mPageCount; |
||||
|
||||
}; |
||||
|
||||
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2) |
||||
{ |
||||
return proxy1.persistencePath() == proxy2.persistencePath(); |
||||
} |
||||
|
||||
inline uint qHash(const UBDocumentProxy &key) |
||||
{ |
||||
return qHash(key.persistencePath()); |
||||
} |
||||
|
||||
|
||||
#endif /* UBDOCUMENTPROXY_H_ */ |
||||
/*
|
||||
* 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 2 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 UBDOCUMENTPROXY_H_ |
||||
#define UBDOCUMENTPROXY_H_ |
||||
|
||||
#include <QtGui> |
||||
|
||||
#include "frameworks/UBStringUtils.h" |
||||
|
||||
#include "core/UBSettings.h" |
||||
|
||||
class UBGraphicsScene; |
||||
|
||||
class UBDocumentProxy : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
friend class UBPersistenceManager; |
||||
|
||||
public: |
||||
|
||||
UBDocumentProxy(); |
||||
UBDocumentProxy(const QString& pPersistencePath); |
||||
|
||||
virtual ~UBDocumentProxy(); |
||||
|
||||
QString persistencePath() const; |
||||
|
||||
void setPersistencePath(const QString& pPersistencePath); |
||||
|
||||
void setMetaData(const QString& pKey , const QVariant& pValue); |
||||
QVariant metaData(const QString& pKey) const; |
||||
QHash<QString, QVariant> metaDatas() const; |
||||
|
||||
QString name() const; |
||||
QString groupName() const; |
||||
QDateTime documentDate(); |
||||
|
||||
QDateTime lastUpdate(); |
||||
|
||||
|
||||
QSize defaultDocumentSize() const; |
||||
void setDefaultDocumentSize(QSize pSize); |
||||
void setDefaultDocumentSize(int pWidth, int pHeight); |
||||
|
||||
QUuid uuid() const; |
||||
void setUuid(const QUuid& uuid); |
||||
|
||||
bool isModified() const; |
||||
|
||||
int pageCount(); |
||||
|
||||
protected: |
||||
void setPageCount(int pPageCount); |
||||
int incPageCount(); |
||||
int decPageCount(); |
||||
|
||||
signals: |
||||
void defaultDocumentSizeChanged(); |
||||
|
||||
private: |
||||
|
||||
void init(); |
||||
|
||||
QString mPersistencePath; |
||||
|
||||
QHash<QString, QVariant> mMetaDatas; |
||||
|
||||
bool mIsModified; |
||||
|
||||
int mPageCount; |
||||
|
||||
}; |
||||
|
||||
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2) |
||||
{ |
||||
return proxy1.persistencePath() == proxy2.persistencePath(); |
||||
} |
||||
|
||||
inline uint qHash(const UBDocumentProxy &key) |
||||
{ |
||||
return qHash(key.persistencePath()); |
||||
} |
||||
|
||||
|
||||
#endif /* UBDOCUMENTPROXY_H_ */ |
||||
|
@ -1,6 +1,8 @@ |
||||
|
||||
HEADERS += src/document/UBDocumentController.h \ |
||||
src/document/UBDocumentContainer.h \ |
||||
src/document/UBDocumentProxy.h |
||||
|
||||
SOURCES += src/document/UBDocumentController.cpp \ |
||||
SOURCES += src/document/UBDocumentController.cpp \ |
||||
src/document/UBDocumentContainer.cpp \ |
||||
src/document/UBDocumentProxy.cpp |
@ -1,384 +1,273 @@ |
||||
/*
|
||||
* 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 2 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 <QList> |
||||
#include <QPointF> |
||||
#include <QPixmap> |
||||
#include <QTransform> |
||||
#include <QScrollBar> |
||||
#include <QFontMetrics> |
||||
#include <QGraphicsItem> |
||||
#include <QGraphicsPixmapItem> |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "UBDocumentNavigator.h" |
||||
#include "board/UBBoardController.h" |
||||
#include "adaptors/UBThumbnailAdaptor.h" |
||||
#include "adaptors/UBSvgSubsetAdaptor.h" |
||||
#include "document/UBDocumentController.h" |
||||
#include "domain/UBGraphicsScene.h" |
||||
#include "board/UBBoardPaletteManager.h" |
||||
#include "core/UBApplicationController.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGraphicsView(parent) |
||||
, mScene(NULL) |
||||
, mCrntItem(NULL) |
||||
, mCrntDoc(NULL) |
||||
, mNbColumns(1) |
||||
, mThumbnailWidth(0) |
||||
, mThumbnailMinWidth(100) |
||||
, bNavig(false) |
||||
{ |
||||
setObjectName(name); |
||||
mScene = new QGraphicsScene(this); |
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||
setScene(mScene); |
||||
mThumbnailWidth = width() - 2*border(); |
||||
|
||||
setFrameShadow(QFrame::Plain); |
||||
|
||||
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))); |
||||
connect(UBApplication::boardController, SIGNAL(scrollToSelectedPage()), this, SLOT(onScrollToSelectedPage())); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBDocumentNavigator::~UBDocumentNavigator() |
||||
{ |
||||
if(NULL != mCrntItem) |
||||
{ |
||||
delete mCrntItem; |
||||
mCrntItem = NULL; |
||||
} |
||||
|
||||
if(NULL != mScene) |
||||
{ |
||||
delete mScene; |
||||
mScene = NULL; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the current document |
||||
* @param document as the new document |
||||
*/ |
||||
void UBDocumentNavigator::setDocument(UBDocumentProxy *document) |
||||
{ |
||||
// Here we set a new document to the navigator. We must clear the current
|
||||
// content and add all the pages of the given document.
|
||||
if(document) |
||||
{ |
||||
mCrntDoc = document; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Generate the thumbnails |
||||
*/ |
||||
void UBDocumentNavigator::generateThumbnails() |
||||
{ |
||||
// Get the thumbnails
|
||||
QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc); |
||||
|
||||
mThumbsWithLabels.clear(); |
||||
foreach(QGraphicsItem* it, mScene->items()) |
||||
{ |
||||
mScene->removeItem(it); |
||||
delete it; |
||||
} |
||||
|
||||
for(int i = 0; i < thumbs.count(); i++) |
||||
{ |
||||
QPixmap pix = thumbs.at(i); |
||||
QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, i); |
||||
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(tr("Page %0").arg(UBApplication::boardController->pageFromSceneIndex(i))); |
||||
|
||||
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem); |
||||
thumbWithText.setBorder(border()); |
||||
mThumbsWithLabels.append(thumbWithText); |
||||
|
||||
mScene->addItem(pixmapItem); |
||||
mScene->addItem(labelItem); |
||||
|
||||
// Get the selected item
|
||||
if(UBApplication::boardController->activeSceneIndex() == i) |
||||
{ |
||||
mCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pixmapItem); |
||||
mCrntItem->setSelected(true); |
||||
} |
||||
} |
||||
|
||||
// Draw the items
|
||||
refreshScene(); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Refresh the given thumbnail |
||||
* @param iPage as the given page related thumbnail |
||||
*/ |
||||
void UBDocumentNavigator::updateSpecificThumbnail(int iPage) |
||||
{ |
||||
// Generate the new thumbnail
|
||||
UBGraphicsScene* pScene = UBApplication::boardController->activeScene(); |
||||
|
||||
if(NULL != pScene) |
||||
{ |
||||
// Save the current state of the scene
|
||||
pScene->setModified(true); |
||||
if(UBApplication::boardController) |
||||
{ |
||||
UBApplication::boardController->persistCurrentScene(); |
||||
}else |
||||
{ |
||||
UBThumbnailAdaptor::persistScene(mCrntDoc->persistencePath(), pScene, iPage); |
||||
} |
||||
|
||||
// Load it
|
||||
QPixmap pix = UBThumbnailAdaptor::load(mCrntDoc, iPage); |
||||
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage); |
||||
if(pixmapItem) |
||||
{ |
||||
// Get the old thumbnail
|
||||
QGraphicsItem* pItem = mThumbsWithLabels.at(iPage).getThumbnail(); |
||||
if(NULL != pItem) |
||||
{ |
||||
mScene->removeItem(pItem); |
||||
mScene->addItem(pixmapItem); |
||||
mThumbsWithLabels[iPage].setThumbnail(pixmapItem); |
||||
delete pItem; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Add a new page to the thumbnails list |
||||
* |
||||
* This method is called automatically by the board controller each time the user |
||||
* adds a new page, duplicates a page or imports a document. |
||||
*/ |
||||
void UBDocumentNavigator::addNewPage() |
||||
{ |
||||
if(!bNavig) |
||||
{ |
||||
generateThumbnails(); |
||||
if(NULL != mCrntItem) |
||||
{ |
||||
mCrntItem->setSelected(true); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Put the element in the right place in the scene. |
||||
*/ |
||||
void UBDocumentNavigator::refreshScene() |
||||
{ |
||||
qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio; |
||||
|
||||
for(int i = 0; i < mThumbsWithLabels.size(); i++) |
||||
{ |
||||
// Get the item
|
||||
UBImgTextThumbnailElement& item = mThumbsWithLabels[i]; |
||||
int columnIndex = i % mNbColumns; |
||||
int rowIndex = i / mNbColumns; |
||||
item.Place(rowIndex, columnIndex, mThumbnailWidth, thumbnailHeight); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the number of thumbnails columns |
||||
* @param nbColumns as the number of columns |
||||
*/ |
||||
void UBDocumentNavigator::setNbColumns(int nbColumns) |
||||
{ |
||||
mNbColumns = nbColumns; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the number of columns |
||||
* @return the number of thumbnails columns |
||||
*/ |
||||
int UBDocumentNavigator::nbColumns() |
||||
{ |
||||
return mNbColumns; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the thumbnails minimum width |
||||
* @param width as the minimum width |
||||
*/ |
||||
void UBDocumentNavigator::setThumbnailMinWidth(int width) |
||||
{ |
||||
mThumbnailMinWidth = width; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the thumbnails minimum width |
||||
* @return the minimum thumbnails width |
||||
*/ |
||||
int UBDocumentNavigator::thumbnailMinWidth() |
||||
{ |
||||
return mThumbnailMinWidth; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the border size |
||||
* @return the border size in pixels |
||||
*/ |
||||
int UBDocumentNavigator::border() |
||||
{ |
||||
return 20; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the resize event |
||||
* @param event as the resize event |
||||
*/ |
||||
void UBDocumentNavigator::resizeEvent(QResizeEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
// Update the thumbnails width
|
||||
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; |
||||
|
||||
// Refresh the scene
|
||||
refreshScene(); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the mouse press event |
||||
* @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); |
||||
} |
||||
} |
||||
} |
||||
/*
|
||||
* 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 <QList> |
||||
#include <QPointF> |
||||
#include <QPixmap> |
||||
#include <QTransform> |
||||
#include <QScrollBar> |
||||
#include <QFontMetrics> |
||||
#include <QGraphicsItem> |
||||
#include <QGraphicsPixmapItem> |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "UBDocumentNavigator.h" |
||||
#include "board/UBBoardController.h" |
||||
#include "adaptors/UBThumbnailAdaptor.h" |
||||
#include "adaptors/UBSvgSubsetAdaptor.h" |
||||
#include "document/UBDocumentController.h" |
||||
#include "domain/UBGraphicsScene.h" |
||||
#include "board/UBBoardPaletteManager.h" |
||||
#include "core/UBApplicationController.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGraphicsView(parent) |
||||
, mScene(NULL) |
||||
, mNbColumns(1) |
||||
, mThumbnailWidth(0) |
||||
, mThumbnailMinWidth(100) |
||||
{ |
||||
setObjectName(name); |
||||
mScene = new QGraphicsScene(this); |
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||
setScene(mScene); |
||||
mThumbnailWidth = width() - 2*border(); |
||||
|
||||
setFrameShadow(QFrame::Plain); |
||||
|
||||
connect(UBApplication::boardController, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(generateThumbnails(UBDocumentContainer*))); |
||||
connect(UBApplication::boardController, SIGNAL(documentPageUpdated(int)), this, SLOT(updateSpecificThumbnail(int))); |
||||
connect(UBApplication::boardController, SIGNAL(pageSelectionChanged(int)), this, SLOT(onScrollToSelectedPage(int))); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBDocumentNavigator::~UBDocumentNavigator() |
||||
{ |
||||
if(NULL != mScene) |
||||
{ |
||||
delete mScene; |
||||
mScene = NULL; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Generate the thumbnails |
||||
*/ |
||||
void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source) |
||||
{ |
||||
|
||||
mThumbsWithLabels.clear(); |
||||
foreach(QGraphicsItem* it, mScene->items()) |
||||
{ |
||||
mScene->removeItem(it); |
||||
delete it; |
||||
} |
||||
|
||||
for(int i = 0; i < source->selectedDocument()->pageCount(); i++) |
||||
{ |
||||
const QPixmap* pix = source->pageAt(i); |
||||
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i); |
||||
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(tr("Page %0").arg(UBDocumentContainer::pageFromSceneIndex(i))); |
||||
|
||||
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem); |
||||
thumbWithText.setBorder(border()); |
||||
mThumbsWithLabels.append(thumbWithText); |
||||
|
||||
mScene->addItem(pixmapItem); |
||||
mScene->addItem(labelItem); |
||||
} |
||||
|
||||
// Draw the items
|
||||
refreshScene(); |
||||
} |
||||
|
||||
void UBDocumentNavigator::onScrollToSelectedPage(int index) |
||||
{ |
||||
qDebug() << "Selection in widet: " << index; |
||||
int c = 0; |
||||
foreach(UBImgTextThumbnailElement el, mThumbsWithLabels) |
||||
{ |
||||
if (c==index) |
||||
{ |
||||
el.getThumbnail()->setSelected(true); |
||||
} |
||||
else |
||||
{ |
||||
el.getThumbnail()->setSelected(false); |
||||
} |
||||
c++; |
||||
} |
||||
centerOn(mThumbsWithLabels[index].getThumbnail()); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Refresh the given thumbnail |
||||
* @param iPage as the given page related thumbnail |
||||
*/ |
||||
void UBDocumentNavigator::updateSpecificThumbnail(int iPage) |
||||
{ |
||||
// Generate the new thumbnail
|
||||
//UBGraphicsScene* pScene = UBApplication::boardController->activeScene();
|
||||
|
||||
const QPixmap* pix = UBApplication::boardController->pageAt(iPage); |
||||
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix,
|
||||
UBApplication::boardController->selectedDocument(), iPage); |
||||
|
||||
// Get the old thumbnail
|
||||
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail(); |
||||
if(NULL != oldItem) |
||||
{ |
||||
mScene->removeItem(oldItem); |
||||
mScene->addItem(newItem); |
||||
mThumbsWithLabels[iPage].setThumbnail(newItem); |
||||
delete oldItem; |
||||
} |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* \brief Put the element in the right place in the scene. |
||||
*/ |
||||
void UBDocumentNavigator::refreshScene() |
||||
{ |
||||
qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio; |
||||
|
||||
for(int i = 0; i < mThumbsWithLabels.size(); i++) |
||||
{ |
||||
// Get the item
|
||||
UBImgTextThumbnailElement& item = mThumbsWithLabels[i]; |
||||
int columnIndex = i % mNbColumns; |
||||
int rowIndex = i / mNbColumns; |
||||
item.Place(rowIndex, columnIndex, mThumbnailWidth, thumbnailHeight); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the number of thumbnails columns |
||||
* @param nbColumns as the number of columns |
||||
*/ |
||||
void UBDocumentNavigator::setNbColumns(int nbColumns) |
||||
{ |
||||
mNbColumns = nbColumns; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the number of columns |
||||
* @return the number of thumbnails columns |
||||
*/ |
||||
int UBDocumentNavigator::nbColumns() |
||||
{ |
||||
return mNbColumns; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the thumbnails minimum width |
||||
* @param width as the minimum width |
||||
*/ |
||||
void UBDocumentNavigator::setThumbnailMinWidth(int width) |
||||
{ |
||||
mThumbnailMinWidth = width; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the thumbnails minimum width |
||||
* @return the minimum thumbnails width |
||||
*/ |
||||
int UBDocumentNavigator::thumbnailMinWidth() |
||||
{ |
||||
return mThumbnailMinWidth; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Get the border size |
||||
* @return the border size in pixels |
||||
*/ |
||||
int UBDocumentNavigator::border() |
||||
{ |
||||
return 20; |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the resize event |
||||
* @param event as the resize event |
||||
*/ |
||||
void UBDocumentNavigator::resizeEvent(QResizeEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
// Update the thumbnails width
|
||||
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; |
||||
|
||||
// Refresh the scene
|
||||
refreshScene(); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the mouse press event |
||||
* @param event as the mouse event |
||||
*/ |
||||
void UBDocumentNavigator::mousePressEvent(QMouseEvent *event) |
||||
{ |
||||
QGraphicsItem* pClickedItem = itemAt(event->pos()); |
||||
if(NULL != pClickedItem) |
||||
{ |
||||
|
||||
// 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 = el.getThumbnail(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
int index = 0; |
||||
for(int i = 0; i < mThumbsWithLabels.size(); i++) |
||||
{ |
||||
if (mThumbsWithLabels.at(i).getThumbnail() == pCrntItem) |
||||
{ |
||||
index = i; |
||||
break; |
||||
} |
||||
} |
||||
qDebug() << "Selected Scene: " << index; |
||||
UBApplication::boardController->setActiveDocumentScene(index); |
||||
} |
||||
QGraphicsView::mousePressEvent(event); |
||||
} |
||||
|
||||
void UBDocumentNavigator::mouseReleaseEvent(QMouseEvent *event) |
||||
{ |
||||
event->accept(); |
||||
} |
@ -1,84 +1,72 @@ |
||||
/*
|
||||
* 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 2 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 UBDOCUMENTNAVIGATOR_H |
||||
#define UBDOCUMENTNAVIGATOR_H |
||||
|
||||
#include <QResizeEvent> |
||||
#include <QGraphicsView> |
||||
#include <QGraphicsScene> |
||||
#include <QMouseEvent> |
||||
#include <QThread> |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
#include "UBThumbnailWidget.h" |
||||
|
||||
#define NO_PAGESELECTED -1 |
||||
|
||||
class UBDocumentNavigator : public QGraphicsView |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBDocumentNavigator(QWidget* parent=0, const char* name="documentNavigator"); |
||||
~UBDocumentNavigator(); |
||||
|
||||
void setDocument(UBDocumentProxy* document); |
||||
void setNbColumns(int nbColumns); |
||||
int nbColumns(); |
||||
void setThumbnailMinWidth(int width); |
||||
int thumbnailMinWidth(); |
||||
int selectedPageNumber(); |
||||
UBDocumentProxy* currentDoc(); |
||||
|
||||
signals: |
||||
void changeCurrentPage(); |
||||
|
||||
public slots: |
||||
void onMovedToIndex(int index); |
||||
void onScrollToSelectedPage() { centerOn(mCrntItem); } |
||||
|
||||
protected: |
||||
virtual void resizeEvent(QResizeEvent *event); |
||||
virtual void mousePressEvent(QMouseEvent *event); |
||||
|
||||
private slots: |
||||
void addNewPage(); |
||||
void onSelectionChanged(); |
||||
void generateThumbnails(); |
||||
|
||||
private: |
||||
void refreshScene(); |
||||
void updateSpecificThumbnail(int iPage); |
||||
int border(); |
||||
|
||||
|
||||
/** The scene */ |
||||
QGraphicsScene* mScene; |
||||
/** The current selected item */ |
||||
UBSceneThumbnailNavigPixmap* mCrntItem; |
||||
/** The current document */ |
||||
UBDocumentProxy* mCrntDoc; |
||||
/** The list of current thumbnails with labels*/ |
||||
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
|
||||
/*
|
||||
* 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 2 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 UBDOCUMENTNAVIGATOR_H |
||||
#define UBDOCUMENTNAVIGATOR_H |
||||
|
||||
#include <QResizeEvent> |
||||
#include <QGraphicsView> |
||||
#include <QGraphicsScene> |
||||
#include <QMouseEvent> |
||||
#include <QThread> |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
#include "document/UBDocumentContainer.h" |
||||
#include "UBThumbnailWidget.h" |
||||
|
||||
#define NO_PAGESELECTED -1 |
||||
|
||||
class UBDocumentNavigator : public QGraphicsView |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBDocumentNavigator(QWidget* parent=0, const char* name="documentNavigator"); |
||||
~UBDocumentNavigator(); |
||||
|
||||
void setNbColumns(int nbColumns); |
||||
int nbColumns(); |
||||
void setThumbnailMinWidth(int width); |
||||
int thumbnailMinWidth(); |
||||
|
||||
public slots: |
||||
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
|
||||
void generateThumbnails(UBDocumentContainer* source); |
||||
void updateSpecificThumbnail(int iPage); |
||||
|
||||
protected: |
||||
virtual void resizeEvent(QResizeEvent *event); |
||||
virtual void mousePressEvent(QMouseEvent *event); |
||||
virtual void mouseReleaseEvent(QMouseEvent *event); |
||||
|
||||
private: |
||||
|
||||
void refreshScene(); |
||||
int border(); |
||||
|
||||
|
||||
/** The scene */ |
||||
QGraphicsScene* mScene; |
||||
/** The current selected item */ |
||||
//UBSceneThumbnailNavigPixmap* mCrntItem;
|
||||
/** The list of current thumbnails with labels*/ |
||||
QList<UBImgTextThumbnailElement> mThumbsWithLabels; |
||||
/** The current number of columns */ |
||||
int mNbColumns; |
||||
/** The current thumbnails width */ |
||||
int mThumbnailWidth; |
||||
/** The current thumbnails minimum width */ |
||||
int mThumbnailMinWidth; |
||||
}; |
||||
|
||||
#endif // UBDOCUMENTNAVIGATOR_H
|
||||
|
@ -1,316 +1,315 @@ |
||||
/*
|
||||
* 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 2 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 "UBDocumentThumbnailWidget.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBMimeData.h" |
||||
#include "core/UBSettings.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
|
||||
UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent) |
||||
: UBThumbnailWidget(parent) |
||||
, mDropCaretRectItem(0) |
||||
, mClosestDropItem(0) |
||||
, mDragEnabled(true) |
||||
, mScrollMagnitude(0) |
||||
{ |
||||
bCanDrag = false; |
||||
mScrollTimer = new QTimer(this); |
||||
connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll())); |
||||
} |
||||
|
||||
|
||||
UBDocumentThumbnailWidget::~UBDocumentThumbnailWidget() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event) |
||||
{ |
||||
if (!dragEnabled()) |
||||
{ |
||||
event->ignore(); |
||||
return; |
||||
} |
||||
|
||||
if (!(event->buttons() & Qt::LeftButton)) |
||||
return; |
||||
|
||||
if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance()) |
||||
return; |
||||
|
||||
QList<QGraphicsItem*> graphicsItems = items(mMousePressPos); |
||||
|
||||
UBSceneThumbnailPixmap* sceneItem = 0; |
||||
|
||||
while (!graphicsItems.isEmpty() && !sceneItem) |
||||
sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst()); |
||||
|
||||
if (sceneItem) |
||||
{ |
||||
int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneItem->sceneIndex()); |
||||
if(pageIndex != 0){ |
||||
QDrag *drag = new QDrag(this); |
||||
QList<UBMimeDataItem> mimeDataItems; |
||||
foreach (QGraphicsItem *item, selectedItems()) |
||||
mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item))); |
||||
|
||||
UBMimeData *mime = new UBMimeData(mimeDataItems); |
||||
drag->setMimeData(mime); |
||||
|
||||
drag->setPixmap(sceneItem->pixmap().scaledToWidth(100)); |
||||
drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2)); |
||||
|
||||
drag->exec(Qt::MoveAction); |
||||
} |
||||
} |
||||
|
||||
UBThumbnailWidget::mouseMoveEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event) |
||||
{ |
||||
if (!event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
event->setDropAction(Qt::IgnoreAction); |
||||
event->ignore(); |
||||
return; |
||||
} |
||||
|
||||
UBThumbnailWidget::dragEnterEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
if (mScrollTimer->isActive()) |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
deleteDropCaret(); |
||||
UBThumbnailWidget::dragLeaveEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::autoScroll() |
||||
{ |
||||
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) |
||||
{ |
||||
QRect boundingFrame = frameRect(); |
||||
//setting up automatic scrolling
|
||||
const int SCROLL_DISTANCE = 16; |
||||
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); |
||||
if(qAbs(bottomDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else if(qAbs(topDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
|
||||
QList<UBSceneThumbnailPixmap*> pixmapItems; |
||||
foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame))) |
||||
{ |
||||
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item); |
||||
if (sceneItem) |
||||
pixmapItems.append(sceneItem); |
||||
} |
||||
|
||||
int minDistance = 0; |
||||
QGraphicsItem *underlyingItem = itemAt(event->pos()); |
||||
mClosestDropItem = dynamic_cast<UBSceneThumbnailPixmap*>(underlyingItem); |
||||
|
||||
int pageIndex = -1; |
||||
if(mClosestDropItem){ |
||||
pageIndex = UBApplication::boardController->pageFromSceneIndex(mClosestDropItem->sceneIndex()); |
||||
if(pageIndex == 0){ |
||||
event->acceptProposedAction(); |
||||
return; |
||||
} |
||||
} |
||||
if (!mClosestDropItem) |
||||
{ |
||||
foreach (UBSceneThumbnailPixmap *item, pixmapItems) |
||||
{ |
||||
qreal scale = item->transform().m11(); |
||||
QPointF itemCenter( |
||||
item->pos().x() + item->boundingRect().width() * scale / 2, |
||||
item->pos().y() + item->boundingRect().height() * scale / 2); |
||||
|
||||
int distance = (itemCenter.toPoint() - mapToScene(event->pos()).toPoint()).manhattanLength(); |
||||
if (!mClosestDropItem || distance < minDistance) |
||||
{ |
||||
mClosestDropItem = item; |
||||
minDistance = distance; |
||||
pageIndex = UBApplication::boardController->pageFromSceneIndex(mClosestDropItem->sceneIndex()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (mClosestDropItem && pageIndex != 0) |
||||
{ |
||||
qreal scale = mClosestDropItem->transform().m11(); |
||||
|
||||
QPointF itemCenter( |
||||
mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale / 2, |
||||
mClosestDropItem->pos().y() + mClosestDropItem->boundingRect().height() * scale / 2); |
||||
|
||||
mDropIsRight = mapToScene(event->pos()).x() > itemCenter.x(); |
||||
|
||||
if (!mDropCaretRectItem && selectedItems().count() < mGraphicItems.count()) |
||||
{ |
||||
mDropCaretRectItem = new QGraphicsRectItem(0, scene()); |
||||
mDropCaretRectItem->setPen(QPen(Qt::darkGray)); |
||||
mDropCaretRectItem->setBrush(QBrush(Qt::lightGray)); |
||||
} |
||||
|
||||
QRectF dropCaretRect( |
||||
mDropIsRight ? mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale + spacing() / 2 - 1 : mClosestDropItem->pos().x() - spacing() / 2 - 1, |
||||
mClosestDropItem->pos().y(), |
||||
3, |
||||
mClosestDropItem->boundingRect().height() * scale); |
||||
|
||||
if (mDropCaretRectItem) |
||||
mDropCaretRectItem->setRect(dropCaretRect); |
||||
} |
||||
|
||||
event->acceptProposedAction(); |
||||
} |
||||
|
||||
|
||||
void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) |
||||
{ |
||||
if (mScrollTimer->isActive()) |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
deleteDropCaret(); |
||||
|
||||
if (mClosestDropItem) |
||||
{ |
||||
int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem); |
||||
if(UBApplication::boardController->pageFromSceneIndex(targetIndex) == 0){ |
||||
event->ignore(); |
||||
return; |
||||
} |
||||
|
||||
QList<UBMimeDataItem> mimeDataItems; |
||||
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
const UBMimeData* mimeData = qobject_cast<const UBMimeData*>(event->mimeData()); |
||||
if (mimeData) |
||||
mimeDataItems = mimeData->items(); |
||||
} |
||||
|
||||
if (1 == mimeDataItems.count() && |
||||
(mimeDataItems.at(0).sceneIndex() == mGraphicItems.indexOf(mClosestDropItem) || |
||||
targetIndex == mimeDataItems.at(0).sceneIndex() || |
||||
targetIndex == mimeDataItems.at(0).sceneIndex() + 1)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
int sourceIndexOffset = 0; |
||||
int actualTargetIndex = targetIndex; |
||||
for (int i = mimeDataItems.count() - 1; i >= 0; i--) |
||||
{ |
||||
UBMimeDataItem sourceItem = mimeDataItems.at(i); |
||||
int actualSourceIndex = sourceItem.sceneIndex(); |
||||
if (sourceItem.sceneIndex() >= targetIndex) |
||||
actualSourceIndex += sourceIndexOffset; |
||||
|
||||
//event->acceptProposedAction();
|
||||
if (sourceItem.sceneIndex() < targetIndex) |
||||
{ |
||||
if (actualSourceIndex != actualTargetIndex - 1) |
||||
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex - 1); |
||||
actualTargetIndex -= 1; |
||||
} |
||||
else |
||||
{ |
||||
if (actualSourceIndex != actualTargetIndex) |
||||
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex); |
||||
sourceIndexOffset += 1; |
||||
} |
||||
} |
||||
} |
||||
UBThumbnailWidget::dropEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::deleteDropCaret() |
||||
{ |
||||
if (mDropCaretRectItem && scene()) |
||||
{ |
||||
scene()->removeItem(mDropCaretRectItem); |
||||
delete mDropCaretRectItem; |
||||
mDropCaretRectItem = 0; |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, |
||||
const QList<QUrl>& pItemPaths, const QStringList pLabels, |
||||
const QString& pMimeType) |
||||
{ |
||||
deleteDropCaret(); |
||||
|
||||
UBThumbnailWidget::setGraphicsItems(pGraphicsItems, pItemPaths, pLabels, pMimeType); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::setDragEnabled(bool enabled) |
||||
{ |
||||
mDragEnabled = enabled; |
||||
} |
||||
|
||||
bool UBDocumentThumbnailWidget::dragEnabled() const |
||||
{ |
||||
return mDragEnabled; |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::hightlightItem(int index) |
||||
{ |
||||
if (0 <= index && index < mLabelsItems.length()) |
||||
{ |
||||
mLabelsItems.at(index)->highlight(); |
||||
} |
||||
if (0 <= index && index < mGraphicItems.length()) |
||||
{ |
||||
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(index)); |
||||
if (thumbnail) |
||||
thumbnail->highlight(); |
||||
} |
||||
|
||||
selectItemAt(index); |
||||
} |
||||
/*
|
||||
* 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 2 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 "UBDocumentThumbnailWidget.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBMimeData.h" |
||||
#include "core/UBSettings.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
|
||||
UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent) |
||||
: UBThumbnailWidget(parent) |
||||
, mDropCaretRectItem(0) |
||||
, mClosestDropItem(0) |
||||
, mDragEnabled(true) |
||||
, mScrollMagnitude(0) |
||||
{ |
||||
bCanDrag = false; |
||||
mScrollTimer = new QTimer(this); |
||||
connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll())); |
||||
} |
||||
|
||||
|
||||
UBDocumentThumbnailWidget::~UBDocumentThumbnailWidget() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event) |
||||
{ |
||||
if (!dragEnabled()) |
||||
{ |
||||
event->ignore(); |
||||
return; |
||||
} |
||||
|
||||
if (!(event->buttons() & Qt::LeftButton)) |
||||
return; |
||||
|
||||
if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance()) |
||||
return; |
||||
|
||||
QList<QGraphicsItem*> graphicsItems = items(mMousePressPos); |
||||
|
||||
UBSceneThumbnailPixmap* sceneItem = 0; |
||||
|
||||
while (!graphicsItems.isEmpty() && !sceneItem) |
||||
sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst()); |
||||
|
||||
if (sceneItem) |
||||
{ |
||||
int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex()); |
||||
if(pageIndex != 0){ |
||||
QDrag *drag = new QDrag(this); |
||||
QList<UBMimeDataItem> mimeDataItems; |
||||
foreach (QGraphicsItem *item, selectedItems()) |
||||
mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item))); |
||||
|
||||
UBMimeData *mime = new UBMimeData(mimeDataItems); |
||||
drag->setMimeData(mime); |
||||
|
||||
drag->setPixmap(sceneItem->pixmap().scaledToWidth(100)); |
||||
drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2)); |
||||
|
||||
drag->exec(Qt::MoveAction); |
||||
} |
||||
} |
||||
|
||||
UBThumbnailWidget::mouseMoveEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event) |
||||
{ |
||||
if (!event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
event->setDropAction(Qt::IgnoreAction); |
||||
event->ignore(); |
||||
return; |
||||
} |
||||
|
||||
UBThumbnailWidget::dragEnterEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
if (mScrollTimer->isActive()) |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
deleteDropCaret(); |
||||
UBThumbnailWidget::dragLeaveEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::autoScroll() |
||||
{ |
||||
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) |
||||
{ |
||||
QRect boundingFrame = frameRect(); |
||||
//setting up automatic scrolling
|
||||
const int SCROLL_DISTANCE = 16; |
||||
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); |
||||
if(qAbs(bottomDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else if(qAbs(topDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
|
||||
QList<UBSceneThumbnailPixmap*> pixmapItems; |
||||
foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame))) |
||||
{ |
||||
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item); |
||||
if (sceneItem) |
||||
pixmapItems.append(sceneItem); |
||||
} |
||||
|
||||
int minDistance = 0; |
||||
QGraphicsItem *underlyingItem = itemAt(event->pos()); |
||||
mClosestDropItem = dynamic_cast<UBSceneThumbnailPixmap*>(underlyingItem); |
||||
|
||||
int pageIndex = -1; |
||||
if(mClosestDropItem){ |
||||
pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex()); |
||||
if(pageIndex == 0){ |
||||
event->acceptProposedAction(); |
||||
return; |
||||
} |
||||
} |
||||
if (!mClosestDropItem) |
||||
{ |
||||
foreach (UBSceneThumbnailPixmap *item, pixmapItems) |
||||
{ |
||||
qreal scale = item->transform().m11(); |
||||
QPointF itemCenter( |
||||
item->pos().x() + item->boundingRect().width() * scale / 2, |
||||
item->pos().y() + item->boundingRect().height() * scale / 2); |
||||
|
||||
int distance = (itemCenter.toPoint() - mapToScene(event->pos()).toPoint()).manhattanLength(); |
||||
if (!mClosestDropItem || distance < minDistance) |
||||
{ |
||||
mClosestDropItem = item; |
||||
minDistance = distance; |
||||
pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (mClosestDropItem && pageIndex != 0) |
||||
{ |
||||
qreal scale = mClosestDropItem->transform().m11(); |
||||
|
||||
QPointF itemCenter( |
||||
mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale / 2, |
||||
mClosestDropItem->pos().y() + mClosestDropItem->boundingRect().height() * scale / 2); |
||||
|
||||
mDropIsRight = mapToScene(event->pos()).x() > itemCenter.x(); |
||||
|
||||
if (!mDropCaretRectItem && selectedItems().count() < mGraphicItems.count()) |
||||
{ |
||||
mDropCaretRectItem = new QGraphicsRectItem(0, scene()); |
||||
mDropCaretRectItem->setPen(QPen(Qt::darkGray)); |
||||
mDropCaretRectItem->setBrush(QBrush(Qt::lightGray)); |
||||
} |
||||
|
||||
QRectF dropCaretRect( |
||||
mDropIsRight ? mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale + spacing() / 2 - 1 : mClosestDropItem->pos().x() - spacing() / 2 - 1, |
||||
mClosestDropItem->pos().y(), |
||||
3, |
||||
mClosestDropItem->boundingRect().height() * scale); |
||||
|
||||
if (mDropCaretRectItem) |
||||
mDropCaretRectItem->setRect(dropCaretRect); |
||||
} |
||||
|
||||
event->acceptProposedAction(); |
||||
} |
||||
|
||||
|
||||
void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) |
||||
{ |
||||
if (mScrollTimer->isActive()) |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
deleteDropCaret(); |
||||
|
||||
if (mClosestDropItem) |
||||
{ |
||||
int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem); |
||||
if(UBDocumentContainer::pageFromSceneIndex(targetIndex) == 0){ |
||||
event->ignore(); |
||||
return; |
||||
} |
||||
|
||||
QList<UBMimeDataItem> mimeDataItems; |
||||
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
const UBMimeData* mimeData = qobject_cast<const UBMimeData*>(event->mimeData()); |
||||
if (mimeData) |
||||
mimeDataItems = mimeData->items(); |
||||
} |
||||
|
||||
if (1 == mimeDataItems.count() && |
||||
(mimeDataItems.at(0).sceneIndex() == mGraphicItems.indexOf(mClosestDropItem) || |
||||
targetIndex == mimeDataItems.at(0).sceneIndex() || |
||||
targetIndex == mimeDataItems.at(0).sceneIndex() + 1)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
int sourceIndexOffset = 0; |
||||
int actualTargetIndex = targetIndex; |
||||
for (int i = mimeDataItems.count() - 1; i >= 0; i--) |
||||
{ |
||||
UBMimeDataItem sourceItem = mimeDataItems.at(i); |
||||
int actualSourceIndex = sourceItem.sceneIndex(); |
||||
if (sourceItem.sceneIndex() >= targetIndex) |
||||
actualSourceIndex += sourceIndexOffset; |
||||
|
||||
//event->acceptProposedAction();
|
||||
if (sourceItem.sceneIndex() < targetIndex) |
||||
{ |
||||
if (actualSourceIndex != actualTargetIndex - 1) |
||||
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex - 1); |
||||
actualTargetIndex -= 1; |
||||
} |
||||
else |
||||
{ |
||||
if (actualSourceIndex != actualTargetIndex) |
||||
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex); |
||||
sourceIndexOffset += 1; |
||||
} |
||||
} |
||||
} |
||||
UBThumbnailWidget::dropEvent(event); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::deleteDropCaret() |
||||
{ |
||||
if (mDropCaretRectItem && scene()) |
||||
{ |
||||
scene()->removeItem(mDropCaretRectItem); |
||||
delete mDropCaretRectItem; |
||||
mDropCaretRectItem = 0; |
||||
} |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, |
||||
const QList<QUrl>& pItemPaths, const QStringList pLabels, |
||||
const QString& pMimeType) |
||||
{ |
||||
deleteDropCaret(); |
||||
|
||||
UBThumbnailWidget::setGraphicsItems(pGraphicsItems, pItemPaths, pLabels, pMimeType); |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::setDragEnabled(bool enabled) |
||||
{ |
||||
mDragEnabled = enabled; |
||||
} |
||||
|
||||
bool UBDocumentThumbnailWidget::dragEnabled() const |
||||
{ |
||||
return mDragEnabled; |
||||
} |
||||
|
||||
void UBDocumentThumbnailWidget::hightlightItem(int index) |
||||
{ |
||||
if (0 <= index && index < mLabelsItems.length()) |
||||
{ |
||||
mLabelsItems.at(index)->highlight(); |
||||
} |
||||
if (0 <= index && index < mGraphicItems.length()) |
||||
{ |
||||
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(index)); |
||||
if (thumbnail) |
||||
thumbnail->highlight(); |
||||
} |
||||
|
||||
selectItemAt(index); |
||||
} |
||||
|
@ -1,455 +1,457 @@ |
||||
/*
|
||||
* 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 2 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 "UBDocumentTreeWidget.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "core/UBSettings.h" |
||||
#include "core/UBApplication.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBMimeData.h" |
||||
#include "core/UBApplicationController.h" |
||||
#include "core/UBDocumentManager.h" |
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include "adaptors/UBThumbnailAdaptor.h" |
||||
#include "adaptors/UBSvgSubsetAdaptor.h" |
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent) |
||||
: QTreeWidget(parent) |
||||
, mSelectedProxyTi(0) |
||||
, mDropTargetProxyTi(0) |
||||
{ |
||||
setDragDropMode(QAbstractItemView::InternalMove); |
||||
setAutoScroll(true); |
||||
|
||||
mScrollTimer = new QTimer(this); |
||||
connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*)) |
||||
, this, SLOT(documentUpdated(UBDocumentProxy*))); |
||||
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)) |
||||
, this, SLOT(itemChangedValidation(QTreeWidgetItem *, int))); |
||||
connect(mScrollTimer, SIGNAL(timeout()) |
||||
, this, SLOT(autoScroll())); |
||||
} |
||||
|
||||
|
||||
UBDocumentTreeWidget::~UBDocumentTreeWidget() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int column) |
||||
{ |
||||
if (column == 0) |
||||
{ |
||||
UBDocumentGroupTreeItem *group = dynamic_cast< UBDocumentGroupTreeItem *>(item); |
||||
|
||||
if (group) |
||||
{ |
||||
QString name = group->text(0); |
||||
|
||||
for(int i = 0; i < topLevelItemCount (); i++) |
||||
{ |
||||
QTreeWidgetItem *someTopLevelItem = topLevelItem(i); |
||||
|
||||
if (someTopLevelItem != group && |
||||
someTopLevelItem->text(0) == name) |
||||
{ |
||||
group->setText(0, tr("%1 (copy)").arg(name)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
Qt::DropActions UBDocumentTreeWidget::supportedDropActions() const |
||||
{ |
||||
return Qt::MoveAction | Qt::CopyAction; |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::mousePressEvent(QMouseEvent *event) |
||||
{ |
||||
QTreeWidgetItem* twItem = this->itemAt(event->pos()); |
||||
|
||||
mSelectedProxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(twItem); |
||||
|
||||
QTreeWidget::mousePressEvent(event); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dragEnterEvent(QDragEnterEvent *event) |
||||
{ |
||||
event->acceptProposedAction(); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
if (mScrollTimer->isActive()) |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
|
||||
if (mDropTargetProxyTi) |
||||
{ |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = 0; |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event) |
||||
{ |
||||
QRect boundingFrame = frameRect(); |
||||
//setting up automatic scrolling
|
||||
const int SCROLL_DISTANCE = 4; |
||||
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); |
||||
if(qAbs(bottomDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else if(qAbs(topDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
|
||||
|
||||
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); |
||||
|
||||
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingItem); |
||||
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi) |
||||
{ |
||||
event->setDropAction(Qt::CopyAction); |
||||
event->accept(); |
||||
} |
||||
else |
||||
{ |
||||
event->ignore(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem); |
||||
|
||||
if (groupItem && mSelectedProxyTi && groupItem != mSelectedProxyTi->parent()) |
||||
event->acceptProposedAction(); |
||||
else |
||||
event->ignore(); |
||||
} |
||||
|
||||
if (event->isAccepted()) |
||||
{ |
||||
if (mDropTargetProxyTi) |
||||
{ |
||||
if (underlyingItem != mDropTargetProxyTi) |
||||
{ |
||||
mBackground = underlyingItem->background(0); |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = underlyingItem; |
||||
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5"))); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
mBackground = underlyingItem->background(0); |
||||
mDropTargetProxyTi = underlyingItem; |
||||
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5"))); |
||||
} |
||||
} |
||||
else if (mDropTargetProxyTi) |
||||
{ |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = 0; |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::focusInEvent(QFocusEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
itemSelectionChanged(); |
||||
QTreeWidget::focusInEvent(event); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dropEvent(QDropEvent *event) |
||||
{ |
||||
if (mDropTargetProxyTi) |
||||
{ |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = 0; |
||||
} |
||||
|
||||
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); |
||||
|
||||
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem); |
||||
|
||||
if (groupItem && mSelectedProxyTi && mSelectedProxyTi->proxy()) |
||||
{ |
||||
UBDocumentGroupTreeItem *sourceGroupItem = dynamic_cast<UBDocumentGroupTreeItem*>(mSelectedProxyTi->parent()); |
||||
bool isTrashItem = sourceGroupItem && sourceGroupItem->isTrashFolder(); |
||||
if ((isTrashItem && !groupItem->isTrashFolder()) || |
||||
(!isTrashItem && mSelectedProxyTi->proxy()->groupName() != groupItem->groupName())) |
||||
{ |
||||
QString groupName; |
||||
if (groupItem->isTrashFolder()) |
||||
{ |
||||
QString oldGroupName = mSelectedProxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); |
||||
groupName = UBSettings::trashedDocumentGroupNamePrefix + oldGroupName; |
||||
} |
||||
else |
||||
{ |
||||
if (groupItem->groupName() == UBSettings::defaultDocumentGroupName) |
||||
groupName = ""; |
||||
else |
||||
groupName = groupItem->groupName(); |
||||
} |
||||
mSelectedProxyTi->proxy()->setMetaData(UBSettings::documentGroupName, groupName); |
||||
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mSelectedProxyTi->proxy()); |
||||
|
||||
mSelectedProxyTi->parent()->removeChild(mSelectedProxyTi); |
||||
|
||||
int i = 0; |
||||
for (i = 0; i < groupItem->childCount(); i++) |
||||
{ |
||||
QTreeWidgetItem *ti = groupItem->child(i); |
||||
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); |
||||
if (pi) |
||||
{ |
||||
if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
groupItem->insertChild(i, mSelectedProxyTi); |
||||
|
||||
if (isTrashItem) |
||||
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() | Qt::ItemIsEditable); |
||||
|
||||
if (groupItem->isTrashFolder()) |
||||
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() ^ Qt::ItemIsEditable); |
||||
|
||||
//clearSelection();
|
||||
expandItem(groupItem); |
||||
scrollToItem(mSelectedProxyTi); |
||||
|
||||
// disabled, as those 2 calls are buggy on windows, the item disappears if we selected them
|
||||
//
|
||||
setCurrentItem(mSelectedProxyTi); |
||||
mSelectedProxyTi->setSelected(true); |
||||
|
||||
event->setDropAction(Qt::IgnoreAction); |
||||
event->accept(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
QTreeWidgetItem* underlyingTreeItem = this->itemAt(event->pos()); |
||||
|
||||
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingTreeItem); |
||||
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi) |
||||
{ |
||||
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
event->setDropAction(Qt::CopyAction); |
||||
event->accept(); |
||||
|
||||
const UBMimeData *mimeData = qobject_cast <const UBMimeData*>(event->mimeData()); |
||||
|
||||
if (mimeData && mimeData->items().size() > 0) |
||||
{ |
||||
int count = 0; |
||||
int total = mimeData->items().size(); |
||||
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||||
|
||||
foreach (UBMimeDataItem sourceItem, mimeData->items()) |
||||
{ |
||||
count++; |
||||
|
||||
UBApplication::applicationController->showMessage(tr("Copying page %1/%2").arg(count).arg(total), true); |
||||
|
||||
// TODO UB 4.x Move following code to some controller class
|
||||
UBGraphicsScene *scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(sourceItem.documentProxy(), sourceItem.sceneIndex()); |
||||
if (scene) |
||||
{ |
||||
UBGraphicsScene* sceneClone = scene->sceneDeepCopy(); |
||||
|
||||
UBDocumentProxy *targetDocProxy = targetProxyTreeItem->proxy(); |
||||
|
||||
foreach (QUrl relativeFile, scene->relativeDependencies()) |
||||
{ |
||||
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString(); |
||||
QString target = targetDocProxy->persistencePath() + "/" + relativeFile.toString(); |
||||
|
||||
QFileInfo fi(target); |
||||
QDir d = fi.dir(); |
||||
|
||||
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
|
||||
//it's not universal and good way but it's faster
|
||||
QString from = sourceItem.documentProxy()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceItem.sceneIndex()); |
||||
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); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
event->setDropAction(Qt::IgnoreAction); |
||||
event->ignore(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument) |
||||
{ |
||||
UBDocumentProxyTreeItem *treeItem = UBApplication::documentController->findDocument(pDocument); |
||||
if (treeItem) |
||||
{ |
||||
QTreeWidgetItem * parent = treeItem->parent(); |
||||
|
||||
if (parent) |
||||
{ |
||||
for (int i = 0; i < parent->indexOfChild(treeItem); i++) |
||||
{ |
||||
QTreeWidgetItem *ti = parent->child(i); |
||||
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); |
||||
if (pi) |
||||
{ |
||||
if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) |
||||
{ |
||||
bool selected = treeItem->isSelected(); |
||||
parent->removeChild(treeItem); |
||||
parent->insertChild(i, treeItem); |
||||
for (int j = 0; j < selectedItems().count(); j++) |
||||
selectedItems().at(j)->setSelected(false); |
||||
if (selected) |
||||
treeItem->setSelected(true); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDocumentProxy* proxy, bool isEditable) |
||||
: QTreeWidgetItem() |
||||
, mProxy(proxy) |
||||
{ |
||||
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled; |
||||
|
||||
if (isEditable) |
||||
flags |= Qt::ItemIsEditable; |
||||
|
||||
setFlags(flags); |
||||
|
||||
int i = 0; |
||||
for (i = 0; i < parent->childCount(); i++) |
||||
{ |
||||
QTreeWidgetItem *ti = parent->child(i); |
||||
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); |
||||
if (pi) |
||||
{ |
||||
if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
parent->insertChild(i, this); |
||||
} |
||||
|
||||
|
||||
UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable) |
||||
: QTreeWidgetItem(parent) |
||||
{ |
||||
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; |
||||
if (isEditable) |
||||
flags |= Qt::ItemIsEditable; |
||||
setFlags(flags); |
||||
} |
||||
|
||||
|
||||
UBDocumentGroupTreeItem::~UBDocumentGroupTreeItem() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBDocumentGroupTreeItem::setGroupName(const QString& groupName) |
||||
{ |
||||
setText(0, groupName); |
||||
} |
||||
|
||||
|
||||
QString UBDocumentGroupTreeItem::groupName() const |
||||
{ |
||||
return text(0); |
||||
} |
||||
|
||||
|
||||
bool UBDocumentGroupTreeItem::isTrashFolder() const |
||||
{ |
||||
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::documentTrashGroupName); |
||||
} |
||||
|
||||
bool UBDocumentGroupTreeItem::isDefaultFolder() const |
||||
{ |
||||
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::defaultDocumentGroupName); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::autoScroll() |
||||
{ |
||||
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); |
||||
} |
||||
/*
|
||||
* 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 2 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 "UBDocumentTreeWidget.h" |
||||
|
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "core/UBSettings.h" |
||||
#include "core/UBApplication.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
#include "core/UBMimeData.h" |
||||
#include "core/UBApplicationController.h" |
||||
#include "core/UBDocumentManager.h" |
||||
#include "document/UBDocumentController.h" |
||||
|
||||
#include "adaptors/UBThumbnailAdaptor.h" |
||||
#include "adaptors/UBSvgSubsetAdaptor.h" |
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent) |
||||
: QTreeWidget(parent) |
||||
, mSelectedProxyTi(0) |
||||
, mDropTargetProxyTi(0) |
||||
{ |
||||
setDragDropMode(QAbstractItemView::InternalMove); |
||||
setAutoScroll(true); |
||||
|
||||
mScrollTimer = new QTimer(this); |
||||
connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*)) |
||||
, this, SLOT(documentUpdated(UBDocumentProxy*))); |
||||
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)) |
||||
, this, SLOT(itemChangedValidation(QTreeWidgetItem *, int))); |
||||
connect(mScrollTimer, SIGNAL(timeout()) |
||||
, this, SLOT(autoScroll())); |
||||
} |
||||
|
||||
|
||||
UBDocumentTreeWidget::~UBDocumentTreeWidget() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int column) |
||||
{ |
||||
if (column == 0) |
||||
{ |
||||
UBDocumentGroupTreeItem *group = dynamic_cast< UBDocumentGroupTreeItem *>(item); |
||||
|
||||
if (group) |
||||
{ |
||||
QString name = group->text(0); |
||||
|
||||
for(int i = 0; i < topLevelItemCount (); i++) |
||||
{ |
||||
QTreeWidgetItem *someTopLevelItem = topLevelItem(i); |
||||
|
||||
if (someTopLevelItem != group && |
||||
someTopLevelItem->text(0) == name) |
||||
{ |
||||
group->setText(0, tr("%1 (copy)").arg(name)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
Qt::DropActions UBDocumentTreeWidget::supportedDropActions() const |
||||
{ |
||||
return Qt::MoveAction | Qt::CopyAction; |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::mousePressEvent(QMouseEvent *event) |
||||
{ |
||||
QTreeWidgetItem* twItem = this->itemAt(event->pos()); |
||||
|
||||
mSelectedProxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(twItem); |
||||
|
||||
QTreeWidget::mousePressEvent(event); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dragEnterEvent(QDragEnterEvent *event) |
||||
{ |
||||
event->acceptProposedAction(); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
if (mScrollTimer->isActive()) |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
|
||||
if (mDropTargetProxyTi) |
||||
{ |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = 0; |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event) |
||||
{ |
||||
QRect boundingFrame = frameRect(); |
||||
//setting up automatic scrolling
|
||||
const int SCROLL_DISTANCE = 4; |
||||
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); |
||||
if(qAbs(bottomDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else if(qAbs(topDist) <= SCROLL_DISTANCE) |
||||
{ |
||||
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; |
||||
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); |
||||
} |
||||
else |
||||
{ |
||||
mScrollMagnitude = 0; |
||||
mScrollTimer->stop(); |
||||
} |
||||
|
||||
|
||||
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); |
||||
|
||||
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingItem); |
||||
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi) |
||||
{ |
||||
event->setDropAction(Qt::CopyAction); |
||||
event->accept(); |
||||
} |
||||
else |
||||
{ |
||||
event->ignore(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem); |
||||
|
||||
if (groupItem && mSelectedProxyTi && groupItem != mSelectedProxyTi->parent()) |
||||
event->acceptProposedAction(); |
||||
else |
||||
event->ignore(); |
||||
} |
||||
|
||||
if (event->isAccepted()) |
||||
{ |
||||
if (mDropTargetProxyTi) |
||||
{ |
||||
if (underlyingItem != mDropTargetProxyTi) |
||||
{ |
||||
mBackground = underlyingItem->background(0); |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = underlyingItem; |
||||
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5"))); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
mBackground = underlyingItem->background(0); |
||||
mDropTargetProxyTi = underlyingItem; |
||||
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5"))); |
||||
} |
||||
} |
||||
else if (mDropTargetProxyTi) |
||||
{ |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = 0; |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::focusInEvent(QFocusEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
// Tolik
|
||||
//itemSelectionChanged();
|
||||
|
||||
QTreeWidget::focusInEvent(event); |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::dropEvent(QDropEvent *event) |
||||
{ |
||||
if (mDropTargetProxyTi) |
||||
{ |
||||
mDropTargetProxyTi->setBackground(0, mBackground); |
||||
mDropTargetProxyTi = 0; |
||||
} |
||||
|
||||
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); |
||||
|
||||
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem); |
||||
|
||||
if (groupItem && mSelectedProxyTi && mSelectedProxyTi->proxy()) |
||||
{ |
||||
UBDocumentGroupTreeItem *sourceGroupItem = dynamic_cast<UBDocumentGroupTreeItem*>(mSelectedProxyTi->parent()); |
||||
bool isTrashItem = sourceGroupItem && sourceGroupItem->isTrashFolder(); |
||||
if ((isTrashItem && !groupItem->isTrashFolder()) || |
||||
(!isTrashItem && mSelectedProxyTi->proxy()->groupName() != groupItem->groupName())) |
||||
{ |
||||
QString groupName; |
||||
if (groupItem->isTrashFolder()) |
||||
{ |
||||
QString oldGroupName = mSelectedProxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); |
||||
groupName = UBSettings::trashedDocumentGroupNamePrefix + oldGroupName; |
||||
} |
||||
else |
||||
{ |
||||
if (groupItem->groupName() == UBSettings::defaultDocumentGroupName) |
||||
groupName = ""; |
||||
else |
||||
groupName = groupItem->groupName(); |
||||
} |
||||
mSelectedProxyTi->proxy()->setMetaData(UBSettings::documentGroupName, groupName); |
||||
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mSelectedProxyTi->proxy()); |
||||
|
||||
mSelectedProxyTi->parent()->removeChild(mSelectedProxyTi); |
||||
|
||||
int i = 0; |
||||
for (i = 0; i < groupItem->childCount(); i++) |
||||
{ |
||||
QTreeWidgetItem *ti = groupItem->child(i); |
||||
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); |
||||
if (pi) |
||||
{ |
||||
if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
groupItem->insertChild(i, mSelectedProxyTi); |
||||
|
||||
if (isTrashItem) |
||||
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() | Qt::ItemIsEditable); |
||||
|
||||
if (groupItem->isTrashFolder()) |
||||
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() ^ Qt::ItemIsEditable); |
||||
|
||||
//clearSelection();
|
||||
expandItem(groupItem); |
||||
scrollToItem(mSelectedProxyTi); |
||||
|
||||
// disabled, as those 2 calls are buggy on windows, the item disappears if we selected them
|
||||
//
|
||||
setCurrentItem(mSelectedProxyTi); |
||||
mSelectedProxyTi->setSelected(true); |
||||
|
||||
event->setDropAction(Qt::IgnoreAction); |
||||
event->accept(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
QTreeWidgetItem* underlyingTreeItem = this->itemAt(event->pos()); |
||||
|
||||
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingTreeItem); |
||||
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi) |
||||
{ |
||||
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) |
||||
{ |
||||
event->setDropAction(Qt::CopyAction); |
||||
event->accept(); |
||||
|
||||
const UBMimeData *mimeData = qobject_cast <const UBMimeData*>(event->mimeData()); |
||||
|
||||
if (mimeData && mimeData->items().size() > 0) |
||||
{ |
||||
int count = 0; |
||||
int total = mimeData->items().size(); |
||||
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||||
|
||||
foreach (UBMimeDataItem sourceItem, mimeData->items()) |
||||
{ |
||||
count++; |
||||
|
||||
UBApplication::applicationController->showMessage(tr("Copying page %1/%2").arg(count).arg(total), true); |
||||
|
||||
// TODO UB 4.x Move following code to some controller class
|
||||
UBGraphicsScene *scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(sourceItem.documentProxy(), sourceItem.sceneIndex()); |
||||
if (scene) |
||||
{ |
||||
UBGraphicsScene* sceneClone = scene->sceneDeepCopy(); |
||||
|
||||
UBDocumentProxy *targetDocProxy = targetProxyTreeItem->proxy(); |
||||
|
||||
foreach (QUrl relativeFile, scene->relativeDependencies()) |
||||
{ |
||||
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString(); |
||||
QString target = targetDocProxy->persistencePath() + "/" + relativeFile.toString(); |
||||
|
||||
QFileInfo fi(target); |
||||
QDir d = fi.dir(); |
||||
|
||||
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
|
||||
//it's not universal and good way but it's faster
|
||||
QString from = sourceItem.documentProxy()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceItem.sceneIndex()); |
||||
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); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
event->setDropAction(Qt::IgnoreAction); |
||||
event->ignore(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument) |
||||
{ |
||||
UBDocumentProxyTreeItem *treeItem = UBApplication::documentController->findDocument(pDocument); |
||||
if (treeItem) |
||||
{ |
||||
QTreeWidgetItem * parent = treeItem->parent(); |
||||
|
||||
if (parent) |
||||
{ |
||||
for (int i = 0; i < parent->indexOfChild(treeItem); i++) |
||||
{ |
||||
QTreeWidgetItem *ti = parent->child(i); |
||||
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); |
||||
if (pi) |
||||
{ |
||||
if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) |
||||
{ |
||||
bool selected = treeItem->isSelected(); |
||||
parent->removeChild(treeItem); |
||||
parent->insertChild(i, treeItem); |
||||
for (int j = 0; j < selectedItems().count(); j++) |
||||
selectedItems().at(j)->setSelected(false); |
||||
if (selected) |
||||
treeItem->setSelected(true); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDocumentProxy* proxy, bool isEditable) |
||||
: QTreeWidgetItem() |
||||
, mProxy(proxy) |
||||
{ |
||||
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled; |
||||
|
||||
if (isEditable) |
||||
flags |= Qt::ItemIsEditable; |
||||
|
||||
setFlags(flags); |
||||
|
||||
int i = 0; |
||||
for (i = 0; i < parent->childCount(); i++) |
||||
{ |
||||
QTreeWidgetItem *ti = parent->child(i); |
||||
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); |
||||
if (pi) |
||||
{ |
||||
if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
parent->insertChild(i, this); |
||||
} |
||||
|
||||
|
||||
UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable) |
||||
: QTreeWidgetItem(parent) |
||||
{ |
||||
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; |
||||
if (isEditable) |
||||
flags |= Qt::ItemIsEditable; |
||||
setFlags(flags); |
||||
} |
||||
|
||||
|
||||
UBDocumentGroupTreeItem::~UBDocumentGroupTreeItem() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
void UBDocumentGroupTreeItem::setGroupName(const QString& groupName) |
||||
{ |
||||
setText(0, groupName); |
||||
} |
||||
|
||||
|
||||
QString UBDocumentGroupTreeItem::groupName() const |
||||
{ |
||||
return text(0); |
||||
} |
||||
|
||||
|
||||
bool UBDocumentGroupTreeItem::isTrashFolder() const |
||||
{ |
||||
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::documentTrashGroupName); |
||||
} |
||||
|
||||
bool UBDocumentGroupTreeItem::isDefaultFolder() const |
||||
{ |
||||
return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::defaultDocumentGroupName); |
||||
} |
||||
|
||||
|
||||
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 |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 2 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 "UBNavigatorPalette.h" |
||||
#include "core/UBApplication.h" |
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name): |
||||
UBDockPalette(eUBDockPaletteType_LEFT, parent, name) |
||||
, mNavigator(NULL) |
||||
, mLayout(NULL) |
||||
, mHLayout(NULL) |
||||
, mPageNbr(NULL) |
||||
, mClock(NULL) |
||||
{ |
||||
// Build the gui
|
||||
mLayout = new QVBoxLayout(this); |
||||
mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin()); |
||||
setLayout(mLayout); |
||||
|
||||
mNavigator = new UBDocumentNavigator(this); |
||||
mNavigator->setStyleSheet(QString("background-color : transparent;")); |
||||
mLayout->addWidget(mNavigator, 1); |
||||
|
||||
mHLayout = new QHBoxLayout(); |
||||
mLayout->addLayout(mHLayout, 0); |
||||
|
||||
mPageNbr = new QLabel(this); |
||||
mClock = new QLabel(this); |
||||
mHLayout->addWidget(mPageNbr); |
||||
mHLayout->addWidget(mClock); |
||||
|
||||
// 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 }")); |
||||
setPageNumber(0, 0); |
||||
mPageNbr->setAlignment(Qt::AlignHCenter); |
||||
|
||||
// Configure the clock
|
||||
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); |
||||
mClock->setAlignment(Qt::AlignHCenter); |
||||
|
||||
//strip seconds
|
||||
mTimeFormat = mTimeFormat.remove(":ss"); |
||||
mTimeFormat = mTimeFormat.remove(":s"); |
||||
mTimerID = startTimer(1000); |
||||
|
||||
connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage()));
|
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBNavigatorPalette::~UBNavigatorPalette() |
||||
{ |
||||
killTimer(mTimerID); |
||||
|
||||
if(NULL != mClock) |
||||
{ |
||||
delete mClock; |
||||
mClock = NULL; |
||||
} |
||||
if(NULL != mPageNbr) |
||||
{ |
||||
delete mPageNbr; |
||||
mPageNbr = NULL; |
||||
} |
||||
if(NULL != mHLayout) |
||||
{ |
||||
delete mHLayout; |
||||
mHLayout = NULL; |
||||
} |
||||
if(NULL != mLayout) |
||||
{ |
||||
delete mLayout; |
||||
mLayout = NULL; |
||||
} |
||||
if(NULL != mNavigator) |
||||
{ |
||||
delete mNavigator; |
||||
mNavigator = NULL; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the current document in the navigator |
||||
* @param document as the given document |
||||
*/ |
||||
void UBNavigatorPalette::setDocument(UBDocumentProxy *document) |
||||
{ |
||||
if(mNavigator->currentDoc() != document) |
||||
{ |
||||
mNavigator->setDocument(document); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Change the current page |
||||
*/ |
||||
void UBNavigatorPalette::changeCurrentPage() |
||||
{ |
||||
// Get the index of the page to display
|
||||
int iPage = mNavigator->selectedPageNumber(); |
||||
if(NO_PAGESELECTED != iPage) |
||||
{ |
||||
// Display the selected page
|
||||
UBApplication::boardController->setActiveDocumentScene(mNavigator->currentDoc(), iPage); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Refresh the thumbnails widget |
||||
*/ |
||||
void UBNavigatorPalette::refresh() |
||||
{ |
||||
mNavigator->setDocument(UBApplication::boardController->activeDocument()); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the resize event |
||||
* @param event as the resize event |
||||
*/ |
||||
void UBNavigatorPalette::resizeEvent(QResizeEvent *event) |
||||
{ |
||||
UBDockPalette::resizeEvent(event); |
||||
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)); |
||||
} |
||||
/*
|
||||
* 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 2 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 "UBNavigatorPalette.h" |
||||
#include "core/UBApplication.h" |
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name): |
||||
UBDockPalette(eUBDockPaletteType_LEFT, parent, name) |
||||
, mNavigator(NULL) |
||||
, mLayout(NULL) |
||||
, mHLayout(NULL) |
||||
, mPageNbr(NULL) |
||||
, mClock(NULL) |
||||
{ |
||||
// Build the gui
|
||||
mLayout = new QVBoxLayout(this); |
||||
mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin()); |
||||
setLayout(mLayout); |
||||
|
||||
mNavigator = new UBDocumentNavigator(this); |
||||
mNavigator->setStyleSheet(QString("background-color : transparent;")); |
||||
mLayout->addWidget(mNavigator, 1); |
||||
|
||||
mHLayout = new QHBoxLayout(); |
||||
mLayout->addLayout(mHLayout, 0); |
||||
|
||||
mPageNbr = new QLabel(this); |
||||
mClock = new QLabel(this); |
||||
mHLayout->addWidget(mPageNbr); |
||||
mHLayout->addWidget(mClock); |
||||
|
||||
// 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 }")); |
||||
setPageNumber(0, 0); |
||||
mPageNbr->setAlignment(Qt::AlignHCenter); |
||||
|
||||
// Configure the clock
|
||||
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); |
||||
mClock->setAlignment(Qt::AlignHCenter); |
||||
|
||||
//strip seconds
|
||||
mTimeFormat = mTimeFormat.remove(":ss"); |
||||
mTimeFormat = mTimeFormat.remove(":s"); |
||||
mTimerID = startTimer(1000); |
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBNavigatorPalette::~UBNavigatorPalette() |
||||
{ |
||||
killTimer(mTimerID); |
||||
|
||||
if(NULL != mClock) |
||||
{ |
||||
delete mClock; |
||||
mClock = NULL; |
||||
} |
||||
if(NULL != mPageNbr) |
||||
{ |
||||
delete mPageNbr; |
||||
mPageNbr = NULL; |
||||
} |
||||
if(NULL != mHLayout) |
||||
{ |
||||
delete mHLayout; |
||||
mHLayout = NULL; |
||||
} |
||||
if(NULL != mLayout) |
||||
{ |
||||
delete mLayout; |
||||
mLayout = NULL; |
||||
} |
||||
if(NULL != mNavigator) |
||||
{ |
||||
delete mNavigator; |
||||
mNavigator = NULL; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the current document in the navigator |
||||
* @param document as the given document |
||||
*/ |
||||
|
||||
/**
|
||||
* \brief Refresh the thumbnails widget |
||||
*/ |
||||
void UBNavigatorPalette::refresh() |
||||
{ |
||||
} |
||||
|
||||
/**
|
||||
* \brief Handle the resize event |
||||
* @param event as the resize event |
||||
*/ |
||||
void UBNavigatorPalette::resizeEvent(QResizeEvent *event) |
||||
{ |
||||
UBDockPalette::resizeEvent(event); |
||||
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 |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 2 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 UBNAVIGATORPALETTE_H |
||||
#define UBNAVIGATORPALETTE_H |
||||
|
||||
#include <QVBoxLayout> |
||||
#include <QHBoxLayout> |
||||
#include <QMouseEvent> |
||||
#include <QResizeEvent> |
||||
#include <QTimerEvent> |
||||
#include <QLabel> |
||||
#include <QString> |
||||
|
||||
#include "UBDockPalette.h" |
||||
#include "UBDocumentNavigator.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
|
||||
class UBNavigatorPalette : public UBDockPalette |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBNavigatorPalette(QWidget* parent=0, const char* name="navigatorPalette"); |
||||
~UBNavigatorPalette(); |
||||
|
||||
void setDocument(UBDocumentProxy* document); |
||||
void refresh(); |
||||
|
||||
public slots: |
||||
void setPageNumber(int current, int total); |
||||
|
||||
protected: |
||||
virtual void resizeEvent(QResizeEvent *event); |
||||
virtual void timerEvent(QTimerEvent *event); |
||||
|
||||
private: |
||||
void updateTime(); |
||||
|
||||
/** The thumbnails navigator widget */ |
||||
UBDocumentNavigator* mNavigator; |
||||
/** The layout */ |
||||
QVBoxLayout* mLayout; |
||||
QHBoxLayout* mHLayout; |
||||
QLabel* mPageNbr; |
||||
QLabel* mClock; |
||||
QString mTimeFormat; |
||||
int mTimerID; |
||||
|
||||
private slots: |
||||
void changeCurrentPage(); |
||||
}; |
||||
|
||||
|
||||
#endif // UBNAVIGATORPALETTE_H
|
||||
/*
|
||||
* 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 2 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 UBNAVIGATORPALETTE_H |
||||
#define UBNAVIGATORPALETTE_H |
||||
|
||||
#include <QVBoxLayout> |
||||
#include <QHBoxLayout> |
||||
#include <QMouseEvent> |
||||
#include <QResizeEvent> |
||||
#include <QTimerEvent> |
||||
#include <QLabel> |
||||
#include <QString> |
||||
|
||||
#include "UBDockPalette.h" |
||||
#include "UBDocumentNavigator.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
|
||||
class UBNavigatorPalette : public UBDockPalette |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBNavigatorPalette(QWidget* parent=0, const char* name="navigatorPalette"); |
||||
~UBNavigatorPalette(); |
||||
|
||||
void setDocument(UBDocumentProxy* document); |
||||
void refresh(); |
||||
|
||||
public slots: |
||||
void setPageNumber(int current, int total); |
||||
|
||||
protected: |
||||
virtual void resizeEvent(QResizeEvent *event); |
||||
virtual void timerEvent(QTimerEvent *event); |
||||
|
||||
private: |
||||
void updateTime(); |
||||
|
||||
/** The thumbnails navigator widget */ |
||||
UBDocumentNavigator* mNavigator; |
||||
/** The layout */ |
||||
QVBoxLayout* mLayout; |
||||
QHBoxLayout* mHLayout; |
||||
QLabel* mPageNbr; |
||||
QLabel* mClock; |
||||
QString mTimeFormat; |
||||
int mTimerID; |
||||
|
||||
}; |
||||
|
||||
|
||||
#endif // UBNAVIGATORPALETTE_H
|
||||
|
@ -1,206 +1,173 @@ |
||||
/*
|
||||
* 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 2 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 "UBPageNavigationWidget.h" |
||||
#include "core/UBApplication.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "globals/UBGlobals.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBPageNavigationWidget::UBPageNavigationWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) |
||||
, mNavigator(NULL) |
||||
, mLayout(NULL) |
||||
, mHLayout(NULL) |
||||
, mPageNbr(NULL) |
||||
, mClock(NULL) |
||||
{ |
||||
setObjectName(name); |
||||
mName = "PageNavigator"; |
||||
mVisibleState = true; |
||||
|
||||
SET_STYLE_SHEET(); |
||||
|
||||
mIconToRight = QPixmap(":images/pages_open.png"); |
||||
mIconToLeft = QPixmap(":images/pages_close.png"); |
||||
|
||||
// Build the gui
|
||||
mLayout = new QVBoxLayout(this); |
||||
setLayout(mLayout); |
||||
|
||||
mNavigator = new UBDocumentNavigator(this); |
||||
mLayout->addWidget(mNavigator, 1); |
||||
|
||||
mHLayout = new QHBoxLayout(); |
||||
mLayout->addLayout(mHLayout, 0); |
||||
|
||||
mPageNbr = new QLabel(this); |
||||
mClock = new QLabel(this); |
||||
mHLayout->addWidget(mPageNbr); |
||||
mHLayout->addWidget(mClock); |
||||
|
||||
// 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 }")); |
||||
setPageNumber(0, 0); |
||||
mPageNbr->setAlignment(Qt::AlignHCenter); |
||||
|
||||
// Configure the clock
|
||||
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); |
||||
mClock->setAlignment(Qt::AlignHCenter); |
||||
|
||||
//strip seconds
|
||||
mTimeFormat = mTimeFormat.remove(":ss"); |
||||
mTimeFormat = mTimeFormat.remove(":s"); |
||||
mTimerID = startTimer(1000); |
||||
|
||||
connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage())); |
||||
connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(onSetDocOnPageNavigator(UBDocumentProxy*))); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBPageNavigationWidget::~UBPageNavigationWidget() |
||||
{ |
||||
killTimer(mTimerID); |
||||
|
||||
if(NULL != mClock) |
||||
{ |
||||
delete mClock; |
||||
mClock = NULL; |
||||
} |
||||
if(NULL != mPageNbr) |
||||
{ |
||||
delete mPageNbr; |
||||
mPageNbr = NULL; |
||||
} |
||||
if(NULL != mHLayout) |
||||
{ |
||||
delete mHLayout; |
||||
mHLayout = NULL; |
||||
} |
||||
if(NULL != mLayout) |
||||
{ |
||||
delete mLayout; |
||||
mLayout = NULL; |
||||
} |
||||
if(NULL != mNavigator) |
||||
{ |
||||
delete mNavigator; |
||||
mNavigator = NULL; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Set the current document in the navigator |
||||
* @param document as the given document |
||||
*/ |
||||
void UBPageNavigationWidget::setDocument(UBDocumentProxy *document) |
||||
{ |
||||
if(mNavigator->currentDoc() != document) |
||||
{ |
||||
mNavigator->setDocument(document); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Change the current page |
||||
*/ |
||||
void UBPageNavigationWidget::changeCurrentPage() |
||||
{ |
||||
// Get the index of the page to display
|
||||
int iPage = mNavigator->selectedPageNumber(); |
||||
if(NO_PAGESELECTED != iPage) |
||||
{ |
||||
// Display the selected page
|
||||
UBApplication::boardController->setActiveDocumentScene(mNavigator->currentDoc(), iPage); |
||||
|
||||
// emit here the signal to indicate that page change
|
||||
UBApplication::boardController->notifyPageChanged(); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \brief Refresh the thumbnails widget |
||||
*/ |
||||
void UBPageNavigationWidget::refresh() |
||||
{ |
||||
mNavigator->setDocument(UBApplication::boardController->activeDocument()); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Notify a timer event |
||||
* @param event as the timer event |
||||
*/ |
||||
void UBPageNavigationWidget::timerEvent(QTimerEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
updateTime(); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Update the current time |
||||
*/ |
||||
void UBPageNavigationWidget::updateTime() |
||||
{ |
||||
if (mClock) |
||||
{ |
||||
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat)); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \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); |
||||
} |
||||
/*
|
||||
* 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 2 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 "UBPageNavigationWidget.h" |
||||
#include "core/UBApplication.h" |
||||
|
||||
#include "board/UBBoardController.h" |
||||
|
||||
#include "document/UBDocumentContainer.h" |
||||
|
||||
#include "globals/UBGlobals.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
/**
|
||||
* \brief Constructor |
||||
* @param parent as the parent widget |
||||
* @param name as the object name |
||||
*/ |
||||
UBPageNavigationWidget::UBPageNavigationWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) |
||||
, mNavigator(NULL) |
||||
, mLayout(NULL) |
||||
, mHLayout(NULL) |
||||
, mPageNbr(NULL) |
||||
, mClock(NULL) |
||||
{ |
||||
setObjectName(name); |
||||
mName = "PageNavigator"; |
||||
mVisibleState = true; |
||||
|
||||
SET_STYLE_SHEET(); |
||||
|
||||
mIconToRight = QPixmap(":images/pages_open.png"); |
||||
mIconToLeft = QPixmap(":images/pages_close.png"); |
||||
|
||||
// Build the gui
|
||||
mLayout = new QVBoxLayout(this); |
||||
setLayout(mLayout); |
||||
|
||||
mNavigator = new UBDocumentNavigator(this); |
||||
mLayout->addWidget(mNavigator, 1); |
||||
|
||||
mHLayout = new QHBoxLayout(); |
||||
mLayout->addLayout(mHLayout, 0); |
||||
|
||||
mPageNbr = new QLabel(this); |
||||
mClock = new QLabel(this); |
||||
mHLayout->addWidget(mPageNbr); |
||||
mHLayout->addWidget(mClock); |
||||
|
||||
// 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 }")); |
||||
setPageNumber(0, 0); |
||||
mPageNbr->setAlignment(Qt::AlignHCenter); |
||||
|
||||
// Configure the clock
|
||||
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); |
||||
mClock->setAlignment(Qt::AlignHCenter); |
||||
|
||||
//strip seconds
|
||||
mTimeFormat = mTimeFormat.remove(":ss"); |
||||
mTimeFormat = mTimeFormat.remove(":s"); |
||||
mTimerID = startTimer(1000); |
||||
|
||||
//connect(mNavigator, SIGNAL(changeCurrentPage()), this, SLOT(changeCurrentPage()));
|
||||
//connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(onSetDocOnPageNavigator(UBDocumentProxy*)));
|
||||
} |
||||
|
||||
/**
|
||||
* \brief Destructor |
||||
*/ |
||||
UBPageNavigationWidget::~UBPageNavigationWidget() |
||||
{ |
||||
killTimer(mTimerID); |
||||
|
||||
if(NULL != mClock) |
||||
{ |
||||
delete mClock; |
||||
mClock = NULL; |
||||
} |
||||
if(NULL != mPageNbr) |
||||
{ |
||||
delete mPageNbr; |
||||
mPageNbr = NULL; |
||||
} |
||||
if(NULL != mHLayout) |
||||
{ |
||||
delete mHLayout; |
||||
mHLayout = NULL; |
||||
} |
||||
if(NULL != mLayout) |
||||
{ |
||||
delete mLayout; |
||||
mLayout = NULL; |
||||
} |
||||
if(NULL != mNavigator) |
||||
{ |
||||
delete mNavigator; |
||||
mNavigator = NULL; |
||||
} |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* \brief Refresh the thumbnails widget |
||||
*/ |
||||
void UBPageNavigationWidget::refresh() |
||||
{ |
||||
// TOLIK!!!
|
||||
// mNavigator->setDocument(UBApplication::boardController->activeDocument());
|
||||
} |
||||
|
||||
/**
|
||||
* \brief Notify a timer event |
||||
* @param event as the timer event |
||||
*/ |
||||
void UBPageNavigationWidget::timerEvent(QTimerEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
updateTime(); |
||||
} |
||||
|
||||
/**
|
||||
* \brief Update the current time |
||||
*/ |
||||
void UBPageNavigationWidget::updateTime() |
||||
{ |
||||
if (mClock) |
||||
{ |
||||
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat)); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* \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(UBDocumentContainer::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; |
||||
} |
||||
|
||||
|
@ -1,75 +1,71 @@ |
||||
/*
|
||||
* 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 2 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 UBPAGENAVIGATIONWIDGET_H |
||||
#define UBPAGENAVIGATIONWIDGET_H |
||||
|
||||
#include <QVBoxLayout> |
||||
#include <QHBoxLayout> |
||||
#include <QMouseEvent> |
||||
#include <QResizeEvent> |
||||
#include <QTimerEvent> |
||||
#include <QLabel> |
||||
#include <QString> |
||||
|
||||
#include "UBDocumentNavigator.h" |
||||
#include "UBDockPaletteWidget.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
class UBPageNavigationWidget : public UBDockPaletteWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBPageNavigationWidget(QWidget* parent=0, const char* name="UBPageNavigationWidget"); |
||||
~UBPageNavigationWidget(); |
||||
void setDocument(UBDocumentProxy* document); |
||||
void refresh(); |
||||
|
||||
bool visibleInMode(eUBDockPaletteWidgetMode mode) |
||||
{ |
||||
return mode == eUBDockPaletteWidget_BOARD; |
||||
} |
||||
|
||||
signals: |
||||
void resizeRequest(QResizeEvent* event); |
||||
|
||||
public slots: |
||||
void setPageNumber(int current, int total); |
||||
|
||||
protected: |
||||
virtual void timerEvent(QTimerEvent *event); |
||||
|
||||
private slots: |
||||
void onSetDocOnPageNavigator(UBDocumentProxy* doc); |
||||
|
||||
private: |
||||
void updateTime(); |
||||
int customMargin(); |
||||
int border(); |
||||
|
||||
/** The thumbnails navigator widget */ |
||||
UBDocumentNavigator* mNavigator; |
||||
/** The layout */ |
||||
QVBoxLayout* mLayout; |
||||
QHBoxLayout* mHLayout; |
||||
QLabel* mPageNbr; |
||||
QLabel* mClock; |
||||
QString mTimeFormat; |
||||
int mTimerID; |
||||
|
||||
private slots: |
||||
void changeCurrentPage(); |
||||
}; |
||||
|
||||
#endif // UBPAGENAVIGATIONWIDGET_H
|
||||
/*
|
||||
* 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 2 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 UBPAGENAVIGATIONWIDGET_H |
||||
#define UBPAGENAVIGATIONWIDGET_H |
||||
|
||||
#include <QVBoxLayout> |
||||
#include <QHBoxLayout> |
||||
#include <QMouseEvent> |
||||
#include <QResizeEvent> |
||||
#include <QTimerEvent> |
||||
#include <QLabel> |
||||
#include <QString> |
||||
|
||||
#include "UBDocumentNavigator.h" |
||||
#include "UBDockPaletteWidget.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
class UBPageNavigationWidget : public UBDockPaletteWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
UBPageNavigationWidget(QWidget* parent=0, const char* name="UBPageNavigationWidget"); |
||||
~UBPageNavigationWidget(); |
||||
//void setDocument(UBDocumentProxy* document);
|
||||
void refresh(); |
||||
|
||||
bool visibleInMode(eUBDockPaletteWidgetMode mode) |
||||
{ |
||||
return mode == eUBDockPaletteWidget_BOARD; |
||||
} |
||||
|
||||
signals: |
||||
void resizeRequest(QResizeEvent* event); |
||||
|
||||
public slots: |
||||
void setPageNumber(int current, int total); |
||||
|
||||
protected: |
||||
virtual void timerEvent(QTimerEvent *event); |
||||
|
||||
|
||||
private: |
||||
void updateTime(); |
||||
int customMargin(); |
||||
int border(); |
||||
|
||||
/** The thumbnails navigator widget */ |
||||
UBDocumentNavigator* mNavigator; |
||||
/** The layout */ |
||||
QVBoxLayout* mLayout; |
||||
QHBoxLayout* mHLayout; |
||||
QLabel* mPageNbr; |
||||
QLabel* mClock; |
||||
QString mTimeFormat; |
||||
int mTimerID; |
||||
|
||||
}; |
||||
|
||||
#endif // UBPAGENAVIGATIONWIDGET_H
|
||||
|
Loading…
Reference in new issue