NorMIT-nav  16.5
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  this->setFocusPolicy(Qt::StrongFocus); // needed for help system: focus is used to display help text
48  this->setObjectName(mObjectName);
49  this->setWindowTitle(mWindowTitle);
50 }
51 
52 QWidget* BaseWidget::createMethodWidget(QWidget* inputWidget, QWidget* outputWidget, QString methodname, bool inputChecked, bool outputVisible)
53 {
54  QWidget* retval = new QWidget(this);
55  QVBoxLayout* toplayout = new QVBoxLayout(retval);
56  QGridLayout* layout = new QGridLayout();
57  toplayout->addLayout(layout);
58  toplayout->addStretch();
59 
60  QLabel* methodLabel = new QLabel("<b>" + methodname + "</b>");
61  QCheckBox* checkBox = new QCheckBox("generate");
62 
63  inputWidget->setVisible(inputChecked);
64  outputWidget->setVisible(outputVisible);
65  connect(checkBox, SIGNAL(clicked(bool)), inputWidget, SLOT(setVisible(bool)));
66 
67  layout->addWidget(methodLabel, 0, 0);
68  layout->addWidget(checkBox, 0, 1);
69  layout->addWidget(inputWidget, 1, 0, 1, 2);
70  layout->addWidget(outputWidget, 2, 0, 1, 2);
71 
72  return retval;
73 }
74 
75 QGroupBox* BaseWidget::createGroupbox(QWidget* widget, QString boxname)
76 {
77  QGroupBox* retval = new QGroupBox(this);
78  QVBoxLayout* toplayout = new QVBoxLayout(retval);
79 
80  QLabel* nameLabel = new QLabel(boxname);
81  toplayout->addWidget(nameLabel);
82  toplayout->addWidget(widget);
83 
84  return retval;
85 }
86 
88 {
89  QFrame* retval = new QFrame();
90  retval->setFrameStyle(QFrame::Sunken + QFrame::HLine);
91  return retval;
92 }
93 
95 {
96  CXFrame* frame = new CXFrame(NULL);
97  QVBoxLayout* layout = new QVBoxLayout(frame);
98  layout->setMargin(0);
99  layout->addWidget(base);
100  return frame;
101 }
102 
103 QGroupBox* BaseWidget::wrapInGroupBox(QWidget* base, QString name)
104 {
105  QGroupBox* groupBox = new QGroupBox(name);
106  QVBoxLayout* layout = new QVBoxLayout(groupBox);
107  layout->setMargin(2);
108  layout->addWidget(base);
109  return groupBox;
110 }
111 
113 {
114  this->parentWidget()->adjustSize();
115  this->adjustSize();
116 }
117 
118 void BaseWidget::showEvent(QShowEvent* event)
119 {
120  QWidget::showEvent(event);
121 }
122 
123 }
124 
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)
BaseWidget(QWidget *parent, QString objectName, QString windowTitle)
Interface for all classes following the modified/prepaint paradigm.