Qt 4.8
qscriptdebuggercodefinderwidget.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 <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 
54 
57 {
59 public:
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 
78 };
79 
81 {
82 }
83 
85 {
86 }
87 
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 
100 {
101  int flags = 0;
102  if (checkCase->isChecked())
104  if (checkWholeWords->isChecked())
106  return flags;
107 }
108 
110 {
111  emit q_func()->findRequest(text, findOptions() | 0x100);
112 }
113 
115 {
116  emit q_func()->findRequest(editFind->text(), findOptions());
117 }
118 
120 {
121  emit q_func()->findRequest(editFind->text(), findOptions() | QTextDocument::FindBackward);
122 }
123 
127 {
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);
141  d->toolClose->setText(tr("Close"));
142  hboxLayout->addWidget(d->toolClose);
143 
144  d->editFind = new QLineEdit(this);
145  d->editFind->setMinimumSize(QSize(150, 0));
146  connect(d->editFind, SIGNAL(textChanged(QString)),
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\">&nbsp;Search wrapped"));
179  hboxLayout->addWidget(d->labelWrapped);
180 
182  hboxLayout->addItem(spacerItem);
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 
197 {
198 }
199 
201 {
203  return d->findOptions();
204 }
205 
207 {
209  return d->editFind->text();
210 }
211 
213 {
215  d->editFind->setText(text);
216 }
217 
219 {
221  QPalette p = d->editFind->palette();
222  QColor c;
223  if (ok)
224  c = Qt::white;
225  else
226  c = QColor(255, 102, 102);
228  d->editFind->setPalette(p);
229  if (!ok)
230  d->labelWrapped->hide();
231 }
232 
234 {
236  d->labelWrapped->setVisible(wrapped);
237 }
238 
240 {
241  if (e->key() == Qt::Key_Escape)
242  hide();
243  else
245 }
246 
248 
249 #include "moc_qscriptdebuggercodefinderwidget_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
The QKeyEvent class describes a key event.
Definition: qevent.h:224
bool isChecked() const
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual QSize minimumSizeHint() const
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#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 addItem(QLayoutItem *)
Reimplemented Function
Definition: qboxlayout.cpp:894
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QSpacerItem class provides blank space in a layout.
Definition: qlayoutitem.h:96
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...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int width() const
QString text
the line edit&#39;s text
Definition: qlineedit.h:72
#define emit
Definition: qobjectdefs.h:76
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
void setEnabled(bool)
Definition: qwidget.cpp:3447
void hide()
Hides the widget.
Definition: qwidget.h:501
void keyPressEvent(QKeyEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
void setFocusProxy(QWidget *)
Sets the widget&#39;s focus proxy to widget w.
Definition: qwidget.cpp:6537
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void setSpacing(int spacing)
Reimplements QLayout::setSpacing().
Definition: qboxlayout.cpp:667
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
void setMinimumWidth(int minw)
Definition: qwidget.cpp:4325
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
The QHBoxLayout class lines up widgets horizontally.
Definition: qboxlayout.h:129
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QObject * parent
Definition: qobject.h:92
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
The QCheckBox widget provides a checkbox with a text label.
Definition: qcheckbox.h:56
void setMargin(int)
Definition: qlayout.cpp:464
#define text
Definition: qobjectdefs.h:80
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60