/*
* SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2022, 2024 Felix Ernst <felixernst@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
void setOffset(qreal offset);
qreal offset() const;
- void setSidePadding(qreal width);
- qreal sidePadding() const;
+ void setSidePadding(qreal leftPaddingWidth, qreal rightPaddingWidth);
+ qreal leftPadding() const;
+ qreal rightPadding() const;
qreal minimumColumnWidth() const;
*/
void columnWidthChanged(const QByteArray &role, qreal currentWidth, qreal previousWidth);
- void sidePaddingChanged(qreal width);
+ void sidePaddingChanged(qreal leftPaddingWidth, qreal rightPaddingWidth);
/**
* Is emitted if the user has released the mouse button after adjusting the
*/
void sortRoleChanged(const QByteArray ¤t, const QByteArray &previous);
- void columnUnHovered(int roleIndex);
- void columnHovered(int roleIndex);
+ void columnUnHovered(int columnIndex);
+ void columnHovered(int columnIndex);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);
private:
- enum PaddingGrip {
- Leading,
- Trailing,
+ struct Grip {
+ QByteArray roleToTheLeft;
+ QByteArray roleToTheRight;
};
void paintRole(QPainter *painter, const QByteArray &role, const QRectF &rect, int orderIndex, QWidget *widget = nullptr) const;
void updatePressedRoleIndex(const QPointF &pos);
- void updateHoveredRoleIndex(const QPointF &pos);
+ void updateHoveredIndex(const QPointF &pos);
int roleIndexAt(const QPointF &pos) const;
- bool isAboveRoleGrip(const QPointF &pos, int roleIndex) const;
- bool isAbovePaddingGrip(const QPointF &pos, PaddingGrip paddingGrip) const;
+
+ /**
+ * @returns std::nullopt if none of the resize grips is below @p position.
+ * Otherwise returns a Grip defined by the two roles on each side of @p position.
+ * @note If the Grip is between a padding and a role, a class-specific "leftPadding" or "rightPadding" role is used.
+ */
+ std::optional<const Grip> isAboveResizeGrip(const QPointF &position) const;
/**
* Creates a pixmap of the role with the index \a roleIndex that is shown
*/
qreal roleXPosition(const QByteArray &role) const;
-private:
- enum RoleOperation { NoRoleOperation, ResizeRoleOperation, ResizePaddingColumnOperation, MoveRoleOperation };
+ /**
+ * @returns 0 for left-to-right layoutDirection().
+ * Otherwise returns the space that is left over when space is distributed between padding and role columns.
+ * Used to make the column headers stay above their information columns for right-to-left layout directions.
+ */
+ qreal unusedSpace() const;
+private:
bool m_automaticColumnResizing;
KItemModelBase *m_model;
qreal m_offset;
- qreal m_sidePadding;
+ qreal m_leftPadding;
+ qreal m_rightPadding;
QList<QByteArray> m_columns;
QHash<QByteArray, qreal> m_columnWidths;
QHash<QByteArray, qreal> m_preferredColumnWidths;
- int m_hoveredRoleIndex;
+ int m_hoveredIndex;
+ std::optional<Grip> m_pressedGrip;
int m_pressedRoleIndex;
- RoleOperation m_roleOperation;
QPointF m_pressedMousePos;
struct MovingRole {