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

Last change on this file since 7538 was 7538, checked in by kbut, 13 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-2016, Teo Mrnjavac <teo@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef PARTITIONSPLITTERWIDGET_H
20#define PARTITIONSPLITTERWIDGET_H
21
22#include <QWidget>
23
24#include <functional>
25
26class Device;
27
28struct PartitionSplitterItem
29{
30    enum Status
31    {
32        Normal = 0,
33        Resizing,
34        ResizingNext
35    };
36
37    QString itemPath;
38    QColor color;
39    bool isFreeSpace;
40    qint64 size;
41    Status status;
42
43    using ChildVector = QVector< PartitionSplitterItem >;
44    ChildVector children;
45
46    static PartitionSplitterItem null() { return { QString(), QColor(), false, 0, Normal, ChildVector() }; }
47
48    bool isNull() const { return itemPath.isEmpty() && size == 0 && status == Normal; }
49    operator bool() const { return !isNull(); }
50};
51
52class PartitionSplitterWidget : public QWidget
53{
54    Q_OBJECT
55public:
56    explicit PartitionSplitterWidget( QWidget* parent = nullptr );
57
58    void init( Device* dev, bool drawNestedPartitions );
59
60    void setSplitPartition( const QString& path,
61                            qint64 minSize,
62                            qint64 maxSize,
63                            qint64 preferredSize );
64
65    qint64 splitPartitionSize() const;
66    qint64 newPartitionSize() const;
67
68    QSize sizeHint() const override;
69    QSize minimumSizeHint() const override;
70
71signals:
72    void partitionResized( const QString&, qint64, qint64 );
73
74protected:
75    void paintEvent( QPaintEvent* event ) override;
76    void mousePressEvent( QMouseEvent* event ) override;
77    void mouseMoveEvent( QMouseEvent* event ) override;
78    void mouseReleaseEvent( QMouseEvent* event ) override;
79
80private:
81    void setupItems( const QVector< PartitionSplitterItem >& items );
82
83    void drawPartitions( QPainter* painter,
84                         const QRect& rect,
85                         const QVector< PartitionSplitterItem >& itemList );
86    void drawSection( QPainter* painter, const QRect& rect_, int x, int width,
87                      const PartitionSplitterItem& item );
88    void drawResizeHandle( QPainter* painter,
89                           const QRect& rect_,
90                           int x );
91
92    PartitionSplitterItem _findItem( QVector< PartitionSplitterItem >& items,
93                                     std::function< bool ( PartitionSplitterItem& ) > condition ) const;
94
95    int _eachItem( QVector< PartitionSplitterItem >& items,
96                   std::function< bool ( PartitionSplitterItem& ) > operation ) const;
97
98    QPair< QVector< PartitionSplitterItem >, qreal >
99    computeItemsVector( const QVector< PartitionSplitterItem >& originalItems ) const;
100
101    QVector< PartitionSplitterItem > m_items;
102    QString m_itemToResizePath;
103    PartitionSplitterItem m_itemToResize;
104    PartitionSplitterItem m_itemToResizeNext;
105
106    qint64 m_itemMinSize;
107    qint64 m_itemMaxSize;
108    qint64 m_itemPrefSize;
109    bool m_resizing;
110    int m_resizeHandleX;
111
112    const int HANDLE_SNAP;
113
114    bool m_drawNestedPartitions;
115};
116
117#endif // PARTITIONSPLITTERWIDGET_H
Note: See TracBrowser for help on using the repository browser.