00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00029 #define YASAGUI_OUTPUT_INCLUDE
00030
00031 #include <qobject.h>
00032 #include <qlistview.h>
00033
00034 #include <qtextview.h>
00035
00036
00037
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
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
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