1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
|
#include <stdarg.h>
#include <cstdio>
#include <QPushButton>
#include <QFile>
#include <QDir>
#include <QMessageBox>
#include <QApplication>
#include <QFontMetrics>
#include <QScrollBar>
#include <QClipboard>
#include <QKeyEvent>
#include <QPixmap>
#include <QMimeData>
#include <QTimer>
#include "QFitsGlobal.h"
#include "qtdpuser.h"
#include "QFitsMainWindow.h"
#include "platform.h"
extern "C" {
#include "resources/dpusericon.xpm"
}
int init_dpuser();
QStringList qtinput;
QMutex *qtinputmutex;
QMutex *dpusermutex;
dpuser_thread dpuserthread;
extern bool pythonmode;
/* Copied from
http://lists.trolltech.com/qt-interest/2005-06/thread00166-0.html
with bugfix
http://lists.qt-project.org/pipermail/interest/2011-November/000085.html
*/
//################
//# qdebugstream.h #
//################
#ifndef Q_DEBUG_STREAM_H
#define Q_DEBUG_STREAM_H
#include <iostream>
#include <streambuf>
#include <string>
class QDebugStream : public std::basic_streambuf<char>
{
public:
QDebugStream(std::ostream &stream) : m_stream(stream)
{
m_old_buf = stream.rdbuf();
stream.rdbuf(this);
}
~QDebugStream()
{
// output anything that is left
if (!m_string.empty())
dpDisplayOutput(QString::fromStdString(m_string));
m_stream.rdbuf(m_old_buf);
}
protected:
virtual int_type overflow(int_type v)
{
if (v == '\n')
{
dpDisplayOutput(QString::fromStdString(m_string));
m_string.erase(m_string.begin(), m_string.end());
}
else
m_string += v;
return v;
}
virtual std::streamsize xsputn(const char *p, std::streamsize n)
{
m_string.append(p, p + n);
// int pos = 0;
// unsigned pos = 0; // avoid conversion warnings
size_t pos = 0; // patch to avoid 64-bit conversion error
while (pos != std::string::npos)
{
pos = m_string.find('\n');
if (pos != std::string::npos)
{
std::string tmp(m_string.begin(), m_string.begin() + pos);
dpDisplayOutput(QString::fromStdString(tmp));
m_string.erase(m_string.begin(), m_string.begin() + pos + 1);
}
}
return n;
}
private:
std::ostream &m_stream;
std::streambuf *m_old_buf;
std::string m_string;
};
#endif
int dp_output(const char *msg, ...) {
// char _tmp[1024];
// va_list args;
// if (dpuser_widget) {
// va_start(args, msg);
// vsnprintf(_tmp, 1023, msg, args);
// va_end(args);
// if (strlen(_tmp) > 0)
// if (_tmp[strlen(_tmp)-1] == '\n')
// _tmp[strlen(_tmp)-1] = '\0';
// dpDisplayOutput(_tmp);
// }
// return 1;
// Code from https://stackoverflow.com/questions/19009094/c-variable-arguments-with-stdstring-only, requires C++11
// initialize use of the variable argument array
va_list args;
if (dpuser_widget) {
va_start(args, msg);
// reliably acquire the size from a copy of
// the variable argument array
// and a functionally reliable call
// to mock the formatting
va_list vaCopy;
va_copy(vaCopy, args);
const int iLen = std::vsnprintf(NULL, 0, msg, vaCopy);
va_end(vaCopy);
// return a formatted string without
// risking memory mismanagement
// and without assuming any compiler
// or platform specific behavior
char *_tmp = (char *)malloc((iLen + 2) * sizeof(char)); // +2 for paranoia
if (_tmp != NULL) {
vsnprintf(_tmp, iLen + 1, msg, args);
if (strlen(_tmp) > 0)
if (_tmp[strlen(_tmp)-1] == '\n')
_tmp[strlen(_tmp)-1] = '\0';
dpDisplayOutput(_tmp);
free(_tmp);
}
va_end(args);
}
return 1;
}
int dp_output_string(const char *dummy, const char *msg) {
if (dpuser_widget) {
dpDisplayOutput(msg);
}
return 1;
}
int dp_log(int level, const char *msg, ...) {
char _tmp[1024];
va_list args;
if (dpuser_widget) {
va_start(args, msg);
vsnprintf(_tmp, 1023, msg, args);
va_end(args);
if (strlen(_tmp) > 0)
if (_tmp[strlen(_tmp)-1] == '\n')
_tmp[strlen(_tmp)-1] = '\0';
dpDisplayOutput(_tmp);
}
return 1;
}
void dpuser_thread::run() {
init_dpuser();
}
void dpuser_thread::sendVar(const std::string &which) {
emit dpuserVar(which);
}
void dpuser_thread::sendView(const std::string &which) {
emit dpuserView(which);
}
void dpuser_thread::sendCommand(const char *what, const char *args, const int &option) {
QString cmd(what);
QString arguments(args);
emit dpuserCommand(cmd, arguments, option);
}
dpuserOutput::dpuserOutput(QWidget *parent) : QTextEdit(parent) {
setWordWrapMode(QTextOption::WrapAnywhere);
}
void dpuserOutput::focusInEvent(QFocusEvent *e) {
((qtdpuser *)parent())->input->setFocus();
}
void dpuserOutput::paste() {
emit pasteRequested();
}
void dpuserOutput::dropEvent(QDropEvent *e) {
dynamic_cast<qtdpuser *>(parent())->dropEvent(e);
}
void dpuserOutput::mouseReleaseEvent(QMouseEvent *e) {
if (e->button() == Qt::MiddleButton)
emit pasteSelectionRequested();
}
qtdpuserInput::qtdpuserInput(QWidget *parent) : QLineEdit(parent) {
setFocusPolicy(Qt::StrongFocus);
}
bool qtdpuserInput::event(QEvent *e) {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = (QKeyEvent *)e;
switch (ke->key()) {
case Qt::Key_Tab:
emit(tabPressed());
e->accept();
break;
case Qt::Key_Up:
emit(upPressed());
ke->ignore();
break;
case Qt::Key_Down:
emit(downPressed());
ke->ignore();
break;
default:
// don't handle this here, otherwise qtdpuser looses focus when this is executed...
// if (((ke->key() == Qt::Key_Right) || (ke->key() == Qt::Key_Left)) &&
// (ke->modifiers() == Qt::CTRL)) {
// fitsMainWindow->main_view->keyPressEvent(ke);
// } else {
if (ke->matches(QKeySequence::Paste)) {
emit pasteRequested();
ke->ignore();
} else {
QLineEdit::keyPressEvent(ke);
}
// }
break;
}
return true;
// } else if (e->type() == QEvent::MouseButtonRelease && dynamic_cast<QMouseEvent *>(e)->button() == Qt::MidButton) {
// emit pasteRequested();
}
else return QLineEdit::event(e);
}
void qtdpuserInput::keyPressEvent(QKeyEvent *e) {
dpuser_widget->keyPressEvent(e);
}
void qtdpuserInput::paste() {
emit pasteRequested();
}
void qtdpuserInput::dropEvent(QDropEvent *e) {
dynamic_cast<qtdpuser *>(parent())->dropEvent(e);
}
void qtdpuserInput::mouseReleaseEvent(QMouseEvent *e) {
if (e->button() == Qt::MiddleButton)
emit pasteSelectionRequested();
}
qtdpuser::qtdpuser(QWidget *parent) : QWidget(parent) {
QFont theFont(settings.textfont, settings.textsize);
history = new dpuserOutput(this);
history->setFrameStyle(QFrame::NoFrame);
history->setGeometry(0, 0, width(), height() - 20);
history->setStyleSheet("font-family: " + settings.textfont + "; font-size: " + QString::number(settings.textsize) + "pt");
history->setText("");
history->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
prompt = new QLabel("DPUSER> ", this);
prompt->setStyleSheet("border: none; font-family: " + settings.textfont + "; font-size: " + QString::number(settings.textsize) + "pt");
prompt->adjustSize();
prompt->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
prompt->setGeometry(0, height() - 20, prompt->width(), 20);
input = new qtdpuserInput(this);
input->setGeometry(prompt->width() + prompt->x(), height() - 20, width() - prompt->width() - prompt->x(), 20);
input->setFocus();
input->setStyleSheet("border: none; font-family: " + settings.textfont + "; font-size: " + QString::number(settings.textsize) + "pt");
list = new QStringList();
connect(input, SIGNAL(returnPressed()), SLOT(appendHistory()));
histpos = list->begin();
// setIcon(QPixmap((const char **)dpusericon));
setFocusPolicy(Qt::StrongFocus);
// find out how wide 80 characters are and set width accordingly
QFontMetrics f(theFont);
setMinimumSize(f.boundingRect("MMMMMMMMM").width() + history->verticalScrollBar()->width(), 100);
connect(input, SIGNAL(tabPressed()),
this, SLOT(fileNameCompletion()));
connect(input, SIGNAL(pasteRequested()),
this, SLOT(paste()));
connect(history, SIGNAL(pasteRequested()),
this, SLOT(paste()));
connect(input, SIGNAL(pasteSelectionRequested()),
this, SLOT(pasteSelection()));
connect(history, SIGNAL(pasteSelectionRequested()),
this, SLOT(pasteSelection()));
connect(&dpuserthread, SIGNAL(dpuserText(const QString &)),
this, SLOT(dpuserText(const QString &)));
// make stdout and stderr unbuffered
// setvbuf(stdout,NULL,_IONBF,0);
// setvbuf(stderr,NULL,_IONBF,0);
// redirect stderr to stdout
// std::cerr.rdbuf(std::cout.rdbuf());
// redirect stdout and stderr to streambuf (works only for C++ std::cout and std::cerr, not the C stdout!
// oldstdout_buffer = std::cout.rdbuf(stdout_buffer.rdbuf());
// oldstderr_buffer = std::cerr.rdbuf(stderr_buffer.rdbuf());
QDebugStream *qout = new QDebugStream (std::cout);
QDebugStream *qerr = new QDebugStream (std::cerr);
// hideButton = new QFitsSimplestButton(QPixmap(xicon), this);
hideButton = new QFitsSimplestButton(QIcon(":/xicon.svg").pixmap(10, 10), this);
hideButton->setGeometry(width() - 12, 12, 12, 12);
hideButton->setToolTip("Close");
connect(hideButton, SIGNAL(clicked()),
this, SLOT(hide()));
oldfont = settings.textfont;
oldfontsize = settings.textsize;
setAcceptDrops(true);
}
qtdpuser::~qtdpuser() {
// std::cout.rdbuf(oldstdout_buffer);
// std::cerr.rdbuf(oldstderr_buffer);
}
void qtdpuser::resizeEvent( QResizeEvent *e )
{
history->setGeometry(0, 0, width(), height() - 20);
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
// history->verticalScrollBar()->setSliderPosition(history->verticalScrollBar()->maximum());
prompt->move(3, height() - 20);
input->setGeometry(prompt->width() + prompt->x(), height() - 20, width() - prompt->width() - prompt->x(), 20);
hideButton->setGeometry(width() - 12 - style()->pixelMetric(QStyle::PM_ScrollBarExtent), 0, 12, 12);
}
void qtdpuser::enterEvent(QEvent *e) {
input->setFocus();
emit statusbartext("Enter DPUSER commands");
}
void qtdpuser::enableRedirector() {
redirector.open();
freopen(redirector.fileName().toStdString().c_str(), "w", stdout);
QTimer *stdout_timer = new QTimer(this);
connect(stdout_timer, SIGNAL(timeout()), this, SLOT(getStdout()));
// connect(&redirector, SIGNAL(readyRead()), this, SLOT(getStdout()));
stdout_timer->start(250);
}
void qtdpuser::getStdout() {
// QString out = QString::fromStdString(stdout_buffer.str());
// if (!out.isEmpty()) {
// stdout_buffer.str("");
// dpuserText(out);
// }
if (redirector.isOpen()) {
// if (redirector.canReadLine()) {
// std::cout << std::flush;
QString out = redirector.readAll();
if (!out.isEmpty()) {
dpuserText(out);
} else if (redirector.size() > 100000) { // reopen when getting too large....
redirector.close();
redirector.open();
freopen(redirector.fileName().toStdString().c_str(), "w", stdout);
}
}
// QString err = QString::fromStdString(stderr_buffer.str());
// if (!err.isEmpty()) {
// stderr_buffer.str("");
// dpuserText(err);
// }
}
void qtdpuser::appendHistory() {
// dp_output(QString("DPUSER> " + input->text()).toStdString().c_str());
dpDisplayOutput(QString("DPUSER> " + input->text()).toStdString().c_str());
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
// history->verticalScrollBar()->setSliderPosition(history->verticalScrollBar()->maximum());
qtinputmutex->lock();
qtinput += input->text();
qtinputmutex->unlock();
if (!input->text().isEmpty()) list->append(input->text());
histpos = list->end();
if (!pythonmode) {
if ((input->text() == "exit") || (input->text() == "bye") || (input->text() == "quit")) {
emit dpuserExited();
}
}
input->setText("");
}
void qtdpuser::executeCommand(const QString &cmd) {
if (cmd == "gdlevent") {
qtinputmutex->lock();
qtinput += cmd;
qtinputmutex->unlock();
} else {
if (pythonmode) {
QMessageBox::warning(this, "QFitsView", "Cannot execute DPUSER commands while in PYTHON mode.");
return;
}
dp_output(QString("DPUSER> " + cmd).toStdString().c_str());
qtinputmutex->lock();
qtinput += cmd;
qtinputmutex->unlock();
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
// history->verticalScrollBar()->setSliderPosition(history->verticalScrollBar()->maximum());
if (!cmd.isEmpty())
list->append(cmd);
histpos = list->end();
}
}
void qtdpuser::executeScript(const QStringList &script) {
qtinputmutex->lock();
qtinput += script;
qtinputmutex->unlock();
}
void qtdpuser::keyPressEvent(QKeyEvent *e) {
switch (e->key()) {
case Qt::Key_Up:
if (histpos != list->begin()) {
histpos--;
input->setText(*histpos);
}
break;
case Qt::Key_Down:
if (histpos != list->end()) {
histpos++;
if (histpos == list->end())
input->setText("");
else
input->setText(*histpos);
}
break;
case Qt::Key_Tab: {
char delimiter;
int delimiterPosition, pos[6], currentPosition, i;
char delimiters[7] = "'\" ,;@";
currentPosition = input->cursorPosition();
QString text = input->text();
for (i = 0; i < 6; i++) {
pos[i] = text.lastIndexOf(delimiters[i], currentPosition);
}
delimiterPosition = -1;
for (i = 0; i < 6; i++) {
if (pos[i] > delimiterPosition) {
delimiterPosition = pos[i];
delimiter = delimiters[i];
}
}
text = "";
for (i = delimiterPosition + 1; i < currentPosition; i++ ) {
text += input->text()[i];
}
QDir files(QFileInfo(text).dir().path());
files.setNameFilters(QStringList(QFileInfo(text).fileName() + "*"));
int numfiles = files.count();
QString ttt;
if ((numfiles == 1) && (files[0].right(files[0].length() - QFileInfo(text).fileName().length()).length() == 0)) {
files.setPath(QFileInfo(text + "*").dir().path());
files.setNameFilters(QStringList(QFileInfo(text + "*").fileName() + "*"));
numfiles = files.count();
}
if (numfiles > 1) {
QString filelist;
for (i = 0; i < numfiles; i++) {
filelist += files[i];
filelist += " ";
}
history->append(filelist);
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
bool sub = true;
int count = 0;
filelist = files[0][0];
while (sub) {
for (i = 0; i < numfiles; i++) {
if (files[i][count] != filelist[count])
sub = false;
}
if (sub) {
count++;
filelist += files[0][count];
} else {
count--;
filelist.remove(filelist.length() - 1, 1);
}
}
if (count > 0)
input->insert(filelist.right(filelist.length() - QFileInfo(text).fileName().length()));
QApplication::beep();
} else if (numfiles == 1) {
QString filename;
filename = files[0].right(files[0].length() - QFileInfo(text).fileName().length());
input->insert(filename);
filename = "";
for (i = delimiterPosition + 1; i < input->cursorPosition(); i++)
filename += input->text()[i];
QFileInfo info(filename);
if (info.isDir()) {
if (filename.at(filename.length() - 1) != '/')
input->insert("/");
} else {
if (delimiter == '"')
input->insert("\"");
else if (delimiter == '\'')
input->insert("'");
}
}
}
break;
case Qt::Key_PageUp: {
int x, y;
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepSub);
}
break;
case Qt::Key_PageDown: {
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderPageStepAdd);
}
break;
default:
// QWidget::keyPressEvent(e);
break;
}
}
void qtdpuser::paste() {
QString contents = QApplication::clipboard()->text();
if (!contents.isEmpty()) {
contents.replace("\r", "\n");
contents.replace("\n\n", "\n");
QStringList commands = contents.split("\n");
for (QStringList::Iterator it = commands.begin(); it != commands.end(); ++it) {
if ((it == commands.end()-1) && !contents.endsWith("\n"))
input->insert(*it);
else
executeCommand(*it);
}
}
}
void qtdpuser::pasteSelection() {
QString contents = QApplication::clipboard()->text(QClipboard::Selection);
if (!contents.isEmpty()) {
contents.replace("\r", "\n");
contents.replace("\n\n", "\n");
QStringList commands = contents.split("\n");
for (QStringList::Iterator it = commands.begin(); it != commands.end(); ++it) {
if ((it == commands.end()-1) && !contents.endsWith("\n"))
input->insert(*it);
else
executeCommand(*it);
}
}
}
void qtdpuser::dropEvent(QDropEvent *event) {
if (event->mimeData()->hasText()) {
QString contents = event->mimeData()->text();
if (!contents.isEmpty()) {
contents.replace("\r", "\n");
contents.replace("\n\n", "\n");
QStringList commands = contents.split("\n");
for (QStringList::Iterator it = commands.begin(); it != commands.end(); ++it) {
if ((it == commands.end()-1) && !contents.endsWith("\n"))
input->insert(*it);
else
executeCommand(*it);
}
}
}
}
void qtdpuser::fileNameCompletion() {
char delimiter;
int delimiterPosition, pos[6], currentPosition, i;
char delimiters[7] = "'\" ,;@";
currentPosition = input->cursorPosition();
QString text = input->text();
for (i = 0; i < 6; i++) {
pos[i] = text.lastIndexOf(delimiters[i], currentPosition - 1);
}
delimiterPosition = -1;
for (i = 0; i < 6; i++) {
if (pos[i] > delimiterPosition) {
delimiterPosition = pos[i];
delimiter = delimiters[i];
}
}
text = "";
for (i = delimiterPosition + 1; i < currentPosition; i++ ) {
text += input->text()[i];
}
QDir files(QFileInfo(text).dir().path());
files.setNameFilters(QStringList(QFileInfo(text).fileName() + "*"));
int numfiles = files.count();
QString ttt;
if ((numfiles == 1) && (files[0].right(files[0].length() - QFileInfo(text).fileName().length()).length() == 0)) {
files.setPath(QFileInfo(text + "*").dir().path());
files.setNameFilters(QStringList(QFileInfo(text + "*").fileName() + "*"));
numfiles = files.count();
}
if (numfiles > 1) {
QString filelist;
for (i = 0; i < numfiles; i++) {
filelist += files[i];
filelist += " ";
}
history->append(filelist);
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
bool sub = true;
int count = 0;
filelist = files[0][0];
while (sub) {
for (i = 0; i < numfiles; i++) {
if (files[i][count] != filelist[count])
sub = false;
}
if (sub) {
count++;
filelist += files[0][count];
} else {
count--;
filelist.remove(filelist.length() - 1, 1);
}
}
if (count > 0)
input->insert(filelist.right(filelist.length() - QFileInfo(text).fileName().length()));
QApplication::beep();
} else if (numfiles == 1) {
QString filename;
filename = files[0].right(files[0].length() - QFileInfo(text).fileName().length());
input->insert(filename);
filename = "";
for (i = delimiterPosition + 1; i < input->cursorPosition(); i++)
filename += input->text()[i];
QFileInfo info(filename);
if (info.isDir()) {
if (filename.at(filename.length() - 1) != '/')
input->insert("/");
} else {
if (delimiter == '"')
input->insert("\"");
else if (delimiter == '\'')
input->insert("'");
}
}
}
void qtdpuser::historyUp() {
if (histpos != list->begin()) {
histpos--;
input->setText(*histpos);
}
}
void qtdpuser::historyDown() {
if (histpos != list->end()) {
histpos++;
if (histpos != list->end()) {
input->setText(*histpos);
} else {
input->setText("");
}
}
}
void qtdpuser::dpuserText(const QString &text) {
history->append(text);
history->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
if (text.contains("readfits:"))
QMessageBox::warning(this, "QFitsView", "Could not read file");
}
void qtdpuser::fontchanged() {
if ((oldfont != settings.textfont) || (oldfontsize != settings.textsize)) {
oldfont = settings.textfont;
oldfontsize = settings.textsize;
prompt->setStyleSheet("border: none; font-family: " + settings.textfont + "; font-size: " + QString::number(settings.textsize) + "pt");
input->setStyleSheet("border: none; font-family: " + settings.textfont + "; font-size: " + QString::number(settings.textsize) + "pt");
history->setStyleSheet("border: none; font-family: " + settings.textfont + "; font-size: " + QString::number(settings.textsize) + "pt");
prompt->adjustSize();
prompt->setGeometry(3, height() - 20, prompt->width(), 20);
input->setGeometry(prompt->width() + prompt->x(), height() - 20, width() - prompt->width() - prompt->x(), 20);
}
}
void dpDisplayOutput(const QString &what) {
dpuserthread.sendText(what);
}
void SetupWidgets(QWidget *parent) {
qtdpuser contents(parent);
}
|