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"
31 #include "YQDumbTab.h"
32 #include "YQAlignment.h"
35 #define YQDumbTabSpacing 2
36 #define YQDumbTabFrameMargin 4
39 YQDumbTab::YQDumbTab( YWidget * parent )
40 : QWidget( (QWidget *) parent->widgetRep() )
49 _tabBar = new QTabBar( this );
50 Q_CHECK_PTR( _tabBar );
52 _tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); // hor/vert
53 setFocusProxy( _tabBar );
54 setFocusPolicy( Qt::TabFocus );
56 connect( _tabBar, SIGNAL( selected ( int ) ),
57 this, SLOT ( slotSelected( int ) ) );
61 YQDumbTab::~YQDumbTab()
68 YQDumbTab::addItem( YItem * item )
70 YQSignalBlocker sigBlocker( _tabBar );
71 YDumbTab::addItem( item );
73 _tabBar->insertTab( item->index(), fromUTF8( item->label() ) );
74 y2debug( "Adding tab page [%s]", item->label().c_str() );
75 #warning YItem::setData
76 // item->setData( tab );
78 if ( item->selected() )
79 _tabBar->setCurrentIndex( item->index() );
84 YQDumbTab::selectItem( YItem * item, bool selected )
88 // Don't try to suppress any signals sent here with a YQSignalBlocker,
89 // otherwise the application code that handles the event will never be executed.
91 _tabBar->setCurrentIndex( item->index() );
94 YDumbTab::selectItem( item, selected );
99 YQDumbTab::deleteAllItems()
101 for ( YItemConstIterator it = itemsBegin();
105 _tabBar->removeTab( ( *it )->index() );
108 YDumbTab::deleteAllItems();
113 YQDumbTab::deselectAllItems()
115 YDumbTab::deselectAllItems();
120 YQDumbTab::slotSelected( int index )
122 YItem * item = itemAt( index );
123 YUI_CHECK_PTR( item );
124 y2debug( "Tab [%s] selected", item->label().c_str() );
127 YQUI::ui()->sendEvent( new YMenuEvent( item ) );
132 YQDumbTab::setEnabled( bool enabled )
134 _tabBar->setEnabled( enabled );
135 YWidget::setEnabled( enabled );
140 YQDumbTab::preferredWidth()
142 int tabBarWidth = _tabBar->sizeHint().width();
143 int childWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
145 return max( tabBarWidth, childWidth );
150 YQDumbTab::preferredHeight()
152 int tabBarHeight = _tabBar->sizeHint().height();
153 int childHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
155 return tabBarHeight + YQDumbTabSpacing + childHeight;
160 YQDumbTab::paintEvent( QPaintEvent * event )
162 QPainter painter( this );
165 int y_offset = _tabBar->height() + YQDumbTabSpacing;
166 int frameHeight = height() - y_offset;
167 int frameWidth = width();
169 qDrawWinPanel( &painter,
171 frameWidth, frameHeight,
174 (const QBrush *) 0 ); // brush - don't fill interior
179 YQDumbTab::setSize( int newWidth, int newHeight )
181 QWidget::resize( newWidth, newHeight );
182 int remainingHeight = newHeight;
183 int remainingWidth = newWidth;
188 // _tabBar (fixed height)
191 int tabBarHeight = _tabBar->sizeHint().height();
193 if ( remainingHeight < tabBarHeight )
194 tabBarHeight = remainingHeight;
196 _tabBar->resize( newWidth, tabBarHeight );
197 remainingHeight -= tabBarHeight;
202 // Spacing between tabBar and client area
205 remainingHeight -= YQDumbTabSpacing;
206 y_offset = newHeight - remainingHeight;
212 remainingHeight -= 2 * YQDumbTabFrameMargin;
213 remainingWidth -= 2 * YQDumbTabFrameMargin;
214 x_offset += YQDumbTabFrameMargin;
215 y_offset += YQDumbTabFrameMargin;
217 if ( remainingHeight < 0 )
220 if ( remainingWidth < 0 )
228 firstChild()->setSize( remainingWidth, remainingHeight );
230 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
231 qChild->move( x_offset, y_offset );
237 #include "YQDumbTab.moc"