#pragma once #include #if __cplusplus >= 201703L #include #else #include namespace std { struct nullopt_t { // no-value state indicator struct _Tag { }; constexpr explicit nullopt_t(_Tag) {} }; constexpr nullopt_t nullopt{ nullopt_t::_Tag{} }; class bad_optional_access : public std::exception { public: const char* what() const noexcept override { return "bad optional access"; } }; template class optional { public: constexpr optional() noexcept : _engaged(false) {} constexpr optional(nullopt_t) noexcept : _engaged(false) {} optional(const optional& other) : _engaged(other._engaged) { if (other._engaged) { new (_storage) T(*other); } } optional(optional&& other) noexcept : _engaged(other._engaged) { if (other._engaged) { new (_storage) T(std::move(*other)); other._engaged = false; } } optional& operator=(const optional& other) { if(this == &other) return *this; if(_engaged && other._engaged) { **this = *other; } else if(other._engaged) { new (_storage) T(*other); _engaged = true; } else if(_engaged) { reset(); } return *this; } optional& operator=(optional&& other) noexcept { if(this == &other) return *this; if(_engaged && other._engaged) { **this = std::move(*other); } else if (other._engaged) { new(_storage) T(std::move(*other)); _engaged = true; } else if(_engaged) { reset(); } other._engaged = false; return *this; } optional(const T& value) : _engaged(true) { new (_storage) T(value); } optional(T&& value) : _engaged(true) { new (_storage) T(std::move(value)); } ~optional() { reset(); } void reset() noexcept { if (_engaged) { reinterpret_cast(_storage)->~T(); _engaged = false; } } constexpr bool has_value() const noexcept { return _engaged; } T& operator*() & { if(!_engaged) throw std::bad_optional_access(); return *reinterpret_cast(_storage); } const T& operator*() const& { if(!_engaged) throw std::bad_optional_access(); return *reinterpret_cast(_storage); } T&& operator*() && { if(!_engaged) throw std::bad_optional_access(); return std::move(*reinterpret_cast(_storage)); } const T&& operator*() const&& { if(!_engaged) throw std::bad_optional_access(); return std::move(*reinterpret_cast(_storage)); } T* operator->() { return reinterpret_cast(_storage); } const T* operator->() const { return reinterpret_cast(_storage); } explicit operator bool() const noexcept { return _engaged; } private: bool _engaged; char _storage[sizeof(T)]; }; // // template // 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_; // } // // 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 workRect_; HMONITOR monitor_{ nullptr }; WINDOWPLACEMENT wndPlaceMent_{ 0, 0, 0, {0, 0}, {0, 0}, {0, 0, 0, 0} }; };