Rename FRAME_MARGIN to FRAME_MARGIN_PX to avoid clash with winapi constant

And move to constexpr
This commit is contained in:
Nyall Dawson 2025-07-21 11:17:26 +10:00 committed by github-actions[bot]
parent 56297a13ea
commit 8e1209a576
2 changed files with 14 additions and 14 deletions

View File

@ -26,14 +26,6 @@
#endif
#include <QMouseEvent>
#define MARKER_WIDTH 11
#define MARKER_HEIGHT 14
#define MARKER_GAP 1.5
#define MARGIN_BOTTOM ( MARKER_HEIGHT + 2 )
#define MARGIN_X ( MARKER_WIDTH / 2 )
#define FRAME_MARGIN 2
#define CLICK_THRESHOLD ( MARKER_WIDTH / 2 + 3 )
QgsGradientStopEditor::QgsGradientStopEditor( QWidget *parent, QgsGradientColorRamp *ramp )
: QWidget( parent )
{
@ -106,7 +98,7 @@ void QgsGradientStopEditor::paintEvent( QPaintEvent *event )
painter.setBrush( checkBrush );
painter.setPen( Qt::NoPen );
QRect box( frameRect.x() + FRAME_MARGIN, frameRect.y() + FRAME_MARGIN, frameRect.width() - 2 * FRAME_MARGIN, frameRect.height() - 2 * FRAME_MARGIN );
QRect box( frameRect.x() + FRAME_MARGIN_PX, frameRect.y() + FRAME_MARGIN_PX, frameRect.width() - 2 * FRAME_MARGIN_PX, frameRect.height() - 2 * FRAME_MARGIN_PX );
painter.drawRect( box );
@ -395,7 +387,7 @@ void QgsGradientStopEditor::keyPressEvent( QKeyEvent *e )
if ( selectedStopIsMovable() )
{
// calculate offset corresponding to 1 px
double offsetDiff = pointToRelativePosition( rect().x() + MARGIN_X + FRAME_MARGIN + 2 ) - pointToRelativePosition( rect().x() + MARGIN_X + FRAME_MARGIN + 1 );
double offsetDiff = pointToRelativePosition( rect().x() + MARGIN_X + FRAME_MARGIN_PX + 2 ) - pointToRelativePosition( rect().x() + MARGIN_X + FRAME_MARGIN_PX + 1 );
if ( e->modifiers() & Qt::ShiftModifier )
offsetDiff *= 10.0;
@ -447,8 +439,8 @@ void QgsGradientStopEditor::drawStopMarker( QPainter &painter, QPoint topMiddle,
double QgsGradientStopEditor::pointToRelativePosition( int x ) const
{
int left = rect().x() + MARGIN_X + FRAME_MARGIN;
int right = left + rect().width() - 2 * MARGIN_X - 2 * FRAME_MARGIN;
int left = rect().x() + MARGIN_X + FRAME_MARGIN_PX;
int right = left + rect().width() - 2 * MARGIN_X - 2 * FRAME_MARGIN_PX;
if ( x <= left )
return 0;
@ -460,8 +452,8 @@ double QgsGradientStopEditor::pointToRelativePosition( int x ) const
int QgsGradientStopEditor::relativePositionToPoint( double position ) const
{
int left = rect().x() + MARGIN_X + FRAME_MARGIN;
int right = left + rect().width() - 2 * MARGIN_X - 2 * FRAME_MARGIN;
int left = rect().x() + MARGIN_X + FRAME_MARGIN_PX;
int right = left + rect().width() - 2 * MARGIN_X - 2 * FRAME_MARGIN_PX;
if ( position <= 0 )
return left;

View File

@ -200,6 +200,14 @@ class GUI_EXPORT QgsGradientStopEditor : public QWidget
//! Polygon for stop triangle marker inner
QPolygonF sInnerTriangle;
static constexpr int FRAME_MARGIN_PX = 2;
static constexpr int MARKER_WIDTH = 11;
static constexpr int MARKER_HEIGHT = 14;
static constexpr double MARKER_GAP = 1.5;
static constexpr int MARGIN_BOTTOM = MARKER_HEIGHT + 2;
static constexpr int MARGIN_X = MARKER_WIDTH / 2;
static constexpr int CLICK_THRESHOLD = MARKER_WIDTH / 2 + 3;
};
#endif // QGSGRADIENTSTOPEDITOR_H