From 7f8d9c10f1791b61d26d9b48ec2eac446e218c39 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Fri, 13 Apr 2012 19:05:16 +0300 Subject: [PATCH] =?UTF-8?q?Sankor=C3=A9SANKORE-499=20Document=20explorer(n?= =?UTF-8?q?avigator):=20pages=20of=20a=20document=20can=20not=20be=20moved?= =?UTF-8?q?=20using=20D'n'D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/board/UBBoardController.h | 2 ++ src/core/UBApplicationController.cpp | 11 +++++++-- src/gui/UBDocumentNavigator.cpp | 1 + src/gui/UBDocumentNavigator.h | 1 + src/gui/UBDocumentTreeWidget.cpp | 36 ++++++++++++++++++++++++++++ src/gui/UBDocumentTreeWidget.h | 4 ++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 4ea56d7a..d5d6bee1 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -152,6 +152,7 @@ class UBBoardController : public QObject void displayMetaData(QMap metadatas); void ClearUndoStack(); + void emitScrollSignal() { emit scrollToSelectedPage(); } public slots: void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0); @@ -230,6 +231,7 @@ class UBBoardController : public QObject void setDocOnPageNavigator(UBDocumentProxy* doc); void documentReorganized(int index); void displayMetadata(QMap metadata); + void scrollToSelectedPage(); protected: void setupViews(); diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 89af16fa..ac2e12af 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -337,8 +337,15 @@ void UBApplicationController::showBoard() mMainWindow->tutorialToolBar->hide(); mMainWindow->boardToolBar->show(); - if (mMainMode == Document && UBApplication::documentController->getSelectedItemIndex() != -1) - UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->getCurrentDocument(), UBApplication::documentController->getSelectedItemIndex()); + if (mMainMode == Document) + { + int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex(); + if (selectedSceneIndex != -1) + { + UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->getCurrentDocument(), selectedSceneIndex); + UBApplication::boardController->emitScrollSignal(); + } + } mMainMode = Board; diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index efb3e04a..c2dd5df2 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -58,6 +58,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(addNewPage())); connect(mScene, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); connect(UBApplication::boardController, SIGNAL(documentReorganized(int)), this, SLOT(onMovedToIndex(int))); + connect(UBApplication::boardController, SIGNAL(scrollToSelectedPage()), this, SLOT(onScrollToSelectedPage())); } /** diff --git a/src/gui/UBDocumentNavigator.h b/src/gui/UBDocumentNavigator.h index 5f322355..e643fbf6 100644 --- a/src/gui/UBDocumentNavigator.h +++ b/src/gui/UBDocumentNavigator.h @@ -46,6 +46,7 @@ signals: public slots: void onMovedToIndex(int index); + void onScrollToSelectedPage() { centerOn(mCrntItem); } protected: virtual void resizeEvent(QResizeEvent *event); diff --git a/src/gui/UBDocumentTreeWidget.cpp b/src/gui/UBDocumentTreeWidget.cpp index b344855c..e693e865 100644 --- a/src/gui/UBDocumentTreeWidget.cpp +++ b/src/gui/UBDocumentTreeWidget.cpp @@ -39,11 +39,14 @@ UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent) setDragDropMode(QAbstractItemView::InternalMove); setAutoScroll(true); + mScrollTimer = new QTimer(this); connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*)) , this, SLOT(documentUpdated(UBDocumentProxy*))); connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)) , this, SLOT(itemChangedValidation(QTreeWidgetItem *, int))); + connect(mScrollTimer, SIGNAL(timeout()) + , this, SLOT(autoScroll())); } @@ -104,6 +107,12 @@ void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event) { Q_UNUSED(event); + if (mScrollTimer->isActive()) + { + mScrollMagnitude = 0; + mScrollTimer->stop(); + } + if (mDropTargetProxyTi) { mDropTargetProxyTi->setBackground(0, mBackground); @@ -114,6 +123,27 @@ void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event) void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event) { + QRect boundingFrame = frameRect(); + //setting up automatic scrolling + const int SCROLL_DISTANCE = 4; + int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); + if(qAbs(bottomDist) <= SCROLL_DISTANCE) + { + mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; + if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); + } + else if(qAbs(topDist) <= SCROLL_DISTANCE) + { + mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; + if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); + } + else + { + mScrollMagnitude = 0; + mScrollTimer->stop(); + } + + QTreeWidgetItem* underlyingItem = this->itemAt(event->pos()); if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) @@ -417,3 +447,9 @@ bool UBDocumentGroupTreeItem::isDefaultFolder() const { return (0 == (flags() & Qt::ItemIsEditable)) && (groupName() == UBSettings::defaultDocumentGroupName); } + + +void UBDocumentTreeWidget::autoScroll() +{ + this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); +} \ No newline at end of file diff --git a/src/gui/UBDocumentTreeWidget.h b/src/gui/UBDocumentTreeWidget.h index f76d1696..d4fe72f6 100644 --- a/src/gui/UBDocumentTreeWidget.h +++ b/src/gui/UBDocumentTreeWidget.h @@ -43,10 +43,14 @@ class UBDocumentTreeWidget : public QTreeWidget void itemChangedValidation(QTreeWidgetItem * item, int column); + void autoScroll(); + private: UBDocumentProxyTreeItem *mSelectedProxyTi; QTreeWidgetItem *mDropTargetProxyTi; QBrush mBackground; + QTimer* mScrollTimer; + int mScrollMagnitude; };