96 lines
3.7 KiB
C++
96 lines
3.7 KiB
C++
|
#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();
|
||
|
}
|