[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtSCriptTools module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qscriptdebuggercodefinderwidget_p.h"
|
---|
| 43 | #include "qscriptdebuggercodefinderwidgetinterface_p_p.h"
|
---|
| 44 |
|
---|
| 45 | #include <QtGui/qboxlayout.h>
|
---|
| 46 | #include <QtGui/qlineedit.h>
|
---|
| 47 | #include <QtGui/qcheckbox.h>
|
---|
| 48 | #include <QtGui/qlabel.h>
|
---|
| 49 | #include <QtGui/qtoolbutton.h>
|
---|
| 50 | #include <QtGui/qevent.h>
|
---|
| 51 | #include <QtCore/qdebug.h>
|
---|
| 52 |
|
---|
| 53 | QT_BEGIN_NAMESPACE
|
---|
| 54 |
|
---|
| 55 | class QScriptDebuggerCodeFinderWidgetPrivate
|
---|
| 56 | : public QScriptDebuggerCodeFinderWidgetInterfacePrivate
|
---|
| 57 | {
|
---|
| 58 | Q_DECLARE_PUBLIC(QScriptDebuggerCodeFinderWidget)
|
---|
| 59 | public:
|
---|
| 60 | QScriptDebuggerCodeFinderWidgetPrivate();
|
---|
| 61 | ~QScriptDebuggerCodeFinderWidgetPrivate();
|
---|
| 62 |
|
---|
| 63 | // private slots
|
---|
| 64 | void _q_updateButtons();
|
---|
| 65 | void _q_onTextChanged(const QString &);
|
---|
| 66 | void _q_next();
|
---|
| 67 | void _q_previous();
|
---|
| 68 |
|
---|
| 69 | int findOptions() const;
|
---|
| 70 |
|
---|
| 71 | QLineEdit *editFind;
|
---|
| 72 | QCheckBox *checkCase;
|
---|
| 73 | QLabel *labelWrapped;
|
---|
| 74 | QToolButton *toolNext;
|
---|
| 75 | QToolButton *toolClose;
|
---|
| 76 | QToolButton *toolPrevious;
|
---|
| 77 | QCheckBox *checkWholeWords;
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | QScriptDebuggerCodeFinderWidgetPrivate::QScriptDebuggerCodeFinderWidgetPrivate()
|
---|
| 81 | {
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | QScriptDebuggerCodeFinderWidgetPrivate::~QScriptDebuggerCodeFinderWidgetPrivate()
|
---|
| 85 | {
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | void QScriptDebuggerCodeFinderWidgetPrivate::_q_updateButtons()
|
---|
| 89 | {
|
---|
| 90 | if (editFind->text().isEmpty()) {
|
---|
| 91 | toolPrevious->setEnabled(false);
|
---|
| 92 | toolNext->setEnabled(false);
|
---|
| 93 | } else {
|
---|
| 94 | toolPrevious->setEnabled(true);
|
---|
| 95 | toolNext->setEnabled(true);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | int QScriptDebuggerCodeFinderWidgetPrivate::findOptions() const
|
---|
| 100 | {
|
---|
| 101 | int flags = 0;
|
---|
| 102 | if (checkCase->isChecked())
|
---|
| 103 | flags |= QTextDocument::FindCaseSensitively;
|
---|
| 104 | if (checkWholeWords->isChecked())
|
---|
| 105 | flags |= QTextDocument::FindWholeWords;
|
---|
| 106 | return flags;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | void QScriptDebuggerCodeFinderWidgetPrivate::_q_onTextChanged(const QString &text)
|
---|
| 110 | {
|
---|
| 111 | emit q_func()->findRequest(text, findOptions() | 0x100);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | void QScriptDebuggerCodeFinderWidgetPrivate::_q_next()
|
---|
| 115 | {
|
---|
| 116 | emit q_func()->findRequest(editFind->text(), findOptions());
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | void QScriptDebuggerCodeFinderWidgetPrivate::_q_previous()
|
---|
| 120 | {
|
---|
| 121 | emit q_func()->findRequest(editFind->text(), findOptions() | QTextDocument::FindBackward);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | QScriptDebuggerCodeFinderWidget::QScriptDebuggerCodeFinderWidget(QWidget *parent)
|
---|
| 125 | : QScriptDebuggerCodeFinderWidgetInterface(
|
---|
| 126 | *new QScriptDebuggerCodeFinderWidgetPrivate, parent, 0)
|
---|
| 127 | {
|
---|
| 128 | Q_D(QScriptDebuggerCodeFinderWidget);
|
---|
| 129 | QString system = QLatin1String("win");
|
---|
| 130 | QHBoxLayout *hboxLayout = new QHBoxLayout(this);
|
---|
| 131 | #ifdef Q_OS_MAC
|
---|
| 132 | system = QLatin1String("mac");
|
---|
| 133 | #else
|
---|
| 134 | hboxLayout->setSpacing(6);
|
---|
| 135 | hboxLayout->setMargin(0);
|
---|
| 136 | #endif
|
---|
| 137 |
|
---|
| 138 | d->toolClose = new QToolButton(this);
|
---|
| 139 | d->toolClose->setIcon(QIcon(QString::fromUtf8(":/qt/scripttools/debugging/images/%1/closetab.png").arg(system)));
|
---|
| 140 | d->toolClose->setAutoRaise(true);
|
---|
[561] | 141 | d->toolClose->setText(tr("Close"));
|
---|
[2] | 142 | hboxLayout->addWidget(d->toolClose);
|
---|
| 143 |
|
---|
| 144 | d->editFind = new QLineEdit(this);
|
---|
| 145 | d->editFind->setMinimumSize(QSize(150, 0));
|
---|
[561] | 146 | connect(d->editFind, SIGNAL(textChanged(QString)),
|
---|
[2] | 147 | this, SLOT(_q_updateButtons()));
|
---|
| 148 | connect(d->editFind, SIGNAL(returnPressed()),
|
---|
| 149 | this, SLOT(_q_next()));
|
---|
| 150 | hboxLayout->addWidget(d->editFind);
|
---|
| 151 |
|
---|
| 152 | d->toolPrevious = new QToolButton(this);
|
---|
| 153 | d->toolPrevious->setAutoRaise(true);
|
---|
| 154 | d->toolPrevious->setText(tr("Previous"));
|
---|
| 155 | d->toolPrevious->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
---|
| 156 | d->toolPrevious->setIcon(QIcon(QString::fromUtf8(":/qt/scripttools/debugging/images/%1/previous.png").arg(system)));
|
---|
| 157 | hboxLayout->addWidget(d->toolPrevious);
|
---|
| 158 |
|
---|
| 159 | d->toolNext = new QToolButton(this);
|
---|
| 160 | d->toolNext->setAutoRaise(true);
|
---|
| 161 | d->toolNext->setText(tr("Next"));
|
---|
| 162 | d->toolNext->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
---|
| 163 | d->toolNext->setIcon(QIcon(QString::fromUtf8(":/qt/scripttools/debugging/images/%1/next.png").arg(system)));
|
---|
| 164 | hboxLayout->addWidget(d->toolNext);
|
---|
| 165 |
|
---|
| 166 | d->checkCase = new QCheckBox(tr("Case Sensitive"), this);
|
---|
| 167 | hboxLayout->addWidget(d->checkCase);
|
---|
| 168 |
|
---|
| 169 | d->checkWholeWords = new QCheckBox(tr("Whole words"), this);
|
---|
| 170 | hboxLayout->addWidget(d->checkWholeWords);
|
---|
| 171 |
|
---|
| 172 | d->labelWrapped = new QLabel(this);
|
---|
| 173 | d->labelWrapped->setMinimumSize(QSize(0, 20));
|
---|
| 174 | d->labelWrapped->setMaximumSize(QSize(115, 20));
|
---|
| 175 | d->labelWrapped->setTextFormat(Qt::RichText);
|
---|
| 176 | d->labelWrapped->setScaledContents(true);
|
---|
| 177 | d->labelWrapped->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
|
---|
| 178 | d->labelWrapped->setText(tr("<img src=\":/qt/scripttools/debugging/images/wrap.png\"> Search wrapped"));
|
---|
| 179 | hboxLayout->addWidget(d->labelWrapped);
|
---|
| 180 |
|
---|
| 181 | QSpacerItem *spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
---|
| 182 | hboxLayout->addItem(spacerItem);
|
---|
| 183 | setMinimumWidth(minimumSizeHint().width());
|
---|
| 184 | d->labelWrapped->hide();
|
---|
| 185 |
|
---|
| 186 | d->_q_updateButtons();
|
---|
| 187 |
|
---|
| 188 | setFocusProxy(d->editFind);
|
---|
| 189 | QObject::connect(d->toolClose, SIGNAL(clicked()), this, SLOT(hide()));
|
---|
| 190 | QObject::connect(d->editFind, SIGNAL(textChanged(QString)),
|
---|
| 191 | this, SLOT(_q_onTextChanged(QString)));
|
---|
| 192 | QObject::connect(d->toolNext, SIGNAL(clicked()), this, SLOT(_q_next()));
|
---|
| 193 | QObject::connect(d->toolPrevious, SIGNAL(clicked()), this, SLOT(_q_previous()));
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | QScriptDebuggerCodeFinderWidget::~QScriptDebuggerCodeFinderWidget()
|
---|
| 197 | {
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | int QScriptDebuggerCodeFinderWidget::findOptions() const
|
---|
| 201 | {
|
---|
| 202 | Q_D(const QScriptDebuggerCodeFinderWidget);
|
---|
| 203 | return d->findOptions();
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | QString QScriptDebuggerCodeFinderWidget::text() const
|
---|
| 207 | {
|
---|
| 208 | Q_D(const QScriptDebuggerCodeFinderWidget);
|
---|
| 209 | return d->editFind->text();
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | void QScriptDebuggerCodeFinderWidget::setText(const QString &text)
|
---|
| 213 | {
|
---|
| 214 | Q_D(const QScriptDebuggerCodeFinderWidget);
|
---|
| 215 | d->editFind->setText(text);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | void QScriptDebuggerCodeFinderWidget::setOK(bool ok)
|
---|
| 219 | {
|
---|
| 220 | Q_D(QScriptDebuggerCodeFinderWidget);
|
---|
| 221 | QPalette p = d->editFind->palette();
|
---|
| 222 | QColor c;
|
---|
| 223 | if (ok)
|
---|
| 224 | c = Qt::white;
|
---|
| 225 | else
|
---|
| 226 | c = QColor(255, 102, 102);
|
---|
| 227 | p.setColor(QPalette::Active, QPalette::Base, c);
|
---|
| 228 | d->editFind->setPalette(p);
|
---|
| 229 | if (!ok)
|
---|
| 230 | d->labelWrapped->hide();
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | void QScriptDebuggerCodeFinderWidget::setWrapped(bool wrapped)
|
---|
| 234 | {
|
---|
| 235 | Q_D(QScriptDebuggerCodeFinderWidget);
|
---|
| 236 | d->labelWrapped->setVisible(wrapped);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | void QScriptDebuggerCodeFinderWidget::keyPressEvent(QKeyEvent *e)
|
---|
| 240 | {
|
---|
| 241 | if (e->key() == Qt::Key_Escape)
|
---|
| 242 | hide();
|
---|
| 243 | else
|
---|
| 244 | QScriptDebuggerCodeFinderWidgetInterface::keyPressEvent(e);
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | QT_END_NAMESPACE
|
---|
| 248 |
|
---|
| 249 | #include "moc_qscriptdebuggercodefinderwidget_p.cpp"
|
---|