diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2021-04-27 13:34:23 +0300 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-09-27 17:15:00 +0200 |
commit | 089c7d05fde13251eb8cd8daaf7627b6bb0072f9 (patch) | |
tree | 2ac7af0611be392a8c2e953656426ba2fbe2de47 | |
parent | 6e200689eb309cdbe1e4f08311a400835de19bfb (diff) |
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 <samuel.mehrbrodt@allotropia.de>
-rw-r--r-- | cui/source/inc/border.hxx | 6 | ||||
-rw-r--r-- | cui/source/tabpages/border.cxx | 48 | ||||
-rw-r--r-- | 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<int> m_aLineWidths; public: SvxBorderTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs); @@ -128,6 +129,7 @@ private: std::unique_ptr<SvtLineListBox> m_xLbLineStyle; std::unique_ptr<ColorListBox> m_xLbLineColor; + std::unique_ptr<weld::ComboBox> m_xLineWidthLB; std::unique_ptr<weld::MetricSpinButton> m_xLineWidthMF; std::unique_ptr<weld::Container> 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<int> 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<const SfxInt64Item*>(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<sal_Int64>(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<sal_Int64>(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 @@ </packing> </child> <child> - <object class="GtkSpinButton" id="linewidthmf"> + <object class="GtkGrid" id="gridlinewidth"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="halign">start</property> - <property name="activates_default">True</property> - <property name="adjustment">adjustment1</property> - <property name="digits">2</property> - <property name="truncate-multiline">True</property> - <property name="value">0.05</property> + <property name="can_focus">False</property> + <property name="row_spacing">0</property> + <property name="column_spacing">6</property> + <property name="margin-start">0</property> + <property name="margin-top">0</property> + <child> + <object class="GtkComboBoxText" id="linewidthlb"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <items> + <item translatable="yes" context="borderpage|linewidthlb">Thin</item> + <item translatable="yes" context="borderpage|linewidthlb">Medium</item> + <item translatable="yes" context="borderpage|linewidthlb">Thick</item> + <item translatable="yes" context="borderpage|linewidthlb">Custom</item> + </items> + </object> + <packing> + <property name="left_attach">0</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="linewidthmf"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="halign">start</property> + <property name="activates_default">True</property> + <property name="adjustment">adjustment1</property> + <property name="digits">2</property> + <property name="truncate-multiline">True</property> + <property name="value">0.05</property> + </object> + <packing> + <property name="left_attach">1</property> + </packing> + </child> </object> <packing> <property name="left_attach">1</property> |