Salome HOME
Copyright update 2022
[modules/gui.git] / src / LogWindow / LogWindow.h
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  KERNEL SALOME_Event : Define event posting mechanism
24 // File   : LogWindow.h
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 //
27 #ifndef LOGWINDOW_H
28 #define LOGWINDOW_H
29
30 #if defined WIN32
31 #  if defined LOGWINDOW_EXPORTS || defined LogWindow_EXPORTS
32 #    define LOGWINDOW_EXPORT __declspec( dllexport )
33 #  else
34 #    define LOGWINDOW_EXPORT __declspec( dllimport )
35 #  endif
36 #else
37 #  define LOGWINDOW_EXPORT
38 #endif
39
40 #include "QtxMsgHandler.h"
41 #include "SUIT_PopupClient.h"
42
43 #include <QWidget>
44 #include <QMap>
45 #include <QStringList>
46
47 #ifdef WIN32
48 #pragma warning( disable:4251 )
49 #endif
50
51 class QAction;
52 class QTextEdit;
53
54 class LOGWINDOW_EXPORT LogWindow : public QWidget, public SUIT_PopupClient, public QtxMsgHandlerCallback
55 {
56   Q_OBJECT
57
58 public:
59   //! Context popup menu actions flags
60   enum
61   {
62     CopyId       = 0x01,                                //!< "Copy" menu action
63     ClearId      = 0x02,                                //!< "Clear" menu action
64     SelectAllId  = 0x04,                                //!< "Select All" menu action
65     SaveToFileId = 0x08,                                //!< "Save To File" menu action
66     All = CopyId | ClearId | SelectAllId | SaveToFileId //!< all menu actions
67   };
68
69   //! Display messages flags
70   enum
71   {
72     DisplayNormal    = 0x00,                     //!< do not display extra data
73     DisplayDate      = 0x01,                     //!< display message date
74     DisplayTime      = 0x02,                     //!< display message time
75     DisplaySeparator = 0x04,                     //!< display separator between messages
76     DisplayNoColor   = 0x08,                     //!< display non-colored message
77     DisplayDateTime  = DisplayDate | DisplayTime //!< display date & time
78   };
79
80 public:
81   LogWindow( QWidget* );
82   virtual ~LogWindow();
83
84   virtual             QString popupClientType() const { return QString( "LogWindow" ); }
85   virtual void        contextMenuPopup( QMenu* );
86
87   virtual bool        eventFilter( QObject*, QEvent* );
88
89   QString             banner() const;
90   QString             separator() const;
91
92   void                setBanner( const QString& );
93   void                setSeparator( const QString& );
94
95   void                putMessage( const QString&, const int = DisplayNormal );
96   virtual void        putMessage( const QString&, const QColor&, const int = DisplayNormal );
97   void                clear( const bool = false );
98
99   bool                saveLog( const QString& );
100
101   void                setMenuActions( const int );
102   int                 menuActions() const;
103
104   void                handleQtMessages(bool);
105
106 protected slots:
107   void                onSaveToFile();
108   void                onSelectAll();
109   void                onClear();
110   void                onCopy();
111
112 private:
113   void                append( const QString text );
114   void                createActions();
115   void                updateActions();
116   void                qtMessage( QtMsgType, const QMessageLogContext&, const QString& );
117
118 private:
119   QTextEdit*          myView;           //!< internal view window
120   QString             myBanner;         //!< current banner
121   QStringList         myHistory;        //!< messages history
122   QString             mySeparator;      //!< current separator
123   int                 myBannerSize;     //!< current banner's size
124   QMap<int, QAction*> myActions;        //!< popup menu actions
125 };
126
127 #ifdef WIN32
128 #pragma warning( default:4251 )
129 #endif
130
131 #endif // LOGWINDOW_H