Only show the labels section where it's relevant.

This commit is contained in:
Teo Mrnjavac 2015-04-22 11:17:22 +02:00
parent 966ccdaafc
commit 45d5c5bbde
5 changed files with 24 additions and 4 deletions

View File

@ -224,11 +224,13 @@ EraseDiskPage::updatePreviews()
layout->addRow( new QLabel( info.deviceName ) ); layout->addRow( new QLabel( info.deviceName ) );
preview = new PartitionPreview; preview = new PartitionPreview;
preview->setLabelsVisible( true );
preview->setModel( info.partitionModelBefore ); preview->setModel( info.partitionModelBefore );
info.partitionModelBefore->setParent( m_previewFrame ); info.partitionModelBefore->setParent( m_previewFrame );
layout->addRow( tr( "Before:" ), preview ); layout->addRow( tr( "Before:" ), preview );
preview = new PartitionPreview; preview = new PartitionPreview;
preview->setLabelsVisible( true );
preview->setModel( info.partitionModelAfter ); preview->setModel( info.partitionModelAfter );
info.partitionModelAfter->setParent( m_previewFrame ); info.partitionModelAfter->setParent( m_previewFrame );
layout->addRow( tr( "After:" ), preview ); layout->addRow( tr( "After:" ), preview );

View File

@ -35,7 +35,8 @@ static const int EXTENDED_PARTITION_MARGIN = 4;
PartitionPreview::PartitionPreview( QWidget* parent ) PartitionPreview::PartitionPreview( QWidget* parent )
: QAbstractItemView( parent ) : m_showLabels( false )
, QAbstractItemView( parent )
{ {
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
setFrameStyle( QFrame::NoFrame ); setFrameStyle( QFrame::NoFrame );
@ -57,7 +58,9 @@ PartitionPreview::minimumSizeHint() const
QSize QSize
PartitionPreview::sizeHint() const PartitionPreview::sizeHint() const
{ {
if ( m_showLabels )
return QSize( -1, VIEW_HEIGHT + LAYOUT_MARGIN + labelsHeight() ); return QSize( -1, VIEW_HEIGHT + LAYOUT_MARGIN + labelsHeight() );
return QSize( -1, VIEW_HEIGHT );
} }
@ -75,6 +78,7 @@ PartitionPreview::paintEvent( QPaintEvent* event )
painter.save(); painter.save();
drawPartitions( &painter, partitionsRect, QModelIndex() ); drawPartitions( &painter, partitionsRect, QModelIndex() );
painter.restore(); painter.restore();
if ( m_showLabels )
drawLabels( &painter, labelsRect, QModelIndex() ); drawLabels( &painter, labelsRect, QModelIndex() );
} }
@ -284,6 +288,14 @@ PartitionPreview::scrollTo( const QModelIndex& index, ScrollHint hint )
} }
void
PartitionPreview::setLabelsVisible( bool visible )
{
m_showLabels = visible;
repaint();
}
QModelIndex QModelIndex
PartitionPreview::moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) PartitionPreview::moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers )
{ {

View File

@ -31,7 +31,7 @@
class PartitionPreview : public QAbstractItemView class PartitionPreview : public QAbstractItemView
{ {
public: public:
explicit PartitionPreview( QWidget* parent = 0 ); explicit PartitionPreview( QWidget* parent = nullptr );
~PartitionPreview(); ~PartitionPreview();
QSize minimumSizeHint() const override; QSize minimumSizeHint() const override;
@ -45,6 +45,8 @@ public:
QRect visualRect( const QModelIndex& index ) const override; QRect visualRect( const QModelIndex& index ) const override;
void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) override; void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) override;
void setLabelsVisible( bool visible = true );
protected: protected:
// QAbstractItemView API // QAbstractItemView API
QRegion visualRegionForSelection( const QItemSelection& selection ) const override; QRegion visualRegionForSelection( const QItemSelection& selection ) const override;
@ -58,6 +60,7 @@ private:
void drawPartitions( QPainter* painter, const QRect& rect, const QModelIndex& parent ); void drawPartitions( QPainter* painter, const QRect& rect, const QModelIndex& parent );
void drawLabels( QPainter* painter, const QRect& rect, const QModelIndex& parent ); void drawLabels( QPainter* painter, const QRect& rect, const QModelIndex& parent );
static int labelsHeight(); static int labelsHeight();
bool m_showLabels;
}; };
#endif /* PARTITIONPREVIEW_H */ #endif /* PARTITIONPREVIEW_H */

View File

@ -262,11 +262,13 @@ PartitionViewStep::createSummaryWidget() const
PartitionPreview* preview; PartitionPreview* preview;
preview = new PartitionPreview; preview = new PartitionPreview;
preview->setLabelsVisible( true );
preview->setModel( info.partitionModelBefore ); preview->setModel( info.partitionModelBefore );
info.partitionModelBefore->setParent( widget ); info.partitionModelBefore->setParent( widget );
formLayout->addRow( tr( "Before:" ), preview ); formLayout->addRow( tr( "Before:" ), preview );
preview = new PartitionPreview; preview = new PartitionPreview;
preview->setLabelsVisible( true );
preview->setModel( info.partitionModelAfter ); preview->setModel( info.partitionModelAfter );
info.partitionModelAfter->setParent( widget ); info.partitionModelAfter->setParent( widget );
formLayout->addRow( tr( "After:" ), preview ); formLayout->addRow( tr( "After:" ), preview );

View File

@ -42,6 +42,7 @@ ReplacePage::ReplacePage( PartitionCoreModule* core, QWidget* parent )
{ {
m_ui->setupUi( this ); m_ui->setupUi( this );
m_ui->deviceComboBox->setModel( m_core->deviceModel() ); m_ui->deviceComboBox->setModel( m_core->deviceModel() );
m_ui->partitionPreview->setLabelsVisible( true );
// updateButtons(); // updateButtons();