2012-06-27 01:21:57 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "internetservice.h"
|
|
|
|
#include "searchboxwidget.h"
|
|
|
|
#include "ui_searchboxwidget.h"
|
|
|
|
#include "ui/iconloader.h"
|
2012-06-28 23:57:51 +02:00
|
|
|
#include "widgets/didyoumean.h"
|
2012-06-27 01:21:57 +02:00
|
|
|
|
2012-06-27 17:19:46 +02:00
|
|
|
#include <QKeyEvent>
|
2012-06-27 01:21:57 +02:00
|
|
|
#include <QMenu>
|
|
|
|
|
|
|
|
SearchBoxWidget::SearchBoxWidget(InternetService* service)
|
|
|
|
: service_(service),
|
|
|
|
ui_(new Ui_SearchBoxWidget),
|
|
|
|
menu_(new QMenu(tr("Display options"), this))
|
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
|
|
|
|
|
|
|
// Icons
|
|
|
|
ui_->options->setIcon(IconLoader::Load("configure"));
|
|
|
|
|
|
|
|
// Options menu
|
|
|
|
menu_->setIcon(ui_->options->icon());
|
|
|
|
ui_->options->setMenu(menu_);
|
|
|
|
|
|
|
|
menu_->addAction(IconLoader::Load("configure"),
|
|
|
|
tr("Configure %1...").arg(service_->name()),
|
|
|
|
service_, SLOT(ShowConfig()));
|
|
|
|
|
2012-06-28 14:32:39 +02:00
|
|
|
ui_->filter->setPlaceholderText(QString("Search on %1").arg(service_->name()));
|
2012-06-27 17:19:46 +02:00
|
|
|
connect(ui_->filter, SIGNAL(textChanged(QString)), SIGNAL(TextChanged(QString)));
|
2012-06-28 23:57:51 +02:00
|
|
|
|
|
|
|
did_you_mean_ = new DidYouMean(ui_->filter, this);
|
|
|
|
connect(did_you_mean_, SIGNAL(Accepted(QString)),
|
|
|
|
ui_->filter, SLOT(setText(QString)));
|
2012-06-27 01:21:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchBoxWidget::~SearchBoxWidget() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchBoxWidget::FocusOnFilter(QKeyEvent *event) {
|
|
|
|
ui_->filter->setFocus(Qt::OtherFocusReason);
|
|
|
|
QApplication::sendEvent(ui_->filter, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchBoxWidget::keyReleaseEvent(QKeyEvent* e) {
|
|
|
|
switch (e->key()) {
|
|
|
|
case Qt::Key_Escape:
|
2012-06-27 17:19:46 +02:00
|
|
|
ui_->filter->clear();
|
2012-06-27 01:21:57 +02:00
|
|
|
e->accept();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::keyReleaseEvent(e);
|
|
|
|
}
|