Skip to content

Commit

Permalink
Fullscreen: show popup with with fullscreen and menu hotkeys
Browse files Browse the repository at this point in the history
This modal popup is displayed every time when going fullscreen as long as the
"Remind me again" checkbox is ticked when Okay is clicked.
It can be styled to match the skin.
  • Loading branch information
ronso0 committed Apr 5, 2023
1 parent 63f3592 commit f466855
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 1 deletion.
141 changes: 141 additions & 0 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "mixxxmainwindow.h"

#include <QCheckBox>
#include <QDesktopServices>
#include <QFileDialog>
#include <QGLFormat>
Expand Down Expand Up @@ -97,6 +98,7 @@ MixxxMainWindow::MixxxMainWindow(std::shared_ptr<mixxx::CoreServices> pCoreServi
: m_pCoreServices(pCoreServices),
m_pCentralWidget(nullptr),
m_pLaunchImage(nullptr),
m_pFullScreenHint(nullptr),
m_pGuiTick(nullptr),
#ifdef __LINUX__
m_supportsGlobalMenuBar(supportsGlobalMenu()),
Expand Down Expand Up @@ -338,6 +340,13 @@ void MixxxMainWindow::initialize() {
// otherwise it would shift the launch image shortly before the skin is visible.
m_pMenuBar->show();

// Show the fullscreen hotkey hint if we went fullscreen earlier.
// This should make users aware of the new feature (press Alt to show/hide menu bar)
// if they upgraded Mixxx with 'Start in fullscreen mode'.
// Show the hint now so it doesn't interfere with other popups, e.g. the
// sound device warnings.
showFullScreenHotkeyHint();

// The launch image widget is automatically disposed, but we still have a
// pointer to it.
m_pLaunchImage = nullptr;
Expand All @@ -363,6 +372,14 @@ void MixxxMainWindow::initialize() {
&PlayerInfo::currentPlayingTrackChanged,
this,
&MixxxMainWindow::slotUpdateWindowTitle);

if (m_pCoreServices->getSettings()->getValueString(
ConfigKey("[Config]", "hide_fullscreen_hint")) != "1") {
connect(this,
&MixxxMainWindow::fullScreenChanged,
this,
&MixxxMainWindow::showFullScreenHotkeyHint);
}
}

MixxxMainWindow::~MixxxMainWindow() {
Expand Down Expand Up @@ -1233,3 +1250,127 @@ void MixxxMainWindow::initializationProgressUpdate(int progress, const QString&
}
qApp->processEvents();
}

void MixxxMainWindow::showFullScreenHotkeyHint() {
if (!isFullScreen()) {
return;
}
if (m_pCoreServices->getSettings()->getValueString(
ConfigKey("[Config]", "hide_fullscreen_hint")) == "1") {
return;
}
// don't show fullscreen hotkey hint during startup
if (centralWidget() == m_pLaunchImage) {
return;
}

if (!m_pFullScreenHint) {
m_pFullScreenHint = new WFullScreenHint(this, m_pCoreServices->getSettings());
}
if (m_pFullScreenHint->isVisible()) {
return;
}
// apply skin stylesheet
m_pFullScreenHint->setStyleSheet(m_pCentralWidget->styleSheet());
m_pFullScreenHint->popup();
}

WFullScreenHint::WFullScreenHint(QWidget* parent, UserSettingsPointer pConfig)
: QWidget(parent),
m_pConfig(pConfig) {
QWidget::hide();
// stay on top, remove OS window frame
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
// block the GUI as long as it is open
setWindowModality(Qt::ApplicationModal);
// allow custom styles? at least the custom border is not applied without this
setAttribute(Qt::WA_StyledBackground);
// name it like the class so /tools/qsscheck.py can pick it up
setObjectName("WFullScreenHint");

QVBoxLayout* pLabelLayout = new QVBoxLayout();
pLabelLayout->addStretch();

auto* fullScreenTitle = new QLabel(tr("<b>Mixxx is now fullscreen</b>"), this);
fullScreenTitle->setObjectName("FullScreenTitle");
pLabelLayout->addWidget(fullScreenTitle);

// list all fullscreen keyboard shortcuts
const QList<QKeySequence> fsshortcuts = WMainMenuBar::s_fullScreenShortcuts;
if (!fsshortcuts.isEmpty()) {
QString fssString;
int i = 1;
for (const auto& shortcut : fsshortcuts) {
if (i > 1) { // separate multiple shortcuts
fssString.append(" / ");
}
fssString.append(QStringLiteral("<b>%1</b>").arg(shortcut.toString()));
i++;
}
QLabel* fullScreenHotkeys = new QLabel(this);
fullScreenHotkeys->setObjectName("FullScreenHotkeyLabel");
fullScreenHotkeys->setText(tr("Press %1 to toggle fullscreen").arg(fssString));
pLabelLayout->addWidget(fullScreenHotkeys);
}

#ifndef __APPLE__
auto* menuHotkey = new QLabel(tr("Press <b>Alt</b> to toggle the menu bar"), this);
menuHotkey->setObjectName("MenuHotkeyLabel");
pLabelLayout->addWidget(menuHotkey);
#endif

pLabelLayout->addStretch();

m_pRemindCheckBox = new QCheckBox(tr("&Remind me again"), this);
m_pRemindCheckBox->setObjectName("RemindAgainCheckBox");
m_pRemindCheckBox->setChecked(true);
pLabelLayout->addWidget(m_pRemindCheckBox);

pLabelLayout->addStretch();

m_pOkayBtn = new QPushButton(tr("&Okay"), this);
connect(m_pOkayBtn,
&QPushButton::clicked,
this,
&WFullScreenHint::close);
pLabelLayout->addWidget(m_pOkayBtn);

QHBoxLayout* pMainLayout = new QHBoxLayout();
// center the labels horizontally
pMainLayout->addStretch();
pMainLayout->addLayout(pLabelLayout);
pMainLayout->addStretch();
setLayout(pMainLayout);

// we need to update the the layout here since the size is used to
// calculate the positioning later
layout()->update();
layout()->activate();
}

void WFullScreenHint::popup() {
const QWidget* pParentWidget = parentWidget();
VERIFY_OR_DEBUG_ASSERT(pParentWidget) {
qWarning() << "WFullScreenHint: no parent widget!";
}
const QScreen* const pScreen = mixxx::widgethelper::getScreen(*pParentWidget);
int dlgWidth = 400;
VERIFY_OR_DEBUG_ASSERT(pScreen) {
qWarning() << "No screen detectable, assuming screen size of 800x600px.";
}
else {
dlgWidth = pScreen->geometry().width() / 2;
}
setFixedWidth(dlgWidth);
setFixedHeight(static_cast<int>(sizeHint().height() * 1.2));
// Show the hint centered in the upper part of the window.
move(dlgWidth / 2, 100);
QWidget::show();
m_pOkayBtn->setFocus();
}

void WFullScreenHint::closeEvent(QCloseEvent* event) {
int remind = m_pRemindCheckBox->isChecked() ? 0 : 1;
m_pConfig->set(ConfigKey("[Config]", "hide_fullscreen_hint"), ConfigValue(remind));
QWidget::closeEvent(event);
}
22 changes: 22 additions & 0 deletions src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class DlgKeywheel;
class GuiTick;
class LaunchImage;
class VisualsManager;
class WFullScreenHint;
class WMainMenuBar;
class QCheckBox;

namespace mixxx {

Expand Down Expand Up @@ -100,6 +102,9 @@ class MixxxMainWindow : public QMainWindow {
bool loadConfiguredSkin();

bool confirmExit();

void showFullScreenHotkeyHint();

QDialog::DialogCode soundDeviceErrorDlg(
const QString &title, const QString &text, bool* retryClicked);
QDialog::DialogCode soundDeviceBusyDlg(bool* retryClicked);
Expand All @@ -111,6 +116,7 @@ class MixxxMainWindow : public QMainWindow {

QWidget* m_pCentralWidget;
LaunchImage* m_pLaunchImage;
WFullScreenHint* m_pFullScreenHint;

std::shared_ptr<mixxx::skin::SkinLoader> m_pSkinLoader;
GuiTick* m_pGuiTick;
Expand All @@ -137,3 +143,19 @@ class MixxxMainWindow : public QMainWindow {

QSet<ControlObject*> m_skinCreatedControls;
};

class WFullScreenHint : public QWidget {
Q_OBJECT
public:
WFullScreenHint(QWidget* parent, UserSettingsPointer pConfig);

void popup();

protected:
void closeEvent(QCloseEvent* event) override;

private:
QCheckBox* m_pRemindCheckBox;
QPushButton* m_pOkayBtn;
UserSettingsPointer m_pConfig;
};
4 changes: 3 additions & 1 deletion src/widget/wmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ QUrl documentationUrl(
}
} // namespace

QList<QKeySequence> WMainMenuBar::s_fullScreenShortcuts = {};

WMainMenuBar::WMainMenuBar(QWidget* pParent, UserSettingsPointer pConfig,
ConfigObject<ConfigValueKbd>* pKbdConfig)
: QMenuBar(pParent),
Expand Down Expand Up @@ -313,7 +315,7 @@ void WMainMenuBar::initialize() {
if (!osShortcut.isEmpty() && !shortcuts.contains(osShortcut)) {
shortcuts << osShortcut;
}

s_fullScreenShortcuts = shortcuts;
pViewFullScreen->setShortcuts(shortcuts);
pViewFullScreen->setShortcutContext(Qt::ApplicationShortcut);
pViewFullScreen->setCheckable(true);
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class WMainMenuBar : public QMenuBar {
WMainMenuBar(QWidget* pParent, UserSettingsPointer pConfig,
ConfigObject<ConfigValueKbd>* pKbdConfig);

static QList<QKeySequence> s_fullScreenShortcuts;

public slots:
void onLibraryScanStarted();
void onLibraryScanFinished();
Expand Down

0 comments on commit f466855

Please sign in to comment.