summaryrefslogtreecommitdiffstats
path: root/lib/widgets/propeditor/propertyeditor.h
blob: 6bdd3e32b6664224d1347403c81d0812e390e0e4 (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
/***************************************************************************
 *   Copyright (C) 2002-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.             *
 ***************************************************************************/
#ifndef PROPERTYEDITOR_H
#define PROPERTYEDITOR_H

#ifndef PURE_QT
#include <klistview.h>
#else
#include <tqlistview.h>
#define KListView QListView
#define KListViewItem QListViewItem
#endif

#include "propertylist.h"

class TQPushButton;
class TQGridLayout;

namespace PropertyLib{

class PropertyItem;
class PropertyGroupItem;
class PropertyWidget;
class Property;
class MultiProperty;
struct Machine;

/** @file propertyeditor.h
@short Contains @ref PropertyLib::PropertyEditor class.
*/

/**
@short %Property editor.

Displays a list of properties in a table form. Also performs grouping and
creation of property widgets from the machine factory.
@see PropertyWidget
@see Machine
@see PropertyMachineFactory
*/
class PropertyEditor: public KListView{
   Q_OBJECT
public:
    /**Constructs the property editor.*/
    PropertyEditor(TQWidget *parent = 0, const char *name = 0);
    ~PropertyEditor();
    
    /**@return @ref Machine for given property.
    Uses cache to store created machines. 
    Cache will be cleared only with @ref clearMachineCache.*/
    Machine *machine(MultiProperty *property);
    
public slots:
    /**Shows properties from a list.*/
    void populateProperties(PropertyList *list);
    /**Clears property list, disconnects accessor from the editor and deletes it.*/
    void clearProperties();
    /**Deletes cached machines.*/
    void clearMachineCache();

signals:
    /**Emitted when something is changed in property editor.*/
    void changed();

protected slots:
    /**Updates property widget in the editor.*/
    void propertyValueChanged(Property* property);
    /**Updates property in the list when new value is selected in the editor.*/
    void propertyChanged(MultiProperty *property, const TQVariant &value);

    /**Shows property editor.*/
    void slotClicked(TQListViewItem* item);
    void updateEditorSize();
    
    /**Undoes the last change in property editor.*/
    void undo();
    
protected:
    void editItem(TQListViewItem*, int);
    void hideEditor();
    void showEditor(PropertyItem *item);
    void placeEditor(PropertyItem *item);
    PropertyWidget *prepareEditor(PropertyItem *item);

    void addGroup(const TQString &name);
    void addProperty(PropertyGroupItem *group, const TQString &name);
    void addProperty(const TQString &name);
    void addChildProperties(PropertyItem *parent);
    
private:
    PropertyList *m_list;
    PropertyList m_detailedList;

    //machines cache for property types, machines will be deleted
    TQMap<TQString, Machine* > m_registeredForType;

    PropertyItem *m_currentEditItem;
    PropertyWidget *m_currentEditWidget;
    TQWidget *m_currentEditArea;
    TQGridLayout *m_currentEditLayout;
    
    bool m_doubleClickForEdit;
    TQListViewItem* m_lastClickedItem;
    
    TQPushButton *m_undoButton;
    
friend class PropertyItem;
};

}

#endif