Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace qMin,qMax,qBound,qRound,qAbs with standard funcs #2236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions panel/lxqtpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#include <KX11Extras>
#include <NETWM>

#include <algorithm>

#include "backends/ilxqtabstractwmiface.h"


Expand Down Expand Up @@ -375,7 +377,7 @@ void LXQtPanel::readSettings()
false);

const auto screens = QApplication::screens();
mScreenNum = qBound(0, mSettings->value(QStringLiteral(CFG_KEY_SCREENNUM), 0).toInt(), screens.size() - 1);
mScreenNum = std::clamp<int>(mSettings->value(QStringLiteral(CFG_KEY_SCREENNUM), 0).toInt(), 0, screens.size() - 1);
if (QGuiApplication::platformName() == QStringLiteral("wayland"))
{
// On Wayland, first check the screen name, and if it does not exist, add it.
Expand Down Expand Up @@ -594,15 +596,15 @@ void LXQtPanel::loadPlugins()
************************************************/
int LXQtPanel::getReserveDimension()
{
return mHidable ? PANEL_HIDE_SIZE : qMax(PANEL_MINIMUM_SIZE, mPanelSize);
return mHidable ? PANEL_HIDE_SIZE : std::max(PANEL_MINIMUM_SIZE, mPanelSize);
}

QMargins LXQtPanel::layerWindowMargins()
{
QMargins margins;
if (!mHidden)
return margins;
int offset = PANEL_HIDE_SIZE - qMax(PANEL_MINIMUM_SIZE, mPanelSize); // negative
int offset = PANEL_HIDE_SIZE - std::max(PANEL_MINIMUM_SIZE, mPanelSize); // negative
if (isHorizontal())
{
if (mPosition == ILXQtPanel::PositionTop)
Expand Down Expand Up @@ -633,7 +635,7 @@ void LXQtPanel::setPanelGeometry(bool animate)
if (isHorizontal())
{
// Horiz panel ***************************
rect.setHeight(qMax(PANEL_MINIMUM_SIZE, mPanelSize));
rect.setHeight(std::max(PANEL_MINIMUM_SIZE, mPanelSize));
if (mLengthInPercents)
rect.setWidth(currentScreen.width() * mLength / 100.0);
else
Expand All @@ -644,7 +646,7 @@ void LXQtPanel::setPanelGeometry(bool animate)
rect.setWidth(mLength);
}

rect.setWidth(qMax(rect.size().width(), mLayout->minimumSize().width()));
rect.setWidth(std::max(rect.size().width(), mLayout->minimumSize().width()));

// Horiz ......................
switch (mAlignment)
Expand Down Expand Up @@ -694,7 +696,7 @@ void LXQtPanel::setPanelGeometry(bool animate)
else
{
// Vert panel ***************************
rect.setWidth(qMax(PANEL_MINIMUM_SIZE, mPanelSize));
rect.setWidth(std::max(PANEL_MINIMUM_SIZE, mPanelSize));
if (mLengthInPercents)
rect.setHeight(currentScreen.height() * mLength / 100.0);
else
Expand All @@ -705,7 +707,7 @@ void LXQtPanel::setPanelGeometry(bool animate)
rect.setHeight(mLength);
}

rect.setHeight(qMax(rect.size().height(), mLayout->minimumSize().height()));
rect.setHeight(std::max(rect.size().height(), mLayout->minimumSize().height()));

// Vert .......................
switch (mAlignment)
Expand Down Expand Up @@ -1361,7 +1363,7 @@ void LXQtPanel::setBackgroundImage(QString path, bool save)
************************************************/
void LXQtPanel::setOpacity(int opacity, bool save)
{
mOpacity = qBound(0, opacity, 100);
mOpacity = std::clamp(opacity, 0, 100);
updateStyleSheet();

if (save)
Expand Down
58 changes: 30 additions & 28 deletions panel/lxqtpanellayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <QToolButton>
#include <QStyle>

#include <algorithm>

#define ANIMATION_DURATION 250

class ItemMoveAnimation : public QVariantAnimation
Expand Down Expand Up @@ -255,9 +257,9 @@ void LayoutItemGrid::doAddToGrid(QLayoutItem *item)

int idx = mNextRow * mColCount + mNextCol;
mInfoItems[idx] = info;
mUsedColCount = qMax(mUsedColCount, mNextCol + 1);
mUsedColCount = std::max(mUsedColCount, mNextCol + 1);
mExpandable = mExpandable || info.expandable;
mRowCount = qMax(mRowCount, mNextRow+1);
mRowCount = std::max(mRowCount, mNextRow+1);

if (info.separate || mNextCol >= mColCount-1)
{
Expand Down Expand Up @@ -337,15 +339,15 @@ void LayoutItemGrid::update()
QSize sz = info.item->sizeHint();
info.geometry = QRect(QPoint(x,y), sz);
y += sz.height();
rw = qMax(rw, sz.width());
rw = std::max(rw, sz.width());
}
x += rw;

if (itemInfo(r, 0).expandable)
mExpandableSize += rw;

mSizeHint.setWidth(x);
mSizeHint.rheight() = qMax(mSizeHint.rheight(), y);
mSizeHint.rheight() = std::max(mSizeHint.rheight(), y);
}
}
else
Expand All @@ -365,15 +367,15 @@ void LayoutItemGrid::update()
QSize sz = info.item->sizeHint();
info.geometry = QRect(QPoint(x,y), sz);
x += sz.width();
rh = qMax(rh, sz.height());
rh = std::max(rh, sz.height());
}
y += rh;

if (itemInfo(r, 0).expandable)
mExpandableSize += rh;

mSizeHint.setHeight(y);
mSizeHint.rwidth() = qMax(mSizeHint.rwidth(), x);
mSizeHint.rwidth() = std::max(mSizeHint.rwidth(), x);
}
}

