diff --git a/src/widget/wtrackproperty.cpp b/src/widget/wtrackproperty.cpp index b9c871f3169b..f213dda3fe66 100644 --- a/src/widget/wtrackproperty.cpp +++ b/src/widget/wtrackproperty.cpp @@ -38,6 +38,7 @@ WTrackProperty::WTrackProperty( m_pTrackMenu(make_parented( this, pConfig, pLibrary, kTrackMenuFeatures)) { setAcceptDrops(true); + resetClickInterval(); } WTrackProperty::~WTrackProperty() { @@ -99,9 +100,47 @@ void WTrackProperty::mouseMoveEvent(QMouseEvent* event) { } } +void WTrackProperty::mousePressEvent(QMouseEvent* event) { + if (event->buttons().testFlag(Qt::LeftButton) && m_pCurrentTrack) { + if (m_clickElapsed > mixxx::Duration::fromMillis(0) && + (mixxx::Time::elapsed() - m_clickElapsed) > mixxx::Duration::fromMillis(300)) { + // reset elapsed if interval is longer than 2s + if (mixxx::Time::elapsed() - m_clickElapsed > mixxx::Duration::fromMillis(2000)) { + resetClickInterval(); + return; + } + + // create editor, populate and connect signals + auto* ed = new PropertyEditor(this); + connect(ed, + &QLineEdit::editingFinished, + this, + [this, ed]() { + resetClickInterval(); + ed->hide(); + QString txt = ed->text(); + if (txt != text()) { // commit new data + const QVariant var(QVariant::fromValue(txt)); + m_pCurrentTrack->setProperty( + m_property.toUtf8().constData(), + var); + } + }); + ed->setFixedSize(size()); + ed->setText(text()); + ed->show(); + ed->setFocus(); + return; + } + + m_clickElapsed = mixxx::Time::elapsed(); + } +} + void WTrackProperty::mouseDoubleClickEvent(QMouseEvent* event) { Q_UNUSED(event); if (m_pCurrentTrack) { + resetClickInterval(); m_pTrackMenu->loadTrack(m_pCurrentTrack, m_group); m_pTrackMenu->slotShowDlgTrackInfo(); } @@ -123,3 +162,15 @@ void WTrackProperty::contextMenuEvent(QContextMenuEvent* event) { m_pTrackMenu->popup(event->globalPos()); } } + +PropertyEditor::PropertyEditor(WTrackProperty* pParent) + : QLineEdit(pParent->toQWidget()) { +} + +void PropertyEditor::keyPressEvent(QKeyEvent* pEvent) { + if (pEvent->key() == Qt::Key_Escape) { + close(); + return; + } + QLineEdit::keyPressEvent(pEvent); +} diff --git a/src/widget/wtrackproperty.h b/src/widget/wtrackproperty.h index d2cd7f4e9fa7..baae2a15211e 100644 --- a/src/widget/wtrackproperty.h +++ b/src/widget/wtrackproperty.h @@ -2,6 +2,7 @@ #include #include +#include #include #include "preferences/usersettings.h" @@ -9,6 +10,7 @@ #include "track/track_decl.h" #include "track/trackid.h" #include "util/parented_ptr.h" +#include "util/time.h" #include "widget/trackdroptarget.h" #include "widget/wlabel.h" @@ -45,14 +47,29 @@ private slots: void dragEnterEvent(QDragEnterEvent* event) override; void dropEvent(QDropEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; void mouseDoubleClickEvent(QMouseEvent* event) override; + void resetClickInterval() { + m_clickElapsed = mixxx::Duration::fromMillis(0); + } + void updateLabel(); const QString m_group; const UserSettingsPointer m_pConfig; TrackPointer m_pCurrentTrack; QString m_property; + mixxx::Duration m_clickElapsed; const parented_ptr m_pTrackMenu; }; + +class PropertyEditor : public QLineEdit { + Q_OBJECT + public: + PropertyEditor(WTrackProperty* pParent); + + private: + void keyPressEvent(QKeyEvent* pEvent) override; +};