mirror of
https://github.com/CURTLab/LVGLBuilder.git
synced 2025-05-09 03:41:35 +08:00
Fixed object inspector
This commit is contained in:
parent
5e8770ebc8
commit
a04a4ace85
@ -85,41 +85,41 @@ QVariant LVGLObjectModel::data(const QModelIndex &index, int role) const
|
||||
font.setBold(m_current == o);
|
||||
return font;
|
||||
}
|
||||
|
||||
// FIXME: Implement me!
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool LVGLObjectModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
void LVGLObjectModel::beginInsertObject(LVGLObject *obj)
|
||||
{
|
||||
int row = 0;
|
||||
LVGLObject *p = obj->parent();
|
||||
QModelIndex parent;
|
||||
if (p) {
|
||||
row = p->childs().indexOf(obj);
|
||||
parent = objIndex(p, 0);
|
||||
}
|
||||
beginInsertRows(parent, row, row);
|
||||
}
|
||||
|
||||
void LVGLObjectModel::endInsertObject()
|
||||
{
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LVGLObjectModel::insertColumns(int column, int count, const QModelIndex &parent)
|
||||
void LVGLObjectModel::beginRemoveObject(LVGLObject *obj)
|
||||
{
|
||||
beginInsertColumns(parent, column, column + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertColumns();
|
||||
return true;
|
||||
int row = 0;
|
||||
LVGLObject *p = obj->parent();
|
||||
QModelIndex parent;
|
||||
if (p) {
|
||||
row = p->childs().indexOf(obj);
|
||||
parent = objIndex(p, 0);
|
||||
}
|
||||
beginRemoveRows(parent, row, row);
|
||||
}
|
||||
|
||||
bool LVGLObjectModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
void LVGLObjectModel::endRemoveObject()
|
||||
{
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LVGLObjectModel::removeColumns(int column, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginRemoveColumns(parent, column, column + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endRemoveColumns();
|
||||
return true;
|
||||
}
|
||||
|
||||
LVGLObject *LVGLObjectModel::object(const QModelIndex &index) const
|
||||
@ -132,6 +132,7 @@ LVGLObject *LVGLObjectModel::object(const QModelIndex &index) const
|
||||
void LVGLObjectModel::setCurrentObject(LVGLObject *obj)
|
||||
{
|
||||
LVGLObject *old = m_current;
|
||||
m_current = obj;
|
||||
emit dataChanged(objIndex(obj, 0), objIndex(obj, 1), QVector<int>({Qt::FontRole}));
|
||||
emit dataChanged(objIndex(old, 0), objIndex(old, 1), QVector<int>({Qt::FontRole}));
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ public:
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Add data:
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
// Add object
|
||||
void beginInsertObject(LVGLObject *obj);
|
||||
void endInsertObject();
|
||||
|
||||
// Remove data:
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
// Remove object
|
||||
void beginRemoveObject(LVGLObject *obj);
|
||||
void endRemoveObject();
|
||||
|
||||
LVGLObject *object(const QModelIndex &index) const;
|
||||
|
||||
|
@ -20,6 +20,10 @@
|
||||
#include "LVGLCore.h"
|
||||
#include "properties/LVGLPropertyGeometry.h"
|
||||
#include "LVGLFontData.h"
|
||||
#include "LVGLItem.h"
|
||||
#include "LVGLObject.h"
|
||||
#include "LVGLProject.h"
|
||||
#include "LVGLObjectModel.h"
|
||||
|
||||
#define IS_PAGE_OF_TABVIEW(o) ((o->widgetType() == LVGLWidget::Page) && (o->index() >= 0) && o->parent() && (o->parent()->widgetType() == LVGLWidget::Tabview))
|
||||
|
||||
@ -83,6 +87,7 @@ LVGLSimulator::LVGLSimulator(QWidget *parent)
|
||||
, m_selectedObject(nullptr)
|
||||
, m_mouseEnabled(false)
|
||||
, m_item(new LVGLItem)
|
||||
, m_objectModel(nullptr)
|
||||
{
|
||||
//setMinimumSize(LV_HOR_RES_MAX, LV_VER_RES_MAX);
|
||||
//setMaximumSize(LV_HOR_RES_MAX, LV_VER_RES_MAX);
|
||||
@ -120,6 +125,9 @@ void LVGLSimulator::setSelectedObject(LVGLObject *obj)
|
||||
|
||||
m_selectedObject = obj;
|
||||
m_item->setObject(obj);
|
||||
if (m_objectModel)
|
||||
m_objectModel->setCurrentObject(obj);
|
||||
|
||||
emit objectSelected(m_selectedObject);
|
||||
update();
|
||||
}
|
||||
@ -280,16 +288,9 @@ void LVGLSimulator::dropEvent(QDropEvent *event)
|
||||
pos.setY(lvgl.height() - size.height());
|
||||
newObj->setGeometry(QRect(pos, size));
|
||||
}
|
||||
|
||||
qDebug().noquote() << "Class:" << widgetClass->className() << "Id:" << newObj->name();
|
||||
|
||||
connect(newObj, &LVGLObject::positionChanged,
|
||||
m_item, &LVGLItem::updateGeometry
|
||||
);
|
||||
lvgl.addObject(newObj);
|
||||
setSelectedObject(newObj);
|
||||
setFocus();
|
||||
|
||||
emit objectAdded(newObj);
|
||||
addObject(newObj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,6 +349,11 @@ QList<LVGLObject *> LVGLSimulator::objectsUnderCoords(QPoint pos, bool includeLo
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LVGLSimulator::setObjectModel(LVGLObjectModel *objectModel)
|
||||
{
|
||||
m_objectModel = objectModel;
|
||||
}
|
||||
|
||||
LVGLItem *LVGLSimulator::item() const
|
||||
{
|
||||
return m_item;
|
||||
@ -366,6 +372,41 @@ void LVGLSimulator::moveObject(LVGLObject *obj, int dx, int dy)
|
||||
}
|
||||
}
|
||||
|
||||
void LVGLSimulator::addObject(LVGLObject *obj)
|
||||
{
|
||||
connect(obj, &LVGLObject::positionChanged,
|
||||
m_item, &LVGLItem::updateGeometry
|
||||
);
|
||||
|
||||
// add to object viewer
|
||||
if (m_objectModel)
|
||||
m_objectModel->beginInsertObject(obj);
|
||||
|
||||
// add object to interal list
|
||||
lvgl.addObject(obj);
|
||||
|
||||
if (m_objectModel)
|
||||
m_objectModel->endInsertObject();
|
||||
|
||||
setSelectedObject(obj);
|
||||
setFocus();
|
||||
|
||||
emit objectAdded(obj);
|
||||
}
|
||||
|
||||
void LVGLSimulator::removeObject(LVGLObject *obj)
|
||||
{
|
||||
setSelectedObject(nullptr);
|
||||
|
||||
if (m_objectModel)
|
||||
m_objectModel->beginRemoveObject(obj);
|
||||
|
||||
lvgl.removeObject(obj);
|
||||
|
||||
if (m_objectModel)
|
||||
m_objectModel->endRemoveObject();
|
||||
}
|
||||
|
||||
LVGLObject *LVGLSimulator::selectedObject() const
|
||||
{
|
||||
return m_selectedObject;
|
||||
@ -388,8 +429,7 @@ bool LVGLKeyPressEventFilter::eventFilter(QObject *obj, QEvent *event)
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Delete) {
|
||||
LVGLObject *obj = m_sim->selectedObject();
|
||||
m_sim->setSelectedObject(nullptr);
|
||||
lvgl.removeObject(obj);
|
||||
m_sim->removeObject(obj);
|
||||
return true;
|
||||
} else if (keyEvent->key() == Qt::Key_Left) {
|
||||
m_sim->moveObject(m_sim->selectedObject(), -1, 0);
|
||||
@ -408,10 +448,8 @@ bool LVGLKeyPressEventFilter::eventFilter(QObject *obj, QEvent *event)
|
||||
if (obj) {
|
||||
QJsonDocument doc(obj->toJson());
|
||||
QApplication::clipboard()->setText(doc.toJson(QJsonDocument::Compact));
|
||||
if (keyEvent->key() == Qt::Key_X) {
|
||||
m_sim->setSelectedObject(nullptr);
|
||||
lvgl.removeObject(obj);
|
||||
}
|
||||
if (keyEvent->key() == Qt::Key_X)
|
||||
m_sim->removeObject(obj);
|
||||
}
|
||||
return true;
|
||||
} else if (keyEvent->modifiers() & Qt::ControlModifier && keyEvent->key() == Qt::Key_V) {
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "LVGLItem.h"
|
||||
#include "LVGLObject.h"
|
||||
#include "LVGLProject.h"
|
||||
class LVGLObject;
|
||||
class LVGLItem;
|
||||
class LVGLObjectModel;
|
||||
|
||||
class LVGLScene : public QGraphicsScene
|
||||
{
|
||||
@ -44,6 +44,10 @@ public:
|
||||
LVGLItem *item() const;
|
||||
|
||||
void moveObject(LVGLObject *obj, int dx, int dy);
|
||||
void addObject(LVGLObject *obj);
|
||||
void removeObject(LVGLObject *obj);
|
||||
|
||||
void setObjectModel(LVGLObjectModel *objectModel);
|
||||
|
||||
public slots:
|
||||
void setSelectedObject(LVGLObject *obj);
|
||||
@ -80,6 +84,7 @@ private:
|
||||
LVGLObject *m_selectedObject;
|
||||
bool m_mouseEnabled;
|
||||
LVGLItem *m_item;
|
||||
LVGLObjectModel *m_objectModel;
|
||||
|
||||
};
|
||||
|
||||
|
@ -8,8 +8,11 @@
|
||||
|
||||
#include "widgets/LVGLWidgets.h"
|
||||
|
||||
#include "LVGLDialog.h"
|
||||
#include "LVGLItem.h"
|
||||
#include "LVGLProject.h"
|
||||
#include "LVGLFontData.h"
|
||||
|
||||
#include "LVGLDialog.h"
|
||||
#include "LVGLNewDialog.h"
|
||||
#include "LVGLFontDialog.h"
|
||||
|
||||
@ -51,6 +54,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(m_ui->action_new, &QAction::triggered,
|
||||
this, &MainWindow::openNewProject
|
||||
);
|
||||
connect(m_ui->simulation, &LVGLSimulator::objectAdded,
|
||||
m_ui->object_tree, &QTreeView::expandAll
|
||||
);
|
||||
|
||||
m_ui->property_tree->setModel(m_propertyModel);
|
||||
m_ui->property_tree->setItemDelegate(new LVGLPropertyDelegate);
|
||||
@ -64,6 +70,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_ui->simulation->setSelectedObject(m_objectModel->object(index));
|
||||
});
|
||||
m_ui->object_tree->setModel(m_objectModel);
|
||||
m_ui->simulation->setObjectModel(m_objectModel);
|
||||
|
||||
LVGLWidgetModel *widgetModel = new LVGLWidgetModel;
|
||||
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user