From 39fcd97bfe83a82b82c871876b970c6076db5b0f Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 10 Apr 2012 14:08:46 +0300 Subject: [PATCH 1/2] 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 From 4d2990a905b473be691f95ff064f3d937496fff2 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Tue, 10 Apr 2012 16:59:30 +0200 Subject: [PATCH 2/2] Backup of the mirroring implementation --- src/domain/UBGraphicsDelegateFrame.cpp | 70 +++++++++++++++++++------- src/domain/UBGraphicsDelegateFrame.h | 1 + src/domain/UBGraphicsPixmapItem.cpp | 2 +- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index ea90a676..cdf184a4 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -189,7 +189,7 @@ void UBGraphicsDelegateFrame::initializeTransform() mAngle = topLine.angle(); - //the fact the the lenght is used we loose the horizontalFlip information + // the fact the the length 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; @@ -227,6 +227,22 @@ void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event) event->accept(); } +bool UBGraphicsDelegateFrame::canResizeBottomRight(qreal width, qreal height, qreal scaleFactor) +{ + bool res = false; + + if(!mMirrorX && !mMirrorX && ((width * scaleFactor) > 2*mFrameWidth && (height * scaleFactor) > 2*mFrameWidth)){ + res = true; + }else if(mMirrorX && !mMirrorY && (-width * scaleFactor) > 2*mFrameWidth && (height*scaleFactor) > 2*mFrameWidth){ + res = true; + }else if(!mMirrorX && mMirrorY && (width * scaleFactor) > 2*mFrameWidth && (-height*scaleFactor) > 2*mFrameWidth){ + res = true; + }else if(mMirrorX && mMirrorY && (-width * scaleFactor) > 2*mFrameWidth && (-height*scaleFactor) > 2*mFrameWidth){ + res = true; + } + + return res; +} void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { @@ -237,27 +253,33 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) qreal height = delegated()->boundingRect().height() * mTotalScaleY; mTranslateX = moveX; - if(mOperationMode == Scaling) { -// // Hide the buttons -// mDelegate->setButtonsVisible(false); -// mResizing = true; - // Perform the resize if (resizingBottomRight()) { // ----------------------------------------------------- // ! We want to keep the aspect ratio with this resize ! // ----------------------------------------------------- - qreal scaleX = (width + moveX) / width; - qreal scaleY = (height + moveY) / height; + qreal scaleX; + qreal scaleY; + + if(!mMirrorX){ + scaleX = (width + moveX) / width; + }else{ + scaleX = (width - moveX) / width; + } + + if(!mMirrorY){ + scaleY = (height + moveY) / height; + }else{ + scaleY = (height - moveY) / height; + } + qreal scaleFactor = (scaleX + scaleY) / 2; // Do not allow resizing of image size under frame size - if (scaleFactor > 1 - || ((width * scaleFactor) > 2 * mFrameWidth - && (height * scaleFactor) > 2 * mFrameWidth)) + if (canResizeBottomRight(width, height, scaleFactor)) { if (mRespectRatio) { @@ -282,7 +304,6 @@ 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); if(negative){ scaleX = -2*mFrameWidth/width; }else{ @@ -360,9 +381,6 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QSizeF newSize = resizableItem->size() + incVector; -// if (newSize.width() < 50 /*0*/ || newSize.height() < /*0*/ 50) -// return; - resizableItem->resize(newSize); } } @@ -395,10 +413,28 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) //TODO UB 4.x: Could find a better solution ? if (resizingRight() || resizingBottom() || resizingBottomRight()) { - QPointF topLeft = tr.map(delegated()->boundingRect().topLeft()); - QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().topLeft()); + QPointF ref; + if(!mMirrorX && !mMirrorY){ + ref = delegated()->boundingRect().topLeft(); + }else if(mMirrorX && !mMirrorY){ + ref = delegated()->boundingRect().topRight(); + }else if(!mMirrorX && mMirrorY){ + ref = delegated()->boundingRect().bottomLeft(); + }else if(mMirrorX && mMirrorY){ + ref = delegated()->boundingRect().bottomRight(); + } + + // Map the item topleft point to the current mouse move transform + QPointF topLeft = tr.map(ref); + + // Map the item topleft point to the mouse press transform + QPointF fixedPoint = mInitialTransform.map(ref); + + // Update the translation coordinates mTranslateX += fixedPoint.x() - topLeft.x(); mTranslateY += fixedPoint.y() - topLeft.y(); + + // Update the transform tr = buildTransform(); } else if (resizingTop() || resizingLeft()) diff --git a/src/domain/UBGraphicsDelegateFrame.h b/src/domain/UBGraphicsDelegateFrame.h index 2cd1e0d1..7a825d53 100644 --- a/src/domain/UBGraphicsDelegateFrame.h +++ b/src/domain/UBGraphicsDelegateFrame.h @@ -64,6 +64,7 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject inline bool resizingTop () const { return mCurrentTool == ResizeTop; } inline bool rotating () const { return mCurrentTool == Rotate; } inline bool moving () const { return mCurrentTool == Move; } + bool canResizeBottomRight(qreal width, qreal height, qreal scaleFactor); QTransform buildTransform (); void updateResizeCursors (); diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 223ca4a2..07dc4679 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);