#include #include #include #include #include #include "main.h" #include "ui_mainwindow.h" #include "glwidget.h" #include "widget.h" ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////// TerraDockWidget ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /// All UI elements get created, initialized and connected. /// /// @param parent QWidget* the parent widget /// /// @date /// 2016-07-29 (created by KTH) /////////////////////////////////////////////////////////////////////////////// TerraDockWidget::TerraDockWidget(const QString &title, QWidget * parent, Qt::WindowFlags flags) : QDockWidget(title, parent, flags) , maxButton(NULL) { init(); } /////////////////////////////////////////////////////////////////////////////// /// @date /// 2016-08-03 (created by KTH) /////////////////////////////////////////////////////////////////////////////// void TerraDockWidget::init() { QWidget* widget = new QWidget(this); this->setWidget(widget); Widget *native = new Widget(&helper, widget); GLWidget *openGL = new GLWidget(&helper, widget); QLabel *nativeLabel = new QLabel(tr("Native")); nativeLabel->setAlignment(Qt::AlignHCenter); QLabel *openGLLabel = new QLabel(tr("OpenGL")); openGLLabel->setAlignment(Qt::AlignHCenter); maxButton = new QPushButton("Maximize", widget); QObject::connect(maxButton, &QPushButton::clicked, this, &TerraDockWidget::maximizeDock); QGridLayout *layout = new QGridLayout; layout->addWidget(native, 0, 0); layout->addWidget(openGL, 0, 1); layout->addWidget(nativeLabel, 1, 0); layout->addWidget(openGLLabel, 1, 1); layout->addWidget(maxButton, 2, 1); widget->setLayout(layout); openGL->winId(); QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, native, &Widget::animate); connect(timer, &QTimer::timeout, openGL, &GLWidget::animate); timer->start(50); } void TerraDockWidget::maximizeDock() { if (isMaximized()) { setWindowState(Qt::WindowNoState); maxButton->setText("Maximize"); } else { setWindowState(Qt::WindowMaximized); maxButton->setText("Normal"); } } class MainWindow : public QMainWindow { public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: /// The UI object Ui::MainWindow ui; }; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); this->setCentralWidget(NULL); TerraDockWidget* dockWidget = new TerraDockWidget("New Dock1"); addDockWidget(Qt::RightDockWidgetArea, dockWidget); this->show(); } MainWindow::~MainWindow() { } int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication app( argc, argv ); app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) ); MainWindow * myMainWindow = new MainWindow(); return app.exec(); }