mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-27 17:35:37 -04:00
Factor out text building for label view items for proper sizeHint.
This commit is contained in:
parent
0be736acf7
commit
0af434bfc1
2 changed files with 49 additions and 44 deletions
|
@ -136,6 +136,51 @@ PartitionLabelsView::getIndexesToDraw( const QModelIndex& parent ) const
|
|||
}
|
||||
|
||||
|
||||
QStringList
|
||||
PartitionLabelsView::buildTexts( const QModelIndex& index ) const
|
||||
{
|
||||
QString firstLine, secondLine;
|
||||
|
||||
if ( index.data( PartitionModel::IsPartitionNewRole ).toBool() )
|
||||
{
|
||||
QString mountPoint = index.sibling( index.row(),
|
||||
PartitionModel::MountPointColumn )
|
||||
.data().toString();
|
||||
if ( mountPoint == "/" )
|
||||
firstLine = tr( "New root partition" );
|
||||
else if ( mountPoint == "/home" )
|
||||
firstLine = tr( "New home partition" );
|
||||
else if ( mountPoint == "/boot" )
|
||||
firstLine = tr( "New boot partition" );
|
||||
else if ( mountPoint.contains( "/efi" ) &&
|
||||
index.sibling( index.row(),
|
||||
PartitionModel::FileSystemColumn )
|
||||
.data().toString() == "fat32" )
|
||||
firstLine = tr( "New EFI system partition" );
|
||||
else if ( index.sibling( index.row(),
|
||||
PartitionModel::FileSystemColumn )
|
||||
.data().toString() == "linuxswap" )
|
||||
firstLine = tr( "New swap partition" );
|
||||
else
|
||||
firstLine = tr( "New partition for %1" ).arg( mountPoint );
|
||||
}
|
||||
else if ( index.data( PartitionModel::OsproberNameRole ).toString().isEmpty() )
|
||||
firstLine = index.data().toString();
|
||||
else
|
||||
firstLine = index.data( PartitionModel::OsproberNameRole ).toString();
|
||||
|
||||
secondLine = tr( "%1 %2" )
|
||||
.arg( index.sibling( index.row(),
|
||||
PartitionModel::SizeColumn )
|
||||
.data().toString() )
|
||||
.arg( index.sibling( index.row(),
|
||||
PartitionModel::FileSystemColumn )
|
||||
.data().toString() );
|
||||
|
||||
return { firstLine, secondLine };
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PartitionLabelsView::drawLabels( QPainter* painter,
|
||||
const QRect& rect,
|
||||
|
@ -151,46 +196,7 @@ PartitionLabelsView::drawLabels( QPainter* painter,
|
|||
int label_y = rect.y();
|
||||
foreach ( const QModelIndex& index, indexesToDraw )
|
||||
{
|
||||
QString firstLine, secondLine;
|
||||
|
||||
if ( index.data( PartitionModel::IsPartitionNewRole ).toBool() )
|
||||
{
|
||||
QString mountPoint = index.sibling( index.row(),
|
||||
PartitionModel::MountPointColumn )
|
||||
.data().toString();
|
||||
if ( mountPoint == "/" )
|
||||
firstLine = tr( "New root partition" );
|
||||
else if ( mountPoint == "/home" )
|
||||
firstLine = tr( "New home partition" );
|
||||
else if ( mountPoint == "/boot" )
|
||||
firstLine = tr( "New boot partition" );
|
||||
else if ( mountPoint.contains( "/efi" ) &&
|
||||
index.sibling( index.row(),
|
||||
PartitionModel::FileSystemColumn )
|
||||
.data().toString() == "fat32" )
|
||||
firstLine = tr( "New EFI system partition" );
|
||||
else if ( index.sibling( index.row(),
|
||||
PartitionModel::FileSystemColumn )
|
||||
.data().toString() == "linuxswap" )
|
||||
firstLine = tr( "New swap partition" );
|
||||
else
|
||||
firstLine = tr( "New partition for %1" ).arg( mountPoint );
|
||||
}
|
||||
else if ( index.data( PartitionModel::OsproberNameRole ).toString().isEmpty() )
|
||||
firstLine = index.data().toString();
|
||||
else
|
||||
firstLine = index.data( PartitionModel::OsproberNameRole ).toString();
|
||||
|
||||
secondLine = tr( "%1 %2" )
|
||||
.arg( index.sibling( index.row(),
|
||||
PartitionModel::SizeColumn )
|
||||
.data().toString() )
|
||||
.arg( index.sibling( index.row(),
|
||||
PartitionModel::FileSystemColumn )
|
||||
.data().toString() );
|
||||
|
||||
QStringList texts = { firstLine,
|
||||
secondLine };
|
||||
QStringList texts = buildTexts( index );
|
||||
|
||||
QSize labelSize = sizeForLabel( texts );
|
||||
|
||||
|
@ -231,10 +237,8 @@ PartitionLabelsView::sizeForAllLabels( int maxLineWidth ) const
|
|||
int singleLabelHeight = 0;
|
||||
foreach ( const QModelIndex& index, indexesToDraw )
|
||||
{
|
||||
QStringList texts = { index.data().toString(),
|
||||
index.sibling( index.row(),
|
||||
PartitionModel::SizeColumn )
|
||||
.data().toString() };
|
||||
QStringList texts = buildTexts( index );
|
||||
|
||||
QSize labelSize = sizeForLabel( texts );
|
||||
|
||||
if ( lineLength + labelSize.width() > maxLineWidth )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue