LibreOffice Module svx (master) 1
ColorSets.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 */
10
11#include <svx/ColorSets.hxx>
12
13#include <utility>
14#include <unordered_set>
16
17using namespace com::sun::star;
18
19namespace svx
20{
21
23{
24 init();
25}
26
28{
29 static std::optional<ColorSets> sColorSet;
30 if (!sColorSet)
31 sColorSet = ColorSets();
32 return *sColorSet;
33}
34
35
37{
38 {
39 model::ColorSet aColorSet("LibreOffice");
40 aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
41 aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
42 aColorSet.add(model::ThemeColorType::Dark2, 0x000000);
43 aColorSet.add(model::ThemeColorType::Light2, 0xFFFFFF);
44 aColorSet.add(model::ThemeColorType::Accent1, 0x18A303);
45 aColorSet.add(model::ThemeColorType::Accent2, 0x0369A3);
46 aColorSet.add(model::ThemeColorType::Accent3, 0xA33E03);
47 aColorSet.add(model::ThemeColorType::Accent4, 0x8E03A3);
48 aColorSet.add(model::ThemeColorType::Accent5, 0xC99C00);
49 aColorSet.add(model::ThemeColorType::Accent6, 0xC9211E);
50 aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
52 maColorSets.push_back(aColorSet);
53 }
54 {
55 model::ColorSet aColorSet("Rainbow");
56 aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
57 aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
58 aColorSet.add(model::ThemeColorType::Dark2, 0x1C1C1C);
59 aColorSet.add(model::ThemeColorType::Light2, 0xDDDDDD);
60 aColorSet.add(model::ThemeColorType::Accent1, 0xFF0000);
61 aColorSet.add(model::ThemeColorType::Accent2, 0xFF8000);
62 aColorSet.add(model::ThemeColorType::Accent3, 0xFFFF00);
63 aColorSet.add(model::ThemeColorType::Accent4, 0x00A933);
64 aColorSet.add(model::ThemeColorType::Accent5, 0x2A6099);
65 aColorSet.add(model::ThemeColorType::Accent6, 0x800080);
66 aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
68 maColorSets.push_back(aColorSet);
69 }
70 {
71 model::ColorSet aColorSet("Beach");
72 aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
73 aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
74 aColorSet.add(model::ThemeColorType::Dark2, 0xFFBF00);
75 aColorSet.add(model::ThemeColorType::Light2, 0x333333);
76 aColorSet.add(model::ThemeColorType::Accent1, 0xFFF5CE);
77 aColorSet.add(model::ThemeColorType::Accent2, 0xDEE6EF);
78 aColorSet.add(model::ThemeColorType::Accent3, 0xE8F2A1);
79 aColorSet.add(model::ThemeColorType::Accent4, 0xFFD7D7);
80 aColorSet.add(model::ThemeColorType::Accent5, 0xDEE7E5);
81 aColorSet.add(model::ThemeColorType::Accent6, 0xDDDBB6);
82 aColorSet.add(model::ThemeColorType::Hyperlink, 0x7777EE);
84 maColorSets.push_back(aColorSet);
85 }
86 {
87 model::ColorSet aColorSet("Sunset");
88 aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
89 aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
90 aColorSet.add(model::ThemeColorType::Dark2, 0x492300);
91 aColorSet.add(model::ThemeColorType::Light2, 0xF6F9D4);
92 aColorSet.add(model::ThemeColorType::Accent1, 0xFFFF00);
93 aColorSet.add(model::ThemeColorType::Accent2, 0xFFBF00);
94 aColorSet.add(model::ThemeColorType::Accent3, 0xFF8000);
95 aColorSet.add(model::ThemeColorType::Accent4, 0xFF4000);
96 aColorSet.add(model::ThemeColorType::Accent5, 0xBF0041);
97 aColorSet.add(model::ThemeColorType::Accent6, 0x800080);
98 aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
100 maColorSets.push_back(aColorSet);
101 }
102 {
103 model::ColorSet aColorSet("Ocean");
104 aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
105 aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
106 aColorSet.add(model::ThemeColorType::Dark2, 0x2A6099);
107 aColorSet.add(model::ThemeColorType::Light2, 0xCCCCCC);
108 aColorSet.add(model::ThemeColorType::Accent1, 0x800080);
109 aColorSet.add(model::ThemeColorType::Accent2, 0x55308D);
110 aColorSet.add(model::ThemeColorType::Accent3, 0x2A6099);
111 aColorSet.add(model::ThemeColorType::Accent4, 0x158466);
112 aColorSet.add(model::ThemeColorType::Accent5, 0x00A933);
113 aColorSet.add(model::ThemeColorType::Accent6, 0x81D41A);
114 aColorSet.add(model::ThemeColorType::Hyperlink, 0x0000EE);
116 maColorSets.push_back(aColorSet);
117 }
118 {
119 model::ColorSet aColorSet("Forest");
120 aColorSet.add(model::ThemeColorType::Dark1, 0x000000);
121 aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF);
122 aColorSet.add(model::ThemeColorType::Dark2, 0x000000);
123 aColorSet.add(model::ThemeColorType::Light2, 0xFFFFFF);
124 aColorSet.add(model::ThemeColorType::Accent1, 0x813709);
125 aColorSet.add(model::ThemeColorType::Accent2, 0x224B12);
126 aColorSet.add(model::ThemeColorType::Accent3, 0x706E0C);
127 aColorSet.add(model::ThemeColorType::Accent4, 0x355269);
128 aColorSet.add(model::ThemeColorType::Accent5, 0xBE480A);
129 aColorSet.add(model::ThemeColorType::Accent6, 0xBE480A);
130 aColorSet.add(model::ThemeColorType::Hyperlink, 0x2A6099);
132 maColorSets.push_back(aColorSet);
133 }
134 {
135 model::ColorSet aColorSet("Breeze");
136 aColorSet.add(model::ThemeColorType::Dark1, 0x232629);
137 aColorSet.add(model::ThemeColorType::Light1, 0xFCFCFC);
138 aColorSet.add(model::ThemeColorType::Dark2, 0x31363B);
139 aColorSet.add(model::ThemeColorType::Light2, 0xEFF0F1);
140 aColorSet.add(model::ThemeColorType::Accent1, 0xDA4453);
141 aColorSet.add(model::ThemeColorType::Accent2, 0xF47750);
142 aColorSet.add(model::ThemeColorType::Accent3, 0xFDBC4B);
143 aColorSet.add(model::ThemeColorType::Accent4, 0xC9CE3B);
144 aColorSet.add(model::ThemeColorType::Accent5, 0x1CDC9A);
145 aColorSet.add(model::ThemeColorType::Accent6, 0x2ECC71);
146 aColorSet.add(model::ThemeColorType::Hyperlink, 0x1D99F3);
148 maColorSets.push_back(aColorSet);
149 }
150}
151
152model::ColorSet const* ColorSets::getColorSet(std::u16string_view rName) const
153{
154 for (const model::ColorSet & rColorSet : maColorSets)
155 {
156 if (rColorSet.getName() == rName)
157 return &rColorSet;
158 }
159 return nullptr;
160}
161namespace
162{
163
164OUString findUniqueName(std::unordered_set<OUString> const& rNames, OUString const& rNewName)
165{
166 auto iterator = rNames.find(rNewName);
167 if (iterator == rNames.cend())
168 return rNewName;
169
170 int i = 1;
171 OUString aName;
172 do
173 {
174 aName = rNewName + "_" + OUString::number(i);
175 i++;
176 iterator = rNames.find(aName);
177 } while (iterator != rNames.cend());
178
179 return aName;
180}
181
182} // end anonymous namespace
183
184void ColorSets::insert(model::ColorSet const& rNewColorSet, IdenticalNameAction eAction)
185{
186 if (eAction == IdenticalNameAction::Overwrite)
187 {
188 for (model::ColorSet& rColorSet : maColorSets)
189 {
190 if (rColorSet.getName() == rNewColorSet.getName())
191 {
192 rColorSet = rNewColorSet;
193 return;
194 }
195 }
196 // color set not found, so insert it
197 maColorSets.push_back(rNewColorSet);
198 }
199 else if (eAction == IdenticalNameAction::AutoRename)
200 {
201 std::unordered_set<OUString> aNames;
202 for (model::ColorSet& rColorSet : maColorSets)
203 aNames.insert(rColorSet.getName());
204
205 OUString aName = findUniqueName(aNames, rNewColorSet.getName());
206
207 model::ColorSet aNewColorSet = rNewColorSet;
208 aNewColorSet.setName(aName);
209 maColorSets.push_back(aNewColorSet);
210 }
211}
212
213} // end of namespace svx
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setName(OUString const &rName)
void add(model::ThemeColorType Type, Color aColorData)
const OUString & getName() const
static ColorSets & get()
Definition: ColorSets.cxx:27
std::vector< model::ColorSet > maColorSets
Definition: ColorSets.hxx:26
const model::ColorSet & getColorSet(sal_uInt32 nIndex) const
Definition: ColorSets.hxx:38
void insert(model::ColorSet const &rColorSet, IdenticalNameAction eAction=IdenticalNameAction::Overwrite)
Definition: ColorSets.cxx:184
OUString aName
int i