Expand All @@ -386,7 +388,7 @@ void LayoutItemGrid::update()
************************************************/
void LayoutItemGrid::setLineSize(int value)
{
mLineSize = qMax(1, value);
mLineSize = std::max(1, value);
invalidate();
}

Expand All @@ -396,7 +398,7 @@ void LayoutItemGrid::setLineSize(int value)
************************************************/
void LayoutItemGrid::setColCount(int value)
{
mColCount = qMax(1, value);
mColCount = std::max(1, value);
rebuild();
}

Expand Down Expand Up @@ -577,11 +579,11 @@ QSize LXQtPanelLayout::sizeHint() const
if (isHorizontal())
{
return QSize(ls.width() + rs.width(),
qMax(ls.height(), rs.height()));
std::max(ls.height(), rs.height()));
}
else
{
return QSize(qMax(ls.width(), rs.width()),
return QSize(std::max(ls.width(), rs.width()),
ls.height() + rs.height());
}
}
Expand Down Expand Up @@ -649,7 +651,7 @@ void LXQtPanelLayout::setGeometryHoriz(const QRect &geometry)
}

// Calc baselines for plugins like button.
QList<int> baseLines(qMax(mLeftGrid->colCount(), mRightGrid->colCount()));
QList<int> baseLines(std::max(mLeftGrid->colCount(), mRightGrid->colCount()));
const int bh = geometry.height() / baseLines.count();
const int base_center = bh >> 1;
const int height_remain = 0 < bh ? geometry.height() % baseLines.size() : 0;
Expand Down Expand Up @@ -702,18 +704,18 @@ void LXQtPanelLayout::setGeometryHoriz(const QRect &geometry)
{
int height = bh + (0 < remain-- ? 1 : 0);
if (!info.item->expandingDirections().testFlag(Qt::Orientation::Vertical))
height = qMin(info.geometry.height(), height);
height = qMin(geometry.height(), height);
height = std::min(info.geometry.height(), height);
height = std::min(geometry.height(), height);
rect.setHeight(height);
rect.setWidth(qMin(info.geometry.width(), geometry.width()));
rect.setWidth(std::min(info.geometry.width(), geometry.width()));
if (height < bh)
rect.moveCenter(QPoint(0, baseLines[c] + base_center));
else
rect.moveTop(baseLines[c]);
rect.moveLeft(left);
}

rw = qMax(rw, rect.width());
rw = std::max(rw, rect.width());
if (visual_h_reversed)
rect.moveLeft(geometry.left() + geometry.right() - rect.x() - rect.width() + 1);
setItemGeometry(info.item, rect, mAnimate);
Expand Down Expand Up @@ -750,18 +752,18 @@ void LXQtPanelLayout::setGeometryHoriz(const QRect &geometry)
{
int height = bh + (0 < remain-- ? 1 : 0);
if (!info.item->expandingDirections().testFlag(Qt::Orientation::Vertical))
height = qMin(info.geometry.height(), height);
height = qMin(geometry.height(), height);
height = std::min(info.geometry.height(), height);
height = std::min(geometry.height(), height);
rect.setHeight(height);
rect.setWidth(qMin(info.geometry.width(), geometry.width()));
rect.setWidth(std::min(info.geometry.width(), geometry.width()));
if (height < bh)
rect.moveCenter(QPoint(0, baseLines[c] + base_center));
else
rect.moveTop(baseLines[c]);
rect.moveRight(right);
}

