From cf024b21872d36062790662ea3de6d1786c9e8a8 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 3 Apr 2012 18:50:40 +0300 Subject: [PATCH 01/18] Triangle behaviour fix --- src/board/UBBoardView.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index e9ffde4d..e1d1f0b2 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -54,6 +54,7 @@ #include "tools/UBGraphicsCompass.h" #include "tools/UBGraphicsCache.h" +#include "tools/UBGraphicsTriangle.h" #include "core/memcheck.h" @@ -425,7 +426,8 @@ UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsCompass::Type || movingItem->type() == UBGraphicsPDFItem::Type || movingItem->type() == UBGraphicsPolygonItem::Type - || movingItem->type() == UBGraphicsCache::Type) + || movingItem->type() == UBGraphicsCache::Type + || movingItem->type() == UBGraphicsTriangle::Type) { movingItem = NULL; QGraphicsView::mousePressEvent (event); From 9745c5d058e7d69c09fc9256ff35d47136f85909 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 3 Apr 2012 19:24:32 +0300 Subject: [PATCH 02/18] Fixed for correctly work on 3 platforms. --- plugins/cffadaptor/UBCFFAdaptor.pro | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/cffadaptor/UBCFFAdaptor.pro b/plugins/cffadaptor/UBCFFAdaptor.pro index 78f1bf71..36ef90fe 100644 --- a/plugins/cffadaptor/UBCFFAdaptor.pro +++ b/plugins/cffadaptor/UBCFFAdaptor.pro @@ -10,14 +10,16 @@ linux-g++: SUB_DIR = linux linux-g++-32: SUB_DIR = linux linux-g++-64: SUB_DIR = linux -QUAZIP_DIR = "$$PWD/../../../Sankore-ThirdParty/quazip" -ZLIB_DIR = "$$PWD/../../../Sankore-ThirdParty/zlib" +THIRD_PARTY_PATH = ../../../Sankore-ThirdParty +QUAZIP_DIR = "$$PWD/../../../Sankore-ThirdParty/quazip/quazip-0.3" -INCLUDEPATH += src \ - "$$QUAZIP_DIR/quazip-0.3" \ - "$$ZLIB_DIR/1.2.3/include" +INCLUDEPATH += src -LIBS += "-L$$QUAZIP_DIR/lib/$$SUB_DIR" "-lquazip" +DEPENDPATH += $$THIRD_PARTY_PATH/quazip/ +INCLUDEPATH += $$THIRD_PARTY_PATH/quazip/ +include($$THIRD_PARTY_PATH/quazip/quazip.pri) + +LIBS += "-L$$THIRD_PARTY_PATH/quazip/lib/$$SUB_DIR" "-lquazip" QT += xml xmlpatterns core QT += gui From 1e67bf6e4a4a3371f14b69860adfd35ce3436d54 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 3 Apr 2012 19:44:34 +0300 Subject: [PATCH 03/18] SANKORE-475 Improve the rendering of the magnifier --- src/board/UBBoardController.cpp | 5 +- src/desktop/UBDesktopAnnotationController.cpp | 1 + src/domain/UBGraphicsScene.cpp | 64 +- src/domain/UBGraphicsScene.h | 7 +- src/gui/UBMagnifer.cpp | 790 +++++++++--------- src/gui/UBMagnifer.h | 193 ++--- 6 files changed, 571 insertions(+), 489 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 961a2dc3..4b54b76b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -664,6 +664,7 @@ void UBBoardController::zoom(const qreal ratio, QPointF scenePoint) UBApplication::applicationController->adjustDisplayView(); emit controlViewportChanged(); + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11()); } @@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, mControlView->setScene(mActiveScene); mDisplayView->setScene(mActiveScene); - + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11()); pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize()); updatePageSizeState(); @@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor() mControlView->setTransform(scalingTransform); mControlView->horizontalScrollBar()->setValue(viewState.horizontalPosition); mControlView->verticalScrollBar()->setValue(viewState.verticalPostition); -} + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());} void UBBoardController::setWidePageSize(bool checked) diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index 9cb92e4b..1f27f607 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent) mTransparentDrawingScene = new UBGraphicsScene(0); mTransparentDrawingView->setScene(mTransparentDrawingScene); + mTransparentDrawingScene->setDrawingMode(true); // mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView); //mRightPalette = new UBRightPalette(mTransparentDrawingView); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index bbd4af62..6f7f4d77 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -135,6 +135,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) , enableUndoRedoStack(true) , magniferControlViewWidget(0) , magniferDisplayViewWidget(0) + , mIsDesktopMode(false) { @@ -160,8 +161,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) UBGraphicsScene::~UBGraphicsScene() { - DisposeMagnifierQWidgets(); - if (mCurrentStroke) if (mCurrentStroke->polygons().empty()) delete mCurrentStroke; @@ -711,6 +710,15 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) } } +void UBGraphicsScene::setBackgroundZoomFactor(qreal zoom) +{ + mZoomFactor = zoom; +} + +void UBGraphicsScene::setDrawingMode(bool bModeDesktop) +{ + mIsDesktopMode = bModeDesktop; +} void UBGraphicsScene::recolorAllItems() { @@ -1854,6 +1862,58 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems, } } +void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) +{ + if (mIsDesktopMode) + { + QGraphicsScene::drawBackground (painter, rect); + return; + } + bool darkBackground = isDarkBackground (); + + if (darkBackground) + { + painter->fillRect (rect, QBrush (QColor (Qt::black))); + } + else + { + painter->fillRect (rect, QBrush (QColor (Qt::white))); + } + + if (mZoomFactor > 0.5) + { + QColor bgCrossColor; + + if (darkBackground) + bgCrossColor = UBSettings::crossDarkBackground; + else + bgCrossColor = UBSettings::crossLightBackground; + if (mZoomFactor < 1.0) + { + int alpha = 255 * mZoomFactor / 2; + bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms + } + + painter->setPen (bgCrossColor); + + if (isCrossedBackground()) + { + qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; + + for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) + { + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + } + + qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; + + for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) + { + painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); + } + } + } +} void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 8fa84053..1cdd37e4 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -288,7 +288,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void hideEraser(); void setBackground(bool pIsDark, bool pIsCrossed); - + void setBackgroundZoomFactor(qreal zoom); + void setDrawingMode(bool bModeDesktop); void deselectAllItems(); UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false); @@ -331,6 +332,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem QGraphicsItem* rootItem(QGraphicsItem* item) const; + virtual void drawBackground(QPainter *painter, const QRectF &rect); + private: void setDocumentUpdated(); void createEraiser(); @@ -348,6 +351,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem bool mDarkBackground; bool mCrossedBackground; + bool mIsDesktopMode; + qreal mZoomFactor; bool mIsModified; diff --git a/src/gui/UBMagnifer.cpp b/src/gui/UBMagnifer.cpp index 08285c91..93693797 100644 --- a/src/gui/UBMagnifer.cpp +++ b/src/gui/UBMagnifer.cpp @@ -1,388 +1,402 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include "UBMagnifer.h" - -#include "core/UBApplication.h" -#include "board/UBBoardController.h" -#include "domain/UBGraphicsScene.h" - -#include "core/memcheck.h" - - -UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) - : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) - , mShouldMoveWidget(false) - , mShouldResizeWidget(false) - , inTimer(false) - , borderPen(Qt::darkGray) - , gView(0) - , mView(0) -{ - isCusrsorAlreadyStored = false; - setMouseTracking(true); - - //--------------------------------------------------// - - QPixmap pix(":/images/cursors/resize.png"); - QTransform tr; - tr.rotate(45); - mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); - - //--------------------------------------------------// - - params.sizePercentFromScene = 20; - m_isInteractive = isInteractive; - sClosePixmap = new QPixmap(":/images/close.svg"); - sIncreasePixmap = new QPixmap(":/images/increase.svg"); - sDecreasePixmap = new QPixmap(":/images/decrease.svg"); - mResizeItem = new QPixmap(":/images/resize.svg"); - - if (parent) - { - setAttribute(Qt::WA_NoMousePropagation); - } - else - { - // standalone window - // !!!! Should be included into Windows after QT recompilation -#ifndef Q_WS_WIN -// setAttribute(Qt::WA_TranslucentBackground); - setAttribute(Qt::WA_MacAlwaysShowToolWindow); -#endif -#ifdef Q_WS_MAC - setAttribute(Qt::WA_MacAlwaysShowToolWindow); - setAttribute(Qt::WA_MacNonActivatingToolWindow); - setAttribute(Qt::WA_MacNoShadow); -#endif - } - -} - -UBMagnifier::~UBMagnifier() -{ - if (timerUpdate != 0) - { - killTimer(timerUpdate); - timerUpdate = 0; - } - - if(sClosePixmap) - { - delete sClosePixmap; - sClosePixmap = NULL; - } - - if(sIncreasePixmap) - { - delete sIncreasePixmap; - sIncreasePixmap = NULL; - } - - if(sDecreasePixmap) - { - delete sDecreasePixmap; - sDecreasePixmap = NULL; - } -} - -void UBMagnifier::setSize(qreal percentFromScene) -{ - if(gView == NULL || mView == NULL) return; - - // calculate object size - params.sizePercentFromScene = percentFromScene; - QSize sceneSize = mView->size(); - qreal size = params.sizePercentFromScene * sceneSize.width() / 100; - - QRect currGeom = geometry(); - if(currGeom.width() == currGeom.height()) - { - QPoint newPos = mView->mapFromGlobal(updPointMove); - setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); - } - else - setGeometry(0, 0, size, size); - - // prepare transparent bit mask - QImage mask_img(width(), height(), QImage::Format_Mono); - mask_img.fill(0xff); - QPainter mask_ptr(&mask_img); - mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); - mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); - bmpMask = QBitmap::fromImage(mask_img); - - // prepare general image - pMap = QPixmap(width(), height()); - pMap.fill(Qt::transparent); - pMap.setMask(bmpMask); -} - -void UBMagnifier::setZoom(qreal zoom) -{ - params.zoom = zoom; -} - -void UBMagnifier::paintEvent(QPaintEvent * event) -{ - Q_UNUSED(event); - QPainter painter(this); - - painter.setRenderHint(QPainter::Antialiasing); - painter.setPen(Qt::NoPen); - - if (m_isInteractive) - { - painter.setBrush(QColor(127, 127, 127, 127)); - painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); - - painter.setBrush(QColor(190, 190, 190, 255)); - painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); - - painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); - painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); - painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); - - painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); - } - else - { - painter.setBrush(QColor(127, 127, 127, 127)); - painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); - } - - painter.drawPixmap(0, 0, pMap); -} - -void UBMagnifier::mousePressEvent ( QMouseEvent * event ) -{ - if(m_isInteractive) - { - - QWidget::mousePressEvent(event); - - if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && - event->pos().x() < size().width() - 20 && - event->pos().y() >= size().height() - mResizeItem->height() - 20 && - event->pos().y() < size().height() - - 20) - { - mShouldResizeWidget = true; - } - else - { - mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); - } - - mMousePressPos = event->pos(); - mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); - - event->accept(); - - update(); - } - else - event->ignore(); -} - -void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) -{ - if(m_isInteractive) - { - if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) - { - move(pos() - mMousePressPos + event->pos()); - event->accept(); - - QWidget::mouseMoveEvent(event); - emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); - return; - } - - if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) - { - - QPoint currGlobalPos = event->globalPos(); - qreal cvW = mView->width(); - - qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; - qreal newPercentSize = newXSize * 100 / cvW; - - emit magnifierResized_Signal(newPercentSize); - - event->ignore(); - return; - } - - if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && - event->pos().x() < size().width() - 20 && - event->pos().y() >= size().height() - mResizeItem->height() - 20 && - event->pos().y() < size().height() - - 20 && - isCusrsorAlreadyStored == false - ) - { - mOldCursor = cursor(); - isCusrsorAlreadyStored = true; - setCursor(mResizeCursor); - } - - } - else - event->ignore(); -} - - -void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) -{ - if(m_isInteractive) - { - mShouldMoveWidget = false; - mShouldResizeWidget = false; - - if (event->pos().x() >= size().width() - sClosePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 && - event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) - { - event->accept(); - emit magnifierClose_Signal(); - } - else - if (event->pos().x() >= size().width() - sIncreasePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 && - event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) - { - event->accept(); - emit magnifierZoomIn_Signal(); - } - else - if (event->pos().x() >= size().width() - sDecreasePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 && - event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) - { - event->accept(); - emit magnifierZoomOut_Signal(); - } - else - QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool - } - else - event->ignore(); - -} - -void UBMagnifier::timerEvent(QTimerEvent *e) -{ - if(inTimer) return; - if (e->timerId() == timerUpdate) - { - inTimer = true; - if(!(updPointGrab.isNull())) - grabPoint(updPointGrab); - - if(isCusrsorAlreadyStored) - { - QPoint globalCursorPos = QCursor::pos(); - QPoint cursorPos = mapFromGlobal(globalCursorPos); - if (cursorPos.x() < size().width() - mResizeItem->width() - 20 || - cursorPos.x() > size().width() - 20 || - cursorPos.y() < size().height() - mResizeItem->height() - 20 || - cursorPos.y() > size().height() - - 20 - ) - { - isCusrsorAlreadyStored = false; - setCursor(mOldCursor); - } - - } - - inTimer = false; - } -} - -void UBMagnifier::grabPoint() -{ - QPointF itemPos = gView->mapFromGlobal(updPointGrab); - - qreal zWidth = size().width() / params.zoom; - qreal zWidthHalf = zWidth / 2; - qreal zHeight = size().height() / params.zoom; - qreal zHeightHalf = zHeight / 2; - - int x = itemPos.x() - zWidthHalf; - int y = itemPos.y() - zHeightHalf; - - QPixmap newPixMap(QSize(zWidth,zHeight)); - ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); - UBApplication::boardController->activeScene()->update(); - - pMap.fill(Qt::transparent); - pMap = newPixMap.scaled(QSize(width(), height())); - pMap.setMask(bmpMask); - - update(); -} - -void UBMagnifier::grabPoint(const QPoint &pGrab) -{ - updPointGrab = pGrab; - QPointF itemPos = gView->mapFromGlobal(pGrab); - - qreal zWidth = size().width() / params.zoom; - qreal zWidthHalf = zWidth / 2; - qreal zHeight = size().height() / params.zoom; - qreal zHeightHalf = zHeight / 2; - - int x = itemPos.x() - zWidthHalf; - int y = itemPos.y() - zHeightHalf; - - QPixmap newPixMap(QSize(zWidth,zHeight)); - ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); - UBApplication::boardController->activeScene()->update(); - - pMap.fill(Qt::transparent); - pMap = newPixMap.scaled(QSize(width(), height())); - pMap.setMask(bmpMask); - - update(); -} - -// from global -void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) -{ - updPointGrab = pGrab; - updPointMove = pMove; - - if(needGrab) - grabPoint(pGrab); - - if(needMove) - { - QPoint movePos = mView->mapFromGlobal(pMove); - move(movePos.x() - width()/2, movePos.y() - height()/2); - // move(itemPos.x(), itemPos.y()); - } -} - -void UBMagnifier::setGrabView(QWidget *view) -{ - if (timerUpdate != 0) - killTimer(timerUpdate); - gView = view; - timerUpdate = startTimer(200); -} - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "UBMagnifer.h" + +#include "core/UBApplication.h" +#include "board/UBBoardController.h" +#include "domain/UBGraphicsScene.h" +#include "board/UBBoardView.h" + +#include "core/memcheck.h" + + +UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) + : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) + , mShouldMoveWidget(false) + , mShouldResizeWidget(false) + , borderPen(Qt::darkGray) + , gView(0) + , mView(0) +{ + isCusrsorAlreadyStored = false; + setMouseTracking(true); + + //--------------------------------------------------// + + QPixmap pix(":/images/cursors/resize.png"); + QTransform tr; + tr.rotate(45); + mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); + + //--------------------------------------------------// + + params.sizePercentFromScene = 20; + m_isInteractive = isInteractive; + sClosePixmap = new QPixmap(":/images/close.svg"); + sIncreasePixmap = new QPixmap(":/images/increase.svg"); + sDecreasePixmap = new QPixmap(":/images/decrease.svg"); + mResizeItem = new QPixmap(":/images/resize.svg"); + + if (parent) + { + setAttribute(Qt::WA_NoMousePropagation); + } + else + { + // standalone window + // !!!! Should be included into Windows after QT recompilation +#ifndef Q_WS_WIN +// setAttribute(Qt::WA_TranslucentBackground); + setAttribute(Qt::WA_MacAlwaysShowToolWindow); +#endif +#ifdef Q_WS_MAC + setAttribute(Qt::WA_MacAlwaysShowToolWindow); + setAttribute(Qt::WA_MacNonActivatingToolWindow); + setAttribute(Qt::WA_MacNoShadow); +#endif + } + + connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh())); +} + +UBMagnifier::~UBMagnifier() +{ + if(sClosePixmap) + { + delete sClosePixmap; + sClosePixmap = NULL; + } + + if(sIncreasePixmap) + { + delete sIncreasePixmap; + sIncreasePixmap = NULL; + } + + if(sDecreasePixmap) + { + delete sDecreasePixmap; + sDecreasePixmap = NULL; + } +} + +void UBMagnifier::setSize(qreal percentFromScene) +{ + if(gView == NULL || mView == NULL) return; + + // calculate object size + params.sizePercentFromScene = percentFromScene; + QSize sceneSize = mView->size(); + qreal size = params.sizePercentFromScene * sceneSize.width() / 100; + + QRect currGeom = geometry(); + if(currGeom.width() == currGeom.height()) + { + QPoint newPos = mView->mapFromGlobal(updPointMove); + setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); + } + else + setGeometry(0, 0, size, size); + + // prepare transparent bit mask + QImage mask_img(width(), height(), QImage::Format_Mono); + mask_img.fill(0xff); + QPainter mask_ptr(&mask_img); + mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); + mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); + bmpMask = QBitmap::fromImage(mask_img); + + // prepare general image + pMap = QPixmap(width(), height()); + pMap.fill(Qt::transparent); + pMap.setMask(bmpMask); +} + +void UBMagnifier::setZoom(qreal zoom) +{ + params.zoom = zoom; +} + +void UBMagnifier::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + QPainter painter(this); + + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::NoPen); + + if (m_isInteractive) + { + painter.setBrush(QColor(127, 127, 127, 127)); + painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); + + painter.setBrush(QColor(190, 190, 190, 255)); + painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); + + painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); + painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); + painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); + + painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); + } + else + { + painter.setBrush(QColor(127, 127, 127, 127)); + painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); + } + + painter.drawPixmap(0, 0, pMap); +} + +void UBMagnifier::mousePressEvent ( QMouseEvent * event ) +{ + if(m_isInteractive) + { + + QWidget::mousePressEvent(event); + + if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && + event->pos().x() < size().width() - 20 && + event->pos().y() >= size().height() - mResizeItem->height() - 20 && + event->pos().y() < size().height() - - 20) + { + mShouldResizeWidget = true; + } + else + { + mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); + } + + mMousePressPos = event->pos(); + mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); + + event->accept(); + + update(); + } + else + event->ignore(); +} + +void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) +{ + if(m_isInteractive) + { + if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) + { + move(pos() - mMousePressPos + event->pos()); + event->accept(); + + QWidget::mouseMoveEvent(event); + emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); + return; + } + + if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) + { + + QPoint currGlobalPos = event->globalPos(); + qreal cvW = mView->width(); + + qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; + qreal newPercentSize = newXSize * 100 / cvW; + + emit magnifierResized_Signal(newPercentSize); + + event->ignore(); + return; + } + + if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && + event->pos().x() < size().width() - 20 && + event->pos().y() >= size().height() - mResizeItem->height() - 20 && + event->pos().y() < size().height() - - 20 && + isCusrsorAlreadyStored == false + ) + { + mOldCursor = cursor(); + isCusrsorAlreadyStored = true; + setCursor(mResizeCursor); + } + + } + else + event->ignore(); +} + + +void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) +{ + if(m_isInteractive) + { + mShouldMoveWidget = false; + mShouldResizeWidget = false; + + if (event->pos().x() >= size().width() - sClosePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 && + event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) + { + event->accept(); + emit magnifierClose_Signal(); + } + else + if (event->pos().x() >= size().width() - sIncreasePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 && + event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) + { + event->accept(); + emit magnifierZoomIn_Signal(); + } + else + if (event->pos().x() >= size().width() - sDecreasePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 && + event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) + { + event->accept(); + emit magnifierZoomOut_Signal(); + } + else + QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool + } + else + event->ignore(); + +} + +void UBMagnifier::slot_refresh() +{ + if(!(updPointGrab.isNull())) + grabPoint(updPointGrab); + + if(isCusrsorAlreadyStored) + { + QPoint globalCursorPos = QCursor::pos(); + QPoint cursorPos = mapFromGlobal(globalCursorPos); + if (cursorPos.x() < size().width() - mResizeItem->width() - 20 || + cursorPos.x() > size().width() - 20 || + cursorPos.y() < size().height() - mResizeItem->height() - 20 || + cursorPos.y() > size().height() - - 20 + ) + { + isCusrsorAlreadyStored = false; + setCursor(mOldCursor); + } + } +} + +void UBMagnifier::grabPoint() +{ + QMatrix transM = UBApplication::boardController->controlView()->matrix(); + QPointF itemPos = gView->mapFromGlobal(updPointGrab); + + qreal zWidth = width() / (params.zoom * transM.m11()); + qreal zWidthHalf = zWidth / 2; + qreal zHeight = height() / (params.zoom * transM.m22()); + qreal zHeightHalf = zHeight / 2; + + + QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); + + + QRect magnifierRect = rect(); + + float x = pfScLtF.x() - zWidthHalf; + float y = pfScLtF.y() - zHeightHalf; + + QPointF leftTop(x,y); + QPointF rightBottom(x + zWidth, y + zHeight); + QRectF srcRect(leftTop, rightBottom); + + QPixmap newPixMap(QSize(width(), height())); + QPainter painter(&newPixMap); + + UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); + painter.end(); + + pMap.fill(Qt::transparent); + pMap = newPixMap.scaled(QSize(width(), height())); + pMap.setMask(bmpMask); + + update(); +} + +void UBMagnifier::grabPoint(const QPoint &pGrab) +{ + QMatrix transM = UBApplication::boardController->controlView()->matrix(); + updPointGrab = pGrab; + QPointF itemPos = gView->mapFromGlobal(pGrab); + + qreal zWidth = width() / (params.zoom * transM.m11()); + qreal zWidthHalf = zWidth / 2; + qreal zHeight = height() / (params.zoom * transM.m22()); + qreal zHeightHalf = zHeight / 2; + + + QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); + + + QRect magnifierRect = rect(); + + float x = pfScLtF.x() - zWidthHalf; + float y = pfScLtF.y() - zHeightHalf; + + QPointF leftTop(x,y); + QPointF rightBottom(x + zWidth, y + zHeight); + QRectF srcRect(leftTop, rightBottom); + + QPixmap newPixMap(QSize(width(), height())); + QPainter painter(&newPixMap); + + UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); + painter.end(); + + // pMap.fill(Qt::transparent); + pMap = newPixMap; + pMap.setMask(bmpMask); + + update(); +} + + + +// from global +void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) +{ + updPointGrab = pGrab; + updPointMove = pMove; + + if(needGrab) + grabPoint(pGrab); + + if(needMove) + { + QPoint movePos = mView->mapFromGlobal(pMove); + move(movePos.x() - width()/2, movePos.y() - height()/2); + // move(itemPos.x(), itemPos.y()); + } +} + +void UBMagnifier::setGrabView(QWidget *view) +{ + gView = view; + mRefreshTimer.setInterval(40); + mRefreshTimer.start(); +} + diff --git a/src/gui/UBMagnifer.h b/src/gui/UBMagnifer.h index 73a81692..7a118a99 100644 --- a/src/gui/UBMagnifer.h +++ b/src/gui/UBMagnifer.h @@ -1,96 +1,97 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UBMAGNIFIER_H -#define UBMAGNIFIER_H - -#include - -class UBMagnifierParams -{ -public : - int x; - int y; - qreal zoom; - qreal sizePercentFromScene; -}; - -class UBMagnifier : public QWidget -{ - Q_OBJECT - -public: - UBMagnifier(QWidget *parent = 0, bool isInteractive = false); - ~UBMagnifier(); - - void setSize(qreal percentFromScene); - void setZoom(qreal zoom); - - void setGrabView(QWidget *view); - void setMoveView(QWidget *view) {mView = view;} - - void grabPoint(); - void grabPoint(const QPoint &point); - void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); - - UBMagnifierParams params; - -signals: - void magnifierMoved_Signal(QPoint newPos); - void magnifierClose_Signal(); - void magnifierZoomIn_Signal(); - void magnifierZoomOut_Signal(); - void magnifierResized_Signal(qreal newPercentSize); - -protected: - void paintEvent(QPaintEvent *); - void timerEvent(QTimerEvent *); - - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent * event ); - virtual void mouseReleaseEvent ( QMouseEvent * event ); - - QPoint mMousePressPos; - qreal mMousePressDelta; - bool mShouldMoveWidget; - bool mShouldResizeWidget; - - - QPixmap *sClosePixmap; - QPixmap *sIncreasePixmap; - QPixmap *sDecreasePixmap; - QPixmap *mResizeItem; - - bool isCusrsorAlreadyStored; - QCursor mOldCursor; - QCursor mResizeCursor; - -private: - bool inTimer; - bool m_isInteractive; - - int timerUpdate; - QPoint updPointGrab; - QPoint updPointMove; - - QPixmap pMap; - QBitmap bmpMask; - QPen borderPen; - - QWidget *gView; - QWidget *mView; -}; - -#endif // UBMAGNIFIER_H +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef UBMAGNIFIER_H +#define UBMAGNIFIER_H + +#include + +class UBMagnifierParams +{ +public : + int x; + int y; + qreal zoom; + qreal sizePercentFromScene; +}; + +class UBMagnifier : public QWidget +{ + Q_OBJECT + +public: + UBMagnifier(QWidget *parent = 0, bool isInteractive = false); + ~UBMagnifier(); + + void setSize(qreal percentFromScene); + void setZoom(qreal zoom); + + void setGrabView(QWidget *view); + void setMoveView(QWidget *view) {mView = view;} + + void grabPoint(); + void grabPoint(const QPoint &point); + void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); + + UBMagnifierParams params; + +signals: + void magnifierMoved_Signal(QPoint newPos); + void magnifierClose_Signal(); + void magnifierZoomIn_Signal(); + void magnifierZoomOut_Signal(); + void magnifierResized_Signal(qreal newPercentSize); + +public slots: + void slot_refresh(); + +protected: + void paintEvent(QPaintEvent *); + + virtual void mousePressEvent ( QMouseEvent * event ); + virtual void mouseMoveEvent ( QMouseEvent * event ); + virtual void mouseReleaseEvent ( QMouseEvent * event ); + + QPoint mMousePressPos; + qreal mMousePressDelta; + bool mShouldMoveWidget; + bool mShouldResizeWidget; + + + QPixmap *sClosePixmap; + QPixmap *sIncreasePixmap; + QPixmap *sDecreasePixmap; + QPixmap *mResizeItem; + + bool isCusrsorAlreadyStored; + QCursor mOldCursor; + QCursor mResizeCursor; + +private: + QTimer mRefreshTimer; + bool m_isInteractive; + + QPoint updPointGrab; + QPoint updPointMove; + + QPixmap pMap; + QBitmap bmpMask; + QPen borderPen; + + QWidget *gView; + QWidget *mView; +}; + +#endif // UBMAGNIFIER_H From fc8e70f193e7215c73a4077e8275db6856989970 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 4 Apr 2012 09:26:06 +0200 Subject: [PATCH 04/18] fixed cffexport library path --- Sankore_3.1.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index 7f87beca..a630e889 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -131,7 +131,7 @@ win32 { } macx { - LIBS += "-Lplugins/cffadaptor/lib/mac" "-lCFF_Adaptor" + LIBS += "-Lplugins/cffadaptor/lib/macx" "-lCFF_Adaptor" LIBS += -framework Foundation LIBS += -lcrypto LIBS += -framework AppKit From aad810506c118ce04a48cffc7d739ba6ff5ab45f Mon Sep 17 00:00:00 2001 From: Didier Clerc Date: Wed, 4 Apr 2012 16:02:18 +0200 Subject: [PATCH 05/18] wording --- .../Choisir.wgt/scripts/languages.js | 26 +++++++++---------- .../locales/fr/js/script.js | 4 +-- .../locales/fr/js/script.js | 6 ++--- .../locales/fr/js/script.js | 6 ++--- .../locales/fr/js/script.js | 6 ++--- .../etudier.wgt/locales/fr/js/script.js | 6 ++--- .../locales/fr/script/template2.js | 4 +-- .../locales/fr/scripts/template2.js | 4 +-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/resources/library/interactivities/Choisir.wgt/scripts/languages.js b/resources/library/interactivities/Choisir.wgt/scripts/languages.js index af618b41..071f5c67 100644 --- a/resources/library/interactivities/Choisir.wgt/scripts/languages.js +++ b/resources/library/interactivities/Choisir.wgt/scripts/languages.js @@ -49,23 +49,23 @@ var sankoreLang = { "edit": "Modifier", "display":"Afficher", "question":"La question", - "example_question":"Ceci est un exemple de la question", - "answer":"Ceci est un exemple de la réponse", + "example_question":"Ceci est un exemple de question", + "answer":"Ceci est un exemple de réponse", "q":"Q", - "add_new_question":"Ajouter nouvelle question ...", - "options":"Les options", + "add_new_question":"Ajouter une nouvelle question ...", + "options":"Options", "close":"Fermer", "delete_question":"Supprimer la question", - "delete_answer":"Supprimer réponse", + "delete_answer":"Supprimer la possibilité", "right_answer":"Bonne réponse", - "template_question":"Saisissez votre question ici ...", - "template_answer":"Entrez la réponse ici ...", - "add_answer":"Ajouter une réponse", - "select_text":"Choisissez la bonne réponse", - "options_desc":"Vous pouvez choisir n'importe lequel de ces trois options d'affichage de vos réponses. Voir un court leur description.", - "radio_desc":"Cette option permet de choisir une seule réponse et les réponses sont affichées sous forme de boutons radio.", - "checkbox_desc":"Cette option permet de choisir plusieurs réponses et les réponses sont affichées comme des cases à cocher.", - "select_desc":"Cette option permet de choisir une seule réponse et les réponses sont affichées sous forme de menu déroulant.", + "template_question":"Saisir la question ici ...", + "template_answer":"Saisir la réponse ici ...", + "add_answer":"Ajouter une possibilité", + "select_text":"Choisir la bonne réponse", + "options_desc":"Types de questions", + "radio_desc":"Option 1 : une seule bonne réponse, les possibilités sont affichées sous forme de boutons radio.", + "checkbox_desc":"Option 2 : plusieurs bonnes réponses, les possibilités sont affichées sous forme de cases à cocher.", + "select_desc":"Option 3 : une seule bonne réponse, les possibilités sont affichées sous forme de menu déroulant.", "a":"R" } }; diff --git a/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js b/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js index eeea8c90..d535038b 100644 --- a/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "Affichage", + display: "Afficher", edit: "Modifier", short_desc: "Sélectionner le numéro «trois».", add: "Nouveau bloc", - enter: "Saisissez la consigne ici ..." + enter: "Saisir la consigne ici ..." }; //main function diff --git a/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js b/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js index 372b4096..26f4b7e2 100644 --- a/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", - short_desc: "Combien de signaux entendez-vous?", + short_desc: "Combien de signaux sonores entendez-vous?", add: "Nouveau bloc", - enter: "Entrez votre description ici ..." + enter: "Saisir votre description ici ..." }; //main function diff --git a/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js b/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js index 58d96a0f..f0f8b5e1 100644 --- a/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", first_desc: "Les nombres impairs", - second_desc: "Même les chiffres", - enter: "Entrez votre nom de la catégorie ici ...", + second_desc: "Les nombres pairs", + enter: "Saisir le nom de la catégorie ici ...", add: "Nouveau bloc" }; diff --git a/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js b/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js index 98619403..01ec59dc 100644 --- a/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js @@ -1,14 +1,14 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", first_desc: "Fruits", second_desc: "Légumes", - potatoes: "Pommes de terre", + potatoes: "Pomme de terre", carrot: "Carotte", onion: "Oignon", apple: "Pomme", pear: "Poire", - enter: "Entrez votre nom de la catégorie ici ...", + enter: "Saisir le nom de la catégorie ici ...", add: "Nouveau bloc", text: "Texte" }; diff --git a/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js b/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js index 92e22585..d0660316 100644 --- a/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", - text_content: "Ceci est un exemple. Au lieu de ce texte, vous pouvez mettre votre propre contenu.", + text_content: "Ceci est un exemple. Au lieu de ce texte, vous pouvez saisir votre propre texte ou glisser-dŽposer une image, un son.", new_txt: "Nouveau bloc de texte", - new_slide: "C'est une nouvelle diapositive." + new_slide: "Ceci est une nouvelle diapositive." }; //some flags diff --git a/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js b/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js index 14759a5e..717a36c5 100644 --- a/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js +++ b/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js @@ -26,9 +26,9 @@ function checkResponse() */ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", - example: "il\ns'agit\nd'une\nphrase\nd'exemple" + example: "Cette phrase\nest un\nexemple." }; diff --git a/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js b/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js index 320953b2..9418604a 100644 --- a/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js +++ b/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js @@ -27,9 +27,9 @@ function checkResponse() */ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", - example: "une*longue*,*il*ya*bien*longtemps*..." + example: "Il*y*a*longtemps*,*nous*Žtions*ˆ*la*mer*." }; var word = ""; From 0dd72f68a2b71eaede2010c7dc43e0493d7e4eb2 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Thu, 5 Apr 2012 08:51:41 +0200 Subject: [PATCH 06/18] Backup of the mirroring --- src/domain/UBGraphicsDelegateFrame.cpp | 134 ++++++++++++++++++++----- src/domain/UBGraphicsDelegateFrame.h | 10 +- src/domain/UBGraphicsItemDelegate.cpp | 19 +++- src/domain/UBGraphicsItemDelegate.h | 2 + 4 files changed, 136 insertions(+), 29 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 7dd2e5ab..21c4e8fd 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -48,6 +48,8 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega , mTotalTranslateX(0) , mTotalTranslateY(0) , mOperationMode(Scaling) + , mMirrorX(false) + , mMirrorY(false) { setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); @@ -156,14 +158,37 @@ void UBGraphicsDelegateFrame::initializeTransform() QPointF topRight = itemTransform.map(itemRect.topRight()); QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft()); + qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1; + if(horizontalFlip < 0){ + // why this is because of the way of calculating the translations that checks which side is the most is the + // nearest instead of checking which one is the left side. + QPointF tmp = topLeft; + topLeft = topRight; + topRight = tmp; + + // because of the calculation of the height is done by lenght and not deltaY + bottomLeft = itemTransform.map(itemRect.bottomRight()); + } + + qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1; + // not sure that is usefull + if(verticalFlip < 0){ + topLeft = itemTransform.map(itemRect.bottomLeft()); + topRight = itemTransform.map(itemRect.bottomRight()); + bottomLeft = itemTransform.map(itemRect.topLeft()); + } + QLineF topLine(topLeft, topRight); QLineF leftLine(topLeft, bottomLeft); qreal width = topLine.length(); qreal height = leftLine.length(); mAngle = topLine.angle(); - mTotalScaleX = width / itemRect.width(); - mTotalScaleY = height / itemRect.height(); + + //the fact the the lenght is used we loose the horizontalFlip information + // a better way to do this is using DeltaX that preserve the direction information. + mTotalScaleX = (width / itemRect.width()) * horizontalFlip; + mTotalScaleY = height / itemRect.height() * verticalFlip; QTransform tr; QPointF center = delegated()->boundingRect().center(); @@ -192,6 +217,7 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) mAngleOffset = 0; mInitialTransform = buildTransform(); + mCurrentTool = toolFromPos(event->pos()); event->accept(); @@ -205,9 +231,16 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; + mTranslateX = moveX; + if(mOperationMode == Scaling) { +// // Hide the buttons +// mDelegate->setButtonsVisible(false); +// mResizing = true; + + // Perform the resize if (resizingBottomRight()) { // ----------------------------------------------------- @@ -240,11 +273,12 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if(resizingLeft()){ scaleX = (width - moveX) / width; }else if(resizingRight()){ - scaleX = (width + moveX) / width; + scaleX = (width + moveX) / width; } if(mDelegate->isFlippable() && qAbs(scaleX) != 0){ - if((width * qAbs(scaleX)) < 2*mFrameWidth){ + if((qAbs(width * scaleX)) < 2*mFrameWidth){ bool negative = (scaleX < 0)?true:false; + mMirrorX = (negative?mMirrorX:!mMirrorX); if(negative){ scaleX = -2*mFrameWidth/width; }else{ @@ -269,8 +303,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } if(mDelegate->isFlippable() && qAbs(scaleY) != 0){ - if((height * qAbs(scaleY)) < 2*mFrameWidth){ + if((qAbs(height * scaleY)) < 2*mFrameWidth){ bool negative = (scaleY < 0)?true:false; + mMirrorY = (negative?mMirrorY:!mMirrorY); if(negative){ scaleY = -2*mFrameWidth/width; }else{ @@ -281,7 +316,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) }else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth) { mScaleY = scaleY; - mTranslateY = moveY; + if(resizingTop()){ + mTranslateY = moveY; + } } } } @@ -421,6 +458,12 @@ void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) mCurrentTool = None; QGraphicsRectItem::mouseReleaseEvent(event); + + // Show the buttons + if(isResizing()){ + mResizing = false; + } + mDelegate->setButtonsVisible(true); } @@ -464,6 +507,14 @@ void UBGraphicsDelegateFrame::positionHandles() QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft()); QPointF center = itemTransform.map(itemRect.center()); + // Handle the mirroring + if(topLeft.x() > topRight.x()){ + QPointF tmp = topRight; + topRight = topLeft; + topLeft = tmp; + bottomLeft.setX(topLeft.x()); + } + QLineF topLine(topLeft, topRight); qreal angle = topLine.angle(); qreal width = topLine.length(); @@ -507,17 +558,8 @@ void UBGraphicsDelegateFrame::positionHandles() mBottomRightResizeGripSvgItem->setPos(rect().right() - brRect.width(), rect().bottom() - brRect.height()); mBottomResizeGripSvgItem->setPos(rect().center().x() - bRect.width() / 2, rect().bottom() - bRect.height()); - if(0 <= mScaleX){ - mLeftResizeGripSvgItem->setPos(rect().left(), rect().center().y() - lRect.height() / 2); - mRightResizeGripSvgItem->setPos(rect().right() - rRect.width(), rect().center().y() - rRect.height() / 2); - }else{ - mLeftResizeGripSvgItem->setPos(rect().right() - rRect.width(), rect().center().y() - lRect.height() / 2); - mRightResizeGripSvgItem->setPos(rect().left() , rect().center().y() - rRect.height() / 2); - } - - if(0 < mScaleY){ - - } + mLeftResizeGripSvgItem->setPos(rect().left(), rect().center().y() - lRect.height() / 2); + mRightResizeGripSvgItem->setPos(rect().right() - rRect.width(), rect().center().y() - rRect.height() / 2); mTopResizeGripSvgItem->setPos(rect().center().x() - trRect.width() / 2, rect().y()); mRotateButton->setPos(rect().right() - mFrameWidth - 5, rect().top() + 5); @@ -571,14 +613,37 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF return None; else if (bottomRightResizeGripRect().contains(pos)) return ResizeBottomRight; - else if (bottomResizeGripRect().contains(pos)) - return ResizeBottom; - else if (leftResizeGripRect().contains(pos)) - return ResizeLeft; - else if (rightResizeGripRect().contains(pos)) - return ResizeRight; - else if (topResizeGripRect().contains(pos)) - return ResizeTop; + else if (bottomResizeGripRect().contains(pos)){ + if(mMirrorY){ + return ResizeTop; + }else{ + return ResizeBottom; + } + } + else if (leftResizeGripRect().contains(pos)){ + qDebug() << "LEFT GRIP (" << mMirrorX << ")"; + if(mMirrorX){ + return ResizeRight; + }else{ + return ResizeLeft; + } + return ResizeLeft; + } + else if (rightResizeGripRect().contains(pos)){ + qDebug() << "RIGHT GRIP (" << mMirrorX << ")"; + if(mMirrorX){ + return ResizeLeft; + }else{ + return ResizeRight; + } + } + else if (topResizeGripRect().contains(pos)){ + if(mMirrorY){ + return ResizeBottom; + }else{ + return ResizeTop; + } + } else if (rotateButtonBounds().contains(pos) && mDelegate && mDelegate->canRotate()) return Rotate; else @@ -621,3 +686,22 @@ QRectF UBGraphicsDelegateFrame::rotateButtonBounds() const return QRectF(rect().right()- mFrameWidth, rect().top(), mFrameWidth, mFrameWidth); } +void UBGraphicsDelegateFrame::refreshGeometry() +{ + // Here we want to have the left on the left, the right on the right, the top on the top and the bottom on the bottom! + QRectF itemRect = delegated()->boundingRect(); + QTransform itemTransform = delegated()->sceneTransform(); + QPointF topLeft = itemTransform.map(itemRect.topLeft()); + QPointF topRight = itemTransform.map(itemRect.topRight()); + QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft()); + QPointF center = itemTransform.map(itemRect.center()); + + qDebug() << topLeft << ", " << topRight << ", " << bottomLeft; + + QLineF topLine(topLeft, topRight); + qreal angle = topLine.angle(); + qreal width = topLine.length(); + QLineF leftLine(topLeft, bottomLeft); + qreal height = leftLine.length(); + setRect(topRight.x() - mFrameWidth, topLeft.y() - mFrameWidth, width + 2*mFrameWidth, height + 2*mFrameWidth); +} diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 71508419..2cd1e0d1 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -47,6 +47,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject enum OperationMode {Scaling, Resizing}; void setOperationMode(OperationMode pMode) {mOperationMode = pMode;} + bool isResizing(){return mResizing;} private: QRectF bottomRightResizeGripRect() const; @@ -69,8 +70,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject void initializeTransform (); enum FrameTool {None, Move, Rotate, ResizeBottomRight, ResizeTop, ResizeRight, ResizeBottom, ResizeLeft}; - - FrameTool toolFromPos (QPointF pos); + FrameTool toolFromPos (QPointF pos); + void refreshGeometry(); FrameTool mCurrentTool; UBGraphicsItemDelegate* mDelegate; @@ -111,5 +112,10 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject OperationMode mOperationMode; QGraphicsItem* delegated(); + bool mMirrorX; + bool mMirrorY; + bool mResizing; + bool mMirroredXAtStart; + bool mMirroredYAtStart; }; #endif /* UBGRAPHICSDELEGATEFRAME_H_ */ diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index edcc5426..235cc7ba 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -239,6 +239,8 @@ void UBGraphicsItemDelegate::positionHandles() mDeleteButton->setTransform(tr); + + // This is where the position of the buttons is calculated. It starts always on the topleft of mFrame! qreal x = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; qreal y = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; @@ -251,7 +253,9 @@ void UBGraphicsItemDelegate::positionHandles() mDelegated->scene()->addItem(mDeleteButton); } - mDeleteButton->show(); + if(!mFrame->isResizing()){ + mDeleteButton->show(); + } bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; showHide(shownOnDisplay); @@ -264,13 +268,17 @@ void UBGraphicsItemDelegate::positionHandles() button->setTransform(tr); button->setPos(x + (i * 1.6 * mFrameWidth * mAntiScaleRatio), y); + + if (!button->scene()) { button->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene if (mDelegated->scene()) mDelegated->scene()->addItem(button); } - button->show(); + if(!mFrame->isResizing()){ + button->show(); + } } } else @@ -469,3 +477,10 @@ bool UBGraphicsItemDelegate::isFlippable() { return mFlippable; } + +void UBGraphicsItemDelegate::setButtonsVisible(bool visible) +{ + foreach(DelegateButton* pButton, mButtons){ + pButton->setVisible(visible); + } +} diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 30767179..a4bd3843 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -133,6 +133,8 @@ class UBGraphicsItemDelegate : public QObject void setFlippable(bool flippable); bool isFlippable(); + void setButtonsVisible(bool visible); + signals: void showOnDisplayChanged(bool shown); void lockChanged(bool locked); From f16c06f9b8fca6cd62744f2cd9a74c1c2f1c3a1e Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Thu, 5 Apr 2012 09:29:02 +0200 Subject: [PATCH 07/18] backup --- src/adaptors/UBExportCFF.cpp | 60 ++ src/adaptors/UBExportCFF.h | 39 + src/adaptors/UBSvgSubsetAdaptor.cpp | 107 ++- src/adaptors/UBSvgSubsetAdaptor.h | 2 + src/adaptors/adaptors.pri | 2 + src/board/UBBoardController.cpp | 7 +- src/board/UBBoardView.cpp | 4 +- src/core/UB.h | 25 +- src/core/UBApplication.cpp | 3 +- src/core/UBApplicationController.cpp | 21 +- src/core/UBApplicationController.h | 2 +- src/core/UBDisplayManager.cpp | 22 +- src/core/UBDisplayManager.h | 10 +- src/core/UBDocumentManager.cpp | 3 + src/core/UBPreferencesController.cpp | 2 +- src/desktop/UBDesktopAnnotationController.cpp | 1 + src/domain/UBGraphicsAudioItem.cpp | 4 +- src/domain/UBGraphicsItemDelegate.cpp | 67 +- src/domain/UBGraphicsItemDelegate.h | 18 +- src/domain/UBGraphicsPDFItem.cpp | 7 +- src/domain/UBGraphicsPixmapItem.cpp | 3 +- src/domain/UBGraphicsPolygonItem.cpp | 11 +- src/domain/UBGraphicsPolygonItem.h | 2 + src/domain/UBGraphicsScene.cpp | 302 ++++--- src/domain/UBGraphicsScene.h | 67 +- src/domain/UBGraphicsSvgItem.cpp | 7 +- src/domain/UBGraphicsTextItem.cpp | 18 +- src/domain/UBGraphicsTextItemDelegate.cpp | 8 +- src/domain/UBGraphicsVideoItem.cpp | 4 +- src/domain/UBGraphicsVideoItemDelegate.cpp | 4 +- src/domain/UBGraphicsWidgetItem.cpp | 4 +- src/domain/UBItem.h | 1 + src/gui/UBMagnifer.cpp | 790 +++++++++--------- src/gui/UBMagnifer.h | 193 ++--- src/tools/UBAbstractDrawRuler.cpp | 1 + src/tools/UBGraphicsCache.cpp | 8 +- src/tools/UBGraphicsCache.h | 2 - src/tools/UBGraphicsCompass.cpp | 4 +- src/tools/UBGraphicsCurtainItem.cpp | 6 +- src/tools/UBGraphicsCurtainItemDelegate.cpp | 1 - src/tools/UBGraphicsProtractor.cpp | 3 +- src/tools/UBGraphicsRuler.cpp | 4 +- src/tools/UBGraphicsTriangle.cpp | 6 +- 43 files changed, 1034 insertions(+), 821 deletions(-) create mode 100644 src/adaptors/UBExportCFF.cpp create mode 100644 src/adaptors/UBExportCFF.h diff --git a/src/adaptors/UBExportCFF.cpp b/src/adaptors/UBExportCFF.cpp new file mode 100644 index 00000000..741eb871 --- /dev/null +++ b/src/adaptors/UBExportCFF.cpp @@ -0,0 +1,60 @@ +#include "UBExportCFF.h" +#include "UBCFFAdaptor.h" +#include "document/UBDocumentProxy.h" +#include "core/UBDocumentManager.h" +#include "core/UBApplication.h" + + +UBExportCFF::UBExportCFF(QObject *parent) +: UBExportAdaptor(parent) +{ + +} + +UBExportCFF::~UBExportCFF() +{ + +} +QString UBExportCFF::exportName() +{ + return tr("Export to IWB"); +} + +QString UBExportCFF::exportExtention() +{ + return QString(".iwb"); +} + +void UBExportCFF::persist(UBDocumentProxy* pDocument) +{ + QString src = pDocument->persistencePath(); + + if (!pDocument) + return; + + QString filename = askForFileName(pDocument, tr("Export as IWB File")); + + if (filename.length() > 0) + { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + + if (mIsVerbose) + UBApplication::showMessage(tr("Exporting document...")); + + UBCFFAdaptor toIWBExporter; + if (toIWBExporter.convertUBZToIWB(src, filename)) + { + if (mIsVerbose) + UBApplication::showMessage(tr("Export successful.")); + } + else + if (mIsVerbose) + UBApplication::showMessage(tr("Export failed.")); + + + QApplication::restoreOverrideCursor(); + + } + + +} \ No newline at end of file diff --git a/src/adaptors/UBExportCFF.h b/src/adaptors/UBExportCFF.h new file mode 100644 index 00000000..6c7012d6 --- /dev/null +++ b/src/adaptors/UBExportCFF.h @@ -0,0 +1,39 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef UBExportCFF_H_ +#define UBExportCFF_H_ + +#include + +#include "UBExportAdaptor.h" + +#include "frameworks/UBFileSystemUtils.h" + +class UBDocumentProxy; + +class UBExportCFF : public UBExportAdaptor +{ + Q_OBJECT; + +public: + UBExportCFF(QObject *parent = 0); + virtual ~UBExportCFF(); + + virtual QString exportName(); + virtual QString exportExtention(); + virtual void persist(UBDocumentProxy* pDocument); +}; + +#endif /* UBExportCFF_H_ */ \ No newline at end of file diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 00e159a6..b39b7d25 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -306,9 +306,6 @@ UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { UBGraphicsScene *scene = 0; - qreal maxDrawingZIndex = 0; - qreal maxObjectZIndex = 0; - UBGraphicsWidgetItem *currentWidget = 0; mFileVersion = 40100; // default to 4.1.0 @@ -320,6 +317,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() mXmlReader.readNext(); if (mXmlReader.isStartElement()) { + qreal zFromSvg = getZValueFromSvg(); + if (mXmlReader.name() == "svg") { if (!scene) @@ -479,7 +478,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(polygonItem); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - maxDrawingZIndex = qMax(polygonItem->zValue(), maxDrawingZIndex); polygonItem->show(); } @@ -499,8 +497,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(polygonItem); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - maxDrawingZIndex = qMax(polygonItem->zValue(), maxDrawingZIndex); - polygonItem->show(); } } @@ -525,10 +521,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(pixmapItem->zValue(), maxObjectZIndex); - scene->addItem(pixmapItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(pixmapItem, zFromSvg); + if (isBackground) scene->setAsBackgroundObject(pixmapItem); @@ -544,10 +541,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(svgItem->zValue(), maxObjectZIndex); - scene->addItem(svgItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(svgItem, zFromSvg); + if (isBackground) scene->setAsBackgroundObject(svgItem); @@ -569,10 +567,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(audioItem->zValue(), maxObjectZIndex); - scene->addItem(audioItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(audioItem, zFromSvg); + audioItem->show(); //force start to load the video and display the first frame @@ -589,10 +588,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(videoItem->zValue(), maxObjectZIndex); - scene->addItem(videoItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(videoItem, zFromSvg); + videoItem->show(); //force start to load the video and display the first frame @@ -609,10 +609,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex); - scene->addItem(textItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(textItem, zFromSvg); + textItem->show(); } } @@ -624,17 +625,27 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(mask); scene->registerTool(mask); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(mask, zFromSvg); } } else if (mXmlReader.name() == "ruler") { + + QString ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString(); UBGraphicsRuler *ruler = rulerFromSvg(); + ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString(); if (ruler) { scene->addItem(ruler); scene->registerTool(ruler); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(ruler, zFromSvg); } + } else if (mXmlReader.name() == "compass") { @@ -644,6 +655,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(compass); scene->registerTool(compass); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(compass, zFromSvg); } } else if (mXmlReader.name() == "protractor") @@ -654,6 +668,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(protractor); scene->registerTool(protractor); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(protractor, zFromSvg); } } else if (mXmlReader.name() == "triangle") @@ -664,6 +681,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(triangle); scene->registerTool(triangle); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(triangle, zFromSvg); } } else if(mXmlReader.name() == "cache") @@ -674,6 +694,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(cache); scene->registerTool(cache); UBApplication::boardController->notifyCache(true); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(cache, zFromSvg); } } else if (mXmlReader.name() == "foreignObject") @@ -694,10 +717,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() pdfItem->setFlag(QGraphicsItem::ItemIsMovable, true); pdfItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(pdfItem->zValue(), maxObjectZIndex); - scene->addItem(pdfItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(pdfItem, zFromSvg); + if (isBackground) scene->setAsBackgroundObject(pdfItem); @@ -716,10 +740,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); - maxObjectZIndex = qMax(appleWidgetItem->zValue(), maxObjectZIndex); - scene->addItem(appleWidgetItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg); + appleWidgetItem->show(); currentWidget = appleWidgetItem; @@ -736,10 +761,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() w3cWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); - maxObjectZIndex = qMax(w3cWidgetItem->zValue(), maxObjectZIndex); - scene->addItem(w3cWidgetItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg); + w3cWidgetItem->show(); currentWidget = w3cWidgetItem; @@ -754,8 +780,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex); scene->addItem(textItem); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(textItem, zFromSvg); + textItem->show(); } } @@ -804,17 +833,14 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() qWarning() << "error parsing Sankore file " << mXmlReader.errorString(); } - if (scene) - { - scene->setObjectZIndex(maxObjectZIndex); - scene->setDrawingZIndex(maxDrawingZIndex); + if (scene) { scene->setModified(false); } if (annotationGroup) { - if (annotationGroup->polygons().empty()) - delete annotationGroup; + if (annotationGroup->polygons().empty()) + delete annotationGroup; } return scene; @@ -1348,12 +1374,10 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol if (!ubZValue.isNull()) { -// polygonItem->setZValue (ubZValue.toString().toFloat()); UBGraphicsItem::assignZValue(polygonItem, ubZValue.toString().toFloat()); } else { -// polygonItem->setZValue(mGroupZIndex); UBGraphicsItem::assignZValue(polygonItem, mGroupZIndex); } @@ -1457,12 +1481,10 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromLin if (!ubZValue.isNull()) { -// polygonItem->setZValue(ubZValue.toString().toFloat()); UBGraphicsItem::assignZValue(polygonItem, ubZValue.toString().toFloat()); } else { -// polygonItem->setZValue(mGroupZIndex); UBGraphicsItem::assignZValue(polygonItem, mGroupZIndex); } @@ -1611,7 +1633,6 @@ QList UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItem { UBGraphicsPolygonItem* polygonItem = new UBGraphicsPolygonItem(QLineF(points.at(i), points.at(i + 1)), lineWidth); polygonItem->setColor(brushColor); -// polygonItem->setZValue(zValue); UBGraphicsItem::assignZValue(polygonItem, zValue); polygonItem->setColorOnDarkBackground(colorOnDarkBackground); polygonItem->setColorOnLightBackground(colorOnLightBackground); @@ -1956,7 +1977,6 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g if (!ubZValue.isNull()) { -// gItem->setZValue(ubZValue.toString().toFloat()); UBGraphicsItem::assignZValue(gItem, ubZValue.toString().toFloat()); } @@ -2009,6 +2029,17 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g } } +qreal UBSvgSubsetAdaptor::UBSvgSubsetReader::getZValueFromSvg() +{ + qreal result = UBZLayerController::errorNum(); + + QStringRef ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value"); + if (!ubZValue.isNull()) { + result = ubZValue.toString().toFloat(); + } + + return result; +} void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsItemToSvg(QGraphicsItem* item) { @@ -2528,7 +2559,6 @@ UBGraphicsRuler* UBSvgSubsetAdaptor::UBSvgSubsetReader::rulerFromSvg() graphicsItemFromSvg(ruler); -// ruler->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetRuler); UBGraphicsItem::assignZValue(ruler, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetRuler); ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2587,7 +2617,6 @@ UBGraphicsCompass* UBSvgSubsetAdaptor::UBSvgSubsetReader::compassFromSvg() graphicsItemFromSvg(compass); - //compass->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCompass); UBGraphicsItem::assignZValue(compass, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCompass); compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2652,7 +2681,6 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg() { UBGraphicsProtractor* protractor = new UBGraphicsProtractor(); -// protractor->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetProtractor); UBGraphicsItem::assignZValue(protractor, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetProtractor); protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2723,7 +2751,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() { UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); -// triangle->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle); UBGraphicsItem::assignZValue(triangle, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle); triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2750,8 +2777,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() UBGraphicsCache* UBSvgSubsetAdaptor::UBSvgSubsetReader::cacheFromSvg() { UBGraphicsCache* pCache = new UBGraphicsCache(); - pCache->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCache); -// UBGraphicsItem::assignZValue(pCache, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCache); pCache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); graphicsItemFromSvg(pCache); diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 89915585..188bba2f 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -134,6 +134,8 @@ class UBSvgSubsetAdaptor void graphicsItemFromSvg(QGraphicsItem* gItem); + qreal getZValueFromSvg(); + QXmlStreamReader mXmlReader; int mFileVersion; UBDocumentProxy *mProxy; diff --git a/src/adaptors/adaptors.pri b/src/adaptors/adaptors.pri index b69d434f..4fc92ce9 100644 --- a/src/adaptors/adaptors.pri +++ b/src/adaptors/adaptors.pri @@ -14,6 +14,7 @@ HEADERS += src/adaptors/UBExportAdaptor.h\ src/adaptors/UBExportWeb.h \ src/adaptors/UBWebPublisher.h \ src/adaptors/UBImportCFF.h \ + src/adaptors/UBExportCFF.h \ src/adaptors/UBCFFSubsetAdaptor.h HEADERS += src/adaptors/publishing/UBDocumentPublisher.h \ @@ -36,6 +37,7 @@ SOURCES += src/adaptors/UBExportAdaptor.cpp\ src/adaptors/UBExportWeb.cpp \ src/adaptors/UBWebPublisher.cpp \ src/adaptors/UBImportCFF.cpp \ + src/adaptors/UBExportCFF.cpp \ src/adaptors/UBCFFSubsetAdaptor.cpp \ src/adaptors/publishing/UBDocumentPublisher.cpp diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 5bc5653d..4b54b76b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -664,6 +664,7 @@ void UBBoardController::zoom(const qreal ratio, QPointF scenePoint) UBApplication::applicationController->adjustDisplayView(); emit controlViewportChanged(); + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11()); } @@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, mControlView->setScene(mActiveScene); mDisplayView->setScene(mActiveScene); - + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11()); pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize()); updatePageSizeState(); @@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor() mControlView->setTransform(scalingTransform); mControlView->horizontalScrollBar()->setValue(viewState.horizontalPosition); mControlView->verticalScrollBar()->setValue(viewState.verticalPostition); -} + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());} void UBBoardController::setWidePageSize(bool checked) @@ -1943,8 +1944,6 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint if (gi) { -// gi->setZValue(mActiveScene->getNextObjectZIndex()); - UBGraphicsItem::assignZValue(gi, mActiveScene->getNextObjectZIndex()); mActiveScene->addItem(gi); gi->setPos(gi->pos() + QPointF(50, 50)); } diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index e9ffde4d..e1d1f0b2 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -54,6 +54,7 @@ #include "tools/UBGraphicsCompass.h" #include "tools/UBGraphicsCache.h" +#include "tools/UBGraphicsTriangle.h" #include "core/memcheck.h" @@ -425,7 +426,8 @@ UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsCompass::Type || movingItem->type() == UBGraphicsPDFItem::Type || movingItem->type() == UBGraphicsPolygonItem::Type - || movingItem->type() == UBGraphicsCache::Type) + || movingItem->type() == UBGraphicsCache::Type + || movingItem->type() == UBGraphicsTriangle::Type) { movingItem = NULL; QGraphicsView::mousePressEvent (event); diff --git a/src/core/UB.h b/src/core/UB.h index 83a4b456..0ca8d2cd 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -62,7 +62,7 @@ struct UBSize }; }; - +// Deprecated. Keep it for backward campability with old versions struct UBItemLayerType { enum Enum @@ -71,17 +71,38 @@ struct UBItemLayerType }; }; +struct itemLayerType +{ + enum Enum { + NoLayer = 0 + , BackgroundItem + , ObjectItem + , DrawingItem + , ToolItem + , CppTool + , Eraiser + , Curtain + , Pointer + , Cache + , SelectedItem + }; +}; + + struct UBGraphicsItemData { enum Enum { - ItemLayerType + ItemLayerType //Deprecated. Keep it for backward campability with old versions. Use itemLayerType instead , ItemLocked , ItemEditable//for text only , ItemOwnZValue + , itemLayerType //use instead of deprecated ItemLayerType }; }; + + struct UBGraphicsItemType { enum Enum diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 7c78a086..b8a3e257 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -289,7 +289,6 @@ int UBApplication::exec(const QString& pFileToImport) bool bUseMultiScreen = UBSettings::settings()->appUseMultiscreen->get().toBool(); mainWindow->actionMultiScreen->setChecked(bUseMultiScreen); - applicationController->useMultiScreen(bUseMultiScreen); connect(mainWindow->actionMultiScreen, SIGNAL(triggered(bool)), applicationController, SLOT(useMultiScreen(bool))); connect(mainWindow->actionWidePageSize, SIGNAL(triggered(bool)), boardController, SLOT(setWidePageSize(bool))); connect(mainWindow->actionRegularPageSize, SIGNAL(triggered(bool)), boardController, SLOT(setRegularPageSize(bool))); @@ -299,7 +298,7 @@ int UBApplication::exec(const QString& pFileToImport) connect(mainWindow->actionCopy, SIGNAL(triggered()), applicationController, SLOT(actionCopy())); connect(mainWindow->actionPaste, SIGNAL(triggered()), applicationController, SLOT(actionPaste())); - applicationController->initScreenLayout(); + applicationController->initScreenLayout(bUseMultiScreen); boardController->setupLayout(); if (pFileToImport.length() > 0) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index e2e09375..0ee793e1 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -135,14 +135,15 @@ void UBApplicationController::initViewState(int horizontalPosition, int vertical } -void UBApplicationController::initScreenLayout() +void UBApplicationController::initScreenLayout(bool useMultiscreen) { - mDisplayManager->setAsControl(mMainWindow, true); - mDisplayManager->setAsDisplay(mDisplayView); + mDisplayManager->setControlWidget(mMainWindow); + mDisplayManager->setDisplayWidget(mDisplayView); - mDisplayManager->setAsPreviousDisplays(mPreviousViews); - mDisplayManager->setAsDesktop(mUninoteController->drawingView()); + mDisplayManager->setPreviousDisplaysWidgets(mPreviousViews); + mDisplayManager->setDesktopWidget(mUninoteController->drawingView()); + mDisplayManager->setUseMultiScreen(useMultiscreen); mDisplayManager->adjustScreens(-1); } @@ -343,7 +344,6 @@ void UBApplicationController::showBoard() mirroringEnabled(false); mMainWindow->switchToBoardWidget(); - mDisplayManager->setAsDisplay(mDisplayView); if (UBApplication::boardController) UBApplication::boardController->show(); @@ -353,7 +353,7 @@ void UBApplicationController::showBoard() mUninoteController->hideWindow(); - mDisplayManager->adjustScreens(0); + mMainWindow->show(); emit mainModeChanged(Board); @@ -637,12 +637,12 @@ void UBApplicationController::mirroringEnabled(bool enabled) if (enabled) { mMirror->start(); - mDisplayManager->setAsDisplay(mMirror); + mDisplayManager->setDisplayWidget(mMirror); } else { - mDisplayManager->setAsDisplay(mDisplayView); + mDisplayManager->setDisplayWidget(mDisplayView); mMirror->stop(); } @@ -652,7 +652,7 @@ void UBApplicationController::mirroringEnabled(bool enabled) } else { - mDisplayManager->setAsDisplay(mDisplayView); + mDisplayManager->setDisplayWidget(mDisplayView); } } @@ -727,6 +727,7 @@ void UBApplicationController::importFile(const QString& pFilePath) void UBApplicationController::useMultiScreen(bool use) { mDisplayManager->setUseMultiScreen(use); + mDisplayManager->adjustScreens(0); UBSettings::settings()->appUseMultiscreen->set(use); } diff --git a/src/core/UBApplicationController.h b/src/core/UBApplicationController.h index 2bdf6890..4d578b42 100644 --- a/src/core/UBApplicationController.h +++ b/src/core/UBApplicationController.h @@ -51,7 +51,7 @@ class UBApplicationController : public QObject void blackout(); - void initScreenLayout(); + void initScreenLayout(bool useMultiscreen); void closing(); diff --git a/src/core/UBDisplayManager.cpp b/src/core/UBDisplayManager.cpp index 1bffbb26..1d441adb 100644 --- a/src/core/UBDisplayManager.cpp +++ b/src/core/UBDisplayManager.cpp @@ -118,16 +118,11 @@ int UBDisplayManager::numPreviousViews() } -void UBDisplayManager::setAsControl(QWidget* pControlWidget, bool init) +void UBDisplayManager::setControlWidget(QWidget* pControlWidget) { if(hasControl() && pControlWidget && (pControlWidget != mControlWidget)) { mControlWidget = pControlWidget; - mControlWidget->hide(); - mControlWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex)); - - if (!init) - mControlWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC // mControlWidget->setAttribute(Qt::WA_MacNoShadow); @@ -135,14 +130,11 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget, bool init) } } -void UBDisplayManager::setAsDesktop(QWidget* pControlWidget ) +void UBDisplayManager::setDesktopWidget(QWidget* pControlWidget ) { if(pControlWidget && (pControlWidget != mControlWidget)) { mDesktopWidget = pControlWidget; - mDesktopWidget->hide(); - mDesktopWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex)); -// mDisplayWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC // mControlWidget->setAttribute(Qt::WA_MacNoShadow); @@ -150,14 +142,11 @@ void UBDisplayManager::setAsDesktop(QWidget* pControlWidget ) } } -void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget) +void UBDisplayManager::setDisplayWidget(QWidget* pDisplayWidget) { if(pDisplayWidget && (pDisplayWidget != mDisplayWidget)) { mDisplayWidget = pDisplayWidget; - mDisplayWidget->hide(); - mDisplayWidget->setGeometry(mDesktop->screenGeometry(mDisplayScreenIndex)); - mDisplayWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC // mDisplayWidget->setAttribute(Qt::WA_MacNoShadow); @@ -166,7 +155,7 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget) } -void UBDisplayManager::setAsPreviousDisplays(QList pPreviousViews) +void UBDisplayManager::setPreviousDisplaysWidgets(QList pPreviousViews) { mPreviousDisplayWidgets = pPreviousViews; } @@ -182,7 +171,7 @@ QRect UBDisplayManager::displayGeometry() return mDesktop->screenGeometry(mDisplayScreenIndex); } -void UBDisplayManager::swapScreens(bool swap) +void UBDisplayManager::reinitScreens(bool swap) { Q_UNUSED(swap); adjustScreens(-1); @@ -310,6 +299,5 @@ void UBDisplayManager::setRoleToScreen(DisplayRole role, int screenIndex) void UBDisplayManager::setUseMultiScreen(bool pUse) { mUseMultiScreen = pUse; - adjustScreens(0); } diff --git a/src/core/UBDisplayManager.h b/src/core/UBDisplayManager.h index 33ee9244..f6ca289d 100644 --- a/src/core/UBDisplayManager.h +++ b/src/core/UBDisplayManager.h @@ -33,13 +33,13 @@ class UBDisplayManager : public QObject int numPreviousViews(); - void setAsControl(QWidget* pControlWidget, bool init = false); + void setControlWidget(QWidget* pControlWidget); - void setAsDisplay(QWidget* pDisplayWidget); + void setDisplayWidget(QWidget* pDisplayWidget); - void setAsDesktop(QWidget* pControlWidget); + void setDesktopWidget(QWidget* pControlWidget); - void setAsPreviousDisplays(QList pPreviousViews); + void setPreviousDisplaysWidgets(QList pPreviousViews); bool hasControl() { @@ -77,7 +77,7 @@ class UBDisplayManager : public QObject public slots: - void swapScreens(bool bswap); + void reinitScreens(bool bswap); void adjustScreens(int screen); diff --git a/src/core/UBDocumentManager.cpp b/src/core/UBDocumentManager.cpp index 48dd0352..fbe315e2 100644 --- a/src/core/UBDocumentManager.cpp +++ b/src/core/UBDocumentManager.cpp @@ -21,6 +21,7 @@ #include "adaptors/UBExportFullPDF.h" #include "adaptors/UBExportDocument.h" #include "adaptors/UBExportWeb.h" +#include "adaptors/UBExportCFF.h" #include "adaptors/UBWebPublisher.h" #include "adaptors/UBImportDocument.h" #include "adaptors/UBImportPDF.h" @@ -62,6 +63,8 @@ UBDocumentManager::UBDocumentManager(QObject *parent) QString dummyObjects = tr("objects"); QString dummyWidgets = tr("widgets"); + UBExportCFF* cffExporter = new UBExportCFF(this); + mExportAdaptors.append(cffExporter); UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this); mExportAdaptors.append(exportFullPdf); UBExportDocument* exportDocument = new UBExportDocument(this); diff --git a/src/core/UBPreferencesController.cpp b/src/core/UBPreferencesController.cpp index cd5fde30..3968f602 100644 --- a/src/core/UBPreferencesController.cpp +++ b/src/core/UBPreferencesController.cpp @@ -118,7 +118,7 @@ void UBPreferencesController::wire() connect(mPreferencesUI->useExternalBrowserCheckBox, SIGNAL(clicked(bool)), settings->webUseExternalBrowser, SLOT(setBool(bool))); connect(mPreferencesUI->displayBrowserPageCheckBox, SIGNAL(clicked(bool)), settings->webShowPageImmediatelyOnMirroredScreen, SLOT(setBool(bool))); connect(mPreferencesUI->swapControlAndDisplayScreensCheckBox, SIGNAL(clicked(bool)), settings->swapControlAndDisplayScreens, SLOT(setBool(bool))); - connect(mPreferencesUI->swapControlAndDisplayScreensCheckBox, SIGNAL(clicked(bool)), UBApplication::applicationController->displayManager(), SLOT(swapScreens(bool))); + connect(mPreferencesUI->swapControlAndDisplayScreensCheckBox, SIGNAL(clicked(bool)), UBApplication::applicationController->displayManager(), SLOT(reinitScreens(bool))); connect(mPreferencesUI->toolbarAtTopRadioButton, SIGNAL(clicked(bool)), this, SLOT(toolbarPositionChanged(bool))); connect(mPreferencesUI->toolbarAtBottomRadioButton, SIGNAL(clicked(bool)), this, SLOT(toolbarPositionChanged(bool))); diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index 9cb92e4b..1f27f607 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent) mTransparentDrawingScene = new UBGraphicsScene(0); mTransparentDrawingView->setScene(mTransparentDrawingScene); + mTransparentDrawingScene->setDrawingMode(true); // mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView); //mRightPalette = new UBRightPalette(mTransparentDrawingView); diff --git a/src/domain/UBGraphicsAudioItem.cpp b/src/domain/UBGraphicsAudioItem.cpp index d38e27b7..f2d1ab45 100644 --- a/src/domain/UBGraphicsAudioItem.cpp +++ b/src/domain/UBGraphicsAudioItem.cpp @@ -64,6 +64,8 @@ UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsIte mDelegate->frame()->setOperationMode ( UBGraphicsDelegateFrame::Resizing ); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + } void UBGraphicsAudioItem::onStateChanged(Phonon::State newState, Phonon::State oldState) @@ -95,8 +97,6 @@ UBItem* UBGraphicsAudioItem::deepCopy() const UBGraphicsAudioItem *copy = new UBGraphicsAudioItem(audioUrl, parentItem()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 235cc7ba..9ad4c7aa 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -73,29 +73,33 @@ void UBGraphicsItemDelegate::init() { mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame->hide(); -// mFrame->setZValue(UBGraphicsScene::toolLayerStart + 1); - UBGraphicsItem::assignZValue(mFrame, UBGraphicsScene::toolLayerStart + 1); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); - mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame); + 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); + 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); + mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); mButtons << mMenuButton; + mZOrderUpButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::BottomLeftSection); + connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevel())); + mButtons << mZOrderUpButton; + + mZOrderDownButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::BottomLeftSection); + connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(decreaseZLevel())); + mButtons << mZOrderDownButton; + buildButtons(); foreach(DelegateButton* button, mButtons) { button->hide(); -// button->setZValue(UBGraphicsScene::toolLayerStart + 2); - UBGraphicsItem::assignZValue(button, UBGraphicsScene::toolLayerStart + 2); button->setFlag(QGraphicsItem::ItemIsSelectable, true); } } @@ -160,18 +164,9 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) if (!mDelegated->isSelected()) { mDelegated->setSelected(true); - - UBGraphicsScene* scene = static_cast(mDelegated->scene()); - qDebug() << mDelegated->zValue(); - qDebug() << scene->currentObjectZIndex(); - -// To investigate. Z value behavior -// if (mDelegated->zValue() < scene->currentObjectZIndex() && !isLocked()) -// mDelegated->setZValue(scene->getNextObjectZIndex()); positionHandles(); - return true; } else @@ -239,12 +234,13 @@ void UBGraphicsItemDelegate::positionHandles() mDeleteButton->setTransform(tr); + qreal topX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; + qreal topY = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; - // This is where the position of the buttons is calculated. It starts always on the topleft of mFrame! - qreal x = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; - qreal y = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; + qreal bottomX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; + qreal bottomY = mFrame->rect().bottom() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; - mDeleteButton->setPos(x, y); + mDeleteButton->setPos(topX, topY); if (!mDeleteButton->scene()) { @@ -262,13 +258,19 @@ void UBGraphicsItemDelegate::positionHandles() lock(isLocked()); - for(int i = 1 ; i < mButtons.length(); i++) - { - DelegateButton* button = mButtons[i]; + int i = 1, j = 0, k = 0; + while ((i + j) < mButtons.size()) { + DelegateButton* button = mButtons[i + j]; button->setTransform(tr); - button->setPos(x + (i * 1.6 * mFrameWidth * mAntiScaleRatio), y); + if (button->getSection() == Qt::TopLeftSection) { + button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY); + } else if (button->getSection() == Qt::BottomLeftSection) { + button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY); + } else if (button->getSection() == Qt::NoSection) { + ++k; + } if (!button->scene()) { @@ -278,11 +280,10 @@ void UBGraphicsItemDelegate::positionHandles() } if(!mFrame->isResizing()){ button->show(); + button->setZValue(delegated()->zValue()); } } - } - else - { + } else { foreach(DelegateButton* button, mButtons) button->hide(); @@ -325,7 +326,19 @@ void UBGraphicsItemDelegate::duplicate() UBApplication::boardController->copy(); UBApplication::boardController->paste(); } +void UBGraphicsItemDelegate::increaseZLevel(int delta) +{ + qDebug() << delegated()->scene()->items().count(); +// UBGraphicsItem::assignZValue(delegated(), ) + +// int valueCandidate = delegated()->data(UBGraphicsItemData::ItemOwnZValue).toInt(); +// if (delta < 0) { + +// } else if (delta > 0) { + +// } +} void UBGraphicsItemDelegate::lock(bool locked) { diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index a4bd3843..57e347bc 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -33,10 +33,11 @@ class DelegateButton: public QGraphicsSvgItem Q_OBJECT public: - DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0) + DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0, Qt::WindowFrameSection section = Qt::TopLeftSection) : QGraphicsSvgItem(fileName, parent) , mDelegated(pDelegated) , mIsTransparentToMouseEvent(false) + , mButtonAlignmentSection(section) { setAcceptedMouseButtons(Qt::LeftButton); setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); @@ -57,6 +58,9 @@ class DelegateButton: public QGraphicsSvgItem QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this)); } + void setSection(Qt::WindowFrameSection section) {mButtonAlignmentSection = section;} + Qt::WindowFrameSection getSection() const {return mButtonAlignmentSection;} + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -80,7 +84,9 @@ class DelegateButton: public QGraphicsSvgItem QGraphicsItem* mDelegated; + bool mIsTransparentToMouseEvent; + Qt::WindowFrameSection mButtonAlignmentSection; signals: void clicked (bool checked = false); @@ -147,6 +153,9 @@ class UBGraphicsItemDelegate : public QObject virtual void lock(bool lock); virtual void duplicate(); + virtual void increaseZLevel() {increaseZLevel(1);} + virtual void decreaseZLevel() {increaseZLevel(-1);} + protected: virtual void buildButtons() {;} virtual void decorateMenu(QMenu *menu); @@ -154,10 +163,15 @@ class UBGraphicsItemDelegate : public QObject QGraphicsItem* mDelegated; + //buttons from the top left section of delegate frame DelegateButton* mDeleteButton; DelegateButton* mDuplicateButton; DelegateButton* mMenuButton; + //buttons from the bottom left section of delegate frame + DelegateButton *mZOrderUpButton; + DelegateButton *mZOrderDownButton; + QMenu* mMenu; QAction* mLockAction; @@ -176,6 +190,8 @@ protected slots: private: + virtual void increaseZLevel(int delta); + QPointF mOffset; QTransform mPreviousTransform; QPointF mPreviousPosition; diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 704ba676..aa8c7ea3 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -26,7 +26,8 @@ UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGraphicsItem* parent) : GraphicsPDFItem(renderer, pageNumber, parent) { - setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); + setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); //deprecated + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::BackgroundItem)); //Necessary to set if we want z value to be assigned correctly mDelegate = new UBGraphicsItemDelegate(this,0); mDelegate->init(); } @@ -84,8 +85,6 @@ UBItem* UBGraphicsPDFItem::deepCopy() const UBGraphicsPDFItem *copy = new UBGraphicsPDFItem(mRenderer, mPageNumber, parentItem()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -135,8 +134,6 @@ UBGraphicsPixmapItem* UBGraphicsPDFItem::toPixmapItem() const pixmapItem->setPixmap(pixmap); pixmapItem->setPos(this->pos()); -// pixmapItem->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(pixmapItem, this->zValue()); pixmapItem->setTransform(this->transform()); pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 326aded2..07dc4679 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -37,6 +37,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setTransformationMode(Qt::SmoothTransformation); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } @@ -102,8 +103,6 @@ UBItem* UBGraphicsPixmapItem::deepCopy() const copy->setPixmap(this->pixmap()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index d2e96e25..7608e20e 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -30,6 +30,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (QGraphicsItem * parent) , mStroke(0) { // NOOP + initialize(); } @@ -40,6 +41,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi , mStroke(0) { // NOOP + initialize(); } @@ -51,6 +53,12 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth) , mStroke(0) { // NOOP + initialize(); +} + +void UBGraphicsPolygonItem::initialize() +{ + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly } void UBGraphicsPolygonItem::clearStroke() @@ -153,9 +161,6 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con copy->setPen(this->pen()); copy->mHasAlpha = this->mHasAlpha; -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); - copy->setColorOnDarkBackground(this->colorOnDarkBackground()); copy->setColorOnLightBackground(this->colorOnLightBackground()); diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 66498ef2..22dfe712 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -35,6 +35,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem ~UBGraphicsPolygonItem(); + void initialize(); + void setColor(const QColor& color); QColor color() const; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b20cf7f8..6f7f4d77 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -61,8 +61,6 @@ #include "core/memcheck.h" -qreal UBGraphicsScene::backgroundLayerStart = -20000000.0; -qreal UBGraphicsScene::objectLayerStart = -10000000.0; qreal UBGraphicsScene::drawingLayerStart = 0.0; qreal UBGraphicsScene::toolLayerStart = 10000000.0; @@ -77,6 +75,47 @@ qreal UBGraphicsScene::toolOffsetPointer = 1100; qreal UBGraphicsScene::toolOffsetCache = 1000;//Didier please define offset you want +qreal UBZLayerController::errorNumber = -20000001.0; + + +UBZLayerController::UBZLayerController() +{ + scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber)); + scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-10000000.0, -10000000.0 )); + scopeMap.insert(itemLayerType::ObjectItem, ItemLayerTypeData(-10000000.0, 0.0 )); + scopeMap.insert(itemLayerType::DrawingItem, ItemLayerTypeData( 0.0, 10000000.0 )); + scopeMap.insert(itemLayerType::ToolItem, ItemLayerTypeData( 10000000.0, 10000100.0 )); + scopeMap.insert(itemLayerType::CppTool, ItemLayerTypeData( 10000100.0, 10000200.0 )); + scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 10000200.0, 10001000.0 )); + scopeMap.insert(itemLayerType::Eraiser, ItemLayerTypeData( 10001000.0, 10001100.0 )); + scopeMap.insert(itemLayerType::Pointer, ItemLayerTypeData( 10001100.0, 10001200.0 )); + scopeMap.insert(itemLayerType::Cache, ItemLayerTypeData( 10001300.0, 10001400.0 )); + + scopeMap.insert(itemLayerType::SelectedItem, ItemLayerTypeData( 10001000.0, 10001000.0 )); +} + +qreal UBZLayerController::generateZLevel(itemLayerType::Enum key) +{ + + if (!scopeMap.contains(key)) { + qDebug() << "Number is out of layer scope"; + return errorNumber; + } + + qreal result = scopeMap.value(key).curValue; + qreal top = scopeMap.value(key).topLimit; + + result++; + if (result >= top) { + qDebug() << "new values are over for the scope" << key; + result = top - 1; + } + + scopeMap[key].curValue = result; + + return result; +} + UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) : UBCoreGraphicsScene(parent) , mEraser(0) @@ -96,6 +135,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) , enableUndoRedoStack(true) , magniferControlViewWidget(0) , magniferDisplayViewWidget(0) + , mIsDesktopMode(false) { @@ -106,32 +146,8 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) #endif setDocument(parent); - - mDrawingZIndex = drawingLayerStart; - mObjectZIndex = objectLayerStart; - - mEraser = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene - mEraser->setRect(QRect(0, 0, 0, 0)); - mEraser->setVisible(false); - - mEraser->setZValue(/*toolLayerStart + toolOffsetEraser*/2); - mEraser->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - - mTools << mEraser; - addItem(mEraser); - - mPointer = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene - mPointer->setRect(QRect(0, 0, 20, 20)); - mPointer->setVisible(false); - - mPointer->setPen(Qt::NoPen); - mPointer->setBrush(QBrush(QColor(255, 0, 0, 186))); - - mPointer->setZValue( /*toolLayerStart + toolOffsetPointer*/ 2); - mPointer->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); - - mTools << mPointer; - addItem(mPointer); + createEraiser(); + createPointer(); if (UBApplication::applicationController) { @@ -145,8 +161,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) UBGraphicsScene::~UBGraphicsScene() { - DisposeMagnifierQWidgets(); - if (mCurrentStroke) if (mCurrentStroke->polygons().empty()) delete mCurrentStroke; @@ -155,27 +169,18 @@ UBGraphicsScene::~UBGraphicsScene() void UBGraphicsScene::selectionChangedProcessing() { if (selectedItems().count()) - UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f')); - + UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " + + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); QList allItemsList = items(); - qreal maxZ = 0.; for( int i = 0; i < allItemsList.size(); i++ ) { QGraphicsItem *nextItem = allItemsList.at(i); - //Temporary stub. Due to ugly z-order implementation I need to do this (sankore 360) - //z-order behavior should be reimplemented and this stub should be deleted - if (nextItem == mBackgroundObject) - continue; - //Temporary stub end (sankore 360) - if (nextItem->zValue() > maxZ) - maxZ = nextItem->zValue(); - nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); -// nextItem->setZValue(qreal(1)); - } - QList selItemsList = selectedItems(); - for( int i = 0; i < selItemsList.size(); i++ ) { - QGraphicsItem *nextItem = selItemsList.at(i); - nextItem->setZValue(maxZ + 0.0001); + + if (nextItem->isSelected()) { + nextItem->setZValue(mZLayerController.generateZLevel(itemLayerType::SelectedItem)); + } else { + nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + } } } @@ -404,25 +409,11 @@ void UBGraphicsScene::drawEraser(const QPointF &pPoint, bool isFirstDraw) qreal eraserRadius = eraserWidth / 2; // TODO UB 4.x optimize - no need to do that every time we move it - if (mEraser) - { + if (mEraser) { mEraser->setRect(QRectF(pPoint.x() - eraserRadius, pPoint.y() - eraserRadius, eraserWidth, eraserWidth)); - if(isFirstDraw) - { - qreal maxZ = 0.; - QList allItemsList = items(); - for( int i = 0; i < allItemsList.size(); i++ ) - { - QGraphicsItem *nextItem = allItemsList.at(i); - qreal zValue = nextItem->zValue(); - if (zValue > maxZ) - maxZ = zValue; - nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); - } - - mEraser->setZValue(maxZ + 0.0001); - mEraser->show(); + if(isFirstDraw) { + mEraser->show(); } } } @@ -433,27 +424,12 @@ void UBGraphicsScene::drawPointer(const QPointF &pPoint, bool isFirstDraw) qreal pointerRadius = pointerDiameter / 2; // TODO UB 4.x optimize - no need to do that every time we move it - if (mPointer) - { + if (mPointer) { mPointer->setRect(QRectF(pPoint.x() - pointerRadius, - pPoint.y() - pointerRadius, - pointerDiameter, - pointerDiameter)); - - if(isFirstDraw) - { - qreal maxZ = 0.; - QList allItemsList = items(); - for( int i = 0; i < allItemsList.size(); i++ ) - { - QGraphicsItem *nextItem = allItemsList.at(i); - qreal zValue = nextItem->zValue(); - if (zValue > maxZ) - maxZ = zValue; - nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); - } - - mPointer->setZValue(maxZ + 0.0001); + pPoint.y() - pointerRadius, + pointerDiameter, + pointerDiameter)); + if(isFirstDraw) { mPointer->show(); } } @@ -690,21 +666,6 @@ void UBGraphicsScene::drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle) setDocumentUpdated(); } - -qreal UBGraphicsScene::getNextDrawingZIndex() -{ - mDrawingZIndex = mDrawingZIndex + 1.0; - return mDrawingZIndex; -} - - -qreal UBGraphicsScene::getNextObjectZIndex() -{ - mObjectZIndex = mObjectZIndex + 1.0; - return mObjectZIndex; -} - - void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) { bool needRepaint = false; @@ -749,6 +710,15 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) } } +void UBGraphicsScene::setBackgroundZoomFactor(qreal zoom) +{ + mZoomFactor = zoom; +} + +void UBGraphicsScene::setDrawingMode(bool bModeDesktop) +{ + mIsDesktopMode = bModeDesktop; +} void UBGraphicsScene::recolorAllItems() { @@ -827,9 +797,6 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem) polygonItem->setColorOnLightBackground(colorOnLightBG); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - -// polygonItem->setZValue(getNextDrawingZIndex()); - UBGraphicsItem::assignZValue(polygonItem, getNextDrawingZIndex()); } @@ -870,9 +837,6 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const UBGraphicsScene* copy = new UBGraphicsScene(this->document()); copy->setBackground(this->isDarkBackground(), this->isCrossedBackground()); - - copy->mDrawingZIndex = this->mDrawingZIndex; - copy->mObjectZIndex = this->mObjectZIndex; copy->setSceneRect(this->sceneRect()); if (this->mNominalSize.isValid()) @@ -1050,8 +1014,6 @@ UBGraphicsPixmapItem* UBGraphicsScene::addPixmap(const QPixmap& pPixmap, const Q pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// pixmapItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(pixmapItem, getNextObjectZIndex()); pixmapItem->setPixmap(pPixmap); @@ -1103,8 +1065,6 @@ UBGraphicsVideoItem* UBGraphicsScene::addVideo(const QUrl& pVideoFileUrl, bool s videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// videoItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(videoItem, getNextObjectZIndex()); addItem(videoItem); @@ -1136,8 +1096,6 @@ UBGraphicsAudioItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool s audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// audioItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(audioItem, getNextObjectZIndex()); addItem(audioItem); @@ -1204,8 +1162,6 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addW3CWidget(const QUrl& pWidgetUrl, c void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos) { graphicsWidget->setFlag(QGraphicsItem::ItemIsSelectable, true); -// graphicsWidget->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(graphicsWidget, getNextObjectZIndex()); addItem(graphicsWidget); @@ -1267,8 +1223,6 @@ UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPoint svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// svgItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(svgItem, getNextObjectZIndex()); qreal sscale = 1 / UBApplication::boardController->systemScaleFactor(); svgItem->scale(sscale, sscale); @@ -1303,8 +1257,6 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con { UBGraphicsTextItem *textItem = new UBGraphicsTextItem(); textItem->setPlainText(pString); -// textItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(textItem, getNextObjectZIndex()); QFont font = textItem->font(); @@ -1361,8 +1313,6 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const Q UBGraphicsTextItem *textItem = new UBGraphicsTextItem(); textItem->setPlainText(""); textItem->setHtml(pString); -// textItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(textItem, getNextObjectZIndex()); addItem(textItem); textItem->show(); @@ -1388,6 +1338,8 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) setModified(true); UBCoreGraphicsScene::addItem(item); + UBGraphicsItem::assignZValue(item, generateZLevel(item)); + if (!mTools.contains(item)) ++mItemCount; @@ -1398,8 +1350,10 @@ void UBGraphicsScene::addItems(const QSet& items) { setModified(true); - foreach(QGraphicsItem* item, items) + foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::addItem(item); + UBGraphicsItem::assignZValue(item, generateZLevel(item)); + } mItemCount += items.size(); @@ -1460,8 +1414,7 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool item->setAcceptedMouseButtons(Qt::NoButton); item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground); -// item->setZValue(backgroundLayerStart); - UBGraphicsItem::assignZValue(item, backgroundLayerStart); + UBGraphicsItem::assignZValue(item, mZLayerController.generateZLevel(itemLayerType::BackgroundItem)); if (pAdaptTransformation) { @@ -1565,9 +1518,6 @@ void UBGraphicsScene::addRuler(QPointF center) QRectF rect = ruler->rect(); ruler->setRect(center.x() - rect.width()/2, center.y() - rect.height()/2, rect.width(), rect.height()); -// ruler->setZValue(toolLayerStart + toolOffsetRuler); - UBGraphicsItem::assignZValue(ruler, toolLayerStart + toolOffsetRuler); - ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); addItem(ruler); @@ -1584,9 +1534,6 @@ void UBGraphicsScene::addProtractor(QPointF center) UBGraphicsProtractor* protractor = new UBGraphicsProtractor(); // mem : owned and destroyed by the scene mTools << protractor; -// protractor->setZValue(toolLayerStart + toolOffsetProtractor); - UBGraphicsItem::assignZValue(protractor, toolLayerStart + toolOffsetProtractor); - protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); addItem(protractor); @@ -1605,9 +1552,6 @@ void UBGraphicsScene::addTriangle(QPointF center) UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); // mem : owned and destroyed by the scene mTools << triangle; -// triangle->setZValue(toolLayerStart + toolOffsetProtractor); - UBGraphicsItem::assignZValue(triangle, toolLayerStart + toolOffsetTriangle); - triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); addItem(triangle); @@ -1738,9 +1682,6 @@ void UBGraphicsScene::addCompass(QPointF center) QRectF rect = compass->rect(); compass->setRect(center.x() - rect.width() / 2, center.y() - rect.height() / 2, rect.width(), rect.height()); -// compass->setZValue(toolLayerStart + toolOffsetCompass); - UBGraphicsItem::assignZValue(compass, toolLayerStart + toolOffsetCompass); - compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); compass->setVisible(true); @@ -1772,8 +1713,6 @@ void UBGraphicsScene::addMask(const QPointF ¢er) QRectF rect = UBApplication::boardController->activeScene()->normalizedSceneRect(); rect.setRect(center.x() - rect.width()/4, center.y() - rect.height()/4, rect.width()/2 , rect.height()/2); curtain->setRect(rect); - UBGraphicsItem::assignZValue(curtain, toolLayerStart + toolOffsetCurtain); - curtain->setVisible(true); curtain->setSelected(true); setModified(true); @@ -1923,6 +1862,58 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems, } } +void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) +{ + if (mIsDesktopMode) + { + QGraphicsScene::drawBackground (painter, rect); + return; + } + bool darkBackground = isDarkBackground (); + + if (darkBackground) + { + painter->fillRect (rect, QBrush (QColor (Qt::black))); + } + else + { + painter->fillRect (rect, QBrush (QColor (Qt::white))); + } + + if (mZoomFactor > 0.5) + { + QColor bgCrossColor; + + if (darkBackground) + bgCrossColor = UBSettings::crossDarkBackground; + else + bgCrossColor = UBSettings::crossLightBackground; + if (mZoomFactor < 1.0) + { + int alpha = 255 * mZoomFactor / 2; + bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms + } + + painter->setPen (bgCrossColor); + + if (isCrossedBackground()) + { + qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; + + for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) + { + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + } + + qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; + + for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) + { + painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); + } + } + } +} void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) { @@ -1991,7 +1982,46 @@ void UBGraphicsScene::setDocumentUpdated() document()->setMetaData(UBSettings::documentUpdatedAt , UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); } +void UBGraphicsScene::createEraiser() +{ + mEraser = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene + mEraser->setRect(QRect(0, 0, 0, 0)); + mEraser->setVisible(false); + + mEraser->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + mEraser->setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Eraiser)); //Necessary to set if we want z value to be assigned correctly + + mTools << mEraser; + addItem(mEraser); + +} +void UBGraphicsScene::createPointer() +{ + mPointer = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene + mPointer->setRect(QRect(0, 0, 20, 20)); + mPointer->setVisible(false); + + mPointer->setPen(Qt::NoPen); + mPointer->setBrush(QBrush(QColor(255, 0, 0, 186))); + + mPointer->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); + mPointer->setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Pointer)); //Necessary to set if we want z value to be assigned correctly + + mTools << mPointer; + addItem(mPointer); +} + +qreal UBGraphicsScene::generateZLevel(QGraphicsItem *item) +{ + qreal result = UBZLayerController::errorNum(); + itemLayerType::Enum type = static_cast(item->data(UBGraphicsItemData::itemLayerType).toInt()); + + if (mZLayerController.validLayerType(type)) { + result = mZLayerController.generateZLevel(type); + } + return result; +} void UBGraphicsScene::setToolCursor(int tool) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 446bfb93..1cdd37e4 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -25,7 +25,6 @@ #include "UBItem.h" #include "tools/UBGraphicsCurtainItem.h" - class UBGraphicsPixmapItem; class UBGraphicsProxyWidget; class UBGraphicsSvgItem; @@ -50,11 +49,41 @@ class UBGraphicsCache; const double PI = 4.0 * atan(1.0); +class UBZLayerController +{ +public: + + struct ItemLayerTypeData { + ItemLayerTypeData() : bottomLimit(0), topLimit(0), curValue(0) {;} + ItemLayerTypeData(qreal bot, qreal top) : bottomLimit(bot), topLimit(top), curValue(bot) {;} + qreal bottomLimit; + qreal topLimit; + qreal curValue; + }; + + typedef QMap ScopeMap; + + UBZLayerController(); + + qreal getBottomLimit(itemLayerType::Enum key) const {return scopeMap.value(key).bottomLimit;} + qreal getTopLimit(itemLayerType::Enum key) const {return scopeMap.value(key).topLimit;} + bool validLayerType(itemLayerType::Enum key) const {return scopeMap.contains(key);} + static qreal errorNum() {return errorNumber;} + + qreal generateZLevel(itemLayerType::Enum key); + + private: + ScopeMap scopeMap; + static qreal errorNumber; + +}; + class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem { Q_OBJECT public: + // tmp stub for divide addings scene objects from undo mechanism implementation void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} @@ -152,23 +181,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem return mCrossedBackground; } - void setDrawingZIndex(qreal pDrawingZIndex) - { - mDrawingZIndex = pDrawingZIndex; - } - - void setObjectZIndex(qreal pObjectZIndex) - { - mObjectZIndex = pObjectZIndex; - } - bool hasBackground() { return (mBackgroundObject != 0); } - qreal getNextObjectZIndex(); - void addRuler(QPointF center); void addProtractor(QPointF center); void addCompass(QPointF center); @@ -225,11 +242,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void setNominalSize(int pWidth, int pHeight); - qreal currentObjectZIndex() - { - return mObjectZIndex; - } - enum RenderingContext { Screen = 0, NonScreen, PdfExport, Podcast @@ -276,7 +288,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void hideEraser(); void setBackground(bool pIsDark, bool pIsCrossed); - + void setBackgroundZoomFactor(qreal zoom); + void setDrawingMode(bool bModeDesktop); void deselectAllItems(); UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false); @@ -314,18 +327,19 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void recolorAllItems(); - qreal getNextDrawingZIndex(); - - virtual void drawItems (QPainter * painter, int numItems, + virtual void drawItems (QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[], QWidget * widget = 0); QGraphicsItem* rootItem(QGraphicsItem* item) const; + virtual void drawBackground(QPainter *painter, const QRectF &rect); + private: void setDocumentUpdated(); + void createEraiser(); + void createPointer(); - qreal mDrawingZIndex; - qreal mObjectZIndex; + qreal generateZLevel(QGraphicsItem *item); QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mPointer; @@ -337,6 +351,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem bool mDarkBackground; bool mCrossedBackground; + bool mIsDesktopMode; + qreal mZoomFactor; bool mIsModified; @@ -376,7 +392,10 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBMagnifier *magniferControlViewWidget; UBMagnifier *magniferDisplayViewWidget; + UBZLayerController mZLayerController; }; + + #endif /* UBGRAPHICSSCENE_H_ */ diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 9d8798ec..5e572b19 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -37,7 +37,6 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QString& pFilePath, QGraphicsItem* pa } } - UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* parent) : QGraphicsSvgItem(parent) { @@ -61,6 +60,8 @@ void UBGraphicsSvgItem::init() setCacheMode(QGraphicsItem::DeviceCoordinateCache); setMaximumCacheSize(boundingRect().size().toSize() * UB_MAX_ZOOM); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } @@ -132,8 +133,6 @@ UBItem* UBGraphicsSvgItem::deepCopy() const UBGraphicsSvgItem* copy = new UBGraphicsSvgItem(this->fileData()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -187,8 +186,6 @@ UBGraphicsPixmapItem* UBGraphicsSvgItem::toPixmapItem() const pixmapItem->setPixmap(QPixmap::fromImage(image)); pixmapItem->setPos(this->pos()); -// pixmapItem->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(pixmapItem, this->zValue()); pixmapItem->setTransform(this->transform()); pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 0d01527a..f42158f3 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -40,23 +40,11 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) mTypeTextHereLabel = tr(""); -// if (lastUsedTextColor.isValid()) -// { -// setDefaultTextColor(lastUsedTextColor); -// setColorOnDarkBackground(lastUsedTextColor); -// setColorOnLightBackground(lastUsedTextColor); -// } -// else -// { -// QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); -// QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); - -// setColorOnDarkBackground(colorOnDarkBG); -// setColorOnLightBackground(colorOnLightBG); -// } setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); // setData(UBGraphicsItemData::ItemEditable, QVariant(true)); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + setFlag(QGraphicsItem::ItemIsSelectable, true); // setFlag(QGraphicsItem::ItemIsMovable, true); @@ -205,8 +193,6 @@ UBItem* UBGraphicsTextItem::deepCopy() const copy->setHtml(toHtml()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index ea031cf1..6c6ea66e 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -96,10 +96,10 @@ void UBGraphicsTextItemDelegate::buildButtons() { UBGraphicsItemDelegate::buildButtons(); - mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame); - mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame); - mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame); - mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame); + mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection); + mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame, Qt::TopLeftSection); + mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TopLeftSection); + mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::TopLeftSection); connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont())); connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor())); diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index c1e57e4d..887fdb7a 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -51,6 +51,8 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl& pVideoFileUrl, QGraphicsIte mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + connect(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool))); } @@ -68,8 +70,6 @@ UBItem* UBGraphicsVideoItem::deepCopy() const UBGraphicsVideoItem *copy = new UBGraphicsVideoItem(videoUrl, parentItem()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsVideoItemDelegate.cpp b/src/domain/UBGraphicsVideoItemDelegate.cpp index 99ba687b..35620cf0 100644 --- a/src/domain/UBGraphicsVideoItemDelegate.cpp +++ b/src/domain/UBGraphicsVideoItemDelegate.cpp @@ -52,8 +52,7 @@ void UBGraphicsVideoItemDelegate::buildButtons() mMuteButton->hide(); mVideoControl = new DelegateVideoControl(delegated(), mFrame); -// mVideoControl->setZValue(UBGraphicsScene::toolLayerStart + 2); - UBGraphicsItem::assignZValue(mVideoControl, UBGraphicsScene::toolLayerStart + 2); + UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue()); mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); @@ -106,6 +105,7 @@ void UBGraphicsVideoItemDelegate::positionHandles() } mVideoControl->setAntiScale(mAntiScaleRatio); + mVideoControl->setZValue(delegated()->zValue()); mVideoControl->show(); } else diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 54baebc7..899a7714 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -39,6 +39,7 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this, widgetType); delegate->init(); setDelegate(delegate); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } @@ -154,6 +155,8 @@ void UBGraphicsWidgetItem::initialize() if (mDelegate && mDelegate->frame() && mWebKitWidget->resizable()) mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } @@ -408,7 +411,6 @@ UBItem* UBGraphicsW3CWidgetItem::deepCopy() const UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(mWebKitWidget->widgetUrl(), parentItem()); copy->setPos(this->pos()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 9a318011..e10cd57a 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -17,6 +17,7 @@ #include #include "domain/UBGraphicsItemDelegate.h" +#include "core/UB.h" class UBGraphicsScene; diff --git a/src/gui/UBMagnifer.cpp b/src/gui/UBMagnifer.cpp index 08285c91..93693797 100644 --- a/src/gui/UBMagnifer.cpp +++ b/src/gui/UBMagnifer.cpp @@ -1,388 +1,402 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include "UBMagnifer.h" - -#include "core/UBApplication.h" -#include "board/UBBoardController.h" -#include "domain/UBGraphicsScene.h" - -#include "core/memcheck.h" - - -UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) - : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) - , mShouldMoveWidget(false) - , mShouldResizeWidget(false) - , inTimer(false) - , borderPen(Qt::darkGray) - , gView(0) - , mView(0) -{ - isCusrsorAlreadyStored = false; - setMouseTracking(true); - - //--------------------------------------------------// - - QPixmap pix(":/images/cursors/resize.png"); - QTransform tr; - tr.rotate(45); - mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); - - //--------------------------------------------------// - - params.sizePercentFromScene = 20; - m_isInteractive = isInteractive; - sClosePixmap = new QPixmap(":/images/close.svg"); - sIncreasePixmap = new QPixmap(":/images/increase.svg"); - sDecreasePixmap = new QPixmap(":/images/decrease.svg"); - mResizeItem = new QPixmap(":/images/resize.svg"); - - if (parent) - { - setAttribute(Qt::WA_NoMousePropagation); - } - else - { - // standalone window - // !!!! Should be included into Windows after QT recompilation -#ifndef Q_WS_WIN -// setAttribute(Qt::WA_TranslucentBackground); - setAttribute(Qt::WA_MacAlwaysShowToolWindow); -#endif -#ifdef Q_WS_MAC - setAttribute(Qt::WA_MacAlwaysShowToolWindow); - setAttribute(Qt::WA_MacNonActivatingToolWindow); - setAttribute(Qt::WA_MacNoShadow); -#endif - } - -} - -UBMagnifier::~UBMagnifier() -{ - if (timerUpdate != 0) - { - killTimer(timerUpdate); - timerUpdate = 0; - } - - if(sClosePixmap) - { - delete sClosePixmap; - sClosePixmap = NULL; - } - - if(sIncreasePixmap) - { - delete sIncreasePixmap; - sIncreasePixmap = NULL; - } - - if(sDecreasePixmap) - { - delete sDecreasePixmap; - sDecreasePixmap = NULL; - } -} - -void UBMagnifier::setSize(qreal percentFromScene) -{ - if(gView == NULL || mView == NULL) return; - - // calculate object size - params.sizePercentFromScene = percentFromScene; - QSize sceneSize = mView->size(); - qreal size = params.sizePercentFromScene * sceneSize.width() / 100; - - QRect currGeom = geometry(); - if(currGeom.width() == currGeom.height()) - { - QPoint newPos = mView->mapFromGlobal(updPointMove); - setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); - } - else - setGeometry(0, 0, size, size); - - // prepare transparent bit mask - QImage mask_img(width(), height(), QImage::Format_Mono); - mask_img.fill(0xff); - QPainter mask_ptr(&mask_img); - mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); - mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); - bmpMask = QBitmap::fromImage(mask_img); - - // prepare general image - pMap = QPixmap(width(), height()); - pMap.fill(Qt::transparent); - pMap.setMask(bmpMask); -} - -void UBMagnifier::setZoom(qreal zoom) -{ - params.zoom = zoom; -} - -void UBMagnifier::paintEvent(QPaintEvent * event) -{ - Q_UNUSED(event); - QPainter painter(this); - - painter.setRenderHint(QPainter::Antialiasing); - painter.setPen(Qt::NoPen); - - if (m_isInteractive) - { - painter.setBrush(QColor(127, 127, 127, 127)); - painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); - - painter.setBrush(QColor(190, 190, 190, 255)); - painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); - - painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); - painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); - painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); - - painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); - } - else - { - painter.setBrush(QColor(127, 127, 127, 127)); - painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); - } - - painter.drawPixmap(0, 0, pMap); -} - -void UBMagnifier::mousePressEvent ( QMouseEvent * event ) -{ - if(m_isInteractive) - { - - QWidget::mousePressEvent(event); - - if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && - event->pos().x() < size().width() - 20 && - event->pos().y() >= size().height() - mResizeItem->height() - 20 && - event->pos().y() < size().height() - - 20) - { - mShouldResizeWidget = true; - } - else - { - mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); - } - - mMousePressPos = event->pos(); - mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); - - event->accept(); - - update(); - } - else - event->ignore(); -} - -void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) -{ - if(m_isInteractive) - { - if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) - { - move(pos() - mMousePressPos + event->pos()); - event->accept(); - - QWidget::mouseMoveEvent(event); - emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); - return; - } - - if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) - { - - QPoint currGlobalPos = event->globalPos(); - qreal cvW = mView->width(); - - qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; - qreal newPercentSize = newXSize * 100 / cvW; - - emit magnifierResized_Signal(newPercentSize); - - event->ignore(); - return; - } - - if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && - event->pos().x() < size().width() - 20 && - event->pos().y() >= size().height() - mResizeItem->height() - 20 && - event->pos().y() < size().height() - - 20 && - isCusrsorAlreadyStored == false - ) - { - mOldCursor = cursor(); - isCusrsorAlreadyStored = true; - setCursor(mResizeCursor); - } - - } - else - event->ignore(); -} - - -void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) -{ - if(m_isInteractive) - { - mShouldMoveWidget = false; - mShouldResizeWidget = false; - - if (event->pos().x() >= size().width() - sClosePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 && - event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) - { - event->accept(); - emit magnifierClose_Signal(); - } - else - if (event->pos().x() >= size().width() - sIncreasePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 && - event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) - { - event->accept(); - emit magnifierZoomIn_Signal(); - } - else - if (event->pos().x() >= size().width() - sDecreasePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 && - event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) - { - event->accept(); - emit magnifierZoomOut_Signal(); - } - else - QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool - } - else - event->ignore(); - -} - -void UBMagnifier::timerEvent(QTimerEvent *e) -{ - if(inTimer) return; - if (e->timerId() == timerUpdate) - { - inTimer = true; - if(!(updPointGrab.isNull())) - grabPoint(updPointGrab); - - if(isCusrsorAlreadyStored) - { - QPoint globalCursorPos = QCursor::pos(); - QPoint cursorPos = mapFromGlobal(globalCursorPos); - if (cursorPos.x() < size().width() - mResizeItem->width() - 20 || - cursorPos.x() > size().width() - 20 || - cursorPos.y() < size().height() - mResizeItem->height() - 20 || - cursorPos.y() > size().height() - - 20 - ) - { - isCusrsorAlreadyStored = false; - setCursor(mOldCursor); - } - - } - - inTimer = false; - } -} - -void UBMagnifier::grabPoint() -{ - QPointF itemPos = gView->mapFromGlobal(updPointGrab); - - qreal zWidth = size().width() / params.zoom; - qreal zWidthHalf = zWidth / 2; - qreal zHeight = size().height() / params.zoom; - qreal zHeightHalf = zHeight / 2; - - int x = itemPos.x() - zWidthHalf; - int y = itemPos.y() - zHeightHalf; - - QPixmap newPixMap(QSize(zWidth,zHeight)); - ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); - UBApplication::boardController->activeScene()->update(); - - pMap.fill(Qt::transparent); - pMap = newPixMap.scaled(QSize(width(), height())); - pMap.setMask(bmpMask); - - update(); -} - -void UBMagnifier::grabPoint(const QPoint &pGrab) -{ - updPointGrab = pGrab; - QPointF itemPos = gView->mapFromGlobal(pGrab); - - qreal zWidth = size().width() / params.zoom; - qreal zWidthHalf = zWidth / 2; - qreal zHeight = size().height() / params.zoom; - qreal zHeightHalf = zHeight / 2; - - int x = itemPos.x() - zWidthHalf; - int y = itemPos.y() - zHeightHalf; - - QPixmap newPixMap(QSize(zWidth,zHeight)); - ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); - UBApplication::boardController->activeScene()->update(); - - pMap.fill(Qt::transparent); - pMap = newPixMap.scaled(QSize(width(), height())); - pMap.setMask(bmpMask); - - update(); -} - -// from global -void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) -{ - updPointGrab = pGrab; - updPointMove = pMove; - - if(needGrab) - grabPoint(pGrab); - - if(needMove) - { - QPoint movePos = mView->mapFromGlobal(pMove); - move(movePos.x() - width()/2, movePos.y() - height()/2); - // move(itemPos.x(), itemPos.y()); - } -} - -void UBMagnifier::setGrabView(QWidget *view) -{ - if (timerUpdate != 0) - killTimer(timerUpdate); - gView = view; - timerUpdate = startTimer(200); -} - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "UBMagnifer.h" + +#include "core/UBApplication.h" +#include "board/UBBoardController.h" +#include "domain/UBGraphicsScene.h" +#include "board/UBBoardView.h" + +#include "core/memcheck.h" + + +UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) + : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) + , mShouldMoveWidget(false) + , mShouldResizeWidget(false) + , borderPen(Qt::darkGray) + , gView(0) + , mView(0) +{ + isCusrsorAlreadyStored = false; + setMouseTracking(true); + + //--------------------------------------------------// + + QPixmap pix(":/images/cursors/resize.png"); + QTransform tr; + tr.rotate(45); + mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); + + //--------------------------------------------------// + + params.sizePercentFromScene = 20; + m_isInteractive = isInteractive; + sClosePixmap = new QPixmap(":/images/close.svg"); + sIncreasePixmap = new QPixmap(":/images/increase.svg"); + sDecreasePixmap = new QPixmap(":/images/decrease.svg"); + mResizeItem = new QPixmap(":/images/resize.svg"); + + if (parent) + { + setAttribute(Qt::WA_NoMousePropagation); + } + else + { + // standalone window + // !!!! Should be included into Windows after QT recompilation +#ifndef Q_WS_WIN +// setAttribute(Qt::WA_TranslucentBackground); + setAttribute(Qt::WA_MacAlwaysShowToolWindow); +#endif +#ifdef Q_WS_MAC + setAttribute(Qt::WA_MacAlwaysShowToolWindow); + setAttribute(Qt::WA_MacNonActivatingToolWindow); + setAttribute(Qt::WA_MacNoShadow); +#endif + } + + connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh())); +} + +UBMagnifier::~UBMagnifier() +{ + if(sClosePixmap) + { + delete sClosePixmap; + sClosePixmap = NULL; + } + + if(sIncreasePixmap) + { + delete sIncreasePixmap; + sIncreasePixmap = NULL; + } + + if(sDecreasePixmap) + { + delete sDecreasePixmap; + sDecreasePixmap = NULL; + } +} + +void UBMagnifier::setSize(qreal percentFromScene) +{ + if(gView == NULL || mView == NULL) return; + + // calculate object size + params.sizePercentFromScene = percentFromScene; + QSize sceneSize = mView->size(); + qreal size = params.sizePercentFromScene * sceneSize.width() / 100; + + QRect currGeom = geometry(); + if(currGeom.width() == currGeom.height()) + { + QPoint newPos = mView->mapFromGlobal(updPointMove); + setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); + } + else + setGeometry(0, 0, size, size); + + // prepare transparent bit mask + QImage mask_img(width(), height(), QImage::Format_Mono); + mask_img.fill(0xff); + QPainter mask_ptr(&mask_img); + mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); + mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); + bmpMask = QBitmap::fromImage(mask_img); + + // prepare general image + pMap = QPixmap(width(), height()); + pMap.fill(Qt::transparent); + pMap.setMask(bmpMask); +} + +void UBMagnifier::setZoom(qreal zoom) +{ + params.zoom = zoom; +} + +void UBMagnifier::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + QPainter painter(this); + + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::NoPen); + + if (m_isInteractive) + { + painter.setBrush(QColor(127, 127, 127, 127)); + painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); + + painter.setBrush(QColor(190, 190, 190, 255)); + painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); + + painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); + painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); + painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); + + painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); + } + else + { + painter.setBrush(QColor(127, 127, 127, 127)); + painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); + } + + painter.drawPixmap(0, 0, pMap); +} + +void UBMagnifier::mousePressEvent ( QMouseEvent * event ) +{ + if(m_isInteractive) + { + + QWidget::mousePressEvent(event); + + if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && + event->pos().x() < size().width() - 20 && + event->pos().y() >= size().height() - mResizeItem->height() - 20 && + event->pos().y() < size().height() - - 20) + { + mShouldResizeWidget = true; + } + else + { + mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); + } + + mMousePressPos = event->pos(); + mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); + + event->accept(); + + update(); + } + else + event->ignore(); +} + +void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) +{ + if(m_isInteractive) + { + if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) + { + move(pos() - mMousePressPos + event->pos()); + event->accept(); + + QWidget::mouseMoveEvent(event); + emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); + return; + } + + if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) + { + + QPoint currGlobalPos = event->globalPos(); + qreal cvW = mView->width(); + + qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; + qreal newPercentSize = newXSize * 100 / cvW; + + emit magnifierResized_Signal(newPercentSize); + + event->ignore(); + return; + } + + if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && + event->pos().x() < size().width() - 20 && + event->pos().y() >= size().height() - mResizeItem->height() - 20 && + event->pos().y() < size().height() - - 20 && + isCusrsorAlreadyStored == false + ) + { + mOldCursor = cursor(); + isCusrsorAlreadyStored = true; + setCursor(mResizeCursor); + } + + } + else + event->ignore(); +} + + +void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) +{ + if(m_isInteractive) + { + mShouldMoveWidget = false; + mShouldResizeWidget = false; + + if (event->pos().x() >= size().width() - sClosePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 && + event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) + { + event->accept(); + emit magnifierClose_Signal(); + } + else + if (event->pos().x() >= size().width() - sIncreasePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 && + event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) + { + event->accept(); + emit magnifierZoomIn_Signal(); + } + else + if (event->pos().x() >= size().width() - sDecreasePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 && + event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) + { + event->accept(); + emit magnifierZoomOut_Signal(); + } + else + QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool + } + else + event->ignore(); + +} + +void UBMagnifier::slot_refresh() +{ + if(!(updPointGrab.isNull())) + grabPoint(updPointGrab); + + if(isCusrsorAlreadyStored) + { + QPoint globalCursorPos = QCursor::pos(); + QPoint cursorPos = mapFromGlobal(globalCursorPos); + if (cursorPos.x() < size().width() - mResizeItem->width() - 20 || + cursorPos.x() > size().width() - 20 || + cursorPos.y() < size().height() - mResizeItem->height() - 20 || + cursorPos.y() > size().height() - - 20 + ) + { + isCusrsorAlreadyStored = false; + setCursor(mOldCursor); + } + } +} + +void UBMagnifier::grabPoint() +{ + QMatrix transM = UBApplication::boardController->controlView()->matrix(); + QPointF itemPos = gView->mapFromGlobal(updPointGrab); + + qreal zWidth = width() / (params.zoom * transM.m11()); + qreal zWidthHalf = zWidth / 2; + qreal zHeight = height() / (params.zoom * transM.m22()); + qreal zHeightHalf = zHeight / 2; + + + QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); + + + QRect magnifierRect = rect(); + + float x = pfScLtF.x() - zWidthHalf; + float y = pfScLtF.y() - zHeightHalf; + + QPointF leftTop(x,y); + QPointF rightBottom(x + zWidth, y + zHeight); + QRectF srcRect(leftTop, rightBottom); + + QPixmap newPixMap(QSize(width(), height())); + QPainter painter(&newPixMap); + + UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); + painter.end(); + + pMap.fill(Qt::transparent); + pMap = newPixMap.scaled(QSize(width(), height())); + pMap.setMask(bmpMask); + + update(); +} + +void UBMagnifier::grabPoint(const QPoint &pGrab) +{ + QMatrix transM = UBApplication::boardController->controlView()->matrix(); + updPointGrab = pGrab; + QPointF itemPos = gView->mapFromGlobal(pGrab); + + qreal zWidth = width() / (params.zoom * transM.m11()); + qreal zWidthHalf = zWidth / 2; + qreal zHeight = height() / (params.zoom * transM.m22()); + qreal zHeightHalf = zHeight / 2; + + + QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); + + + QRect magnifierRect = rect(); + + float x = pfScLtF.x() - zWidthHalf; + float y = pfScLtF.y() - zHeightHalf; + + QPointF leftTop(x,y); + QPointF rightBottom(x + zWidth, y + zHeight); + QRectF srcRect(leftTop, rightBottom); + + QPixmap newPixMap(QSize(width(), height())); + QPainter painter(&newPixMap); + + UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); + painter.end(); + + // pMap.fill(Qt::transparent); + pMap = newPixMap; + pMap.setMask(bmpMask); + + update(); +} + + + +// from global +void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) +{ + updPointGrab = pGrab; + updPointMove = pMove; + + if(needGrab) + grabPoint(pGrab); + + if(needMove) + { + QPoint movePos = mView->mapFromGlobal(pMove); + move(movePos.x() - width()/2, movePos.y() - height()/2); + // move(itemPos.x(), itemPos.y()); + } +} + +void UBMagnifier::setGrabView(QWidget *view) +{ + gView = view; + mRefreshTimer.setInterval(40); + mRefreshTimer.start(); +} + diff --git a/src/gui/UBMagnifer.h b/src/gui/UBMagnifer.h index 73a81692..7a118a99 100644 --- a/src/gui/UBMagnifer.h +++ b/src/gui/UBMagnifer.h @@ -1,96 +1,97 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UBMAGNIFIER_H -#define UBMAGNIFIER_H - -#include - -class UBMagnifierParams -{ -public : - int x; - int y; - qreal zoom; - qreal sizePercentFromScene; -}; - -class UBMagnifier : public QWidget -{ - Q_OBJECT - -public: - UBMagnifier(QWidget *parent = 0, bool isInteractive = false); - ~UBMagnifier(); - - void setSize(qreal percentFromScene); - void setZoom(qreal zoom); - - void setGrabView(QWidget *view); - void setMoveView(QWidget *view) {mView = view;} - - void grabPoint(); - void grabPoint(const QPoint &point); - void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); - - UBMagnifierParams params; - -signals: - void magnifierMoved_Signal(QPoint newPos); - void magnifierClose_Signal(); - void magnifierZoomIn_Signal(); - void magnifierZoomOut_Signal(); - void magnifierResized_Signal(qreal newPercentSize); - -protected: - void paintEvent(QPaintEvent *); - void timerEvent(QTimerEvent *); - - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent * event ); - virtual void mouseReleaseEvent ( QMouseEvent * event ); - - QPoint mMousePressPos; - qreal mMousePressDelta; - bool mShouldMoveWidget; - bool mShouldResizeWidget; - - - QPixmap *sClosePixmap; - QPixmap *sIncreasePixmap; - QPixmap *sDecreasePixmap; - QPixmap *mResizeItem; - - bool isCusrsorAlreadyStored; - QCursor mOldCursor; - QCursor mResizeCursor; - -private: - bool inTimer; - bool m_isInteractive; - - int timerUpdate; - QPoint updPointGrab; - QPoint updPointMove; - - QPixmap pMap; - QBitmap bmpMask; - QPen borderPen; - - QWidget *gView; - QWidget *mView; -}; - -#endif // UBMAGNIFIER_H +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef UBMAGNIFIER_H +#define UBMAGNIFIER_H + +#include + +class UBMagnifierParams +{ +public : + int x; + int y; + qreal zoom; + qreal sizePercentFromScene; +}; + +class UBMagnifier : public QWidget +{ + Q_OBJECT + +public: + UBMagnifier(QWidget *parent = 0, bool isInteractive = false); + ~UBMagnifier(); + + void setSize(qreal percentFromScene); + void setZoom(qreal zoom); + + void setGrabView(QWidget *view); + void setMoveView(QWidget *view) {mView = view;} + + void grabPoint(); + void grabPoint(const QPoint &point); + void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); + + UBMagnifierParams params; + +signals: + void magnifierMoved_Signal(QPoint newPos); + void magnifierClose_Signal(); + void magnifierZoomIn_Signal(); + void magnifierZoomOut_Signal(); + void magnifierResized_Signal(qreal newPercentSize); + +public slots: + void slot_refresh(); + +protected: + void paintEvent(QPaintEvent *); + + virtual void mousePressEvent ( QMouseEvent * event ); + virtual void mouseMoveEvent ( QMouseEvent * event ); + virtual void mouseReleaseEvent ( QMouseEvent * event ); + + QPoint mMousePressPos; + qreal mMousePressDelta; + bool mShouldMoveWidget; + bool mShouldResizeWidget; + + + QPixmap *sClosePixmap; + QPixmap *sIncreasePixmap; + QPixmap *sDecreasePixmap; + QPixmap *mResizeItem; + + bool isCusrsorAlreadyStored; + QCursor mOldCursor; + QCursor mResizeCursor; + +private: + QTimer mRefreshTimer; + bool m_isInteractive; + + QPoint updPointGrab; + QPoint updPointMove; + + QPixmap pMap; + QBitmap bmpMask; + QPen borderPen; + + QWidget *gView; + QWidget *mView; +}; + +#endif // UBMAGNIFIER_H diff --git a/src/tools/UBAbstractDrawRuler.cpp b/src/tools/UBAbstractDrawRuler.cpp index e69aa815..385e55c6 100644 --- a/src/tools/UBAbstractDrawRuler.cpp +++ b/src/tools/UBAbstractDrawRuler.cpp @@ -48,6 +48,7 @@ UBAbstractDrawRuler::UBAbstractDrawRuler() QDesktopWidget* desktop = UBApplication::desktop(); int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; sPixelsPerMillimeter = qRound(dpiCommon / 25.4f);//because 1inch = 25.4 mm + } void UBAbstractDrawRuler::create(QGraphicsItem& item) diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index cff7c43c..ae178ea9 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -33,14 +33,12 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem() // Get the board size and pass it to the shape QRect boardRect = UBApplication::boardController->displayView()->rect(); setRect(-15*boardRect.width(), -15*boardRect.height(), 30*boardRect.width(), 30*boardRect.height()); -// setZValue(CACHE_ZVALUE); - UBGraphicsItem::assignZValue(this, CACHE_ZVALUE); setData(Qt::UserRole, QVariant("Cache")); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Cache)); //Necessary to set if we want z value to be assigned correctly } UBGraphicsCache::~UBGraphicsCache() { - } UBItem* UBGraphicsCache::deepCopy() const @@ -49,8 +47,6 @@ UBItem* UBGraphicsCache::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? @@ -92,8 +88,6 @@ void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *o Q_UNUSED(option); Q_UNUSED(widget); - UBGraphicsItem::assignZValue(this, CACHE_ZVALUE); - painter->setBrush(mMaskColor); painter->setPen(mMaskColor); diff --git a/src/tools/UBGraphicsCache.h b/src/tools/UBGraphicsCache.h index 6a8ce4cd..6a27233b 100644 --- a/src/tools/UBGraphicsCache.h +++ b/src/tools/UBGraphicsCache.h @@ -21,8 +21,6 @@ #include "domain/UBItem.h" #include "core/UB.h" -#define CACHE_ZVALUE 100000 - typedef enum { eMaskShape_Circle, diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp index 6e13b125..f2bc45df 100644 --- a/src/tools/UBGraphicsCompass.cpp +++ b/src/tools/UBGraphicsCompass.cpp @@ -70,6 +70,8 @@ UBGraphicsCompass::UBGraphicsCompass() unsetCursor(); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + connect(UBApplication::boardController, SIGNAL(penColorChanged()), this, SLOT(penColorChanged())); connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged())); } @@ -85,8 +87,6 @@ UBItem* UBGraphicsCompass::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index a71a224d..6f0154d8 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -49,6 +49,8 @@ UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Tool); setPen(Qt::NoPen); this->setAcceptHoverEvents(true); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Curtain)); //Necessary to set if we want z value to be assigned correctly } UBGraphicsCurtainItem::~UBGraphicsCurtainItem() @@ -58,8 +60,6 @@ UBGraphicsCurtainItem::~UBGraphicsCurtainItem() QVariant UBGraphicsCurtainItem::itemChange(GraphicsItemChange change, const QVariant &value) { -// if (change == QGraphicsItem::ItemSelectedHasChanged && QGraphicsRectItem::scene() && isSelected()) -// setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCurtain); QVariant newValue = value; @@ -131,8 +131,6 @@ UBItem* UBGraphicsCurtainItem::deepCopy() const copy->setPos(this->pos()); copy->setBrush(this->brush()); copy->setPen(this->pen()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/tools/UBGraphicsCurtainItemDelegate.cpp b/src/tools/UBGraphicsCurtainItemDelegate.cpp index a16685b6..4161c50d 100644 --- a/src/tools/UBGraphicsCurtainItemDelegate.cpp +++ b/src/tools/UBGraphicsCurtainItemDelegate.cpp @@ -52,7 +52,6 @@ bool UBGraphicsCurtainItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *ev if (!mDelegated->isSelected()) { mDelegated->setSelected(true); -// mDelegated->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCurtain); positionHandles(); return true; diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index bafb5689..129a1250 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -63,6 +63,7 @@ UBGraphicsProtractor::UBGraphicsProtractor() mRotateSvgItem->setVisible(false); mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly scale(1.5, 1.5); } @@ -580,8 +581,6 @@ UBItem* UBGraphicsProtractor::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->mCurrentAngle = this->mCurrentAngle; diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 2bf27719..728b5bad 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -44,6 +44,8 @@ UBGraphicsRuler::UBGraphicsRuler() create(*this); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + updateResizeCursor(); } @@ -74,8 +76,6 @@ UBItem* UBGraphicsRuler::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index e5c7fdeb..bd4156e0 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -43,8 +43,8 @@ UBGraphicsTriangle::UBGraphicsTriangle() mHFlipSvgItem = new QGraphicsSvgItem(":/images/hflipTool.svg", this); mHFlipSvgItem->setVisible(false); - mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mVFlipSvgItem = new QGraphicsSvgItem(":/images/vflipTool.svg", this); mVFlipSvgItem->setVisible(false); @@ -54,6 +54,8 @@ UBGraphicsTriangle::UBGraphicsTriangle() mRotateSvgItem->setVisible(false); mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + updateResizeCursor(); } @@ -93,8 +95,6 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const copy->setPos(this->pos()); copy->setPolygon(this->polygon()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? From 4f8648e8b6730904f950e2ce9d5d1f3931d0c416 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 5 Apr 2012 11:06:09 +0200 Subject: [PATCH 08/18] fixed issue on mirroring --- src/domain/UBGraphicsDelegateFrame.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 21c4e8fd..1eacc6c3 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -71,9 +71,11 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega mBottomResizeGrip = new QGraphicsRectItem(this); mBottomResizeGrip->setPen(Qt::NoPen); mLeftResizeGrip = new QGraphicsRectItem(this); + mLeftResizeGrip->setToolTip("left"); mLeftResizeGrip->setPen(Qt::NoPen); mRightResizeGrip = new QGraphicsRectItem(this); mRightResizeGrip->setPen(Qt::NoPen); + mRightResizeGrip->setToolTip("Right"); mTopResizeGrip = new QGraphicsRectItem(this); mTopResizeGrip->setPen(Qt::NoPen); @@ -159,6 +161,7 @@ void UBGraphicsDelegateFrame::initializeTransform() QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft()); qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1; + mMirrorX = horizontalFlip < 0 ; if(horizontalFlip < 0){ // why this is because of the way of calculating the translations that checks which side is the most is the // nearest instead of checking which one is the left side. @@ -172,12 +175,15 @@ void UBGraphicsDelegateFrame::initializeTransform() qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1; // not sure that is usefull - if(verticalFlip < 0){ + mMirrorY = verticalFlip < 0; + if(verticalFlip < 0 && !mMirrorX){ topLeft = itemTransform.map(itemRect.bottomLeft()); topRight = itemTransform.map(itemRect.bottomRight()); bottomLeft = itemTransform.map(itemRect.topLeft()); } + qDebug() << "mMirrorX " << mMirrorX << " ,mMirrorY " << mMirrorY; + QLineF topLine(topLeft, topRight); QLineF leftLine(topLeft, bottomLeft); qreal width = topLine.length(); @@ -278,7 +284,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if(mDelegate->isFlippable() && qAbs(scaleX) != 0){ if((qAbs(width * scaleX)) < 2*mFrameWidth){ bool negative = (scaleX < 0)?true:false; - mMirrorX = (negative?mMirrorX:!mMirrorX); + //mMirrorX = (negative?mMirrorX:!mMirrorX); if(negative){ scaleX = -2*mFrameWidth/width; }else{ @@ -305,7 +311,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if(mDelegate->isFlippable() && qAbs(scaleY) != 0){ if((qAbs(height * scaleY)) < 2*mFrameWidth){ bool negative = (scaleY < 0)?true:false; - mMirrorY = (negative?mMirrorY:!mMirrorY); + //mMirrorY = (negative?mMirrorY:!mMirrorY); if(negative){ scaleY = -2*mFrameWidth/width; }else{ From 10bd10a38a474340a004d255a519dfa0c88cff92 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 5 Apr 2012 11:07:19 +0200 Subject: [PATCH 09/18] removed qDebug() --- src/domain/UBGraphicsDelegateFrame.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 1eacc6c3..6b389303 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -182,8 +182,6 @@ void UBGraphicsDelegateFrame::initializeTransform() bottomLeft = itemTransform.map(itemRect.topLeft()); } - qDebug() << "mMirrorX " << mMirrorX << " ,mMirrorY " << mMirrorY; - QLineF topLine(topLeft, topRight); QLineF leftLine(topLeft, bottomLeft); qreal width = topLine.length(); @@ -627,7 +625,6 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF } } else if (leftResizeGripRect().contains(pos)){ - qDebug() << "LEFT GRIP (" << mMirrorX << ")"; if(mMirrorX){ return ResizeRight; }else{ @@ -636,7 +633,6 @@ UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF return ResizeLeft; } else if (rightResizeGripRect().contains(pos)){ - qDebug() << "RIGHT GRIP (" << mMirrorX << ")"; if(mMirrorX){ return ResizeLeft; }else{ @@ -702,7 +698,6 @@ void UBGraphicsDelegateFrame::refreshGeometry() QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft()); QPointF center = itemTransform.map(itemRect.center()); - qDebug() << topLeft << ", " << topRight << ", " << bottomLeft; QLineF topLine(topLeft, topRight); qreal angle = topLine.angle(); From a9769e42365a19e06f640d88065215d659b78bc5 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Thu, 5 Apr 2012 11:16:11 +0200 Subject: [PATCH 10/18] backup --- src/domain/UBGraphicsDelegateFrame.cpp | 4 +++- src/domain/UBGraphicsPixmapItem.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 21c4e8fd..df89d4c1 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -273,12 +273,14 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if(resizingLeft()){ scaleX = (width - moveX) / width; }else if(resizingRight()){ - scaleX = (width + moveX) / width; + scaleX = (width + moveX) / width; } if(mDelegate->isFlippable() && qAbs(scaleX) != 0){ if((qAbs(width * scaleX)) < 2*mFrameWidth){ bool negative = (scaleX < 0)?true:false; + mMirrorX = (negative?mMirrorX:!mMirrorX); + if(negative){ scaleX = -2*mFrameWidth/width; }else{ diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 07dc4679..223ca4a2 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -32,7 +32,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) mDelegate->init(); // NOTE: Do not remove this code, I'm just doing a backup of my changes! thx.. - //mDelegate->setFlippable(true); + mDelegate->setFlippable(true); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setTransformationMode(Qt::SmoothTransformation); From ab1b28e0b8f957ae0351c748229ba3c0ee4d1302 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 5 Apr 2012 14:36:13 +0300 Subject: [PATCH 11/18] Fix for background objects --- src/board/UBBoardView.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index e1d1f0b2..c15618f0 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -427,7 +427,8 @@ UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsPDFItem::Type || movingItem->type() == UBGraphicsPolygonItem::Type || movingItem->type() == UBGraphicsCache::Type - || movingItem->type() == UBGraphicsTriangle::Type) + || movingItem->type() == UBGraphicsTriangle::Type + || movingItem == this->scene()->backgroundObject()) { movingItem = NULL; QGraphicsView::mousePressEvent (event); From 8a74d6ca0bdd9cf33787951f5f29b3d849bcde38 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 5 Apr 2012 14:07:28 +0200 Subject: [PATCH 12/18] wording --- .../Choisir.wgt/scripts/languages.js | 22 +++++++++---------- .../associer_images.wgt/js/script.js | 2 +- .../categoriser_images.wgt/js/script.js | 2 +- .../categoriser_text.wgt/js/script.js | 4 ++-- .../interactivities/etudier.wgt/js/script.js | 4 ++-- .../locales/fr/scripts/template2.js | 2 +- .../locales/fr/js/script.js | 6 ++--- .../locales/fr/js/script.js | 6 ++--- .../selectionner.wgt/locales/fr/js/script.js | 4 ++-- .../locales/fr/scripts/wcontainer.js | 4 ++-- .../locales/fr/scripts/wcontainer.js | 2 +- .../locales/fr/scripts/wcontainer.js | 2 +- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/resources/library/interactivities/Choisir.wgt/scripts/languages.js b/resources/library/interactivities/Choisir.wgt/scripts/languages.js index 071f5c67..a2989844 100644 --- a/resources/library/interactivities/Choisir.wgt/scripts/languages.js +++ b/resources/library/interactivities/Choisir.wgt/scripts/languages.js @@ -6,20 +6,20 @@ var sankoreLang = { "example_question":"This is an example of the question", "answer":"This is an example of the answer", "q":"Q", - "add_new_question":"Add new question ...", + "add_new_question":"Add a new question ...", "options":"Options", "close":"Close", - "delete_question":"Delete question", - "delete_answer":"Delete answer", + "delete_question":"Delete the question", + "delete_answer":"Delete a possibility", "right_answer":"Right answer", - "template_question":"Enter your question here ...", - "template_answer":"Enter the answer here ...", - "add_answer":"Add answer", + "template_question":"Enter a question here ...", + "template_answer":"Enter a possibility here ...", + "add_answer":"Add a possibility", "select_text":"Choose the right answer", - "options_desc":"You can choose any of these three options of displaying your answers. See a short their description.", - "radio_desc":"This option allow to choose one answer only and the answers are displayed as radio buttons.", - "checkbox_desc":"This option allow to choose several answers and the answers are displayed as checkboxes.", - "select_desc":"This option allow to chose one answer only and the answers are displayed as pull-down menu.", + "options_desc":"Types of question", + "radio_desc":"Option 1 : one right answer, possibilities are displayed as radio buttons.", + "checkbox_desc":"Option 2 : several right answers, possibilities are displayed as checkboxes.", + "select_desc":"Option 3 : one right answer, possibilities are displayed as pull-down menu.", "a":"A" }, "ru":{ @@ -59,7 +59,7 @@ var sankoreLang = { "delete_answer":"Supprimer la possibilité", "right_answer":"Bonne réponse", "template_question":"Saisir la question ici ...", - "template_answer":"Saisir la réponse ici ...", + "template_answer":"Saisir une possibilité ici ...", "add_answer":"Ajouter une possibilité", "select_text":"Choisir la bonne réponse", "options_desc":"Types de questions", diff --git a/resources/library/interactivities/associer_images.wgt/js/script.js b/resources/library/interactivities/associer_images.wgt/js/script.js index c850c3cb..55910d11 100644 --- a/resources/library/interactivities/associer_images.wgt/js/script.js +++ b/resources/library/interactivities/associer_images.wgt/js/script.js @@ -3,7 +3,7 @@ var sankoreLang = { edit: "Edit", short_desc: "Select the number \"three\".", add: "Add new block", - enter: "Enter your condition here ..." + enter: "Enter what to do here ..." }; //main function diff --git a/resources/library/interactivities/categoriser_images.wgt/js/script.js b/resources/library/interactivities/categoriser_images.wgt/js/script.js index 0eef29e0..79e1647e 100644 --- a/resources/library/interactivities/categoriser_images.wgt/js/script.js +++ b/resources/library/interactivities/categoriser_images.wgt/js/script.js @@ -3,7 +3,7 @@ var sankoreLang = { edit: "Edit", first_desc: "Odd numbers", second_desc: "Even numbers", - enter: "Enter your category name here ...", + enter: "Enter a category name here ...", add: "Add new block" }; diff --git a/resources/library/interactivities/categoriser_text.wgt/js/script.js b/resources/library/interactivities/categoriser_text.wgt/js/script.js index 6e209d47..a6491291 100644 --- a/resources/library/interactivities/categoriser_text.wgt/js/script.js +++ b/resources/library/interactivities/categoriser_text.wgt/js/script.js @@ -3,12 +3,12 @@ var sankoreLang = { edit: "Edit", first_desc: "Fruits", second_desc: "Vegetables", - potatoes: "Potatoes", + potatoes: "Potato", carrot: "Carrot", onion: "Onion", apple: "Apple", pear: "Pear", - enter: "Enter your category name here ...", + enter: "Enter a category name here ...", add: "Add new block", text: "Some text" }; diff --git a/resources/library/interactivities/etudier.wgt/js/script.js b/resources/library/interactivities/etudier.wgt/js/script.js index 0c8dbd3d..074b169b 100644 --- a/resources/library/interactivities/etudier.wgt/js/script.js +++ b/resources/library/interactivities/etudier.wgt/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { display: "Display", edit: "Edit", - text_content: "This is an example. Instead of this text you can put your own content.", + text_content: "This is an example. Instead of this text you can put your own content or drag an drop a picture or an audio file", new_txt: "New text block", - new_slide: "This is new slide." + new_slide: "This is a new slide." }; //some flags diff --git a/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js b/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js index 9418604a..fe887a32 100644 --- a/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js +++ b/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js @@ -29,7 +29,7 @@ function checkResponse() var sankoreLang = { view: "Afficher", edit: "Modifier", - example: "Il*y*a*longtemps*,*nous*Žtions*ˆ*la*mer*." + example: "Il*était*une*fois*..." }; var word = ""; diff --git a/resources/library/interactivities/ordonner_des_images.wgt/locales/fr/js/script.js b/resources/library/interactivities/ordonner_des_images.wgt/locales/fr/js/script.js index 7c8a2f19..45944117 100644 --- a/resources/library/interactivities/ordonner_des_images.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/ordonner_des_images.wgt/locales/fr/js/script.js @@ -1,10 +1,10 @@ var sankoreLang = { - display: "Affichage", + display: "Afficher", edit: "Modifier", - short_desc: "Placez les photos dans l'ordre croissant.", + short_desc: "Placer les photos dans l'ordre croissant.", add: "Nouveau bloc", - enter: "Saisissez votre texte ici ..." + enter: "Saisir votre texte ici ..." }; //main function diff --git a/resources/library/interactivities/ordonner_des_letters.wgt/locales/fr/js/script.js b/resources/library/interactivities/ordonner_des_letters.wgt/locales/fr/js/script.js index c0949d22..6530c52a 100644 --- a/resources/library/interactivities/ordonner_des_letters.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/ordonner_des_letters.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", - short_desc: "Ecoutez le son et faire le bon mot.", + short_desc: "Ecouter le son et replacer les lettres dans l'ordre.", add: "Nouveau bloc", - enter: "Entrez votre description ici ...", + enter: "Saisir la consigne ici ...", example: "exemple" }; diff --git a/resources/library/interactivities/selectionner.wgt/locales/fr/js/script.js b/resources/library/interactivities/selectionner.wgt/locales/fr/js/script.js index 7440523c..093aad50 100644 --- a/resources/library/interactivities/selectionner.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/selectionner.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { display: "Affichage", edit: "Modifier", - short_desc: "Sélectionnez les animaux de la liste suivante:", + short_desc: "Sélectionner les animaux dans la liste suivante :", add: "Nouveau bloc", - enter: "Saisissez votre texte ici ...", + enter: "Saisir le texte ici ...", cat: "chat", ball: "balle", shovel: "pelle", diff --git a/resources/library/interactivities/spl-phrase.wgt/locales/fr/scripts/wcontainer.js b/resources/library/interactivities/spl-phrase.wgt/locales/fr/scripts/wcontainer.js index cc1edff6..60ad007e 100644 --- a/resources/library/interactivities/spl-phrase.wgt/locales/fr/scripts/wcontainer.js +++ b/resources/library/interactivities/spl-phrase.wgt/locales/fr/scripts/wcontainer.js @@ -1,7 +1,7 @@ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", - example: "c'est un tas de mots qui ne devraient être répartis à part" + example: "Ceci est une série de mots à séparer correctement" }; // if use the "view/edit" button or rely on the api instead diff --git a/resources/library/interactivities/spl-text.wgt/locales/fr/scripts/wcontainer.js b/resources/library/interactivities/spl-text.wgt/locales/fr/scripts/wcontainer.js index 46ac92a9..465f59fc 100644 --- a/resources/library/interactivities/spl-text.wgt/locales/fr/scripts/wcontainer.js +++ b/resources/library/interactivities/spl-text.wgt/locales/fr/scripts/wcontainer.js @@ -1,5 +1,5 @@ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", example: "bonjour, ceci est la première phrase. salut, c'est la deuxième phrase. bonjour à nouveau, c'est la troisième phrase. bonjour, c'est la quatrième phrase. salut, désolé, je suis en retard, je suis la cinquième phrase." }; diff --git a/resources/library/interactivities/spl-word.wgt/locales/fr/scripts/wcontainer.js b/resources/library/interactivities/spl-word.wgt/locales/fr/scripts/wcontainer.js index 1f3edcca..f2ad8832 100644 --- a/resources/library/interactivities/spl-word.wgt/locales/fr/scripts/wcontainer.js +++ b/resources/library/interactivities/spl-word.wgt/locales/fr/scripts/wcontainer.js @@ -1,5 +1,5 @@ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", example: "so*phis*ti*qué" }; From a5aa8996da95d44709b80226ce812e9e26b3a7f6 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 5 Apr 2012 17:19:42 +0300 Subject: [PATCH 13/18] SANKORE-80 Objects rotation --- src/core/UBSettings.cpp | 3 +++ src/core/UBSettings.h | 5 +++-- src/domain/UBGraphicsDelegateFrame.cpp | 31 +++++++++++++++++++++++--- src/domain/UBGraphicsDelegateFrame.h | 7 +++++- src/domain/domain.pri | 6 +++-- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index afd08aa9..8e689a61 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -377,6 +377,8 @@ void UBSettings::init() KeyboardLocale = new UBSetting(this, "Board", "StartupKeyboardLocale", 0); swapControlAndDisplayScreens = new UBSetting(this, "App", "SwapControlAndDisplayScreens", false); + + angleTolerance = new UBSetting(this, "App", "AngleTolerance", 4); } @@ -1139,3 +1141,4 @@ QString UBSettings::replaceWildcard(QString& path) return result; } + diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 4e8c9666..d9d4d80d 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -97,8 +97,7 @@ class UBSettings : public QObject void setCommunityPassword(const QString& password); void init(); - - + //user directories static QString userDataDirectory(); static QString userDocumentDirectory(); @@ -326,6 +325,8 @@ class UBSettings : public QObject UBSetting* KeyboardLocale; UBSetting* swapControlAndDisplayScreens; + UBSetting* angleTolerance; + public slots: void setPenWidthIndex(int index); diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index ea90a676..8968d498 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -29,8 +29,6 @@ #include "core/memcheck.h" -qreal const UBGraphicsDelegateFrame::mAngleTolerance = 6; - UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelegate, QRectF pRect, qreal pFrameWidth, bool respectRatio) : QGraphicsRectItem(), QObject(pDelegate) , mCurrentTool(None) @@ -51,6 +49,8 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega , mMirrorX(false) , mMirrorY(false) { + mAngleTolerance = UBSettings::settings()->angleTolerance->get().toReal(); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setAcceptedMouseButtons(Qt::LeftButton); @@ -90,11 +90,14 @@ UBGraphicsDelegateFrame::UBGraphicsDelegateFrame(UBGraphicsItemDelegate* pDelega positionHandles(); this->setAcceptHoverEvents(true); + + angleWidget = new UBAngleWidget(); } UBGraphicsDelegateFrame::~UBGraphicsDelegateFrame() { +delete angleWidget; // NOOP } @@ -372,7 +375,9 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); mAngle += startLine.angleTo(currentLine); - if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance) + + if ((int)mAngle % 45 >= 45 - mAngleTolerance + || (int)mAngle % 45 <= mAngleTolerance) { mAngle = qRound(mAngle / 45) * 45; mAngleOffset += startLine.angleTo(currentLine); @@ -382,6 +387,23 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) mAngleOffset = 0; } } + else if ((int)mAngle % 30 >= 30 - mAngleTolerance + || (int)mAngle % 30 <= mAngleTolerance) + { + mAngle = qRound(mAngle / 30) * 30; + mAngleOffset += startLine.angleTo(currentLine); + if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) + { + mAngle += mAngleOffset; + mAngleOffset = 0; + } + } + + if (!angleWidget->isVisible()) + angleWidget->show(); + + angleWidget->setText(QString::number((int)mAngle % 360)); + angleWidget->update(); } else if (moving()) @@ -451,6 +473,9 @@ QTransform UBGraphicsDelegateFrame::buildTransform() void UBGraphicsDelegateFrame::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if (angleWidget->isVisible()) + angleWidget->hide(); + updateResizeCursors(); mDelegate->commitUndoStep(); diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 2cd1e0d1..11d451f1 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -18,6 +18,7 @@ #include #include "core/UB.h" +#include "domain/UBAngleWidget.h" class QGraphicsSceneMouseEvent; class UBGraphicsItemDelegate; @@ -91,7 +92,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject qreal mTranslateY; qreal mTotalTranslateX; qreal mTotalTranslateY; - static const qreal mAngleTolerance; + qreal mAngleTolerance; + QRect mAngleRect; QPointF mStartingPoint; QTransform mInitialTransform; @@ -117,5 +119,8 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject bool mResizing; bool mMirroredXAtStart; bool mMirroredYAtStart; + + UBAngleWidget *angleWidget; + }; #endif /* UBGRAPHICSDELEGATEFRAME_H_ */ diff --git a/src/domain/domain.pri b/src/domain/domain.pri index e3653576..a2d126ac 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -22,7 +22,8 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsMediaItem.h \ src/domain/UBGraphicsAudioItem.h \ src/domain/UBGraphicsAudioItemDelegate.h \ - src/domain/UBAbstractUndoCommand.h + src/domain/UBAbstractUndoCommand.h\ + src/domain/UBAngleWidget.h HEADERS += src/domain/UBGraphicsItemDelegate.h \ src/domain/UBGraphicsVideoItemDelegate.h \ @@ -54,7 +55,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsMediaItem.cpp \ src/domain/UBGraphicsAudioItem.cpp \ src/domain/UBGraphicsAudioItemDelegate.cpp \ - src/domain/UBAbstractUndoCommand.cpp + src/domain/UBAbstractUndoCommand.cpp \ + src/domain/UBAngleWidget.cpp SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ src/domain/UBGraphicsVideoItemDelegate.cpp \ From fea77f49b4c81b712e47408c7b0aa896d945e80b Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 5 Apr 2012 19:55:31 +0300 Subject: [PATCH 14/18] Missed files --- src/domain/UBAngleWidget.cpp | 46 ++++++++++++++++++++++++++++++++++++ src/domain/UBAngleWidget.h | 25 ++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/domain/UBAngleWidget.cpp create mode 100644 src/domain/UBAngleWidget.h diff --git a/src/domain/UBAngleWidget.cpp b/src/domain/UBAngleWidget.cpp new file mode 100644 index 00000000..542a7eed --- /dev/null +++ b/src/domain/UBAngleWidget.cpp @@ -0,0 +1,46 @@ +#include "UBAngleWidget.h" +#include + +UBAngleWidget::UBAngleWidget(QWidget *parent) + : QWidget(parent) +{ + this->setFixedSize(45,30); + this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + this->setAttribute(Qt::WA_TranslucentBackground); + + QImage mask_img(width(), height(), QImage::Format_Mono); + mask_img.fill(0xff); + QPainter mask_ptr(&mask_img); + mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); + mask_ptr.drawRoundedRect(0,0,this->geometry().width() - 6,this->geometry().height() - 6,1,1); + bmpMask = QBitmap::fromImage(mask_img); + this->setMask(bmpMask); +} + +UBAngleWidget::~UBAngleWidget() +{ + +} + +void UBAngleWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + this->move(this->cursor().pos().x(), this->cursor().pos().y() - 30); + + QPainter painter(this); + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + QBrush brush(Qt::white); + painter.setBrush(brush); + painter.drawRoundedRect(1,1,this->geometry().width() - 10,this->geometry().height() - 10,1,1); + + painter.setPen(QColor(85,50,127)); + painter.setFont(QFont("Arial", 10)); + painter.drawText(1,1,this->geometry().width() - 10,this->geometry().height() - 10, Qt::AlignCenter, text); +} + +void UBAngleWidget::setText(QString newText) +{ + text = newText; + text.append(QChar(176)); +} \ No newline at end of file diff --git a/src/domain/UBAngleWidget.h b/src/domain/UBAngleWidget.h new file mode 100644 index 00000000..20b09431 --- /dev/null +++ b/src/domain/UBAngleWidget.h @@ -0,0 +1,25 @@ +#ifndef UBANGLEWIDGET_H +#define UBANGLEWIDGET_H + +#include +#include + +class UBAngleWidget : public QWidget +{ + Q_OBJECT + +public: + UBAngleWidget(QWidget *parent = 0); + ~UBAngleWidget(); + + void setText(QString); + +protected: + void paintEvent(QPaintEvent *event); + +private: + QString text; + QBitmap bmpMask; +}; + +#endif // UBANGLEWIDGET_H From da61ebad0cfc84f56667915e29d7f7b8eca6807f Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Mon, 9 Apr 2012 19:20:34 +0300 Subject: [PATCH 15/18] Permanent Z-layer order changes, click bugs with pictures --- src/adaptors/UBSvgSubsetAdaptor.cpp | 4 - src/board/UBBoardView.cpp | 6 +- src/core/UBSettings.cpp | 1 + src/core/UBSettings.h | 1 + src/domain/UBGraphicsItemDelegate.cpp | 255 ++++++++++++++++++-------- src/domain/UBGraphicsItemDelegate.h | 39 ++-- src/domain/UBGraphicsPixmapItem.cpp | 7 +- src/domain/UBGraphicsPixmapItem.h | 4 - src/domain/UBGraphicsScene.cpp | 211 +++++++++++++++++---- src/domain/UBGraphicsScene.h | 62 ++++--- src/domain/UBGraphicsVideoItem.cpp | 8 +- src/domain/UBGraphicsWidgetItem.cpp | 2 + src/domain/UBItem.cpp | 2 +- src/domain/UBItem.h | 2 +- src/tools/UBGraphicsRuler.h | 2 +- 15 files changed, 427 insertions(+), 179 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index b39b7d25..33a5a091 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -2559,7 +2559,6 @@ UBGraphicsRuler* UBSvgSubsetAdaptor::UBSvgSubsetReader::rulerFromSvg() graphicsItemFromSvg(ruler); - UBGraphicsItem::assignZValue(ruler, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetRuler); ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); QStringRef svgWidth = mXmlReader.attributes().value("width"); @@ -2617,7 +2616,6 @@ UBGraphicsCompass* UBSvgSubsetAdaptor::UBSvgSubsetReader::compassFromSvg() graphicsItemFromSvg(compass); - UBGraphicsItem::assignZValue(compass, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCompass); compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); QStringRef svgX = mXmlReader.attributes().value("x"); @@ -2681,7 +2679,6 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg() { UBGraphicsProtractor* protractor = new UBGraphicsProtractor(); - UBGraphicsItem::assignZValue(protractor, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetProtractor); protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); graphicsItemFromSvg(protractor); @@ -2751,7 +2748,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() { UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); - UBGraphicsItem::assignZValue(triangle, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle); triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); graphicsItemFromSvg(triangle); diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index e9ffde4d..e4d9045c 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -418,10 +418,10 @@ UBBoardView::mousePressEvent (QMouseEvent *event) movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint())); - if (!movingItem + if (!movingItem || movingItem->isSelected() || movingItem->type() == UBGraphicsDelegateFrame::Type - || movingItem->type() == DelegateButton::Type + || movingItem->type() == DelegateButton::Type || movingItem->type() == UBGraphicsCompass::Type || movingItem->type() == UBGraphicsPDFItem::Type || movingItem->type() == UBGraphicsPolygonItem::Type @@ -431,7 +431,7 @@ UBBoardView::mousePressEvent (QMouseEvent *event) QGraphicsView::mousePressEvent (event); } - else + else { mLastPressedMousePos = mapToScene(event->pos()); if (suspendedMousePressEvent) diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index afd08aa9..3aa758d3 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -86,6 +86,7 @@ const int UBSettings::defaultWidgetIconWidth = 110; const int UBSettings::defaultVideoWidth = 80; const int UBSettings::thumbnailSpacing = 20; +const int UBSettings::longClickInterval = 2000; const qreal UBSettings::minScreenRatio = 1.33; // 800/600 or 1024/768 diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 4e8c9666..e32e6210 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -179,6 +179,7 @@ class UBSettings : public QObject static const int defaultSoundWidth; static const int thumbnailSpacing; + static const int longClickInterval; static const qreal minScreenRatio; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 3d233923..c5d7cdbf 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -47,6 +47,28 @@ class UBGraphicsParaschoolEditorWidgetItem; +void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + // make sure delegate is selected, to avoid control being hidden + mPressedTime = QTime::currentTime(); +// mDelegated->setSelected(true); + + event->setAccepted(!mIsTransparentToMouseEvent); + } + +void DelegateButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + int timeto = qAbs(QTime::currentTime().msecsTo(mPressedTime)); + + if (timeto < UBSettings::longClickInterval) { + emit clicked(); + } else { + emit longClicked(); + } + + event->setAccepted(!mIsTransparentToMouseEvent); +} + UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate) : QObject(parent) , mDelegated(pDelegated) @@ -88,11 +110,13 @@ void UBGraphicsItemDelegate::init() mButtons << mMenuButton; mZOrderUpButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::BottomLeftSection); - connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevel())); + connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); + connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); mButtons << mZOrderUpButton; mZOrderDownButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::BottomLeftSection); - connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(decreaseZLevel())); + connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); + connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); mButtons << mZOrderDownButton; buildButtons(); @@ -149,23 +173,22 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch return value; } +UBGraphicsScene *UBGraphicsItemDelegate::castUBGraphicsScene() +{ + UBGraphicsScene *castScene = dynamic_cast(delegated()->scene()); + + return castScene; +} bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(NULL != mMimeData) - { - QDrag* mDrag = new QDrag(event->widget()); - mDrag->setMimeData(mMimeData); - mDrag->start(); - } + mDragStartPosition = event->pos(); startUndoStep(); if (!mDelegated->isSelected()) { mDelegated->setSelected(true); - qDebug() << mDelegated->zValue(); - positionHandles(); return true; } @@ -182,13 +205,27 @@ void UBGraphicsItemDelegate::setMimeData(QMimeData *mimeData) bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if((NULL != mMimeData) && ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())) + { + QDrag* mDrag = new QDrag(event->widget()); + mDrag->setMimeData(mMimeData); + if (!mDragPixmap.isNull()) { + mDrag->setPixmap(mDragPixmap); + mDrag->setHotSpot(mDragPixmap.rect().center()); + } + mDrag->exec(); + mDragPixmap = QPixmap(); + + return true; + } + if(isLocked()) { event->accept(); return true; } else - return false; + return true; } bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) @@ -215,68 +252,34 @@ bool UBGraphicsItemDelegate::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) return true; } - -void UBGraphicsItemDelegate::positionHandles() +void UBGraphicsItemDelegate::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - if (mDelegated->isSelected()) - { - if (mFrame && !mFrame->scene() && mDelegated->scene()) - { - mDelegated->scene()->addItem(mFrame); - } - - mFrame->setAntiScale(mAntiScaleRatio); - mFrame->positionHandles(); - mFrame->show(); - - QTransform tr; - tr.scale(mAntiScaleRatio, mAntiScaleRatio); - - mDeleteButton->setTransform(tr); - - qreal topX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; - qreal topY = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; - - qreal bottomX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; - qreal bottomY = mFrame->rect().bottom() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; - - mDeleteButton->setPos(topX, topY); + Q_UNUSED(event) +// if (!mDelegated->isSelected()) { +// setZOrderButtonsVisible(true); +// } +} - if (!mDeleteButton->scene()) - { - mDeleteButton->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene - if (mDelegated->scene()) - mDelegated->scene()->addItem(mDeleteButton); - } +void UBGraphicsItemDelegate::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event) +// if (!mDelegated->isSelected()) { +// setZOrderButtonsVisible(false); +// } +} - mDeleteButton->show(); +void UBGraphicsItemDelegate::positionHandles() +{ + if (mDelegated->isSelected()) { bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; showHide(shownOnDisplay); - lock(isLocked()); + updateFrame(); + mFrame->show(); + + updateButtons(true); - int i = 1, j = 0, k = 0; - while ((i + j) < mButtons.size()) { - DelegateButton* button = mButtons[i + j]; - - button->setTransform(tr); - if (button->getSection() == Qt::TopLeftSection) { - button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY); - } else if (button->getSection() == Qt::BottomLeftSection) { - button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY); - } else if (button->getSection() == Qt::NoSection) { - ++k; - } - if (!button->scene()) - { - button->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene - if (mDelegated->scene()) - mDelegated->scene()->addItem(button); - } - button->show(); - button->setZValue(delegated()->zValue()); - } } else { foreach(DelegateButton* button, mButtons) button->hide(); @@ -284,7 +287,30 @@ void UBGraphicsItemDelegate::positionHandles() mFrame->hide(); } } +void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible) +{ + if (visible) { + updateFrame(); + updateButtons(); + + QPointF newUpPoint = mFrame->mapToItem(mDelegated, mZOrderUpButton->pos()); + QPointF newDownPoint = mFrame->mapToItem(mDelegated, mZOrderDownButton->pos()); + + + mZOrderUpButton->setParentItem(mDelegated); + mZOrderDownButton->setParentItem(mDelegated); + mZOrderUpButton->setPos(newUpPoint + QPointF(0,0)); + mZOrderDownButton->setPos(newDownPoint + QPointF(0,0)); + + mZOrderUpButton->show(); + mZOrderDownButton->show(); + + } else { + mZOrderUpButton->hide(); + mZOrderDownButton->hide(); + } +} void UBGraphicsItemDelegate::remove(bool canUndo) { @@ -320,18 +346,34 @@ void UBGraphicsItemDelegate::duplicate() UBApplication::boardController->copy(); UBApplication::boardController->paste(); } -void UBGraphicsItemDelegate::increaseZLevel(int delta) -{ - qDebug() << delegated()->scene()->items().count(); - -// UBGraphicsItem::assignZValue(delegated(), ) -// int valueCandidate = delegated()->data(UBGraphicsItemData::ItemOwnZValue).toInt(); -// if (delta < 0) { - -// } else if (delta > 0) { - -// } +void UBGraphicsItemDelegate::increaseZLevelUp() +{ + UBGraphicsScene *curScene = castUBGraphicsScene(); + if (curScene) { + curScene->changeZLevelTo(delegated(), UBZLayerController::up); + } +} +void UBGraphicsItemDelegate::increaseZlevelTop() +{ + UBGraphicsScene *curScene = castUBGraphicsScene(); + if (curScene) { + curScene->changeZLevelTo(delegated(), UBZLayerController::top); + } +} +void UBGraphicsItemDelegate::increaseZLevelDown() +{ + UBGraphicsScene *curScene = castUBGraphicsScene(); + if (curScene) { + curScene->changeZLevelTo(delegated(), UBZLayerController::down); + } +} +void UBGraphicsItemDelegate::increaseZlevelBottom() +{ + UBGraphicsScene *curScene = castUBGraphicsScene(); + if (curScene) { + curScene->changeZLevelTo(delegated(), UBZLayerController::bottom); + } } void UBGraphicsItemDelegate::lock(bool locked) @@ -484,3 +526,64 @@ bool UBGraphicsItemDelegate::isFlippable() { return mFlippable; } + +void UBGraphicsItemDelegate::updateFrame() +{ + if (mFrame && !mFrame->scene() && mDelegated->scene()) + { + mDelegated->scene()->addItem(mFrame); + } + + mFrame->setAntiScale(mAntiScaleRatio); + mFrame->positionHandles(); +} + +void UBGraphicsItemDelegate::updateButtons(bool showUpdated) +{ + QTransform tr; + tr.scale(mAntiScaleRatio, mAntiScaleRatio); + + mDeleteButton->setParentItem(mFrame); + mDeleteButton->setTransform(tr); + + qreal topX = mFrame->rect().left() - mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; + qreal topY = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; + + qreal bottomX = mFrame->rect().left() - mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; + qreal bottomY = mFrame->rect().bottom() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; + + mDeleteButton->setPos(topX, topY); + + if (!mDeleteButton->scene()) + { + if (mDelegated->scene()) + mDelegated->scene()->addItem(mDeleteButton); + } + + if (showUpdated) + mDeleteButton->show(); + + int i = 1, j = 0, k = 0; + while ((i + j + k) < mButtons.size()) { + DelegateButton* button = mButtons[i + j]; + button->setParentItem(mFrame); + + button->setTransform(tr); + if (button->getSection() == Qt::TopLeftSection) { + button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY); + } else if (button->getSection() == Qt::BottomLeftSection) { + button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY); + } else if (button->getSection() == Qt::NoSection) { + ++k; + } + if (!button->scene()) + { + if (mDelegated->scene()) + mDelegated->scene()->addItem(button); + } + if (showUpdated) { + button->show(); + button->setZValue(delegated()->zValue()); + } + } +} diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index b7388665..8bf0b3ad 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -21,9 +21,11 @@ #include #include "core/UB.h" +#include "core/UBSettings.h" class QGraphicsSceneMouseEvent; class QGraphicsItem; +class UBGraphicsScene; class UBGraphicsProxyWidget; class UBGraphicsDelegateFrame; class UBGraphicsWidgetItem; @@ -63,20 +65,8 @@ class DelegateButton: public QGraphicsSvgItem protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) - { - // make sure delegate is selected, to avoid control being hidden - mDelegated->setSelected(true); - - event->setAccepted(!mIsTransparentToMouseEvent); - } - - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) - { - emit clicked(); - - event->setAccepted(!mIsTransparentToMouseEvent); - } + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void modified(); @@ -84,12 +74,13 @@ class DelegateButton: public QGraphicsSvgItem QGraphicsItem* mDelegated; - + QTime mPressedTime; bool mIsTransparentToMouseEvent; Qt::WindowFrameSection mButtonAlignmentSection; signals: void clicked (bool checked = false); + void longClicked(); }; @@ -110,8 +101,12 @@ class UBGraphicsItemDelegate : public QObject virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual bool weelEvent(QGraphicsSceneWheelEvent *event); + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); + virtual UBGraphicsScene *castUBGraphicsScene(); void printMessage(const QString &mess) {qDebug() << mess;} @@ -123,6 +118,7 @@ class UBGraphicsItemDelegate : public QObject void setCanDuplicate(bool allow){ mCanDuplicate = allow; } virtual void positionHandles(); + void setZOrderButtonsVisible(bool visible); void startUndoStep(); void commitUndoStep(); @@ -135,6 +131,7 @@ class UBGraphicsItemDelegate : public QObject QMimeData* mimeData(){ return mMimeData; } void setMimeData(QMimeData* mimeData); + void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;} void setFlippable(bool flippable); bool isFlippable(); @@ -151,8 +148,10 @@ class UBGraphicsItemDelegate : public QObject virtual void lock(bool lock); virtual void duplicate(); - virtual void increaseZLevel() {increaseZLevel(1);} - virtual void decreaseZLevel() {increaseZLevel(-1);} + void increaseZLevelUp(); + void increaseZLevelDown(); + void increaseZlevelTop(); + void increaseZlevelBottom(); protected: virtual void buildButtons() {;} @@ -187,18 +186,22 @@ protected slots: virtual void gotoContentSource(bool checked); private: + void updateFrame(); + void updateButtons(bool showUpdated = false); + - virtual void increaseZLevel(int delta); QPointF mOffset; QTransform mPreviousTransform; QPointF mPreviousPosition; + QPointF mDragStartPosition; qreal mPreviousZValue; QSizeF mPreviousSize; bool mCanRotate; bool mCanDuplicate; bool mRespectRatio; QMimeData* mMimeData; + QPixmap mDragPixmap; /** A boolean saying that this object can be flippable (mirror effect) */ bool mFlippable; diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 07dc4679..9298d775 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -58,13 +58,18 @@ void UBGraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) QMimeData* pMime = new QMimeData(); pMime->setImageData(pixmap().toImage()); mDelegate->setMimeData(pMime); + int k = pixmap().width() / 100; + QSize newSize(pixmap().width() / k, pixmap().height() / k); + + mDelegate->setDragPixmap(pixmap().scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + if (mDelegate->mousePressEvent(event)) { //NOOP } else { - QGraphicsPixmapItem::mousePressEvent(event); +// QGraphicsPixmapItem::mousePressEvent(event); } } diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 56608ba1..5cb7d599 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -61,10 +61,6 @@ protected: virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - - -// UBGraphicsItemDelegate* mDelegate; - }; #endif /* UBGRAPHICSPIXMAPITEM_H_ */ diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index bbd4af62..d3a77e0e 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -61,24 +61,11 @@ #include "core/memcheck.h" -qreal UBGraphicsScene::drawingLayerStart = 0.0; -qreal UBGraphicsScene::toolLayerStart = 10000000.0; - -qreal UBGraphicsScene::toolOffsetRuler = 100; -qreal UBGraphicsScene::toolOffsetProtractor = 100; -qreal UBGraphicsScene::toolOffsetTriangle = 100; -qreal UBGraphicsScene::toolOffsetCompass = 100; -qreal UBGraphicsScene::toolOffsetEraser = 200; - -qreal UBGraphicsScene::toolOffsetCurtain = 1000; -qreal UBGraphicsScene::toolOffsetPointer = 1100; - -qreal UBGraphicsScene::toolOffsetCache = 1000;//Didier please define offset you want - qreal UBZLayerController::errorNumber = -20000001.0; +UBZLayerController::UBZLayerController(QGraphicsScene *scene) : + mScene(scene) -UBZLayerController::UBZLayerController() { scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber)); scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-10000000.0, -10000000.0 )); @@ -104,17 +91,162 @@ qreal UBZLayerController::generateZLevel(itemLayerType::Enum key) qreal result = scopeMap.value(key).curValue; qreal top = scopeMap.value(key).topLimit; + qreal incrementalStep = scopeMap.value(key).incStep; - result++; + result += incrementalStep; if (result >= top) { - qDebug() << "new values are over for the scope" << key; - result = top - 1; + // If not only one variable presents in the scope, notify that values for scope are over + if (scopeMap.value(key).topLimit != scopeMap.value(key).bottomLimit) { + qDebug() << "new values are over for the scope" << key; + } + result = top - incrementalStep; } scopeMap[key].curValue = result; return result; } +qreal UBZLayerController::generateZLevel(QGraphicsItem *item) +{ + qreal result = errorNumber; + itemLayerType::Enum type = static_cast(item->data(UBGraphicsItemData::itemLayerType).toInt()); + + if (validLayerType(type)) { + result = generateZLevel(type); + } + + return result; +} + +qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination dest) +{ + itemLayerType::Enum curItemLayerType = typeForData(item); + if (curItemLayerType == itemLayerType::NoLayer) { + qDebug() << "item's layer is out of the scope. Can't implement z-layer changing operation"; + return errorNum(); + } + + //select only items wiht the same z-level as item's one and push it to sortedItems QMultiMap + QMultiMap sortedItems; + if (mScene->items().count()) { + foreach (QGraphicsItem *tmpItem, mScene->items()) { + if (typeForData(tmpItem) == curItemLayerType) { + + sortedItems.insert(tmpItem->data(UBGraphicsItemData::ItemOwnZValue).toReal(), tmpItem); + } + } + } + + //If only one item itself - do nothing, return it's z-value + if (sortedItems.count() == 1 && sortedItems.values().first() == item) { + qDebug() << "only one item exists in layer. Have nothing to change"; + return item->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + } + + QMapIteratoriCurElement(sortedItems); + + if (dest == up) { + if (iCurElement.findNext(item)) { + if (iCurElement.hasNext()) { + qreal nextZ = iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + UBGraphicsItem::assignZValue(iCurElement.peekNext().value(), item->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + UBGraphicsItem::assignZValue(item, nextZ); + + iCurElement.next(); + + while (iCurElement.hasNext() && iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == nextZ) { + UBGraphicsItem::assignZValue(iCurElement.next().value(), nextZ); + } + + item->scene()->clearSelection(); + item->setSelected(true); + } + } + + } else if (dest == top) { + if (iCurElement.findNext(item)) { + if (iCurElement.hasNext()) { + UBGraphicsItem::assignZValue(item, generateZLevel(item)); + } + } + + } else if (dest == down) { + iCurElement.toBack(); + if (iCurElement.findPrevious(item)) { + if (iCurElement.hasPrevious()) { + qreal nextZ = iCurElement.peekPrevious().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + UBGraphicsItem::assignZValue(iCurElement.peekPrevious().value(), item->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + UBGraphicsItem::assignZValue(item, nextZ); + + while (iCurElement.hasNext() && iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == nextZ) { + UBGraphicsItem::assignZValue(iCurElement.next().value(), nextZ); + } + } + } + + } else if (dest == bottom) { + iCurElement.toBack(); + if (iCurElement.findPrevious(item)) { + if (iCurElement.hasPrevious()) { +// qreal oldz = iCurElement.peekPrevious().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + qreal oldz = item->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + iCurElement.toFront(); + qreal nextZ = iCurElement.next().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + + ItemLayerTypeData curItemLayerTypeData = scopeMap.value(curItemLayerType); +// + //if we have some free space between lowest graphics item and layer's bottom bound, + //insert element close to first element in layer + if (nextZ >= curItemLayerTypeData.bottomLimit + curItemLayerTypeData.incStep) { + qreal result = nextZ - curItemLayerTypeData.incStep; + UBGraphicsItem::assignZValue(item, result); + } else { + UBGraphicsItem::assignZValue(item, nextZ); + bool doubleGap = false; //to detect if we can finish rundown since we can insert item to the free space + + while (iCurElement.peekNext().value() != item) { + qreal curZ = iCurElement.value()->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + qreal curNextZ = iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + if (curNextZ - curZ >= 2 * curItemLayerTypeData.incStep) { + UBGraphicsItem::assignZValue(iCurElement.value(), curZ + curItemLayerTypeData.incStep); + doubleGap = true; + break; + } else { + UBGraphicsItem::assignZValue(iCurElement.value(), iCurElement.next().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + } + } + if (!doubleGap) { + + UBGraphicsItem::assignZValue(iCurElement.value(), oldz); + + while (iCurElement.hasNext() && (iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == oldz)) { + UBGraphicsItem::assignZValue(iCurElement.next().value(), oldz); + } + } + } + } + } + } + + + //clear selection of the item and then select it again to activate selectionChangeProcessing() + item->scene()->clearSelection(); + item->setSelected(true); + + //Return new z value assigned to item + return item->data(UBGraphicsItemData::ItemOwnZValue).toReal(); +} + +itemLayerType::Enum UBZLayerController::typeForData(QGraphicsItem *item) const +{ + itemLayerType::Enum result = static_cast(item->data(UBGraphicsItemData::itemLayerType).toInt()); + + if (!scopeMap.contains(result)) { + result = itemLayerType::NoLayer; + } + + return result; +} UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) : UBCoreGraphicsScene(parent) @@ -135,7 +267,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) , enableUndoRedoStack(true) , magniferControlViewWidget(0) , magniferDisplayViewWidget(0) - + , mZLayerController(new UBZLayerController(this)) { #ifdef __ppc__ @@ -165,6 +297,9 @@ UBGraphicsScene::~UBGraphicsScene() if (mCurrentStroke) if (mCurrentStroke->polygons().empty()) delete mCurrentStroke; + + if (mZLayerController) + delete mZLayerController; } void UBGraphicsScene::selectionChangedProcessing() @@ -178,7 +313,7 @@ void UBGraphicsScene::selectionChangedProcessing() QGraphicsItem *nextItem = allItemsList.at(i); if (nextItem->isSelected()) { - nextItem->setZValue(mZLayerController.generateZLevel(itemLayerType::SelectedItem)); + nextItem->setZValue(mZLayerController->generateZLevel(itemLayerType::SelectedItem)); } else { nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); } @@ -823,7 +958,6 @@ void UBGraphicsScene::leaveEvent(QEvent * event) hideEraser(); } - UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const { UBGraphicsScene* copy = new UBGraphicsScene(this->document()); @@ -1330,7 +1464,7 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) setModified(true); UBCoreGraphicsScene::addItem(item); - UBGraphicsItem::assignZValue(item, generateZLevel(item)); + UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); if (!mTools.contains(item)) ++mItemCount; @@ -1344,7 +1478,7 @@ void UBGraphicsScene::addItems(const QSet& items) foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::addItem(item); - UBGraphicsItem::assignZValue(item, generateZLevel(item)); + UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); } mItemCount += items.size(); @@ -1406,7 +1540,7 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool item->setAcceptedMouseButtons(Qt::NoButton); item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground); - UBGraphicsItem::assignZValue(item, mZLayerController.generateZLevel(itemLayerType::BackgroundItem)); + UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(itemLayerType::BackgroundItem)); if (pAdaptTransformation) { @@ -1779,6 +1913,23 @@ void UBGraphicsScene::setNominalSize(int pWidth, int pHeight) setNominalSize(QSize(pWidth, pHeight)); } +void UBGraphicsScene::setSelectedZLevel(QList itemList) +{ + foreach (QGraphicsItem *item, itemList) { + item->setZValue(mZLayerController->generateZLevel(itemLayerType::SelectedItem)); + } +} +void UBGraphicsScene::setOwnZlevel(QList itemList) +{ + foreach (QGraphicsItem *item, itemList) { + item->setZValue(item->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + } +} + +qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest) +{ + return mZLayerController->changeZLevelTo(item, dest); +} QGraphicsItem* UBGraphicsScene::rootItem(QGraphicsItem* item) const { @@ -1951,18 +2102,6 @@ void UBGraphicsScene::createPointer() addItem(mPointer); } -qreal UBGraphicsScene::generateZLevel(QGraphicsItem *item) -{ - qreal result = UBZLayerController::errorNum(); - itemLayerType::Enum type = static_cast(item->data(UBGraphicsItemData::itemLayerType).toInt()); - - if (mZLayerController.validLayerType(type)) { - result = mZLayerController.generateZLevel(type); - } - - return result; -} - void UBGraphicsScene::setToolCursor(int tool) { if (tool != (int)UBStylusTool::Selector diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 8fa84053..b869063f 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -49,33 +49,47 @@ class UBGraphicsCache; const double PI = 4.0 * atan(1.0); -class UBZLayerController +class UBZLayerController : public QObject { -public: + Q_OBJECT +public: struct ItemLayerTypeData { - ItemLayerTypeData() : bottomLimit(0), topLimit(0), curValue(0) {;} - ItemLayerTypeData(qreal bot, qreal top) : bottomLimit(bot), topLimit(top), curValue(bot) {;} - qreal bottomLimit; - qreal topLimit; - qreal curValue; + ItemLayerTypeData() : bottomLimit(0), topLimit(0), curValue(0), incStep(1) {;} + ItemLayerTypeData(qreal bot, qreal top, qreal increment = 1) : bottomLimit(bot), topLimit(top), curValue(bot), incStep(increment) {;} + qreal bottomLimit; //bottom bound of the layer + qreal topLimit;//top bound of the layer + qreal curValue;//current value of variable + qreal incStep;//incremental step + }; + + enum moveDestination { + up + , down + , top + , bottom }; typedef QMap ScopeMap; - UBZLayerController(); + UBZLayerController(QGraphicsScene *scene); qreal getBottomLimit(itemLayerType::Enum key) const {return scopeMap.value(key).bottomLimit;} qreal getTopLimit(itemLayerType::Enum key) const {return scopeMap.value(key).topLimit;} bool validLayerType(itemLayerType::Enum key) const {return scopeMap.contains(key);} + static qreal errorNum() {return errorNumber;} qreal generateZLevel(itemLayerType::Enum key); + qreal generateZLevel(QGraphicsItem *item); - private: - ScopeMap scopeMap; - static qreal errorNumber; + qreal changeZLevelTo(QGraphicsItem *item, moveDestination dest); + itemLayerType::Enum typeForData(QGraphicsItem *item) const; +private: + ScopeMap scopeMap; + static qreal errorNumber; + QGraphicsScene *mScene; }; class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem @@ -87,7 +101,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem // tmp stub for divide addings scene objects from undo mechanism implementation void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} - UBGraphicsScene(UBDocumentProxy *parent); + UBGraphicsScene(UBDocumentProxy *parent); virtual ~UBGraphicsScene(); virtual UBItem* deepCopy() const; @@ -242,6 +256,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void setNominalSize(int pWidth, int pHeight); + qreal changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest); + enum RenderingContext { Screen = 0, NonScreen, PdfExport, Podcast @@ -257,20 +273,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem return mRenderingContext; } - static qreal backgroundLayerStart; - static qreal objectLayerStart; - static qreal drawingLayerStart; - static qreal toolLayerStart; - - static qreal toolOffsetEraser; - static qreal toolOffsetPointer; - static qreal toolOffsetRuler; - static qreal toolOffsetProtractor; - static qreal toolOffsetCompass; - static qreal toolOffsetCurtain; - static qreal toolOffsetTriangle; - static qreal toolOffsetCache; - QSet tools(){ return mTools;} void registerTool(QGraphicsItem* item) @@ -283,7 +285,9 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem return mPreviousPoint; } - public slots: + void setSelectedZLevel(QList itemList); + void setOwnZlevel(QList itemList); +public slots: void hideEraser(); @@ -336,8 +340,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void createEraiser(); void createPointer(); - qreal generateZLevel(QGraphicsItem *item); - QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mPointer; @@ -387,7 +389,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBMagnifier *magniferControlViewWidget; UBMagnifier *magniferDisplayViewWidget; - UBZLayerController mZLayerController; + UBZLayerController *mZLayerController; }; diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index 887fdb7a..9fa9d345 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -109,10 +109,10 @@ void UBGraphicsVideoItem::showOnDisplayChanged(bool shown) void UBGraphicsVideoItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - QDrag* mDrag = new QDrag(event->widget()); - QMimeData* pMime = new QMimeData(); - mDrag->setMimeData(pMime); - mDrag->start(); +// QDrag* mDrag = new QDrag(event->widget()); +// QMimeData* pMime = new QMimeData(); +// mDrag->setMimeData(pMime); +// mDrag->start(); mShouldMove = (event->buttons() & Qt::LeftButton); mMousePressPos = event->scenePos(); diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 899a7714..13487641 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -82,11 +82,13 @@ void UBGraphicsWidgetItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsWidgetItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { sendJSEnterEvent(); + mDelegate->hoverEnterEvent(event); UBGraphicsProxyWidget::hoverEnterEvent(event); } void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { sendJSLeaveEvent(); + mDelegate->hoverLeaveEvent(event); UBGraphicsProxyWidget::hoverLeaveEvent(event); } diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 3e6f68cf..54c16e73 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -29,7 +29,7 @@ UBItem::~UBItem() // NOOP } -void UBGraphicsItem::assignZValue(QGraphicsItem *item, int value) +void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value) { item->setZValue(value); item->setData(UBGraphicsItemData::ItemOwnZValue, value); diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index e10cd57a..301395fa 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -101,7 +101,7 @@ protected: public: - static void assignZValue(QGraphicsItem*, int value); + static void assignZValue(QGraphicsItem*, qreal value); virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual void remove() = 0; diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index fb74dd9d..1c799bb1 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -44,7 +44,7 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu virtual void StartLine(const QPointF& position, qreal width); virtual void DrawLine(const QPointF& position, qreal width); - virtual void EndLine(); + virtual void EndLine(); protected: From 9f9299a7e4fcaf6b0a024d23d81ea3d4bdb7b838 Mon Sep 17 00:00:00 2001 From: bmagnin Date: Mon, 9 Apr 2012 20:27:31 +0200 Subject: [PATCH 16/18] Wording wording --- resources/library/applications/Notes.wgt/js/ubw-main.js | 2 +- .../BlackYellow.wgt/locales/fr/scripts/blackYellow.js | 2 +- .../library/interactivities/associer_images.wgt/js/script.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/library/applications/Notes.wgt/js/ubw-main.js b/resources/library/applications/Notes.wgt/js/ubw-main.js index cea778fa..de5c2ed3 100644 --- a/resources/library/applications/Notes.wgt/js/ubw-main.js +++ b/resources/library/applications/Notes.wgt/js/ubw-main.js @@ -199,7 +199,7 @@ function init(){ if(text) textField.html(text); else - textField.html("Enter your notes here ..."); + textField.html("Saisir votre texte ici ..."); textField.focus(); } diff --git a/resources/library/interactivities/BlackYellow.wgt/locales/fr/scripts/blackYellow.js b/resources/library/interactivities/BlackYellow.wgt/locales/fr/scripts/blackYellow.js index 61b709f9..56976f82 100644 --- a/resources/library/interactivities/BlackYellow.wgt/locales/fr/scripts/blackYellow.js +++ b/resources/library/interactivities/BlackYellow.wgt/locales/fr/scripts/blackYellow.js @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -var sankoreLang = {display: "Afficher", edit: "Modifier", add: "Ajouter", enter_data: "Saisir la donnée:", enter_result: "Saisir le résultat:", ok: "Accepter", cancel: "Annuler"}; +var sankoreLang = {display: "Afficher", edit: "Modifier", add: "Ajouter", enter_data: "Saisir la donnée:", enter_result: "Saisir le résultat:", ok: "Valider", cancel: "Annuler"}; function init(){ diff --git a/resources/library/interactivities/associer_images.wgt/js/script.js b/resources/library/interactivities/associer_images.wgt/js/script.js index 55910d11..633d943f 100644 --- a/resources/library/interactivities/associer_images.wgt/js/script.js +++ b/resources/library/interactivities/associer_images.wgt/js/script.js @@ -3,7 +3,7 @@ var sankoreLang = { edit: "Edit", short_desc: "Select the number \"three\".", add: "Add new block", - enter: "Enter what to do here ..." + enter: "Enter what to do here..." }; //main function From 087bb09849eedd6b20b1055eb94a5ac6d5090166 Mon Sep 17 00:00:00 2001 From: bmagnin Date: Mon, 9 Apr 2012 23:50:46 +0200 Subject: [PATCH 17/18] Wording icell French wording for iCell --- .../iCell.wgt/js/textes_descriptifs.js | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/resources/library/applications/iCell.wgt/js/textes_descriptifs.js b/resources/library/applications/iCell.wgt/js/textes_descriptifs.js index 003d0c8e..0533292f 100644 --- a/resources/library/applications/iCell.wgt/js/textes_descriptifs.js +++ b/resources/library/applications/iCell.wgt/js/textes_descriptifs.js @@ -147,64 +147,64 @@ switch(lang){ break; case "fr": txt_vesicule = "

