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:
parent
6508ad1d71
commit
68d1eb14ce
|
@ -179,7 +179,7 @@ Partition* PartitionManagerWidget::selectedPartition()
|
||||||
// The active partition we get from the part table widget is const; we need non-const.
|
// 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
|
// So take the first sector and find the partition in the selected device's
|
||||||
// partition table.
|
// partition table.
|
||||||
const Partition* activePartition = &partTableWidget().activeWidget()->partition();
|
const Partition* activePartition = partTableWidget().activeWidget()->partition();
|
||||||
return selectedDevice()->partitionTable()->findPartitionBySector(activePartition->firstSector(), PartitionRole(PartitionRole::Any));
|
return selectedDevice()->partitionTable()->findPartitionBySector(activePartition->firstSector(), PartitionRole(PartitionRole::Any));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,22 +322,27 @@ void PartitionManagerWidget::on_m_PartTableWidget_itemSelectionChanged(PartWidge
|
||||||
return;
|
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]);
|
const PartitionTreeWidgetItem* ptwItem = dynamic_cast<PartitionTreeWidgetItem*>(findResult[idx]);
|
||||||
break;
|
|
||||||
|
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)
|
void PartitionManagerWidget::on_m_PartTableWidget_customContextMenuRequested(const QPoint& pos)
|
||||||
|
|
|
@ -96,7 +96,7 @@ void PartPropsDialog::setupDialog()
|
||||||
enableButtonOk(false);
|
enableButtonOk(false);
|
||||||
button(KDialog::Cancel)->setFocus();
|
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()
|
const QString mp = partition().mountPoint().isEmpty()
|
||||||
? i18nc("@item mountpoint", "(none found)")
|
? i18nc("@item mountpoint", "(none found)")
|
||||||
|
@ -315,7 +315,7 @@ void PartPropsDialog::updatePartitionFileSystem()
|
||||||
FileSystem* fs = FileSystemFactory::create(newFileSystemType(), partition().firstSector(), partition().lastSector());
|
FileSystem* fs = FileSystemFactory::create(newFileSystemType(), partition().firstSector(), partition().lastSector());
|
||||||
partition().deleteFileSystem();
|
partition().deleteFileSystem();
|
||||||
partition().setFileSystem(fs);
|
partition().setFileSystem(fs);
|
||||||
dialogWidget().partResizerWidget().update();
|
dialogWidget().partWidget().update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartPropsDialog::onFilesystemChanged(int)
|
void PartPropsDialog::onFilesystemChanged(int)
|
||||||
|
|
|
@ -32,7 +32,7 @@ class PartPropsWidget : public QWidget, public Ui::PartPropsWidgetBase
|
||||||
PartPropsWidget(QWidget* parent) : QWidget(parent) { setupUi(this); }
|
PartPropsWidget(QWidget* parent) : QWidget(parent) { setupUi(this); }
|
||||||
|
|
||||||
public:
|
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& mountPoint() { Q_ASSERT(m_LabelMountPoint); return *m_LabelMountPoint; }
|
||||||
QLabel& role() { Q_ASSERT(m_LabelRole); return *m_LabelRole; }
|
QLabel& role() { Q_ASSERT(m_LabelRole); return *m_LabelRole; }
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" rowspan="2" colspan="3">
|
<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">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>300</width>
|
<width>300</width>
|
||||||
|
@ -360,9 +360,9 @@
|
||||||
<header>kcombobox.h</header>
|
<header>kcombobox.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>PartResizerWidget</class>
|
<class>PartWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>gui/partresizerwidget.h</header>
|
<header>gui/partwidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
@ -118,7 +118,7 @@ void PartTableWidget::setActivePartition(const Partition* p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (PartWidget* pw, findChildren<PartWidget*>())
|
foreach (PartWidget* pw, findChildren<PartWidget*>())
|
||||||
if (&pw->partition() == p)
|
if (pw->partition() == p)
|
||||||
{
|
{
|
||||||
setActiveWidget(pw);
|
setActiveWidget(pw);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -38,12 +38,22 @@
|
||||||
*/
|
*/
|
||||||
PartWidget::PartWidget(QWidget* parent, const Partition* p) :
|
PartWidget::PartWidget(QWidget* parent, const Partition* p) :
|
||||||
PartWidgetBase(parent),
|
PartWidgetBase(parent),
|
||||||
m_Partition(p),
|
m_Partition(NULL),
|
||||||
m_Active(false)
|
m_Active(false)
|
||||||
{
|
{
|
||||||
setFont(KGlobalSettings::smallestReadableFont());
|
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();
|
updateChildren();
|
||||||
}
|
}
|
||||||
|
@ -51,25 +61,29 @@ PartWidget::PartWidget(QWidget* parent, const Partition* p) :
|
||||||
/** Updates the widget's children */
|
/** Updates the widget's children */
|
||||||
void PartWidget::updateChildren()
|
void PartWidget::updateChildren()
|
||||||
{
|
{
|
||||||
foreach (QWidget* w, childWidgets())
|
if (partition())
|
||||||
{
|
{
|
||||||
w->setVisible(false);
|
foreach (QWidget* w, childWidgets())
|
||||||
w->deleteLater();
|
{
|
||||||
w->setParent(NULL);
|
w->setVisible(false);
|
||||||
}
|
w->deleteLater();
|
||||||
|
w->setParent(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
foreach(const Partition* child, partition().children())
|
foreach(const Partition* child, partition()->children())
|
||||||
{
|
{
|
||||||
QWidget* w = new PartWidget(this, child);
|
QWidget* w = new PartWidget(this, child);
|
||||||
w->setVisible(true);
|
w->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
positionChildren(this, partition().children(), childWidgets());
|
positionChildren(this, partition()->children(), childWidgets());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartWidget::resizeEvent(QResizeEvent*)
|
void PartWidget::resizeEvent(QResizeEvent*)
|
||||||
{
|
{
|
||||||
positionChildren(this, partition().children(), childWidgets());
|
if (partition())
|
||||||
|
positionChildren(this, partition()->children(), childWidgets());
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor PartWidget::activeColor(const QColor& col) const
|
QColor PartWidget::activeColor(const QColor& col) const
|
||||||
|
@ -79,20 +93,23 @@ QColor PartWidget::activeColor(const QColor& col) const
|
||||||
|
|
||||||
void PartWidget::paintEvent(QPaintEvent*)
|
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;
|
const int w = (width() - 1 - (PartWidget::borderWidth() * 2)) * usedPercentage / 100;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
// draw border
|
// draw border
|
||||||
painter.setPen(isActive() ? QColor(250, 250, 250) : QColor(20, 20, 20));
|
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));
|
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
|
||||||
|
|
||||||
if (partition().roles().has(PartitionRole::Extended))
|
if (partition()->roles().has(PartitionRole::Extended))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!partition().roles().has(PartitionRole::Unallocated))
|
if (!partition()->roles().has(PartitionRole::Unallocated))
|
||||||
{
|
{
|
||||||
// draw free space background
|
// draw free space background
|
||||||
painter.setBrush(activeColor(Config::availableSpaceColorCode()));
|
painter.setBrush(activeColor(Config::availableSpaceColorCode()));
|
||||||
|
@ -104,7 +121,7 @@ void PartWidget::paintEvent(QPaintEvent*)
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw name and size
|
// 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 textRect(0, 0, width() - 1, height() - 1);
|
||||||
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
||||||
|
|
|
@ -41,14 +41,15 @@ class PartWidget : public PartWidgetBase
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PartWidget(QWidget* parent, const Partition* p);
|
PartWidget(QWidget* parent, const Partition* p = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void init(const Partition* p);
|
||||||
void setActive(bool b) { m_Active = b; }
|
void setActive(bool b) { m_Active = b; }
|
||||||
bool isActive() const { return m_Active; } /**< @return true if this is the currently active widget */
|
bool isActive() const { return m_Active; } /**< @return true if this is the currently active widget */
|
||||||
void updateChildren();
|
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:
|
protected:
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
|
|
Loading…
Reference in New Issue