initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,146 @@
|
||||
#include "Dpi/DpiForms.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QEventLoop>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QtMath>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
Form::Form(QWidget *parent) : QWidget(parent) {}
|
||||
|
||||
Form::~Form()
|
||||
{
|
||||
if (m_modalLoop)
|
||||
m_modalLoop->quit();
|
||||
}
|
||||
|
||||
ModalResult Form::showModal()
|
||||
{
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
m_modalResult = ModalResult::None;
|
||||
show();
|
||||
|
||||
QEventLoop loop;
|
||||
m_modalLoop = &loop;
|
||||
loop.exec();
|
||||
m_modalLoop = nullptr;
|
||||
|
||||
return m_modalResult;
|
||||
}
|
||||
|
||||
void Form::showEvent(QShowEvent *event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
if (onShow)
|
||||
onShow();
|
||||
}
|
||||
|
||||
void Form::hideEvent(QHideEvent *event)
|
||||
{
|
||||
QWidget::hideEvent(event);
|
||||
if (onHide)
|
||||
onHide();
|
||||
if (m_modalLoop)
|
||||
m_modalLoop->quit();
|
||||
}
|
||||
|
||||
void Form::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (onCloseQuery && !onCloseQuery()) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
if (onClose)
|
||||
onClose();
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
bool Form::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::WindowActivate && onActivate)
|
||||
onActivate();
|
||||
if (event->type() == QEvent::WindowDeactivate && onDeactivate)
|
||||
onDeactivate();
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
Form *Application::s_mainForm = nullptr;
|
||||
|
||||
void Application::run()
|
||||
{
|
||||
if (s_mainForm)
|
||||
s_mainForm->show();
|
||||
QApplication::exec();
|
||||
}
|
||||
|
||||
void Application::processMessages()
|
||||
{
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void Application::terminate()
|
||||
{
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
QString Application::title() { return QApplication::applicationDisplayName(); }
|
||||
void Application::setTitle(const QString &value) { QApplication::setApplicationDisplayName(value); }
|
||||
QString Application::exeName() { return QApplication::applicationFilePath(); }
|
||||
|
||||
int Monitor::left() const { return m_screen ? m_screen->geometry().left() : 0; }
|
||||
int Monitor::top() const { return m_screen ? m_screen->geometry().top() : 0; }
|
||||
int Monitor::width() const { return m_screen ? m_screen->geometry().width() : 0; }
|
||||
int Monitor::height() const { return m_screen ? m_screen->geometry().height() : 0; }
|
||||
QRect Monitor::boundsRect() const { return m_screen ? m_screen->geometry() : QRect(); }
|
||||
|
||||
int Screen::formCount()
|
||||
{
|
||||
int count = 0;
|
||||
const auto widgets = QApplication::topLevelWidgets();
|
||||
for (QWidget *widget : widgets) {
|
||||
if (qobject_cast<Form *>(widget))
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
Form *Screen::activeForm()
|
||||
{
|
||||
return qobject_cast<Form *>(QApplication::activeWindow());
|
||||
}
|
||||
|
||||
int Screen::dpi()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? qRound(screen->logicalDotsPerInch()) : 96;
|
||||
}
|
||||
|
||||
int Screen::pixelsPerInch() { return dpi(); }
|
||||
|
||||
int Screen::width()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->geometry().width() : 0;
|
||||
}
|
||||
|
||||
int Screen::height()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->geometry().height() : 0;
|
||||
}
|
||||
|
||||
QRect Screen::desktopRect()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->availableGeometry() : QRect();
|
||||
}
|
||||
|
||||
Monitor Screen::primaryMonitor()
|
||||
{
|
||||
return Monitor(QGuiApplication::primaryScreen());
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
Reference in new issue
Block a user