Qt 4.8
qscriptdebugoutputwidget.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSCriptTools module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
44 
45 #include <QtCore/qdebug.h>
46 #include <QtGui/qboxlayout.h>
47 #include <QtGui/qplaintextedit.h>
48 #include <QtGui/qscrollbar.h>
49 
51 
52 namespace {
53 
54 class QScriptDebugOutputWidgetOutputEdit : public QPlainTextEdit
55 {
56 public:
57  QScriptDebugOutputWidgetOutputEdit(QWidget *parent = 0)
58  : QPlainTextEdit(parent)
59  {
60  setReadOnly(true);
61 // setFocusPolicy(Qt::NoFocus);
63  }
64 
65  void scrollToBottom()
66  {
68  bar->setValue(bar->maximum());
69  }
70 
71  int charactersPerLine() const
72  {
73  QFontMetrics fm(font());
74  return width() / fm.maxWidth();
75  }
76 };
77 
78 } // namespace
79 
82 {
84 public:
87 
88  QScriptDebugOutputWidgetOutputEdit *outputEdit;
89 };
90 
92 {
93 }
94 
96 {
97 }
98 
101 {
103  d->outputEdit = new QScriptDebugOutputWidgetOutputEdit();
104  QVBoxLayout *vbox = new QVBoxLayout(this);
105  vbox->setMargin(0);
106  vbox->setSpacing(0);
107  vbox->addWidget(d->outputEdit);
108 
109 #ifndef QT_NO_STYLE_STYLESHEET
110  QString sheet = QString::fromLatin1("font-size: 14px; font-family: \"Monospace\";");
111  setStyleSheet(sheet);
112 #endif
113 }
114 
116 {
117 }
118 
120  QtMsgType type, const QString &text, const QString &fileName,
121  int lineNumber, int columnNumber, const QVariant &/*data*/)
122 {
123  // ### unify with QScriptDebuggerConsoleWidget::message()
125  QString msg;
126  if (!fileName.isEmpty() || (lineNumber != -1)) {
127  if (!fileName.isEmpty())
128  msg.append(fileName);
129  else
130  msg.append(QLatin1String("<noname>"));
131  if (lineNumber != -1) {
132  msg.append(QLatin1Char(':'));
133  msg.append(QString::number(lineNumber));
134  if (columnNumber != -1) {
135  msg.append(QLatin1Char(':'));
136  msg.append(QString::number(columnNumber));
137  }
138  }
139  msg.append(QLatin1String(": "));
140  }
141  msg.append(text);
142  QTextCharFormat oldFmt = d->outputEdit->currentCharFormat();
143  QTextCharFormat fmt(oldFmt);
144  if (type == QtCriticalMsg) {
145  fmt.setForeground(Qt::red);
146  d->outputEdit->setCurrentCharFormat(fmt);
147  }
148  d->outputEdit->appendPlainText(msg);
149  d->outputEdit->setCurrentCharFormat(oldFmt);
150  d->outputEdit->scrollToBottom();
151 }
152 
154 {
156  d->outputEdit->clear();
157 }
158 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QtMsgType
This enum describes the messages that can be sent to a message handler (QtMsgHandler).
Definition: qglobal.h:1881
#define Q_D(Class)
Definition: qglobal.h:2482
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
void setMaximumBlockCount(int maximum)
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QScriptDebugOutputWidget(QWidget *parent=0)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int width() const
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QScriptDebugOutputWidgetOutputEdit * outputEdit
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QString & append(QChar c)
Definition: qstring.cpp:1777
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void setSpacing(int spacing)
Reimplements QLayout::setSpacing().
Definition: qboxlayout.cpp:667
void message(QtMsgType type, const QString &text, const QString &fileName=QString(), int lineNumber=-1, int columnNumber=-1, const QVariant &data=QVariant())
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
const QFont & font() const
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
void setReadOnly(bool ro)
void setStyleSheet(const QString &styleSheet)
Definition: qwidget.cpp:2709
int maximum() const
void setMargin(int)
Definition: qlayout.cpp:464
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define text
Definition: qobjectdefs.h:80