Debian Codegraph @

src/Gui/SoFCColorBarNotifier.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2024 Werner Mayer <wmayer[at]users.sourceforge.net> *
5 * *
6 * This file is part of FreeCAD. *
7 * *
8 * FreeCAD is free software: you can redistribute it and/or modify it *
9 * under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation, either version 2.1 of the *
11 * License, or (at your option) any later version. *
12 * *
13 * FreeCAD is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with FreeCAD. If not, see *
20 * <https://www.gnu.org/licenses/>. *
21 * *
22 **************************************************************************/
23
24
25 #include "SoFCColorBarNotifier.h"
26 #include "SoFCColorBar.h"
27 #include "Window.h"
28
29 using namespace Gui;
30
31 SoFCColorBarNotifier& SoFCColorBarNotifier::instance()
32 {
33 static SoFCColorBarNotifier instance;
34 return instance;
35 }
36
37 SoFCColorBarNotifier::SoFCColorBarNotifier()
38 {
39 group = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
40 group->Attach(this);
41 }
42
43 void SoFCColorBarNotifier::attach(SoFCColorBarBase* bar)
44 {
45 if (bars.insert(bar).second) {
46 bar->ref();
47 group->Notify("CbLabelTextSize");
48 }
49 }
50
51 void SoFCColorBarNotifier::detach(SoFCColorBarBase* bar)
52 {
53 auto pos = bars.find(bar);
54 if (pos != bars.end()) {
55 bars.erase(pos);
56 bar->unref();
57 }
58 }
59
60 void SoFCColorBarNotifier::OnChange(ParameterGrp::SubjectType& caller, ParameterGrp::MessageType reason)
61 {
62 const ParameterGrp& grp = dynamic_cast<ParameterGrp&>(caller);
63 if (strcmp(reason, "CbLabelTextSize") == 0 || strcmp(reason, "CbLabelColor") == 0) {
64 SoLabelTextFormat format;
65 format.textSize = static_cast<int>(grp.GetInt("CbLabelTextSize", format.textSize));
66 format.textColor = static_cast<uint32_t>(grp.GetUnsigned("CbLabelColor", format.textColor));
67
68 for (auto bar : bars) {
69 bar->setFormat(format);
70 }
71 }
72 }