From f10ffb50014e0b577c7c4b925ba679a92fa958b7 Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Mon, 6 Oct 2008 09:18:31 +0000 Subject: [PATCH] Show an info message if no device is selected or the selected device has no valid partition table. No need to overwrite paintEvent(). svn path=/trunk/playground/sysadmin/partitionmanager/; revision=868394 --- src/gui/parttablewidget.cpp | 35 +++++++++++++++++++---------------- src/gui/parttablewidget.h | 7 +++++-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/gui/parttablewidget.cpp b/src/gui/parttablewidget.cpp index 631f231..f5ac6d2 100644 --- a/src/gui/parttablewidget.cpp +++ b/src/gui/parttablewidget.cpp @@ -25,13 +25,7 @@ #include #include - -/** @class PartTableWidget - - @todo If there's no disk label on a device, we currently don't show anything at all. - That's not particularly helpful, we should print something like "you need to create - a partition table on this device to use it". -*/ +#include /** Creates a new PartTableWidget. @param parent pointer to the parent widget @@ -40,8 +34,10 @@ PartTableWidget::PartTableWidget(QWidget* parent) : QWidget(parent), m_PartitionTable(NULL), m_Widgets(), - m_ActiveWidget(NULL) + m_ActiveWidget(NULL), + m_LabelEmpty(i18nc("@info", "Please select a device."), this) { + labelEmpty().setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); } /** Sets the PartitionTable this widget shows. @@ -67,7 +63,18 @@ void PartTableWidget::setPartitionTable(const PartitionTable* ptable) widgets().last()->show(); } - positionChildren(this, partitionTable()->children(), widgets()); + if (widgets().isEmpty()) + { + labelEmpty().setVisible(true); + labelEmpty().setText(i18nc("@info", "No valid partition table was found on this device.")); + labelEmpty().resize(size()); + } + else + { + labelEmpty().setVisible(false); + positionChildren(this, partitionTable()->children(), widgets()); + } + update(); } @@ -125,13 +132,9 @@ void PartTableWidget::clear() void PartTableWidget::resizeEvent(QResizeEvent*) { - if (partitionTable()) - positionChildren(this, partitionTable()->children(), widgets()); -} - -void PartTableWidget::paintEvent(QPaintEvent*) -{ - if (partitionTable()) + if (partitionTable() == NULL || widgets().isEmpty()) + labelEmpty().resize(size()); + else positionChildren(this, partitionTable()->children(), widgets()); } diff --git a/src/gui/parttablewidget.h b/src/gui/parttablewidget.h index ed6b846..89cdc61 100644 --- a/src/gui/parttablewidget.h +++ b/src/gui/parttablewidget.h @@ -25,11 +25,11 @@ #include #include +#include class PartWidget; class PartitionTable; -class QPaintEvent; class QResizeEvent; class QMouseEvent; @@ -59,7 +59,6 @@ class PartTableWidget : public QWidget, public PartWidgetBase protected: void resizeEvent(QResizeEvent* event); - void paintEvent(QPaintEvent* event); void mousePressEvent(QMouseEvent* event); void mouseDoubleClickEvent(QMouseEvent* event); @@ -70,10 +69,14 @@ class PartTableWidget : public QWidget, public PartWidgetBase const PartitionTable* partitionTable() const { return m_PartitionTable; } + QLabel& labelEmpty() { return m_LabelEmpty; } + const QLabel& labelEmpty() const { return m_LabelEmpty; } + private: const PartitionTable* m_PartitionTable; QList m_Widgets; PartWidget* m_ActiveWidget; + QLabel m_LabelEmpty; }; #endif