2014-10-06 18:30:23 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2016-01-11 17:30:33 +01:00
|
|
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
2014-10-06 18:30:23 +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 PARTITIONSPLITTERWIDGET_H
|
|
|
|
#define PARTITIONSPLITTERWIDGET_H
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
2016-02-23 10:36:30 +01:00
|
|
|
#include <functional>
|
|
|
|
|
2016-01-11 15:10:50 +01:00
|
|
|
class Device;
|
2014-10-06 20:02:53 +02:00
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
struct PartitionSplitterItem
|
|
|
|
{
|
2016-02-23 10:36:30 +01:00
|
|
|
enum Status
|
|
|
|
{
|
|
|
|
Normal = 0,
|
|
|
|
Resizing,
|
|
|
|
ResizingNext
|
|
|
|
};
|
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
QString itemPath;
|
|
|
|
QColor color;
|
|
|
|
bool isFreeSpace;
|
|
|
|
qint64 size;
|
2016-02-23 10:36:30 +01:00
|
|
|
Status status;
|
2014-10-06 18:30:23 +02:00
|
|
|
|
2016-02-17 16:46:51 +01:00
|
|
|
QVector< PartitionSplitterItem > children;
|
2016-02-22 18:51:44 +01:00
|
|
|
|
2016-02-23 10:36:30 +01:00
|
|
|
static PartitionSplitterItem null() { return { QString(), QColor(), false, 0, Normal }; }
|
2016-02-22 18:51:44 +01:00
|
|
|
|
2016-02-26 13:13:01 +01:00
|
|
|
bool isNull() const { return itemPath.isEmpty() && size == 0 && status == Normal; }
|
2016-02-22 18:51:44 +01:00
|
|
|
operator bool() const { return !isNull(); }
|
2014-10-06 18:30:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class PartitionSplitterWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PartitionSplitterWidget( QWidget* parent = nullptr );
|
|
|
|
|
2016-02-10 17:02:10 +01:00
|
|
|
void init( Device* dev, bool drawNestedPartitions );
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
void setSplitPartition( const QString& path,
|
|
|
|
qint64 minSize,
|
|
|
|
qint64 maxSize,
|
|
|
|
qint64 preferredSize,
|
|
|
|
const QString& newLabel );
|
|
|
|
|
|
|
|
qint64 splitPartitionSize() const;
|
|
|
|
qint64 newPartitionSize() const;
|
|
|
|
|
|
|
|
QSize sizeHint() const override;
|
2016-01-11 15:54:10 +01:00
|
|
|
QSize minimumSizeHint() const override;
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void partitionResized( const QString&, qint64, qint64 );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent( QPaintEvent* event ) override;
|
|
|
|
void mousePressEvent( QMouseEvent* event ) override;
|
|
|
|
void mouseMoveEvent( QMouseEvent* event ) override;
|
|
|
|
void mouseReleaseEvent( QMouseEvent* event ) override;
|
|
|
|
|
|
|
|
private:
|
2016-02-17 16:46:51 +01:00
|
|
|
void setupItems( const QVector< PartitionSplitterItem >& items );
|
2016-01-11 15:10:50 +01:00
|
|
|
|
2014-10-06 18:30:23 +02:00
|
|
|
void drawPartitions( QPainter* painter,
|
|
|
|
const QRect& rect,
|
2016-02-17 16:46:51 +01:00
|
|
|
const QVector< PartitionSplitterItem >& itemList );
|
2014-10-06 18:30:23 +02:00
|
|
|
void drawSection( QPainter* painter, const QRect& rect_, int x, int width,
|
|
|
|
const PartitionSplitterItem& item );
|
|
|
|
void drawResizeHandle( QPainter* painter,
|
|
|
|
const QRect& rect_,
|
|
|
|
int x );
|
|
|
|
|
2016-02-23 10:36:30 +01:00
|
|
|
PartitionSplitterItem _findItem( QVector< PartitionSplitterItem >& items,
|
|
|
|
std::function< bool ( PartitionSplitterItem& ) > condition ) const;
|
|
|
|
|
|
|
|
int _eachItem( QVector< PartitionSplitterItem >& items,
|
|
|
|
std::function< bool ( PartitionSplitterItem& ) > operation ) const;
|
2014-10-06 18:30:23 +02:00
|
|
|
|
2016-02-17 16:46:51 +01:00
|
|
|
QPair< QVector< PartitionSplitterItem >, qreal >
|
|
|
|
computeItemsVector( const QVector< PartitionSplitterItem >& originalItems ) const;
|
2016-02-17 16:24:39 +01:00
|
|
|
|
2016-02-17 16:46:51 +01:00
|
|
|
QVector< PartitionSplitterItem > m_items;
|
2014-10-06 18:30:23 +02:00
|
|
|
QString m_itemToResizePath;
|
2016-02-22 18:51:44 +01:00
|
|
|
PartitionSplitterItem m_itemToResize;
|
|
|
|
PartitionSplitterItem m_itemToResizeNext;
|
2014-10-06 18:30:23 +02:00
|
|
|
|
|
|
|
qint64 m_itemMinSize;
|
|
|
|
qint64 m_itemMaxSize;
|
|
|
|
qint64 m_itemPrefSize;
|
|
|
|
bool m_resizing;
|
|
|
|
int m_resizeHandleX;
|
|
|
|
|
|
|
|
const int HANDLE_SNAP;
|
2016-02-10 17:02:10 +01:00
|
|
|
|
|
|
|
bool m_drawNestedPartitions;
|
2014-10-06 18:30:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PARTITIONSPLITTERWIDGET_H
|