1 /*
2 * Copyright (c) 2007,2010 Cyrille Berger <cberger@cberger.net>
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "kis_dynamic_sensor_time.h"
20
21 #include <kis_debug.h>
22
23 #include <QDomElement>
24 #include "ui_SensorTimeConfiguration.h"
25
26 #include <brushengine/kis_paint_information.h>
27
KisDynamicSensorTime()28 KisDynamicSensorTime::KisDynamicSensorTime()
29 : KisDynamicSensor(TIME)
30 , m_periodic(true)
31 {
32 setLength(3);
33 }
34
value(const KisPaintInformation & pi)35 qreal KisDynamicSensorTime::value(const KisPaintInformation& pi)
36 {
37 if (pi.isHoveringMode()) return 1.0;
38
39 const qreal currentTime =
40 m_periodic ?
41 std::fmod(pi.currentTime(), m_length) :
42 qMin(pi.currentTime(), qreal(m_length));
43
44 return currentTime / qreal(m_length);
45 }
46
reset()47 void KisDynamicSensorTime::reset()
48 {
49 }
50
setPeriodic(bool periodic)51 void KisDynamicSensorTime::setPeriodic(bool periodic)
52 {
53 m_periodic = periodic;
54 }
55
setLength(qreal length)56 void KisDynamicSensorTime::setLength(qreal length)
57 {
58 m_length = (int)(length * 1000); // convert to milliseconds
59 }
60
createConfigurationWidget(QWidget * parent,QWidget * ss)61 QWidget* KisDynamicSensorTime::createConfigurationWidget(QWidget* parent, QWidget* ss)
62 {
63 QWidget* wdg = new QWidget(parent);
64 Ui_SensorTimeConfiguration stc;
65 stc.setupUi(wdg);
66 stc.checkBoxRepeat->setChecked(m_periodic);
67 connect(stc.checkBoxRepeat, SIGNAL(toggled(bool)), SLOT(setPeriodic(bool)));
68 connect(stc.checkBoxRepeat, SIGNAL(toggled(bool)), ss, SIGNAL(parametersChanged()));
69
70 stc.spinBoxDuration->setRange(0.02, 10.0, 2);
71 stc.spinBoxDuration->setSuffix(i18n(" s"));
72
73 stc.spinBoxDuration->setValue(m_length / 1000);
74 connect(stc.spinBoxDuration, SIGNAL(valueChanged(qreal)), SLOT(setLength(qreal)));
75 connect(stc.spinBoxDuration, SIGNAL(valueChanged(qreal)), ss, SIGNAL(parametersChanged()));
76
77
78
79 return wdg;
80 }
81
toXML(QDomDocument & doc,QDomElement & e) const82 void KisDynamicSensorTime::toXML(QDomDocument& doc, QDomElement& e) const
83 {
84 KisDynamicSensor::toXML(doc, e);
85 e.setAttribute("periodic", m_periodic);
86 e.setAttribute("duration", m_length);
87 }
88
fromXML(const QDomElement & e)89 void KisDynamicSensorTime::fromXML(const QDomElement& e)
90 {
91 KisDynamicSensor::fromXML(e);
92 m_periodic = e.attribute("periodic", "0").toInt();
93 m_length = e.attribute("duration", "30").toInt();
94 }
95
96