Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) ShinyButton

 

STLQt CreatorLubuntu

 

ShinyButton is a class for a shiny button.

Technical facts

 

 

 

 

 

 

./CppShinyButton/CppShinyButton.pri

 

INCLUDEPATH += \
    ../../Classes/CppShinyButton

SOURCES += \
    ../../Classes/CppShinyButton/shinybutton.cpp

HEADERS  += \
    ../../Classes/CppShinyButton/shinybutton.h

OTHER_FILES += \
    ../../Classes/CppShinyButton/Licence.txt

 

 

 

 

 

./CppShinyButton/shinybutton.h

 

//---------------------------------------------------------------------------
/*
ShinyButton, toggle button class
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppShinyButton.htm
//---------------------------------------------------------------------------
#ifndef SHINYBUTTON_H
#define SHINYBUTTON_H

#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/checked_delete.hpp>
#include <boost/signals2.hpp>
#pragma GCC diagnostic pop

namespace ribi {

///ShinyButton is a class for a toggle button
struct ShinyButton
{
  explicit ShinyButton(
    const double color,
    const double gradient,
    const std::string& text = "") noexcept;

  ///Get the main color (the color in the middle) of the ShinyButton
  double GetColor() const noexcept { return m_color; }

  ///Get the change of gradient on the ShinyButton.
  ///The difference in color between the left and right of the ShinyButton
  double GetGradient() const noexcept { return m_gradient; }

  const std::string& GetText() const noexcept { return m_text; }

  ///Set the ShinyButton its color
  void SetColor(
    const double color,
    const double gradient) noexcept;

  ///Set the ShinyButton its text
  void SetText(const std::string& text) noexcept;

  ///The signal that is emitted when ShinyButton changes color
  mutable boost::signals2::signal<void ()> m_signal_color_changed;

  ///The signal that is emitted when ShinyButton changes color
  mutable boost::signals2::signal<void ()> m_signal_text_changed;

  private:
  //ShinyButton can only be deleted by Boost smart pointers
  virtual ~ShinyButton() noexcept {}
  //ShinyButton can only be deleted by Boost smart pointers
  friend void boost::checked_delete<>(ShinyButton*);

  ///\brief
  ///The main color of the ShinyButton
  ///
  ///m_color denotes the fraction [0.0,1.0] on the rainbow:
  ///0.0 = red, 1.0 = magenta
  double m_color;

  ///\brief
  ///The change of gradient on the ShinyButton
  ///
  ///Gradient goes from [m_color-(0.5*m_gradient),m_color+(0.5*m_gradient)]
  ///0.0 = no gradient = a single color
  ///1.0 = show the entire rainbow with m_color in the middle
  double m_gradient;

  ///The text displayed by the ShinyButton
  std::string m_text;

  friend std::ostream& operator<<(std::ostream& os, const ShinyButton& button) noexcept;

  public:
  static std::string GetVersion() noexcept;
  static std::vector<std::string> GetVersionHistory() noexcept;
};

std::ostream& operator<<(std::ostream& os, const ShinyButton& button) noexcept;

} //~namespace ribi

#endif // SHINYBUTTON_H

 

 

 

 

 

./CppShinyButton/shinybutton.cpp

 

//---------------------------------------------------------------------------
/*
ShinyButton, toggle button class
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppShinyButton.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "shinybutton.h"

#include <cassert>
#include <cmath>

#include "trace.h"

#pragma GCC diagnostic pop

ribi::ShinyButton::ShinyButton(
  const double color,
  const double gradient,
  const std::string& text) noexcept
  : m_signal_color_changed{},
    m_signal_text_changed{},
    m_color(color),
    m_gradient(gradient),
    m_text(text)
{

}

std::string ribi::ShinyButton::GetVersion() noexcept
{
  return "1.0";
}

std::vector<std::string> ribi::ShinyButton::GetVersionHistory() noexcept
{
  return {
    "2011-09-21: Version 1.0: initial version"
  };
}

void ribi::ShinyButton::SetColor(
  const double color,
  const double gradient) noexcept
{
  if (color != m_color || gradient != m_gradient)
  {
    m_color = color;
    m_gradient = gradient;
    m_signal_color_changed();
  }
}

void ribi::ShinyButton::SetText(
  const std::string& text) noexcept
{
  if (text != m_text)
  {
    m_text = text;
    m_signal_text_changed();
  }
}

std::ostream& ribi::operator<<(std::ostream& os, const ShinyButton& button) noexcept
{
  os
    << "<ShinyButton>"
    << "<color>"
      << button.m_color
    << "</color>"
    << "<gradient>"
      << button.m_gradient
    << "</gradient>"
    << "<text>"
      << button.m_text
    << "</text>"
    << "</ShinyButton>";
  return os;

}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml