Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) TestShape source code (version 2.0)

 

TestShape source code (version 2.0).

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ToolTestShapeDesktop.pro

 

#-------------------------------------------------
#
# Project created by QtCreator 2011-04-11T09:14:30
#
#-------------------------------------------------
QT       += core gui
TARGET = ToolTestShapeDesktop
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++0x
INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppQtAboutDialog \
    ../../Classes/CppQtShapeWidget \
    ../../Classes/CppRectangle \
    ../../Classes/CppShape \
    ../../Classes/CppShapeWidget \
    ../../Classes/CppTrace \
    ../../Classes/CppWidget

SOURCES += qtmain.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.cpp \
    ../../Classes/CppWidget/widget.cpp \
    ../../Classes/CppRectangle/rectangle.cpp \
    ../../Classes/CppShapeWidget/shapewidget.cpp \
    ../../Classes/CppShape/shape.cpp \
    ../../Classes/CppQtShapeWidget/qtshapewidget.cpp \
    qttestshapemaindialog.cpp \
    qttestshapemenudialog.cpp \
    testshapemaindialog.cpp \
    testshapemenudialog.cpp

HEADERS  += \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.h \
    ../../Classes/CppWidget/widget.h \
    ../../Classes/CppRectangle/rectangle.h \
    ../../Classes/CppShapeWidget/shapewidget.h \
    ../../Classes/CppShape/shape.h \
    ../../Classes/CppQtShapeWidget/qtshapewidget.h \
    ../../Classes/CppTrace/trace.h \
    qttestshapemaindialog.h \
    qttestshapemenudialog.h \
    testshapemaindialog.h \
    testshapemenudialog.h

FORMS += \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.ui \
    qttestshapemaindialog.ui \
    qttestshapemenudialog.ui

RESOURCES += \
    ToolTestShape.qrc

 

 

 

 

 

Qt project file: ToolTestShapeWebsite.pro

 

#-------------------------------------------------
#
# Project created by QtCreator 2011-04-11T09:14:30
#
#-------------------------------------------------
QT       += core
QT       -= gui
LIBS += -lwt -lwthttp -lboost_program_options

QMAKE_CXXFLAGS += -std=c++0x

TARGET = TestShapeWebsite
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppRectangle \
    ../../Classes/CppShape \
    ../../Classes/CppShapeWidget \
    ../../Classes/CppTrace \
    ../../Classes/CppWidget \
    ../../Classes/CppWtAboutDialog \
    ../../Classes/CppWtAutoConfig \
    ../../Classes/CppWtShapeWidget

SOURCES += wtmain.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppShape/shape.cpp \
    ../../Classes/CppShapeWidget/shapewidget.cpp \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.cpp \
    ../../Classes/CppWtAutoConfig/wtautoconfig.cpp \
    wttestshapemaindialog.cpp \
    wttestshapemenudialog.cpp \
    testshapemaindialog.cpp \
    testshapemenudialog.cpp \
    ../../Classes/CppWidget/widget.cpp \
    ../../Classes/CppRectangle/rectangle.cpp \
    ../../Classes/CppWtShapeWidget/wtshapewidget.cpp

HEADERS  += \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppShape/shape.h \
    ../../Classes/CppShapeWidget/shapewidget.h \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.h \
    ../../Classes/CppWtAutoConfig/wtautoconfig.h \
    wttestshapemaindialog.h \
    wttestshapemenudialog.h \
    testshapemaindialog.h \
    testshapemenudialog.h \
    ../../Classes/CppWidget/widget.h \
    ../../Classes/CppRectangle/rectangle.h \
    ../../Classes/CppWtShapeWidget/wtshapewidget.h

RESOURCES += \
    ToolTestShape.qrc

 

 

 

 

 

qtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <cassert>
//---------------------------------------------------------------------------
#include <boost/foreach.hpp>
//---------------------------------------------------------------------------
#include <QtGui/QApplication>
#include <QFile>
#include "qttestshapemenudialog.h"
#include "trace.h"
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  START_TRACE();
  QtTestShapeMenuDialog w;
  w.show();
  return a.exec();
}
//---------------------------------------------------------------------------

 

 

 

 

 

qttestshapemaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>
//---------------------------------------------------------------------------
#include "qtaboutdialog.h"
#include "qttestshapemaindialog.h"
#include "qtshapewidget.h"
#include "testshapemaindialog.h"
#include "trace.h"
#include "ui_qttestshapemaindialog.h"
//---------------------------------------------------------------------------
QtTestShapeMainDialog::QtTestShapeMainDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QtTestShapeMainDialog),
    m_dialog(new TestShapeMainDialog)
{
  ui->setupUi(this);
  int i=0;
  BOOST_FOREACH(boost::shared_ptr<ShapeWidget>& widget,
    m_dialog->GetShapes())
  {
    boost::shared_ptr<QtShapeWidget> w(new QtShapeWidget(widget));

    ui->my_layout->addWidget(w.get(),i/8,i%8,1,1);
    //If the QtShapeWidget is not stored, no glory
    m_widgets.push_back(w);
    ++i;
  }
}
//---------------------------------------------------------------------------
QtTestShapeMainDialog::~QtTestShapeMainDialog()
{
  delete ui;
}
//---------------------------------------------------------------------------
void QtTestShapeMainDialog::changeEvent(QEvent *e)
{
  QDialog::changeEvent(e);
  switch (e->type()) {
  case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
  default:
    break;
  }
}
//---------------------------------------------------------------------------

 

 

 

 

 

qttestshapemaindialog.h

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#ifndef QTTESTSHAPEMAINDIALOG_H
#define QTTESTSHAPEMAINDIALOG_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------------------
#include <QDialog>
//---------------------------------------------------------------------------
namespace Ui {
  class QtTestShapeMainDialog;
}
struct TestShapeMainDialog;
struct QtShapeWidget;
//---------------------------------------------------------------------------
class QtTestShapeMainDialog : public QDialog
{
  Q_OBJECT

public:
  explicit QtTestShapeMainDialog(QWidget *parent = 0);
  ~QtTestShapeMainDialog();

protected:
  void changeEvent(QEvent *e);

private:
  Ui::QtTestShapeMainDialog *ui;
  boost::scoped_ptr<TestShapeMainDialog> m_dialog;
  std::vector<boost::shared_ptr<QtShapeWidget> > m_widgets;
};
//---------------------------------------------------------------------------
#endif // QTTESTSHAPEMAINDIALOG_H

 

 

 

 

 

qttestshapemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include "about.h"
#include "qtaboutdialog.h"
#include "qtshapewidget.h"
#include "qttestshapemaindialog.h"
#include "qttestshapemenudialog.h"
#include "shape.h"
#include "shapewidget.h"
#include "testshapemenudialog.h"
#include "ui_qttestshapemenudialog.h"
//---------------------------------------------------------------------------
QtTestShapeMenuDialog::QtTestShapeMenuDialog(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::QtTestShapeMenuDialog),
  m_dialog(new TestShapeMenuDialog)
{
  ui->setupUi(this);
}
//---------------------------------------------------------------------------
QtTestShapeMenuDialog::~QtTestShapeMenuDialog()
{
  delete ui;
}
//---------------------------------------------------------------------------
void QtTestShapeMenuDialog::on_button_start_clicked()
{
  hide();
  QtTestShapeMainDialog d;
  d.exec();
  show();
}
//---------------------------------------------------------------------------
void QtTestShapeMenuDialog::on_button_about_clicked()
{
  hide();
  About a = m_dialog->GetAbout();
  a.AddLibrary("QtShapeWidget version: " + QtShapeWidget::GetVersion());
  QtAboutDialog d(a);
  d.exec();
  show();
}
//---------------------------------------------------------------------------
void QtTestShapeMenuDialog::on_button_quit_clicked()
{
  close();
}
//---------------------------------------------------------------------------


 

 

 

 

 

qttestshapemenudialog.h

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#ifndef QTTESTSHAPEMENUDIALOG_H
#define QTTESTSHAPEMENUDIALOG_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
//---------------------------------------------------------------------------
#include <QDialog>
//---------------------------------------------------------------------------
namespace Ui {
class QtTestShapeMenuDialog;
}
struct TestShapeMenuDialog;
//---------------------------------------------------------------------------
class QtTestShapeMenuDialog : public QDialog
{
  Q_OBJECT

public:
  explicit QtTestShapeMenuDialog(QWidget *parent = 0);
  ~QtTestShapeMenuDialog();

private slots:
  void on_button_start_clicked();
  void on_button_about_clicked();
  void on_button_quit_clicked();

private:
  Ui::QtTestShapeMenuDialog *ui;
  boost::scoped_ptr<TestShapeMenuDialog> m_dialog;
};
//---------------------------------------------------------------------------
#endif // QTTESTSHAPEMENUDIALOG_H

 

 

 

 

 

testshapemaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <boost/numeric/conversion/cast.hpp>
//---------------------------------------------------------------------------
#include "shape.h"
#include "shapewidget.h"
#include "testshapemaindialog.h"
//---------------------------------------------------------------------------
TestShapeMainDialog::TestShapeMainDialog()
  : m_shapes(CreateShapes())
{

}
//---------------------------------------------------------------------------
std::vector<boost::shared_ptr<ShapeWidget> > TestShapeMainDialog::CreateShapes()
{
  std::vector<boost::shared_ptr<ShapeWidget> > v;
  for (int n_corners=0; n_corners!=8; ++n_corners)
  {
    for (int angle=0; angle!=8; ++angle)
    {
      const double rotation = (boost::numeric_cast<double>(angle) / 8.0) * 2.0 * M_PI;
      const int r_i = (n_corners           * 32) % 256;
      const int g_i = (angle               * 32) % 256;
      const int b_i = ((n_corners + angle) * 32) % 256;
      const unsigned char r = boost::numeric_cast<unsigned char>(r_i);
      const unsigned char g = boost::numeric_cast<unsigned char>(g_i);
      const unsigned char b = boost::numeric_cast<unsigned char>(b_i);
      boost::shared_ptr<ShapeWidget> w(new ShapeWidget(
        n_corners,rotation,0,0,32,32,r,g,b));
      v.push_back(w);
    }
  }

  //std::random_shuffle(v.begin(),v.end());
  return v;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

 

 

 

 

 

testshapemaindialog.h

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#ifndef TESTSHAPEMAINDIALOG_H
#define TESTSHAPEMAINDIALOG_H
//---------------------------------------------------------------------------
#include <vector>
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------------------
struct MultipleChoiceShape;
struct MultipleChoiceShapeDialog;
struct OpenShape;
struct OpenShapeDialog;
struct ShapeWidget;
//---------------------------------------------------------------------------
///The GUI independent TestShape main dialog
struct TestShapeMainDialog
{
  TestShapeMainDialog();

  std::vector<boost::shared_ptr<ShapeWidget> >& GetShapes() { return m_shapes; }

  private:
  std::vector<boost::shared_ptr<ShapeWidget> > m_shapes;

  void OnShapeAnswered();

  static std::vector<boost::shared_ptr<ShapeWidget> > CreateShapes();
};
//---------------------------------------------------------------------------
#endif // TESTSHAPEMAINDIALOG_H

 

 

 

 

 

testshapemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <boost/foreach.hpp>
//---------------------------------------------------------------------------
#include "shape.h"
#include "shapewidget.h"
#include "testshapemenudialog.h"
#include "trace.h"
//---------------------------------------------------------------------------
#include <QFile>
//---------------------------------------------------------------------------
TestShapeMenuDialog::TestShapeMenuDialog()
{
  const std::vector<std::string> files =
  {
    GetFilenameImageWelcome()
  };
  BOOST_FOREACH(const std::string& filename,files)
  {
    if (!QFile::exists(filename.c_str()))
    {
      QFile f( (std::string(":/images/") + filename).c_str() );
        f.copy(filename.c_str());
    }
    assert(QFile::exists(filename.c_str()));
  }
}
//---------------------------------------------------------------------------
const About TestShapeMenuDialog::GetAbout() const
{
  About a(
    "Richel Bilderbeek",
    "TestShape",
    "tool to test the Shape and ShapeWidget classes",
    "the 8th of August 2011",
    "2011",
    "http://www.richelbilderbeek.nl/ToolTestShape.htm",
    GetVersion(),
    GetVersionHistory());
  //a.AddLibrary("Rectangle version: " + Rect::GetVersion());
  a.AddLibrary("Shape version: " + Shape::GetVersion());
  a.AddLibrary("ShapeWidget version: " + ShapeWidget::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());
  a.AddLibrary("Widget version: " + Widget::GetVersion());
  return a;
}
//---------------------------------------------------------------------------
const std::string TestShapeMenuDialog::GetVersion()
{
  return "2.0";
}
//---------------------------------------------------------------------------
const std::vector<std::string> TestShapeMenuDialog::GetVersionHistory()
{
  std::vector<std::string> v;
  v.push_back("2011-06-28: Version 1.0: initial version");
  v.push_back("2011-08-08: Version 2.0: conformized architecture to MysteryMachineWidget");
  return v;
}
//---------------------------------------------------------------------------

 

 

 

 

 

testshapemenudialog.h

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#ifndef TESTSHAPEMENUDIALOG_H
#define TESTSHAPEMENUDIALOG_H
//---------------------------------------------------------------------------
#include "about.h"
//---------------------------------------------------------------------------
///The logic behind the menu dialog
struct TestShapeMenuDialog
{
  ///Creates the resources needed
  TestShapeMenuDialog();

  ///Obtain the about information
  ///
  ///\note
  ///This is a non-static method, to ensure users of this class
  ///call TestShapeMenuDialog its constructor: this is where
  ///the resources needed are created
  const About GetAbout() const;

  ///\brief
  ///Get the filename of the image shown at the welcome screen
  ///
  ///This is a non-static method to force this class its constructor being
  ///called, creating the file from the application its resource file
  const std::string GetFilenameImageWelcome() const { return "ToolTestShapeWelcome.png"; }

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

  ///Obtain the version history
  static const std::vector<std::string> GetVersionHistory();
};
//---------------------------------------------------------------------------
#endif // TESTSHAPEMENUDIALOG_H

 

 

 

 

 

wtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <Wt/WApplication>
#include <Wt/WEnvironment>
//---------------------------------------------------------------------------
#include "wtautoconfig.h"
#include "wttestshapemenudialog.h"
//---------------------------------------------------------------------------
struct WtApplication : public Wt::WApplication
{
  WtApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env),
    m_dialog(new WtTestShapeMenuDialog)
  {
    this->setTitle("TestShape");
    this->useStyleSheet("wt.css");
    root()->addWidget(m_dialog);
  }
  private:
  WtTestShapeMenuDialog * const m_dialog;
};
//---------------------------------------------------------------------------
Wt::WApplication *createApplication(
  const Wt::WEnvironment& env)
{
  return new WtApplication(env);
}
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
  WtAutoConfig a(argc,argv,createApplication);
  WtAutoConfig::SaveDefaultStylesheet();
  return a.Run();
}
//---------------------------------------------------------------------------

 

 

 

 

 

wttestshapemaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>
//---------------------------------------------------------------------------
#include <Wt/WBreak>
#include <Wt/WGridLayout>
#include <Wt/WGroupBox>
#include <Wt/WLabel>
#include <Wt/WPushButton>
#include <Wt/WSlider>
//---------------------------------------------------------------------------
#include "shape.h"
#include "shapewidget.h"
#include "testshapemaindialog.h"
#include "wtaboutdialog.h"
#include "wtshapewidget.h"
#include "wttestshapemaindialog.h"
//---------------------------------------------------------------------------
WtTestShapeMainDialog::WtTestShapeMainDialog()
  : m_dialog(new TestShapeMainDialog),
    m_label_score(0)
{
  Show();
}
//---------------------------------------------------------------------------
void WtTestShapeMainDialog::Show()
{
  clear();
  setContentAlignment(Wt::AlignCenter);

  Wt::WGridLayout * const layout = new Wt::WGridLayout(this);

  int i=0;
  BOOST_FOREACH(boost::shared_ptr<ShapeWidget>& widget,
    m_dialog->GetShapes())
  {
    layout->addWidget(
      new WtShapeWidget(widget),
      i/8,
      i%8,1,1);
    ++i;
  }
}
//---------------------------------------------------------------------------

 

 

 

 

 

wttestshapemaindialog.h

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#ifndef WTTESTSHAPEMAINDIALOG_H
#define WTTESTSHAPEMAINDIALOG_H
//---------------------------------------------------------------------------
#include <vector>
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------------------
#include <Wt/WContainerWidget>
//---------------------------------------------------------------------------
namespace Wt { struct WLabel; }
struct TestShapeMainDialog;
struct WtShapeWidget;
//---------------------------------------------------------------------------
struct WtTestShapeMainDialog : public Wt::WContainerWidget
{
  WtTestShapeMainDialog();

  private:

  boost::scoped_ptr<TestShapeMainDialog> m_dialog;
  std::vector<WtShapeWidget*> m_dialogs;
  Wt::WLabel * m_label_score;
  void OnSubmit();
  void Show();
};
//---------------------------------------------------------------------------
#endif // WTTESTQUESTIONMAINDIALOG_H

 

 

 

 

 

wttestshapemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeDialog classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WGroupBox>
#include <Wt/WImage>
#include <Wt/WLabel>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WMenuItem>
//---------------------------------------------------------------------------
#include "testshapemenudialog.h"
#include "wtaboutdialog.h"
#include "wtautoconfig.h"
#include "wttestshapemaindialog.h"
#include "wttestshapemenudialog.h"
#include "wtshapewidget.h"
//---------------------------------------------------------------------------
WtTestShapeMenuDialog::WtTestShapeMenuDialog()
  : m_dialog(new TestShapeMenuDialog)
{
  this->setContentAlignment(Wt::AlignCenter);
  {
    Wt::WLabel * const title = new Wt::WLabel("TestShape");
    title->setStyleClass("title");
    this->addWidget(title);
  }
  //Menu
  {
    Wt::WStackedWidget * const contents = new Wt::WStackedWidget;
    Wt::WMenu * const menu = new Wt::WMenu(contents,Wt::Horizontal);
    //Using CSS styleclass is the best (only?) way to display the menu well
    menu->setStyleClass("menu");
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "Welcome",
        CreateNewWelcomeDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "Start",
        CreateNewMainDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "About",
        CreateNewAboutDialog());
      menu->addItem(item);
    }
    //Display menu on top
    this->addWidget(menu);
    this->addWidget(new Wt::WBreak);
    //Display contents below menu
    this->addWidget(contents);
  }
}
//---------------------------------------------------------------------------
Wt::WWidget * WtTestShapeMenuDialog::CreateNewAboutDialog() const
{
  About a = m_dialog->GetAbout();
  a.AddLibrary("WtAutoConfig version: " + WtAutoConfig::GetVersion());
  a.AddLibrary("WtShapeWidget version: " + WtShapeWidget::GetVersion());
  WtAboutDialog * const d = new WtAboutDialog(a,false);
  assert(d);
  return d;
}
//---------------------------------------------------------------------------
Wt::WWidget * WtTestShapeMenuDialog::CreateNewMainDialog() const
{
  WtTestShapeMainDialog * const d = new WtTestShapeMainDialog;
  assert(d);
  return d;
}
//---------------------------------------------------------------------------
Wt::WWidget * WtTestShapeMenuDialog::CreateNewWelcomeDialog() const
{
  Wt::WContainerWidget * dialog = new Wt::WContainerWidget;
  dialog->setContentAlignment(Wt::AlignCenter);
  dialog->addWidget(new Wt::WBreak);
  new Wt::WLabel("Welcome to TestShape",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  new Wt::WLabel("TestShape tests and displays the Shape and ShapeDialog classes",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  Wt::WGroupBox * const box = new Wt::WGroupBox("Explanation",dialog);
  box->addWidget(new Wt::WImage(m_dialog->GetFilenameImageWelcome()));
  return dialog;
}
//---------------------------------------------------------------------------

 

 

 

 

 

wttestshapemenudialog.h

 

//---------------------------------------------------------------------------
/*
TestShape, tool to test the Shape and ShapeWidget classes
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/ToolTestShape.htm
//---------------------------------------------------------------------------
#ifndef WTTESTSHAPEMENUDIALOG_H
#define WTTESTSHAPEMENUDIALOG_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
//---------------------------------------------------------------------------
#include <Wt/WContainerWidget>
//---------------------------------------------------------------------------
struct TestShapeMenuDialog;
//---------------------------------------------------------------------------
struct WtTestShapeMenuDialog : public Wt::WContainerWidget
{
  WtTestShapeMenuDialog();
  private:
  Wt::WWidget * CreateNewAboutDialog() const;
  Wt::WWidget * CreateNewMainDialog() const;
  Wt::WWidget * CreateNewWelcomeDialog() const;

  boost::scoped_ptr<TestShapeMenuDialog> m_dialog;
};
//---------------------------------------------------------------------------
#endif // WTTESTQUESTIONMENUDIALOG_H

 

 

 

 

 

crosscompiletowindows.sh

 

#!/bin/sh
#From http://richelbilderbeek.nl/CppQtCrosscompileToWindowsExample15.htm

echo "Cross compiling to Windows"

echo "1/2: Creating Windows makefile"
i686-pc-mingw32-qmake ToolTestDialDesktop.pro

echo "2/2: making makefile"

make

echo "Done"

 

 

 

 

 

zip.sh

 

#!/bin/sh
#zip packs all the files to port into a single .zip file,
#minicking the same folder structure
#Folder structure
# *
#   * Classes
#     * CppAbout
#     * CppQtAboutDialog
#     * CppQtShapeWidget
#     * CppRectangle
#     * CppShape
#     * CppShapeWidget
#     * CppTrace
#     * CppWidget
#     * CppWtAboutDialog
#     * CppWtAutoConfig
#     * CppWtMultipleChoiceShapeWidget
#     * CppWtOpenShapeWidget
#     * CppWtShapeWidget
#   * Tools
#    * ToolTestShape

echo "Converting DIA to PNG"
dia --filter=png ToolTestShapeArchitecture.dia

echo "Removing previous user's information"
rm ToolTestShapeDesktop.pro.user
rm ToolTestShapeWebsite.pro.user

echo "Mimicking file structure"
mkdir temp_zip
mkdir temp_zip/Classes
mkdir temp_zip/Classes/CppAbout
mkdir temp_zip/Classes/CppQtAboutDialog
mkdir temp_zip/Classes/CppQtShapeWidget
mkdir temp_zip/Classes/CppRectangle
mkdir temp_zip/Classes/CppShape
mkdir temp_zip/Classes/CppShapeWidget
mkdir temp_zip/Classes/CppTrace
mkdir temp_zip/Classes/CppWidget
mkdir temp_zip/Classes/CppWtAboutDialog
mkdir temp_zip/Classes/CppWtAutoConfig
mkdir temp_zip/Classes/CppWtShapeWidget
mkdir temp_zip/Tools
mkdir temp_zip/Tools/ToolTestShape

echo "Copying files"
cp ../../Classes/CppAbout/*.* temp_zip/Classes/CppAbout
cp ../../Classes/CppQtAboutDialog/*.* temp_zip/Classes/CppQtAboutDialog
cp ../../Classes/CppQtShapeWidget/*.* temp_zip/Classes/CppQtShapeWidget
cp ../../Classes/CppRectangle/*.* temp_zip/Classes/CppRectangle
cp ../../Classes/CppShape/*.* temp_zip/Classes/CppShape
cp ../../Classes/CppShapeWidget/*.* temp_zip/Classes/CppShapeWidget
cp ../../Classes/CppTrace/*.* temp_zip/Classes/CppTrace
cp ../../Classes/CppWidget/*.* temp_zip/Classes/CppWidget
cp ../../Classes/CppWtAboutDialog/*.* temp_zip/Classes/CppWtAboutDialog
cp ../../Classes/CppWtAutoConfig/*.* temp_zip/Classes/CppWtAutoConfig
cp ../../Classes/CppWtShapeWidget/*.* temp_zip/Classes/CppWtShapeWidget
cp ../../Tools/ToolTestShape/*.* temp_zip/Tools/ToolTestShape

FILENAME=ToolTestShapeSource_2_0
ZIP_FILENAME=$FILENAME".zip"

#echo "Compressing files"
cd temp_zip
zip -r $FILENAME Classes
#zip -r $FILENAME Libraries
#zip -r $FILENAME Projects
zip -r $FILENAME Tools
cd ..
cp "temp_zip/"$ZIP_FILENAME $ZIP_FILENAME

echo "Cleaning up"

#Classes
rm temp_zip/Classes/CppAbout/*.*
rm temp_zip/Classes/CppQtAboutDialog/*.*
rm temp_zip/Classes/CppQtShapeWidget/*.*
rm temp_zip/Classes/CppRectangle/*.*
rm temp_zip/Classes/CppShape/*.*
rm temp_zip/Classes/CppShapeWidget/*.*
rm temp_zip/Classes/CppTrace/*.*
rm temp_zip/Classes/CppWidget/*.*
rm temp_zip/Classes/CppWtAboutDialog/*.*
rm temp_zip/Classes/CppWtAutoConfig/*.*
rm temp_zip/Classes/CppWtShapeWidget/*.*
rmdir temp_zip/Classes/CppAbout
rmdir temp_zip/Classes/CppQtAboutDialog
rmdir temp_zip/Classes/CppQtShapeWidget
rmdir temp_zip/Classes/CppRectangle
rmdir temp_zip/Classes/CppShape
rmdir temp_zip/Classes/CppShapeWidget
rmdir temp_zip/Classes/CppTrace
rmdir temp_zip/Classes/CppWidget
rmdir temp_zip/Classes/CppWtAboutDialog
rmdir temp_zip/Classes/CppWtAutoConfig
rmdir temp_zip/Classes/CppWtShapeWidget
rmdir temp_zip/Classes

#Tools
rm temp_zip/Tools/ToolTestShape/*.*
rmdir temp_zip/Tools/ToolTestShape
rmdir temp_zip/Tools
rm temp_zip/*.*
rmdir temp_zip
echo "Done"

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict