#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include "fileDialog.h"
#include <QtWidgets/QDialog>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QCheckBox>
#include <map>
#include <array>
#include <utility>
#include <filesystem>
MString ExampleFileDialog::fLoadPath;
void* ExampleFileDialog::widget()
{
QWidget* displayWidget = new QWidget();
QVBoxLayout* mainLayout = new QVBoxLayout(displayWidget);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
displayWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
fSelectedFiles.clear();
QVBoxLayout* fileSelectionLayout = new QVBoxLayout();
fileSelectionLayout->setContentsMargins(0, 0, 0, 0);
fileSelectionLayout->setSpacing(5);
const char* file1 = "cone.ma";
const char* file2 = "cylinder.abc";
const char* file3 = "script.py";
std::filesystem::path pathFile1 = std::filesystem::path(ExampleFileDialog::fLoadPath.asChar()) / file1;
std::filesystem::path pathFile2 = std::filesystem::path(ExampleFileDialog::fLoadPath.asChar()) / file2;
std::filesystem::path pathFile3 = std::filesystem::path(ExampleFileDialog::fLoadPath.asChar()) / file3;
QCheckBox* file1Checkbox = new QCheckBox(file1);
QCheckBox* file2Checkbox = new QCheckBox(file2);
QCheckBox* file3Checkbox = new QCheckBox(file3);
fileSelectionLayout->addWidget(file1Checkbox);
fileSelectionLayout->addWidget(file2Checkbox);
fileSelectionLayout->addWidget(file3Checkbox);
mainLayout->addLayout(fileSelectionLayout);
auto buttonAction = [this](const auto* filepath, QCheckBox* checkbox) {
if (checkbox->isChecked()) {
fSelectedFiles.append(filepath);
} else {
fSelectedFiles.remove(fSelectedFiles.indexOf(filepath));
}
};
QObject::connect(file1Checkbox, &QCheckBox::checkStateChanged, [file1Checkbox, pathFile1, buttonAction]() {
buttonAction(pathFile1.c_str(), file1Checkbox);
});
QObject::connect(file2Checkbox, &QCheckBox::checkStateChanged, [file2Checkbox, pathFile2, buttonAction]() {
buttonAction(pathFile2.c_str(), file2Checkbox);
});
QObject::connect(file3Checkbox, &QCheckBox::checkStateChanged, [file3Checkbox, pathFile3, buttonAction]() {
buttonAction(pathFile3.c_str(), file3Checkbox);
});
QHBoxLayout* buttonLayout = new QHBoxLayout();
buttonLayout->setContentsMargins(0, 0, 0, 0);
buttonLayout->setSpacing(5);
mainLayout->addLayout(buttonLayout);
QPushButton* cancelButton = new QPushButton("Cancel");
buttonLayout->addWidget(cancelButton);
QObject::connect(cancelButton, &QPushButton::clicked, [this]() {
this->done(QDialog::Rejected);
this->reject();
});
QPushButton* openButton = new QPushButton("Open");
buttonLayout->addWidget(openButton);
QObject::connect(openButton, &QPushButton::clicked, [this]() {
this->done(QDialog::Accepted);
this->accept();
});
return displayWidget;
}
{
return fSelectedFiles;
}
{
MFnPlugin pluginFn(plugin,
"Autodesk, Inc.",
"1.0",
"Any", &st);
if (!st) {
MString(
"fileDialog - could not initialize plugin: ")
);
return st;
}
st = pluginFn.registerFileDialog(
"fileDialog",
ExampleFileDialog::creator
);
if (!st) {
MString(
"fileDialog - could not register '")
);
return st;
}
ExampleFileDialog::fLoadPath = pluginFn.loadPath();
return st;
}
{
MFnPlugin pluginFn(plugin,
"Autodesk, Inc.",
"1.0",
"Any", &st);
if (!st) {
MString(
"fileDialog - could not uninitialize plugin: ")
);
return st;
}
st = pluginFn.deregisterFileDialog(
"fileDialog"
);
if (!st) {
MString(
"qtForms - could not deregister '")
);
return st;
}
return st;
}