Merge pull request #2129 from Cacodemon345/fullscreenstaticonqt

qt: Add fullscreen status icons support and option
This commit is contained in:
Miran Grča
2023-11-08 07:09:00 +01:00
committed by GitHub
12 changed files with 99 additions and 0 deletions

View File

@@ -139,6 +139,8 @@ load_general(void)
rctrl_is_lalt = ini_section_get_int(cat, "rctrl_is_lalt", 0);
update_icons = ini_section_get_int(cat, "update_icons", 1);
status_icons_fullscreen = !!config_get_int(cat, "status_icons_fullscreen", 0);
window_remember = ini_section_get_int(cat, "window_remember", 0);
if (!window_remember && !(vid_resize & 2))
@@ -1782,6 +1784,11 @@ save_general(void)
else
ini_section_delete_var(cat, "open_dir_usr_path");
if (status_icons_fullscreen)
config_set_int(cat, "status_icons_fullscreen", status_icons_fullscreen);
else
config_delete_var(cat, "status_icons_fullscreen");
if (video_framerate != -1)
ini_section_set_int(cat, "video_gl_framerate", video_framerate);
else

View File

@@ -107,6 +107,7 @@ extern int infocus;
extern char emu_version[200]; /* version ID string */
extern int rctrl_is_lalt;
extern int update_icons;
extern int status_icons_fullscreen;
extern int kbd_req_capture;
extern int hide_status_bar;

View File

@@ -136,6 +136,22 @@ HardwareRenderer::initializeGL()
m_context->swapBuffers(this);
}
void
HardwareRenderer::paintOverGL()
{
/* Context switching is needed to make use of QPainter to draw status bar icons in fullscreen.
Especially since it seems to be impossible to use QPainter on externally-created OpenGL contexts. */
if (video_fullscreen && status_icons_fullscreen) {
m_context->makeCurrent(nullptr);
makeCurrent();
QPainter painter(this);
drawStatusBarIcons(&painter);
painter.end();
doneCurrent();
m_context->makeCurrent(this);
}
}
void
HardwareRenderer::paintGL()
{

View File

@@ -53,6 +53,7 @@ public:
{
onResize(size().width(), size().height());
}
void paintOverGL() override;
std::vector<std::tuple<uint8_t *, std::atomic_flag *>> getBuffers() override;
HardwareRenderer(QWidget *parent = nullptr, RenderType rtype = RenderType::OpenGL)
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent->windowHandle())

View File

@@ -346,6 +346,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->actionUpdate_status_bar_icons->setChecked(update_icons);
ui->actionEnable_Discord_integration->setChecked(enable_discord);
ui->actionApply_fullscreen_stretch_mode_when_maximized->setChecked(video_fullscreen_scale_maximized);
ui->actionShow_status_icons_in_fullscreen->setChecked(status_icons_fullscreen);
#ifndef DISCORD
ui->actionEnable_Discord_integration->setVisible(false);
@@ -2027,3 +2028,10 @@ void MainWindow::on_actionACPI_Shutdown_triggered()
{
acpi_pwrbut_pressed = 1;
}
void MainWindow::on_actionShow_status_icons_in_fullscreen_triggered()
{
status_icons_fullscreen = !status_icons_fullscreen;
ui->actionShow_status_icons_in_fullscreen->setChecked(status_icons_fullscreen);
}

View File

@@ -144,6 +144,7 @@ private slots:
void on_actionCursor_Puck_triggered();
void on_actionACPI_Shutdown_triggered();
void on_actionShow_status_icons_in_fullscreen_triggered();
private slots:
void on_actionShow_non_primary_monitors_triggered();

View File

@@ -180,6 +180,7 @@
</widget>
<addaction name="actionHide_tool_bar"/>
<addaction name="actionHide_status_bar"/>
<addaction name="actionShow_status_icons_in_fullscreen"/>
<addaction name="separator"/>
<addaction name="actionShow_non_primary_monitors"/>
<addaction name="actionResizable_window"/>
@@ -881,6 +882,14 @@
<string>Cursor/Puck</string>
</property>
</action>
<action name="actionShow_status_icons_in_fullscreen">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show status icons in fullscreen</string>
</property>
</action>
<action name="actionPen">
<property name="checkable">
<bool>true</bool>

View File

