summaryrefslogtreecommitdiffstats
path: root/lib/widgets/propeditor/childproperty.cpp
blob: 12b7f4d959ae07f2a0c5fd6829c07397507b1d33 (plain)
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
/***************************************************************************
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 *   cloudtemple@mskat.net                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#include "childproperty.h"

#include <qsize.h>
#include <qpoint.h>
#include <qrect.h>
#include <qsizepolicy.h>

#include "multiproperty.h"

namespace PropertyLib{

ChildProperty::ChildProperty(MultiProperty *parent, int type, ChildPropertyType childType, const QString &name,
    const QString &description, const QVariant &value, bool save, bool readOnly)
    :Property(type, name, description, value, save, readOnly), m_parent(parent), m_childType(childType)
{
}

ChildProperty::ChildProperty(MultiProperty *parent, const QString & name, ChildPropertyType childType,
    const QMap<QString, QVariant> &v_valueList, const QString &description,
    const QVariant &value, bool save, bool readOnly)
    :Property(name, v_valueList, description, value, save, readOnly), m_parent(parent), m_childType(childType)
{
}

void ChildProperty::setValue(const QVariant &value, bool // rememberOldValue
                             )
{
    qWarning("ChildProperty::setValue");
    if (!m_parent->valid())
        return;
    switch (m_parent->type())
    {
        case Size:
        {
            qWarning("ChildProperty::setValue for QSize");
            QSize v = m_parent->value().toSize();
            if (m_childType == Size_Height)
                v.setHeight(value.toInt());
            else if (m_childType == Size_Width)
                v.setWidth(value.toInt());
            m_parent->setValue(v);
            break;
        }
        case Point:
        {
            qWarning("ChildProperty::setValue for QPoint");
            QPoint v = m_parent->value().toPoint();
            if (m_childType == Point_X)
                v.setX(value.toInt());
            else if (m_childType == Point_Y)
                v.setY(value.toInt());
            m_parent->setValue(v);
            break;
        }
        case Rect:
        {
            qWarning("ChildProperty::setValue for QRect");
            QRect v = m_parent->value().toRect();
            if (m_childType == Rect_X)
                v.setX(value.toInt());
            else if (m_childType == Rect_Y)
                v.setY(value.toInt());
            else if (m_childType == Rect_Width)
                v.setWidth(value.toInt());
            else if (m_childType == Rect_Height)
                v.setHeight(value.toInt());
            m_parent->setValue(v);
            break;
        }
        case SizePolicy:
        {
            qWarning("ChildProperty::setValue for QSizePolicy");
            QSizePolicy v = m_parent->value().toSizePolicy();
            if (m_childType == SizePolicy_HorData)
                v.setHorData(QSizePolicy::SizeType(value.toInt()));
            else if (m_childType == SizePolicy_VerData)
                v.setVerData(QSizePolicy::SizeType(value.toInt()));
            else if (m_childType == SizePolicy_HorStretch)
                v.setHorStretch(value.toInt());
            else if (m_childType == SizePolicy_VerStretch)
                v.setVerStretch(value.toInt());
            m_parent->setValue(v);
            break;
        }
    }
}

QVariant ChildProperty::value( ) const
{
    if (!m_parent->valid())
        return QVariant();
    switch (m_parent->type())
    {
        case Size:
            if (m_childType == Size_Height)
                return m_parent->value().toSize().height();
            else if (m_childType == Size_Width)
                return m_parent->value().toSize().width();
        case Point:
            if (m_childType == Point_X)
                return m_parent->value().toPoint().x();
            else if (m_childType == Point_Y)
                return m_parent->value().toPoint().y();
        case Rect:
            if (m_childType == Rect_X)
                return m_parent->value().toRect().x();
            else if (m_childType == Rect_Y)
                return m_parent->value().toRect().y();
            else if (m_childType == Rect_Width)
                return m_parent->value().toRect().width();
            else if (m_childType == Rect_Height)
                return m_parent->value().toRect().height();
        case SizePolicy:
            if (m_childType == SizePolicy_HorData)
                return m_parent->value().toSizePolicy().horData();
            else if (m_childType == SizePolicy_VerData)
                return m_parent->value().toSizePolicy().verData();
            else if (m_childType == SizePolicy_HorStretch)
                return m_parent->value().toSizePolicy().horStretch();
            else if (m_childType == SizePolicy_VerStretch)
                return m_parent->value().toSizePolicy().verStretch();
    }
    return QVariant();
}

}