2008-09-24 20:32:01 +01:00
/***************************************************************************
2010-03-16 11:40:54 +00:00
* Copyright ( C ) 2008 , 2010 by Volker Lanz < vl @ fidra . de > *
2008-09-24 20:32:01 +01:00
* *
* This program 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 2 of the License , or *
* ( at your option ) any later version . *
* *
* This program 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 this program ; if not , write to the *
* Free Software Foundation , Inc . , *
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "gui/partresizerwidget.h"
# include "gui/partwidget.h"
# include "core/partition.h"
# include "core/device.h"
2010-03-16 11:40:54 +00:00
# include "core/partitiontable.h"
2010-04-13 11:04:01 +01:00
# include "core/partitionalignment.h"
2008-09-24 20:32:01 +01:00
# include "fs/filesystem.h"
# include <QPainter>
# include <QMouseEvent>
# include <QPaintEvent>
# include <QResizeEvent>
# include <kdebug.h>
# include <kcolorscheme.h>
const qint32 PartResizerWidget : : m_HandleWidth = 16 ;
const qint32 PartResizerWidget : : m_HandleHeight = 59 ;
/** Creates a new PartResizerWidget
Initializing is mostly done in init ( ) .
@ param parent pointer to the parent widget
*/
PartResizerWidget : : PartResizerWidget ( QWidget * parent ) :
QWidget ( parent ) ,
m_Device ( NULL ) ,
m_Partition ( NULL ) ,
m_PartWidget ( NULL ) ,
2010-03-16 11:40:54 +00:00
m_MinimumFirstSector ( 0 ) ,
m_MaximumFirstSector ( - 1 ) ,
m_MinimumLastSector ( - 1 ) ,
m_MaximumLastSector ( 0 ) ,
m_MinimumLength ( - 1 ) ,
m_MaximumLength ( - 1 ) ,
2008-09-24 20:32:01 +01:00
m_LeftHandle ( this ) ,
m_RightHandle ( this ) ,
m_DraggedWidget ( NULL ) ,
m_Hotspot ( 0 ) ,
m_MoveAllowed ( true ) ,
2010-03-19 14:13:04 +00:00
m_ReadOnly ( false ) ,
m_Align ( true )
2008-09-24 20:32:01 +01:00
{
}
/** Intializes the PartResizerWidget
@ param d the Device the Partition is on
@ param p the Partition to show and / or resize
2010-03-16 11:40:54 +00:00
@ param minFirst the minimum value for the first sector
@ param maxLast the maximum value for the last sector
2008-09-24 20:32:01 +01:00
*/
2010-04-15 14:41:12 +01:00
void PartResizerWidget : : init ( Device & d , Partition & p , qint64 minFirst , qint64 maxLast , bool read_only , bool move_allowed )
2008-09-24 20:32:01 +01:00
{
2010-04-15 14:41:12 +01:00
m_ReadOnly = read_only ;
m_MoveAllowed = move_allowed & & ! read_only ;
2008-09-24 20:32:01 +01:00
setDevice ( d ) ;
setPartition ( p ) ;
2010-03-16 11:40:54 +00:00
setMinimumFirstSector ( minFirst ) ;
setMaximumLastSector ( maxLast ) ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
setMinimumLength ( qMax ( partition ( ) . sectorsUsed ( ) , partition ( ) . minimumSectors ( ) ) ) ;
setMaximumLength ( qMin ( totalSectors ( ) , partition ( ) . maximumSectors ( ) ) ) ;
2008-09-24 20:32:01 +01:00
/** @todo get real pixmaps for the handles */
QPixmap pixmap ( handleWidth ( ) , handleHeight ( ) ) ;
pixmap . fill ( QColor ( 0x44 , 0x44 , 0x44 ) ) ;
2008-12-27 17:12:13 +00:00
2008-09-24 20:32:01 +01:00
leftHandle ( ) . setPixmap ( pixmap ) ;
rightHandle ( ) . setPixmap ( pixmap ) ;
leftHandle ( ) . setFixedSize ( handleWidth ( ) , handleHeight ( ) ) ;
rightHandle ( ) . setFixedSize ( handleWidth ( ) , handleHeight ( ) ) ;
delete m_PartWidget ;
2010-04-12 15:35:02 +01:00
m_PartWidget = new PartWidget ( this , & partition ( ) ) ;
2008-09-24 20:32:01 +01:00
if ( ! readOnly ( ) )
{
leftHandle ( ) . setCursor ( Qt : : SizeHorCursor ) ;
rightHandle ( ) . setCursor ( Qt : : SizeHorCursor ) ;
if ( moveAllowed ( ) )
partWidget ( ) . setCursor ( Qt : : SizeAllCursor ) ;
2008-12-27 17:12:13 +00:00
partWidget ( ) . setToolTip ( QString ( ) ) ;
2008-09-24 20:32:01 +01:00
}
updatePositions ( ) ;
}
qint64 PartResizerWidget : : sectorsPerPixel ( ) const
{
return totalSectors ( ) / ( width ( ) - 2 * handleWidth ( ) ) ;
}
int PartResizerWidget : : partWidgetStart ( ) const
{
2010-03-16 11:40:54 +00:00
return handleWidth ( ) + ( partition ( ) . firstSector ( ) - minimumFirstSector ( ) ) / sectorsPerPixel ( ) ;
2008-09-24 20:32:01 +01:00
}
int PartResizerWidget : : partWidgetWidth ( ) const
{
return partition ( ) . length ( ) / sectorsPerPixel ( ) ;
}
void PartResizerWidget : : updatePositions ( )
{
partWidget ( ) . move ( partWidgetStart ( ) , 0 ) ;
partWidget ( ) . resize ( partWidgetWidth ( ) , height ( ) - 1 ) ;
leftHandle ( ) . move ( partWidgetStart ( ) - leftHandle ( ) . width ( ) , 0 ) ;
rightHandle ( ) . move ( partWidgetStart ( ) + partWidgetWidth ( ) , 0 ) ;
partWidget ( ) . update ( ) ;
}
void PartResizerWidget : : resizeEvent ( QResizeEvent * event )
{
updatePositions ( ) ;
QWidget : : resizeEvent ( event ) ;
}
void PartResizerWidget : : paintEvent ( QPaintEvent * )
{
QPainter painter ( this ) ;
painter . setPen ( Qt : : NoPen ) ;
painter . setBrush ( QColor ( 0x99 , 0x99 , 0x99 ) ) ;
painter . drawRect ( QRect ( handleWidth ( ) , 0 , width ( ) - ( 2 * handleWidth ( ) ) - 1 , height ( ) - 1 ) ) ;
}
void PartResizerWidget : : mousePressEvent ( QMouseEvent * event )
{
if ( readOnly ( ) )
return ;
2008-12-27 17:12:13 +00:00
2008-09-24 20:32:01 +01:00
if ( event - > button ( ) = = Qt : : LeftButton )
{
m_DraggedWidget = static_cast < QWidget * > ( childAt ( event - > pos ( ) ) ) ;
if ( m_DraggedWidget ! = NULL )
{
if ( partWidget ( ) . isAncestorOf ( m_DraggedWidget ) )
m_DraggedWidget = & partWidget ( ) ;
m_Hotspot = m_DraggedWidget - > mapFromParent ( event - > pos ( ) ) . x ( ) ;
}
}
}
2010-04-12 19:20:14 +01:00
bool PartResizerWidget : : checkConstraints ( qint64 first , qint64 last ) const
{
2010-04-15 11:45:43 +01:00
return ( maximumFirstSector ( ) = = - 1 | | first < = maximumFirstSector ( ) ) & &
( minimumFirstSector ( ) = = 0 | | first > = minimumFirstSector ( ) ) & &
( minimumLastSector ( ) = = - 1 | | last > = minimumLastSector ( ) ) & &
( maximumLastSector ( ) = = 0 | | last < = maximumLastSector ( ) ) ;
2010-04-12 19:20:14 +01:00
}
2010-03-16 11:40:54 +00:00
bool PartResizerWidget : : movePartition ( qint64 newFirstSector )
2008-09-24 20:32:01 +01:00
{
2010-04-15 11:45:43 +01:00
const qint64 originalLength = partition ( ) . length ( ) ;
const bool isLengthAligned = PartitionAlignment : : isLengthAligned ( device ( ) , partition ( ) ) ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( maximumFirstSector ( align ( ) ) > - 1 & & newFirstSector > maximumFirstSector ( align ( ) ) )
newFirstSector = maximumFirstSector ( align ( ) ) ;
if ( minimumFirstSector ( align ( ) ) > 0 & & newFirstSector < minimumFirstSector ( align ( ) ) )
newFirstSector = minimumFirstSector ( align ( ) ) ;
if ( align ( ) )
newFirstSector = PartitionAlignment : : alignedFirstSector ( device ( ) , partition ( ) , newFirstSector ) ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
qint64 delta = newFirstSector - partition ( ) . firstSector ( ) ;
2010-04-12 18:51:21 +01:00
if ( delta = = 0 )
return false ;
2010-03-16 11:40:54 +00:00
qint64 newLastSector = partition ( ) . lastSector ( ) + delta ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( minimumLastSector ( align ( ) ) > - 1 & & newLastSector < minimumLastSector ( align ( ) ) )
2010-03-16 11:40:54 +00:00
{
2010-04-15 11:45:43 +01:00
const qint64 deltaLast = minimumLastSector ( align ( ) ) - newLastSector ;
2010-03-16 11:40:54 +00:00
newFirstSector + = deltaLast ;
newLastSector + = deltaLast ;
2008-09-24 20:32:01 +01:00
}
2010-04-15 11:45:43 +01:00
if ( maximumLastSector ( align ( ) ) > 0 & & newLastSector > maximumLastSector ( align ( ) ) )
2010-03-16 11:40:54 +00:00
{
2010-04-15 11:45:43 +01:00
const qint64 deltaLast = newLastSector - maximumLastSector ( align ( ) ) ;
2010-03-16 11:40:54 +00:00
newFirstSector - = deltaLast ;
newLastSector - = deltaLast ;
}
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( align ( ) )
newLastSector = PartitionAlignment : : alignedLastSector ( device ( ) , partition ( ) , newLastSector , originalLength , isLengthAligned ) ;
2010-04-12 18:51:21 +01:00
if ( newLastSector = = partition ( ) . lastSector ( ) )
return false ;
2010-04-15 11:45:43 +01:00
if ( isLengthAligned & & newLastSector - newFirstSector + 1 ! = partition ( ) . length ( ) )
{
kDebug ( ) < < " length changes while trying to move partition " < < partition ( ) . deviceNode ( ) < < " . new first: " < < newFirstSector < < " , new last: " < < newLastSector < < " , old length: " < < partition ( ) . length ( ) < < " , new length: " < < newLastSector - newFirstSector + 1 ;
return false ;
}
if ( ! checkConstraints ( newFirstSector , newLastSector ) )
{
kDebug ( ) < < " constraints not satisfied while trying to move partition " < < partition ( ) . deviceNode ( ) < < " . new first: " < < newFirstSector < < " , new last: " < < newLastSector ;
return false ;
}
if ( align ( ) & & ! PartitionAlignment : : isAligned ( device ( ) , partition ( ) , newFirstSector , newLastSector , true ) )
2008-09-24 20:32:01 +01:00
{
2010-04-15 11:45:43 +01:00
kDebug ( ) < < " partition " < < partition ( ) . deviceNode ( ) < < " not aligned but supposed to be. new first: " < < newFirstSector < < " delta: " < < PartitionAlignment : : firstDelta ( device ( ) , partition ( ) , newFirstSector ) < < " , new last: " < < newLastSector < < " , delta: " < < PartitionAlignment : : lastDelta ( device ( ) , partition ( ) , newLastSector ) ;
2008-09-24 20:32:01 +01:00
return false ;
}
2010-03-16 11:40:54 +00:00
if ( partition ( ) . children ( ) . size ( ) > 0 & &
( ! checkAlignment ( * partition ( ) . children ( ) . first ( ) , partition ( ) . firstSector ( ) - newFirstSector ) | |
! checkAlignment ( * partition ( ) . children ( ) . last ( ) , partition ( ) . lastSector ( ) - newLastSector ) ) )
2008-09-24 20:32:01 +01:00
{
2010-03-16 11:40:54 +00:00
kDebug ( ) < < " cannot align children while trying to move partition " < < partition ( ) . deviceNode ( ) ;
2008-09-24 20:32:01 +01:00
return false ;
}
2008-12-27 17:12:13 +00:00
2010-03-16 11:40:54 +00:00
partition ( ) . setFirstSector ( newFirstSector ) ;
partition ( ) . fileSystem ( ) . setFirstSector ( newFirstSector ) ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
partition ( ) . setLastSector ( newLastSector ) ;
partition ( ) . fileSystem ( ) . setLastSector ( newLastSector ) ;
2010-04-15 11:45:43 +01:00
updatePositions ( ) ;
2010-03-19 14:13:04 +00:00
2010-04-15 11:45:43 +01:00
emit firstSectorChanged ( partition ( ) . firstSector ( ) ) ;
emit lastSectorChanged ( partition ( ) . lastSector ( ) ) ;
2010-03-19 14:13:04 +00:00
2010-04-15 11:45:43 +01:00
return true ;
2010-03-16 11:40:54 +00:00
}
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
void PartResizerWidget : : mouseMoveEvent ( QMouseEvent * event )
{
int x = event - > pos ( ) . x ( ) - m_Hotspot ;
2008-12-27 17:12:13 +00:00
2010-03-16 11:40:54 +00:00
if ( draggedWidget ( ) = = & leftHandle ( ) )
2008-09-24 20:32:01 +01:00
{
2010-03-16 11:40:54 +00:00
const qint64 newFirstSector = qMax ( minimumFirstSector ( ) + x * sectorsPerPixel ( ) , 0LL ) ;
updateFirstSector ( newFirstSector ) ;
2008-09-24 20:32:01 +01:00
}
2010-03-16 11:40:54 +00:00
else if ( draggedWidget ( ) = = & rightHandle ( ) )
2008-09-24 20:32:01 +01:00
{
2010-03-16 11:40:54 +00:00
const qint64 newLastSector = qMin ( minimumFirstSector ( ) + ( x - rightHandle ( ) . width ( ) ) * sectorsPerPixel ( ) , maximumLastSector ( ) ) ;
updateLastSector ( newLastSector ) ;
}
else if ( draggedWidget ( ) = = & partWidget ( ) & & moveAllowed ( ) )
{
const qint64 newFirstSector = qMax ( minimumFirstSector ( ) + ( x - handleWidth ( ) ) * sectorsPerPixel ( ) , 0LL ) ;
movePartition ( newFirstSector ) ;
2008-09-24 20:32:01 +01:00
}
}
void PartResizerWidget : : mouseReleaseEvent ( QMouseEvent * event )
{
if ( event - > button ( ) = = Qt : : LeftButton )
m_DraggedWidget = NULL ;
}
2010-03-16 11:40:54 +00:00
bool PartResizerWidget : : updateFirstSector ( qint64 newFirstSector )
2008-09-24 20:32:01 +01:00
{
2010-04-15 11:45:43 +01:00
if ( maximumFirstSector ( align ( ) ) > - 1 & & newFirstSector > maximumFirstSector ( align ( ) ) )
newFirstSector = maximumFirstSector ( align ( ) ) ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( minimumFirstSector ( align ( ) ) > 0 & & newFirstSector < minimumFirstSector ( align ( ) ) )
newFirstSector = minimumFirstSector ( align ( ) ) ;
2008-12-27 17:12:13 +00:00
2010-03-16 11:40:54 +00:00
const qint64 newLength = partition ( ) . lastSector ( ) - newFirstSector + 1 ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
if ( newLength < minimumLength ( ) )
2010-03-25 19:58:35 +00:00
newFirstSector - = minimumLength ( ) - newLength ;
2008-12-27 17:12:13 +00:00
2010-03-16 11:40:54 +00:00
if ( newLength > maximumLength ( ) )
newFirstSector - = newLength - maximumLength ( ) ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( align ( ) )
newFirstSector = PartitionAlignment : : alignedFirstSector ( device ( ) , partition ( ) , newFirstSector ) ;
2010-03-16 11:40:54 +00:00
if ( newFirstSector ! = partition ( ) . firstSector ( ) & & ( partition ( ) . children ( ) . size ( ) = = 0 | | checkAlignment ( * partition ( ) . children ( ) . first ( ) , partition ( ) . firstSector ( ) - newFirstSector ) ) )
2008-09-24 20:32:01 +01:00
{
partition ( ) . setFirstSector ( newFirstSector ) ;
partition ( ) . fileSystem ( ) . setFirstSector ( newFirstSector ) ;
2008-12-27 17:12:13 +00:00
2010-04-15 11:45:43 +01:00
resizeLogicals ( ) ;
updatePositions ( ) ;
2008-12-27 17:12:13 +00:00
2010-04-15 11:45:43 +01:00
emit firstSectorChanged ( partition ( ) . firstSector ( ) ) ;
return true ;
2008-09-24 20:32:01 +01:00
}
return false ;
}
2010-03-16 11:40:54 +00:00
bool PartResizerWidget : : checkAlignment ( const Partition & child , qint64 delta ) const
2008-09-24 20:32:01 +01:00
{
2010-04-15 11:45:43 +01:00
// TODO: what is this exactly good for? and is it correct in non-cylinder-aligned
// situations?
2008-09-24 20:32:01 +01:00
if ( ! partition ( ) . roles ( ) . has ( PartitionRole : : Extended ) )
return true ;
if ( child . roles ( ) . has ( PartitionRole : : Unallocated ) )
return true ;
2010-04-13 11:04:01 +01:00
return qAbs ( delta ) > = PartitionAlignment : : sectorAlignment ( device ( ) ) ;
2008-09-24 20:32:01 +01:00
}
void PartResizerWidget : : resizeLogicals ( )
{
2010-04-15 14:41:12 +01:00
if ( ! partition ( ) . roles ( ) . has ( PartitionRole : : Extended ) )
2008-09-24 20:32:01 +01:00
return ;
2009-01-09 07:10:59 +00:00
Q_ASSERT ( device ( ) . partitionTable ( ) ) ;
device ( ) . partitionTable ( ) - > removeUnallocated ( & partition ( ) ) ;
device ( ) . partitionTable ( ) - > insertUnallocated ( device ( ) , & partition ( ) , partition ( ) . firstSector ( ) ) ;
2008-12-27 17:12:13 +00:00
2008-09-24 20:32:01 +01:00
partWidget ( ) . updateChildren ( ) ;
}
2010-03-16 11:40:54 +00:00
bool PartResizerWidget : : updateLastSector ( qint64 newLastSector )
2008-09-24 20:32:01 +01:00
{
2010-04-15 11:45:43 +01:00
if ( minimumLastSector ( align ( ) ) > - 1 & & newLastSector < minimumLastSector ( align ( ) ) )
newLastSector = minimumLastSector ( align ( ) ) ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( maximumLastSector ( align ( ) ) > 0 & & newLastSector > maximumLastSector ( align ( ) ) )
newLastSector = maximumLastSector ( align ( ) ) ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
const qint64 newLength = newLastSector - partition ( ) . firstSector ( ) + 1 ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
if ( newLength < minimumLength ( ) )
newLastSector + = minimumLength ( ) - newLength ;
2008-09-24 20:32:01 +01:00
2010-03-16 11:40:54 +00:00
if ( newLength > maximumLength ( ) )
newLastSector - = newLength - maximumLength ( ) ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
if ( align ( ) )
newLastSector = PartitionAlignment : : alignedLastSector ( device ( ) , partition ( ) , newLastSector ) ;
2010-03-16 11:40:54 +00:00
if ( newLastSector ! = partition ( ) . lastSector ( ) & & ( partition ( ) . children ( ) . size ( ) = = 0 | | checkAlignment ( * partition ( ) . children ( ) . last ( ) , partition ( ) . lastSector ( ) - newLastSector ) ) )
2008-09-24 20:32:01 +01:00
{
partition ( ) . setLastSector ( newLastSector ) ;
partition ( ) . fileSystem ( ) . setLastSector ( newLastSector ) ;
2008-12-27 17:12:13 +00:00
2010-04-15 11:45:43 +01:00
resizeLogicals ( ) ;
updatePositions ( ) ;
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
emit lastSectorChanged ( partition ( ) . lastSector ( ) ) ;
return true ;
2008-09-24 20:32:01 +01:00
}
return false ;
}
/** Updates the Partition's length
@ param newLength the new length
@ return true on success
*/
bool PartResizerWidget : : updateLength ( qint64 newLength )
{
2010-03-16 11:40:54 +00:00
newLength = qBound ( minimumLength ( ) , newLength , qMin ( totalSectors ( ) , maximumLength ( ) ) ) ;
2008-09-24 20:32:01 +01:00
if ( newLength = = partition ( ) . length ( ) )
return false ;
const qint64 oldLength = partition ( ) . length ( ) ;
qint64 delta = newLength - oldLength ;
2010-04-15 11:45:43 +01:00
qint64 tmp = qMin ( delta , maximumLastSector ( align ( ) ) - partition ( ) . lastSector ( ) ) ;
2008-09-24 20:32:01 +01:00
delta - = tmp ;
if ( tmp ! = 0 )
{
partition ( ) . setLastSector ( partition ( ) . lastSector ( ) + tmp ) ;
partition ( ) . fileSystem ( ) . setLastSector ( partition ( ) . lastSector ( ) + tmp ) ;
2010-03-16 11:40:54 +00:00
emit lastSectorChanged ( partition ( ) . lastSector ( ) ) ;
2008-09-24 20:32:01 +01:00
}
2010-04-15 11:45:43 +01:00
tmp = qMin ( delta , partition ( ) . firstSector ( ) - minimumFirstSector ( align ( ) ) ) ;
2008-09-24 20:32:01 +01:00
delta - = tmp ;
if ( tmp ! = 0 )
{
partition ( ) . setFirstSector ( partition ( ) . firstSector ( ) - tmp ) ;
partition ( ) . fileSystem ( ) . setFirstSector ( partition ( ) . firstSector ( ) - tmp ) ;
2010-03-16 11:40:54 +00:00
emit firstSectorChanged ( partition ( ) . firstSector ( ) ) ;
2008-09-24 20:32:01 +01:00
}
if ( partition ( ) . length ( ) ! = oldLength )
{
emit lengthChanged ( partition ( ) . length ( ) ) ;
updatePositions ( ) ;
return true ;
}
return false ;
}
/** Sets the minimum sectors the Partition can be long.
@ note This value can never be less than 0 and never be higher than totalSectors ( )
@ param s the new minimum length
*/
2010-03-16 11:40:54 +00:00
void PartResizerWidget : : setMinimumLength ( qint64 s )
2008-09-24 20:32:01 +01:00
{
2010-03-16 11:40:54 +00:00
m_MinimumLength = qBound ( 0LL , s , totalSectors ( ) ) ;
2008-09-24 20:32:01 +01:00
}
/** Sets the maximum sectors the Partition can be long.
@ note This value can never be less than 0 and never by higher than totalSectors ( )
@ param s the new maximum length
*/
2010-03-16 11:40:54 +00:00
void PartResizerWidget : : setMaximumLength ( qint64 s )
2008-09-24 20:32:01 +01:00
{
2010-03-16 11:40:54 +00:00
m_MaximumLength = qBound ( 0LL , s , totalSectors ( ) ) ;
2008-09-24 20:32:01 +01:00
}
/** Sets if moving the Partition is allowed.
@ param b true if moving is allowed
*/
void PartResizerWidget : : setMoveAllowed ( bool b )
{
m_MoveAllowed = b ;
2010-04-15 14:41:12 +01:00
if ( m_PartWidget ! = NULL )
partWidget ( ) . setCursor ( b ? Qt : : SizeAllCursor : Qt : : ArrowCursor ) ;
2010-04-15 11:45:43 +01:00
}
qint64 PartResizerWidget : : minimumFirstSector ( bool aligned ) const
{
return ( m_MinimumFirstSector ! = 0 & & aligned )
? m_MinimumFirstSector - PartitionAlignment : : firstDelta ( device ( ) , partition ( ) , m_MinimumFirstSector ) + PartitionAlignment : : sectorAlignment ( device ( ) )
: m_MinimumFirstSector ;
}
2008-09-24 20:32:01 +01:00
2010-04-15 11:45:43 +01:00
qint64 PartResizerWidget : : maximumFirstSector ( bool aligned ) const
{
return ( m_MaximumFirstSector ! = - 1 & & aligned )
? m_MaximumFirstSector - PartitionAlignment : : firstDelta ( device ( ) , partition ( ) , m_MaximumFirstSector )
: m_MaximumFirstSector ;
}
qint64 PartResizerWidget : : minimumLastSector ( bool aligned ) const
{
return ( m_MinimumLastSector ! = - 1 & & aligned )
? m_MinimumLastSector - PartitionAlignment : : lastDelta ( device ( ) , partition ( ) , m_MinimumLastSector )
: m_MinimumLastSector ;
}
qint64 PartResizerWidget : : maximumLastSector ( bool aligned ) const
{
return ( m_MaximumLastSector ! = 0 & & aligned )
? m_MaximumLastSector - PartitionAlignment : : lastDelta ( device ( ) , partition ( ) , m_MaximumLastSector )
: m_MaximumLastSector ;
2008-09-24 20:32:01 +01:00
}