Commit 1833713d authored by shibakaneki's avatar shibakaneki

Implemented move up, move down and delete page in the navigation palette

parent 2f245a94
...@@ -262,6 +262,7 @@ class UBBoardController : public QObject ...@@ -262,6 +262,7 @@ class UBBoardController : public QObject
void cacheDisabled(); void cacheDisabled();
void pageChanged(); void pageChanged();
void setDocOnPageNavigator(UBDocumentProxy* doc); void setDocOnPageNavigator(UBDocumentProxy* doc);
void documentReorganized(int index);
protected: protected:
......
...@@ -717,3 +717,8 @@ UBRightPalette* UBBoardPaletteManager::createDesktopRightPalette(QWidget* parent ...@@ -717,3 +717,8 @@ UBRightPalette* UBBoardPaletteManager::createDesktopRightPalette(QWidget* parent
return mDesktopRightPalette; return mDesktopRightPalette;
} }
void UBBoardPaletteManager::connectToDocumentController()
{
emit connectToDocController();
}
...@@ -49,10 +49,14 @@ class UBBoardPaletteManager : public QObject ...@@ -49,10 +49,14 @@ class UBBoardPaletteManager : public QObject
UBLeftPalette* leftPalette(){return mLeftPalette;} UBLeftPalette* leftPalette(){return mLeftPalette;}
void showVirtualKeyboard(bool show = true); void showVirtualKeyboard(bool show = true);
void initPalettesPosAtStartup(); void initPalettesPosAtStartup();
void connectToDocumentController();
UBKeyboardPalette *mKeyboardPalette; UBKeyboardPalette *mKeyboardPalette;
UBRightPalette* createDesktopRightPalette(QWidget* parent); UBRightPalette* createDesktopRightPalette(QWidget* parent);
signals:
void connectToDocController();
public slots: public slots:
void activeSceneChanged(); void activeSceneChanged();
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "board/UBDrawingController.h" #include "board/UBDrawingController.h"
#include "board/UBBoardView.h" #include "board/UBBoardView.h"
#include "board/UBBoardPaletteManager.h"
#include "web/UBWebController.h" #include "web/UBWebController.h"
#include "document/UBDocumentController.h" #include "document/UBDocumentController.h"
...@@ -233,13 +233,15 @@ int UBApplication::exec(const QString& pFileToImport) ...@@ -233,13 +233,15 @@ int UBApplication::exec(const QString& pFileToImport)
connect(mainWindow->actionDocument, SIGNAL(triggered()), this, SLOT(showDocument())); connect(mainWindow->actionDocument, SIGNAL(triggered()), this, SLOT(showDocument()));
connect(mainWindow->actionQuit, SIGNAL(triggered()), this, SLOT(closing())); connect(mainWindow->actionQuit, SIGNAL(triggered()), this, SLOT(closing()));
connect(mainWindow, SIGNAL(closeEvent_Signal(QCloseEvent*)), this, SLOT(closeEvent(QCloseEvent*))); connect(mainWindow, SIGNAL(closeEvent_Signal(QCloseEvent*)), this, SLOT(closeEvent(QCloseEvent*)));
boardController = new UBBoardController(mainWindow); boardController = new UBBoardController(mainWindow);
boardController->init(); boardController->init();
webController = new UBWebController(mainWindow); webController = new UBWebController(mainWindow);
documentController = new UBDocumentController(mainWindow); documentController = new UBDocumentController(mainWindow);
boardController->paletteManager()->connectToDocumentController();
applicationController = new UBApplicationController(boardController->controlView(), boardController->displayView(), mainWindow, staticMemoryCleaner); applicationController = new UBApplicationController(boardController->controlView(), boardController->displayView(), mainWindow, staticMemoryCleaner);
connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), applicationController, SLOT(showDesktop(bool))); connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), applicationController, SLOT(showDesktop(bool)));
...@@ -249,6 +251,8 @@ int UBApplication::exec(const QString& pFileToImport) ...@@ -249,6 +251,8 @@ int UBApplication::exec(const QString& pFileToImport)
connect(mainWindow->actionHideApplication, SIGNAL(triggered()), this, SLOT(showMinimized())); connect(mainWindow->actionHideApplication, SIGNAL(triggered()), this, SLOT(showMinimized()));
#endif #endif
connect(documentController, SIGNAL(movedToIndex(int)), boardController, SIGNAL(documentReorganized(int)));
mPreferencesController = new UBPreferencesController(mainWindow); mPreferencesController = new UBPreferencesController(mainWindow);
connect(mainWindow->actionPreferences, SIGNAL(triggered()), mPreferencesController, SLOT(show())); connect(mainWindow->actionPreferences, SIGNAL(triggered()), mPreferencesController, SLOT(show()));
......
...@@ -102,7 +102,6 @@ class UBApplicationController : public QObject ...@@ -102,7 +102,6 @@ class UBApplicationController : public QObject
signals: signals:
void mainModeChanged(UBApplicationController::MainMode pMode); void mainModeChanged(UBApplicationController::MainMode pMode);
void desktopMode(bool displayed); void desktopMode(bool displayed);
public slots: public slots:
......
...@@ -620,40 +620,42 @@ void UBDocumentController::deleteSelectedItem() ...@@ -620,40 +620,42 @@ void UBDocumentController::deleteSelectedItem()
{ {
QList<QGraphicsItem*> selectedItems = mDocumentUI->thumbnailWidget->selectedItems(); QList<QGraphicsItem*> selectedItems = mDocumentUI->thumbnailWidget->selectedItems();
if (selectedItems.count() > 0) deletePages(selectedItems);
{
QList<int> sceneIndexes; // if (selectedItems.count() > 0)
UBDocumentProxy* proxy = 0; // {
// QList<int> sceneIndexes;
foreach (QGraphicsItem* item, selectedItems) // UBDocumentProxy* proxy = 0;
{
UBSceneThumbnailPixmap* thumb = dynamic_cast<UBSceneThumbnailPixmap*> (item); // foreach (QGraphicsItem* item, selectedItems)
// {
if (thumb) // UBSceneThumbnailPixmap* thumb = dynamic_cast<UBSceneThumbnailPixmap*> (item);
{
proxy = thumb->proxy(); // if (thumb)
if (proxy) // {
{ // proxy = thumb->proxy();
sceneIndexes.append(thumb->sceneIndex()); // if (proxy)
} // {
} // sceneIndexes.append(thumb->sceneIndex());
} // }
// }
if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Page"), tr("Are you sure you want to remove %n page(s) from the selected document '%1'?", "", sceneIndexes.count()).arg(proxy->metaData(UBSettings::documentName).toString()))) // }
{
UBPersistenceManager::persistenceManager()->deleteDocumentScenes(proxy, sceneIndexes); // if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Page"), tr("Are you sure you want to remove %n page(s) from the selected document '%1'?", "", sceneIndexes.count()).arg(proxy->metaData(UBSettings::documentName).toString())))
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); // {
UBMetadataDcSubsetAdaptor::persist(proxy); // UBPersistenceManager::persistenceManager()->deleteDocumentScenes(proxy, sceneIndexes);
refreshDocumentThumbnailsView(); // proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
// UBMetadataDcSubsetAdaptor::persist(proxy);
int minIndex = proxy->pageCount() - 1; // refreshDocumentThumbnailsView();
foreach (int i, sceneIndexes) // int minIndex = proxy->pageCount() - 1;
minIndex = qMin(i, minIndex);
// foreach (int i, sceneIndexes)
mDocumentUI->thumbnailWidget->selectItemAt(minIndex); // minIndex = qMin(i, minIndex);
}
} // mDocumentUI->thumbnailWidget->selectItemAt(minIndex);
// }
// }
} }
else else
{ {
...@@ -1164,7 +1166,11 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source, ...@@ -1164,7 +1166,11 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source,
UBMetadataDcSubsetAdaptor::persist(proxy); UBMetadataDcSubsetAdaptor::persist(proxy);
refreshDocumentThumbnailsView(); refreshDocumentThumbnailsView();
// NOTE [Didier]: I think that selecting the thumbnail is not the role of the documentController
mDocumentUI->thumbnailWidget->selectItemAt(target); mDocumentUI->thumbnailWidget->selectItemAt(target);
// Notify the move to anyone interested in knowing it
emit movedToIndex(target);
} }
...@@ -1630,3 +1636,40 @@ void UBDocumentController::focusChanged(QWidget *old, QWidget *current) ...@@ -1630,3 +1636,40 @@ void UBDocumentController::focusChanged(QWidget *old, QWidget *current)
selectionChanged(); selectionChanged();
} }
void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
{
if (itemsToDelete.count() > 0)
{
QList<int> sceneIndexes;
UBDocumentProxy* proxy = 0;
foreach (QGraphicsItem* item, itemsToDelete)
{
UBSceneThumbnailPixmap* thumb = dynamic_cast<UBSceneThumbnailPixmap*> (item);
if (thumb)
{
proxy = thumb->proxy();
if (proxy)
{
sceneIndexes.append(thumb->sceneIndex());
}
}
}
if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Page"), tr("Are you sure you want to remove %n page(s) from the selected document '%1'?", "", sceneIndexes.count()).arg(proxy->metaData(UBSettings::documentName).toString())))
{
UBPersistenceManager::persistenceManager()->deleteDocumentScenes(proxy, sceneIndexes);
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(proxy);
refreshDocumentThumbnailsView();
int minIndex = proxy->pageCount() - 1;
foreach (int i, sceneIndexes)
minIndex = qMin(i, minIndex);
mDocumentUI->thumbnailWidget->selectItemAt(minIndex);
}
}
}
...@@ -49,10 +49,12 @@ class UBDocumentController : public QObject ...@@ -49,10 +49,12 @@ class UBDocumentController : public QObject
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy); UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy);
bool addFileToDocument(UBDocumentProxy* document); bool addFileToDocument(UBDocumentProxy* document);
UBDocumentProxy* getCurrentDocument(); UBDocumentProxy* getCurrentDocument();
void deletePages(QList<QGraphicsItem*> itemsToDelete);
signals: signals:
void refreshThumbnails(); void refreshThumbnails();
void exportDone(); void exportDone();
void movedToIndex(int index);
public slots: public slots:
void createNewDocument(); void createNewDocument();
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "adaptors/UBSvgSubsetAdaptor.h" #include "adaptors/UBSvgSubsetAdaptor.h"
#include "document/UBDocumentController.h" #include "document/UBDocumentController.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "board/UBBoardPaletteManager.h"
#include "core/UBApplicationController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
...@@ -56,6 +58,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra ...@@ -56,6 +58,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(addNewPage())); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(addNewPage()));
connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(generateThumbnails())); connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(generateThumbnails()));
connect(mScene, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); connect(mScene, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
connect(UBApplication::boardController, SIGNAL(documentReorganized(int)), this, SLOT(onMovedToIndex(int)));
} }
/** /**
...@@ -107,13 +110,13 @@ void UBDocumentNavigator::generateThumbnails() ...@@ -107,13 +110,13 @@ void UBDocumentNavigator::generateThumbnails()
for(int i = 0; i < thumbs.count(); i++) for(int i = 0; i < thumbs.count(); i++)
{ {
QPixmap pix = thumbs.at(i); QPixmap pix = thumbs.at(i);
QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailPixmap(pix, mCrntDoc, i); QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, i);
// Get the selected item // Get the selected item
if(UBApplication::boardController->activeSceneIndex() == i) if(UBApplication::boardController->activeSceneIndex() == i)
{ {
selection = pixmapItem; selection = pixmapItem;
mCrntItem = dynamic_cast<UBSceneThumbnailPixmap*>(pixmapItem); mCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pixmapItem);
mCrntItem->setSelected(true); mCrntItem->setSelected(true);
} }
...@@ -145,7 +148,7 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage) ...@@ -145,7 +148,7 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
// Load it // Load it
QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc); QList<QPixmap> thumbs = UBThumbnailAdaptor::load(mCrntDoc);
QPixmap pix = thumbs.at(iPage); QPixmap pix = thumbs.at(iPage);
QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailPixmap(pix, mCrntDoc, iPage); QGraphicsPixmapItem* pixmapItem = new UBSceneThumbnailNavigPixmap(pix, mCrntDoc, iPage);
if(pixmapItem) if(pixmapItem)
{ {
// Get the old thumbnail // Get the old thumbnail
...@@ -370,7 +373,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event) ...@@ -370,7 +373,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
bNavig = true; bNavig = true;
// First, select the clicked item // First, select the clicked item
UBSceneThumbnailPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailPixmap*>(pClickedItem); UBSceneThumbnailNavigPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pClickedItem);
if(NULL == pCrntItem) if(NULL == pCrntItem)
{ {
...@@ -378,7 +381,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event) ...@@ -378,7 +381,7 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem); UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem);
if(NULL != pTextItem) if(NULL != pTextItem)
{ {
pCrntItem = dynamic_cast<UBSceneThumbnailPixmap*>(mThumbnails.at(mLabels.indexOf(pTextItem))); pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(mThumbnails.at(mLabels.indexOf(pTextItem)));
} }
} }
else else
...@@ -387,12 +390,14 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event) ...@@ -387,12 +390,14 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
{ {
// Unselect the previous item // Unselect the previous item
int iOldPage = mThumbnails.indexOf(mCrntItem); int iOldPage = mThumbnails.indexOf(mCrntItem);
mCrntItem->setSelected(false);
updateSpecificThumbnail(iOldPage); updateSpecificThumbnail(iOldPage);
mCrntItem = pCrntItem; mCrntItem = pCrntItem;
} }
pCrntItem->setSelected(true); // HACK: for an unknown reason, the mousePressEvent of the item is not
// called when a click occurs on it. So I created this method in
// order to handle the click.
mCrntItem->notifyClick(mapToScene(event->pos()));
// Then display the related page // Then display the related page
emit changeCurrentPage(); emit changeCurrentPage();
...@@ -435,3 +440,18 @@ void UBDocumentNavigator::onSelectionChanged() ...@@ -435,3 +440,18 @@ void UBDocumentNavigator::onSelectionChanged()
// QList<QGraphicsItem*> qlItems = mScene->selectedItems(); // QList<QGraphicsItem*> qlItems = mScene->selectedItems();
// qDebug() << "The number of selected items is " << qlItems.count(); // qDebug() << "The number of selected items is " << qlItems.count();
} }
/**
* \brief Occurs when a page has been moved to another index in the document
* @param index as the new index
*/
void UBDocumentNavigator::onMovedToIndex(int index)
{
UBSceneThumbnailNavigPixmap* pItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(mThumbnails.at(index));
if(NULL != pItem)
{
mCrntItem = pItem;
mCrntItem->setSelected(true);
centerOn(mCrntItem);
}
}
...@@ -44,6 +44,9 @@ public: ...@@ -44,6 +44,9 @@ public:
signals: signals:
void changeCurrentPage(); void changeCurrentPage();
public slots:
void onMovedToIndex(int index);
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
virtual void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event);
...@@ -63,7 +66,7 @@ private: ...@@ -63,7 +66,7 @@ private:
/** The scene */ /** The scene */
QGraphicsScene* mScene; QGraphicsScene* mScene;
/** The current selected item */ /** The current selected item */
UBSceneThumbnailPixmap* mCrntItem; UBSceneThumbnailNavigPixmap* mCrntItem;
/** The current document */ /** The current document */
UBDocumentProxy* mCrntDoc; UBDocumentProxy* mCrntDoc;
/** The list of current thumbnails */ /** The list of current thumbnails */
......
...@@ -13,14 +13,19 @@ ...@@ -13,14 +13,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QString> #include <QString>
#include <QCursor>
#include "UBThumbnailWidget.h" #include "UBThumbnailWidget.h"
#include "UBRubberBand.h" #include "UBRubberBand.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBApplication.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentController.h"
UBThumbnailWidget::UBThumbnailWidget(QWidget* parent) UBThumbnailWidget::UBThumbnailWidget(QWidget* parent)
: QGraphicsView(parent) : QGraphicsView(parent)
, mThumbnailWidth(UBSettings::defaultThumbnailWidth) , mThumbnailWidth(UBSettings::defaultThumbnailWidth)
...@@ -681,3 +686,158 @@ UBThumbnail::~UBThumbnail() ...@@ -681,3 +686,158 @@ UBThumbnail::~UBThumbnail()
if (mSelectionItem && !mAddedToScene) if (mSelectionItem && !mAddedToScene)
delete mSelectionItem; delete mSelectionItem;
} }
UBSceneThumbnailNavigPixmap::UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
: UBSceneThumbnailPixmap(pix, proxy, pSceneIndex)
, bButtonsVisible(false)
, bCanDelete(false)
, bCanMoveUp(false)
, bCanMoveDown(false)
{
setAcceptsHoverEvents(true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
}
UBSceneThumbnailNavigPixmap::~UBSceneThumbnailNavigPixmap()
{
}
void UBSceneThumbnailNavigPixmap::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
updateButtonsState();
update();
}
void UBSceneThumbnailNavigPixmap::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
bButtonsVisible = false;
update();
}
void UBSceneThumbnailNavigPixmap::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
UBSceneThumbnailPixmap::paint(painter, option, widget);
if(bButtonsVisible)
{
if(bCanDelete)
painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/close.svg"));
else
painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/closeDisabled.svg"));
if(bCanMoveUp)
painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg"));
else
painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg"));
if(bCanMoveDown)
painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg"));
else
painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg"));
}
}
void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// INFO: This implementation should work but this method is not called on a mousePressEvent, why?
// PLEASE DO NOT REMOVE THIS METHOD! We should reactivate this code when we will fix
// the mousePressEvent-not-called issue!
// 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(bCanMoveUp && p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= 2*BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
// {
// moveUpPage();
// }
// if(bCanMoveDown && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 2*(BUTTONSIZE + BUTTONSPACING) + BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE)
// {
// moveDownPage();
// }
event->accept();
}
void UBSceneThumbnailNavigPixmap::updateButtonsState()
{
bCanDelete = false;
bCanMoveUp = false;
bCanMoveDown = false;
UBDocumentProxy* p = proxy();
if(NULL != p)
{
int iNbPages = p->pageCount();
if(1 < iNbPages)
{
bCanDelete = true;
if(sceneIndex() > 0)
{
bCanMoveUp = true;
}
if(sceneIndex() != iNbPages - 1)
{
bCanMoveDown = true;
}
}
}
if(bCanDelete || bCanMoveUp || bCanMoveDown)
{
bButtonsVisible = true;
}
}
void UBSceneThumbnailNavigPixmap::deletePage()
{
QList<QGraphicsItem*> itemsToDelete;
itemsToDelete << this;
UBApplication::documentController->deletePages(itemsToDelete);
}
void UBSceneThumbnailNavigPixmap::moveUpPage()
{
UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() - 1);
}
void UBSceneThumbnailNavigPixmap::moveDownPage()
{
UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() + 1);
}
void UBSceneThumbnailNavigPixmap::notifyClick(QPointF clickedScenePos)
{
QPointF p = clickedPos(clickedScenePos);
// 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/2 && p.y() >= 0 && p.y() <= BUTTONSIZE/2)
{
deletePage();
}
if(bCanMoveUp && p.x() >= (BUTTONSIZE + BUTTONSPACING)/2 && p.x() <= BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE/2)
{
moveUpPage();
}
if(bCanMoveDown && p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= BUTTONSIZE + BUTTONSPACING + BUTTONSIZE/2 && p.y() >= 0 && p.y() <= BUTTONSIZE/2)
{
moveDownPage();
}
}
QPointF UBSceneThumbnailNavigPixmap::clickedPos(QPointF clickedScenePos)
{
QPointF p;
p.setX(clickedScenePos.x() - scenePos().x());
p.setY(clickedScenePos.y() - scenePos().y());
return p;
}
...@@ -19,11 +19,14 @@ ...@@ -19,11 +19,14 @@
#include <QtGui> #include <QtGui>
#include <QtSvg> #include <QtSvg>
#include <QTime> #include <QTime>
#include <QGraphicsSceneHoverEvent>
#include "frameworks/UBCoreGraphicsScene.h" #include "frameworks/UBCoreGraphicsScene.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#define STARTDRAGTIME 1000000 #define STARTDRAGTIME 1000000
#define BUTTONSIZE 48
#define BUTTONSPACING 5
class UBDocumentProxy; class UBDocumentProxy;
class UBThumbnailTextItem; class UBThumbnailTextItem;
...@@ -282,6 +285,31 @@ class UBSceneThumbnailPixmap : public UBThumbnailPixmap ...@@ -282,6 +285,31 @@ class UBSceneThumbnailPixmap : public UBThumbnailPixmap
int mSceneIndex; int mSceneIndex;
}; };
class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
{
public:
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
~UBSceneThumbnailNavigPixmap();
void notifyClick(QPointF clickedScenePos);
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
void updateButtonsState();
void deletePage();
void moveUpPage();
void moveDownPage();
QPointF clickedPos(QPointF clickedScenePos);
bool bButtonsVisible;
bool bCanDelete;
bool bCanMoveUp;
bool bCanMoveDown;
};
class UBThumbnailVideo : public UBThumbnailPixmap class UBThumbnailVideo : public UBThumbnailPixmap
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment