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>
This commit is contained in:
Vasily Melenchuk
2021-09-27 17:15:00 +02:00
committed by Samuel Mehrbrodt
parent 6e200689eb
commit 089c7d05fd
3 changed files with 84 additions and 14 deletions
+5 -1
View File
@@ -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();
+43 -5
View File
@@ -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*/ )
{
+36 -8
View File
@@ -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>