48 mTopLayout =
new QVBoxLayout(
this);
49 QHBoxLayout* nameLayout =
new QHBoxLayout;
50 mTopLayout->addLayout(nameLayout);
51 mRCLayout =
new QHBoxLayout;
52 mTopLayout->addLayout(mRCLayout);
53 mLayout =
new QGridLayout;
54 mLayout->setMargin(0);
55 mLayout->setSpacing(2);
56 mTopLayout->addLayout(mLayout);
58 mNameEdit =
new QLineEdit;
59 connect(mNameEdit, SIGNAL(editingFinished()),
this, SLOT(nameChanged()));
60 nameLayout->addWidget(
new QLabel(
"Name"));
61 nameLayout->addWidget(mNameEdit);
64 mRowsEdit =
new QSpinBox;
65 mRowsEdit->setRange(1,10);
66 mColsEdit =
new QSpinBox;
67 mColsEdit->setRange(1,10);
68 connect(mRowsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
69 connect(mColsEdit, SIGNAL(valueChanged(
int)),
this, SLOT(rowsColumnsChangedSlot()));
70 mRCLayout->addWidget(
new QLabel(
"Rows"));
71 mRCLayout->addWidget(mRowsEdit);
72 mRCLayout->addWidget(
new QLabel(
"Columns"));
73 mRCLayout->addWidget(mColsEdit);
74 mRCLayout->addStretch();
78 PLANE_TYPE type =
static_cast<PLANE_TYPE
>(i);
104 void LayoutEditorWidget::nameChanged()
106 mViewData.
setName(mNameEdit->text());
109 void LayoutEditorWidget::contextMenuSlot(
const QPoint& point)
112 QPoint pointGlobal = this->mapToGlobal(point);
115 LayoutViewData viewData = this->getViewData(point);
117 QAction* mergeAction =
new QAction(
"merge view", &menu);
118 mergeAction->setEnabled(this->getSelectedViews().size()>1);
119 connect(mergeAction, SIGNAL(triggered()),
this, SLOT(mergeActionSlot()));
120 menu.addAction(mergeAction);
122 QAction* splitAction =
new QAction(
"split view", &menu);
123 splitAction->setEnabled(mSelection.
span.
row!=1 || mSelection.
span.
col!=1);
124 connect(splitAction, SIGNAL(triggered()),
this, SLOT(splitActionSlot()));
125 menu.addAction(splitAction);
132 QActionGroup* groupActions =
new QActionGroup(
this);
133 for (
int i=0; i<viewGroupCount; ++i)
135 QAction* action =
new QAction(QString(
"Group %1").arg(i), groupActions);
136 action->setData(QVariant(i));
137 action->setCheckable(
true);
138 connect(action, SIGNAL(triggered()),
this, SLOT(groupActionSlot()));
139 action->setChecked(viewData.mGroup==i);
144 menu.addActions(groupActions->actions());
148 QActionGroup* typeActions =
new QActionGroup(
this);
150 for (
unsigned i=0; i<mViewNames.size(); ++i)
152 ViewNamesType current = mViewNames[i];
157 QAction* action =
new QAction(QString(
"%1").arg(current.mName), typeActions);
159 action->setCheckable(
true);
160 connect(action, SIGNAL(triggered()),
this, SLOT(typeActionSlot()));
161 action->setChecked(viewData.mPlane==current.mPlane && viewData.mType==current.mView);
176 menu.addActions(typeActions->actions());
178 menu.exec(pointGlobal);
181 void LayoutEditorWidget::splitActionSlot()
183 mViewData.
split(mSelection);
187 void LayoutEditorWidget::mergeActionSlot()
189 mViewData.
merge(mSelection);
193 void LayoutEditorWidget::groupActionSlot()
195 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
198 int group = sender->data().toInt();
200 std::set<LayoutData::iterator> selection = this->getSelectedViews();
201 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
202 (*iter)->mGroup = group;
207 void LayoutEditorWidget::typeActionSlot()
209 QAction* sender =
dynamic_cast<QAction*
>(this->sender());
214 for (
unsigned i=0; i<mViewNames.size(); ++i)
215 if (mViewNames[i].mName == sender->text())
218 std::set<LayoutData::iterator> selection = this->getSelectedViews();
219 for (std::set<LayoutData::iterator>::iterator iter=selection.begin(); iter!=selection.end(); ++iter)
221 (*iter)->mPlane = type.mPlane;
222 (*iter)->mType = type.mView;
228 void LayoutEditorWidget::mouseMoveEvent(QMouseEvent* event)
230 this->updateSelection(event->pos());
233 void LayoutEditorWidget::updateSelection(QPoint pos)
235 LayoutViewData start = this->getViewData(mClickPos);
236 LayoutViewData stop = this->getViewData(pos);
237 mSelection =
merge(start.mRegion, stop.mRegion);
238 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
244 std::set<LayoutData::iterator> LayoutEditorWidget::getSelectedViews()
246 std::set<LayoutData::iterator> retval;
249 retval.insert(mViewData.
find(LayoutPosition(r,c)));
253 void LayoutEditorWidget::mousePressEvent(QMouseEvent* event)
255 mClickPos =
event->pos();
257 if (event->button()==Qt::RightButton)
260 if (!mSelection.
contains(this->getViewData(mClickPos).mRegion.pos))
261 this->updateSelection(event->pos());
264 this->contextMenuSlot(event->pos());
269 this->updateSelection(event->pos());
273 void LayoutEditorWidget::colorRegion(LayoutRegion region, QString selectColor, QString backColor)
277 LayoutPosition pos = iter->mRegion.pos;
280 if (region.contains(pos))
285 mViewDataCache[pos.row][pos.col].mFrame->setStyleSheet(QString(
"QFrame { background-color: %1 }").arg(color));
292 LayoutViewData LayoutEditorWidget::getViewData(QPoint pt)
296 LayoutPosition pos = iter->mRegion.pos;
297 if (!mViewDataCache[pos.row][pos.col].mFrame->geometry().contains(pt))
303 return LayoutViewData();
309 void LayoutEditorWidget::rowsColumnsChangedSlot()
311 mViewData.
resize(mRowsEdit->value(), mColsEdit->value());
312 this->setSaneGroupIDs();
316 QString LayoutEditorWidget::getViewName(LayoutViewData data)
const
318 for (
unsigned i=0; i<mViewNames.size(); ++i)
320 if (mViewNames[i].mPlane==data.mPlane && mViewNames[i].mView==data.mType)
321 return mViewNames[i].mName;
329 void LayoutEditorWidget::setSaneGroupIDs()
342 void LayoutEditorWidget::updateGrid()
346 this->clearDisplay();
351 LayoutRegion region = iter->mRegion;
352 GridElement gridData = mViewDataCache[region.pos.row][region.pos.col];
355 mLayout->addWidget(gridData.mFrame, region.pos.row, region.pos.col, region.span.row, region.span.col);
356 gridData.mFrame->show();
359 QString name = this->getViewName(*iter);
360 if (iter->mGroup<0 && name.isEmpty())
361 gridData.mLabel->setText(
"NA");
363 gridData.mLabel->setText(QString(
"%1/%2").arg(iter->mGroup).arg(name));
366 mNameEdit->setText(mViewData.
getName());
370 mRowsEdit->blockSignals(
true);
371 mRowsEdit->setValue(mViewData.
size().
row);
372 mRowsEdit->blockSignals(
false);
374 mColsEdit->blockSignals(
true);
375 mColsEdit->setValue(mViewData.
size().
col);
376 mColsEdit->blockSignals(
false);
379 this->colorRegion(mSelection,
"dimgrey",
"lightgrey");
403 void LayoutEditorWidget::clearDisplay()
405 for (
unsigned r = 0; r < mViewDataCache.size(); ++r)
407 for (
unsigned c = 0; c < mViewDataCache[r].size(); ++c)
409 mViewDataCache[r][c].mFrame->hide();
414 void LayoutEditorWidget::initCache()
418 mViewDataCache.resize(maxRows);
420 for (
int r = 0; r < maxRows; ++r)
422 mViewDataCache[r].resize(maxCols);
424 for (
int c = 0; c < maxCols; ++c)
426 QFrame* frame =
new QFrame(
this);
428 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
429 frame->setLineWidth(3);
430 frame->setLayout(
new QVBoxLayout);
431 QLabel* label =
new QLabel(
"NA", frame);
432 frame->layout()->addWidget(label);
434 mViewDataCache[r][c].mFrame = frame;
435 mViewDataCache[r][c].mLabel = label;
QString qstring_cast(const T &val)
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
ptNOPLANE
a initial plane, if no yet set
cxLogicManager_EXPORT ViewServicePtr viewService()
LayoutPosition pos
start position of region
LayoutRegion merge(LayoutRegion a, LayoutRegion b)