TabButton * TabBar::addTab( QWidget * _w, const QString & _text, int _id, bool _add_stretch, bool _text_is_tooltip ) { // already tab with id? if( m_tabs.contains( _id ) ) { // then remove it removeTab( _id ); } QString caption = ( _text_is_tooltip ) ? QString( "" ) : _text; // create tab-button TabButton * b = new TabButton( caption, _id, this ); connect( b, SIGNAL( clicked( int ) ), this, SLOT( tabClicked( int ) ) ); b->setIconSize( QSize( 48, 48 ) ); b->setFixedSize( 64, 64 ); b->show(); if( _text_is_tooltip ) { ToolTip::add( b, _text ); } // small workaround, because QBoxLayout::addWidget(...) doesn't // work properly, so we first have to remove all tabs from the // layout and them add them in the correct order QMap<int, QPair<TabButton *, QWidget *> >::iterator it; for( it = m_tabs.begin(); it != m_tabs.end(); ++it ) { m_layout->removeWidget( it.value().first ); } m_tabs.insert( _id, qMakePair( b, _w ) ); for( it = m_tabs.begin(); it != m_tabs.end(); ++it ) { m_layout->addWidget( it.value().first ); } if( _add_stretch ) { m_layout->addStretch(); } // we assume, parent-widget is a widget acting as widget-stack so all // widgets have the same size and only the one on the top is visible _w->setFixedSize( _w->parentWidget()->size() ); b->setFont( pointSize<8>( b->font() ) ); return( b ); }
/************************************************************************* Add tab button *************************************************************************/ void TabControl::addButtonForTabContent(Window* wnd) { // Create the button TabButton* tb = createTabButton(makeButtonName(wnd)); // Copy font tb->setFont(getFont()); // Set target window tb->setTargetWindow(wnd); // Instert into map d_tabButtonVector.push_back(tb); // add the button getTabButtonPane()->addChildWindow(tb); // Subscribe to clicked event so that we can change tab tb->subscribeEvent(TabButton::EventClicked, Event::Subscriber(&TabControl::handleTabButtonClicked, this)); tb->subscribeEvent(TabButton::EventDragged, Event::Subscriber(&TabControl::handleDraggedPane, this)); tb->subscribeEvent(TabButton::EventScrolled, Event::Subscriber(&TabControl::handleWheeledPane, this)); }
/************************************************************************* Add tab button *************************************************************************/ void TabControl::addButtonForTabContent(Window* wnd) { // Create the button TabButton* tb = createTabButton(makeButtonName(wnd)); // Copy font tb->setFont(getFont()); // Set target window tb->setTargetWindow(wnd); // Set index tb->setTabIndex(d_nextTabIndex++); // Instert into map d_tabButtonIndexMap.insert( TabButtonIndexMap::value_type(tb->getTabIndex(), tb)); // add the button d_tabButtonPane->addChildWindow(tb); // Subscribe to clicked event so that we can change tab tb->subscribeEvent(TabButton::EventClicked, Event::Subscriber(&TabControl::handleTabButtonClicked, this)); }