0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / VInspector / VInspector_ToolBar.cxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #include <inspector/VInspector_ToolBar.hxx>
17
18 #include <QHBoxLayout>
19 #include <QPushButton>
20 #include <QWidget>
21
22
23 // =======================================================================
24 // function : Constructor
25 // purpose :
26 // =======================================================================
27 VInspector_ToolBar::VInspector_ToolBar (QWidget* theParent)
28 : QObject (theParent)
29 {
30   myActionsMap[VInspector_ToolActionType_UpdateId] = new QPushButton (theParent);
31   myActionsMap[VInspector_ToolActionType_UpdateId]->setIcon (QIcon (":/icons/treeview_update.png"));
32   myActionsMap[VInspector_ToolActionType_UpdateId]->setText (tr ("Update Tree Model"));
33   myActionsMap[VInspector_ToolActionType_UpdateId]->setToolTip (tr ("Update Tree Model"));
34
35   myActionsMap[VInspector_ToolActionType_UpdateId]->setText ("Update");
36
37   myActionsMap[VInspector_ToolActionType_SelectPresentationsId] = new QPushButton (theParent);
38   myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setText ("Select Presentations");
39   myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setCheckable (true);
40   myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setFixedHeight(20);
41
42   myActionsMap[VInspector_ToolActionType_SelectOwnersId] = new QPushButton (theParent);
43   myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setText ("Select Owners");
44   myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setCheckable (true);
45   myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setFixedHeight(25);
46
47   myMainWindow = new QWidget (theParent);
48
49   QHBoxLayout* aLay = new QHBoxLayout (myMainWindow);
50   aLay->setMargin(0);
51   for (QMap<VInspector_ToolActionType, QPushButton*>::ConstIterator anActionsIt = myActionsMap.begin();
52        anActionsIt != myActionsMap.end(); anActionsIt++)
53   {
54     QPushButton* aBtn = anActionsIt.value();
55     connect (aBtn, SIGNAL (clicked()), this, SLOT (onActionClicked()));
56     aLay->addWidget (aBtn);
57   }
58   aLay->addStretch(1);
59 }
60
61 // =======================================================================
62 // function : GetToolButton
63 // purpose :
64 // =======================================================================
65 QPushButton* VInspector_ToolBar::GetToolButton (const VInspector_ToolActionType& theActionId ) const
66 {
67   return myActionsMap.contains (theActionId) ? myActionsMap[theActionId] : 0;
68 }
69
70 // =======================================================================
71 // function : onActionClicked
72 // purpose :
73 // =======================================================================
74 void VInspector_ToolBar::onActionClicked()
75 {
76   int anId = -1;
77   QPushButton* aSenderBtn = (QPushButton*)sender();
78
79   for (QMap<VInspector_ToolActionType, QPushButton*>::ConstIterator anActionsIt = myActionsMap.begin();
80        anActionsIt != myActionsMap.end(); anActionsIt++)
81   {
82     if (anActionsIt.value() != aSenderBtn)
83       continue;
84     anId = anActionsIt.key();
85     break;
86   }
87
88   if (anId == VInspector_ToolActionType_SelectPresentationsId && myActionsMap[VInspector_ToolActionType_SelectOwnersId]->isChecked())
89     myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setChecked(false);
90   else if (anId == VInspector_ToolActionType_SelectOwnersId && myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->isChecked())
91     myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setChecked(false);
92
93   if (anId != -1)
94     emit actionClicked (anId);
95 }