When pressing Ctrl+C on a playlist item, copy the text of all visible columns, rather than just the text of the "current" one. Fixes issue 2558
This commit is contained in:
parent
281d69581c
commit
7166f0d922
@ -23,6 +23,7 @@
|
||||
#include "core/logging.h"
|
||||
|
||||
#include <QCleanlooksStyle>
|
||||
#include <QClipboard>
|
||||
#include <QPainter>
|
||||
#include <QHeaderView>
|
||||
#include <QSettings>
|
||||
@ -467,11 +468,9 @@ bool CompareSelectionRanges(const QItemSelectionRange& a, const QItemSelectionRa
|
||||
}
|
||||
|
||||
void PlaylistView::keyPressEvent(QKeyEvent* event) {
|
||||
if (!model()) {
|
||||
if (!model() || state() == QAbstractItemView::EditingState) {
|
||||
QTreeView::keyPressEvent(event);
|
||||
} else if (state() == QAbstractItemView::EditingState) {
|
||||
QTreeView::keyPressEvent(event);
|
||||
} else if (event->matches(QKeySequence::Delete)) {
|
||||
} else if (event == QKeySequence::Delete) {
|
||||
RemoveSelected();
|
||||
event->accept();
|
||||
#ifdef Q_OS_DARWIN
|
||||
@ -479,6 +478,8 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
|
||||
RemoveSelected();
|
||||
event->accept();
|
||||
#endif
|
||||
} else if (event == QKeySequence::Copy) {
|
||||
CopyCurrentSongToClipboard();
|
||||
} else if (event->key() == Qt::Key_Enter ||
|
||||
event->key() == Qt::Key_Return) {
|
||||
if (currentIndex().isValid())
|
||||
@ -1006,3 +1007,30 @@ void PlaylistView::SetColumnAlignment(int section, Qt::Alignment alignment) {
|
||||
Qt::Alignment PlaylistView::column_alignment(int section) const {
|
||||
return column_alignment_.value(section, Qt::AlignLeft | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
void PlaylistView::CopyCurrentSongToClipboard() const {
|
||||
// Get the display text of all visible columns.
|
||||
QStringList columns;
|
||||
|
||||
for (int i=0 ; i<header()->count() ; ++i) {
|
||||
if (header()->isSectionHidden(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QVariant data = model()->data(
|
||||
currentIndex().sibling(currentIndex().row(), i));
|
||||
if (data.type() == QVariant::String) {
|
||||
columns << data.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the song's URL
|
||||
const QUrl url = model()->data(currentIndex().sibling(
|
||||
currentIndex().row(), Playlist::Column_Filename)).toUrl();
|
||||
|
||||
QMimeData* mime_data = new QMimeData;
|
||||
mime_data->setUrls(QList<QUrl>() << url);
|
||||
mime_data->setText(columns.join(" - "));
|
||||
|
||||
QApplication::clipboard()->setMimeData(mime_data);
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ class PlaylistView : public QTreeView {
|
||||
// QTreeView
|
||||
void drawTree(QPainter* painter, const QRegion& region) const;
|
||||
void drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void setModel(QAbstractItemModel* model);
|
||||
|
||||
public slots:
|
||||
@ -95,6 +94,8 @@ class PlaylistView : public QTreeView {
|
||||
void DynamicModeChanged(bool dynamic);
|
||||
void SetColumnAlignment(int section, Qt::Alignment alignment);
|
||||
|
||||
void CopyCurrentSongToClipboard() const;
|
||||
|
||||
signals:
|
||||
void PlayItem(const QModelIndex& index);
|
||||
void PlayPause();
|
||||
@ -106,6 +107,7 @@ class PlaylistView : public QTreeView {
|
||||
|
||||
protected:
|
||||
// QWidget
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void contextMenuEvent(QContextMenuEvent* e);
|
||||
void hideEvent(QHideEvent* event);
|
||||
void showEvent(QShowEvent* event);
|
||||
|
Loading…
x
Reference in New Issue
Block a user