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.
24 #include <QStackedWidget>
25 #include <QHBoxLayout>
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,
45 QHBoxLayout *hbox = new QHBoxLayout(this);
46 // hbox->setFrameStyle( QFrame::Panel | QFrame::Raised );
47 // hbox->setLineWidth(2);
48 // hbox->setMidLineWidth(2);
49 hbox->setSpacing( SPACING );
50 hbox->setMargin ( MARGIN );
53 //this->setSpacing( SPACING );
54 this->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
57 combo_label = new QLabel(label);
58 hbox->addWidget(combo_label);
59 Q_CHECK_PTR( combo_label );
61 combo_box = new QComboBox( this );
62 Q_CHECK_PTR( combo_box );
63 hbox->addWidget(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 QStackedWidget( 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->currentWidget() )
89 widget_stack->setCurrentWidget( new_page );
94 QY2ComboTabWidget::showPage( int index )
96 QWidget * page = pages[ index ];
100 widget_stack->setCurrentWidget( 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->setCurrentWidget( 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 QHashIterator<int, QWidget *> it( pages );
130 while ( it.hasNext() )
132 if ( page == it.value() )
134 combo_box->setCurrentIndex( it.key() );
141 // If we come this far, that page isn't present in the dict.
143 qWarning( "QY2ComboTabWidget: Page not found" );
148 #include "QY2ComboTabWidget.moc"