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 );
54 _tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); // hor/vert
55 setFocusProxy( _tabBar );
56 setFocusPolicy( 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 QTab * tab = new QTab( fromUTF8( item->label() ) );
77 y2debug( "Adding tab page [%s]", item->label().c_str() );
79 tab->setIdentifier( item->index() );
80 _tabBar->addTab( tab );
83 if ( item->selected() )
84 _tabBar->setCurrentTab( tab );
89 YQDumbTab::selectItem( YItem * item, bool selected )
93 // Don't try to suppress any signals sent here with a YQSignalBlocker,
94 // otherwise the application code that handles the event will never be executed.
96 QTab * tab = (QTab *) item->data();
99 _tabBar->setCurrentTab( tab );
102 YDumbTab::selectItem( item, selected );
107 YQDumbTab::deleteAllItems()
109 for ( YItemConstIterator it = itemsBegin();
113 QTab * tab = (QTab *) (*it)->data();
116 _tabBar->removeTab( tab );
119 YDumbTab::deleteAllItems();
124 YQDumbTab::deselectAllItems()
126 YDumbTab::deselectAllItems();
131 YQDumbTab::slotSelected( int index )
133 YItem * item = itemAt( index );
134 YUI_CHECK_PTR( item );
135 y2debug( "Tab [%s] selected", item->label().c_str() );
138 YQUI::ui()->sendEvent( new YMenuEvent( item ) );
143 YQDumbTab::setEnabled( bool enabled )
145 _tabBar->setEnabled( enabled );
146 YWidget::setEnabled( enabled );
151 YQDumbTab::preferredWidth()
153 int tabBarWidth = _tabBar->sizeHint().width();
154 int childWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
156 return max( tabBarWidth, childWidth );
161 YQDumbTab::preferredHeight()
163 int tabBarHeight = _tabBar->sizeHint().height();
164 int childHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
166 return tabBarHeight + YQDumbTabSpacing + childHeight;
171 YQDumbTab::paintEvent( QPaintEvent * event )
173 QPainter painter( this );
176 int y_offset = _tabBar->height() + YQDumbTabSpacing;
177 int frameHeight = height() - y_offset;
178 int frameWidth = width();
180 qDrawWinPanel( &painter,
182 frameWidth, frameHeight,
185 (const QBrush *) 0 ); // brush - don't fill interior
190 YQDumbTab::setSize( int newWidth, int newHeight )
192 QWidget::resize( newWidth, newHeight );
193 int remainingHeight = newHeight;
194 int remainingWidth = newWidth;
199 // _tabBar (fixed height)
202 int tabBarHeight = _tabBar->sizeHint().height();
204 if ( remainingHeight < tabBarHeight )
205 tabBarHeight = remainingHeight;
207 _tabBar->resize( newWidth, tabBarHeight );
208 remainingHeight -= tabBarHeight;
213 // Spacing between tabBar and client area
216 remainingHeight -= YQDumbTabSpacing;
217 y_offset = newHeight - remainingHeight;
223 remainingHeight -= 2 * YQDumbTabFrameMargin;
224 remainingWidth -= 2 * YQDumbTabFrameMargin;
225 x_offset += YQDumbTabFrameMargin;
226 y_offset += YQDumbTabFrameMargin;
228 if ( remainingHeight < 0 )
231 if ( remainingWidth < 0 )
239 firstChild()->setSize( remainingWidth, remainingHeight );
241 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
242 qChild->move( x_offset, y_offset );
248 #include "YQDumbTab.moc"