@@ -17,11 +17,15 @@
#include "qt_renderercommon.hpp"
#include "qt_mainwindow.hpp"
#include "qt_machinestatus.hpp"
#include <QPainter>
#include <QWidget>
#include <QEvent>
#include <QApplication>
#include <QFontMetrics>
#include <QStatusBar>
#include <QLayout>
#include <cmath>
@@ -29,6 +33,8 @@ extern "C" {
#include <86box/86box.h>
#include <86box/plat.h>
#include <86box/video.h>
int status_icons_fullscreen = 0;
}
RendererCommon::RendererCommon() = default;
@@ -131,6 +137,50 @@ RendererCommon::onResize(int width, int height)
monitors[r_monitor_index].mon_res_y = (double) destination.height();
}
void RendererCommon::drawStatusBarIcons(QPainter* painter)
{
uint32_t x = 0;
auto prevcompositionMode = painter->compositionMode();
painter->setCompositionMode(QPainter::CompositionMode::CompositionMode_SourceOver);
for (int i = 0; i < main_window->statusBar()->children().count(); i++) {
QLabel* label = qobject_cast<QLabel*>(main_window->statusBar()->children()[i]);
if (label) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QPixmap pixmap = label->pixmap();
#else
const QPixmap pixmap = label->pixmap() ? *label->pixmap() : QPixmap();
#endif
if (!pixmap.isNull()) {
painter->setBrush(QColor::fromRgbF(0, 0, 0, 1.));
painter->fillRect(x, painter->device()->height() - pixmap.height() - 5,
pixmap.width(), pixmap.height() + 5, QColor::fromRgbF(0, 0, 0, .5));
painter->drawPixmap(x + main_window->statusBar()->layout()->spacing() / 2,
painter->device()->height() - pixmap.height() - 3, pixmap);
x += pixmap.width();
if (i <= main_window->statusBar()->children().count() - 3) {
painter->fillRect(x, painter->device()->height() - pixmap.height() - 5,
main_window->statusBar()->layout()->spacing(), pixmap.height() + 5,
QColor::fromRgbF(0, 0, 0, .5));
x += main_window->statusBar()->layout()->spacing();
} else
painter->fillRect(x, painter->device()->height() - pixmap.height() - 4, 4,
pixmap.height() + 4, QColor::fromRgbF(0, 0, 0, .5));
}
}
}
if (main_window->status->getMessage().isEmpty() == false) {
auto curStatusMsg = main_window->status->getMessage();
auto textSize = painter->fontMetrics().size(Qt::TextSingleLine, QChar(' ') + curStatusMsg + QChar(' '));
painter->setPen(QColor(0, 0, 0, 127));
painter->fillRect(painter->device()->width() - textSize.width(), painter->device()->height() - textSize.height(),
textSize.width(), textSize.height(), QColor(0, 0, 0, 127));
painter->setPen(QColor(255, 255, 255, 255));
painter->drawText(QRectF(painter->device()->width() - textSize.width(), painter->device()->height() - textSize.height(),
textSize.width(), textSize.height()), Qt::TextSingleLine, QChar(' ') + curStatusMsg + QChar(' '));
}
painter->setCompositionMode(prevcompositionMode);
}
bool
RendererCommon::eventDelegate(QEvent *event, bool &result)
{

View File

@@ -42,6 +42,7 @@ public:
protected:
bool eventDelegate(QEvent *event, bool &result);
void drawStatusBarIcons(QPainter* painter);
QRect source { 0, 0, 0, 0 };
QRect destination;

View File

@@ -24,6 +24,7 @@
extern "C" {
#include <86box/86box.h>
#include <86box/plat.h>
#include <86box/video.h>
}
@@ -113,6 +114,7 @@ SoftwareRenderer::onPaint(QPaintDevice *device)
#endif
painter.setCompositionMode(QPainter::CompositionMode_Plus);
painter.drawImage(destination, *images[cur_image], source);
if (video_fullscreen && status_icons_fullscreen) drawStatusBarIcons(&painter);
}
std::vector<std::tuple<uint8_t *, std::atomic_flag *>>

View File

@@ -60,6 +60,7 @@ extern wchar_t sdl_win_title[512];
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_t joystick_state[MAX_JOYSTICKS];
int joysticks_present;
int status_icons_fullscreen = 0; /* unused. */
SDL_mutex *blitmtx;
SDL_threadID eventthread;
static int exit_event = 0;

View File

@@ -76,6 +76,8 @@ int hide_status_bar = 0;
int hide_tool_bar = 0;
int dpi = 96;
int status_icons_fullscreen = 0; /* unused. */
extern char openfilestring[512];
extern WCHAR wopenfilestring[512];