14 #include <qlineedit.h>
15 #include <qtextedit.h>
16 #include <qdockwindow.h>
23 font = QFont(
"Courier New");
25 font.setStyleHint(QFont::Courier);
26 font.setFixedPitch(
true);
29 vBox =
new QVBoxLayout(
this);
31 output =
new QTextEdit(
this);
32 output->setReadOnly(
true);
33 output->setUndoRedoEnabled(
false);
34 output->setTextFormat(Qt::LogText);
35 output->setMaxLogLines(2000);
36 output->setWordWrap(QTextEdit::NoWrap);
38 vBox->addWidget(output, 10);
40 input =
new QLineEdit(
this);
41 connect(
input, SIGNAL(returnPressed()), SLOT(slotSendCommand()));
42 vBox->addWidget(
input);
44 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
45 parent_->setWidget(
this);
46 parent_->setResizeEnabled(
true);
47 parent_->setHorizontallyStretchable(
true);
49 histIterator = cmdHistory.end();
55 if(octProcess.isRunning())
65 Size = output->sizeHint();
67 h = Size.height() +
input->sizeHint().height();
74 if(octProcess.isRunning())
77 QStringList CommandLine;
78 CommandLine <<
"octave" <<
"--no-history" <<
"-i" <<
"-f" <<
"-p"
80 octProcess.setArguments(CommandLine);
82 disconnect(&octProcess, 0, 0, 0);
83 connect(&octProcess, SIGNAL(readyReadStderr()), SLOT(slotDisplayErr()));
84 connect(&octProcess, SIGNAL(readyReadStdout()), SLOT(slotDisplayMsg()));
85 connect(&octProcess, SIGNAL(processExited()), SLOT(slotOctaveEnded()));
89 if(!octProcess.start()) {
90 output->setText(tr(
"ERROR: Cannot start Octave!"));
107 int par = output->paragraphs() - 1;
108 int idx = output->paragraphLength(par);
109 output->insertAt(cmd +
"\n", par, idx);
110 octProcess.writeToStdin(cmd +
"\n");
111 output->scrollToBottom();
117 QFileInfo info(name);
122 void OctaveWindow::slotSendCommand()
125 if(!
input->text().stripWhiteSpace().isEmpty())
126 cmdHistory.append(
input->text());
127 histIterator = cmdHistory.end();
134 if(event->key() == Qt::Key_Up) {
135 if(histIterator == cmdHistory.begin())
138 input->setText(*histIterator);
142 if(event->key() == Qt::Key_Down) {
143 if(histIterator == cmdHistory.end())
146 input->setText(*histIterator);
153 void OctaveWindow::slotDisplayMsg()
155 int par = output->paragraphs() - 1;
156 int idx = output->paragraphLength(par);
157 output->insertAt(QString(octProcess.readStdout()), par, idx);
158 output->scrollToBottom();
163 void OctaveWindow::slotDisplayErr()
166 ((QDockWindow*)parent())->show();
168 int par = output->paragraphs() - 1;
169 int idx = output->paragraphLength(par);
170 output->insertAt(QString(octProcess.readStderr()), par, idx);
171 output->scrollToBottom();
176 void OctaveWindow::slotOctaveEnded()