compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / multipagewidget.cpp
blobadf0b5924d062dcb8af86b649ba429845501be2d
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>
63 #include <QComboBox>
64 #include <QStackedWidget>
65 #include <QVBoxLayout>
67 #include "multipagewidget.h"
69 MultiPageWidget::MultiPageWidget( QWidget *parent )
70 : QWidget( parent )
72 comboBox = new QComboBox();
73 comboBox->setObjectName( "__qt__passive_comboBox" );
74 stackWidget = new QStackedWidget();
76 connect( comboBox, SIGNAL( activated( int ) ),
77 this, SLOT( setCurrentIndex( int ) ) );
79 layout = new QVBoxLayout();
80 layout->addWidget( comboBox );
81 layout->addWidget( stackWidget );
82 setLayout( layout );
85 QSize MultiPageWidget::sizeHint() const
87 return QSize( 200, 150 );
90 void MultiPageWidget::addPage( QWidget *page )
92 insertPage( count(), page );
95 void MultiPageWidget::removePage( int index )
97 QWidget *widget = stackWidget->widget( index );
98 stackWidget->removeWidget( widget );
100 comboBox->removeItem( index );
103 int MultiPageWidget::count() const
105 return stackWidget->count();
108 int MultiPageWidget::currentIndex() const
110 return stackWidget->currentIndex();
113 void MultiPageWidget::insertPage( int index, QWidget *page )
115 page->setParent( stackWidget );
117 stackWidget->insertWidget( index, page );
119 QString title = page->windowTitle();
120 if ( title.isEmpty() ) {
121 title = tr( "Page %1" ).arg( comboBox->count() + 1 );
122 page->setWindowTitle( title );
124 comboBox->insertItem( index, title );
127 void MultiPageWidget::setCurrentIndex( int index )
129 if ( index != currentIndex() ) {
130 stackWidget->setCurrentIndex( index );
131 comboBox->setCurrentIndex( index );
132 emit currentIndexChanged( index );
136 QWidget* MultiPageWidget::widget( int index )
138 return stackWidget->widget( index );
141 QString MultiPageWidget::pageTitle() const
143 if ( const QWidget *currentWidget = stackWidget->currentWidget() )
144 return currentWidget->windowTitle();
145 return QString();
148 void MultiPageWidget::setPageTitle( QString const &newTitle )
150 comboBox->setItemText( currentIndex(), newTitle );
151 if ( QWidget *currentWidget = stackWidget->currentWidget() )
152 currentWidget->setWindowTitle( newTitle );
153 emit pageTitleChanged( newTitle );
156 void MultiPageWidget::setPageTitle( QString const &newTitle, int index )
158 comboBox->setItemText( index, newTitle );
159 if ( QWidget *widget = stackWidget-> widget( index ) )
160 widget->setWindowTitle( newTitle );
161 emit pageTitleChanged( newTitle );