Remember the active PartWidget in the widget, not in the PartTableWidget. This
means the PartWidget doesn't need to know its PartTableWidget anymore. Don't keep a list of child widgets, Qt will do that for us. Remove the showChildren param and property from PartWidget, it wasn't used anymore. Rename active() to isActive() in PartWidget for consistency. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1114033
This commit is contained in:
parent
3f1b211df9
commit
c1a6713e45
|
@ -91,7 +91,7 @@ void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 ma
|
|||
rightHandle().setFixedSize(handleWidth(), handleHeight());
|
||||
|
||||
delete m_PartWidget;
|
||||
m_PartWidget = new PartWidget(this, NULL, &partition());
|
||||
m_PartWidget = new PartWidget(this, &partition());
|
||||
|
||||
if (!readOnly())
|
||||
{
|
||||
|
|
|
@ -34,7 +34,6 @@ PartTableWidget::PartTableWidget(QWidget* parent) :
|
|||
QWidget(parent),
|
||||
m_PartitionTable(NULL),
|
||||
m_Widgets(),
|
||||
m_ActiveWidget(NULL),
|
||||
m_LabelEmpty(i18nc("@info", "Please select a device."), this),
|
||||
m_ReadOnly(false)
|
||||
{
|
||||
|
@ -54,7 +53,7 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable)
|
|||
{
|
||||
foreach(const Partition* p, partitionTable()->children())
|
||||
{
|
||||
widgets().append(new PartWidget(this, this, p));
|
||||
widgets().append(new PartWidget(this, p));
|
||||
widgets().last()->show();
|
||||
}
|
||||
}
|
||||
|
@ -74,20 +73,39 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable)
|
|||
update();
|
||||
}
|
||||
|
||||
PartWidget* PartTableWidget::activeWidget()
|
||||
{
|
||||
foreach (PartWidget* pw, findChildren<PartWidget*>())
|
||||
if (pw->isActive())
|
||||
return pw;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const PartWidget* PartTableWidget::activeWidget() const
|
||||
{
|
||||
foreach (const PartWidget* pw, findChildren<PartWidget*>())
|
||||
if (pw->isActive())
|
||||
return pw;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Sets a widget active.
|
||||
@param p pointer to the PartWidget to set active. May be NULL.
|
||||
*/
|
||||
void PartTableWidget::setActiveWidget(PartWidget* p)
|
||||
{
|
||||
if (isReadOnly())
|
||||
if (isReadOnly() || p == activeWidget())
|
||||
return;
|
||||
|
||||
const PartWidget* old = m_ActiveWidget;
|
||||
if (activeWidget())
|
||||
activeWidget()->setActive(false);
|
||||
|
||||
m_ActiveWidget = p;
|
||||
if (p != NULL)
|
||||
p->setActive(true);
|
||||
|
||||
if (old != activeWidget())
|
||||
emit itemSelectionChanged(p);
|
||||
emit itemSelectionChanged(p);
|
||||
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ class PartTableWidget : public QWidget, public PartWidgetBase
|
|||
public:
|
||||
void setPartitionTable(const PartitionTable* ptable);
|
||||
|
||||
PartWidget* activeWidget() { return m_ActiveWidget; } /**< @return the active widget or NULL if none */
|
||||
const PartWidget* activeWidget() const { return m_ActiveWidget; } /**< @return the active widget or NULL if none */
|
||||
PartWidget* activeWidget(); /**< @return the active widget or NULL if none */
|
||||
const PartWidget* activeWidget() const; /**< @return the active widget or NULL if none */
|
||||
|
||||
void setActiveWidget(PartWidget* partWidget);
|
||||
void setActivePartition(const Partition* p);
|
||||
|
@ -78,7 +78,6 @@ class PartTableWidget : public QWidget, public PartWidgetBase
|
|||
private:
|
||||
const PartitionTable* m_PartitionTable;
|
||||
QList<PartWidget*> m_Widgets;
|
||||
PartWidget* m_ActiveWidget;
|
||||
QLabel m_LabelEmpty;
|
||||
bool m_ReadOnly;
|
||||
};
|
||||
|
|
|
@ -18,12 +18,10 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include "gui/partwidget.h"
|
||||
#include "gui/parttablewidget.h"
|
||||
|
||||
#include "util/capacity.h"
|
||||
|
||||
#include "core/partition.h"
|
||||
#include "core/operationstack.h"
|
||||
|
||||
#include "fs/filesystem.h"
|
||||
|
||||
|
@ -36,17 +34,13 @@
|
|||
|
||||
/** Creates a new PartWidget
|
||||
@param parent pointer to the parent widget
|
||||
@param ptWidget pointer to the PartTableWidget this widget will be in or NULL if none
|
||||
@param p pointer to the Partition this widget will show. must not be NULL.
|
||||
@param show_children true if this widget is supposed to show child widgets
|
||||
*/
|
||||
PartWidget::PartWidget(QWidget* parent, const PartTableWidget* ptWidget, const Partition* p, bool show_children) :
|
||||
PartWidget::PartWidget(QWidget* parent, const Partition* p) :
|
||||
QWidget(parent),
|
||||
PartWidgetBase(),
|
||||
m_PartTableWidget(ptWidget),
|
||||
m_Partition(p),
|
||||
m_ChildWidgets(),
|
||||
m_ShowChildren(show_children)
|
||||
m_Active(false)
|
||||
{
|
||||
setFont(KGlobalSettings::smallestReadableFont());
|
||||
|
||||
|
@ -55,6 +49,17 @@ PartWidget::PartWidget(QWidget* parent, const PartTableWidget* ptWidget, const P
|
|||
updateChildren();
|
||||
}
|
||||
|
||||
QList<PartWidget*> PartWidget::childWidgets()
|
||||
{
|
||||
QList<PartWidget*> rval;
|
||||
|
||||
foreach(QObject* o, children())
|
||||
if (PartWidget* w = qobject_cast<PartWidget*>(o))
|
||||
rval.append(w);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/** Updates the widget's children */
|
||||
void PartWidget::updateChildren()
|
||||
{
|
||||
|
@ -64,35 +69,20 @@ void PartWidget::updateChildren()
|
|||
w->deleteLater();
|
||||
}
|
||||
|
||||
childWidgets().clear();
|
||||
foreach(const Partition* child, partition().children())
|
||||
new PartWidget(this, child);
|
||||
|
||||
if (showChildren())
|
||||
{
|
||||
foreach(const Partition* child, partition().children())
|
||||
{
|
||||
childWidgets().append(new PartWidget(this, partTableWidget(), child));
|
||||
childWidgets().last()->show();
|
||||
}
|
||||
|
||||
positionChildren(this, partition().children(), childWidgets());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return true if this is the currently active widget */
|
||||
bool PartWidget::active() const
|
||||
{
|
||||
return partTableWidget() != NULL && partTableWidget()->activeWidget() == this;
|
||||
positionChildren(this, partition().children(), childWidgets());
|
||||
}
|
||||
|
||||
void PartWidget::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
if (showChildren())
|
||||
positionChildren(this, partition().children(), childWidgets());
|
||||
positionChildren(this, partition().children(), childWidgets());
|
||||
}
|
||||
|
||||
QColor PartWidget::activeColor(const QColor& col) const
|
||||
{
|
||||
return active() ? col.darker(130) : col;
|
||||
return isActive() ? col.darker(130) : col;
|
||||
}
|
||||
|
||||
void PartWidget::paintEvent(QPaintEvent*)
|
||||
|
@ -103,7 +93,7 @@ void PartWidget::paintEvent(QPaintEvent*)
|
|||
QPainter painter(this);
|
||||
|
||||
// draw border
|
||||
painter.setPen(active() ? 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.drawRect(QRect(0, 0, width() - 1, height() - 1));
|
||||
|
||||
|
@ -129,4 +119,3 @@ void PartWidget::paintEvent(QPaintEvent*)
|
|||
if (boundingRect.x() > PartWidgetBase::borderWidth() && boundingRect.y() > PartWidgetBase::borderHeight())
|
||||
painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
class PartTableWidget;
|
||||
class Partition;
|
||||
|
||||
class QPaintEvent;
|
||||
|
@ -44,10 +43,11 @@ class PartWidget : public QWidget, public PartWidgetBase
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PartWidget(QWidget* parent, const PartTableWidget* ptWidget, const Partition* p, bool showChildren = true);
|
||||
PartWidget(QWidget* parent, const Partition* p);
|
||||
|
||||
public:
|
||||
bool active() const;
|
||||
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 */
|
||||
|
@ -56,20 +56,13 @@ class PartWidget : public QWidget, public PartWidgetBase
|
|||
void paintEvent(QPaintEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
const PartTableWidget* partTableWidget() const { return m_PartTableWidget; }
|
||||
|
||||
QList<PartWidget*>& childWidgets() { return m_ChildWidgets; }
|
||||
const QList<PartWidget*>& childWidgets() const { return m_ChildWidgets; }
|
||||
|
||||
bool showChildren() const { return m_ShowChildren; }
|
||||
QList<PartWidget*> childWidgets();
|
||||
|
||||
QColor activeColor(const QColor& col) const;
|
||||
|
||||
private:
|
||||
const PartTableWidget* m_PartTableWidget;
|
||||
const Partition* m_Partition;
|
||||
QList<PartWidget*> m_ChildWidgets;
|
||||
const bool m_ShowChildren;
|
||||
bool m_Active;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -99,7 +99,7 @@ bool levelChildrenWidths(QList<qint32>& childrenWidth, const QList<qint32>& minC
|
|||
return true;
|
||||
}
|
||||
|
||||
void PartWidgetBase::positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList<PartWidget*>& widgets)
|
||||
void PartWidgetBase::positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList<PartWidget*> widgets)
|
||||
{
|
||||
if (partitions.size() == 0)
|
||||
return;
|
||||
|
|
|
@ -47,7 +47,7 @@ class PartWidgetBase
|
|||
static qint32 minWidth() { return m_MinWidth; } /**< @return minimum width for a Partition widget */
|
||||
|
||||
protected:
|
||||
static void positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList<PartWidget*>& widgets);
|
||||
static void positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList<PartWidget*> widgets);
|
||||
|
||||
private:
|
||||
static const qint32 m_Spacing;
|
||||
|
|
Loading…
Reference in New Issue