dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
alarmsmonitorwidget.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 #include "alarmsmonitorwidget.h"
26 #include <QFont>
27 #include <coreplugin/icore.h>
28 #include <globalmessaging.h>
29 
30 #define DIMMED_SYMBOL 0.25
31 
32 AlarmsMonitorWidget::AlarmsMonitorWidget()
33  : hasErrors(false)
34  , hasWarnings(false)
35  , hasInfos(false)
36  , needsUpdate(false)
37 {
38 }
39 
40 void AlarmsMonitorWidget::init(QSvgRenderer *renderer, QGraphicsSvgItem *graph)
41 {
42  error_sym = new QGraphicsSvgItem();
43  error_sym->setSharedRenderer(renderer);
44  error_sym->setElementId("error_sym");
45  error_sym->setParentItem(graph);
46  error_txt = new QGraphicsTextItem();
47  error_txt->setDefaultTextColor(Qt::white);
48  error_txt->setFont(QFont("Helvetica", 24, 2));
49  error_txt->setParentItem(graph);
50  error_txt->setPlainText("0");
51 
52  QRectF orig = renderer->boundsOnElement("error_sym");
53  QMatrix Matrix = renderer->matrixForElement("error_sym");
54  orig = Matrix.mapRect(orig);
55  QTransform trans;
56  trans.translate(orig.x(), orig.y());
57  error_sym->setTransform(trans, false);
58  trans.reset();
59  int refY = orig.y();
60  trans.translate(orig.x() + orig.width() + 1, refY);
61  error_txt->setTransform(trans, false);
62  trans.reset();
63 
64  info_sym = new QGraphicsSvgItem();
65  info_sym->setSharedRenderer(renderer);
66  info_sym->setElementId("info_sym");
67  info_sym->setParentItem(graph);
68  info_txt = new QGraphicsTextItem();
69  info_txt->setDefaultTextColor(Qt::white);
70  info_txt->setFont(QFont("Helvetica", 24, 2));
71  info_txt->setParentItem(graph);
72  info_txt->setPlainText("0");
73  orig = renderer->boundsOnElement("info_sym");
74  Matrix = renderer->matrixForElement("info_sym");
75  orig = Matrix.mapRect(orig);
76  trans.translate(orig.x(), orig.y());
77  info_sym->setTransform(trans, false);
78  trans.reset();
79  trans.translate(orig.x() + 3 + orig.width(), refY);
80  info_txt->setTransform(trans, false);
81  trans.reset();
82 
83  warning_sym = new QGraphicsSvgItem();
84  warning_sym->setSharedRenderer(renderer);
85  warning_sym->setElementId("warning_sym");
86  warning_sym->setParentItem(graph);
87  warning_txt = new QGraphicsTextItem();
88  warning_txt->setDefaultTextColor(Qt::white);
89  warning_txt->setFont(QFont("Helvetica", 24, 2));
90  warning_txt->setParentItem(graph);
91  warning_txt->setPlainText("0");
92  orig = renderer->boundsOnElement("warning_sym");
93  Matrix = renderer->matrixForElement("warning_sym");
94  orig = Matrix.mapRect(orig);
95  trans.translate(orig.x(), orig.y());
96  warning_sym->setTransform(trans, false);
97  trans.reset();
98  trans.translate(orig.x() + orig.width() - 23, refY);
99  warning_txt->setTransform(trans, false);
100  trans.reset();
101  error_sym->setOpacity(DIMMED_SYMBOL);
102  warning_sym->setOpacity(DIMMED_SYMBOL);
103  info_sym->setOpacity(DIMMED_SYMBOL);
104  error_txt->setOpacity(DIMMED_SYMBOL);
105  warning_txt->setOpacity(DIMMED_SYMBOL);
106  info_txt->setOpacity(DIMMED_SYMBOL);
107 
108  connect(&alertTimer, SIGNAL(timeout()), this, SLOT(processAlerts()));
109  connect(Core::ICore::instance()->globalMessaging(), SIGNAL(newMessage(GlobalMessage *)), this,
110  SLOT(updateMessages()));
111  connect(Core::ICore::instance()->globalMessaging(), SIGNAL(deletedMessage()), this,
112  SLOT(updateMessages()));
113  connect(Core::ICore::instance()->globalMessaging(), SIGNAL(changedMessage(GlobalMessage *)),
114  this, SLOT(updateNeeded()));
115 
116  alertTimer.start(1000);
117 }
118 
120 {
121  QString error;
122  error.append("<html><head/><body>");
123  foreach (Core::GlobalMessage *msg,
124  Core::ICore::instance()->globalMessaging()->getActiveErrors()) {
125  QString temp;
126  temp = QString("<p><span style=' font-size:11pt; font-weight:600;'>%0</span></p>")
127  .arg(msg->getBrief());
128  error.append(temp);
129  temp = QString("<p><span style=' font-style:italic;'>%0</span></p>")
130  .arg(msg->getDescription());
131  error.append(temp);
132  }
133  error.append("</body></html>");
134  QString warning;
135  warning.append("<html><head/><body>");
136  foreach (Core::GlobalMessage *msg,
137  Core::ICore::instance()->globalMessaging()->getActiveWarnings()) {
138  QString temp;
139  temp = QString("<p><span style=' font-size:11pt; font-weight:600;'>%0</span></p>")
140  .arg(msg->getBrief());
141  warning.append(temp);
142  temp = QString("<p><span style=' font-style:italic;'>%0</span></p>")
143  .arg(msg->getDescription());
144  warning.append(temp);
145  }
146  warning.append("</body></html>");
147  QString info;
148  info.append("<html><head/><body>");
149  foreach (Core::GlobalMessage *msg,
150  Core::ICore::instance()->globalMessaging()->getActiveInfos()) {
151  QString temp;
152  temp = QString("<p><span style=' font-size:11pt; font-weight:600;'>%0</span></p>")
153  .arg(msg->getBrief());
154  info.append(temp);
155  temp = QString("<p><span style=' font-style:italic;'>%0</span></p>")
156  .arg(msg->getDescription());
157  info.append(temp);
158  }
159  info.append("</body></html>");
160  error_txt->setPlainText(
161  QString::number(Core::ICore::instance()->globalMessaging()->getActiveErrors().length()));
162  if (Core::ICore::instance()->globalMessaging()->getActiveErrors().length() > 0) {
163  error_txt->setOpacity(1);
164  hasErrors = true;
165  } else {
166  error = "No errors";
167  error_txt->setOpacity(DIMMED_SYMBOL);
168  hasErrors = false;
169  }
170  warning_txt->setPlainText(
171  QString::number(Core::ICore::instance()->globalMessaging()->getActiveWarnings().length()));
172  if (Core::ICore::instance()->globalMessaging()->getActiveWarnings().length() > 0) {
173  warning_txt->setOpacity(1);
174  hasWarnings = true;
175  } else {
176  warning = "No warnings";
177  warning_txt->setOpacity(DIMMED_SYMBOL);
178  hasWarnings = false;
179  }
180  info_txt->setPlainText(
181  QString::number(Core::ICore::instance()->globalMessaging()->getActiveInfos().length()));
182  if (Core::ICore::instance()->globalMessaging()->getActiveInfos().length() > 0) {
183  info_txt->setOpacity(1);
184  hasInfos = true;
185  } else {
186  info = "No info";
187  info_txt->setOpacity(DIMMED_SYMBOL);
188  hasInfos = false;
189  }
190  error_sym->setToolTip(error);
191  warning_sym->setToolTip(warning);
192  info_sym->setToolTip(info);
193 }
194 
196 {
197  needsUpdate = true;
198 }
199 
201 {
202  if (needsUpdate)
203  updateMessages();
204  ;
205  needsUpdate = false;
206  static bool flag = true;
207  flag = flag ^ true;
208  if (hasErrors) {
209  if (flag)
210  error_sym->setOpacity(1);
211  else
212  error_sym->setOpacity(DIMMED_SYMBOL);
213  } else
214  error_sym->setOpacity(DIMMED_SYMBOL);
215  if (hasWarnings) {
216  if (flag)
217  warning_sym->setOpacity(1);
218  else
219  warning_sym->setOpacity(DIMMED_SYMBOL);
220  } else
221  warning_sym->setOpacity(DIMMED_SYMBOL);
222  if (hasInfos) {
223  if (flag)
224  info_sym->setOpacity(1);
225  else
226  info_sym->setOpacity(DIMMED_SYMBOL);
227  } else
228  info_sym->setOpacity(DIMMED_SYMBOL);
229 }
static ICore * instance()
Definition: coreimpl.cpp:46
void init(QSvgRenderer *renderer, QGraphicsSvgItem *graph)
else error('Your technical computing program does not support file choosers.Please input the file name in the argument. ') end elseif nargin >0 logfile