diff options
author | André Nusser <andre.nusser@googlemail.com> | 2017-04-17 12:48:41 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2017-04-17 12:54:16 +0200 |
commit | 7cfbb8bfb1c4689dc78115931bab96d657be88be (patch) | |
tree | 2ddb893809114920bbc3f15f6592493bdd86d7cd | |
parent | f0e8f4c95349bbc658bd73f885908b7c324dbb46 (diff) |
Add version number to GUI.
-rw-r--r-- | plugingui/label.cc | 23 | ||||
-rw-r--r-- | plugingui/label.h | 8 | ||||
-rw-r--r-- | plugingui/maintab.cc | 8 | ||||
-rw-r--r-- | 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 <cpp11fix.h> + 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>(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 <string> +#include <memory> 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> 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 <version.h> + 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:: |