Commit 185bc0ee authored by dt's avatar dt
Browse files

Fix scrolling of compile output windwow again

This time by porting to the ApplicationOutputwindow
parent 7862e312
......@@ -54,14 +54,14 @@ const int MAX_LINECOUNT = 10000;
CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
{
m_textEdit = new QPlainTextEdit();
m_textEdit->setWindowTitle(tr("Compile Output"));
m_textEdit->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
m_textEdit->setReadOnly(true);
m_textEdit->setFrameStyle(QFrame::NoFrame);
m_outputWindow = new OutputWindow();
m_outputWindow->setWindowTitle(tr("Compile Output"));
m_outputWindow->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
m_outputWindow->setReadOnly(true);
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(m_textEdit);
agg->add(new Find::BaseTextFind(m_textEdit));
agg->add(m_outputWindow);
agg->add(new Find::BaseTextFind(m_outputWindow));
qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
......@@ -77,7 +77,7 @@ CompileOutputWindow::~CompileOutputWindow()
bool CompileOutputWindow::hasFocus()
{
return m_textEdit->hasFocus();
return m_outputWindow->hasFocus();
}
bool CompileOutputWindow::canFocus()
......@@ -87,52 +87,28 @@ bool CompileOutputWindow::canFocus()
void CompileOutputWindow::setFocus()
{
m_textEdit->setFocus();
m_outputWindow->setFocus();
}
QWidget *CompileOutputWindow::outputWidget(QWidget *)
{
return m_textEdit;
return m_outputWindow;
}
void CompileOutputWindow::appendText(const QString &text, const QTextCharFormat &textCharFormat)
{
if (m_textEdit->document()->blockCount() > 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);
}
m_outputWindow->appendText(text, textCharFormat, MAX_LINECOUNT);
}
void CompileOutputWindow::clearContents()
{
m_textEdit->clear();
m_outputWindow->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
......@@ -167,7 +143,7 @@ bool CompileOutputWindow::canNavigate()
void CompileOutputWindow::registerPositionOf(const Task &task)
{
int blocknumber = m_textEdit->blockCount();
int blocknumber = m_outputWindow->blockCount();
if (blocknumber > MAX_LINECOUNT)
return;
m_taskPositions.insert(task.taskId, blocknumber - 1);
......@@ -181,7 +157,7 @@ bool CompileOutputWindow::knowsPositionOf(const Task &task)
void CompileOutputWindow::showPositionOf(const Task &task)
{
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);
m_textEdit->setTextCursor(newCursor);
m_outputWindow->setTextCursor(newCursor);
}
......@@ -30,6 +30,7 @@
#ifndef COMPILEOUTPUTWINDOW_H
#define COMPILEOUTPUTWINDOW_H
#include "outputwindow.h"
#include <coreplugin/ioutputpane.h>
#include <QtCore/QHash>
......@@ -78,7 +79,7 @@ public:
void showPositionOf(const Task &task);
private:
QPlainTextEdit *m_textEdit;
OutputWindow *m_outputWindow;
QHash<unsigned int, int> m_taskPositions;
ShowOutputTaskHandler * m_handler;
};
......
......@@ -221,6 +221,8 @@ void OutputPane::createNewOutputWindow(RunControl *rc)
}
if (!found) {
OutputWindow *ow = new OutputWindow(m_tabWidget);
ow->setWindowTitle(tr("Application Output Window"));
ow->setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
ow->setFormatter(rc->outputFormatter());
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(ow);
......@@ -376,6 +378,7 @@ bool OutputPane::canNavigate()
OutputWindow::OutputWindow(QWidget *parent)
: QPlainTextEdit(parent)
, m_formatter(0)
, m_enforceNewline(false)
, m_scrollToBottom(false)
, m_linksActive(true)
......@@ -383,8 +386,6 @@ OutputWindow::OutputWindow(QWidget *parent)
{
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
//setCenterOnScroll(false);
setWindowTitle(tr("Application Output Window"));
setWindowIcon(QIcon(":/qt4projectmanager/images/window.png"));
setFrameShape(QFrame::NoFrame);
setMouseTracking(true);
......@@ -433,10 +434,9 @@ OutputWindow::~OutputWindow()
delete m_outputWindowContext;
}
void OutputWindow::mousePressEvent(QMouseEvent *e)
void OutputWindow::mousePressEvent(QMouseEvent * /*e*/)
{
m_mousePressed = true;
QPlainTextEdit::mousePressEvent(e);
}
......@@ -453,7 +453,6 @@ void OutputWindow::mouseReleaseEvent(QMouseEvent *e)
const QString href = anchorAt(e->pos());
if (m_formatter)
m_formatter->handleLink(href);
QPlainTextEdit::mouseReleaseEvent(e);
}
void OutputWindow::mouseMoveEvent(QMouseEvent *e)
......@@ -466,7 +465,6 @@ void OutputWindow::mouseMoveEvent(QMouseEvent *e)
viewport()->setCursor(Qt::IBeamCursor);
else
viewport()->setCursor(Qt::PointingHandCursor);
QPlainTextEdit::mouseMoveEvent(e);
}
OutputFormatter *OutputWindow::formatter() const
......@@ -556,6 +554,28 @@ void OutputWindow::appendMessage(const QString &out, bool isError)
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
{
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
......
......@@ -135,11 +135,19 @@ public:
void appendApplicationOutput(const QString &out, bool onStdErr);
void appendApplicationOutputInline(const QString &out, bool onStdErr);
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 showEvent(QShowEvent *);
void clear()
{
m_enforceNewline = false;
QPlainTextEdit::clear();
}
protected:
bool isScrollbarAtBottom() const;
void scrollToBottom();
......
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