Improved document navigation for the ticket 382.

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 18925ab001
commit 2fd15cc027
  1. 79
      src/adaptors/UBThumbnailAdaptor.cpp
  2. 15
      src/adaptors/UBThumbnailAdaptor.h
  3. 5
      src/board/UBBoardController.cpp
  4. 37
      src/gui/UBDocumentNavigator.cpp
  5. 2
      src/gui/UBDocumentNavigator.h

@ -31,22 +31,8 @@
#include "core/memcheck.h"
UBThumbnailAdaptor::UBThumbnailAdaptor(QObject *parent)
: QObject(parent)
{
// NOOP
}
UBThumbnailAdaptor::~UBThumbnailAdaptor()
{
// NOOP
}
QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
{
QList<QPixmap> thumbnails;
if (!proxy || proxy->persistencePath().size() == 0)
@ -76,14 +62,14 @@ QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
thumbCount++;
if (displayMessage && thumbCount == 1)
UBApplication::showMessage(tr("Generating preview thumbnails ..."));
UBApplication::showMessage(QObject::tr("Generating preview thumbnails ..."));
persistScene(proxy->persistencePath(), scene, i);
}
}
if (displayMessage && thumbCount > 0)
UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount));
UBApplication::showMessage(QObject::tr("%1 thumbnails generated ...").arg(thumbCount));
}
@ -114,8 +100,65 @@ QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
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
QString thumbFileName = proxy->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", existingPageCount);
QFile thumbFile(thumbFileName);
if (!thumbFile.exists())
{
bool displayMessage = (existingPageCount > 5);
int thumbCount = 0;
for(int i = 0 ; i < existingPageCount; i++)
{
UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, i);
if (scene)
{
thumbCount++;
if (displayMessage && thumbCount == 1)
UBApplication::showMessage(QObject::tr("Generating preview thumbnails ..."));
persistScene(proxy->persistencePath(), scene, i);
}
}
if (displayMessage && thumbCount > 0)
UBApplication::showMessage(QObject::tr("%1 thumbnails generated ...").arg(thumbCount));
}
//end compatibility with older format
QString fileName = proxy->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index + 1);
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, const int pageIndex, const bool overrideModified)
void UBThumbnailAdaptor::persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified)
{
QString fileName = pDocPath + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex + 1);
@ -161,7 +204,7 @@ void UBThumbnailAdaptor::persistScene(const QString& pDocPath, UBGraphicsScene*
}
QUrl UBThumbnailAdaptor::thumbnailUrl(UBDocumentProxy* proxy, const int pageIndex)
QUrl UBThumbnailAdaptor::thumbnailUrl(UBDocumentProxy* proxy, int pageIndex)
{
QString fileName = proxy->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex + 1);

@ -21,21 +21,16 @@ class UBDocument;
class UBDocumentProxy;
class UBGraphicsScene;
class UBThumbnailAdaptor : public QObject
class UBThumbnailAdaptor //static class
{
Q_OBJECT;
private: UBThumbnailAdaptor() {}
public:
UBThumbnailAdaptor(QObject *parent = 0);
~UBThumbnailAdaptor();
static void persistScene(const QString& pDocPath, UBGraphicsScene* pScene, const int pageIndex, const bool overrideModified = false);
static void persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false);
static QList<QPixmap> load(UBDocumentProxy* proxy);
static QPixmap load(UBDocumentProxy* proxy, int index);
static QUrl thumbnailUrl(UBDocumentProxy* proxy, const int pageIndex);
static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex);
};
#endif // UBTHUMBNAILADAPTOR_H

@ -1166,11 +1166,10 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy,
{
emit activeDocumentChanged();
UBGraphicsTextItem::lastUsedTextColor = QColor();
// Notify the navigator palette that the document has changed
emit setDocOnPageNavigator(pDocumentProxy);
}
// Notify the navigator palette that the document has changed
emit setDocOnPageNavigator(pDocumentProxy);
if (sceneChange)
{
emit activeSceneChanged();

@ -99,7 +99,7 @@ void UBDocumentNavigator::setDocument(UBDocumentProxy *document)
*/
void UBDocumentNavigator::generateThumbnails()
{
// Get the thumbnails
// Get the thumbnails
QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc);
mThumbsWithLabels.clear();
@ -155,9 +155,8 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
UBThumbnailAdaptor::persistScene(mCrntDoc->persistencePath(), pScene, iPage);
// Load it
QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc);
QPixmap pix = thumbs.at(iPage);
QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage);
QPixmap pix = UBThumbnailAdaptor::load(mCrntDoc, iPage);
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage);
if(pixmapItem)
{
// Get the old thumbnail
@ -307,27 +306,29 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
}
}
}
else
{
if(NULL != mCrntItem && mCrntItem != pCrntItem)
{
// Unselect the previous item
int iOldPage = -1;
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;
}
updateSpecificThumbnail(iOldPage);
mCrntItem = pCrntItem;
}
// Then display the related page
emit changeCurrentPage();
refreshScene();
}
bNavig = false;
// Then display the related page
emit changeCurrentPage();
refreshScene();
}
bNavig = false;
}
QGraphicsView::mousePressEvent(event);
}

@ -58,7 +58,7 @@ private slots:
private:
void refreshScene();
void updateSpecificThumbnail(int iPage);
void updateSpecificThumbnail(int iPage);
int border();

Loading…
Cancel
Save