mirror of
https://github.com/CURTLab/LVGLBuilder.git
synced 2025-05-08 19:40:36 +08:00
Save the resolution in the json project file
Save the resolution in the json project file and change the resolution if a new project is loaded
This commit is contained in:
parent
f9fa620e0a
commit
9a6a7a7c90
12
LVGLCore.cpp
12
LVGLCore.cpp
@ -15,7 +15,7 @@ QLVGL lvgl(nullptr);
|
|||||||
|
|
||||||
#include "LVGLObject.h"
|
#include "LVGLObject.h"
|
||||||
|
|
||||||
static void lvgl_core_flush_cb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
|
void lvgl_core_flush_cb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
|
||||||
{
|
{
|
||||||
QLVGL *self = reinterpret_cast<QLVGL*>(disp->user_data);
|
QLVGL *self = reinterpret_cast<QLVGL*>(disp->user_data);
|
||||||
self->dispFlush(disp, area, color_p);
|
self->dispFlush(disp, area, color_p);
|
||||||
@ -133,9 +133,9 @@ void QLVGL::init(int width, int height)
|
|||||||
//lv_log_register_print_cb(lvgl_print_cb);
|
//lv_log_register_print_cb(lvgl_print_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QLVGL::changeResolution(lv_coord_t width, lv_coord_t height)
|
bool QLVGL::changeResolution(QSize size)
|
||||||
{
|
{
|
||||||
const uint32_t n = static_cast<uint32_t>(width * height);
|
const uint32_t n = static_cast<uint32_t>(size.width() * size.height());
|
||||||
if (n != m_disp_buf.size) {
|
if (n != m_disp_buf.size) {
|
||||||
m_disp_framebuffer.resize(n);
|
m_disp_framebuffer.resize(n);
|
||||||
m_buf1.resize(n);
|
m_buf1.resize(n);
|
||||||
@ -143,8 +143,8 @@ bool QLVGL::changeResolution(lv_coord_t width, lv_coord_t height)
|
|||||||
lv_disp_buf_init(&m_disp_buf, m_buf1.data(), m_buf2.data(), n);
|
lv_disp_buf_init(&m_disp_buf, m_buf1.data(), m_buf2.data(), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_disp_drv.hor_res = static_cast<lv_coord_t>(width);
|
m_disp_drv.hor_res = static_cast<lv_coord_t>(size.width());
|
||||||
m_disp_drv.ver_res = static_cast<lv_coord_t>(height);
|
m_disp_drv.ver_res = static_cast<lv_coord_t>(size.height());
|
||||||
lv_disp_drv_update(lv_disp_get_default(), &m_disp_drv);
|
lv_disp_drv_update(lv_disp_get_default(), &m_disp_drv);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -170,7 +170,7 @@ QPixmap QLVGL::grab(const QRect ®ion) const
|
|||||||
QImage img(region.width(), region.height(), QImage::Format_ARGB32);
|
QImage img(region.width(), region.height(), QImage::Format_ARGB32);
|
||||||
for (auto y = 0; y < region.height(); ++y)
|
for (auto y = 0; y < region.height(); ++y)
|
||||||
memcpy(img.scanLine(y + region.y()),
|
memcpy(img.scanLine(y + region.y()),
|
||||||
&m_disp_framebuffer[y * stride + region.x()],
|
&m_disp_framebuffer[static_cast<size_t>(y * stride + region.x())],
|
||||||
static_cast<size_t>(stride) * 4
|
static_cast<size_t>(stride) * 4
|
||||||
);
|
);
|
||||||
return QPixmap::fromImage(img);
|
return QPixmap::fromImage(img);
|
||||||
|
@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
void init(int width, int height);
|
void init(int width, int height);
|
||||||
|
|
||||||
bool changeResolution(lv_coord_t width, lv_coord_t height);
|
bool changeResolution(QSize size);
|
||||||
|
|
||||||
QPixmap framebuffer() const;
|
QPixmap framebuffer() const;
|
||||||
QPixmap grab(const QRect ®ion) const;
|
QPixmap grab(const QRect ®ion) const;
|
||||||
@ -117,9 +117,9 @@ private:
|
|||||||
lv_style_t m_screen_style;
|
lv_style_t m_screen_style;
|
||||||
const LVGLFontData *m_defaultFont;
|
const LVGLFontData *m_defaultFont;
|
||||||
|
|
||||||
QVector<lv_color_t> m_disp_framebuffer;
|
std::vector<lv_color_t> m_disp_framebuffer;
|
||||||
QVector<lv_color_t> m_buf1;
|
std::vector<lv_color_t> m_buf1;
|
||||||
QVector<lv_color_t> m_buf2;
|
std::vector<lv_color_t> m_buf2;
|
||||||
lv_disp_buf_t m_disp_buf;
|
lv_disp_buf_t m_disp_buf;
|
||||||
lv_disp_drv_t m_disp_drv;
|
lv_disp_drv_t m_disp_drv;
|
||||||
|
|
||||||
|
@ -43,14 +43,14 @@ QString LVGLNewDialog::selectedName() const
|
|||||||
return m_ui->edit_name->text();
|
return m_ui->edit_name->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<lv_coord_t, lv_coord_t> LVGLNewDialog::selectedResolution() const
|
QSize LVGLNewDialog::selectedResolution() const
|
||||||
{
|
{
|
||||||
lv_coord_t w = static_cast<lv_coord_t>(m_ui->spin_width->value());
|
int w = m_ui->spin_width->value();
|
||||||
lv_coord_t h = static_cast<lv_coord_t>(m_ui->spin_height->value());
|
int h = m_ui->spin_height->value();
|
||||||
|
|
||||||
if (m_ui->radio_portrait->isChecked())
|
if (m_ui->radio_portrait->isChecked())
|
||||||
qSwap(w, h);
|
qSwap(w, h);
|
||||||
return qMakePair<lv_coord_t,lv_coord_t>(w, h);
|
return QSize(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LVGLNewDialog::accept()
|
void LVGLNewDialog::accept()
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
virtual ~LVGLNewDialog() override;
|
virtual ~LVGLNewDialog() override;
|
||||||
|
|
||||||
QString selectedName() const;
|
QString selectedName() const;
|
||||||
QPair<lv_coord_t,lv_coord_t> selectedResolution() const;
|
QSize selectedResolution() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void accept() override;
|
virtual void accept() override;
|
||||||
|
@ -15,11 +15,13 @@
|
|||||||
|
|
||||||
LVGLProject::LVGLProject()
|
LVGLProject::LVGLProject()
|
||||||
: m_name("App")
|
: m_name("App")
|
||||||
|
, m_resolution(LV_HOR_RES_MAX, LV_VER_RES_MAX)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LVGLProject::LVGLProject(const QString &name)
|
LVGLProject::LVGLProject(const QString &name, QSize resolution)
|
||||||
: m_name(name)
|
: m_name(name)
|
||||||
|
, m_resolution(resolution)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +30,11 @@ QString LVGLProject::name() const
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize LVGLProject::resolution() const
|
||||||
|
{
|
||||||
|
return m_resolution;
|
||||||
|
}
|
||||||
|
|
||||||
LVGLProject *LVGLProject::load(const QString &fileName)
|
LVGLProject *LVGLProject::load(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
@ -42,6 +49,14 @@ LVGLProject *LVGLProject::load(const QString &fileName)
|
|||||||
if (!lvglObj.contains("widgets"))
|
if (!lvglObj.contains("widgets"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
QSize resolution;
|
||||||
|
if (lvglObj.contains("resolution")) {
|
||||||
|
QJsonObject res = lvglObj["resolution"].toObject();
|
||||||
|
resolution = QSize(res["width"].toInt(), res["height"].toInt());
|
||||||
|
} else {
|
||||||
|
resolution = QSize(LV_HOR_RES_MAX, LV_VER_RES_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray imageArr = doc["images"].toArray();
|
QJsonArray imageArr = doc["images"].toArray();
|
||||||
for (int i = 0; i < imageArr.size(); ++i) {
|
for (int i = 0; i < imageArr.size(); ++i) {
|
||||||
LVGLImageData *img = new LVGLImageData(imageArr[i].toObject());
|
LVGLImageData *img = new LVGLImageData(imageArr[i].toObject());
|
||||||
@ -62,7 +77,7 @@ LVGLProject *LVGLProject::load(const QString &fileName)
|
|||||||
LVGLObject::parse(object, nullptr);
|
LVGLObject::parse(object, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LVGLProject(lvglObj["name"].toString());
|
return new LVGLProject(lvglObj["name"].toString(), resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LVGLProject::save(const QString &fileName) const
|
bool LVGLProject::save(const QString &fileName) const
|
||||||
@ -90,8 +105,12 @@ bool LVGLProject::save(const QString &fileName) const
|
|||||||
for (const LVGLFontData *f:lvgl.customFonts())
|
for (const LVGLFontData *f:lvgl.customFonts())
|
||||||
fontArr.append(f->toJson());
|
fontArr.append(f->toJson());
|
||||||
|
|
||||||
|
QJsonObject resolution({{"width", m_resolution.width()},
|
||||||
|
{"height", m_resolution.height()}
|
||||||
|
});
|
||||||
QJsonObject screen({{"widgets", widgetArr},
|
QJsonObject screen({{"widgets", widgetArr},
|
||||||
{"name", m_name}
|
{"name", m_name},
|
||||||
|
{"resolution", resolution}
|
||||||
});
|
});
|
||||||
if (lvgl.screenColorChanged())
|
if (lvgl.screenColorChanged())
|
||||||
screen.insert("screen color", QVariant(lvgl.screenColor()).toString());
|
screen.insert("screen color", QVariant(lvgl.screenColor()).toString());
|
||||||
|
@ -2,14 +2,16 @@
|
|||||||
#define LVGLPROJECT_H
|
#define LVGLPROJECT_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSize>
|
||||||
|
|
||||||
class LVGLProject
|
class LVGLProject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LVGLProject();
|
LVGLProject();
|
||||||
LVGLProject(const QString &name);
|
LVGLProject(const QString &name, QSize resolution);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
|
QSize resolution() const;
|
||||||
|
|
||||||
static LVGLProject *load(const QString &fileName);
|
static LVGLProject *load(const QString &fileName);
|
||||||
bool save(const QString &fileName) const;
|
bool save(const QString &fileName) const;
|
||||||
@ -17,6 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
QSize m_resolution;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,9 +146,9 @@ void LVGLSimulator::setMouseEnable(bool enable)
|
|||||||
m_mouseEnabled = enable;
|
m_mouseEnabled = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LVGLSimulator::changeResolution(lv_coord_t width, lv_coord_t height)
|
void LVGLSimulator::changeResolution(QSize size)
|
||||||
{
|
{
|
||||||
m_scene->setSceneRect(0, 0, width, height);
|
m_scene->setSceneRect(0, 0, size.width(), size.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LVGLSimulator::mousePressEvent(QMouseEvent *event)
|
void LVGLSimulator::mousePressEvent(QMouseEvent *event)
|
||||||
|
@ -50,7 +50,7 @@ public slots:
|
|||||||
void setZoomLevel(int level);
|
void setZoomLevel(int level);
|
||||||
void clear();
|
void clear();
|
||||||
void setMouseEnable(bool enable);
|
void setMouseEnable(bool enable);
|
||||||
void changeResolution(lv_coord_t width, lv_coord_t height);
|
void changeResolution(QSize size);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void objectSelected(LVGLObject *obj);
|
void objectSelected(LVGLObject *obj);
|
||||||
|
@ -168,7 +168,7 @@ void MainWindow::loadRecent()
|
|||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction*>(QObject::sender());
|
QAction *action = qobject_cast<QAction*>(QObject::sender());
|
||||||
if (action == nullptr) return;
|
if (action == nullptr) return;
|
||||||
loadUI(action->data().toString());
|
loadProject(action->data().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openNewProject()
|
void MainWindow::openNewProject()
|
||||||
@ -176,14 +176,14 @@ void MainWindow::openNewProject()
|
|||||||
LVGLNewDialog dialog(this);
|
LVGLNewDialog dialog(this);
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
delete m_project;
|
delete m_project;
|
||||||
m_project = new LVGLProject(dialog.selectedName());
|
m_project = new LVGLProject(dialog.selectedName(), dialog.selectedResolution());
|
||||||
m_ui->simulation->clear();
|
m_ui->simulation->clear();
|
||||||
setEnableBuilder(true);
|
setEnableBuilder(true);
|
||||||
setWindowTitle("LVGL Builder - [" + m_project->name() + "]");
|
setWindowTitle("LVGL Builder - [" + m_project->name() + "]");
|
||||||
const auto res = dialog.selectedResolution();
|
const auto res = dialog.selectedResolution();
|
||||||
lvgl.changeResolution(res.first, res.second);
|
lvgl.changeResolution(res);
|
||||||
m_ui->simulation->changeResolution(res.first, res.second);
|
m_ui->simulation->changeResolution(res);
|
||||||
} else {
|
} else if (m_project == nullptr) {
|
||||||
setEnableBuilder(false);
|
setEnableBuilder(false);
|
||||||
setWindowTitle("LVGL Builder");
|
setWindowTitle("LVGL Builder");
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ void MainWindow::adjustForCurrentFile(const QString &fileName)
|
|||||||
updateRecentActionList();
|
updateRecentActionList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadUI(const QString &fileName)
|
void MainWindow::loadProject(const QString &fileName)
|
||||||
{
|
{
|
||||||
delete m_project;
|
delete m_project;
|
||||||
m_ui->simulation->clear();
|
m_ui->simulation->clear();
|
||||||
@ -277,6 +277,8 @@ void MainWindow::loadUI(const QString &fileName)
|
|||||||
} else {
|
} else {
|
||||||
adjustForCurrentFile(fileName);
|
adjustForCurrentFile(fileName);
|
||||||
setWindowTitle("LVGL Builder - [" + m_project->name() + "]");
|
setWindowTitle("LVGL Builder - [" + m_project->name() + "]");
|
||||||
|
lvgl.changeResolution(m_project->resolution());
|
||||||
|
m_ui->simulation->changeResolution(m_project->resolution());
|
||||||
setEnableBuilder(true);
|
setEnableBuilder(true);
|
||||||
}
|
}
|
||||||
updateImages();
|
updateImages();
|
||||||
@ -299,7 +301,7 @@ void MainWindow::on_action_load_triggered()
|
|||||||
QString fileName = QFileDialog::getOpenFileName(this, "Load lvgl", "", "LVGL (*.lvgl)");
|
QString fileName = QFileDialog::getOpenFileName(this, "Load lvgl", "", "LVGL (*.lvgl)");
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
loadUI(fileName);
|
loadProject(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_action_save_triggered()
|
void MainWindow::on_action_save_triggered()
|
||||||
|
@ -58,7 +58,7 @@ private:
|
|||||||
|
|
||||||
void updateRecentActionList();
|
void updateRecentActionList();
|
||||||
void adjustForCurrentFile(const QString &fileName);
|
void adjustForCurrentFile(const QString &fileName);
|
||||||
void loadUI(const QString &fileName);
|
void loadProject(const QString &fileName);
|
||||||
void setEnableBuilder(bool enable);
|
void setEnableBuilder(bool enable);
|
||||||
|
|
||||||
Ui::MainWindow *m_ui;
|
Ui::MainWindow *m_ui;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user