diff --git a/src/gui/partresizerwidget.cpp b/src/gui/partresizerwidget.cpp index 6400ee0..aea15b3 100644 --- a/src/gui/partresizerwidget.cpp +++ b/src/gui/partresizerwidget.cpp @@ -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()) { diff --git a/src/gui/parttablewidget.cpp b/src/gui/parttablewidget.cpp index fd5502f..6df67d9 100644 --- a/src/gui/parttablewidget.cpp +++ b/src/gui/parttablewidget.cpp @@ -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()) + if (pw->isActive()) + return pw; + + return NULL; +} + +const PartWidget* PartTableWidget::activeWidget() const +{ + foreach (const PartWidget* pw, findChildren()) + 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(); } diff --git a/src/gui/parttablewidget.h b/src/gui/parttablewidget.h index fc356ed..85e8239 100644 --- a/src/gui/parttablewidget.h +++ b/src/gui/parttablewidget.h @@ -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 m_Widgets; - PartWidget* m_ActiveWidget; QLabel m_LabelEmpty; bool m_ReadOnly; }; diff --git a/src/gui/partwidget.cpp b/src/gui/partwidget.cpp index 51c6c29..ada7f61 100644 --- a/src/gui/partwidget.cpp +++ b/src/gui/partwidget.cpp @@ -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::childWidgets() +{ + QList rval; + + foreach(QObject* o, children()) + if (PartWidget* w = qobject_cast(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); } - diff --git a/src/gui/partwidget.h b/src/gui/partwidget.h index ed3bf45..0434c48 100644 --- a/src/gui/partwidget.h +++ b/src/gui/partwidget.h @@ -27,7 +27,6 @@ #include -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& childWidgets() { return m_ChildWidgets; } - const QList& childWidgets() const { return m_ChildWidgets; } - - bool showChildren() const { return m_ShowChildren; } + QList childWidgets(); QColor activeColor(const QColor& col) const; private: - const PartTableWidget* m_PartTableWidget; const Partition* m_Partition; - QList m_ChildWidgets; - const bool m_ShowChildren; + bool m_Active; }; #endif diff --git a/src/gui/partwidgetbase.cpp b/src/gui/partwidgetbase.cpp index d12d2eb..4e310b1 100644 --- a/src/gui/partwidgetbase.cpp +++ b/src/gui/partwidgetbase.cpp @@ -99,7 +99,7 @@ bool levelChildrenWidths(QList& childrenWidth, const QList& minC return true; } -void PartWidgetBase::positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList& widgets) +void PartWidgetBase::positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList widgets) { if (partitions.size() == 0) return; diff --git a/src/gui/partwidgetbase.h b/src/gui/partwidgetbase.h index a3e333b..dfa29f5 100644 --- a/src/gui/partwidgetbase.h +++ b/src/gui/partwidgetbase.h @@ -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& widgets); + static void positionChildren(const QWidget* destWidget, const PartitionNode::Partitions& partitions, QList widgets); private: static const qint32 m_Spacing;