1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
9 | contributed Qt widgets |
11 \----------------------------------------------------------------------/
13 File: QY2ComboTabWidget.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 This is a pure Qt widget - it can be used independently of YaST2.
23 #include <qcombobox.h>
25 #include <q3widgetstack.h>
29 #define y2log_component "qt-pkg"
30 #include <ycp/y2log.h>
32 #include "QY2ComboTabWidget.h"
35 #define SPACING 6 // between subwidgets
36 #define MARGIN 4 // around the widget
40 QY2ComboTabWidget::QY2ComboTabWidget( const QString & label,
43 : Q3VBox( parent, name )
45 setFrameStyle( Q3Frame::Panel | Q3Frame::Raised );
48 setSpacing( SPACING );
52 Q3HBox * hbox = new Q3HBox( this );
54 hbox->setSpacing( SPACING );
55 hbox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
58 combo_label = new QLabel( label, hbox );
59 Q_CHECK_PTR( combo_label );
61 combo_box = new QComboBox( hbox );
62 Q_CHECK_PTR( combo_box );
64 combo_label->setBuddy( combo_box );
65 combo_box->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
66 connect( combo_box, SIGNAL( activated( int ) ),
67 this, SLOT ( showPage ( int ) ) );
69 widget_stack = new Q3WidgetStack( this );
70 Q_CHECK_PTR( widget_stack );
75 QY2ComboTabWidget::~QY2ComboTabWidget()
82 QY2ComboTabWidget::addPage( const QString & page_label, QWidget * new_page )
84 pages.insert( combo_box->count(), new_page );
85 combo_box->addItem( page_label );
86 widget_stack->addWidget( new_page );
88 if ( ! widget_stack->visibleWidget() )
89 widget_stack->raiseWidget( new_page );
94 QY2ComboTabWidget::showPage( int index )
96 QWidget * page = pages[ index ];
100 widget_stack->raiseWidget( page );
101 // y2debug( "Changing current page" );
102 emit currentChanged( page );
106 qWarning( "QY2ComboTabWidget: Page #%d not found", index );
113 QY2ComboTabWidget::showPage( QWidget * page )
115 widget_stack->raiseWidget( page );
117 if ( page == pages[ combo_box->currentIndex() ] )
119 // Shortcut: If the requested page is the one that belongs to the item
120 // currently selected in the combo box, don't bother searching the
121 // correct combo box item.
126 // Search the dict for this page
128 Q3IntDictIterator<QWidget> it( pages );
130 while ( it.current() )
132 if ( page == it.current() )
134 combo_box->setCurrentIndex( it.currentKey() );
141 // If we come this far, that page isn't present in the dict.
143 qWarning( "QY2ComboTabWidget: Page not found" );
148 #include "QY2ComboTabWidget.moc"