107 lines
2.4 KiB
C++
107 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <QRect>
|
|
#include <QString>
|
|
#include <QWidget>
|
|
#include <functional>
|
|
|
|
class QCloseEvent;
|
|
class QShowEvent;
|
|
class QHideEvent;
|
|
class QEventLoop;
|
|
class QScreen;
|
|
|
|
namespace Dpi {
|
|
|
|
// Modal result constants equivalent (mrNone, mrOk, mrCancel, ...).
|
|
enum class ModalResult {
|
|
None,
|
|
Ok,
|
|
Cancel,
|
|
Abort,
|
|
Retry,
|
|
Ignore,
|
|
Yes,
|
|
No,
|
|
All,
|
|
NoToAll,
|
|
YesToAll,
|
|
Close,
|
|
};
|
|
|
|
// TForm equivalent. Subclass this the same way game windows subclassed
|
|
// Dpi.Forms.TForm; ShowModal()/close handling mirror the VCL/LCL semantics.
|
|
class Form : public QWidget {
|
|
Q_OBJECT
|
|
public:
|
|
explicit Form(QWidget *parent = nullptr);
|
|
~Form() override;
|
|
|
|
ModalResult showModal();
|
|
ModalResult modalResult() const { return m_modalResult; }
|
|
void setModalResult(ModalResult value) { m_modalResult = value; }
|
|
|
|
// TNotifyEvent / TCloseEvent equivalents.
|
|
std::function<void()> onShow;
|
|
std::function<void()> onHide;
|
|
std::function<void()> onActivate;
|
|
std::function<void()> onDeactivate;
|
|
std::function<bool()> onCloseQuery; // return false to veto the close
|
|
std::function<void()> onClose;
|
|
|
|
protected:
|
|
void showEvent(QShowEvent *event) override;
|
|
void hideEvent(QHideEvent *event) override;
|
|
void closeEvent(QCloseEvent *event) override;
|
|
bool event(QEvent *event) override;
|
|
|
|
private:
|
|
ModalResult m_modalResult = ModalResult::None;
|
|
QEventLoop *m_modalLoop = nullptr;
|
|
};
|
|
|
|
// TApplication equivalent: thin facade over QApplication.
|
|
class Application {
|
|
public:
|
|
static void run();
|
|
static void processMessages();
|
|
static void terminate();
|
|
static Form *mainForm() { return s_mainForm; }
|
|
static void setMainForm(Form *form) { s_mainForm = form; }
|
|
static QString title();
|
|
static void setTitle(const QString &value);
|
|
static QString exeName();
|
|
|
|
private:
|
|
static Form *s_mainForm;
|
|
};
|
|
|
|
// TMonitor equivalent.
|
|
class Monitor {
|
|
public:
|
|
explicit Monitor(QScreen *screen) : m_screen(screen) {}
|
|
int left() const;
|
|
int top() const;
|
|
int width() const;
|
|
int height() const;
|
|
QRect boundsRect() const;
|
|
|
|
private:
|
|
QScreen *m_screen;
|
|
};
|
|
|
|
// TScreen equivalent: thin facade over QGuiApplication screen state.
|
|
class Screen {
|
|
public:
|
|
static int formCount();
|
|
static Form *activeForm();
|
|
static int dpi();
|
|
static int pixelsPerInch();
|
|
static int width();
|
|
static int height();
|
|
static QRect desktopRect();
|
|
static Monitor primaryMonitor();
|
|
};
|
|
|
|
} // namespace Dpi
|