Vesicule
Transporteurs

"+ - "

Structure:

Bicouche phospholipidique

"+ - "

Role:

Transport de proteines ou d'autres elements a l'interieur de la cellule, vers l'exterieur (exocytose) ou vers l'interieur (endocytose).

"+ - '

Fonctionnement:

Transporteur "remorque" par des proteines prenant appui sur le cytosquelette.

' + "

Structure :

Bicouche phospholipidique

"+ + "

Rôle :

Transport de protéines ou d'autres éléments à l'intérieur de la cellule, vers l'extérieur (exocytose) ou vers l'intérieur (endocytose).

"+ + '

Fonctionnement :

Transporteur "remorque" par des protéines prenant appui sur le cytosquelette.

' txt_lysosome = "

Lysosome
Estomacs cellulaires

"+ - "

Structure:

Bicouche phospholipidique

"+ - "

Role:

Digestion intra-cellulaire a l'aide d'enzymes

"+ - "

Fonctionnement:

Absorption de nutriments par endocytose ou d'elements cellulaires abimes, digestion de ceux-ci, puis distribution des resultats de la reaction chimique dans la cellule et enfin expulsion des dechets par exocytose.

" + "

Structure :

Bicouche phospholipidique

"+ + "

Role :

Digestion intracellulaire à l'aide d'enzymes

