Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Wt::WMenu

 

Wt::WMenu is a Wt class for displaying a menu.

 

 

 

 

 

 

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: CppWMenu.pro

 

#-------------------------------------------------
#
# Project created by QtCreator 2011-04-10T11:16:42
#
#-------------------------------------------------
QT       -= core
QT       -= gui
LIBS += \
  -lwt -lwthttp \
  -lboost_program_options
QMAKE_CXXFLAGS += -DNDEBUG
#QMAKE_CXXFLAGS += -std=c++0x
TARGET = CppWMenu
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppDial \
    ../../Classes/CppLed \
    ../../Classes/CppWtAboutDialog \
    ../../Classes/CppWtLedWidget \
    ../../Classes/CppWtDialWidget \
    ../../Tools/ToolTestDial \
    ../../Tools/ToolTestLed

SOURCES += wtmain.cpp \
    wtmenudialog.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.cpp \
    ../../Classes/CppDial/dial.cpp \
    ../../Classes/CppLed/led.cpp \
    ../../Classes/CppWtLedWidget/wtledwidget.cpp \
    ../../Classes/CppWtDialWidget/wtdialwidget.cpp \
    ../../Tools/ToolTestDial/wttestdialdialog.cpp \
    ../../Tools/ToolTestDial/testdialdialog.cpp \
    ../../Tools/ToolTestLed/wttestleddialog.cpp \
    ../../Tools/ToolTestLed/testleddialog.cpp

HEADERS += \
    wtmenudialog.h \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.h \
    ../../Tools/ToolTestDial/wttestdialdialog.h \
    ../../Tools/ToolTestLed/wttestleddialog.h \
    ../../Classes/CppDial/dial.h \
    ../../Classes/CppLed/led.h \
    ../../Classes/CppWtLedWidget/wtledwidget.h \
    ../../Tools/ToolTestDial/testdialdialog.h \
    ../../Classes/CppWtDialWidget/wtdialwidget.h \
    ../../Tools/ToolTestLed/testleddialog.h

OTHER_FILES += \
    wt.css

 

 

 

 

 

wtmain.cpp

 

