Krita Source Code Documentation
Loading...
Searching...
No Matches
KisMultiSensorsSelector.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2011 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
8
10#include "ui_wdgmultisensorsselector.h"
13
14
16 lager::cursor<KisCurveOptionDataCommon> optionData;
17
18 Ui_WdgMultiSensorsSelector form;
21 QHBoxLayout* layout;
22};
23
24auto sensorsLens = lager::lenses::getset(
26 std::vector<const KisSensorData*> srcSensors = data.sensors();
27
29 sensors.reserve(srcSensors.size());
30
31 Q_FOREACH(const KisSensorData* srcSensor, srcSensors) {
32 sensors.emplace_back(srcSensor->id, srcSensor->isActive);
33 }
34 return sensors;
35 },
37 std::vector<KisSensorData*> parentSensors = data.sensors();
38
39 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(parentSensors.size() == sensors.size(), data);
40
41 auto parentIt = parentSensors.begin();
42 auto it = sensors.begin();
43 for (; parentIt != parentSensors.end(); ++parentIt, ++it) {
44
45 KIS_SAFE_ASSERT_RECOVER((*parentIt)->id == it->first) {
46 continue;
47 }
48 (*parentIt)->isActive = it->second;
49 }
50
51 return data;
52 });
53
54
55
57 : QWidget(parent)
58 , d(new Private)
59{
61 d->form.setupUi(this);
62
63 connect(d->form.sensorsList, SIGNAL(activated(QModelIndex)), SLOT(setCurrent(QModelIndex)));
64 connect(d->form.sensorsList, SIGNAL(clicked(QModelIndex)), SLOT(setCurrent(QModelIndex)));
65
66 d->layout = new QHBoxLayout(d->form.widgetConfiguration);
67
68 // allow the list viewport to be responsive to input release events
69 d->form.sensorsList->viewport()->installEventFilter(this);
70}
71
76
77void KisMultiSensorsSelector::setOptionDataCursor(lager::cursor<KisCurveOptionDataCommon> optionData)
78{
79 d->optionData = optionData;
80 d->model = new KisMultiSensorsModel(optionData.zoom(sensorsLens), this);
81 d->form.sensorsList->setModel(d->model);
82
83 // TODO: verify that at least one sensor is always active!
84}
85
87{
88 const QModelIndex index = d->model->sensorIndex(id);
89 KIS_SAFE_ASSERT_RECOVER_RETURN(index.isValid());
90
91 d->form.sensorsList->setCurrentIndex(index);
92
93 sensorActivated(index);
94 Q_EMIT highlightedSensorChanged(id);
95}
96
97void KisMultiSensorsSelector::setCurrent(const QModelIndex& index)
98{
99 setCurrent(d->model->getSensorId(index));
100}
101
103{
104 return d->model->getSensorId(d->form.sensorsList->currentIndex());
105}
106
107void KisMultiSensorsSelector::sensorActivated(const QModelIndex& index)
108{
109 delete d->currentConfigWidget;
110
111 KisDynamicSensorFactory *factory =
114
115 d->currentConfigWidget = factory->createConfigWidget(d->optionData, d->form.widgetConfiguration);
116 if (d->currentConfigWidget) {
117 d->layout->addWidget(d->currentConfigWidget);
118 }
119}
120
121bool KisMultiSensorsSelector::eventFilter(QObject *obj, QEvent *event)
122{
129 if (event->type() == (QEvent::MouseButtonRelease) || event->type() == QEvent::TabletRelease) {
130 QModelIndex index = d->form.sensorsList->currentIndex();
131 setCurrent(index);
132 event->accept();
133 }
134
135 return QObject::eventFilter(obj, event);
136}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisDynamicSensorFactoryRegistry * instance()
virtual QWidget * createConfigWidget(lager::cursor< KisCurveOptionDataCommon >, QWidget *)=0
QString getSensorId(const QModelIndex &index)
QModelIndex sensorIndex(const QString &id)
std::vector< SensorData > MultiSensorData
void sensorActivated(const QModelIndex &index)
void setCurrent(const QString &id)
bool eventFilter(QObject *obj, QEvent *event) override
void setOptionDataCursor(lager::cursor< KisCurveOptionDataCommon > optionData)
void highlightedSensorChanged(const QString &id)
T get(const QString &id) const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
std::vector< SensorData * > sensors(Data *data)
std::vector< const KisSensorData * > sensors() const
lager::cursor< KisCurveOptionDataCommon > optionData