2008-09-24 20:32:01 +01:00
|
|
|
/***************************************************************************
|
2010-04-12 11:55:13 +01:00
|
|
|
* Copyright (C) 2008,2010 by Volker Lanz <vl@fidra.de> *
|
2008-09-24 20:32:01 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gui/partwidget.h"
|
|
|
|
|
|
|
|
#include "util/capacity.h"
|
|
|
|
|
|
|
|
#include "core/partition.h"
|
|
|
|
|
2008-12-17 10:19:58 +00:00
|
|
|
#include "fs/filesystem.h"
|
|
|
|
|
2008-09-24 20:32:01 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kglobalsettings.h>
|
|
|
|
|
2010-02-17 19:39:24 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2008-09-24 20:32:01 +01:00
|
|
|
/** Creates a new PartWidget
|
|
|
|
@param parent pointer to the parent widget
|
2010-04-12 11:55:13 +01:00
|
|
|
@param p pointer to the Partition this widget will show. must not be NULL.
|
2008-09-24 20:32:01 +01:00
|
|
|
*/
|
2010-04-12 15:35:02 +01:00
|
|
|
PartWidget::PartWidget(QWidget* parent, const Partition* p) :
|
2010-04-12 17:14:10 +01:00
|
|
|
PartWidgetBase(parent),
|
2010-04-12 11:55:13 +01:00
|
|
|
m_Partition(p),
|
2010-04-12 15:35:02 +01:00
|
|
|
m_Active(false)
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
|
|
|
setFont(KGlobalSettings::smallestReadableFont());
|
2008-12-17 10:19:58 +00:00
|
|
|
|
2010-04-12 11:55:13 +01:00
|
|
|
setToolTip(partition().deviceNode() + '\n' + partition().fileSystem().name() + ' ' + Capacity(partition()).toString());
|
2008-12-17 10:19:58 +00:00
|
|
|
|
2008-09-24 20:32:01 +01:00
|
|
|
updateChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Updates the widget's children */
|
|
|
|
void PartWidget::updateChildren()
|
|
|
|
{
|
2010-04-12 11:55:13 +01:00
|
|
|
foreach (QWidget* w, childWidgets())
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
|
|
|
w->setVisible(false);
|
|
|
|
w->deleteLater();
|
2010-04-12 17:08:13 +01:00
|
|
|
w->setParent(NULL);
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
2010-04-12 15:35:02 +01:00
|
|
|
foreach(const Partition* child, partition().children())
|
2010-04-12 18:29:29 +01:00
|
|
|
{
|
|
|
|
QWidget* w = new PartWidget(this, child);
|
|
|
|
w->setVisible(true);
|
|
|
|
}
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2010-04-12 15:35:02 +01:00
|
|
|
positionChildren(this, partition().children(), childWidgets());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PartWidget::resizeEvent(QResizeEvent*)
|
|
|
|
{
|
2010-04-12 15:35:02 +01:00
|
|
|
positionChildren(this, partition().children(), childWidgets());
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
2010-02-17 23:00:55 +00:00
|
|
|
QColor PartWidget::activeColor(const QColor& col) const
|
|
|
|
{
|
2010-04-12 15:35:02 +01:00
|
|
|
return isActive() ? col.darker(130) : col;
|
2010-02-17 23:00:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 13:48:17 +01:00
|
|
|
void PartWidget::paintEvent(QPaintEvent*)
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
2010-04-12 11:55:13 +01:00
|
|
|
const int usedPercentage = partition().used() * 100 / partition().capacity();
|
2010-04-12 13:48:17 +01:00
|
|
|
const int w = (width() - 1 - (PartWidget::borderWidth() * 2)) * usedPercentage / 100;
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2010-04-12 13:48:17 +01:00
|
|
|
QPainter painter(this);
|
2008-09-24 20:32:01 +01:00
|
|
|
|
|
|
|
// draw border
|
2010-04-12 15:35:02 +01:00
|
|
|
painter.setPen(isActive() ? QColor(250, 250, 250) : QColor(20, 20, 20));
|
2010-04-12 11:55:13 +01:00
|
|
|
painter.setBrush(activeColor(Config::fileSystemColorCode(partition().fileSystem().type())));
|
2010-04-12 13:48:17 +01:00
|
|
|
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2010-04-12 11:55:13 +01:00
|
|
|
if (partition().roles().has(PartitionRole::Extended))
|
2008-09-24 20:32:01 +01:00
|
|
|
return;
|
|
|
|
|
2010-04-12 11:55:13 +01:00
|
|
|
if (!partition().roles().has(PartitionRole::Unallocated))
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
|
|
|
// draw free space background
|
2010-02-17 23:00:55 +00:00
|
|
|
painter.setBrush(activeColor(Config::availableSpaceColorCode()));
|
2010-04-12 13:48:17 +01:00
|
|
|
painter.drawRect(QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), width() - 1 - (PartWidget::borderWidth() * 2), height() - (PartWidget::borderHeight() * 2)));
|
2008-09-24 20:32:01 +01:00
|
|
|
|
|
|
|
// draw used space in front of that
|
2010-02-17 23:00:55 +00:00
|
|
|
painter.setBrush(activeColor(Config::usedSpaceColorCode()));
|
2010-04-12 13:48:17 +01:00
|
|
|
painter.drawRect(QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), w, height() - (PartWidget::borderHeight() * 2)));
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw name and size
|
2010-04-12 11:55:13 +01:00
|
|
|
QString text = partition().deviceNode().remove("/dev/") + '\n' + Capacity(partition()).toString();
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2010-04-12 13:48:17 +01:00
|
|
|
const QRect textRect(0, 0, width() - 1, height() - 1);
|
2008-09-24 20:32:01 +01:00
|
|
|
const QRect boundingRect = painter.boundingRect(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
|
|
|
if (boundingRect.x() > PartWidgetBase::borderWidth() && boundingRect.y() > PartWidgetBase::borderHeight())
|
|
|
|
painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
|
|
|
}
|