CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxConsoleWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #ifndef CXCONSOLEWIDGET_H_
35 #define CXCONSOLEWIDGET_H_
36 
37 #include "cxResourceWidgetsExport.h"
38 
39 #include "cxBaseWidget.h"
40 #include "cxReporter.h"
41 #include <QTextBrowser>
42 #include <QTextCharFormat>
43 #include "cxStringProperty.h"
44 class QTableWidget;
45 class QTableWidgetItem;
46 
47 
48 class QContextMenuEvent;
49 class QAction;
50 class QStackedLayout;
51 
52 namespace cx
53 {
54 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
55 
56 class LogMessageDisplayWidget : public QWidget
57 {
58 public:
59  LogMessageDisplayWidget(QWidget *parent);
61  virtual void clear() = 0;
62  virtual void add(const Message& message) = 0;
63  virtual void normalize() = 0;
64  virtual QString getType() const = 0;
65  virtual void setScrollToBottom(bool on) = 0;
66  virtual void showHeader(bool on) = 0;
67 protected:
68  void createTextCharFormats();
69  std::map<MESSAGE_LEVEL, QTextCharFormat> mFormat;
70 };
71 
73 {
74 public:
75  DetailedLogMessageDisplayWidget(QWidget* parent, XmlOptionFile options);
77  virtual void clear();
78  virtual void add(const Message& message);
79  virtual void normalize();
80  virtual QString getType() const { return "detail";}
81  virtual void setScrollToBottom(bool on);
82  virtual void showHeader(bool on);
83 
84 protected:
86  QTableWidget* mTable;
87  QTableWidgetItem *addItem(int column, QString text, const Message& message);
88  void scrollToBottom();
90 };
91 
93 {
94 public:
95  SimpleLogMessageDisplayWidget(QWidget* parent=NULL);
97  virtual void clear();
98  virtual void add(const Message& message);
99  virtual void normalize();
100  virtual QString getType() const { return "simple";}
101  virtual void setScrollToBottom(bool on);
102  virtual void showHeader(bool on) {}
103 
104  QTextBrowser* mBrowser;
105  void format(const Message &message);
106  QString getCompactMessage(Message message);
107 private:
108  void scrollToBottom();
109  bool mScrollToBottomEnabled;
110 };
111 
112 class PopupButton : public QFrame
113 {
114  Q_OBJECT
115 public:
116  PopupButton(QWidget *parent = NULL);
117  bool getShowPopup() const;
118 
119 signals:
120  void popup(bool show);
121 private slots:
122  void onTriggered();
123 protected:
124 // void mouseMoveEvent(QMouseEvent* event);
125 private:
126  QAction* mAction;
127  QToolButton* mShowHeaderButton;
128 
129 };
130 
138 class cxResourceWidgets_EXPORT ConsoleWidget: public BaseWidget
139 {
140 Q_OBJECT
141 
142 public:
143  ConsoleWidget(QWidget* parent, QString uid="ConsoleWidget", QString name="Console");
144  ConsoleWidget(QWidget* parent, QString uid, QString name, XmlOptionFile options, LogPtr log);
145  ~ConsoleWidget();
146 
147  void setDetails(bool on);
148 
149 protected slots:
150  void contextMenuEvent(QContextMenuEvent* event);
151  virtual void showEvent(QShowEvent* event);
152 
153 protected:
154  virtual void prePaintEvent();
155 
156 private slots:
157  void onChannelSelectorChanged();
158  void onLoggingFolderChanged();
159  void receivedMessage(Message message);
160  void receivedChannel(QString channel);
161 
162  void onSeverityUp();
163  void onSeverityDown();
164  void onSeverityChange(int delta);
165  void updateUI();
166  void clearTable();
167  void updateShowHeader();
168 
169 private:
170  XmlOptionItem option(QString name);
171  void createUI();
172  void printMessage(const Message& message);
173  void addSeverityButtons(QBoxLayout* buttonLayout);
174  void addDetailsButton(QBoxLayout* buttonLayout);
175  void createChannelSelector();
176  void updateSeverityIndicator(QString iconname, QString help);
177  void addSeverityIndicator(QBoxLayout* buttonLayout);
178  void updateSeverityIndicator();
179  QString getDetailTypeFromButton() const;
180  void selectMessagesWidget();
181  void createButtonWidget();
182 
183 // QAction* mLineWrappingAction;
184  QAction* mSeverityAction;
185  LogMessageDisplayWidget* mMessagesWidget;
186  QVBoxLayout* mMessagesLayout;
187 
188  QAction* mDetailsAction;
189  StringPropertyPtr mChannelSelector;
190  QStringList mChannels;
191  MessageListenerPtr mMessageListener;
192  boost::shared_ptr<class MessageFilterConsole> mMessageFilter;
193  XmlOptionFile mOptions;
194  QWidget* mButtonWidget;
195  QHBoxLayout* mControlLayout;
196  PopupButton* mShowControlsButton;
197 
198 
199  LogPtr mLog;
200 };
201 } // namespace cx
202 #endif /* CXCONSOLEWIDGET_H_ */
QString getCompactMessage(Message message)
SimpleLogMessageDisplayWidget(QWidget *parent=NULL)
virtual void showHeader(bool on)=0
virtual QString getType() const
DetailedLogMessageDisplayWidget(QWidget *parent, XmlOptionFile options)
PopupButton(QWidget *parent=NULL)
void format(const Message &message)
formats the text to suit the message level
Widget for displaying status messages.
virtual QString getType() const =0
virtual void setScrollToBottom(bool on)
virtual void showHeader(bool on)
void popup(bool show)
Helper class for storing one string value in an xml document.
boost::shared_ptr< class StringProperty > StringPropertyPtr
boost::shared_ptr< class Log > LogPtr
Definition: cxLog.h:68
std::map< MESSAGE_LEVEL, QTextCharFormat > mFormat
QTableWidgetItem * addItem(int column, QString text, const Message &message)
void createTextCharFormats()
sets up the formating rules for the message levels
bool getShowPopup() const
virtual void add(const Message &message)=0
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
virtual void add(const Message &message)
virtual QString getType() const
LogMessageDisplayWidget(QWidget *parent)
virtual void normalize()=0
virtual void add(const Message &message)
virtual void setScrollToBottom(bool on)=0
Helper class for xml files used to store ssc/cx data.
boost::shared_ptr< class MessageListener > MessageListenerPtr
Definition: cxLog.h:66