CustusX  22.04-rc5
An IGT application
cxPopupToolbarWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxPopupToolbarWidget.h"
12 
13 #include <QHBoxLayout>
14 #include <QToolButton>
15 #include <QIcon>
16 #include "cxBaseWidget.h"
17 #include "cxLogger.h"
18 
19 namespace cx
20 {
21 
22 
23 PopupButton::PopupButton(QWidget* parent)
24 {
25  // this->setFrameStyle(QFrame::Box);
26 
27  QVBoxLayout* layout = new QVBoxLayout(this);
28  layout->setMargin(0);
29  this->setLayout(layout);
30 
31  // QToolButton* expandButton = new QToolButton(this);
32  QToolButton* expandButton = new CXSmallToolButton(this);
33  mShowHeaderButton = expandButton;
34  this->setFixedSize(expandButton->sizeHint());
35 
36  QAction* action = new QAction(QIcon(":icons/open_icon_library/layer-lower-3.png"), "Controls", this);
37  QString tip = "Show Controls";
38  action->setStatusTip(tip);
39  action->setWhatsThis(tip);
40  action->setToolTip(tip);
41  connect(action, SIGNAL(triggered()), this, SLOT(onTriggered()));
42  mAction = action;
43 
44  mShowHeaderButton->setDefaultAction(action);
45  layout->addWidget(mShowHeaderButton);
46 
47  action->setCheckable(true);
48 }
49 
51 {
52  return mAction->isChecked();
53 }
54 
56 {
57  mAction->setChecked(val);
58 }
59 
60 void PopupButton::onTriggered()
61 {
62  if (this->getShowPopup())
63  mAction->setIcon(QIcon(":icons/open_icon_library/layer-raise-3.png"));
64  else
65  mAction->setIcon(QIcon(":icons/open_icon_library/layer-lower-3.png"));
66 
67  emit popup(this->getShowPopup());
68 }
69 
73 
75  QWidget(parent)
76 {
77  mControlLayout = new QHBoxLayout(this);
78  mControlLayout->setMargin(0);
79 
80  mShowControlsButton = new PopupButton(this->parentWidget());
81  mControlLayout->addWidget(mShowControlsButton);
82  connect(mShowControlsButton, &PopupButton::popup, this, &PopupToolbarWidget::onPopup);
83 
84  mButtonWidget = new QWidget(this);
85  mControlLayout->addWidget(mButtonWidget);
86 
87  this->onPopup();
88 }
89 
91 {
92  return mButtonWidget;
93 }
94 
96 {
97  return mButtonWidget->isVisible();
98  // return mShowControlsButton->getShowPopup();
99 }
100 
102 {
103  mShowControlsButton->setShowPopup(val);
104 }
105 
106 void PopupToolbarWidget::onPopup()
107 {
108  bool show = mShowControlsButton->getShowPopup();
109 
110  mButtonWidget->setVisible(show);
111 
112  if (show)
113  {
114  mControlLayout->insertWidget(0, mShowControlsButton);
115  }
116  else
117  {
118  // remove from layout, add to top of this
119  mControlLayout->removeWidget(mShowControlsButton);
120  mShowControlsButton->setParent(NULL);
121  mShowControlsButton->setParent(this->parentWidget());
122  mShowControlsButton->setVisible(true);
123  }
124 
125  emit popup(show);
126 }
127 
128 
129 }//namespace cx
130 
PopupButton(QWidget *parent=NULL)
void popup(bool show)
bool getShowPopup() const
void setShowPopup(bool val)
void popup(bool show)
PopupToolbarWidget(QWidget *parent)
Namespace for all CustusX production code.