49 mViewService(viewService)
51 mTopLayout =
new QVBoxLayout(
this);
52 QHBoxLayout* nameLayout =
new QHBoxLayout;
53 mTopLayout->addLayout(nameLayout);
54 mRCLayout =
new QHBoxLayout;
55 mTopLayout->addLayout(mRCLayout);
56 mLayout =
new QGridLayout;
57 mLayout->setMargin(0);
58 mLayout->setSpacing(2);
59 mTopLayout->addLayout(mLayout);
61 mNameEdit =
new QLineEdit;
62 connect(mNameEdit, SIGNAL(editingFinished()),
this, SLOT(nameChanged()));
63 nameLayout->addWidget(
new QLabel(
"Name"));
64 nameLayout->addWidget(mNameEdit);
68 mRowsEdit =
new QSpinBox;
70 mColsEdit =
new QSpinBox;
72 connect(mRowsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
73 connect(mColsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
74 mRCLayout->addWidget(
new QLabel(
"Rows"));
75 mRCLayout->addWidget(mRowsEdit);
76 mRCLayout->addWidget(
new QLabel(
"Columns"));
77 mRCLayout->addWidget(mColsEdit);
78 mRCLayout->addStretch();
82 PLANE_TYPE type =
static_cast<PLANE_TYPE
>(i);
95 "Render the layout to memory only.\n" 96 "This will cause the displayed area to be black,\n" 97 "but the application can access the rendering programatically.",
100 connect(mOffScreenRendering.get(), &
BoolProperty::changed,
this, &LayoutEditorWidget::onOffScreenRenderingChanged);
117 void LayoutEditorWidget::onOffScreenRenderingChanged()
122 void LayoutEditorWidget::nameChanged()
124 mViewData.
setName(mNameEdit->text());
127 void LayoutEditorWidget::contextMenuSlot(
const QPoint& point)
130 QPoint pointGlobal = this->mapToGlobal(point);
135 QAction* mergeAction =
new QAction(
"merge view", &menu);
136 mergeAction->setEnabled(this->getSelectedViews().size()>1);
137 connect(mergeAction, SIGNAL(triggered()),
this, SLOT(mergeActionSlot()));
138 menu.addAction(mergeAction);
140 QAction* splitAction =
new QAction(
"split view", &menu);
141 splitAction->setEnabled(mSelection.
span.
row!=1 || mSelection.
span.
col!=1);
142 connect(splitAction, SIGNAL(triggered()),
this, SLOT(splitActionSlot()));
143 menu.addAction(splitAction);
149 int viewGroupCount = mViewService->groupCount();
150 QActionGroup* groupActions =
new QActionGroup(
this);
151 for (
int i=0; i<viewGroupCount; ++i)
153 QAction* action =
new QAction(QString(
"Group %1").arg(i), groupActions);
154 action->setData(QVariant(i));
155 action->setCheckable(
true);
156 connect(action, SIGNAL(triggered()),
this, SLOT(groupActionSlot()));
157 action->setChecked(viewData.
mGroup==i);
162 menu.addActions(groupActions->actions());
166 QActionGroup* typeActions =
new QActionGroup(
this);
168 for (
unsigned i=0; i<mViewNames.size(); ++i)
170 ViewNamesType current = mViewNames[i];
175 QAction* action =
new QAction(QString(
"%1").arg(current.mName), typeActions);
177 action->setCheckable(
true);
178 connect(action, SIGNAL(triggered()),
this, SLOT(typeActionSlot()));
179 action->setChecked(viewData.
mPlane==current.mPlane && viewData.
mType==current.mView);
194 menu.addActions(typeActions->actions());
196 menu.exec(pointGlobal);
199 void LayoutEditorWidget::splitActionSlot()
201 mViewData.
split(mSelection);
205 void LayoutEditorWidget::mergeActionSlot()
207 mViewData.
merge(mSelection);
211 void LayoutEditorWidget::groupActionSlot()
213 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
216 int group = sender->data().toInt();
218 std::set<LayoutData::iterator> selection = this->getSelectedViews();
219 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
220 (*iter)->mGroup = group;
225 void LayoutEditorWidget::typeActionSlot()
227 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
232 for (
unsigned i=0; i<mViewNames.size(); ++i)
233 if (mViewNames[i].mName == sender->text())
236 std::set<LayoutData::iterator> selection = this->getSelectedViews();
237 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
239 (*iter)->mPlane = type.mPlane;
240 (*iter)->mType = type.mView;
246 void LayoutEditorWidget::mouseMoveEvent(QMouseEvent* event)
248 this->updateSelection(event->pos());
251 void LayoutEditorWidget::updateSelection(QPoint pos)
256 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
262 std::set<LayoutData::iterator> LayoutEditorWidget::getSelectedViews()
264 std::set<LayoutData::iterator> retval;
271 void LayoutEditorWidget::mousePressEvent(QMouseEvent* event)
273 mClickPos =
event->pos();
275 if (event->button()==Qt::RightButton)
278 if (!mSelection.
contains(this->getViewData(mClickPos).mRegion.pos))
279 this->updateSelection(event->pos());
282 this->contextMenuSlot(event->pos());
287 this->updateSelection(event->pos());
291 void LayoutEditorWidget::colorRegion(
LayoutRegion region, QString selectColor, QString backColor)
303 mViewDataCache[pos.
row][pos.
col].mFrame->setStyleSheet(QString(
"QFrame { background-color: %1 }").arg(color));
315 if (!mViewDataCache[pos.
row][pos.
col].mFrame->geometry().contains(pt))
327 void LayoutEditorWidget::rowsColumnsChangedSlot()
329 mViewData.
resize(mRowsEdit->value(), mColsEdit->value());
330 this->setSaneGroupIDs();
334 QString LayoutEditorWidget::getViewName(
LayoutViewData data)
const 336 for (
unsigned i=0; i<mViewNames.size(); ++i)
338 if (mViewNames[i].mPlane==data.
mPlane && mViewNames[i].mView==data.
mType)
339 return mViewNames[i].mName;
347 void LayoutEditorWidget::setSaneGroupIDs()
360 void LayoutEditorWidget::updateGrid()
364 this->clearDisplay();
377 QString name = this->getViewName(*iter);
378 if (iter->mGroup<0 && name.isEmpty())
379 gridData.
mLabel->setText(
"NA");
381 gridData.
mLabel->setText(QString(
"%1/%2").arg(iter->mGroup).arg(name));
384 mNameEdit->setText(mViewData.
getName());
389 mRowsEdit->blockSignals(
true);
390 mRowsEdit->setValue(mViewData.
size().
row);
391 mRowsEdit->blockSignals(
false);
393 mColsEdit->blockSignals(
true);
394 mColsEdit->setValue(mViewData.
size().
col);
395 mColsEdit->blockSignals(
false);
398 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
422 void LayoutEditorWidget::clearDisplay()
424 for (
unsigned r = 0; r < mViewDataCache.size(); ++r)
426 for (
unsigned c = 0; c < mViewDataCache[r].size(); ++c)
428 mViewDataCache[r][c].mFrame->hide();
433 void LayoutEditorWidget::initCache()
437 mViewDataCache.resize(maxRows);
439 for (
int r = 0; r < maxRows; ++r)
441 mViewDataCache[r].resize(maxCols);
443 for (
int c = 0; c < maxCols; ++c)
445 QFrame* frame =
new QFrame(
this);
447 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
448 frame->setLineWidth(3);
449 frame->setLayout(
new QVBoxLayout);
450 QLabel* label =
new QLabel(
"NA", frame);
451 frame->layout()->addWidget(label);
453 mViewDataCache[r][c].mFrame = frame;
454 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.