DataWidget* WidgetArea::loadOneWidget(DataFileParser *file, bool skip) { // type if(!file->seekToNextBlock("widgetType", BLOCK_WIDGET)) return NULL; quint8 type = 0; file->read((char*)&type, sizeof(quint8)); // pos and size if(!file->seekToNextBlock("widgetPosSize", BLOCK_WIDGET)) return NULL; int val[4]; file->read((char*)&val, sizeof(val)); DataWidget *w = addWidget(QPoint(val[0], val[1]), type, !skip); if(!w) return NULL; w->resize(val[2], val[3]); w->loadWidgetInfo(file); if(skip) removeWidget(w->getId()); else updateMarker(w); return w; }
void WidgetArea::dropEvent(QDropEvent *event) { QString data = event->mimeData()->text().remove(0, 1); quint8 type = data.toInt(); event->acceptProposedAction(); DataWidget *w = addWidget(event->pos(), type); if(m_grid != 1) w->align(); }
UndoAction *MoveAction::restore(WidgetArea *area) { DataWidget *w = area->getWidget(m_id); if(!w) return NULL; UndoAction *opposite = new MoveAction(w); w->setScaledUp(m_scaledUp); w->move(m_pos); w->resize(m_size); return opposite; }
UndoAction *MoveGroupAction::restore(WidgetArea *area) { MoveGroupAction *opposite = new MoveGroupAction(std::set<DataWidget*>()); for(QHash<quint32, QPoint>::iterator itr = m_positions.begin(); itr != m_positions.end(); ++itr) { DataWidget *w = area->getWidget(itr.key()); if(!w) continue; opposite->addWidget(w); w->move(*itr); } if(opposite->empty()) { delete opposite; return NULL; } return opposite; }
QRegion WidgetArea::getRegionWithWidgets() { QPoint p; QSize s = size(); for(w_map::iterator itr = m_widgets.begin(); itr != m_widgets.end(); ++itr) { DataWidget *w = *itr; p.rx() = std::min(w->x(), p.x()); p.ry() = std::min(w->y(), p.y()); s.rwidth() = std::max(s.width(), w->x() + w->width()); s.rheight() = std::max(s.height(), w->y() + w->height()); } s.rwidth() += abs(p.x()); s.rheight() += abs(p.y()); return QRegion(QRect(p, s)); }
DataWidget *WidgetArea::addWidget(QPoint pos, quint8 type, bool show) { DataWidget *w = sWidgetFactory.getWidget(type, this); if(!w) return NULL; quint32 id = getNewId(); w->setId(id); w->setUp(m_storage); w->move(pos); if(show) w->show(); m_widgets.insert(id, w); connect(w, SIGNAL(removeWidget(quint32)), SLOT(removeWidget(quint32))); connect(w, SIGNAL(updateMarker(DataWidget*)), SLOT(updateMarker(DataWidget*))); connect(w, SIGNAL(clearPlacementLines()), SLOT(clearPlacementLines())); connect(w, SIGNAL(updateData()), SIGNAL(updateData())); connect(w, SIGNAL(mouseStatus(bool,data_widget_info,qint32)), SIGNAL(mouseStatus(bool,data_widget_info,qint32))); connect(w, SIGNAL(SendData(QByteArray)), m_analyzer, SIGNAL(SendData(QByteArray))); connect(w, SIGNAL(toggleSelection(bool)), SLOT(toggleSelection(bool))); connect(this, SIGNAL(setTitleVisibility(bool)), w, SLOT(setTitleVisibility(bool))); connect(w, SIGNAL(addChildTab(ChildTab*,QString)), m_analyzer, SLOT(addChildTab(ChildTab*,QString))); connect(w, SIGNAL(removeChildTab(ChildTab*)), m_analyzer, SLOT(removeChildTab(ChildTab*))); connect(w, SIGNAL(addUndoAct(UndoAction*)),&m_undoStack,SLOT(addAction(UndoAction*))); connect(m_analyzer, SIGNAL(rawData(QByteArray)), w, SIGNAL(rawData(QByteArray))); connect(this, SIGNAL(setLocked(bool)), w, SLOT(setLocked(bool))); //events connect(this, SIGNAL(onWidgetAdd(DataWidget*)), w, SLOT(onWidgetAdd(DataWidget*))); connect(this, SIGNAL(onWidgetRemove(DataWidget*)), w, SLOT(onWidgetRemove(DataWidget*))); connect(this, SIGNAL(onScriptEvent(QString)), w, SLOT(onScriptEvent(QString))); connect(this, SIGNAL(onScriptEvent(QString,QVariantList)), w, SLOT(onScriptEvent(QString, QVariantList))); connect(w, SIGNAL(scriptEvent(QString)), this, SIGNAL(onScriptEvent(QString))); connect(w, SIGNAL(scriptEvent(QString, QVariantList)),this, SIGNAL(onScriptEvent(QString, QVariantList))); emit onWidgetAdd(w); m_analyzer->setDataChanged(); w->setTitleVisibility(m_actTitleVisibility->isChecked()); return w; }