Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Examples  

output.h

Go to the documentation of this file.
00001 
00002 //
00003 // YASA output
00004 //
00005 // Project: Yasa 2
00006 // Author : Jan Blumenthal
00007 // Start  : 2002/02/28
00008 // $Header: /sources/yasa/yasagui/output.h,v 1.4 2003/01/24 15:47:42 bj Exp $
00009 //
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program (See the included file COPYING);
00024 // if not, write to the Free Software Foundation, Inc.,
00025 // 675 Mass Ave, Cambridge, MA 02139, USA.
00026 //
00028 #ifndef YASAGUI_OUTPUT_INCLUDE
00029 #define YASAGUI_OUTPUT_INCLUDE
00030 
00031 #include <qobject.h>
00032 #include <qlistview.h>
00033 //#if QT_VERSION<300
00034  #include <qtextview.h>
00035 //#else
00036 // #include <qtextedit.h>
00037 //#endif
00038 #include <stdio.h>
00039 #include "translations.h"
00040 #include "mainwindow.h"
00041 
00042 
00043 
00046 #define YWARNING_LOW            -1
00047 #define YWARNING_MEDIUM         0
00048 #define YWARNING_HIGH           1
00049 #define YWARNING_DEFAULT        YWARNING_MEDIUM
00050 
00051 
00053 class YOutput : public QObject
00054 {   Q_OBJECT
00055 public:
00056     int             InitInstance()                                      {   return 0;                   }
00057     void            NewLine()                                           {   emit NewMessage("\n");      }
00058     void            Important(const QString &text=QString::null)        {   emit NewImportant(text);    }
00059     void            Command(const QString &text=QString::null)          {   emit NewCommand(text);      }
00060     void            Comment(const QString &text=QString::null)          {   emit NewComment(text);      }
00061     void            Message(const QString &text=QString::null)          {   emit NewMessage(text);      }
00062     void            Warning(const QString &text=QString::null, int level=YWARNING_MEDIUM) { emit NewWarning(text,level);}
00063     void            Error(const QString &text=QString::null)            {   emit NewError(text);        }
00064 signals:
00065     void            NewImportant(const QString &text);
00066     void            NewComment(const QString &text);
00067     void            NewCommand(const QString &text);
00068     void            NewMessage(const QString &text);
00069     void            NewWarning(const QString &text, int level);
00070     void            NewError(const QString &text);
00071 };
00072 
00073 
00074 
00075 
00078 //class YOutputView : public QTextView
00079 class YOutputView : public QTextView
00080 {   Q_OBJECT
00081     YOutput         *output;
00082     QString         buffer;
00084     int             minlevel;
00085 public:             YOutputView(QWidget *widget) :
00086                     QTextView(MSGP_OUTPUTVIEW_WELCOME, MSGP_OUTPUT_TITLE, widget),
00087                     output(0),
00088                     minlevel(YWARNING_MEDIUM)
00089                     {
00090                         // The event filter is needed to receive events occured by pressing the right button of the mouse
00091                         widget->installEventFilter( this );
00092                     }
00093     int             InitInstance(YOutput *output);
00094     void            _print(const QString &str);
00095 protected:
00096     bool            eventFilter(QObject *o, QEvent *e);
00097     virtual QPopupMenu *
00098                     createPopupMenu( const QPoint & pos );
00099 public slots:
00100     void            PrintImportant(const QString &text)                 {   _print( QString("<font size=5 color=\"#e00000\">%1</font>").arg(text) );    }
00101     void            PrintCommand(const QString &text)                   {   _print( text );                                                             }
00102     void            PrintComment(const QString &text)                   {   _print( QString("<font color=\"#005000\">%1</font>").arg(text) );           }
00103     void            PrintMessage(const QString &text)                   {   _print( text );                                                             }
00104     void            PrintWarning(const QString &text, int level)        {   if (level>=minlevel)
00105                                                                                 _print( QString("<font color=\"#0000e0\">Warning: %1</font>").arg(text) );  }
00106     void            PrintError(const QString &text)                     {   _print( QString("<font color=\"#e00000\">Error: %1</font>").arg(text) );    }
00107     void            ClearView()                                         {   setText(QString::null);
00108                                                                             buffer=QString::null;                                                       }
00109     void            PopupMenuActivated(int index);
00110     YOutput*        GetOutput() const                                   {   return output;  }
00111     const QString & GetText();
00112 };
00113 
00114 
00115 
00116 
00117 
00119 class YOutputWindowFrameArgs : public YFrameArgs
00120 {   YOutputView         *oritextview;
00121 public:                 YOutputWindowFrameArgs( YOutputView *oritextview );
00122     YOutputView*        GetOutputView() const                           {   return oritextview; }
00123 };
00126 class YOutputWindowFrame : public YFrame
00127 {   Q_OBJECT
00128 protected:
00129     YOutputView         outputview;
00130 public:                 YOutputWindowFrame(QWidget *parent, YFrameArgs &args) :
00131                         YFrame(args),
00132                         outputview(parent)
00133                         {}
00134     virtual int         InitInstance()                          {   outputview.InitInstance( ((YOutputWindowFrameArgs&)GetFrameArgs()).GetOutputView()->GetOutput() );
00135                                                                     outputview.setText( MSGP_OUTPUTVIEW_WELCOME );
00136                                                                     outputview.append( ((YOutputWindowFrameArgs&)GetFrameArgs()).GetOutputView()->GetText() );
00137                                                                     return YFrame::InitInstance();  }
00138     virtual QWidget*    GetMainWidget()                             { return &outputview;   }
00139     static YFrame*      CreateOutputWindowFrame(QWidget *parent, YFrameArgs &args)
00140                         {
00141                             return new YOutputWindowFrame(parent, args );
00142                         }
00143 };
00144 
00145 
00146 
00149 class YConsoleOutput : public QObject
00150 {   Q_OBJECT
00151 public:             YConsoleOutput(YOutput *output)
00152                     {
00153                         connect( output, SIGNAL( NewMessage(const QString &) ), this, SLOT( PrintMessage(const QString &) ) );
00154                         connect( output, SIGNAL( NewWarning(const QString &) ), this, SLOT( PrintWarning(const QString &) ) );
00155                         connect( output, SIGNAL( NewError(const QString &) ), this, SLOT( PrintError(const QString &) ) );
00156                     }
00157     int             InitInstance();
00158 public slots:
00159     void            PrintMessage(const QString &text)
00160                     {
00161                         if ( text.length() )
00162                             printf( text.latin1() );
00163                         else
00164                             printf("\n");
00165                     }
00166     void            PrintWarning(const QString &text)
00167                     {
00168                         if ( text.length() )
00169                             printf( text.latin1() );
00170                         else
00171                             printf("\n");
00172                     }
00173     void            PrintError(const QString &text)
00174                     {
00175                         if ( text.length() )
00176                             printf( text.latin1() );
00177                         else
00178                             printf("\n");
00179                     }
00180 };
00181 
00182 
00183 
00185 #endif                                                                  // ifndef YASAGUI_OUTPUT_INCLUDE

Generated on Thu Feb 13 23:43:54 2003 for Yasa by doxygen1.3-rc3