1 | #include <Wt/WVBoxLayout> |
---|
2 | #include <Wt/WImage> |
---|
3 | #include <Wt/WText> |
---|
4 | #include <Wt/WBreak> |
---|
5 | #include <Wt/WHBoxLayout> |
---|
6 | #include <Wt/WPushButton> |
---|
7 | #include <Wt/WCssDecorationStyle> |
---|
8 | #include "GWt_dialog.h" |
---|
9 | |
---|
10 | GWt_dialog::GWt_dialog( |
---|
11 | WString titre, |
---|
12 | std::string message, |
---|
13 | iconType icon, |
---|
14 | bool modal, |
---|
15 | bool ok |
---|
16 | ): |
---|
17 | WDialog(titre) |
---|
18 | { |
---|
19 | |
---|
20 | // change the title bar style |
---|
21 | titleBar()->decorationStyle().setBackgroundColor (WColor(70,180,220)); |
---|
22 | |
---|
23 | WContainerWidget* widgt = new WContainerWidget(contents()); |
---|
24 | WHBoxLayout* hLayout = new WHBoxLayout(); |
---|
25 | |
---|
26 | WImage* tImg = new WImage("icons/error.png"); |
---|
27 | switch (icon) { |
---|
28 | case Warning: |
---|
29 | tImg->setImageLink ("icons/warning.png"); |
---|
30 | tImg->setMaximumSize (70,70); |
---|
31 | hLayout->addWidget(tImg); |
---|
32 | break; |
---|
33 | case Error: |
---|
34 | tImg->setImageLink ("icons/error.png"); |
---|
35 | tImg->setMaximumSize (70,70); |
---|
36 | hLayout->addWidget(tImg); |
---|
37 | break; |
---|
38 | case Info: |
---|
39 | tImg->setImageLink ("icons/info.png"); |
---|
40 | tImg->setMaximumSize (70,70); |
---|
41 | hLayout->addWidget(tImg); |
---|
42 | break; |
---|
43 | case Wait: |
---|
44 | tImg->setImageLink ("icons/patienter.gif"); |
---|
45 | tImg->setMaximumSize (70,70); |
---|
46 | hLayout->addWidget(tImg); |
---|
47 | break; |
---|
48 | case NoIcon: |
---|
49 | break; |
---|
50 | default: |
---|
51 | break; |
---|
52 | } |
---|
53 | |
---|
54 | WContainerWidget* right = new WContainerWidget(); |
---|
55 | WVBoxLayout* vLayout = new WVBoxLayout(); |
---|
56 | |
---|
57 | // changement des "\n" par des <br> |
---|
58 | size_t pos = message.find("\n", 0); |
---|
59 | |
---|
60 | while(pos != std::string::npos) { |
---|
61 | vLayout->addWidget(new Wt::WText(WString::fromUTF8(message.substr(0,pos)))); |
---|
62 | message = message.substr(pos+1); |
---|
63 | pos = message.find("\n"); |
---|
64 | vLayout->addWidget(new Wt::WBreak()); |
---|
65 | } |
---|
66 | vLayout->addWidget(new Wt::WText(WString::fromUTF8(message))); |
---|
67 | |
---|
68 | |
---|
69 | if (ok) { |
---|
70 | vLayout->addWidget(new Wt::WBreak); |
---|
71 | |
---|
72 | Wt::WPushButton *ok = new Wt::WPushButton("Ok"); |
---|
73 | vLayout->addWidget(ok); |
---|
74 | |
---|
75 | // this event will accept() the Dialog |
---|
76 | ok->clicked().connect(this, &Wt::WDialog::accept); |
---|
77 | } |
---|
78 | |
---|
79 | right->setLayout(vLayout); |
---|
80 | hLayout->addWidget(right); |
---|
81 | |
---|
82 | widgt->setLayout(hLayout); |
---|
83 | |
---|
84 | setModal (modal); |
---|
85 | } |
---|
86 | |
---|