diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index bd80f275..c70aebd1 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -374,6 +374,7 @@ macx { linux-g++* { CONFIG += link_prl LIBS += -lcrypto + LIBS += -lprofiler LIBS += -lX11 QMAKE_CFLAGS += -fopenmp QMAKE_CXXFLAGS += -fopenmp diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 3071dc82..a97c7635 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -1028,9 +1028,10 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) } else { - if(mUBRubberBand) + if(mUBRubberBand) { mUBRubberBand->hide(); - scene()->setMultipleSelectionProcess(false); + scene()->setMultipleSelectionProcess(false); + } } handleItemMousePress(event); @@ -1107,6 +1108,12 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) void UBBoardView::mouseMoveEvent (QMouseEvent *event) { + static QTime lastCallTime; + if (!lastCallTime.isNull()) { + qDebug() << "time interval is " << lastCallTime.msecsTo(QTime::currentTime()); + } + + QTime mouseMoveTime = QTime::currentTime(); if(!mIsDragInProgress && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) { return; @@ -1153,15 +1160,23 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) mUBRubberBand->setGeometry(bandRect); + QTime startTime = QTime::currentTime(); + QTime testTime = QTime::currentTime(); QList rubberItems = items(bandRect); + qDebug() << "=================="; + qDebug() << "| ====rubber items" << testTime.msecsTo(QTime::currentTime()); + testTime = QTime::currentTime(); foreach (QGraphicsItem *item, mJustSelectedItems) { if (!rubberItems.contains(item)) { item->setSelected(false); mJustSelectedItems.remove(item); } } + qDebug() << "| ===foreach length" << testTime.msecsTo(QTime::currentTime()); + testTime = QTime::currentTime(); - if (currentTool == UBStylusTool::Selector) + int counter = 0; + if (currentTool == UBStylusTool::Selector) { foreach (QGraphicsItem *item, items(bandRect)) { if (item->type() == UBGraphicsW3CWidgetItem::Type @@ -1172,12 +1187,21 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) || item->type() == UBGraphicsStrokesGroup::Type || item->type() == UBGraphicsGroupContainerItem::Type) { + if (!mJustSelectedItems.contains(item)) { + counter++; item->setSelected(true); mJustSelectedItems.insert(item); } + item->setSelected(true); } } + } + + qDebug() << "| ==selected items count" << counter << endl + << "| ==selection time" << testTime.msecsTo(QTime::currentTime()) << endl + << "| =elapsed time " << startTime.msecsTo(QTime::currentTime()) << endl + << "=================="; } } @@ -1211,6 +1235,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) mWidgetMoved = true; + qDebug() << "mouse move time" << mouseMoveTime.msecsTo(QTime::currentTime()); + lastCallTime = QTime::currentTime(); } void @@ -1289,6 +1315,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) if (mUBRubberBand && mUBRubberBand->isVisible()) { mUBRubberBand->hide(); scene()->setMultipleSelectionProcess(false); + scene()->updateMultipleSelectionFrame(); } if (bReleaseIsNeed) @@ -1325,6 +1352,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) if (mRubberBand) { mRubberBand->hide (); scene()->setMultipleSelectionProcess(false); + scene()->updateMultipleSelectionFrame(); } diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 3e8d6acf..f305bc5b 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -179,61 +179,67 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec void UBGraphicsItemDelegate::init() { -// if (mToolBarUsed) -// mToolBarItem = new UBGraphicsToolBarItem(mDelegated); - -// mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); -// mFrame->hide(); -// mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); - -// mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); -// mButtons << mDeleteButton; -// connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); -// if (canDuplicate()){ -// mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); -// connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); -// mButtons << mDuplicateButton; -// } -// mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); -// connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); -// mButtons << mMenuButton; - -// mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); -// mZOrderUpButton->setShowProgressIndicator(true); -// connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); -// connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); -// mButtons << mZOrderUpButton; - -// mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); -// mZOrderDownButton->setShowProgressIndicator(true); -// connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); -// connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); -// mButtons << mZOrderDownButton; - -// buildButtons(); - -// foreach(DelegateButton* button, mButtons) -// { -// if (button->getSection() != Qt::TitleBarArea) -// { -// button->hide(); -// button->setFlag(QGraphicsItem::ItemIsSelectable, true); -// } -// } - -// //Wrapper function. Use it to set correct data() to QGraphicsItem as well -// setFlippable(false); -// setRotatable(false); + //Wrapper function. Use it to set correct data() to QGraphicsItem as well + setFlippable(false); + setRotatable(false); } void UBGraphicsItemDelegate::createControls() { + if (mToolBarUsed) + mToolBarItem = new UBGraphicsToolBarItem(mDelegated); + mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); + mFrame->hide(); + mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); + + mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); + mButtons << mDeleteButton; + connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); + if (canDuplicate()){ + mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); + connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); + mButtons << mDuplicateButton; + } + mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); + connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); + mButtons << mMenuButton; + + mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); + mZOrderUpButton->setShowProgressIndicator(true); + connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); + connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); + mButtons << mZOrderUpButton; + + mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); + mZOrderDownButton->setShowProgressIndicator(true); + connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); + connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); + mButtons << mZOrderDownButton; + + buildButtons(); + + foreach(DelegateButton* button, mButtons) + { + if (button->getSection() != Qt::TitleBarArea) + { + button->hide(); + button->setFlag(QGraphicsItem::ItemIsSelectable, true); + } + } } void UBGraphicsItemDelegate::freeControls() { + QGraphicsScene *controlsScene = delegated()->scene(); + + UB_FREE_CONTROL(mFrame, controlsScene); + UB_FREE_CONTROL(mDeleteButton, controlsScene); + UB_FREE_CONTROL(mMenuButton, controlsScene); + UB_FREE_CONTROL(mZOrderUpButton, controlsScene); + UB_FREE_CONTROL(mZOrderDownButton, controlsScene); + freeButtons(); } @@ -266,15 +272,16 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch } -// if ((change == QGraphicsItem::ItemSelectedHasChanged -// || change == QGraphicsItem::ItemPositionHasChanged -// || change == QGraphicsItem::ItemTransformHasChanged) -// && mDelegated->scene() -// && UBApplication::boardController) -// { -// mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); -// positionHandles(); -// } + if ((change == QGraphicsItem::ItemSelectedHasChanged + || change == QGraphicsItem::ItemPositionHasChanged + || change == QGraphicsItem::ItemTransformHasChanged) + && mDelegated->scene() + && UBApplication::boardController) + { + createControls(); + mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + positionHandles(); + } if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemTransformHasChanged @@ -611,6 +618,9 @@ void UBGraphicsItemDelegate::onZoomChanged() void UBGraphicsItemDelegate::buildButtons() { } +void UBGraphicsItemDelegate::freeButtons() +{ +} void UBGraphicsItemDelegate::decorateMenu(QMenu* menu) { diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 5c892946..31047152 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -24,6 +24,14 @@ #ifndef UBGRAPHICSITEMDELEGATE_H_ #define UBGRAPHICSITEMDELEGATE_H_ +#define UB_FREE_CONTROL(Object, Scene) \ + if (Object) { \ + if (Scene) { \ + Scene->removeItem(Object); \ + } \ + delete Object; \ + } \ + #include #include #include @@ -289,6 +297,7 @@ class UBGraphicsItemDelegate : public QObject protected: virtual void buildButtons(); + virtual void freeButtons(); virtual void decorateMenu(QMenu *menu); virtual void updateMenuActionState(); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 2315b16b..654e6324 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -66,6 +66,7 @@ #include "UBGraphicsPDFItem.h" #include "UBGraphicsTextItem.h" #include "UBGraphicsStrokesGroup.h" +#include "UBSelectionFrame.h" #include "domain/UBGraphicsGroupContainerItem.h" @@ -288,6 +289,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta , mpLastPolygon(NULL) , mCurrentPolygon(0) , mMultipleSelectionProcess(false) + , mSelectionFrame(0) { UBCoreGraphicsScene::setObjectName("BoardScene"); #ifdef __ppc__ @@ -296,7 +298,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta mShouldUseOMP = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5; #endif - setItemIndexMethod(QGraphicsScene::BspTreeIndex); +// setItemIndexMethod(QGraphicsScene::BspTreeIndex); setUuid(QUuid::createUuid()); setDocument(parent); @@ -1032,6 +1034,23 @@ UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRad return polygonToPolygonItem(polygon); } +void UBGraphicsScene::updateMultipleSelectionFrame() +{ + qDebug() << "selected item count" << selectedItems().count(); + QList selItems = selectedItems(); + if (!mSelectionFrame) { + mSelectionFrame = new UBSelectionFrame(); + addItem(mSelectionFrame); + } + + mSelectionFrame->setEnclosedItems(selItems); + if (!mSelectionFrame->isEmpty()) { + mSelectionFrame->setVisible(true); + } else { + mSelectionFrame->setVisible(false); + } +} + UBGraphicsPolygonItem* UBGraphicsScene::polygonToPolygonItem(const QPolygonF pPolygon) { UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pPolygon); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 54bc267f..ce56c86c 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -19,8 +19,6 @@ * along with Open-Sankoré. If not, see . */ - - #ifndef UBGRAPHICSSCENE_H_ #define UBGRAPHICSSCENE_H_ @@ -56,6 +54,7 @@ class UBMagnifierParams; class UBMagnifier; class UBGraphicsCache; class UBGraphicsGroupContainerItem; +class UBSelectionFrame; const double PI = 4.0 * atan(1.0); @@ -312,6 +311,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon); void setMultipleSelectionProcess(bool pEnabled) {mMultipleSelectionProcess = pEnabled;} bool multipleSelectionProcess() const {return mMultipleSelectionProcess;} + void updateMultipleSelectionFrame(); public slots: void initStroke(); @@ -430,6 +430,7 @@ public slots: bool mDrawWithCompass; UBGraphicsPolygonItem *mCurrentPolygon; bool mMultipleSelectionProcess; + UBSelectionFrame *mSelectionFrame; }; diff --git a/src/domain/UBSelectionFrame.cpp b/src/domain/UBSelectionFrame.cpp new file mode 100644 index 00000000..4d7460f3 --- /dev/null +++ b/src/domain/UBSelectionFrame.cpp @@ -0,0 +1,105 @@ +#include "UBSelectionFrame.h" + +#include + +#include "core/UB.h" +#include "domain/UBItem.h" +#include "board/UBBoardController.h" +#include "core/UBSettings.h" +#include "core/UBApplication.h" + +UBSelectionFrame::UBSelectionFrame() + : mThickness(UBSettings::settings()->objectFrameWidth) + , mAntiscaleRatio(1.0) +{ + setLocalBrush(QBrush(UBSettings::paletteColor)); + setPen(Qt::NoPen); + setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + setFlags(QGraphicsItem::ItemIsMovable); + + connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged(qreal))); +} + +void UBSelectionFrame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + QPainterPath path; + QRectF shRect = option->rect; + path.addRoundedRect(shRect, mThickness / 2, mThickness / 2); + + if (rect().width() > 1 && rect().height() > 1) { + QPainterPath extruded; + extruded.addRect(shRect.adjusted(mThickness, mThickness, (mThickness * -1), (mThickness * -1))); + path = path.subtracted(extruded); + } + + painter->fillPath(path, mLocalBrush); +} + +QRectF UBSelectionFrame::boundingRect() const +{ + return rect().adjusted(-mThickness, -mThickness, mThickness, mThickness); +} + +QPainterPath UBSelectionFrame::shape() const +{ + QPainterPath resShape; + QRectF ownRect = rect(); + QRectF shRect = ownRect.adjusted(-mThickness, -mThickness, mThickness, mThickness); + resShape.addRoundedRect(shRect, mThickness / 2, mThickness / 2); + + if (rect().width() > 1 && rect().height() > 1) { + QPainterPath extruded; + extruded.addRect(ownRect); + resShape = resShape.subtracted(extruded); + } + + return resShape; +} + +void UBSelectionFrame::setEnclosedItems(const QList pGraphicsItems) +{ + QRectF resultRect; + mEnclosedtems.clear(); + foreach (QGraphicsItem *nextItem, pGraphicsItems) { + UBGraphicsItemDelegate *nextDelegate = UBGraphicsItem::Delegate(nextItem); + if (nextDelegate) { + mEnclosedtems.append(nextDelegate); + resultRect |= nextItem->boundingRect(); + } + } + + setRect(resultRect); + + if (resultRect.isEmpty()) { + hide(); + } +} + +void UBSelectionFrame::updateRect() +{ + QRectF result; + foreach (UBGraphicsItemDelegate *curDelegateItem, mEnclosedtems) { + result |= curDelegateItem->delegated()->boundingRect(); + } + + setRect(result); + + if (result.isEmpty()) { + setVisible(false); + } +} + +void UBSelectionFrame::updateScale() +{ + setScale(-UBApplication::boardController->currentZoom()); +} + +void UBSelectionFrame::onZoomChanged(qreal pZoom) +{ + mAntiscaleRatio = pZoom; + updateScale(); + +} diff --git a/src/domain/UBSelectionFrame.h b/src/domain/UBSelectionFrame.h new file mode 100644 index 00000000..809cdde6 --- /dev/null +++ b/src/domain/UBSelectionFrame.h @@ -0,0 +1,39 @@ +#ifndef UBSELECTIONFRAME_H +#define UBSELECTIONFRAME_H + +#include +#include + +class UBGraphicsItemDelegate; + +class UBSelectionFrame : public QObject, public QGraphicsRectItem +{ + Q_OBJECT + +public: + UBSelectionFrame(); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QRectF boundingRect() const; + QPainterPath shape() const; + + void setLocalBrush(const QBrush &pBrush) {mLocalBrush = pBrush;} + QBrush localBrush() const {return mLocalBrush;} + void setEnclosedItems(const QList pEncItems) {mEnclosedtems = pEncItems; updateRect();} + void setEnclosedItems(const QList pGraphicsItems); + void updateRect(); + void updateScale(); + bool isEmpty() const {return this->rect().isEmpty();} + +private slots: + void setAntiScaleRatio(qreal pAntiscaleRatio) {mAntiscaleRatio = pAntiscaleRatio;} + void onZoomChanged(qreal pZoom); + +private: + int mThickness; + qreal mAntiscaleRatio; + QList mEnclosedtems; + QBrush mLocalBrush; +}; + +#endif // UBSELECTIONFRAME_H diff --git a/src/domain/domain.pri b/src/domain/domain.pri index bb3751e4..f2d149c6 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -24,7 +24,8 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsTextItemDelegate.h \ src/domain/UBGraphicsDelegateFrame.h \ src/domain/UBGraphicsWidgetItemDelegate.h \ - src/domain/UBGraphicsMediaItemDelegate.h + src/domain/UBGraphicsMediaItemDelegate.h \ + src/domain/UBSelectionFrame.h SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsItemUndoCommand.cpp \ @@ -53,4 +54,5 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsTextItemDelegate.cpp \ src/domain/UBGraphicsMediaItemDelegate.cpp \ src/domain/UBGraphicsDelegateFrame.cpp \ - src/domain/UBGraphicsWidgetItemDelegate.cpp + src/domain/UBGraphicsWidgetItemDelegate.cpp \ + src/domain/UBSelectionFrame.cpp