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