rw = qMax(rw, rect.width());
rw = std::max(rw, rect.width());
if (visual_h_reversed)
rect.moveLeft(geometry.left() + geometry.right() - rect.x() - rect.width() + 1);
setItemGeometry(info.item, rect, mAnimate);
Expand All @@ -788,7 +790,7 @@ void LXQtPanelLayout::setGeometryVert(const QRect &geometry)
}

// Calc baselines for plugins like button.
QList<int> baseLines(qMax(mLeftGrid->colCount(), mRightGrid->colCount()));
QList<int> baseLines(std::max(mLeftGrid->colCount(), mRightGrid->colCount()));
const int bw = geometry.width() / baseLines.count();
const int base_center = bw >> 1;
const int width_remain = 0 < bw ? geometry.width() % baseLines.size() : 0;
Expand Down Expand Up @@ -838,11 +840,11 @@ void LXQtPanelLayout::setGeometryVert(const QRect &geometry)
}
else
{
rect.setHeight(qMin(info.geometry.height(), geometry.height()));
rect.setHeight(std::min(info.geometry.height(), geometry.height()));
int width = bw + (0 < remain-- ? 1 : 0);
if (!info.item->expandingDirections().testFlag(Qt::Orientation::Horizontal))
width = qMin(info.geometry.width(), width);
width = qMin(geometry.width(), width);
width = std::min(info.geometry.width(), width);
width = std::min(geometry.width(), width);
rect.setWidth(width);
if (width < bw)
rect.moveCenter(QPoint(baseLines[c] + base_center, 0));
Expand All @@ -851,7 +853,7 @@ void LXQtPanelLayout::setGeometryVert(const QRect &geometry)
rect.moveTop(top);
}

rh = qMax(rh, rect.height());
rh = std::max(rh, rect.height());
if (visual_h_reversed)
rect.moveLeft(geometry.left() + geometry.right() - rect.x() - rect.width() + 1);
setItemGeometry(info.item, rect, mAnimate);
Expand Down Expand Up @@ -886,11 +888,11 @@ void LXQtPanelLayout::setGeometryVert(const QRect &geometry)
}
else
{
rect.setHeight(qMin(info.geometry.height(), geometry.height()));
rect.setHeight(std::min(info.geometry.height(), geometry.height()));
int width = bw + (0 < remain-- ? 1 : 0);
if (!info.item->expandingDirections().testFlag(Qt::Orientation::Horizontal))
width = qMin(info.geometry.width(), width);
width = qMin(geometry.width(), width);
width = std::min(info.geometry.width(), width);
width = std::min(geometry.width(), width);
rect.setWidth(width);
if (width < bw)
rect.moveCenter(QPoint(baseLines[c] + base_center, 0));
Expand All @@ -899,7 +901,7 @@ void LXQtPanelLayout::setGeometryVert(const QRect &geometry)
rect.moveBottom(bottom);
}

rh = qMax(rh, rect.height());
rh = std::max(rh, rect.height());
if (visual_h_reversed)
rect.moveLeft(geometry.left() + geometry.right() - rect.x() - rect.width() + 1);
setItemGeometry(info.item, rect, mAnimate);
Expand Down
10 changes: 6 additions & 4 deletions plugin-backlight/sliderdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <QDebug>
#include "sliderdialog.h"

#include <cmath>
#include <algorithm>

