26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
31 #include <qdrawutil.h>
34 #include "YQSignalBlocker.h"
37 #include "YQDumbTab.h"
38 #include "YQAlignment.h"
39 #include <yui/YEvent.h>
41 #define YQDumbTabSpacing 2
42 #define YQDumbTabFrameMargin 2
46 : QWidget( (QWidget *) parent->widgetRep() )
55 _tabBar =
new QTabBar(
this );
56 Q_CHECK_PTR( _tabBar );
58 _tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
59 setFocusProxy( _tabBar );
60 setFocusPolicy( Qt::TabFocus );
62 connect( _tabBar, &pclass(_tabBar)::currentChanged,
77 YDumbTab::addItem( item );
79 _tabBar->insertTab( item->index(), fromUTF8( item->label() ) );
80 yuiDebug() <<
"Adding tab page [" << item->label() <<
"]" << std::endl;
82 if ( item->selected() )
83 _tabBar->setCurrentIndex( item->index() );
95 _tabBar->setCurrentIndex( item->index() );
98 YDumbTab::selectItem( item, selected );
105 for ( YItemConstIterator it = itemsBegin();
109 _tabBar->removeTab( ( *it )->index() );
112 YDumbTab::deleteAllItems();
119 YDumbTab::deselectAllItems();
126 YItem * item = itemAt( index );
127 YUI_CHECK_PTR( item );
128 yuiDebug() <<
"Tab [" << item->label() <<
"] selected" << std::endl;
129 YDumbTab::selectItem( item );
141 for ( YItemConstIterator it = itemsBegin();
146 _tabBar->setTabText( item->index(), fromUTF8( item->label() ) );
154 _tabBar->setEnabled( enabled );
155 YWidget::setEnabled( enabled );
162 int tabBarWidth = _tabBar->sizeHint().width();
163 int childWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
165 return std::max( tabBarWidth, childWidth );
172 int tabBarHeight = _tabBar->sizeHint().height();
173 int childHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
175 return tabBarHeight + YQDumbTabSpacing + childHeight;
182 QWidget::resize( newWidth, newHeight );
183 int remainingHeight = newHeight;
184 int remainingWidth = newWidth;
192 int tabBarHeight = _tabBar->sizeHint().height();
194 if ( remainingHeight < tabBarHeight )
195 tabBarHeight = remainingHeight;
197 _tabBar->resize( newWidth, tabBarHeight );
198 remainingHeight -= tabBarHeight;
206 remainingHeight -= YQDumbTabSpacing;
207 y_offset = newHeight - remainingHeight;
213 remainingHeight -= 2 * YQDumbTabFrameMargin;
214 remainingWidth -= 2 * YQDumbTabFrameMargin;
215 x_offset += YQDumbTabFrameMargin;
216 y_offset += YQDumbTabFrameMargin;
218 if ( remainingHeight < 0 )
221 if ( remainingWidth < 0 )
229 firstChild()->setSize( remainingWidth, remainingHeight );
231 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
232 qChild->move( x_offset, y_offset );
238 #include "YQDumbTab.moc"
virtual void addItem(YItem *item)
Add an item (a tab page).
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
virtual void deleteAllItems()
Delete all items (all tab pages).
YQDumbTab(YWidget *parent)
Constructor.
void slotSelected(int index)
Send an event that the tab with the specified index is selected.
virtual int preferredHeight()
Preferred height of the widget.
virtual ~YQDumbTab()
Destructor.
virtual void shortcutChanged()
Notification that some shortcut was changed.
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual int preferredWidth()
Preferred width of the widget.
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
static YQUI * ui()
Access the global Qt-UI.
virtual void deselectAllItems()
Deselect all items.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.