only return true from PartResizerWidget::movePartition() if the partition was

actually moved.

set single step for the sector spinboxes to align value

add a checkbox to turn off aligning the partition


svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1105207
This commit is contained in:
Volker Lanz 2010-03-19 14:13:04 +00:00
parent 6eab5deb08
commit 791377f176
8 changed files with 174 additions and 105 deletions

View File

@ -472,10 +472,7 @@ void PartitionManagerWidget::onNewPartition()
QPointer<NewDialog> dlg = new NewDialog(this, *selectedDevice(), *newPartition, selectedDevice()->partitionTable()->childRoles(*selectedPartition())); QPointer<NewDialog> dlg = new NewDialog(this, *selectedDevice(), *newPartition, selectedDevice()->partitionTable()->childRoles(*selectedPartition()));
if (dlg->exec() == KDialog::Accepted) if (dlg->exec() == KDialog::Accepted)
{
PartitionTable::alignPartition(*selectedDevice(), *newPartition);
operationStack().push(new NewOperation(*selectedDevice(), newPartition)); operationStack().push(new NewOperation(*selectedDevice(), newPartition));
}
else else
delete newPartition; delete newPartition;
@ -565,8 +562,6 @@ void PartitionManagerWidget::onResizePartition()
if (dlg->exec() == KDialog::Accepted && dlg->isModified()) if (dlg->exec() == KDialog::Accepted && dlg->isModified())
{ {
PartitionTable::alignPartition(*selectedDevice(), resizedPartition, selectedPartition());
if (resizedPartition.firstSector() == selectedPartition()->firstSector() && resizedPartition.lastSector() == selectedPartition()->lastSector()) if (resizedPartition.firstSector() == selectedPartition()->firstSector() && resizedPartition.lastSector() == selectedPartition()->lastSector())
Log(Log::information) << i18nc("@info/plain", "Partition <filename>%1</filename> has the same position and size after resize/move. Ignoring operation.", selectedPartition()->deviceNode()); Log(Log::information) << i18nc("@info/plain", "Partition <filename>%1</filename> has the same position and size after resize/move. Ignoring operation.", selectedPartition()->deviceNode());
else else
@ -628,7 +623,7 @@ void PartitionManagerWidget::onPastePartition()
delete copiedPartition; delete copiedPartition;
} }
bool PartitionManagerWidget::showInsertDialog(Partition& insertPartition, qint64 sourceLength) bool PartitionManagerWidget::showInsertDialog(Partition& insertedPartition, qint64 sourceLength)
{ {
Q_ASSERT(selectedDevice()); Q_ASSERT(selectedDevice());
Q_ASSERT(selectedPartition()); Q_ASSERT(selectedPartition());
@ -643,22 +638,20 @@ bool PartitionManagerWidget::showInsertDialog(Partition& insertPartition, qint64
// Make sure the inserted partition has the right parent and logical or primary set. Only then // Make sure the inserted partition has the right parent and logical or primary set. Only then
// can PartitionTable::alignPartition() work correctly. // can PartitionTable::alignPartition() work correctly.
selectedPartition()->parent()->reparent(insertPartition); selectedPartition()->parent()->reparent(insertedPartition);
if (!overwrite) if (!overwrite)
{ {
QPointer<InsertDialog> dlg = new InsertDialog(this, *selectedDevice(), insertPartition, *selectedPartition()); QPointer<InsertDialog> dlg = new InsertDialog(this, *selectedDevice(), insertedPartition, *selectedPartition());
int result = dlg->exec(); int result = dlg->exec();
delete dlg; delete dlg;
if (result != KDialog::Accepted) if (result != KDialog::Accepted)
return false; return false;
PartitionTable::alignPartition(*selectedDevice(), insertPartition, selectedPartition());
} }
if (insertPartition.length() < sourceLength) if (insertedPartition.length() < sourceLength)
{ {
if (overwrite) if (overwrite)
KMessageBox::error(this, i18nc("@info", KMessageBox::error(this, i18nc("@info",

View File

@ -59,7 +59,8 @@ PartResizerWidget::PartResizerWidget(QWidget* parent) :
m_DraggedWidget(NULL), m_DraggedWidget(NULL),
m_Hotspot(0), m_Hotspot(0),
m_MoveAllowed(true), m_MoveAllowed(true),
m_ReadOnly(false) m_ReadOnly(false),
m_Align(true)
{ {
} }
@ -207,18 +208,31 @@ bool PartResizerWidget::movePartition(qint64 newFirstSector)
return false; return false;
} }
const qint64 originalFirst = partition().firstSector();
const qint64 originalLast = partition().lastSector();
partition().setFirstSector(newFirstSector); partition().setFirstSector(newFirstSector);
partition().fileSystem().setFirstSector(newFirstSector); partition().fileSystem().setFirstSector(newFirstSector);
emit firstSectorChanged(newFirstSector);
partition().setLastSector(newLastSector); partition().setLastSector(newLastSector);
partition().fileSystem().setLastSector(newLastSector); partition().fileSystem().setLastSector(newLastSector);
emit lastSectorChanged(newLastSector);
resizeLogicals(); if (align())
updatePositions(); device().partitionTable()->alignPartition(device(), partition());
return true; if (originalFirst != partition().firstSector() || originalLast != partition().lastSector())
{
resizeLogicals();
updatePositions();
}
if (originalFirst != partition().firstSector())
emit firstSectorChanged(partition().firstSector());
if (originalLast != partition().lastSector())
emit lastSectorChanged(partition().lastSector());
return originalFirst != partition().firstSector() || originalLast != partition().lastSector();
} }
void PartResizerWidget::mouseMoveEvent(QMouseEvent* event) void PartResizerWidget::mouseMoveEvent(QMouseEvent* event)
@ -266,16 +280,21 @@ bool PartResizerWidget::updateFirstSector(qint64 newFirstSector)
if (newFirstSector != partition().firstSector() && (partition().children().size() == 0 || checkAlignment(*partition().children().first(), partition().firstSector() - newFirstSector))) if (newFirstSector != partition().firstSector() && (partition().children().size() == 0 || checkAlignment(*partition().children().first(), partition().firstSector() - newFirstSector)))
{ {
const qint64 originalFirst = partition().lastSector();
partition().setFirstSector(newFirstSector); partition().setFirstSector(newFirstSector);
partition().fileSystem().setFirstSector(newFirstSector); partition().fileSystem().setFirstSector(newFirstSector);
resizeLogicals(); if (align())
device().partitionTable()->alignPartition(device(), partition());
emit firstSectorChanged(newFirstSector); if (originalFirst != partition().firstSector())
{
updatePositions(); resizeLogicals();
updatePositions();
return true; emit firstSectorChanged(partition().firstSector());
return true;
}
} }
return false; return false;
@ -323,16 +342,21 @@ bool PartResizerWidget::updateLastSector(qint64 newLastSector)
if (newLastSector != partition().lastSector() && (partition().children().size() == 0 || checkAlignment(*partition().children().last(), partition().lastSector() - newLastSector))) if (newLastSector != partition().lastSector() && (partition().children().size() == 0 || checkAlignment(*partition().children().last(), partition().lastSector() - newLastSector)))
{ {
const qint64 originalLast = partition().lastSector();
partition().setLastSector(newLastSector); partition().setLastSector(newLastSector);
partition().fileSystem().setLastSector(newLastSector); partition().fileSystem().setLastSector(newLastSector);
resizeLogicals(); if (align())
device().partitionTable()->alignPartition(device(), partition());
emit lastSectorChanged(newLastSector); if (partition().lastSector() != originalLast)
{
updatePositions(); resizeLogicals();
updatePositions();
return true; emit lastSectorChanged(partition().lastSector());
return true;
}
} }
return false; return false;

View File

@ -72,6 +72,9 @@ class PartResizerWidget : public QWidget
bool readOnly() const { return m_ReadOnly; } /**< @return true if the widget is read only */ bool readOnly() const { return m_ReadOnly; } /**< @return true if the widget is read only */
void setReadOnly(bool b) { m_ReadOnly = b; } /**< @param b the new value for read only */ void setReadOnly(bool b) { m_ReadOnly = b; } /**< @param b the new value for read only */
bool align() const { return m_Align; } /**< @return true if the Partition is to be aligned */
void setAlign(bool b) { m_Align = b; } /**< @param b the new value for aligning the Partition */
static qint32 handleWidth() { return m_HandleWidth; } /**< @return the handle width in pixels */ static qint32 handleWidth() { return m_HandleWidth; } /**< @return the handle width in pixels */
static qint32 handleHeight() { return m_HandleHeight; } /**< @return the handle height in pixels */ static qint32 handleHeight() { return m_HandleHeight; } /**< @return the handle height in pixels */
@ -143,6 +146,7 @@ class PartResizerWidget : public QWidget
bool m_MoveAllowed; bool m_MoveAllowed;
bool m_ReadOnly; bool m_ReadOnly;
bool m_Align;
static const qint32 m_HandleWidth; static const qint32 m_HandleWidth;
static const qint32 m_HandleHeight; static const qint32 m_HandleHeight;

View File

@ -39,6 +39,7 @@ class SizeDetailsWidget : public QWidget, public Ui::SizeDetailsWidgetBase
public: public:
QDoubleSpinBox& spinFirstSector() { Q_ASSERT(m_SpinFirstSector); return *m_SpinFirstSector; } QDoubleSpinBox& spinFirstSector() { Q_ASSERT(m_SpinFirstSector); return *m_SpinFirstSector; }
QDoubleSpinBox& spinLastSector() { Q_ASSERT(m_SpinLastSector); return *m_SpinLastSector; } QDoubleSpinBox& spinLastSector() { Q_ASSERT(m_SpinLastSector); return *m_SpinLastSector; }
QCheckBox& checkAlign() { Q_ASSERT(m_CheckAlign); return *m_CheckAlign; }
}; };
#endif #endif

View File

@ -7,81 +7,11 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>428</width> <width>428</width>
<height>134</height> <height>211</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="4" column="0"> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string comment="@label:listbox">First sector:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>m_SpinFreeBefore</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="m_SpinFirstSector">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<number>0</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string comment="@label:listbox">Last sector:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>m_SpinFreeBefore</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="m_SpinLastSector">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<number>0</number>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer_3"> <spacer name="verticalSpacer_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -97,14 +27,14 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<spacer name="verticalSpacer_4"> <spacer name="verticalSpacer_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -120,7 +50,87 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="0" colspan="2"> <item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string comment="@label:listbox">First sector:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>m_SpinFirstSector</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="m_SpinFirstSector">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<number>0</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string comment="@label:listbox">Last sector:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>m_SpinLastSector</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="m_SpinLastSector">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<number>0</number>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="m_CheckAlign">
<property name="text">
<string>Align Partition According To Partition Table Settings</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer_5"> <spacer name="verticalSpacer_5">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -136,6 +146,29 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="5" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -29,6 +29,7 @@
#include "util/capacity.h" #include "util/capacity.h"
#include <kdebug.h> #include <kdebug.h>
#include <config.h>
SizeDialogBase::SizeDialogBase(QWidget* parent, Device& d, Partition& part, qint64 minFirst, qint64 maxLast) : SizeDialogBase::SizeDialogBase(QWidget* parent, Device& d, Partition& part, qint64 minFirst, qint64 maxLast) :
KDialog(parent), KDialog(parent),
@ -127,6 +128,9 @@ void SizeDialogBase::setupConstraints()
detailsWidget().spinFirstSector().setRange(minimumFirstSector(), maximumLastSector()); detailsWidget().spinFirstSector().setRange(minimumFirstSector(), maximumLastSector());
detailsWidget().spinLastSector().setRange(minimumFirstSector(), maximumLastSector()); detailsWidget().spinLastSector().setRange(minimumFirstSector(), maximumLastSector());
detailsWidget().spinFirstSector().setSingleStep(Config::sectorAlignment());
detailsWidget().spinLastSector().setSingleStep(Config::sectorAlignment());
} }
void SizeDialogBase::setupConnections() void SizeDialogBase::setupConnections()
@ -140,6 +144,7 @@ void SizeDialogBase::setupConnections()
connect(&detailsWidget().spinFirstSector(), SIGNAL(valueChanged(double)), SLOT(onSpinFirstSectorChanged(double))); connect(&detailsWidget().spinFirstSector(), SIGNAL(valueChanged(double)), SLOT(onSpinFirstSectorChanged(double)));
connect(&detailsWidget().spinLastSector(), SIGNAL(valueChanged(double)), SLOT(onSpinLastSectorChanged(double))); connect(&detailsWidget().spinLastSector(), SIGNAL(valueChanged(double)), SLOT(onSpinLastSectorChanged(double)));
connect(&detailsWidget().checkAlign(), SIGNAL(stateChanged(int)), SLOT(onAlignStateChanged(int)));
} }
@ -161,6 +166,14 @@ void SizeDialogBase::onSpinLastSectorChanged(double newLast)
} }
} }
void SizeDialogBase::onAlignStateChanged(int)
{
const bool align = detailsWidget().checkAlign().isChecked();
dialogWidget().partResizerWidget().setAlign(align);
detailsWidget().spinFirstSector().setSingleStep(align ? Config::sectorAlignment() : 1);
detailsWidget().spinLastSector().setSingleStep(align ? Config::sectorAlignment() : 1);
}
void SizeDialogBase::onFirstSectorChanged(qint64 newFirst) void SizeDialogBase::onFirstSectorChanged(qint64 newFirst)
{ {
bool state = dialogWidget().spinFreeBefore().blockSignals(true); bool state = dialogWidget().spinFreeBefore().blockSignals(true);

View File

@ -80,6 +80,7 @@ class SizeDialogBase : public KDialog
void onSpinFirstSectorChanged(double newFirst); void onSpinFirstSectorChanged(double newFirst);
void onSpinLastSectorChanged(double newLast); void onSpinLastSectorChanged(double newLast);
void onAlignStateChanged(int);
protected: protected:
SizeDialogWidget* m_SizeDialogWidget; SizeDialogWidget* m_SizeDialogWidget;

View File

@ -76,7 +76,7 @@ QList<Device*> DummyBackend::scanDevices()
Device* DummyBackend::scanDevice(const QString& device_node) Device* DummyBackend::scanDevice(const QString& device_node)
{ {
Device* d = new Device("Dummy Device", QString("/tmp" + device_node), 255, 3000, 63, 512); Device* d = new Device("Dummy Device", QString("/tmp" + device_node), 255, 30, 63, 512);
CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(PartitionTable::msdos_sectorbased, 2048, d->totalSectors() - 2048)); CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(PartitionTable::msdos_sectorbased, 2048, d->totalSectors() - 2048));
CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 128); CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 128);
d->partitionTable()->updateUnallocated(*d); d->partitionTable()->updateUnallocated(*d);