Clementine-audio-player-Mac.../src/playlist/playlistview.h

194 lines
6.0 KiB
C
Raw Normal View History

/* 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/>.
*/
2009-12-24 20:16:07 +01:00
#ifndef PLAYLISTVIEW_H
#define PLAYLISTVIEW_H
#include "playlist.h"
#include <QBasicTimer>
#include <QProxyStyle>
#include <QTreeView>
#include <boost/scoped_ptr.hpp>
class QCleanlooksStyle;
2009-12-24 20:16:07 +01:00
class DynamicPlaylistControls;
class LibraryBackend;
class PlaylistHeader;
class RadioLoadingIndicator;
class RatingItemDelegate;
2009-12-26 22:35:45 +01: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.
// This class is used by the global search view as well.
class PlaylistProxyStyle : public QProxyStyle {
public:
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;
private:
boost::scoped_ptr<QCleanlooksStyle> cleanlooks_;
};
2009-12-24 20:16:07 +01:00
class PlaylistView : public QTreeView {
Q_OBJECT
Q_PROPERTY(bool background_enabled
READ background_enabled
WRITE set_background_enabled
NOTIFY BackgroundPropertyChanged)
2009-12-24 20:16:07 +01:00
public:
PlaylistView(QWidget* parent = 0);
static const int kStateVersion;
void SetItemDelegates(LibraryBackend* backend);
2010-05-22 18:36:13 +02:00
void SetPlaylist(Playlist* playlist);
void RemoveSelected();
void SetReadOnlySettings(bool read_only) { read_only_settings_ = read_only; }
Playlist* playlist() const { return playlist_; }
bool background_enabled() const { return background_enabled_; }
2009-12-24 20:16:07 +01:00
// QTreeView
void drawTree(QPainter* painter, const QRegion& region) const;
2009-12-24 20:16:07 +01:00
void drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void keyPressEvent(QKeyEvent* event);
void setModel(QAbstractItemModel *model);
2009-12-24 20:16:07 +01:00
public slots:
void ReloadSettings();
2009-12-24 20:16:07 +01:00
void StopGlowing();
void StartGlowing();
void JumpToCurrentlyPlayingTrack();
void JumpToLastPlayedTrack();
void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint);
void DynamicModeChanged(bool dynamic);
2009-12-24 20:16:07 +01:00
2010-01-14 15:38:27 +01:00
signals:
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);
void FocusOnFilterSignal(QKeyEvent *event);
void BackgroundPropertyChanged();
2010-01-14 15:38:27 +01:00
2009-12-24 20:16:07 +01:00
protected:
void contextMenuEvent(QContextMenuEvent* e);
2009-12-24 20:16:07 +01:00
void hideEvent(QHideEvent* event);
void showEvent(QShowEvent* event);
void timerEvent(QTimerEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void leaveEvent(QEvent*);
void scrollContentsBy(int dx, int dy);
void paintEvent(QPaintEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dropEvent(QDropEvent *event);
void resizeEvent(QResizeEvent* event);
bool eventFilter(QObject* object, QEvent* event);
2009-12-24 20:16:07 +01:00
private slots:
void LoadGeometry();
void SaveGeometry();
void GlowIntensityChanged();
void InhibitAutoscrollTimeout();
void MaybeAutoscroll();
void InvalidateCachedCurrentPixmap();
void PlaylistDestroyed();
2009-12-24 20:16:07 +01:00
void SaveSettings();
void StretchChanged(bool stretch);
void RatingHoverIn(const QModelIndex& index, const QPoint& pos);
void RatingHoverOut();
2009-12-24 20:16:07 +01:00
private:
void ReloadBarPixmaps();
QList<QPixmap> LoadBarPixmap(const QString& filename);
void UpdateCachedCurrentRowPixmap(QStyleOptionViewItemV4 option,
const QModelIndex& index);
2009-12-24 20:16:07 +01:00
inline void set_background_enabled(bool bg) { background_enabled_ = bg; emit BackgroundPropertyChanged(); }
2009-12-24 20:16:07 +01:00
private:
static const int kGlowIntensitySteps;
static const int kAutoscrollGraceTimeout;
static const int kDropIndicatorWidth;
static const int kDropIndicatorGradientWidth;
2009-12-24 20:16:07 +01:00
QList<int> GetEditableColumns();
QModelIndex NextEditableIndex(const QModelIndex& current);
QModelIndex PrevEditableIndex(const QModelIndex& current);
void RepositionDynamicControls();
PlaylistProxyStyle* style_;
2010-05-22 18:36:13 +02:00
Playlist* playlist_;
PlaylistHeader* header_;
bool setting_initial_header_layout_;
bool upgrading_from_qheaderview_;
bool read_only_settings_;
2010-05-22 18:36:13 +02:00
bool background_enabled_;
2009-12-24 20:16:07 +01:00
bool glow_enabled_;
bool currently_glowing_;
QBasicTimer glow_timer_;
2009-12-24 20:16:07 +01:00
int glow_intensity_step_;
QModelIndex last_current_item_;
QRect last_glow_rect_;
RatingItemDelegate* rating_delegate_;
QTimer* inhibit_autoscroll_timer_;
bool inhibit_autoscroll_;
bool currently_autoscrolling_;
2009-12-24 20:16:07 +01:00
int row_height_; // Used to invalidate the currenttrack_bar pixmaps
QList<QPixmap> currenttrack_bar_left_;
QList<QPixmap> currenttrack_bar_mid_;
QList<QPixmap> currenttrack_bar_right_;
QPixmap currenttrack_play_;
QPixmap currenttrack_pause_;
QRegion current_paint_region_;
QPixmap cached_current_row_;
QRect cached_current_row_rect_;
int cached_current_row_row_;
QPixmap cached_tree_;
int drop_indicator_row_;
bool drag_over_;
DynamicPlaylistControls* dynamic_controls_;
2009-12-24 20:16:07 +01:00
};
#endif // PLAYLISTVIEW_H