2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-07-29 13:37:32 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2016-01-13 15:15:26 +01:00
|
|
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
2017-09-19 11:11:46 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2014-07-29 13:37:32 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef PARTITIONPREVIEW_H
|
|
|
|
#define PARTITIONPREVIEW_H
|
|
|
|
|
2016-01-15 16:55:23 +01:00
|
|
|
#include "PartitionViewSelectionFilter.h"
|
|
|
|
|
2014-07-29 13:37:32 +02:00
|
|
|
#include <QAbstractItemView>
|
|
|
|
|
2016-01-15 16:55:23 +01:00
|
|
|
|
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.
|
|
|
|
*/
|
2015-12-03 17:19:02 +01:00
|
|
|
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:
|
2016-02-10 14:57:44 +01:00
|
|
|
enum NestedPartitionsMode
|
|
|
|
{
|
|
|
|
NoNestedPartitions = 0,
|
|
|
|
DrawNestedPartitions
|
|
|
|
};
|
|
|
|
|
2015-12-03 17:19:02 +01:00
|
|
|
explicit PartitionBarsView( QWidget* parent = nullptr );
|
2017-09-14 13:02:24 +02:00
|
|
|
virtual ~PartitionBarsView() override;
|
2014-07-29 13:37:32 +02:00
|
|
|
|
2016-02-10 14:57:44 +01: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;
|
|
|
|
|
2016-01-15 16:55:23 +01:00
|
|
|
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;
|
|
|
|
|
2015-12-04 18:02:19 +01:00
|
|
|
void mouseMoveEvent( QMouseEvent* event ) override;
|
|
|
|
void leaveEvent( QEvent* event ) override;
|
2016-01-15 18:35:19 +01:00
|
|
|
void mousePressEvent( QMouseEvent* event ) override;
|
2015-12-04 18:02:19 +01:00
|
|
|
|
2015-04-23 18:00:56 +02:00
|
|
|
protected slots:
|
|
|
|
void updateGeometries() override;
|
|
|
|
|
2014-07-29 13:37:32 +02:00
|
|
|
private:
|
|
|
|
void drawPartitions( QPainter* painter, const QRect& rect, const QModelIndex& parent );
|
2015-12-04 18:02:19 +01:00
|
|
|
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;
|
2015-12-04 18:02:19 +01:00
|
|
|
|
2016-02-10 14:57:44 +01:00
|
|
|
NestedPartitionsMode m_nestedPartitionsMode;
|
|
|
|
|
2016-01-15 16:55:23 +01:00
|
|
|
SelectionFilter canBeSelected;
|
|
|
|
|
2015-12-04 18:02:19 +01:00
|
|
|
struct Item
|
|
|
|
{
|
|
|
|
qreal size;
|
|
|
|
QModelIndex index;
|
|
|
|
};
|
|
|
|
inline QPair< QVector< Item >, qreal > computeItemsVector( const QModelIndex& parent ) const;
|
2015-12-10 18:05:07 +01:00
|
|
|
QPersistentModelIndex m_hoveredIndex;
|
2014-07-29 13:37:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PARTITIONPREVIEW_H */
|