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. 3
      src/board/UBBoardController.cpp
  4. 7
      src/gui/UBDocumentNavigator.cpp

@ -31,22 +31,8 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBThumbnailAdaptor::UBThumbnailAdaptor(QObject *parent)
: QObject(parent)
{
// NOOP
}
UBThumbnailAdaptor::~UBThumbnailAdaptor()
{
// NOOP
}
QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy) QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
{ {
QList<QPixmap> thumbnails; QList<QPixmap> thumbnails;
if (!proxy || proxy->persistencePath().size() == 0) if (!proxy || proxy->persistencePath().size() == 0)
@ -76,14 +62,14 @@ QList<QPixmap> UBThumbnailAdaptor::load(UBDocumentProxy* proxy)
thumbCount++; thumbCount++;
if (displayMessage && thumbCount == 1) if (displayMessage && thumbCount == 1)
UBApplication::showMessage(tr("Generating preview thumbnails ...")); UBApplication::showMessage(QObject::tr("Generating preview thumbnails ..."));
persistScene(proxy->persistencePath(), scene, i); persistScene(proxy->persistencePath(), scene, i);
} }
} }
if (displayMessage && thumbCount > 0) 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; 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); 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() + QString fileName = proxy->persistencePath() +
UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex + 1); UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex + 1);

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

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

@ -155,9 +155,8 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
UBThumbnailAdaptor::persistScene(mCrntDoc->persistencePath(), pScene, iPage); UBThumbnailAdaptor::persistScene(mCrntDoc->persistencePath(), pScene, iPage);
// Load it // Load it
QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc); QPixmap pix = UBThumbnailAdaptor::load(mCrntDoc, iPage);
QPixmap pix = thumbs.at(iPage); UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage);
QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage);
if(pixmapItem) if(pixmapItem)
{ {
// Get the old thumbnail // Get the old thumbnail
@ -312,6 +311,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
if(NULL != mCrntItem && mCrntItem != pCrntItem) if(NULL != mCrntItem && mCrntItem != pCrntItem)
{ {
// Unselect the previous item // Unselect the previous item
mCrntItem->setSelected(false);
int iOldPage = -1; int iOldPage = -1;
for(int i = 0; i < mThumbsWithLabels.size(); i++) for(int i = 0; i < mThumbsWithLabels.size(); i++)
if (mThumbsWithLabels.at(i).getThumbnail() == mCrntItem) if (mThumbsWithLabels.at(i).getThumbnail() == mCrntItem)
@ -327,6 +327,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
emit changeCurrentPage(); emit changeCurrentPage();
refreshScene(); refreshScene();
} }
bNavig = false; bNavig = false;
} }
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);

Loading…
Cancel
Save