Skip to content

Commit

Permalink
WTrackProperty: show simple editor on delayed double-click
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jul 22, 2023
1 parent 92c22d4 commit ba395ea
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WTrackProperty::WTrackProperty(
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
setAcceptDrops(true);
resetClickInterval();
}

WTrackProperty::~WTrackProperty() {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}
17 changes: 17 additions & 0 deletions src/widget/wtrackproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

#include <QDragEnterEvent>
#include <QDropEvent>
#include <QLineEdit>
#include <QMouseEvent>

#include "preferences/usersettings.h"
#include "skin/legacy/skincontext.h"
#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"

Expand Down Expand Up @@ -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<WTrackMenu> m_pTrackMenu;
};

class PropertyEditor : public QLineEdit {
Q_OBJECT
public:
PropertyEditor(WTrackProperty* pParent);

private:
void keyPressEvent(QKeyEvent* pEvent) override;
};

0 comments on commit ba395ea

Please sign in to comment.