qt: Add toolbar

This commit is contained in:
ts-korhonen
2022-01-09 17:00:16 +02:00
parent 7555282d30
commit 06002ed322
4 changed files with 85 additions and 6 deletions

View File

@@ -67,6 +67,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->stackedWidget->setMouseTracking(true);
statusBar()->setVisible(!hide_status_bar);
statusBar()->setStyleSheet("QStatusBar::item {border: None;}");
ui->toolBar->setVisible(!hide_tool_bar);
this->setWindowIcon(QIcon(":/settings/win/icons/86Box-yellow.ico"));
this->setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, vid_resize != 1);
@@ -118,7 +119,12 @@ MainWindow::MainWindow(QWidget *parent) :
connect(this, &MainWindow::resizeContents, this, [this](int w, int h) {
if (!QApplication::platformName().contains("eglfs") && vid_resize == 0) {
w = w / (!dpi_scale ? this->screen()->devicePixelRatio() : 1);
int modifiedHeight = (h / (!dpi_scale ? this->screen()->devicePixelRatio() : 1)) + menuBar()->height() + (statusBar()->height() * !hide_status_bar);
int modifiedHeight = (h / (!dpi_scale ? this->screen()->devicePixelRatio() : 1))
+ menuBar()->height()
+ (statusBar()->height() * !hide_status_bar)
+ (ui->toolBar->height() * !hide_tool_bar);
ui->stackedWidget->resize(w, h);
if (vid_resize == 0) {
setFixedSize(w, modifiedHeight);
@@ -152,6 +158,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->menuWindow_scale_factor->setEnabled(vid_resize == 0);
ui->actionHiDPI_scaling->setChecked(dpi_scale);
ui->actionHide_status_bar->setChecked(hide_status_bar);
ui->actionHide_tool_bar->setChecked(hide_tool_bar);
ui->actionUpdate_status_bar_icons->setChecked(update_icons);
ui->actionEnable_Discord_integration->setChecked(enable_discord);
@@ -335,7 +342,11 @@ void MainWindow::showEvent(QShowEvent *event) {
setGeometry(window_x, window_y, window_w, window_h + menuBar()->height() + (hide_status_bar ? 0 : statusBar()->height()));
}
if (vid_resize == 2) {
setFixedSize(fixed_size_x, fixed_size_y + menuBar()->height() + (hide_status_bar ? 0 : statusBar()->height()));
setFixedSize(fixed_size_x, fixed_size_y
+ menuBar()->height()
+ (hide_status_bar ? 0 : statusBar()->height())
+ (hide_tool_bar ? 0 : ui->toolBar->height()));
scrnsz_x = fixed_size_x;
scrnsz_y = fixed_size_y;
}
@@ -955,15 +966,21 @@ void MainWindow::on_actionFullscreen_triggered() {
showNormal();
ui->menubar->show();
if (!hide_status_bar) ui->statusbar->show();
if (!hide_tool_bar) ui->toolBar->show();
video_fullscreen = 0;
if (vid_resize != 1) {
if (vid_resize == 2) setFixedSize(fixed_size_x, fixed_size_y + menuBar()->height() + (!hide_status_bar ? statusBar()->height() : 0));
if (vid_resize == 2) setFixedSize(fixed_size_x, fixed_size_y
+ menuBar()->height()
+ (!hide_status_bar ? statusBar()->height() : 0)
+ (!hide_tool_bar ? ui->toolBar->height() : 0));
emit resizeContents(scrnsz_x, scrnsz_y);
}
} else {
setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
ui->menubar->hide();
ui->statusbar->hide();
ui->toolBar->hide();
showFullScreen();
video_fullscreen = 1;
}
@@ -1345,8 +1362,30 @@ void MainWindow::on_actionHide_status_bar_triggered()
hide_status_bar ^= 1;
ui->actionHide_status_bar->setChecked(hide_status_bar);
statusBar()->setVisible(!hide_status_bar);
if (vid_resize >= 2) setFixedSize(fixed_size_x, fixed_size_y + menuBar()->height() + (hide_status_bar ? 0 : statusBar()->height()));
else {
if (vid_resize >= 2) {
setFixedSize(fixed_size_x, fixed_size_y
+ menuBar()->height()
+ (hide_status_bar ? 0 : statusBar()->height())
+ (hide_tool_bar ? 0 : ui->toolBar->height()));
} else {
int vid_resize_orig = vid_resize;
vid_resize = 0;
emit resizeContents(scrnsz_x, scrnsz_y);
vid_resize = vid_resize_orig;
}
}
void MainWindow::on_actionHide_tool_bar_triggered()
{
hide_tool_bar ^= 1;
ui->actionHide_tool_bar->setChecked(hide_tool_bar);
ui->toolBar->setVisible(!hide_tool_bar);
if (vid_resize >= 2) {
setFixedSize(fixed_size_x, fixed_size_y
+ menuBar()->height()
+ (hide_status_bar ? 0 : statusBar()->height())
+ (hide_tool_bar ? 0 : ui->toolBar->height()));
} else {
int vid_resize_orig = vid_resize;
vid_resize = 0;
emit resizeContents(scrnsz_x, scrnsz_y);

View File

@@ -90,6 +90,7 @@ private slots:
void on_actionSpecify_dimensions_triggered();
void on_actionHiDPI_scaling_triggered();
void on_actionHide_status_bar_triggered();
void on_actionHide_tool_bar_triggered();
void on_actionUpdate_status_bar_icons_triggered();
void refreshMediaMenu();

View File

@@ -144,6 +144,7 @@
<addaction name="menuVGA_screen_type"/>
<addaction name="menuGrayscale_conversion_type"/>
</widget>
<addaction name="actionHide_tool_bar"/>
<addaction name="actionHide_status_bar"/>
<addaction name="separator"/>
<addaction name="actionResizable_window"/>
@@ -183,6 +184,27 @@
<addaction name="menuAbout"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="movable">
<bool>false</bool>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionHard_Reset"/>
<addaction name="actionCtrl_Alt_Del"/>
<addaction name="actionCtrl_Alt_Esc"/>
<addaction name="actionPause"/>
</widget>
<action name="actionKeyboard_requires_capture">
<property name="checkable">
<bool>true</bool>
@@ -564,6 +586,17 @@
<string>Enable &amp;Discord integration</string>
</property>
</action>
<action name="actionHide_tool_bar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Hide tool bar</string>
</property>
<property name="toolTip">
<string>Hide tool bar</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@@ -45,7 +45,13 @@ void SpecifyDimensions::on_SpecifyDimensions_accepted()
window_remember = 0;
fixed_size_x = ui->spinBoxWidth->value();
fixed_size_y = ui->spinBoxHeight->value();
main_window->setFixedSize(ui->spinBoxWidth->value(), ui->spinBoxHeight->value() + (!hide_status_bar ? main_window->statusBar()->height() : 0) + main_window->menuBar()->height());
main_window->setFixedSize(ui->spinBoxWidth->value(),
ui->spinBoxHeight->value()
+ (!hide_status_bar ? main_window->statusBar()->height() : 0)
+ (!hide_tool_bar ? main_window->ui->toolBar->height() : 0)
+ main_window->menuBar()->height());
emit main_window->updateMenuResizeOptions();
main_window->show();
main_window->ui->stackedWidget->switchRenderer((RendererStack::Renderer)vid_api);