2012-06-27 01:21:57 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2012, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2012, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
Copyright 2014, Maltsev Vlad <shedwardx@gmail.com>
|
2012-06-27 01:21:57 +02:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/searchboxwidget.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>
|
|
|
|
|
2014-12-19 00:40:30 +01:00
|
|
|
#include "internet/core/internetservice.h"
|
|
|
|
#include "ui/iconloader.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "ui_searchboxwidget.h"
|
2014-12-19 00:40:30 +01:00
|
|
|
#include "widgets/didyoumean.h"
|
|
|
|
|
2012-06-27 01:21:57 +02:00
|
|
|
SearchBoxWidget::SearchBoxWidget(InternetService* service)
|
2014-02-07 16:34:20 +01:00
|
|
|
: service_(service),
|
|
|
|
ui_(new Ui_SearchBoxWidget),
|
|
|
|
menu_(new QMenu(tr("Display options"), this)) {
|
2012-06-27 01:21:57 +02:00
|
|
|
ui_->setupUi(this);
|
|
|
|
|
|
|
|
// Icons
|
2015-10-14 03:01:08 +02:00
|
|
|
ui_->options->setIcon(IconLoader::Load("configure", IconLoader::Base));
|
2012-06-27 01:21:57 +02:00
|
|
|
|
|
|
|
// Options menu
|
|
|
|
menu_->setIcon(ui_->options->icon());
|
|
|
|
ui_->options->setMenu(menu_);
|
|
|
|
|
2015-10-14 03:01:08 +02:00
|
|
|
menu_->addAction(IconLoader::Load("configure", IconLoader::Base),
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("Configure %1...").arg(service_->name()), service_,
|
|
|
|
SLOT(ShowConfig()));
|
2012-06-27 01:21:57 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->filter->setPlaceholderText(
|
|
|
|
QString("Search on %1").arg(service_->name()));
|
|
|
|
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);
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(did_you_mean_, SIGNAL(Accepted(QString)), ui_->filter,
|
|
|
|
SLOT(setText(QString)));
|
2012-06-27 01:21:57 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SearchBoxWidget::~SearchBoxWidget() { delete ui_; }
|
2012-06-27 01:21:57 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SearchBoxWidget::FocusOnFilter(QKeyEvent* event) {
|
2012-06-27 01:21:57 +02:00
|
|
|
ui_->filter->setFocus(Qt::OtherFocusReason);
|
|
|
|
QApplication::sendEvent(ui_->filter, event);
|
|
|
|
}
|
|
|
|
|
2014-12-17 19:02:21 +01:00
|
|
|
void SearchBoxWidget::SetText(const QString& text) {
|
|
|
|
ui_->filter->setText(text);
|
2014-03-07 18:58:50 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 01:21:57 +02:00
|
|
|
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);
|
|
|
|
}
|