NCL Composer  0.1.5
 All Classes Functions Variables Pages
QLLineEditFilter.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "QLineEditFilter.h"
19 
20 QLineEditFilter::QLineEditFilter(QWidget *parent) : QLineEdit(parent)
21 {
22  setStyleSheet("color: #bbbbbb;");
23  setText(tr("Filter..."));
24  isFilterText = true;
25 
26  connect(this, SIGNAL(textEdited(QString)),
27  this, SLOT(userTextEdited(QString)));
28 }
29 
30 QLineEditFilter::~QLineEditFilter()
31 {
32 
33 }
34 
35 void QLineEditFilter::focusInEvent(QFocusEvent *focusEvent)
36 {
37  if(isFilterText)
38  {
39  setText("");
40  setStyleSheet("color: #000000;");
41  isFilterText = false;
42  }
43  QLineEdit::focusInEvent(focusEvent);
44 }
45 
46 void QLineEditFilter::focusOutEvent(QFocusEvent *focusEvent)
47 {
48  if(text() == "") {
49  isFilterText = true;
50  setStyleSheet("color: #bbbbbb;");
51  setText(tr("Filter..."));
52  }
53  QLineEdit::focusOutEvent(focusEvent);
54 }
55 
56 void QLineEditFilter::userTextEdited(const QString &text)
57 {
58  if(!isFilterText)
59  emit filterTextChanged(text);
60  else
61  emit filterTextChanged(QString (""));
62 }