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