PDF view performance:multiple pages selection

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

@ -243,7 +243,7 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event)
if (Qt::ControlModifier & event->modifiers() || Qt::ShiftModifier & event->modifiers()) if (Qt::ControlModifier & event->modifiers() || Qt::ShiftModifier & event->modifiers())
{ {
mSelectedThumbnailItems = selectedItems(); // mSelectedThumbnailItems = selectedItems().toSet();
return; return;
} }
@ -261,7 +261,7 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event)
int index2 = mGraphicItems.indexOf(underlyingItem); int index2 = mGraphicItems.indexOf(underlyingItem);
if (-1 == index2) if (-1 == index2)
{ {
mSelectedThumbnailItems = selectedItems(); mSelectedThumbnailItems = selectedItems().toSet();
return; return;
} }
mSelectionSpan = index2 - index1; mSelectionSpan = index2 - index1;
@ -300,40 +300,64 @@ void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
if (mLassoRectItem) if (mLassoRectItem)
{ {
bSelectionInProgress = true; bSelectionInProgress = true;
int incrementLassoMinWidth = 2;
QPointF currentScenePos = mapToScene(event->pos()); QPointF currentScenePos = mapToScene(event->pos());
QRectF lassoRect( QRectF lassoRect(
qMin(mMousePressScenePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()), qMin(mMousePressScenePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()),
qAbs(mMousePressScenePos.x() - currentScenePos.x()), qAbs(mMousePressScenePos.y() - currentScenePos.y())); qAbs(mMousePressScenePos.x() - currentScenePos.x()), qAbs(mMousePressScenePos.y() - currentScenePos.y()));
QRectF incrementXSelection(
qMin(prevMoveMousePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()),
qAbs(prevMoveMousePos.x() - currentScenePos.x())+incrementLassoMinWidth, qAbs(mMousePressScenePos.y() - currentScenePos.y()));
QRectF incrementYSelection(
qMin(mMousePressScenePos.x(), currentScenePos.x()), qMin(prevMoveMousePos.y(), currentScenePos.y()),
qAbs(mMousePressScenePos.x() - currentScenePos.x()), qAbs(prevMoveMousePos.y() - currentScenePos.y())+incrementLassoMinWidth);
prevMoveMousePos = currentScenePos;
mLassoRectItem->setRect(lassoRect); mLassoRectItem->setRect(lassoRect);
QList<QGraphicsItem*> lassoSelectedItems = scene()->items(lassoRect, Qt::IntersectsItemBoundingRect);
QList<QGraphicsItem*> lassoSelectedThumbnailItems;
foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedItems)
{
UBThumbnail *thumbnailItem = dynamic_cast<UBThumbnail*>(lassoSelectedItem);
if (thumbnailItem)
lassoSelectedThumbnailItems.append(lassoSelectedItems);
}
unselectAll(); QSet<QGraphicsItem*> incSelectedItems = scene()->items(incrementXSelection, Qt::IntersectsItemBoundingRect).toSet()
foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedThumbnailItems) + scene()->items(incrementYSelection, Qt::IntersectsItemBoundingRect).toSet();
mPreviouslyIncrementalSelectedItems = incSelectedItems;
QSet<QGraphicsItem*> lassoSelectedItems;
QSet<QGraphicsItem*> lassoSelectedThumbnailItems;
foreach (QGraphicsItem *lassoSelectedItem, incSelectedItems)
{ {
if (Qt::ControlModifier & event->modifiers()) if (lassoSelectedItem)
{ {
if (!mSelectedThumbnailItems.contains(lassoSelectedItem)) UBSceneThumbnailPixmap *thumbnailItem = dynamic_cast<UBSceneThumbnailPixmap*>(lassoSelectedItem);
selectItemAt(mGraphicItems.indexOf(lassoSelectedItem), true);
} if (thumbnailItem)
else {
{ lassoSelectedItem->setSelected(true);
selectItemAt(mGraphicItems.indexOf(lassoSelectedItem), true); lassoSelectedThumbnailItems += lassoSelectedItem;
}
} }
} }
QSet<QGraphicsItem*> toUnset;
toUnset = mSelectedThumbnailItems - lassoSelectedThumbnailItems;
foreach(QGraphicsItem* item, toUnset)
{
item->setSelected(false);
}
mSelectedThumbnailItems += lassoSelectedItems;
// foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedThumbnailItems)
{
}
if (Qt::ControlModifier & event->modifiers()) if (Qt::ControlModifier & event->modifiers())
{ {
foreach (QGraphicsItem *selectedItem, mSelectedThumbnailItems) for (int i = 0; i < mSelectedThumbnailItems.count()-1; i++)
{
mSelectedThumbnailItems.values().at(i)->setSelected(true);
}
// foreach (QGraphicsItem *selectedItem, mSelectedThumbnailItems)
{ {
if (!lassoSelectedThumbnailItems.contains(selectedItem)) // selectedItem->setSelected(true);
selectItemAt(mGraphicItems.indexOf(selectedItem), true);
} }
} }
} }
@ -609,14 +633,6 @@ void UBThumbnailWidget::selectAll()
} }
} }
void UBThumbnailWidget::unselectAll()
{
foreach (QGraphicsItem* item, mGraphicItems)
{
item->setSelected(false);
}
}
int UBThumbnailWidget::rowCount() const int UBThumbnailWidget::rowCount() const
{ {
UBThumbnail *lastThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.last()); UBThumbnail *lastThumbnail = dynamic_cast<UBThumbnail*>(mGraphicItems.last());

@ -93,7 +93,6 @@ class UBThumbnailWidget : public QGraphicsView
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;
@ -106,6 +105,8 @@ class UBThumbnailWidget : public QGraphicsView
QString mMimeType; QString mMimeType;
QPointF prevMoveMousePos;
qreal mThumbnailWidth; qreal mThumbnailWidth;
qreal mThumbnailHeight; qreal mThumbnailHeight;
qreal mSpacing; qreal mSpacing;
@ -113,7 +114,8 @@ class UBThumbnailWidget : public QGraphicsView
UBThumbnail *mLastSelectedThumbnail; UBThumbnail *mLastSelectedThumbnail;
int mSelectionSpan; int mSelectionSpan;
QGraphicsRectItem *mLassoRectItem; QGraphicsRectItem *mLassoRectItem;
QList<QGraphicsItem*> mSelectedThumbnailItems; QSet<QGraphicsItem*> mSelectedThumbnailItems;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItems;
QTime mClickTime; QTime mClickTime;
}; };

Loading…
Cancel
Save