Fraxinus  17.12-rc1
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) 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 #include "cxLogger.h"
39 
40 namespace cx
41 {
42 
43 
44 PopupButton::PopupButton(QWidget* parent)
45 {
46  // this->setFrameStyle(QFrame::Box);
47 
48  QVBoxLayout* layout = new QVBoxLayout(this);
49  layout->setMargin(0);
50  this->setLayout(layout);
51 
52  // QToolButton* expandButton = new QToolButton(this);
53  QToolButton* expandButton = new CXSmallToolButton(this);
54  mShowHeaderButton = expandButton;
55  this->setFixedSize(expandButton->sizeHint());
56 
57  QAction* action = new QAction(QIcon(":icons/open_icon_library/layer-lower-3.png"), "Controls", this);
58  QString tip = "Show Controls";
59  action->setStatusTip(tip);
60  action->setWhatsThis(tip);
61  action->setToolTip(tip);
62  connect(action, SIGNAL(triggered()), this, SLOT(onTriggered()));
63  mAction = action;
64 
65  mShowHeaderButton->setDefaultAction(action);
66  layout->addWidget(mShowHeaderButton);
67 
68  action->setCheckable(true);
69 }
70 
72 {
73  return mAction->isChecked();
74 }
75 
77 {
78  mAction->setChecked(val);
79 }
80 
81 void PopupButton::onTriggered()
82 {
83  if (this->getShowPopup())
84  mAction->setIcon(QIcon(":icons/open_icon_library/layer-raise-3.png"));
85  else
86  mAction->setIcon(QIcon(":icons/open_icon_library/layer-lower-3.png"));
87 
88  emit popup(this->getShowPopup());
89 }
90 
94 
96  QWidget(parent)
97 {
98  mControlLayout = new QHBoxLayout(this);
99  mControlLayout->setMargin(0);
100 
101  mShowControlsButton = new PopupButton(this->parentWidget());
102  mControlLayout->addWidget(mShowControlsButton);
103  connect(mShowControlsButton, &PopupButton::popup, this, &PopupToolbarWidget::onPopup);
104 
105  mButtonWidget = new QWidget(this);
106  mControlLayout->addWidget(mButtonWidget);
107 
108  this->onPopup();
109 }
110 
112 {
113  return mButtonWidget;
114 }
115 
117 {
118  return mButtonWidget->isVisible();
119  // return mShowControlsButton->getShowPopup();
120 }
121 
123 {
124  mShowControlsButton->setShowPopup(val);
125 }
126 
127 void PopupToolbarWidget::onPopup()
128 {
129  bool show = mShowControlsButton->getShowPopup();
130 
131  mButtonWidget->setVisible(show);
132 
133  if (show)
134  {
135  mControlLayout->insertWidget(0, mShowControlsButton);
136  }
137  else
138  {
139  // remove from layout, add to top of this
140  mControlLayout->removeWidget(mShowControlsButton);
141  mShowControlsButton->setParent(NULL);
142  mShowControlsButton->setParent(this->parentWidget());
143  mShowControlsButton->setVisible(true);
144  }
145 
146  emit popup(show);
147 }
148 
149 
150 }//namespace cx
151 
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.