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