PDF view performance:multiple pages selection

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 896383fd95
commit e6f84716f0
  1. 1742
      src/gui/UBThumbnailWidget.cpp
  2. 844
      src/gui/UBThumbnailWidget.h

File diff suppressed because it is too large Load Diff

@ -1,421 +1,423 @@
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBTHUMBNAILWIDGET_H_ #ifndef UBTHUMBNAILWIDGET_H_
#define UBTHUMBNAILWIDGET_H_ #define UBTHUMBNAILWIDGET_H_
#include <QtGui> #include <QtGui>
#include <QtSvg> #include <QtSvg>
#include <QTime> #include <QTime>
#include <QGraphicsSceneHoverEvent> #include <QGraphicsSceneHoverEvent>
#include "frameworks/UBCoreGraphicsScene.h" #include "frameworks/UBCoreGraphicsScene.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#define STARTDRAGTIME 1000000 #define STARTDRAGTIME 1000000
#define BUTTONSIZE 48 #define BUTTONSIZE 48
#define BUTTONSPACING 5 #define BUTTONSPACING 5
class UBDocumentProxy; class UBDocumentProxy;
class UBThumbnailTextItem; class UBThumbnailTextItem;
class UBThumbnail; class UBThumbnail;
class UBThumbnailWidget : public QGraphicsView class UBThumbnailWidget : public QGraphicsView
{ {
Q_OBJECT; Q_OBJECT;
public: public:
UBThumbnailWidget(QWidget* parent); UBThumbnailWidget(QWidget* parent);
virtual ~UBThumbnailWidget(); virtual ~UBThumbnailWidget();
QList<QGraphicsItem*> selectedItems(); QList<QGraphicsItem*> selectedItems();
void selectItemAt(int pIndex, bool extend = false); void selectItemAt(int pIndex, bool extend = false);
void unselectItemAt(int pIndex); void unselectItemAt(int pIndex);
qreal thumbnailWidth() qreal thumbnailWidth()
{ {
return mThumbnailWidth; return mThumbnailWidth;
} }
void setBackgroundBrush(const QBrush& brush) void setBackgroundBrush(const QBrush& brush)
{ {
mThumbnailsScene.setBackgroundBrush(brush); mThumbnailsScene.setBackgroundBrush(brush);
} }
public slots: public slots:
void setThumbnailWidth(qreal pThumbnailWidth); void setThumbnailWidth(qreal pThumbnailWidth);
void setSpacing(qreal pSpacing); void setSpacing(qreal pSpacing);
virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString("")); virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
void refreshScene(); void refreshScene();
void sceneSelectionChanged(); void sceneSelectionChanged();
signals: signals:
void resized(); void resized();
void selectionChanged(); void selectionChanged();
void mouseDoubleClick(QGraphicsItem* item, int index); void mouseDoubleClick(QGraphicsItem* item, int index);
void mouseClick(QGraphicsItem* item, int index); void mouseClick(QGraphicsItem* item, int index);
protected: protected:
virtual void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent * event); virtual void resizeEvent(QResizeEvent * event);
void mouseDoubleClickEvent(QMouseEvent * event); void mouseDoubleClickEvent(QMouseEvent * event);
virtual void keyPressEvent(QKeyEvent *event); virtual void keyPressEvent(QKeyEvent *event);
virtual void focusInEvent(QFocusEvent *event); virtual void focusInEvent(QFocusEvent *event);
QList<QGraphicsItem*> mGraphicItems; QList<QGraphicsItem*> mGraphicItems;
QList<UBThumbnailTextItem*> mLabelsItems; QList<UBThumbnailTextItem*> mLabelsItems;
QPointF mMousePressScenePos; QPointF mMousePressScenePos;
QPoint mMousePressPos; QPoint mMousePressPos;
protected: protected:
qreal spacing() { return mSpacing; } qreal spacing() { return mSpacing; }
QList<QUrl> mItemsPaths; QList<QUrl> mItemsPaths;
QStringList mLabels; QStringList mLabels;
bool bSelectionInProgress; bool bSelectionInProgress;
bool bCanDrag; bool bCanDrag;
private: private:
void selectAll(); void selectAll();
void unselectAll(); void selectItems(int startIndex, int count);
void selectItems(int startIndex, int count); int rowCount() const;
int rowCount() const; int columnCount() const;
int columnCount() const;
static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);
static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);
void deleteLasso();
void deleteLasso();
UBCoreGraphicsScene mThumbnailsScene;
UBCoreGraphicsScene mThumbnailsScene;
QString mMimeType;
QString mMimeType;
QPointF prevMoveMousePos;
qreal mThumbnailWidth;
qreal mThumbnailHeight; qreal mThumbnailWidth;
qreal mSpacing; qreal mThumbnailHeight;
qreal mSpacing;
UBThumbnail *mLastSelectedThumbnail;
int mSelectionSpan; UBThumbnail *mLastSelectedThumbnail;
QGraphicsRectItem *mLassoRectItem; int mSelectionSpan;
QList<QGraphicsItem*> mSelectedThumbnailItems; QGraphicsRectItem *mLassoRectItem;
QTime mClickTime; QSet<QGraphicsItem*> mSelectedThumbnailItems;
}; QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItems;
QTime mClickTime;
};
class UBThumbnail
{
public: class UBThumbnail
UBThumbnail(); {
public:
virtual ~UBThumbnail(); UBThumbnail();
QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option) virtual ~UBThumbnail();
{
// Never draw the rubber band, we draw our custom selection with the DelegateFrame QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option)
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); {
styleOption.state &= ~QStyle::State_Selected; // Never draw the rubber band, we draw our custom selection with the DelegateFrame
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
return styleOption; styleOption.state &= ~QStyle::State_Selected;
}
return styleOption;
virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value) }
{
Q_UNUSED(value); virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if ((change == QGraphicsItem::ItemSelectedHasChanged Q_UNUSED(value);
|| change == QGraphicsItem::ItemTransformHasChanged
|| change == QGraphicsItem::ItemPositionHasChanged) if ((change == QGraphicsItem::ItemSelectedHasChanged
&& item->scene()) || change == QGraphicsItem::ItemTransformHasChanged
{ || change == QGraphicsItem::ItemPositionHasChanged)
if (item->isSelected()) && item->scene())
{ {
if (!mSelectionItem->scene()) if (item->isSelected())
{ {
item->scene()->addItem(mSelectionItem); if (!mSelectionItem->scene())
mSelectionItem->setZValue(item->zValue() - 1); {
// UBGraphicsItem::assignZValue(mSelectionItem, item->zValue() - 1); item->scene()->addItem(mSelectionItem);
mAddedToScene = true; mSelectionItem->setZValue(item->zValue() - 1);
} // UBGraphicsItem::assignZValue(mSelectionItem, item->zValue() - 1);
mAddedToScene = true;
mSelectionItem->setRect( }
item->sceneBoundingRect().x() - 5,
item->sceneBoundingRect().y() - 5, mSelectionItem->setRect(
item->sceneBoundingRect().width() + 10, item->sceneBoundingRect().x() - 5,
item->sceneBoundingRect().height() + 10); item->sceneBoundingRect().y() - 5,
item->sceneBoundingRect().width() + 10,
mSelectionItem->show(); item->sceneBoundingRect().height() + 10);
} mSelectionItem->show();
else
{ }
mSelectionItem->hide(); else
} {
} mSelectionItem->hide();
} }
}
int column() { return mColumn; } }
void setColumn(int column) { mColumn = column; }
int row() { return mRow; } int column() { return mColumn; }
void setRow(int row) { mRow = row; } void setColumn(int column) { mColumn = column; }
int row() { return mRow; }
protected: void setRow(int row) { mRow = row; }
QGraphicsRectItem *mSelectionItem;
private: protected:
bool mAddedToScene; QGraphicsRectItem *mSelectionItem;
private:
int mColumn; bool mAddedToScene;
int mRow;
}; int mColumn;
int mRow;
};
class UBThumbnailSvg : public QGraphicsSvgItem, public UBThumbnail
{
public: class UBThumbnailSvg : public QGraphicsSvgItem, public UBThumbnail
UBThumbnailSvg(const QString& path) {
: QGraphicsSvgItem(path) public:
{ UBThumbnailSvg(const QString& path)
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); : QGraphicsSvgItem(path)
} {
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
virtual ~UBThumbnailSvg() }
{
// NOOP virtual ~UBThumbnailSvg()
} {
// NOOP
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) }
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsSvgItem::paint(painter, &styleOption, widget); {
} QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsSvgItem::paint(painter, &styleOption, widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) }
{
UBThumbnail::itemChange(this, change, value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
return QGraphicsSvgItem::itemChange(change, value); {
} UBThumbnail::itemChange(this, change, value);
return QGraphicsSvgItem::itemChange(change, value);
}; }
};
class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
{
public: class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
UBThumbnailPixmap(const QPixmap& pix) {
: QGraphicsPixmapItem(pix) public:
{ UBThumbnailPixmap(const QPixmap& pix)
setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable : QGraphicsPixmapItem(pix)
setShapeMode(QGraphicsPixmapItem::BoundingRectShape); {
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable
} setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
virtual ~UBThumbnailPixmap() }
{
// NOOP virtual ~UBThumbnailPixmap()
} {
// NOOP
virtual QPainterPath shape () const }
{
QPainterPath path; virtual QPainterPath shape () const
path.addRect(boundingRect()); {
return path; QPainterPath path;
} path.addRect(boundingRect());
return path;
}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsPixmapItem::paint(painter, &styleOption, widget); {
} QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsPixmapItem::paint(painter, &styleOption, widget);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) }
{
UBThumbnail::itemChange(this, change, value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
return QGraphicsPixmapItem::itemChange(change, value); {
} UBThumbnail::itemChange(this, change, value);
}; return QGraphicsPixmapItem::itemChange(change, value);
}
};
class UBSceneThumbnailPixmap : public UBThumbnailPixmap
{
public: class UBSceneThumbnailPixmap : public UBThumbnailPixmap
UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex) {
: UBThumbnailPixmap(pix) public:
, mProxy(proxy) UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
, mSceneIndex(pSceneIndex) : UBThumbnailPixmap(pix)
{ , mProxy(proxy)
// NOOP , mSceneIndex(pSceneIndex)
} {
// NOOP
virtual ~UBSceneThumbnailPixmap() }
{
// NOOP virtual ~UBSceneThumbnailPixmap()
} {
// NOOP
UBDocumentProxy* proxy() }
{
return mProxy; UBDocumentProxy* proxy()
} {
return mProxy;
int sceneIndex() }
{
return mSceneIndex; int sceneIndex()
} {
return mSceneIndex;
void highlight() }
{
//NOOP void highlight()
} {
//NOOP
private: }
UBDocumentProxy* mProxy;
int mSceneIndex; private:
}; UBDocumentProxy* mProxy;
int mSceneIndex;
class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap };
{
public: class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex); {
~UBSceneThumbnailNavigPixmap(); public:
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
protected: ~UBSceneThumbnailNavigPixmap();
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private: void mousePressEvent(QGraphicsSceneMouseEvent *event);
void updateButtonsState();
void deletePage(); private:
void moveUpPage(); void updateButtonsState();
void moveDownPage(); void deletePage();
void moveUpPage();
bool bButtonsVisible; void moveDownPage();
bool bCanDelete;
bool bCanMoveUp; bool bButtonsVisible;
bool bCanMoveDown; bool bCanDelete;
}; bool bCanMoveUp;
bool bCanMoveDown;
class UBThumbnailVideo : public UBThumbnailPixmap };
{
public: class UBThumbnailVideo : public UBThumbnailPixmap
UBThumbnailVideo(const QUrl &path) {
: UBThumbnailPixmap(QPixmap(":/images/movie.svg")) public:
, mPath(path) UBThumbnailVideo(const QUrl &path)
{ : UBThumbnailPixmap(QPixmap(":/images/movie.svg"))
// NOOP , mPath(path)
} {
// NOOP
virtual ~UBThumbnailVideo() }
{
// NOOP virtual ~UBThumbnailVideo()
} {
// NOOP
QUrl path() }
{
return mPath; QUrl path()
} {
return mPath;
private: }
QUrl mPath; private:
};
QUrl mPath;
class UBThumbnailTextItem : public QGraphicsTextItem };
{
public: class UBThumbnailTextItem : public QGraphicsTextItem
UBThumbnailTextItem(const QString& text) {
: QGraphicsTextItem(text) public:
, mUnelidedText(text) UBThumbnailTextItem(const QString& text)
, mIsHighlighted(false) : QGraphicsTextItem(text)
{ , mUnelidedText(text)
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); , mIsHighlighted(false)
} {
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));} }
void setWidth(qreal pWidth) QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}
{
if (mWidth != pWidth) void setWidth(qreal pWidth)
{ {
prepareGeometryChange(); if (mWidth != pWidth)
mWidth = pWidth; {
computeText(); prepareGeometryChange();
} mWidth = pWidth;
}; computeText();
}
qreal width() {return mWidth;} };
void highlight() qreal width() {return mWidth;}
{
if (!mIsHighlighted) void highlight()
{ {
mIsHighlighted = true; if (!mIsHighlighted)
computeText(); {
} mIsHighlighted = true;
} computeText();
}
void computeText() }
{
QFontMetricsF fm(font()); void computeText()
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth); {
QFontMetricsF fm(font());
if (mIsHighlighted) QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth);
{
setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>"); if (mIsHighlighted)
} {
else setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>");
{ }
setPlainText(elidedText); else
} {
} setPlainText(elidedText);
}
private: }
qreal mWidth;
QString mUnelidedText; private:
bool mIsHighlighted; qreal mWidth;
}; QString mUnelidedText;
bool mIsHighlighted;
class UBImgTextThumbnailElement };
{
private: class UBImgTextThumbnailElement
QGraphicsItem* thumbnail; {
UBThumbnailTextItem* caption; private:
int border; QGraphicsItem* thumbnail;
UBThumbnailTextItem* caption;
public: int border;
UBImgTextThumbnailElement(QGraphicsItem* thumb, UBThumbnailTextItem* text): border(0)
{ public:
this->thumbnail = thumb; UBImgTextThumbnailElement(QGraphicsItem* thumb, UBThumbnailTextItem* text): border(0)
this->caption = text; {
} this->thumbnail = thumb;
this->caption = text;
QGraphicsItem* getThumbnail() const { return this->thumbnail; } }
void setThumbnail(QGraphicsItem* newGItem) { this->thumbnail = newGItem; }
QGraphicsItem* getThumbnail() const { return this->thumbnail; }
UBThumbnailTextItem* getCaption() const { return this->caption; } void setThumbnail(QGraphicsItem* newGItem) { this->thumbnail = newGItem; }
void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }
UBThumbnailTextItem* getCaption() const { return this->caption; }
void Place(int row, int col, qreal width, qreal height); void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }
int getBorder() const { return this->border; } void Place(int row, int col, qreal width, qreal height);
void setBorder(int newBorder) { this->border = newBorder; }
}; int getBorder() const { return this->border; }
void setBorder(int newBorder) { this->border = newBorder; }
};
#endif /* UBTHUMBNAILWIDGET_H_ */
#endif /* UBTHUMBNAILWIDGET_H_ */

Loading…
Cancel
Save