//---------------------------------------------------------------------------
/*
CppWMenu, demonstration of Wt::WMenu
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/CppWMenu.htm
//---------------------------------------------------------------------------
#include <iostream>
//---------------------------------------------------------------------------
#include <boost/program_options.hpp>
//---------------------------------------------------------------------------
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WText>
//---------------------------------------------------------------------------
#include "wtmenudialog.h"
//---------------------------------------------------------------------------
struct WtApplication : public Wt::WApplication
{
  WtApplication(const Wt::WEnvironment& env);
};
//---------------------------------------------------------------------------
WtApplication::WtApplication(
  const Wt::WEnvironment& env)
  : WApplication(env)
{
  setTitle("CppWMenu");
  this->useStyleSheet("wt.css");
  root()->addWidget(new WtMenuDialog);
}
//---------------------------------------------------------------------------
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
  return new WtApplication(env);
}
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
  // Declare the supported options.
  boost::program_options::options_description d(
    "Allowed options for CppWMenu");
  std::string docroot;
  std::string http_address;
  std::string http_port;
  d.add_options()
      ("help",
        "produce this help message")
      ("docroot",
         boost::program_options::value<std::string>(&docroot)->default_value("."),
         "the docroot")
      ("http-address",
         boost::program_options::value<std::string>(&http_address)->default_value("0.0.0.0"),
         "the server's http address")
      ("http-port",
         boost::program_options::value<std::string>(&http_port)->default_value("8080"),
         "the server's http port")
      ;

  boost::program_options::variables_map m;
  boost::program_options::store(
    boost::program_options::parse_command_line(
      argc, argv, d), m);
  boost::program_options::notify(m);

  if (m.count("help"))
  {
    //Display the options_description
    std::cout << d << "\n";
    return 0;
  }

  //Create the arguments in std::string format
  std::vector<std::string> v(7);
  v[0] = argv[0];
  v[1] = "--docroot";
  v[2] = docroot;
  v[3] = "--http-address";
  v[4] = http_address;
  v[5] = "--http-port";
  v[6] = http_port;

  //Convert the arguments to char* format
  std::vector<char*> w(7);
  for (int i=0; i!=7; ++i) w[i] = &v[i][0];

  //Give Wt the modified parameters
  return WRun(w.size(), &w[0], &createApplication);
}
//---------------------------------------------------------------------------

 

 

 

 

 

wtmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
CppWMenu, demonstration of Wt::WMenu
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/CppWMenu.htm
//---------------------------------------------------------------------------
#include <iostream>
//---------------------------------------------------------------------------
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>
//---------------------------------------------------------------------------
#include <Wt/WLabel>
#include <Wt/WMenu>
#include <Wt/WStackedWidget>
//---------------------------------------------------------------------------
#include "dial.h"
#include "led.h"
#include "wtaboutdialog.h"
#include "wtdialwidget.h"
#include "wtledwidget.h"
#include "wtmenudialog.h"
#include "wttestdialdialog.h"
#include "wttestleddialog.h"
//---------------------------------------------------------------------------
WtMenuDialog::WtMenuDialog()
{
  this->setContentAlignment(Wt::AlignCenter);
  ShowMenu();
}
//---------------------------------------------------------------------------
const About WtMenuDialog::GetAbout()
{
  About a(
    "Richel Bilderbeek",
    "CppWMenu",
    "demonstration of Wt::WMenu",
    "the 14th of April 2011",
    "2011",
    "http://www.richelbilderbeek.nl/CppWMenu.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("Dial version: " + Dial::GetVersion());
  a.AddLibrary("Led version: " + Led::GetVersion());
  a.AddLibrary("WtDialWidget version: " + WtDialWidget::GetVersion());
  a.AddLibrary("WtLedWidget version: " + WtLedWidget::GetVersion());
  return a;
}
//---------------------------------------------------------------------------
const std::string WtMenuDialog::GetVersion()
{
  return "1.0";
}
//---------------------------------------------------------------------------
const std::vector<std::string> WtMenuDialog::GetVersionHistory()
{
  std::vector<std::string> v;
  v.push_back("2011-04-14: Version 1.0: initial version");
  return v;
}
//---------------------------------------------------------------------------
WtAboutDialog * WtMenuDialog::CreateNewAboutDialog()
{
  About a = GetAbout();
  WtAboutDialog * const d = new WtAboutDialog(a);
  return d;
}
//---------------------------------------------------------------------------
void WtMenuDialog::ShowMenu()
{
  this->clear();
  //Title
  {
    Wt::WLabel * const title = new Wt::WLabel("CppWMenu");
    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(
        "TestDial",
        new WtTestDialDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "TestLed",
        new WtTestLedDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "About",
        CreateNewAboutDialog());
      menu->addItem(item);
    }
    //Display menu on top
    this->addWidget(menu);
    //Display contents below menu
    this->addWidget(contents);
  }
}
//---------------------------------------------------------------------------

 

 

 

 

 

wtmenudialog.h

 

//---------------------------------------------------------------------------
/*
CppWMenu, demonstration of Wt::WMenu
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/CppWMenu.htm
//---------------------------------------------------------------------------
#ifndef WTMENUDIALOG_H
#define WTMENUDIALOG_H
//---------------------------------------------------------------------------
#include <string>
#include <vector>
//---------------------------------------------------------------------------
#include <Wt/WContainerWidget>
//---------------------------------------------------------------------------
#include "about.h"
//---------------------------------------------------------------------------
struct WtAboutDialog;
//---------------------------------------------------------------------------
struct WtMenuDialog : public Wt::WContainerWidget
{
  WtMenuDialog();

  private:

  void ShowMenu();
  static WtAboutDialog * CreateNewAboutDialog();

  public:
  static const std::vector<std::string> GetVersionHistory();
  static const std::string GetVersion();
  static const About GetAbout();
};
//---------------------------------------------------------------------------
#endif // WTMENUDIALOG_H

 

 

 

 

 

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict