Allow the info pane dock to be docked in any dock area.

Adjust to being docked at the top or bottom by layouting the information in
more columns than just two.

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1073610
This commit is contained in:
Volker Lanz 2010-01-12 14:36:16 +00:00
parent b394afa487
commit 8694682e72
4 changed files with 100 additions and 76 deletions

View File

@ -29,6 +29,7 @@
#include <QGridLayout>
#include <QLabel>
#include <QFrame>
#include <QDockWidget>
#include <kglobal.h>
#include <kglobalsettings.h>
@ -52,7 +53,7 @@ void InfoPane::clear()
qDeleteAll(findChildren<QFrame*>());
}
int InfoPane::createHeader(const QString& title)
int InfoPane::createHeader(const QString& title, const int num_cols)
{
int y = 0;
@ -62,17 +63,17 @@ int InfoPane::createHeader(const QString& title)
font.setWeight(75);
label->setFont(font);
label->setAlignment(Qt::AlignCenter);
gridLayout().addWidget(label, y++, 0, 1, 2);
gridLayout().addWidget(label, y++, 0, 1, num_cols);
QFrame* line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
gridLayout().addWidget(line, y++, 0, 1, 2);
gridLayout().addWidget(line, y++, 0, 1, num_cols);
return y;
}
void InfoPane::createLabels(const QString& title, const QString& value, int y)
void InfoPane::createLabels(const QString& title, const QString& value, const int num_cols, int& x, int& y)
{
QLabel* labelTitle = new QLabel(title, this);
labelTitle->setFont(KGlobalSettings::smallestReadableFont());
@ -84,42 +85,54 @@ void InfoPane::createLabels(const QString& title, const QString& value, int y)
palette.setColor(QPalette::Foreground, f);
labelTitle->setPalette(palette);
gridLayout().addWidget(labelTitle, y, 0, 1, 1);
gridLayout().addWidget(labelTitle, y, x, 1, 1);
QLabel* labelValue = new QLabel(value, this);
labelValue->setTextInteractionFlags(Qt::TextBrowserInteraction);
labelValue->setFont(KGlobalSettings::smallestReadableFont());
gridLayout().addWidget(labelValue, y, 1, 1, 1);
gridLayout().addWidget(labelValue, y, x + 1, 1, 1);
x += 2;
if (x % num_cols == 0)
{
x = 0;
y++;
}
}
/** Shows information about a Partition in the InfoPane
@param area the current area the widget's dock is in
@param p the Partition to show information about
*/
void InfoPane::showPartition(const Partition& p)
void InfoPane::showPartition(Qt::DockWidgetArea area, const Partition& p)
{
clear();
parentWidget()->setWindowTitle(i18nc("@title:window", "Partition Information"));
int y = createHeader(p.deviceNode());
createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), y++);
createLabels(i18nc("@label partition", "Capacity:"), Capacity(p).toString(), y++);
createLabels(i18nc("@label partition", "Available:"), Capacity(p, Capacity::Available).toString(), y++);
createLabels(i18nc("@label partition", "Used:"), Capacity(p, Capacity::Used).toString(), y++);
createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), y++);
createLabels(i18nc("@label partition", "Last sector:"), KGlobal::locale()->formatNumber(p.lastSector(), 0), y++);
createLabels(i18nc("@label partition", "Number of sectors:"), KGlobal::locale()->formatNumber(p.length(), 0), y++);
int x = 0;
int y = createHeader(p.deviceNode(), cols(area));
createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
createLabels(i18nc("@label partition", "Capacity:"), Capacity(p).toString(), cols(area), x, y);
createLabels(i18nc("@label partition", "Available:"), Capacity(p, Capacity::Available).toString(), cols(area), x, y);
createLabels(i18nc("@label partition", "Used:"), Capacity(p, Capacity::Used).toString(), cols(area), x, y);
createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Last sector:"), KGlobal::locale()->formatNumber(p.lastSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Number of sectors:"), KGlobal::locale()->formatNumber(p.length(), 0), cols(area), x, y);
}
/** Shows information about a Device in the InfoPane
@param area the current area the widget's dock is in
@param d the Device to show information about
*/
void InfoPane::showDevice(const Device& d)
void InfoPane::showDevice(Qt::DockWidgetArea area, const Device& d)
{
clear();
parentWidget()->setWindowTitle(i18nc("@title:window", "Device Information"));
int y = createHeader(d.name());
createLabels(i18nc("@label device", "Path:"), d.deviceNode(), y++);
int x = 0;
int y = createHeader(d.name(), cols(area));
createLabels(i18nc("@label device", "Path:"), d.deviceNode(), cols(area), x, y);
QString type = "---";
QString maxPrimaries = "---";
@ -132,13 +145,25 @@ void InfoPane::showDevice(const Device& d)
maxPrimaries = QString("%1/%2").arg(d.partitionTable()->numPrimaries()).arg(d.partitionTable()->maxPrimaries());
}
createLabels(i18nc("@label device", "Type:"), type, y++);
createLabels(i18nc("@label device", "Capacity:"), Capacity(d).toString(), y++);
createLabels(i18nc("@label device", "Total sectors:"), KGlobal::locale()->formatNumber(d.totalSectors(), 0), y++);
createLabels(i18nc("@label device", "Heads:"), QString::number(d.heads()), y++);
createLabels(i18nc("@label device", "Cylinders:"), KGlobal::locale()->formatNumber(d.cylinders(), 0), y++);
createLabels(i18nc("@label device", "Sectors:"), KGlobal::locale()->formatNumber(d.sectorsPerTrack(), 0), y++);
createLabels(i18nc("@label device", "Sector size:"), Capacity(d.sectorSize()).toString(Capacity::Byte, Capacity::AppendUnit), y++);
createLabels(i18nc("@label device", "Cylinder size:"), i18ncp("@label", "1 Sector", "%1 Sectors", d.cylinderSize()), y++);
createLabels(i18nc("@label device", "Primaries/Max:"), maxPrimaries, y++);
createLabels(i18nc("@label device", "Type:"), type, cols(area), x, y);
createLabels(i18nc("@label device", "Capacity:"), Capacity(d).toString(), cols(area), x, y);
createLabels(i18nc("@label device", "Total sectors:"), KGlobal::locale()->formatNumber(d.totalSectors(), 0), cols(area), x, y);
createLabels(i18nc("@label device", "Heads:"), QString::number(d.heads()), cols(area), x, y);
createLabels(i18nc("@label device", "Cylinders:"), KGlobal::locale()->formatNumber(d.cylinders(), 0), cols(area), x, y);
createLabels(i18nc("@label device", "Sectors:"), KGlobal::locale()->formatNumber(d.sectorsPerTrack(), 0), cols(area), x, y);
createLabels(i18nc("@label device", "Sector size:"), Capacity(d.sectorSize()).toString(Capacity::Byte, Capacity::AppendUnit), cols(area), x, y);
createLabels(i18nc("@label device", "Cylinder size:"), i18ncp("@label", "1 Sector", "%1 Sectors", d.cylinderSize()), cols(area), x, y);
createLabels(i18nc("@label device", "Primaries/Max:"), maxPrimaries, cols(area), x, y);
}
quint32 InfoPane::cols(Qt::DockWidgetArea area) const
{
QDockWidget* dockWidget = qobject_cast<QDockWidget*>(parentWidget());
Q_ASSERT(dockWidget);
if (dockWidget->isFloating() || area == Qt::TopDockWidgetArea || area == Qt::BottomDockWidgetArea)
return 6;
return 2;
}

