qtk/app/mainwindow.cpp

41 lines
1.6 KiB
C++
Raw Normal View History

2022-11-25 19:36:12 +00:00
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: MainWindow for creating an example Qt application ##
2022-11-25 19:36:12 +00:00
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#include <mainwindow.h>
#include <qtkwidget.h>
#include "ui_mainwindow.h"
2022-11-24 22:26:53 +00:00
MainWindow::MainWindow(QWidget * parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
// For use in design mode using Qt Creator
// + We can use the `ui` member to access nested widgets by name
2022-11-25 19:36:12 +00:00
ui->setupUi(this);
// Find all QtkWidgets in this QMainWindow and initialize their scenes.
2022-11-24 22:26:53 +00:00
for(const auto widget : ui->qWidget->children()) {
auto qtkWidget = dynamic_cast<Qtk::QtkWidget *>(widget);
if(qtkWidget != nullptr) {
std::string key = qtkWidget->objectName().toStdString();
2022-11-25 19:36:12 +00:00
// Initialize each scene into a map if it doesn't exist.
2022-11-24 22:26:53 +00:00
if(mScenes[key] == nullptr) {
2022-11-25 19:36:12 +00:00
mScenes[key] = new ExampleScene();
}
2022-11-25 19:36:12 +00:00
// Set the QtkWidget to use the scene associated with this widget.
qtkWidget->setScene(mScenes[key]);
}
}
2022-11-25 19:36:12 +00:00
// Set the window icon used for Qtk.
// TODO: Update this to be something other than kilroy.
setWindowIcon(QIcon("../resources/icon.png"));
}
2022-11-24 22:26:53 +00:00
MainWindow::~MainWindow() {
delete ui;
}