compileoutputwindow.cpp 5.16 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
#include "compileoutputwindow.h"
#include "buildmanager.h"
Tobias Hunger's avatar
Tobias Hunger committed
32
33
#include "showoutputtaskhandler.h"
#include "task.h"
con's avatar
con committed
34
35
36

#include <find/basetextfind.h>
#include <aggregation/aggregate.h>
Tobias Hunger's avatar
Tobias Hunger committed
37
#include <extensionsystem/pluginmanager.h>
38
#include <qt4projectmanager/qt4projectmanagerconstants.h>
con's avatar
con committed
39
40
41

#include <QtGui/QKeyEvent>
#include <QtGui/QIcon>
42
#include <QtGui/QTextCharFormat>
Tobias Hunger's avatar
Tobias Hunger committed
43
44
#include <QtGui/QTextBlock>
#include <QtGui/QTextCursor>
con's avatar
con committed
45
#include <QtGui/QTextEdit>
46
#include <QtGui/QScrollBar>
47
#include <QtGui/QPlainTextEdit>
con's avatar
con committed
48
49
50
51

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

Tobias Hunger's avatar
Tobias Hunger committed
52
53
54
55
namespace {
const int MAX_LINECOUNT = 10000;
}

con's avatar
con committed
56
57
CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
{
58
59
    m_outputWindow = new OutputWindow();
    m_outputWindow->setWindowTitle(tr("Compile Output"));
60
    m_outputWindow->setWindowIcon(QIcon(QLatin1String(Qt4ProjectManager::Constants::ICON_WINDOW)));
61
62
    m_outputWindow->setReadOnly(true);

con's avatar
con committed
63
    Aggregation::Aggregate *agg = new Aggregation::Aggregate;
64
65
    agg->add(m_outputWindow);
    agg->add(new Find::BaseTextFind(m_outputWindow));
66
67

    qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
Tobias Hunger's avatar
Tobias Hunger committed
68
69
70
71
72
73
74
75
76

    m_handler = new ShowOutputTaskHandler(this);
    ExtensionSystem::PluginManager::instance()->addObject(m_handler);
}

CompileOutputWindow::~CompileOutputWindow()
{
    ExtensionSystem::PluginManager::instance()->removeObject(m_handler);
    delete m_handler;
con's avatar
con committed
77
78
79
80
}

bool CompileOutputWindow::hasFocus()
{
81
    return m_outputWindow->hasFocus();
con's avatar
con committed
82
83
84
85
86
87
88
89
90
}

bool CompileOutputWindow::canFocus()
{
    return true;
}

void CompileOutputWindow::setFocus()
{
91
    m_outputWindow->setFocus();
con's avatar
con committed
92
93
94
95
}

QWidget *CompileOutputWindow::outputWidget(QWidget *)
{
96
    return m_outputWindow;
con's avatar
con committed
97
98
}

99
static QColor mix_colors(QColor a, QColor b)
con's avatar
con committed
100
{
101
102
    return QColor((a.red() + 2 * b.red()) / 3, (a.green() + 2 * b.green()) / 3,
                  (a.blue() + 2* b.blue()) / 3, (a.alpha() + 2 * b.alpha()) / 3);
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
}

void CompileOutputWindow::appendText(const QString &text, ProjectExplorer::BuildStep::OutputFormat format)
{
    QPalette p = m_outputWindow->palette();
    QTextCharFormat textFormat;
    switch (format) {
    case BuildStep::NormalOutput:
        textFormat.setForeground(p.color(QPalette::Text));
        textFormat.setFontWeight(QFont::Normal);
        break;
    case BuildStep::ErrorOutput:
        textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
        textFormat.setFontWeight(QFont::Normal);
        break;
    case BuildStep::MessageOutput:
        textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::blue)));
        break;
    case BuildStep::ErrorMessageOutput:
        textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
        textFormat.setFontWeight(QFont::Bold);
        break;

    }

    m_outputWindow->appendText(text, textFormat, MAX_LINECOUNT);
con's avatar
con committed
129
130
131
132
}

void CompileOutputWindow::clearContents()
{
133
    m_outputWindow->clear();
Tobias Hunger's avatar
Tobias Hunger committed
134
    m_taskPositions.clear();
con's avatar
con committed
135
136
}

137
void CompileOutputWindow::visibilityChanged(bool)
con's avatar
con committed
138
{
139

con's avatar
con committed
140
141
142
143
144
145
}

int CompileOutputWindow::priorityInStatusBar() const
{
    return 50;
}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

bool CompileOutputWindow::canNext()
{
    return false;
}

bool CompileOutputWindow::canPrevious()
{
    return false;
}

void CompileOutputWindow::goToNext()
{

}

void CompileOutputWindow::goToPrev()
{

}

bool CompileOutputWindow::canNavigate()
{
    return false;
}
Tobias Hunger's avatar
Tobias Hunger committed
171
172
173

void CompileOutputWindow::registerPositionOf(const Task &task)
{
174
    int blocknumber = m_outputWindow->blockCount();
Tobias Hunger's avatar
Tobias Hunger committed
175
176
    if (blocknumber > MAX_LINECOUNT)
        return;
177
    m_taskPositions.insert(task.taskId, blocknumber);
Tobias Hunger's avatar
Tobias Hunger committed
178
179
180
181
182
183
184
185
186
187
}

bool CompileOutputWindow::knowsPositionOf(const Task &task)
{
    return (m_taskPositions.contains(task.taskId));
}

void CompileOutputWindow::showPositionOf(const Task &task)
{
    int position = m_taskPositions.value(task.taskId);
188
    QTextCursor newCursor(m_outputWindow->document()->findBlockByNumber(position));
Tobias Hunger's avatar
Tobias Hunger committed
189
    newCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
190
    m_outputWindow->setTextCursor(newCursor);
Tobias Hunger's avatar
Tobias Hunger committed
191
}