File: message-window.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (59 lines) | stat: -rw-r--r-- 2,973 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#if defined(Hiro_MessageWindow)

namespace hiro {

static auto MessageWindow_buttons(MessageWindow::Buttons buttons) -> QMessageBox::StandardButtons {
  QMessageBox::StandardButtons standardButtons = QMessageBox::NoButton;
  if(buttons == MessageWindow::Buttons::Ok) standardButtons = QMessageBox::Ok;
  if(buttons == MessageWindow::Buttons::OkCancel) standardButtons = QMessageBox::Ok | QMessageBox::Cancel;
  if(buttons == MessageWindow::Buttons::YesNo) standardButtons = QMessageBox::Yes | QMessageBox::No;
  if(buttons == MessageWindow::Buttons::YesNoCancel) standardButtons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
  return standardButtons;
}

static auto MessageWindow_response(MessageWindow::Buttons buttons, QMessageBox::StandardButton response) -> MessageWindow::Response {
  if(response == QMessageBox::Ok) return MessageWindow::Response::Ok;
  if(response == QMessageBox::Cancel) return MessageWindow::Response::Cancel;
  if(response == QMessageBox::Yes) return MessageWindow::Response::Yes;
  if(response == QMessageBox::No) return MessageWindow::Response::No;

  //MessageWindow was closed via window manager, rather than by a button; assume a cancel/no response
  if(buttons == MessageWindow::Buttons::Ok) return MessageWindow::Response::Ok;
  if(buttons == MessageWindow::Buttons::OkCancel) return MessageWindow::Response::Cancel;
  if(buttons == MessageWindow::Buttons::YesNo) return MessageWindow::Response::No;
  if(buttons == MessageWindow::Buttons::YesNoCancel) return MessageWindow::Response::Cancel;

  throw;
}

auto pMessageWindow::error(MessageWindow::State& state) -> MessageWindow::Response {
  return MessageWindow_response(
    state.buttons, QMessageBox::critical(state.parent ? state.parent->self()->qtWindow : nullptr, state.title ? QString::fromUtf8(state.title) : " ",
    QString::fromUtf8(state.text), MessageWindow_buttons(state.buttons))
  );
}

auto pMessageWindow::information(MessageWindow::State& state) -> MessageWindow::Response {
  return MessageWindow_response(
    state.buttons, QMessageBox::information(state.parent ? state.parent->self()->qtWindow : nullptr, state.title ? QString::fromUtf8(state.title) : " ",
    QString::fromUtf8(state.text), MessageWindow_buttons(state.buttons))
  );
}

auto pMessageWindow::question(MessageWindow::State& state) -> MessageWindow::Response {
  return MessageWindow_response(
    state.buttons, QMessageBox::question(state.parent ? state.parent->self()->qtWindow : nullptr, state.title ? QString::fromUtf8(state.title) : " ",
    QString::fromUtf8(state.text), MessageWindow_buttons(state.buttons))
  );
}

auto pMessageWindow::warning(MessageWindow::State& state) -> MessageWindow::Response {
  return MessageWindow_response(
    state.buttons, QMessageBox::warning(state.parent ? state.parent->self()->qtWindow : nullptr, state.title ? QString::fromUtf8(state.title) : " ",
    QString::fromUtf8(state.text), MessageWindow_buttons(state.buttons))
  );
}

}

#endif