Commit 2b93fea5 authored by hjk's avatar hjk Committed by David Schulz

BaseTextEditor: Style fixes

Whitespace, s/e/m_editorWidget/, remove unneeded struct, remove 'inline'
when not needed...

Change-Id: I1ce76f5c4b1febe45c4a3b6404107fed7d9c6868
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent cfc8ce8c
......@@ -104,39 +104,38 @@
\internal
*/
using namespace TextEditor;
using namespace TextEditor::Internal;
using namespace Utils;
namespace TextEditor {
namespace Internal {
class TextEditExtraArea : public QWidget {
BaseTextEditorWidget *textEdit;
class TextEditExtraArea : public QWidget
{
public:
TextEditExtraArea(BaseTextEditorWidget *edit):QWidget(edit) {
TextEditExtraArea(BaseTextEditorWidget *edit)
: QWidget(edit)
{
textEdit = edit;
setAutoFillBackground(true);
}
public:
protected:
QSize sizeHint() const {
return QSize(textEdit->extraAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event){
void paintEvent(QPaintEvent *event) {
textEdit->extraAreaPaintEvent(event);
}
void mousePressEvent(QMouseEvent *event){
void mousePressEvent(QMouseEvent *event) {
textEdit->extraAreaMouseEvent(event);
}
void mouseMoveEvent(QMouseEvent *event){
void mouseMoveEvent(QMouseEvent *event) {
textEdit->extraAreaMouseEvent(event);
}
void mouseReleaseEvent(QMouseEvent *event){
void mouseReleaseEvent(QMouseEvent *event) {
textEdit->extraAreaMouseEvent(event);
}
void leaveEvent(QEvent *event){
void leaveEvent(QEvent *event) {
textEdit->extraAreaLeaveEvent(event);
}
void contextMenuEvent(QContextMenuEvent *event) {
......@@ -146,13 +145,17 @@ protected:
void wheelEvent(QWheelEvent *event) {
QCoreApplication::sendEvent(textEdit->viewport(), event);
}
private:
BaseTextEditorWidget *textEdit;
};
} // namespace Internal
} // namespace TextEditor
using namespace Internal;
Core::IEditor *BaseTextEditorWidget::openEditorAt(const QString &fileName, int line, int column,
const Core::Id &editorKind,
Core::Id editorKind,
Core::EditorManager::OpenEditorFlags flags,
bool *newEditor)
{
......@@ -294,7 +297,7 @@ void BaseTextEditorWidget::setMimeType(const QString &mt)
void BaseTextEditorWidget::print(QPrinter *printer)
{
const bool oldFullPage = printer->fullPage();
const bool oldFullPage = printer->fullPage();
printer->setFullPage(true);
QPrintDialog *dlg = new QPrintDialog(printer, this);
dlg->setWindowTitle(tr("Print Document"));
......@@ -307,7 +310,7 @@ void BaseTextEditorWidget::print(QPrinter *printer)
static int foldBoxWidth(const QFontMetrics &fm)
{
const int lineSpacing = fm.lineSpacing();
return lineSpacing + lineSpacing%2 + 1;
return lineSpacing + lineSpacing % 2 + 1;
}
static void printPage(int index, QPainter *painter, const QTextDocument *doc,
......@@ -381,7 +384,7 @@ void BaseTextEditorWidgetPrivate::print(QPrinter *printer)
QList<QTextLayout::FormatRange> formatList = srcBlock.layout()->additionalFormats();
if (backgroundIsDark) {
// adjust syntax highlighting colors for better contrast
for (int i = formatList.count() - 1; i >=0; --i) {
for (int i = formatList.count() - 1; i >= 0; --i) {
QTextCharFormat &format = formatList[i].format;
if (format.background().color() == background) {
QBrush brush = format.foreground();
......@@ -423,7 +426,7 @@ void BaseTextEditorWidgetPrivate::print(QPrinter *printer)
int docCopies;
int pageCopies;
if (printer->collateCopies() == true){
if (printer->collateCopies() == true) {
docCopies = 1;
pageCopies = printer->numCopies();
} else {
......@@ -631,8 +634,6 @@ const Utils::ChangeSet &BaseTextEditorWidget::changeSet() const
void BaseTextEditorWidget::setChangeSet(const Utils::ChangeSet &changeSet)
{
using namespace Utils;
d->m_changeSet = changeSet;
foreach (const ChangeSet::EditOp &op, changeSet.operationList()) {
......@@ -1057,7 +1058,6 @@ void BaseTextEditorWidget::uppercaseSelection()
transformSelection(&QString::toUpper);
}
void BaseTextEditorWidget::lowercaseSelection()
{
transformSelection(&QString::toLower);
......@@ -1173,7 +1173,7 @@ void BaseTextEditorWidget::moveLineUpDown(bool up)
d->m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers);
bool shouldReindent = true;
const Utils::CommentDefinition* commentDefinition(editor()->commentDefinition());
const CommentDefinition *commentDefinition(editor()->commentDefinition());
if (commentDefinition) {
QString trimmedText(text.trimmed());
......@@ -2825,19 +2825,6 @@ void BaseTextEditorWidgetPrivate::highlightSearchResults(const QTextBlock &block
}
}
namespace TextEditor {
namespace Internal {
struct BlockSelectionData {
int selectionIndex;
int selectionStart;
int selectionEnd;
int firstColumn;
int lastColumn;
};
}
}
void BaseTextEditorWidgetPrivate::clearBlockSelection()
{
if (m_inBlockSelectionMode) {
......@@ -6281,9 +6268,9 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor)
: e(editor)
: m_editorWidget(editor)
{
setWidget(e);
setWidget(m_editorWidget);
using namespace Find;
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
BaseTextFind *baseTextFind = new BaseTextFind(editor);
......@@ -6318,7 +6305,7 @@ BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor)
BaseTextEditor::~BaseTextEditor()
{
delete m_toolBar;
delete e;
delete m_editorWidget;
}
QWidget *BaseTextEditor::toolBar()
......@@ -6343,74 +6330,74 @@ void BaseTextEditor::insertExtraToolBarWidget(BaseTextEditor::Side side,
int BaseTextEditor::currentLine() const
{
return e->textCursor().blockNumber() + 1;
return m_editorWidget->textCursor().blockNumber() + 1;
}
int BaseTextEditor::currentColumn() const
{
QTextCursor cursor = e->textCursor();
QTextCursor cursor = m_editorWidget->textCursor();
return cursor.position() - cursor.block().position() + 1;
}
int BaseTextEditor::columnCount() const
{
return e->columnCount();
return m_editorWidget->columnCount();
}
int BaseTextEditor::rowCount() const
{
return e->rowCount();
return m_editorWidget->rowCount();
}
QRect BaseTextEditor::cursorRect(int pos) const
{
QTextCursor tc = e->textCursor();
QTextCursor tc = m_editorWidget->textCursor();
if (pos >= 0)
tc.setPosition(pos);
QRect result = e->cursorRect(tc);
result.moveTo(e->viewport()->mapToGlobal(result.topLeft()));
QRect result = m_editorWidget->cursorRect(tc);
result.moveTo(m_editorWidget->viewport()->mapToGlobal(result.topLeft()));
return result;
}
QString BaseTextEditor::selectedText() const
{
if (e->textCursor().hasSelection())
return e->textCursor().selectedText();
if (m_editorWidget->textCursor().hasSelection())
return m_editorWidget->textCursor().selectedText();
return QString();
}
void BaseTextEditor::remove(int length)
{
QTextCursor tc = e->textCursor();
QTextCursor tc = m_editorWidget->textCursor();
tc.setPosition(tc.position() + length, QTextCursor::KeepAnchor);
tc.removeSelectedText();
}
void BaseTextEditor::insert(const QString &string)
{
QTextCursor tc = e->textCursor();
QTextCursor tc = m_editorWidget->textCursor();
tc.insertText(string);
}
void BaseTextEditor::replace(int length, const QString &string)
{
QTextCursor tc = e->textCursor();
QTextCursor tc = m_editorWidget->textCursor();
tc.setPosition(tc.position() + length, QTextCursor::KeepAnchor);
tc.insertText(string);
}
void BaseTextEditor::setCursorPosition(int pos)
{
QTextCursor tc = e->textCursor();
QTextCursor tc = m_editorWidget->textCursor();
tc.setPosition(pos);
e->setTextCursor(tc);
m_editorWidget->setTextCursor(tc);
}
void BaseTextEditor::select(int toPos)
{
QTextCursor tc = e->textCursor();
QTextCursor tc = m_editorWidget->textCursor();
tc.setPosition(toPos, QTextCursor::KeepAnchor);
e->setTextCursor(tc);
m_editorWidget->setTextCursor(tc);
}
const CommentDefinition *BaseTextEditor::commentDefinition() const
......@@ -6420,16 +6407,16 @@ const CommentDefinition *BaseTextEditor::commentDefinition() const
void BaseTextEditor::updateCursorPosition()
{
const QTextCursor cursor = e->textCursor();
const QTextCursor cursor = m_editorWidget->textCursor();
const QTextBlock block = cursor.block();
const int line = block.blockNumber() + 1;
const int column = cursor.position() - block.position();
m_cursorPositionLabel->setText(tr("Line: %1, Col: %2").arg(line).arg(e->tabSettings().columnAt(block.text(), column)+1),
m_cursorPositionLabel->setText(tr("Line: %1, Col: %2").arg(line).arg(m_editorWidget->tabSettings().columnAt(block.text(), column)+1),
tr("Line: 9999, Col: 999"));
m_contextHelpId.clear();
if (!block.isVisible())
e->ensureCursorVisible();
m_editorWidget->ensureCursorVisible();
}
......@@ -6456,8 +6443,8 @@ void BaseTextEditor::setFileEncodingLabelText(const QString &text)
QString BaseTextEditor::contextHelpId() const
{
if (m_contextHelpId.isEmpty())
emit const_cast<BaseTextEditor*>(this)->contextHelpIdRequested(e->editor(),
e->textCursor().position());
emit const_cast<BaseTextEditor*>(this)->contextHelpIdRequested(m_editorWidget->editor(),
m_editorWidget->textCursor().position());
return m_contextHelpId;
}
......@@ -6754,3 +6741,10 @@ QString TextEditor::BaseTextEditorWidget::foldReplacementText(const QTextBlock &
{
return QLatin1String("...");
}
bool BaseTextEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
return m_editorWidget->open(errorString, fileName, realFileName);
}
} // namespace TextEditor
......@@ -126,12 +126,13 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit
Q_OBJECT
Q_PROPERTY(int verticalBlockSelectionFirstColumn READ verticalBlockSelectionFirstColumn)
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
public:
BaseTextEditorWidget(QWidget *parent);
~BaseTextEditorWidget();
static Core::IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
const Core::Id &editorId = Core::Id(),
Core::Id editorId = Core::Id(),
Core::EditorManager::OpenEditorFlags flags = Core::EditorManager::IgnoreNavigationHistory,
bool *newEditor = 0);
......@@ -146,13 +147,10 @@ public:
bool restoreState(const QByteArray &state);
QString displayName() const;
// ITextEditor
void gotoLine(int line, int column = 0);
int position(
ITextEditor::PositionOperation posOp = ITextEditor::Current
, int at = -1) const;
int position(ITextEditor::PositionOperation posOp = ITextEditor::Current,
int at = -1) const;
void convertPosition(int pos, int *line, int *column) const;
BaseTextEditor *editor() const;
......@@ -164,7 +162,7 @@ public:
QString mimeType() const;
virtual void setMimeType(const QString &mt);
void appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId);
void appendMenuActionsFromContext(QMenu *menu, Core::Id menuContextId);
void appendStandardContextMenuActions(QMenu *menu);
// Works only in conjunction with a syntax highlighter that puts
......@@ -217,7 +215,7 @@ public:
int columnCount() const;
int rowCount() const;
void setActionHack(QObject *);
void setActionHack(QObject *hack);
QObject *actionHack() const;
void setTextCodec(QTextCodec *codec);
......@@ -617,17 +615,17 @@ public:
~BaseTextEditor();
friend class BaseTextEditorWidget;
BaseTextEditorWidget *editorWidget() const { return e; }
BaseTextEditorWidget *editorWidget() const { return m_editorWidget; }
// IEditor
Core::IDocument * document() { return e->editorDocument(); }
bool createNew(const QString &contents) { return e->createNew(contents); }
bool open(QString *errorString, const QString &fileName, const QString &realFileName) { return e->open(errorString, fileName, realFileName); }
QString displayName() const { return e->displayName(); }
void setDisplayName(const QString &title) { e->setDisplayName(title); emit changed(); }
QByteArray saveState() const { return e->saveState(); }
bool restoreState(const QByteArray &state) { return e->restoreState(state); }
Core::IDocument *document() { return m_editorWidget->editorDocument(); }
bool createNew(const QString &contents) { return m_editorWidget->createNew(contents); }
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QString displayName() const { return m_editorWidget->displayName(); }
void setDisplayName(const QString &title) { m_editorWidget->setDisplayName(title); emit changed(); }
QByteArray saveState() const { return m_editorWidget->saveState(); }
bool restoreState(const QByteArray &state) { return m_editorWidget->restoreState(state); }
QWidget *toolBar();
enum Side { Left, Right };
......@@ -636,25 +634,24 @@ public:
// ITextEditor
int currentLine() const;
int currentColumn() const;
void gotoLine(int line, int column = 0) { e->gotoLine(line, column); }
void gotoLine(int line, int column = 0) { m_editorWidget->gotoLine(line, column); }
int columnCount() const;
int rowCount() const;
int position(PositionOperation posOp = Current, int at = -1) const
{ return e->position(posOp, at); }
{ return m_editorWidget->position(posOp, at); }
void convertPosition(int pos, int *line, int *column) const
{ e->convertPosition(pos, line, column); }
{ m_editorWidget->convertPosition(pos, line, column); }
QRect cursorRect(int pos = -1) const;
QString selectedText() const;
inline ITextMarkable *markableInterface() { return e->markableInterface(); }
ITextMarkable *markableInterface() { return m_editorWidget->markableInterface(); }
QString contextHelpId() const; // from IContext
inline void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason) { e->setTextCodec(codec); }
inline QTextCodec *textCodec() const { return e->textCodec(); }
void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason) { m_editorWidget->setTextCodec(codec); }
QTextCodec *textCodec() const { return m_editorWidget->textCodec(); }
// ITextEditor
void remove(int length);
......@@ -662,7 +659,7 @@ public:
void replace(int length, const QString &string);
void setCursorPosition(int pos);
void select(int toPos);
const Utils::CommentDefinition* commentDefinition() const;
const Utils::CommentDefinition *commentDefinition() const;
private slots:
void updateCursorPosition();
......@@ -671,7 +668,9 @@ private slots:
void setFileEncodingLabelText(const QString &text);
private:
BaseTextEditorWidget *e;
// Note: This is always a copy of IContext::m_widget.
BaseTextEditorWidget *m_editorWidget;
QToolBar *m_toolBar;
QWidget *m_stretchWidget;
QAction *m_cursorPositionLabelAction;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment