summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugingui/abouttab.cc96
1 files changed, 50 insertions, 46 deletions
diff --git a/plugingui/abouttab.cc b/plugingui/abouttab.cc
index 7e330cb..a04fac2 100644
--- a/plugingui/abouttab.cc
+++ b/plugingui/abouttab.cc
@@ -33,6 +33,48 @@
namespace GUI
{
+//!Simple helper class to avoid direct repeats of text manipulation.
+class AboutTextBuilder {
+public:
+ //!Class constructor. Sets the separator character.
+ AboutTextBuilder(char _separator='=')
+ :separator_character(_separator)
+ {
+ }
+
+ //!Adds a new section to the "about" text with the given title and contents.
+ //!Returns a reference to the builder so more calls can be chained.
+ AboutTextBuilder& add(const std::string& _title, const std::string& _contents)
+ {
+ auto repeat=[](std::string& _str, char _fill, size_t _count)
+ {
+ _str.insert(_str.size(), _count, _fill);
+ };
+
+ repeat(about_text, separator_character, separator_count);
+ about_text+="\n";
+ repeat(about_text, ' ', space_count);
+ about_text+=_title+"\n";
+ repeat(about_text, separator_character, separator_count);
+ repeat(about_text, '\n', 3);
+ about_text+=_contents+"\n";
+
+ return *this;
+ }
+
+ //!Returns the built string.
+ const std::string& get() const
+ {
+ return about_text;
+ }
+
+private:
+ const size_t separator_count=13; //!< Number of times that the separator character will be added.
+ const size_t space_count=13; //!< Number of times that the space character will be added before the title.
+ char separator_character; //!< Separator character. Defaults to '='.
+ std::string about_text; //!< Text that will be filled up with calls to "add".
+};
+
AboutTab::AboutTab(Widget* parent)
: Widget(parent)
{
@@ -52,53 +94,15 @@ void AboutTab::resize(std::size_t width, std::size_t height)
std::string AboutTab::getAboutText()
{
- std::string about_text;
-
- // About
- about_text.append(
- "=============\n"
- " About\n"
- "=============\n"
- "\n");
- about_text.append(about.data());
-
- // Version
- about_text.append(
- "\n"
- "=============\n"
- " Version\n"
- "=============\n"
- "\n");
- about_text.append(std::string(VERSION) + "\n");
-
- // Bugs
- about_text.append(
- "\n"
- "=============\n"
- " Bugs\n"
- "=============\n"
- "\n");
- about_text.append(bugs.data());
-
- // Authors
- about_text.append(
- "\n"
- "=============\n"
- " Authors\n"
- "=============\n"
- "\n");
- about_text.append(UTF8().toLatin1(authors.data()));
-
- // GPL
- about_text.append(
- "\n"
- "=============\n"
- " License\n"
- "=============\n"
- "\n");
- about_text.append(gpl.data());
+ AboutTextBuilder builder('*');
- return about_text;
+ //This will casually add an extra newline at the end of License.
+ return builder.add("About", about.data())
+ .add("Version", std::string(VERSION)+"\n")
+ .add("Bugs", bugs.data())
+ .add("Authors", UTF8().toLatin1(authors.data()))
+ .add("License", gpl.data())
+ .get();
}
} // GUI::