Doc: Enabling Qt QML linking to Qt Quick.
[profile/ivi/qtdeclarative.git] / tools / qmleasing / segmentproperties.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "segmentproperties.h"
43 #include "splineeditor.h"
44
45 SegmentProperties::SegmentProperties(QWidget *parent) :
46     QWidget(parent), m_splineEditor(0), m_blockSignals(false)
47 {
48     QVBoxLayout *layout = new QVBoxLayout(this);
49     layout->setMargin(0);
50     layout->setSpacing(2);
51     setLayout(layout);
52     {
53         QWidget *widget = new QWidget(this);
54         m_ui_pane_c1.setupUi(widget);
55         m_ui_pane_c1.label->setText("c1");
56         m_ui_pane_c1.smooth->setVisible(false);
57         layout->addWidget(widget);
58
59         connect(m_ui_pane_c1.p1_x, SIGNAL(valueChanged(double)), this, SLOT(c1Updated()));
60         connect(m_ui_pane_c1.p1_y, SIGNAL(valueChanged(double)), this, SLOT(c1Updated()));
61     }
62     {
63         QWidget *widget = new QWidget(this);
64         m_ui_pane_c2.setupUi(widget);
65         m_ui_pane_c2.label->setText("c2");
66         m_ui_pane_c2.smooth->setVisible(false);
67         layout->addWidget(widget);
68
69         connect(m_ui_pane_c2.p1_x, SIGNAL(valueChanged(double)), this, SLOT(c2Updated()));
70         connect(m_ui_pane_c2.p1_y, SIGNAL(valueChanged(double)), this, SLOT(c2Updated()));
71     }
72     {
73         QWidget *widget = new QWidget(this);
74         m_ui_pane_p.setupUi(widget);
75         m_ui_pane_p.label->setText("p1");
76         layout->addWidget(widget);
77
78         connect(m_ui_pane_p.smooth, SIGNAL(toggled(bool)), this, SLOT(pUpdated()));
79         connect(m_ui_pane_p.p1_x, SIGNAL(valueChanged(double)), this, SLOT(pUpdated()));
80         connect(m_ui_pane_p.p1_y, SIGNAL(valueChanged(double)), this, SLOT(pUpdated()));
81     }
82 }
83
84 void SegmentProperties::c1Updated()
85 {
86     if (m_splineEditor && !m_blockSignals) {
87         QPointF c1(m_ui_pane_c1.p1_x->value(), m_ui_pane_c1.p1_y->value());
88         m_splineEditor->setControlPoint(m_segment * 3, c1);
89     }
90 }
91
92 void SegmentProperties::c2Updated()
93 {
94     if (m_splineEditor && !m_blockSignals) {
95         QPointF c2(m_ui_pane_c2.p1_x->value(), m_ui_pane_c2.p1_y->value());
96         m_splineEditor->setControlPoint(m_segment * 3 + 1, c2);
97     }
98 }
99
100 void SegmentProperties::pUpdated()
101 {
102     if (m_splineEditor && !m_blockSignals) {
103         QPointF p(m_ui_pane_p.p1_x->value(), m_ui_pane_p.p1_y->value());
104         bool smooth = m_ui_pane_p.smooth->isChecked();
105         m_splineEditor->setControlPoint(m_segment * 3 + 2, p);
106         m_splineEditor->setSmooth(m_segment, smooth);
107     }
108 }
109
110 void SegmentProperties::invalidate()
111 {
112     m_blockSignals = true;
113
114      m_ui_pane_p.label->setText(QLatin1String("p") + QString::number(m_segment));
115      m_ui_pane_p.smooth->setChecked(m_smooth);
116      m_ui_pane_p.smooth->parentWidget()->setEnabled(!m_last);
117
118      m_ui_pane_c1.p1_x->setValue(m_points.at(0).x());
119      m_ui_pane_c1.p1_y->setValue(m_points.at(0).y());
120
121      m_ui_pane_c2.p1_x->setValue(m_points.at(1).x());
122      m_ui_pane_c2.p1_y->setValue(m_points.at(1).y());
123
124      m_ui_pane_p.p1_x->setValue(m_points.at(2).x());
125      m_ui_pane_p.p1_y->setValue(m_points.at(2).y());
126
127      m_blockSignals = false;
128 }