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>
|
2010-06-06 18:57:08 +01:00
|
|
|
#include <QStyleOptionButton>
|
2008-09-24 20:32:01 +01:00
|
|
|
|
|
|
|
#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-06-03 16:01:53 +01:00
|
|
|
m_Partition(NULL),
|
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-06-03 16:01:53 +01:00
|
|
|
init(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PartWidget::init(const Partition* p)
|
|
|
|
{
|
|
|
|
m_Partition = p;
|
|
|
|
|
|
|
|
if (partition())
|
|
|
|
setToolTip(partition()->deviceNode() + '\n' + partition()->fileSystem().name() + ' ' + Capacity(*partition()).toString());
|
|
|
|
else
|
|
|
|
setToolTip(QString());
|
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-06-03 16:01:53 +01:00
|
|
|
if (partition())
|
2010-04-12 18:29:29 +01:00
|
|
|
{
|
2010-06-03 16:01:53 +01:00
|
|
|
foreach (QWidget* w, childWidgets())
|
|
|
|
{
|
|
|
|
w->setVisible(false);
|
|
|
|
w->deleteLater();
|
|
|
|
w->setParent(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(const Partition* child, partition()->children())
|
|
|
|
{
|
|
|
|
QWidget* w = new PartWidget(this, child);
|
|
|
|
w->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
positionChildren(this, partition()->children(), childWidgets());
|
2010-04-12 18:29:29 +01:00
|
|
|
}
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PartWidget::resizeEvent(QResizeEvent*)
|
|
|
|
{
|
2010-06-03 16:01:53 +01:00
|
|
|
if (partition())
|
|
|
|
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-06-03 16:01:53 +01:00
|
|
|
if (partition() == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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);
|
2010-06-06 18:57:08 +01:00
|
|
|
painter.setRenderHints(QPainter::Antialiasing);
|
|
|
|
drawGradient( &painter, activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())),QRect(0, 0, width() - 1, height() - 1));
|
2008-09-24 20:32:01 +01:00
|
|
|
|
2010-06-03 16:01:53 +01:00
|
|
|
if (partition()->roles().has(PartitionRole::Extended))
|
2008-09-24 20:32:01 +01:00
|
|
|
return;
|
|
|
|
|
2010-06-03 16:01:53 +01:00
|
|
|
if (!partition()->roles().has(PartitionRole::Unallocated))
|
2008-09-24 20:32:01 +01:00
|
|
|
{
|
|
|
|
// draw free space background
|
2010-06-06 18:57:08 +01:00
|
|
|
drawGradient( &painter, activeColor(Config::availableSpaceColorCode()), 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-06-06 18:57:08 +01:00
|
|
|
drawGradient( &painter, activeColor(Config::usedSpaceColorCode()), QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), w, height() - (PartWidget::borderHeight() * 2)));
|
2008-09-24 20:32:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw name and size
|
2010-06-03 16:01:53 +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);
|
|
|
|
}
|
2010-06-06 18:57:08 +01:00
|
|
|
|
|
|
|
void PartWidget::drawGradient( QPainter* painter, const QColor& color, const QRect& rect ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
if( rect.width() < 8 ) return;
|
|
|
|
QStyleOptionButton option;
|
|
|
|
option.initFrom(this);
|
|
|
|
option.rect = rect;
|
|
|
|
option.palette.setColor( QPalette::Button, color );
|
|
|
|
option.palette.setColor( QPalette::Window, color );
|
|
|
|
option.state |= QStyle::State_Raised;
|
|
|
|
option.state &= ~QStyle::State_MouseOver;
|
|
|
|
|
|
|
|
style()->drawControl(QStyle::CE_PushButtonBevel, &option, painter, this);
|
|
|
|
|
|
|
|
}
|