LibreOffice Module svx (master) 1
ThemeDialog.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
14#include <svx/ColorSets.hxx>
15#include <vcl/svapp.hxx>
16#include <svx/colorbox.hxx>
17#include <comphelper/lok.hxx>
18
19namespace svx
20{
22 : GenericDialogController(pParent, "svx/ui/themedialog.ui", "ThemeDialog")
23 , mpWindow(pParent)
24 , mpTheme(pTheme)
25 , mxValueSetThemeColors(new svx::ThemeColorValueSet)
26 , mxValueSetThemeColorsWindow(
27 new weld::CustomWeld(*m_xBuilder, "valueset_theme_colors", *mxValueSetThemeColors))
28 , mxAdd(m_xBuilder->weld_button("button_add"))
29{
30 mxValueSetThemeColors->SetColCount(3);
31 mxValueSetThemeColors->SetLineCount(4);
32 mxValueSetThemeColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
33 mxValueSetThemeColors->SetDoubleClickHdl(LINK(this, ThemeDialog, DoubleClickValueSetHdl));
34 mxValueSetThemeColors->SetSelectHdl(LINK(this, ThemeDialog, SelectItem));
35
36 mxAdd->connect_clicked(LINK(this, ThemeDialog, ButtonClicked));
37
39
40 if (!maColorSets.empty())
41 {
42 mxValueSetThemeColors->SelectItem(1); // ItemId 1, position 0
43 mpCurrentColorSet = std::make_shared<model::ColorSet>(maColorSets[0]);
44 }
45}
46
48
50{
51 if (mpTheme)
52 maColorSets.push_back(*mpTheme->getColorSet());
53
54 auto const& rColorSetVector = ColorSets::get().getColorSetVector();
55 maColorSets.insert(maColorSets.end(), rColorSetVector.begin(), rColorSetVector.end());
56
57 for (auto const& rColorSet : maColorSets)
58 {
59 mxValueSetThemeColors->insert(rColorSet);
60 }
61
62 mxValueSetThemeColors->SetOptimalSize();
63}
64
65IMPL_LINK_NOARG(ThemeDialog, DoubleClickValueSetHdl, ValueSet*, void)
66{
67 SelectItem(nullptr);
69 m_xDialog->response(RET_OK);
70}
71
73{
74 sal_uInt32 nItemId = mxValueSetThemeColors->GetSelectedItemId();
75 if (!nItemId)
76 return;
77
78 sal_uInt32 nIndex = nItemId - 1;
79
80 if (nIndex >= maColorSets.size())
81 return;
82
83 mpCurrentColorSet = std::make_shared<model::ColorSet>(maColorSets[nIndex]);
84}
85
87{
88 auto pDialog = std::make_shared<svx::ThemeColorEditDialog>(mpWindow, *mpCurrentColorSet);
89 std::shared_ptr<DialogController> xKeepAlive(shared_from_this());
90 weld::DialogController::runAsync(pDialog, [this, xKeepAlive, pDialog](sal_uInt32 nResult) {
91 if (nResult != RET_OK)
92 {
93 mxAdd->set_sensitive(true);
94 return;
95 }
96 auto aColorSet = pDialog->getColorSet();
97 if (!aColorSet.getName().isEmpty())
98 {
99 ColorSets::get().insert(aColorSet, ColorSets::IdenticalNameAction::AutoRename);
100 maColorSets.clear();
101 mxValueSetThemeColors->Clear();
102
103 initColorSets();
104
105 mxValueSetThemeColors->SelectItem(maColorSets.size() - 1);
106 mpCurrentColorSet
107 = std::make_shared<model::ColorSet>(maColorSets[maColorSets.size() - 1]);
108 }
109 mxAdd->set_sensitive(true);
110 });
111}
112
113IMPL_LINK(ThemeDialog, ButtonClicked, weld::Button&, rButton, void)
114{
115 if (mpCurrentColorSet && mxAdd.get() == &rButton)
116 {
117 runThemeColorEditDialog();
118 mxAdd->set_sensitive(false);
119 }
120}
121
122} // end svx namespace
123
124/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static const AllSettings & GetSettings()
std::shared_ptr< model::ColorSet > const & getColorSet() const
static ColorSets & get()
Definition: ColorSets.cxx:27
const std::vector< model::ColorSet > & getColorSetVector() const
Definition: ColorSets.hxx:33
std::unique_ptr< svx::ThemeColorValueSet > mxValueSetThemeColors
Definition: ThemeDialog.hxx:35
virtual ~ThemeDialog() override
std::shared_ptr< model::ColorSet > mpCurrentColorSet
Definition: ThemeDialog.hxx:39
std::vector< model::ColorSet > maColorSets
Definition: ThemeDialog.hxx:33
void runThemeColorEditDialog()
Definition: ThemeDialog.cxx:86
weld::Window * mpWindow
Definition: ThemeDialog.hxx:31
ThemeDialog(weld::Window *pParent, model::Theme *pTheme)
Definition: ThemeDialog.cxx:21
model::Theme * mpTheme
Definition: ThemeDialog.hxx:32
std::unique_ptr< weld::Button > mxAdd
Definition: ThemeDialog.hxx:37
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
sal_Int32 nIndex
IMPL_LINK(HangulHanjaConversionDialog, ClickByCharacterHdl, weld::Toggleable &, rBox, void)
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, ValueSet *, void)
RET_OK
VclPtr< vcl::Window > mpWindow