mirror of
https://github.com/citra-emu/citra.git
synced 2025-02-17 04:21:04 +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();
|
||||
setAcceptDrops(true);
|
||||
ui.setupUi(this);
|
||||
installEventFilter(this);
|
||||
statusBar()->hide();
|
||||
|
||||
InitializeWidgets();
|
||||
InitializeDebugWidgets();
|
||||
InitializeRecentFileMenuActions();
|
||||
InitializeHotkeys();
|
||||
InitializeAnimations();
|
||||
|
||||
SetDefaultUIGeometry();
|
||||
RestoreUIState();
|
||||
@ -254,6 +256,22 @@ void GMainWindow::InitializeHotkeys() {
|
||||
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() {
|
||||
// geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
|
||||
const QRect screenRect = QApplication::desktop()->screenGeometry(this);
|
||||
@ -697,6 +715,26 @@ void GMainWindow::UpdateStatusBar() {
|
||||
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) {
|
||||
QMessageBox::StandardButton answer;
|
||||
QString status_message;
|
||||
@ -824,6 +862,18 @@ void GMainWindow::dragMoveEvent(QDragMoveEvent* event) {
|
||||
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() {
|
||||
if (emu_thread == nullptr)
|
||||
return true;
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <memory>
|
||||
#include <QMainWindow>
|
||||
#include <QTimer>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
#include "core/core.h"
|
||||
#include "ui_main.h"
|
||||
|
||||
@ -69,6 +71,7 @@ private:
|
||||
void InitializeDebugWidgets();
|
||||
void InitializeRecentFileMenuActions();
|
||||
void InitializeHotkeys();
|
||||
void InitializeAnimations();
|
||||
|
||||
void SetDefaultUIGeometry();
|
||||
void RestoreUIState();
|
||||
@ -133,6 +136,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void UpdateStatusBar();
|
||||
void AnimateMenubar(bool show);
|
||||
|
||||
Ui::MainWindow ui;
|
||||
|
||||
@ -165,10 +169,16 @@ private:
|
||||
|
||||
QAction* actions_recent_files[max_recent_files_item];
|
||||
|
||||
// Animations
|
||||
QTimer menubar_timer;
|
||||
QPropertyAnimation* menubar_animation;
|
||||
QGraphicsOpacityEffect* menubar_effect;
|
||||
|
||||
protected:
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||
bool eventFilter(QObject* obj, QEvent* ev) override;
|
||||
};
|
||||
|
||||
#endif // _CITRA_QT_MAIN_HXX_
|
||||
|
Loading…
Reference in New Issue
Block a user