mirror of
https://github.com/citra-emu/citra.git
synced 2025-02-20 01:54:34 +00:00
citra-qt: Add an animation for the menubar
This commit is contained in:
parent
74d4050924
commit
6a4b0429c0
@ -93,12 +93,14 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
|
|||||||
Pica::g_debug_context = Pica::DebugContext::Construct();
|
Pica::g_debug_context = Pica::DebugContext::Construct();
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
installEventFilter(this);
|
||||||
statusBar()->hide();
|
statusBar()->hide();
|
||||||
|
|
||||||
InitializeWidgets();
|
InitializeWidgets();
|
||||||
InitializeDebugWidgets();
|
InitializeDebugWidgets();
|
||||||
InitializeRecentFileMenuActions();
|
InitializeRecentFileMenuActions();
|
||||||
InitializeHotkeys();
|
InitializeHotkeys();
|
||||||
|
InitializeAnimations();
|
||||||
|
|
||||||
SetDefaultUIGeometry();
|
SetDefaultUIGeometry();
|
||||||
RestoreUIState();
|
RestoreUIState();
|
||||||
@ -254,6 +256,22 @@ void GMainWindow::InitializeHotkeys() {
|
|||||||
SLOT(OnSwapScreens()));
|
SLOT(OnSwapScreens()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GMainWindow::InitializeAnimations() {
|
||||||
|
menubar_animation = new QPropertyAnimation(menuBar(), "opacity");
|
||||||
|
menubar_effect = new QGraphicsOpacityEffect(menuBar());
|
||||||
|
|
||||||
|
menubar_effect->setOpacity(1);
|
||||||
|
menuBar()->setGraphicsEffect(menubar_effect);
|
||||||
|
menubar_animation->setTargetObject(menubar_effect);
|
||||||
|
|
||||||
|
connect(&menubar_timer, &QTimer::timeout, [this] { AnimateMenubar(false); });
|
||||||
|
connect(menubar_animation, &QPropertyAnimation::finished, [this] {
|
||||||
|
if (!menubar_effect->opacity()) {
|
||||||
|
menuBar()->hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void GMainWindow::SetDefaultUIGeometry() {
|
void GMainWindow::SetDefaultUIGeometry() {
|
||||||
// geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
|
// geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
|
||||||
const QRect screenRect = QApplication::desktop()->screenGeometry(this);
|
const QRect screenRect = QApplication::desktop()->screenGeometry(this);
|
||||||
@ -697,6 +715,26 @@ void GMainWindow::UpdateStatusBar() {
|
|||||||
emu_frametime_label->setVisible(true);
|
emu_frametime_label->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GMainWindow::AnimateMenubar(bool show) {
|
||||||
|
menubar_timer.stop();
|
||||||
|
menubar_animation->stop();
|
||||||
|
|
||||||
|
if (show && menubar_effect->opacity() < 1) {
|
||||||
|
menubar_animation->setEasingCurve(QEasingCurve::OutQuad);
|
||||||
|
menubar_animation->setDuration(2000);
|
||||||
|
menubar_animation->setStartValue(menubar_effect->opacity());
|
||||||
|
menubar_animation->setEndValue(1);
|
||||||
|
menubar_animation->start();
|
||||||
|
menuBar()->show();
|
||||||
|
} else {
|
||||||
|
menubar_animation->setEasingCurve(QEasingCurve::InCirc);
|
||||||
|
menubar_animation->setDuration(3000);
|
||||||
|
menubar_animation->setStartValue(menubar_effect->opacity());
|
||||||
|
menubar_animation->setEndValue(0);
|
||||||
|
menubar_animation->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
|
void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
|
||||||
QMessageBox::StandardButton answer;
|
QMessageBox::StandardButton answer;
|
||||||
QString status_message;
|
QString status_message;
|
||||||
@ -824,6 +862,18 @@ void GMainWindow::dragMoveEvent(QDragMoveEvent* event) {
|
|||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GMainWindow::eventFilter(QObject* obj, QEvent* event) {
|
||||||
|
QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
|
||||||
|
if ((mouse && mouse->y() < 0 && mouse->x() > 0) || menuBar()->underMouse()) {
|
||||||
|
AnimateMenubar(true);
|
||||||
|
} else if (event->type() == QEvent::HoverMove) {
|
||||||
|
if (menuBar()->isVisible() && !menubar_timer.isActive()) {
|
||||||
|
menubar_timer.start(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QMainWindow::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
bool GMainWindow::ConfirmChangeGame() {
|
bool GMainWindow::ConfirmChangeGame() {
|
||||||
if (emu_thread == nullptr)
|
if (emu_thread == nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
#include <QGraphicsOpacityEffect>
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "ui_main.h"
|
#include "ui_main.h"
|
||||||
|
|
||||||
@ -69,6 +71,7 @@ private:
|
|||||||
void InitializeDebugWidgets();
|
void InitializeDebugWidgets();
|
||||||
void InitializeRecentFileMenuActions();
|
void InitializeRecentFileMenuActions();
|
||||||
void InitializeHotkeys();
|
void InitializeHotkeys();
|
||||||
|
void InitializeAnimations();
|
||||||
|
|
||||||
void SetDefaultUIGeometry();
|
void SetDefaultUIGeometry();
|
||||||
void RestoreUIState();
|
void RestoreUIState();
|
||||||
@ -133,6 +136,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateStatusBar();
|
void UpdateStatusBar();
|
||||||
|
void AnimateMenubar(bool show);
|
||||||
|
|
||||||
Ui::MainWindow ui;
|
Ui::MainWindow ui;
|
||||||
|
|
||||||
@ -165,10 +169,16 @@ private:
|
|||||||
|
|
||||||
QAction* actions_recent_files[max_recent_files_item];
|
QAction* actions_recent_files[max_recent_files_item];
|
||||||
|
|
||||||
|
// Animations
|
||||||
|
QTimer menubar_timer;
|
||||||
|
QPropertyAnimation* menubar_animation;
|
||||||
|
QGraphicsOpacityEffect* menubar_effect;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dropEvent(QDropEvent* event) override;
|
void dropEvent(QDropEvent* event) override;
|
||||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||||
|
bool eventFilter(QObject* obj, QEvent* ev) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _CITRA_QT_MAIN_HXX_
|
#endif // _CITRA_QT_MAIN_HXX_
|
||||||
|
Loading…
Reference in New Issue
Block a user