2
Copyright (C) 2011 by Mike McQuaid
3
Copyright (C) 2011 by Leo Franchi
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
#include "qsearchfield.h"
27
#include <QVBoxLayout>
29
#include "widgets/searchlineedit/SearchLineEdit.h"
30
#include "utils/TomahawkUtilsGui.h"
32
class DLLEXPORT QSearchFieldPrivate : public QObject
36
QSearchFieldPrivate(SearchLineEdit *lineEdit) : QObject( lineEdit ), lineEdit(lineEdit) {}
37
virtual ~QSearchFieldPrivate() {}
39
SearchLineEdit *lineEdit;
42
QSearchField::QSearchField(QWidget *parent) : QWidget(parent)
44
SearchLineEdit *lineEdit = new SearchLineEdit(this);
45
connect(lineEdit, SIGNAL(textChanged(QString)),
46
this, SIGNAL(textChanged(QString)));
47
connect(lineEdit, SIGNAL(returnPressed()),
48
this, SIGNAL(returnPressed()));
50
pimpl = QPointer< QSearchFieldPrivate>( new QSearchFieldPrivate( lineEdit ) );
52
QVBoxLayout *layout = new QVBoxLayout(this);
53
layout->addWidget(lineEdit);
54
TomahawkUtils::unmarginLayout(layout);
55
setContentsMargins(0, 0, 0, 0);
57
lineEdit->setStyleSheet( "QLineEdit { border: 1px solid gray; border-radius: 6px; }" );
58
lineEdit->setMinimumHeight(27);
62
lineEdit->setContentsMargins(0, 0, 0, 0);
64
lineEdit->setContentsMargins(2, 2, 2, 2);
69
void QSearchField::setText(const QString &text)
71
Q_ASSERT( !pimpl.isNull() );
75
pimpl.data()->lineEdit->setText(text);
78
void QSearchField::setPlaceholderText(const QString& text)
80
Q_ASSERT( !pimpl.isNull() );
84
pimpl.data()->lineEdit->setInactiveText( text );
87
void QSearchField::clear()
89
Q_ASSERT( !pimpl.isNull() );
93
pimpl.data()->lineEdit->clear();
96
QString QSearchField::text() const
98
Q_ASSERT( !pimpl.isNull() );
102
return pimpl.data()->lineEdit->text();
105
QString QSearchField::placeholderText() const
107
Q_ASSERT( !pimpl.isNull() );
108
if ( pimpl.isNull() )
111
return pimpl.data()->lineEdit->placeholderText();
114
void QSearchField::selectAll()
116
Q_ASSERT( !pimpl.isNull() );
117
if ( pimpl.isNull() )
120
pimpl.data()->lineEdit->selectAll();
123
void QSearchField::setFocus()
125
Q_ASSERT( !pimpl.isNull() );
126
if ( pimpl.isNull() )
129
pimpl.data()->lineEdit->setFocus();
132
void QSearchField::setFocus(Qt::FocusReason reason)
134
Q_ASSERT( !pimpl.isNull() );
135
if ( pimpl.isNull() )
138
pimpl.data()->lineEdit->setFocus(reason);
142
void QSearchField::resizeEvent(QResizeEvent* e)
144
QWidget::resizeEvent(e);
148
bool QSearchField::eventFilter(QObject *o, QEvent *e)
150
return QWidget::eventFilter(o, e);
153
#include "qsearchfield.moc"