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
49 : QWidget( (QWidget *) parent->widgetRep() )
58 _tabBar =
new QTabBar(
this );
59 Q_CHECK_PTR( _tabBar );
61 _tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
62 setFocusProxy( _tabBar );
63 setFocusPolicy( Qt::TabFocus );
65 connect( _tabBar, &pclass(_tabBar)::currentChanged,
80 YDumbTab::addItem( item );
82 _tabBar->insertTab( item->index(), fromUTF8( item->label() ) );
83 yuiDebug() <<
"Adding tab page [" << item->label() <<
"]" << endl;
85 if ( item->selected() )
86 _tabBar->setCurrentIndex( item->index() );
98 _tabBar->setCurrentIndex( item->index() );
101 YDumbTab::selectItem( item, selected );
108 for ( YItemConstIterator it = itemsBegin();
112 _tabBar->removeTab( ( *it )->index() );
115 YDumbTab::deleteAllItems();
122 YDumbTab::deselectAllItems();
129 YItem * item = itemAt( index );
130 YUI_CHECK_PTR( item );
131 yuiDebug() <<
"Tab [" << item->label() <<
"] selected" << endl;
132 YDumbTab::selectItem( item );
144 for ( YItemConstIterator it = itemsBegin();
149 _tabBar->setTabText( item->index(), fromUTF8( item->label() ) );
157 _tabBar->setEnabled( enabled );
158 YWidget::setEnabled( enabled );
165 int tabBarWidth = _tabBar->sizeHint().width();
166 int childWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
168 return std::max( tabBarWidth, childWidth );
175 int tabBarHeight = _tabBar->sizeHint().height();
176 int childHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
178 return tabBarHeight + YQDumbTabSpacing + childHeight;
185 QWidget::resize( newWidth, newHeight );
186 int remainingHeight = newHeight;
187 int remainingWidth = newWidth;
195 int tabBarHeight = _tabBar->sizeHint().height();
197 if ( remainingHeight < tabBarHeight )
198 tabBarHeight = remainingHeight;
200 _tabBar->resize( newWidth, tabBarHeight );
201 remainingHeight -= tabBarHeight;
209 remainingHeight -= YQDumbTabSpacing;
210 y_offset = newHeight - remainingHeight;
216 remainingHeight -= 2 * YQDumbTabFrameMargin;
217 remainingWidth -= 2 * YQDumbTabFrameMargin;
218 x_offset += YQDumbTabFrameMargin;
219 y_offset += YQDumbTabFrameMargin;
221 if ( remainingHeight < 0 )
224 if ( remainingWidth < 0 )
232 firstChild()->setSize( remainingWidth, remainingHeight );
234 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
235 qChild->move( x_offset, y_offset );
YQDumbTab(YWidget *parent)
Constructor.
virtual int preferredHeight()
Preferred height of the widget.
virtual void shortcutChanged()
Notification that some shortcut was changed.
virtual int preferredWidth()
Preferred width of the widget.
virtual void deleteAllItems()
Delete all items (all tab pages).
virtual void activate()
Activate selected tab.
virtual ~YQDumbTab()
Destructor.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
void slotSelected(int index)
Send an event that the tab with the specified index is selected.
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
virtual void addItem(YItem *item)
Add an item (a tab page).
virtual void deselectAllItems()
Deselect all items.
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
static YQUI * ui()
Access the global Qt-UI.
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...