[Ktutorial-commits] SF.net SVN: ktutorial:[348] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2012-06-27 16:49:51
|
Revision: 348 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=348&view=rev Author: danxuliu Date: 2012-06-27 16:49:40 +0000 (Wed, 27 Jun 2012) Log Message: ----------- Fix stopping the highlighting of a widget when a context menu was just shown for the link to another widget, even if the action to highlight the other widget was not activated. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.cpp trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.h trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.cpp 2012-06-27 11:35:47 UTC (rev 347) +++ trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.cpp 2012-06-27 16:49:40 UTC (rev 348) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -34,8 +34,8 @@ StepTextWidget::StepTextWidget(QWidget* parent /*= 0*/): KTextEdit(parent), - mCurrentWidget(0), - mCurrentWidgetIsBeingHighlighted(false) { + mLastReferencedWidget(0), + mWidgetBeingHighlighted(0) { setReadOnly(true); setFrameShape(QFrame::NoFrame); setFrameShadow(QFrame::Plain); @@ -61,13 +61,13 @@ } StepTextWidget::~StepTextWidget() { - if (mCurrentWidgetIsBeingHighlighted) { + if (mWidgetBeingHighlighted) { stopHighlightingCurrentWidget(); } } bool StepTextWidget::eventFilter(QObject* watched, QEvent* event) { - if (watched != mCurrentWidget) { + if (watched != mWidgetBeingHighlighted) { return false; } @@ -107,16 +107,10 @@ QMenu* menu = new QMenu(this); - if (mCurrentWidgetIsBeingHighlighted && - mCurrentWidget != widgetForAnchor(anchor)) { - stopHighlightingCurrentWidget(); - } - - if (!mCurrentWidgetIsBeingHighlighted) { + mLastReferencedWidget = widgetForAnchor(anchor); + if (mLastReferencedWidget != mWidgetBeingHighlighted) { menu->addAction(i18nc("@item:inmenu", "Highlight"), - this, SLOT(highlightCurrentWidget())); - - mCurrentWidget = widgetForAnchor(anchor); + this, SLOT(highlightLastReferencedWidget())); } else { menu->addAction(i18nc("@item:inmenu", "Stop highlighting"), this, SLOT(stopHighlightingCurrentWidget())); @@ -144,15 +138,9 @@ return; } - if (mCurrentWidgetIsBeingHighlighted && - mCurrentWidget != widgetForAnchor(anchor)) { - stopHighlightingCurrentWidget(); - } - - if (!mCurrentWidgetIsBeingHighlighted) { - mCurrentWidget = widgetForAnchor(anchor); - - highlightCurrentWidget(); + mLastReferencedWidget = widgetForAnchor(anchor); + if (mLastReferencedWidget != mWidgetBeingHighlighted) { + highlightLastReferencedWidget(); } else { stopHighlightingCurrentWidget(); } @@ -186,36 +174,37 @@ void StepTextWidget::updateText() { updateGeometry(); - if (mCurrentWidgetIsBeingHighlighted) { + if (mWidgetBeingHighlighted) { stopHighlightingCurrentWidget(); } } -void StepTextWidget::highlightCurrentWidget() { - if (!mCurrentWidget) { +void StepTextWidget::highlightLastReferencedWidget() { + if (!mLastReferencedWidget) { kWarning() << "The widget to highlight was not found!"; return; } - WidgetHighlighterManager::self()->highlight(mCurrentWidget); + if (mWidgetBeingHighlighted) { + stopHighlightingCurrentWidget(); + } - mCurrentWidget->installEventFilter(this); + WidgetHighlighterManager::self()->highlight(mLastReferencedWidget); - mCurrentWidgetIsBeingHighlighted = true; + mLastReferencedWidget->installEventFilter(this); + mWidgetBeingHighlighted = mLastReferencedWidget; } void StepTextWidget::stopHighlightingCurrentWidget() { - if (!mCurrentWidget) { + if (!mWidgetBeingHighlighted) { kWarning() << "The widget to stop highlighting was not found!"; return; } - WidgetHighlighterManager::self()->stopHighlighting(mCurrentWidget); + WidgetHighlighterManager::self()->stopHighlighting(mWidgetBeingHighlighted); - mCurrentWidget->removeEventFilter(this); - mCurrentWidget = 0; - - mCurrentWidgetIsBeingHighlighted = false; + mWidgetBeingHighlighted->removeEventFilter(this); + mWidgetBeingHighlighted = 0; } } Modified: trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.h 2012-06-27 11:35:47 UTC (rev 347) +++ trunk/ktutorial/ktutorial-library/src/view/StepTextWidget.h 2012-06-27 16:49:40 UTC (rev 348) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2012 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -109,8 +109,7 @@ * "widget:" anchor. * The context menu will contain a "Stop highlighting" or a "Highlight" item * depending on whether the widget is the one currently being highlighted or - * not. If the widget currently being highlighted is another one, it is - * stopped. + * not. * * @param event The context menu event. */ @@ -126,7 +125,6 @@ /** * When the mouse is pressed on a "widget:" anchor, it is highlighted or * stopped being highlighted. - * If the widget currently being highlighted is another one, it is stopped. * * @param event The mouse press event. */ @@ -138,12 +136,12 @@ * The last widget referenced by a link activated or selected in this * StepTextWidget. */ - QPointer<QWidget> mCurrentWidget; + QPointer<QWidget> mLastReferencedWidget; /** - * Whether the current widget is being highlighted or not. + * The widget being highlighted. */ - bool mCurrentWidgetIsBeingHighlighted; + QPointer<QWidget> mWidgetBeingHighlighted; /** * Returns the size for the given text width. @@ -172,18 +170,18 @@ /** * Notifies the layout that the geometry of the widget has changed and stops - * the highlighting of the current widget, if any. + * the widget currently being highlighted, if any. */ void updateText(); /** - * Starts highlighting the current widget. + * Starts highlighting the last referenced widget. + * If there is any widget currently being highlighted, it is stopped. */ - void highlightCurrentWidget(); + void highlightLastReferencedWidget(); /** - * Stops highlighting the current widget. - * The current widget is cleared. + * Stops highlighting the widget currently being highlighted. */ void stopHighlightingCurrentWidget(); Modified: trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp 2012-06-27 11:35:47 UTC (rev 347) +++ trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp 2012-06-27 16:49:40 UTC (rev 348) @@ -51,6 +51,7 @@ void testHighlightWidgetUsingContextMenu(); void testStopHighlightingWidgetUsingContextMenu(); void testCancelContextMenu(); + void testCancelContextMenuOnOtherLink(); void testHighlightSeveralWidgets(); void testHighlightUnknownWidget(); @@ -232,11 +233,46 @@ showContextMenuCheckFirstOptionAndCancel(widget, position, i18n("Stop highlighting")); + //Ensure that just showing the context menu does not stop the highlighting + QVERIFY(!waitForHighlighterToStop(widgetToHighlight, 1000)); + //Ensure that the option text is the right one after cancelling the menu showContextMenuCheckFirstOptionAndCancel(widget, position, i18n("Stop highlighting")); } +void StepTextWidgetTest::testCancelContextMenuOnOtherLink() { + KXmlGuiWindow mainWindow; + KTutorial::self()->setup(&mainWindow); + QWidget* widgetToHighlight1 = new QWidget(&mainWindow); + widgetToHighlight1->setObjectName("widget1"); + QWidget* widgetToHighlight2 = new QWidget(&mainWindow); + widgetToHighlight2->setObjectName("widget2"); + + StepTextWidget widget; + widget.setText("The <a href=\"widget:widget1\">first widget</a> and the " +"<a href=\"widget:widget2\">second widget</a>"); + widget.show(); + + QTest::qWaitForWindowShown(&widget); + + QPoint position1 = centerOfText(widget, "first widget"); + QPoint position2 = centerOfText(widget, "second widget"); + + showContextMenuAndSelectFirstOption(widget, position1); + + showContextMenuCheckFirstOptionAndCancel(widget, position2, + i18n("Highlight")); + + //Ensure that just showing the context menu on the second link does not stop + //the highlighting of the first widget + QVERIFY(!waitForHighlighterToStop(widgetToHighlight1, 1000)); + + //Ensure that the option text is the right one after cancelling the menu + showContextMenuCheckFirstOptionAndCancel(widget, position2, + i18n("Highlight")); +} + void StepTextWidgetTest::testHighlightSeveralWidgets() { KXmlGuiWindow mainWindow; KTutorial::self()->setup(&mainWindow); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |