Qt 4.8
qscripterrorlogwidget.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/qdatetime.h>
46 #include <QtGui/qboxlayout.h>
47 #include <QtGui/qtextedit.h>
48 #include <QtGui/qscrollbar.h>
49 #include <QtCore/qdebug.h>
50 
52 
53 namespace {
54 
55 class QScriptErrorLogWidgetOutputEdit : public QTextEdit
56 {
57 public:
58  QScriptErrorLogWidgetOutputEdit(QWidget *parent = 0)
59  : QTextEdit(parent)
60  {
61  setReadOnly(true);
62 // setFocusPolicy(Qt::NoFocus);
64  }
65 
66  void scrollToBottom()
67  {
69  bar->setValue(bar->maximum());
70  }
71 };
72 
73 } // namespace
74 
77 {
79 public:
82 
83  QScriptErrorLogWidgetOutputEdit *outputEdit;
84 };
85 
87 {
88 }
89 
91 {
92 }
93 
96 {
98  d->outputEdit = new QScriptErrorLogWidgetOutputEdit();
99  QVBoxLayout *vbox = new QVBoxLayout(this);
100  vbox->setMargin(0);
101  vbox->setSpacing(0);
102  vbox->addWidget(d->outputEdit);
103 
104 // QString sheet = QString::fromLatin1("font-size: 14px; font-family: \"Monospace\";");
105 // setStyleSheet(sheet);
106 }
107 
109 {
110 }
111 
113  QtMsgType type, const QString &text, const QString &fileName,
114  int lineNumber, int columnNumber, const QVariant &/*data*/)
115 {
116  // ### we need the error message rather than Error.toString()
117  Q_UNUSED(type);
118  Q_UNUSED(fileName);
119  Q_UNUSED(lineNumber);
120  Q_UNUSED(columnNumber);
122  QString html;
123  html.append(QString::fromLatin1("<b>%0</b> %1<br>")
124  .arg(QDateTime::currentDateTime().toString()).arg(Qt::escape(text)));
125  d->outputEdit->insertHtml(html);
126  d->outputEdit->scrollToBottom();
127 }
128 
130 {
132  d->outputEdit->clear();
133 }
134 
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
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QScriptErrorLogWidget(QWidget *parent=0)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QScriptErrorLogWidgetOutputEdit * outputEdit
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
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...
static QString toString(Register *reg, int type, bool *ok=0)
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
void setMaximumBlockCount(int maximum)
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
#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
QTextDocument * document() const
Returns a pointer to the underlying document.
Definition: qtextedit.cpp:804
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
void message(QtMsgType type, const QString &text, const QString &fileName=QString(), int lineNumber=-1, int columnNumber=-1, const QVariant &data=QVariant())
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
int maximum() const
void setMargin(int)
Definition: qlayout.cpp:464
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
void setReadOnly(bool ro)
Definition: qtextedit.cpp:2133
The QTextEdit class provides a widget that is used to edit and display both plain and rich text...
Definition: qtextedit.h:70
#define text
Definition: qobjectdefs.h:80