111 lines
4 KiB
C++
111 lines
4 KiB
C++
//
|
|
// 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 <iostream>
|
|
#include <qguiapplication.h>
|
|
|
|
#include "ui_main_window.h"
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QListWidget>
|
|
#include <QFrame>
|
|
|
|
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<QLabel*>("label_" + next_widget_name)->setEnabled(true);
|
|
this->findChild<QFrame*>("line_" + previous_widget_name + "_" + next_widget_name)->setEnabled(true);
|
|
|
|
QWidget* view = this->ui->current_view;
|
|
if (view->findChild<QWidget*>(next_widget_name.toStdString()) != nullptr) {
|
|
view->findChild<QWidget*>(next_widget_name)->show();
|
|
}
|
|
if (view->findChild<QWidget*>(previous_widget_name.toStdString()) != nullptr) {
|
|
view->findChild<QWidget*>(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<QLabel*>("label_" + previous_widget_name)->setEnabled(false);
|
|
this->findChild<QFrame*>("line_" + next_widget_name + "_" + previous_widget_name)->setEnabled(false);
|
|
|
|
QWidget* view = this->ui->current_view;
|
|
if (view->findChild<QWidget*>(next_widget_name.toStdString()) != nullptr) {
|
|
view->findChild<QWidget*>(next_widget_name)->show();
|
|
}
|
|
if (view->findChild<QWidget*>(previous_widget_name.toStdString()) != nullptr) {
|
|
view->findChild<QWidget*>(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<QListWidget*>("listWidget")->addItem(available_view);
|
|
}
|
|
|
|
QWidget* view_widget = this->ui->current_view;
|
|
|
|
view_widget = this->findChild<QWidget*>("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<QPushButton*>("button_next");
|
|
connect(next_button, &QPushButton::clicked, this, &main_window::increment_active_widget);
|
|
|
|
const QPushButton* previous_button = this->findChild<QPushButton*>("button_previous");
|
|
connect(previous_button, &QPushButton::clicked, this, &main_window::decrement_active_widget);
|
|
|
|
}
|
|
|
|
void main_window::on_submit_clicked() {
|
|
this->centralWidget()->findChild<QLabel*>("label")->setText(this->centralWidget()->findChild<QLineEdit*>("lineEdit")->text());
|
|
}
|
|
|
|
main_window::~main_window() {
|
|
delete ui;
|
|
}
|
|
} // kuwindow
|