diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-01-05 23:58:50 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-01-18 12:58:43 +0000 |
commit | 424855cc772d9759e1846f2460390eb91f4e7370 (patch) | |
tree | 02e9a43c28904d789bb75676c0290e0cf9675dc4 /svx | |
parent | e89a7f3ebf86c6724e7f2fca4d994bf640c15a6c (diff) |
sw: rework ThemePanel, theme color ValueSet drawing as custom draw
Rework the ThemePanel to only work with theme colors, as fonts
are uing an old mock implemntation of themes. To do this properly
it is needed to remove the implementation for now.
The theme colors entries were rendered as a bitmap and then shown
in the ValueSet. This has the problem that it doesn't look sharp
on a HiDPI screen, so replace that with a ThemeColorValueSet, which
uses custom draw to render the theme color entries directly.
The ThemeColorValueSet was added to th svx component as it will be
used in other components as well.
Change-Id: I1a727ef4cf4be4e215db57ac33f571f43aaddc15
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145087
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 8bc22ed6899bcbafc3020f0af6c939019506a5fd)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145693
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/Library_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/dialog/ThemeColorValueSet.cxx | 98 |
2 files changed, 99 insertions, 0 deletions
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index 3a54b129ebb9..79bc39776e75 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -157,6 +157,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/dialog/svxruler \ svx/source/dialog/swframeexample \ svx/source/dialog/swframeposstrings \ + svx/source/dialog/ThemeColorValueSet \ svx/source/dialog/txencbox \ svx/source/dialog/txenctab \ svx/source/dialog/weldeditview \ diff --git a/svx/source/dialog/ThemeColorValueSet.cxx b/svx/source/dialog/ThemeColorValueSet.cxx new file mode 100644 index 000000000000..02297a9eb51e --- /dev/null +++ b/svx/source/dialog/ThemeColorValueSet.cxx @@ -0,0 +1,98 @@ +/* -*- 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 <svx/dialog/ThemeColorValueSet.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> +#include <vcl/event.hxx> + +namespace svx +{ +constexpr tools::Long BORDER = 3; +constexpr tools::Long SIZE = 14; +constexpr tools::Long LABEL_HEIGHT = 16; +constexpr tools::Long LABEL_TEXT_HEIGHT = 14; +constexpr tools::Long constElementNumber = 8; + +void ThemeColorValueSet::insert(svx::ColorSet const& rColorSet) +{ + maColorSets.push_back(std::cref(rColorSet)); + InsertItem(maColorSets.size()); +} + +void ThemeColorValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea) +{ + ValueSet::SetDrawingArea(pDrawingArea); + SetStyle(WB_TABSTOP | WB_ITEMBORDER | WB_DOUBLEBORDER); + Size aSize(BORDER * 7 + SIZE * 6 + BORDER * 2, BORDER * 3 + SIZE * 2 + LABEL_HEIGHT); + SetItemWidth(aSize.Width()); + SetItemHeight(aSize.Height()); +} + +void ThemeColorValueSet::UserDraw(const UserDrawEvent& rUserDrawEvent) +{ + vcl::RenderContext* pDev = rUserDrawEvent.GetRenderContext(); + tools::Rectangle aRect = rUserDrawEvent.GetRect(); + const Point aPosition = aRect.TopLeft(); + const sal_uInt16 nItemId = rUserDrawEvent.GetItemId(); + svx::ColorSet const& rColorSet = maColorSets[nItemId - 1]; + + Size aSize = aRect.GetSize(); + Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2, + BORDER * 3 + SIZE * 2 + LABEL_HEIGHT); + tools::Long startX = (aSize.Width() / 2.0) - (aMin.Width() / 2.0); + tools::Long x = BORDER; + tools::Long y1 = BORDER + LABEL_HEIGHT; + tools::Long y2 = y1 + SIZE + BORDER; + + pDev->SetLineColor(COL_LIGHTGRAY); + pDev->SetFillColor(COL_LIGHTGRAY); + tools::Rectangle aNameRect(aPosition, Size(aSize.Width(), LABEL_HEIGHT)); + pDev->DrawRect(aNameRect); + + vcl::Font aFont; + OUString aName = rColorSet.getName(); + aFont.SetFontHeight(LABEL_TEXT_HEIGHT); + pDev->SetFont(aFont); + + Size aTextSize(pDev->GetTextWidth(aName), pDev->GetTextHeight()); + + Point aPoint(aPosition.X() + (aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0), + aPosition.Y() + (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0)); + + pDev->DrawText(aPoint, aName); + + pDev->SetLineColor(COL_LIGHTGRAY); + pDev->SetFillColor(); + + for (sal_uInt32 i = 2; i < 10; i += 2) + { + pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i))); + pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, aPosition.Y() + y1), + Size(SIZE, SIZE))); + + pDev->SetFillColor(rColorSet.getColor(model::convertToThemeColorType(i + 1))); + pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, aPosition.Y() + y2), + Size(SIZE, SIZE))); + + x += SIZE + BORDER; + if (i == 2 || i == 8) + x += BORDER; + } +} + +void ThemeColorValueSet::StyleUpdated() +{ + SetFormat(); + Invalidate(); + ValueSet::StyleUpdated(); +} + +} // end svx namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |