Instead of hard-coding a size based on the icon size
for the icon views in ChartColorPalettes, rather let
the toolkit allocate a proper size.
Tweak some properties in the .ui file to achieve
proper auto-sizing.
Maybe, hard-coding the size was done because before
commit 478b712ea1
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Thu Aug 7 09:45:15 2025 +0200
tdf#167658 vcl: Honor GtkIconView::columns + calc size
, the vcl implementation didn't take the column count
set in the .ui file into account when the original
code was was introduced in
commit a26c93a630
Date: Sun Aug 10 22:33:37 2025 +0200
chart color palettes: switch from drawingarea to IconView
.
In any case, it seems unnecessary now, and not hard-coding
the size e.g. results in all rows being visible at once
when using the gen vcl plugin for the following dialog,
instead of showing only part of them and using a scrollbar
despite there being plenty of space below the icon view.
Steps to trigger a dialog using this:
* start Writer
* "Insert" -> "Chart"
* double-click on a bar in the chart to open the
"Data Series" dialog.
* switch to the "Color Palette" tab
Now, all rows are shown at once for both, the gtk3
and the gen vcl plugins.
The code is also used in the chart palette popup
that can be triggered like this (and whose .ui
file is also tweaked in this commit a bit):
* start Writer
* "Insert" -> "Chart"
* click on a bar in the chart
* switch to the "Properties" sidebar deck
* in the "Colors" section, click on the arrow
of the button to open the popup
This commit also prepares for supporting the
dialog mentioned above with native Qt widgets
in an upcoming commit.
Change-Id: Ibf1cb597bc93f29033ab76432ca08af0b029cc0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204209
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
116 lines
3.4 KiB
C++
116 lines
3.4 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include <ChartColorPalettes.hxx>
|
|
#include <ChartColorPaletteHelper.hxx>
|
|
#include <vcl/event.hxx>
|
|
#include <vcl/virdev.hxx>
|
|
|
|
namespace chart
|
|
{
|
|
constexpr tools::Long BORDER = ChartColorPaletteLayout::ItemBorder;
|
|
constexpr tools::Long SIZE = ChartColorPaletteLayout::ItemSize;
|
|
|
|
ChartColorPalettes::ChartColorPalettes(weld::Builder& rBuilder, const OUString& id,
|
|
const OUString& winId)
|
|
: mxIconView(rBuilder.weld_icon_view(id))
|
|
, mxWindow(rBuilder.weld_scrolled_window(winId))
|
|
{
|
|
mxIconView->connect_mouse_move(LINK(this, ChartColorPalettes, OnMouseMove));
|
|
}
|
|
|
|
void ChartColorPalettes::SetSelectHdl(const Link<const weld::TreeIter&, bool>& rLink)
|
|
{
|
|
mxIconView->connect_item_activated(rLink);
|
|
}
|
|
|
|
sal_uInt16 ChartColorPalettes::GetSelectedItemId()
|
|
{
|
|
OUString sId = mxIconView->get_selected_id();
|
|
if (sId.isEmpty())
|
|
return 0;
|
|
return sId.toUInt32();
|
|
}
|
|
|
|
void ChartColorPalettes::SelectItem(sal_uInt16 nItemId) { mxIconView->select(nItemId - 1); }
|
|
|
|
void ChartColorPalettes::SetNoSelection() { mxIconView->unselect_all(); }
|
|
|
|
bool ChartColorPalettes::IsNoSelection() { return mxIconView->get_selected_id().isEmpty(); }
|
|
|
|
void ChartColorPalettes::GrabFocus() { mxIconView->grab_focus(); }
|
|
|
|
void ChartColorPalettes::insert(ChartColorPalette const& rColorSet)
|
|
{
|
|
maColorSets.push_back(rColorSet);
|
|
}
|
|
|
|
const ChartColorPalette* ChartColorPalettes::getPalette(const sal_uInt32 nItem) const
|
|
{
|
|
if (maColorSets.size() > nItem)
|
|
{
|
|
return &maColorSets[nItem];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void ChartColorPalettes::setMouseMoveHdl(const Link<const OUString&, bool>& rLink)
|
|
{
|
|
maMouseMoveHdl = rLink;
|
|
}
|
|
|
|
void ChartColorPalettes::Fill()
|
|
{
|
|
const Size aSize(BORDER * 6 + SIZE * ChartColorPaletteSize / 2, BORDER * 5 + SIZE * 2);
|
|
|
|
mxIconView->clear();
|
|
|
|
mxIconView->freeze();
|
|
|
|
ScopedVclPtrInstance<VirtualDevice> pVDev;
|
|
pVDev->SetOutputSizePixel(aSize);
|
|
|
|
tools::Rectangle aDrawArea(0, 0, aSize.getWidth(), aSize.getHeight());
|
|
for (size_t i = 0; i < maColorSets.size(); ++i)
|
|
{
|
|
const ChartColorPalette& rColorSet = maColorSets[i];
|
|
pVDev->Erase();
|
|
ChartColorPaletteHelper::renderColorPalette(*pVDev, aDrawArea, rColorSet, false);
|
|
OUString sId = OUString::number(i + 1);
|
|
OUString sName = "Palette " + OUString::number(i + 1);
|
|
|
|
Bitmap aBitmap(pVDev->GetBitmap(Point(0, 0), pVDev->GetOutputSizePixel()));
|
|
mxIconView->insert(-1, nullptr, &sId, &aBitmap, nullptr);
|
|
mxIconView->set_item_accessible_name(i, sName);
|
|
}
|
|
|
|
mxIconView->thaw();
|
|
}
|
|
|
|
IMPL_LINK(ChartColorPalettes, OnMouseMove, const MouseEvent&, rMouseEvent, bool)
|
|
{
|
|
OUString sHighlightedId;
|
|
if (!rMouseEvent.IsLeaveWindow())
|
|
{
|
|
if (std::unique_ptr<weld::TreeIter> pItem
|
|
= mxIconView->get_item_at_pos(rMouseEvent.GetPosPixel()))
|
|
{
|
|
sHighlightedId = mxIconView->get_id(*pItem);
|
|
}
|
|
}
|
|
|
|
if (maMouseMoveHdl.IsSet())
|
|
return maMouseMoveHdl.Call(sHighlightedId);
|
|
return false;
|
|
}
|
|
|
|
} // end namespace chart
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|