#include <workspaceControlCmd.h>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>
#include <maya/MArgParser.h>
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <maya/MObject.h>
#include <maya/MQtUtil.h>
#include <maya/MSyntax.h>
#define kReloadFlag "-rl"
#define kReloadFlagLong "-reload"
QPointer<QWidget> WorkspaceControlCmd::workspaceControl;
const MString WorkspaceControlCmd::commandName(
"workspaceControlWindow");
void WorkspaceControlCmd::cleanup()
{
if(!workspaceControl.isNull()) {
MString closeCommand(
"workspaceControl -e -close customWorkspaceControl");
}
}
bool WorkspaceControlCmd::hasSyntax()
{
return true;
}
MSyntax WorkspaceControlCmd::newSyntax()
{
syntax.
addFlag( kReloadFlag, kReloadFlagLong );
return syntax;
}
{
if(!workspaceControl.isNull()) {
MString restoreCommand(
"workspaceControl -e -restore customWorkspaceControl");
} else {
bool doReload = argParser.isFlagSet( kReloadFlag );
if (!doReload) {
MGlobal::executeCommand(
"workspaceControl -label \"Custom Workspace Control\" -retain false -loadImmediately true -floating true -initialWidth 400 -initialHeight 200 -requiredPlugin \"workspaceControlCmd\" customWorkspaceControl");
}
QWidget *uiWidget = new QWidget();
QVBoxLayout *uiLayout = new QVBoxLayout();
QLabel *uiLabel = new QLabel("Hello World!");
uiLabel->setAlignment(Qt::AlignCenter);
uiLayout->addWidget(uiLabel);
uiWidget->setLayout(uiLayout);
if (!doReload) {
MString uiScriptCommand(
"workspaceControl -e -uiScript \"workspaceControlWindow -reload\" customWorkspaceControl");
}
}
}
{
MFnPlugin pluginFn(plugin,
"Autodesk, Inc.",
"1.0",
"Any", &st);
if (!st) {
MString(
"workspaceControlCmd - could not initialize plugin: ")
);
return st;
}
st = pluginFn.registerCommand(WorkspaceControlCmd::commandName, WorkspaceControlCmd::creator, WorkspaceControlCmd::newSyntax);
if (!st) {
MString(
"workspaceControlCmd - could not register '")
+ WorkspaceControlCmd::commandName + "' command: "
);
return st;
}
return st;
}
{
MFnPlugin pluginFn(plugin,
"Autodesk, Inc.",
"1.0",
"Any", &st);
if (!st) {
MString(
"workspaceControlCmd - could not uninitialize plugin: ")
);
return st;
}
WorkspaceControlCmd::cleanup();
st = pluginFn.deregisterCommand(WorkspaceControlCmd::commandName);
if (!st) {
MString(
"workspaceControlCmd - could not deregister '")
+ WorkspaceControlCmd::commandName + "' command: "
);
return st;
}
return st;
}