CustusX  15.4.0-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLayoutEditorWidget.h
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 #ifndef CXLAYOUTEDITORWIDGET_H_
33 #define CXLAYOUTEDITORWIDGET_H_
34 
35 #include "cxGuiExport.h"
36 
37 #include <map>
38 #include <set>
39 #include <QWidget>
40 #include <QLineEdit>
41 class QFrame;
42 class QSpinBox;
43 class QLabel;
44 class QBoxLayout;
45 class QGridLayout;
46 class QLineEdit;
47 #include "cxLayoutData.h"
48 #include "cxLegacySingletons.h"
49 
50 namespace cx
51 {
52 
53 
57 class cxGui_EXPORT SmallLineEdit : public QLineEdit
58 {
59 public:
60  SmallLineEdit(QWidget* parent = 0) : QLineEdit(parent) {}
61  virtual QSize sizeHint() const
62  {
63  QSize size = QLineEdit::minimumSizeHint();
64  size.setWidth(size.height()*2);
65  return size;
66  }
67 };
68 
73 class cxGui_EXPORT LayoutEditorWidget : public QWidget
74 {
75  Q_OBJECT
76 public:
77  struct GridElement
78  {
79  QFrame* mFrame;
80  QLabel* mLabel;
81  };
82 
83  LayoutEditorWidget(QWidget* parent);
84  void setLayoutData(const LayoutData& data);
85  LayoutData getLayoutData() const;
86 
87 private slots:
88  void rowsColumnsChangedSlot();
89  void contextMenuSlot(const QPoint& point);
90  void splitActionSlot();
91  void mergeActionSlot();
92  void groupActionSlot();
93  void typeActionSlot();
94  void nameChanged();
95 
96 private:
97  void initCache();
98  void clearDisplay();
99  void updateGrid();
100  LayoutViewData getViewData(QPoint pt);
101  void colorRegion(LayoutRegion region, QString selectColor, QString backColor);
102  std::set<LayoutData::iterator> getSelectedViews();
103  void updateSelection(QPoint pos);
104  void setSaneGroupIDs();
105 
106  QBoxLayout* mTopLayout;
107  QBoxLayout* mRCLayout;
108  QGridLayout* mLayout;
109  QSpinBox* mRowsEdit;
110  QSpinBox* mColsEdit;
111  QLineEdit* mNameEdit;
112 
113  std::vector<std::vector<GridElement> > mViewDataCache;
114  LayoutData mViewData;
115  std::map<PLANE_TYPE, QString> mPlaneNames;
116  QPoint mClickPos;
117  LayoutRegion mSelection;
118 
119  struct ViewNamesType
120  {
121  ViewNamesType() {}
122  ViewNamesType(PLANE_TYPE plane, View::Type view, QString name) : mPlane(plane), mView(view), mName(name) {}
123  PLANE_TYPE mPlane;
124  View::Type mView;
125  QString mName;
126  };
127  std::vector<ViewNamesType> mViewNames;
128  QString getViewName(LayoutViewData data) const;
129 
130  virtual void mouseMoveEvent(QMouseEvent* event);
131  virtual void mousePressEvent(QMouseEvent* event);
132 };
133 
134 
135 } // namespace cx
136 
137 #endif /* CXLAYOUTEDITORWIDGET_H_ */
virtual QSize sizeHint() const
SmallLineEdit(QWidget *parent=0)