Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) ToggleButtonWidget

 

ToggleButtonWidget is a widget class for a ToggleButton.

 

 

 

 

 

togglebuttonwidget.h

 

//---------------------------------------------------------------------------
/*
ToggleButtonWidget, widget for the ToggleButton class
Copyright (C) 2011 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/CppToggleButtonWidget.htm
//---------------------------------------------------------------------------
#ifndef TOGGLEBUTTONWIDGET_H
#define TOGGLEBUTTONWIDGET_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
//---------------------------------------------------------------------------
#include "widget.h"
//---------------------------------------------------------------------------
struct ToggleButton;
//---------------------------------------------------------------------------
struct ToggleButtonWidget : public Widget
{
  ToggleButtonWidget(
    const bool pressed = false,
    const unsigned char red = 255,
    const unsigned char green = 255,
    const unsigned char blue = 255
  );

  ///Obtain a read-and-write pointer to ToggleButton
  ToggleButton * GetToggleButton() { return m_button.get(); }

  ///Obtain a read-only pointer to ToggleButton
  const ToggleButton * GetToggleButton() const { return m_button.get(); }

  ///Respond to the user clicking on this class
  void Click(const int x, const int y);

  ///Obtain the version of this class
  static const std::string GetVersion();

  ///Obtain the version history of this class
  static const std::vector<std::string> GetVersionHistory();

  private:
  boost::scoped_ptr<ToggleButton> m_button;

  friend std::ostream& operator<<(std::ostream& os, const ToggleButtonWidget& button);
};
//---------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const ToggleButtonWidget& button);
//---------------------------------------------------------------------------
#endif // TOGGLEBUTTONWIDGET_H

 

 

 

 

 

togglebuttonwidget.cpp

 

//---------------------------------------------------------------------------
/*
ToggleButtonWidget, widget for the ToggleButton class
Copyright (C) 2011 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/CppToggleButtonWidget.htm
//---------------------------------------------------------------------------
#include "togglebutton.h"
#include "togglebuttonwidget.h"
#include "trace.h"
//---------------------------------------------------------------------------
ToggleButtonWidget::ToggleButtonWidget(
  const bool pressed,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
  : m_button(new ToggleButton(pressed,red,green,blue))
{

}
//---------------------------------------------------------------------------
void ToggleButtonWidget::Click(const int, const int)
{
  TRACE_FUNC();
  m_button->Toggle();
}
//---------------------------------------------------------------------------
const std::string ToggleButtonWidget::GetVersion()
{
  return "1.2";
}
//---------------------------------------------------------------------------
const std::vector<std::string> ToggleButtonWidget::GetVersionHistory()
{
  std::vector<std::string> v;
  v.push_back("YYYY-MM-DD: version X.Y: [description]");
  v.push_back("2011-07-03: version 1.0: initial version");
  v.push_back("2011-08-20: Version 1.1: added operator<<");
  v.push_back("2011-08-31: Version 1.2: added setting the color of a ToggleButton");
  return v;
}
//---------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const ToggleButtonWidget& button)
{
  os
    << "<ToggleButtonWidget>"
    << *button.m_button
    << button.GetGeometry()
    << "</ToggleButtonWidget>";
  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