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(this);
48 QHBoxLayout *hbox = new QHBoxLayout(this);
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 ( showPage ( 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::showPage( int index )
101 QWidget * page = pages[ index ];
105 widget_stack->setCurrentWidget( page );
106 // y2debug( "Changing current page" );
107 emit currentChanged( page );
111 qWarning( "QY2ComboTabWidget: Page #%d not found", index );
118 QY2ComboTabWidget::showPage( QWidget * page )
120 widget_stack->setCurrentWidget( page );
122 if ( page == pages[ combo_box->currentIndex() ] )
124 // Shortcut: If the requested page is the one that belongs to the item
125 // currently selected in the combo box, don't bother searching the
126 // correct combo box item.
131 // Search the dict for this page
133 QHashIterator<int, QWidget *> it( pages );
135 while ( it.hasNext() )
137 if ( page == it.value() )
139 combo_box->setCurrentIndex( it.key() );
146 // If we come this far, that page isn't present in the dict.
148 qWarning( "QY2ComboTabWidget: Page not found" );
153 #include "QY2ComboTabWidget.moc"