Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

serverinterface.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include "serverinterface.h"
00021 #include "server.h"
00022 #include "documentlist.h"
00023 
00024 #include <qtopia/qpeapplication.h>
00025 #include <qwindowsystem_qws.h>
00026 #include <qgfx_qws.h>
00027 
00028 class LayoutManager : public QObject
00029 {
00030     Q_OBJECT
00031 public:
00032     LayoutManager();
00033 
00034     void addDocked( QWidget *w, ServerInterface::DockArea placement );
00035 
00036 private:
00037     struct Item {
00038         QWidget *w;
00039         ServerInterface::DockArea p;
00040     };
00041 
00042     bool eventFilter( QObject *object, QEvent *event );
00043     void layout();
00044     Item *findWidget( const QWidget *w ) const;
00045 
00046     QList<Item> docked;
00047 };
00048 
00049 LayoutManager::LayoutManager()
00050 {
00051     docked.setAutoDelete( TRUE );
00052     qApp->desktop()->installEventFilter( this );
00053 }
00054 
00055 void LayoutManager::addDocked( QWidget *w, ServerInterface::DockArea placement )
00056 {
00057     Item *i = new Item;
00058     i->w = w;
00059     i->p = placement;
00060     w->installEventFilter( this );
00061     docked.append(i);
00062     layout();
00063 }
00064 
00065 bool LayoutManager::eventFilter( QObject *object, QEvent *event )
00066 {
00067     if ( object == qApp->desktop() ) {
00068         if ( event->type() == QEvent::Resize )
00069             layout();
00070         return QObject::eventFilter( object, event );
00071     }
00072 
00073     Item *item;
00074 
00075     switch ( event->type() ) {
00076         case QEvent::Destroy:
00077             item = findWidget( (QWidget *)object );
00078             if ( item ) {
00079                 docked.removeRef( item );
00080                 layout();
00081             }
00082             break;
00083 
00084         case QEvent::Hide:
00085         case QEvent::Show:
00086             item = findWidget( (QWidget *)object );
00087             if ( item )
00088                 layout();
00089             break;
00090 
00091         default:
00092             break;
00093     }
00094 
00095     return QObject::eventFilter( object, event );
00096 }
00097 
00098 void LayoutManager::layout()
00099 {
00100     QRect mwr( qApp->desktop()->geometry() );
00101     QListIterator<Item> it( docked );
00102     Item *item;
00103     for ( ; (item = it.current()); ++it ) {
00104         QWidget *w = item->w;
00105         if ( !w->isVisible() )
00106             continue;
00107 
00108         QSize sh = w->sizeHint();
00109         switch ( item->p ) {
00110             case ServerInterface::Top:
00111                 w->setGeometry( mwr.left(), mwr.top(),
00112                                 mwr.width(), sh.height() );
00113                 mwr.setTop( w->geometry().bottom() + 1 );
00114                 break;
00115             case ServerInterface::Bottom:
00116                 w->setGeometry( mwr.left(), mwr.bottom() - sh.height(),
00117                                 mwr.width(), sh.height() );
00118                 mwr.setBottom( w->geometry().top() - 1 );
00119                 break;
00120             case ServerInterface::Left:
00121                 w->setGeometry( mwr.left(), mwr.top(),
00122                                 sh.width(), mwr.height() );
00123                 mwr.setLeft( w->geometry().right() + 1 );
00124                 break;
00125             case ServerInterface::Right:
00126                 w->setGeometry( mwr.right() - sh.width(), mwr.top(),
00127                                 sh.width(), mwr.height() );
00128                 mwr.setRight( w->geometry().left() - 1 );
00129                 break;
00130         }
00131     }
00132 
00133 #ifdef Q_WS_QWS
00134 # if QT_VERSION < 0x030000
00135     QWSServer::setMaxWindowRect( qt_screen->mapToDevice(mwr,
00136         QSize(qt_screen->width(),qt_screen->height())) );
00137 # else
00138     QWSServer::setMaxWindowRect( mwr );
00139 # endif
00140 #endif
00141 }
00142 
00143 LayoutManager::Item *LayoutManager::findWidget( const QWidget *w ) const
00144 {
00145     QListIterator<Item> it( docked );
00146     Item *item;
00147     for ( ; (item = it.current()); ++it ) {
00148         if ( item->w == w )
00149             return item;
00150     }
00151 
00152     return 0;
00153 }
00154 
00155 //---------------------------------------------------------------------------
00156 
00354 ServerInterface::~ServerInterface()
00355 {
00356 }
00357 
00358 void ServerInterface::dockWidget( QWidget *w, DockArea placement )
00359 {
00360     static LayoutManager *lm = 0;
00361 
00362     if ( !lm )
00363         lm = new LayoutManager;
00364 
00365     lm->addDocked( w, placement );
00366 }
00367 
00368 const AppLnkSet& ServerInterface::appLnks()
00369 {
00370     return *DocumentList::appLnkSet;
00371 }
00372 
00373 #include "serverinterface.moc"
00374 

Generated on Sat Nov 5 16:15:32 2005 for OPIE by  doxygen 1.4.2