From 7cfbb8bfb1c4689dc78115931bab96d657be88be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 17 Apr 2017 12:48:41 +0200 Subject: Add version number to GUI. --- plugingui/label.cc | 23 +++++++++++++++++++---- plugingui/label.h | 8 ++++++-- plugingui/maintab.cc | 8 ++++++++ plugingui/maintab.h | 3 +++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/plugingui/label.cc b/plugingui/label.cc index 781dbca..dc5fe23 100644 --- a/plugingui/label.cc +++ b/plugingui/label.cc @@ -29,6 +29,8 @@ #include "painter.h" #include "guievent.h" +#include + namespace GUI { Label::Label(Widget *parent) @@ -47,6 +49,16 @@ void Label::setAlignment(TextAlignment alignment) this->alignment = alignment; } +void Label::setColour(Colour colour) +{ + this->colour = std::make_unique(colour); +} + +void Label::resetColour() +{ + colour.release(); +} + void Label::resizeToText() { resize(font.textWidth(_text) + border, font.textHeight()); @@ -55,11 +67,8 @@ void Label::resizeToText() void Label::repaintEvent(RepaintEvent* repaintEvent) { Painter p(*this); - p.clear(); - p.setColour(Colour(1)); - int offset = 0; switch(alignment) { case TextAlignment::left: @@ -73,7 +82,13 @@ void Label::repaintEvent(RepaintEvent* repaintEvent) break; } - p.drawText(offset, (height() + font.textHeight()) / 2, font, _text, true); + if (colour) { + p.setColour(*colour); + p.drawText(offset, (height() + font.textHeight()) / 2, font, _text); + } + else { + p.drawText(offset, (height() + font.textHeight()) / 2, font, _text, true); + } } } // GUI:: diff --git a/plugingui/label.h b/plugingui/label.h index f76a598..837f6c0 100644 --- a/plugingui/label.h +++ b/plugingui/label.h @@ -31,6 +31,7 @@ #include "font.h" #include +#include namespace GUI { @@ -46,9 +47,9 @@ public: virtual ~Label() = default; void setText(const std::string& text); - void setAlignment(TextAlignment alignment); - + void setColour(Colour colour); + void resetColour(); void resizeToText(); protected: @@ -60,6 +61,9 @@ private: Font font{":fontemboss.png"}; TextAlignment alignment{TextAlignment::left}; int border{0}; + + // optional colour + std::unique_ptr colour; }; } // GUI:: diff --git a/plugingui/maintab.cc b/plugingui/maintab.cc index a9ae9f2..9b910b8 100644 --- a/plugingui/maintab.cc +++ b/plugingui/maintab.cc @@ -26,6 +26,8 @@ */ #include "maintab.h" +#include + namespace GUI { @@ -59,6 +61,12 @@ MainTab::MainTab(Widget* parent) : Widget(parent) status_frame.setContent(&statusframe_content); humanizer_frame.setContent(&humanizerframe_content); diskstreaming_frame.setContent(&diskstreamingframe_content); + + version_label.setText("v." + std::string(VERSION) + " "); + version_label.setAlignment(TextAlignment::right); + version_label.setColour(Colour(0.1, 0.1, 0.2)); + layout.addItem(&version_label); + layout.setPosition(&version_label, GridLayout::GridRange{1, 2, 31, 32}); } } // GUI:: diff --git a/plugingui/maintab.h b/plugingui/maintab.h index 105c283..a30238c 100644 --- a/plugingui/maintab.h +++ b/plugingui/maintab.h @@ -33,6 +33,7 @@ #include "statusframecontent.h" #include "humanizerframecontent.h" #include "diskstreamingframecontent.h" +#include "label.h" namespace GUI { @@ -53,6 +54,8 @@ private: StatusframeContent statusframe_content{this}; HumanizerframeContent humanizerframe_content{this}; DiskstreamingframeContent diskstreamingframe_content{this}; + + Label version_label{this}; }; } // GUI:: -- cgit v1.2.3