[Ktutorial-commits] SF.net SVN: ktutorial:[289] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-03-08 02:47:21
|
Revision: 289 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=289&view=rev Author: danxuliu Date: 2011-03-08 02:47:15 +0000 (Tue, 08 Mar 2011) Log Message: ----------- Modify how widgets are highlighted. Due to performance reasons (specially in interfaces with a lot of widgets) instead of tinting the whole widget now only a frame is tinted. The color used now is always got from the active palette, as the highlight color in the inactive palette could be too subtle. The animation interval was increased also for performance reasons, and now only the frame is updated instead of the whole widget. However, the duration of the animation was increased just for stylistic purposes (and StepTextWidgetTest had to be updated due to the new animation length). Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.cpp trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.h trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.cpp 2011-01-28 10:59:11 UTC (rev 288) +++ trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.cpp 2011-03-08 02:47:15 UTC (rev 289) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -42,13 +42,15 @@ mIncreasing = true; mStopping = false; - int interval = 25; - int duration = 500; + int interval = 80; + int duration = 1000; mProgressForEachTick = interval / (qreal)duration; mTimer.setInterval(interval); connect(&mTimer, SIGNAL(timeout()), this, SLOT(updateProgress())); + mFrameWidth = 6; + show(); } @@ -86,11 +88,10 @@ void WidgetHighlighter::paintEvent(QPaintEvent* event) { //Painting the WidgetHighlighter over its parent widget with a - //semi-transpaernt color is the best I could get. However, it has some + //semi-transparent color is the best I could get. However, it has some //flaws. For example, a QMenu does not highlight its menu button. And some //widgets may be hardly highlighted if their background color is almost the - //same as the highlight color (like QStatusBar in Oxygen style and default - //colors). + //same as the highlight color (although it should not happen very often). // //Changing the parent widget palette does not work because some widgets //(like tool buttons) don't paint a background, only paint the text and get @@ -123,12 +124,33 @@ //quickly enough to be done in a realtime animation, so... a //semi-transparent colored child widget is good enough until someone makes //something better ;) + // + //However, filling the whole widget and animating it is too CPU intensive + //when tinting a parent widget with lots of child widgets (for example, the + //main widget in showfoto). So, instead of tinting the whole parent only + //a frame is painted and animated. In this case, the frame gets its full + //opacity at the peak of the animation, instead of half the opacity as used + //when tinting the whole widget. - QColor color = mTargetWidget->palette().color(QPalette::Highlight); + //The inactive palette does not usually have a lot of contrast between + //normal color and highlight color (for example, a QStatusBar in Oxygen + //style). The highlight color from the active palette is used in every case + //to ensure that the widget is clearly highlighted, even if the window is + //not the active one. + QColor color = mTargetWidget->palette().color(QPalette::Active, + QPalette::Highlight); QPainter painter(this); - painter.setOpacity(mProgress / 2.0f); - painter.fillRect(event->rect(), color); + painter.setOpacity(mProgress); + + QPen pen; + pen.setWidth(mFrameWidth); + pen.setColor(color); + painter.setPen(pen); + + //Third and fourth arguments are width and height, not end coordinates + painter.drawRect(pen.width() / 2, pen.width() / 2, + width() - pen.width(), height() - pen.width()); painter.end(); } @@ -145,7 +167,12 @@ mIncreasing = mProgress == 0; } - update(); + //Update just the frame of the widget instead of the whole widget for + //performance + update(0, 0, width(), mFrameWidth); + update(0, 0, mFrameWidth, height()); + update(width() - mFrameWidth, 0, width(), height()); + update(0, height() - mFrameWidth, width(), height()); if (mStopping && mProgress == 0) { mTimer.stop(); Modified: trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.h 2011-01-28 10:59:11 UTC (rev 288) +++ trunk/ktutorial/ktutorial-library/src/extendedinformation/WidgetHighlighter.h 2011-03-08 02:47:15 UTC (rev 289) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -37,9 +37,10 @@ * stop animation is cancelled and a new highlight animation is started from * that point). * - * To tint the widget, the WidgetHighlighter paints itself over the whole parent - * widget with a semi-transparent highlight color, so the parent widget can - * still be seen but tinted with the highlight color. + * To tint the widget, the WidgetHighlighter paints itself over the parent + * widget with a semi-transparent highlight color. However, due to performance + * reasons, only a frame is tinted instead of the whole widget. The center of + * the frame is always transparent. * * WidgetHighlighter should not be created directly. Instead, * WidgetHighlighterManager should be used, as it takes care of deleting the @@ -99,7 +100,7 @@ protected: /** - * Fills the widget with a semi-transparent highlight color. + * Paints a frame with a semi-transparent highlight color. * The degree of opacity depends on the progress of the animation. * * @param event The paint event. @@ -139,6 +140,11 @@ */ bool mStopping; + /** + * The width of the frame used to highlight the widget. + */ + int mFrameWidth; + private Q_SLOTS: /** Modified: trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp 2011-01-28 10:59:11 UTC (rev 288) +++ trunk/ktutorial/ktutorial-library/tests/view/StepTextWidgetTest.cpp 2011-03-08 02:47:15 UTC (rev 289) @@ -201,7 +201,7 @@ showContextMenuAndSelectFirstOption(widget, position); //Give the highlighter time to stop - QTest::qWait(500); + QTest::qWait(1000); QVERIFY(!widgetToHighlight->findChild<WidgetHighlighter*>("")); } @@ -260,7 +260,7 @@ position1, 500); //Give the highlighter time to stop - QTest::qWait(500); + QTest::qWait(1000); QVERIFY(!widgetToHighlight1->findChild<WidgetHighlighter*>("")); QVERIFY(!widgetToHighlight2->findChild<WidgetHighlighter*>("")); @@ -272,7 +272,7 @@ showContextMenuAndSelectFirstOption(widget, position2); //Give the highlighter time to stop - QTest::qWait(500); + QTest::qWait(1000); QVERIFY(!widgetToHighlight1->findChild<WidgetHighlighter*>("")); QVERIFY(!widgetToHighlight2->findChild<WidgetHighlighter*>("")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |