CustusX  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 #include "cxPopupToolbarWidget.h"
33 
34 #include <QHBoxLayout>
35 #include <QToolButton>
36 #include <QIcon>
37 #include "cxBaseWidget.h"
38 
39 namespace cx
40 {
41 
42 
43 PopupButton::PopupButton(QWidget* parent)
44 {
45  // this->setFrameStyle(QFrame::Box);
46 
47  QVBoxLayout* layout = new QVBoxLayout(this);
48  layout->setMargin(0);
49  this->setLayout(layout);
50 
51  // QToolButton* expandButton = new QToolButton(this);
52  QToolButton* expandButton = new CXSmallToolButton(this);
53  mShowHeaderButton = expandButton;
54  this->setFixedSize(expandButton->sizeHint());
55 
56  QAction* action = new QAction(QIcon(":icons/open_icon_library/layer-lower-3.png"), "Controls", this);
57  QString tip = "Show Controls";
58  action->setStatusTip(tip);
59  action->setWhatsThis(tip);
60  action->setToolTip(tip);
61  connect(action, SIGNAL(triggered()), this, SLOT(onTriggered()));
62  mAction = action;
63 
64  mShowHeaderButton->setDefaultAction(action);
65  layout->addWidget(mShowHeaderButton);
66 
67  action->setCheckable(true);
68 }
69 
71 {
72  return mShowHeaderButton->isChecked();
73 }
74 
76 {
77  mShowHeaderButton->setChecked(val);
78 }
79 
80 void PopupButton::onTriggered()
81 {
82  if (this->getShowPopup())
83  mAction->setIcon(QIcon(":icons/open_icon_library/layer-raise-3.png"));
84  else
85  mAction->setIcon(QIcon(":icons/open_icon_library/layer-lower-3.png"));
86 
87  emit popup(this->getShowPopup());
88 }
89 
93 
95  QWidget(parent)
96 {
97  mControlLayout = new QHBoxLayout(this);
98  mControlLayout->setMargin(0);
99 
100  mShowControlsButton = new PopupButton(this->parentWidget());
101  mControlLayout->addWidget(mShowControlsButton);
102  connect(mShowControlsButton, &PopupButton::popup, this, &PopupToolbarWidget::onPopup);
103 
104  mButtonWidget = new QWidget(this);
105  mControlLayout->addWidget(mButtonWidget);
106 
107  this->onPopup();
108 }
109 
111 {
112  return mButtonWidget;
113 }
114 
116 {
117  return mButtonWidget->isVisible();
118  // return mShowControlsButton->getShowPopup();
119 }
120 
122 {
123  mShowControlsButton->setShowPopup(val);
124 }
125 
126 void PopupToolbarWidget::onPopup()
127 {
128  bool show = mShowControlsButton->getShowPopup();
129 
130  mButtonWidget->setVisible(show);
131 
132  if (show)
133  {
134  mControlLayout->insertWidget(0, mShowControlsButton);
135  }
136  else
137  {
138  // remove from layout, add to top of this
139  mControlLayout->removeWidget(mShowControlsButton);
140  mShowControlsButton->setParent(NULL);
141  mShowControlsButton->setParent(this->parentWidget());
142  mShowControlsButton->setVisible(true);
143  }
144 
145  emit popup(show);
146 }
147 
148 
149 }//namespace cx
150 
PopupButton(QWidget *parent=NULL)
void popup(bool show)
bool getShowPopup() const
void setShowPopup(bool val)
void popup(bool show)
PopupToolbarWidget(QWidget *parent)