2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#ifndef PLAYLISTVIEW_H
|
|
|
|
#define PLAYLISTVIEW_H
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include <memory>
|
2010-03-28 00:45:46 +01:00
|
|
|
|
2010-04-28 13:09:57 +02:00
|
|
|
#include <QBasicTimer>
|
2010-09-07 00:49:15 +02:00
|
|
|
#include <QProxyStyle>
|
|
|
|
#include <QTreeView>
|
|
|
|
|
2014-02-06 14:48:00 +01:00
|
|
|
#include "playlist.h"
|
2010-09-07 00:49:15 +02:00
|
|
|
|
|
|
|
class QCleanlooksStyle;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2012-03-03 01:20:37 +01:00
|
|
|
class Application;
|
2010-11-20 21:00:40 +01:00
|
|
|
class DynamicPlaylistControls;
|
2010-05-09 02:10:26 +02:00
|
|
|
class LibraryBackend;
|
2010-08-27 14:42:06 +02:00
|
|
|
class PlaylistHeader;
|
|
|
|
class RadioLoadingIndicator;
|
2010-10-17 23:56:19 +02:00
|
|
|
class RatingItemDelegate;
|
2012-03-16 22:39:39 +01:00
|
|
|
class QTimeLine;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-09-07 00:49:15 +02:00
|
|
|
// This proxy style works around a bug/feature introduced in Qt 4.7's QGtkStyle
|
|
|
|
// that uses Gtk to paint row backgrounds, ignoring any custom brush or palette
|
|
|
|
// the caller set in the QStyleOption. That breaks our currently playing track
|
|
|
|
// animation, which relies on the background painted by Qt to be transparent.
|
|
|
|
// This proxy style uses QCleanlooksStyle to paint the affected elements.
|
2011-09-19 12:05:38 +02:00
|
|
|
// This class is used by the global search view as well.
|
2010-09-07 00:49:15 +02:00
|
|
|
class PlaylistProxyStyle : public QProxyStyle {
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2010-09-07 00:49:15 +02:00
|
|
|
PlaylistProxyStyle(QStyle* base);
|
|
|
|
void drawControl(ControlElement element, const QStyleOption* option,
|
|
|
|
QPainter* painter, const QWidget* widget) const;
|
|
|
|
void drawPrimitive(PrimitiveElement element, const QStyleOption* option,
|
|
|
|
QPainter* painter, const QWidget* widget) const;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2014-02-06 14:48:00 +01:00
|
|
|
std::unique_ptr<QCleanlooksStyle> cleanlooks_;
|
2010-09-07 00:49:15 +02:00
|
|
|
};
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
class PlaylistView : public QTreeView {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-07 16:34:20 +01:00
|
|
|
enum BackgroundImageType { Default, None, Custom, AlbumCover };
|
2012-02-18 19:57:36 +01:00
|
|
|
|
2014-02-10 16:03:54 +01:00
|
|
|
PlaylistView(QWidget* parent = nullptr);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-10-17 20:21:30 +02:00
|
|
|
static const int kStateVersion;
|
2012-02-18 19:57:36 +01:00
|
|
|
// Constants for settings: are persistent, values should not be changed
|
|
|
|
static const char* kSettingBackgroundImageType;
|
|
|
|
static const char* kSettingBackgroundImageFilename;
|
2010-08-27 12:36:01 +02:00
|
|
|
|
2013-02-17 04:03:39 +01:00
|
|
|
static const int kDefaultBlurRadius;
|
|
|
|
static const int kDefaultOpacityLevel;
|
|
|
|
|
2011-11-12 17:12:03 +01:00
|
|
|
static ColumnAlignmentMap DefaultColumnAlignment();
|
|
|
|
|
2012-03-03 01:20:37 +01:00
|
|
|
void SetApplication(Application* app);
|
2010-05-09 02:10:26 +02:00
|
|
|
void SetItemDelegates(LibraryBackend* backend);
|
2010-05-22 18:36:13 +02:00
|
|
|
void SetPlaylist(Playlist* playlist);
|
2010-03-24 17:36:44 +01:00
|
|
|
void RemoveSelected();
|
|
|
|
|
2010-10-29 20:58:43 +02:00
|
|
|
void SetReadOnlySettings(bool read_only) { read_only_settings_ = read_only; }
|
|
|
|
|
2010-12-22 11:45:14 +01:00
|
|
|
Playlist* playlist() const { return playlist_; }
|
2014-02-07 16:34:20 +01:00
|
|
|
BackgroundImageType background_image_type() const {
|
|
|
|
return background_image_type_;
|
|
|
|
}
|
2011-11-12 17:23:41 +01:00
|
|
|
Qt::Alignment column_alignment(int section) const;
|
2010-12-22 11:45:14 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// QTreeView
|
2010-10-23 22:58:20 +02:00
|
|
|
void drawTree(QPainter* painter, const QRegion& region) const;
|
2014-02-07 16:34:20 +01:00
|
|
|
void drawRow(QPainter* painter, const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const;
|
2011-11-12 17:12:03 +01:00
|
|
|
void setModel(QAbstractItemModel* model);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
public slots:
|
2010-08-27 12:36:01 +02:00
|
|
|
void ReloadSettings();
|
2009-12-24 20:16:07 +01:00
|
|
|
void StopGlowing();
|
|
|
|
void StartGlowing();
|
2010-05-17 01:55:00 +02:00
|
|
|
void JumpToCurrentlyPlayingTrack();
|
2011-02-10 21:55:19 +01:00
|
|
|
void JumpToLastPlayedTrack();
|
2010-03-26 00:48:58 +01:00
|
|
|
void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint);
|
2010-11-20 21:00:40 +01:00
|
|
|
void DynamicModeChanged(bool dynamic);
|
2011-11-12 17:12:03 +01:00
|
|
|
void SetColumnAlignment(int section, Qt::Alignment alignment);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2012-01-29 20:24:13 +01:00
|
|
|
void CopyCurrentSongToClipboard() const;
|
2014-02-07 16:34:20 +01:00
|
|
|
void CurrentSongChanged(const Song& new_song, const QString& uri,
|
|
|
|
const QImage& cover_art);
|
2012-03-13 23:15:53 +01:00
|
|
|
void PlayerStopped();
|
2012-01-29 20:24:13 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
signals:
|
2011-02-24 00:59:12 +01:00
|
|
|
void PlayItem(const QModelIndex& index);
|
|
|
|
void PlayPause();
|
2010-01-15 17:22:19 +01:00
|
|
|
void RightClicked(const QPoint& global_pos, const QModelIndex& index);
|
2011-01-27 00:20:56 +01:00
|
|
|
void SeekTrack(int gap);
|
2014-02-07 16:34:20 +01:00
|
|
|
void FocusOnFilterSignal(QKeyEvent* event);
|
2011-06-08 16:48:43 +02:00
|
|
|
void BackgroundPropertyChanged();
|
2011-11-12 17:12:03 +01:00
|
|
|
void ColumnAlignmentChanged(const ColumnAlignmentMap& alignment);
|
2010-01-14 15:38:27 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
protected:
|
2011-09-27 23:28:12 +02:00
|
|
|
// QWidget
|
2012-01-29 20:24:13 +01:00
|
|
|
void keyPressEvent(QKeyEvent* event);
|
2010-11-21 00:20:27 +01:00
|
|
|
void contextMenuEvent(QContextMenuEvent* e);
|
2009-12-24 20:16:07 +01:00
|
|
|
void hideEvent(QHideEvent* event);
|
|
|
|
void showEvent(QShowEvent* event);
|
2010-10-17 23:56:19 +02:00
|
|
|
void timerEvent(QTimerEvent* event);
|
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
|
|
|
void mousePressEvent(QMouseEvent* event);
|
|
|
|
void leaveEvent(QEvent*);
|
2014-02-07 16:34:20 +01:00
|
|
|
void paintEvent(QPaintEvent* event);
|
|
|
|
void dragMoveEvent(QDragMoveEvent* event);
|
|
|
|
void dragEnterEvent(QDragEnterEvent* event);
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent* event);
|
|
|
|
void dropEvent(QDropEvent* event);
|
2010-11-20 21:00:40 +01:00
|
|
|
void resizeEvent(QResizeEvent* event);
|
2010-11-21 00:20:27 +01:00
|
|
|
bool eventFilter(QObject* object, QEvent* event);
|
2014-01-14 10:07:03 +01:00
|
|
|
void focusInEvent(QFocusEvent* event);
|
2010-04-09 00:59:02 +02:00
|
|
|
|
2011-09-27 23:28:12 +02:00
|
|
|
// QAbstractScrollArea
|
|
|
|
void scrollContentsBy(int dx, int dy);
|
|
|
|
|
|
|
|
// QAbstractItemView
|
|
|
|
void rowsInserted(const QModelIndex& parent, int start, int end);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private slots:
|
|
|
|
void LoadGeometry();
|
|
|
|
void SaveGeometry();
|
|
|
|
void GlowIntensityChanged();
|
2010-04-09 00:59:02 +02:00
|
|
|
void InhibitAutoscrollTimeout();
|
2010-04-14 15:07:21 +02:00
|
|
|
void MaybeAutoscroll();
|
2010-06-02 15:51:16 +02:00
|
|
|
void InvalidateCachedCurrentPixmap();
|
2010-07-11 22:23:34 +02:00
|
|
|
void PlaylistDestroyed();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-08-27 14:42:06 +02:00
|
|
|
void SaveSettings();
|
|
|
|
void StretchChanged(bool stretch);
|
|
|
|
|
2010-10-24 01:30:38 +02:00
|
|
|
void RatingHoverIn(const QModelIndex& index, const QPoint& pos);
|
|
|
|
void RatingHoverOut();
|
|
|
|
|
2012-03-16 22:39:39 +01:00
|
|
|
void FadePreviousBackgroundImage(qreal value);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private:
|
|
|
|
void ReloadBarPixmaps();
|
|
|
|
QList<QPixmap> LoadBarPixmap(const QString& filename);
|
2010-09-07 00:49:15 +02:00
|
|
|
void UpdateCachedCurrentRowPixmap(QStyleOptionViewItemV4 option,
|
2010-05-27 22:31:00 +02:00
|
|
|
const QModelIndex& index);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void set_background_image_type(BackgroundImageType bg) {
|
|
|
|
background_image_type_ = bg;
|
|
|
|
emit BackgroundPropertyChanged();
|
|
|
|
}
|
|
|
|
// Save image as the background_image_ after applying some modifications
|
|
|
|
// (opacity, ...).
|
2012-03-10 18:55:22 +01:00
|
|
|
// Should be used instead of modifying background_image_ directly
|
|
|
|
void set_background_image(const QImage& image);
|
2011-06-08 16:48:43 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private:
|
|
|
|
static const int kGlowIntensitySteps;
|
2010-04-09 00:59:02 +02:00
|
|
|
static const int kAutoscrollGraceTimeout;
|
2010-04-24 14:18:42 +02:00
|
|
|
static const int kDropIndicatorWidth;
|
|
|
|
static const int kDropIndicatorGradientWidth;
|
2013-02-15 13:41:56 +01:00
|
|
|
|
2010-03-26 00:48:58 +01:00
|
|
|
QList<int> GetEditableColumns();
|
|
|
|
QModelIndex NextEditableIndex(const QModelIndex& current);
|
|
|
|
QModelIndex PrevEditableIndex(const QModelIndex& current);
|
|
|
|
|
2010-11-20 21:00:40 +01:00
|
|
|
void RepositionDynamicControls();
|
2012-03-06 13:40:19 +01:00
|
|
|
|
2012-03-03 01:20:37 +01:00
|
|
|
Application* app_;
|
2010-09-07 00:49:15 +02:00
|
|
|
PlaylistProxyStyle* style_;
|
2010-05-22 18:36:13 +02:00
|
|
|
Playlist* playlist_;
|
2010-08-27 14:42:06 +02:00
|
|
|
PlaylistHeader* header_;
|
2010-08-27 15:15:32 +02:00
|
|
|
bool setting_initial_header_layout_;
|
2011-07-24 13:46:31 +02:00
|
|
|
bool upgrading_from_qheaderview_;
|
2010-10-29 20:58:43 +02:00
|
|
|
bool read_only_settings_;
|
2012-01-04 19:45:08 +01:00
|
|
|
int upgrading_from_version_;
|
2010-05-22 18:36:13 +02:00
|
|
|
|
2012-02-18 19:57:36 +01:00
|
|
|
BackgroundImageType background_image_type_;
|
2012-03-10 18:55:22 +01:00
|
|
|
// Stores the background image to be displayed. As we want this image to be
|
|
|
|
// particular (in terms of format, opacity), you should probably use
|
|
|
|
// set_background_image_type instead of modifying background_image_ directly
|
2012-03-06 13:40:19 +01:00
|
|
|
QImage background_image_;
|
2012-11-09 20:17:26 +01:00
|
|
|
int blur_radius_;
|
2013-02-15 13:41:56 +01:00
|
|
|
int opacity_level_;
|
2012-03-16 22:39:39 +01:00
|
|
|
// Used if background image is a filemane
|
|
|
|
QString background_image_filename_;
|
2012-03-06 13:40:19 +01:00
|
|
|
QImage current_song_cover_art_;
|
2012-02-18 19:57:36 +01:00
|
|
|
QPixmap cached_scaled_background_image_;
|
2013-02-15 13:41:56 +01:00
|
|
|
|
2012-03-16 22:39:39 +01:00
|
|
|
// For fading when image change
|
|
|
|
QPixmap previous_background_image_;
|
|
|
|
qreal previous_background_image_opacity_;
|
|
|
|
QTimeLine* fade_animation_;
|
2013-02-15 13:41:56 +01:00
|
|
|
|
2012-03-16 22:39:39 +01:00
|
|
|
// To know if we should redraw the background or not
|
2012-02-18 19:57:36 +01:00
|
|
|
int last_height_;
|
|
|
|
int last_width_;
|
2012-02-19 22:40:58 +01:00
|
|
|
bool force_background_redraw_;
|
2011-06-08 16:48:43 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
bool glow_enabled_;
|
2010-08-27 12:36:01 +02:00
|
|
|
bool currently_glowing_;
|
2010-04-28 13:09:57 +02:00
|
|
|
QBasicTimer glow_timer_;
|
2009-12-24 20:16:07 +01:00
|
|
|
int glow_intensity_step_;
|
|
|
|
QModelIndex last_current_item_;
|
|
|
|
QRect last_glow_rect_;
|
|
|
|
|
2010-10-17 23:56:19 +02:00
|
|
|
RatingItemDelegate* rating_delegate_;
|
|
|
|
|
2010-04-09 00:59:02 +02:00
|
|
|
QTimer* inhibit_autoscroll_timer_;
|
|
|
|
bool inhibit_autoscroll_;
|
2010-04-14 15:11:39 +02:00
|
|
|
bool currently_autoscrolling_;
|
2010-04-09 00:59:02 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int row_height_; // Used to invalidate the currenttrack_bar pixmaps
|
2009-12-24 20:16:07 +01:00
|
|
|
QList<QPixmap> currenttrack_bar_left_;
|
|
|
|
QList<QPixmap> currenttrack_bar_mid_;
|
|
|
|
QList<QPixmap> currenttrack_bar_right_;
|
|
|
|
QPixmap currenttrack_play_;
|
|
|
|
QPixmap currenttrack_pause_;
|
2010-04-23 15:10:03 +02:00
|
|
|
|
2010-10-23 22:58:20 +02:00
|
|
|
QRegion current_paint_region_;
|
2010-05-27 22:31:00 +02:00
|
|
|
QPixmap cached_current_row_;
|
|
|
|
QRect cached_current_row_rect_;
|
|
|
|
int cached_current_row_row_;
|
|
|
|
|
2010-06-20 21:02:19 +02:00
|
|
|
QPixmap cached_tree_;
|
2010-04-23 15:10:03 +02:00
|
|
|
int drop_indicator_row_;
|
2010-12-06 23:18:00 +01:00
|
|
|
bool drag_over_;
|
2010-11-20 21:00:40 +01:00
|
|
|
|
|
|
|
DynamicPlaylistControls* dynamic_controls_;
|
2011-11-12 17:12:03 +01:00
|
|
|
|
|
|
|
ColumnAlignmentMap column_alignment_;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // PLAYLISTVIEW_H
|