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