mirror of
https://github.com/huderlem/porymap.git
synced 2026-04-25 15:27:53 -05:00
create splash screen for loading
This commit is contained in:
parent
c52bc46c0f
commit
134a933d11
164
forms/loadingscreen.ui
Normal file
164
forms/loadingscreen.ui
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LoadingScreen</class>
|
||||
<widget class="QWidget" name="LoadingScreen">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>366</width>
|
||||
<height>255</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>BusyCursor</cursorShape>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::NoContextMenu</enum>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelPorymap">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>porymap</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelVersion">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Version 6.0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelPixmap">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>IMAGE</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelLoading">
|
||||
<property name="text">
|
||||
<string>Loading.....</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="labelText">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -52,6 +52,8 @@ public:
|
|||
MainWindow(const MainWindow &) = delete;
|
||||
MainWindow & operator = (const MainWindow &) = delete;
|
||||
|
||||
void initialize();
|
||||
|
||||
// Scripting API
|
||||
Q_INVOKABLE QJSValue getBlock(int x, int y);
|
||||
void tryRedrawMapArea(bool forceRedraw);
|
||||
|
|
|
|||
46
include/ui/loadingscreen.h
Normal file
46
include/ui/loadingscreen.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "qgifimage.h"
|
||||
|
||||
#include <QSplashScreen>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class LoadingScreen;
|
||||
}
|
||||
|
||||
// Loading class
|
||||
// LOAD() // or Offload() OFFLOAD() WorkerThread()
|
||||
// function that wraps around QFuture and QtConcurrent, does not block gui thread
|
||||
// can call any other function that is not directly painting the gui on another thread
|
||||
|
||||
// Execute function while playing loading screen and display text
|
||||
// void executeLoadingScreen(QString text, void (*function)(void));
|
||||
|
||||
class PorymapLoadingScreen : public QWidget {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PorymapLoadingScreen(QWidget *parent = nullptr);
|
||||
~PorymapLoadingScreen();
|
||||
|
||||
void setPixmap(QPixmap pixmap);
|
||||
void showMessage(QString text);
|
||||
|
||||
void start() { this->timer.start(120); }
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
|
||||
public slots:
|
||||
void updateFrame();
|
||||
|
||||
private:
|
||||
Ui::LoadingScreen *ui;
|
||||
|
||||
QGifImage splashImage;
|
||||
int frame = 0;
|
||||
QTimer timer;
|
||||
};
|
||||
|
||||
extern PorymapLoadingScreen *porysplash;
|
||||
|
|
@ -133,6 +133,7 @@ SOURCES += src/core/advancemapparser.cpp \
|
|||
src/ui/preferenceeditor.cpp \
|
||||
src/ui/regionmappropertiesdialog.cpp \
|
||||
src/ui/colorpicker.cpp \
|
||||
src/ui/loadingscreen.cpp \
|
||||
src/config.cpp \
|
||||
src/editor.cpp \
|
||||
src/main.cpp \
|
||||
|
|
@ -248,6 +249,7 @@ HEADERS += include/core/advancemapparser.h \
|
|||
include/ui/preferenceeditor.h \
|
||||
include/ui/regionmappropertiesdialog.h \
|
||||
include/ui/colorpicker.h \
|
||||
include/ui/loadingscreen.h \
|
||||
include/config.h \
|
||||
include/editor.h \
|
||||
include/mainwindow.h \
|
||||
|
|
@ -267,6 +269,7 @@ FORMS += forms/mainwindow.ui \
|
|||
forms/connectionslistitem.ui \
|
||||
forms/customattributesframe.ui \
|
||||
forms/gridsettingsdialog.ui \
|
||||
forms/loadingscreen.ui \
|
||||
forms/mapheaderform.ui \
|
||||
forms/maplisttoolbar.ui \
|
||||
forms/newlayoutdialog.ui \
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@
|
|||
<file>images/collisions_unknown.png</file>
|
||||
<file>images/Entities_16x16.png</file>
|
||||
<file>images/pokemon_icon_placeholder.png</file>
|
||||
<file>images/porysplash.gif</file>
|
||||
<file>icons/clipboard.ico</file>
|
||||
<file>icons/map_go.ico</file>
|
||||
</qresource>
|
||||
|
|
|
|||
BIN
resources/images/porysplash.gif
Normal file
BIN
resources/images/porysplash.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
|
|
@ -1,5 +1,6 @@
|
|||
#include "log.h"
|
||||
#include "parseutil.h"
|
||||
#include "loadingscreen.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QJsonDocument>
|
||||
|
|
@ -74,6 +75,8 @@ QString ParseUtil::createErrorMessage(const QString &message, const QString &exp
|
|||
}
|
||||
|
||||
QString ParseUtil::readTextFile(const QString &path, QString *error) {
|
||||
// splash screen message
|
||||
porysplash->showMessage(path);
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
if (error) *error = file.errorString();
|
||||
|
|
|
|||
10
src/main.cpp
10
src/main.cpp
|
|
@ -1,4 +1,6 @@
|
|||
#include "mainwindow.h"
|
||||
#include "loadingscreen.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
@ -6,8 +8,14 @@ int main(int argc, char *argv[])
|
|||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
|
||||
QApplication a(argc, argv);
|
||||
a.setStyle("fusion");
|
||||
|
||||
porysplash = new PorymapLoadingScreen;
|
||||
porysplash->show();
|
||||
|
||||
QObject::connect(&a, &QCoreApplication::aboutToQuit, [=]() { delete porysplash; });
|
||||
|
||||
MainWindow w(nullptr);
|
||||
w.show();
|
||||
w.initialize();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include "newmapgroupdialog.h"
|
||||
#include "newlocationdialog.h"
|
||||
#include "message.h"
|
||||
#include "loadingscreen.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDirIterator>
|
||||
|
|
@ -75,10 +76,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
cleanupLargeLog();
|
||||
logInfo(QString("Launching Porymap v%1").arg(QCoreApplication::applicationVersion()));
|
||||
}
|
||||
|
||||
void MainWindow::initialize() {
|
||||
porysplash->start();
|
||||
this->initWindow();
|
||||
if (porymapConfig.reopenOnLaunch && !porymapConfig.projectManuallyClosed && this->openProject(porymapConfig.getRecentProject(), true))
|
||||
if (porymapConfig.reopenOnLaunch && !porymapConfig.projectManuallyClosed && this->openProject(porymapConfig.getRecentProject(), true)) {
|
||||
on_toolButton_Paint_clicked();
|
||||
}
|
||||
|
||||
// there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture
|
||||
// the warning is a bit annoying, so it is disabled here
|
||||
|
|
@ -86,6 +91,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
if (porymapConfig.checkForUpdates)
|
||||
this->checkForUpdates(false);
|
||||
|
||||
porysplash->close();
|
||||
this->show();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
|
@ -153,7 +161,6 @@ void MainWindow::initWindow() {
|
|||
#endif
|
||||
|
||||
setWindowDisabled(true);
|
||||
show();
|
||||
}
|
||||
|
||||
void MainWindow::initShortcuts() {
|
||||
|
|
|
|||
51
src/ui/loadingscreen.cpp
Normal file
51
src/ui/loadingscreen.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
#include "loadingscreen.h"
|
||||
#include "ui_loadingscreen.h"
|
||||
#include "qgifimage.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
PorymapLoadingScreen *porysplash = nullptr;
|
||||
|
||||
|
||||
|
||||
PorymapLoadingScreen::~PorymapLoadingScreen() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
PorymapLoadingScreen::PorymapLoadingScreen(QWidget *parent) : QWidget(parent), ui(new Ui::LoadingScreen) {
|
||||
ui->setupUi(this);
|
||||
this->setWindowFlags(Qt::FramelessWindowHint);
|
||||
|
||||
this->splashImage.load(":/images/porysplash.gif");
|
||||
|
||||
this->setPixmap(QPixmap::fromImage(this->splashImage.frame(0)));
|
||||
|
||||
connect(&this->timer, &QTimer::timeout, this, &PorymapLoadingScreen::updateFrame);
|
||||
}
|
||||
|
||||
void PorymapLoadingScreen::setPixmap(QPixmap pixmap) {
|
||||
if (!this->isVisible()) return;
|
||||
this->ui->labelPixmap->setPixmap(pixmap);
|
||||
}
|
||||
|
||||
void PorymapLoadingScreen::showMessage(QString text) {
|
||||
if (!this->isVisible()) return;
|
||||
this->ui->labelText->setText(text.mid(text.lastIndexOf("/") + 1));
|
||||
//this->updateFrame();
|
||||
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void PorymapLoadingScreen::updateFrame() {
|
||||
//
|
||||
this->frame = (this->frame + 1) % this->splashImage.frameCount();
|
||||
|
||||
this->setPixmap(QPixmap::fromImage(this->splashImage.frame(this->frame)));
|
||||
|
||||
QApplication::processEvents();
|
||||
|
||||
//this->showMessage("Frame Number: " + QString::number(this->frame));
|
||||
|
||||
//this->repaint();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user