Skip to content

Commit

Permalink
Realize some event functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrQzs committed May 29, 2021
1 parent a6fa243 commit ce17165
Show file tree
Hide file tree
Showing 102 changed files with 402,850 additions and 358,612 deletions.
14 changes: 2 additions & 12 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(this, &MainWindow::stopAutoSave, m_autosaveThread,
&LVGLAutoSaveThread::stop);
m_asThread->start();

LVGLLog::log_trace("Main started", __FILE__, __LINE__, __func__);
}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -215,7 +213,8 @@ MainWindow::~MainWindow() {
delete m_ld2;
delete m_ld3;
delete m_project;
LVGLLog::log_trace("Main deleted", __FILE__, __LINE__, __func__);
ushort a;
uchar(1);
}

LVGLSimulator *MainWindow::simulator() const { return m_curSimulation; }
Expand Down Expand Up @@ -254,8 +253,6 @@ void MainWindow::setCurrentObject(LVGLObject *obj) {
m_styleModel->setLvglObj(obj);
m_styleModel->setObj(nullptr);
if (obj) {
LVGLLog::log_trace(QString("%1 selected").arg(obj->name()), __FILE__,
__LINE__, __func__);
auto parts = obj->widgetClass()->parts();
m_styleModel->setPart(parts[0]);
m_styleModel->setObj(obj->obj());
Expand Down Expand Up @@ -401,8 +398,6 @@ void MainWindow::adjustForCurrentFile(const QString &fileName) {
}

void MainWindow::loadProject(const QString &fileName) {
LVGLLog::log_trace(QString("%1 load").arg(fileName), __FILE__, __LINE__,
__func__);
delete m_project;
m_project = nullptr;
int index = m_ui->tabWidget->currentIndex();
Expand Down Expand Up @@ -541,13 +536,8 @@ void MainWindow::on_action_save_triggered() {

if (!m_project->save(fileName)) {
QMessageBox::critical(this, "Error", "Could not save lvgl file!");
LVGLLog::getInstance().log_error(
QString("Could not save %1!").arg(fileName), __FILE__, __LINE__,
__func__);
} else {
adjustForCurrentFile(fileName);
LVGLLog::log_trace(QString("%1 save").arg(fileName), __FILE__, __LINE__,
__func__);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/LVGLCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ const LVGLWidget *LVGLCore::widget(const QString &name) const {
return new LVGLCanvas;
else if (name == "lv_chart")
return new LVGLChart;
else if (name == "lv_cb")
else if (name == "lv_checkbox")
return new LVGLCheckBox;
else if (name == "lv_cpicker")
return new LVGLColorPicker;
Expand Down
7 changes: 6 additions & 1 deletion core/LVGLHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class LVGLHelper {
QSet<QString>& getSaveFontName() { return m_saveFontN; }
LVGLSimulator* getcursim();
QMap<lv_obj_t*, QList<LVGLEvent*>>& getObjEvents() { return m_objEvents; }
QMap<lv_obj_t*, QString>& getTimeCmd() { return m_timeCmd; }
bool getNeedSetTime() { return m_needSetTime; }

// set
void setMainW(MainWindow* m) { m_pMainW = m; }
void reduceFileindex() { --m_filecount; }
void setNeedSetTime(bool b) { m_needSetTime = b; }

// other
void updatetabDate();
Expand All @@ -45,12 +48,14 @@ class LVGLHelper {
}

private:
LVGLHelper() : m_pMainW(nullptr), m_filecount(0){};
LVGLHelper() : m_pMainW(nullptr), m_filecount(0), m_needSetTime(false){};
MainWindow* m_pMainW;
int m_filecount;
QStringList pagelist;
QMap<LVGLObject*, int> m_btnGoPage;
QSet<QString> m_saveFontN;
QMap<lv_obj_t*, QList<LVGLEvent*>> m_objEvents;
QMap<lv_obj_t*, QString> m_timeCmd;
bool m_needSetTime;
};
#endif
25 changes: 23 additions & 2 deletions core/LVGLProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ bool LVGLProject::exportCode(const QString &path) const {
file.copy(copyfilepath);
}

if (LVGLHelper::getInstance().getNeedSetTime())
if (!exportTimeFuncs(path)) return false;

return exportCodePlus(path);
}

Expand Down Expand Up @@ -387,6 +390,7 @@ bool LVGLProject::exportCodePlus(const QString &path) const {
}

stream << "\n";

stream << "void app();\n";
stream << "\n";

Expand All @@ -399,11 +403,15 @@ bool LVGLProject::exportCodePlus(const QString &path) const {
stream.setCodec(QTextCodec::codecForName("UTF-8"));

auto tabW = LVGLHelper::getInstance().getMainW()->getTabW();
stream << "#include \"app.h\"\n";
stream << "#include \"app.h\"\n\n";
stream << "#include <stdlib.h>\n\n";
if (LVGLHelper::getInstance().getNeedSetTime())
stream << "#include \"timefuncs.h\"\n";
stream << "\n";

for (int i = 0; i < tabW->count(); ++i) {
stream << "#include \"page_" << QString::number(i + 1) << ".h\"\n";
}
stream << "#include \"stdlib.h\"\n";
stream << "\n";

for (int i = 0; i < tabW->count(); ++i) {
Expand Down Expand Up @@ -452,4 +460,17 @@ bool LVGLProject::exportCodePlus(const QString &path) const {
return true;
}

bool LVGLProject::exportTimeFuncs(const QString &path) const {
QString timefuncsdir = QDir::currentPath();
QString filepath = timefuncsdir + "/timefuncs";
QString copyfilepath = path + "/timefuncs";

QFile file(filepath + ".h");
file.copy(copyfilepath + ".h");

QFile file2(filepath + ".c");
file2.copy(copyfilepath + ".c");
return true;
}

QString LVGLProject::fileName() const { return m_fileName; }
1 change: 1 addition & 0 deletions core/LVGLProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LVGLProject {
bool save(const QString &fileName);
bool exportCode(const QString &path) const;
bool exportCodePlus(const QString &path) const;
bool exportTimeFuncs(const QString &path) const;

void setres(const QSize &res) { m_resolution = res; };
void setName(const QString &name) { m_name = name; }
Expand Down
2 changes: 1 addition & 1 deletion core/LVGLStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum StylePart {
Container = Background | Padding | Margin | Mix | Border,
CPickerBG = Mix | Padding | Background | Margin,
CpickerKNOB = Mix | Padding | Background | Margin,
DropdownMAIN = Mix | Background | Text | Border,
DropdownMAIN = Mix | Background | Text | Border | Padding | Margin,
DropdownLIST = Background | Border | Text,
DropdownDCRLBAR = Background,
DropdownSELECTED = Background | Border | Text,
Expand Down
24 changes: 23 additions & 1 deletion events/EventSelectWIdget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,34 @@ void EventSelectWIdget::getEventType(LVGLEventType *&ev, int index) {
case 2:
ev = new LVGLEventType(0, LVGLEventType::BAR);
break;
case 3:
ev = new LVGLEventType(0, LVGLEventType::BUTTON, 1);
ev->setneedCusVal(false);
break;
case 4:
ev = new LVGLEventType(0, LVGLEventType::CHECKBOX, 1);
ev->setneedCusVal(false);
break;
case 5:
ev = new LVGLEventType(0, LVGLEventType::DROPDOWNLIST);
break;
case 6:
ev = new LVGLEventType(0, LVGLEventType::IMAGE, 1);
ev->setneedCusVal(false);
break;
case 7:
ev = new LVGLEventType(0, LVGLEventType::IMAGEBUTTON, 1);
ev->setneedCusVal(false);
break;
case 8:
ev = new LVGLEventType(0, LVGLEventType::LABEL);
break;
case 12:
ev = new LVGLEventType(0, LVGLEventType::SLIDER);
break;
case 14:
ev = new LVGLEventType(0, LVGLEventType::SWITCH, 1);
break;
ev->setneedCusVal(false);
break;
}
}
2 changes: 1 addition & 1 deletion events/EventSettingWidgeet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void EventSettingWidgeet::init() {
break;
}

if (m_event->getwtype() == LVGLEventType::SWITCH) m_issendercomhide = true;
m_issendercomhide = !m_event->getneedCusVal();

if (m_issendercomhide) {
ui->Sendercomb->hide();
Expand Down
137 changes: 135 additions & 2 deletions events/LVGLEventButton.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,140 @@
#include "LVGLEventButton.h"

#include "LVGLEventStateResume.h"
#include "MainWindow.h"
#include "core/LVGLCore.h"
#include "core/LVGLHelper.h"
#include "core/LVGLObject.h"
#include "core/LVGLTabWidget.h"
#include "lvgl/lvgl.h"

LVGLEventButton::LVGLEventButton() {}

void LVGLEventButton::eventRun(lv_obj_t *obj) {}
void LVGLEventButton::eventRun(lv_obj_t *obj) {
QString name = m_result.at(4);
lv_obj_t *targert = nullptr;
LVGLHelper::getInstance().updatetabDate();
QList<LVGLObject *> objs;
auto tabw = LVGLHelper::getInstance().getMainW()->getTabW();
for (int i = 0; i < tabw->count(); ++i) {
auto tab = static_cast<LVGLTabWidget *>(tabw->widget(i));
auto os = tab->allObject();
for (auto o : os) {
if (o->obj() == obj) {
objs = os;
break;
}
}
}

for (auto o : objs) {
if (o->name() == name) {
targert = o->obj();
LVGLEventStateResume::getInstance().addEvent(o);
break;
}
}

QString proprety = m_result.at(5);
QString way = m_result.at(6);
if (way == "On") {
lv_btn_set_checkable(targert, true);
} else if (way == "OFf") {
lv_btn_set_checkable(targert, false);
}
}

QStringList LVGLEventButton::eventCode() {
QStringList list;
list << QString("%1{").arg(m_eventHeadCode) << "\n";
if (m_result[1] == "Pressed") {
list << "\t"
<< "if (event == LV_EVENT_PRESSED){"
<< "\n";
} else if (m_result[1] == "Clicked") {
list << "\t"
<< "if (event == LV_EVENT_CLICKED){"
<< "\n";
} else if (m_result[1] == "Long_Pressed") {
list << "\t"
<< "if (event == LV_EVENT_LONG_PRESSED){"
<< "\n";
} else if (m_result[1] == "Long_Pressed_Repeat") {
list << "\t"
<< "if (event == LV_EVENT_LONG_PRESSED_REPEAT){"
<< "\n";
} else if (m_result[1] == "Focused") {
list << "\t"
<< "if (event == LV_EVENT_FOCUSED){"
<< "\n";
} else if (m_result[1] == "Defocused") {
list << "\t"
<< "if (event == LV_EVENT_DEFOCUSED){"
<< "\n";
} else if (m_result[1] == "Value_Changed") {
list << "\t"
<< "if (event == LV_EVENT_VALUE_CHANGED){"
<< "\n";
}
list << "\t\t";

auto tabw = LVGLHelper::getInstance().getMainW()->getTabW();
int tabindex = tabw->currentIndex();
auto objs = lvgl.allObjects();
auto nowtab = static_cast<LVGLTabWidget *>(tabw->widget(tabindex));
LVGLWidget::Type type;
QString codename;
int nameindex = tabindex;

nowtab->setAllObjects(lvgl.allObjects());
nowtab->setAllImages(lvgl.allImages());

QString name;
QMap<lv_obj_t *, QList<LVGLEvent *>> &objevs =
LVGLHelper::getInstance().getObjEvents();
lv_obj_t *obb = nullptr;
auto iter = objevs.begin();
for (; iter != objevs.end(); ++iter) {
QList<LVGLEvent *> &listev = iter.value();
for (auto e : listev)
if (e == this) {
obb = iter.key();
break;
}
}

for (int i = 0; i < tabw->count(); ++i) {
auto tb = static_cast<LVGLTabWidget *>(tabw->widget(i));
auto os = tb->allObject();
for (auto o : os) {
if (obb == o->obj()) {
tabindex = i;
nameindex = i;
codename = o->codeName();
type = o->widgetType();
}
}
}

auto tb = static_cast<LVGLTabWidget *>(tabw->widget(nameindex));
auto os = tb->allObject();
for (auto o : os)
if (o->name() == m_result[4]) name = o->codeName();

QString proprety = m_result.at(5);
QString way = m_result.at(6);

if (way == "On") {
list << QString("lv_btn_set_checkable(%1_ev_%2, true);\n")
.arg(name)
.arg(tabindex);
} else if (way == "Off") {
list << QString("lv_btn_set_checkable(%1_ev_%2, false);\n")
.arg(name)
.arg(tabindex);
}

QStringList LVGLEventButton::eventCode() { return QStringList(); }
list << "\t}\n";
list << "}";
return list;
}
Loading

0 comments on commit ce17165

Please sign in to comment.