~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/thirdparty/Qocoa/qsearchfield.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2011 by Mike McQuaid
 
3
Copyright (C) 2011 by Leo Franchi
 
4
 
 
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:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
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
 
21
THE SOFTWARE.
 
22
*/
 
23
 
 
24
#include "qsearchfield.h"
 
25
 
 
26
#include <QLineEdit>
 
27
#include <QVBoxLayout>
 
28
 
 
29
#include "widgets/searchlineedit/SearchLineEdit.h"
 
30
#include "utils/TomahawkUtilsGui.h"
 
31
 
 
32
class DLLEXPORT QSearchFieldPrivate : public QObject
 
33
{
 
34
    Q_OBJECT
 
35
public:
 
36
    QSearchFieldPrivate(SearchLineEdit *lineEdit) : QObject( lineEdit ), lineEdit(lineEdit) {}
 
37
    virtual ~QSearchFieldPrivate() {}
 
38
 
 
39
    SearchLineEdit *lineEdit;
 
40
};
 
41
 
 
42
QSearchField::QSearchField(QWidget *parent) : QWidget(parent)
 
43
{
 
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()));
 
49
 
 
50
    pimpl = QPointer< QSearchFieldPrivate>( new QSearchFieldPrivate( lineEdit ) );
 
51
 
 
52
    QVBoxLayout *layout = new QVBoxLayout(this);
 
53
    layout->addWidget(lineEdit);
 
54
    TomahawkUtils::unmarginLayout(layout);
 
55
    setContentsMargins(0, 0, 0, 0);
 
56
 
 
57
    lineEdit->setStyleSheet( "QLineEdit { border: 1px solid gray; border-radius: 6px; }" );
 
58
    lineEdit->setMinimumHeight(27);
 
59
    setFixedHeight(27);
 
60
 
 
61
#ifdef Q_WS_MAC
 
62
    lineEdit->setContentsMargins(0, 0, 0, 0);
 
63
#else
 
64
    lineEdit->setContentsMargins(2, 2, 2, 2);
 
65
#endif
 
66
 
 
67
}
 
68
 
 
69
void QSearchField::setText(const QString &text)
 
70
{
 
71
    Q_ASSERT( !pimpl.isNull() );
 
72
    if ( pimpl.isNull() )
 
73
        return;
 
74
 
 
75
    pimpl.data()->lineEdit->setText(text);
 
76
}
 
77
 
 
78
void QSearchField::setPlaceholderText(const QString& text)
 
79
{
 
80
    Q_ASSERT( !pimpl.isNull() );
 
81
    if ( pimpl.isNull() )
 
82
        return;
 
83
 
 
84
    pimpl.data()->lineEdit->setInactiveText( text );
 
85
}
 
86
 
 
87
void QSearchField::clear()
 
88
{
 
89
    Q_ASSERT( !pimpl.isNull() );
 
90
    if ( pimpl.isNull() )
 
91
        return;
 
92
 
 
93
    pimpl.data()->lineEdit->clear();
 
94
}
 
95
 
 
96
QString QSearchField::text() const
 
97
{
 
98
    Q_ASSERT( !pimpl.isNull() );
 
99
    if ( pimpl.isNull() )
 
100
        return QString();
 
101
 
 
102
    return pimpl.data()->lineEdit->text();
 
103
}
 
104
 
 
105
QString QSearchField::placeholderText() const
 
106
{
 
107
    Q_ASSERT( !pimpl.isNull() );
 
108
    if ( pimpl.isNull() )
 
109
        return QString();
 
110
 
 
111
    return pimpl.data()->lineEdit->placeholderText();
 
112
}
 
113
 
 
114
void QSearchField::selectAll()
 
115
{
 
116
    Q_ASSERT( !pimpl.isNull() );
 
117
    if ( pimpl.isNull() )
 
118
        return;
 
119
 
 
120
    pimpl.data()->lineEdit->selectAll();
 
121
}
 
122
 
 
123
void QSearchField::setFocus()
 
124
{
 
125
    Q_ASSERT( !pimpl.isNull() );
 
126
    if ( pimpl.isNull() )
 
127
        return;
 
128
 
 
129
    pimpl.data()->lineEdit->setFocus();
 
130
}
 
131
 
 
132
void QSearchField::setFocus(Qt::FocusReason reason)
 
133
{
 
134
    Q_ASSERT( !pimpl.isNull() );
 
135
    if ( pimpl.isNull() )
 
136
        return;
 
137
 
 
138
    pimpl.data()->lineEdit->setFocus(reason);
 
139
}
 
140
 
 
141
 
 
142
void QSearchField::resizeEvent(QResizeEvent* e)
 
143
{
 
144
    QWidget::resizeEvent(e);
 
145
}
 
146
 
 
147
 
 
148
bool QSearchField::eventFilter(QObject *o, QEvent *e)
 
149
{
 
150
    return QWidget::eventFilter(o, e);
 
151
}
 
152
 
 
153
#include "qsearchfield.moc"