forked from qt-creator/qt-creator
Add some methods which will be needed by diff editor
Change-Id: Iae85e123a5b72e85b8b55359267bc1b2810a640b Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -181,10 +181,20 @@ Core::IEditor *BaseTextEditorWidget::openEditorAt(const QString &fileName, int l
|
|||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void convertToPlainText(QString &txt)
|
QString BaseTextEditorWidget::plainTextFromSelection() const
|
||||||
{
|
{
|
||||||
QChar *uc = txt.data();
|
QTextCursor cursor = textCursor();
|
||||||
QChar *e = uc + txt.size();
|
|
||||||
|
// Copy the selected text as plain text
|
||||||
|
QString text = cursor.selectedText();
|
||||||
|
return convertToPlainText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BaseTextEditorWidget::convertToPlainText(const QString &txt)
|
||||||
|
{
|
||||||
|
QString ret = txt;
|
||||||
|
QChar *uc = ret.data();
|
||||||
|
QChar *e = uc + ret.size();
|
||||||
|
|
||||||
for (; uc != e; ++uc) {
|
for (; uc != e; ++uc) {
|
||||||
switch (uc->unicode()) {
|
switch (uc->unicode()) {
|
||||||
@@ -201,6 +211,7 @@ static void convertToPlainText(QString &txt)
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char kTextBlockMimeType[] = "application/vnd.nokia.qtcreator.blocktext";
|
static const char kTextBlockMimeType[] = "application/vnd.nokia.qtcreator.blocktext";
|
||||||
@@ -3701,13 +3712,7 @@ int BaseTextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
|||||||
fnt.setItalic(d->m_currentLineNumberFormat.font().italic());
|
fnt.setItalic(d->m_currentLineNumberFormat.font().italic());
|
||||||
const QFontMetrics linefm(fnt);
|
const QFontMetrics linefm(fnt);
|
||||||
|
|
||||||
int digits = 2;
|
space += linefm.width(QLatin1Char('9')) * lineNumberDigits();
|
||||||
int max = qMax(1, blockCount());
|
|
||||||
while (max >= 100) {
|
|
||||||
max /= 10;
|
|
||||||
++digits;
|
|
||||||
}
|
|
||||||
space += linefm.width(QLatin1Char('9')) * digits;
|
|
||||||
}
|
}
|
||||||
int markWidth = 0;
|
int markWidth = 0;
|
||||||
|
|
||||||
@@ -3918,7 +3923,7 @@ void BaseTextEditorWidget::extraAreaPaintEvent(QPaintEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (d->m_lineNumbersVisible) {
|
if (d->m_lineNumbersVisible) {
|
||||||
const QString &number = QString::number(blockNumber + 1);
|
const QString &number = lineNumber(blockNumber);
|
||||||
bool selected = (
|
bool selected = (
|
||||||
(selStart < block.position() + block.length()
|
(selStart < block.position() + block.length()
|
||||||
|
|
||||||
@@ -3933,7 +3938,7 @@ void BaseTextEditorWidget::extraAreaPaintEvent(QPaintEvent *e)
|
|||||||
painter.setFont(f);
|
painter.setFont(f);
|
||||||
painter.setPen(d->m_currentLineNumberFormat.foreground().color());
|
painter.setPen(d->m_currentLineNumberFormat.foreground().color());
|
||||||
}
|
}
|
||||||
painter.drawText(QRectF(markWidth, top, extraAreaWidth - markWidth - 4, height), Qt::AlignRight, number);
|
painter.drawText(QRectF(markWidth, top + lineNumberTopPositionOffset(blockNumber), extraAreaWidth - markWidth - 4, height), Qt::AlignRight, number);
|
||||||
if (selected)
|
if (selected)
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
@@ -5966,9 +5971,7 @@ QMimeData *BaseTextEditorWidget::createMimeDataFromSelection() const
|
|||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
|
|
||||||
// Copy the selected text as plain text
|
QString text = plainTextFromSelection();
|
||||||
QString text = cursor.selectedText();
|
|
||||||
convertToPlainText(text);
|
|
||||||
mimeData->setText(text);
|
mimeData->setText(text);
|
||||||
|
|
||||||
// Copy the selected text as HTML
|
// Copy the selected text as HTML
|
||||||
@@ -6186,6 +6189,28 @@ QMimeData *BaseTextEditorWidget::duplicateMimeData(const QMimeData *source) cons
|
|||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString BaseTextEditorWidget::lineNumber(int blockNumber) const
|
||||||
|
{
|
||||||
|
return QString::number(blockNumber + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int BaseTextEditorWidget::lineNumberTopPositionOffset(int blockNumber) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(blockNumber)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BaseTextEditorWidget::lineNumberDigits() const
|
||||||
|
{
|
||||||
|
int digits = 2;
|
||||||
|
int max = qMax(1, blockCount());
|
||||||
|
while (max >= 100) {
|
||||||
|
max /= 10;
|
||||||
|
++digits;
|
||||||
|
}
|
||||||
|
return digits;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId)
|
void BaseTextEditorWidget::appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId)
|
||||||
{
|
{
|
||||||
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(menuContextId);
|
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(menuContextId);
|
||||||
|
@@ -354,6 +354,13 @@ protected:
|
|||||||
bool canInsertFromMimeData(const QMimeData *source) const;
|
bool canInsertFromMimeData(const QMimeData *source) const;
|
||||||
void insertFromMimeData(const QMimeData *source);
|
void insertFromMimeData(const QMimeData *source);
|
||||||
|
|
||||||
|
virtual QString plainTextFromSelection() const;
|
||||||
|
static QString convertToPlainText(const QString &txt);
|
||||||
|
|
||||||
|
virtual QString lineNumber(int blockNumber) const;
|
||||||
|
virtual int lineNumberTopPositionOffset(int blockNumber) const;
|
||||||
|
virtual int lineNumberDigits() const;
|
||||||
|
|
||||||
static QString msgTextTooLarge(quint64 size);
|
static QString msgTextTooLarge(quint64 size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user