summaryrefslogtreecommitdiffstats
path: root/kexi/formeditor/objecttreeview.h
blob: e1b6932b2f14438b368ac0ad65de8b6e6bd223ef (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
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <[email protected]>

   This library 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 library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef OBJECTTREEVIEW_H
#define OBJECTTREEVIEW_H

#include <klistview.h>

namespace KFormDesigner {

class ObjectTreeItem;
class Form;

//! @short An item in ObjectTreeView associated with an ObjectTreeItem.
class KFORMEDITOR_EXPORT ObjectTreeViewItem : public TDEListViewItem
{
	public:
		ObjectTreeViewItem(ObjectTreeViewItem *parent, ObjectTreeItem *item);
		ObjectTreeViewItem(TDEListView *list, ObjectTreeItem *item=0);
		virtual ~ObjectTreeViewItem();

		//! \return the item name, ie the ObjectTreeItem name
		TQString name() const;

		//! \return the ObjectTreeItem associated to this item.
		ObjectTreeItem* objectTree() const { return m_item; }

		virtual void setOpen( bool o );

	protected:
		//! Reimplemented to draw custom contents (copied from Property Editor)
		virtual void paintCell(TQPainter *p, const TQColorGroup & cg, int column, int width, int align);

		//! Reimplemented to draw custom contents (copied from Property Editor)
		virtual void paintBranches(TQPainter *p, const TQColorGroup &cg, int w, int y, int h);

		//! Reimplemented to draw custom contents (copied from Property Editor)
		virtual void setup();

	private:
		ObjectTreeItem *m_item;

	friend class ObjectTreeView;
};

/*! @short A graphical view of Form's ObjectTree.
 This is a TDEListView which represents an item for each widget in the form. 
 The actually selected widget is written bold
 and selected. Clicking on a list item selects the corresponding widget in the Form.
 */
class KFORMEDITOR_EXPORT ObjectTreeView : public TDEListView
{
	Q_OBJECT
  

	public:
		ObjectTreeView(TQWidget *parent=0, const char *name=0, bool tabStop = false);
		virtual ~ObjectTreeView();

		virtual TQSize sizeHint() const;

		/*! Sets \a form as the current Form in the list. The list will automatically 
		 be filled with an item for each widget in the Form, and selection will be synced. 
		 Nothing happens if \a form is already the current Form.
		 */
		void setForm(Form *form);

		//! \return the pixmap name for a given class, to be shown next to the widget name.
		TQString iconNameForClass(const TQCString &classname);

	public slots:
		/*! Sets the widget \a w as selected item, so it will be written bold. 
		 It is added to current selection if \a add is true. */
		void setSelectedWidget(TQWidget *w, bool add=false);

		/*! Adds the ObjectTreeItem \a item in the list, with the appropriate parent. */
		void addItem(ObjectTreeItem *item);

		/*! Removess the ObjectTreeItem \a item from the list. */
		void removeItem(ObjectTreeItem *item);

		/*! Just renames the list item from \a oldname to \a newname. */
		void renameItem(const TQCString &oldname, const TQCString &newname);

	protected slots:
		/*! This slot is called when the user right-click a list item. 
		 The widget context menu is shown, as inisde the Form. */
		void displayContextMenu(TDEListView *list, TQListViewItem *item, const TQPoint &p);

		void slotColumnSizeChanged(int);

		/*! The selected list item has changed, so we emit a signal to update the Form. */
		void slotSelectionChanged();

		/*! Called before Form object is destroyed. */
		void slotBeforeFormDestroyed();

	protected:
		//! Internal function to fill the list.
		ObjectTreeViewItem* loadTree(ObjectTreeItem *item, ObjectTreeViewItem *parent);

		//! \return The item whose name is \a name.
		ObjectTreeViewItem* findItem(const TQString &name);

	private:
		Form *m_form;
		ObjectTreeViewItem *m_topItem;

	friend class TabStopDialog;
};

}

#endif