View File

@ -44,14 +44,15 @@ class InfoPane : public QWidget
InfoPane(QWidget* parent);
public:
void showPartition(const Partition& p);
void showDevice(const Device& d);
void showPartition(Qt::DockWidgetArea area, const Partition& p);
void showDevice(Qt::DockWidgetArea area, const Device& d);
void clear();
protected:
void createLabels(const QString& title, const QString& value, int y);
int createHeader(const QString& title);
void createLabels(const QString& title, const QString& value, const int cols, int& x, int& y);
int createHeader(const QString& title, const int cols);
QGridLayout& gridLayout() { Q_ASSERT(m_GridLayout); return *m_GridLayout; }
quint32 cols(Qt::DockWidgetArea area) const;
private:
QGridLayout* m_GridLayout;

View File

@ -167,7 +167,7 @@ void MainWindow::updateDevices()
listDevices().updateDevices();
if (pmWidget().selectedDevice())
infoPane().showDevice(*pmWidget().selectedDevice());
infoPane().showDevice(dockWidgetArea(&dockInformation()), *pmWidget().selectedDevice());
else
infoPane().clear();
@ -195,9 +195,9 @@ void MainWindow::updateWindowTitle()
void MainWindow::updateSelection(const Partition* p)
{
if (p)
infoPane().showPartition(*p);
infoPane().showPartition(dockWidgetArea(&dockInformation()), *p);
else if (pmWidget().selectedDevice())
infoPane().showDevice(*pmWidget().selectedDevice());
infoPane().showDevice(dockWidgetArea(&dockInformation()), *pmWidget().selectedDevice());
else
infoPane().clear();

View File

@ -1,7 +1,8 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindowBase</class>
<widget class="QMainWindow" name="MainWindowBase" >
<property name="geometry" >
<widget class="QMainWindow" name="MainWindowBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@ -9,80 +10,77 @@
<height>684</height>
</rect>
</property>
<property name="windowTitle" >
<string comment="@title:window" >KDE Partition Manager</string>
<property name="windowTitle">
<string comment="@title:window">KDE Partition Manager</string>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QVBoxLayout" name="verticalLayout" >
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="PartitionManagerWidget" native="1" name="m_PartitionManagerWidget" />
<widget class="PartitionManagerWidget" name="m_PartitionManagerWidget" native="true"/>
</item>
</layout>
</widget>
<widget class="QDockWidget" name="m_DockDevices" >
<property name="allowedAreas" >
<widget class="QDockWidget" name="m_DockDevices">
<property name="allowedAreas">
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle" >
<string comment="@title:window" >Devices</string>
<property name="windowTitle">
<string comment="@title:window">Devices</string>
</property>
<attribute name="dockWidgetArea" >
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="m_DockDevicesContents" >
<layout class="QVBoxLayout" >
<widget class="QWidget" name="m_DockDevicesContents">
<layout class="QVBoxLayout">
<item>
<widget class="ListDevices" native="1" name="m_ListDevices" />
<widget class="ListDevices" name="m_ListDevices" native="true"/>
</item>
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="m_DockOperations" >
<property name="allowedAreas" >
<widget class="QDockWidget" name="m_DockOperations">
<property name="allowedAreas">
<set>Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle" >
<string comment="@title:window" >Pending Operations</string>
<property name="windowTitle">
<string comment="@title:window">Pending Operations</string>
</property>
<attribute name="dockWidgetArea" >
<attribute name="dockWidgetArea">
<number>8</number>
</attribute>
<widget class="QWidget" name="m_DockOperationsContents" >
<layout class="QVBoxLayout" name="verticalLayout_2" >
<widget class="QWidget" name="m_DockOperationsContents">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="ListOperations" native="1" name="m_ListOperations" />
<widget class="ListOperations" name="m_ListOperations" native="true"/>
</item>
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="m_DockInformation" >
<property name="allowedAreas" >
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
<widget class="QDockWidget" name="m_DockInformation">
<property name="windowTitle">
<string comment="@title:window">Information</string>
</property>
<property name="windowTitle" >
<string comment="@title:window" >Information</string>
</property>
<attribute name="dockWidgetArea" >
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="m_DockInformationContents" >
<layout class="QGridLayout" name="_2" />
<widget class="QWidget" name="m_DockInformationContents">
<layout class="QGridLayout" name="_2"/>
</widget>
</widget>
<widget class="QDockWidget" name="m_DockLog" >
<property name="allowedAreas" >
<widget class="QDockWidget" name="m_DockLog">
<property name="allowedAreas">
<set>Qt::BottomDockWidgetArea|Qt::TopDockWidgetArea</set>
</property>
<property name="windowTitle" >
<string comment="@title:window" >Log Output</string>
<property name="windowTitle">
<string comment="@title:window">Log Output</string>
</property>
<attribute name="dockWidgetArea" >
<attribute name="dockWidgetArea">
<number>8</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents" >
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="TreeLog" native="1" name="m_TreeLog" />
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="TreeLog" name="m_TreeLog" native="true"/>
</item>
</layout>
</widget>