// // Created by neshura on 21.11.24. // // You may need to build the project (run Qt uic code generator) to get "ui_main_window.h" resolved #include "main_window.h" #include #include #include "ui_main_window.h" #include #include #include #include #include namespace kuwindow { uint main_window::increment_active_widget() { const QString& previous_widget_name = this->available_views[this->active_widget_id]; this->active_widget_id += 1; const QString& next_widget_name = this->available_views[this->active_widget_id]; this->findChild("label_" + next_widget_name)->setEnabled(true); this->findChild("line_" + previous_widget_name + "_" + next_widget_name)->setEnabled(true); QWidget* view = this->ui->current_view; if (view->findChild(next_widget_name.toStdString()) != nullptr) { view->findChild(next_widget_name)->show(); } if (view->findChild(previous_widget_name.toStdString()) != nullptr) { view->findChild(previous_widget_name)->hide(); } if (this->active_widget_id >= this->available_views.size() - 1) { this->ui->button_next->setEnabled(false); } if (this->active_widget_id > 0) { this->ui->button_previous->setEnabled(true); } return this->active_widget_id; } uint main_window::decrement_active_widget() { const QString& previous_widget_name = this->available_views[this->active_widget_id]; this->active_widget_id -= 1; const QString& next_widget_name = this->available_views[this->active_widget_id]; this->findChild("label_" + previous_widget_name)->setEnabled(false); this->findChild("line_" + next_widget_name + "_" + previous_widget_name)->setEnabled(false); QWidget* view = this->ui->current_view; if (view->findChild(next_widget_name.toStdString()) != nullptr) { view->findChild(next_widget_name)->show(); } if (view->findChild(previous_widget_name.toStdString()) != nullptr) { view->findChild(previous_widget_name)->hide(); } if (this->active_widget_id < this->available_views.size() - 1) { this->ui->button_next->setEnabled(true); } if (this->active_widget_id <= 0) { this->ui->button_previous->setEnabled(false); } return this->active_widget_id; } uint main_window::get_active_widget() { return this->active_widget_id; } main_window::main_window(QWidget *parent) : QMainWindow(parent), ui(new Ui::main_window) { ui->setupUi(this); this->available_views = this->property("available_widgets").toStringList(); for(const auto & available_view : available_views) { this->findChild("listWidget")->addItem(available_view); } QWidget* view_widget = this->ui->current_view; view_widget = this->findChild("current_view"); std::cout << "Kids after Init" << std::endl; foreach(QObject* kid, view_widget->children()) { std::cout << kid->objectName().toStdString() << std::endl; } const QPushButton* next_button = this->findChild("button_next"); connect(next_button, &QPushButton::clicked, this, &main_window::increment_active_widget); const QPushButton* previous_button = this->findChild("button_previous"); connect(previous_button, &QPushButton::clicked, this, &main_window::decrement_active_widget); } void main_window::on_submit_clicked() { this->centralWidget()->findChild("label")->setText(this->centralWidget()->findChild("lineEdit")->text()); } main_window::~main_window() { delete ui; } } // kuwindow