Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Grabber

 

Technical facts

 

 

 

 

 

 

./CppGrabber/CppGrabber.pri

 

INCLUDEPATH += \
    ../../Classes/CppGrabber

SOURCES += \
    ../../Classes/CppGrabber/grabber.cpp

HEADERS  += \
    ../../Classes/CppGrabber/grabber.h

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

 

 

 

 

 

./CppGrabber/grabber.h

 

#ifndef GRABBER_H
#define GRABBER_H

#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 <string>
#include <vector>

#include <QObject>
#pragma GCC diagnostic pop

namespace ribi {

struct Grabber : public QObject
{
  Q_OBJECT

  public:
  Grabber(
    const int win_id,
    const std::string& filename = "screengrab.png"
  );
  ~Grabber() noexcept;

  public slots:
  void Grab() const noexcept;

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

  private:
  const std::string m_filename;
  const int m_win_id;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

};

} //~namespace ribi

#endif // GRABBER_H

 

 

 

 

 

./CppGrabber/grabber.cpp

 

#include "grabber.h"

#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 <QImage>
#include <QPixmap>

#include "testtimer.h"
#include "trace.h"
#pragma GCC diagnostic pop

ribi::Grabber::Grabber(
  const int win_id,
  const std::string& filename
)
  : m_filename{filename},
    m_win_id{win_id}
{

}

ribi::Grabber::~Grabber() noexcept
{

}

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

std::vector<std::string> ribi::Grabber::GetVersionHistory() noexcept
{
  return {
    "2014-08-04: Version 1.0: initial version",
  };
}

void ribi::Grabber::Grab() const noexcept
{
  const QImage screenshot{QPixmap::grabWindow(m_win_id).toImage()};
  screenshot.save(m_filename.c_str());
}

#ifndef NDEBUG
void ribi::Grabber::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  const bool verbose{false};
  if (verbose) { TRACE("Default-construction of Grabber"); }
  {
    const Grabber g(0);
  }
}
#endif

 

 

 

 

 

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