Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) LedWidget

 

LedWidget is a Led widget.

 

 

 

 

 

ledwidget.h

 

//---------------------------------------------------------------------------
/*
LedWidget, Widget for the Led 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/CppLedWidget.htm
//---------------------------------------------------------------------------
#ifndef LEDWIDGET_H
#define LEDWIDGET_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#include <boost/signals2.hpp>
//---------------------------------------------------------------------------
#include "widget.h"
//---------------------------------------------------------------------------
struct Led;
//---------------------------------------------------------------------------
///Widget for displaying a Led
struct LedWidget : public Widget
{
  LedWidget(
    const int x = 0,
    const int y = 0,
    const int width = 100,
    const int height = 100,
    const double intensity    = 0.0,
    const unsigned char red   = 255,
    const unsigned char green =   0,
    const unsigned char blue  =   0
  );

  ///Obtain a read-only pointer to Led
  const Led * GetLed() const { return m_led.get(); }

  ///Obtain a read-and-write pointer to Led
  Led * GetLed() { return m_led.get(); }

  ///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:
  ///The LED
  boost::scoped_ptr<Led> m_led;

  friend std::ostream& operator<<(std::ostream& os, const LedWidget& widget);
};
//---------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const LedWidget& widget);
//---------------------------------------------------------------------------
#endif // LEDWIDGET_H

 

 

 

 

 

ledwidget.cpp

 

//---------------------------------------------------------------------------
/*
LedWidget, Widget for the Led 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/CppLedWidget.htm
//---------------------------------------------------------------------------
#include <iostream>
//---------------------------------------------------------------------------
#include "led.h"
#include "ledwidget.h"
//---------------------------------------------------------------------------
LedWidget::LedWidget(
  const int x,
  const int y,
  const int width,
  const int height,
  const double intensity,
  const unsigned char red,
  const unsigned char green,
  const unsigned char blue)
  : m_led(new Led(intensity,red,green,blue))
{
  this->SetGeometry(Rect(x,y,width,height));
}
//---------------------------------------------------------------------------
const std::string LedWidget::GetVersion()
{
  return "1.3";
}
//---------------------------------------------------------------------------
const std::vector<std::string> LedWidget::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-17: Version 1.1: emit a signal when the color is changed");
  v.push_back("2011-08-20: Version 1.2: added operator<<");
  v.push_back("2011-09-08: Version 1.3: removed redundant signals");
  return v;
}
//---------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const LedWidget& widget)
{
  os
    << "<LedWidget>"
    << widget.GetGeometry()
    << *widget.m_led
    << "</LedWidget>";
  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