Thread: [Libufo-commits] ufo-0.5/src/widgets ustackwidget.cpp,NONE,1.1 utabbar.cpp,NONE,1.1 utabwidget.cpp,N
Status: Beta
Brought to you by:
schmidtjf
|
From: Johannes S. <sch...@us...> - 2005-10-24 15:52:14
|
Update of /cvsroot/libufo/ufo-0.5/src/widgets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30102/src/widgets Modified Files: Makefile.am Added Files: ustackwidget.cpp utabbar.cpp utabwidget.cpp Log Message: Added tab widget, tab bar and stack widget. --- NEW FILE: utabwidget.cpp --- /*************************************************************************** LibUFO - UI For OpenGL copyright : (C) 2001-2005 by Johannes Schmidt email : schmidtjf at users.sourceforge.net ------------------- file : src/widgets/utabwidget.hpp begin : Sun Sep 25 2005 $Id: utabwidget.cpp,v 1.1 2005/10/24 15:52:02 schmidtjf Exp $ ***************************************************************************/ /*************************************************************************** * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "ufo/widgets/utabwidget.hpp" #include "ufo/widgets/ustackwidget.hpp" #include "ufo/widgets/utabbar.hpp" #include "ufo/layouts/uborderlayout.hpp" using namespace ufo; UFO_IMPLEMENT_CLASS(UTabWidget, UWidget) UTabWidget::UTabWidget() : m_stackWidget(new UStackWidget()) , m_tabBar(new UTabBar()) { setLayout(new UBorderLayout(0, 0)); add(m_stackWidget); add(m_tabBar, UBorderLayout::North); m_stackWidget->setBorder(LineBorder); m_tabBar->sigSelectionChanged().connect(slot(*this, &UTabWidget::slotTabSelected)); } UTabWidget::~UTabWidget() { } void UTabWidget::addTab(UWidget * child, const std::string & label) { m_stackWidget->add(child); m_tabBar->addTab(label); if (getTabCount() == 1) { setSelectedIndex(0); } } void UTabWidget::removeTab(int index) { // FIXME:: not yet implemented m_tabBar->removeTab(index); m_stackWidget->remove(index); } std::string UTabWidget::getTabText(int index) const { return m_tabBar->getTabText(index); } UWidget * UTabWidget::getTabWidget(int index) const { return m_stackWidget->getWidget(index); } int UTabWidget::getTabIndex(const std::string & label) const { return m_tabBar->getTabIndex(label); } int UTabWidget::getTabIndex(UWidget * child) const { return m_stackWidget->getIndexOf(child); } static bool ufo_is_recursive = false; void UTabWidget::setSelectedIndex(int index) { if (!ufo_is_recursive) { ufo_is_recursive = true; m_stackWidget->setSelectedIndex(index); m_tabBar->setSelectedIndex(index); ufo_is_recursive = false; } } int UTabWidget::getSelectedIndex() const { return m_stackWidget->getSelectedIndex(); } int UTabWidget::getTabCount() const { return m_stackWidget->getWidgetCount(); } void UTabWidget::slotTabSelected(UTabBar * bar) { setSelectedIndex(bar->getSelectedIndex()); } Index: Makefile.am =================================================================== RCS file: /cvsroot/libufo/ufo-0.5/src/widgets/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile.am 21 Jun 2005 09:26:40 -0000 1.13 --- Makefile.am 24 Oct 2005 15:52:02 -0000 1.14 *************** *** 30,33 **** --- 30,36 ---- widgets/uslider.cpp \ widgets/uspinbox.cpp \ + widgets/ustackwidget.cpp \ + widgets/utabbar.cpp \ + widgets/utabwidget.cpp \ widgets/utextedit.cpp \ widgets/utextwidget.cpp \ --- NEW FILE: ustackwidget.cpp --- /*************************************************************************** LibUFO - UI For OpenGL copyright : (C) 2001-2005 by Johannes Schmidt email : schmidtjf at users.sourceforge.net ------------------- file : src/widgets/ustackwidget.hpp begin : Sun Sep 25 2005 $Id: ustackwidget.cpp,v 1.1 2005/10/24 15:52:02 schmidtjf Exp $ ***************************************************************************/ /*************************************************************************** * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "ufo/widgets/ustackwidget.hpp" using namespace ufo; UFO_IMPLEMENT_CLASS(UStackWidget, UWidget) UStackWidget::UStackWidget() : m_selectedIndex(0) , m_selectionMode(1) { } UStackWidget::UStackWidget(int selectionMode) : m_selectedIndex(0) , m_selectionMode(selectionMode) { } void UStackWidget::setSelectedIndex(int index) { int count = getWidgetCount(); if (m_selectionMode && index < count && index >= 0) { UWidget * oldWidget = getWidget(m_selectedIndex); if (oldWidget) { oldWidget->setVisible(false); } m_selectedIndex = index; getWidget(m_selectedIndex)->setVisible(true); // FIXME: is this necessary? invalidate(); } } int UStackWidget::getSelectedIndex() const { return m_selectedIndex; } void UStackWidget::addImpl(UWidget * w, UObject * constraints, int index) { // stack is from bottom up // FIXME: add reverse showing attribute to UWidget /*if (index == -1) { index = 0; }*/ if (index == -1) { index = getWidgetCount(); } UWidget * oldWidget = getWidget(index); if (m_selectionMode && oldWidget) { oldWidget->setVisible(false); } UWidget::addImpl(w, constraints, index); if (m_selectionMode && index != m_selectedIndex) { w->setVisible(false); } } bool UStackWidget::removeImpl(int index) { return UWidget::removeImpl(index); } UDimension UStackWidget::getContentsSize(const UDimension & maxSize) const { UDimension ret; for (unsigned int i = 0; i < getWidgetCount(); ++i) { UWidget * w = getWidget(i); if (w) { ret.expand(w->getPreferredSize(maxSize)); } } ret.clamp(maxSize); return ret; } --- NEW FILE: utabbar.cpp --- /*************************************************************************** LibUFO - UI For OpenGL copyright : (C) 2001-2005 by Johannes Schmidt email : schmidtjf at users.sourceforge.net ------------------- file : src/widgets/utabbar.hpp begin : Mon Sep 26 2005 $Id: utabbar.cpp,v 1.1 2005/10/24 15:52:02 schmidtjf Exp $ ***************************************************************************/ /*************************************************************************** * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "ufo/widgets/utabbar.hpp" #include "ufo/widgets/ucompound.hpp" #include "ufo/events/umouseevent.hpp" #include "ufo/events/ushortcutevent.hpp" #include "ufo/layouts/uboxlayout.hpp" using namespace ufo; UFO_IMPLEMENT_CLASS(UTabBar, UWidget) class UTabBarTab : public UCompound { UFO_STYLE_TYPE(UStyle::CE_TabBarTab) public: UTabBarTab(const std::string & text) : UCompound(text) {} void deselect() { setState(WidgetSelected, false); } void select() { setState(WidgetSelected); } protected: void processMouseEvent(UMouseEvent * e) { switch (e->getType()) { case UEvent::MousePressed: if (UTabBar * bar = dynamic_cast<UTabBar*>(getParent())) { bar->setSelectedIndex(bar->getIndexOf(this)); } else { select(); } e->consume(); break; default: break; } } void processShortcutEvent(UShortcutEvent * e) { if (isEnabled()) { if (UTabBar * bar = dynamic_cast<UTabBar*>(getParent())) { bar->setSelectedIndex(bar->getIndexOf(this)); } else { select(); } e->consume(); } UWidget::processShortcutEvent(e); } UDimension getContentsSize(const UDimension & maxSize) const { UDimension ret(getStyle()->getCompoundPreferredSize( getStyleHints(), getText(), getIcon()) ); if (ret.isValid()) { ret.clamp(maxSize); return ret; } return UDimension::invalid; } }; UTabBar::UTabBar() : m_selectedIndex(-1) { setOrientation(Horizontal); setLayout(new UBoxLayout(Horizontal, 0, 0)); } UTabBar::~UTabBar() { } void UTabBar::addTab(const std::string & label) { UTabBarTab * tab = new UTabBarTab(label); add(tab); } void UTabBar::removeTab(int index) { remove(index); if (index == m_selectedIndex) { setSelectedIndex(0); } } void UTabBar::setSelectedIndex(int index) { if (index == m_selectedIndex) { return; } if (UTabBarTab * tab = dynamic_cast<UTabBarTab*>(getWidget(m_selectedIndex))) { tab->deselect(); } m_selectedIndex = index; if (UTabBarTab * tab = dynamic_cast<UTabBarTab*>(getWidget(index))) { tab->select(); } m_sigSelectionChanged(this); } int UTabBar::getSelectedIndex() const { return m_selectedIndex; } std::string UTabBar::getTabText(int index) const { if (UTabBarTab * tab = dynamic_cast<UTabBarTab*>(getWidget(index))) { return tab->getText(); } return ""; } int UTabBar::getTabIndex(const std::string & label) const { for (unsigned int i = 0; i < getWidgetCount(); ++i) { if (UTabBarTab * tab = dynamic_cast<UTabBarTab*>(getWidget(i))) { if (tab->getText() == label) { return i; } } } return -1; } int UTabBar::getTabCount() const { return getWidgetCount(); } |