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

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

sync with github

File size: 3.5 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
21#ifndef PARTITIONLABELSVIEW_H
22#define PARTITIONLABELSVIEW_H
23
24#include "PartitionViewSelectionFilter.h"
25
26#include <QAbstractItemView>
27
28/**
29 * A Qt model view which displays colored labels for partitions.
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 PartitionLabelsView : public QAbstractItemView
36{
37    Q_OBJECT
38public:
39    explicit PartitionLabelsView( QWidget* parent = nullptr );
40    virtual ~PartitionLabelsView() override;
41
42    QSize minimumSizeHint() const override;
43
44    QSize sizeHint() const override;
45
46    void paintEvent( QPaintEvent* event ) override;
47
48    // QAbstractItemView API
49    QModelIndex indexAt( const QPoint& point ) const override;
50    QRect visualRect( const QModelIndex& idx ) const override;
51    void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) override;
52
53    void setCustomNewRootLabel( const QString& text );
54
55    void setSelectionModel( QItemSelectionModel* selectionModel ) override;
56
57    void setSelectionFilter( SelectionFilter canBeSelected );
58
59    void setExtendedPartitionHidden( bool hidden );
60
61protected:
62    // QAbstractItemView API
63    QRegion visualRegionForSelection( const QItemSelection& selection ) const override;
64    int horizontalOffset() const override;
65    int verticalOffset() const override;
66    bool isIndexHidden( const QModelIndex& index ) const override;
67    QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) override;
68    void setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags flags ) override;
69
70    void mouseMoveEvent( QMouseEvent* event ) override;
71    void leaveEvent( QEvent* event ) override;
72    void mousePressEvent( QMouseEvent* event ) override;
73
74protected slots:
75    void updateGeometries() override;
76
77private:
78    QRect labelsRect() const;
79    void drawLabels( QPainter* painter, const QRect& rect, const QModelIndex& parent );
80    QSize sizeForAllLabels( int maxLineWidth ) const;
81    QSize sizeForLabel( const QStringList& text ) const;
82    void drawLabel( QPainter* painter, const QStringList& text, const QColor& color,
83                    const QPoint& pos , bool selected );
84    QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const;
85    QStringList buildTexts( const QModelIndex& index ) const;
86
87    SelectionFilter m_canBeSelected;
88    bool m_extendedPartitionHidden;
89
90    QString m_customNewRootLabel;
91    QPersistentModelIndex m_hoveredIndex;
92};
93
94#endif // PARTITIONLABELSVIEW_H
Note: See TracBrowser for help on using the repository browser.