1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
25 #include <qdrawutil.h>
28 #include "YQSignalBlocker.h"
29 #include "QY2LayoutUtils.h"
32 #include "YQDumbTab.h"
33 #include "YQAlignment.h"
36 #define YQDumbTabSpacing 2
37 #define YQDumbTabFrameMargin 4
40 YQDumbTab::YQDumbTab( YWidget * parent )
41 : QWidget( (QWidget *) parent->widgetRep() )
45 addVSpacing( this, YQDumbTabSpacing );
51 _tabBar = new QTabBar( this );
52 Q_CHECK_PTR( _tabBar );
54 _tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); // hor/vert
55 setFocusProxy( _tabBar );
56 setFocusPolicy( Qt::TabFocus );
58 connect( _tabBar, SIGNAL( selected ( int ) ),
59 this, SLOT ( slotSelected( int ) ) );
63 YQDumbTab::~YQDumbTab()
70 YQDumbTab::addItem( YItem * item )
72 YQSignalBlocker sigBlocker( _tabBar );
73 YDumbTab::addItem( item );
75 _tabBar->insertTab( item->index(), fromUTF8( item->label() ) );
76 y2debug( "Adding tab page [%s]", item->label().c_str() );
77 #warning YItem::setData
78 // item->setData( tab );
80 if ( item->selected() )
81 _tabBar->setCurrentIndex( item->index() );
86 YQDumbTab::selectItem( YItem * item, bool selected )
90 // Don't try to suppress any signals sent here with a YQSignalBlocker,
91 // otherwise the application code that handles the event will never be executed.
93 _tabBar->setCurrentIndex( item->index() );
96 YDumbTab::selectItem( item, selected );
101 YQDumbTab::deleteAllItems()
103 for ( YItemConstIterator it = itemsBegin();
107 _tabBar->removeTab( ( *it )->index() );
110 YDumbTab::deleteAllItems();
115 YQDumbTab::deselectAllItems()
117 YDumbTab::deselectAllItems();
122 YQDumbTab::slotSelected( int index )
124 YItem * item = itemAt( index );
125 YUI_CHECK_PTR( item );
126 y2debug( "Tab [%s] selected", item->label().c_str() );
129 YQUI::ui()->sendEvent( new YMenuEvent( item ) );
134 YQDumbTab::setEnabled( bool enabled )
136 _tabBar->setEnabled( enabled );
137 YWidget::setEnabled( enabled );
142 YQDumbTab::preferredWidth()
144 int tabBarWidth = _tabBar->sizeHint().width();
145 int childWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
147 return max( tabBarWidth, childWidth );
152 YQDumbTab::preferredHeight()
154 int tabBarHeight = _tabBar->sizeHint().height();
155 int childHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
157 return tabBarHeight + YQDumbTabSpacing + childHeight;
162 YQDumbTab::paintEvent( QPaintEvent * event )
164 QPainter painter( this );
167 int y_offset = _tabBar->height() + YQDumbTabSpacing;
168 int frameHeight = height() - y_offset;
169 int frameWidth = width();
171 qDrawWinPanel( &painter,
173 frameWidth, frameHeight,
176 (const QBrush *) 0 ); // brush - don't fill interior
181 YQDumbTab::setSize( int newWidth, int newHeight )
183 QWidget::resize( newWidth, newHeight );
184 int remainingHeight = newHeight;
185 int remainingWidth = newWidth;
190 // _tabBar (fixed height)
193 int tabBarHeight = _tabBar->sizeHint().height();
195 if ( remainingHeight < tabBarHeight )
196 tabBarHeight = remainingHeight;
198 _tabBar->resize( newWidth, tabBarHeight );
199 remainingHeight -= tabBarHeight;
204 // Spacing between tabBar and client area
207 remainingHeight -= YQDumbTabSpacing;
208 y_offset = newHeight - remainingHeight;
214 remainingHeight -= 2 * YQDumbTabFrameMargin;
215 remainingWidth -= 2 * YQDumbTabFrameMargin;
216 x_offset += YQDumbTabFrameMargin;
217 y_offset += YQDumbTabFrameMargin;
219 if ( remainingHeight < 0 )
222 if ( remainingWidth < 0 )
230 firstChild()->setSize( remainingWidth, remainingHeight );
232 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
233 qChild->move( x_offset, y_offset );
239 #include "YQDumbTab.moc"