void OutputWindowPlainTextEdit::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = createStandardContextMenu(); // Add 'open file' QString repository; const QString token = identifierUnderCursor(event->pos(), &repository); QAction *openAction = 0; if (!token.isEmpty()) { // Check for a file, expand via repository if relative QFileInfo fi(token); if (!repository.isEmpty() && !fi.isFile() && fi.isRelative()) fi = QFileInfo(repository + QLatin1Char('/') + token); if (fi.isFile()) { menu->addSeparator(); openAction = menu->addAction(VcsOutputWindow::tr("Open \"%1\""). arg(QDir::toNativeSeparators(fi.fileName()))); openAction->setData(fi.absoluteFilePath()); } } // Add 'clear' menu->addSeparator(); QAction *clearAction = menu->addAction(VcsOutputWindow::tr("Clear")); // Run QAction *action = menu->exec(event->globalPos()); if (action) { if (action == clearAction) { clear(); return; } if (action == openAction) { const QString fileName = action->data().toString(); Core::EditorManager::openEditor(fileName); } } delete menu; }
void SqlTextEdit::keyPressEvent(QKeyEvent *e) { if (m_Completer && m_Completer->popup()->isVisible()) { // The following keys are forwarded by the completer to the widget switch (e->key()) { case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Escape: case Qt::Key_Tab: case Qt::Key_Backtab: e->ignore(); return; // let the completer do default behavior default: break; } } // indent on tab if (e->key() == Qt::Key_Tab && textCursor().hasSelection()) { increaseSelectionIndent(); return; } bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space); // CTRL+SPACE if (!m_Completer || !isShortcut) // do not process the shortcut when we have a completer QPlainTextEdit::keyPressEvent(e); const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier); const bool cursorKey = e->key() == Qt::Key_Left || e->key() == Qt::Key_Up || e->key() == Qt::Key_Right || e->key() == Qt::Key_Down; if (!m_Completer || (ctrlOrShift && e->text().isEmpty()) || cursorKey) return; QString identifier = identifierUnderCursor(); QString table = identifier; QString field; int dotpos = 0; if((dotpos = identifier.indexOf('.')) > 0) { table = identifier.left(dotpos); field = identifier.mid(dotpos + 1); } if( dotpos > 0 ) { // swap model to field completion FieldCompleterModelMap::ConstIterator it = m_fieldCompleterMap.find(table.toLower()); if( it != m_fieldCompleterMap.end() ) { if( *it != m_Completer->model() ) m_Completer->setModel(*it); if (field != m_Completer->completionPrefix()) { m_Completer->setCompletionPrefix(field); m_Completer->popup()->setCurrentIndex(m_Completer->completionModel()->index(0, 0)); } QRect cr = cursorRect(); cr.setWidth(m_Completer->popup()->sizeHintForColumn(0) + m_Completer->popup()->verticalScrollBar()->sizeHint().width()); m_Completer->complete(cr); } return; } // table completion mode if( m_Completer->model() != m_defaultCompleterModel ) m_Completer->setModel(m_defaultCompleterModel); static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift; if (!isShortcut && (hasModifier || e->text().isEmpty()|| identifier.length() < 3 || eow.contains(e->text().right(1)))) { m_Completer->popup()->hide(); return; } if (identifier != m_Completer->completionPrefix()) { m_Completer->setCompletionPrefix(identifier); m_Completer->popup()->setCurrentIndex(m_Completer->completionModel()->index(0, 0)); } QRect cr = cursorRect(); cr.setWidth(m_Completer->popup()->sizeHintForColumn(0) + m_Completer->popup()->verticalScrollBar()->sizeHint().width()); m_Completer->complete(cr); // popup it up! }