1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
Change the value of EXAMPLE_COMPLEXITY in the first line to change the behavior :
- 0 : prints "Hello World!" in the Info and console widgets
- 1 : pops-up a simple dialog asking to enter an integer , then prints it in the Info and console widgets
- 2 : pops-up a little more elaborated dialog asking to enter an integer , then prints it in the Info and console widgets if it was indeed an integer, else pops-up an error message box.
*/
#define EXAMPLE_COMPLEXITY 0
#include "ui_Basic_dialog.h"
//! [headers_plugin]
#include <CGAL/Three/CGAL_Lab_plugin_interface.h>
#include <QApplication>
#include <QObject>
#include <QAction>
#include <QMainWindow>
#include <QInputDialog>
#include <QMessageBox>
#include "CGAL/Three/Three.h"
//! [headers_plugin]
//! [dialog_plugin]
class ComplexDialog :
public QDialog,
public Ui::BasicDialog
{
Q_OBJECT
public:
ComplexDialog(QWidget* =0)
{
setupUi(this);
}
};
//! [dialog_plugin]
//! [opening_plugin]
//This plugin creates an action in Operations depending on EXAMPLE_COMPLEXITY.
class BasicPlugin :
public QObject,
public CGAL::Three::CGAL_Lab_plugin_interface
{
Q_OBJECT
Q_INTERFACES(CGAL::Three::CGAL_Lab_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.PluginInterface/1.0")
public:
//decides if the plugin's actions will be displayed or not.
bool applicable(QAction*) const override
{
return true;
}
//the list of the actions of the plugin.
QList<QAction*> actions() const override
{
return _actions;
}
//this acts like a constructor for the plugin. It gets the references to the main window and the scene, and connects the action.
void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* sc, Messages_interface*) override
{
//get the references
this->scene = sc;
this->mw = mainWindow;
//creates the action
QAction *actionHelloWorld= new QAction(QString("Hello World"), mw);
//specifies the subMenu
actionHelloWorld->setProperty("submenuName", "Basic");
//links the action
if(actionHelloWorld) {
connect(actionHelloWorld, SIGNAL(triggered()),
this, SLOT(helloWorld()));
_actions << actionHelloWorld;
}
}
private Q_SLOTS:
//! [opening_plugin]
#if EXAMPLE_COMPLEXITY == 0
//! [basic_plugin]
void helloWorld()
{
CGAL::Three::Three::information(QString("Hello World!"));
}
//! [basic_plugin]
#elif EXAMPLE_COMPLEXITY == 1
//! [basic_dialog_plugin]
void helloWorld()
{
bool ok = false;
const unsigned int parameter =
QInputDialog::getInt((QWidget*)mw,
tr("Hello World"), // dialog title
tr("Hello dear user! What integer would you want me to display for you ? "), // field label
10, // default value = fast
0, // min
100, // max
1, // step
&ok);
if(!ok) return;
messageInterface->information(QString("You asked me to display %1, so here it is : %1").arg(parameter));
}
//! [basic_dialog_plugin]
#elif EXAMPLE_COMPLEXITY == 2
//! [complex_dialog_plugin]
void helloWorld()
{
//creates a new dialog
ComplexDialog *dialog = new ComplexDialog();
//opens the dialog
if(!dialog->exec())
return;
//! [warningbox]
QString result = dialog->lineEdit->text();
bool ok = false;
int int_res = result.toInt(&ok);
if(!ok)
{
QMessageBox::warning(mw,
"ERROR",
tr("This is not an integer !")
);
return;
}
//! [warningbox]
messageInterface->information(QString("You asked me to display %1, so here it is : %1").arg(int_res));
}
//! [complex_dialog_plugin]
#endif
//! [ending_plugin]
private:
QList<QAction*> _actions;
//The reference to the scene
CGAL::Three::Scene_interface* scene;
//The reference to the main window
QMainWindow* mw;
};
#include "Basic_plugin.moc"
//! [ending_plugin]
|