Salome HOME
Copyright update 2022
[modules/gui.git] / src / LogWindow / LogWindow.h
old mode 100755 (executable)
new mode 100644 (file)
index 44001e0..d20a8ee
-//  KERNEL SALOME_Event : Define event posting mechanism
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  File   : LogWindow.h
-//  Author : 
-//  Module : KERNEL
 
-#ifndef LogWindow_HeaderFile
-#define LogWindow_HeaderFile
+//  KERNEL SALOME_Event : Define event posting mechanism
+// File   : LogWindow.h
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
+#ifndef LOGWINDOW_H
+#define LOGWINDOW_H
 
-#if defined LOGWINDOW_EXPORTS
 #if defined WIN32
-#define LOGWINDOW_EXPORT __declspec( dllexport )
+#  if defined LOGWINDOW_EXPORTS || defined LogWindow_EXPORTS
+#    define LOGWINDOW_EXPORT __declspec( dllexport )
+#  else
+#    define LOGWINDOW_EXPORT __declspec( dllimport )
+#  endif
 #else
-#define LOGWINDOW_EXPORT
-#endif
-#else
-#if defined WIN32
-#define LOGWINDOW_EXPORT __declspec( dllimport )
-#else
-#define LOGWINDOW_EXPORT
-#endif
+#  define LOGWINDOW_EXPORT
 #endif
 
-#include <SUIT_PopupClient.h>
+#include "QtxMsgHandler.h"
+#include "SUIT_PopupClient.h"
 
-#include <qframe.h>
-#include <qstringlist.h>
+#include <QWidget>
+#include <QMap>
+#include <QStringList>
 
 #ifdef WIN32
 #pragma warning( disable:4251 )
 #endif
 
 class QAction;
-class QTextBrowser;
+class QTextEdit;
 
-class LOGWINDOW_EXPORT LogWindow : public QFrame, public SUIT_PopupClient
+class LOGWINDOW_EXPORT LogWindow : public QWidget, public SUIT_PopupClient, public QtxMsgHandlerCallback
 {
   Q_OBJECT
 
-  enum { CopyId, ClearId, SelectAllId, SaveToFileId };
+public:
+  //! Context popup menu actions flags
+  enum
+  {
+    CopyId       = 0x01,                                //!< "Copy" menu action
+    ClearId      = 0x02,                                //!< "Clear" menu action
+    SelectAllId  = 0x04,                                //!< "Select All" menu action
+    SaveToFileId = 0x08,                                //!< "Save To File" menu action
+    All = CopyId | ClearId | SelectAllId | SaveToFileId //!< all menu actions
+  };
+
+  //! Display messages flags
+  enum
+  {
+    DisplayNormal    = 0x00,                     //!< do not display extra data
+    DisplayDate      = 0x01,                     //!< display message date
+    DisplayTime      = 0x02,                     //!< display message time
+    DisplaySeparator = 0x04,                     //!< display separator between messages
+    DisplayNoColor   = 0x08,                     //!< display non-colored message
+    DisplayDateTime  = DisplayDate | DisplayTime //!< display date & time
+  };
 
 public:
-       LogWindow( QWidget* theParent );
-       virtual ~LogWindow();
+  LogWindow( QWidget* );
+  virtual ~LogWindow();
 
   virtual             QString popupClientType() const { return QString( "LogWindow" ); }
-  virtual void        contextMenuPopup( QPopupMenu* );
+  virtual void        contextMenuPopup( QMenu* );
 
-  bool                eventFilter( QObject* o, QEvent* e );
+  virtual bool        eventFilter( QObject*, QEvent* );
 
-  void                setBanner( const QString& banner );
-  void                setSeparator( const QString& separator );
+  QString             banner() const;
+  QString             separator() const;
 
-  virtual void        putMessage( const QString& message, bool addSeparator = true );
-  void                clear( bool clearHistory = false );
+  void                setBanner( const QString& );
+  void                setSeparator( const QString& );
 
-  bool                saveLog( const QString& fileName );
+  void                putMessage( const QString&, const int = DisplayNormal );
+  virtual void        putMessage( const QString&, const QColor&, const int = DisplayNormal );
+  void                clear( const bool = false );
+
+  bool                saveLog( const QString& );
+
+  void                setMenuActions( const int );
+  int                 menuActions() const;
+
+  void                handleQtMessages(bool);
 
 protected slots:
   void                onSaveToFile();
@@ -82,20 +110,22 @@ protected slots:
   void                onCopy();
 
 private:
+  void                append( const QString text );
   void                createActions();
   void                updateActions();
+  void                qtMessage( QtMsgType, const QMessageLogContext&, const QString& );
 
 private:
-  QTextBrowser*       myView;
-  QString             myBanner;
-  QString             mySeparator;
-  QStringList         myHistory;
-  int                 myBannerSize;
-  QMap<int, QAction*> myActions;
+  QTextEdit*          myView;           //!< internal view window
+  QString             myBanner;         //!< current banner
+  QStringList         myHistory;        //!< messages history
+  QString             mySeparator;      //!< current separator
+  int                 myBannerSize;     //!< current banner's size
+  QMap<int, QAction*> myActions;        //!< popup menu actions
 };
 
 #ifdef WIN32
 #pragma warning( default:4251 )
 #endif
 
-#endif
+#endif // LOGWINDOW_H