summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorRodolfo Ribeiro Gomes <rodolforg@gmail.com>2013-11-17 17:06:38 -0200
committerCaolán McNamara <caolanm@redhat.com>2013-11-20 06:07:04 -0600
commit55716b1ed969073f273c00baedb56d8f5de93761 (patch)
tree624b279e266d7909eb186c54281b48ac0df2e277 /sw
parentf8b22654197178a441d383398b515bb2fb6deaf2 (diff)
Highlight fade in SwCommentRuler
It was not implemented, though designed. No delay was used before start fading. I don't think it flickers. https://wiki.documentfoundation.org/Design/Whiteboards/Comments_Ruler_Control#Behavior Change-Id: I419220aac0a9cbfae328874cf6015d9530b93784 Signed-off-by: Rodolfo Ribeiro Gomes <rodolforg@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/6706 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/ui/inc/swruler.hxx19
-rw-r--r--sw/source/ui/misc/swruler.cxx54
2 files changed, 60 insertions, 13 deletions
diff --git a/sw/source/ui/inc/swruler.hxx b/sw/source/ui/inc/swruler.hxx
index 10a23c175fa8..aebf0b97396d 100644
--- a/sw/source/ui/inc/swruler.hxx
+++ b/sw/source/ui/inc/swruler.hxx
@@ -45,6 +45,8 @@ protected:
SwViewShell * mpViewShell; //< Shell to check if there is any comments on doc and their visibility
SwEditWin * mpSwWin; //< Used to get SwView to change the SideBar visibility
bool mbIsHighlighted; //< If comment control is highlighted (mouse is over it)
+ Timer maFadeTimer; //< Timer for high/'low'light fading
+ int mnFadeRate; //< From 0 to 100. 0 means not highlighted.
VirtualDevice maVirDev; //< VirtualDevice of this window. Just for convenience.
/**
@@ -77,7 +79,7 @@ protected:
* Get the rectangle area that should be used to draw the comment control.
*
* It is horizontally aligned to the SideBar panel.
- * \param Rectangle The area where the comment control is.
+ * \return The area where the comment control is.
*/
Rectangle GetCommentControlRegion();
@@ -98,6 +100,21 @@ protected:
* Update the tooltip text.
*/
void UpdateCommentHelpText();
+
+ /**
+ * Get the proper color between two options, according to current status.
+ *
+ * The return color can be one of the given colors, or a merged one.
+ * It depends on highlight fadind status.
+ *
+ * \param rHighColor color used to highlight status
+ * \param rLowColor color used to normal status
+ * \return The proper color to used in moment
+ */
+ Color GetFadedColor(const Color &rHighColor, const Color &rLowColor);
+
+ /// Fade timer callback.
+ DECL_LINK(FadeHandler, void *);
};
#endif
diff --git a/sw/source/ui/misc/swruler.cxx b/sw/source/ui/misc/swruler.cxx
index 06976395b92f..fa396d062aff 100644
--- a/sw/source/ui/misc/swruler.cxx
+++ b/sw/source/ui/misc/swruler.cxx
@@ -10,7 +10,6 @@
// FIX fdo#38246 https://bugs.libreoffice.org/show_bug.cgi?id=38246
// Design proposal: https://wiki.documentfoundation.org/Design/Whiteboards/Comments_Ruler_Control
// TODO Alpha blend border when it doesn't fit in window
-// TODO Delayed highlight fading when user moves mouse over and out the control
#include "swruler.hxx"
@@ -40,8 +39,12 @@ SwCommentRuler::SwCommentRuler( SwViewShell* pViewSh, Window* pParent, SwEditWin
, mpViewShell(pViewSh)
, mpSwWin(pWin)
, mbIsHighlighted(false)
+, mnFadeRate(0)
, maVirDev( *this )
{
+ // Set fading timeout: 5 x 40ms = 200ms
+ maFadeTimer.SetTimeout(40);
+ maFadeTimer.SetTimeoutHdl( LINK( this, SwCommentRuler, FadeHandler ) );
}
// Destructor
@@ -57,6 +60,7 @@ void SwCommentRuler::Paint( const Rectangle& rRect )
DrawCommentControl();
}
+
void SwCommentRuler::DrawCommentControl()
{
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
@@ -67,10 +71,8 @@ void SwCommentRuler::DrawCommentControl()
// Paint comment control background
// TODO Check if these are best colors to be used
- if ( mbIsHighlighted )
- maVirDev.SetFillColor( rStyleSettings.GetDarkShadowColor() );
- else
- maVirDev.SetFillColor( rStyleSettings.GetWorkspaceColor() );
+ Color aBgColor = GetFadedColor( rStyleSettings.GetDarkShadowColor(), rStyleSettings.GetWorkspaceColor() );
+ maVirDev.SetFillColor( aBgColor );
if ( mbIsHighlighted || !bIsCollapsed )
{
@@ -85,6 +87,7 @@ void SwCommentRuler::DrawCommentControl()
maVirDev.DrawRect( Rectangle( Point(), aControlRect.GetSize() ) );
+ // Label and arrow tip
OUString aLabel( SW_RESSTR ( STR_COMMENTS_LABEL ) );
// Get label and arrow coordinates
Point aLabelPos;
@@ -130,15 +133,15 @@ void SwCommentRuler::DrawCommentControl()
}
// Draw label
- const Color &rTextColor = mbIsHighlighted ? rStyleSettings.GetButtonTextColor() : rStyleSettings.GetDeactiveTextColor();
- maVirDev.SetTextColor( rTextColor );
+ Color aTextColor = GetFadedColor( rStyleSettings.GetButtonTextColor(), rStyleSettings.GetDeactiveTextColor() );
+ maVirDev.SetTextColor( aTextColor );
// FIXME Expected font size?
maVirDev.DrawText( aLabelPos, aLabel );
// Draw arrow
// FIXME consistence of button colors. http://opengrok.libreoffice.org/xref/core/vcl/source/control/button.cxx#785
- const Color &rArrowColor = mbIsHighlighted ? Color( COL_BLACK ) : rStyleSettings.GetShadowColor();
- ImplDrawArrow ( aArrowPos.X(), aArrowPos.Y(), rArrowColor, bArrowToRight );
+ Color aArrowColor = GetFadedColor( Color( COL_BLACK ), rStyleSettings.GetShadowColor() );
+ ImplDrawArrow ( aArrowPos.X(), aArrowPos.Y(), aArrowColor, bArrowToRight );
// Blit comment control
DrawOutDev( aControlRect.TopLeft(), aControlRect.GetSize(), Point(), aControlRect.GetSize(), maVirDev );
@@ -180,14 +183,12 @@ void SwCommentRuler::MouseMove(const MouseEvent& rMEvt)
SvxRuler::MouseMove(rMEvt);
if ( ! mpViewShell->GetPostItMgr() || ! mpViewShell->GetPostItMgr()->HasNotes() )
return;
- // TODO Delay 0.1s to highlight and 0.2s to "lowlight"
+
Point aMousePos = rMEvt.GetPosPixel();
bool bWasHighlighted = mbIsHighlighted;
mbIsHighlighted = GetCommentControlRegion().IsInside( aMousePos );
if ( mbIsHighlighted != bWasHighlighted )
{
- // Repaint for highlight changes make effect
- Invalidate();
// Set proper help text
if ( mbIsHighlighted )
{
@@ -200,6 +201,8 @@ void SwCommentRuler::MouseMove(const MouseEvent& rMEvt)
// FIXME Should remember previous tooltip text?
SetQuickHelpText( OUString() );
}
+ // Do start fading
+ maFadeTimer.Start();
}
}
@@ -268,4 +271,31 @@ Rectangle SwCommentRuler::GetCommentControlRegion()
return aRect;
}
+Color SwCommentRuler::GetFadedColor(const Color &rHighColor, const Color &rLowColor)
+{
+ if ( ! maFadeTimer.IsActive() )
+ return mbIsHighlighted ? rHighColor : rLowColor;
+
+ Color aColor = rHighColor;
+ aColor.Merge( rLowColor, mnFadeRate * 255/100.f );
+ return aColor;
+}
+
+IMPL_LINK_NOARG(SwCommentRuler, FadeHandler)
+{
+ const int nStep = 25;
+ if ( mbIsHighlighted && mnFadeRate < 100 )
+ mnFadeRate += nStep;
+ else if ( !mbIsHighlighted && mnFadeRate > 0 )
+ mnFadeRate -= nStep;
+ else
+ return 0;
+
+ Invalidate();
+
+ if ( mnFadeRate != 0 && mnFadeRate != 100)
+ maFadeTimer.Start();
+ return 0;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */