Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / LogWindow / LogWindow.h
1 //  Copyright (C) 2007-2008  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.
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 //  KERNEL SALOME_Event : Define event posting mechanism
23 // File   : LogWindow.h
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #ifndef LOGWINDOW_H
27 #define LOGWINDOW_H
28
29 #if defined WIN32
30 #  if defined LOGWINDOW_EXPORTS
31 #    define LOGWINDOW_EXPORT __declspec( dllexport )
32 #  else
33 #    define LOGWINDOW_EXPORT __declspec( dllimport )
34 #  endif
35 #else
36 #  define LOGWINDOW_EXPORT
37 #endif
38
39 #include <SUIT_PopupClient.h>
40
41 #include <QWidget>
42 #include <QMap>
43 #include <QStringList>
44
45 #ifdef WIN32
46 #pragma warning( disable:4251 )
47 #endif
48
49 class QAction;
50 class QTextEdit;
51
52 class LOGWINDOW_EXPORT LogWindow : public QWidget, public SUIT_PopupClient
53 {
54   Q_OBJECT
55
56 public:
57   //! Context popup menu actions flags
58   enum
59   {
60     CopyId       = 0x01,                                //!< "Copy" menu action
61     ClearId      = 0x02,                                //!< "Clear" menu action
62     SelectAllId  = 0x04,                                //!< "Select All" menu action
63     SaveToFileId = 0x08,                                //!< "Save To File" menu action
64     All = CopyId | ClearId | SelectAllId | SaveToFileId //!< all menu actions
65   };
66
67   //! Display messages flags
68   enum
69   {
70     DisplayNormal    = 0x00,                     //!< do not display extra data
71     DisplayDate      = 0x01,                     //!< display message date
72     DisplayTime      = 0x02,                     //!< display message time
73     DisplaySeparator = 0x04,                     //!< display separator between messages
74     DisplayNoColor   = 0x08,                     //!< display non-colored message
75     DisplayDateTime  = DisplayDate | DisplayTime //!< display date & time
76   };
77
78 public:
79   LogWindow( QWidget* theParent );
80   virtual ~LogWindow();
81
82   virtual             QString popupClientType() const { return QString( "LogWindow" ); }
83   virtual void        contextMenuPopup( QMenu* );
84
85   virtual bool        eventFilter( QObject*, QEvent* );
86
87   QString             banner() const;
88   QString             separator() const;
89
90   void                setBanner( const QString& );
91   void                setSeparator( const QString& );
92
93   void                putMessage( const QString&, const int = DisplayNormal );
94   virtual void        putMessage( const QString&, const QColor&, const int = DisplayNormal );
95   void                clear( const bool = false );
96
97   bool                saveLog( const QString& );
98
99   void                setMenuActions( const int );
100   int                 menuActions() const;
101
102 protected slots:
103   void                onSaveToFile();
104   void                onSelectAll();
105   void                onClear();
106   void                onCopy();
107
108 private:
109   void                createActions();
110   void                updateActions();
111
112 private:
113   QTextEdit*          myView;           //!< internal view window
114   QString             myBanner;         //!< current banner
115   QStringList         myHistory;        //!< messages history
116   QString             mySeparator;      //!< current separator
117   int                 myBannerSize;     //!< current banner's size
118   QMap<int, QAction*> myActions;        //!< popup menu actions
119 };
120
121 #ifdef WIN32
122 #pragma warning( default:4251 )
123 #endif
124
125 #endif // LOGWINDOW_H