summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-30 13:45:35 -0500
committerSlávek Banko <slavek.banko@axis.cz>2013-05-01 02:24:24 +0200
commitf081179ea04eec90c2a24860d45ff2d404bd27d0 (patch)
treeb45e41ec04ceae7142d0915537dcad96d433691a
parent93f550d17da9d258fe8cced99ceea088e14172b9 (diff)
downloadtdelibs-f081179ea04eec90c2a24860d45ff2d404bd27d0.tar.gz
tdelibs-f081179ea04eec90c2a24860d45ff2d404bd27d0.zip
Fix ugly open/save dialog icon item highlight rectangle mismatch
(cherry picked from commit 89798786dbb571ff5af2af8127bf19be9141957b)
-rw-r--r--kdeui/kiconview.cpp88
1 files changed, 62 insertions, 26 deletions
diff --git a/kdeui/kiconview.cpp b/kdeui/kiconview.cpp
index a26519729..9c1f924d5 100644
--- a/kdeui/kiconview.cpp
+++ b/kdeui/kiconview.cpp
@@ -447,9 +447,16 @@ void KIconView::setIconTextHeight( int n )
/////////////
-struct KIconViewItem::KIconViewItemPrivate
+class KIconViewItem::KIconViewItemPrivate
{
- TQSize m_pixmapSize;
+ public:
+ KIconViewItemPrivate() {
+ m_pixmapSize = TQSize(0,0);
+ }
+
+ public:
+ TQSize m_pixmapSize;
+ int realTextHeight;
};
void KIconViewItem::init()
@@ -462,11 +469,18 @@ void KIconViewItem::init()
KIconViewItem::~KIconViewItem()
{
delete m_wordWrap;
- delete d;
+ if (d) {
+ delete d;
+ }
}
void KIconViewItem::calcRect( const TQString& text_ )
{
+ if ( !d ) {
+ d = new KIconViewItemPrivate;
+ }
+ d->realTextHeight = -1;
+
bool drawRoundedRect = KGlobalSettings::iconUseRoundedRect();
Q_ASSERT( iconView() );
@@ -510,19 +524,22 @@ void KIconViewItem::calcRect( const TQString& text_ )
// properly when the pixmapRect is not at the top of the itemRect, so we
// have to increase the height of the pixmapRect and leave it at the top
// of the itemRect...
- if ( d && !d->m_pixmapSize.isNull() )
+ if ( d && !d->m_pixmapSize.isNull() ) {
itemIconRect.setHeight( d->m_pixmapSize.height() + 2 );
+ }
else
#endif
itemIconRect.setHeight( ph );
int tw = 0;
- if ( d && !d->m_pixmapSize.isNull() )
+ if ( d && !d->m_pixmapSize.isNull() ) {
tw = view->maxItemWidth() - ( view->itemTextPos() == TQIconView::Bottom ? 0 :
d->m_pixmapSize.width() + 2 );
- else
+ }
+ else {
tw = view->maxItemWidth() - ( view->itemTextPos() == TQIconView::Bottom ? 0 :
itemIconRect.width() );
+ }
TQFontMetrics *fm = view->itemFontMetrics();
TQString t;
@@ -550,10 +567,12 @@ void KIconViewItem::calcRect( const TQString& text_ )
r = m_wordWrap->boundingRect();
int realWidth = QMAX( QMIN( r.width() + 4, tw ), fm->width( "X" ) );
- if (drawRoundedRect == true)
+ if (drawRoundedRect == true) {
itemTextRect.setWidth( realWidth + 2);
- else
+ }
+ else {
itemTextRect.setWidth( realWidth );
+ }
itemTextRect.setHeight( r.height() );
int w = 0; int h = 0; int y = 0;
@@ -582,10 +601,10 @@ void KIconViewItem::calcRect( const TQString& text_ )
itemTextRect.width(), itemTextRect.height() );
itemIconRect = TQRect( ( width - itemIconRect.width() ) / 2, y,
itemIconRect.width(), itemIconRect.height() );
- } else {
+ }
+ else {
// If the pixmap size has been specified, use it
- if ( d && !d->m_pixmapSize.isNull() )
- {
+ if ( d && !d->m_pixmapSize.isNull() ) {
h = QMAX( itemTextRect.height(), d->m_pixmapSize.height() + 2 );
#if 0 // FIXME
// Waiting for the qt bug to be solved, the pixmapRect must
@@ -593,8 +612,9 @@ void KIconViewItem::calcRect( const TQString& text_ )
y = ( d->m_pixmapSize.height() + 2 - itemIconRect.height() ) / 2;
#endif
}
- else
+ else {
h = QMAX( itemTextRect.height(), itemIconRect.height() );
+ }
w = itemTextRect.width() + itemIconRect.width() + 1;
itemRect.setWidth( w );
@@ -604,25 +624,30 @@ void KIconViewItem::calcRect( const TQString& text_ )
itemTextRect = TQRect( width - itemTextRect.width(), ( height - itemTextRect.height() ) / 2,
itemTextRect.width(), itemTextRect.height() );
- if ( itemIconRect.height() > itemTextRect.height() ) // icon bigger than text -> center vertically
+ if ( itemIconRect.height() > itemTextRect.height() ) { // icon bigger than text -> center vertically
itemIconRect = TQRect( 0, ( height - itemIconRect.height() ) / 2,
itemIconRect.width(), itemIconRect.height() );
- else // icon smaller than text -> place in top or center with first line
+ }
+ else { // icon smaller than text -> place in top or center with first line
itemIconRect = TQRect( 0, QMAX(( fm->height() - itemIconRect.height() ) / 2 + y, 0),
itemIconRect.width(), itemIconRect.height() );
- if ( ( itemIconRect.height() <= 20 ) && ( itemTextRect.height() < itemIconRect.height() ) )
- {
- itemTextRect.setHeight( itemIconRect.height() - 2 );
+ }
+ if ( ( itemIconRect.height() <= 20 ) && ( itemTextRect.height() < itemIconRect.height() ) ) {
+ d->realTextHeight = itemTextRect.height();
+ itemTextRect.setHeight( itemIconRect.height() - 4 );
itemTextRect.setY( itemIconRect.y() );
}
}
- if ( itemIconRect != pixmapRect() )
+ if ( itemIconRect != pixmapRect() ) {
setPixmapRect( itemIconRect );
- if ( itemTextRect != textRect() )
+ }
+ if ( itemTextRect != textRect() ) {
setTextRect( itemTextRect );
- if ( itemRect != rect() )
+ }
+ if ( itemRect != rect() ) {
setItemRect( itemRect );
+ }
// Done by setPixmapRect, setTextRect and setItemRect ! [and useless if no rect changed]
//view->updateItemContainer( this );
@@ -706,11 +731,19 @@ void KIconViewItem::paintText( TQPainter *p, const TQColorGroup &cg )
{
bool drawRoundedRect = KGlobalSettings::iconUseRoundedRect();
int textX;
- if (drawRoundedRect == true)
+ if (drawRoundedRect == true) {
textX = textRect( false ).x() + 4;
- else
+ }
+ else {
textX = textRect( false ).x() + 2;
- int textY = textRect( false ).y();
+ }
+ int textY;
+ if ( d && (d->realTextHeight != -1) ) {
+ textY = textRect( false ).y() + ((rect().height() - d->realTextHeight) / 2);
+ }
+ else {
+ textY = textRect( false ).y();
+ }
if ( isSelected() ) {
if (drawRoundedRect == true) {
@@ -722,9 +755,11 @@ void KIconViewItem::paintText( TQPainter *p, const TQColorGroup &cg )
p->fillRect( textRect( false ), cg.highlight() );
}
p->setPen( TQPen( cg.highlightedText() ) );
- } else {
- if ( iconView()->itemTextBackground() != Qt::NoBrush )
+ }
+ else {
+ if ( iconView()->itemTextBackground() != Qt::NoBrush ) {
p->fillRect( textRect( false ), iconView()->itemTextBackground() );
+ }
p->setPen( cg.text() );
}
@@ -739,8 +774,9 @@ TQSize KIconViewItem::pixmapSize() const
void KIconViewItem::setPixmapSize( const TQSize& size )
{
- if ( !d )
+ if ( !d ) {
d = new KIconViewItemPrivate;
+ }
d->m_pixmapSize = size;
}