OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / compileoutputwindow.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "compileoutputwindow.h"
34 #include "buildmanager.h"
35 #include "showoutputtaskhandler.h"
36 #include "task.h"
37
38 #include <find/basetextfind.h>
39 #include <aggregation/aggregate.h>
40 #include <extensionsystem/pluginmanager.h>
41 #include <qt4projectmanager/qt4projectmanagerconstants.h>
42
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>
51
52 using namespace ProjectExplorer;
53 using namespace ProjectExplorer::Internal;
54
55 namespace {
56 const int MAX_LINECOUNT = 50000;
57 }
58
59 CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
60 {
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);
66
67     Aggregation::Aggregate *agg = new Aggregation::Aggregate;
68     agg->add(m_outputWindow);
69     agg->add(new Find::BaseTextFind(m_outputWindow));
70
71     qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
72
73     m_handler = new ShowOutputTaskHandler(this);
74     ExtensionSystem::PluginManager::instance()->addObject(m_handler);
75 }
76
77 CompileOutputWindow::~CompileOutputWindow()
78 {
79     ExtensionSystem::PluginManager::instance()->removeObject(m_handler);
80     delete m_handler;
81 }
82
83 bool CompileOutputWindow::hasFocus()
84 {
85     return m_outputWindow->hasFocus();
86 }
87
88 bool CompileOutputWindow::canFocus()
89 {
90     return true;
91 }
92
93 void CompileOutputWindow::setFocus()
94 {
95     m_outputWindow->setFocus();
96 }
97
98 QWidget *CompileOutputWindow::outputWidget(QWidget *)
99 {
100     return m_outputWindow;
101 }
102
103 static QColor mix_colors(QColor a, QColor b)
104 {
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);
107 }
108
109 void CompileOutputWindow::appendText(const QString &text, ProjectExplorer::BuildStep::OutputFormat format)
110 {
111     QPalette p = m_outputWindow->palette();
112     QTextCharFormat textFormat;
113     switch (format) {
114     case BuildStep::NormalOutput:
115         textFormat.setForeground(p.color(QPalette::Text));
116         textFormat.setFontWeight(QFont::Normal);
117         break;
118     case BuildStep::ErrorOutput:
119         textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
120         textFormat.setFontWeight(QFont::Normal);
121         break;
122     case BuildStep::MessageOutput:
123         textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::blue)));
124         break;
125     case BuildStep::ErrorMessageOutput:
126         textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
127         textFormat.setFontWeight(QFont::Bold);
128         break;
129
130     }
131
132     m_outputWindow->appendText(text, textFormat, MAX_LINECOUNT);
133 }
134
135 void CompileOutputWindow::clearContents()
136 {
137     m_outputWindow->clear();
138     m_taskPositions.clear();
139 }
140
141 void CompileOutputWindow::visibilityChanged(bool)
142 {
143
144 }
145
146 int CompileOutputWindow::priorityInStatusBar() const
147 {
148     return 50;
149 }
150
151 bool CompileOutputWindow::canNext()
152 {
153     return false;
154 }
155
156 bool CompileOutputWindow::canPrevious()
157 {
158     return false;
159 }
160
161 void CompileOutputWindow::goToNext()
162 {
163
164 }
165
166 void CompileOutputWindow::goToPrev()
167 {
168
169 }
170
171 bool CompileOutputWindow::canNavigate()
172 {
173     return false;
174 }
175
176 void CompileOutputWindow::registerPositionOf(const Task &task)
177 {
178     int blocknumber = m_outputWindow->blockCount();
179     if (blocknumber > MAX_LINECOUNT)
180         return;
181     m_taskPositions.insert(task.taskId, blocknumber);
182 }
183
184 bool CompileOutputWindow::knowsPositionOf(const Task &task)
185 {
186     return (m_taskPositions.contains(task.taskId));
187 }
188
189 void CompileOutputWindow::showPositionOf(const Task &task)
190 {
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);
195 }