From c1e263671929493014babeb76d34d5d8b5e4a270 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 15 Oct 2012 20:16:14 +0300 Subject: [PATCH] Sankore 1224 z-layer reordering amended Delegate button progressbar added retrieving data from the internet --- src/board/UBFeaturesController.cpp | 9 +++- src/board/UBFeaturesController.h | 1 + src/domain/UBGraphicsItemDelegate.cpp | 59 ++++++++++++++++++++++++++- src/domain/UBGraphicsItemDelegate.h | 12 ++++++ src/domain/UBGraphicsScene.cpp | 17 ++++---- src/gui/UBFeaturesWidget.cpp | 29 ++++++++++--- 6 files changed, 110 insertions(+), 17 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index b05c212b..fa5cbb74 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -251,7 +251,14 @@ bool UBFeature::operator !=( const UBFeature &f )const bool UBFeature::isFolder() const { return elementType == FEATURE_CATEGORY || elementType == FEATURE_TRASH || elementType == FEATURE_FAVORITE - || elementType == FEATURE_FOLDER; + || elementType == FEATURE_FOLDER || elementType == FEATURE_SEARCH; +} + +bool UBFeature::allowedCopy() const +{ + return isFolder() + && elementType != FEATURE_CATEGORY + && elementType != FEATURE_SEARCH; } bool UBFeature::isDeletable() const diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 472f8460..61bee3ec 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -106,6 +106,7 @@ public: UBFeatureElementType getType() const { return elementType; } bool isFolder() const; + bool allowedCopy() const; bool isDeletable() const; bool inTrash() const; bool operator ==( const UBFeature &f )const; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index a1d57202..8c09e838 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -54,6 +54,10 @@ DelegateButton::DelegateButton(const QString & fileName, QGraphicsItem* pDelegat : QGraphicsSvgItem(fileName, parent) , mDelegated(pDelegated) , mIsTransparentToMouseEvent(false) + , mIsPressed(false) + , mProgressTimerId(-1) + , mPressProgres(0) + , mShowProgressIndicator(false) , mButtonAlignmentSection(section) { setAcceptedMouseButtons(Qt::LeftButton); @@ -71,26 +75,75 @@ void DelegateButton::setFileName(const QString & fileName) QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this)); } - void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event) { + if (mShowProgressIndicator) { + QTimer::singleShot(300, this, SLOT(startShowProgress())); + } + + mIsPressed = true; + // make sure delegate is selected, to avoid control being hidden mPressedTime = QTime::currentTime(); event->setAccepted(!mIsTransparentToMouseEvent); - } +} void DelegateButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if (mShowProgressIndicator && mProgressTimerId != -1) { + killTimer(mProgressTimerId); + mPressProgres = 0; + } + + mIsPressed = false; int timeto = qAbs(QTime::currentTime().msecsTo(mPressedTime)); if (timeto < UBSettings::longClickInterval) { emit clicked(); + qDebug() << "clicked"; } else { emit longClicked(); + qDebug() << "longClicked"; } event->setAccepted(!mIsTransparentToMouseEvent); + + update(); +} + +void DelegateButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QGraphicsSvgItem::paint(painter, option, widget); + + if (mIsPressed && mShowProgressIndicator) { + QPen pen; + pen.setBrush(Qt::darkRed); + pen.setWidth(3); + painter->save(); + + painter->setPen(pen); + + int spanAngle = qMin(mPressProgres, UBSettings::longClickInterval) * 360 / UBSettings::longClickInterval; + painter->drawArc(option->rect.adjusted(pen.width(), pen.width(), -pen.width(), -pen.width()), 16 * 90, -16 * spanAngle); + + painter->restore(); + } +} + +void DelegateButton::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == mProgressTimerId) { + mPressProgres = qAbs(QTime::currentTime().msecsTo(mPressedTime)); + update(); + } +} + +void DelegateButton::startShowProgress() +{ + if (mIsPressed) { + mProgressTimerId = startTimer(37); + } } UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate, bool useToolBar) @@ -139,11 +192,13 @@ void UBGraphicsItemDelegate::init() mButtons << mMenuButton; mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); + mZOrderUpButton->setShowProgressIndicator(true); connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); mButtons << mZOrderUpButton; mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); + mZOrderDownButton->setShowProgressIndicator(true); connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); mButtons << mZOrderDownButton; diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 01ef854b..418ae80a 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -50,6 +50,9 @@ class DelegateButton: public QGraphicsSvgItem void setFileName(const QString & fileName); + void setShowProgressIndicator(bool pShow) {mShowProgressIndicator = pShow;} + bool testShowProgresIndicator() const {return mShowProgressIndicator;} + void setSection(Qt::WindowFrameSection section) {mButtonAlignmentSection = section;} Qt::WindowFrameSection getSection() const {return mButtonAlignmentSection;} @@ -57,15 +60,24 @@ class DelegateButton: public QGraphicsSvgItem virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void timerEvent(QTimerEvent *event); void modified(); +private slots: + void startShowProgress(); + private: QGraphicsItem* mDelegated; QTime mPressedTime; bool mIsTransparentToMouseEvent; + bool mIsPressed; + int mProgressTimerId; + int mPressProgres; + bool mShowProgressIndicator; Qt::WindowFrameSection mButtonAlignmentSection; signals: diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 7eb8a3ea..ca953a76 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -190,7 +190,6 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de 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(); @@ -199,11 +198,12 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de // //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) { + 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) { @@ -214,7 +214,8 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de doubleGap = true; break; } else { - UBGraphicsItem::assignZValue(iCurElement.value(), iCurElement.next().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + UBGraphicsItem::assignZValue(iCurElement.value(), curNextZ); + iCurElement.next(); } } if (!doubleGap) { @@ -237,6 +238,7 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de //Return new z value assigned to item return item->data(UBGraphicsItemData::ItemOwnZValue).toReal(); + } itemLayerType::Enum UBZLayerController::typeForData(QGraphicsItem *item) const @@ -297,7 +299,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta } // Just for debug. Do not delete please -// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); + connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState())); } @@ -315,10 +317,9 @@ UBGraphicsScene::~UBGraphicsScene() void UBGraphicsScene::selectionChangedProcessing() { if (selectedItems().count()){ - // UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " -// + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); - qDebug() << "flippable" << selectedItems().first()->data(UBGraphicsItemData::ItemFlippable).toBool() << endl - << "rotatable" << selectedItems().first()->data(UBGraphicsItemData::ItemRotatable).toBool(); + UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " + + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); + } } diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 226f27c5..cfce8694 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -121,18 +121,27 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) if ( feature.getType() == FEATURE_FAVORITE ) { mActionBar->setCurrentState( IN_FAVORITE ); - } else if ( feature.getType() == FEATURE_CATEGORY && feature.getName() == "root" ) { + } else if ( feature.getType() == FEATURE_CATEGORY && feature.getName() == "root" ) { mActionBar->setCurrentState( IN_ROOT ); } else if (feature.getType() == FEATURE_TRASH) { mActionBar->setCurrentState(IN_TRASH); - } else { + } else if (feature.getType() == FEATURE_SEARCH) { + //The search feature behavior is not standard. If features list clicked - show empty element + //else show existing saved features search QWebView + if (sender()->objectName() == objNameFeatureList) { + centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView); + } else if (sender()->objectName() == objNamePathList) { + centralWidget->switchTo(UBFeaturesCentralWidget::FeaturesWebView); + } + + } else { mActionBar->setCurrentState(IN_FOLDER); } - } else if (feature.getType() == FEATURE_SEARCH) { - centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView); +// } else if (feature.getType() == FEATURE_SEARCH) { +// centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView); } else { centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList); @@ -1067,7 +1076,15 @@ void UBFeatureProperties::onAddToLib() desc.name = mpElement->getMetadata().value("Title", QString()); qDebug() << desc.name; desc.srcUrl = mpElement->getFullPath().toString(); - qDebug() << desc.srcUrl; + QString str1 = mpElement->getFullPath().toString().normalized(QString::NormalizationForm_C); + QString str2 = mpElement->getFullPath().toString().normalized(QString::NormalizationForm_D); + QString str3 = mpElement->getFullPath().toString().normalized(QString::NormalizationForm_KC); + QString str4 = mpElement->getFullPath().toString().normalized(QString::NormalizationForm_KD); + qDebug() << desc.srcUrl << endl + << "str1" << str1 << endl + << "str2" << str2 << endl + << "str3" << str3 << endl + << "str4" << str4 << endl; UBDownloadManager::downloadManager()->addFileToDownload(desc); } } @@ -1411,7 +1428,7 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value(); - return feature.isFolder() && path.startsWith( feature.getFullVirtualPath() ); + return feature.isFolder() && path.startsWith( feature.getFullVirtualPath()) ; } QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLocale & locale ) const