28 mViewService(viewService)
30 mTopLayout =
new QVBoxLayout(
this);
31 QHBoxLayout* nameLayout =
new QHBoxLayout;
32 mTopLayout->addLayout(nameLayout);
33 mRCLayout =
new QHBoxLayout;
34 mTopLayout->addLayout(mRCLayout);
35 mLayout =
new QGridLayout;
36 mLayout->setMargin(0);
37 mLayout->setSpacing(2);
38 mTopLayout->addLayout(mLayout);
40 mNameEdit =
new QLineEdit;
41 connect(mNameEdit, SIGNAL(editingFinished()),
this, SLOT(nameChanged()));
42 nameLayout->addWidget(
new QLabel(
"Name"));
43 nameLayout->addWidget(mNameEdit);
47 mRowsEdit =
new QSpinBox;
49 mColsEdit =
new QSpinBox;
51 connect(mRowsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
52 connect(mColsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
53 mRCLayout->addWidget(
new QLabel(
"Rows"));
54 mRCLayout->addWidget(mRowsEdit);
55 mRCLayout->addWidget(
new QLabel(
"Columns"));
56 mRCLayout->addWidget(mColsEdit);
57 mRCLayout->addStretch();
61 PLANE_TYPE type =
static_cast<PLANE_TYPE
>(i);
74 "Render the layout to memory only.\n" 75 "This will cause the displayed area to be black,\n" 76 "but the application can access the rendering programatically.",
79 connect(mOffScreenRendering.get(), &
BoolProperty::changed,
this, &LayoutEditorWidget::onOffScreenRenderingChanged);
96 void LayoutEditorWidget::onOffScreenRenderingChanged()
101 void LayoutEditorWidget::nameChanged()
103 mViewData.
setName(mNameEdit->text());
106 void LayoutEditorWidget::contextMenuSlot(
const QPoint& point)
109 QPoint pointGlobal = this->mapToGlobal(point);
114 QAction* mergeAction =
new QAction(
"merge view", &menu);
115 mergeAction->setEnabled(this->getSelectedViews().size()>1);
116 connect(mergeAction, SIGNAL(triggered()),
this, SLOT(mergeActionSlot()));
117 menu.addAction(mergeAction);
119 QAction* splitAction =
new QAction(
"split view", &menu);
120 splitAction->setEnabled(mSelection.
span.
row!=1 || mSelection.
span.
col!=1);
121 connect(splitAction, SIGNAL(triggered()),
this, SLOT(splitActionSlot()));
122 menu.addAction(splitAction);
128 int viewGroupCount = mViewService->groupCount();
129 QActionGroup* groupActions =
new QActionGroup(
this);
130 for (
int i=0; i<viewGroupCount; ++i)
132 QAction* action =
new QAction(QString(
"Group %1").arg(i), groupActions);
133 action->setData(QVariant(i));
134 action->setCheckable(
true);
135 connect(action, SIGNAL(triggered()),
this, SLOT(groupActionSlot()));
136 action->setChecked(viewData.
mGroup==i);
141 menu.addActions(groupActions->actions());
145 QActionGroup* typeActions =
new QActionGroup(
this);
147 for (
unsigned i=0; i<mViewNames.size(); ++i)
149 ViewNamesType current = mViewNames[i];
154 QAction* action =
new QAction(QString(
"%1").arg(current.mName), typeActions);
156 action->setCheckable(
true);
157 connect(action, SIGNAL(triggered()),
this, SLOT(typeActionSlot()));
158 action->setChecked(viewData.
mPlane==current.mPlane && viewData.
mType==current.mView);
173 menu.addActions(typeActions->actions());
175 menu.exec(pointGlobal);
178 void LayoutEditorWidget::splitActionSlot()
180 mViewData.
split(mSelection);
184 void LayoutEditorWidget::mergeActionSlot()
186 mViewData.
merge(mSelection);
190 void LayoutEditorWidget::groupActionSlot()
192 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
195 int group = sender->data().toInt();
197 std::set<LayoutData::iterator> selection = this->getSelectedViews();
198 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
199 (*iter)->mGroup = group;
204 void LayoutEditorWidget::typeActionSlot()
206 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
211 for (
unsigned i=0; i<mViewNames.size(); ++i)
212 if (mViewNames[i].mName == sender->text())
215 std::set<LayoutData::iterator> selection = this->getSelectedViews();
216 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
218 (*iter)->mPlane = type.mPlane;
219 (*iter)->mType = type.mView;
225 void LayoutEditorWidget::mouseMoveEvent(QMouseEvent* event)
227 this->updateSelection(event->pos());
230 void LayoutEditorWidget::updateSelection(QPoint pos)
235 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
241 std::set<LayoutData::iterator> LayoutEditorWidget::getSelectedViews()
243 std::set<LayoutData::iterator> retval;
250 void LayoutEditorWidget::mousePressEvent(QMouseEvent* event)
252 mClickPos =
event->pos();
254 if (event->button()==Qt::RightButton)
257 if (!mSelection.
contains(this->getViewData(mClickPos).mRegion.pos))
258 this->updateSelection(event->pos());
261 this->contextMenuSlot(event->pos());
266 this->updateSelection(event->pos());
270 void LayoutEditorWidget::colorRegion(
LayoutRegion region, QString selectColor, QString backColor)
282 mViewDataCache[pos.
row][pos.
col].mFrame->setStyleSheet(QString(
"QFrame { background-color: %1 }").arg(color));
294 if (!mViewDataCache[pos.
row][pos.
col].mFrame->geometry().contains(pt))
306 void LayoutEditorWidget::rowsColumnsChangedSlot()
308 mViewData.
resize(mRowsEdit->value(), mColsEdit->value());
309 this->setSaneGroupIDs();
313 QString LayoutEditorWidget::getViewName(
LayoutViewData data)
const 315 for (
unsigned i=0; i<mViewNames.size(); ++i)
317 if (mViewNames[i].mPlane==data.
mPlane && mViewNames[i].mView==data.
mType)
318 return mViewNames[i].mName;
326 void LayoutEditorWidget::setSaneGroupIDs()
339 void LayoutEditorWidget::updateGrid()
343 this->clearDisplay();
356 QString name = this->getViewName(*iter);
357 if (iter->mGroup<0 && name.isEmpty())
358 gridData.
mLabel->setText(
"NA");
360 gridData.
mLabel->setText(QString(
"%1/%2").arg(iter->mGroup).arg(name));
363 mNameEdit->setText(mViewData.
getName());
368 mRowsEdit->blockSignals(
true);
369 mRowsEdit->setValue(mViewData.
size().
row);
370 mRowsEdit->blockSignals(
false);
372 mColsEdit->blockSignals(
true);
373 mColsEdit->setValue(mViewData.
size().
col);
374 mColsEdit->blockSignals(
false);
377 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
401 void LayoutEditorWidget::clearDisplay()
403 for (
unsigned r = 0; r < mViewDataCache.size(); ++r)
405 for (
unsigned c = 0; c < mViewDataCache[r].size(); ++c)
407 mViewDataCache[r][c].mFrame->hide();
412 void LayoutEditorWidget::initCache()
416 mViewDataCache.resize(maxRows);
418 for (
int r = 0; r < maxRows; ++r)
420 mViewDataCache[r].resize(maxCols);
422 for (
int c = 0; c < maxCols; ++c)
424 QFrame* frame =
new QFrame(
this);
426 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
427 frame->setLineWidth(3);
428 frame->setLayout(
new QVBoxLayout);
429 QLabel* label =
new QLabel(
"NA", frame);
430 frame->layout()->addWidget(label);
432 mViewDataCache[r][c].mFrame = frame;
433 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.