general fixes
fixed some minor issues Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
c3fa2f6920
commit
840cf3060d
|
@ -16,11 +16,18 @@
|
|||
#include <private/framelesswidgetshelper_p.h>
|
||||
#include "../shared/settings.h"
|
||||
|
||||
extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
extern template void Settings::set<qreal>(const QString &, const QString &, const qreal &);
|
||||
|
||||
extern template QRect Settings::get<QRect>(const QString &, const QString &);
|
||||
extern template qreal Settings::get<qreal>(const QString &, const QString &);
|
||||
|
||||
FRAMELESSHELPER_USE_NAMESPACE
|
||||
|
||||
using namespace Global;
|
||||
|
||||
FRAMELESSHELPER_STRING_CONSTANT(Geometry)
|
||||
FRAMELESSHELPER_STRING_CONSTANT(DevicePixelRatio)
|
||||
|
||||
Dialog::Dialog(QWidget *parent) : FramelessDialog(parent)
|
||||
{
|
||||
|
@ -31,7 +38,10 @@ Dialog::~Dialog() = default;
|
|||
|
||||
void Dialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Settings::set({}, kGeometry, saveGeometry());
|
||||
if (!parent()) {
|
||||
Settings::set({}, kGeometry, geometry());
|
||||
Settings::set({}, kDevicePixelRatio, devicePixelRatioF());
|
||||
}
|
||||
FramelessDialog::closeEvent(event);
|
||||
}
|
||||
|
||||
|
@ -123,11 +133,15 @@ void Dialog::setupUi()
|
|||
// So apparently we can't use QWidget::setFixedWidth/Height/Size() here.
|
||||
FramelessWidgetsHelperPrivate::get(helper)->setProperty(kDontOverrideCursorVar, true);
|
||||
connect(helper, &FramelessWidgetsHelper::ready, this, [this, helper](){
|
||||
const QByteArray data = Settings::get({}, kGeometry);
|
||||
if (data.isEmpty()) {
|
||||
helper->moveWindowToDesktopCenter();
|
||||
const auto savedGeometry = Settings::get<QRect>({}, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>({}, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
} else {
|
||||
restoreGeometry(data);
|
||||
helper->moveWindowToDesktopCenter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -53,10 +53,5 @@ int main(int argc, char *argv[])
|
|||
const auto dialog = std::make_unique<Dialog>();
|
||||
dialog->show();
|
||||
|
||||
const int exec = QCoreApplication::exec();
|
||||
|
||||
// Not necessary, but if you don't call it, there will be some small memory leaks.
|
||||
FramelessHelper::Widgets::uninitialize();
|
||||
|
||||
return exec;
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
|
|
@ -53,10 +53,5 @@ int main(int argc, char *argv[])
|
|||
const auto mainWindow = std::make_unique<MainWindow>();
|
||||
mainWindow->show();
|
||||
|
||||
const int exec = QCoreApplication::exec();
|
||||
|
||||
// Not necessary, but if you don't call it, there will be some small memory leaks.
|
||||
FramelessHelper::Widgets::uninitialize();
|
||||
|
||||
return exec;
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
|
|
@ -34,12 +34,21 @@
|
|||
#include "../widget/widget.h"
|
||||
#include "../dialog/dialog.h"
|
||||
|
||||
extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
extern template void Settings::set<qreal>(const QString &, const QString &, const qreal &);
|
||||
extern template void Settings::set<QByteArray>(const QString &, const QString &, const QByteArray &);
|
||||
|
||||
extern template QRect Settings::get<QRect>(const QString &, const QString &);
|
||||
extern template qreal Settings::get<qreal>(const QString &, const QString &);
|
||||
extern template QByteArray Settings::get<QByteArray>(const QString &, const QString &);
|
||||
|
||||
FRAMELESSHELPER_USE_NAMESPACE
|
||||
|
||||
using namespace Global;
|
||||
|
||||
FRAMELESSHELPER_STRING_CONSTANT(Geometry)
|
||||
FRAMELESSHELPER_STRING_CONSTANT(State)
|
||||
FRAMELESSHELPER_STRING_CONSTANT(DevicePixelRatio)
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent, const Qt::WindowFlags flags) : FramelessMainWindow(parent, flags)
|
||||
{
|
||||
|
@ -50,8 +59,11 @@ MainWindow::~MainWindow() = default;
|
|||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Settings::set({}, kGeometry, saveGeometry());
|
||||
if (!parent()) {
|
||||
Settings::set({}, kGeometry, geometry());
|
||||
Settings::set({}, kState, saveState());
|
||||
Settings::set({}, kDevicePixelRatio, devicePixelRatioF());
|
||||
}
|
||||
FramelessMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
|
@ -94,15 +106,19 @@ QMenuBar::item:pressed {
|
|||
helper->setSystemButton(m_titleBar->closeButton(), SystemButtonType::Close);
|
||||
helper->setHitTestVisible(mb); // IMPORTANT!
|
||||
connect(helper, &FramelessWidgetsHelper::ready, this, [this, helper](){
|
||||
const QByteArray geoData = Settings::get({}, kGeometry);
|
||||
const QByteArray stateData = Settings::get({}, kState);
|
||||
if (geoData.isEmpty()) {
|
||||
helper->moveWindowToDesktopCenter();
|
||||
const auto savedGeometry = Settings::get<QRect>({}, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>({}, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
} else {
|
||||
restoreGeometry(geoData);
|
||||
helper->moveWindowToDesktopCenter();
|
||||
}
|
||||
if (!stateData.isEmpty()) {
|
||||
restoreState(stateData);
|
||||
const QByteArray savedState = Settings::get<QByteArray>({}, kState);
|
||||
if (!savedState.isEmpty() && !parent()) {
|
||||
restoreState(savedState);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -105,10 +105,5 @@ int main(int argc, char *argv[])
|
|||
const auto mainWindow = std::make_unique<MainWindow>();
|
||||
mainWindow->show();
|
||||
|
||||
const int exec = QCoreApplication::exec();
|
||||
|
||||
// Not necessary, but if you don't call it, there will be some small memory leaks.
|
||||
FramelessHelper::Widgets::uninitialize();
|
||||
|
||||
return exec;
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
|
|
@ -31,11 +31,18 @@
|
|||
#include <StandardSystemButton>
|
||||
#include "../shared/settings.h"
|
||||
|
||||
extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
extern template void Settings::set<qreal>(const QString &, const QString &, const qreal &);
|
||||
|
||||
extern template QRect Settings::get<QRect>(const QString &, const QString &);
|
||||
extern template qreal Settings::get<qreal>(const QString &, const QString &);
|
||||
|
||||
FRAMELESSHELPER_USE_NAMESPACE
|
||||
|
||||
using namespace Global;
|
||||
|
||||
FRAMELESSHELPER_STRING_CONSTANT(Geometry)
|
||||
FRAMELESSHELPER_STRING_CONSTANT(DevicePixelRatio)
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : FramelessWidget(parent)
|
||||
{
|
||||
|
@ -46,7 +53,10 @@ MainWindow::~MainWindow() = default;
|
|||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Settings::set({}, kGeometry, saveGeometry());
|
||||
if (!parent()) {
|
||||
Settings::set({}, kGeometry, geometry());
|
||||
Settings::set({}, kDevicePixelRatio, devicePixelRatioF());
|
||||
}
|
||||
FramelessWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
|
@ -71,11 +81,15 @@ void MainWindow::initialize()
|
|||
helper->setSystemButton(m_titleBar->maximizeButton(), SystemButtonType::Maximize);
|
||||
helper->setSystemButton(m_titleBar->closeButton(), SystemButtonType::Close);
|
||||
connect(helper, &FramelessWidgetsHelper::ready, this, [this, helper](){
|
||||
const QByteArray data = Settings::get({}, kGeometry);
|
||||
if (data.isEmpty()) {
|
||||
helper->moveWindowToDesktopCenter();
|
||||
const auto savedGeometry = Settings::get<QRect>({}, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>({}, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
} else {
|
||||
restoreGeometry(data);
|
||||
helper->moveWindowToDesktopCenter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -145,9 +145,5 @@ int main(int argc, char *argv[])
|
|||
homePage->show();
|
||||
#endif
|
||||
|
||||
const int exec = QCoreApplication::exec();
|
||||
|
||||
FramelessHelper::Quick::uninitialize();
|
||||
|
||||
return exec;
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
|
|
@ -23,10 +23,16 @@
|
|||
*/
|
||||
|
||||
#include "quicksettings.h"
|
||||
#include <QtCore/qdatastream.h>
|
||||
#include "../shared/settings.h"
|
||||
|
||||
FRAMELESSHELPER_STRING_CONSTANT(Geometry)
|
||||
FRAMELESSHELPER_STRING_CONSTANT(DevicePixelRatio)
|
||||
|
||||
extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
extern template void Settings::set<qreal>(const QString &, const QString &, const qreal &);
|
||||
|
||||
extern template QRect Settings::get<QRect>(const QString &, const QString &);
|
||||
extern template qreal Settings::get<qreal>(const QString &, const QString &);
|
||||
|
||||
QuickSettings::QuickSettings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
@ -40,11 +46,9 @@ void QuickSettings::saveGeometry(QWindow *window)
|
|||
if (!window) {
|
||||
return;
|
||||
}
|
||||
QByteArray data = {};
|
||||
QDataStream stream(&data, QDataStream::WriteOnly);
|
||||
stream.setVersion(QDataStream::Qt_5_6);
|
||||
stream << window->geometry();
|
||||
Settings::set(window->objectName(), kGeometry, data);
|
||||
const QString objName = window->objectName();
|
||||
Settings::set(objName, kGeometry, window->geometry());
|
||||
Settings::set(objName, kDevicePixelRatio, window->devicePixelRatio());
|
||||
}
|
||||
|
||||
bool QuickSettings::restoreGeometry(QWindow *window)
|
||||
|
@ -53,17 +57,15 @@ bool QuickSettings::restoreGeometry(QWindow *window)
|
|||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
const QByteArray data = Settings::get(window->objectName(), kGeometry);
|
||||
if (data.isEmpty()) {
|
||||
const QString objName = window->objectName();
|
||||
const auto savedGeometry = Settings::get<QRect>(objName, kGeometry);
|
||||
if (!savedGeometry.isValid()) {
|
||||
return false;
|
||||
}
|
||||
QRect geometry = {};
|
||||
QDataStream stream(data);
|
||||
stream.setVersion(QDataStream::Qt_5_6);
|
||||
stream >> geometry;
|
||||
if (!geometry.isValid()) {
|
||||
return false;
|
||||
}
|
||||
window->setGeometry(geometry);
|
||||
const auto savedDpr = Settings::get<qreal>(objName, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (window->devicePixelRatio() / oldDpr);
|
||||
window->setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QtCore/qsettings.h>
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include <QtCore/qrect.h>
|
||||
#include <framelesshelpercore_global.h>
|
||||
|
||||
static std::unique_ptr<QSettings> g_settings = nullptr;
|
||||
|
@ -47,11 +48,11 @@ static std::unique_ptr<QSettings> g_settings = nullptr;
|
|||
return (id.isEmpty() ? key : (id + u'/' + key));
|
||||
}
|
||||
|
||||
void Settings::set(const QString &id, const QString &key, const QByteArray &data)
|
||||
template<typename T>
|
||||
void Settings::set(const QString &id, const QString &key, const T &data)
|
||||
{
|
||||
Q_ASSERT(!key.isEmpty());
|
||||
Q_ASSERT(!data.isEmpty());
|
||||
if (key.isEmpty() || data.isEmpty()) {
|
||||
if (key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!g_settings) {
|
||||
|
@ -60,14 +61,23 @@ void Settings::set(const QString &id, const QString &key, const QByteArray &data
|
|||
g_settings->setValue(appKey(id, key), data);
|
||||
}
|
||||
|
||||
QByteArray Settings::get(const QString &id, const QString &key)
|
||||
template<typename T>
|
||||
T Settings::get(const QString &id, const QString &key)
|
||||
{
|
||||
Q_ASSERT(!key.isEmpty());
|
||||
if (key.isEmpty()) {
|
||||
return {};
|
||||
return T{};
|
||||
}
|
||||
if (!g_settings) {
|
||||
g_settings.reset(appConfigFile());
|
||||
}
|
||||
return g_settings->value(appKey(id, key)).toByteArray();
|
||||
return qvariant_cast<T>(g_settings->value(appKey(id, key)));
|
||||
}
|
||||
|
||||
template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
template void Settings::set<qreal>(const QString &, const QString &, const qreal &);
|
||||
template void Settings::set<QByteArray>(const QString &, const QString &, const QByteArray &);
|
||||
|
||||
template QRect Settings::get<QRect>(const QString &, const QString &);
|
||||
template qreal Settings::get<qreal>(const QString &, const QString &);
|
||||
template QByteArray Settings::get<QByteArray>(const QString &, const QString &);
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
|
||||
namespace Settings
|
||||
{
|
||||
void set(const QString &id, const QString &key, const QByteArray &data);
|
||||
[[nodiscard]] QByteArray get(const QString &id, const QString &key);
|
||||
template<typename T>
|
||||
void set(const QString &id, const QString &key, const T &data);
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] T get(const QString &id, const QString &key);
|
||||
} // namespace Settings
|
||||
|
|
|
@ -58,10 +58,5 @@ int main(int argc, char *argv[])
|
|||
window2->setObjectName(FRAMELESSHELPER_STRING_LITERAL("window2"));
|
||||
window2->show();
|
||||
|
||||
const int exec = QCoreApplication::exec();
|
||||
|
||||
// Not necessary, but if you don't call it, there will be some small memory leaks.
|
||||
FramelessHelper::Widgets::uninitialize();
|
||||
|
||||
return exec;
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
|
|
@ -39,11 +39,18 @@
|
|||
#include <StandardSystemButton>
|
||||
#include "../shared/settings.h"
|
||||
|
||||
extern template void Settings::set<QRect>(const QString &, const QString &, const QRect &);
|
||||
extern template void Settings::set<qreal>(const QString &, const QString &, const qreal &);
|
||||
|
||||
extern template QRect Settings::get<QRect>(const QString &, const QString &);
|
||||
extern template qreal Settings::get<qreal>(const QString &, const QString &);
|
||||
|
||||
FRAMELESSHELPER_USE_NAMESPACE
|
||||
|
||||
using namespace Global;
|
||||
|
||||
FRAMELESSHELPER_STRING_CONSTANT(Geometry)
|
||||
FRAMELESSHELPER_STRING_CONSTANT(DevicePixelRatio)
|
||||
|
||||
Widget::Widget(QWidget *parent) : FramelessWidget(parent)
|
||||
{
|
||||
|
@ -64,7 +71,11 @@ void Widget::timerEvent(QTimerEvent *event)
|
|||
|
||||
void Widget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Settings::set(objectName(), kGeometry, saveGeometry());
|
||||
if (!parent()) {
|
||||
const QString objName = objectName();
|
||||
Settings::set(objName, kGeometry, geometry());
|
||||
Settings::set(objName, kDevicePixelRatio, devicePixelRatioF());
|
||||
}
|
||||
FramelessWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
|
@ -121,11 +132,16 @@ void Widget::initialize()
|
|||
helper->setSystemButton(m_titleBar->maximizeButton(), SystemButtonType::Maximize);
|
||||
helper->setSystemButton(m_titleBar->closeButton(), SystemButtonType::Close);
|
||||
connect(helper, &FramelessWidgetsHelper::ready, this, [this, helper](){
|
||||
const QByteArray data = Settings::get(objectName(), kGeometry);
|
||||
if (data.isEmpty()) {
|
||||
helper->moveWindowToDesktopCenter();
|
||||
const QString objName = objectName();
|
||||
const auto savedGeometry = Settings::get<QRect>(objName, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>(objName, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
} else {
|
||||
restoreGeometry(data);
|
||||
helper->moveWindowToDesktopCenter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -631,7 +631,9 @@ Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionInfo)
|
|||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Dpi);
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QT_BEGIN_NAMESPACE
|
||||
FRAMELESSHELPER_CORE_API QDebug operator<<(QDebug, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionNumber &);
|
||||
FRAMELESSHELPER_CORE_API QDebug operator<<(QDebug, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionInfo &);
|
||||
FRAMELESSHELPER_CORE_API QDebug operator<<(QDebug, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Dpi &);
|
||||
QT_END_NAMESPACE
|
||||
#endif // QT_NO_DEBUG_STREAM
|
||||
|
|
|
@ -254,6 +254,8 @@ function(deploy_qt_runtime arg_target)
|
|||
endif()
|
||||
add_custom_command(TARGET ${arg_target} POST_BUILD COMMAND
|
||||
"${QT_DEPLOY_EXECUTABLE}"
|
||||
$<$<CONFIG:Debug>:--debug>
|
||||
$<$<OR:$<CONFIG:MinSizeRel>,$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:--release>
|
||||
--libdir "$<TARGET_FILE_DIR:${arg_target}>"
|
||||
--plugindir "$<TARGET_FILE_DIR:${arg_target}>/plugins"
|
||||
--no-translations
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QT_BEGIN_NAMESPACE
|
||||
QDebug operator<<(QDebug d, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionNumber &ver)
|
||||
{
|
||||
const QDebugStateSaver saver(d);
|
||||
|
@ -108,6 +109,7 @@ QDebug operator<<(QDebug d, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Dpi
|
|||
<< "scale factor: " << scaleFactor << ')';
|
||||
return d;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
#endif // QT_NO_DEBUG_STREAM
|
||||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
|
|
@ -1229,15 +1229,10 @@ QColor Utils::getFrameBorderColor(const bool active)
|
|||
if (!WindowsVersionHelper::isWin10OrGreater()) {
|
||||
return (active ? kDefaultBlackColor : kDefaultDarkGrayColor);
|
||||
}
|
||||
const bool dark = shouldAppsUseDarkMode();
|
||||
if (active) {
|
||||
if (isFrameBorderColorized()) {
|
||||
return getDwmColorizationColor();
|
||||
return (isFrameBorderColorized() ? getDwmColorizationColor() : kDefaultTransparentColor);
|
||||
} else {
|
||||
return kDefaultFrameBorderActiveColor;
|
||||
}
|
||||
} else {
|
||||
return (dark ? kDefaultFrameBorderInactiveColorDark : kDefaultFrameBorderInactiveColorLight);
|
||||
return (shouldAppsUseDarkMode() ? kDefaultFrameBorderInactiveColorDark : kDefaultFrameBorderInactiveColorLight);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue