add dialog example.
All checks were successful
Deploy / PullDocker (push) Successful in 6s
Deploy / Build (push) Successful in 2m23s

This commit is contained in:
amass 2024-10-31 23:30:34 +08:00
parent 1eaa4a6787
commit 3630721e63
4 changed files with 121 additions and 0 deletions

View File

@ -1,6 +1,7 @@
add_library(WebApplication add_library(WebApplication
WebApplication.h WebApplication.cpp WebApplication.h WebApplication.cpp
Hello.h Hello.cpp Hello.h Hello.cpp
Dialog.h Dialog.cpp
Session.h Session.cpp Session.h Session.cpp
User.h User.cpp User.h User.cpp
) )

95
WebApplication/Dialog.cpp Normal file
View File

@ -0,0 +1,95 @@
#include "Dialog.h"
#include <Wt/WMessageBox.h>
#include <Wt/WPushButton.h>
Dialog::Dialog() {
Wt::WContainerWidget *textdiv = addWidget(std::make_unique<Wt::WContainerWidget>());
textdiv->setStyleClass("text");
Wt::WContainerWidget *buttons = addWidget(std::make_unique<Wt::WContainerWidget>());
buttons->setStyleClass("buttons");
Wt::WPushButton *button = buttons->addWidget(std::make_unique<Wt::WPushButton>("One liner"));
button->clicked().connect(this, &Dialog::messageBox1);
button = buttons->addWidget(std::make_unique<Wt::WPushButton>("Comfortable?"));
button->clicked().connect(this, &Dialog::messageBox2);
button = buttons->addWidget(std::make_unique<Wt::WPushButton>("Havoc!"));
button->clicked().connect(this, &Dialog::messageBox3);
button = buttons->addWidget(std::make_unique<Wt::WPushButton>("Discard"));
button->clicked().connect(this, &Dialog::messageBox4);
textdiv = addWidget(std::make_unique<Wt::WContainerWidget>());
textdiv->setStyleClass("text");
m_status = textdiv->addWidget(std::make_unique<Wt::WText>("Go ahead..."));
}
void Dialog::setStatus(const Wt::WString &result) {
m_status->setText(result);
}
void Dialog::messageBox1() {
Wt::WMessageBox::show("信息", "这是一个对话框示例。", Wt::StandardButton::Ok);
setStatus("Ok'ed");
}
void Dialog::messageBox2() {
m_messageBox = std::make_unique<Wt::WMessageBox>("Question", "Are you getting comfortable ?", Wt::Icon::Question,
Wt::StandardButton::Yes | Wt::StandardButton::No |
Wt::StandardButton::Cancel);
m_messageBox->buttonClicked().connect(this, &Dialog::messageBoxDone);
m_messageBox->animateShow(
Wt::WAnimation(Wt::AnimationEffect::Pop | Wt::AnimationEffect::Fade, Wt::TimingFunction::Linear, 250));
}
void Dialog::messageBox3() {
Wt::StandardButton result = Wt::WMessageBox::show("Confirm", "About to wreak havoc... Continue ?",
Wt::StandardButton::Ok | Wt::StandardButton::Cancel,
Wt::WAnimation(Wt::AnimationEffect::SlideInFromTop));
if (result == Wt::StandardButton::Ok)
setStatus("Wreaking havoc.");
else
setStatus("Cancelled!");
}
void Dialog::messageBox4() {
m_messageBox = std::make_unique<Wt::WMessageBox>("Warning!",
"Are you sure you want to continue?\n"
"You have unsaved changes.",
Wt::Icon::None, Wt::StandardButton::None);
m_messageBox->addButton("Discard Modifications", Wt::StandardButton::Ok);
Wt::WPushButton *continueButton = m_messageBox->addButton("Cancel", Wt::StandardButton::Cancel);
m_messageBox->setDefaultButton(continueButton);
m_messageBox->buttonClicked().connect(this, &Dialog::messageBoxDone);
m_messageBox->setOffsets(0, Wt::Side::Bottom);
m_messageBox->animateShow(Wt::WAnimation(Wt::AnimationEffect::SlideInFromBottom | Wt::AnimationEffect::Fade,
Wt::TimingFunction::Linear, 250));
}
void Dialog::messageBoxDone(Wt::StandardButton result) {
switch (result) {
case Wt::StandardButton::Ok:
setStatus("Ok'ed");
break;
case Wt::StandardButton::Cancel:
setStatus("Cancelled!");
break;
case Wt::StandardButton::Yes:
setStatus("Me too!");
break;
case Wt::StandardButton::No:
setStatus("Me neither!");
break;
default:
setStatus("Unknown result?");
}
m_messageBox.reset();
}

22
WebApplication/Dialog.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef __DIALOG_H__
#define __DIALOG_H__
#include <Wt/WContainerWidget.h>
class Dialog : public Wt::WContainerWidget {
public:
Dialog();
protected:
void setStatus(const Wt::WString &result);
void messageBox1();
void messageBox2();
void messageBox3();
void messageBox4();
void messageBoxDone(Wt::StandardButton result);
private:
Wt::WText *m_status = nullptr;
std::unique_ptr<Wt::WMessageBox> m_messageBox;
};
#endif // __DIALOG_H__

View File

@ -1,5 +1,6 @@
#include "Hello.h" #include "Hello.h"
#include "BoostLog.h" #include "BoostLog.h"
#include "Dialog.h"
#include "Session.h" #include "Session.h"
#include <Wt/Auth/AuthService.h> #include <Wt/Auth/AuthService.h>
#include <Wt/Auth/AuthWidget.h> #include <Wt/Auth/AuthWidget.h>
@ -61,6 +62,8 @@ Hello::Hello(const Wt::WEnvironment &env, bool embedded) : Wt::WApplication(env)
authWidget->setRegistrationEnabled(true); authWidget->setRegistrationEnabled(true);
authWidget->processEnvironment(); authWidget->processEnvironment();
top->addWidget(std::move(authWidget)); top->addWidget(std::move(authWidget));
top->addWidget(std::make_unique<Dialog>());
} }
Hello::~Hello() { Hello::~Hello() {