From 3b6c9880018fee39011abde151881ffbe9a563b7 Mon Sep 17 00:00:00 2001 From: coolo Date: Fri, 7 Dec 2007 13:01:51 +0000 Subject: [PATCH] impress Duncan git-svn-id: http://svn.opensuse.org/svn/yast/trunk/qt4@42796 e0cc52ee-31ee-0310-8b87-e83c4596d67c --- src/QY2DiskUsageList.cc | 85 ++++++++++++++++++++++------------------- src/QY2DiskUsageList.h | 4 ++ src/YQUI_core.cc | 11 ++++-- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/QY2DiskUsageList.cc b/src/QY2DiskUsageList.cc index a93b235..3db7fd4 100644 --- a/src/QY2DiskUsageList.cc +++ b/src/QY2DiskUsageList.cc @@ -24,7 +24,8 @@ #include "QY2DiskUsageList.h" #include "YQi18n.h" #include - +#include +#include /** * Stolen from KDirStat::KDirTreeView with the author's permission. @@ -114,6 +115,36 @@ interpolateColor( int val, } +class QY2DiskUsagePercentageItem : public QItemDelegate +{ + QY2DiskUsageList *_view; + +public: + QY2DiskUsagePercentageItem( QY2DiskUsageList *parent ) : QItemDelegate( parent ), _view( parent ) { + } + + virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const + { + painter->save(); + QColor background = option.palette.color(QPalette::Window); + painter->setBackground( background ); + + QY2DiskUsageListItem *item = dynamic_cast(_view->itemFromIndex(index)); + if ( item ) + { + item->paintPercentageBar( item->usedPercent(), + painter, + option, + interpolateColor( item->usedPercent(), + 60, 95, + QColor( 0, 0x80, 0 ), // Medium dark green + QColor( 0xFF, 0, 0 ) ), // Bright red + background.dark( 115 ) ); + } + painter->restore(); + } +}; + QY2DiskUsageList::QY2DiskUsageList( QWidget * parent, bool addStdColumns ) : QY2ListView( parent ) { @@ -133,6 +164,7 @@ QY2DiskUsageList::QY2DiskUsageList( QWidget * parent, bool addStdColumns ) // Translators: Please keep this short! columnLabels << _("Disk Usage"); _percentageBarCol = numCol++; columnLabels << ""; _percentageCol = numCol++; + setItemDelegateForColumn( _percentageBarCol, new QY2DiskUsagePercentageItem( this ) ); columnLabels << _("Used"); _usedSizeCol = numCol++; columnLabels << _( "Free"); _freeSizeCol = numCol++; columnLabels << _("Total"); _totalSizeCol = numCol++; @@ -142,7 +174,7 @@ QY2DiskUsageList::QY2DiskUsageList( QWidget * parent, bool addStdColumns ) // needed? setColumnCount(numCol); setHeaderLabels(columnLabels); - + //FIXME // setTextAlignment( percentageCol(), Qt::AlignRight ); // setTextAlignment( usedSizeCol(), Qt::AlignRight ); @@ -163,40 +195,13 @@ QY2DiskUsageList::~QY2DiskUsageList() void QY2DiskUsageList::drawRow( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { - if ( index.column() == percentageBarCol() ) - { - QColor background = option.palette.color(QPalette::Base); - painter->setBackground( background ); + // Intentionally bypassing the direct parent class method, use the grandparent's: + // Don't let QY2ListViewItem::_textColor / _backgroundColor interfere with our colors. - QY2DiskUsageListItem *item = dynamic_cast(itemFromIndex(index)); - if ( item ) - { - item->paintPercentageBar( item->usedPercent(), - painter, - option, - interpolateColor( item->usedPercent(), - 60, 95, - QColor( 0, 0x80, 0 ), // Medium dark green - QColor( 0xFF, 0, 0 ) ), // Bright red - background.dark( 115 ) ); - } - } - else - { - //QColorGroup cg( colorGroup ); - - //if ( usedSize() > totalSize() ) - // cg.setColor( QColorGroup::Text, Qt::red ); // Set red text foreground - - // Intentionally bypassing the direct parent class method, use the grandparent's: - // Don't let QY2ListViewItem::_textColor / _backgroundColor interfere with our colors. - - QTreeWidget::drawRow( painter, option, index ); - } + QTreeWidget::drawRow( painter, option, index ); } - QY2DiskUsageListItem::QY2DiskUsageListItem( QY2DiskUsageList * parent ) : QY2ListViewItem( parent ) , _diskUsageList( parent ) @@ -343,17 +348,17 @@ QY2DiskUsageListItem::paintPercentageBar( float percent, if ( percent < 0.0 ) percent = 0.0; int penWidth = 2; int extraMargin = 3; - int x = 0; /*FIXME _diskUsageList->itemMargin(); */ - int y = extraMargin; + int x = option.rect.left(); /*FIXME _diskUsageList->itemMargin(); */ + int y = option.rect.top() + extraMargin; int w = option.rect.width() - 2; /*FIXME * _diskUsageList->horizontalOffset(); */ int h = option.rect.height() - 2; /*FIXME * extraMargin; */ int fillWidth; - - painter->eraseRect( 0, 0, option.rect.width(), option.rect.height() ); + + painter->eraseRect( option.rect ); int indent=0; w -= indent; x += indent; - + if ( w > 0 ) { QPen pen( painter->pen() ); @@ -361,10 +366,10 @@ QY2DiskUsageListItem::paintPercentageBar( float percent, painter->setPen( pen ); painter->setBrush( Qt::NoBrush ); fillWidth = (int) ( ( w - 2 * penWidth ) * percent / 100.0 ); - - + + // Fill bar background. - + painter->fillRect( x + penWidth, y + penWidth, w - 2 * penWidth + 1, h - 2 * penWidth + 1, barBackground ); diff --git a/src/QY2DiskUsageList.h b/src/QY2DiskUsageList.h index 6dc51f7..32f9d4b 100644 --- a/src/QY2DiskUsageList.h +++ b/src/QY2DiskUsageList.h @@ -66,6 +66,10 @@ public: virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + // make it public + QTreeWidgetItem * itemFromIndex ( const QModelIndex & index ) const + { return QY2ListView::itemFromIndex(index); } + protected: int _nameCol; diff --git a/src/YQUI_core.cc b/src/YQUI_core.cc index e22a752..1d6b746 100644 --- a/src/YQUI_core.cc +++ b/src/YQUI_core.cc @@ -46,6 +46,7 @@ #include "YQDialog.h" #include "QY2Settings.h" +#define NOWARNINGS 0 #define BUSY_CURSOR_TIMEOUT 200 // milliseconds YQUI * YQUI::_ui = 0; @@ -92,12 +93,14 @@ void YQUI::init_ui() if (_ui_inited) return; +#if NOWARNINGS /* Qt thinks the first QObject defines the main thread, but the main thread in this case is the ycp thread, not UI */ - //extern void qt_set_current_thread_to_main_thread(); - //qt_set_current_thread_to_main_thread(); + extern void qt_set_current_thread_to_main_thread(); + qt_set_current_thread_to_main_thread(); +#endif _ui_inited = true; @@ -569,7 +572,9 @@ qMessageHandler( QtMsgType type, const char * msg ) break; case QtWarningMsg: y2warning ("qt-warning: %s\n", msg); - //abort(); +#if NOWARNINGS + abort(); +#endif break; case QtCriticalMsg: y2warning ("qt-critical: %s\n", msg); -- 2.39.2