/*! \reimp */ int Q3AccessibleTextEdit::itemAt(int x, int y) const { int p; QPoint cp = textEdit()->viewportToContents(QPoint(x,y)); textEdit()->charAt(cp , &p); return p + 1; }
bool TextView::eventFilter(QObject *watched, QEvent *event) { if (watched == textEdit()) { if (event->type() == QEvent::FocusIn) { connect(textEdit_, SIGNAL(cursorPositionChanged()), this, SLOT(updatePositionStatus())); updatePositionStatus(); } else if (event->type() == QEvent::FocusOut) { disconnect(textEdit_, SIGNAL(cursorPositionChanged()), this, SLOT(updatePositionStatus())); } } if (watched == textEdit()->viewport()) { if (event->type() == QEvent::Resize) { updateExtraSelections(); } else if (event->type() == QEvent::Wheel) { auto wheelEvent = static_cast<QWheelEvent *>(event); if (wheelEvent->orientation() == Qt::Vertical && wheelEvent->modifiers() & Qt::ControlModifier) { if (wheelEvent->delta() > 0) { zoomIn(1 + wheelEvent->delta() / 360); } else { zoomOut(1 - wheelEvent->delta() / 360); } return true; } } } return QDockWidget::eventFilter(watched, event); }
QPoint QAccessibleTextEdit::scrollBarPosition() const { QPoint result; result.setX(textEdit()->horizontalScrollBar() ? textEdit()->horizontalScrollBar()->sliderPosition() : 0); result.setY(textEdit()->verticalScrollBar() ? textEdit()->verticalScrollBar()->sliderPosition() : 0); return result; }
void HtmlEditor::validate() { if (Tools::htmlToText(textEdit()->toHtml()).isEmpty()) setEmpty(); QString convert = textEdit()->document()->toHtml("utf-8"); if(note()->allowCrossReferences()) convert = Tools::tagCrossReferences(convert, /*userLink=*/true); m_htmlContent->setHtml(convert); m_htmlContent->saveToFile(); m_htmlContent->setEdited(); disconnect(); graphicsWidget()->disconnect(); if (InlineEditors::instance()) { InlineEditors::instance()->disableRichTextToolBar(); // if (InlineEditors::instance()->richTextToolBar()) // InlineEditors::instance()->richTextToolBar()->hide(); } if( graphicsWidget() ) { note()->setZValue(1); delete graphicsWidget()->widget(); setInlineEditor(0); } }
void TextView::highlight(std::vector<Range<int>> ranges, bool ensureVisible) { if (!ranges.empty()) { std::sort(ranges.begin(), ranges.end()); if (ensureVisible) { std::vector<Range<int>> difference; set_difference( ranges.begin(), ranges.end(), highlighting_.begin(), highlighting_.end(), std::back_inserter(difference)); if (difference.empty()) { set_difference( highlighting_.begin(), highlighting_.end(), ranges.begin(), ranges.end(), std::back_inserter(difference)); } if (!difference.empty()) { textEdit()->blockSignals(true); moveCursor(difference.front().end(), true); moveCursor(difference.front().start(), true); textEdit()->blockSignals(false); } } highlighting_.swap(ranges); } else { highlighting_.clear(); } updateExtraSelections(); }
void TextView::moveCursor(int position, bool ensureVisible) { QTextCursor cursor = textEdit()->textCursor(); cursor.setPosition(position); textEdit()->setTextCursor(cursor); if (ensureVisible) { textEdit()->ensureCursorVisible(); } }
/*! \reimp */ QRect Q3AccessibleTextEdit::itemRect(int item) const { QRect rect = textEdit()->paragraphRect(item - 1); if (!rect.isValid()) return QRect(); QPoint ntl = textEdit()->contentsToViewport(QPoint(rect.x(), rect.y())); return QRect(ntl.x(), ntl.y(), rect.width(), rect.height()); }
void HtmlEditor::editTextChanged() { // The following is a workaround for an apparent Qt bug. // When I start typing in a textEdit, the undo&redo actions are not enabled until I click // or move the cursor - probably, the signal undoAvailable() is not emitted. // So, I had to intervene and do that manually. InlineEditors::instance()->richTextUndo->setEnabled(textEdit()->document()->isUndoAvailable()); InlineEditors::instance()->richTextRedo->setEnabled(textEdit()->document()->isRedoAvailable()); }
void TextView::showContextMenu(const QPoint &pos) { std::unique_ptr<QMenu> menu(textEdit()->createStandardContextMenu()); Q_EMIT contextMenuCreated(menu.get()); if (!menu->isEmpty()) { menu->exec(textEdit()->mapToGlobal(pos)); } }
void Q3SyntaxHighlighter::setFormat(int start, int count, const QFont &font) { if (!para || count <= 0) return; Q3TextFormat *f = 0; QColor c = textEdit()->viewport()->palette().color(textEdit()->viewport()->foregroundRole()); f = para->document()->formatCollection()->format(font, c); para->setFormat(start, count, f); f->removeRef(); }
void SpellHighlighter::flush() { if (m_curWord.isEmpty()) return; string ss; if (!m_curWord.isEmpty()) ss = static_cast<string>(m_curWord.toLocal8Bit()); log(L_DEBUG, ">> %s [%u %u %u]", ss.c_str(), m_index, m_curStart, m_pos); if ((m_index >= m_curStart) && (m_index <= m_pos)){ if (m_bCheck){ m_word = m_curWord; m_bInError = m_bError; m_start_word = m_curStart; m_curWord = ""; return; } if (m_bError){ if (m_bDisable) { setFormat(m_curStart, m_pos - m_curStart, static_cast<TextEdit*>(textEdit())->defForeground()); }else if (m_parag == m_paragraph){ MAP_BOOL::iterator it = m_words.find(my_string(m_curWord.toUtf8())); if ((it == m_words.end()) || (*it).second) setFormat(m_curStart, m_pos - m_curStart, static_cast<TextEdit*>(textEdit())->defForeground()); } } m_curWord = ""; return; } if (m_bCheck){ m_curWord = ""; return; } if (m_bDisable){ if (m_bError) setFormat(m_curStart, m_pos - m_curStart, static_cast<TextEdit*>(textEdit())->defForeground()); m_curWord = ""; return; } MAP_BOOL::iterator it = m_words.find(my_string(m_curWord.toUtf8())); if (it != m_words.end()){ if (!(*it).second){ if (!m_bError) setFormat(m_curStart, m_pos - m_curStart, QColor(ErrorColor)); }else if (m_bError){ setFormat(m_curStart, m_pos - m_curStart, static_cast<TextEdit*>(textEdit())->defForeground()); } }else{ m_words.insert(MAP_BOOL::value_type(my_string(m_curWord.toUtf8()), true)); if (m_plugin->m_ignore.find(my_string(m_curWord.toUtf8())) == m_plugin->m_ignore.end()) emit check(m_curWord); } m_curWord = ""; }
void QAccessibleTextEdit::setText(QAccessible::Text t, const QString &text) { if (t != QAccessible::Value) { QAccessibleWidget::setText(t, text); return; } if (textEdit()->isReadOnly()) return; textEdit()->setText(text); }
void SpellHighlighter::text(const QString &text) { int i; for (i = 0; i < (int)(text.length());){ for (; i < (int)(text.length()); i++, m_pos++){ if (!text[i].isSpace() && !text[i].isPunct()) break; } if (i >= (int)(text.length())) break; int start = m_pos; QString word; for (; i < (int)(text.length()); i++, m_pos++){ if (text[i].isSpace() || text[i].isPunct()) break; word += text[i]; } if ((m_index >= start) && (m_index <= m_pos)){ if (m_bCheck){ m_word = word; m_bInError = m_bError; m_start_word = start; }else if (m_bError){ if (m_bDisable) { setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); }else if (m_parag == m_paragraph){ MAP_BOOL::iterator it = m_words.find(my_string(word.utf8())); if ((it == m_words.end()) || (*it).second) setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); } } }else if (!m_bCheck){ if (m_bDisable){ if (m_bError) setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); }else{ MAP_BOOL::iterator it = m_words.find(my_string(word.utf8())); if (it != m_words.end()){ if (!(*it).second){ setFormat(start, m_pos - start, QColor(ErrorColor)); }else if (m_bError){ setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); } }else{ m_words.insert(MAP_BOOL::value_type(my_string(word.utf8()), true)); if (m_plugin->m_ignore.find(my_string(word.utf8())) == m_plugin->m_ignore.end()) emit check(word); } } } } }
void SpellHighlighter::text(const QString &text) { int i; for (i = 0; i < (int)(text.length());){ for (; i < (int)(text.length()); i++, m_pos++){ if (!text[i].isSpace() && !text[i].isPunct()) break; } if (i >= (int)(text.length())) break; int start = m_pos; QString word; for (; i < (int)(text.length()); i++, m_pos++){ if (text[i].isSpace() || text[i].isPunct()) break; word += text[i]; } if ((m_index >= start) && (m_index <= m_pos)){ if (m_bCheck){ m_word = word; m_bInError = m_bError; m_start_word = start; }else if (m_bError){ if (m_bDisable) { setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); }else if (m_parag == m_paragraph){ bool *state = m_words.find(word); if ((state == NULL) || *state) setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); } } }else if (!m_bCheck){ if (m_bDisable){ if (m_bError) setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); }else{ bool *state = m_words.find(word); if (state){ if (!*state){ setFormat(start, m_pos - start, QColor(ErrorColor)); }else if (m_bError){ setFormat(start, m_pos - start, static_cast<TextEdit*>(textEdit())->defForeground()); } }else{ m_words.insert(word, &WORD_OK); if (m_plugin->m_ignore.find(m_word) == NULL) emit check(word); } } } } }
/*! \reimp */ QString Q3AccessibleTextEdit::text(Text t, int child) const { if (t == Name && child > 0) return textEdit()->text(child - 1); if (t == Value) { if (child > 0) return textEdit()->text(child - 1); else return textEdit()->text(); } return Q3AccessibleScrollView::text(t, child); }
void HtmlEditor::onFontSelectionChanged(const QFont& font) { //Change font family only textEdit()->setFontFamily(font.family()); InlineEditors::instance()->richTextFont->clearFocus(); //textEdit()->setFocus(); }
void TextEditor::validate() { if (Settings::spellCheckTextNotes() != textEdit()->checkSpellingEnabled()) { Settings::setSpellCheckTextNotes(textEdit()->checkSpellingEnabled()); Settings::saveConfig(); } textEdit()->setCheckSpellingEnabled(false); if (textEdit()->document()->isEmpty()) setEmpty(); m_textContent->setText(textEdit()->toPlainText()); m_textContent->saveToFile(); m_textContent->setEdited(); note()->setWidth(0); }
void TextView::updatePositionStatus() { QTextCursor cursor = textEdit()->textCursor(); int line = cursor.blockNumber() + 1; int column = cursor.columnNumber() + 1; Q_EMIT status(tr("Line %1, Column %2").arg(line).arg(column)); }
void AboutDialog::displayFile(const QString &fileName, const QString &title) { QDialog dialog(this); QVBoxLayout layout(&dialog); QTextEdit textEdit(&dialog); QDialogButtonBox buttonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog); textEdit.setLayoutDirection(Qt::LeftToRight); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) return; QTextStream stream(&file); stream.setCodec("UTF-8"); QString text = stream.readAll(); // this is done to force the content of the text editor to be LTR, and monospaced. textEdit.setHtml(QString(QLatin1String("<pre>%1</pre>")).arg(text)); textEdit.setReadOnly(true); connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(close())); buttonBox.setCenterButtons(true); layout.addWidget(&textEdit); layout.addWidget(&buttonBox); layout.setMargin(6); dialog.setLayout(&layout); dialog.setWindowTitle(title); dialog.setWindowFlags(Qt::Sheet); dialog.resize(600, 350); dialog.exec(); }
QString QAccessibleTextEdit::text(QAccessible::Text t) const { if (t == QAccessible::Value) return textEdit()->toPlainText(); return QAccessibleWidget::text(t); }
LocationBar::LocationBar(QupZilla* mainClass) : LineEdit(mainClass) , p_QupZilla(mainClass) , m_webView(0) , m_pasteAndGoAction(0) , m_clearAction(0) , m_rssIconVisible(false) , m_holdingAlt(false) , m_loadProgress(0) , m_progressVisible(false) , m_forcePaintEvent(false) , m_inlineCompletionVisible(false) , m_popupClosed(false) { setObjectName("locationbar"); setDragEnabled(true); m_bookmarkIcon = new BookmarksIcon(this); m_goIcon = new GoIcon(this); m_rssIcon = new RssIcon(this); m_siteIcon = new SiteIcon(p_QupZilla, this); m_autofillIcon = new AutoFillIcon(this); DownIcon* down = new DownIcon(this); // RTL Support // if we don't add 'm_siteIcon' by following code, then we should use suitable padding-left value // but then, when typing RTL text the layout dynamically changed and within RTL layout direction // padding-left is equivalent to padding-right and vice versa, and because style sheet is // not changed dynamically this create padding problems. addWidget(m_siteIcon, LineEdit::LeftSide); addWidget(m_autofillIcon, LineEdit::RightSide); addWidget(m_bookmarkIcon, LineEdit::RightSide); addWidget(m_rssIcon, LineEdit::RightSide); addWidget(m_goIcon, LineEdit::RightSide); addWidget(down, LineEdit::RightSide); m_completer.setLocationBar(this); connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString))); connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter())); connect(&m_completer, SIGNAL(popupClosed()), this, SLOT(completionPopupClosed())); connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit())); connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter())); connect(down, SIGNAL(clicked(QPoint)), &m_completer, SLOT(showMostVisited())); connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp->searchEnginesManager(), SIGNAL(defaultEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), SLOT(onMessage(Qz::AppMessageType,bool))); loadSettings(); clearIcon(); // Hide icons by default hideGoButton(); m_rssIcon->hide(); m_autofillIcon->hide(); QTimer::singleShot(0, this, SLOT(updatePlaceHolderText())); }
void HtmlEditor::autoSave(bool toFileToo) { m_htmlContent->setHtml(textEdit()->document()->toHtml("utf-8")); if (toFileToo) { m_htmlContent->saveToFile(); m_htmlContent->setEdited(); } }
/*! \reimp */ void Q3AccessibleTextEdit::setText(Text t, int control, const QString &text) { if (t != Value || control) { Q3AccessibleScrollView::setText(t, control, text); return; } textEdit()->setText(text); }
int SpellHighlighter::highlightParagraph(const QString&, int state) { m_bDirty = false; if (state == -2) state = 0; if (state != m_paragraph){ m_paragraph = state; m_words.clear(); } textEdit()->getCursorPosition(&m_parag, &m_index); m_pos = 0; m_bError = false; while (!m_fonts.empty()) m_fonts.pop(); parse(textEdit()->text(m_paragraph)); return state + 1; }
QAccessible::State QAccessibleTextEdit::state() const { QAccessible::State st = QAccessibleTextWidget::state(); if (textEdit()->isReadOnly()) st.readOnly = true; else st.editable = true; return st; }
void QSyntaxHighlighter::setFormat( int start, int count, const QColor &color ) { if ( !para || count <= 0 ) return; QTextFormat *f = 0; QFont fnt = textEdit()->QWidget::font(); f = para->document()->formatCollection()->format( fnt, color ); para->setFormat( start, count, f ); f->removeRef(); }
void TextView::updateExtraSelections() { auto size = textEdit()->viewport()->size(); auto firstVisiblePosition = textEdit()->cursorForPosition(QPoint(0, 0)).position(); auto lastVisiblePosition = textEdit()->cursorForPosition(QPoint(size.width() - 1, size.height() - 1)).position(); auto first = std::lower_bound(highlighting_.begin(), highlighting_.end(), firstVisiblePosition, [](const Range<int> &range, int pos) { return range.end() < pos; }); QList<QTextEdit::ExtraSelection> selections; for (auto i = first; i != highlighting_.end() && i->start() <= lastVisiblePosition; ++i) { QTextEdit::ExtraSelection selection; selection.cursor = textEdit()->textCursor(); selection.cursor.setPosition(i->start()); selection.cursor.setPosition(i->end(), QTextCursor::KeepAnchor); selection.format.setBackground(QColor(highlightColor)); selections.append(selection); } textEdit()->setExtraSelections(selections); }
void TextView::saveAs() { QString filename = QFileDialog::getSaveFileName(this, tr("Where should I save the text?")); if (!filename.isEmpty()) { QFile file(filename); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { QMessageBox::critical(this, tr("Error"), tr("File %1 could not be opened for writing.").arg(filename)); } QTextStream out(&file); out << textEdit()->toPlainText(); } }
void QAccessibleTextEdit::scrollToSubstring(int startIndex, int endIndex) { QTextEdit *edit = textEdit(); QTextCursor cursor = textCursor(); cursor.setPosition(startIndex); QRect r = edit->cursorRect(cursor); cursor.setPosition(endIndex); r.setBottomRight(edit->cursorRect(cursor).bottomRight()); r.moveTo(r.x() + edit->horizontalScrollBar()->value(), r.y() + edit->verticalScrollBar()->value()); // E V I L, but ensureVisible is not public if (!QMetaObject::invokeMethod(edit, "_q_ensureVisible", Q_ARG(QRectF, r))) qWarning("AccessibleTextEdit::scrollToSubstring failed!"); }
void HtmlEditor::cursorPositionChanged() { InlineEditors::instance()->richTextFont->setCurrentFont(textEdit()->currentFont().family()); if (InlineEditors::instance()->richTextColor->color() != textEdit()->textColor()) InlineEditors::instance()->richTextColor->setColor(textEdit()->textColor()); InlineEditors::instance()->richTextBold->setChecked((textEdit()->fontWeight() >= QFont::Bold)); InlineEditors::instance()->richTextItalic->setChecked(textEdit()->fontItalic()); InlineEditors::instance()->richTextUnderline->setChecked(textEdit()->fontUnderline()); switch (textEdit()->alignment()) { default: case 1/*Qt::AlignLeft*/: InlineEditors::instance()->richTextLeft->setChecked(true); break; case 2/*Qt::AlignRight*/: InlineEditors::instance()->richTextRight->setChecked(true); break; case 4/*Qt::AlignHCenter*/: InlineEditors::instance()->richTextCenter->setChecked(true); break; case 8/*Qt::AlignJustify*/: InlineEditors::instance()->richTextJustified->setChecked(true); break; } }