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 <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QFrame> #include <QFrame>
#include <QDockWidget>
#include <kglobal.h> #include <kglobal.h>
#include <kglobalsettings.h> #include <kglobalsettings.h>
@ -52,7 +53,7 @@ void InfoPane::clear()
qDeleteAll(findChildren<QFrame*>()); qDeleteAll(findChildren<QFrame*>());
} }
int InfoPane::createHeader(const QString& title) int InfoPane::createHeader(const QString& title, const int num_cols)
{ {
int y = 0; int y = 0;
@ -62,17 +63,17 @@ int InfoPane::createHeader(const QString& title)
font.setWeight(75); font.setWeight(75);
label->setFont(font); label->setFont(font);
label->setAlignment(Qt::AlignCenter); label->setAlignment(Qt::AlignCenter);
gridLayout().addWidget(label, y++, 0, 1, 2); gridLayout().addWidget(label, y++, 0, 1, num_cols);
QFrame* line = new QFrame(this); QFrame* line = new QFrame(this);
line->setFrameShape(QFrame::HLine); line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken); line->setFrameShadow(QFrame::Sunken);
gridLayout().addWidget(line, y++, 0, 1, 2); gridLayout().addWidget(line, y++, 0, 1, num_cols);
return y; 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); QLabel* labelTitle = new QLabel(title, this);
labelTitle->setFont(KGlobalSettings::smallestReadableFont()); labelTitle->setFont(KGlobalSettings::smallestReadableFont());
@ -84,42 +85,54 @@ void InfoPane::createLabels(const QString& title, const QString& value, int y)
palette.setColor(QPalette::Foreground, f); palette.setColor(QPalette::Foreground, f);
labelTitle->setPalette(palette); labelTitle->setPalette(palette);
gridLayout().addWidget(labelTitle, y, 0, 1, 1); gridLayout().addWidget(labelTitle, y, x, 1, 1);
QLabel* labelValue = new QLabel(value, this); QLabel* labelValue = new QLabel(value, this);
labelValue->setTextInteractionFlags(Qt::TextBrowserInteraction); labelValue->setTextInteractionFlags(Qt::TextBrowserInteraction);
labelValue->setFont(KGlobalSettings::smallestReadableFont()); 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 /** 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 @param p the Partition to show information about
*/ */
void InfoPane::showPartition(const Partition& p) void InfoPane::showPartition(Qt::DockWidgetArea area, const Partition& p)
{ {
clear(); clear();
parentWidget()->setWindowTitle(i18nc("@title:window", "Partition Information")); parentWidget()->setWindowTitle(i18nc("@title:window", "Partition Information"));
int y = createHeader(p.deviceNode()); int x = 0;
createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), y++); int y = createHeader(p.deviceNode(), cols(area));
createLabels(i18nc("@label partition", "Capacity:"), Capacity(p).toString(), y++); createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
createLabels(i18nc("@label partition", "Available:"), Capacity(p, Capacity::Available).toString(), y++); createLabels(i18nc("@label partition", "Capacity:"), Capacity(p).toString(), cols(area), x, y);
createLabels(i18nc("@label partition", "Used:"), Capacity(p, Capacity::Used).toString(), y++); createLabels(i18nc("@label partition", "Available:"), Capacity(p, Capacity::Available).toString(), cols(area), x, y);
createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), y++); createLabels(i18nc("@label partition", "Used:"), Capacity(p, Capacity::Used).toString(), cols(area), x, y);
createLabels(i18nc("@label partition", "Last sector:"), KGlobal::locale()->formatNumber(p.lastSector(), 0), y++); createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Number of sectors:"), KGlobal::locale()->formatNumber(p.length(), 0), 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 /** 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 @param d the Device to show information about
*/ */
void InfoPane::showDevice(const Device& d) void InfoPane::showDevice(Qt::DockWidgetArea area, const Device& d)
{ {
clear(); clear();
parentWidget()->setWindowTitle(i18nc("@title:window", "Device Information")); parentWidget()->setWindowTitle(i18nc("@title:window", "Device Information"));
int y = createHeader(d.name()); int x = 0;
createLabels(i18nc("@label device", "Path:"), d.deviceNode(), y++); int y = createHeader(d.name(), cols(area));
createLabels(i18nc("@label device", "Path:"), d.deviceNode(), cols(area), x, y);
QString type = "---"; QString type = "---";
QString maxPrimaries = "---"; QString maxPrimaries = "---";
@ -132,13 +145,25 @@ void InfoPane::showDevice(const Device& d)
maxPrimaries = QString("%1/%2").arg(d.partitionTable()->numPrimaries()).arg(d.partitionTable()->maxPrimaries()); maxPrimaries = QString("%1/%2").arg(d.partitionTable()->numPrimaries()).arg(d.partitionTable()->maxPrimaries());
} }
createLabels(i18nc("@label device", "Type:"), type, y++); createLabels(i18nc("@label device", "Type:"), type, cols(area), x, y);
createLabels(i18nc("@label device", "Capacity:"), Capacity(d).toString(), 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), 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()), 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), 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), 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), 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()), 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, 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); InfoPane(QWidget* parent);
public: public:
void showPartition(const Partition& p); void showPartition(Qt::DockWidgetArea area, const Partition& p);
void showDevice(const Device& d); void showDevice(Qt::DockWidgetArea area, const Device& d);
void clear(); void clear();
protected: protected:
void createLabels(const QString& title, const QString& value, int y); void createLabels(const QString& title, const QString& value, const int cols, int& x, int& y);
int createHeader(const QString& title); int createHeader(const QString& title, const int cols);
QGridLayout& gridLayout() { Q_ASSERT(m_GridLayout); return *m_GridLayout; } QGridLayout& gridLayout() { Q_ASSERT(m_GridLayout); return *m_GridLayout; }
quint32 cols(Qt::DockWidgetArea area) const;
private: private:
QGridLayout* m_GridLayout; QGridLayout* m_GridLayout;

