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 QVBoxLayout *vbox = new QVBoxLayout();
48 QHBoxLayout *hbox = new QHBoxLayout();
50 // hbox->setFrameStyle( QFrame::Panel | QFrame::Raised );
51 // hbox->setLineWidth(2);
52 // hbox->setMidLineWidth(2);
53 hbox->setSpacing( SPACING );
54 hbox->setMargin ( MARGIN );
56 vbox->addLayout(hbox);
57 //this->setSpacing( SPACING );
58 this->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
61 combo_label = new QLabel(label);
62 hbox->addWidget(combo_label);
63 Q_CHECK_PTR( combo_label );
65 combo_box = new QComboBox( this );
66 Q_CHECK_PTR( combo_box );
67 hbox->addWidget(combo_box);
68 combo_label->setBuddy( combo_box );
69 combo_box->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
70 connect( combo_box, SIGNAL( activated( int ) ),
71 this, SLOT ( showPageIndex ( int ) ) );
73 widget_stack = new QStackedWidget( this );
74 Q_CHECK_PTR( widget_stack );
75 vbox->addWidget(widget_stack);
80 QY2ComboTabWidget::~QY2ComboTabWidget()
87 QY2ComboTabWidget::addPage( const QString & page_label, QWidget * new_page )
89 pages.insert( combo_box->count(), new_page );
90 combo_box->addItem( page_label );
91 widget_stack->addWidget( new_page );
93 if ( ! widget_stack->currentWidget() )
94 widget_stack->setCurrentWidget( new_page );
99 QY2ComboTabWidget::showPageIndex( int index )
101 if ( pages.contains(index) )
103 QWidget * page = pages[ index ];
104 widget_stack->setCurrentWidget( page );
105 // y2debug( "Changing current page" );
106 emit currentChanged( page );
110 qWarning( "QY2ComboTabWidget: Page #%d not found", index );
117 QY2ComboTabWidget::showPage( QWidget * page )
119 widget_stack->setCurrentWidget( page );
121 if ( page == pages[ combo_box->currentIndex() ] )
123 // Shortcut: If the requested page is the one that belongs to the item
124 // currently selected in the combo box, don't bother searching the
125 // correct combo box item.
129 // Search the dict for this page
131 QHashIterator<int, QWidget *> it( pages );
133 while ( it.hasNext() )
136 if ( page == it.value() )
138 combo_box->setCurrentIndex( it.key() );
143 // If we come this far, that page isn't present in the dict.
145 qWarning( "QY2ComboTabWidget: Page not found" );
150 #include "QY2ComboTabWidget.moc"