Selection items hotfix.

preferencesAboutTextFull
Aleksei Kanash 13 years ago
parent 281eb751c9
commit 0d339d4cdf
  1. 78
      src/gui/UBThumbnailWidget.cpp
  2. 4
      src/gui/UBThumbnailWidget.h

@ -33,6 +33,7 @@ UBThumbnailWidget::UBThumbnailWidget(QWidget* parent)
, mLastSelectedThumbnail(0) , mLastSelectedThumbnail(0)
, mSelectionSpan(0) , mSelectionSpan(0)
, mLassoRectItem(0) , mLassoRectItem(0)
, mPrevLassoRect(QRect())
{ {
// By default, the drag is possible // By default, the drag is possible
bCanDrag = true; bCanDrag = true;
@ -217,6 +218,7 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event)
QStyleOption option; QStyleOption option;
option.initFrom(&rubberBand); option.initFrom(&rubberBand);
mPrevLassoRect = QRect();
mLassoRectItem = new QGraphicsRectItem(0, scene()); mLassoRectItem = new QGraphicsRectItem(0, scene());
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
@ -248,6 +250,8 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event)
} }
mSelectedThumbnailItems.clear(); mSelectedThumbnailItems.clear();
mPreviouslyIncrementalSelectedItemsX.clear();
mPreviouslyIncrementalSelectedItemsY.clear();
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);
} }
else if (Qt::ShiftModifier & event->modifiers()) else if (Qt::ShiftModifier & event->modifiers())
@ -305,6 +309,8 @@ void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
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()));
if (QPoint() == prevMoveMousePos)
prevMoveMousePos = currentScenePos;
QRectF incrementXSelection( QRectF incrementXSelection(
qMin(prevMoveMousePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()), qMin(prevMoveMousePos.x(), currentScenePos.x()), qMin(mMousePressScenePos.y(), currentScenePos.y()),
qAbs(prevMoveMousePos.x() - currentScenePos.x())+incrementLassoMinWidth, qAbs(mMousePressScenePos.y() - currentScenePos.y())); qAbs(prevMoveMousePos.x() - currentScenePos.x())+incrementLassoMinWidth, qAbs(mMousePressScenePos.y() - currentScenePos.y()));
@ -315,50 +321,83 @@ void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
prevMoveMousePos = currentScenePos; prevMoveMousePos = currentScenePos;
mLassoRectItem->setRect(lassoRect); mLassoRectItem->setRect(lassoRect);
QSet<QGraphicsItem*> lassoSelectedThumbnailItems;
QSet<QGraphicsItem*> incSelectedItems = scene()->items(incrementXSelection, Qt::IntersectsItemBoundingRect).toSet() QSet<QGraphicsItem*> toUnset;
+ scene()->items(incrementYSelection, Qt::IntersectsItemBoundingRect).toSet(); QSet<QGraphicsItem*> toSet;
mPreviouslyIncrementalSelectedItems = incSelectedItems; // for horizontal moving
QSet<QGraphicsItem*> lassoSelectedItems; QSet<QGraphicsItem*> incSelectedItemsX = scene()->items(incrementXSelection, Qt::IntersectsItemBoundingRect).toSet();
QSet<QGraphicsItem*> lassoSelectedThumbnailItems; foreach (QGraphicsItem *lassoSelectedItem, incSelectedItemsX)
foreach (QGraphicsItem *lassoSelectedItem, incSelectedItems)
{ {
if (lassoSelectedItem) if (lassoSelectedItem)
{ {
UBSceneThumbnailPixmap *thumbnailItem = dynamic_cast<UBSceneThumbnailPixmap*>(lassoSelectedItem); UBSceneThumbnailPixmap *thumbnailItem = dynamic_cast<UBSceneThumbnailPixmap*>(lassoSelectedItem);
if (thumbnailItem) if (thumbnailItem)
{
lassoSelectedItem->setSelected(true);
lassoSelectedThumbnailItems += lassoSelectedItem; lassoSelectedThumbnailItems += lassoSelectedItem;
} }
} }
if(lassoRect.width() < mPrevLassoRect.width())
{
if (!lassoSelectedThumbnailItems.contains(mPreviouslyIncrementalSelectedItemsX))
toUnset += mPreviouslyIncrementalSelectedItemsX - lassoSelectedThumbnailItems;
} }
mPreviouslyIncrementalSelectedItemsX = lassoSelectedThumbnailItems;
QSet<QGraphicsItem*> toUnset; toSet += lassoSelectedThumbnailItems + mPreviouslyIncrementalSelectedItemsX;
toUnset = mSelectedThumbnailItems - lassoSelectedThumbnailItems;
foreach(QGraphicsItem* item, toUnset)
lassoSelectedThumbnailItems.clear();
// for vertical moving
QSet<QGraphicsItem*> incSelectedItemsY = scene()->items(incrementYSelection, Qt::IntersectsItemBoundingRect).toSet();
foreach (QGraphicsItem *lassoSelectedItem, incSelectedItemsY)
{ {
item->setSelected(false); if (lassoSelectedItem)
{
UBSceneThumbnailPixmap *thumbnailItem = dynamic_cast<UBSceneThumbnailPixmap*>(lassoSelectedItem);
if (thumbnailItem)
lassoSelectedThumbnailItems += lassoSelectedItem;
}
} }
if(lassoRect.height() < mPrevLassoRect.height())
{
if (!lassoSelectedThumbnailItems.contains(mPreviouslyIncrementalSelectedItemsY))
toUnset += mPreviouslyIncrementalSelectedItemsY - lassoSelectedThumbnailItems;
}
mPreviouslyIncrementalSelectedItemsY = lassoSelectedThumbnailItems;
toSet += lassoSelectedThumbnailItems + mPreviouslyIncrementalSelectedItemsY;
mSelectedThumbnailItems += lassoSelectedItems; toSet -= toUnset;
// foreach (QGraphicsItem *lassoSelectedItem, lassoSelectedThumbnailItems)
foreach (QGraphicsItem *item, toSet)
{ {
item->setSelected(true);
}
foreach (QGraphicsItem *item, toUnset)
{
item->setSelected(false);
} }
mSelectedThumbnailItems += lassoSelectedThumbnailItems;
mPrevLassoRect = lassoRect;
if (Qt::ControlModifier & event->modifiers()) if (Qt::ControlModifier & event->modifiers())
{ {
for (int i = 0; i < mSelectedThumbnailItems.count()-1; i++) for (int i = 0; i < mSelectedThumbnailItems.count()-1; i++)
{ {
mSelectedThumbnailItems.values().at(i)->setSelected(true); mSelectedThumbnailItems.values().at(i)->setSelected(true);
} }
// foreach (QGraphicsItem *selectedItem, mSelectedThumbnailItems)
{
// selectedItem->setSelected(true);
}
} }
} }
else else
@ -404,6 +443,7 @@ void UBThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
void UBThumbnailWidget::mouseReleaseEvent(QMouseEvent *event) void UBThumbnailWidget::mouseReleaseEvent(QMouseEvent *event)
{ {
int elapsedTimeSincePress = mClickTime.elapsed(); int elapsedTimeSincePress = mClickTime.elapsed();
prevMoveMousePos = QPoint();
deleteLasso(); deleteLasso();
QGraphicsView::mouseReleaseEvent(event); QGraphicsView::mouseReleaseEvent(event);

@ -113,9 +113,11 @@ class UBThumbnailWidget : public QGraphicsView
UBThumbnail *mLastSelectedThumbnail; UBThumbnail *mLastSelectedThumbnail;
int mSelectionSpan; int mSelectionSpan;
QRectF mPrevLassoRect;
QGraphicsRectItem *mLassoRectItem; QGraphicsRectItem *mLassoRectItem;
QSet<QGraphicsItem*> mSelectedThumbnailItems; QSet<QGraphicsItem*> mSelectedThumbnailItems;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItems; QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsX;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsY;
QTime mClickTime; QTime mClickTime;
}; };

Loading…
Cancel
Save