include/vcl/toolkit/svlbitm.hxx | 5 +-- include/vcl/weld/TreeView.hxx | 4 +- sd/source/ui/animations/CustomAnimationPane.cxx | 2 - vcl/inc/qt5/QtInstanceTreeView.hxx | 4 +- vcl/inc/qt5/QtTools.hxx | 2 + vcl/inc/salvtables.hxx | 6 +-- vcl/qt5/QtInstanceTreeView.cxx | 14 ++++++-- vcl/qt5/QtTools.cxx | 16 ++++++++++ vcl/source/app/salvtables.cxx | 12 +++---- vcl/source/treelist/svlbitm.cxx | 38 +++++++++++++----------- vcl/unx/gtk3/gtkinst.cxx | 24 ++++++++++++--- 11 files changed, 87 insertions(+), 40 deletions(-)
New commits: commit ac90a84214a7f822baa7413b89df9f630a005e20 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 18 00:55:59 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Dec 18 09:32:16 2025 +0100 tdf#130857 qt weld: Implement QtInstanceTreeView::set_text_align Change-Id: Ibe184c9ae590a63511b61569035f98e4c6a7fa39 Author: Michael Weghorn <[email protected]> Date: Thu Dec 18 00:44:14 2025 +0100 tdf#130857 weld: Restrict TreeView text alignment to left/center/right describes how to trigger the currently only case where weld::TreeView::set_text_align is used. At the moment, using native widgets for that one isn't supported yet, so this implementation isn't tested in practice yet. Change-Id: Icc84ab6fc9690325166dd5bb272b716da4fc0470 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195820 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/qt5/QtTools.hxx b/vcl/inc/qt5/QtTools.hxx index 72ea64904d8d..edf9f3428c65 100644 --- a/vcl/inc/qt5/QtTools.hxx +++ b/vcl/inc/qt5/QtTools.hxx @@ -96,6 +96,8 @@ inline QDate toQDate(const Date& rDate) inline Date toDate(const QDate& rDate) { return Date(rDate.day(), rDate.month(), rDate.year()); } +Qt::Alignment toQtAlignment(TxtAlign eAlign); + Qt::CheckState toQtCheckState(TriState eTristate); TriState toVclTriState(Qt::CheckState eTristate); diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 7ff58c5d706a..8feaeee2d7e7 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -600,9 +600,15 @@ bool QtInstanceTreeView::get_text_emphasis(const weld::TreeIter&, int) const return false; } -void QtInstanceTreeView::set_text_align(const weld::TreeIter&, TxtAlign, int) +void QtInstanceTreeView::set_text_align(const weld::TreeIter& rIter, TxtAlign eAlign, int nCol) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + QStandardItem* pItem = itemFromIndex(modelIndex(rIter, nCol)); + if (pItem) + pItem->setTextAlignment(toQtAlignment(eAlign)); + }); } void QtInstanceTreeView::set_toggle(const weld::TreeIter& rIter, TriState eState, int nCol) diff --git a/vcl/qt5/QtTools.cxx b/vcl/qt5/QtTools.cxx index 7c14e6289002..56978054c308 100644 --- a/vcl/qt5/QtTools.cxx +++ b/vcl/qt5/QtTools.cxx @@ -40,6 +40,22 @@ void CairoDeleter::operator()(cairo_surface_t* pSurface) const { cairo_surface_destroy(pSurface); } +Qt::Alignment toQtAlignment(TxtAlign eAlign) +{ + switch (eAlign) + { + case TxtAlign::Left: + return Qt::AlignLeft; + case TxtAlign::Center: + return Qt::AlignHCenter; + case TxtAlign::Right: + return Qt::AlignRight; + default: + assert(false && "unhandled TxtAlign value"); + return Qt::AlignLeft; + } +} + Qt::CheckState toQtCheckState(TriState eTristate) { switch (eTristate) commit 2084e033daa3ca0e6e87a7eacb976070c7db606d Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 18 00:44:14 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Dec 18 09:32:08 2025 +0100 tdf#130857 weld: Restrict TreeView text alignment to left/center/right So far, a floating point value was used, but for the vcl/SalInstanceTreeView implementation, this was already mapped to an alignment of only left/center/right. Qt also only supports these via QStandardItem::setTextAlignment [1]. Restrict the API to the same, and simply map that to 0, 0.5 and 1.0 again in the GtkInstanceTreeView implementation. So far, CustomAnimationPane is the only place where this API is used, and it uses a value of 0.5 (for centered text). No change in behavior intended or seen in a quick test of that pane with gtk3 or gen: * start Impress * select the title textbox * open the "Animation" sidebar panel * click the "Add" button Some texts in the treeview in the "Effects" section are bold and centered. [1] https://doc.qt.io/qt-6/qstandarditem.html#setTextAlignment Change-Id: Ibe184c9ae590a63511b61569035f98e4c6a7fa39 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195819 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/vcl/toolkit/svlbitm.hxx b/include/vcl/toolkit/svlbitm.hxx index 472a4bf38c16..1845a57d33cb 100644 --- a/include/vcl/toolkit/svlbitm.hxx +++ b/include/vcl/toolkit/svlbitm.hxx @@ -103,7 +103,8 @@ class UNLESS_MERGELIBS(VCL_DLLPUBLIC) SvLBoxString : public SvLBoxItem private: bool mbEmphasized; bool mbCustom; - double mfAlign; + TxtAlign meAlign; + protected: OUString maText; @@ -119,7 +120,7 @@ public: virtual int CalcWidth(const SvTreeListBox* pView) const override; - void Align(double fAlign) { mfAlign = fAlign; } + void Align(TxtAlign eAlign) { meAlign = eAlign; } void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; } bool IsEmphasized() const { return mbEmphasized; } diff --git a/include/vcl/weld/TreeView.hxx b/include/vcl/weld/TreeView.hxx index e803c863b639..67d5b5bf0033 100644 --- a/include/vcl/weld/TreeView.hxx +++ b/include/vcl/weld/TreeView.hxx @@ -259,7 +259,7 @@ public: = 0; virtual void set_text_emphasis(int row, bool bOn, int col) = 0; virtual bool get_text_emphasis(int row, int col) const = 0; - virtual void set_text_align(int row, double fAlign, int col) = 0; + virtual void set_text_align(int row, TxtAlign eAlign, int col) = 0; virtual void swap(int pos1, int pos2) = 0; virtual std::vector<int> get_selected_rows() const = 0; virtual void set_font_color(int pos, const Color& rColor) = 0; @@ -384,7 +384,7 @@ public: virtual bool get_sensitive(const TreeIter& rIter, int col) const = 0; virtual void set_text_emphasis(const TreeIter& rIter, bool bOn, int col) = 0; virtual bool get_text_emphasis(const TreeIter& rIter, int col) const = 0; - virtual void set_text_align(const TreeIter& rIter, double fAlign, int col) = 0; + virtual void set_text_align(const TreeIter& rIter, TxtAlign eAlign, int col) = 0; // col index -1 sets the expander toggle, enable_toggle_buttons must have been called to create that column virtual void set_toggle(const TreeIter& rIter, TriState bOn, int col = -1) = 0; // col index -1 gets the expander toggle, enable_toggle_buttons must have been called to create that column diff --git a/sd/source/ui/animations/CustomAnimationPane.cxx b/sd/source/ui/animations/CustomAnimationPane.cxx index 5cb04499becd..fc7f13945e4c 100644 --- a/sd/source/ui/animations/CustomAnimationPane.cxx +++ b/sd/source/ui/animations/CustomAnimationPane.cxx @@ -2206,7 +2206,7 @@ namespace int nRow = rLBAnimation.n_children(); rLBAnimation.append_text(rMotionPathLabel); rLBAnimation.set_text_emphasis(nRow, true, 0); - rLBAnimation.set_text_align(nRow, 0.5, 0); + rLBAnimation.set_text_align(nRow, TxtAlign::Center, 0); } } diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx index f9ff62c3722b..cbc995b1ca8e 100644 --- a/vcl/inc/qt5/QtInstanceTreeView.hxx +++ b/vcl/inc/qt5/QtInstanceTreeView.hxx @@ -72,7 +72,7 @@ public: int nCol = -1) override; virtual void set_text_emphasis(int nRow, bool bOn, int nCol) override; virtual bool get_text_emphasis(int nRow, int nCol) const override; - virtual void set_text_align(int nRow, double fAlign, int nCol) override; + virtual void set_text_align(int nRow, TxtAlign eAlign, int nCol) override; virtual void swap(int nPos1, int nPos2) override; virtual std::vector<int> get_selected_rows() const override; virtual void set_font_color(int nPos, const Color& rColor) override; @@ -113,7 +113,7 @@ public: virtual bool get_sensitive(const weld::TreeIter& rIter, int nCol) const override; virtual void set_text_emphasis(const weld::TreeIter& rIter, bool bOn, int nCol) override; virtual bool get_text_emphasis(const weld::TreeIter& rIter, int nCol) const override; - virtual void set_text_align(const weld::TreeIter& rIter, double fAlign, int nCol) override; + virtual void set_text_align(const weld::TreeIter& rIter, TxtAlign eAlign, int nCol) override; virtual void set_toggle(const weld::TreeIter& rIter, TriState eState, int nCol = -1) override; virtual TriState get_toggle(const weld::TreeIter& rIter, int nCol = -1) const override; virtual OUString get_text(const weld::TreeIter& rIter, int nCol = -1) const override; diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index bbd948c6327a..d2c9a283bcdd 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -1696,11 +1696,11 @@ public: virtual bool get_text_emphasis(int pos, int col) const override; - void set_text_align(SvTreeListEntry* pEntry, double fAlign, int col); + void set_text_align(SvTreeListEntry* pEntry, TxtAlign eAlign, int col); - virtual void set_text_align(const weld::TreeIter& rIter, double fAlign, int col) override; + virtual void set_text_align(const weld::TreeIter& rIter, TxtAlign eAlign, int col) override; - virtual void set_text_align(int pos, double fAlign, int col) override; + virtual void set_text_align(int pos, TxtAlign eAlign, int col) override; virtual void connect_editing(const Link<const weld::TreeIter&, bool>& rStartLink, const Link<const iter_string&, bool>& rEndLink) override; diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 991605f48960..7ff58c5d706a 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -227,9 +227,9 @@ bool QtInstanceTreeView::get_text_emphasis(int nRow, int nCol) const return get_text_emphasis(treeIter(nRow), nCol); } -void QtInstanceTreeView::set_text_align(int nRow, double fAlign, int nCol) +void QtInstanceTreeView::set_text_align(int nRow, TxtAlign eAlign, int nCol) { - return set_text_align(treeIter(nRow), fAlign, nCol); + return set_text_align(treeIter(nRow), eAlign, nCol); } void QtInstanceTreeView::swap(int nPos1, int nPos2) @@ -600,7 +600,7 @@ bool QtInstanceTreeView::get_text_emphasis(const weld::TreeIter&, int) const return false; } -void QtInstanceTreeView::set_text_align(const weld::TreeIter&, double, int) +void QtInstanceTreeView::set_text_align(const weld::TreeIter&, TxtAlign, int) { assert(false && "Not implemented yet"); } diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index c5ac94e6912b..adc7cc528daa 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -4399,28 +4399,28 @@ bool SalInstanceTreeView::get_text_emphasis(int pos, int col) const return get_text_emphasis(pEntry, col); } -void SalInstanceTreeView::set_text_align(SvTreeListEntry* pEntry, double fAlign, int col) +void SalInstanceTreeView::set_text_align(SvTreeListEntry* pEntry, TxtAlign eAlign, int col) { col = to_internal_model(col); assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount()); SvLBoxItem& rItem = pEntry->GetItem(col); assert(dynamic_cast<SvLBoxString*>(&rItem)); - static_cast<SvLBoxString&>(rItem).Align(fAlign); + static_cast<SvLBoxString&>(rItem).Align(eAlign); InvalidateModelEntry(pEntry); } -void SalInstanceTreeView::set_text_align(const weld::TreeIter& rIter, double fAlign, int col) +void SalInstanceTreeView::set_text_align(const weld::TreeIter& rIter, TxtAlign eAlign, int col) { const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); - set_text_align(rVclIter.iter, fAlign, col); + set_text_align(rVclIter.iter, eAlign, col); } -void SalInstanceTreeView::set_text_align(int pos, double fAlign, int col) +void SalInstanceTreeView::set_text_align(int pos, TxtAlign eAlign, int col) { SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); - set_text_align(pEntry, fAlign, col); + set_text_align(pEntry, eAlign, col); } void SalInstanceTreeView::connect_editing(const Link<const weld::TreeIter&, bool>& rStartLink, diff --git a/vcl/source/treelist/svlbitm.cxx b/vcl/source/treelist/svlbitm.cxx index 0af34c8cedf2..f9c3b43e4cce 100644 --- a/vcl/source/treelist/svlbitm.cxx +++ b/vcl/source/treelist/svlbitm.cxx @@ -152,7 +152,7 @@ bool SvLBoxButtonData::IsRadio() const { SvLBoxString::SvLBoxString(OUString aStr) : mbEmphasized(false) , mbCustom(false) - , mfAlign(0.0) + , meAlign(TxtAlign::Left) , maText(std::move(aStr)) { } @@ -160,7 +160,7 @@ SvLBoxString::SvLBoxString(OUString aStr) SvLBoxString::SvLBoxString() : mbEmphasized(false) , mbCustom(false) - , mfAlign(0.0) + , meAlign(TxtAlign::Left) { } @@ -208,20 +208,26 @@ void SvLBoxString::Paint( } else { - if (mfAlign < 0.5 ) + switch (meAlign) { - nStyle |= DrawTextFlags::Left; - aSize.setWidth(GetWidth(&rDev, &rEntry)); - } - else if (mfAlign == 0.5) - { - nStyle |= DrawTextFlags::Center; - aSize.setWidth(rDev.GetBoundingRect(&rEntry).getOpenWidth()); - } - else if (mfAlign > 0.5) - { - nStyle |= DrawTextFlags::Right; - aSize.setWidth(rDev.GetBoundingRect(&rEntry).getOpenWidth()); + case TxtAlign::Left: + { + nStyle |= DrawTextFlags::Left; + aSize.setWidth(GetWidth(&rDev, &rEntry)); + break; + } + case TxtAlign::Center: + { + nStyle |= DrawTextFlags::Center; + aSize.setWidth(rDev.GetBoundingRect(&rEntry).getOpenWidth()); + break; + } + case TxtAlign::Right: + { + nStyle |= DrawTextFlags::Right; + aSize.setWidth(rDev.GetBoundingRect(&rEntry).getOpenWidth()); + break; + } } } aSize.setHeight(GetHeight(&rDev, &rEntry)); @@ -253,7 +259,7 @@ std::unique_ptr<SvLBoxItem> SvLBoxString::Clone(SvLBoxItem const * pSource) cons pNew->maText = pOther->maText; pNew->mbEmphasized = pOther->mbEmphasized; pNew->mbCustom = pOther->mbCustom; - pNew->mfAlign = pOther->mfAlign; + pNew->meAlign = pOther->meAlign; return std::unique_ptr<SvLBoxItem>(pNew.release()); } diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 9729e4aacba5..d010cfe46253 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -4472,6 +4472,22 @@ namespace return aColor; } + double toGtkTextAlignValue(TxtAlign eAlign) + { + switch (eAlign) + { + case TxtAlign::Left: + return 0; + case TxtAlign::Center: + return 0.5; + case TxtAlign::Right: + return 1; + default: + assert(false && "Unhandled value for text alignment"); + return 0; + } + } + Color toVclColor(const GdkRGBA& rColor) { return Color(rColor.red * 255, rColor.green * 255, rColor.blue * 255); @@ -15507,17 +15523,17 @@ public: return get_int(pos, iter->second) == PANGO_WEIGHT_BOLD; } - virtual void set_text_align(const weld::TreeIter& rIter, double fAlign, int col) override + virtual void set_text_align(const weld::TreeIter& rIter, TxtAlign eAlign, int col) override { const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); col = to_internal_model(col); - set(rGtkIter.iter, m_aAlignMap[col], fAlign); + set(rGtkIter.iter, m_aAlignMap[col], toGtkTextAlignValue(eAlign)); } - virtual void set_text_align(int pos, double fAlign, int col) override + virtual void set_text_align(int pos, TxtAlign eAlign, int col) override { col = to_internal_model(col); - set(pos, m_aAlignMap[col], fAlign); + set(pos, m_aAlignMap[col], toGtkTextAlignValue(eAlign)); } using GtkInstanceWidget::set_sensitive;
