kexi

utils.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qcursor.h>
00021 #include <qobjectlist.h>
00022 #include <kdebug.h>
00023 
00024 #include "form.h"
00025 #include "objecttree.h"
00026 #include "utils.h"
00027 
00028 using namespace KFormDesigner;
00029 
00031 void
00032 KFormDesigner::removeChildrenFromList(WidgetList &list)
00033 {
00034     for(WidgetListIterator it(list); it.current() != 0; ++it)  {
00035         QWidget *w = it.current();
00036 
00037         // If any widget in the list is a child of this widget, we remove it from the list
00038         for(WidgetListIterator it2(list); it2.current() != 0; ++it2) {
00039             QWidget *widg = it2.current();
00040             if((w != widg) && (w->child(widg->name())))
00041             {
00042                 kdDebug() << "Removing the widget " << widg->name() << "which is a child of " << w->name() << endl;
00043                 list.remove(widg);
00044             }
00045         }
00046     }
00047 }
00048 
00050 void
00051 KFormDesigner::installRecursiveEventFilter(QObject *object, QObject *container)
00052 {
00053     if(!object || !container|| !object->isWidgetType())
00054         return;
00055 
00056     kdDebug() << "Installing event filter on widget: " << object->name() << " directed to " << container->name() << endl;
00057     object->installEventFilter(container);
00058     if(((QWidget*)object)->ownCursor())
00059         ((QWidget*)object)->setCursor(QCursor(Qt::ArrowCursor));
00060 
00061     if(!object->children())
00062         return;
00063 
00064     QObjectList list = *(object->children());
00065     for(QObject *obj = list.first(); obj; obj = list.next())
00066         installRecursiveEventFilter(obj, container);
00067 }
00068 
00069 void
00070 KFormDesigner::removeRecursiveEventFilter(QObject *object, QObject *container)
00071 {
00072     object->removeEventFilter(container);
00073     if(!object->isWidgetType())
00074         return;
00075     if(!object->children())
00076         return;
00077 
00078     QObjectList list = *(object->children());
00079     for(QObject *obj = list.first(); obj; obj = list.next())
00080         removeRecursiveEventFilter(obj, container);
00081 }
00082 
00083 void
00084 KFormDesigner::setRecursiveCursor(QWidget *w, Form *form)
00085 {
00086     ObjectTreeItem *tree = form->objectTree()->lookup(w->name());
00087     if(tree && ((tree->modifiedProperties()->contains("cursor")) || !tree->children()->isEmpty())
00088         && !w->inherits("QLineEdit") && !w->inherits("QTextEdit")
00089         ) //fix weird behaviour
00090         return; // if the user has set a cursor for this widget or this is a container, don't change it
00091 
00092     if(w->ownCursor())
00093         w->setCursor(Qt::ArrowCursor);
00094 
00095     QObjectList *l = w->queryList( "QWidget" );
00096     for(QObject *o = l->first(); o; o = l->next())
00097         ((QWidget*)o)->setCursor(Qt::ArrowCursor);
00098     delete l;
00099 }
00100 
00101 QSize
00102 KFormDesigner::getSizeFromChildren(QWidget *w, const char *inheritClass)
00103 {
00104     int tmpw = 0, tmph = 0;
00105     QObjectList *list = w->queryList(inheritClass, 0, false, false);
00106     for(QObject *o = list->first(); o; o = list->next()) {
00107         QRect  r = ((QWidget*)o)->geometry();
00108         tmpw = QMAX(tmpw, r.right());
00109         tmph = QMAX(tmph, r.bottom());
00110     }
00111 
00112     delete list;
00113     return QSize(tmpw, tmph) + QSize(10, 10);
00114 }
00115 
KDE Home | KDE Accessibility Home | Description of Access Keys