2011-08-28 22:33:59 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GLOBALSEARCHWIDGET_H
|
|
|
|
#define GLOBALSEARCHWIDGET_H
|
|
|
|
|
|
|
|
#include "searchprovider.h"
|
|
|
|
|
2011-09-18 01:06:07 +02:00
|
|
|
#include <QScopedPointer>
|
2011-08-28 22:33:59 +02:00
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
class GlobalSearch;
|
2011-09-18 01:06:07 +02:00
|
|
|
class GlobalSearchTooltip;
|
2011-08-28 22:33:59 +02:00
|
|
|
class LibraryBackendInterface;
|
|
|
|
class Ui_GlobalSearchWidget;
|
|
|
|
|
2011-09-17 16:12:00 +02:00
|
|
|
class QDesktopWidget;
|
2011-08-28 22:33:59 +02:00
|
|
|
class QListView;
|
2011-08-29 03:37:55 +02:00
|
|
|
class QMimeData;
|
2011-08-28 23:20:22 +02:00
|
|
|
class QModelIndex;
|
|
|
|
class QSortFilterProxyModel;
|
2011-08-28 22:33:59 +02:00
|
|
|
class QStandardItemModel;
|
|
|
|
|
|
|
|
|
|
|
|
class GlobalSearchWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
GlobalSearchWidget(QWidget *parent = 0);
|
|
|
|
~GlobalSearchWidget();
|
|
|
|
|
|
|
|
static const int kMinVisibleItems;
|
|
|
|
static const int kMaxVisibleItems;
|
2011-09-17 18:42:14 +02:00
|
|
|
static const char* kSettingsGroup;
|
2011-08-28 22:33:59 +02:00
|
|
|
|
|
|
|
enum Role {
|
2011-09-17 18:42:14 +02:00
|
|
|
Role_PrimaryResult = Qt::UserRole + 1,
|
|
|
|
Role_AllResults,
|
2011-08-28 22:33:59 +02:00
|
|
|
Role_LazyLoadingArt
|
|
|
|
};
|
|
|
|
|
|
|
|
void Init(LibraryBackendInterface* library);
|
|
|
|
|
|
|
|
// Called by the delegate
|
|
|
|
void LazyLoadArt(const QModelIndex& index);
|
|
|
|
|
|
|
|
// QWidget
|
|
|
|
bool eventFilter(QObject* o, QEvent* e);
|
2011-09-01 16:41:47 +02:00
|
|
|
void setFocus(Qt::FocusReason reason);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-09-17 18:42:14 +02:00
|
|
|
public slots:
|
|
|
|
void ReloadSettings();
|
|
|
|
|
2011-08-29 03:37:55 +02:00
|
|
|
signals:
|
|
|
|
void AddToPlaylist(QMimeData* data);
|
|
|
|
|
2011-08-28 22:33:59 +02:00
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent* e);
|
|
|
|
void paintEvent(QPaintEvent* e);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void TextEdited(const QString& text);
|
2011-08-28 23:20:22 +02:00
|
|
|
void SearchFinished(int id);
|
2011-08-28 22:33:59 +02:00
|
|
|
void AddResults(int id, const SearchProvider::ResultList& results);
|
|
|
|
|
2011-08-28 23:52:24 +02:00
|
|
|
void ArtLoaded(int id, const QPixmap& pixmap);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-08-29 03:37:55 +02:00
|
|
|
void TracksLoaded(int id, MimeData* mime_data);
|
|
|
|
|
|
|
|
void AddCurrent();
|
|
|
|
|
2011-09-18 01:06:07 +02:00
|
|
|
void HidePopup();
|
|
|
|
void UpdateTooltip();
|
|
|
|
|
2011-08-28 22:33:59 +02:00
|
|
|
private:
|
2011-09-17 18:42:14 +02:00
|
|
|
// Return values from CanCombineResults
|
|
|
|
enum CombineAction {
|
|
|
|
CannotCombine, // The two results are different and can't be combined
|
|
|
|
LeftPreferred, // The two results can be combined - the left one is better
|
|
|
|
RightPreferred // The two results can be combined - the right one is better
|
|
|
|
};
|
|
|
|
|
2011-08-28 23:20:22 +02:00
|
|
|
void Reset();
|
2011-08-28 22:33:59 +02:00
|
|
|
void RepositionPopup();
|
2011-09-17 18:42:14 +02:00
|
|
|
CombineAction CanCombineResults(const QModelIndex& left, const QModelIndex& right) const;
|
|
|
|
void CombineResults(const QModelIndex& superior, const QModelIndex& inferior);
|
2011-08-28 22:33:59 +02:00
|
|
|
|
2011-09-17 15:22:19 +02:00
|
|
|
bool EventFilterSearchWidget(QObject* o, QEvent* e);
|
|
|
|
bool EventFilterPopup(QObject* o, QEvent* e);
|
|
|
|
|
2011-08-28 22:33:59 +02:00
|
|
|
private:
|
|
|
|
Ui_GlobalSearchWidget* ui_;
|
|
|
|
|
|
|
|
GlobalSearch* engine_;
|
|
|
|
int last_id_;
|
|
|
|
bool clear_model_on_next_result_;
|
|
|
|
|
|
|
|
QMap<int, QModelIndex> art_requests_;
|
|
|
|
|
|
|
|
QStandardItemModel* model_;
|
2011-08-28 23:20:22 +02:00
|
|
|
QSortFilterProxyModel* proxy_;
|
2011-08-28 22:33:59 +02:00
|
|
|
QListView* view_;
|
|
|
|
bool eat_focus_out_;
|
|
|
|
|
|
|
|
QPixmap background_;
|
|
|
|
QPixmap background_scaled_;
|
2011-09-17 16:12:00 +02:00
|
|
|
|
|
|
|
QDesktopWidget* desktop_;
|
2011-09-17 18:42:14 +02:00
|
|
|
|
|
|
|
bool combine_identical_results_;
|
|
|
|
QStringList provider_order_;
|
2011-09-18 01:06:07 +02:00
|
|
|
|
|
|
|
QScopedPointer<GlobalSearchTooltip> tooltip_;
|
2011-08-28 22:33:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GLOBALSEARCHWIDGET_H
|