libyui-qt  2.44.0
 All Classes Functions Variables
QY2ComboTabWidget.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2ComboTabWidget.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23  This is a pure Qt widget - it can be used independently of YaST2.
24 
25 /-*/
26 
27 
28 #include <QComboBox>
29 #include <QLabel>
30 #include <QStackedWidget>
31 #include <QHBoxLayout>
32 
33 #include <QFrame>
34 
35 #define YUILogComponent "qt-pkg"
36 #include <yui/YUILog.h>
37 
38 #include "QY2ComboTabWidget.h"
39 
40 
41 #define SPACING 6 // between subwidgets
42 #define MARGIN 4 // around the widget
43 
44 
45 
46 QY2ComboTabWidget::QY2ComboTabWidget( const QString & label,
47  QWidget * parent,
48  const char * name )
49  : QWidget(parent)
50 {
51  QVBoxLayout *vbox = new QVBoxLayout(this);
52  vbox->setMargin( 0 );
53 
54  QHBoxLayout *hbox = new QHBoxLayout();
55  Q_CHECK_PTR( hbox );
56 // hbox->setFrameStyle( QFrame::Panel | QFrame::Raised );
57 // hbox->setLineWidth(2);
58 // hbox->setMidLineWidth(2);
59  hbox->setSpacing( 0 );
60  hbox->setMargin ( 0 );
61 
62  vbox->addLayout(hbox);
63  //this->setSpacing( SPACING );
64  this->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); // hor/vert
65 
66  combo_label = new QLabel(label);
67  hbox->addWidget(combo_label);
68  Q_CHECK_PTR( combo_label );
69 
70  combo_box = new QComboBox( this );
71  Q_CHECK_PTR( combo_box );
72  hbox->addWidget(combo_box);
73  combo_label->setBuddy( combo_box );
74  combo_box->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
75  connect( combo_box, SIGNAL( activated( int ) ),
76  this, SLOT ( showPageIndex ( int ) ) );
77 
78  widget_stack = new QStackedWidget( this );
79  Q_CHECK_PTR( widget_stack );
80  vbox->addWidget(widget_stack);
81 }
82 
83 
84 
86 {
87 
88 }
89 
90 
91 void
92 QY2ComboTabWidget::addPage( const QString & page_label, QWidget * new_page )
93 {
94  pages.insert( combo_box->count(), new_page );
95  combo_box->addItem( page_label );
96  widget_stack->addWidget( new_page );
97 
98  if ( ! widget_stack->currentWidget() )
99  widget_stack->setCurrentWidget( new_page );
100 }
101 
102 
103 void
105 {
106  if ( pages.contains(index) )
107  {
108  QWidget * page = pages[ index ];
109  widget_stack->setCurrentWidget( page );
110  // yuiDebug() << "Changing current page" << std::endl;
111  emit currentChanged( page );
112  }
113  else
114  {
115  qWarning( "QY2ComboTabWidget: Page #%d not found", index );
116  return;
117  }
118 }
119 
120 
121 void
123 {
124  widget_stack->setCurrentWidget( page );
125 
126  if ( page == pages[ combo_box->currentIndex() ] )
127  {
128  // Shortcut: If the requested page is the one that belongs to the item
129  // currently selected in the combo box, don't bother searching the
130  // correct combo box item.
131  return;
132  }
133 
134  // Search the dict for this page
135 
136  QHashIterator<int, QWidget *> it( pages );
137 
138  while ( it.hasNext() )
139  {
140  it.next();
141  if ( page == it.value() )
142  {
143  combo_box->setCurrentIndex( it.key() );
144  return;
145  }
146  }
147 
148  // If we come this far, that page isn't present in the dict.
149 
150  qWarning( "QY2ComboTabWidget: Page not found" );
151 }
152 
153 
154 
155 #include "QY2ComboTabWidget.moc"
void showPage(QWidget *page)
void showPageIndex(int index)
void addPage(const QString &page_label, QWidget *page)
virtual ~QY2ComboTabWidget()
void currentChanged(QWidget *newCurrentPage)
QY2ComboTabWidget(const QString &combo_box_label, QWidget *parent=0, const char *name=0)