void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) { if (dy) { lineNumberArea->scroll(0, dy); } else if (m_countCache.first != blockCount() || m_countCache.second != textCursor().block().lineCount()) { lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); m_countCache.first = blockCount(); m_countCache.second = textCursor().block().lineCount(); } if (rect.contains(viewport()->rect())) updateLineNumberAreaWidth(0); }
std::vector<Block> File::blocks(const util::Filter<Block>::type &filter) const { auto f = [this] (ndsize_t i) { return getBlock(i); }; return getEntities<Block>(f, blockCount(), filter); }
bool SourceWindow::loadFile() { QFile f(m_fileName); if (!f.open(QIODevice::ReadOnly)) { return false; } QTextStream t(&f); setPlainText(t.readAll()); f.close(); int n = blockCount(); m_sourceCode.resize(n); m_rowToLine.resize(n); for (int i = 0; i < n; i++) { m_rowToLine[i] = i; } m_lineItems.resize(n, 0); // set a font for line numbers m_lineNoFont = currentCharFormat().font(); m_lineNoFont.setPixelSize(11); return true; }
void SourceWindow::reloadFile() { QFile f(m_fileName); if (!f.open(QIODevice::ReadOnly)) { // open failed; leave alone return; } m_sourceCode.clear(); /* clear old text */ QTextStream t(&f); setPlainText(t.readAll()); f.close(); m_sourceCode.resize(blockCount()); // expanded lines are collapsed: move existing line items up for (size_t i = 0; i < m_lineItems.size(); i++) { if (m_rowToLine[i] != int(i)) { m_lineItems[m_rowToLine[i]] |= m_lineItems[i]; m_lineItems[i] = 0; } } // allocate line items m_lineItems.resize(m_sourceCode.size(), 0); m_rowToLine.resize(m_sourceCode.size()); for (size_t i = 0; i < m_sourceCode.size(); i++) m_rowToLine[i] = i; // Highlighting was applied above when the text was inserted into widget, // but at that time m_rowToLine was not corrected, yet, so that lines // that previously were assembly were painted incorrectly. if (m_highlighter) m_highlighter->rehighlight(); }
int TextDocument::totalCount() const { int count = d.queue.count(); if (!isEmpty()) count += blockCount(); return count; }
int QTextDocument::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 14) qt_static_metacall(this, _c, _id, _a); _id -= 14; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = isUndoRedoEnabled(); break; case 1: *reinterpret_cast< bool*>(_v) = isModified(); break; case 2: *reinterpret_cast< QSizeF*>(_v) = pageSize(); break; case 3: *reinterpret_cast< QFont*>(_v) = defaultFont(); break; case 4: *reinterpret_cast< bool*>(_v) = useDesignMetrics(); break; case 5: *reinterpret_cast< QSizeF*>(_v) = size(); break; case 6: *reinterpret_cast< qreal*>(_v) = textWidth(); break; case 7: *reinterpret_cast< int*>(_v) = blockCount(); break; case 8: *reinterpret_cast< qreal*>(_v) = indentWidth(); break; case 9: *reinterpret_cast< QString*>(_v) = defaultStyleSheet(); break; case 10: *reinterpret_cast< int*>(_v) = maximumBlockCount(); break; case 11: *reinterpret_cast< qreal*>(_v) = documentMargin(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setUndoRedoEnabled(*reinterpret_cast< bool*>(_v)); break; case 1: setModified(*reinterpret_cast< bool*>(_v)); break; case 2: setPageSize(*reinterpret_cast< QSizeF*>(_v)); break; case 3: setDefaultFont(*reinterpret_cast< QFont*>(_v)); break; case 4: setUseDesignMetrics(*reinterpret_cast< bool*>(_v)); break; case 6: setTextWidth(*reinterpret_cast< qreal*>(_v)); break; case 8: setIndentWidth(*reinterpret_cast< qreal*>(_v)); break; case 9: setDefaultStyleSheet(*reinterpret_cast< QString*>(_v)); break; case 10: setMaximumBlockCount(*reinterpret_cast< int*>(_v)); break; case 11: setDocumentMargin(*reinterpret_cast< qreal*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
int TextEdit::gutterWidth() { int blocks = blockCount(); int digits = 1; while (blocks /= 10) digits++; return fontMetrics().width(QLatin1Char('9')) * (qMax(digits, 3) + 1); }
GenericCodeEditor::GenericCodeEditor( Document *doc, QWidget *parent ): QPlainTextEdit( parent ), mDoc(doc), mEditorBoxIsActive(false), mLastCursorBlock(-1) { Q_ASSERT(mDoc != 0); setFrameShape(QFrame::NoFrame); viewport()->setAttribute( Qt::WA_MacNoClickThrough, true ); mLineIndicator = new LineIndicator(this); mLineIndicator->move( contentsRect().topLeft() ); mOverlay = new QGraphicsScene(this); QPalette overlayPalette; overlayPalette.setBrush(QPalette::Base, Qt::NoBrush); QGraphicsView *overlayView = new QGraphicsView(mOverlay, this); overlayView->setFrameShape( QFrame::NoFrame ); overlayView->setPalette(overlayPalette); overlayView->setFocusPolicy( Qt::NoFocus ); overlayView->setAttribute(Qt::WA_TransparentForMouseEvents, true); overlayView->setSceneRect(QRectF(0,0,1,1)); overlayView->setAlignment(Qt::AlignLeft | Qt::AlignTop); mOverlayWidget = overlayView; mOverlayAnimator = new OverlayAnimator(this, mOverlay); connect( mDoc, SIGNAL(defaultFontChanged()), this, SLOT(onDocumentFontChanged()) ); connect( this, SIGNAL(blockCountChanged(int)), mLineIndicator, SLOT(setLineCount(int)) ); connect( mLineIndicator, SIGNAL( widthChanged() ), this, SLOT( updateLayout() ) ); connect( this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineIndicator(QRect,int)) ); connect( this, SIGNAL(selectionChanged()), mLineIndicator, SLOT(update()) ); connect( this, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged()) ); connect( Main::instance(), SIGNAL(applySettingsRequest(Settings::Manager*)), this, SLOT(applySettings(Settings::Manager*)) ); QTextDocument *tdoc = doc->textDocument(); QPlainTextEdit::setDocument(tdoc); onDocumentFontChanged(); mLineIndicator->setLineCount(blockCount()); applySettings( Main::settings() ); }
std::shared_ptr<base::IBlock> FileFS::getBlock(ndsize_t index) const { if (index >= blockCount()) { throw nix::OutOfBounds("Trying to access file.block with invalid index", index); } bfs::path p = data_dir.sub_dir_by_index(index); std::shared_ptr<BlockFS> b; b = std::make_shared<BlockFS>(file(), p.string()); return b; }
void ScriptView::updateLineNumberArea(const QRect& rect, int dy) { if ( dy != 0 ) { mpLineNumberArea->scroll(0, dy); } else if ( mCountCache.first != blockCount() || mCountCache.second != textCursor().block().lineCount() ) { mpLineNumberArea->update(0, rect.y(), mpLineNumberArea->width(), rect.height()); mCountCache.first = blockCount(); mCountCache.second = textCursor().block().lineCount(); } if ( rect.contains(viewport()->rect()) ) { updateLineNuberAreaWidth(0); } }
int CodeEditor::lineNumberAreaWidth() { int digits = 3 ; int max = qMax(1, blockCount()); while ( max >= 10 ) { max /= 10 ; ++digits ; } int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits ; return space ; }
int ScriptEditBox::lineNumberAreaWidth() { int digits = 1; const int SPACER_PIXELS = 3; const int BASE_TEN = 10; int max = qMax(1, blockCount()); while (max >= BASE_TEN) { max /= BASE_TEN; digits++; } return SPACER_PIXELS + fontMetrics().width(QLatin1Char('H')) * digits; }
int BaseEditor::lineNumberAreaWidth() { int digits = 1; int max = qMax(1, blockCount()); while(max >= 10) { max /= 10; ++digits; } int space = 3 + QFontMetrics(document()->defaultFont()).width(QLatin1Char('9')) * digits; return space; }
void GenericCodeEditor::applySettings( Settings::Manager *settings ) { settings->beginGroup("IDE/editor"); bool lineWrap = settings->value("lineWrap").toBool(); bool showWhitespace = settings->value("showWhitespace").toBool(); bool showLinenumber = settings->value("showLinenumber").toBool(); mInactiveFadeAlpha = settings->value("inactiveEditorFadeAlpha").toInt(); QPalette palette; const QTextCharFormat *format = &settings->getThemeVal("text"); QBrush bg = format->background(); QBrush fg = format->foreground(); if (bg.style() != Qt::NoBrush) palette.setBrush(QPalette::Base, bg); if (fg.style() != Qt::NoBrush) palette.setBrush(QPalette::Text, fg); // NOTE: the line number widget will inherit the palette from the editor format = &settings->getThemeVal("lineNumbers"); mLineIndicator->setFont(format->font()); bg = format->background(); fg = format->foreground(); palette.setBrush(QPalette::Mid, bg.style() != Qt::NoBrush ? bg : palette.base()); palette.setBrush(QPalette::ButtonText, fg.style() != Qt::NoBrush ? fg : palette.base()); format = &settings->getThemeVal("selection"); bg = format->background(); fg = format->foreground(); if (bg.style() != Qt::NoBrush) palette.setBrush(QPalette::Highlight, bg); if (fg.style() != Qt::NoBrush) palette.setBrush(QPalette::HighlightedText, fg); mCurrentLineTextFormat = settings->getThemeVal("currentLine"); mSearchResultTextFormat = settings->getThemeVal("searchResult"); mHighlightCurrentLine = settings->value("highlightCurrentLine").toBool(); updateCurrentLineHighlighting(); settings->endGroup(); // IDE/editor setLineWrapMode( lineWrap ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap ); setShowWhitespace( showWhitespace ); setShowLinenumber( showLinenumber ); mLineIndicator->setLineCount(blockCount()); setPalette(palette); setActiveAppearance(hasFocus()); }
int SqlTextEdit::lineNumberAreaWidth() { int digits = 1; int max = qMax(1, blockCount()); while(max >= 10) { max /= 10; ++digits; } return 3 + fontMetrics().width(QLatin1Char('9')) * digits; }
int CCodeEditor::lineNumberAreaWidth() { int digits = 1; int max = qMax(1, blockCount()); while (max >= 10) { max /= 10; ++digits; } int space = 3 + fontMetrics().maxWidth() * digits; return space + 10; }
int SyntaxTextEditor::editorAreaWidth() { int digits = 1; int max = qMax(1, blockCount()); while (max >= 10) { max /= 10; ++digits; } int space = 6 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
int QCodeEdit::line_number_area_width() { int digits = 1; int max = std::max(1, blockCount()); while(max >= 10) { max /= 10; ++digits; } int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
int ScriptView::getLineNumberAreaWidth() const { int digits = 1; int max = qMax(1, blockCount()); while ( max >= 10 ) { max /= 10; ++digits; } int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
int MarkdownEditor::lineNumberAreaWidth() { int digits = 2; int max = qMax(1, blockCount()); while (max >= 100) { max /= 10; ++digits; } QFont font = lineNumberArea->font(); const QFontMetrics linefmt(font); int space = 10 + linefmt.width(QLatin1Char('9')) * digits; return space; }
/** * @brief Returns the width needed for the line number area. * * It depends on the number of lines. * * @return The line number area width. */ int TextEditorWidget::get_line_number_area_width() { int digits = 1; int max = qMax(1, blockCount()); while (max >= 10) { max /= 10; ++digits; } ++digits; // Add space equivalent to an extra digit to the right. int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
GenericCodeEditor::GenericCodeEditor( Document *doc, QWidget *parent ): QPlainTextEdit( parent ), mDoc(doc) { Q_ASSERT(mDoc != 0); setFrameShape( QFrame::NoFrame ); mLineIndicator = new LineIndicator(this); mLineIndicator->move( contentsRect().topLeft() ); mOverlay = new QGraphicsScene(this); QGraphicsView *overlayView = new QGraphicsView(mOverlay, this); overlayView->setFrameShape( QFrame::NoFrame ); overlayView->setBackgroundBrush( Qt::NoBrush ); overlayView->setStyleSheet("background: transparent"); overlayView->setFocusPolicy( Qt::NoFocus ); overlayView->setAttribute(Qt::WA_TransparentForMouseEvents, true); overlayView->setSceneRect(QRectF(0,0,1,1)); overlayView->setAlignment(Qt::AlignLeft | Qt::AlignTop); mOverlayWidget = overlayView; connect( mDoc, SIGNAL(defaultFontChanged()), this, SLOT(onDocumentFontChanged()) ); connect( this, SIGNAL(blockCountChanged(int)), mLineIndicator, SLOT(setLineCount(int)) ); connect( mLineIndicator, SIGNAL( widthChanged() ), this, SLOT( updateLayout() ) ); connect( this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineIndicator(QRect,int)) ); connect( this, SIGNAL(selectionChanged()), mLineIndicator, SLOT(update()) ); connect( Main::instance(), SIGNAL(applySettingsRequest(Settings::Manager*)), this, SLOT(applySettings(Settings::Manager*)) ); QTextDocument *tdoc = doc->textDocument(); QPlainTextEdit::setDocument(tdoc); onDocumentFontChanged(); mLineIndicator->setLineCount(blockCount()); applySettings( Main::settings() ); }
int CodeEditor::lineNumberAreaWidth() { int digits = 1; int max = qMax(1, blockCount()); int space; /* number of digits of the biggest number */ while (max >= 10) { max /= 10; ++digits; } space = 2 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
void SparqlTextEdit::paintLineNumbers(QPaintEvent *e) { QFontMetrics metrics(currentCharFormat().font()); int digits = 0; int blocks = blockCount(); do { blocks /= 10; ++digits; } while (blocks); int maxCharWidth = 0; for (char c = '0'; c <= '9'; c++) { maxCharWidth = qMax(maxCharWidth, metrics.width(c)); } int newLeftMargin = frameWidth() + maxCharWidth * digits; if (leftMargin != newLeftMargin) { leftMargin = newLeftMargin; setViewportMargins(leftMargin, 0, 0, 0); } QPainter painter(this); painter.setClipRect(lineNumbersRect(), Qt::IntersectClip); painter.fillRect(e->rect(), palette().window()); painter.setPen(palette().windowText().color()); painter.setFont(currentCharFormat().font()); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int) blockBoundingGeometry(block) .translated(contentOffset()).top() + lineNumbersRect().top(); int bottom = top + (int) blockBoundingRect(block).height(); while (block.isValid() && top <= e->rect().bottom()) { if (block.isVisible() && bottom >= e->rect().top()) { QString number = QString::number(blockNumber + 1); painter.drawText(0, top, leftMargin, metrics.height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
int CSVWorld::ScriptEdit::lineNumberAreaWidth() { if(!mShowLineNum) return 0; int digits = 1; int max = qMax(1, blockCount()); while (max >= 10) { max /= 10; ++digits; } int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
int CodeView::lineNumberAreaWidth() { int digits = 1; if (m_mode == Disassembly) { digits = m_addressWidth * 2; } else { int max = qMax(1, blockCount()); while (max >= 10) { max /= 10; ++digits; } } // 20 + to give rom for breakpoint marker int space = 20 + 3 + fontMetrics().width(QLatin1Char('9')) * digits; return space; }
int QScriptEdit::extraAreaWidth() const { int space = 0; const QFontMetrics fm(fontMetrics()); int digits = 1; int max = qMax(1, blockCount() + m_baseLineNumber); while (max >= 10) { max /= 10; ++digits; } space += fm.width(QLatin1Char('9')) * digits; int markWidth = fm.lineSpacing(); space += markWidth; space += 4; return space; }
void TextDocument::drawForeground(QPainter* painter, const QRect& bounds) { const int num = blockCount() - d.uc; if (num > 0) { const QPen oldPen = painter->pen(); const QBrush oldBrush = painter->brush(); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(QPalette().color(QPalette::Mid), 1, Qt::DashLine)); QTextBlock block = findBlockByNumber(num); if (block.isValid()) { QRect br = documentLayout()->blockBoundingRect(block).toAlignedRect(); if (bounds.intersects(br)) { QLine line(br.topLeft(), br.topRight()); line.translate(0, -2); painter->drawLine(line); } } painter->setPen(oldPen); painter->setBrush(oldBrush); } }
int CCodeEdit::lineNumberWidth() { int drawWidth = 0; drawWidth += m_lineIconSize.width(); if( m_visibleLineNumber ) { int digits = 1; for(int n = qMax(10, blockCount()); 10 <= n; digits++) { n /= 10; } drawWidth += 3 + fontMetrics().width(QLatin1Char('9')) * digits; drawWidth += fontMetrics().width(QLatin1Char('#')); } return drawWidth; }
void CodeEdit::keyPressEvent(QKeyEvent *event) { QPlainTextEdit::keyPressEvent(event); if((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)) { if(blockCount() == 1) return; QString indent; const QString prevLine = textCursor().block().previous().text(); for(int i = 0; i < prevLine.size(); ++i) { if(!prevLine[i].isSpace()) break; indent += prevLine[i]; } QTextCursor cursor = textCursor(); cursor.insertText(indent); setTextCursor(cursor); } }