Add ability to drag and drop plugin files into the UI
This commit is contained in:
parent
70a2fa81c8
commit
4f62d68f6d
6 changed files with 116 additions and 7 deletions
|
|
@ -175,7 +175,8 @@ HEADERS +=
|
|||
qt/DeviceView.h \
|
||||
qt/OpenRGBDialog2.h \
|
||||
qt/OpenRGBPluginContainer.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsList.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.h \
|
||||
qt/OpenRGBProfileSaveDialog.h \
|
||||
qt/OpenRGBServerInfoPage.h \
|
||||
|
|
@ -507,7 +508,8 @@ SOURCES +=
|
|||
qt/DeviceView.cpp \
|
||||
qt/OpenRGBDialog2.cpp \
|
||||
qt/OpenRGBPluginContainer.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsList.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.cpp \
|
||||
qt/OpenRGBProfileSaveDialog.cpp \
|
||||
qt/OpenRGBServerInfoPage.cpp \
|
||||
|
|
@ -861,7 +863,7 @@ FORMS +=
|
|||
qt/OpenRGBDialog.ui \
|
||||
qt/OpenRGBDialog2.ui \
|
||||
qt/OpenRGBPluginContainer.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.ui \
|
||||
qt/OpenRGBProfileSaveDialog.ui \
|
||||
qt/OpenRGBServerInfoPage.ui \
|
||||
|
|
|
|||
45
qt/OpenRGBPluginsPage/OpenRGBPluginsList.cpp
Normal file
45
qt/OpenRGBPluginsPage/OpenRGBPluginsList.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include "OpenRGBPluginsList.h"
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
|
||||
OpenRGBPluginsList::OpenRGBPluginsList(QWidget *parent) : QListWidget (parent)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void OpenRGBPluginsList::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
|
||||
if (mimeData->hasUrls())
|
||||
{
|
||||
std::vector<std::string> path_list;
|
||||
|
||||
QList<QUrl> urls = mimeData->urls();
|
||||
|
||||
for(const QUrl& url: urls)
|
||||
{
|
||||
path_list.push_back(url.toLocalFile().toStdString());
|
||||
}
|
||||
|
||||
emit PluginsDropped(path_list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OpenRGBPluginsList::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsList::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
24
qt/OpenRGBPluginsPage/OpenRGBPluginsList.h
Normal file
24
qt/OpenRGBPluginsPage/OpenRGBPluginsList.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef OPENRGBPLUGINSLIST_H
|
||||
#define OPENRGBPLUGINSLIST_H
|
||||
|
||||
#include <QListWidget>
|
||||
#include <QDropEvent>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
class OpenRGBPluginsList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OpenRGBPluginsList(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void PluginsDropped(std::vector<std::string>);
|
||||
|
||||
protected:
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // OPENRGBPLUGINSLIST_H
|
||||
|
|
@ -88,7 +88,17 @@ void Ui::OpenRGBPluginsPage::on_InstallPluginButton_clicked()
|
|||
\*-----------------------------------------------------*/
|
||||
QString install_file = QFileDialog::getOpenFileName(this, "Install OpenRGB Plugin", "", "DLL Files (*.dll; *.dylib; *.so; *.so.*)");
|
||||
|
||||
std::string from_path = install_file.toStdString();
|
||||
bool installed = InstallPlugin(install_file.toStdString());
|
||||
|
||||
if(installed)
|
||||
{
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
bool Ui::OpenRGBPluginsPage::InstallPlugin(std::string install_file)
|
||||
{
|
||||
std::string from_path = install_file;
|
||||
std::string to_path = ResourceManager::get()->GetConfigurationDirectory() + "plugins/";
|
||||
std::string to_file = to_path + filesystem::path(from_path).filename().string();
|
||||
bool match = false;
|
||||
|
|
@ -116,7 +126,7 @@ void Ui::OpenRGBPluginsPage::on_InstallPluginButton_clicked()
|
|||
|
||||
if(reply != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,12 +142,14 @@ void Ui::OpenRGBPluginsPage::on_InstallPluginButton_clicked()
|
|||
|
||||
plugin_manager->AddPlugin(to_file);
|
||||
|
||||
RefreshList();
|
||||
return true;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
||||
|
|
@ -306,3 +318,19 @@ void Ui::OpenRGBPluginsPage::on_PluginsList_itemSelectionChanged()
|
|||
\*-----------------------------------------------------*/
|
||||
ui->RemovePluginButton->setEnabled(!ui->PluginsList->selectedItems().empty());
|
||||
}
|
||||
|
||||
void Ui::OpenRGBPluginsPage::on_PluginsList_PluginsDropped(std::vector<std::string> path_list)
|
||||
{
|
||||
bool installed = false;
|
||||
|
||||
for(const std::string& file_path: path_list)
|
||||
{
|
||||
installed |= InstallPlugin(file_path);
|
||||
}
|
||||
|
||||
if(installed)
|
||||
{
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,15 @@ private slots:
|
|||
void on_RemovePluginButton_clicked();
|
||||
|
||||
void on_PluginsList_itemSelectionChanged();
|
||||
|
||||
void on_PluginsList_PluginsDropped(std::vector<std::string>);
|
||||
|
||||
private:
|
||||
Ui::OpenRGBPluginsPageUi* ui;
|
||||
PluginManager* plugin_manager;
|
||||
std::vector<OpenRGBPluginsEntry*> entries;
|
||||
|
||||
bool InstallPlugin(std::string path);
|
||||
void RefreshList();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="PluginsList">
|
||||
<widget class="OpenRGBPluginsList" name="PluginsList">
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
|
|
@ -40,6 +40,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>OpenRGBPluginsList</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>qt/OpenRGBPluginsPage/OpenRGBPluginsList.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue