From: Manuel Nickschas Date: Fri, 21 Aug 2009 21:57:15 +0000 (+0200) Subject: Add ResizingStackedWidget X-Git-Tag: 0.5-rc1~53 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=96f84c21f30180cc52471715d2e2d3b3ede906a4 Add ResizingStackedWidget This extends QStackedWidget by adding a dynamic sizeHint that only depends on the currently selected page. Geometry is updated on page change. Use this widget if you want a stacked container that dynamically adapts to the size of the visible page only rather than caring for all the pages. Note that pages should have QSizePolicy::Ignore for this to work properly. --- diff --git a/src/uisupport/resizingstackedwidget.cpp b/src/uisupport/resizingstackedwidget.cpp new file mode 100644 index 00000000..fe6ffd71 --- /dev/null +++ b/src/uisupport/resizingstackedwidget.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2005-09 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "resizingstackedwidget.h" + +ResizingStackedWidget::ResizingStackedWidget(QWidget *parent) : QStackedWidget(parent) +{ + connect(this, SIGNAL(currentChanged(int)), SLOT(indexChanged(int))); +} + +QSize ResizingStackedWidget::sizeHint() const { + QWidget *widget = currentWidget(); + if(!widget) + return QSize(); + return widget->sizeHint(); +} + +void ResizingStackedWidget::indexChanged(int index) { + Q_UNUSED(index) + updateGeometry(); +} diff --git a/src/uisupport/resizingstackedwidget.h b/src/uisupport/resizingstackedwidget.h new file mode 100644 index 00000000..37aa4465 --- /dev/null +++ b/src/uisupport/resizingstackedwidget.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2005-09 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef RESIZINGSTACKEDWIDGET_H_ +#define RESIZINGSTACKEDWIDGET_H_ + +#include + +class ResizingStackedWidget : public QStackedWidget { + Q_OBJECT + +public: + ResizingStackedWidget(QWidget *parent = 0); + + virtual QSize sizeHint() const; + +private slots: + void indexChanged(int index); +}; + +#endif // RESIZINGSTACKEDWIDGET_H_