libplasma
freelayout.cpp
Go to the documentation of this file.00001 /* 00002 * Copyright 2007 by Robert Knight <robertknight@gmail.com> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details 00014 * 00015 * You should have received a copy of the GNU Library General Public 00016 * License along with this program; if not, write to the 00017 * Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "freelayout.h" 00022 00023 #include <KDebug> 00024 00025 #include <plasma/layouts/layout.h> 00026 00027 namespace Plasma 00028 { 00029 00030 class FreeLayout::Private 00031 { 00032 public: 00033 QList<LayoutItem*> children; 00034 }; 00035 00036 FreeLayout::FreeLayout(LayoutItem *parent) 00037 : Layout(parent), 00038 d(new Private) 00039 { 00040 } 00041 00042 FreeLayout::~FreeLayout() 00043 { 00044 delete d; 00045 } 00046 00047 Qt::Orientations FreeLayout::expandingDirections() const 00048 { 00049 return Qt::Horizontal | Qt::Vertical; 00050 } 00051 00052 void FreeLayout::addItem(LayoutItem *item) 00053 { 00054 if (d->children.contains(item)) { 00055 return; 00056 } 00057 00058 d->children << item; 00059 item->setManagingLayout(this); 00060 } 00061 00062 void FreeLayout::removeItem(LayoutItem *item) 00063 { 00064 if (!item) { 00065 return; 00066 } 00067 00068 d->children.removeAll(item); 00069 item->unsetManagingLayout(this); 00070 } 00071 00072 int FreeLayout::indexOf(LayoutItem *item) const 00073 { 00074 return d->children.indexOf(item); 00075 } 00076 00077 LayoutItem * FreeLayout::itemAt(int i) const 00078 { 00079 return d->children[i]; 00080 } 00081 00082 int FreeLayout::count() const 00083 { 00084 return d->children.count(); 00085 } 00086 00087 LayoutItem * FreeLayout::takeAt(int i) 00088 { 00089 return d->children.takeAt(i); 00090 } 00091 00092 void FreeLayout::relayout() 00093 { 00094 foreach (LayoutItem *child , d->children) { 00095 if (child->geometry().size() != child->sizeHint()) { 00096 QSizeF newSize = child->sizeHint().expandedTo(minimumSize()).boundedTo(maximumSize()); 00097 child->setGeometry(QRectF(child->geometry().topLeft(), newSize)); 00098 } 00099 } 00100 } 00101 00102 QRectF FreeLayout::geometry() const 00103 { 00104 if (parent()) { 00105 return parent()->geometry(); 00106 } 00107 00108 return QRectF(QPointF(0, 0), maximumSize()); 00109 } 00110 00111 QSizeF FreeLayout::sizeHint() const 00112 { 00113 if (parent()) { 00114 //kDebug() << "returning size hint from freelayout of" << parent()->geometry().size(); 00115 return parent()->geometry().size(); 00116 } 00117 00118 //kDebug() << "returning size hint from freelayout of" << maximumSize(); 00119 return maximumSize(); 00120 } 00121 00122 } 00123
KDE 4.0 API Reference