diff --git a/UpdatePTUDevCtrl/mainwindow.cpp b/UpdatePTUDevCtrl/mainwindow.cpp index 6a7aa64..1d69513 100644 --- a/UpdatePTUDevCtrl/mainwindow.cpp +++ b/UpdatePTUDevCtrl/mainwindow.cpp @@ -12,6 +12,9 @@ #include #include +#include + + MainWindow::MainWindow(Worker *worker, QWidget *parent) : QMainWindow(parent) @@ -30,6 +33,7 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent) this->statusBar()->setFont(f); ui->setupUi(this); + checkOrientation(); ui->updateProgress->setRange(0, 100); ui->updateProgress->reset(); @@ -98,6 +102,56 @@ MainWindow::~MainWindow() { delete ui; } + +// ----------------------------- Ui::LAYOUT setting ------------------------------------- + +void MainWindow::checkOrientation() +{ + QScreen *screen = QGuiApplication::primaryScreen(); + Qt::ScreenOrientation orientation = screen->orientation(); + + switch (orientation) { + case Qt::PrimaryOrientation: + this->setLandscapeLayout(); + break; + case Qt::LandscapeOrientation: + this->setLandscapeLayout(); + break; + case Qt::PortraitOrientation: + this->setPortraitLayout(); + break; + case Qt::InvertedLandscapeOrientation: + this->setLandscapeLayout(); + break; + case Qt::InvertedPortraitOrientation: + this->setPortraitLayout(); + break; + } + + this->currentOrientation = orientation; +} + + + +void MainWindow::setPortraitLayout() +{ + // Adjust layout for portrait mode (480x800) + this->setFixedSize(480, 800); + ui->centralwidget->setFixedSize(480, 800); +} + +void MainWindow::setLandscapeLayout() +{ + // Adjust layout for landscape mode (800x480) + this->setFixedSize(800, 480); + ui->centralwidget->setFixedSize(800, 480); +} + + + + + + void MainWindow::customEvent(QEvent *event) { if (event->type() == ProgressEvent::type()) { ProgressEvent *pevent = (ProgressEvent *)event; diff --git a/UpdatePTUDevCtrl/mainwindow.h b/UpdatePTUDevCtrl/mainwindow.h index 4cf7b5f..4a80d18 100644 --- a/UpdatePTUDevCtrl/mainwindow.h +++ b/UpdatePTUDevCtrl/mainwindow.h @@ -66,6 +66,12 @@ private: void onShowMessage(QString, QString); Ui::MainWindow *ui; + void checkOrientation(); + void setPortraitLayout(); + void setLandscapeLayout(); + Qt::ScreenOrientation currentOrientation; + + Worker *m_worker; int const m_width; QTimer *m_startTimer; diff --git a/UpdatePTUDevCtrl/mainwindow.ui b/UpdatePTUDevCtrl/mainwindow.ui index 4d081d4..82fa12e 100644 --- a/UpdatePTUDevCtrl/mainwindow.ui +++ b/UpdatePTUDevCtrl/mainwindow.ui @@ -10,6 +10,12 @@ 480 + + + 480 + 480 + + Source Code Pro @@ -19,55 +25,47 @@ MainWindow - - - - 10 - 10 - 781 - 441 - - - - - - - Exit - - - - - - - 1 - - - - - - - true - - - - Misc Fixed - 11 - true - - - - Qt::ScrollBarAsNeeded - - - Qt::ScrollBarAsNeeded - - - QAbstractScrollArea::AdjustToContents - - - - - + + + + + + + Exit + + + + + + + 1 + + + + + + + true + + + + Misc Fixed + 11 + 75 + true + + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAsNeeded + + + + + +