include/svtools/valueset.hxx | 8 ++- svtools/source/control/valueset.cxx | 92 ++++++++++++++++++++++++++---------- 2 files changed, 73 insertions(+), 27 deletions(-)
New commits: commit e9393a27646d5d43317cbdae9785e9e0319b4cc8 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Wed Oct 27 10:16:02 2021 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Oct 27 16:45:15 2021 +0200 draw valuesets with a visual difference between selected and mouse hover similar to the select a template dialog in impress use: * ActiveColor for selected + hover * HighlightColor for selected or hover, with some transparency for hover Change-Id: I0b6dd9ff36a51e9ce3d8bc6deac3f35794a7d429 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124262 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx index f7b30a83c2f8..ada2641c2eb4 100644 --- a/include/svtools/valueset.hxx +++ b/include/svtools/valueset.hxx @@ -230,9 +230,13 @@ private: SVT_DLLPRIVATE void ImplDeleteItems(); SVT_DLLPRIVATE void ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem* pItem, tools::Rectangle aRect); SVT_DLLPRIVATE void ImplDrawItemText(vcl::RenderContext& rRenderContext, const OUString& rStr); - // nItemId is the item to draw selected, but if nothing is selected something else may be drawn as selected instead, the item drawn + // nItemId is the item to draw selected, but if nothing is selected something else may be drawn as selected instead, the item to draw // selected is returned - SVT_DLLPRIVATE sal_uInt16 ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel); + SVT_DLLPRIVATE ValueSetItem* ImplGetDrawSelectItem(sal_uInt16 nItemId, const bool bFocus, tools::Rectangle& rRect); + SVT_DLLPRIVATE void ImplDrawSelect(vcl::RenderContext& rRenderContext, + const tools::Rectangle& rRect, ValueSetItem* pItem, + const bool bFocus, const bool bDrawSel, + const bool bSelected, const bool bHover); SVT_DLLPRIVATE void ImplDrawSelect(vcl::RenderContext& rRenderContext); SVT_DLLPRIVATE void ImplHighlightItem(sal_uInt16 nItemId, bool bIsSelection = true); SVT_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext); diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx index a5c1b21e47e9..13f2abfa0df5 100644 --- a/svtools/source/control/valueset.cxx +++ b/svtools/source/control/valueset.cxx @@ -1189,46 +1189,72 @@ void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext) return; } - sal_uInt16 nItemDrawnSelected = ImplDrawSelect(rRenderContext, mnSelItemId, bFocus, bDrawSel); - if (mbHighlight && mnHighItemId != nItemDrawnSelected) + tools::Rectangle aSelectedRect, aHoverRect; + ValueSetItem* pSelectedItem = ImplGetDrawSelectItem(mnSelItemId, bFocus, aSelectedRect); + ValueSetItem* pHighlightItem = mnHighItemId ? ImplGetDrawSelectItem(mnHighItemId, false, aHoverRect) : nullptr; + + if (pSelectedItem) + { + const bool bHover = mnHighItemId && pSelectedItem == pHighlightItem; + ImplDrawSelect(rRenderContext, aSelectedRect, pSelectedItem, bFocus, bDrawSel, true, bHover); + } + if (mnHighItemId && pHighlightItem && pSelectedItem != pHighlightItem) { - ImplDrawSelect(rRenderContext, mnHighItemId, false, bDrawSel); + ImplDrawSelect(rRenderContext, aHoverRect, pHighlightItem, false, bDrawSel, false, true); } } -sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel ) +ValueSetItem* ValueSet::ImplGetDrawSelectItem(sal_uInt16 nItemId, const bool bFocus, tools::Rectangle& rRect) { - ValueSetItem* pItem; - tools::Rectangle aRect; + ValueSetItem* pItem = nullptr; if (nItemId) { const size_t nPos = GetItemPos( nItemId ); pItem = mItemList[ nPos ].get(); - aRect = ImplGetItemRect( nPos ); + rRect = ImplGetItemRect( nPos ); } else if (mpNoneItem) { pItem = mpNoneItem.get(); - aRect = maNoneItemRect; + rRect = maNoneItemRect; } else if (bFocus && (pItem = ImplGetFirstItem())) { - aRect = ImplGetItemRect(0); - } - else - { - return 0; + rRect = ImplGetItemRect(0); } + return pItem; +} - if (!pItem->mbVisible) - return 0; +void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, + const tools::Rectangle& rRect, ValueSetItem* pItem, + const bool bFocus, const bool bDrawSel, + const bool bSelected, const bool bHover) +{ + tools::Rectangle aRect(rRect); // draw selection const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); rRenderContext.SetFillColor(); - Color aDoubleColor(rStyleSettings.GetHighlightColor()); - Color aSingleColor(rStyleSettings.GetHighlightTextColor()); + Color aDoubleColor; + Color aSingleColor; + + sal_uInt16 nTransparencePercent = 0; + + if (bSelected && bHover) + { + aDoubleColor = rStyleSettings.GetActiveColor(); + aSingleColor = rStyleSettings.GetActiveTextColor(); + } + else if (bSelected || bHover) + { + aDoubleColor = rStyleSettings.GetHighlightColor(); + aSingleColor = rStyleSettings.GetHighlightTextColor(); + if (bHover) + { + nTransparencePercent = 55; + } + } // specify selection output WinBits nStyle = GetStyle(); @@ -1239,7 +1265,9 @@ sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt if (bDrawSel) { rRenderContext.SetLineColor(aDoubleColor); - rRenderContext.DrawRect(aRect); + tools::PolyPolygon aPolyPoly(1); + aPolyPoly.Insert(aRect); + rRenderContext.DrawTransparent(aPolyPoly, nTransparencePercent); } } else @@ -1247,7 +1275,9 @@ sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt if (bDrawSel) { rRenderContext.SetLineColor(aDoubleColor); - rRenderContext.DrawRect(aRect); + tools::PolyPolygon aPolyPoly(1); + aPolyPoly.Insert(aRect); + rRenderContext.DrawTransparent(aPolyPoly, nTransparencePercent); } if (mbDoubleSel) { @@ -1256,7 +1286,11 @@ sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt aRect.AdjustRight( -1 ); aRect.AdjustBottom( -1 ); if (bDrawSel) - rRenderContext.DrawRect(aRect); + { + tools::PolyPolygon aPolyPoly(1); + aPolyPoly.Insert(aRect); + rRenderContext.DrawTransparent(aPolyPoly, nTransparencePercent); + } } aRect.AdjustLeft( 1 ); aRect.AdjustTop( 1 ); @@ -1268,7 +1302,11 @@ sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt aRect.AdjustRight( -1 ); aRect.AdjustBottom( -1 ); if (bDrawSel) - rRenderContext.DrawRect(aRect); + { + tools::PolyPolygon aPolyPoly(1); + aPolyPoly.Insert(aRect); + rRenderContext.DrawTransparent(aPolyPoly, nTransparencePercent); + } if (mbDoubleSel) { aRect.AdjustLeft( 1 ); @@ -1276,7 +1314,11 @@ sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt aRect.AdjustRight( -1 ); aRect.AdjustBottom( -1 ); if (bDrawSel) - rRenderContext.DrawRect(aRect); + { + tools::PolyPolygon aPolyPoly(1); + aPolyPoly.Insert(aRect); + rRenderContext.DrawTransparent(aPolyPoly, nTransparencePercent); + } } if (bDrawSel) @@ -1287,14 +1329,14 @@ sal_uInt16 ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt { rRenderContext.SetLineColor(COL_LIGHTGRAY); } - rRenderContext.DrawRect(aRect2); + tools::PolyPolygon aPolyPoly(1); + aPolyPoly.Insert(aRect2); + rRenderContext.DrawTransparent(aPolyPoly, nTransparencePercent); if (bFocus) InvertFocusRect(rRenderContext, aRect2); } ImplDrawItemText(rRenderContext, pItem->maText); - - return pItem->mnId; } void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem* pItem, tools::Rectangle aRect)