"+ + "

Fonctionnement :

Absorption de nutriments par endocytose ou d'éléments cellulaires abimés, digestion de ceux-ci, puis distribution des résultats de la réaction chimique dans la cellule et enfin expulsion des déchets par exocytose.

" txt_mitoch = "

Mitochondrie
Piles

"+ - "

Structure:

Deux bichouches phospholipidiques appelees membranes mitochondriales, une externe et une interne. La mitochondrie contient des ribosomes, de l'ATP de l'ADN et bien d'autres molecules.

"+ - "

Role:

Centrale energetique de la cellule.

"+ - "

Fonctionnement:

L'energie - sous forme d'ATP (adenosine triphosphate) - est issue de differentes etapes de reactions chimique partant d'une molecule de glucose.

" + "

Structure :

Deux bicouches phospholipidiques appelées membranes mitochondriales, une externe et une interne. La mitochondrie contient des ribosomes, de l'ATP de l'ADN et bien d'autres molécules.

"+ + "

Rôle :

Centrale énergétique de la cellule.

"+ + "

Fonctionnement :

L'énergie - sous forme d'ATP (adénosine triphosphate) - est issue de différentes étapes de réactions chimiques partant d'une molécule de glucose.

" txt_golgi = "

Appareil de Golgi
Usines miniatures

"+ - "

Structure:

Forme d'un empilement de saccules membranaires applatis.

"+ - "

Role:

Modification de certaines proteines au cours d'un cheminement au travers de ses saccules.

"+ - "

Fonctionnement:

Suite de reactions chimiques, notamment par glycosilation.

" + "

Structure :

Forme d'un empilement de saccules membranaires aplatis.

"+ + "

Rôle :

Modification de certaines protéines au cours d'un cheminement au travers de ses saccules.

"+ + "

Fonctionnement :

Suite de réactions chimiques, notamment par glycosilation.

" txt_rer = "

Reticulum endoplasmique rugueux - Tunnel

"+ - "

Structure:

Compose d'une bicouche phospholipidique piquetee de ribosomes (d'un aspect rugueux) delimitant la lumiere, un espace interne pouvant tre compare a un tunnel.

"+ - "

Role:

Plus specialise que le REL, il participe au transport et a la finalisation des proteines, qui sont synthetisees par les ribosomes.

"+ - '

Fonctionnement:

Les proteines "tombent" dans la lumiere du RER o elles sont modifiees et deplacees. Elles quittent le RER dans une vesucule issue de la membrane de ce dernier.

' + "

Structure :

Composé d'une bicouche phospholipidique piquetée de ribosomes (d'un aspect rugueux) délimitant la lumière, un espace interne pouvant être comparé à un tunnel.

"+ + "

Rôle :

Plus spécialisé que le REL, il participe au transport et à la finalisation des protéines, qui sont synthétisées par les ribosomes.

"+ + '

Fonctionnement :

Les protéines "tombent" dans la lumière du RER où elles sont modifiées et déplacées. Elles quittent le RER dans une vésicule issue de la membrane de ce dernier.

' txt_noy = "

Noyau - Le coffre-fort

"+ - "

Structure:

Entoure par une double membrane appelee enveloppe nucleaire en lien par endroits avec le RER. Ces deux membranes fusionnent a intervalles reguliers pour former les pores nucleaires. a l'interieur se trouvent le nucleole et l'ADN, sous forme de chromatine ou de chomosomes.

"+ - "

Role:

Stockage de la totalite des informations genetiques necessaires a la vie de la cellule.

"+ - "

Fonctionnement:

Site de la transcription (copie de l'information genetique sur des ARNm).

" + "

Structure :

Entouré par une double membrane appelée enveloppe nucléaire en lien par endroits avec le RER. Ces deux membranes fusionnent à intervalles réguliers pour former les pores nucléaires. À l'intérieur se trouve le nucléole et l'ADN, sous forme de chromatine ou de chromosomes.

"+ + "

Rôle :

Stockage de la totalité des informations génétiques nécessaires à la vie de la cellule.

"+ + "

Fonctionnement :

Site de la transcription (copie de l'information génétique sur des ARNm).

" txt_rel = "

Reticulum endoplasmique lisse - REL

"+ - "

Structure:

Similaires a celle du RER, a la difference que sa membranne n'est pas parsemee de ribosomes, d'o son aspect lisse.

"+ - "

Role:

Sinthese des phospholipides,stockage du calcium, transformation de certaines molecules exterieures (medicament, alcool, ...). Dans certaines cellules, le REL remplit aussi des fonctions supplementaires, telles la production d'hormones, d'acides gastriques, etc.

"+ - "

Fonctionnement:

Il est le siege de beaucoup de reactions chimiques complexes (ex: detoxification, differentes syntheses).

" + "

Structure :

Similaire à celle du RER, à la différence que sa membrane n'est pas parsemée de ribosomes, d'où son aspect lisse.

"+ + "

Rôle :

Synthèse des phospholipides, stockage du calcium, transformation de certaines molécules extérieures (médicament, alcool...). Dans certaines cellules, le REL remplit aussi des fonctions supplémentaires, telles que la production d'hormones, d'acides gastriques, etc.

"+ + "

Fonctionnement :

Il est le siège de beaucoup de réactions chimiques complexes (ex : détoxification, différentes synthèses).

" txt_adn = "

ADN - Le livre de la vie

"+ - "

Structure:

echelle a la celebre forme de double helice composee de deux colonnes sucre-phosphate-sucre-phosphate-... et dont les echelons sont apelles bases azotees.

"+ - "

Role:

L'ADN contient toutes les informations necessaires a la vie.

"+ - "

Fonctionnement:

Toutes les informations sont ecrites a l'aide des quatre lettres A, T, G, et C. Grace a ces combinaisons, il est possible d'ecrire tout ce qui est utile a la cellule.

" + "

Structure :

échelle à la célèbre forme de double hélice composée de deux colonnes sucre-phosphate-sucre-phosphate-... et dont les échelons sont appelés bases azotées.

"+ + "

Rôle :

L'ADN contient toutes les informations nécessaires à la vie.

"+ + "

Fonctionnement :

Toutes les informations sont écrites à l'aide des quatre lettres A, T, G, et C. Grâce à ces combinaisons, il est possible d'écrire tout ce qui est utile à la cellule.

" - txt_centr= "

Centrioles - Remorqueurs de choromosomes

"+ - "

Structure:

Neuf triplets de microtubules entoures par un certain nombre de proteines.

"+ - "

Role:

Separer les differents chromosomes durant la division cellulaire.

"+ - "

Fonctionnement:

Les centrioles, une fois places aux deux poles de la cellule, deploient des microtubules vers les centromeres des chromosomes et les tirent vers eux pour les separer.

" + txt_centr= "

Centrioles - Remorqueurs de chromosomes

"+ + "

Structure :

Neuf triplets de microtubules entourent par un certain nombre de protéines.

"+ + "

Rôle :

Séparer les différents chromosomes durant la division cellulaire.

"+ + "

Fonctionnement :

Les centrioles, une fois placés aux deux pôles de la cellule, déploient des microtubules vers les centromères des chromosomes et les tirent vers eux pour les séparer.

" - txt_rib = "

Ribosome - Decodeurs

"+ - "

Structure:

Forme par deux sous-unites composees d'ARN ribosomique et de proteines.

"+ - "

Role:

Le ribosome synthetise les proteines.

"+ - "

Fonctionnement:

Un brin d'ARNm (messager) passe dans le ribosome et un ARNt (de transfert) entre dans la grande sous-unite si son codon (groupe de trois bases azotees) correspond a celui qui est en face sur l'ARNm. Cet ARNt porte avec lui un acide amine specifique qui est ajoute a la chaine deja assemblee.

" + txt_rib = "

Ribosome - Décodeurs

"+ + "

Structure :

Formé par deux sous-unités composées d'ARN ribosomique et de protéines.

"+ + "

Rôle :

Le ribosome synthétise les protéines.

"+ + "

Fonctionnement :

Un brin d'ARNm (messager) passe dans le ribosome et un ARNt (de transfert) entre dans la grande sous-unité si son codon (groupe de trois bases azotées) correspond à celui qui est en face sur l'ARNm. Cet ARNt porte avec lui un acide aminé spécifique qui est ajouté à la chaîne déjà assemblée.

" txt_arn = "

ARN - Multifonction

"+ - "

Structure:

Tres similaire a l'ADN a la difference qu'il ne possede qu'un brin et que la thymine (T) de l'ADN est remplacee par l'uracile (U). De plus, il est chimiquement plus instable que l'ADN, c'est pourquoi il n'est pas utilise pour le stockage d'informations a long terme.

"+ - "

Role:

Multiples, il existe des ARN de transport, messagers, regulateus, guides, satellites, ...

"+ - "

Fonctionnement:

La copie d'informations genetiques se fait grace a l'ouverture de la double-helice d'ADN, puis la copie des codons sur l'ARN. Celui-ci peut alors sortir du noyau, ce que l'ADN ne peut pas faire.

" + "

Structure :

Très similaire à l'ADN à la différence qu'il ne possède qu'un brin et que la thymine (T) de l'ADN est remplacée par l'uracile (U). De plus, il est chimiquement plus instable que l'ADN, c'est pourquoi il n'est pas utilisé pour le stockage d'informations à long terme.

"+ + "

Rôle :

Multiples, il existe des ARN de transport, messagers, régulateurs, guides, satellites...

"+ + "

Fonctionnement :

La copie d'informations génétiques se fait grâce à l'ouverture de la double hélice d'ADN, puis la copie des codons sur l'ARN. Celui-ci peut alors sortir du noyau, ce que l'ADN ne peut pas faire.

" - txt_nucl = "

Nucleole - Fabrique d'ARN

"+ - "

Structure:

Compose d'aucune membranne, c'est un agglomerat de proteines et d'ARN.

"+ - "

Role:

Lieu de la transcription d'ARN, nottament d'ARNr (ribosomiques) qui, associes avec des proteines, vont former les deux sous-unites des ribosomes.

"+ - "

Fonctionnement:

Creation d'un ribosome: Transcription des ARNr ainsi que des proteines necessaires (cette etape est effectuee dans le cytoplasme par d'autres ribosomes) qui rentrent dans le noyau, association des molecules franchement formees en un nouveau ribosome, qui sort du noyau pour jouer son Role.

" + txt_nucl = "

Nucléole - Fabrique d'ARN

"+ + "

Structure :

Composé d'aucune membrane, c'est un agglomérat de protéines et d'ARN.

"+ + "

Rôle :

Lieu de la transcription d'ARN, notamment d'ARNr (ribosomiques) qui, associés avec des protéines, vont former les deux sous-unités des ribosomes.

"+ + "

Fonctionnement :

Création d'un ribosome: Transcription des ARNr ainsi que des protéines nécessaires (cette étape est effectuée dans le cytoplasme par d'autres ribosomes) qui rentrent dans le noyau, association des molécules franchement formées en un nouveau ribosome, qui sort du noyau pour jouer son rôle.

" break; default: txt_vesicule = "

Vesicle
Transporter

"+ From 39fcd97bfe83a82b82c871876b970c6076db5b0f Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 10 Apr 2012 14:08:46 +0300 Subject: [PATCH 18/18] SANKORE-483 Web History --- src/core/UBSettings.cpp | 1 + src/core/UBSettings.h | 1 + src/web/browser/WBBrowserWindow.cpp | 128 ++++++++++++++++++++++++++++ src/web/browser/WBBrowserWindow.h | 7 ++ 4 files changed, 137 insertions(+) diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 8e689a61..80513cf0 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -379,6 +379,7 @@ void UBSettings::init() swapControlAndDisplayScreens = new UBSetting(this, "App", "SwapControlAndDisplayScreens", false); angleTolerance = new UBSetting(this, "App", "AngleTolerance", 4); + historyLimit = new UBSetting(this, "Web", "HistoryLimit", 15); } diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index d9d4d80d..25c94596 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -326,6 +326,7 @@ class UBSettings : public QObject UBSetting* swapControlAndDisplayScreens; UBSetting* angleTolerance; + UBSetting* historyLimit; public slots: diff --git a/src/web/browser/WBBrowserWindow.cpp b/src/web/browser/WBBrowserWindow.cpp index e8151811..7cfb79d5 100644 --- a/src/web/browser/WBBrowserWindow.cpp +++ b/src/web/browser/WBBrowserWindow.cpp @@ -196,6 +196,36 @@ void WBBrowserWindow::setupToolBar() mTabWidget->addWebAction(mUniboardMainWindow->actionWebReload, QWebPage::Reload); mTabWidget->addWebAction(mUniboardMainWindow->actionStopLoading, QWebPage::Stop); + mHistoryBackMenu = new QMenu(this); + connect(mHistoryBackMenu, SIGNAL(aboutToShow()),this, SLOT(aboutToShowBackMenu())); + connect(mHistoryBackMenu, SIGNAL(triggered(QAction *)), this, SLOT(openActionUrl(QAction *))); + + foreach (QWidget* menuWidget, mUniboardMainWindow->actionWebBack->associatedWidgets()) + { + QToolButton *tb = qobject_cast(menuWidget); + + if (tb && !tb->menu()) + { + tb->setMenu(mHistoryBackMenu); + tb->setStyleSheet("QToolButton::menu-indicator { subcontrol-position: bottom left; }"); + } + } + + mHistoryForwardMenu = new QMenu(this); + connect(mHistoryForwardMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowForwardMenu())); + connect(mHistoryForwardMenu, SIGNAL(triggered(QAction *)), this, SLOT(openActionUrl(QAction *))); + + foreach (QWidget* menuWidget, mUniboardMainWindow->actionWebForward->associatedWidgets()) + { + QToolButton *tb = qobject_cast(menuWidget); + + if (tb && !tb->menu()) + { + tb->setMenu(mHistoryForwardMenu); + tb->setStyleSheet("QToolButton { padding-right: 8px; }"); + } + } + mWebToolBar->insertWidget(mUniboardMainWindow->actionWebBigger, mTabWidget->lineEditStack()); mSearchToolBar = new WBToolbarSearch(mWebToolBar); @@ -224,6 +254,22 @@ void WBBrowserWindow::setupToolBarForTutorial() mTabWidget->addWebAction(mUniboardMainWindow->actionWebBack, QWebPage::Back); mTabWidget->addWebAction(mUniboardMainWindow->actionWebForward, QWebPage::Forward); + + foreach (QWidget* menuWidget, mUniboardMainWindow->actionWebBack->associatedWidgets()) + { + QToolButton *tb = qobject_cast(menuWidget); + + if (tb && tb->menu()) + tb->setMenu(NULL); + } + + foreach (QWidget* menuWidget, mUniboardMainWindow->actionWebForward->associatedWidgets()) + { + QToolButton *tb = qobject_cast(menuWidget); + + if (tb && tb->menu()) + tb->setMenu(NULL); + } // mTabWidget->addWebAction(mUniboardMainWindow->actionWebReload, QWebPage::Reload); // mTabWidget->addWebAction(mUniboardMainWindow->actionStopLoading, QWebPage::Stop); @@ -534,4 +580,86 @@ void WBBrowserWindow::showTabAtTop(bool attop) mTabWidget->setTabPosition(QTabWidget::South); } +void WBBrowserWindow::aboutToShowBackMenu() +{ + mHistoryBackMenu->clear(); + if (!currentTabWebView()) + return; + QWebHistory *history = currentTabWebView()->history(); + + int historyCount = history->count(); + int historyLimit = history->backItems(historyCount).count() - UBSettings::settings()->historyLimit->get().toReal(); + if (historyLimit < 0) + historyLimit = 0; + + for (int i = history->backItems(historyCount).count() - 1; i >= historyLimit; --i) + { + QWebHistoryItem item = history->backItems(historyCount).at(i); + + QAction *action = new QAction(this); + action->setData(-1*(historyCount-i-1)); + + if (!QWebSettings::iconForUrl(item.originalUrl()).isNull()) + action->setIcon(item.icon()); + action->setText(item.title().isEmpty() ? item.url().toString() : item.title()); + mHistoryBackMenu->addAction(action); + } + + mHistoryBackMenu->addSeparator(); + + QAction *action = new QAction(this); + action->setData("clear"); + action->setText("Clear history"); + mHistoryBackMenu->addAction(action); + +} + +void WBBrowserWindow::aboutToShowForwardMenu() +{ + mHistoryForwardMenu->clear(); + if (!currentTabWebView()) + return; + QWebHistory *history = currentTabWebView()->history(); + int historyCount = history->count(); + + int historyLimit = history->forwardItems(historyCount).count(); + if (historyLimit > UBSettings::settings()->historyLimit->get().toReal()) + historyLimit = UBSettings::settings()->historyLimit->get().toReal(); + + for (int i = 0; i < historyLimit; ++i) + { + QWebHistoryItem item = history->forwardItems(historyCount).at(i); + + QAction *action = new QAction(this); + action->setData(historyCount-i); + + if (!QWebSettings::iconForUrl(item.originalUrl()).isNull()) + action->setIcon(item.icon()); + action->setText(item.title().isEmpty() ? item.url().toString() : item.title()); + mHistoryForwardMenu->addAction(action); + } + + mHistoryForwardMenu->addSeparator(); + + QAction *action = new QAction(this); + action->setData("clear"); + action->setText("Clear history"); + mHistoryForwardMenu->addAction(action); +} + +void WBBrowserWindow::openActionUrl(QAction *action) +{ + QWebHistory *history = currentTabWebView()->history(); + + if (action->data() == "clear") + { + history->clear(); + return; + } + int offset = action->data().toInt(); + if (offset < 0) + history->goToItem(history->backItems(-1*offset).first()); + else if (offset > 0) + history->goToItem(history->forwardItems(history->count() - offset + 1).back()); + } \ No newline at end of file diff --git a/src/web/browser/WBBrowserWindow.h b/src/web/browser/WBBrowserWindow.h index 0cca883a..40cab320 100644 --- a/src/web/browser/WBBrowserWindow.h +++ b/src/web/browser/WBBrowserWindow.h @@ -112,6 +112,10 @@ class WBBrowserWindow : public QWidget void showTabAtTop(bool attop); + void aboutToShowBackMenu(); + void aboutToShowForwardMenu(); + void openActionUrl(QAction *action); + signals: void activeViewPageChanged(); void activeViewChange(QWidget*); @@ -160,6 +164,9 @@ class WBBrowserWindow : public QWidget QString mLastSearch; Ui::MainWindow* mUniboardMainWindow; + + QMenu *mHistoryBackMenu; + QMenu *mHistoryForwardMenu; }; #endif // WBBROWSERMAINWINDOW_H