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 namespace casa { 00036 00037 // Subclass of QLayout to have multiple widgets layered on top of each other. 00038 // Since the top widget will be the only one who receives certain types of Qt 00039 // events, the layout can also propagate events to lower children if desired. 00040 // NOTE: EVENT PROPAGATION IS NOT CURRENTLY WORKING. 00041 class QtLayeredLayout : public QLayout { 00042 public: 00043 // Static // 00044 00045 // Returns true if the given event type is propagate-able, false otherwise. 00046 static bool propagateEventType(QEvent::Type type); 00047 00048 00049 // Non-Static // 00050 00051 // Constructor which takes no parent. 00052 QtLayeredLayout(); 00053 00054 // Constructor which takes a parent (cannot be null). 00055 QtLayeredLayout(QWidget* parent); 00056 00057 // Destructor. 00058 ~QtLayeredLayout(); 00059 00060 00061 // QLayoutItem Methods // 00062 00063 // Implements QLayoutItem::geometry(). Returns the last geometry set using 00064 // setGeometry(). 00065 QRect geometry() const; 00066 00067 // Implements QLayoutItem::isEmpty(). 00068 bool isEmpty() const; 00069 00070 // Implements QLayoutItem::setGeometry(). Sets the geometry of all 00071 // children to the given. 00072 void setGeometry(const QRect& r); 00073 00074 // Implements QLayoutItem::sizeHint(). Returns minimumSizeHint(). 00075 QSize sizeHint() const; 00076 00077 00078 // QObject Methods // 00079 00080 // Overrides QObject::eventFilter() to propagate events as needed. 00081 virtual bool eventFilter(QObject* watched, QEvent* event); 00082 00083 00084 // QLayout Methods // 00085 00086 // Implements QLayout::addItem(). Does not add duplicates. 00087 void addItem(QLayoutItem* item); 00088 00089 // Implements QLayout::count(). 00090 int count() const; 00091 00092 // Overrides QLayout::expandingDirections(). 00093 Qt::Orientations expandingDirections() const; 00094 00095 // Overrides QLayout::indexOf(). 00096 int indexOf(QWidget* widget) const; 00097 00098 // Implements QLayout::itemAt(). 00099 QLayoutItem* itemAt(int index) const; 00100 00101 // Overrides QLayout::maximumSize(). Returns the smallest valid maximum 00102 // size for its items. 00103 QSize maximumSize() const; 00104 00105 // Overrides QLayout::minimumSize(). Returns the largest valid minimum 00106 // size for its items. 00107 QSize minimumSize() const; 00108 00109 // Implements QLayout::takeAt(). 00110 QLayoutItem* takeAt(int index); 00111 00112 00113 // QtLayeredLayout Methods // 00114 00115 // Inserts the given item at the given index. If index is outside the 00116 // bounds of the item list, the item is inserted at the end. Null or 00117 // duplicate items are not inserted. 00118 // <group> 00119 void insertItem(int index, QLayoutItem* item); 00120 void insertWidget(int index, QWidget* widget); 00121 // </group> 00122 00123 private: 00124 // Items. 00125 QList<QLayoutItem*> itsItems_; 00126 00127 // Last set geometry. 00128 QRect itsGeometry_; 00129 00130 // Flag to propagate events or not. 00131 bool itsPropagateEvents_; 00132 00133 00134 // Installs or removes this layout as an event filter on the given item. 00135 void installOrRemoveSelf(QLayoutItem* item, bool install); 00136 00137 // Redoes the sibling widget stack in the parent, if applicable. 00138 void redoParentStack(); 00139 00140 // Returns the layered index of the given widget, using recursive 00141 // parameters. 00142 // <group> 00143 int layeredIndexOf(QWidget* widget) const; 00144 static int layeredIndexOf(QWidget* widget, QLayoutItem* item); 00145 // </group> 00146 }; 00147 00148 } 00149 00150 #endif /* QTLAYEREDLAYOUT_H_ */