]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/QY2ComboTabWidget.cc
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / QY2ComboTabWidget.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                          contributed Qt widgets                      |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       QY2ComboTabWidget.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   This is a pure Qt widget - it can be used independently of YaST2.
18
19 /-*/
20
21
22 #include <q3hbox.h>
23 #include <qcombobox.h>
24 #include <qlabel.h>
25 #include <q3widgetstack.h>
26 //Added by qt3to4:
27 #include <q3frame.h>
28
29 #define y2log_component "qt-pkg"
30 #include <ycp/y2log.h>
31
32 #include "QY2ComboTabWidget.h"
33
34
35 #define SPACING                 6       // between subwidgets
36 #define MARGIN                  4       // around the widget
37
38
39
40 QY2ComboTabWidget::QY2ComboTabWidget( const QString &   label,
41                                       QWidget *         parent,
42                                       const char *      name )
43     : Q3VBox( parent, name )
44 {
45     setFrameStyle( Q3Frame::Panel | Q3Frame::Raised );
46     setLineWidth(2);
47     setMidLineWidth(2);
48     setSpacing( SPACING );
49     setMargin ( MARGIN  );
50
51     
52     Q3HBox * hbox = new Q3HBox( this );
53     Q_CHECK_PTR( hbox );
54     hbox->setSpacing( SPACING );
55     hbox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); // hor/vert
56     
57
58     combo_label = new QLabel( label, hbox );
59     Q_CHECK_PTR( combo_label );
60     
61     combo_box = new QComboBox( hbox );
62     Q_CHECK_PTR( combo_box );
63     
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 ) ) );
68     
69     widget_stack = new Q3WidgetStack( this );
70     Q_CHECK_PTR( widget_stack );
71 }
72
73
74
75 QY2ComboTabWidget::~QY2ComboTabWidget()
76 {
77     
78 }
79
80
81 void
82 QY2ComboTabWidget::addPage( const QString & page_label, QWidget * new_page )
83 {
84     pages.insert( combo_box->count(), new_page );
85     combo_box->insertItem( page_label );
86     widget_stack->addWidget( new_page );
87
88     if ( ! widget_stack->visibleWidget() )
89         widget_stack->raiseWidget( new_page );
90 }
91
92
93 void
94 QY2ComboTabWidget::showPage( int index )
95 {
96     QWidget * page = pages[ index ];
97
98     if ( page )
99     {
100         widget_stack->raiseWidget( page );
101         // y2debug( "Changing current page" );
102         emit currentChanged( page );
103     }
104     else
105     {
106         qWarning( "QY2ComboTabWidget: Page #%d not found", index );
107         return;
108     }
109 }
110
111
112 void
113 QY2ComboTabWidget::showPage( QWidget * page )
114 {
115     widget_stack->raiseWidget( page );
116
117     if ( page == pages[ combo_box->currentItem() ] )
118     {
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.
122         return;
123     }
124
125     
126     // Search the dict for this page
127     
128     Q3IntDictIterator<QWidget> it( pages );
129
130     while ( it.current() )
131     {
132         if ( page == it.current() )
133         {
134             combo_box->setCurrentItem( it.currentKey() );
135             return;
136         }
137
138         ++it;
139     }
140
141     // If we come this far, that page isn't present in the dict.
142
143     qWarning( "QY2ComboTabWidget: Page not found" );
144 }
145
146
147
148 #include "QY2ComboTabWidget.moc"