cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / svx / source / styles / ColorSets.cxx
blob92b4973cbccac94dc4d6073fc2f72eb473fa7791
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <svx/ColorSets.hxx>
13 #include <optional>
14 #include <unordered_set>
15 #include <docmodel/theme/ColorSet.hxx>
17 using namespace com::sun::star;
19 namespace svx
22 ColorSets::ColorSets()
24 init();
27 ColorSets& ColorSets::get()
29 static std::optional<ColorSets> sColorSet;
30 if (!sColorSet)
31 sColorSet = ColorSets();
32 return *sColorSet;
36 void ColorSets::init()
39 model::ColorSet aColorSet(u"LibreOffice"_ustr);
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);
51 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
52 maColorSets.push_back(aColorSet);
55 model::ColorSet aColorSet(u"Rainbow"_ustr);
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);
67 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
68 maColorSets.push_back(aColorSet);
71 model::ColorSet aColorSet(u"Beach"_ustr);
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);
83 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0xEE77D7);
84 maColorSets.push_back(aColorSet);
87 model::ColorSet aColorSet(u"Sunset"_ustr);
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);
99 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
100 maColorSets.push_back(aColorSet);
103 model::ColorSet aColorSet(u"Ocean"_ustr);
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);
115 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x551A8B);
116 maColorSets.push_back(aColorSet);
119 model::ColorSet aColorSet(u"Forest"_ustr);
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);
131 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x800080);
132 maColorSets.push_back(aColorSet);
135 model::ColorSet aColorSet(u"Breeze"_ustr);
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);
147 aColorSet.add(model::ThemeColorType::FollowedHyperlink, 0x3DAEE9);
148 maColorSets.push_back(aColorSet);
152 model::ColorSet const* ColorSets::getColorSet(std::u16string_view rName) const
154 for (const model::ColorSet & rColorSet : maColorSets)
156 if (rColorSet.getName() == rName)
157 return &rColorSet;
159 return nullptr;
161 namespace
164 OUString findUniqueName(std::unordered_set<OUString> const& rNames, OUString const& rNewName)
166 auto iterator = rNames.find(rNewName);
167 if (iterator == rNames.cend())
168 return rNewName;
170 int i = 1;
171 OUString aName;
174 aName = rNewName + "_" + OUString::number(i);
175 i++;
176 iterator = rNames.find(aName);
177 } while (iterator != rNames.cend());
179 return aName;
182 } // end anonymous namespace
184 void ColorSets::insert(model::ColorSet const& rNewColorSet, IdenticalNameAction eAction)
186 if (eAction == IdenticalNameAction::Overwrite)
188 for (model::ColorSet& rColorSet : maColorSets)
190 if (rColorSet.getName() == rNewColorSet.getName())
192 rColorSet = rNewColorSet;
193 return;
196 // color set not found, so insert it
197 maColorSets.push_back(rNewColorSet);
199 else if (eAction == IdenticalNameAction::AutoRename)
201 std::unordered_set<OUString> aNames;
202 for (model::ColorSet& rColorSet : maColorSets)
203 aNames.insert(rColorSet.getName());
205 OUString aName = findUniqueName(aNames, rNewColorSet.getName());
207 model::ColorSet aNewColorSet = rNewColorSet;
208 aNewColorSet.setName(aName);
209 maColorSets.push_back(aNewColorSet);
213 } // end of namespace svx
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */