source: calamares/trunk/fuentes/src/modules/partition/gui/PartitionBarsView.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 16 months ago

sync with github

File size: 3.6 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Aurélien Gâteau <agateau@kde.org>
4 *   Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
5 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
6 *
7 *   Calamares is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   Calamares is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
19 */
20#ifndef PARTITIONPREVIEW_H
21#define PARTITIONPREVIEW_H
22
23#include "PartitionViewSelectionFilter.h"
24
25#include <QAbstractItemView>
26
27
28/**
29 * A Qt model view which displays the partitions inside a device as a colored bar.
30 *
31 * It has been created to be used with a PartitionModel instance, but does not
32 * call any PartitionModel-specific methods: it should be usable with other
33 * models as long as they provide the same roles PartitionModel provides.
34 */
35class PartitionBarsView : public QAbstractItemView
36{
37    Q_OBJECT
38public:
39    enum NestedPartitionsMode
40    {
41        NoNestedPartitions = 0,
42        DrawNestedPartitions
43    };
44
45    explicit PartitionBarsView( QWidget* parent = nullptr );
46    virtual ~PartitionBarsView() override;
47
48    void setNestedPartitionsMode( NestedPartitionsMode mode );
49
50    QSize minimumSizeHint() const override;
51
52    QSize sizeHint() const override;
53
54    void paintEvent( QPaintEvent* event ) override;
55
56    // QAbstractItemView API
57    QModelIndex indexAt( const QPoint& point ) const override;
58    QRect visualRect( const QModelIndex& index ) const override;
59    void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) override;
60
61    void setSelectionModel( QItemSelectionModel* selectionModel ) override;
62
63    void setSelectionFilter( SelectionFilter canBeSelected );
64
65protected:
66    // QAbstractItemView API
67    QRegion visualRegionForSelection( const QItemSelection& selection ) const override;
68    int horizontalOffset() const override;
69    int verticalOffset() const override;
70    bool isIndexHidden( const QModelIndex& index ) const override;
71    QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) override;
72    void setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags flags ) override;
73
74    void mouseMoveEvent( QMouseEvent* event ) override;
75    void leaveEvent( QEvent* event ) override;
76    void mousePressEvent( QMouseEvent* event ) override;
77
78protected slots:
79    void updateGeometries() override;
80
81private:
82    void drawPartitions( QPainter* painter, const QRect& rect, const QModelIndex& parent );
83    void drawSection( QPainter* painter, const QRect& rect_, int x, int width, const QModelIndex& index );
84    QModelIndex indexAt( const QPoint& point, const QRect& rect, const QModelIndex& parent ) const;
85    QRect visualRect( const QModelIndex& index, const QRect& rect, const QModelIndex& parent ) const;
86
87    NestedPartitionsMode m_nestedPartitionsMode;
88
89    SelectionFilter canBeSelected;
90
91    struct Item
92    {
93        qreal size;
94        QModelIndex index;
95    };
96    inline QPair< QVector< Item >, qreal > computeItemsVector( const QModelIndex& parent ) const;
97    QPersistentModelIndex m_hoveredIndex;
98};
99
100#endif /* PARTITIONPREVIEW_H */
Note: See TracBrowser for help on using the repository browser.