From 089c7d05fde13251eb8cd8daaf7627b6bb0072f9 Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Tue, 27 Apr 2021 13:34:23 +0300 Subject: [PATCH] tdf#48622 add border line thickness predefined values in UI According to multiple reports border line width selection will be more intuitive with some predefined values. Here is an implementation of this proposal: line width can be selected from combobox from predefined values (thin, medium, thick and custom). Classical spinner is right now hidden unless custom line width is selected. Change-Id: I87a6237335b79a5f5b63e109360e1ea8f12ae071 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114709 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- cui/source/inc/border.hxx | 6 ++++- cui/source/tabpages/border.cxx | 48 ++++++++++++++++++++++++++++++---- cui/uiconfig/ui/borderpage.ui | 44 +++++++++++++++++++++++++------ 3 files changed, 84 insertions(+), 14 deletions(-) diff --git a/cui/source/inc/border.hxx b/cui/source/inc/border.hxx index d863650ee52f..2a3d14ed5062 100644 --- a/cui/source/inc/border.hxx +++ b/cui/source/inc/border.hxx @@ -77,6 +77,7 @@ private: class SvxBorderTabPage : public SfxTabPage { static const WhichRangesContainer pRanges; + static const std::vector m_aLineWidths; public: SvxBorderTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs); @@ -128,6 +129,7 @@ private: std::unique_ptr m_xLbLineStyle; std::unique_ptr m_xLbLineColor; + std::unique_ptr m_xLineWidthLB; std::unique_ptr m_xLineWidthMF; std::unique_ptr m_xSpacingFrame; @@ -165,7 +167,8 @@ private: DECL_LINK(SelSdwHdl_Impl, ValueSet*, void); DECL_LINK(LinesChanged_Impl, LinkParamNone*, void); DECL_LINK(ModifyDistanceHdl_Impl, weld::MetricSpinButton&, void); - DECL_LINK(ModifyWidthHdl_Impl, weld::MetricSpinButton&, void); + DECL_LINK(ModifyWidthLBHdl_Impl, weld::ComboBox&, void); + DECL_LINK(ModifyWidthMFHdl_Impl, weld::MetricSpinButton&, void); DECL_LINK(SyncHdl_Impl, weld::Toggleable&, void); DECL_LINK(RemoveAdjacentCellBorderHdl_Impl, weld::Toggleable&, void); @@ -175,6 +178,7 @@ private: void FillPresetVS(); void FillShadowVS(); void FillValueSets(); + void SetLineWidth(sal_Int64 nWidth); // Filler void FillLineListBox_Impl(); diff --git a/cui/source/tabpages/border.cxx b/cui/source/tabpages/border.cxx index c0adea646e35..70ec64c1a3bc 100644 --- a/cui/source/tabpages/border.cxx +++ b/cui/source/tabpages/border.cxx @@ -77,6 +77,8 @@ const WhichRangesContainer SvxBorderTabPage::pRanges( SID_SW_COLLAPSING_BORDERS, SID_SW_COLLAPSING_BORDERS, SID_ATTR_BORDER_DIAG_TLBR, SID_ATTR_BORDER_DIAG_BLTR>); +const std::vector SvxBorderTabPage::m_aLineWidths = { 75, 200, 400, -1 }; + static void lcl_SetDecimalDigitsTo1(weld::MetricSpinButton& rField) { auto nMin = rField.denormalize(rField.get_min(FieldUnit::TWIP)); @@ -292,6 +294,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle , m_xLbLineStyle(new SvtLineListBox(m_xBuilder->weld_menu_button("linestylelb"))) , m_xLbLineColor(new ColorListBox(m_xBuilder->weld_menu_button("linecolorlb"), [this]{ return GetDialogController()->getDialog(); })) + , m_xLineWidthLB(m_xBuilder->weld_combo_box("linewidthlb")) , m_xLineWidthMF(m_xBuilder->weld_metric_spin_button("linewidthmf", FieldUnit::POINT)) , m_xSpacingFrame(m_xBuilder->weld_container("spacing")) , m_xLeftFT(m_xBuilder->weld_label("leftft")) @@ -416,7 +419,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle { // The caller specifies default line width. Honor it. const SfxInt64Item* p = static_cast(pItem); - m_xLineWidthMF->set_value(p->GetValue(), FieldUnit::POINT); + SetLineWidth(p->GetValue()); } // set metric @@ -516,13 +519,17 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle m_aFrameSel.SetSelectHdl(LINK(this, SvxBorderTabPage, LinesChanged_Impl)); m_xLbLineStyle->SetSelectHdl( LINK( this, SvxBorderTabPage, SelStyleHdl_Impl ) ); m_xLbLineColor->SetSelectHdl( LINK( this, SvxBorderTabPage, SelColHdl_Impl ) ); - m_xLineWidthMF->connect_value_changed( LINK( this, SvxBorderTabPage, ModifyWidthHdl_Impl ) ); + m_xLineWidthLB->connect_changed(LINK(this, SvxBorderTabPage, ModifyWidthLBHdl_Impl)); + m_xLineWidthMF->connect_value_changed(LINK(this, SvxBorderTabPage, ModifyWidthMFHdl_Impl)); m_xWndPresets->SetSelectHdl( LINK( this, SvxBorderTabPage, SelPreHdl_Impl ) ); m_xWndShadows->SetSelectHdl( LINK( this, SvxBorderTabPage, SelSdwHdl_Impl ) ); FillValueSets(); FillLineListBox_Impl(); + // Reapply line width: probably one of prefefined values should be selected + SetLineWidth(m_xLineWidthMF->get_value(FieldUnit::NONE)); + // connections if (rCoreAttrs.HasItem(GetWhich(SID_ATTR_PARA_GRABBAG), &pItem)) { @@ -779,7 +786,7 @@ void SvxBorderTabPage::Reset( const SfxItemSet* rSet ) sal_Int64 nWidthPt = static_cast(vcl::ConvertDoubleValue( sal_Int64( nWidth ), m_xLineWidthMF->get_digits(), MapUnit::MapTwip, FieldUnit::POINT )); - m_xLineWidthMF->set_value(nWidthPt, FieldUnit::POINT); + SetLineWidth(nWidthPt); m_xLbLineStyle->SetWidth(nWidth); // then set the style @@ -1217,7 +1224,17 @@ IMPL_LINK(SvxBorderTabPage, SelColHdl_Impl, ColorListBox&, rColorBox, void) m_aFrameSel.SetColorToSelection(aColor); } -IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthHdl_Impl, weld::MetricSpinButton&, void) +IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthLBHdl_Impl, weld::ComboBox&, void) +{ + sal_Int32 nPos = m_xLineWidthLB->get_active(); + + SetLineWidth(m_aLineWidths[nPos]); + + // Call the spinner handler to trigger all related modifications + ModifyWidthMFHdl_Impl(*m_xLineWidthMF); +} + +IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthMFHdl_Impl, weld::MetricSpinButton&, void) { sal_Int64 nVal = m_xLineWidthMF->get_value(FieldUnit::NONE); nVal = static_cast(vcl::ConvertDoubleValue( @@ -1254,7 +1271,7 @@ IMPL_LINK_NOARG(SvxBorderTabPage, SelStyleHdl_Impl, SvtLineListBox&, void) m_xLineWidthMF->get_digits(), MapUnit::MapTwip, FieldUnit::POINT)); - m_xLineWidthMF->set_value(nNewWidthPt, FieldUnit::POINT); + SetLineWidth(nNewWidthPt); } // set value inside style box @@ -1381,6 +1398,27 @@ void SvxBorderTabPage::FillValueSets() FillShadowVS(); } +void SvxBorderTabPage::SetLineWidth( sal_Int64 nWidth ) +{ + if ( nWidth >= 0 ) + m_xLineWidthMF->set_value( nWidth, FieldUnit::POINT ); + + auto it = std::find_if( m_aLineWidths.begin(), m_aLineWidths.end(), + [nWidth](const int val) -> bool { return val == nWidth; } ); + + if ( it != m_aLineWidths.end() && *it >= 0 ) + { + // Select predefined value in combobox + m_xLineWidthMF->hide(); + m_xLineWidthLB->set_active(std::distance(m_aLineWidths.begin(), it)); + } + else + { + // This is not one of predefined values. Show spinner + m_xLineWidthLB->set_active(m_aLineWidths.size()-1); + m_xLineWidthMF->show(); + } +} static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ ) { diff --git a/cui/uiconfig/ui/borderpage.ui b/cui/uiconfig/ui/borderpage.ui index bcdd0d39030a..2847f0b736cb 100644 --- a/cui/uiconfig/ui/borderpage.ui +++ b/cui/uiconfig/ui/borderpage.ui @@ -251,15 +251,43 @@ - + True - True - start - True - adjustment1 - 2 - True - 0.05 + False + 0 + 6 + 0 + 0 + + + True + False + + Thin + Medium + Thick + Custom + + + + 0 + + + + + True + True + start + True + adjustment1 + 2 + True + 0.05 + + + 1 + + 1