Wtx ~ Wt Extension Library
WtxLib
PopupYesNo.cpp
1 
2 #include <Wt/WBreak.h>
3 #include <Wt/WPushButton.h>
4 #include <Wt/WText.h>
5 #include <Wt/WApplication.h>
6 #include <Wt/WLineEdit.h>
7 
8 #include "PopupYesNo.h"
9 
10 Wtx::PopupYesNo::PopupYesNo( const std::string & question )
11 : Wt::WDialog("Yes/No")
12 {
13  contents()-> addNew<Wt::WText>(question);
14  contents()-> addNew<Wt::WBreak>();
15  contents()-> addNew<Wt::WPushButton>("Yes")->
16  clicked().connect( [=]()
17  {
18  m_answered.emit( Wt::StandardButton::Yes );
19  accept();
20  });
21 
22  contents()-> addNew<Wt::WPushButton>("No")->
23  clicked().connect( [=]()
24  {
25  m_answered.emit( Wt::StandardButton::No );
26  accept();
27  });
28 
29  rejectWhenEscapePressed();
30 
31  Wt::WDialog::show();
32 }
33 
34 
35 Wtx::PopupYesNo * Wtx::PopupYesNo::ask( const std::string & question )
36 {
37  auto popup = wApp-> addChild( std::make_unique<Wtx::PopupYesNo>( question ) );
38  popup-> finished().connect( [=](){ wApp-> removeChild(popup); });
39  return popup;
40 }
41 
42 Wt::Signal<Wt::StandardButton> & Wtx::PopupYesNo::answered()
43 {
44  return m_answered;
45 }