1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "compileoutputwindow.h"
34 #include "buildmanager.h"
35 #include "showoutputtaskhandler.h"
38 #include <find/basetextfind.h>
39 #include <aggregation/aggregate.h>
40 #include <extensionsystem/pluginmanager.h>
41 #include <qt4projectmanager/qt4projectmanagerconstants.h>
43 #include <QtGui/QKeyEvent>
44 #include <QtGui/QIcon>
45 #include <QtGui/QTextCharFormat>
46 #include <QtGui/QTextBlock>
47 #include <QtGui/QTextCursor>
48 #include <QtGui/QTextEdit>
49 #include <QtGui/QScrollBar>
50 #include <QtGui/QPlainTextEdit>
52 using namespace ProjectExplorer;
53 using namespace ProjectExplorer::Internal;
56 const int MAX_LINECOUNT = 50000;
59 CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
61 m_outputWindow = new OutputWindow();
62 m_outputWindow->setWindowTitle(tr("Compile Output"));
63 m_outputWindow->setWindowIcon(QIcon(QLatin1String(Qt4ProjectManager::Constants::ICON_WINDOW)));
64 m_outputWindow->setReadOnly(true);
65 m_outputWindow->setUndoRedoEnabled(false);
67 Aggregation::Aggregate *agg = new Aggregation::Aggregate;
68 agg->add(m_outputWindow);
69 agg->add(new Find::BaseTextFind(m_outputWindow));
71 qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
73 m_handler = new ShowOutputTaskHandler(this);
74 ExtensionSystem::PluginManager::instance()->addObject(m_handler);
77 CompileOutputWindow::~CompileOutputWindow()
79 ExtensionSystem::PluginManager::instance()->removeObject(m_handler);
83 bool CompileOutputWindow::hasFocus()
85 return m_outputWindow->hasFocus();
88 bool CompileOutputWindow::canFocus()
93 void CompileOutputWindow::setFocus()
95 m_outputWindow->setFocus();
98 QWidget *CompileOutputWindow::outputWidget(QWidget *)
100 return m_outputWindow;
103 static QColor mix_colors(QColor a, QColor b)
105 return QColor((a.red() + 2 * b.red()) / 3, (a.green() + 2 * b.green()) / 3,
106 (a.blue() + 2* b.blue()) / 3, (a.alpha() + 2 * b.alpha()) / 3);
109 void CompileOutputWindow::appendText(const QString &text, ProjectExplorer::BuildStep::OutputFormat format)
111 QPalette p = m_outputWindow->palette();
112 QTextCharFormat textFormat;
114 case BuildStep::NormalOutput:
115 textFormat.setForeground(p.color(QPalette::Text));
116 textFormat.setFontWeight(QFont::Normal);
118 case BuildStep::ErrorOutput:
119 textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
120 textFormat.setFontWeight(QFont::Normal);
122 case BuildStep::MessageOutput:
123 textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::blue)));
125 case BuildStep::ErrorMessageOutput:
126 textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
127 textFormat.setFontWeight(QFont::Bold);
132 m_outputWindow->appendText(text, textFormat, MAX_LINECOUNT);
135 void CompileOutputWindow::clearContents()
137 m_outputWindow->clear();
138 m_taskPositions.clear();
141 void CompileOutputWindow::visibilityChanged(bool)
146 int CompileOutputWindow::priorityInStatusBar() const
151 bool CompileOutputWindow::canNext()
156 bool CompileOutputWindow::canPrevious()
161 void CompileOutputWindow::goToNext()
166 void CompileOutputWindow::goToPrev()
171 bool CompileOutputWindow::canNavigate()
176 void CompileOutputWindow::registerPositionOf(const Task &task)
178 int blocknumber = m_outputWindow->blockCount();
179 if (blocknumber > MAX_LINECOUNT)
181 m_taskPositions.insert(task.taskId, blocknumber);
184 bool CompileOutputWindow::knowsPositionOf(const Task &task)
186 return (m_taskPositions.contains(task.taskId));
189 void CompileOutputWindow::showPositionOf(const Task &task)
191 int position = m_taskPositions.value(task.taskId);
192 QTextCursor newCursor(m_outputWindow->document()->findBlockByNumber(position));
193 newCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
194 m_outputWindow->setTextCursor(newCursor);