Changed rendering of

- partwidget, to use the same appearance as buttons
- partresizewidget, to use a 'sunken' frame, and same appearance as QSplitter for the resize handlers.

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1135173
This commit is contained in:
Hugo Pereira Da Costa 2010-06-06 17:57:08 +00:00
parent 0753131834
commit 16de8b9034
4 changed files with 59 additions and 18 deletions

View File

@ -31,11 +31,14 @@
#include <QMouseEvent>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QStyleOptionToolBar>
#include <QStyleOptionFrameV3>
#include <QStyleOptionButton>
#include <QTextStream>
#include <kdebug.h>
#include <kcolorscheme.h>
const qint32 PartResizerWidget::m_HandleWidth = 16;
const qint32 PartResizerWidget::m_HandleHeight = 59;
/** Creates a new PartResizerWidget
@ -85,9 +88,24 @@ void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 ma
setMinimumLength(qMax(partition().sectorsUsed(), partition().minimumSectors()));
setMaximumLength(qMin(totalSectors(), partition().maximumSectors()));
// set margins to accomodate for top/bottom button asymetric layouts
QStyleOptionButton bOpt;
bOpt.initFrom( this );
QRect buttonRect( style()->subElementRect( QStyle::SE_PushButtonContents, &bOpt ) );
int asym = (rect().bottom() - buttonRect.bottom()) - (buttonRect.top() - rect().top());
if( asym > 0 ) setContentsMargins( 0, asym, 0, 0 );
else setContentsMargins( 0, 0, 0, asym );
/** @todo get real pixmaps for the handles */
QPixmap pixmap(handleWidth(), handleHeight());
pixmap.fill(QColor(0x44, 0x44, 0x44));
pixmap.fill( Qt::transparent );
{
QPainter p( &pixmap );
QStyleOption opt;
opt.state |= QStyle::State_Horizontal;
opt.rect = pixmap.rect().adjusted( 0, 2, 0, -2 );
style()->drawControl(QStyle::CE_Splitter, &opt, &p, this);
}
leftHandle().setPixmap(pixmap);
rightHandle().setPixmap(pixmap);
@ -128,8 +146,9 @@ int PartResizerWidget::partWidgetWidth() const
void PartResizerWidget::updatePositions()
{
partWidget().move(partWidgetStart(), 0);
partWidget().resize(partWidgetWidth(), height() - 1);
QMargins margins( contentsMargins() );
partWidget().move(partWidgetStart() + margins.left(), margins.top());
partWidget().resize(partWidgetWidth() - margins.left() - margins.right(), height() - margins.top() - margins.bottom() );
leftHandle().move(partWidgetStart() - leftHandle().width(), 0);
rightHandle().move(partWidgetStart() + partWidgetWidth(), 0);
@ -144,10 +163,18 @@ void PartResizerWidget::resizeEvent(QResizeEvent* event)
void PartResizerWidget::paintEvent(QPaintEvent*)
{
// draw sunken frame
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0x99, 0x99, 0x99));
painter.drawRect(QRect(handleWidth(), 0, width() - (2 * handleWidth()) - 1, height() - 1));
QStyleOptionFrameV3 opt;
opt.initFrom( this );
opt.frameShape = QFrame::StyledPanel;
opt.state |= QStyle::State_Sunken;
// disable mouse over and focus state
opt.state &= ~QStyle::State_MouseOver;
opt.state &= ~QStyle::State_HasFocus;
opt.rect.adjust( handleWidth(), 0, -handleWidth()-1, -1 );
style()->drawControl(QStyle::CE_ShapedFrame, &opt, &painter, this);
}
void PartResizerWidget::mousePressEvent(QMouseEvent* event)

View File

@ -23,6 +23,7 @@
#include <QWidget>
#include <QLabel>
#include <QStyle>
class Partition;
class PartWidget;
@ -79,7 +80,7 @@ class PartResizerWidget : public QWidget
bool align() const { return m_Align; } /**< @return true if the Partition is to be aligned */
void setAlign(bool b) { m_Align = b; } /**< @param b the new value for aligning the Partition */
static qint32 handleWidth() { return m_HandleWidth; } /**< @return the handle width in pixels */
qint32 handleWidth() const { return style()->pixelMetric( QStyle::PM_SplitterWidth ); } /**< @return the handle width in pixels */
static qint32 handleHeight() { return m_HandleHeight; } /**< @return the handle height in pixels */
signals:
@ -152,7 +153,6 @@ class PartResizerWidget : public QWidget
bool m_ReadOnly;
bool m_Align;
static const qint32 m_HandleWidth;
static const qint32 m_HandleHeight;
};

View File

@ -26,6 +26,7 @@
#include "fs/filesystem.h"
#include <QPainter>
#include <QStyleOptionButton>
#include <kdebug.h>
#include <kglobalsettings.h>
@ -100,11 +101,8 @@ void PartWidget::paintEvent(QPaintEvent*)
const int w = (width() - 1 - (PartWidget::borderWidth() * 2)) * usedPercentage / 100;
QPainter painter(this);
// draw border
painter.setPen(isActive() ? QColor(250, 250, 250) : QColor(20, 20, 20));
painter.setBrush(activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())));
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
painter.setRenderHints(QPainter::Antialiasing);
drawGradient( &painter, activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())),QRect(0, 0, width() - 1, height() - 1));
if (partition()->roles().has(PartitionRole::Extended))
return;
@ -112,12 +110,10 @@ void PartWidget::paintEvent(QPaintEvent*)
if (!partition()->roles().has(PartitionRole::Unallocated))
{
// draw free space background
painter.setBrush(activeColor(Config::availableSpaceColorCode()));
painter.drawRect(QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), width() - 1 - (PartWidget::borderWidth() * 2), height() - (PartWidget::borderHeight() * 2)));
drawGradient( &painter, activeColor(Config::availableSpaceColorCode()), QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), width() - 1 - (PartWidget::borderWidth() * 2), height() - (PartWidget::borderHeight() * 2)));
// draw used space in front of that
painter.setBrush(activeColor(Config::usedSpaceColorCode()));
painter.drawRect(QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), w, height() - (PartWidget::borderHeight() * 2)));
drawGradient( &painter, activeColor(Config::usedSpaceColorCode()), QRect(PartWidget::borderWidth(), PartWidget::borderHeight(), w, height() - (PartWidget::borderHeight() * 2)));
}
// draw name and size
@ -128,3 +124,19 @@ void PartWidget::paintEvent(QPaintEvent*)
if (boundingRect.x() > PartWidgetBase::borderWidth() && boundingRect.y() > PartWidgetBase::borderHeight())
painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
}
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);
}

View File

@ -57,6 +57,8 @@ class PartWidget : public PartWidgetBase
QColor activeColor(const QColor& col) const;
void drawGradient( QPainter*, const QColor&, const QRect& ) const;
private:
const Partition* m_Partition;
bool m_Active;