2010-10-25 01:46:05 +02:00
|
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-25 01:46:05 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
#include "searchtermwidget.h"
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
#include <QFile>
|
2020-09-18 16:15:19 +02:00
|
|
|
|
#include <QKeyEvent>
|
2011-04-24 19:52:16 +02:00
|
|
|
|
#include <QMessageBox>
|
2010-10-25 01:46:05 +02:00
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QtDebug>
|
2020-09-18 16:15:19 +02:00
|
|
|
|
|
|
|
|
|
#include "core/utilities.h"
|
|
|
|
|
#include "playlist/playlist.h"
|
|
|
|
|
#include "playlist/playlistdelegates.h"
|
|
|
|
|
#include "searchterm.h"
|
|
|
|
|
#include "ui/iconloader.h"
|
|
|
|
|
#include "ui_searchtermwidget.h"
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
// Exported by QtGui
|
2014-02-07 16:34:20 +01:00
|
|
|
|
void qt_blurImage(QPainter* p, QImage& blurImage, qreal radius, bool quality,
|
|
|
|
|
bool alphaOnly, int transposed = 0);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
namespace smart_playlists {
|
|
|
|
|
|
|
|
|
|
class SearchTermWidget::Overlay : public QWidget {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
public:
|
2010-11-18 21:19:33 +01:00
|
|
|
|
Overlay(SearchTermWidget* parent);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
void Grab();
|
|
|
|
|
void SetOpacity(float opacity);
|
|
|
|
|
float opacity() const { return opacity_; }
|
|
|
|
|
|
|
|
|
|
static const int kSpacing;
|
|
|
|
|
static const int kIconSize;
|
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
protected:
|
2010-10-25 01:46:05 +02:00
|
|
|
|
void paintEvent(QPaintEvent*);
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent*);
|
2015-06-17 13:51:10 +02:00
|
|
|
|
void keyReleaseEvent(QKeyEvent* e);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
private:
|
2010-11-18 21:19:33 +01:00
|
|
|
|
SearchTermWidget* parent_;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
float opacity_;
|
|
|
|
|
QString text_;
|
|
|
|
|
QPixmap pixmap_;
|
|
|
|
|
QPixmap icon_;
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
const int SearchTermWidget::Overlay::kSpacing = 6;
|
|
|
|
|
const int SearchTermWidget::Overlay::kIconSize = 22;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
SearchTermWidget::SearchTermWidget(LibraryBackend* library, QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
|
: QWidget(parent),
|
|
|
|
|
ui_(new Ui_SmartPlaylistSearchTermWidget),
|
|
|
|
|
library_(library),
|
|
|
|
|
overlay_(nullptr),
|
|
|
|
|
animation_(new QPropertyAnimation(this, "overlay_opacity", this)),
|
|
|
|
|
active_(true),
|
|
|
|
|
initialized_(false),
|
|
|
|
|
current_field_type_(SearchTerm::Type_Invalid) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
ui_->setupUi(this);
|
2014-02-07 16:34:20 +01:00
|
|
|
|
connect(ui_->field, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
SLOT(FieldChanged(int)));
|
2011-04-24 19:52:16 +02:00
|
|
|
|
connect(ui_->op, SIGNAL(currentIndexChanged(int)), SLOT(OpChanged(int)));
|
2010-10-26 21:03:23 +02:00
|
|
|
|
connect(ui_->remove, SIGNAL(clicked()), SIGNAL(RemoveClicked()));
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2010-10-29 20:41:49 +02:00
|
|
|
|
connect(ui_->value_date, SIGNAL(dateChanged(QDate)), SIGNAL(Changed()));
|
|
|
|
|
connect(ui_->value_number, SIGNAL(valueChanged(int)), SIGNAL(Changed()));
|
|
|
|
|
connect(ui_->value_rating, SIGNAL(RatingChanged(float)), SIGNAL(Changed()));
|
|
|
|
|
connect(ui_->value_text, SIGNAL(textChanged(QString)), SIGNAL(Changed()));
|
|
|
|
|
connect(ui_->value_time, SIGNAL(timeChanged(QTime)), SIGNAL(Changed()));
|
2014-02-07 16:34:20 +01:00
|
|
|
|
connect(ui_->value_date_numeric, SIGNAL(valueChanged(int)),
|
|
|
|
|
SIGNAL(Changed()));
|
|
|
|
|
connect(ui_->value_date_numeric1, SIGNAL(valueChanged(int)),
|
|
|
|
|
SLOT(RelativeValueChanged()));
|
|
|
|
|
connect(ui_->value_date_numeric2, SIGNAL(valueChanged(int)),
|
|
|
|
|
SLOT(RelativeValueChanged()));
|
2011-04-24 19:52:16 +02:00
|
|
|
|
connect(ui_->date_type, SIGNAL(currentIndexChanged(int)), SIGNAL(Changed()));
|
2014-02-07 16:34:20 +01:00
|
|
|
|
connect(ui_->date_type_relative, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
SIGNAL(Changed()));
|
2010-10-29 20:41:49 +02:00
|
|
|
|
|
2010-10-29 21:26:37 +02:00
|
|
|
|
ui_->value_date->setDate(QDate::currentDate());
|
|
|
|
|
|
2010-10-25 01:46:05 +02:00
|
|
|
|
// Populate the combo boxes
|
2014-02-07 16:34:20 +01:00
|
|
|
|
for (int i = 0; i < SearchTerm::FieldCount; ++i) {
|
2010-11-18 21:19:33 +01:00
|
|
|
|
ui_->field->addItem(SearchTerm::FieldName(SearchTerm::Field(i)));
|
2010-10-25 01:46:05 +02:00
|
|
|
|
ui_->field->setItemData(i, i);
|
|
|
|
|
}
|
|
|
|
|
ui_->field->model()->sort(0);
|
|
|
|
|
|
2011-04-24 19:52:16 +02:00
|
|
|
|
// Populate the date type combo box
|
2014-02-07 16:34:20 +01:00
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
ui_->date_type->addItem(
|
|
|
|
|
SearchTerm::DateName(SearchTerm::DateType(i), false));
|
2011-04-24 19:52:16 +02:00
|
|
|
|
ui_->date_type->setItemData(i, i);
|
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
ui_->date_type_relative->addItem(
|
|
|
|
|
SearchTerm::DateName(SearchTerm::DateType(i), false));
|
2011-04-24 19:52:16 +02:00
|
|
|
|
ui_->date_type_relative->setItemData(i, i);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 01:46:05 +02:00
|
|
|
|
// Icons on the buttons
|
2015-10-14 03:01:08 +02:00
|
|
|
|
ui_->remove->setIcon(IconLoader::Load("list-remove", IconLoader::Base));
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
// Set stylesheet
|
|
|
|
|
QFile stylesheet_file(":/smartplaylistsearchterm.css");
|
|
|
|
|
stylesheet_file.open(QIODevice::ReadOnly);
|
2015-04-11 22:52:31 +02:00
|
|
|
|
QString stylesheet = QString::fromLatin1(stylesheet_file.readAll());
|
2010-10-25 01:46:05 +02:00
|
|
|
|
const QColor base(222, 97, 97, 128);
|
|
|
|
|
stylesheet.replace("%light2", Utilities::ColorToRgba(base.lighter(140)));
|
2014-02-07 16:34:20 +01:00
|
|
|
|
stylesheet.replace("%light", Utilities::ColorToRgba(base.lighter(120)));
|
|
|
|
|
stylesheet.replace("%dark", Utilities::ColorToRgba(base.darker(120)));
|
|
|
|
|
stylesheet.replace("%base", Utilities::ColorToRgba(base));
|
2010-10-25 01:46:05 +02:00
|
|
|
|
setStyleSheet(stylesheet);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
SearchTermWidget::~SearchTermWidget() { delete ui_; }
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::FieldChanged(int index) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
SearchTerm::Field field =
|
|
|
|
|
SearchTerm::Field(ui_->field->itemData(index).toInt());
|
2010-11-18 21:19:33 +01:00
|
|
|
|
SearchTerm::Type type = SearchTerm::TypeOf(field);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
// Populate the operator combo box
|
2012-12-10 09:37:38 +01:00
|
|
|
|
if (type != current_field_type_) {
|
|
|
|
|
ui_->op->clear();
|
2014-02-10 14:29:07 +01:00
|
|
|
|
for (SearchTerm::Operator op : SearchTerm::OperatorsForType(type)) {
|
2012-12-10 09:37:38 +01:00
|
|
|
|
const int i = ui_->op->count();
|
|
|
|
|
ui_->op->addItem(SearchTerm::OperatorText(type, op));
|
|
|
|
|
ui_->op->setItemData(i, op);
|
|
|
|
|
}
|
|
|
|
|
current_field_type_ = type;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Show the correct value editor
|
2014-02-06 16:49:49 +01:00
|
|
|
|
QWidget* page = nullptr;
|
2018-02-12 19:43:17 +01:00
|
|
|
|
SearchTerm::Operator op = static_cast<SearchTerm::Operator>(
|
2020-09-18 16:15:19 +02:00
|
|
|
|
ui_->op->itemData(ui_->op->currentIndex()).toInt());
|
2010-10-25 01:46:05 +02:00
|
|
|
|
switch (type) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Type_Time:
|
|
|
|
|
page = ui_->page_time;
|
|
|
|
|
break;
|
|
|
|
|
case SearchTerm::Type_Number:
|
|
|
|
|
page = ui_->page_number;
|
|
|
|
|
break;
|
|
|
|
|
case SearchTerm::Type_Date:
|
|
|
|
|
page = ui_->page_date;
|
|
|
|
|
break;
|
|
|
|
|
case SearchTerm::Type_Rating:
|
|
|
|
|
page = ui_->page_rating;
|
|
|
|
|
break;
|
|
|
|
|
case SearchTerm::Type_Text:
|
2018-02-12 19:43:17 +01:00
|
|
|
|
if (op == SearchTerm::Op_Empty || op == SearchTerm::Op_NotEmpty) {
|
2018-02-12 17:59:43 +01:00
|
|
|
|
page = ui_->page_empty;
|
|
|
|
|
} else {
|
|
|
|
|
page = ui_->page_text;
|
|
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
|
break;
|
|
|
|
|
case SearchTerm::Type_Invalid:
|
|
|
|
|
page = nullptr;
|
|
|
|
|
break;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
|
|
|
|
ui_->value_stack->setCurrentWidget(page);
|
|
|
|
|
|
|
|
|
|
// Maybe set a tag completer
|
|
|
|
|
switch (field) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Field_Artist:
|
|
|
|
|
new TagCompleter(library_, Playlist::Column_Artist, ui_->value_text);
|
|
|
|
|
break;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Field_Album:
|
|
|
|
|
new TagCompleter(library_, Playlist::Column_Album, ui_->value_text);
|
|
|
|
|
break;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
default:
|
|
|
|
|
ui_->value_text->setCompleter(nullptr);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
2010-10-29 21:26:37 +02:00
|
|
|
|
|
|
|
|
|
emit Changed();
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-24 19:52:16 +02:00
|
|
|
|
void SearchTermWidget::OpChanged(int index) {
|
2018-02-12 19:43:17 +01:00
|
|
|
|
// Determine the currently selected operator
|
|
|
|
|
SearchTerm::Operator op = static_cast<SearchTerm::Operator>(
|
2020-09-18 16:15:19 +02:00
|
|
|
|
// This uses the operators’s index in the combobox to get its enum value
|
|
|
|
|
ui_->op->itemData(ui_->op->currentIndex()).toInt());
|
2018-02-12 19:43:17 +01:00
|
|
|
|
|
2011-04-24 19:52:16 +02:00
|
|
|
|
// We need to change the page only in the following case
|
2018-02-12 17:59:43 +01:00
|
|
|
|
if ((ui_->value_stack->currentWidget() == ui_->page_text) ||
|
|
|
|
|
(ui_->value_stack->currentWidget() == ui_->page_empty)) {
|
|
|
|
|
QWidget* page = nullptr;
|
2018-02-12 19:43:17 +01:00
|
|
|
|
if (op == SearchTerm::Op_Empty || op == SearchTerm::Op_NotEmpty) {
|
2018-02-12 17:59:43 +01:00
|
|
|
|
page = ui_->page_empty;
|
|
|
|
|
} else {
|
|
|
|
|
page = ui_->page_text;
|
|
|
|
|
}
|
|
|
|
|
ui_->value_stack->setCurrentWidget(page);
|
2018-02-12 19:43:17 +01:00
|
|
|
|
} else if ((ui_->value_stack->currentWidget() == ui_->page_date) ||
|
2020-09-18 16:15:19 +02:00
|
|
|
|
(ui_->value_stack->currentWidget() == ui_->page_date_numeric) ||
|
|
|
|
|
(ui_->value_stack->currentWidget() == ui_->page_date_relative)) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
QWidget* page = nullptr;
|
2020-09-18 16:15:19 +02:00
|
|
|
|
if (op == SearchTerm::Op_NumericDate ||
|
|
|
|
|
op == SearchTerm::Op_NumericDateNot) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
page = ui_->page_date_numeric;
|
2018-02-12 19:43:17 +01:00
|
|
|
|
} else if (op == SearchTerm::Op_RelativeDate) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
page = ui_->page_date_relative;
|
|
|
|
|
} else {
|
|
|
|
|
page = ui_->page_date;
|
|
|
|
|
}
|
|
|
|
|
ui_->value_stack->setCurrentWidget(page);
|
2011-04-24 19:52:16 +02:00
|
|
|
|
}
|
2018-02-12 17:59:43 +01:00
|
|
|
|
|
2011-04-24 19:52:16 +02:00
|
|
|
|
emit Changed();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::SetActive(bool active) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
active_ = active;
|
|
|
|
|
delete overlay_;
|
2014-02-06 16:49:49 +01:00
|
|
|
|
overlay_ = nullptr;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2015-06-17 13:51:10 +02:00
|
|
|
|
ui_->container->setEnabled(active);
|
|
|
|
|
|
2010-10-25 01:46:05 +02:00
|
|
|
|
if (!active) {
|
|
|
|
|
overlay_ = new Overlay(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::enterEvent(QEvent*) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
if (!overlay_ || !isEnabled()) return;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
animation_->stop();
|
|
|
|
|
animation_->setEndValue(1.0);
|
|
|
|
|
animation_->setDuration(80);
|
|
|
|
|
animation_->start();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::leaveEvent(QEvent*) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
if (!overlay_) return;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
animation_->stop();
|
|
|
|
|
animation_->setEndValue(0.0);
|
|
|
|
|
animation_->setDuration(160);
|
|
|
|
|
animation_->start();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::resizeEvent(QResizeEvent* e) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
QWidget::resizeEvent(e);
|
|
|
|
|
if (overlay_ && overlay_->isVisible()) {
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(Grab()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::showEvent(QShowEvent* e) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
QWidget::showEvent(e);
|
|
|
|
|
if (overlay_) {
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(Grab()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
void SearchTermWidget::Grab() { overlay_->Grab(); }
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::set_overlay_opacity(float opacity) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
if (overlay_) overlay_->SetOpacity(opacity);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
float SearchTermWidget::overlay_opacity() const {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
return overlay_ ? overlay_->opacity() : 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 00:08:37 +01:00
|
|
|
|
void SearchTermWidget::SetTerm(const SearchTerm& term) {
|
|
|
|
|
ui_->field->setCurrentIndex(ui_->field->findData(term.field_));
|
|
|
|
|
ui_->op->setCurrentIndex(ui_->op->findData(term.operator_));
|
|
|
|
|
|
|
|
|
|
// The value depends on the data type
|
|
|
|
|
switch (SearchTerm::TypeOf(term.field_)) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Type_Text:
|
2018-02-12 17:59:43 +01:00
|
|
|
|
if (ui_->value_stack->currentWidget() == ui_->page_empty) {
|
|
|
|
|
ui_->value_text->setText("");
|
|
|
|
|
} else {
|
|
|
|
|
ui_->value_text->setText(term.value_.toString());
|
|
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SearchTerm::Type_Number:
|
|
|
|
|
ui_->value_number->setValue(term.value_.toInt());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SearchTerm::Type_Date:
|
|
|
|
|
if (ui_->value_stack->currentWidget() == ui_->page_date_numeric) {
|
|
|
|
|
ui_->value_date_numeric->setValue(term.value_.toInt());
|
|
|
|
|
ui_->date_type->setCurrentIndex(term.date_);
|
|
|
|
|
} else if (ui_->value_stack->currentWidget() == ui_->page_date_relative) {
|
|
|
|
|
ui_->value_date_numeric1->setValue(term.value_.toInt());
|
|
|
|
|
ui_->value_date_numeric2->setValue(term.second_value_.toInt());
|
|
|
|
|
ui_->date_type_relative->setCurrentIndex(term.date_);
|
|
|
|
|
} else if (ui_->value_stack->currentWidget() == ui_->page_date) {
|
|
|
|
|
ui_->value_date->setDateTime(
|
|
|
|
|
QDateTime::fromTime_t(term.value_.toInt()));
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-11-19 00:08:37 +01:00
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Type_Time:
|
|
|
|
|
ui_->value_time->setTime(QTime(0, 0).addSecs(term.value_.toInt()));
|
|
|
|
|
break;
|
2010-11-19 00:08:37 +01:00
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Type_Rating:
|
|
|
|
|
ui_->value_rating->set_rating(term.value_.toFloat());
|
|
|
|
|
break;
|
2012-12-10 09:37:38 +01:00
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
|
case SearchTerm::Type_Invalid:
|
|
|
|
|
break;
|
2010-11-19 00:08:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
SearchTerm SearchTermWidget::Term() const {
|
2010-10-26 21:59:55 +02:00
|
|
|
|
const int field = ui_->field->itemData(ui_->field->currentIndex()).toInt();
|
2014-02-07 16:34:20 +01:00
|
|
|
|
const int op = ui_->op->itemData(ui_->op->currentIndex()).toInt();
|
2010-10-26 21:59:55 +02:00
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
SearchTerm ret;
|
|
|
|
|
ret.field_ = SearchTerm::Field(field);
|
|
|
|
|
ret.operator_ = SearchTerm::Operator(op);
|
2010-10-26 21:59:55 +02:00
|
|
|
|
|
|
|
|
|
// The value depends on the data type
|
|
|
|
|
const QWidget* value_page = ui_->value_stack->currentWidget();
|
|
|
|
|
if (value_page == ui_->page_text) {
|
|
|
|
|
ret.value_ = ui_->value_text->text();
|
2018-02-12 17:59:43 +01:00
|
|
|
|
} else if (value_page == ui_->page_empty) {
|
|
|
|
|
ret.value_ = "";
|
2010-10-26 21:59:55 +02:00
|
|
|
|
} else if (value_page == ui_->page_number) {
|
|
|
|
|
ret.value_ = ui_->value_number->value();
|
|
|
|
|
} else if (value_page == ui_->page_date) {
|
|
|
|
|
ret.value_ = ui_->value_date->dateTime().toTime_t();
|
|
|
|
|
} else if (value_page == ui_->page_time) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
ret.value_ = QTime(0, 0).secsTo(ui_->value_time->time());
|
2010-10-26 21:59:55 +02:00
|
|
|
|
} else if (value_page == ui_->page_rating) {
|
|
|
|
|
ret.value_ = ui_->value_rating->rating();
|
2011-04-24 19:52:16 +02:00
|
|
|
|
} else if (value_page == ui_->page_date_numeric) {
|
|
|
|
|
ret.date_ = SearchTerm::DateType(ui_->date_type->currentIndex());
|
|
|
|
|
ret.value_ = ui_->value_date_numeric->value();
|
|
|
|
|
} else if (value_page == ui_->page_date_relative) {
|
|
|
|
|
ret.date_ = SearchTerm::DateType(ui_->date_type_relative->currentIndex());
|
|
|
|
|
ret.value_ = ui_->value_date_numeric1->value();
|
|
|
|
|
ret.second_value_ = ui_->value_date_numeric2->value();
|
2010-10-26 21:59:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-24 19:52:16 +02:00
|
|
|
|
void SearchTermWidget::RelativeValueChanged() {
|
|
|
|
|
// Don't check for validity when creating the widget
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
initialized_ = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Explain the user why he can't proceed
|
|
|
|
|
if (ui_->value_date_numeric1->value() >= ui_->value_date_numeric2->value()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
|
QMessageBox::warning(
|
|
|
|
|
this, tr("Clementine"),
|
|
|
|
|
tr("The second value must be greater than the first one!"));
|
2011-04-24 19:52:16 +02:00
|
|
|
|
}
|
|
|
|
|
// Emit the signal in any case, so the Next button will be disabled
|
|
|
|
|
emit Changed();
|
|
|
|
|
}
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
SearchTermWidget::Overlay::Overlay(SearchTermWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
|
: QWidget(parent),
|
|
|
|
|
parent_(parent),
|
|
|
|
|
opacity_(0.0),
|
|
|
|
|
text_(tr("Add search term")),
|
2015-10-14 03:01:08 +02:00
|
|
|
|
icon_(IconLoader::Load("list-add", IconLoader::Base).pixmap(kIconSize)) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
raise();
|
2015-06-17 13:51:10 +02:00
|
|
|
|
setFocusPolicy(Qt::TabFocus);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::Overlay::SetOpacity(float opacity) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
opacity_ = opacity;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::Overlay::Grab() {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
hide();
|
|
|
|
|
|
|
|
|
|
// Take a "screenshot" of the window
|
2015-06-16 20:07:11 +02:00
|
|
|
|
QPixmap pixmap = parent_->grab();
|
2010-10-25 01:46:05 +02:00
|
|
|
|
QImage image = pixmap.toImage();
|
|
|
|
|
|
|
|
|
|
// Blur it
|
|
|
|
|
QImage blurred(image.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
|
blurred.fill(Qt::transparent);
|
|
|
|
|
|
|
|
|
|
QPainter blur_painter(&blurred);
|
|
|
|
|
qt_blurImage(&blur_painter, image, 10.0, true, false);
|
|
|
|
|
blur_painter.end();
|
|
|
|
|
|
|
|
|
|
pixmap_ = QPixmap::fromImage(blurred);
|
|
|
|
|
|
|
|
|
|
resize(parent_->size());
|
|
|
|
|
show();
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::Overlay::paintEvent(QPaintEvent*) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
QPainter p(this);
|
|
|
|
|
|
|
|
|
|
// Background
|
|
|
|
|
p.fillRect(rect(), palette().window());
|
|
|
|
|
|
|
|
|
|
// Blurred parent widget
|
|
|
|
|
p.setOpacity(0.25 + opacity_ * 0.25);
|
|
|
|
|
p.drawPixmap(0, 0, pixmap_);
|
|
|
|
|
|
2010-11-03 21:12:42 +01:00
|
|
|
|
// Draw a frame
|
|
|
|
|
p.setOpacity(1.0);
|
|
|
|
|
p.setPen(palette().color(QPalette::Mid));
|
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
p.drawRoundedRect(rect(), 5, 5);
|
|
|
|
|
|
2010-10-25 01:46:05 +02:00
|
|
|
|
// Geometry
|
|
|
|
|
const QSize contents_size(kIconSize + kSpacing + fontMetrics().width(text_),
|
|
|
|
|
qMax(kIconSize, fontMetrics().height()));
|
|
|
|
|
const QRect contents(QPoint((width() - contents_size.width()) / 2,
|
|
|
|
|
(height() - contents_size.height()) / 2),
|
|
|
|
|
contents_size);
|
|
|
|
|
const QRect icon(contents.topLeft(), QSize(kIconSize, kIconSize));
|
|
|
|
|
const QRect text(icon.right() + kSpacing, icon.top(),
|
2014-02-07 16:34:20 +01:00
|
|
|
|
contents.width() - kSpacing - kIconSize, contents.height());
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
|
|
// Icon and text
|
2010-11-03 21:12:42 +01:00
|
|
|
|
p.setPen(palette().color(QPalette::Text));
|
2010-10-25 01:46:05 +02:00
|
|
|
|
p.drawPixmap(icon, icon_);
|
2010-11-03 21:12:42 +01:00
|
|
|
|
p.drawText(text, Qt::TextDontClip | Qt::AlignVCenter, text_);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
|
void SearchTermWidget::Overlay::mouseReleaseEvent(QMouseEvent*) {
|
2010-10-25 01:46:05 +02:00
|
|
|
|
emit parent_->Clicked();
|
|
|
|
|
}
|
2010-11-18 21:19:33 +01:00
|
|
|
|
|
2015-06-17 13:51:10 +02:00
|
|
|
|
void SearchTermWidget::Overlay::keyReleaseEvent(QKeyEvent* e) {
|
|
|
|
|
if (e->key() == Qt::Key_Space) emit parent_->Clicked();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
|
} // namespace smart_playlists
|