integrate Hugo's new code a little better, mainly white space.
move implementation of handleWidget() to cpp file to avoid an include add credit to KAboutData svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1135182
This commit is contained in:
parent
16de8b9034
commit
29f73d29fa
|
@ -34,7 +34,6 @@
|
||||||
#include <QStyleOptionToolBar>
|
#include <QStyleOptionToolBar>
|
||||||
#include <QStyleOptionFrameV3>
|
#include <QStyleOptionFrameV3>
|
||||||
#include <QStyleOptionButton>
|
#include <QStyleOptionButton>
|
||||||
#include <QTextStream>
|
|
||||||
|
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
#include <kcolorscheme.h>
|
#include <kcolorscheme.h>
|
||||||
|
@ -88,22 +87,25 @@ void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 ma
|
||||||
setMinimumLength(qMax(partition().sectorsUsed(), partition().minimumSectors()));
|
setMinimumLength(qMax(partition().sectorsUsed(), partition().minimumSectors()));
|
||||||
setMaximumLength(qMin(totalSectors(), partition().maximumSectors()));
|
setMaximumLength(qMin(totalSectors(), partition().maximumSectors()));
|
||||||
|
|
||||||
// set margins to accomodate for top/bottom button asymetric layouts
|
// set margins to accomodate for top/bottom button asymmetric layouts
|
||||||
QStyleOptionButton bOpt;
|
QStyleOptionButton bOpt;
|
||||||
bOpt.initFrom( this );
|
bOpt.initFrom(this);
|
||||||
QRect buttonRect( style()->subElementRect( QStyle::SE_PushButtonContents, &bOpt ) );
|
|
||||||
int asym = (rect().bottom() - buttonRect.bottom()) - (buttonRect.top() - rect().top());
|
QRect buttonRect(style()->subElementRect(QStyle::SE_PushButtonContents, &bOpt));
|
||||||
if( asym > 0 ) setContentsMargins( 0, asym, 0, 0 );
|
|
||||||
else setContentsMargins( 0, 0, 0, asym );
|
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());
|
QPixmap pixmap(handleWidth(), handleHeight());
|
||||||
pixmap.fill( Qt::transparent );
|
pixmap.fill(Qt::transparent);
|
||||||
{
|
{
|
||||||
QPainter p( &pixmap );
|
QPainter p(&pixmap);
|
||||||
QStyleOption opt;
|
QStyleOption opt;
|
||||||
opt.state |= QStyle::State_Horizontal;
|
opt.state |= QStyle::State_Horizontal;
|
||||||
opt.rect = pixmap.rect().adjusted( 0, 2, 0, -2 );
|
opt.rect = pixmap.rect().adjusted(0, 2, 0, -2);
|
||||||
style()->drawControl(QStyle::CE_Splitter, &opt, &p, this);
|
style()->drawControl(QStyle::CE_Splitter, &opt, &p, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +131,11 @@ void PartResizerWidget::init(Device& d, Partition& p, qint64 minFirst, qint64 ma
|
||||||
updatePositions();
|
updatePositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint32 PartResizerWidget::handleWidth() const
|
||||||
|
{
|
||||||
|
return style()->pixelMetric(QStyle::PM_SplitterWidth);
|
||||||
|
}
|
||||||
|
|
||||||
qint64 PartResizerWidget::sectorsPerPixel() const
|
qint64 PartResizerWidget::sectorsPerPixel() const
|
||||||
{
|
{
|
||||||
return totalSectors() / (width() - 2 * handleWidth());
|
return totalSectors() / (width() - 2 * handleWidth());
|
||||||
|
@ -146,10 +153,13 @@ int PartResizerWidget::partWidgetWidth() const
|
||||||
|
|
||||||
void PartResizerWidget::updatePositions()
|
void PartResizerWidget::updatePositions()
|
||||||
{
|
{
|
||||||
QMargins margins( contentsMargins() );
|
QMargins margins(contentsMargins());
|
||||||
|
|
||||||
partWidget().move(partWidgetStart() + margins.left(), margins.top());
|
partWidget().move(partWidgetStart() + margins.left(), margins.top());
|
||||||
partWidget().resize(partWidgetWidth() - margins.left() - margins.right(), height() - margins.top() - margins.bottom() );
|
partWidget().resize(partWidgetWidth() - margins.left() - margins.right(), height() - margins.top() - margins.bottom());
|
||||||
|
|
||||||
leftHandle().move(partWidgetStart() - leftHandle().width(), 0);
|
leftHandle().move(partWidgetStart() - leftHandle().width(), 0);
|
||||||
|
|
||||||
rightHandle().move(partWidgetStart() + partWidgetWidth(), 0);
|
rightHandle().move(partWidgetStart() + partWidgetWidth(), 0);
|
||||||
|
|
||||||
partWidget().update();
|
partWidget().update();
|
||||||
|
@ -166,14 +176,14 @@ void PartResizerWidget::paintEvent(QPaintEvent*)
|
||||||
// draw sunken frame
|
// draw sunken frame
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QStyleOptionFrameV3 opt;
|
QStyleOptionFrameV3 opt;
|
||||||
opt.initFrom( this );
|
opt.initFrom(this);
|
||||||
opt.frameShape = QFrame::StyledPanel;
|
opt.frameShape = QFrame::StyledPanel;
|
||||||
opt.state |= QStyle::State_Sunken;
|
opt.state |= QStyle::State_Sunken;
|
||||||
|
|
||||||
// disable mouse over and focus state
|
// disable mouse over and focus state
|
||||||
opt.state &= ~QStyle::State_MouseOver;
|
opt.state &= ~QStyle::State_MouseOver;
|
||||||
opt.state &= ~QStyle::State_HasFocus;
|
opt.state &= ~QStyle::State_HasFocus;
|
||||||
opt.rect.adjust( handleWidth(), 0, -handleWidth()-1, -1 );
|
opt.rect.adjust(handleWidth(), 0, -handleWidth() - 1, -1);
|
||||||
style()->drawControl(QStyle::CE_ShapedFrame, &opt, &painter, this);
|
style()->drawControl(QStyle::CE_ShapedFrame, &opt, &painter, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QStyle>
|
|
||||||
|
|
||||||
class Partition;
|
class Partition;
|
||||||
class PartWidget;
|
class PartWidget;
|
||||||
|
@ -80,7 +79,7 @@ class PartResizerWidget : public QWidget
|
||||||
bool align() const { return m_Align; } /**< @return true if the Partition is to be aligned */
|
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 */
|
void setAlign(bool b) { m_Align = b; } /**< @param b the new value for aligning the Partition */
|
||||||
|
|
||||||
qint32 handleWidth() const { return style()->pixelMetric( QStyle::PM_SplitterWidth ); } /**< @return the handle width in pixels */
|
qint32 handleWidth() const; /**< @return the handle width in pixels */
|
||||||
static qint32 handleHeight() { return m_HandleHeight; } /**< @return the handle height in pixels */
|
static qint32 handleHeight() { return m_HandleHeight; } /**< @return the handle height in pixels */
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -102,7 +102,7 @@ void PartWidget::paintEvent(QPaintEvent*)
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHints(QPainter::Antialiasing);
|
painter.setRenderHints(QPainter::Antialiasing);
|
||||||
drawGradient( &painter, activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())),QRect(0, 0, width() - 1, height() - 1));
|
drawGradient(&painter, activeColor(Config::fileSystemColorCode(partition()->fileSystem().type())), QRect(0, 0, width() - 1, height() - 1));
|
||||||
|
|
||||||
if (partition()->roles().has(PartitionRole::Extended))
|
if (partition()->roles().has(PartitionRole::Extended))
|
||||||
return;
|
return;
|
||||||
|
@ -110,10 +110,10 @@ void PartWidget::paintEvent(QPaintEvent*)
|
||||||
if (!partition()->roles().has(PartitionRole::Unallocated))
|
if (!partition()->roles().has(PartitionRole::Unallocated))
|
||||||
{
|
{
|
||||||
// draw free space background
|
// draw free space background
|
||||||
drawGradient( &painter, activeColor(Config::availableSpaceColorCode()), 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
|
// draw used space in front of that
|
||||||
drawGradient( &painter, activeColor(Config::usedSpaceColorCode()), 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
|
// draw name and size
|
||||||
|
@ -125,18 +125,18 @@ void PartWidget::paintEvent(QPaintEvent*)
|
||||||
painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
painter.drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartWidget::drawGradient( QPainter* painter, const QColor& color, const QRect& rect ) const
|
void PartWidget::drawGradient(QPainter* painter, const QColor& color, const QRect& rect) const
|
||||||
{
|
{
|
||||||
|
if (rect.width() < 8)
|
||||||
|
return;
|
||||||
|
|
||||||
if( rect.width() < 8 ) return;
|
|
||||||
QStyleOptionButton option;
|
QStyleOptionButton option;
|
||||||
option.initFrom(this);
|
option.initFrom(this);
|
||||||
option.rect = rect;
|
option.rect = rect;
|
||||||
option.palette.setColor( QPalette::Button, color );
|
option.palette.setColor(QPalette::Button, color);
|
||||||
option.palette.setColor( QPalette::Window, color );
|
option.palette.setColor(QPalette::Window, color);
|
||||||
option.state |= QStyle::State_Raised;
|
option.state |= QStyle::State_Raised;
|
||||||
option.state &= ~QStyle::State_MouseOver;
|
option.state &= ~QStyle::State_MouseOver;
|
||||||
|
|
||||||
style()->drawControl(QStyle::CE_PushButtonBevel, &option, painter, this);
|
style()->drawControl(QStyle::CE_PushButtonBevel, &option, painter, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ class PartWidget : public PartWidgetBase
|
||||||
|
|
||||||
QColor activeColor(const QColor& col) const;
|
QColor activeColor(const QColor& col) const;
|
||||||
|
|
||||||
void drawGradient( QPainter*, const QColor&, const QRect& ) const;
|
void drawGradient(QPainter* painter, const QColor& col, const QRect& rect) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Partition* m_Partition;
|
const Partition* m_Partition;
|
||||||
|
|
|
@ -130,6 +130,8 @@ KAboutData* createPartitionManagerAboutData()
|
||||||
about->addAuthor(ki18nc("@info:credit", "Volker Lanz"), KLocalizedString(), "vl@fidra.de");
|
about->addAuthor(ki18nc("@info:credit", "Volker Lanz"), KLocalizedString(), "vl@fidra.de");
|
||||||
about->setHomepage("http://www.partitionmanager.org");
|
about->setHomepage("http://www.partitionmanager.org");
|
||||||
|
|
||||||
|
about->addCredit(ki18n("Hugo Pereira Da Costa"), ki18nc("@info:credit", "Partition Widget Design"), "hugo@oxygen-icons.org");
|
||||||
|
|
||||||
return about;
|
return about;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue