50 mTopLayout =
new QVBoxLayout(
this);
51 QHBoxLayout* nameLayout =
new QHBoxLayout;
52 mTopLayout->addLayout(nameLayout);
53 mRCLayout =
new QHBoxLayout;
54 mTopLayout->addLayout(mRCLayout);
55 mLayout =
new QGridLayout;
56 mLayout->setMargin(0);
57 mLayout->setSpacing(2);
58 mTopLayout->addLayout(mLayout);
60 mNameEdit =
new QLineEdit;
61 connect(mNameEdit, SIGNAL(editingFinished()),
this, SLOT(nameChanged()));
62 nameLayout->addWidget(
new QLabel(
"Name"));
63 nameLayout->addWidget(mNameEdit);
67 mRowsEdit =
new QSpinBox;
69 mColsEdit =
new QSpinBox;
71 connect(mRowsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
72 connect(mColsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
73 mRCLayout->addWidget(
new QLabel(
"Rows"));
74 mRCLayout->addWidget(mRowsEdit);
75 mRCLayout->addWidget(
new QLabel(
"Columns"));
76 mRCLayout->addWidget(mColsEdit);
77 mRCLayout->addStretch();
81 PLANE_TYPE type =
static_cast<PLANE_TYPE
>(i);
94 "Render the layout to memory only.\n"
95 "This will cause the displayed area to be black,\n"
96 "but the application can access the rendering programatically.",
99 connect(mOffScreenRendering.get(), &
BoolProperty::changed,
this, &LayoutEditorWidget::onOffScreenRenderingChanged);
116 void LayoutEditorWidget::onOffScreenRenderingChanged()
121 void LayoutEditorWidget::nameChanged()
123 mViewData.
setName(mNameEdit->text());
126 void LayoutEditorWidget::contextMenuSlot(
const QPoint& point)
129 QPoint pointGlobal = this->mapToGlobal(point);
132 LayoutViewData viewData = this->getViewData(point);
134 QAction* mergeAction =
new QAction(
"merge view", &menu);
135 mergeAction->setEnabled(this->getSelectedViews().size()>1);
136 connect(mergeAction, SIGNAL(triggered()),
this, SLOT(mergeActionSlot()));
137 menu.addAction(mergeAction);
139 QAction* splitAction =
new QAction(
"split view", &menu);
140 splitAction->setEnabled(mSelection.
span.
row!=1 || mSelection.
span.
col!=1);
141 connect(splitAction, SIGNAL(triggered()),
this, SLOT(splitActionSlot()));
142 menu.addAction(splitAction);
149 QActionGroup* groupActions =
new QActionGroup(
this);
150 for (
int i=0; i<viewGroupCount; ++i)
152 QAction* action =
new QAction(QString(
"Group %1").arg(i), groupActions);
153 action->setData(QVariant(i));
154 action->setCheckable(
true);
155 connect(action, SIGNAL(triggered()),
this, SLOT(groupActionSlot()));
156 action->setChecked(viewData.mGroup==i);
161 menu.addActions(groupActions->actions());
165 QActionGroup* typeActions =
new QActionGroup(
this);
167 for (
unsigned i=0; i<mViewNames.size(); ++i)
169 ViewNamesType current = mViewNames[i];
174 QAction* action =
new QAction(QString(
"%1").arg(current.mName), typeActions);
176 action->setCheckable(
true);
177 connect(action, SIGNAL(triggered()),
this, SLOT(typeActionSlot()));
178 action->setChecked(viewData.mPlane==current.mPlane && viewData.mType==current.mView);
193 menu.addActions(typeActions->actions());
195 menu.exec(pointGlobal);
198 void LayoutEditorWidget::splitActionSlot()
200 mViewData.
split(mSelection);
204 void LayoutEditorWidget::mergeActionSlot()
206 mViewData.
merge(mSelection);
210 void LayoutEditorWidget::groupActionSlot()
212 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
215 int group = sender->data().toInt();
217 std::set<LayoutData::iterator> selection = this->getSelectedViews();
218 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
219 (*iter)->mGroup = group;
224 void LayoutEditorWidget::typeActionSlot()
226 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
231 for (
unsigned i=0; i<mViewNames.size(); ++i)
232 if (mViewNames[i].mName == sender->text())
235 std::set<LayoutData::iterator> selection = this->getSelectedViews();
236 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
238 (*iter)->mPlane = type.mPlane;
239 (*iter)->mType = type.mView;
245 void LayoutEditorWidget::mouseMoveEvent(QMouseEvent* event)
247 this->updateSelection(event->pos());
250 void LayoutEditorWidget::updateSelection(QPoint pos)
252 LayoutViewData start = this->getViewData(mClickPos);
253 LayoutViewData stop = this->getViewData(pos);
254 mSelection =
merge(start.mRegion, stop.mRegion);
255 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
261 std::set<LayoutData::iterator> LayoutEditorWidget::getSelectedViews()
263 std::set<LayoutData::iterator> retval;
266 retval.insert(mViewData.
find(LayoutPosition(r,c)));
270 void LayoutEditorWidget::mousePressEvent(QMouseEvent* event)
272 mClickPos =
event->pos();
274 if (event->button()==Qt::RightButton)
277 if (!mSelection.
contains(this->getViewData(mClickPos).mRegion.pos))
278 this->updateSelection(event->pos());
281 this->contextMenuSlot(event->pos());
286 this->updateSelection(event->pos());
290 void LayoutEditorWidget::colorRegion(LayoutRegion region, QString selectColor, QString backColor)
294 LayoutPosition pos = iter->mRegion.pos;
297 if (region.contains(pos))
302 mViewDataCache[pos.row][pos.col].mFrame->setStyleSheet(QString(
"QFrame { background-color: %1 }").arg(color));
309 LayoutViewData LayoutEditorWidget::getViewData(QPoint pt)
313 LayoutPosition pos = iter->mRegion.pos;
314 if (!mViewDataCache[pos.row][pos.col].mFrame->geometry().contains(pt))
320 return LayoutViewData();
326 void LayoutEditorWidget::rowsColumnsChangedSlot()
328 mViewData.
resize(mRowsEdit->value(), mColsEdit->value());
329 this->setSaneGroupIDs();
333 QString LayoutEditorWidget::getViewName(LayoutViewData data)
const
335 for (
unsigned i=0; i<mViewNames.size(); ++i)
337 if (mViewNames[i].mPlane==data.mPlane && mViewNames[i].mView==data.mType)
338 return mViewNames[i].mName;
346 void LayoutEditorWidget::setSaneGroupIDs()
359 void LayoutEditorWidget::updateGrid()
363 this->clearDisplay();
368 LayoutRegion region = iter->mRegion;
369 GridElement gridData = mViewDataCache[region.pos.row][region.pos.col];
372 mLayout->addWidget(gridData.mFrame, region.pos.row, region.pos.col, region.span.row, region.span.col);
373 gridData.mFrame->show();
376 QString name = this->getViewName(*iter);
377 if (iter->mGroup<0 && name.isEmpty())
378 gridData.mLabel->setText(
"NA");
380 gridData.mLabel->setText(QString(
"%1/%2").arg(iter->mGroup).arg(name));
383 mNameEdit->setText(mViewData.
getName());
388 mRowsEdit->blockSignals(
true);
389 mRowsEdit->setValue(mViewData.
size().
row);
390 mRowsEdit->blockSignals(
false);
392 mColsEdit->blockSignals(
true);
393 mColsEdit->setValue(mViewData.
size().
col);
394 mColsEdit->blockSignals(
false);
397 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
421 void LayoutEditorWidget::clearDisplay()
423 for (
unsigned r = 0; r < mViewDataCache.size(); ++r)
425 for (
unsigned c = 0; c < mViewDataCache[r].size(); ++c)
427 mViewDataCache[r][c].mFrame->hide();
432 void LayoutEditorWidget::initCache()
436 mViewDataCache.resize(maxRows);
438 for (
int r = 0; r < maxRows; ++r)
440 mViewDataCache[r].resize(maxCols);
442 for (
int c = 0; c < maxCols; ++c)
444 QFrame* frame =
new QFrame(
this);
446 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
447 frame->setLineWidth(3);
448 frame->setLayout(
new QVBoxLayout);
449 QLabel* label =
new QLabel(
"NA", frame);
450 frame->layout()->addWidget(label);
452 mViewDataCache[r][c].mFrame = frame;
453 mViewDataCache[r][c].mLabel = label;
QString qstring_cast(const T &val)
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)
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
cxLogicManager_EXPORT ViewServicePtr viewService()
LayoutPosition pos
start position of region
void setOffScreenRendering(bool val)
LayoutRegion merge(LayoutRegion a, LayoutRegion b)
bool getOffScreenRendering() const