mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-28 09:55: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,20 +136,8 @@ PartitionLabelsView::getIndexesToDraw( const QModelIndex& parent ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
QStringList
|
||||||
PartitionLabelsView::drawLabels( QPainter* painter,
|
PartitionLabelsView::buildTexts( const QModelIndex& index ) const
|
||||||
const QRect& rect,
|
|
||||||
const QModelIndex& parent )
|
|
||||||
{
|
|
||||||
PartitionModel* modl = qobject_cast< PartitionModel* >( model() );
|
|
||||||
if ( !modl )
|
|
||||||
return;
|
|
||||||
|
|
||||||
QModelIndexList indexesToDraw = getIndexesToDraw( parent );
|
|
||||||
|
|
||||||
int label_x = rect.x();
|
|
||||||
int label_y = rect.y();
|
|
||||||
foreach ( const QModelIndex& index, indexesToDraw )
|
|
||||||
{
|
{
|
||||||
QString firstLine, secondLine;
|
QString firstLine, secondLine;
|
||||||
|
|
||||||
|
@ -189,8 +177,26 @@ PartitionLabelsView::drawLabels( QPainter* painter,
|
||||||
PartitionModel::FileSystemColumn )
|
PartitionModel::FileSystemColumn )
|
||||||
.data().toString() );
|
.data().toString() );
|
||||||
|
|
||||||
QStringList texts = { firstLine,
|
return { firstLine, secondLine };
|
||||||
secondLine };
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionLabelsView::drawLabels( QPainter* painter,
|
||||||
|
const QRect& rect,
|
||||||
|
const QModelIndex& parent )
|
||||||
|
{
|
||||||
|
PartitionModel* modl = qobject_cast< PartitionModel* >( model() );
|
||||||
|
if ( !modl )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QModelIndexList indexesToDraw = getIndexesToDraw( parent );
|
||||||
|
|
||||||
|
int label_x = rect.x();
|
||||||
|
int label_y = rect.y();
|
||||||
|
foreach ( const QModelIndex& index, indexesToDraw )
|
||||||
|
{
|
||||||
|
QStringList texts = buildTexts( index );
|
||||||
|
|
||||||
QSize labelSize = sizeForLabel( texts );
|
QSize labelSize = sizeForLabel( texts );
|
||||||
|
|
||||||
|
@ -231,10 +237,8 @@ PartitionLabelsView::sizeForAllLabels( int maxLineWidth ) const
|
||||||
int singleLabelHeight = 0;
|
int singleLabelHeight = 0;
|
||||||
foreach ( const QModelIndex& index, indexesToDraw )
|
foreach ( const QModelIndex& index, indexesToDraw )
|
||||||
{
|
{
|
||||||
QStringList texts = { index.data().toString(),
|
QStringList texts = buildTexts( index );
|
||||||
index.sibling( index.row(),
|
|
||||||
PartitionModel::SizeColumn )
|
|
||||||
.data().toString() };
|
|
||||||
QSize labelSize = sizeForLabel( texts );
|
QSize labelSize = sizeForLabel( texts );
|
||||||
|
|
||||||
if ( lineLength + labelSize.width() > maxLineWidth )
|
if ( lineLength + labelSize.width() > maxLineWidth )
|
||||||
|
|
|
@ -66,6 +66,7 @@ private:
|
||||||
QSize sizeForLabel( const QStringList& text ) const;
|
QSize sizeForLabel( const QStringList& text ) const;
|
||||||
void drawLabel( QPainter* painter, const QStringList& text, const QColor& color, const QPoint& pos );
|
void drawLabel( QPainter* painter, const QStringList& text, const QColor& color, const QPoint& pos );
|
||||||
QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const;
|
QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const;
|
||||||
|
QStringList buildTexts( const QModelIndex& index ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PARTITIONLABELSVIEW_H
|
#endif // PARTITIONLABELSVIEW_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue