casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtLayeredLayout.h
Go to the documentation of this file.
00001 //# QtLayeredLayout.h: Subclass of QLayout to have layered widgets.
00002 //# Copyright (C) 2009
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef QTLAYEREDLAYOUT_H_
00028 #define QTLAYEREDLAYOUT_H_
00029 
00030 #include <casa/BasicSL/String.h>
00031 
00032 #include <QEvent>
00033 #include <QLayout>
00034 
00035 #include <casa/namespace.h>
00036 using namespace std;
00037 
00038 namespace casa {
00039 
00040 // Subclass of QLayout to have multiple widgets layered on top of each other.
00041 // Since the top widget will be the only one who receives certain types of Qt
00042 // events, the layout can also propagate events to lower children if desired.
00043 // NOTE: EVENT PROPAGATION IS NOT CURRENTLY WORKING.
00044 class QtLayeredLayout : public QLayout {
00045 public:
00046     // Static //
00047     
00048     // Returns true if the given event type is propagate-able, false otherwise.
00049     static bool propagateEventType(QEvent::Type type);
00050     
00051     
00052     // Non-Static //
00053     
00054     // Constructor which takes no parent.
00055     QtLayeredLayout();
00056     
00057     // Constructor which takes a parent (cannot be null).
00058     QtLayeredLayout(QWidget* parent);
00059     
00060     // Destructor.
00061     ~QtLayeredLayout();
00062     
00063     
00064     // QLayoutItem Methods //
00065     
00066     // Implements QLayoutItem::geometry().  Returns the last geometry set using
00067     // setGeometry().
00068     QRect geometry() const;
00069     
00070     // Implements QLayoutItem::isEmpty().
00071     bool isEmpty() const;
00072     
00073     // Implements QLayoutItem::setGeometry().  Sets the geometry of all
00074     // children to the given.
00075     void setGeometry(const QRect& r);
00076     
00077     // Implements QLayoutItem::sizeHint().  Returns minimumSizeHint().
00078     QSize sizeHint() const;
00079     
00080     
00081     // QObject Methods //
00082     
00083     // Overrides QObject::eventFilter() to propagate events as needed.
00084     virtual bool eventFilter(QObject* watched, QEvent* event);
00085     
00086     
00087     // QLayout Methods //
00088     
00089     // Implements QLayout::addItem().  Does not add duplicates.
00090     void addItem(QLayoutItem* item);
00091     
00092     // Implements QLayout::count().
00093     int count() const;
00094     
00095     // Overrides QLayout::expandingDirections().
00096     Qt::Orientations expandingDirections() const;
00097     
00098     // Overrides QLayout::indexOf().
00099     int indexOf(QWidget* widget) const;
00100     
00101     // Implements QLayout::itemAt().
00102     QLayoutItem* itemAt(int index) const;
00103     
00104     // Overrides QLayout::maximumSize().  Returns the smallest valid maximum
00105     // size for its items.
00106     QSize maximumSize() const;
00107     
00108     // Overrides QLayout::minimumSize().  Returns the largest valid minimum
00109     // size for its items.
00110     QSize minimumSize() const;
00111     
00112     // Implements QLayout::takeAt().
00113     QLayoutItem* takeAt(int index);
00114     
00115     
00116     // QtLayeredLayout Methods //
00117     
00118     // Inserts the given item at the given index.  If index is outside the
00119     // bounds of the item list, the item is inserted at the end.  Null or
00120     // duplicate items are not inserted.
00121     // <group>
00122     void insertItem(int index, QLayoutItem* item);
00123     void insertWidget(int index, QWidget* widget);
00124     // </group>
00125     
00126 private:
00127     // Items.
00128     QList<QLayoutItem*> itsItems_;
00129     
00130     // Last set geometry.
00131     QRect itsGeometry_;
00132     
00133     // Flag to propagate events or not.
00134     bool itsPropagateEvents_;
00135     
00136     
00137     // Installs or removes this layout as an event filter on the given item.
00138     void installOrRemoveSelf(QLayoutItem* item, bool install);
00139     
00140     // Redoes the sibling widget stack in the parent, if applicable.
00141     void redoParentStack();
00142 
00143     // Returns the layered index of the given widget, using recursive
00144     // parameters.
00145     // <group>
00146     int layeredIndexOf(QWidget* widget) const;
00147     static int layeredIndexOf(QWidget* widget, QLayoutItem* item);
00148     // </group>
00149 };
00150 
00151 }
00152 
00153 #endif /* QTLAYEREDLAYOUT_H_ */