forked from github_mirror/framelesshelper
replace qRound with std::round
It's better to do so. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
b1f52837d2
commit
ed3771c949
|
@ -207,6 +207,7 @@ Q_NAMESPACE_EXPORT(FRAMELESSHELPER_CORE_API)
|
||||||
[[maybe_unused]] inline constexpr const int kDefaultTitleBarFontPointSize = 11;
|
[[maybe_unused]] inline constexpr const int kDefaultTitleBarFontPointSize = 11;
|
||||||
[[maybe_unused]] inline constexpr const int kDefaultTitleBarContentsMargin = 10;
|
[[maybe_unused]] inline constexpr const int kDefaultTitleBarContentsMargin = 10;
|
||||||
[[maybe_unused]] inline constexpr const QSize kDefaultWindowIconSize = {16, 16};
|
[[maybe_unused]] inline constexpr const QSize kDefaultWindowIconSize = {16, 16};
|
||||||
|
// We have to use "qRound()" here because "std::round()" is not constexpr, yet.
|
||||||
[[maybe_unused]] inline constexpr const QSize kDefaultSystemButtonSize = {qRound(qreal(kDefaultTitleBarHeight) * 1.5), kDefaultTitleBarHeight};
|
[[maybe_unused]] inline constexpr const QSize kDefaultSystemButtonSize = {qRound(qreal(kDefaultTitleBarHeight) * 1.5), kDefaultTitleBarHeight};
|
||||||
[[maybe_unused]] inline constexpr const QSize kDefaultSystemButtonIconSize = kDefaultWindowIconSize;
|
[[maybe_unused]] inline constexpr const QSize kDefaultSystemButtonIconSize = kDefaultWindowIconSize;
|
||||||
[[maybe_unused]] inline constexpr const QSize kDefaultWindowSize = {160, 160}; // Value taken from QPA.
|
[[maybe_unused]] inline constexpr const QSize kDefaultWindowSize = {160, 160}; // Value taken from QPA.
|
||||||
|
|
|
@ -1066,7 +1066,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
// Make the border a little wider to let the user easy to resize on corners.
|
// Make the border a little wider to let the user easy to resize on corners.
|
||||||
const qreal scaleFactor = ((isTop || isBottom) ? 2.0 : 1.0);
|
const qreal scaleFactor = ((isTop || isBottom) ? 2.0 : 1.0);
|
||||||
const int frameSizeX = Utils::getResizeBorderThickness(windowId, true, true);
|
const int frameSizeX = Utils::getResizeBorderThickness(windowId, true, true);
|
||||||
const int scaledFrameSizeX = qRound(qreal(frameSizeX) * scaleFactor);
|
const int scaledFrameSizeX = std::round(qreal(frameSizeX) * scaleFactor);
|
||||||
const bool isLeft = (nativeLocalPos.x < scaledFrameSizeX);
|
const bool isLeft = (nativeLocalPos.x < scaledFrameSizeX);
|
||||||
const bool isRight = (nativeLocalPos.x >= (width - scaledFrameSizeX));
|
const bool isRight = (nativeLocalPos.x >= (width - scaledFrameSizeX));
|
||||||
if (dontOverrideCursor && (isTop || isBottom || isLeft || isRight)) {
|
if (dontOverrideCursor && (isTop || isBottom || isLeft || isRight)) {
|
||||||
|
@ -1145,8 +1145,8 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
const qreal newDpr = Utils::roundScaleFactor(qreal(newDpi) / defaultDpi);
|
const qreal newDpr = Utils::roundScaleFactor(qreal(newDpi) / defaultDpi);
|
||||||
const QSizeF newSize = (oldSize / oldDpr * newDpr);
|
const QSizeF newSize = (oldSize / oldDpr * newDpr);
|
||||||
const auto suggestedSize = reinterpret_cast<LPSIZE>(lParam);
|
const auto suggestedSize = reinterpret_cast<LPSIZE>(lParam);
|
||||||
suggestedSize->cx = qRound(newSize.width());
|
suggestedSize->cx = std::round(newSize.width());
|
||||||
suggestedSize->cy = qRound(newSize.height());
|
suggestedSize->cy = std::round(newSize.height());
|
||||||
// If the window frame is visible, we need to expand the suggested size, currently
|
// If the window frame is visible, we need to expand the suggested size, currently
|
||||||
// it's pure client size, we need to add the frame size to it. Windows expects a
|
// it's pure client size, we need to add the frame size to it. Windows expects a
|
||||||
// full window size, including the window frame.
|
// full window size, including the window frame.
|
||||||
|
|
|
@ -230,7 +230,7 @@ static inline void expblur(QImage &img, qreal radius, const bool improvedQuality
|
||||||
// the cutOffIntensity
|
// the cutOffIntensity
|
||||||
static constexpr const qreal cutOffIntensity = 2.0;
|
static constexpr const qreal cutOffIntensity = 2.0;
|
||||||
const int alpha = ((radius <= qreal(1e-5)) ? ((1 << aprec) - 1) :
|
const int alpha = ((radius <= qreal(1e-5)) ? ((1 << aprec) - 1) :
|
||||||
qRound((1 << aprec) * (1 - qPow(cutOffIntensity / qreal(255), qreal(1) / radius))));
|
std::round((1 << aprec) * (1 - qPow(cutOffIntensity / qreal(255), qreal(1) / radius))));
|
||||||
|
|
||||||
int img_height = img.height();
|
int img_height = img.height();
|
||||||
for (int row = 0; row != img_height; ++row) {
|
for (int row = 0; row != img_height; ++row) {
|
||||||
|
|
|
@ -214,8 +214,8 @@ void Utils::moveWindowToDesktopCenter(const GetWindowScreenCallback &getWindowSc
|
||||||
}
|
}
|
||||||
const QSize screenSize = (considerTaskBar ? screen->availableVirtualSize() : screen->virtualSize());
|
const QSize screenSize = (considerTaskBar ? screen->availableVirtualSize() : screen->virtualSize());
|
||||||
const QPoint offset = (considerTaskBar ? screen->availableVirtualGeometry().topLeft() : QPoint(0, 0));
|
const QPoint offset = (considerTaskBar ? screen->availableVirtualGeometry().topLeft() : QPoint(0, 0));
|
||||||
const int newX = qRound(qreal(screenSize.width() - windowSize.width()) / 2.0);
|
const int newX = std::round(qreal(screenSize.width() - windowSize.width()) / 2.0);
|
||||||
const int newY = qRound(qreal(screenSize.height() - windowSize.height()) / 2.0);
|
const int newY = std::round(qreal(screenSize.height() - windowSize.height()) / 2.0);
|
||||||
setWindowPosition(QPoint(newX + offset.x(), newY + offset.y()));
|
setWindowPosition(QPoint(newX + offset.x(), newY + offset.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,20 +315,20 @@ qreal Utils::roundScaleFactor(const qreal factor)
|
||||||
static const auto policy = QGuiApplication::highDpiScaleFactorRoundingPolicy();
|
static const auto policy = QGuiApplication::highDpiScaleFactorRoundingPolicy();
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
case Qt::HighDpiScaleFactorRoundingPolicy::Round:
|
case Qt::HighDpiScaleFactorRoundingPolicy::Round:
|
||||||
return qRound(factor);
|
return std::round(factor);
|
||||||
case Qt::HighDpiScaleFactorRoundingPolicy::Ceil:
|
case Qt::HighDpiScaleFactorRoundingPolicy::Ceil:
|
||||||
return qCeil(factor);
|
return qCeil(factor);
|
||||||
case Qt::HighDpiScaleFactorRoundingPolicy::Floor:
|
case Qt::HighDpiScaleFactorRoundingPolicy::Floor:
|
||||||
return qFloor(factor);
|
return qFloor(factor);
|
||||||
case Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor:
|
case Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor:
|
||||||
return (((factor - qreal(int(factor))) >= qreal(0.75)) ? qRound(factor) : qFloor(factor));
|
return (((factor - qreal(int(factor))) >= qreal(0.75)) ? std::round(factor) : qFloor(factor));
|
||||||
case Qt::HighDpiScaleFactorRoundingPolicy::PassThrough:
|
case Qt::HighDpiScaleFactorRoundingPolicy::PassThrough:
|
||||||
case Qt::HighDpiScaleFactorRoundingPolicy::Unset: // According to Qt source code, this enum value is the same with PassThrough.
|
case Qt::HighDpiScaleFactorRoundingPolicy::Unset: // According to Qt source code, this enum value is the same with PassThrough.
|
||||||
return factor;
|
return factor;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
# else // (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
|
# else // (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
|
||||||
return qRound(factor);
|
return std::round(factor);
|
||||||
# endif // (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
# endif // (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
#else // (!FRAMELESSHELPER_CORE_NO_PRIVATE && (QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)))
|
#else // (!FRAMELESSHELPER_CORE_NO_PRIVATE && (QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)))
|
||||||
return QHighDpiScaling::roundScaleFactor(factor);
|
return QHighDpiScaling::roundScaleFactor(factor);
|
||||||
|
@ -342,7 +342,7 @@ int Utils::toNativePixels(const QWindow *window, const int value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE
|
#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE
|
||||||
return qRound(qreal(value) * window->devicePixelRatio());
|
return std::round(qreal(value) * window->devicePixelRatio());
|
||||||
#else // !FRAMELESSHELPER_CORE_NO_PRIVATE
|
#else // !FRAMELESSHELPER_CORE_NO_PRIVATE
|
||||||
return QHighDpi::toNativePixels(value, window);
|
return QHighDpi::toNativePixels(value, window);
|
||||||
#endif // FRAMELESSHELPER_CORE_NO_PRIVATE
|
#endif // FRAMELESSHELPER_CORE_NO_PRIVATE
|
||||||
|
@ -394,7 +394,7 @@ int Utils::fromNativePixels(const QWindow *window, const int value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE
|
#ifdef FRAMELESSHELPER_CORE_NO_PRIVATE
|
||||||
return qRound(qreal(value) / window->devicePixelRatio());
|
return std::round(qreal(value) / window->devicePixelRatio());
|
||||||
#else // !FRAMELESSHELPER_CORE_NO_PRIVATE
|
#else // !FRAMELESSHELPER_CORE_NO_PRIVATE
|
||||||
return QHighDpi::fromNativePixels(value, window);
|
return QHighDpi::fromNativePixels(value, window);
|
||||||
#endif // FRAMELESSHELPER_CORE_NO_PRIVATE
|
#endif // FRAMELESSHELPER_CORE_NO_PRIVATE
|
||||||
|
|
|
@ -1033,7 +1033,7 @@ static inline void moveWindowToMonitor(const HWND hwnd, const MONITORINFOEXW &ac
|
||||||
static constexpr const auto defaultDpi = qreal(USER_DEFAULT_SCREEN_DPI);
|
static constexpr const auto defaultDpi = qreal(USER_DEFAULT_SCREEN_DPI);
|
||||||
const qreal currentDpr = (qreal(Utils::getPrimaryScreenDpi(horizontal)) / defaultDpi);
|
const qreal currentDpr = (qreal(Utils::getPrimaryScreenDpi(horizontal)) / defaultDpi);
|
||||||
const qreal requestedDpr = (qreal(dpi) / defaultDpi);
|
const qreal requestedDpr = (qreal(dpi) / defaultDpi);
|
||||||
return qRound(qreal(GetSystemMetrics(index)) / currentDpr * requestedDpr);
|
return std::round(qreal(GetSystemMetrics(index)) / currentDpr * requestedDpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static inline int getSystemMetrics2(const WId windowId, const int index,
|
[[nodiscard]] static inline int getSystemMetrics2(const WId windowId, const int index,
|
||||||
|
@ -1053,7 +1053,7 @@ static inline void moveWindowToMonitor(const HWND hwnd, const MONITORINFOEXW &ac
|
||||||
// GetSystemMetrics() will always return a scaled value, so if we want to get an unscaled
|
// GetSystemMetrics() will always return a scaled value, so if we want to get an unscaled
|
||||||
// one, we have to calculate it ourself.
|
// one, we have to calculate it ourself.
|
||||||
const qreal dpr = (scaled ? qreal(1) : (qreal(realDpi) / qreal(USER_DEFAULT_SCREEN_DPI)));
|
const qreal dpr = (scaled ? qreal(1) : (qreal(realDpi) / qreal(USER_DEFAULT_SCREEN_DPI)));
|
||||||
return qRound(qreal(GetSystemMetrics(index)) / dpr);
|
return std::round(qreal(GetSystemMetrics(index)) / dpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]] [[nodiscard]] static inline
|
[[maybe_unused]] [[nodiscard]] static inline
|
||||||
|
@ -1547,7 +1547,7 @@ void Utils::syncWmPaintWithDwm()
|
||||||
Q_ASSERT(m >= 0);
|
Q_ASSERT(m >= 0);
|
||||||
Q_ASSERT(m < period);
|
Q_ASSERT(m < period);
|
||||||
const qreal m_ms = (1000.0 * qreal(m) / qreal(freq.QuadPart));
|
const qreal m_ms = (1000.0 * qreal(m) / qreal(freq.QuadPart));
|
||||||
Sleep(static_cast<DWORD>(qRound(m_ms)));
|
Sleep(static_cast<DWORD>(std::round(m_ms)));
|
||||||
if (API_CALL_FUNCTION4(timeEndPeriod, ms_granularity) != TIMERR_NOERROR) {
|
if (API_CALL_FUNCTION4(timeEndPeriod, ms_granularity) != TIMERR_NOERROR) {
|
||||||
WARNING << "timeEndPeriod() failed.";
|
WARNING << "timeEndPeriod() failed.";
|
||||||
}
|
}
|
||||||
|
@ -1584,7 +1584,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
|
||||||
_DEVICE_SCALE_FACTOR factor = _DEVICE_SCALE_FACTOR_INVALID;
|
_DEVICE_SCALE_FACTOR factor = _DEVICE_SCALE_FACTOR_INVALID;
|
||||||
const HRESULT hr = API_CALL_FUNCTION4(GetScaleFactorForMonitor, hMonitor, &factor);
|
const HRESULT hr = API_CALL_FUNCTION4(GetScaleFactorForMonitor, hMonitor, &factor);
|
||||||
if (SUCCEEDED(hr) && (factor != _DEVICE_SCALE_FACTOR_INVALID)) {
|
if (SUCCEEDED(hr) && (factor != _DEVICE_SCALE_FACTOR_INVALID)) {
|
||||||
return quint32(qRound(qreal(USER_DEFAULT_SCREEN_DPI) * qreal(factor) / qreal(100)));
|
return quint32(std::round(qreal(USER_DEFAULT_SCREEN_DPI) * qreal(factor) / qreal(100)));
|
||||||
} else {
|
} else {
|
||||||
WARNING << __getSystemErrorMessage(kGetScaleFactorForMonitor, hr);
|
WARNING << __getSystemErrorMessage(kGetScaleFactorForMonitor, hr);
|
||||||
}
|
}
|
||||||
|
@ -1638,7 +1638,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
|
||||||
d2dFactory->GetDesktopDpi(&dpiX, &dpiY);
|
d2dFactory->GetDesktopDpi(&dpiX, &dpiY);
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
if ((dpiX > 0.0f) && (dpiY > 0.0f)) {
|
if ((dpiX > 0.0f) && (dpiY > 0.0f)) {
|
||||||
return (horizontal ? quint32(qRound(dpiX)) : quint32(qRound(dpiY)));
|
return (horizontal ? quint32(std::round(dpiX)) : quint32(std::round(dpiY)));
|
||||||
} else {
|
} else {
|
||||||
WARNING << "GetDesktopDpi() failed.";
|
WARNING << "GetDesktopDpi() failed.";
|
||||||
}
|
}
|
||||||
|
@ -1816,7 +1816,7 @@ quint32 Utils::getFrameBorderThicknessForDpi(const quint32 dpi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const qreal dpr = (qreal(dpi) / qreal(USER_DEFAULT_SCREEN_DPI));
|
const qreal dpr = (qreal(dpi) / qreal(USER_DEFAULT_SCREEN_DPI));
|
||||||
return qRound(qreal(kDefaultWindowFrameBorderThickness) * dpr);
|
return std::round(qreal(kDefaultWindowFrameBorderThickness) * dpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 Utils::getFrameBorderThickness(const WId windowId, const bool scaled)
|
quint32 Utils::getFrameBorderThickness(const WId windowId, const bool scaled)
|
||||||
|
@ -1840,10 +1840,10 @@ quint32 Utils::getFrameBorderThickness(const WId windowId, const bool scaled)
|
||||||
_DWMWA_VISIBLE_FRAME_BORDER_THICKNESS, &value, sizeof(value));
|
_DWMWA_VISIBLE_FRAME_BORDER_THICKNESS, &value, sizeof(value));
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
const qreal dpr = (scaled ? 1.0 : scaleFactor);
|
const qreal dpr = (scaled ? 1.0 : scaleFactor);
|
||||||
return qRound(qreal(value) / dpr);
|
return std::round(qreal(value) / dpr);
|
||||||
} else {
|
} else {
|
||||||
const qreal dpr = (scaled ? scaleFactor : 1.0);
|
const qreal dpr = (scaled ? scaleFactor : 1.0);
|
||||||
return qRound(qreal(kDefaultWindowFrameBorderThickness) * dpr);
|
return std::round(qreal(kDefaultWindowFrameBorderThickness) * dpr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ QRect QuickImageItemPrivate::paintArea() const
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||||
const QSize size = q->size().toSize();
|
const QSize size = q->size().toSize();
|
||||||
#else
|
#else
|
||||||
const QSize size = {qRound(q->width()), qRound(q->height())};
|
const QSize size = {int(std::round(q->width())), int(std::round(q->height()))};
|
||||||
#endif
|
#endif
|
||||||
return {QPoint(0, 0), size};
|
return {QPoint(0, 0), size};
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ bool QuickStandardTitleBar::mouseEventHandler(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
FramelessQuickHelper::get(this)->showSystemMenu([this, button, &scenePos]() -> QPoint {
|
FramelessQuickHelper::get(this)->showSystemMenu([this, button, &scenePos]() -> QPoint {
|
||||||
if (button == Qt::LeftButton) {
|
if (button == Qt::LeftButton) {
|
||||||
return {0, qRound(height())};
|
return {0, int(std::round(height()))};
|
||||||
}
|
}
|
||||||
return scenePos;
|
return scenePos;
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -263,7 +263,7 @@ void QuickWindowBorder::setThickness(const qreal value)
|
||||||
if (qFuzzyCompare(thickness(), value)) {
|
if (qFuzzyCompare(thickness(), value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
d->m_borderPainter->setThickness(qRound(value));
|
d->m_borderPainter->setThickness(std::round(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickWindowBorder::setEdges(const QuickGlobal::WindowEdges value)
|
void QuickWindowBorder::setEdges(const QuickGlobal::WindowEdges value)
|
||||||
|
|
|
@ -183,10 +183,10 @@ void StandardSystemButtonPrivate::setHovered(const bool value)
|
||||||
static const int h = kDefaultSystemButtonSize.height();
|
static const int h = kDefaultSystemButtonSize.height();
|
||||||
if (const QWidget * const window = q->window()) {
|
if (const QWidget * const window = q->window()) {
|
||||||
if (Utils::windowStatesToWindowState(window->windowState()) == Qt::WindowMaximized) {
|
if (Utils::windowStatesToWindowState(window->windowState()) == Qt::WindowMaximized) {
|
||||||
return qRound(h * 0.5);
|
return std::round(h * 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -qRound(h * 1.3);
|
return -std::round(h * 1.3);
|
||||||
}();
|
}();
|
||||||
QToolTip::showText(q->mapToGlobal(QPoint(-2, yPos)), toolTip, q, q->geometry());
|
QToolTip::showText(q->mapToGlobal(QPoint(-2, yPos)), toolTip, q, q->geometry());
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,7 +342,7 @@ QRect StandardTitleBarPrivate::windowIconRect() const
|
||||||
{
|
{
|
||||||
Q_Q(const StandardTitleBar);
|
Q_Q(const StandardTitleBar);
|
||||||
const QSize size = windowIconSize();
|
const QSize size = windowIconSize();
|
||||||
const int y = qRound(qreal(q->height() - size.height()) / qreal(2));
|
const int y = std::round(qreal(q->height() - size.height()) / qreal(2));
|
||||||
return {QPoint(kDefaultTitleBarContentsMargin, y), size};
|
return {QPoint(kDefaultTitleBarContentsMargin, y), size};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue