void startDialog::WriteLog(const char *logText) { QTextEdit *pEdit = ui->LogText; pEdit->moveCursor(QTextCursor::End); pEdit->insertPlainText(QString(logText)); pEdit->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor); }
void QTextEditProto::moveCursor(int operation, int mode) { QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject()); if (item) item->moveCursor((QTextCursor::MoveOperation)operation, (QTextCursor::MoveMode)mode); }
void MainWindow::on_pushButton_clicked() { RFC1664 rfc; cout << "Envoi du message au serveur !" << endl; int i; QString msg = ui->lineEdit->text(); string msgCom = rfc.createMsgCom(ui->label_pseudo->text().toStdString(), "", msg.toStdString(), ui->QTabWidget_onglets->tabText(ui->QTabWidget_onglets->currentIndex()).toStdString()); if(this->getLeftNeighboor() != NULL) { cout << "J'ai un voisin a gauche et je vais lui envoyer le message [" << msgCom << "]" << endl; NetworkUDP::sendDatagrams(this->socketClients->getSocket(), (char*)msgCom.c_str(), strlen(msgCom.c_str()), (SOCKADDR*)this->getLeftNeighboor()->getSockAddr(), this->socketClients->getAddrinfo()); } if(this->getRightNeighboor() != NULL) { cout << "J'ai un voisin a droite et je vais lui envoyer le message [" << msgCom << "]" << endl; NetworkUDP::sendDatagrams(this->socketClients->getSocket(), (char*)msgCom.c_str(), strlen(msgCom.c_str()), (SOCKADDR*)this->getRightNeighboor()->getSockAddr(), this->socketClients->getAddrinfo()); } this->ui->lineEdit->clear(); // Saisie du message envoyé dans l'IHM et dans le bon salon msgCom = ui->label_pseudo->text().toStdString(); msgCom += " - "; msgCom += msg.toStdString(); msgCom += "\n"; QTextEdit *text; text = this->getRoomLists().take(ui->QTabWidget_onglets->tabText(ui->QTabWidget_onglets->currentIndex())); text->moveCursor(QTextCursor::End); text->insertPlainText(QString(msgCom.c_str())); }
void ConsoleImpl::typeWriterFontChanged() { QTextEdit* te = textEditOutput; te->setFont(QGit::TYPE_WRITER_FONT); te->setPlainText(te->toPlainText()); te->moveCursor(QTextCursor::End); }
int TextEdit::moveCursor( lua_State * L )// ( QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor ) { QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1); Enums enums(L); QTextCursor::MoveOperation operation=(QTextCursor::MoveOperation)enums.MoveMode( 2 ); QTextCursor::MoveMode mode=(QTextCursor::MoveMode)enums.MoveMode( 3 ); obj->moveCursor( operation, mode ); return 0; }
void SourceViewer::setSourceText(const QString &key, const QString &name, const QString &searchText, const QByteArray &sourceTextBuffer) { QTextEdit *logTextEdit = NULL; QTextEditorContextMap::const_iterator i = logTextWidgetMap_.find(key); if(i == logTextWidgetMap_.end()) { // New tab created.. logTextEdit = new QTextEdit(); QObject::connect(logTextEdit, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); logTextEdit->setReadOnly(true); SourceViewContext* ctx = new SourceViewContext(); ctx->logTextEdit = logTextEdit; logTextWidgetMap_.insert(key, ctx); ui.tabWidget->insertTab(0, logTextEdit, name); ui.tabWidget->setCurrentIndex(0); } else { // Already the tab exists. logTextEdit = i.value()->logTextEdit; int index = ui.tabWidget->indexOf(logTextEdit); if(index >= 0) { ui.tabWidget->setCurrentIndex(index); } } workingHighlightText_ = true; ui.searchText->setText(searchText); logTextEdit->setText(sourceTextBuffer); logTextEdit->setFocus(); if(searchText.isEmpty() == false) { doHighlightText(searchText, ui.caseSensitiveCheck->isChecked()); QTextDocument::FindFlags flags = 0x0; if(ui.caseSensitiveCheck->isChecked()) flags |= QTextDocument::FindCaseSensitively; logTextEdit->moveCursor(QTextCursor::Start); while(logTextEdit->find(searchText, flags)) { break; } } workingHighlightText_ = false; }
void Dialog::onMessageToGui(QString name, QString mes) { QTextEdit *output = ui->te_outputMess; output->moveCursor(QTextCursor::End); output->setTextColor(Qt::blue); output->insertPlainText(QTime::currentTime().toString()); output->setTextColor(Qt::red); output->insertPlainText("<"+name+">"); output->setTextColor(Qt::black); output->insertPlainText(mes+"\n"); }
/*! */ void DebugMessageWindow::findString( const QString & expr ) { // case insentive && no whole word QTextDocument::FindFlags flags( M_find_forward_rb->isChecked() ? 0 : QTextDocument::FindBackward ); QTextEdit * edit = M_message[ M_tab_widget->currentIndex() ]; if ( ! edit->find( expr, flags ) ) { if ( M_find_forward_rb->isChecked() ) { edit->moveCursor( QTextCursor::Start ); } else { edit->moveCursor( QTextCursor::End ); } edit->find( expr, flags ); } }
void editMenuActivated(QAction *action) { QWidget* w = qApp->focusWidget(); QTextEdit* te = qobject_cast<QTextEdit*>(w); QLineEdit* le = qobject_cast<QLineEdit*>(w); if (action == selectAction) { highlighting = this; return; } highlighting = 0; if (action == copyAction) { if (te) { if (te->hasEditFocus()) { te->copy(); } else { QTextCursor c = te->textCursor(); te->selectAll(); te->copy(); te->setTextCursor(c); // reset selection } } else if (le) { if (le->hasEditFocus()) { le->copy(); } else { qApp->clipboard()->setText(le->text()); } } } else if (action == pasteAction) { // assumes clipboard is not empty if 'Paste' is able to be // activated, otherwise the line/textedit might be cleared // without pasting anything back into it if (te) { if (!te->hasEditFocus()) te->clear(); te->paste(); if (!te->hasEditFocus()) { te->moveCursor(QTextCursor::Start); te->ensureCursorVisible(); } } else if (le) { if (!le->hasEditFocus()) le->clear(); le->paste(); if (!le->hasEditFocus()) le->home(false); } } }
void SourceViewer::onClickedSearchNext() { QTextEdit *logTextEdit = getCurrentSourceEdit(); if(logTextEdit != NULL) { QTextDocument::FindFlags flags = 0x0; if(ui.caseSensitiveCheck->isChecked()) flags |= QTextDocument::FindCaseSensitively; bool find = logTextEdit->find(ui.searchText->text(), flags); if(find == false) { logTextEdit->moveCursor(QTextCursor::Start); logTextEdit->find(ui.searchText->text(), flags); } } }
void SourceViewer::onClickedSearchPrev() { QTextEdit *logTextEdit = getCurrentSourceEdit(); if(logTextEdit != NULL) { QTextDocument::FindFlags flags = QTextDocument::FindBackward; if(ui.caseSensitiveCheck->isChecked()) flags |= QTextDocument::FindCaseSensitively; bool find = logTextEdit->find(ui.searchText->text(), flags); if(find == false) { logTextEdit->moveCursor(QTextCursor::End); logTextEdit->horizontalScrollBar()->setValue(0); logTextEdit->find(ui.searchText->text(), flags); } } }
void SourceViewer::doHighlightText(const QString &text, bool caseSensitive) { qDebug() << "doHighlightText : text=" << text; workingHighlightText_ = true; do { QTextEdit *logTextEdit = getCurrentSourceEdit(); if(logTextEdit == NULL) break; int orgValueVert = logTextEdit->verticalScrollBar()->value(); int orgValueHor = logTextEdit->horizontalScrollBar()->value(); QTextCursor orgCursor = logTextEdit->textCursor(); QTextDocument::FindFlags flags = 0x0; if(caseSensitive) flags |= QTextDocument::FindCaseSensitively; QList<QTextEdit::ExtraSelection> extraSelections; logTextEdit->moveCursor(QTextCursor::Start); QColor fgColor = QColor("white"); QColor bgColor = QColor("#C32438"); while(logTextEdit->find(text, flags)) { QTextEdit::ExtraSelection extra; extra.format.setForeground(fgColor); extra.format.setBackground(bgColor); extra.cursor = logTextEdit->textCursor(); extraSelections.append(extra); } logTextEdit->setExtraSelections(extraSelections); logTextEdit->setTextCursor(orgCursor); logTextEdit->verticalScrollBar()->setValue(orgValueVert); logTextEdit->horizontalScrollBar()->setValue(orgValueHor); } while(false); workingHighlightText_ = false; }
void ExplorerPane::updateErrors(const QString& errors) { QTextEdit *errorWidget = dynamic_cast<QTextEdit *>(errorsPage); if (errorWidget) { // Get the current text QString text = errorWidget->toPlainText(); if (!text.isEmpty()) { // Set the text color to light grey errorWidget->setTextColor(QColor("grey")); // Restore the current text errorWidget->setPlainText(text); } // Set the text color to red errorWidget->setTextColor(QColor("red")); // Append the new error message errorWidget->append(errors); // Place cursor at end of text errorWidget->moveCursor(QTextCursor::End); // Raise the Error tab tabWidget->setCurrentWidget(errorsPage); } }
void osk_dialog_frame::Create(const std::string& title, const std::u16string& message, char16_t* init_text, u32 charlimit, u32 options) { state = OskDialogState::Open; static const auto& lineEditWidth = []() {return QLabel("This is the very length of the lineedit due to hidpi reasons.").sizeHint().width(); }; if (m_dialog) { m_dialog->close(); delete m_dialog; } m_dialog = new custom_dialog(false); m_dialog->setModal(true); // Title m_dialog->setWindowTitle(qstr(title)); // Message QLabel* message_label = new QLabel(QString::fromStdU16String(message)); // Text Input Counter const QString text = QString::fromStdU16String(std::u16string(init_text)); QLabel* inputCount = new QLabel(QString("%1/%2").arg(text.length()).arg(charlimit)); // Ok Button QPushButton* button_ok = new QPushButton("Ok", m_dialog); // Button Layout QHBoxLayout* buttonsLayout = new QHBoxLayout; buttonsLayout->setAlignment(Qt::AlignCenter); buttonsLayout->addStretch(); buttonsLayout->addWidget(button_ok); buttonsLayout->addStretch(); // Input Layout QHBoxLayout* inputLayout = new QHBoxLayout; inputLayout->setAlignment(Qt::AlignHCenter); // Text Input if (options & CELL_OSKDIALOG_NO_RETURN) { QLineEdit* input = new QLineEdit(m_dialog); input->setFixedWidth(lineEditWidth()); input->setMaxLength(charlimit); input->setText(text); input->setFocus(); if (options & CELL_OSKDIALOG_NO_SPACE) { input->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this)); } connect(input, &QLineEdit::textChanged, [=](const QString& text) { inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit)); SetOskText(text); on_osk_input_entered(); }); connect(input, &QLineEdit::returnPressed, m_dialog, &QDialog::accept); inputLayout->addWidget(input); } else { QTextEdit* input = new QTextEdit(m_dialog); input->setFixedWidth(lineEditWidth()); input->setText(text); input->setFocus(); input->moveCursor(QTextCursor::End); m_text_old = text; connect(input, &QTextEdit::textChanged, [=]() { QString text = input->toPlainText(); if (text == m_text_old) { return; } QTextCursor cursor = input->textCursor(); const int cursor_pos_new = cursor.position(); const int cursor_pos_old = cursor_pos_new + m_text_old.length() - text.length(); // Reset to old state if character limit was reached if ((u32)m_text_old.length() >= charlimit && (u32)text.length() > charlimit) { input->blockSignals(true); input->setPlainText(m_text_old); cursor.setPosition(cursor_pos_old); input->setTextCursor(cursor); input->blockSignals(false); return; } int cursor_pos = cursor.position(); // Clear text of spaces if necessary if (options & CELL_OSKDIALOG_NO_SPACE) { int trim_len = text.length(); text.remove(QRegExp("\\s+")); trim_len -= text.length(); cursor_pos -= trim_len; } // Crop if more than one character was pasted and the character limit was exceeded text.chop(text.length() - charlimit); // Set new text and block signals to prevent infinite loop input->blockSignals(true); input->setPlainText(text); cursor.setPosition(cursor_pos); input->setTextCursor(cursor); input->blockSignals(false); m_text_old = text; inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit)); SetOskText(text); on_osk_input_entered(); }); inputLayout->addWidget(input); } inputLayout->addWidget(inputCount); QFormLayout* layout = new QFormLayout(m_dialog); layout->setFormAlignment(Qt::AlignHCenter); layout->addRow(message_label); layout->addRow(inputLayout); layout->addRow(buttonsLayout); m_dialog->setLayout(layout); // Events connect(button_ok, &QAbstractButton::clicked, m_dialog, &QDialog::accept); connect(m_dialog, &QDialog::accepted, [=] { on_osk_close(CELL_MSGDIALOG_BUTTON_OK); }); connect(m_dialog, &QDialog::rejected, [=] { on_osk_close(CELL_MSGDIALOG_BUTTON_ESCAPE); }); // Fix size m_dialog->layout()->setSizeConstraint(QLayout::SetFixedSize); m_dialog->show(); }
PmQuery::PmQuery(bool inputflag, bool printflag, bool noframeflag, bool nosliderflag, bool usesliderflag, bool exclusiveflag) : QDialog() { QHBoxLayout *hboxLayout; QVBoxLayout *vboxLayout; QSpacerItem *spacerItem; QSpacerItem *spacerItem1; QVBoxLayout *vboxLayout1; QHBoxLayout *hboxLayout1; QSpacerItem *spacerItem2; QString filename; if (iconic == HOST_ICON) filename = tr(":images/dialog-host.png"); else if (iconic == ERROR_ICON) filename = tr(":images/dialog-error.png"); else if (iconic == WARNING_ICON) filename = tr(":images/dialog-warning.png"); else if (iconic == ARCHIVE_ICON) filename = tr(":images/dialog-archive.png"); else if (iconic == QUESTION_ICON) filename = tr(":images/dialog-question.png"); else // (iconic == INFO_ICON) filename = tr(":images/dialog-information.png"); QIcon icon(filename); QPixmap pixmap(filename); setWindowIcon(icon); setWindowTitle(tr(title)); QGridLayout *gridLayout = new QGridLayout(this); gridLayout->setSpacing(6); gridLayout->setMargin(9); hboxLayout = new QHBoxLayout(); hboxLayout->setSpacing(6); hboxLayout->setMargin(0); vboxLayout = new QVBoxLayout(); vboxLayout->setSpacing(6); vboxLayout->setMargin(0); spacerItem = new QSpacerItem(20, 2, QSizePolicy::Minimum, QSizePolicy::Expanding); vboxLayout->addItem(spacerItem); QLabel *imageLabel = new QLabel(this); imageLabel->setPixmap(pixmap); vboxLayout->addWidget(imageLabel); spacerItem1 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); vboxLayout->addItem(spacerItem1); hboxLayout->addLayout(vboxLayout); vboxLayout1 = new QVBoxLayout(); vboxLayout1->setSpacing(6); vboxLayout1->setMargin(0); int height; int width = DEFAULT_EDIT_WIDTH; QLineEdit* lineEdit = NULL; QTextEdit* textEdit = NULL; if (inputflag && messagecount <= 1) { lineEdit = new QLineEdit(this); if (messagecount == 1) lineEdit->setText(tr(messages[0])); height = lineEdit->font().pointSize() + 4; if (height < 0) height = lineEdit->font().pixelSize() + 4; if (height < 0) height = lineEdit->heightForWidth(width) + 4; lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); lineEdit->setMinimumSize(QSize(width, height)); lineEdit->setGeometry(QRect(0, 0, width, height)); vboxLayout1->addWidget(lineEdit); } else { QFont fixed("monospace"); fixed.setStyleHint(QFont::TypeWriter); textEdit = new QTextEdit(this); textEdit->setFont(fixed); textEdit->setLineWrapMode(QTextEdit::FixedColumnWidth); textEdit->setLineWrapColumnOrWidth(80); textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); if (nosliderflag) textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); else if (usesliderflag) textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); else textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); for (int m = 0; m < messagecount; m++) textEdit->append(tr(messages[m])); if (inputflag) textEdit->setReadOnly(false); else { textEdit->setLineWidth(1); textEdit->setFrameStyle(noframeflag ? QFrame::NoFrame : QFrame::Box | QFrame::Sunken); textEdit->setReadOnly(true); } if (usesliderflag) height = DEFAULT_EDIT_HEIGHT; else { height = textEdit->font().pointSize() + 4; if (height < 0) height = textEdit->font().pixelSize() + 4; if (height < 0) height = textEdit->heightForWidth(width) + 4; height *= messagecount; } textEdit->setMinimumSize(QSize(width, height)); textEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); textEdit->moveCursor(QTextCursor::Start); textEdit->ensureCursorVisible(); vboxLayout1->addWidget(textEdit); } hboxLayout1 = new QHBoxLayout(); hboxLayout1->setSpacing(6); hboxLayout1->setMargin(0); spacerItem2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); hboxLayout1->addItem(spacerItem2); for (int i = 0; i < buttoncount; i++) { QueryButton *button = new QueryButton(printflag, this); button->setMinimumSize(QSize(72, 32)); button->setDefault(buttons[i] == defaultbutton); button->setQuery(this); button->setText(tr(buttons[i])); button->setStatus(statusi[i]); if (inputflag && buttons[i] == defaultbutton) { if (textEdit) button->setEditor(textEdit); else if (lineEdit) { button->setEditor(lineEdit); if (buttons[i] == defaultbutton) connect(lineEdit, SIGNAL(returnPressed()), button, SLOT(click())); } } connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked())); hboxLayout1->addWidget(button); } vboxLayout1->addLayout(hboxLayout1); hboxLayout->addLayout(vboxLayout1); gridLayout->addLayout(hboxLayout, 0, 0, 1, 1); gridLayout->setSizeConstraint(QLayout::SetFixedSize); if (inputflag && messagecount <= 1) resize(QSize(320, 83)); else resize(QSize(320, 132)); if (timeout) startTimer(timeout * 1000); if (exclusiveflag) setWindowModality(Qt::WindowModal); }
void Dialog::appendToHistory(const QString& name, const QDateTime& sendTime, QTextDocument *document, InsertingMode mode) { QListWidgetItem *item = new QListWidgetItem(); QTextEdit *te = new QTextEdit(); lwHistory->addItem(item); te->setReadOnly(true); reloadResource(te); lwHistory->setItemWidget(item, te); QString color; if (name == "You") color = "blue"; else color = "red"; te->append(QString("<font color = \"%1\"> <b>" + name + "</b> (" + sendTime.toString("dd-MM-yyyy hh:mm:ss") + "):</font>").arg(color)); te->moveCursor(QTextCursor::End); te->textCursor().insertBlock(); te->textCursor().insertFragment(QTextDocumentFragment(document)); int heig = 17, widthTe = parentWidget()->width(); int curLine = 0; int mx = 0; for (QTextBlock bl = te->document()->begin(); bl != te->document()->end(); bl = bl.next()) if (bl.isValid()) { if (bl.begin().atEnd()) { heig += 17 + mx;//&&& curLine = mx = 0; continue; } for (QTextBlock::iterator it = bl.begin(); !it.atEnd(); ++it) { QTextFragment fragm = it.fragment(); int curw, curh; if (fragm.isValid() && fragm.charFormat().isImageFormat()) { curw = smiles->width() / W_CNT; curh = smiles->height() / H_CNT; processCalc(heig, mx, curLine, curw, curh); } else if (fragm.isValid()) { QString s = fragm.text(); QFontMetrics me(fragm.charFormat().font()); curh = me.lineSpacing(); for (int j = 0; j < s.size(); ++j) { curw = me.width(s[j]); processCalc(heig, mx, curLine, curw, curh); } } } heig += mx; mx = curLine = 0; } te->setStyleSheet(QString("QFrame {" "border: 2px solid #f3f2f1;" "border-radius: 4px;" "padding: 2px;}")); item->setSizeHint(QSize(0, heig + 18)); te->resize(QSize(widthTe, heig)); lwHistory->scrollToBottom(); if (mode == ReceivedMessage && !dgReadByUser) { setUnreadMessage(unreadMessage + 1); queUnreadWrote.push_back(te); te->setStyleSheet("QTextEdit { background-color: #FFFCCC; }"); } else if (mode == LoadHistory) { if (unreadMessage != 0) { queUnreadWrote.push_back(te); te->setStyleSheet("QTextEdit { background-color: #FFFCCC; }"); if (queUnreadWrote.size() > unreadMessage) { queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }"); queUnreadWrote.pop_front(); } } if (wroteMessage != 0) { queUnreadWrote.push_back(te); te->setStyleSheet("QTextEdit { background-color: #DFFFCC; }"); if (queUnreadWrote.size() > wroteMessage) { queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }"); queUnreadWrote.pop_front(); } } } else if (mode == SendMessage) { teMessage->setFocus(); te->setStyleSheet("QTextEdit { background-color: #DFFFCC; }"); wroteMessage++; queUnreadWrote.push_back(te); } }
void QgsCptCityColorRampDialog::pbtnLicenseDetails_pressed() { QString path, title, copyFile, descFile; // get basic information, depending on if is color ramp or directory QgsCptCityDataItem *item = mModel->dataItem( mTreeFilter->mapToSource( mTreeView->currentIndex() ) ); if ( ! item ) return; path = item->path(); if ( item->type() == QgsCptCityDataItem::Directory ) { title = tr( "%1 Directory Details" ).arg( item->path() ); } else if ( item->type() == QgsCptCityColorRampItem::Directory ) { title = tr( "%1 Gradient Details" ).arg( path ); } else { return; } copyFile = mArchive->copyingFileName( path ); descFile = mArchive->descFileName( path ); // prepare dialog QgsDialog dlg( this, nullptr, QDialogButtonBox::Close ); QVBoxLayout *layout = dlg.layout(); dlg.setWindowTitle( title ); QTextEdit *textEdit = new QTextEdit( &dlg ); textEdit->setReadOnly( true ); layout->addWidget( textEdit ); // add contents of DESC.xml and COPYING.xml QString copyText; if ( ! copyFile.isNull() ) { QFile file( copyFile ); if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { copyText = QString( file.readAll() ); file.close(); } } QString descText; if ( ! descFile.isNull() ) { QFile file( descFile ); if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { descText = QString( file.readAll() ); file.close(); } } textEdit->insertPlainText( title + "\n\n" ); textEdit->insertPlainText( QStringLiteral( "===================" ) ); textEdit->insertPlainText( QStringLiteral( " copying " ) ); textEdit->insertPlainText( QStringLiteral( "===================\n" ) ); textEdit->insertPlainText( copyText ); textEdit->insertPlainText( QStringLiteral( "\n" ) ); textEdit->insertPlainText( QStringLiteral( "==================" ) ); textEdit->insertPlainText( QStringLiteral( " description " ) ); textEdit->insertPlainText( QStringLiteral( "==================\n" ) ); textEdit->insertPlainText( descText ); textEdit->moveCursor( QTextCursor::Start ); dlg.resize( 600, 600 ); dlg.exec(); }
bool EmulApp::eventFilter(QObject *watched, QEvent *event) { int type = static_cast<int>(event->type()); if (type == QEvent::KeyPress) { } MainWindow *mw = dynamic_cast<MainWindow *>(watched); if (mw) { if (type == LogLineEventType) { LogLineEvent *evt = dynamic_cast<LogLineEvent *>(event); if (evt && mw->textEdit()) { QTextEdit *te = mw->textEdit(); QColor origcolor = te->textColor(); te->setTextColor(evt->color); te->append(evt->str); // make sure the log textedit doesn't grow forever // so prune old lines when a threshold is hit nLinesInLog += evt->str.split("\n").size(); if (nLinesInLog > nLinesInLogMax) { const int n2del = MAX(nLinesInLogMax/10, nLinesInLog-nLinesInLogMax); QTextCursor cursor = te->textCursor(); cursor.movePosition(QTextCursor::Start); for (int i = 0; i < n2del; ++i) { cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor); } cursor.removeSelectedText(); // deletes the lines, leaves a blank line nLinesInLog -= n2del; } te->setTextColor(origcolor); te->moveCursor(QTextCursor::End); te->ensureCursorVisible(); return true; } else { return false; } } else if (type == StatusMsgEventType) { StatusMsgEvent *evt = dynamic_cast<StatusMsgEvent *>(event); if (evt && mw->statusBar()) { mw->statusBar()->showMessage(evt->msg, evt->timeout); return true; } else { return false; } } } if (watched == this) { if (type == QuitEventType) { quit(); return true; } if (type == SoundTrigEventType) { SoundTrigEvent *evt = dynamic_cast<SoundTrigEvent *>(event); if (evt) trigSound(evt->trig); if (evt->listener) evt->listener->triggered(evt->trig); return true; } if (type == SoundEventType) { SoundEvent *evt = dynamic_cast<SoundEvent *>(event); if (evt) gotSound(evt->id, evt->name, evt->loops); if (evt->listener) evt->listener->gotSound(evt->id); return true; } } // otherwise do default action for event which probably means // propagate it down return QApplication::eventFilter(watched, event); }