improved click handling on thumbnails view

preferencesAboutTextFull
Clément Fauconnier 6 years ago
parent 9e4dfba31b
commit e60416f3fa
  1. 80
      src/gui/UBDocumentNavigator.cpp
  2. 3
      src/gui/UBDocumentNavigator.h
  3. 89
      src/gui/UBThumbnailWidget.cpp
  4. 40
      src/gui/UBThumbnailWidget.h

@ -59,6 +59,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
, mThumbnailWidth(0)
, mThumbnailMinWidth(100)
, mSelectedThumbnail(NULL)
, mLastClickedThumbnail(NULL)
, mDropSource(NULL)
, mDropTarget(NULL)
, mDropBar(new QGraphicsRectItem())
@ -285,50 +286,65 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
*/
void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
{
mLongPressTimer.start();
mLastPressedMousePos = event->pos();
QGraphicsView::mousePressEvent(event);
QGraphicsItem* pClickedItem = itemAt(event->pos());
if(NULL != pClickedItem)
if (!event->isAccepted())
{
mLongPressTimer.start();
mLastPressedMousePos = event->pos();
// First, select the clicked item
UBSceneThumbnailNavigPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pClickedItem);
mLastClickedThumbnail = clickedThumbnail(mLastPressedMousePos);
if(NULL == pCrntItem)
if(mLastClickedThumbnail)
{
int index = 0;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
if (mThumbsWithLabels.at(i).getThumbnail() == mLastClickedThumbnail)
{
mSelectedThumbnail = mLastClickedThumbnail;
index = i;
break;
}
}
UBApplication::boardController->persistViewPositionOnCurrentScene();
UBApplication::boardController->persistCurrentScene();
UBApplication::boardController->setActiveDocumentScene(index);
UBApplication::boardController->centerOn(UBApplication::boardController->activeScene()->lastCenter());
}
}
}
UBSceneThumbnailNavigPixmap* UBDocumentNavigator::clickedThumbnail(const QPoint pos) const
{
UBSceneThumbnailNavigPixmap* clickedThumbnail = NULL;
QGraphicsItem* clickedItem = itemAt(pos);
if(clickedItem)
{
clickedThumbnail = dynamic_cast<UBSceneThumbnailNavigPixmap*>(clickedItem);
if(!clickedThumbnail)
{
// If we fall here we may have clicked on the label instead of the thumbnail
UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem);
if(NULL != pTextItem)
UBThumbnailTextItem* clickedTextItem = dynamic_cast<UBThumbnailTextItem*>(clickedItem);
if(clickedTextItem)
{
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
const UBImgTextThumbnailElement& el = mThumbsWithLabels.at(i);
if(el.getCaption() == pTextItem)
if(el.getCaption() == clickedTextItem)
{
pCrntItem = el.getThumbnail();
clickedThumbnail = el.getThumbnail();
break;
}
}
}
}
int index = 0;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
if (mThumbsWithLabels.at(i).getThumbnail() == pCrntItem)
{
mSelectedThumbnail = pCrntItem;
index = i;
break;
}
}
UBApplication::boardController->persistViewPositionOnCurrentScene();
UBApplication::boardController->persistCurrentScene();
UBApplication::boardController->setActiveDocumentScene(index);
UBApplication::boardController->centerOn(UBApplication::boardController->activeScene()->lastCenter());
}
QGraphicsView::mousePressEvent(event);
return clickedThumbnail;
}
void UBDocumentNavigator::mouseReleaseEvent(QMouseEvent *event)
@ -346,13 +362,13 @@ void UBDocumentNavigator::longPressTimeout()
void UBDocumentNavigator::mousePressAndHoldEvent(QPoint pos)
{
UBSceneThumbnailNavigPixmap* item = dynamic_cast<UBSceneThumbnailNavigPixmap*>(itemAt(pos));
if (item)
// UBSceneThumbnailNavigPixmap* item = dynamic_cast<UBSceneThumbnailNavigPixmap*>(itemAt(pos));
if (mLastClickedThumbnail)
{
mDropSource = item;
mDropTarget = item;
mDropSource = mLastClickedThumbnail;
mDropTarget = mLastClickedThumbnail;
QPixmap pixmap = item->pixmap().scaledToWidth(mThumbnailWidth/2);
QPixmap pixmap = mLastClickedThumbnail->pixmap().scaledToWidth(mThumbnailWidth/2);
QDrag *drag = new QDrag(this);
drag->setMimeData(new QMimeData());

@ -53,6 +53,7 @@ public:
int nbColumns();
void setThumbnailMinWidth(int width);
int thumbnailMinWidth();
UBSceneThumbnailNavigPixmap* clickedThumbnail(const QPoint pos) const;
public slots:
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
@ -94,7 +95,7 @@ private:
int mThumbnailMinWidth;
/** The selected thumbnail */
UBSceneThumbnailNavigPixmap* mSelectedThumbnail;
UBSceneThumbnailNavigPixmap* mLastClickedThumbnail;
UBSceneThumbnailNavigPixmap* mDropSource;
UBSceneThumbnailNavigPixmap* mDropTarget;
QGraphicsRectItem *mDropBar;

@ -773,10 +773,7 @@ UBThumbnail::~UBThumbnail()
UBSceneThumbnailNavigPixmap::UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
: UBSceneThumbnailPixmap(pix, proxy, pSceneIndex)
, bButtonsVisible(false)
, bCanDelete(false)
, bCanMoveUp(false)
, bCanMoveDown(false)
, mEditable(false)
{
if(0 <= UBDocumentContainer::pageFromSceneIndex(pSceneIndex)){
setAcceptHoverEvents(true);
@ -792,49 +789,30 @@ UBSceneThumbnailNavigPixmap::~UBSceneThumbnailNavigPixmap()
void UBSceneThumbnailNavigPixmap::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
bButtonsVisible = true;
bCanDelete = true;
bCanMoveDown = false;
bCanMoveUp = false;
if(sceneIndex() < proxy()->pageCount() - 1)
bCanMoveDown = true;
if(sceneIndex() > 0)
bCanMoveUp = true;
if(proxy()->pageCount() == 1)
bCanDelete = false;
showUI();
update();
}
void UBSceneThumbnailNavigPixmap::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
bButtonsVisible = false;
hideUI();
update();
}
void UBSceneThumbnailNavigPixmap::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
UBSceneThumbnailPixmap::paint(painter, option, widget);
if(bButtonsVisible)
using namespace UBThumbnailUI;
if (editable())
{
if(bCanDelete)
painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/close.svg"));
if(deletable())
draw(painter, *getIcon("close"));
else
painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/closeDisabled.svg"));
painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/duplicate.svg"));
// if(bCanMoveUp)
// painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg"));
// else
// painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg"));
// if(bCanMoveDown)
// painter->drawPixmap(3*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg"));
// else
// painter->drawPixmap(3*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg"));
draw(painter, *getIcon("closeDisabled"));
draw(painter, *getIcon("duplicate"));
}
}
@ -842,18 +820,41 @@ void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *even
{
QPointF p = event->pos();
// Here we check the position of the click and verify if it has to trig an action or not.
if(bCanDelete && p.x() >= 0 && p.x() <= BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE)
deletePage();
if(p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= 2*BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
duplicatePage();
// if(bCanMoveUp && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 3*BUTTONSIZE + 2*BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
// moveUpPage();
// if(bCanMoveDown && p.x() >= 3*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 4*BUTTONSIZE + 3*BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
// moveDownPage();
using namespace UBThumbnailUI;
event->accept();
if (triggered(p.y()))
{
if(deletable() && getIcon("close")->triggered(p.x()))
{
event->accept();
deletePage();
}
else if(getIcon("duplicate")->triggered(p.x()))
{
event->accept();
duplicatePage();
}
else
{
event->ignore();
}
/*
else if(movableUp() && getIcon("moveUp")->triggered(p.x()))
{
event->accept();
moveUpPage();
}
else if (movableDown() && getIcon("moveDown")->triggered(p.x()))
{
event->accept();
moveDownPage();
}
*/
}
else
{
event->ignore();
}
}
void UBSceneThumbnailNavigPixmap::deletePage()

@ -355,6 +355,41 @@ class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
~UBSceneThumbnailNavigPixmap();
bool editable()
{
return mEditable;
}
bool deletable()
{
return proxy()->pageCount() > 1;
}
bool movableUp()
{
return sceneIndex() > 0;
}
bool movableDown()
{
return sceneIndex() < (proxy()->pageCount() -1);
}
void showUI()
{
setEditable(true);
}
void hideUI()
{
setEditable(false);
}
void setEditable(bool editable)
{
mEditable = editable;
}
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
@ -367,10 +402,7 @@ class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
void moveUpPage();
void moveDownPage();
bool bButtonsVisible;
bool bCanDelete;
bool bCanMoveUp;
bool bCanMoveDown;
bool mEditable;
};
class UBImgTextThumbnailElement

Loading…
Cancel
Save