SliderDialog::SliderDialog(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::Popup | Qt::X11BypassWindowManagerHint)
{
Expand All @@ -56,7 +58,7 @@ SliderDialog::SliderDialog(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::W

if(m_backlight->isBacklightAvailable() || m_backlight->isBacklightOff()) {
// Set the minimum to 5% of the maximum to prevent a black screen
int minBacklight = qMax(qRound((qreal)(m_backlight->getMaxBacklight())*0.05), 1);
int minBacklight = std::max(std::round((qreal)(m_backlight->getMaxBacklight())*0.05), 1.0);
int maxBacklight = m_backlight->getMaxBacklight();
int interval = maxBacklight - minBacklight;
if(interval <= 100) {
Expand All @@ -75,7 +77,7 @@ SliderDialog::SliderDialog(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::W
m_upButton->setEnabled(false);
m_downButton->setEnabled(false);
}

connect(m_slider, &QSlider::valueChanged, this, &SliderDialog::sliderValueChanged);
connect(m_upButton, &QToolButton::clicked, this, &SliderDialog::upButtonClicked);
connect(m_downButton, &QToolButton::clicked, this, &SliderDialog::downButtonClicked);
Expand All @@ -85,7 +87,7 @@ SliderDialog::SliderDialog(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::W
void SliderDialog::sliderValueChanged(int value)
{
// Set the minimum to 5% of the maximum to prevent a black screen
int minBacklight = qMax(qRound((qreal)(m_backlight->getMaxBacklight())*0.05), 1);
int minBacklight = std::max(std::round((qreal)(m_backlight->getMaxBacklight())*0.05), 1.0);
int maxBacklight = m_backlight->getMaxBacklight();
int interval = maxBacklight - minBacklight;
if(interval > 100)
Expand All @@ -97,7 +99,7 @@ void SliderDialog::sliderValueChanged(int value)
void SliderDialog::updateBacklight()
{
// Set the minimum to 5% of the maximum to prevent a black screen
int minBacklight = qMax(qRound((qreal)(m_backlight->getMaxBacklight())*0.05), 1);
int minBacklight = std::max(std::round((qreal)(m_backlight->getMaxBacklight())*0.05), 1.0);
int maxBacklight = m_backlight->getMaxBacklight();
int interval = maxBacklight - minBacklight;
if(interval <= 100)
Expand Down
6 changes: 4 additions & 2 deletions plugin-customcommand/custombutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <QStyleOptionToolButton>
#include <QProxyStyle>

#include <algorithm>

class LeftAlignedTextStyle : public QProxyStyle
{
using QProxyStyle::QProxyStyle;
Expand Down Expand Up @@ -77,7 +79,7 @@ CustomButton::~CustomButton() = default;
void CustomButton::wheelEvent(QWheelEvent *event)
{
QPoint anglePoint = event->angleDelta();
bool horizontal(qAbs(event->angleDelta().x()) > qAbs(anglePoint.y()));
bool horizontal(std::abs(event->angleDelta().x()) > std::abs(anglePoint.y()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs cmath.

int delta = horizontal ? anglePoint.x() : anglePoint.y();
emit wheelScrolled(delta);
event->accept();
Expand All @@ -91,7 +93,7 @@ void CustomButton::setMaxWidth(int maxWidth)

void CustomButton::updateWidth()
{
int newWidth = qMin(sizeHint().width(), mMaxWidth);
int newWidth = std::min(sizeHint().width(), mMaxWidth);
if (mOrigin == Qt::TopLeftCorner) {
setFixedWidth(newWidth);

Expand Down
4 changes: 3 additions & 1 deletion plugin-customcommand/lxqtcustomcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <LXQt/Globals>
#include <QDebug>

#include <algorithm>

LXQtCustomCommand::LXQtCustomCommand(const ILXQtPanelPluginStartupInfo &startupInfo):
QObject(),
ILXQtPanelPlugin(startupInfo),
Expand Down Expand Up @@ -116,7 +118,7 @@ void LXQtCustomCommand::settingsChanged()
mOutputImage = settings()->value(QStringLiteral("outputImage"), false).toBool();
mRepeat = settings()->value(QStringLiteral("repeat"), true).toBool();
mRepeatTimer = settings()->value(QStringLiteral("repeatTimer"), 5).toInt();
mRepeatTimer = qMax(1, mRepeatTimer);
mRepeatTimer = std::max(1, mRepeatTimer);
mIcon = settings()->value(QStringLiteral("icon"), QString()).toString();
mText = settings()->value(QStringLiteral("text"), QStringLiteral("%1")).toString();
mTooltip = settings()->value(QStringLiteral("tooltip"), QString()).toString();
Expand Down
5 changes: 3 additions & 2 deletions plugin-desktopswitch/desktopswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "../panel/backends/ilxqtabstractwmiface.h"

#include <cmath>
#include <algorithm>

#include "desktopswitch.h"
#include "desktopswitchbutton.h"
Expand Down Expand Up @@ -160,7 +161,7 @@ void DesktopSwitch::refresh()
int i = 0;
const int current_desktop = mBackend->getCurrentWorkspace();
const int current_cnt = btns.count();
const int border = qMin(btns.count(), m_desktopCount);
const int border = std::min(btns.count(), (qsizetype) m_desktopCount);
//update existing buttons
for ( ; i < border; ++i)
{
Expand Down Expand Up @@ -301,7 +302,7 @@ void DesktopSwitchWidget::wheelEvent(QWheelEvent *e)
{
// Without some sort of threshold which has to be passed, scrolling is too sensitive
QPoint angleDelta = e->angleDelta();
Qt::Orientation orient = (qAbs(angleDelta.x()) > qAbs(angleDelta.y()) ? Qt::Horizontal : Qt::Vertical);
Qt::Orientation orient = (std::abs(angleDelta.x()) > std::abs(angleDelta.y()) ? Qt::Horizontal : Qt::Vertical);
int rotationSteps = (orient == Qt::Horizontal ? angleDelta.x() : angleDelta.y());

m_mouseWheelThresholdCounter -= rotationSteps;
Expand Down
Loading