2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2015-12-03 19:38:56 +01:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2015-12-03 19:38:56 +01:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2015-12-03 19:38:56 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PARTITIONLABELSVIEW_H
|
|
|
|
#define PARTITIONLABELSVIEW_H
|
|
|
|
|
2016-01-15 16:55:23 +01:00
|
|
|
#include "PartitionViewSelectionFilter.h"
|
|
|
|
|
2015-12-03 19:38:56 +01:00
|
|
|
#include <QAbstractItemView>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Qt model view which displays colored labels for partitions.
|
|
|
|
*
|
|
|
|
* It has been created to be used with a PartitionModel instance, but does not
|
|
|
|
* call any PartitionModel-specific methods: it should be usable with other
|
|
|
|
* models as long as they provide the same roles PartitionModel provides.
|
|
|
|
*/
|
|
|
|
class PartitionLabelsView : public QAbstractItemView
|
|
|
|
{
|
2015-12-17 13:44:41 +01:00
|
|
|
Q_OBJECT
|
2015-12-03 19:38:56 +01:00
|
|
|
public:
|
|
|
|
explicit PartitionLabelsView( QWidget* parent = nullptr );
|
2017-09-14 13:02:24 +02:00
|
|
|
virtual ~PartitionLabelsView() override;
|
2015-12-03 19:38:56 +01:00
|
|
|
|
|
|
|
QSize minimumSizeHint() const override;
|
|
|
|
|
|
|
|
QSize sizeHint() const override;
|
|
|
|
|
|
|
|
void paintEvent( QPaintEvent* event ) override;
|
|
|
|
|
|
|
|
// QAbstractItemView API
|
|
|
|
QModelIndex indexAt( const QPoint& point ) const override;
|
2015-12-16 18:22:36 +01:00
|
|
|
QRect visualRect( const QModelIndex& idx ) const override;
|
2015-12-03 19:38:56 +01:00
|
|
|
void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) override;
|
|
|
|
|
2015-12-16 11:13:03 +01:00
|
|
|
void setCustomNewRootLabel( const QString& text );
|
2015-12-03 19:38:56 +01:00
|
|
|
|
2016-01-13 14:50:08 +01:00
|
|
|
void setSelectionModel( QItemSelectionModel* selectionModel ) override;
|
|
|
|
|
2016-01-15 16:55:23 +01:00
|
|
|
void setSelectionFilter( SelectionFilter canBeSelected );
|
|
|
|
|
2016-02-11 16:00:07 +01:00
|
|
|
void setExtendedPartitionHidden( bool hidden );
|
|
|
|
|
2015-12-03 19:38:56 +01:00
|
|
|
protected:
|
|
|
|
// QAbstractItemView API
|
|
|
|
QRegion visualRegionForSelection( const QItemSelection& selection ) const override;
|
|
|
|
int horizontalOffset() const override;
|
|
|
|
int verticalOffset() const override;
|
|
|
|
bool isIndexHidden( const QModelIndex& index ) const override;
|
|
|
|
QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) override;
|
|
|
|
void setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags flags ) override;
|
|
|
|
|
2015-12-16 18:22:36 +01:00
|
|
|
void mouseMoveEvent( QMouseEvent* event ) override;
|
|
|
|
void leaveEvent( QEvent* event ) override;
|
2016-01-15 18:31:57 +01:00
|
|
|
void mousePressEvent( QMouseEvent* event ) override;
|
2015-12-16 18:22:36 +01:00
|
|
|
|
2015-12-03 19:38:56 +01:00
|
|
|
protected slots:
|
|
|
|
void updateGeometries() override;
|
|
|
|
|
|
|
|
private:
|
2015-12-16 18:22:36 +01:00
|
|
|
QRect labelsRect() const;
|
2015-12-03 19:38:56 +01:00
|
|
|
void drawLabels( QPainter* painter, const QRect& rect, const QModelIndex& parent );
|
|
|
|
QSize sizeForAllLabels( int maxLineWidth ) const;
|
|
|
|
QSize sizeForLabel( const QStringList& text ) const;
|
2020-08-22 01:19:58 +02:00
|
|
|
void drawLabel( QPainter* painter, const QStringList& text, const QColor& color, const QPoint& pos, bool selected );
|
2015-12-03 19:38:56 +01:00
|
|
|
QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const;
|
2015-12-15 16:56:10 +01:00
|
|
|
QStringList buildTexts( const QModelIndex& index ) const;
|
2016-01-15 16:55:23 +01:00
|
|
|
|
2017-09-10 21:17:33 +02:00
|
|
|
SelectionFilter m_canBeSelected;
|
2016-02-11 16:00:07 +01:00
|
|
|
bool m_extendedPartitionHidden;
|
2016-01-15 16:55:23 +01:00
|
|
|
|
2015-12-16 11:13:03 +01:00
|
|
|
QString m_customNewRootLabel;
|
2015-12-16 18:22:36 +01:00
|
|
|
QPersistentModelIndex m_hoveredIndex;
|
2015-12-03 19:38:56 +01:00
|
|
|
};
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
#endif // PARTITIONLABELSVIEW_H
|