summaryrefslogtreecommitdiffstats
path: root/lib/widgets/propeditor/propertymachinefactory.cpp
blob: 389fc38f512b92839115d71519c361f0978d90b7 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/***************************************************************************
 *   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 "propertymachinefactory.h"

#ifndef PURE_QT
#include <tdelocale.h>
#else
#define i18n TQObject::tr
#endif

#include <tqmap.h>

#include "property.h"
#include "childproperty.h"
#include "multiproperty.h"
#include "plineedit.h"
#include "pspinbox.h"
#include "pdoublenuminput.h"
#include "pcheckbox.h"
#include "pstringlistedit.h"
#include "pdummywidget.h"
#include "pcombobox.h"
#include "psymbolcombo.h"
#include "pfontcombo.h"
#include "psizeedit.h"
#include "pdateedit.h"
#include "pdatetimeedit.h"
#include "ppointedit.h"
#include "prectedit.h"
#include "psizepolicyedit.h"
#include "pcolorbutton.h"
#include "pyesnobutton.h"
#include "ppixmapedit.h"
#include "pcursoredit.h"
#include "plinestyleedit.h"
#include "purledit.h"


#ifndef PURE_QT
#include "pfontbutton.h"
#include "pcolorcombo.h"
#endif

namespace PropertyLib{

PropertyMachineFactory *PropertyMachineFactory::m_factory = 0;

PropertyMachineFactory::PropertyMachineFactory()
{
}

PropertyMachineFactory::~PropertyMachineFactory()
{
}

Machine *PropertyMachineFactory::machineForProperty(MultiProperty *property)
{
    int type = property->type();
    TQString propertyName = property->name();
    TQMap<TQString, TQVariant> valueList = property->valueList();

    if (m_registeredForType.contains(propertyName))
        return (*m_registeredForType[propertyName])();

    switch (type)
    {
        case Property::String:
            return new Machine(new PLineEdit(property));
        case Property::Integer:
            return new Machine(new PSpinBox(property));
        case Property::Boolean:
            return new Machine(new PYesNoButton(property));
        case Property::Date:
            return new Machine(new PDateEdit(property));
        case Property::DateTime:
            return new Machine(new PDateTimeEdit(property));
        case Property::StringList:
            return new Machine(new PStringListEdit(property));
        case Property::Color:
            return new Machine(new PColorButton(property));
#ifndef PURE_QT
        case Property::Font:
            return new Machine(new PFontButton(property));
#endif
        case Property::FileURL:
            return new Machine(new PUrlEdit(PUrlEdit::File, property));
        case Property::DirectoryURL:
            return new Machine(new PUrlEdit(PUrlEdit::Directory, property));

        case Property::Double:
            return new Machine(new PDoubleNumInput(property));
        case Property::Pixmap:
            return new Machine(new PPixmapEdit(property));

        case Property::ValueFromList:
            return new Machine(new PComboBox(property, valueList));
        case Property::Symbol:
            return new Machine(new PSymbolCombo(property));
        case Property::FontName:
            return new Machine(new PFontCombo(property));
        case Property::LineStyle:
            return new Machine(new PLineStyleEdit(property));

        case Property::Size:
        {
            Machine *mach = new Machine(new PSizeEdit(property));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Size_Width, i18n("Width"), i18n("Width")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Size_Height, i18n("Height"), i18n("Height")));
            return mach;
        }
        case Property::Point:
        {
            Machine *mach = new Machine(new PPointEdit(property));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Point_X, i18n("x"), i18n("x")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Point_Y, i18n("y"), i18n("y")));
            return mach;
        }
        case Property::Rect:
        {
            Machine *mach = new Machine(new PRectEdit(property));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Rect_X, i18n("x"), i18n("x")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Rect_Y, i18n("y"), i18n("y")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Rect_Width, i18n("Width"), i18n("Width")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::Rect_Height, i18n("Height"), i18n("Height")));
            return mach;
        }
        case Property::SizePolicy:
        {
            TQMap<TQString, TQVariant> spValues;
            spValues[i18n("Fixed")] = TQSizePolicy::Fixed;
            spValues[i18n("Minimum")] = TQSizePolicy::Minimum;
            spValues[i18n("Maximum")] = TQSizePolicy::Maximum;
            spValues[i18n("Preferred")] = TQSizePolicy::Preferred;
            spValues[i18n("Expanding")] = TQSizePolicy::Expanding;
            spValues[i18n("Minimum Expanding")] = TQSizePolicy::MinimumExpanding;
            spValues[i18n("Ignored")] = TQSizePolicy::Ignored;

            Machine *mach = new Machine(new PSizePolicyEdit(property, spValues));
            property->details.append(ChildProperty(property, i18n("hSizeType"), ChildProperty::SizePolicy_HorData, spValues, i18n("Horizontal Size Type")));
            property->details.append(ChildProperty(property, i18n("vSizeType"), ChildProperty::SizePolicy_VerData, spValues, i18n("Vertical Size Type")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::SizePolicy_HorStretch, i18n("hStretch"), i18n("Horizontal Stretch")));
            property->details.append(ChildProperty(property, Property::Integer, ChildProperty::SizePolicy_VerStretch, i18n("vStretch"), i18n("Vertical Stretch")));
            return mach;
        }
        case Property::Cursor:
        {
            TQMap<TQString, TQVariant> spValues;
            spValues[i18n("Arrow")] = TQt::ArrowCursor;
            spValues[i18n("Up Arrow")] = TQt::UpArrowCursor;
            spValues[i18n("Cross")] = TQt::CrossCursor;
            spValues[i18n("Waiting")] = TQt::WaitCursor;
            spValues[i18n("iBeam")] = TQt::IbeamCursor;
            spValues[i18n("Size Vertical")] = TQt::SizeVerCursor;
            spValues[i18n("Size Horizontal")] = TQt::SizeHorCursor;
            spValues[i18n("Size Slash")] = TQt::SizeBDiagCursor;
            spValues[i18n("Size Backslash")] = TQt::SizeFDiagCursor;
            spValues[i18n("Size All")] = TQt::SizeAllCursor;
            spValues[i18n("Blank")] = TQt::BlankCursor;
            spValues[i18n("Split Vertical")] = TQt::SplitVCursor;
            spValues[i18n("Split Horizontal")] = TQt::SplitHCursor;
            spValues[i18n("Pointing Hand")] = TQt::PointingHandCursor;
            spValues[i18n("Forbidden")] = TQt::ForbiddenCursor;
            spValues[i18n("What's this")] = TQt::WhatsThisCursor;
            Machine *mach = new Machine(new PCursorEdit(property, spValues));
            return mach;
        }

        case Property::List:
        case Property::Map:
        default:
            return new Machine(new PDummyWidget(property));
    }
}

PropertyMachineFactory *PropertyMachineFactory::getInstance()
{
    if (m_factory == 0)
        m_factory = new PropertyMachineFactory();
    return m_factory;
}

bool PropertyMachineFactory::hasDetailedEditors( int type )
{
    if ( (type==Property::Size) || (type==Property::Point) ||
        (type==Property::Rect) || (type==Property::SizePolicy) )
        return true;
    return 0;
}

}