Salome HOME
Avoid direct link to SketchPlugin
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
1 // File:        PartSet_WidgetSketchLabel.cpp
2 // Created:     07 July 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "PartSet_WidgetSketchLabel.h"
6 #include "PartSet_OperationSketch.h"
7
8 #include <ModuleBase_Operation.h>
9 #include <XGUI_OperationMgr.h>
10
11 #include <Config_WidgetAPI.h>
12
13 #include <QLabel>
14
15 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
16                                                      const Config_WidgetAPI* theData,
17                                                      const std::string& theParentId)
18     : ModuleBase_ModelWidget(theParent, theData, theParentId)
19 {
20   myText = QString::fromStdString(theData->getProperty("title"));
21   myLabel = new QLabel(myText, theParent);
22   myLabel->setWordWrap(true);
23   myTooltip = QString::fromStdString(theData->getProperty("tooltip"));
24   myLabel->setToolTip(myTooltip);
25 }
26
27 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
28 {
29   QList<QWidget*> aLst;
30   aLst << myLabel;
31   return aLst;
32 }
33
34 QWidget* PartSet_WidgetSketchLabel::getControl() const
35 {
36   return myLabel;
37 }
38
39 void PartSet_WidgetSketchLabel::setOperationsMgr(XGUI_OperationMgr* theMgr)
40 {
41   ModuleBase_Operation* aOperation = theMgr->currentOperation();
42   if (aOperation->inherits("PartSet_OperationSketch")) {
43     PartSet_OperationSketch* aSketchOpe = static_cast<PartSet_OperationSketch*>(aOperation);
44     updateLabel(aSketchOpe);
45     connect(aSketchOpe, SIGNAL(planeSelected(double, double, double)), this,
46             SLOT(onPlaneSelected()));
47   }
48 }
49
50 void PartSet_WidgetSketchLabel::onPlaneSelected()
51 {
52   PartSet_OperationSketch* aSketchOpe = static_cast<PartSet_OperationSketch*>(sender());
53   updateLabel(aSketchOpe);
54 }
55
56 void PartSet_WidgetSketchLabel::updateLabel(PartSet_OperationSketch* theSketchOpe)
57 {
58   if (theSketchOpe->hasSketchPlane()) {
59     myLabel->setText("");
60     myLabel->setToolTip("");
61   } else {
62     myLabel->setText(myText);
63     myLabel->setToolTip(myTooltip);
64   }
65 }