Salome HOME
44228fdeca844f59f71fb46242f43250b712bb73
[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("", theParent);
22   myLabel->setWordWrap(true);
23   myTooltip = QString::fromStdString(theData->getProperty("tooltip"));
24   myLabel->setToolTip("");
25   myLabel->setIndent(5);
26 }
27
28 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
29 {
30   QList<QWidget*> aLst;
31   aLst << myLabel;
32   return aLst;
33 }
34
35 QWidget* PartSet_WidgetSketchLabel::getControl() const
36 {
37   return myLabel;
38 }
39
40 void PartSet_WidgetSketchLabel::setOperationsMgr(XGUI_OperationMgr* theMgr)
41 {
42   ModuleBase_Operation* aOperation = theMgr->currentOperation();
43   if (aOperation->inherits("PartSet_OperationSketch")) {
44     PartSet_OperationSketch* aSketchOpe = static_cast<PartSet_OperationSketch*>(aOperation);
45     updateLabel(aSketchOpe);
46     connect(aSketchOpe, SIGNAL(planeSelected(double, double, double)), this,
47             SLOT(onPlaneSelected()));
48   }
49 }
50
51 void PartSet_WidgetSketchLabel::onPlaneSelected()
52 {
53   PartSet_OperationSketch* aSketchOpe = static_cast<PartSet_OperationSketch*>(sender());
54   updateLabel(aSketchOpe);
55 }
56
57 void PartSet_WidgetSketchLabel::updateLabel(PartSet_OperationSketch* theSketchOpe)
58 {
59   if (theSketchOpe->hasSketchPlane()) {
60     myLabel->setText("");
61     myLabel->setToolTip("");
62   } else {
63     myLabel->setText(myText);
64     myLabel->setToolTip(myTooltip);
65   }
66 }