formeditor/utils.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2007 Jaroslaw Staniek <js@iidea.pl>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqcursor.h>
22#include <tqobjectlist.h>
23#include <tqtabwidget.h>
24#include <tqtabbar.h>
25
26#include <kdebug.h>
27#include <kexiutils/utils.h>
28
29#include "form.h"
30#include "objecttree.h"
31#include "utils.h"
32
33using namespace KFormDesigner;
34
35void
37{
38 for(WidgetListIterator it(list); it.current() != 0; ++it) {
39 TQWidget *w = it.current();
40
41 // If any widget in the list is a child of this widget, we remove it from the list
42 for(WidgetListIterator it2(list); it2.current() != 0; ++it2) {
43 TQWidget *widg = it2.current();
44 if((w != widg) && (w->child(widg->name())))
45 {
46 kdDebug() << "Removing the widget " << widg->name() << "which is a child of " << w->name() << endl;
47 list.remove(widg);
48 }
49 }
50 }
51}
52
53void
54KFormDesigner::installRecursiveEventFilter(TQObject *object, TQObject *container)
55{
56 if(!object || !container|| !object->isWidgetType())
57 return;
58
59 kdDebug() << "Installing event filter on widget: " << object->name() << " directed to " << container->name() << endl;
60 object->installEventFilter(container);
61 if(((TQWidget*)object)->ownCursor())
62 ((TQWidget*)object)->setCursor(TQCursor(TQt::ArrowCursor));
63
64 TQObjectList list = object->childrenListObject();
65
66 if(list.isEmpty())
67 return;
68
69 for(TQObject *obj = list.first(); obj; obj = list.next())
71}
72
73void
74KFormDesigner::removeRecursiveEventFilter(TQObject *object, TQObject *container)
75{
76 object->removeEventFilter(container);
77 if(!object->isWidgetType())
78 return;
79 TQObjectList list = object->childrenListObject();
80 if(list.isEmpty())
81 return;
82
83 for(TQObject *obj = list.first(); obj; obj = list.next())
85}
86
87void
88KFormDesigner::setRecursiveCursor(TQWidget *w, Form *form)
89{
90 ObjectTreeItem *tree = form->objectTree()->lookup(w->name());
91 if(tree && ((tree->modifiedProperties()->contains("cursor")) || !tree->children()->isEmpty())
92 && !w->inherits("TQLineEdit") && !w->inherits("TQTextEdit")
93 ) //fix weird behaviour
94 return; // if the user has set a cursor for this widget or this is a container, don't change it
95
96 if(w->ownCursor())
97 w->setCursor(TQt::ArrowCursor);
98
99 TQObjectList *l = w->queryList( "TQWidget" );
100 for(TQObject *o = l->first(); o; o = l->next())
101 ((TQWidget*)o)->setCursor(TQt::ArrowCursor);
102 delete l;
103}
104
105TQSize
107{
108 int tmpw = 0, tmph = 0;
109 TQObjectList *list = w->queryList(inheritClass, 0, false, false);
110 for(TQObject *o = list->first(); o; o = list->next()) {
111 TQRect r = ((TQWidget*)o)->geometry();
112 tmpw = TQMAX(tmpw, r.right());
113 tmph = TQMAX(tmph, r.bottom());
114 }
115
116 delete list;
117 return TQSize(tmpw, tmph) + TQSize(10, 10);
118}
119
120// -----------------
121
122HorWidgetList::HorWidgetList(TQWidget *topLevelWidget)
123 : WidgetList()
124 , m_topLevelWidget(topLevelWidget)
125{
126}
127
128HorWidgetList::~HorWidgetList()
129{
130}
131
132int HorWidgetList::compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2)
133{
134 TQWidget *w1 = static_cast<TQWidget*>(item1);
135 TQWidget *w2 = static_cast<TQWidget*>(item2);
136 return w1->mapTo(m_topLevelWidget, TQPoint(0,0)).x() - w2->mapTo(m_topLevelWidget, TQPoint(0,0)).x();
137}
138
139// -----------------
140
141VerWidgetList::VerWidgetList(TQWidget *topLevelWidget)
142 : WidgetList()
143 , m_topLevelWidget(topLevelWidget)
144{
145}
146
147VerWidgetList::~VerWidgetList()
148{
149}
150
151int VerWidgetList::compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2)
152{
153 TQWidget *w1 = static_cast<TQWidget*>(item1);
154 TQWidget *w2 = static_cast<TQWidget*>(item2);
155
156 int y1, y2;
157 TQObject *page1 = 0;
159 if (tw1) // special case
160 y1 = w1->mapTo(m_topLevelWidget, TQPoint(0,0)).y() + tw1->tabBarHeight() -2 -2;
161 else
162 y1 = w1->mapTo(m_topLevelWidget, TQPoint(0,0)).y();
163
164 TQObject *page2 = 0;
166 if (tw1 && tw2 && tw1 == tw2 && page1 != page2) {
167 // this sorts widgets by tabs there're put in
168 return tw1->indexOf(static_cast<TQWidget*>(page1)) - tw2->indexOf(static_cast<TQWidget*>(page2));
169 }
170
171 if (tw2) // special case
172 y2 = w2->mapTo(m_topLevelWidget, TQPoint(0,0)).y() + tw2->tabBarHeight() -2 -2;
173 else
174 y2 = w2->mapTo(m_topLevelWidget, TQPoint(0,0)).y();
175
176 kdDebug() << w1->name() << ": " << y1 << " "
177 << " | " << w2->name() << ": " << y2 << endl;
178
179
180 //kdDebug() << w1->name() << ": " << w1->mapTo(m_topLevelWidget, TQPoint(0,0)) << " " << w1->y()
181 //<< " | " << w2->name() << ":" /*<< w2->mapFrom(m_topLevelWidget, TQPoint(0,w2->y()))*/ << " " << w2->y() << endl;
182 return y1 - y2;
183}
184
185#include "utils.moc"
A simple class representing a form.
Definition form.h:136
ObjectTree * objectTree() const
Definition form.h:167
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59
ObjectTreeItem * lookup(const TQString &name)
A tab widget providing information about height of the tab bar.
TQPtrList< TQWidget > WidgetList
A list of widget pointers.
KFORMEDITOR_EXPORT TQSize getSizeFromChildren(TQWidget *widget, const char *inheritClass="TQWidget")
TQPtrListIterator< TQWidget > WidgetListIterator
An iterator for WidgetList.
KFORMEDITOR_EXPORT void removeChildrenFromList(WidgetList &list)
KFORMEDITOR_EXPORT void installRecursiveEventFilter(TQObject *object, TQObject *container)
type * findParent(TQObject *o, const char *className, TQObject *&prevPrev)
KFORMEDITOR_EXPORT void removeRecursiveEventFilter(TQObject *object, TQObject *container)