1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <svx/dialog/ThemeColorValueSet.hxx>
11 #include <docmodel/uno/UnoComplexColor.hxx>
12 #include <vcl/event.hxx>
16 constexpr tools::Long BORDER
= 4;
17 constexpr tools::Long SIZE
= 16;
18 constexpr tools::Long LABEL_HEIGHT
= 16;
19 constexpr tools::Long LABEL_TEXT_HEIGHT
= 14;
20 constexpr tools::Long constElementNumber
= 8;
22 void ThemeColorValueSet::insert(model::ColorSet
const& rColorSet
)
24 maColorSets
.push_back(std::cref(rColorSet
));
25 InsertItem(maColorSets
.size());
28 void ThemeColorValueSet::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
30 ValueSet::SetDrawingArea(pDrawingArea
);
31 SetStyle(WB_TABSTOP
| WB_ITEMBORDER
| WB_DOUBLEBORDER
);
32 Size
aSize(BORDER
* 7 + SIZE
* 6 + BORDER
* 2, BORDER
* 3 + SIZE
* 2 + LABEL_HEIGHT
);
33 SetItemWidth(aSize
.Width());
34 SetItemHeight(aSize
.Height());
37 void ThemeColorValueSet::UserDraw(const UserDrawEvent
& rUserDrawEvent
)
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];
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);
49 tools::Long x
= BORDER
;
50 tools::Long y1
= BORDER
+ LABEL_HEIGHT
;
51 tools::Long y2
= y1
+ SIZE
+ BORDER
;
53 pDev
->SetLineColor(COL_LIGHTGRAY
);
54 pDev
->SetFillColor(COL_LIGHTGRAY
);
55 tools::Rectangle
aNameRect(aPosition
, Size(aSize
.Width(), LABEL_HEIGHT
));
56 pDev
->DrawRect(aNameRect
);
59 OUString aName
= rColorSet
.getName();
60 aFont
.SetFontHeight(LABEL_TEXT_HEIGHT
);
63 Size
aTextSize(pDev
->GetTextWidth(aName
), pDev
->GetTextHeight());
65 Point
aPoint(aPosition
.X() + (aNameRect
.GetWidth() / 2.0) - (aTextSize
.Width() / 2.0),
66 aPosition
.Y() + (aNameRect
.GetHeight() / 2.0) - (aTextSize
.Height() / 2.0));
68 pDev
->DrawText(aPoint
, aName
);
70 pDev
->SetLineColor(COL_LIGHTGRAY
);
73 for (sal_uInt32 i
= 2; i
< 10; i
+= 2)
75 pDev
->SetFillColor(rColorSet
.getColor(model::convertToThemeColorType(i
)));
76 pDev
->DrawRect(tools::Rectangle(Point(aPosition
.X() + x
+ startX
, aPosition
.Y() + y1
),
79 pDev
->SetFillColor(rColorSet
.getColor(model::convertToThemeColorType(i
+ 1)));
80 pDev
->DrawRect(tools::Rectangle(Point(aPosition
.X() + x
+ startX
, aPosition
.Y() + y2
),
89 void ThemeColorValueSet::StyleUpdated()
93 ValueSet::StyleUpdated();
96 } // end svx namespace
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */