use a PartWidget instead of a PartResizerWidget in the partition properties

dialog -- no one is going to do any resizing, after all.

to make this possible, allow creating a PartWidget() without a valid Partition
pointer and add an init() method for later setting the Partition pointer. also
take care of the Partition pointer being NULL everywhere in the class

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1134172
This commit is contained in:
Volker Lanz 2010-06-03 15:01:53 +00:00
parent 6508ad1d71
commit 68d1eb14ce
7 changed files with 60 additions and 37 deletions

View File

@ -179,7 +179,7 @@ Partition* PartitionManagerWidget::selectedPartition()
// The active partition we get from the part table widget is const; we need non-const.
// So take the first sector and find the partition in the selected device's
// partition table.
const Partition* activePartition = &partTableWidget().activeWidget()->partition();
const Partition* activePartition = partTableWidget().activeWidget()->partition();
return selectedDevice()->partitionTable()->findPartitionBySector(activePartition->firstSector(), PartitionRole(PartitionRole::Any));
}
@ -322,22 +322,27 @@ void PartitionManagerWidget::on_m_PartTableWidget_itemSelectionChanged(PartWidge
return;
}
const Partition& p = item->partition();
const Partition* p = item->partition();
QList<QTreeWidgetItem*> findResult = treePartitions().findItems(p.deviceNode(), Qt::MatchFixedString | Qt::MatchRecursive, 0);
Q_ASSERT(p);
for (int idx = 0; idx < findResult.size(); idx++)
if (p)
{
const PartitionTreeWidgetItem* ptwItem = dynamic_cast<PartitionTreeWidgetItem*>(findResult[idx]);
QList<QTreeWidgetItem*> findResult = treePartitions().findItems(p->deviceNode(), Qt::MatchFixedString | Qt::MatchRecursive, 0);
if (ptwItem && ptwItem->partition() == &p)
for (int idx = 0; idx < findResult.size(); idx++)
{
treePartitions().setCurrentItem(findResult[idx]);
break;
const PartitionTreeWidgetItem* ptwItem = dynamic_cast<PartitionTreeWidgetItem*>(findResult[idx]);
if (ptwItem && ptwItem->partition() == p)
{
treePartitions().setCurrentItem(findResult[idx]);
break;
}
}
}
emit selectedPartitionChanged(&p);
emit selectedPartitionChanged(p);
}
void PartitionManagerWidget::on_m_PartTableWidget_customContextMenuRequested(const QPoint& pos)

View File

@ -96,7 +96,7 @@ void PartPropsDialog::setupDialog()
enableButtonOk(false);
button(KDialog::Cancel)->setFocus();
dialogWidget().partResizerWidget().init(device(), partition(), partition().firstSector(), partition().lastSector(), true, false);
dialogWidget().partWidget().init(&partition());
const QString mp = partition().mountPoint().isEmpty()
? i18nc("@item mountpoint", "(none found)")
@ -315,7 +315,7 @@ void PartPropsDialog::updatePartitionFileSystem()
FileSystem* fs = FileSystemFactory::create(newFileSystemType(), partition().firstSector(), partition().lastSector());
partition().deleteFileSystem();
partition().setFileSystem(fs);
dialogWidget().partResizerWidget().update();
dialogWidget().partWidget().update();
}
void PartPropsDialog::onFilesystemChanged(int)

View File

@ -32,7 +32,7 @@ class PartPropsWidget : public QWidget, public Ui::PartPropsWidgetBase
PartPropsWidget(QWidget* parent) : QWidget(parent) { setupUi(this); }
public:
PartResizerWidget& partResizerWidget() { Q_ASSERT(m_PartResizerWidget); return *m_PartResizerWidget; }
PartWidget& partWidget() { Q_ASSERT(m_PartWidget); return *m_PartWidget; }
QLabel& mountPoint() { Q_ASSERT(m_LabelMountPoint); return *m_LabelMountPoint; }
QLabel& role() { Q_ASSERT(m_LabelRole); return *m_LabelRole; }

View File

@ -12,7 +12,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2" colspan="3">
<widget class="PartResizerWidget" name="m_PartResizerWidget" native="true">
<widget class="PartWidget" name="m_PartWidget" native="true">
<property name="minimumSize">
<size>
<width>300</width>
@ -360,9 +360,9 @@
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>PartResizerWidget</class>
<class>PartWidget</class>
<extends>QWidget</extends>
<header>gui/partresizerwidget.h</header>
<header>gui/partwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@ -118,7 +118,7 @@ void PartTableWidget::setActivePartition(const Partition* p)
return;
foreach (PartWidget* pw, findChildren<PartWidget*>())
if (&pw->partition() == p)
if (pw->partition() == p)
{
setActiveWidget(pw);
return;

View File

@ -38,12 +38,22 @@
*/
PartWidget::PartWidget(QWidget* parent, const Partition* p) :
PartWidgetBase(parent),
m_Partition(p),
m_Partition(NULL),
m_Active(false)
{
setFont(KGlobalSettings::smallestReadableFont());
setToolTip(partition().deviceNode() + '\n' + partition().fileSystem().name() + ' ' + Capacity(partition()).toString());
init(p);
}
void PartWidget::init(const Partition* p)
{
m_Partition = p;
if (partition())
setToolTip(partition()->deviceNode() + '\n' + partition()->fileSystem().name() + ' ' + Capacity(*partition()).toString());
else
setToolTip(QString());
updateChildren();
}
@ -51,25 +61,29 @@ PartWidget::PartWidget(QWidget* parent, const Partition* p) :
/** Updates the widget's children */
void PartWidget::updateChildren()
{
foreach (QWidget* w, childWidgets())
if (partition())
{
w->setVisible(false);
w->deleteLater();
w->setParent(NULL);
}
foreach (QWidget* w, childWidgets())
{
w->setVisible(false);
w->deleteLater();
w->setParent(NULL);
}
foreach(const Partition* child, partition().children())
{
QWidget* w = new PartWidget(this, child);
w->setVisible(true);
}
foreach(const Partition* child, partition()->children())
{
QWidget* w = new PartWidget(this, child);
w->setVisible(true);
}
positionChildren(this, partition().children(), childWidgets());
positionChildren(this, partition()->children(), childWidgets());
}
}
void PartWidget::resizeEvent(QResizeEvent*)
{
positionChildren(this, partition().children(), childWidgets());
if (partition())
positionChildren(this, partition()->children(), childWidgets());
}
QColor PartWidget::activeColor(const QColor& col) const
@ -79,20 +93,23 @@ QColor PartWidget::activeColor(const QColor& col) const
void PartWidget::paintEvent(QPaintEvent*)
{
const int usedPercentage = partition().used() * 100 / partition().capacity();
if (partition() == NULL)
return;
const int usedPercentage = partition()->used() * 100 / partition()->capacity();
const int w = (width() - 1 - (PartWidget::borderWidth() * 2)) * usedPercentage / 100;
QPainter painter(this);
// draw border
painter.setPen(isActive() ? QColor(250, 250, 250) : QColor(20, 20, 20));
painter.setBrush(activeColor(Config::fileSystemColorCode(partition().fileSystem().type())));
painter.setBrush(activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())));
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
if (partition().roles().has(PartitionRole::Extended))
if (partition()->roles().has(PartitionRole::Extended))
return;
if (!partition().roles().has(PartitionRole::Unallocated))
if (!partition()->roles().has(PartitionRole::Unallocated))
{
// draw free space background
painter.setBrush(activeColor(Config::availableSpaceColorCode()));
@ -104,7 +121,7 @@ void PartWidget::paintEvent(QPaintEvent*)
}
// draw name and size
QString text = partition().deviceNode().remove("/dev/") + '\n' + Capacity(partition()).toString();
QString text = partition()->deviceNode().remove("/dev/") + '\n' + Capacity(*partition()).toString();
const QRect textRect(0, 0, width() - 1, height() - 1);
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);

View File

@ -41,14 +41,15 @@ class PartWidget : public PartWidgetBase
Q_OBJECT
public:
PartWidget(QWidget* parent, const Partition* p);
PartWidget(QWidget* parent, const Partition* p = NULL);
public:
void init(const Partition* p);
void setActive(bool b) { m_Active = b; }
bool isActive() const { return m_Active; } /**< @return true if this is the currently active widget */
void updateChildren();
const Partition& partition() const { Q_ASSERT(m_Partition); return *m_Partition; } /**< @return the widget's Partition */
const Partition* partition() const { return m_Partition; } /**< @return the widget's Partition */
protected:
void paintEvent(QPaintEvent* event);