arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

ErrTxtWin.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     7-15-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 
00019 // ErrTxtWin.cpp
00020 
00021 #include "ErrTxtWin.h"
00022 #include <iostream>
00023 
00024 using namespace std;
00025 
00026 ErrTxtWin::ErrTxtWin(const char *txt, QWidget *parent, const char *name, WFlags wf)
00027 : QMainWindow(parent,name,wf), _mle(0)
00028 {
00029    _mle = new QMultiLineEdit(this, "multiLineEdit" );
00030    _mle->setReadOnly(true);
00031    _mle->setText(txt);
00032    _mle->connect(this,SIGNAL(textChanged(const QString&)),SLOT(setText(const QString &)));
00033    setCentralWidget(_mle);
00034    setCaption("Error");
00035 }
00036 
00037 ErrTxtWin::~ErrTxtWin()
00038 {
00039 
00040 }
00041 
00042 void ErrTxtWin::changeText(const char *txt)
00043 {
00044    textChanged(QString(txt));
00045 }
00046 
00047 void ErrTxtWin::changeText(const QString &s)
00048 {
00049    textChanged(s);
00050 }
00051 
00052 
00053 void ErrTxtWin::launchError(const QString &s)
00054 {
00055    if(!s.isEmpty())
00056    {
00057       changeText(s);
00058       show();
00059       cerr << "ErrTxtWin::error:\n" << s << endl;
00060    }
00061 }
00062 
00063 void ErrTxtWin::maybeError(const QString &s)
00064 {
00065    if(!s.isEmpty())
00066    {
00067       changeText(s);
00068       show();
00069       cerr << "ErrTxtWin::error:\n" << s << endl;
00070    }
00071    else
00072    {
00073       close();
00074    }
00075 }
00076 
00077 //////////////////////////////////////////////////////////////////////////
00078 /// set selection, sigh should have just been a multiline!
00079 //////////////////////////////////////////////////////////////////////////
00080 void ErrTxtWin::setSelection(int start, int length)
00081 {
00082    _mle->setSelection(0,start,0,length);   
00083 }
00084 
00085 void ErrTxtWin::markSelection(int pos)
00086 {
00087    QString text = _mle->text();
00088 
00089    text.insert(pos, ">>>>>>>");
00090    changeText(text);
00091 }
00092 
00093 
00094 //////////////////////////////////////////////////////////////////////////
00095 /// keys
00096 //////////////////////////////////////////////////////////////////////////
00097 
00098 void ErrTxtWin::keyPressEvent(QKeyEvent *key)
00099 {
00100    switch(key->key())
00101    {
00102    case 4096: //< escape key
00103       key->accept();
00104       close();
00105       break;
00106 
00107    default:
00108       //cerr << "Key event : " << key->key() << " = ' " << char(key->ascii()) << " ' " << endl;
00109       break;
00110    }
00111 }

Send questions, comments, and bug reports to:
jmk