forked from richelbilderbeek/TestGroupWidget
/
wttestgroupwidgetmenudialog.cpp
141 lines (129 loc) · 4.42 KB
/
wttestgroupwidgetmenudialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//---------------------------------------------------------------------------
/*
TestGroupWidget, tool to test the GroupWidget class
Copyright (C) 2011-2015 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/ToolTestGroupWidget.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#include <cassert>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#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 "rainbow.h"
#include "testgroupwidgetmenudialog.h"
#include "wtaboutdialog.h"
#include "wtautoconfig.h"
#include "wtgroupwidget.h"
#include "wttestgroupwidgetmaindialog.h"
#include "wttestgroupwidgetmenudialog.h"
#include <QFile>
#pragma GCC diagnostic pop
ribi::tgrw::WtMenuDialog::WtMenuDialog()
{
{
std::vector<std::string> image_names;
image_names.push_back("ToolTestGroupWidgetWelcome.png");
BOOST_FOREACH(const std::string& filename,image_names)
{
if (!(QFile::exists(filename.c_str())))
{
QFile f( (std::string(":/TestGroupWidget/images/") + filename).c_str() );
f.copy(filename.c_str());
}
if (!boost::filesystem::exists(filename.c_str()))
{
std::cerr << "File not found: " << filename << '\n';
}
assert(boost::filesystem::exists(filename.c_str()));
}
}
this->setContentAlignment(Wt::AlignCenter);
{
Wt::WLabel * const title = new Wt::WLabel("TestGroupWidget");
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 * ribi::tgrw::WtMenuDialog::CreateNewAboutDialog() const
{
About a = MenuDialog().GetAbout();
a.AddLibrary("Rainbow version: " + Rainbow::GetVersion());
a.AddLibrary("WtAutoConfig version: " + WtAutoConfig::GetVersion());
a.AddLibrary("WtGroupWidget version: " + WtGroupWidget::GetVersion());
WtAboutDialog * const d = new WtAboutDialog(a,false);
assert(d);
return d;
}
Wt::WWidget * ribi::tgrw::WtMenuDialog::CreateNewMainDialog() const
{
WtMainDialog * const d = new WtMainDialog;
assert(d);
return d;
}
Wt::WWidget * ribi::tgrw::WtMenuDialog::CreateNewWelcomeDialog() const
{
Wt::WContainerWidget * dialog = new Wt::WContainerWidget;
dialog->setContentAlignment(Wt::AlignCenter);
dialog->addWidget(new Wt::WBreak);
new Wt::WLabel("Welcome to TestGroupWidget",dialog);
new Wt::WBreak(dialog);
new Wt::WBreak(dialog);
new Wt::WLabel("TestGroupWidget tests and displays the GroupWidget class",dialog);
new Wt::WBreak(dialog);
new Wt::WBreak(dialog);
Wt::WGroupBox * const box = new Wt::WGroupBox("Explanation",dialog);
box->addWidget(new Wt::WImage("ToolTestGroupWidgetWelcome.png"));
return dialog;
}