Add ResizingStackedWidget
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 21 Aug 2009 21:57:15 +0000 (23:57 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 21 Aug 2009 22:13:44 +0000 (00:13 +0200)
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.

src/uisupport/resizingstackedwidget.cpp [new file with mode: 0644]
src/uisupport/resizingstackedwidget.h [new file with mode: 0644]

diff --git a/src/uisupport/resizingstackedwidget.cpp b/src/uisupport/resizingstackedwidget.cpp
new file mode 100644 (file)
index 0000000..fe6ffd7
--- /dev/null
@@ -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 (file)
index 0000000..37aa446
--- /dev/null
@@ -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 <QStackedWidget>
+
+class ResizingStackedWidget : public QStackedWidget {
+  Q_OBJECT
+
+public:
+  ResizingStackedWidget(QWidget *parent = 0);
+
+  virtual QSize sizeHint() const;
+
+private slots:
+  void indexChanged(int index);
+};
+
+#endif // RESIZINGSTACKEDWIDGET_H_