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); } } }
int TextEdit::ensureCursorVisible(lua_State * L) { QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1); obj->ensureCursorVisible(); return 0; }
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 QTextEditProto::ensureCursorVisible() { QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject()); if (item) item->ensureCursorVisible(); }
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); }