-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBackgroundTool.cpp
More file actions
149 lines (121 loc) · 4.74 KB
/
Copy pathBackgroundTool.cpp
File metadata and controls
149 lines (121 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the toucan project.
#include "BackgroundTool.h"
#include "App.h"
#include <ftk/UI/Divider.h>
#include <ftk/UI/Label.h>
#include <ftk/UI/Spacer.h>
#include <ftk/Core/String.h>
namespace toucan
{
void BackgroundTool::_init(
const std::shared_ptr<ftk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<ftk::IWidget>& parent)
{
IToolWidget::_init(context, app, "toucan::BackgroundTool", "Background", parent);
_model = app->getGlobalViewModel();
_scrollWidget = ftk::ScrollWidget::create(context, ftk::ScrollType::Both, shared_from_this());
_scrollWidget->setBorder(false);
_layout = ftk::VerticalLayout::create(context);
_layout->setMarginRole(ftk::SizeRole::MarginSmall);
_layout->setSpacingRole(ftk::SizeRole::SpacingSmall);
_scrollWidget->setWidget(_layout);
_comboBox = ftk::ComboBox::create(context, getViewBackgroundLabels(), _layout);
ftk::Divider::create(context, ftk::Orientation::Vertical, _layout);
_solidColorWidget = ftk::ColorWidget::create(context, _layout);
_checkersColor0Widget = ftk::ColorWidget::create(context, _layout);
_checkersColor1Widget = ftk::ColorWidget::create(context, _layout);
_checkersSizeSlider = ftk::IntEditSlider::create(context, _layout);
_checkersSizeSlider->setRange(ftk::RangeI(10, 100));
_comboBox->setIndexCallback(
[this](int value)
{
if (_model)
{
auto options = _model->getOptions();
options.background = static_cast<ViewBackground>(value);
_model->setOptions(options);
}
});
_solidColorWidget->setCallback(
[this](const ftk::Color4F& value)
{
if (_model)
{
auto options = _model->getOptions();
options.solidColor = value;
_model->setOptions(options);
}
});
_checkersColor0Widget->setCallback(
[this](const ftk::Color4F& value)
{
if (_model)
{
auto options = _model->getOptions();
options.checkersColor0 = value;
_model->setOptions(options);
}
});
_checkersColor1Widget->setCallback(
[this](const ftk::Color4F& value)
{
if (_model)
{
auto options = _model->getOptions();
options.checkersColor1 = value;
_model->setOptions(options);
}
});
_checkersSizeSlider->setCallback(
[this](int value)
{
if (_model)
{
auto options = _model->getOptions();
options.checkersSize = value;
_model->setOptions(options);
}
});
_optionsObserver = ftk::Observer<GlobalViewOptions>::create(
_model->observeOptions(),
[this](const GlobalViewOptions& value)
{
_options = value;
_widgetUpdate();
});
}
BackgroundTool::~BackgroundTool()
{}
std::shared_ptr<BackgroundTool> BackgroundTool::create(
const std::shared_ptr<ftk::Context>& context,
const std::shared_ptr<App>& app,
const std::shared_ptr<ftk::IWidget>& parent)
{
auto out = std::shared_ptr<BackgroundTool>(new BackgroundTool);
out->_init(context, app, parent);
return out;
}
void BackgroundTool::setGeometry(const ftk::Box2I& value)
{
IToolWidget::setGeometry(value);
_scrollWidget->setGeometry(value);
}
Size2I BackgroundTool::getSizeHint() const
{
return _scrollWidget->getSizeHint();
}
void BackgroundTool::_widgetUpdate()
{
_comboBox->setCurrentIndex(static_cast<int>(_options.background));
_solidColorWidget->setVisible(ViewBackground::Solid == _options.background);
_solidColorWidget->setColor(_options.solidColor);
_checkersColor0Widget->setVisible(ViewBackground::Checkers == _options.background);
_checkersColor0Widget->setColor(_options.checkersColor0);
_checkersColor1Widget->setVisible(ViewBackground::Checkers == _options.background);
_checkersColor1Widget->setColor(_options.checkersColor1);
_checkersSizeSlider->setVisible(ViewBackground::Checkers == _options.background);
_checkersSizeSlider->setValue(_options.checkersSize);
}
}