summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2017-04-16 12:55:42 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2017-04-16 12:55:42 +0200
commit4317e7371e0acd39fe2ef76fc20a902f5cabdd42 (patch)
tree9d548648867647f76463c8aa425e8248e44a5002 /plugingui
parent7c074d96d8b6c93bf76bb093aab124c267287668 (diff)
Add new tabs to the main window.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/mainwindow.cc13
-rw-r--r--plugingui/mainwindow.h5
-rw-r--r--plugingui/tabwidget.cc58
-rw-r--r--plugingui/tabwidget.h13
4 files changed, 80 insertions, 9 deletions
diff --git a/plugingui/mainwindow.cc b/plugingui/mainwindow.cc
index cbc3265..b99e781 100644
--- a/plugingui/mainwindow.cc
+++ b/plugingui/mainwindow.cc
@@ -85,6 +85,8 @@ void MainWindow::repaintEvent(RepaintEvent* repaintEvent)
Painter painter(*this);
+ auto bar_height = tabs.getBarHeight();
+
// Grey background
painter.drawImageStretched(0, 0, back, width(), height());
@@ -92,10 +94,15 @@ void MainWindow::repaintEvent(RepaintEvent* repaintEvent)
painter.drawImage(width() - logo.width() - 16,
height() - logo.height(), logo);
+ // Topbar above the sidebars
+ topbar.setSize(16, bar_height);
+ painter.drawImage(0, 0, topbar);
+ painter.drawImage(width() - 16, 0, topbar);
+
// Sidebars
- sidebar.setSize(16, height());
- painter.drawImage(0, 0, sidebar);
- painter.drawImage(width() - 16, 0, sidebar);
+ sidebar.setSize(16, height() - bar_height + 1);
+ painter.drawImage(0, bar_height-1, sidebar);
+ painter.drawImage(width() - 16, bar_height-1, sidebar);
}
void MainWindow::sizeChanged(std::size_t width, std::size_t height)
diff --git a/plugingui/mainwindow.h b/plugingui/mainwindow.h
index a20f9dc..f922d4c 100644
--- a/plugingui/mainwindow.h
+++ b/plugingui/mainwindow.h
@@ -73,6 +73,11 @@ private:
16, 0, 0, // delta-x
14, 1, 14}; // delta-y
+ TexturedBox topbar{getImageCache(), ":topbar.png",
+ 0, 0, // atlas offset (x, y)
+ 1, 1, 1, // dx1, dx2, dx3
+ 17, 1, 1}; // dy1, dy2, dy3
+
bool closing{false};
Settings& settings;
diff --git a/plugingui/tabwidget.cc b/plugingui/tabwidget.cc
index 10dd996..5082b5b 100644
--- a/plugingui/tabwidget.cc
+++ b/plugingui/tabwidget.cc
@@ -26,6 +26,8 @@
*/
#include "tabwidget.h"
+#include "painter.h"
+
namespace GUI
{
@@ -34,6 +36,7 @@ TabWidget::TabWidget(Widget *parent)
, stack(this)
{
CONNECT(this, sizeChangeNotifier, this, &TabWidget::sizeChanged);
+ CONNECT(&stack, currentChanged, this, &TabWidget::setActiveButtons);
}
void TabWidget::addTab(const std::string& title, Widget* widget)
@@ -46,29 +49,72 @@ void TabWidget::addTab(const std::string& title, Widget* widget)
sizeChanged(width(), height());
}
+std::size_t TabWidget::getBarHeight() const
+{
+ return topbar.height();
+}
+
void TabWidget::switchTab(Widget* tabWidget)
{
stack.setCurrentWidget(tabWidget);
}
+void TabWidget::setActiveButtons(Widget* current_widget)
+{
+ for (auto& button : buttons) {
+ if (button.getTabWidget() == current_widget) {
+ button.setActive(true);
+ }
+ else {
+ button.setActive(false);
+ }
+ }
+}
+
void TabWidget::sizeChanged(int width, int height)
{
std::size_t pos = 0;
- std::size_t buttonWidth = 1;
+
+ std::size_t button_width = 1;
+ std::size_t bar_height = 25;
+ std::size_t button_border_width = 10;
+
+ std::size_t button_padding_left = 25;
+ std::size_t button_padding_inner = 3;
+ std::size_t logo_padding_right = button_padding_left / 2;
+
+ Painter p(*this);
+ p.clear();
+
if(buttons.size() > 0)
{
- buttonWidth = width / buttons.size();
+ for (auto& button : buttons)
+ {
+ auto min_width = button.getMinimalWidth();
+ button_width = std::max(button_width, min_width + button_border_width);
+ }
+
+ button_width = std::min(button_width, width / buttons.size());
}
+ // draw the upper bar
+ topbar.setSize(width, bar_height);
+ p.drawImage(0, 0, topbar);
+ auto x_logo = width - toplogo.width() - logo_padding_right;
+ auto y_logo = (bar_height - toplogo.height()) / 2;
+ p.drawImage(x_logo, y_logo, toplogo);
+
+ // place the buttons
+ pos = button_padding_left;
for(auto& button : buttons)
{
- button.resize(buttonWidth, 40);
+ button.resize(button_width, bar_height);
button.move(pos, 0);
- pos += buttonWidth;
+ pos += button_width + button_padding_inner;
}
- stack.move(0, 40);
- stack.resize(width, height - 40);
+ stack.move(0, bar_height);
+ stack.resize(width, height - bar_height);
}
} // GUI::
diff --git a/plugingui/tabwidget.h b/plugingui/tabwidget.h
index 5a67743..d35550f 100644
--- a/plugingui/tabwidget.h
+++ b/plugingui/tabwidget.h
@@ -29,6 +29,7 @@
#include "widget.h"
#include "tabbutton.h"
#include "stackedwidget.h"
+#include "texture.h"
namespace GUI
{
@@ -44,15 +45,27 @@ public:
//! \param widget The widget to show in the tab.
void addTab(const std::string& title, Widget* widget);
+ std::size_t getBarHeight() const;
+
private:
//! Callback for Widget::sizeChangeNotifier
void sizeChanged(int width, int height);
private:
void switchTab(Widget* tabWidget);
+ void setActiveButtons(Widget* current_widget);
std::list<TabButton> buttons;
StackedWidget stack;
+
+ TexturedBox topbar{getImageCache(), ":topbar.png",
+ 0, 0, // atlas offset (x, y)
+ 1, 1, 1, // dx1, dx2, dx3
+ 17, 1, 1}; // dy1, dy2, dy3
+
+ Texture toplogo{getImageCache(), ":toplogo.png",
+ 0, 0, // atlas offset (x, y)
+ 95, 17}; // width, height
};
} // GUI::