diff options
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/Makefile.am | 3 | ||||
-rw-r--r-- | plugingui/Makefile.am.plugingui | 2 | ||||
-rw-r--r-- | plugingui/stackedwidget.cc | 12 | ||||
-rw-r--r-- | plugingui/stackedwidget.h | 4 | ||||
-rw-r--r-- | plugingui/tabbutton.cc | 49 | ||||
-rw-r--r-- | plugingui/tabbutton.h | 53 | ||||
-rw-r--r-- | plugingui/tabwidget.cc | 69 | ||||
-rw-r--r-- | plugingui/tabwidget.h | 55 | ||||
-rw-r--r-- | plugingui/widget.cc | 20 | ||||
-rw-r--r-- | plugingui/widget.h | 1 |
10 files changed, 268 insertions, 0 deletions
diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am index 21a78f8..49025c7 100644 --- a/plugingui/Makefile.am +++ b/plugingui/Makefile.am @@ -56,6 +56,9 @@ EXTRA_DIST = \ resource_data.h \ scrollbar.h \ slider.h \ + stackedwidget.h \ + tabbutton.h \ + tabwidget.h \ textedit.h \ texture.h \ texturedbox.h \ diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui index 0e48f29..42824cc 100644 --- a/plugingui/Makefile.am.plugingui +++ b/plugingui/Makefile.am.plugingui @@ -19,6 +19,8 @@ PLUGIN_GUI_SOURCES = \ $(top_srcdir)/plugingui/slider.cc \ $(top_srcdir)/plugingui/scrollbar.cc \ $(top_srcdir)/plugingui/stackedwidget.cc \ + $(top_srcdir)/plugingui/tabbutton.cc \ + $(top_srcdir)/plugingui/tabwidget.cc \ $(top_srcdir)/plugingui/textedit.cc \ $(top_srcdir)/plugingui/texture.cc \ $(top_srcdir)/plugingui/texturedbox.cc \ diff --git a/plugingui/stackedwidget.cc b/plugingui/stackedwidget.cc index 77f0f58..069e80b 100644 --- a/plugingui/stackedwidget.cc +++ b/plugingui/stackedwidget.cc @@ -32,6 +32,7 @@ namespace GUI StackedWidget::StackedWidget(Widget *parent) : Widget(parent) { + CONNECT(this, sizeChangeNotifier, this, &StackedWidget::sizeChanged); } StackedWidget::~StackedWidget() @@ -41,6 +42,7 @@ StackedWidget::~StackedWidget() void StackedWidget::addWidget(Widget *widget) { widgets.push_back(widget); + widget->reparent(this); if(currentWidget == nullptr) { @@ -91,4 +93,14 @@ void StackedWidget::setCurrentWidget(Widget *widget) currentChanged(currentWidget); } +void StackedWidget::sizeChanged(int width, int height) +{ + // Propagate size change to child: + if(currentWidget) + { + currentWidget->move(0, 0); + currentWidget->resize(width, height); + } +} + } // GUI:: diff --git a/plugingui/stackedwidget.h b/plugingui/stackedwidget.h index 903aa17..13d764b 100644 --- a/plugingui/stackedwidget.h +++ b/plugingui/stackedwidget.h @@ -62,6 +62,10 @@ public: Notifier<Widget*> currentChanged; private: + //! Callback for Widget::sizeChangeNotifier + void sizeChanged(int width, int height); + +private: Widget* currentWidget{nullptr}; std::list<Widget*> widgets; }; diff --git a/plugingui/tabbutton.cc b/plugingui/tabbutton.cc new file mode 100644 index 0000000..2a55572 --- /dev/null +++ b/plugingui/tabbutton.cc @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * tabbutton.cc + * + * Thu Nov 24 18:52:26 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "tabbutton.h" + +namespace GUI +{ + +TabButton::TabButton(Widget* parent, Widget* tabWidget) + : Button(parent) + , tabWidget(tabWidget) +{ + CONNECT(this, clickNotifier, this, &TabButton::clickHandler); +} + +Widget *TabButton::getTabWidget() +{ + return tabWidget; +} + +void TabButton::clickHandler() +{ + switchTabNotifier(tabWidget); +} + +} // GUI:: diff --git a/plugingui/tabbutton.h b/plugingui/tabbutton.h new file mode 100644 index 0000000..2f5e287 --- /dev/null +++ b/plugingui/tabbutton.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * tabbutton.h + * + * Thu Nov 24 18:52:26 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include <notifier.h> + +#include "widget.h" +#include "button.h" + +namespace GUI +{ + +class TabButton + : public Button +{ +public: + TabButton(Widget* parent, Widget* tabWidget); + + Widget *getTabWidget(); + + Notifier<Widget*> switchTabNotifier; + +private: + void clickHandler(); + + Widget* tabWidget; +}; + +} // GUI:: diff --git a/plugingui/tabwidget.cc b/plugingui/tabwidget.cc new file mode 100644 index 0000000..6988d39 --- /dev/null +++ b/plugingui/tabwidget.cc @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * tabwidget.cc + * + * Thu Nov 24 17:46:22 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "tabwidget.h" + +namespace GUI +{ + +TabWidget::TabWidget(Widget *parent) + : Widget(parent) + , stack(this) +{ + CONNECT(this, sizeChangeNotifier, this, &TabWidget::sizeChanged); +} + +void TabWidget::addTab(const std::string& title, Widget* widget) +{ + buttons.emplace_back(this, widget); + auto& button = buttons.back(); + button.setText(title); + stack.addWidget(widget); + CONNECT(&button, switchTabNotifier, this, &TabWidget::switchTab); + sizeChanged(width(), height()); +} + +void TabWidget::switchTab(Widget* tabWidget) +{ + stack.setCurrentWidget(tabWidget); +} + +void TabWidget::sizeChanged(int width, int height) +{ + std::size_t pos = 0; + std::size_t buttonWidth = width / buttons.size(); + for(auto& button : buttons) + { + button.resize(buttonWidth, 40); + button.move(pos, 0); + pos += buttonWidth; + } + + stack.move(0, 40); + stack.resize(width, height - 40); +} + +} // GUI:: diff --git a/plugingui/tabwidget.h b/plugingui/tabwidget.h new file mode 100644 index 0000000..4a9cba2 --- /dev/null +++ b/plugingui/tabwidget.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * tabwidget.h + * + * Thu Nov 24 17:46:22 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo 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 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include "widget.h" +#include "tabbutton.h" +#include "stackedwidget.h" + +namespace GUI +{ + +class TabWidget + : public Widget +{ +public: + TabWidget(Widget *parent); + + void addTab(const std::string& title, Widget* widget); + +private: + //! Callback for Widget::sizeChangeNotifier + void sizeChanged(int width, int height); + +private: + void switchTab(Widget* tabWidget); + + std::list<TabButton> buttons; + StackedWidget stack; +}; + +} // GUI:: diff --git a/plugingui/widget.cc b/plugingui/widget.cc index 3d9d47c..4b1d1f7 100644 --- a/plugingui/widget.cc +++ b/plugingui/widget.cc @@ -92,6 +92,26 @@ void Widget::removeChild(Widget* widget) } } +void Widget::reparent(Widget* parent) +{ + if(parent == this->parent) + { + return; // Already at the right parent. + } + + if(this->parent) + { + this->parent->removeChild(this); + } + + if(parent) + { + parent->addChild(this); + } + + this->parent = parent; +} + void Widget::resize(int width, int height) { if((width < 1) || (height < 1) || diff --git a/plugingui/widget.h b/plugingui/widget.h index 26070c5..03e8ab0 100644 --- a/plugingui/widget.h +++ b/plugingui/widget.h @@ -74,6 +74,7 @@ public: void addChild(Widget* widget); void removeChild(Widget* widget); + void reparent(Widget* parent); virtual void repaintEvent(RepaintEvent* repaintEvent) {} virtual void mouseMoveEvent(MouseMoveEvent* mouseMoveEvent) {} |