Fixing the autotest for other platforms, hopefully...
[qt-netbsd.git] / src / scripttools / debugging / qscriptdebuggercodefinderwidget.cpp
blob5ef5a0c9aa9be884deda8a8f603e26ac487dbb31
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtSCriptTools module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "qscriptdebuggercodefinderwidget_p.h"
43 #include "qscriptdebuggercodefinderwidgetinterface_p_p.h"
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>
53 QT_BEGIN_NAMESPACE
55 class QScriptDebuggerCodeFinderWidgetPrivate
56 : public QScriptDebuggerCodeFinderWidgetInterfacePrivate
58 Q_DECLARE_PUBLIC(QScriptDebuggerCodeFinderWidget)
59 public:
60 QScriptDebuggerCodeFinderWidgetPrivate();
61 ~QScriptDebuggerCodeFinderWidgetPrivate();
63 // private slots
64 void _q_updateButtons();
65 void _q_onTextChanged(const QString &);
66 void _q_next();
67 void _q_previous();
69 int findOptions() const;
71 QLineEdit *editFind;
72 QCheckBox *checkCase;
73 QLabel *labelWrapped;
74 QToolButton *toolNext;
75 QToolButton *toolClose;
76 QToolButton *toolPrevious;
77 QCheckBox *checkWholeWords;
80 QScriptDebuggerCodeFinderWidgetPrivate::QScriptDebuggerCodeFinderWidgetPrivate()
84 QScriptDebuggerCodeFinderWidgetPrivate::~QScriptDebuggerCodeFinderWidgetPrivate()
88 void QScriptDebuggerCodeFinderWidgetPrivate::_q_updateButtons()
90 if (editFind->text().isEmpty()) {
91 toolPrevious->setEnabled(false);
92 toolNext->setEnabled(false);
93 } else {
94 toolPrevious->setEnabled(true);
95 toolNext->setEnabled(true);
99 int QScriptDebuggerCodeFinderWidgetPrivate::findOptions() const
101 int flags = 0;
102 if (checkCase->isChecked())
103 flags |= QTextDocument::FindCaseSensitively;
104 if (checkWholeWords->isChecked())
105 flags |= QTextDocument::FindWholeWords;
106 return flags;
109 void QScriptDebuggerCodeFinderWidgetPrivate::_q_onTextChanged(const QString &text)
111 emit q_func()->findRequest(text, findOptions() | 0x100);
114 void QScriptDebuggerCodeFinderWidgetPrivate::_q_next()
116 emit q_func()->findRequest(editFind->text(), findOptions());
119 void QScriptDebuggerCodeFinderWidgetPrivate::_q_previous()
121 emit q_func()->findRequest(editFind->text(), findOptions() | QTextDocument::FindBackward);
124 QScriptDebuggerCodeFinderWidget::QScriptDebuggerCodeFinderWidget(QWidget *parent)
125 : QScriptDebuggerCodeFinderWidgetInterface(
126 *new QScriptDebuggerCodeFinderWidgetPrivate, parent, 0)
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
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);
141 d->toolClose->setText(QObject::tr("Close"));
142 hboxLayout->addWidget(d->toolClose);
144 d->editFind = new QLineEdit(this);
145 d->editFind->setMinimumSize(QSize(150, 0));
146 connect(d->editFind, SIGNAL(textChanged(const QString&)),
147 this, SLOT(_q_updateButtons()));
148 connect(d->editFind, SIGNAL(returnPressed()),
149 this, SLOT(_q_next()));
150 hboxLayout->addWidget(d->editFind);
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);
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);
166 d->checkCase = new QCheckBox(tr("Case Sensitive"), this);
167 hboxLayout->addWidget(d->checkCase);
169 d->checkWholeWords = new QCheckBox(tr("Whole words"), this);
170 hboxLayout->addWidget(d->checkWholeWords);
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\">&nbsp;Search wrapped"));
179 hboxLayout->addWidget(d->labelWrapped);
181 QSpacerItem *spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
182 hboxLayout->addItem(spacerItem);
183 setMinimumWidth(minimumSizeHint().width());
184 d->labelWrapped->hide();
186 d->_q_updateButtons();
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()));
196 QScriptDebuggerCodeFinderWidget::~QScriptDebuggerCodeFinderWidget()
200 int QScriptDebuggerCodeFinderWidget::findOptions() const
202 Q_D(const QScriptDebuggerCodeFinderWidget);
203 return d->findOptions();
206 QString QScriptDebuggerCodeFinderWidget::text() const
208 Q_D(const QScriptDebuggerCodeFinderWidget);
209 return d->editFind->text();
212 void QScriptDebuggerCodeFinderWidget::setText(const QString &text)
214 Q_D(const QScriptDebuggerCodeFinderWidget);
215 d->editFind->setText(text);
218 void QScriptDebuggerCodeFinderWidget::setOK(bool ok)
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();
233 void QScriptDebuggerCodeFinderWidget::setWrapped(bool wrapped)
235 Q_D(QScriptDebuggerCodeFinderWidget);
236 d->labelWrapped->setVisible(wrapped);
239 void QScriptDebuggerCodeFinderWidget::keyPressEvent(QKeyEvent *e)
241 if (e->key() == Qt::Key_Escape)
242 hide();
243 else
244 QScriptDebuggerCodeFinderWidgetInterface::keyPressEvent(e);
247 QT_END_NAMESPACE
249 #include "moc_qscriptdebuggercodefinderwidget_p.cpp"