CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxBaseWidget.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 
33 #include "cxBaseWidget.h"
34 #include "cxTypeConversions.h"
35 
36 #include <QVBoxLayout>
37 #include <QGroupBox>
38 #include <QCheckBox>
39 #include <QLabel>
40 
41 namespace cx
42 {
43 
44 BaseWidget::BaseWidget(QWidget* parent, QString objectName, QString windowTitle) :
45  OptimizedUpdateWidget(parent), mObjectName(objectName), mWindowTitle(windowTitle)
46 {
47 // if (mObjectName=="US Reconstruction")
48 // std::cout << ":: [" << this->objectName() << "]" << std::endl;
49  this->setFocusPolicy(Qt::StrongFocus); // needed for help system: focus is used to display help text
50  this->setObjectName(mObjectName);
51  this->setWindowTitle(mWindowTitle);
52 }
53 
54 QWidget* BaseWidget::createMethodWidget(QWidget* inputWidget, QWidget* outputWidget, QString methodname, bool inputChecked, bool outputVisible)
55 {
56  QWidget* retval = new QWidget(this);
57  QVBoxLayout* toplayout = new QVBoxLayout(retval);
58  QGridLayout* layout = new QGridLayout();
59  toplayout->addLayout(layout);
60  toplayout->addStretch();
61 
62  QLabel* methodLabel = new QLabel("<b>" + methodname + "</b>");
63  QCheckBox* checkBox = new QCheckBox("generate");
64 
65  inputWidget->setVisible(inputChecked);
66  outputWidget->setVisible(outputVisible);
67  connect(checkBox, SIGNAL(clicked(bool)), inputWidget, SLOT(setVisible(bool)));
68 
69  layout->addWidget(methodLabel, 0, 0);
70  layout->addWidget(checkBox, 0, 1);
71  layout->addWidget(inputWidget, 1, 0, 1, 2);
72  layout->addWidget(outputWidget, 2, 0, 1, 2);
73 
74  return retval;
75 }
76 
77 QGroupBox* BaseWidget::createGroupbox(QWidget* widget, QString boxname)
78 {
79  QGroupBox* retval = new QGroupBox(this);
80  QVBoxLayout* toplayout = new QVBoxLayout(retval);
81 
82  QLabel* nameLabel = new QLabel(boxname);
83  toplayout->addWidget(nameLabel);
84  toplayout->addWidget(widget);
85 
86  return retval;
87 }
88 
90 {
91  QFrame* retval = new QFrame();
92  retval->setFrameStyle(QFrame::Sunken + QFrame::HLine);
93  return retval;
94 }
95 
97 {
98  CXFrame* frame = new CXFrame(NULL);
99  QVBoxLayout* layout = new QVBoxLayout(frame);
100  layout->setMargin(0);
101  layout->addWidget(base);
102  return frame;
103 }
104 
105 QGroupBox* BaseWidget::wrapInGroupBox(QWidget* base, QString name)
106 {
107  QGroupBox* groupBox = new QGroupBox(name);
108  QVBoxLayout* layout = new QVBoxLayout(groupBox);
109  layout->setMargin(2);
110  layout->addWidget(base);
111  return groupBox;
112 }
113 
115 {
116  this->parentWidget()->adjustSize();
117  this->adjustSize();
118 }
119 
120 void BaseWidget::showEvent(QShowEvent* event)
121 {
122  this->setWhatsThis(this->defaultWhatsThis());
123  QWidget::showEvent(event);
124 }
125 
126 }
127 
QGroupBox * createGroupbox(QWidget *widget, QString boxname)
Create a group box with a given name.
QGroupBox * wrapInGroupBox(QWidget *base, QString name)
virtual void showEvent(QShowEvent *event)
QWidget * createMethodWidget(QWidget *inputWidget, QWidget *outputWidget, QString methodname, bool inputChecked=false, bool outputVisible=true)
Create a specialized widget for filters, with input/ouput, enable and options.
static QFrame * createHorizontalLine()
Creates a horizontal line which can be inserted into widgets.
CXFrame * wrapInFrame(QWidget *base)
virtual QString defaultWhatsThis() const =0
Returns a short description of what this widget will do for you.
BaseWidget(QWidget *parent, QString objectName, QString windowTitle)
Interface for all classes following the modified/prepaint paradigm.