DYTSrouce/src/ui/FramelessDelegateWin.h

128 lines
2.9 KiB
C
Raw Normal View History

2025-01-04 04:12:51 +00:00
#pragma once
#include <Windows.h>
2025-01-07 14:47:07 +00:00
2025-01-04 04:12:51 +00:00
#if __cplusplus >= 201703L
#include <optional>
#else
2025-01-07 14:47:07 +00:00
#include <stdexcept>
2025-01-04 04:12:51 +00:00
namespace std {
struct nullopt_t { // no-value state indicator
struct _Tag {
};
constexpr explicit nullopt_t(_Tag) {}
};
inline constexpr nullopt_t nullopt{ nullopt_t::_Tag{} };
template<typename T>
class optional {
public:
optional() : has_value_(false) {}
optional(const T& value) : has_value_(true), value_(value) {}
optional(T&& value) : has_value_(true), value_(std::move(value)) {}
optional(nullopt_t) : has_value_(false) {}
bool has_value() const {
return has_value_;
}
T& value() {
if (!has_value_) {
throw std::runtime_error("optional has no value");
}
return value_;
}
const T& value() const {
if (!has_value_) {
throw std::runtime_error("optional has no value");
}
return value_;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> * <20><> -> ʹ<><CAB9>ʹ<EFBFBD>ø<EFBFBD><C3B8>ӷ<EFBFBD><D3B7><EFBFBD>
T& operator*() {
return value();
}
const T& operator*() const {
return value();
}
T* operator->() {
return &value();
}
const T* operator->() const {
return &value();
}
bool operator==(const optional& other) const {
if (has_value_ && other.has_value_) {
return value_ == other.value_;
}
return has_value_ == other.has_value_;
}
bool operator!=(const optional& other) const {
return !(*this == other);
}
bool operator!() const {
return !has_value();
}
private:
bool has_value_;
T value_;
};
}
#endif
#include "FramelessDelegate.h"
class FramelessDelegateWin : public FramelessDelegate {
Q_OBJECT
public:
FramelessDelegateWin(QWidget* parent);
~FramelessDelegateWin() override;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
#else
bool nativeEvent(const QByteArray& eventType, void* message, qintptr* result) override;
#endif
protected:
void OnShow() override;
void OnHide() override;
void OnClose() override;
void OnScreenChangeInternaal() override;
void AddMoveBar(QWidget* moveWidget) override;
private:
double DpiScale(double value);
double UnDpiScale(double value);
void CheckMonitorChanged();
void ShowSystemMenu(const QPoint& pos);
void SetNativeWindowLong();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool OnNCTitTest(MSG* msg, long* result);
#else
bool OnNCTitTest(MSG* msg, qintptr* result);
#endif
private:
bool firstShow_{ true };
std::optional<QRect> workRect_;
HMONITOR monitor_{ nullptr };
WINDOWPLACEMENT wndPlaceMent_{ 0, 0, 0, {0, 0}, {0, 0}, {0, 0, 0, 0} };
};