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 | WContainerWidget* wc, |
---|
13 | bool modal |
---|
14 | ): |
---|
15 | WDialog(titre) |
---|
16 | { |
---|
17 | |
---|
18 | // change the title bar style |
---|
19 | titleBar()->decorationStyle().setBackgroundColor (WColor(70,180,220)); |
---|
20 | |
---|
21 | WContainerWidget* widgt = new WContainerWidget(contents()); |
---|
22 | WHBoxLayout* hLayout = new WHBoxLayout(); |
---|
23 | hLayout->addWidget(wc); |
---|
24 | widgt->setLayout(hLayout); |
---|
25 | |
---|
26 | setClosable(true); |
---|
27 | setModal (modal); |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | GWt_dialog::GWt_dialog( |
---|
33 | WString titre, |
---|
34 | std::string message, |
---|
35 | iconType icon, |
---|
36 | bool modal, |
---|
37 | bool ok |
---|
38 | ): |
---|
39 | WDialog(titre) |
---|
40 | { |
---|
41 | |
---|
42 | // change the title bar style |
---|
43 | titleBar()->decorationStyle().setBackgroundColor (WColor(70,180,220)); |
---|
44 | |
---|
45 | WContainerWidget* widgt = new WContainerWidget(contents()); |
---|
46 | WHBoxLayout* hLayout = new WHBoxLayout(); |
---|
47 | |
---|
48 | WImage* tImg = new WImage("icons/error.png"); |
---|
49 | switch (icon) { |
---|
50 | case Warning: |
---|
51 | tImg->setImageLink ("icons/warning.png"); |
---|
52 | tImg->setMaximumSize (70,70); |
---|
53 | hLayout->addWidget(tImg); |
---|
54 | break; |
---|
55 | case Error: |
---|
56 | tImg->setImageLink ("icons/error.png"); |
---|
57 | tImg->setMaximumSize (70,70); |
---|
58 | hLayout->addWidget(tImg); |
---|
59 | break; |
---|
60 | case Info: |
---|
61 | tImg->setImageLink ("icons/info.png"); |
---|
62 | tImg->setMaximumSize (70,70); |
---|
63 | hLayout->addWidget(tImg); |
---|
64 | break; |
---|
65 | case Wait: |
---|
66 | tImg->setImageLink ("icons/patientez.gif"); |
---|
67 | tImg->setMaximumSize (70,70); |
---|
68 | hLayout->addWidget(tImg); |
---|
69 | break; |
---|
70 | case NoIcon: |
---|
71 | break; |
---|
72 | default: |
---|
73 | break; |
---|
74 | } |
---|
75 | |
---|
76 | WContainerWidget* right = new WContainerWidget(); |
---|
77 | WVBoxLayout* vLayout = new WVBoxLayout(); |
---|
78 | |
---|
79 | // changement des "\n" par des <br> |
---|
80 | size_t pos = message.find("\n", 0); |
---|
81 | |
---|
82 | while(pos != std::string::npos) { |
---|
83 | vLayout->addWidget(new Wt::WText(WString::fromUTF8(message.substr(0,pos)))); |
---|
84 | message = message.substr(pos+1); |
---|
85 | pos = message.find("\n"); |
---|
86 | vLayout->addWidget(new Wt::WBreak()); |
---|
87 | } |
---|
88 | vLayout->addWidget(new Wt::WText(WString::fromUTF8(message))); |
---|
89 | |
---|
90 | |
---|
91 | if (ok) { |
---|
92 | vLayout->addWidget(new Wt::WBreak); |
---|
93 | |
---|
94 | Wt::WPushButton *ok = new Wt::WPushButton("Ok"); |
---|
95 | vLayout->addWidget(ok); |
---|
96 | |
---|
97 | // this event will accept() the Dialog |
---|
98 | ok->clicked().connect(this, &Wt::WDialog::accept); |
---|
99 | } |
---|
100 | |
---|
101 | right->setLayout(vLayout); |
---|
102 | hLayout->addWidget(right); |
---|
103 | |
---|
104 | widgt->setLayout(hLayout); |
---|
105 | |
---|
106 | setClosable(true); |
---|
107 | setModal (modal); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|