From 16de8b90343b122493e9e625d00a748ca2c0d982 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Sun, 6 Jun 2010 17:57:08 +0000 Subject: [PATCH] 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 --- src/gui/partresizerwidget.cpp | 41 +++++++++++++++++++++++++++++------ src/gui/partresizerwidget.h | 4 ++-- src/gui/partwidget.cpp | 30 +++++++++++++++++-------- src/gui/partwidget.h | 2 ++ 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/gui/partresizerwidget.cpp b/src/gui/partresizerwidget.cpp index 302ae8a..a26fc90 100644 --- a/src/gui/partresizerwidget.cpp +++ b/src/gui/partresizerwidget.cpp @@ -31,11 +31,14 @@ #include #include #include +#include +#include +#include +#include #include #include -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) diff --git a/src/gui/partresizerwidget.h b/src/gui/partresizerwidget.h index b4f5af2..036ee2b 100644 --- a/src/gui/partresizerwidget.h +++ b/src/gui/partresizerwidget.h @@ -23,6 +23,7 @@ #include #include +#include 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; }; diff --git a/src/gui/partwidget.cpp b/src/gui/partwidget.cpp index 94cd723..4760b09 100644 --- a/src/gui/partwidget.cpp +++ b/src/gui/partwidget.cpp @@ -26,6 +26,7 @@ #include "fs/filesystem.h" #include +#include #include #include @@ -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); + +} diff --git a/src/gui/partwidget.h b/src/gui/partwidget.h index 06775d9..ce9aa84 100644 --- a/src/gui/partwidget.h +++ b/src/gui/partwidget.h @@ -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;