View File

@ -167,7 +167,7 @@ void MainWindow::updateDevices()
listDevices().updateDevices(); listDevices().updateDevices();
if (pmWidget().selectedDevice()) if (pmWidget().selectedDevice())
infoPane().showDevice(*pmWidget().selectedDevice()); infoPane().showDevice(dockWidgetArea(&dockInformation()), *pmWidget().selectedDevice());
else else
infoPane().clear(); infoPane().clear();
@ -195,9 +195,9 @@ void MainWindow::updateWindowTitle()
void MainWindow::updateSelection(const Partition* p) void MainWindow::updateSelection(const Partition* p)
{ {
if (p) if (p)
infoPane().showPartition(*p); infoPane().showPartition(dockWidgetArea(&dockInformation()), *p);
else if (pmWidget().selectedDevice()) else if (pmWidget().selectedDevice())
infoPane().showDevice(*pmWidget().selectedDevice()); infoPane().showDevice(dockWidgetArea(&dockInformation()), *pmWidget().selectedDevice());
else else
infoPane().clear(); 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> <class>MainWindowBase</class>
<widget class="QMainWindow" name="MainWindowBase" > <widget class="QMainWindow" name="MainWindowBase">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,80 +10,77 @@
<height>684</height> <height>684</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string comment="@title:window" >KDE Partition Manager</string> <string comment="@title:window">KDE Partition Manager</string>
</property> </property>
<widget class="QWidget" name="centralwidget" > <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" > <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="PartitionManagerWidget" native="1" name="m_PartitionManagerWidget" /> <widget class="PartitionManagerWidget" name="m_PartitionManagerWidget" native="true"/>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QDockWidget" name="m_DockDevices" > <widget class="QDockWidget" name="m_DockDevices">
<property name="allowedAreas" > <property name="allowedAreas">
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> <set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string comment="@title:window" >Devices</string> <string comment="@title:window">Devices</string>
</property> </property>
<attribute name="dockWidgetArea" > <attribute name="dockWidgetArea">
<number>1</number> <number>1</number>
</attribute> </attribute>
<widget class="QWidget" name="m_DockDevicesContents" > <widget class="QWidget" name="m_DockDevicesContents">
<layout class="QVBoxLayout" > <layout class="QVBoxLayout">
<item> <item>
<widget class="ListDevices" native="1" name="m_ListDevices" /> <widget class="ListDevices" name="m_ListDevices" native="true"/>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QDockWidget" name="m_DockOperations" > <widget class="QDockWidget" name="m_DockOperations">
<property name="allowedAreas" > <property name="allowedAreas">
<set>Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> <set>Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string comment="@title:window" >Pending Operations</string> <string comment="@title:window">Pending Operations</string>
</property> </property>
<attribute name="dockWidgetArea" > <attribute name="dockWidgetArea">
<number>8</number> <number>8</number>
</attribute> </attribute>
<widget class="QWidget" name="m_DockOperationsContents" > <widget class="QWidget" name="m_DockOperationsContents">
<layout class="QVBoxLayout" name="verticalLayout_2" > <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="ListOperations" native="1" name="m_ListOperations" /> <widget class="ListOperations" name="m_ListOperations" native="true"/>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QDockWidget" name="m_DockInformation" > <widget class="QDockWidget" name="m_DockInformation">
<property name="allowedAreas" > <property name="windowTitle">
<set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> <string comment="@title:window">Information</string>
</property> </property>
<property name="windowTitle" > <attribute name="dockWidgetArea">
<string comment="@title:window" >Information</string>
</property>
<attribute name="dockWidgetArea" >
<number>1</number> <number>1</number>
</attribute> </attribute>
<widget class="QWidget" name="m_DockInformationContents" > <widget class="QWidget" name="m_DockInformationContents">
<layout class="QGridLayout" name="_2" /> <layout class="QGridLayout" name="_2"/>
</widget> </widget>
</widget> </widget>
<widget class="QDockWidget" name="m_DockLog" > <widget class="QDockWidget" name="m_DockLog">
<property name="allowedAreas" > <property name="allowedAreas">
<set>Qt::BottomDockWidgetArea|Qt::TopDockWidgetArea</set> <set>Qt::BottomDockWidgetArea|Qt::TopDockWidgetArea</set>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string comment="@title:window" >Log Output</string> <string comment="@title:window">Log Output</string>
</property> </property>
<attribute name="dockWidgetArea" > <attribute name="dockWidgetArea">
<number>8</number> <number>8</number>
</attribute> </attribute>
<widget class="QWidget" name="dockWidgetContents" > <widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout" > <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" > <item row="0" column="0">
<widget class="TreeLog" native="1" name="m_TreeLog" /> <widget class="TreeLog" name="m_TreeLog" native="true"/>
</item> </item>
</layout> </layout>
</widget> </widget>