calamares/src/modules/partition/gui/PartitionBarsView.h

92 lines
3.1 KiB
C
Raw Normal View History

/* === This file is part of Calamares - <https://calamares.io> ===
2014-07-29 13:37:32 +02: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
2014-07-29 13:37:32 +02:00
*
* Calamares is Free Software: see the License-Identifier above.
2014-07-29 13:37:32 +02:00
*
*/
#ifndef PARTITIONPREVIEW_H
#define PARTITIONPREVIEW_H
#include "PartitionViewSelectionFilter.h"
2014-07-29 13:37:32 +02:00
#include <QAbstractItemView>
2014-08-08 11:46:43 +02:00
/**
* A Qt model view which displays the partitions inside a device as a colored bar.
*
* 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 PartitionBarsView : public QAbstractItemView
2014-07-29 13:37:32 +02:00
{
2015-12-17 13:44:41 +01:00
Q_OBJECT
2014-07-29 13:37:32 +02:00
public:
enum NestedPartitionsMode
{
NoNestedPartitions = 0,
DrawNestedPartitions
};
explicit PartitionBarsView( QWidget* parent = nullptr );
~PartitionBarsView() override;
2014-07-29 13:37:32 +02:00
void setNestedPartitionsMode( NestedPartitionsMode mode );
2015-04-17 12:40:56 +02:00
QSize minimumSizeHint() const override;
2014-07-29 13:37:32 +02:00
QSize sizeHint() const override;
void paintEvent( QPaintEvent* event ) override;
// QAbstractItemView API
QModelIndex indexAt( const QPoint& point ) const override;
QRect visualRect( const QModelIndex& index ) const override;
void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) override;
2016-01-13 15:15:26 +01:00
void setSelectionModel( QItemSelectionModel* selectionModel ) override;
void setSelectionFilter( SelectionFilter canBeSelected );
2014-07-29 13:37:32 +02: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;
void mouseMoveEvent( QMouseEvent* event ) override;
void leaveEvent( QEvent* event ) override;
2016-01-15 18:35:19 +01:00
void mousePressEvent( QMouseEvent* event ) override;
protected slots:
void updateGeometries() override;
2014-07-29 13:37:32 +02:00
private:
void drawPartitions( QPainter* painter, const QRect& rect, const QModelIndex& parent );
void drawSection( QPainter* painter, const QRect& rect_, int x, int width, const QModelIndex& index );
QModelIndex indexAt( const QPoint& point, const QRect& rect, const QModelIndex& parent ) const;
2015-12-10 16:13:31 +01:00
QRect visualRect( const QModelIndex& index, const QRect& rect, const QModelIndex& parent ) const;
NestedPartitionsMode m_nestedPartitionsMode;
SelectionFilter canBeSelected;
struct Item
{
qreal size;
QModelIndex index;
};
inline QPair< QVector< Item >, qreal > computeItemsVector( const QModelIndex& parent ) const;
QPersistentModelIndex m_hoveredIndex;
2014-07-29 13:37:32 +02:00
};
#endif /* PARTITIONPREVIEW_H */