From 05067a540b09138e81941dc3f11940ea54a12b3c Mon Sep 17 00:00:00 2001 From: Pekka Nissinen Date: Mon, 16 Aug 2010 16:17:49 +0300 Subject: [PATCH] Renamed PanelContent class to PanelContentStack and simplified the general structure by subclassing the entire class directly from QStackedWidget --- src/src.pro | 4 +-- src/ui/panelcontent.cpp | 62 --------------------------------- src/ui/panelcontent.h | 79 ------------------------------------------ src/ui/panelcontentstack.cpp | 55 +++++++++++++++++++++++++++++ src/ui/panelcontentstack.h | 70 +++++++++++++++++++++++++++++++++++++ src/ui/tabbedpanel.cpp | 25 ++++++------- src/ui/tabbedpanel.h | 7 ++-- 7 files changed, 139 insertions(+), 163 deletions(-) delete mode 100644 src/ui/panelcontent.cpp delete mode 100644 src/ui/panelcontent.h create mode 100644 src/ui/panelcontentstack.cpp create mode 100644 src/ui/panelcontentstack.h diff --git a/src/src.pro b/src/src.pro index c5e3962..4085e45 100644 --- a/src/src.pro +++ b/src/src.pro @@ -66,7 +66,7 @@ SOURCES += main.cpp \ ui/searchdialog.cpp \ ui/panelbase.cpp \ ui/panelbar.cpp \ - ui/panelcontent.cpp \ + ui/panelcontentstack.cpp \ ui/paneltab.cpp \ ui/paneltabbar.cpp \ ui/tabbedpanel.cpp \ @@ -137,8 +137,8 @@ HEADERS += application.h \ ui/searchdialog.h \ ui/panelbase.h \ ui/panelbar.h \ - ui/panelcontent.h \ ui/panelcommon.h \ + ui/panelcontentstack.h \ ui/paneltab.h \ ui/paneltabbar.h \ ui/tabbedpanel.h \ diff --git a/src/ui/panelcontent.cpp b/src/ui/panelcontent.cpp deleted file mode 100644 index ec65575..0000000 --- a/src/ui/panelcontent.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Kaj Wallin - kaj.wallin@ixonos.com - Pekka Nissinen - pekka.nissinen@ixonos.com - - Situare is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as published by the Free Software Foundation. - - Situare 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 Situare; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#include -#include -#include - -#include "panelbase.h" -#include "panelcommon.h" - -#include "panelcontent.h" - -PanelContent::PanelContent(QWidget *parent) - : QWidget(parent) -{ - qDebug() << __PRETTY_FUNCTION__; - - resize(PANEL_WIDTH, PANEL_HEIGHT); - - m_panelVBox = new QVBoxLayout(this); - m_panelVBox->setMargin(0); - m_panelVBox->setSpacing(0); - - m_panelBase = new PanelBase(this); - m_panelBase->setLayout(m_panelVBox); - m_panelBase->resize(this->size()); -} - -void PanelContent::setContentWidget(QWidget *widget) -{ - qDebug() << __PRETTY_FUNCTION__; - - m_panelVBox->addWidget(widget); -} - -void PanelContent::resizePanelContent(const QSize &size) -{ - qDebug() << __PRETTY_FUNCTION__; - - resize(PANEL_WIDTH, size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING); - - m_panelBase->resize(this->size()); -} diff --git a/src/ui/panelcontent.h b/src/ui/panelcontent.h deleted file mode 100644 index 74fabd3..0000000 --- a/src/ui/panelcontent.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Kaj Wallin - kaj.wallin@ixonos.com - Pekka Nissinen - pekka.nissinen@ixonos.com - - Situare is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as published by the Free Software Foundation. - - Situare 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 Situare; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#ifndef PANELCONTENT_H -#define PANELCONTENT_H - -#include - -class QVBoxLayout; - -class PanelBase; - -///< @todo Base class? Might be misleading comment and does not tell about what this class does -/** - * @brief Base class for panel content area - * - * @author Kaj Wallin - kaj.wallin (at) ixonos.com - * @author Pekka Nissinen - pekka.nissinen@ixonos.com - */ -class PanelContent : public QWidget -{ - Q_OBJECT - -public: - /** - * @brief Constructor - * - * @param parent Parent - */ - PanelContent(QWidget *parent = 0); - -/******************************************************************************* - * MEMBER FUNCTIONS AND SLOTS - ******************************************************************************/ -public: - /** - * @brief Sets the panel content widget - * - * @param widget Widget - */ - void setContentWidget(QWidget *widget); - -public slots: - /** - * @brief Slot to redraw the panel content area after window resize event - * - * @param size Size of the new window - */ - void resizePanelContent(const QSize &size); - -/******************************************************************************* - * DATA MEMBERS - *******************************************************************************/ -private: - QVBoxLayout *m_panelVBox; ///< Vertical layout inside the panel - - PanelBase *m_panelBase; ///< Widget for panel base -}; - -#endif // PANELCONTENT_H diff --git a/src/ui/panelcontentstack.cpp b/src/ui/panelcontentstack.cpp new file mode 100644 index 0000000..b23af29 --- /dev/null +++ b/src/ui/panelcontentstack.cpp @@ -0,0 +1,55 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Kaj Wallin - kaj.wallin@ixonos.com + Pekka Nissinen - pekka.nissinen@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare 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 Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include +#include +#include + +#include "panelbase.h" +#include "panelcommon.h" + +#include "panelcontentstack.h" + +PanelContentStack::PanelContentStack(QWidget *parent) + : QStackedWidget(parent) +{ + qDebug() << __PRETTY_FUNCTION__; + + resize(PANEL_WIDTH, PANEL_HEIGHT); + + m_panelVBox = new QVBoxLayout(this); + m_panelVBox->setMargin(0); + m_panelVBox->setSpacing(0); + + m_panelBase = new PanelBase(this); + m_panelBase->setLayout(m_panelVBox); + m_panelBase->resize(this->size()); +} + +void PanelContentStack::resizePanelContentStack(const QSize &size) +{ + qDebug() << __PRETTY_FUNCTION__; + + resize(PANEL_WIDTH, size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING); + + m_panelBase->resize(this->size()); +} diff --git a/src/ui/panelcontentstack.h b/src/ui/panelcontentstack.h new file mode 100644 index 0000000..9715035 --- /dev/null +++ b/src/ui/panelcontentstack.h @@ -0,0 +1,70 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Kaj Wallin - kaj.wallin@ixonos.com + Pekka Nissinen - pekka.nissinen@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare 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 Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef PANELCONTENTSTACK_H +#define PANELCONTENTSTACK_H + +#include + +class QVBoxLayout; + +class PanelBase; + +/** + * @brief Stack class for tabbed pabel widgets + * + * @author Kaj Wallin - kaj.wallin (at) ixonos.com + * @author Pekka Nissinen - pekka.nissinen@ixonos.com + */ +class PanelContentStack : public QStackedWidget +{ + Q_OBJECT + +public: + /** + * @brief Constructor + * + * @param parent Parent + */ + PanelContentStack(QWidget *parent = 0); + +/******************************************************************************* + * MEMBER FUNCTIONS AND SLOTS + ******************************************************************************/ +public slots: + /** + * @brief Slot to redraw the panel content area after window resize event + * + * @param size Size of the new window + */ + void resizePanelContentStack(const QSize &size); + +/******************************************************************************* + * DATA MEMBERS + *******************************************************************************/ +private: + QVBoxLayout *m_panelVBox; ///< Vertical layout inside the panel + + PanelBase *m_panelBase; ///< Widget for panel base +}; + +#endif // PANELCONTENTSTACK_H diff --git a/src/ui/tabbedpanel.cpp b/src/ui/tabbedpanel.cpp index 424496a..311bd66 100644 --- a/src/ui/tabbedpanel.cpp +++ b/src/ui/tabbedpanel.cpp @@ -27,7 +27,7 @@ #include #include "panelbar.h" -#include "panelcontent.h" +#include "panelcontentstack.h" #include "paneltabbar.h" #include "tabbedpanel.h" @@ -42,8 +42,6 @@ TabbedPanel::TabbedPanel(QWidget *parent) move(PANEL_CLOSED_X, PANEL_TOP_PADDING); // --- TABS --- - m_panelWidgetStack = new QStackedWidget(this); - m_panelTabBar = new PanelTabBar(this); connect(m_panelTabBar, SIGNAL(currentChanged(int)), @@ -60,9 +58,8 @@ TabbedPanel::TabbedPanel(QWidget *parent) m_panelBar->move(PANEL_TAB_WIDTH, 0); // --- PANEL CONTENT --- - m_panelContent = new PanelContent(this); - m_panelContent->setContentWidget(m_panelWidgetStack); - m_panelContent->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, 0); + m_panelContentStack = new PanelContentStack(this); + m_panelContentStack->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, 0); // --- PANEL ANIMATION --- m_panelStateMachine = new QStateMachine(this); @@ -97,7 +94,6 @@ int TabbedPanel::addTab(QWidget *widget, const QIcon& icon) { qDebug() << __PRETTY_FUNCTION__; - const int APPEND_INDEX = -1; return insertTab(APPEND_INDEX, widget, icon); @@ -115,7 +111,7 @@ int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon) { qDebug() << __PRETTY_FUNCTION__; - index = m_panelWidgetStack->insertWidget(index, widget); + index = m_panelContentStack->insertWidget(index, widget); m_panelTabBar->insertTab(index, icon); return index; @@ -125,8 +121,8 @@ void TabbedPanel::removeTab(int index) { qDebug() << __PRETTY_FUNCTION__; - if(QWidget *widget = m_panelWidgetStack->widget(index)) { - m_panelWidgetStack->removeWidget(widget); + if(QWidget *widget = m_panelContentStack->widget(index)) { + m_panelContentStack->removeWidget(widget); m_panelTabBar->removeTab(index); } } @@ -145,7 +141,7 @@ void TabbedPanel::resizePanel(const QSize &size) m_panelBar->resizeBar(size); - m_panelContent->resizePanelContent(size); + m_panelContentStack->resizePanelContentStack(size); QPoint closedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING); m_panelStateClosed->assignProperty(this, "pos", closedPosition); @@ -153,22 +149,21 @@ void TabbedPanel::resizePanel(const QSize &size) QPoint openedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING); m_panelStateOpened->assignProperty(this, "pos", openedPosition); - } void TabbedPanel::showPanel(QWidget *widget) { qDebug() << __PRETTY_FUNCTION__; - m_panelTabBar->selectTab(m_panelWidgetStack->indexOf(widget)); + m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget)); } void TabbedPanel::setCurrentIndex(int index) { qDebug() << __PRETTY_FUNCTION__; - if ((index < m_panelWidgetStack->count()) && (index >= 0)) { - m_panelWidgetStack->setCurrentIndex(index); + if ((index < m_panelContentStack->count()) && (index >= 0)) { + m_panelContentStack->setCurrentIndex(index); if(!m_isOpen) emit toggleState(); diff --git a/src/ui/tabbedpanel.h b/src/ui/tabbedpanel.h index 7357229..33b93cb 100644 --- a/src/ui/tabbedpanel.h +++ b/src/ui/tabbedpanel.h @@ -29,12 +29,11 @@ class QPropertyAnimation; class QSignalTransition; -class QStackedWidget; class QState; class QStateMachine; class PanelBar; -class PanelContent; +class PanelContentStack; class PanelTabBar; /** @@ -172,15 +171,13 @@ private: QSignalTransition *m_panelTransitionClose; ///< Transition signal for closing the panel QSignalTransition *m_panelTransitionOpen; ///< Transition signal for opening the panel - QStackedWidget *m_panelWidgetStack; ///< Stack for panel widgets - QState *m_panelStateClosed; ///< State of the closed panel QState *m_panelStateOpened; ///< State of the opened panel QStateMachine *m_panelStateMachine; ///< State machine for sliding the panel PanelBar *m_panelBar; ///< Widget for panel bar - PanelContent *m_panelContent; ///< Widget for panel content + PanelContentStack *m_panelContentStack; ///< Stack for panel widgets PanelTabBar *m_panelTabBar; ///< Widget for panel tab bar }; -- 1.7.9.5