LibreOffice Module svx (master) 1
ThemeColorValueSet.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
12#include <vcl/event.hxx>
13
14namespace svx
15{
16constexpr tools::Long BORDER = 4;
17constexpr tools::Long SIZE = 16;
21
23{
24 maColorSets.push_back(std::cref(rColorSet));
25 InsertItem(maColorSets.size());
26}
27
29{
30 ValueSet::SetDrawingArea(pDrawingArea);
32 Size aSize(BORDER * 7 + SIZE * 6 + BORDER * 2, BORDER * 3 + SIZE * 2 + LABEL_HEIGHT);
33 SetItemWidth(aSize.Width());
34 SetItemHeight(aSize.Height());
35}
36
38{
39 vcl::RenderContext* pDev = rUserDrawEvent.GetRenderContext();
40 tools::Rectangle aRect = rUserDrawEvent.GetRect();
41 const Point aPosition = aRect.GetPos();
42 const sal_uInt16 nItemId = rUserDrawEvent.GetItemId();
43 model::ColorSet const& rColorSet = maColorSets[nItemId - 1];
44
45 Size aSize = aRect.GetSize();
46 Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2,
47 BORDER * 3 + SIZE * 2 + LABEL_HEIGHT);
48 tools::Long startX = (aSize.Width() / 2.0) - (aMin.Width() / 2.0);
51 tools::Long y2 = y1 + SIZE + BORDER;
52
55 tools::Rectangle aNameRect(aPosition, Size(aSize.Width(), LABEL_HEIGHT));
56 pDev->DrawRect(aNameRect);
57
58 vcl::Font aFont;
59 OUString aName = rColorSet.getName();
61 pDev->SetFont(aFont);
62
63 Size aTextSize(pDev->GetTextWidth(aName), pDev->GetTextHeight());
64
65 Point aPoint(aPosition.X() + (aNameRect.GetWidth() / 2.0) - (aTextSize.Width() / 2.0),
66 aPosition.Y() + (aNameRect.GetHeight() / 2.0) - (aTextSize.Height() / 2.0));
67
68 pDev->DrawText(aPoint, aName);
69
71 pDev->SetFillColor();
72
73 for (sal_uInt32 i = 2; i < 10; i += 2)
74 {
76 pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, aPosition.Y() + y1),
77 Size(SIZE, SIZE)));
78
80 pDev->DrawRect(tools::Rectangle(Point(aPosition.X() + x + startX, aPosition.Y() + y2),
81 Size(SIZE, SIZE)));
82
83 x += SIZE + BORDER;
84 if (i == 2 || i == 8)
85 x += BORDER;
86 }
87}
88
90{
91 SetFormat();
92 Invalidate();
94}
95
96} // end svx namespace
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
void SetFillColor()
tools::Long GetTextHeight() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
sal_uInt16 GetItemId() const
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
void SetFormat()
void SetStyle(WinBits nStyle)
virtual void StyleUpdated() override
void SetItemHeight(tools::Long nLineHeight)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void SetItemWidth(tools::Long nItemWidth)
Color getColor(model::ThemeColorType eType) const
const OUString & getName() const
void insert(model::ColorSet const &rColorSet)
void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
std::vector< std::reference_wrapper< const model::ColorSet > > maColorSets
void UserDraw(const UserDrawEvent &rUserDrawEvent) override
constexpr tools::Long GetWidth() const
constexpr Size GetSize() const
constexpr tools::Long GetHeight() const
constexpr Point GetPos() const
void SetFontHeight(tools::Long nHeight)
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
float x
OUString aName
int i
constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex)
constexpr tools::Long BORDER
constexpr tools::Long LABEL_TEXT_HEIGHT
constexpr tools::Long SIZE
constexpr tools::Long constElementNumber
constexpr tools::Long LABEL_HEIGHT
long Long
#define WB_ITEMBORDER
#define WB_DOUBLEBORDER
WinBits const WB_TABSTOP