0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[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 <VInspector_ToolBar.hxx>
17
18 #include <QHBoxLayout>
19 #include <QToolButton>
20 #include <QWidget>
21
22 // =======================================================================
23 // function : Constructor
24 // purpose :
25 // =======================================================================
26 VInspector_ToolBar::VInspector_ToolBar (QWidget* theParent)
27 : QObject (theParent)
28 {
29   myActionsMap[VInspector_ToolActionType_UpdateId] = new QToolButton (theParent);
30   myActionsMap[VInspector_ToolActionType_UpdateId]->setText ("Update");
31
32   myActionsMap[VInspector_ToolActionType_SelectPresentationsId] = new QToolButton (theParent);
33   myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setText ("Select Presentations");
34   myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setCheckable (true);
35
36   myActionsMap[VInspector_ToolActionType_SelectOwnersId] = new QToolButton (theParent);
37   myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setText ("Select Owners");
38   myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setCheckable (true);
39
40   myMainWindow = new QWidget (theParent);
41
42   QHBoxLayout* aLay = new QHBoxLayout (myMainWindow);
43   for (QMap<VInspector_ToolActionType, QToolButton*>::ConstIterator anActionsIt = myActionsMap.begin();
44        anActionsIt != myActionsMap.end(); anActionsIt++)
45   {
46     QToolButton* aBtn = anActionsIt.value();
47     connect (aBtn, SIGNAL (clicked()), this, SLOT (onActionClicked()));
48     aLay->addWidget (aBtn);
49   }
50 }
51
52 // =======================================================================
53 // function : GetToolButton
54 // purpose :
55 // =======================================================================
56 QToolButton* VInspector_ToolBar::GetToolButton (const VInspector_ToolActionType& theActionId ) const
57 {
58   return myActionsMap.contains (theActionId) ? myActionsMap[theActionId] : 0;
59 }
60
61 // =======================================================================
62 // function : onActionClicked
63 // purpose :
64 // =======================================================================
65 void VInspector_ToolBar::onActionClicked()
66 {
67   int anId = -1;
68   QToolButton* aSenderBtn = (QToolButton*)sender();
69
70   for (QMap<VInspector_ToolActionType, QToolButton*>::ConstIterator anActionsIt = myActionsMap.begin();
71        anActionsIt != myActionsMap.end(); anActionsIt++)
72   {
73     if (anActionsIt.value() != aSenderBtn)
74       continue;
75     anId = anActionsIt.key();
76     break;
77   }
78
79   if (anId == VInspector_ToolActionType_SelectPresentationsId && myActionsMap[VInspector_ToolActionType_SelectOwnersId]->isChecked())
80     myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setChecked(false);
81   else if (anId == VInspector_ToolActionType_SelectOwnersId && myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->isChecked())
82     myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setChecked(false);
83
84   if (anId != -1)
85     emit actionClicked (anId);
86 }