added sphere tutorial
[engrid.git] / src / multipagewidget.cpp
blob1bc77f5b885b1869f761219e10adfe18079e3a5f
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2010 enGits GmbH +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 /****************************************************************************
25 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
26 ** Contact: Qt Software Information (qt-info@nokia.com)
28 ** This file is part of the example classes of the Qt Toolkit.
30 ** $QT_BEGIN_LICENSE:LGPL$
31 ** Commercial Usage
32 ** Licensees holding valid Qt Commercial licenses may use this file in
33 ** accordance with the Qt Commercial License Agreement provided with the
34 ** Software or, alternatively, in accordance with the terms contained in
35 ** a written agreement between you and Nokia.
37 ** GNU Lesser General Public License Usage
38 ** Alternatively, this file may be used under the terms of the GNU Lesser
39 ** General Public License version 2.1 as published by the Free Software
40 ** Foundation and appearing in the file LICENSE.LGPL included in the
41 ** packaging of this file. Please review the following information to
42 ** ensure the GNU Lesser General Public License version 2.1 requirements
43 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
45 ** In addition, as a special exception, Nokia gives you certain
46 ** additional rights. These rights are described in the Nokia Qt LGPL
47 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
48 ** package.
50 ** GNU General Public License Usage
51 ** Alternatively, this file may be used under the terms of the GNU
52 ** General Public License version 3.0 as published by the Free Software
53 ** Foundation and appearing in the file LICENSE.GPL included in the
54 ** packaging of this file. Please review the following information to
55 ** ensure the GNU General Public License version 3.0 requirements will be
56 ** met: http://www.gnu.org/copyleft/gpl.html.
58 ** If you are unsure which license is appropriate for your use, please
59 ** contact the sales department at qt-sales@nokia.com.
60 ** $QT_END_LICENSE$
62 ****************************************************************************/
64 #include <QtGui>
66 #include "multipagewidget.h"
68 MultiPageWidget::MultiPageWidget( QWidget *parent )
69 : QWidget( parent )
71 comboBox = new QComboBox();
72 comboBox->setObjectName( "__qt__passive_comboBox" );
73 stackWidget = new QStackedWidget();
75 connect( comboBox, SIGNAL( activated( int ) ),
76 this, SLOT( setCurrentIndex( int ) ) );
78 layout = new QVBoxLayout();
79 layout->addWidget( comboBox );
80 layout->addWidget( stackWidget );
81 setLayout( layout );
84 QSize MultiPageWidget::sizeHint() const
86 return QSize( 200, 150 );
89 void MultiPageWidget::addPage( QWidget *page )
91 insertPage( count(), page );
94 void MultiPageWidget::removePage( int index )
96 QWidget *widget = stackWidget->widget( index );
97 stackWidget->removeWidget( widget );
99 comboBox->removeItem( index );
102 int MultiPageWidget::count() const
104 return stackWidget->count();
107 int MultiPageWidget::currentIndex() const
109 return stackWidget->currentIndex();
112 void MultiPageWidget::insertPage( int index, QWidget *page )
114 page->setParent( stackWidget );
116 stackWidget->insertWidget( index, page );
118 QString title = page->windowTitle();
119 if ( title.isEmpty() ) {
120 title = tr( "Page %1" ).arg( comboBox->count() + 1 );
121 page->setWindowTitle( title );
123 comboBox->insertItem( index, title );
126 void MultiPageWidget::setCurrentIndex( int index )
128 if ( index != currentIndex() ) {
129 stackWidget->setCurrentIndex( index );
130 comboBox->setCurrentIndex( index );
131 emit currentIndexChanged( index );
135 QWidget* MultiPageWidget::widget( int index )
137 return stackWidget->widget( index );
140 QString MultiPageWidget::pageTitle() const
142 if ( const QWidget *currentWidget = stackWidget->currentWidget() )
143 return currentWidget->windowTitle();
144 return QString();
147 void MultiPageWidget::setPageTitle( QString const &newTitle )
149 comboBox->setItemText( currentIndex(), newTitle );
150 if ( QWidget *currentWidget = stackWidget->currentWidget() )
151 currentWidget->setWindowTitle( newTitle );
152 emit pageTitleChanged( newTitle );
155 void MultiPageWidget::setPageTitle( QString const &newTitle, int index )
157 comboBox->setItemText( index, newTitle );
158 if ( QWidget *widget = stackWidget-> widget( index ) )
159 widget->setWindowTitle( newTitle );
160 emit pageTitleChanged( newTitle );