Ui: support portrait mode
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
#include <QScrollBar>
|
||||
#include <QEvent>
|
||||
|
||||
#include <QScreen>
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user