2012-06-11 00:05:30 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-06-11 00:05:30 +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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-06-11 00:05:30 +02:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-06-11 00:05:30 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "suggestionwidget.h"
|
|
|
|
#include "ui_suggestionwidget.h"
|
|
|
|
#include "ui/iconloader.h"
|
|
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
SuggestionWidget::SuggestionWidget(const QIcon& search_icon, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QWidget(parent), ui_(new Ui_SuggestionWidget) {
|
2012-06-11 00:05:30 +02:00
|
|
|
ui_->setupUi(this);
|
|
|
|
|
|
|
|
ui_->icon->setPixmap(search_icon.pixmap(16));
|
|
|
|
ui_->name->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SuggestionWidget::~SuggestionWidget() { delete ui_; }
|
2012-06-11 00:05:30 +02:00
|
|
|
|
|
|
|
void SuggestionWidget::SetText(const QString& text) {
|
|
|
|
ui_->name->setText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SuggestionWidget::eventFilter(QObject* object, QEvent* event) {
|
|
|
|
if (object != ui_->name) {
|
|
|
|
return QWidget::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
QFont font(ui_->name->font());
|
|
|
|
|
|
|
|
switch (event->type()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case QEvent::Enter:
|
|
|
|
font.setUnderline(true);
|
|
|
|
ui_->name->setFont(font);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::Leave:
|
|
|
|
font.setUnderline(false);
|
|
|
|
ui_->name->setFont(font);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::MouseButtonRelease: {
|
|
|
|
QMouseEvent* e = static_cast<QMouseEvent*>(event);
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
QString text = ui_->name->text();
|
|
|
|
text.replace(QRegExp("\\W"), " ");
|
|
|
|
|
|
|
|
emit SuggestionClicked(text.simplified());
|
|
|
|
}
|
|
|
|
break;
|
2012-06-11 00:05:30 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
default:
|
|
|
|
return false;
|
2012-06-11 00:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|