outputwindow.h 5.19 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 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
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
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
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
31
**
32
**************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34 35 36
#ifndef OUTPUTWINDOW_H
#define OUTPUTWINDOW_H

37
#include "outputformat.h"
con's avatar
con committed
38 39 40
#include <coreplugin/ioutputpane.h>

#include <QtGui/QPlainTextEdit>
41
#include <QtGui/QIcon>
con's avatar
con committed
42 43 44

QT_BEGIN_NAMESPACE
class QTabWidget;
45 46
class QToolButton;
class QAction;
con's avatar
con committed
47 48
QT_END_NAMESPACE

49 50 51 52
namespace Core {
    class BaseContext;
}

con's avatar
con committed
53
namespace ProjectExplorer {
54
class OutputFormatter;
con's avatar
con committed
55
class RunControl;
dt's avatar
dt committed
56
class Project;
con's avatar
con committed
57

58 59 60 61
namespace Constants {
    const char * const C_APP_OUTPUT = "Application Output";
}

con's avatar
con committed
62 63 64 65
namespace Internal {

class OutputWindow;

66 67
struct OutputPanePrivate;

con's avatar
con committed
68 69 70 71 72
class OutputPane : public Core::IOutputPane
{
    Q_OBJECT

public:
73 74 75 76 77
    enum CloseTabMode {
        CloseTabNoPrompt,
        CloseTabWithPrompt
    };

hjk's avatar
hjk committed
78
    OutputPane();
79
    virtual ~OutputPane();
con's avatar
con committed
80 81

    QWidget *outputWidget(QWidget *);
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
82
    QList<QWidget*> toolBarWidgets() const;
83
    QString displayName() const;
con's avatar
con committed
84 85 86 87 88 89 90
    int priorityInStatusBar() const;
    void clearContents();
    void visibilityChanged(bool);
    bool canFocus();
    bool hasFocus();
    void setFocus();

91 92 93 94 95 96
    bool canNext();
    bool canPrevious();
    void goToNext();
    void goToPrev();
    bool canNavigate();

97
    void createNewOutputWindow(RunControl *rc);
98
    void showTabFor(RunControl *rc);
99

100
    bool aboutToClose() const;
101
    bool closeTabs(CloseTabMode mode);
102 103 104 105

signals:
     void allRunControlsFinished();

con's avatar
con committed
106
public slots:
107
    // ApplicationOutput specifics
con's avatar
con committed
108 109
    void projectRemoved();

110 111
    void appendMessage(ProjectExplorer::RunControl *rc, const QString &out,
                       ProjectExplorer::OutputFormat format);
112

con's avatar
con committed
113 114 115
private slots:
    void reRunRunControl();
    void stopRunControl();
dt's avatar
dt committed
116
    bool closeTab(int index);
con's avatar
con committed
117 118 119 120
    void tabChanged(int);
    void runControlStarted();
    void runControlFinished();

dt's avatar
dt committed
121 122
    void aboutToUnloadSession();

con's avatar
con committed
123
private:
124 125 126 127 128 129 130 131 132 133
    struct RunControlTab {
        explicit RunControlTab(RunControl *runControl = 0,
                               OutputWindow *window = 0);
        RunControl* runControl;
        OutputWindow *window;
        // Is the run control stopping asynchronously, close the tab once it finishes
        bool asyncClosing;
    };

    bool isRunning() const;
134 135
    bool closeTab(int index, CloseTabMode cm);
    bool optionallyPromptToStop(RunControl *runControl);
136 137 138 139 140 141

    int indexOf(const RunControl *) const;
    int indexOf(const QWidget *outputWindow) const;
    int currentIndex() const;
    RunControl *currentRunControl() const;
    int tabWidgetIndexOf(int runControlIndex) const;
con's avatar
con committed
142 143 144

    QWidget *m_mainWidget;
    QTabWidget *m_tabWidget;
145
    QList<RunControlTab> m_runControlTabs;
146
    QAction *m_stopAction;
con's avatar
con committed
147 148 149 150 151 152 153 154
    QToolButton *m_reRunButton;
    QToolButton *m_stopButton;
};


class OutputWindow : public QPlainTextEdit
{
    Q_OBJECT
155

con's avatar
con committed
156 157 158 159
public:
    OutputWindow(QWidget *parent = 0);
    ~OutputWindow();

160 161 162
    OutputFormatter* formatter() const;
    void setFormatter(OutputFormatter *formatter);

163
    void appendMessage(const QString &out, OutputFormat format);
164 165
    /// appends a \p text using \p format without using formater
    void appendText(const QString &text, const QTextCharFormat &format, int maxLineCount);
166

167
    void grayOutOldContent();
168

169 170
    void showEvent(QShowEvent *);

171 172
    void clear();
    void handleOldOutput();
173

174 175
    void scrollToBottom();

176
protected:
177 178
    bool isScrollbarAtBottom() const;

dt's avatar
dt committed
179 180 181
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseReleaseEvent(QMouseEvent *e);
    virtual void mouseMoveEvent(QMouseEvent *e);
182 183
    virtual void resizeEvent(QResizeEvent *e);
    virtual void keyPressEvent(QKeyEvent *ev);
dt's avatar
dt committed
184

185 186 187
private slots:
    void updateWordWrapMode();

188 189
private:
    void enableUndoRedo();
190
    QString doNewlineEnfocement(const QString &out);
191 192 193

    Core::BaseContext *m_outputWindowContext;
    OutputFormatter *m_formatter;
194

195
    bool m_enforceNewline;
196
    bool m_scrollToBottom;
dt's avatar
dt committed
197 198
    bool m_linksActive;
    bool m_mousePressed;
con's avatar
con committed
199 200
};

hjk's avatar
hjk committed
201 202
} // namespace Internal
} // namespace ProjectExplorer
con's avatar
con committed
203

hjk's avatar
hjk committed
204
#endif // OUTPUTWINDOW_H