48 #include <QtCore/qdebug.h> 49 #include <QtGui/qplaintextedit.h> 50 #include <QtGui/qlabel.h> 51 #include <QtGui/qlineedit.h> 52 #include <QtGui/qlistview.h> 53 #include <QtGui/qscrollbar.h> 54 #include <QtGui/qboxlayout.h> 55 #include <QtGui/qcompleter.h> 61 class PromptLabel :
public QLabel 64 PromptLabel(
QWidget *parent = 0)
72 #ifndef QT_NO_STYLE_STYLESHEET 94 class CommandLine :
public QWidget 98 CommandLine(
QWidget *parent = 0)
101 promptLabel =
new PromptLabel();
102 inputEdit =
new InputEdit();
110 this,
SLOT(onReturnPressed()));
114 setFocusProxy(inputEdit);
119 return promptLabel->text();
121 void setPrompt(
const QString &prompt)
123 promptLabel->setText(prompt);
128 return inputEdit->text();
130 void setInput(
const QString &input)
132 inputEdit->setText(input);
135 int cursorPosition()
const 137 return inputEdit->cursorPosition();
139 void setCursorPosition(
int position)
141 inputEdit->setCursorPosition(position);
150 void lineEntered(
const QString &contents);
151 void lineEdited(
const QString &contents);
154 void onReturnPressed()
158 emit lineEntered(text);
162 PromptLabel *promptLabel;
163 InputEdit *inputEdit;
166 class QScriptDebuggerConsoleWidgetOutputEdit :
public QPlainTextEdit 169 QScriptDebuggerConsoleWidgetOutputEdit(
QWidget *parent = 0)
177 setMaximumBlockCount(2500);
180 void scrollToBottom()
186 int charactersPerLine()
const 189 return width() / fm.maxWidth();
204 void _q_onLineEntered(
const QString &contents);
205 void _q_onLineEdited(
const QString &contents);
206 void _q_onCompletionTaskFinished();
226 outputEdit->appendPlainText(
QString::fromLatin1(
"%0 %1").arg(commandLine->prompt()).arg(contents));
227 outputEdit->scrollToBottom();
230 emit q->lineEntered(contents);
235 if (historyIndex != -1) {
238 historian->changeHistoryAt(historyIndex, contents);
254 for (
int i = lst.
size() - 2; (i >= 0) && !result.
isEmpty(); --i) {
259 result = result.
left(j);
271 QString tmp = commandLine->input();
274 commandLine->setInput(tmp);
282 if (!lcp.isEmpty()) {
283 QString tmp = commandLine->input();
285 commandLine->setInput(tmp);
290 .arg(commandLine->prompt()).arg(commandLine->input()));
296 int columns =
qMax(1, outputEdit->charactersPerLine() / (maxLength + tab));
300 if ((i % columns) == 0) {
301 outputEdit->appendPlainText(msg);
304 int pad = maxLength + tab - (msg.
length() % (maxLength + tab));
311 outputEdit->appendPlainText(msg);
312 outputEdit->scrollToBottom();
321 d->commandLine =
new CommandLine();
323 d->outputEdit =
new QScriptDebuggerConsoleWidgetOutputEdit();
334 "font-family: \"Monospace\"");
336 #ifndef QT_NO_STYLE_STYLESHEET 353 int lineNumber,
int columnNumber,
const QVariant &)
357 if (!fileName.
isEmpty() || (lineNumber != -1)) {
362 if (lineNumber != -1) {
365 if (columnNumber != -1) {
377 d->outputEdit->setCurrentCharFormat(fmt);
379 d->outputEdit->appendPlainText(msg);
380 d->outputEdit->setCurrentCharFormat(oldFmt);
381 d->outputEdit->scrollToBottom();
390 d->commandLine->setPrompt(prompt);
396 d->outputEdit->clear();
403 if (
d->historyIndex+1 ==
d->historian->historyCount())
405 QString cmd =
d->historian->historyAt(++
d->historyIndex);
406 d->commandLine->setInput(cmd);
408 if (
d->historyIndex == -1) {
410 }
else if (
d->historyIndex == 0) {
411 d->commandLine->setInput(
d->newInput);
414 QString cmd =
d->historian->historyAt(--
d->historyIndex);
415 d->commandLine->setInput(cmd);
419 task =
d->completionProvider->createCompletionTask(
420 d->commandLine->input(),
d->commandLine->cursorPosition(),
424 this,
SLOT(_q_onCompletionTaskFinished()));
434 if (
d->outputEdit->hasFocus())
442 #include "qscriptdebuggerconsolewidget.moc" 444 #include "moc_qscriptdebuggerconsolewidget_p.cpp" static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
T qobject_cast(QObject *object)
The QKeyEvent class describes a key event.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
The QFontMetrics class provides font metrics information.
#define QT_END_NAMESPACE
This macro expands to.
const QChar at(int i) const
Returns the character at the given index position in the string.
int length() const
Returns the number of characters in this string.
QString resultAt(int index) const
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
QSize sizeHint() const
em>Reimplemented Function
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
QtMsgType
This enum describes the messages that can be sent to a message handler (QtMsgHandler).
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...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
int key() const
Returns the code of the key that was pressed or released.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
void setFrameShape(Shape)
void qSort(RandomAccessIterator start, RandomAccessIterator end)
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
#define Q_DECLARE_PUBLIC(Class)
QString & append(QChar c)
void clear()
Clears the contents of the string and makes it empty.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
void setSpacing(int spacing)
Reimplements QLayout::setSpacing().
T & last()
Returns a reference to the last item in the list.
int size() const
Returns the number of items in the list.
The QLabel widget provides a text or image display.
The QHBoxLayout class lines up widgets horizontally.
The QLineEdit widget is a one-line text editor.
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
The QSize class defines the size of a two-dimensional object using integer point precision.
The QVBoxLayout class lines up widgets vertically.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
QString & insert(int i, QChar c)
static QString fileName(const QString &fileUrl)
void setAlignment(Qt::Alignment)
Without this function, a call to e.
void deleteLater()
Schedules this object for deletion.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.