Skip to content

Commit

Permalink
Add ability to drag & drop files onto soundboard
Browse files Browse the repository at this point in the history
  • Loading branch information
cg2121 committed Jun 7, 2024
1 parent 05121ae commit 763b503
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Soundboard.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<height>317</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>Soundboard</string>
</property>
Expand Down
27 changes: 27 additions & 0 deletions src/soundboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <QListWidget>
#include <QActionGroup>
#include <QLineEdit>
#include <QMimeData>
#include <QFileInfo>

#include "scene-tree.hpp"
#include "media-controls.hpp"
Expand Down Expand Up @@ -544,6 +546,31 @@ void Soundboard::on_actionFilters_triggered()
obs_frontend_open_source_filters(source);
}

void Soundboard::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls())
event->acceptProposedAction();
}

void Soundboard::dropEvent(QDropEvent *event)
{
QStringList supportedExt;
supportedExt << ".mp3" << ".aac" << ".ogg" << ".wav" << ".flac";

foreach(const QUrl &url, event->mimeData()->urls())
{
QString path = url.toLocalFile();
QFileInfo fi(path);
QString name = fi.fileName();
QString ext = QString(".") + fi.completeSuffix();

if (!supportedExt.contains(ext))
continue;

Add(name, path);
}
}

void Soundboard::EditMediaName()
{
removeAction(renameMedia);
Expand Down
4 changes: 4 additions & 0 deletions src/soundboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ private slots:
void Load(OBSData saveData);

void CreateSource();

protected:
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void dropEvent(QDropEvent *event) override;
};

class MediaRenameDelegate : public QStyledItemDelegate {
Expand Down

0 comments on commit 763b503

Please sign in to comment.