[partition] Apply coding style (to just this one file)
This commit is contained in:
parent
25d36a8943
commit
1c598d769b
@ -31,13 +31,14 @@
|
|||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
|
||||||
using CalamaresUtils::Partition::PartitionIterator;
|
using CalamaresUtils::Partition::PartitionIterator;
|
||||||
|
|
||||||
static const int VIEW_HEIGHT = qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts
|
static const int VIEW_HEIGHT
|
||||||
|
= qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts
|
||||||
int( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts
|
int( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts
|
||||||
static const int CORNER_RADIUS = 3;
|
static const int CORNER_RADIUS = 3;
|
||||||
static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 );
|
static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 );
|
||||||
@ -64,37 +65,40 @@ PartitionSplitterWidget::init( Device* dev, bool drawNestedPartitions )
|
|||||||
m_drawNestedPartitions = drawNestedPartitions;
|
m_drawNestedPartitions = drawNestedPartitions;
|
||||||
QVector< PartitionSplitterItem > allPartitionItems;
|
QVector< PartitionSplitterItem > allPartitionItems;
|
||||||
PartitionSplitterItem* extendedPartitionItem = nullptr;
|
PartitionSplitterItem* extendedPartitionItem = nullptr;
|
||||||
for ( auto it = PartitionIterator::begin( dev );
|
for ( auto it = PartitionIterator::begin( dev ); it != PartitionIterator::end( dev ); ++it )
|
||||||
it != PartitionIterator::end( dev ); ++it )
|
|
||||||
{
|
{
|
||||||
PartitionSplitterItem newItem = {
|
PartitionSplitterItem newItem = { ( *it )->partitionPath(),
|
||||||
( *it )->partitionPath(),
|
|
||||||
ColorUtils::colorForPartition( *it ),
|
ColorUtils::colorForPartition( *it ),
|
||||||
CalamaresUtils::Partition::isPartitionFreeSpace( *it ),
|
CalamaresUtils::Partition::isPartitionFreeSpace( *it ),
|
||||||
( *it )->capacity(),
|
( *it )->capacity(),
|
||||||
PartitionSplitterItem::Normal,
|
PartitionSplitterItem::Normal,
|
||||||
{}
|
{} };
|
||||||
};
|
|
||||||
|
|
||||||
// If we don't draw child partitions of a partitions as child partitions, we
|
// If we don't draw child partitions of a partitions as child partitions, we
|
||||||
// need to flatten the items tree into an items list
|
// need to flatten the items tree into an items list
|
||||||
if ( drawNestedPartitions )
|
if ( drawNestedPartitions )
|
||||||
{
|
{
|
||||||
if ( ( *it )->roles().has( PartitionRole::Logical ) && extendedPartitionItem )
|
if ( ( *it )->roles().has( PartitionRole::Logical ) && extendedPartitionItem )
|
||||||
|
{
|
||||||
extendedPartitionItem->children.append( newItem );
|
extendedPartitionItem->children.append( newItem );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
allPartitionItems.append( newItem );
|
allPartitionItems.append( newItem );
|
||||||
if ( ( *it )->roles().has( PartitionRole::Extended ) )
|
if ( ( *it )->roles().has( PartitionRole::Extended ) )
|
||||||
|
{
|
||||||
extendedPartitionItem = &allPartitionItems.last();
|
extendedPartitionItem = &allPartitionItems.last();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( !( *it )->roles().has( PartitionRole::Extended ) )
|
if ( !( *it )->roles().has( PartitionRole::Extended ) )
|
||||||
|
{
|
||||||
allPartitionItems.append( newItem );
|
allPartitionItems.append( newItem );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setupItems( allPartitionItems );
|
setupItems( allPartitionItems );
|
||||||
}
|
}
|
||||||
@ -110,20 +114,17 @@ PartitionSplitterWidget::setupItems( const QVector<PartitionSplitterItem>& items
|
|||||||
m_items = items;
|
m_items = items;
|
||||||
repaint();
|
repaint();
|
||||||
for ( const PartitionSplitterItem& item : items )
|
for ( const PartitionSplitterItem& item : items )
|
||||||
|
{
|
||||||
cDebug() << "PSI added item" << item.itemPath << "size" << item.size;
|
cDebug() << "PSI added item" << item.itemPath << "size" << item.size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSplitterWidget::setSplitPartition( const QString& path,
|
PartitionSplitterWidget::setSplitPartition( const QString& path, qint64 minSize, qint64 maxSize, qint64 preferredSize )
|
||||||
qint64 minSize,
|
|
||||||
qint64 maxSize,
|
|
||||||
qint64 preferredSize )
|
|
||||||
{
|
{
|
||||||
cDebug() << "path:" << path
|
cDebug() << "path:" << path << Logger::Continuation << "minSize:" << minSize << Logger::Continuation
|
||||||
<< Logger::Continuation << "minSize:" << minSize
|
<< "maxSize:" << maxSize << Logger::Continuation << "prfSize:" << preferredSize;
|
||||||
<< Logger::Continuation << "maxSize:" << maxSize
|
|
||||||
<< Logger::Continuation << "prfSize:" << preferredSize;
|
|
||||||
|
|
||||||
if ( m_itemToResize && m_itemToResizeNext )
|
if ( m_itemToResize && m_itemToResizeNext )
|
||||||
{
|
{
|
||||||
@ -132,9 +133,8 @@ PartitionSplitterWidget::setSplitPartition( const QString& path,
|
|||||||
// We need to remove the itemToResizeNext from wherever it is
|
// We need to remove the itemToResizeNext from wherever it is
|
||||||
for ( int i = 0; i < m_items.count(); ++i )
|
for ( int i = 0; i < m_items.count(); ++i )
|
||||||
{
|
{
|
||||||
if ( m_items[ i ].itemPath == m_itemToResize.itemPath &&
|
if ( m_items[ i ].itemPath == m_itemToResize.itemPath
|
||||||
m_items[ i ].status == PartitionSplitterItem::Resizing &&
|
&& m_items[ i ].status == PartitionSplitterItem::Resizing && i + 1 < m_items.count() )
|
||||||
i + 1 < m_items.count() )
|
|
||||||
{
|
{
|
||||||
m_items[ i ].size = m_items[ i ].size + m_itemToResizeNext.size;
|
m_items[ i ].size = m_items[ i ].size + m_itemToResizeNext.size;
|
||||||
m_items[ i ].status = PartitionSplitterItem::Normal;
|
m_items[ i ].status = PartitionSplitterItem::Normal;
|
||||||
@ -146,11 +146,10 @@ PartitionSplitterWidget::setSplitPartition( const QString& path,
|
|||||||
{
|
{
|
||||||
for ( int j = 0; j < m_items[ i ].children.count(); ++j )
|
for ( int j = 0; j < m_items[ i ].children.count(); ++j )
|
||||||
{
|
{
|
||||||
if ( m_items[ i ].children[ j ].itemPath == m_itemToResize.itemPath &&
|
if ( m_items[ i ].children[ j ].itemPath == m_itemToResize.itemPath
|
||||||
j + 1 < m_items[ i ].children.count() )
|
&& j + 1 < m_items[ i ].children.count() )
|
||||||
{
|
{
|
||||||
m_items[ i ].children[ j ].size =
|
m_items[ i ].children[ j ].size = m_items[ i ].children[ j ].size + m_itemToResizeNext.size;
|
||||||
m_items[ i ].children[ j ].size + m_itemToResizeNext.size;
|
|
||||||
m_items[ i ].children[ j ].status = PartitionSplitterItem::Normal;
|
m_items[ i ].children[ j ].status = PartitionSplitterItem::Normal;
|
||||||
m_items[ i ].children.removeAt( j + 1 );
|
m_items[ i ].children.removeAt( j + 1 );
|
||||||
m_itemToResizeNext = PartitionSplitterItem::null();
|
m_itemToResizeNext = PartitionSplitterItem::null();
|
||||||
@ -158,17 +157,17 @@ PartitionSplitterWidget::setSplitPartition( const QString& path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( m_itemToResizeNext.isNull() )
|
if ( m_itemToResizeNext.isNull() )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_itemToResize = PartitionSplitterItem::null();
|
m_itemToResize = PartitionSplitterItem::null();
|
||||||
m_itemToResizePath.clear();
|
m_itemToResizePath.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionSplitterItem itemToResize = _findItem( m_items,
|
PartitionSplitterItem itemToResize = _findItem( m_items, [path]( PartitionSplitterItem& item ) -> bool {
|
||||||
[ path ]( PartitionSplitterItem& item ) -> bool
|
|
||||||
{
|
|
||||||
if ( path == item.itemPath )
|
if ( path == item.itemPath )
|
||||||
{
|
{
|
||||||
item.status = PartitionSplitterItem::Resizing;
|
item.status = PartitionSplitterItem::Resizing;
|
||||||
@ -178,20 +177,22 @@ PartitionSplitterWidget::setSplitPartition( const QString& path,
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
if ( itemToResize.isNull() )
|
if ( itemToResize.isNull() )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
cDebug() << "itemToResize:" << itemToResize.itemPath;
|
cDebug() << "itemToResize:" << itemToResize.itemPath;
|
||||||
|
|
||||||
m_itemToResize = itemToResize;
|
m_itemToResize = itemToResize;
|
||||||
m_itemToResizePath = path;
|
m_itemToResizePath = path;
|
||||||
|
|
||||||
if ( preferredSize > maxSize )
|
if ( preferredSize > maxSize )
|
||||||
|
{
|
||||||
preferredSize = maxSize;
|
preferredSize = maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
qint64 newSize = m_itemToResize.size - preferredSize;
|
qint64 newSize = m_itemToResize.size - preferredSize;
|
||||||
m_itemToResize.size = preferredSize;
|
m_itemToResize.size = preferredSize;
|
||||||
int opCount = _eachItem( m_items,
|
int opCount = _eachItem( m_items, [preferredSize]( PartitionSplitterItem& item ) -> bool {
|
||||||
[ preferredSize ]( PartitionSplitterItem& item ) -> bool
|
|
||||||
{
|
|
||||||
if ( item.status == PartitionSplitterItem::Resizing )
|
if ( item.status == PartitionSplitterItem::Resizing )
|
||||||
{
|
{
|
||||||
item.size = preferredSize;
|
item.size = preferredSize;
|
||||||
@ -209,12 +210,7 @@ PartitionSplitterWidget::setSplitPartition( const QString& path,
|
|||||||
if ( m_items[ i ].itemPath == itemToResize.itemPath )
|
if ( m_items[ i ].itemPath == itemToResize.itemPath )
|
||||||
{
|
{
|
||||||
m_items.insert( i + 1,
|
m_items.insert( i + 1,
|
||||||
{ "",
|
{ "", QColor( "#c0392b" ), false, newSize, PartitionSplitterItem::ResizingNext, {} } );
|
||||||
QColor( "#c0392b" ),
|
|
||||||
false,
|
|
||||||
newSize,
|
|
||||||
PartitionSplitterItem::ResizingNext,
|
|
||||||
{} } );
|
|
||||||
m_itemToResizeNext = m_items[ i + 1 ];
|
m_itemToResizeNext = m_items[ i + 1 ];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -224,29 +220,26 @@ PartitionSplitterWidget::setSplitPartition( const QString& path,
|
|||||||
{
|
{
|
||||||
if ( m_items[ i ].children[ j ].itemPath == itemToResize.itemPath )
|
if ( m_items[ i ].children[ j ].itemPath == itemToResize.itemPath )
|
||||||
{
|
{
|
||||||
m_items[ i ].children.insert( j+1,
|
m_items[ i ].children.insert(
|
||||||
{ "",
|
j + 1, { "", QColor( "#c0392b" ), false, newSize, PartitionSplitterItem::ResizingNext, {} } );
|
||||||
QColor( "#c0392b" ),
|
|
||||||
false,
|
|
||||||
newSize,
|
|
||||||
PartitionSplitterItem::ResizingNext,
|
|
||||||
{} } );
|
|
||||||
m_itemToResizeNext = m_items[ i ].children[ j + 1 ];
|
m_itemToResizeNext = m_items[ i ].children[ j + 1 ];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !m_itemToResizeNext.isNull() )
|
if ( !m_itemToResizeNext.isNull() )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit partitionResized( m_itemToResize.itemPath,
|
emit partitionResized( m_itemToResize.itemPath, m_itemToResize.size, m_itemToResizeNext.size );
|
||||||
m_itemToResize.size,
|
|
||||||
m_itemToResizeNext.size );
|
|
||||||
|
|
||||||
cDebug() << "Items updated. Status:";
|
cDebug() << "Items updated. Status:";
|
||||||
foreach ( const PartitionSplitterItem& item, m_items )
|
foreach ( const PartitionSplitterItem& item, m_items )
|
||||||
|
{
|
||||||
cDebug() << "item" << item.itemPath << "size" << item.size << "status:" << item.status;
|
cDebug() << "item" << item.itemPath << "size" << item.size << "status:" << item.status;
|
||||||
|
}
|
||||||
|
|
||||||
cDebug() << "m_itemToResize: " << !m_itemToResize.isNull() << m_itemToResize.itemPath;
|
cDebug() << "m_itemToResize: " << !m_itemToResize.isNull() << m_itemToResize.itemPath;
|
||||||
cDebug() << "m_itemToResizeNext:" << !m_itemToResizeNext.isNull() << m_itemToResizeNext.itemPath;
|
cDebug() << "m_itemToResizeNext:" << !m_itemToResizeNext.isNull() << m_itemToResizeNext.itemPath;
|
||||||
@ -259,7 +252,9 @@ qint64
|
|||||||
PartitionSplitterWidget::splitPartitionSize() const
|
PartitionSplitterWidget::splitPartitionSize() const
|
||||||
{
|
{
|
||||||
if ( !m_itemToResize )
|
if ( !m_itemToResize )
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return m_itemToResize.size;
|
return m_itemToResize.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +263,9 @@ qint64
|
|||||||
PartitionSplitterWidget::newPartitionSize() const
|
PartitionSplitterWidget::newPartitionSize() const
|
||||||
{
|
{
|
||||||
if ( !m_itemToResizeNext )
|
if ( !m_itemToResizeNext )
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return m_itemToResizeNext.size;
|
return m_itemToResizeNext.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,14 +300,14 @@ PartitionSplitterWidget::paintEvent( QPaintEvent* event )
|
|||||||
void
|
void
|
||||||
PartitionSplitterWidget::mousePressEvent( QMouseEvent* event )
|
PartitionSplitterWidget::mousePressEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
if ( m_itemToResize &&
|
if ( m_itemToResize && m_itemToResizeNext && event->button() == Qt::LeftButton )
|
||||||
m_itemToResizeNext &&
|
|
||||||
event->button() == Qt::LeftButton )
|
|
||||||
{
|
{
|
||||||
if ( qAbs( event->x() - m_resizeHandleX ) < HANDLE_SNAP )
|
if ( qAbs( event->x() - m_resizeHandleX ) < HANDLE_SNAP )
|
||||||
|
{
|
||||||
m_resizing = true;
|
m_resizing = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -320,16 +317,16 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
|
|||||||
{
|
{
|
||||||
qint64 start = 0;
|
qint64 start = 0;
|
||||||
QString itemPath = m_itemToResize.itemPath;
|
QString itemPath = m_itemToResize.itemPath;
|
||||||
for ( auto it = m_items.constBegin();
|
for ( auto it = m_items.constBegin(); it != m_items.constEnd(); ++it )
|
||||||
it != m_items.constEnd(); ++it )
|
|
||||||
{
|
{
|
||||||
if ( it->itemPath == itemPath )
|
if ( it->itemPath == itemPath )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
else if ( !it->children.isEmpty() )
|
else if ( !it->children.isEmpty() )
|
||||||
{
|
{
|
||||||
bool done = false;
|
bool done = false;
|
||||||
for ( auto jt = it->children.constBegin();
|
for ( auto jt = it->children.constBegin(); jt != it->children.constEnd(); ++jt )
|
||||||
jt != it->children.constEnd(); ++jt )
|
|
||||||
{
|
{
|
||||||
if ( jt->itemPath == itemPath )
|
if ( jt->itemPath == itemPath )
|
||||||
{
|
{
|
||||||
@ -339,11 +336,15 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
|
|||||||
start += jt->size;
|
start += jt->size;
|
||||||
}
|
}
|
||||||
if ( done )
|
if ( done )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
start += it->size;
|
start += it->size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qint64 total = 0;
|
qint64 total = 0;
|
||||||
for ( auto it = m_items.constBegin(); it != m_items.constEnd(); ++it )
|
for ( auto it = m_items.constBegin(); it != m_items.constEnd(); ++it )
|
||||||
@ -357,9 +358,7 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
|
|||||||
qreal mx = event->x() * bpp - start;
|
qreal mx = event->x() * bpp - start;
|
||||||
|
|
||||||
// make sure we are within resize range
|
// make sure we are within resize range
|
||||||
mx = qBound( static_cast< qreal >( m_itemMinSize ),
|
mx = qBound( static_cast< qreal >( m_itemMinSize ), mx, static_cast< qreal >( m_itemMaxSize ) );
|
||||||
mx,
|
|
||||||
static_cast< qreal >( m_itemMaxSize ) );
|
|
||||||
|
|
||||||
qint64 span = m_itemPrefSize;
|
qint64 span = m_itemPrefSize;
|
||||||
qreal percent = mx / span;
|
qreal percent = mx / span;
|
||||||
@ -367,9 +366,7 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
|
|||||||
|
|
||||||
m_itemToResize.size = qRound64( span * percent );
|
m_itemToResize.size = qRound64( span * percent );
|
||||||
m_itemToResizeNext.size -= m_itemToResize.size - oldsize;
|
m_itemToResizeNext.size -= m_itemToResize.size - oldsize;
|
||||||
_eachItem( m_items,
|
_eachItem( m_items, [this]( PartitionSplitterItem& item ) -> bool {
|
||||||
[ this ]( PartitionSplitterItem& item ) -> bool
|
|
||||||
{
|
|
||||||
if ( item.status == PartitionSplitterItem::Resizing )
|
if ( item.status == PartitionSplitterItem::Resizing )
|
||||||
{
|
{
|
||||||
item.size = m_itemToResize.size;
|
item.size = m_itemToResize.size;
|
||||||
@ -385,21 +382,23 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event )
|
|||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
|
|
||||||
emit partitionResized( itemPath,
|
emit partitionResized( itemPath, m_itemToResize.size, m_itemToResizeNext.size );
|
||||||
m_itemToResize.size,
|
|
||||||
m_itemToResizeNext.size );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_itemToResize && m_itemToResizeNext )
|
if ( m_itemToResize && m_itemToResizeNext )
|
||||||
{
|
{
|
||||||
if ( qAbs( event->x() - m_resizeHandleX ) < HANDLE_SNAP )
|
if ( qAbs( event->x() - m_resizeHandleX ) < HANDLE_SNAP )
|
||||||
|
{
|
||||||
setCursor( Qt::SplitHCursor );
|
setCursor( Qt::SplitHCursor );
|
||||||
|
}
|
||||||
else if ( cursor().shape() != Qt::ArrowCursor )
|
else if ( cursor().shape() != Qt::ArrowCursor )
|
||||||
|
{
|
||||||
setCursor( Qt::ArrowCursor );
|
setCursor( Qt::ArrowCursor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -412,7 +411,10 @@ PartitionSplitterWidget::mouseReleaseEvent( QMouseEvent* event )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSplitterWidget::drawSection( QPainter* painter, const QRect& rect_, int x, int width,
|
PartitionSplitterWidget::drawSection( QPainter* painter,
|
||||||
|
const QRect& rect_,
|
||||||
|
int x,
|
||||||
|
int width,
|
||||||
const PartitionSplitterItem& item )
|
const PartitionSplitterItem& item )
|
||||||
{
|
{
|
||||||
QColor color = item.color;
|
QColor color = item.color;
|
||||||
@ -433,7 +435,9 @@ PartitionSplitterWidget::drawSection( QPainter* painter, const QRect& rect_, int
|
|||||||
|
|
||||||
// Draw shade
|
// Draw shade
|
||||||
if ( !isFreeSpace )
|
if ( !isFreeSpace )
|
||||||
|
{
|
||||||
rect.adjust( 2, 2, -2, -2 );
|
rect.adjust( 2, 2, -2, -2 );
|
||||||
|
}
|
||||||
|
|
||||||
QLinearGradient gradient( 0, 0, 0, rectHeight / 2 );
|
QLinearGradient gradient( 0, 0, 0, rectHeight / 2 );
|
||||||
|
|
||||||
@ -449,12 +453,12 @@ PartitionSplitterWidget::drawSection( QPainter* painter, const QRect& rect_, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSplitterWidget::drawResizeHandle( QPainter* painter,
|
PartitionSplitterWidget::drawResizeHandle( QPainter* painter, const QRect& rect_, int x )
|
||||||
const QRect& rect_,
|
|
||||||
int x )
|
|
||||||
{
|
{
|
||||||
if ( !m_itemToResize )
|
if ( !m_itemToResize )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
painter->setPen( Qt::NoPen );
|
painter->setPen( Qt::NoPen );
|
||||||
painter->setBrush( Qt::black );
|
painter->setBrush( Qt::black );
|
||||||
@ -464,15 +468,9 @@ PartitionSplitterWidget::drawResizeHandle( QPainter* painter,
|
|||||||
|
|
||||||
qreal h = VIEW_HEIGHT; // Put the arrow in the center regardless of inner box height
|
qreal h = VIEW_HEIGHT; // Put the arrow in the center regardless of inner box height
|
||||||
int scaleFactor = qRound( height() / static_cast< qreal >( VIEW_HEIGHT ) );
|
int scaleFactor = qRound( height() / static_cast< qreal >( VIEW_HEIGHT ) );
|
||||||
QList< QPair< qreal, qreal > > arrow_offsets = {
|
QList< QPair< qreal, qreal > > arrow_offsets
|
||||||
qMakePair( 0, h / 2 - 1 ),
|
= { qMakePair( 0, h / 2 - 1 ), qMakePair( 4, h / 2 - 1 ), qMakePair( 4, h / 2 - 3 ), qMakePair( 8, h / 2 ),
|
||||||
qMakePair( 4, h / 2 - 1 ),
|
qMakePair( 4, h / 2 + 3 ), qMakePair( 4, h / 2 + 1 ), qMakePair( 0, h / 2 + 1 ) };
|
||||||
qMakePair( 4, h / 2 - 3 ),
|
|
||||||
qMakePair( 8, h / 2 ),
|
|
||||||
qMakePair( 4, h / 2 + 3 ),
|
|
||||||
qMakePair( 4, h / 2 + 1 ),
|
|
||||||
qMakePair( 0, h / 2 + 1 )
|
|
||||||
};
|
|
||||||
for ( int i = 0; i < arrow_offsets.count(); ++i )
|
for ( int i = 0; i < arrow_offsets.count(); ++i )
|
||||||
{
|
{
|
||||||
arrow_offsets[ i ] = qMakePair( arrow_offsets[ i ].first * scaleFactor,
|
arrow_offsets[ i ] = qMakePair( arrow_offsets[ i ].first * scaleFactor,
|
||||||
@ -484,7 +482,9 @@ PartitionSplitterWidget::drawResizeHandle( QPainter* painter,
|
|||||||
{
|
{
|
||||||
auto arrow = QPainterPath( QPointF( x + -1 * p1.first, p1.second ) );
|
auto arrow = QPainterPath( QPointF( x + -1 * p1.first, p1.second ) );
|
||||||
for ( auto p : arrow_offsets )
|
for ( auto p : arrow_offsets )
|
||||||
|
{
|
||||||
arrow.lineTo( x + -1 * p.first + 1, p.second );
|
arrow.lineTo( x + -1 * p.first + 1, p.second );
|
||||||
|
}
|
||||||
painter->drawPath( arrow );
|
painter->drawPath( arrow );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +492,9 @@ PartitionSplitterWidget::drawResizeHandle( QPainter* painter,
|
|||||||
{
|
{
|
||||||
auto arrow = QPainterPath( QPointF( x + p1.first, p1.second ) );
|
auto arrow = QPainterPath( QPointF( x + p1.first, p1.second ) );
|
||||||
for ( auto p : arrow_offsets )
|
for ( auto p : arrow_offsets )
|
||||||
|
{
|
||||||
arrow.lineTo( x + p.first, p.second );
|
arrow.lineTo( x + p.first, p.second );
|
||||||
|
}
|
||||||
painter->drawPath( arrow );
|
painter->drawPath( arrow );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,32 +522,30 @@ PartitionSplitterWidget::drawPartitions( QPainter* painter,
|
|||||||
const PartitionSplitterItem& item = items[ row ];
|
const PartitionSplitterItem& item = items[ row ];
|
||||||
qreal width;
|
qreal width;
|
||||||
if ( row < count - 1 )
|
if ( row < count - 1 )
|
||||||
|
{
|
||||||
width = totalWidth * ( item.size / total );
|
width = totalWidth * ( item.size / total );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
// Make sure we fill the last pixel column
|
// Make sure we fill the last pixel column
|
||||||
|
{
|
||||||
width = rect.right() - x + 1;
|
width = rect.right() - x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
drawSection( painter, rect, x, int( width ), item );
|
drawSection( painter, rect, x, int( width ), item );
|
||||||
if ( !item.children.isEmpty() )
|
if ( !item.children.isEmpty() )
|
||||||
{
|
{
|
||||||
QRect subRect(
|
QRect subRect( x + EXTENDED_PARTITION_MARGIN,
|
||||||
x + EXTENDED_PARTITION_MARGIN,
|
|
||||||
rect.y() + EXTENDED_PARTITION_MARGIN,
|
rect.y() + EXTENDED_PARTITION_MARGIN,
|
||||||
int( width ) - 2 * EXTENDED_PARTITION_MARGIN,
|
int( width ) - 2 * EXTENDED_PARTITION_MARGIN,
|
||||||
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
rect.height() - 2 * EXTENDED_PARTITION_MARGIN );
|
||||||
);
|
|
||||||
drawPartitions( painter, subRect, item.children );
|
drawPartitions( painter, subRect, item.children );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an item to resize and the following new item both exist,
|
// If an item to resize and the following new item both exist,
|
||||||
// and this is not the very first partition,
|
// and this is not the very first partition,
|
||||||
// and the partition preceding this one is the item to resize...
|
// and the partition preceding this one is the item to resize...
|
||||||
if ( m_itemToResize &&
|
if ( m_itemToResize && m_itemToResizeNext && row > 0 && !items[ row - 1 ].isFreeSpace
|
||||||
m_itemToResizeNext &&
|
&& !items[ row - 1 ].itemPath.isEmpty() && items[ row - 1 ].itemPath == m_itemToResize.itemPath )
|
||||||
row > 0 &&
|
|
||||||
!items[ row - 1 ].isFreeSpace &&
|
|
||||||
!items[ row - 1 ].itemPath.isEmpty() &&
|
|
||||||
items[ row - 1 ].itemPath == m_itemToResize.itemPath )
|
|
||||||
{
|
{
|
||||||
m_resizeHandleX = x;
|
m_resizeHandleX = x;
|
||||||
drawResizeHandle( painter, rect, m_resizeHandleX );
|
drawResizeHandle( painter, rect, m_resizeHandleX );
|
||||||
@ -563,12 +563,16 @@ PartitionSplitterWidget::_findItem( QVector< PartitionSplitterItem >& items,
|
|||||||
for ( auto it = items.begin(); it != items.end(); ++it )
|
for ( auto it = items.begin(); it != items.end(); ++it )
|
||||||
{
|
{
|
||||||
if ( condition( *it ) )
|
if ( condition( *it ) )
|
||||||
|
{
|
||||||
return *it;
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
PartitionSplitterItem candidate = _findItem( it->children, condition );
|
PartitionSplitterItem candidate = _findItem( it->children, condition );
|
||||||
if ( !candidate.isNull() )
|
if ( !candidate.isNull() )
|
||||||
|
{
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return PartitionSplitterItem::null();
|
return PartitionSplitterItem::null();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,7 +585,9 @@ PartitionSplitterWidget::_eachItem( QVector< PartitionSplitterItem >& items,
|
|||||||
for ( auto it = items.begin(); it != items.end(); ++it )
|
for ( auto it = items.begin(); it != items.end(); ++it )
|
||||||
{
|
{
|
||||||
if ( operation( *it ) )
|
if ( operation( *it ) )
|
||||||
|
{
|
||||||
opCount++;
|
opCount++;
|
||||||
|
}
|
||||||
|
|
||||||
opCount += _eachItem( it->children, operation );
|
opCount += _eachItem( it->children, operation );
|
||||||
}
|
}
|
||||||
@ -619,7 +625,8 @@ PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterIte
|
|||||||
for ( int row = 0; row < items.count(); ++row )
|
for ( int row = 0; row < items.count(); ++row )
|
||||||
{
|
{
|
||||||
if ( items[ row ].size < 0.01 * total ) // If this item is smaller than 1% of everything,
|
if ( items[ row ].size < 0.01 * total ) // If this item is smaller than 1% of everything,
|
||||||
{ // force its width to 1%.
|
{
|
||||||
|
// force its width to 1%.
|
||||||
adjustedTotal -= items[ row ].size;
|
adjustedTotal -= items[ row ].size;
|
||||||
items[ row ].size = qint64( 0.01 * total );
|
items[ row ].size = qint64( 0.01 * total );
|
||||||
adjustedTotal += items[ row ].size;
|
adjustedTotal += items[ row ].size;
|
||||||
|
Loading…
Reference in New Issue
Block a user