\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 4.12 - Three
Three/Example_plugin/Dock_widget_plugin.cpp
#include "ui_Basic_dock_widget.h"
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
#include <QApplication>
#include <QObject>
#include <QAction>
#include <QMainWindow>
#include "Messages_interface.h"
class DockWidget :
public QDockWidget,
public Ui::BasicDockWidget
{
public:
DockWidget(QString name, QWidget *parent)
:QDockWidget(name,parent)
{
setupUi(this);
}
};
//This plugin crates an action in Operations that creates a DOckWidget to display a number in the 'console' dockwidet.
class BasicPlugin :
public QObject,
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")
public:
//decides if the plugin's actions will be displayed or not.
bool applicable(QAction*) const Q_DECL_OVERRIDE
{
return true;
}
//the list of the actions of the plugin.
QList<QAction*> actions() const Q_DECL_OVERRIDE
{
return _actions;
}
//this acts like a constructor for the plugin. It gets the references to the mainwindow and the scene, and connects the action.
void init(QMainWindow* mw, CGAL::Three::Scene_interface* sc, Messages_interface* mi) Q_DECL_OVERRIDE
{
//gets the reference to the message interface, to display text in the console widget
this->messageInterface = mi;
//get the references
this->scene = sc;
this->mw = mw;
//creates the action
QAction *actionHelloWorld= new QAction(QString("Open Dock Widget"), mw);
//specifies the subMenu
actionHelloWorld->setProperty("submenuName", "Basic");
//links the action
if(actionHelloWorld) {
connect(actionHelloWorld, SIGNAL(triggered()),
this, SLOT(helloWorld()));
_actions << actionHelloWorld;
}
dock_widget = new DockWidget("Print a number", mw);
dock_widget->setVisible(false); // do not show at the beginning
addDockWidget(dock_widget);
connect(dock_widget->pushButton, SIGNAL(clicked(bool)),
this, SLOT(on_dock_button_clicked()));
}
private Q_SLOTS:
void helloWorld()
{
// dock widget should be instancied in init()
if(dock_widget->isVisible()) { dock_widget->hide(); }
else { dock_widget->show(); }
}
void on_dock_button_clicked()
{
messageInterface->information(QString("Here is your number :%1").arg(dock_widget->spinBox->value()));
}
void closure()Q_DECL_OVERRIDE
{
dock_widget->hide();
}
private:
QList<QAction*> _actions;
Messages_interface* messageInterface;
DockWidget* dock_widget;
};
#include "Dock_widget_plugin.moc"