void TabControl::OnTabPressed( Controls::Base* control ) { TabButton* pButton = gwen_cast<TabButton>(control); if ( !pButton ) return; Base* pPage = pButton->GetPage(); if ( !pPage ) return; if ( m_pCurrentButton == pButton) return; if ( m_pCurrentButton ) { Base* pPage = m_pCurrentButton->GetPage(); if ( pPage ) { pPage->SetHidden( true ); } m_pCurrentButton->Redraw(); m_pCurrentButton = NULL; } m_pCurrentButton = pButton; pPage->SetHidden( false ); m_TabStrip->Invalidate(); Invalidate(); }
/************************************************************************* Select tab implementation *************************************************************************/ void TabControl::selectTab_impl(Window* wnd) { bool modified = false; bool foundSelected = false; // Iterate in order of tab index TabButtonIndexMap::iterator i, iend; iend = d_tabButtonIndexMap.end(); for (i = d_tabButtonIndexMap.begin(); i != iend; ++i) { // get corresponding tab button and content window TabButton* tb = i->second; Window* child = tb->getTargetWindow(); // Should we be selecting? bool selectThis = (child == wnd); // Are we modifying this tab? modified = modified || (tb->isSelected() != selectThis); foundSelected = foundSelected || selectThis; // Select tab & set visible if this is the window, not otherwise tb->setSelected(selectThis); tb->setRightOfSelected(foundSelected); child->setVisible(selectThis); } // Trigger event? if (modified) { WindowEventArgs args(this); onSelectionChanged(args); } }
void TabControl::OnTabPressed( Controls::Base* control ) { if (!control) return; TabButton* pButton = control->DynamicCastTabButton(); if ( !pButton ) return; Base* pPage = pButton->GetPage(); if ( !pPage ) return; if ( m_pCurrentButton == pButton) return; if ( m_pCurrentButton ) { Base* pPage = m_pCurrentButton->GetPage(); if ( pPage ) { pPage->SetHidden( true ); } m_pCurrentButton = NULL; } m_pCurrentButton = pButton; pPage->SetHidden( false ); m_TabStrip->Invalidate(); Invalidate(); }
/************************************************************************* Select tab implementation *************************************************************************/ void TabControl::selectTab_impl(Window* wnd) { makeTabVisible_impl(wnd); bool modified = false; // Iterate in order of tab index for (size_t i = 0; i < d_tabButtonVector.size(); ++i) { // get corresponding tab button and content window TabButton* tb = d_tabButtonVector [i]; Window* child = tb->getTargetWindow(); // Should we be selecting? bool selectThis = (child == wnd); // Are we modifying this tab? modified = modified || (tb->isSelected() != selectThis); // Select tab & set visible if this is the window, not otherwise tb->setSelected(selectThis); child->setVisible(selectThis); } // Trigger event? if (modified) { WindowEventArgs args(this); onSelectionChanged(args); } }
bool TabStrip::DragAndDrop_HandleDrop(Gwen::DragAndDrop::Package* /*pPackage*/, int x, int y) { Gwen::Point LocalPos = CanvasPosToLocal(Gwen::Point(x, y)); Base* el = DragAndDrop::SourceControl; TabButton* pButton = el ? el->DynamicCastTabButton() : 0; TabControl* pTabControl = GetParent() ? GetParent()->DynamicCastTabControl() : 0; if (pTabControl && pButton) { if (pButton->GetTabControl() != pTabControl) { // We've moved tab controls! pTabControl->AddPage(pButton); } } Base* DroppedOn = GetControlAt(LocalPos.x, LocalPos.y); if (DroppedOn) { Gwen::Point DropPos = DroppedOn->CanvasPosToLocal(Gwen::Point(x, y)); DragAndDrop::SourceControl->BringNextToControl(DroppedOn, DropPos.x > DroppedOn->Width() / 2); } else { DragAndDrop::SourceControl->BringToFront(); } return true; }
/************************************************************************* Tab button clicked *************************************************************************/ bool TabControl::handleTabButtonClicked(const EventArgs& args) { const WindowEventArgs& wargs = static_cast<const WindowEventArgs&>(args); TabButton* tabButton = static_cast<TabButton*>(wargs.window); setSelectedTab(tabButton->getTargetWindow()->getName()); return true; }
TabButton* Toolbar::addButton(const QPixmap& _icon) { TabButton* button = new TabButton(this); button->setImage(_icon); addButton(button); return button; }
/************************************************************************* Remove tab button *************************************************************************/ void TabControl::removeButtonForTabContent(Window* wnd) { // get TabButton* tb = static_cast<TabButton*>( d_tabButtonPane->getChild(makeButtonName(wnd))); // remove d_tabButtonIndexMap.erase(tb->getTabIndex()); d_tabButtonPane->removeChildWindow(tb); // destroy WindowManager::getSingleton().destroyWindow(tb); }
/************************************************************************* Make tab visible implementation *************************************************************************/ void TabControl::makeTabVisible_impl(Window* wnd) { TabButton *tb = 0; for (size_t i = 0; i < d_tabButtonVector.size (); ++i) { // get corresponding tab button and content window tb = d_tabButtonVector [i]; Window* child = tb->getTargetWindow(); if (child == wnd) break; tb = 0; } if (!tb) return; float ww = getPixelSize ().d_width; float x = tb->getXPosition().asAbsolute (ww); float w = tb->getPixelSize ().d_width; float lx = 0, rx = ww; Window *scrollLeftBtn = 0, *scrollRightBtn = 0; String name = getName() + ButtonScrollLeftSuffix; if (WindowManager::getSingleton().isWindowPresent (name)) { scrollLeftBtn = WindowManager::getSingleton().getWindow (name); lx = scrollLeftBtn->getArea ().d_max.d_x.asAbsolute (ww); scrollLeftBtn->setWantsMultiClickEvents (false); } name = getName() + ButtonScrollRightSuffix; if (WindowManager::getSingleton().isWindowPresent (name)) { scrollRightBtn = WindowManager::getSingleton().getWindow (name); rx = scrollRightBtn->getXPosition ().asAbsolute (ww); scrollRightBtn->setWantsMultiClickEvents (false); } if (x < lx) d_firstTabOffset += lx - x; else { if (x + w <= rx) return; // nothing to do d_firstTabOffset += rx - (x + w); } performChildWindowLayout (); }
void FalagardTabButton::render() { TabButton* w = static_cast<TabButton*>(d_window); // get WidgetLookFeel for the assigned look. const WidgetLookFeel& wlf = getLookNFeel(); TabControl* tc = w->getParent() ? dynamic_cast<TabControl*>(w->getParent()->getParent()) : 0; String prefix((tc && tc->getTabPanePosition() == TabControl::Bottom) ? "Bottom" : "Top"); String state; if (w->isEffectiveDisabled()) state = "Disabled"; else if (w->isSelected()) state = "Selected"; else if (w->isPushed()) state = "Pushed"; else if (w->isHovering()) state = "Hover"; else if (w->isFocused()) state = "Focused"; else state = "Normal"; if (!wlf.isStateImageryPresent(prefix + state)) { state = "Normal"; if (!wlf.isStateImageryPresent(prefix + state)) prefix = ""; } wlf.getStateImagery(prefix + state).render(*w); }
void TabStrip::Layout( Skin::Base* skin ) { Gwen::Point pLargestTab( 5, 5 ); int iNum = 0; for ( Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter ) { TabButton* pButton = gwen_cast<TabButton>(*iter); if ( !pButton ) continue; pButton->SizeToContents(); Margin m; int iNotFirst = iNum > 0 ? -1 : 0; if ( m_iDock == Pos::Top ) { m.left = iNotFirst; pButton->Dock( Pos::Left ); } if ( m_iDock == Pos::Left ) { m.top = iNotFirst; pButton->Dock( Pos::Top ); } if ( m_iDock == Pos::Right ) { m.top = iNotFirst; pButton->Dock( Pos::Top ); } if ( m_iDock == Pos::Bottom ) { m.left = iNotFirst; pButton->Dock( Pos::Left ); } pLargestTab.x = Utility::Max( pLargestTab.x, pButton->Width() ); pLargestTab.y = Utility::Max( pLargestTab.y, pButton->Height() ); pButton->SetMargin( m ); iNum++; } if ( m_iDock == Pos::Top || m_iDock == Pos::Bottom ) SetSize( Width(), pLargestTab.y ); if ( m_iDock == Pos::Left || m_iDock == Pos::Right ) SetSize( pLargestTab.x, Height() ); BaseClass::Layout( skin ); }
bool TabBar::AddButton(const int id, const QString & title, const QIcon & icon) { TabButton * button = new TabButton(this, id); button->setText(title); button->setIcon(icon); layout_.addWidget(button); buttons_.push_back(button); connect(button, SIGNAL(clicked(const int, bool)), this, SLOT(OnClicked(const int, bool))); return true; }
/************************************************************************* Return the tab button for the given tab content window *************************************************************************/ TabButton* TabControl::getButtonForTabContents(Window* wnd) const { TabButtonIndexMap::const_iterator i, iend; iend = d_tabButtonIndexMap.end(); for (i = d_tabButtonIndexMap.begin(); i != iend; ++i) { // get corresponding tab button and content window TabButton* tb = i->second; Window* child = tb->getTargetWindow(); if (child == wnd) { return tb; } } throw UnknownObjectException((utf8*)"TabControl::getButtonForTabContents - The Window object is not a tab contents."); }
/************************************************************************* Return whether the tab content window is currently selected. *************************************************************************/ uint TabControl::getSelectedTabIndex() const { uint index; TabButtonIndexMap::const_iterator i, iend; iend = d_tabButtonIndexMap.end(); for (i = d_tabButtonIndexMap.begin(); i != iend; ++i) { // get corresponding tab button and content window TabButton* tb = i->second; if (tb->isSelected()) { index = i->first; break; } } return index; }
TabButton* TabControl::AddPage( TextObject strText, Controls::Base* pPage ) { if ( !pPage ) { pPage = new Base( this ); } else { pPage->SetParent( this ); } TabButton* pButton = new TabButton( m_TabStrip ); pButton->SetText( strText ); pButton->SetPage( pPage ); pButton->SetTabable( false ); AddPage( pButton ); return pButton; }
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); // 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)); }
/************************************************************************* 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)); }
TabWidget::TabWidget( QWidget* parent ) { qDebug() << "[TABWIDGET] Constructing"; mGrabbedWidget = 0; mTabs = 0; // set the tab position setTabsPosition(); mStatusBar = &mStatusBar->getInstance(); // create the tabbar mBar = new TabBar; setTabBar( mBar ); // connect the mouse clicks connect( mBar, SIGNAL( tabRightClicked( int, QPoint ) ), this, SLOT( tabRightClicked( int, QPoint ) ) ); connect( mBar, SIGNAL( tabMiddleClicked( int, QPoint ) ), this, SLOT( tabMiddleClicked( int, QPoint ) ) ); TabButton* newTabButton = new TabButton( this ); TabButton* mMenuButton = new TabButton( this ); connect( newTabButton, SIGNAL( clicked() ), this, SLOT( addUnityBrowser()) ); connect( newTabButton, SIGNAL( middleClicked() ), this, SLOT( addUnityBrowserWithSR() ) ); connect( mMenuButton, SIGNAL( clicked() ), mMenuButton, SLOT( showMenu()) ); mMenuButton->setMenu( kueueMainMenu() ); newTabButton->setIcon( QIcon( ":icons/menus/newtab.png" ) ); mMenuButton->setIcon( QIcon(":/icons/kueue.png") ); if ( Settings::unityEnabled() ) { setCornerWidget( newTabButton, Qt::TopRightCorner ); } setCornerWidget( mMenuButton, Qt::TopLeftCorner ); // create the main browser tabs... mQueueBrowser = new QueueBrowser( this ); mSubownerBrowser = new SubownerBrowser( this ); mPersonalTab = new BrowserWithSearch( mQueueBrowser, this ); mSubownerTab = new BrowserWithSearch( mSubownerBrowser, this ); connect( mQueueBrowser, SIGNAL( setMenus() ), this, SLOT( setMenus() ) ); connect( mSubownerBrowser, SIGNAL( setMenus() ), this, SLOT( setMenus() ) ); connect( mQueueBrowser, SIGNAL( expandAll() ), this, SLOT( expandAllTables() ) ); connect( mQueueBrowser, SIGNAL( closeAll() ), this, SLOT( closeAllTables() ) ); mQmonBrowser = new QMonBrowser( this ); mMonitorTab = new BrowserWithSearch( mQmonBrowser, this ); mStatsBrowser = new StatsBrowser( this ); mStatsTab = new BrowserWithSearch( mStatsBrowser, this ); if ( Settings::unityEnabled() ) { addUnityBrowser(); rebuildMaps(); } mSubVisible = true; // ...and add them to the tabbar insertTab( 0, mPersonalTab, QIcon( ":icons/conf/targets.png" ), "Personal queue" ); insertTab( 1, mSubownerTab, QIcon( ":icons/conf/targets.png" ), "Subowned SRs" ); insertTab( 2, mMonitorTab, QIcon( ":/icons/conf/monitor.png" ), "Queue monitor" ); insertTab( 3, mStatsTab, QIcon( ":/icons/conf/stats.png" ), "Statistics" ); QShortcut* search = new QShortcut( QKeySequence( Qt::CTRL + Qt::Key_F ), this ); connect( search, SIGNAL( activated() ), this, SLOT( showSearch() ) ); refreshTabs(); }
void TabStrip::Layout(Skin::Base* skin) { Gwen::Point pLargestTab(5, 5); int iNum = 0; for (Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter) { if (!*iter) continue; TabButton* pButton = (*iter)->DynamicCastTabButton(); if (!pButton) continue; pButton->SizeToContents(); Margin m; int iActive = pButton->IsActive() ? 0 : 2; int iNotFirst = iNum > 0 ? -1 : 0; int iControlOverhang = -3; if (m_iDock == Pos::Top) { m.top = iActive; m.left = iNotFirst; m.bottom = iControlOverhang; pButton->Dock(Pos::Left); } if (m_iDock == Pos::Left) { m.left = iActive * 2; m.right = iControlOverhang; m.top = iNotFirst; pButton->Dock(Pos::Top); } if (m_iDock == Pos::Right) { m.right = iActive * 2; m.left = iControlOverhang; m.top = iNotFirst; pButton->Dock(Pos::Top); } if (m_iDock == Pos::Bottom) { m.bottom = iActive; m.left = iNotFirst; m.top = iControlOverhang; pButton->Dock(Pos::Left); } pLargestTab.x = Utility::Max(pLargestTab.x, pButton->Width()); pLargestTab.y = Utility::Max(pLargestTab.y, pButton->Height()); pButton->SetMargin(m); iNum++; } if (m_iDock == Pos::Top || m_iDock == Pos::Bottom) SetSize(Width(), pLargestTab.y); if (m_iDock == Pos::Left || m_iDock == Pos::Right) SetSize(pLargestTab.x, Height()); BaseClass::Layout(skin); }
/************************************************************************* Return whether the tab content window is currently selected. *************************************************************************/ bool TabControl::isTabContentsSelected(Window* wnd) const { TabButton* button = getButtonForTabContents(wnd); return button->isSelected(); }
/************************************************************************* Calculate size and position for a tab button *************************************************************************/ void TabControl::calculateTabButtonSizePosition(size_t index) { TabButton* btn = d_tabButtonVector [index]; // relative height is always 1.0 for buttons since they are embedded in a // panel of the correct height already btn->setHeight(cegui_reldim(1.0f)); btn->setYPosition(cegui_absdim(0.0f)); // x position is based on previous button if (!index) // First button btn->setXPosition(cegui_absdim(d_firstTabOffset)); else { Window* prevButton = d_tabButtonVector [index - 1]; // position is prev pos + width btn->setXPosition(prevButton->getArea().d_max.d_x); } // Width is based on font size (expressed as absolute) Font* fnt = btn->getFont(); btn->setWidth(cegui_absdim(fnt->getTextExtent(btn->getText())) + getTabTextPadding() + getTabTextPadding()); float left_x = btn->getXPosition ().d_offset; btn->setVisible ((left_x < getPixelSize ().d_width) && (left_x + btn->getPixelSize ().d_width > 0)); btn->invalidate(); }