Wtx ~ Wt Extension Library
WtxLib
PopupQuestion.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 "PopupQuestion.h"
9 
10 Wtx::PopupQuestion::PopupQuestion( const std::string & question, const std::string & answer, const std::string & placeholder )
11 : Wt::WDialog("Alert")
12 {
13  contents()-> addNew<Wt::WText>(question);
14  contents()-> addNew<Wt::WBreak>();
15  auto textEdit = contents()-> addNew<Wt::WLineEdit>(answer);
16  textEdit-> setPlaceholderText( placeholder );
17  contents()-> addNew<Wt::WBreak>();
18  contents()-> addNew<Wt::WPushButton>("Ok")->
19  clicked().connect( [=]()
20  {
21  m_answered.emit( textEdit-> valueText().toUTF8() );
22  accept();
23  });
24 
25  contents()-> addNew<Wt::WPushButton>("Cancel")->
26  clicked().connect( this, &Wt::WDialog::reject );
27 
28  rejectWhenEscapePressed();
29 
30  Wt::WDialog::show();
31 }
32 
33 
34 Wtx::PopupQuestion * Wtx::PopupQuestion::ask( const std::string & question, const std::string & answer, const std::string & placeholder )
35 {
36  auto popup = wApp-> addChild( std::make_unique<Wtx::PopupQuestion>( question, answer, placeholder ) );
37  popup-> finished().connect( [=](){ wApp-> removeChild(popup); });
38  return popup;
39 }
40 
41 Wt::Signal<std::string> & Wtx::PopupQuestion::answered()
42 {
43  return m_answered;
44 }