/*************************************************************************** * Copyright (C) 1980-2005 Artur Wiebe * * artur@wiebenet.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "console.h" #include "config.h" #include #include #include #include #include #include myConsole::myConsole(QWidget* parent) : QFrame(parent) { setFont(QFont(font().family(), 10)); setFrameStyle(QFrame::WinPanel | QFrame::Sunken); // m_log = new QTextEdit(this); m_log->setTextFormat(Qt::LogText); // QToolButton* clearbutton = new QToolButton(this); clearbutton->setPixmap(QPixmap::fromMimeSource("clear.png")); clearbutton->setTextLabel(tr("Clear")); connect(clearbutton, SIGNAL(clicked()), this, SLOT(clear())); // QToolButton* savebutton = new QToolButton(this); savebutton->setPixmap(QPixmap::fromMimeSource("filesave.png")); savebutton->setTextLabel(tr("Save")); connect(savebutton, SIGNAL(clicked()), this, SLOT(save())); // m_input = new QLineEdit(this); m_input->setMaxLength(60); // hard coded aw? connect(m_input, SIGNAL(returnPressed()), this, SLOT(slotSendMsg())); // Layout. QVBoxLayout* vb = new QVBoxLayout(5); vb->addWidget(clearbutton); vb->addWidget(savebutton); vb->addStretch(); QHBoxLayout* hb = new QHBoxLayout(5); hb->addLayout(vb, 0); hb->addWidget(m_log, 1); QVBoxLayout* v = new QVBoxLayout(this, 5); v->addLayout(hb, 1); v->addWidget(m_input); //aw?? m_log->append(tr("Type clear to clear the console.")); } void myConsole::message(int type, const QString& text) { char* s_tag; char* e_tag; switch(type) { case MSG_SYSTEM: s_tag = "--> "; e_tag = ""; break; case MSG_USER: s_tag = ""; e_tag = ""; break; case MSG_OPPONENT: s_tag = ""; e_tag = ""; break; case MSG_FATAL: s_tag = "--> "; e_tag = ""; break; case MSG_LOG: default: s_tag = ""; e_tag = ""; } m_log->append(s_tag + text + e_tag); m_log->scrollToBottom(); emit updated(); } void myConsole::slotSendMsg() { if(m_input->text() == "clear") { clear(); return; } else if(m_input->text() == "save") { save(); return; } else if(m_input->text() == "quit") { //aw??? qApp->closeAllWindows(); } emit sendText(m_input->text()); message(MSG_USER, m_input->text()); m_input->clear(); } void myConsole::clear() { m_log->clear(); m_input->clear(); } void myConsole::save() { QString filename = QFileDialog::getSaveFileName(QString::null, QString::null, this, 0, tr("Save Console")+" "APPNAME); if(!filename.isEmpty()) { QFile file(filename); if(file.open(IO_WriteOnly)) { QTextStream st(&file); st << m_log->text(); } } }