forked from qt-creator/qt-creator
Fix scrolling of compile output windwow again
This time by porting to the ApplicationOutputwindow
This commit is contained in:
@@ -54,14 +54,14 @@ const int MAX_LINECOUNT = 10000;
|
|||||||
|
|
||||||
CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
|
CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
|
||||||
{
|
{
|
||||||
m_textEdit = new QPlainTextEdit();
|
m_outputWindow = new OutputWindow();
|
||||||
m_textEdit->setWindowTitle(tr("Compile Output"));
|
m_outputWindow->setWindowTitle(tr("Compile Output"));
|
||||||
m_textEdit->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
|
m_outputWindow->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
|
||||||
m_textEdit->setReadOnly(true);
|
m_outputWindow->setReadOnly(true);
|
||||||
m_textEdit->setFrameStyle(QFrame::NoFrame);
|
|
||||||
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
||||||
agg->add(m_textEdit);
|
agg->add(m_outputWindow);
|
||||||
agg->add(new Find::BaseTextFind(m_textEdit));
|
agg->add(new Find::BaseTextFind(m_outputWindow));
|
||||||
|
|
||||||
qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
|
qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ CompileOutputWindow::~CompileOutputWindow()
|
|||||||
|
|
||||||
bool CompileOutputWindow::hasFocus()
|
bool CompileOutputWindow::hasFocus()
|
||||||
{
|
{
|
||||||
return m_textEdit->hasFocus();
|
return m_outputWindow->hasFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompileOutputWindow::canFocus()
|
bool CompileOutputWindow::canFocus()
|
||||||
@@ -87,52 +87,28 @@ bool CompileOutputWindow::canFocus()
|
|||||||
|
|
||||||
void CompileOutputWindow::setFocus()
|
void CompileOutputWindow::setFocus()
|
||||||
{
|
{
|
||||||
m_textEdit->setFocus();
|
m_outputWindow->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *CompileOutputWindow::outputWidget(QWidget *)
|
QWidget *CompileOutputWindow::outputWidget(QWidget *)
|
||||||
{
|
{
|
||||||
return m_textEdit;
|
return m_outputWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompileOutputWindow::appendText(const QString &text, const QTextCharFormat &textCharFormat)
|
void CompileOutputWindow::appendText(const QString &text, const QTextCharFormat &textCharFormat)
|
||||||
{
|
{
|
||||||
if (m_textEdit->document()->blockCount() > MAX_LINECOUNT)
|
m_outputWindow->appendText(text, textCharFormat, MAX_LINECOUNT);
|
||||||
return;
|
|
||||||
bool shouldScroll = (m_textEdit->verticalScrollBar()->value() ==
|
|
||||||
m_textEdit->verticalScrollBar()->maximum());
|
|
||||||
QString textWithNewline = text;
|
|
||||||
if (!textWithNewline.endsWith("\n"))
|
|
||||||
textWithNewline.append("\n");
|
|
||||||
QTextCursor cursor = QTextCursor(m_textEdit->document());
|
|
||||||
cursor.movePosition(QTextCursor::End);
|
|
||||||
cursor.beginEditBlock();
|
|
||||||
cursor.insertText(textWithNewline, textCharFormat);
|
|
||||||
|
|
||||||
if (m_textEdit->document()->blockCount() > MAX_LINECOUNT) {
|
|
||||||
QTextCharFormat tmp;
|
|
||||||
tmp.setFontWeight(QFont::Bold);
|
|
||||||
cursor.insertText(tr("Additional output omitted\n"), tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.endEditBlock();
|
|
||||||
|
|
||||||
if (shouldScroll) {
|
|
||||||
m_textEdit->verticalScrollBar()->setValue(m_textEdit->verticalScrollBar()->maximum());
|
|
||||||
m_textEdit->setTextCursor(cursor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompileOutputWindow::clearContents()
|
void CompileOutputWindow::clearContents()
|
||||||
{
|
{
|
||||||
m_textEdit->clear();
|
m_outputWindow->clear();
|
||||||
m_taskPositions.clear();
|
m_taskPositions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompileOutputWindow::visibilityChanged(bool b)
|
void CompileOutputWindow::visibilityChanged(bool)
|
||||||
{
|
{
|
||||||
if (b)
|
|
||||||
m_textEdit->verticalScrollBar()->setValue(m_textEdit->verticalScrollBar()->maximum());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CompileOutputWindow::priorityInStatusBar() const
|
int CompileOutputWindow::priorityInStatusBar() const
|
||||||
@@ -167,7 +143,7 @@ bool CompileOutputWindow::canNavigate()
|
|||||||
|
|
||||||
void CompileOutputWindow::registerPositionOf(const Task &task)
|
void CompileOutputWindow::registerPositionOf(const Task &task)
|
||||||
{
|
{
|
||||||
int blocknumber = m_textEdit->blockCount();
|
int blocknumber = m_outputWindow->blockCount();
|
||||||
if (blocknumber > MAX_LINECOUNT)
|
if (blocknumber > MAX_LINECOUNT)
|
||||||
return;
|
return;
|
||||||
m_taskPositions.insert(task.taskId, blocknumber - 1);
|
m_taskPositions.insert(task.taskId, blocknumber - 1);
|
||||||
@@ -181,7 +157,7 @@ bool CompileOutputWindow::knowsPositionOf(const Task &task)
|
|||||||
void CompileOutputWindow::showPositionOf(const Task &task)
|
void CompileOutputWindow::showPositionOf(const Task &task)
|
||||||
{
|
{
|
||||||
int position = m_taskPositions.value(task.taskId);
|
int position = m_taskPositions.value(task.taskId);
|
||||||
QTextCursor newCursor(m_textEdit->document()->findBlockByNumber(position));
|
QTextCursor newCursor(m_outputWindow->document()->findBlockByNumber(position));
|
||||||
newCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
newCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
||||||
m_textEdit->setTextCursor(newCursor);
|
m_outputWindow->setTextCursor(newCursor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#ifndef COMPILEOUTPUTWINDOW_H
|
#ifndef COMPILEOUTPUTWINDOW_H
|
||||||
#define COMPILEOUTPUTWINDOW_H
|
#define COMPILEOUTPUTWINDOW_H
|
||||||
|
|
||||||
|
#include "outputwindow.h"
|
||||||
#include <coreplugin/ioutputpane.h>
|
#include <coreplugin/ioutputpane.h>
|
||||||
|
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
@@ -78,7 +79,7 @@ public:
|
|||||||
void showPositionOf(const Task &task);
|
void showPositionOf(const Task &task);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPlainTextEdit *m_textEdit;
|
OutputWindow *m_outputWindow;
|
||||||
QHash<unsigned int, int> m_taskPositions;
|
QHash<unsigned int, int> m_taskPositions;
|
||||||
ShowOutputTaskHandler * m_handler;
|
ShowOutputTaskHandler * m_handler;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -221,6 +221,8 @@ void OutputPane::createNewOutputWindow(RunControl *rc)
|
|||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
OutputWindow *ow = new OutputWindow(m_tabWidget);
|
OutputWindow *ow = new OutputWindow(m_tabWidget);
|
||||||
|
ow->setWindowTitle(tr("Application Output Window"));
|
||||||
|
ow->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
|
||||||
ow->setFormatter(rc->outputFormatter());
|
ow->setFormatter(rc->outputFormatter());
|
||||||
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
||||||
agg->add(ow);
|
agg->add(ow);
|
||||||
@@ -376,6 +378,7 @@ bool OutputPane::canNavigate()
|
|||||||
|
|
||||||
OutputWindow::OutputWindow(QWidget *parent)
|
OutputWindow::OutputWindow(QWidget *parent)
|
||||||
: QPlainTextEdit(parent)
|
: QPlainTextEdit(parent)
|
||||||
|
, m_formatter(0)
|
||||||
, m_enforceNewline(false)
|
, m_enforceNewline(false)
|
||||||
, m_scrollToBottom(false)
|
, m_scrollToBottom(false)
|
||||||
, m_linksActive(true)
|
, m_linksActive(true)
|
||||||
@@ -383,8 +386,6 @@ OutputWindow::OutputWindow(QWidget *parent)
|
|||||||
{
|
{
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
//setCenterOnScroll(false);
|
//setCenterOnScroll(false);
|
||||||
setWindowTitle(tr("Application Output Window"));
|
|
||||||
setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
|
|
||||||
setFrameShape(QFrame::NoFrame);
|
setFrameShape(QFrame::NoFrame);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
@@ -433,10 +434,9 @@ OutputWindow::~OutputWindow()
|
|||||||
delete m_outputWindowContext;
|
delete m_outputWindowContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindow::mousePressEvent(QMouseEvent *e)
|
void OutputWindow::mousePressEvent(QMouseEvent * /*e*/)
|
||||||
{
|
{
|
||||||
m_mousePressed = true;
|
m_mousePressed = true;
|
||||||
QPlainTextEdit::mousePressEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -453,7 +453,6 @@ void OutputWindow::mouseReleaseEvent(QMouseEvent *e)
|
|||||||
const QString href = anchorAt(e->pos());
|
const QString href = anchorAt(e->pos());
|
||||||
if (m_formatter)
|
if (m_formatter)
|
||||||
m_formatter->handleLink(href);
|
m_formatter->handleLink(href);
|
||||||
QPlainTextEdit::mouseReleaseEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindow::mouseMoveEvent(QMouseEvent *e)
|
void OutputWindow::mouseMoveEvent(QMouseEvent *e)
|
||||||
@@ -466,7 +465,6 @@ void OutputWindow::mouseMoveEvent(QMouseEvent *e)
|
|||||||
viewport()->setCursor(Qt::IBeamCursor);
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
else
|
else
|
||||||
viewport()->setCursor(Qt::PointingHandCursor);
|
viewport()->setCursor(Qt::PointingHandCursor);
|
||||||
QPlainTextEdit::mouseMoveEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputFormatter *OutputWindow::formatter() const
|
OutputFormatter *OutputWindow::formatter() const
|
||||||
@@ -556,6 +554,28 @@ void OutputWindow::appendMessage(const QString &out, bool isError)
|
|||||||
enableUndoRedo();
|
enableUndoRedo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO rename
|
||||||
|
void OutputWindow::appendText(const QString &text, const QTextCharFormat &format, int maxLineCount)
|
||||||
|
{
|
||||||
|
if (document()->blockCount() > maxLineCount)
|
||||||
|
return;
|
||||||
|
const bool atBottom = isScrollbarAtBottom();
|
||||||
|
QTextCursor cursor = QTextCursor(document());
|
||||||
|
cursor.movePosition(QTextCursor::End);
|
||||||
|
cursor.beginEditBlock();
|
||||||
|
cursor.insertText(doNewlineEnfocement(text), format);
|
||||||
|
|
||||||
|
if (document()->blockCount() > maxLineCount) {
|
||||||
|
QTextCharFormat tmp;
|
||||||
|
tmp.setFontWeight(QFont::Bold);
|
||||||
|
cursor.insertText(tr("Additional output omitted\n"), tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.endEditBlock();
|
||||||
|
if (atBottom)
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
bool OutputWindow::isScrollbarAtBottom() const
|
bool OutputWindow::isScrollbarAtBottom() const
|
||||||
{
|
{
|
||||||
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
||||||
|
|||||||
@@ -135,11 +135,19 @@ public:
|
|||||||
void appendApplicationOutput(const QString &out, bool onStdErr);
|
void appendApplicationOutput(const QString &out, bool onStdErr);
|
||||||
void appendApplicationOutputInline(const QString &out, bool onStdErr);
|
void appendApplicationOutputInline(const QString &out, bool onStdErr);
|
||||||
void appendMessage(const QString &out, bool isError);
|
void appendMessage(const QString &out, bool isError);
|
||||||
|
/// appends a \p text using \p format without using formater
|
||||||
|
void appendText(const QString &text, const QTextCharFormat &format, int maxLineCount);
|
||||||
|
|
||||||
void grayOutOldContent();
|
void grayOutOldContent();
|
||||||
|
|
||||||
void showEvent(QShowEvent *);
|
void showEvent(QShowEvent *);
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
m_enforceNewline = false;
|
||||||
|
QPlainTextEdit::clear();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isScrollbarAtBottom() const;
|
bool isScrollbarAtBottom() const;
|
||||||
void scrollToBottom();
|
void scrollToBottom();
|
||||||
|
|||||||
Reference in New Issue
Block a user