27 mViewService(viewService)
29 mTopLayout =
new QVBoxLayout(
this);
30 QHBoxLayout* nameLayout =
new QHBoxLayout;
31 mTopLayout->addLayout(nameLayout);
32 mRCLayout =
new QHBoxLayout;
33 mTopLayout->addLayout(mRCLayout);
34 mLayout =
new QGridLayout;
35 mLayout->setMargin(0);
36 mLayout->setSpacing(2);
37 mTopLayout->addLayout(mLayout);
39 mNameEdit =
new QLineEdit;
40 connect(mNameEdit, SIGNAL(editingFinished()),
this, SLOT(nameChanged()));
41 nameLayout->addWidget(
new QLabel(
"Name"));
42 nameLayout->addWidget(mNameEdit);
46 mRowsEdit =
new QSpinBox;
48 mColsEdit =
new QSpinBox;
50 connect(mRowsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
51 connect(mColsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
52 mRCLayout->addWidget(
new QLabel(
"Rows"));
53 mRCLayout->addWidget(mRowsEdit);
54 mRCLayout->addWidget(
new QLabel(
"Columns"));
55 mRCLayout->addWidget(mColsEdit);
56 mRCLayout->addStretch();
60 PLANE_TYPE type =
static_cast<PLANE_TYPE
>(i);
73 "Render the layout to memory only.\n" 74 "This will cause the displayed area to be black,\n" 75 "but the application can access the rendering programatically.",
78 connect(mOffScreenRendering.get(), &
BoolProperty::changed,
this, &LayoutEditorWidget::onOffScreenRenderingChanged);
95 void LayoutEditorWidget::onOffScreenRenderingChanged()
100 void LayoutEditorWidget::nameChanged()
102 mViewData.
setName(mNameEdit->text());
105 void LayoutEditorWidget::contextMenuSlot(
const QPoint& point)
108 QPoint pointGlobal = this->mapToGlobal(point);
113 QAction* mergeAction =
new QAction(
"merge view", &menu);
114 mergeAction->setEnabled(this->getSelectedViews().size()>1);
115 connect(mergeAction, SIGNAL(triggered()),
this, SLOT(mergeActionSlot()));
116 menu.addAction(mergeAction);
118 QAction* splitAction =
new QAction(
"split view", &menu);
119 splitAction->setEnabled(mSelection.
span.
row!=1 || mSelection.
span.
col!=1);
120 connect(splitAction, SIGNAL(triggered()),
this, SLOT(splitActionSlot()));
121 menu.addAction(splitAction);
127 int viewGroupCount = mViewService->groupCount();
128 QActionGroup* groupActions =
new QActionGroup(
this);
129 for (
int i=0; i<viewGroupCount; ++i)
131 QAction* action =
new QAction(QString(
"Group %1").arg(i), groupActions);
132 action->setData(QVariant(i));
133 action->setCheckable(
true);
134 connect(action, SIGNAL(triggered()),
this, SLOT(groupActionSlot()));
135 action->setChecked(viewData.
mGroup==i);
140 menu.addActions(groupActions->actions());
144 QActionGroup* typeActions =
new QActionGroup(
this);
146 for (
unsigned i=0; i<mViewNames.size(); ++i)
148 ViewNamesType current = mViewNames[i];
153 QAction* action =
new QAction(QString(
"%1").arg(current.mName), typeActions);
155 action->setCheckable(
true);
156 connect(action, SIGNAL(triggered()),
this, SLOT(typeActionSlot()));
157 action->setChecked(viewData.
mPlane==current.mPlane && viewData.
mType==current.mView);
172 menu.addActions(typeActions->actions());
174 menu.exec(pointGlobal);
177 void LayoutEditorWidget::splitActionSlot()
179 mViewData.
split(mSelection);
183 void LayoutEditorWidget::mergeActionSlot()
185 mViewData.
merge(mSelection);
189 void LayoutEditorWidget::groupActionSlot()
191 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
194 int group = sender->data().toInt();
196 std::set<LayoutData::iterator> selection = this->getSelectedViews();
197 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
198 (*iter)->mGroup = group;
203 void LayoutEditorWidget::typeActionSlot()
205 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
210 for (
unsigned i=0; i<mViewNames.size(); ++i)
211 if (mViewNames[i].mName == sender->text())
214 std::set<LayoutData::iterator> selection = this->getSelectedViews();
215 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
217 (*iter)->mPlane = type.mPlane;
218 (*iter)->mType = type.mView;
224 void LayoutEditorWidget::mouseMoveEvent(QMouseEvent* event)
226 this->updateSelection(event->pos());
229 void LayoutEditorWidget::updateSelection(QPoint pos)
234 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
240 std::set<LayoutData::iterator> LayoutEditorWidget::getSelectedViews()
242 std::set<LayoutData::iterator> retval;
249 void LayoutEditorWidget::mousePressEvent(QMouseEvent* event)
251 mClickPos =
event->pos();
253 if (event->button()==Qt::RightButton)
256 if (!mSelection.
contains(this->getViewData(mClickPos).mRegion.pos))
257 this->updateSelection(event->pos());
260 this->contextMenuSlot(event->pos());
265 this->updateSelection(event->pos());
269 void LayoutEditorWidget::colorRegion(
LayoutRegion region, QString selectColor, QString backColor)
281 mViewDataCache[pos.
row][pos.
col].mFrame->setStyleSheet(QString(
"QFrame { background-color: %1 }").arg(color));
293 if (!mViewDataCache[pos.
row][pos.
col].mFrame->geometry().contains(pt))
305 void LayoutEditorWidget::rowsColumnsChangedSlot()
307 mViewData.
resize(mRowsEdit->value(), mColsEdit->value());
308 this->setSaneGroupIDs();
312 QString LayoutEditorWidget::getViewName(
LayoutViewData data)
const 314 for (
unsigned i=0; i<mViewNames.size(); ++i)
316 if (mViewNames[i].mPlane==data.
mPlane && mViewNames[i].mView==data.
mType)
317 return mViewNames[i].mName;
325 void LayoutEditorWidget::setSaneGroupIDs()
338 void LayoutEditorWidget::updateGrid()
342 this->clearDisplay();
355 QString name = this->getViewName(*iter);
356 if (iter->mGroup<0 && name.isEmpty())
357 gridData.
mLabel->setText(
"NA");
359 gridData.
mLabel->setText(QString(
"%1/%2").arg(iter->mGroup).arg(name));
362 mNameEdit->setText(mViewData.
getName());
367 mRowsEdit->blockSignals(
true);
368 mRowsEdit->setValue(mViewData.
size().
row);
369 mRowsEdit->blockSignals(
false);
371 mColsEdit->blockSignals(
true);
372 mColsEdit->setValue(mViewData.
size().
col);
373 mColsEdit->blockSignals(
false);
376 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
400 void LayoutEditorWidget::clearDisplay()
402 for (
unsigned r = 0; r < mViewDataCache.size(); ++r)
404 for (
unsigned c = 0; c < mViewDataCache[r].size(); ++c)
406 mViewDataCache[r][c].mFrame->hide();
411 void LayoutEditorWidget::initCache()
415 mViewDataCache.resize(maxRows);
417 for (
int r = 0; r < maxRows; ++r)
419 mViewDataCache[r].resize(maxCols);
421 for (
int c = 0; c < maxCols; ++c)
423 QFrame* frame =
new QFrame(
this);
425 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
426 frame->setLineWidth(3);
427 frame->setLayout(
new QVBoxLayout);
428 QLabel* label =
new QLabel(
"NA", frame);
429 frame->layout()->addWidget(label);
431 mViewDataCache[r][c].mFrame = frame;
432 mViewDataCache[r][c].mLabel = label;
QString qstring_cast(const T &val)
int mGroup
what group to connect to. -1 means not set.
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
ViewDataContainer::iterator iterator
bool contains(LayoutPosition p) const
LayoutPosition span
size of region
bool merge(LayoutRegion region)
void setName(const QString &name)
PLANE_TYPE mPlane
ptNOPLANE means 3D
iterator find(LayoutPosition pos)
void split(iterator iter)
void resize(int rows, int cols)
LayoutPosition size() const
void changed()
emit when the underlying data value is changed: The user interface will be updated.
ptNOPLANE
a initial plane, if no yet set
static const int MaxGridSize
LayoutPosition pos
start position of region
void setOffScreenRendering(bool val)
LayoutRegion merge(LayoutRegion a, LayoutRegion b)
bool getOffScreenRendering() const
Namespace for all CustusX production code.