Use correct icon area when placing new icons

This resolves another long-standing bug where saved icons are moved to make way for new icons
pull/2/head
Timothy Pearson 11 years ago
parent 5124f6367b
commit 4dc80faf84

@ -1136,9 +1136,9 @@ void KDIconView::slotNewItems( const KFileItemList & entries )
TQRect oldPos = fileIVI->rect(); TQRect oldPos = fileIVI->rect();
fileIVI->move( x, y ); fileIVI->move( x, y );
if ( (!firstRun) && (!isFreePosition( fileIVI )) && (!m_needDesktopAlign) ) // if we can't put it there, then let TQIconView decide if ( (!firstRun) && (!isFreePosition( fileIVI, area )) && (!m_needDesktopAlign) ) // if we can't put it there, then let TQIconView decide
{ {
if (!isFreePosition( fileIVI )) if (!isFreePosition( fileIVI, area ))
{ {
// Find the offending icon and move it out of the way; saved positions have precedence! // Find the offending icon and move it out of the way; saved positions have precedence!
TQRect r = fileIVI->rect(); TQRect r = fileIVI->rect();
@ -1152,7 +1152,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries )
if ( it->intersects( r ) ) if ( it->intersects( r ) )
{ {
moveToFreePosition(it); moveToFreePosition(it, area);
} }
} }
} }
@ -1165,7 +1165,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries )
} }
else else
{ {
if (!isFreePosition( fileIVI )) if (!isFreePosition( fileIVI, area ))
{ {
kdDebug(1214)<<"slotNewItems() pos was not free :-("<<endl; kdDebug(1214)<<"slotNewItems() pos was not free :-("<<endl;
// Find the offending icon and move it out of the way; saved positions have precedence! // Find the offending icon and move it out of the way; saved positions have precedence!
@ -1180,7 +1180,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries )
if ( it->intersects( r ) ) if ( it->intersects( r ) )
{ {
moveToFreePosition(it); moveToFreePosition(it, area);
} }
} }
} }
@ -1194,7 +1194,6 @@ void KDIconView::slotNewItems( const KFileItemList & entries )
{ {
// Not found, we'll need to save the new pos // Not found, we'll need to save the new pos
kdDebug(1214)<<"slotNewItems(): New item without position information, try to find a sane location"<<endl; kdDebug(1214)<<"slotNewItems(): New item without position information, try to find a sane location"<<endl;
newItemsList.append(fileIVI); newItemsList.append(fileIVI);
} }
} }
@ -1204,7 +1203,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries )
for ( newitemit = newItemsList.begin(); newitemit != newItemsList.end(); ++newitemit ) for ( newitemit = newItemsList.begin(); newitemit != newItemsList.end(); ++newitemit )
{ {
fileIVI = (*newitemit); fileIVI = (*newitemit);
moveToFreePosition(fileIVI); moveToFreePosition(fileIVI, area);
m_bNeedSave = true; m_bNeedSave = true;
} }
@ -1731,39 +1730,53 @@ void KDIconView::setupSortKeys()
} }
} }
bool KDIconView::isFreePosition( const TQIconViewItem *item ) const bool KDIconView::isFreePosition( const TQIconViewItem *item, const TQRect &currentIconArea ) const
{ {
TQRect r = item->rect(); TQRect r = item->rect();
TQIconViewItem *it = firstItem(); TQRect area = currentIconArea;
for (; it; it = it->nextItem() ) if (area.isNull()) area = iconArea();
{
if ( !it->rect().isValid() || it == item )
{
continue;
}
if ( it->intersects( r ) )
{
return false;
}
}
return true; // If the proposed item rect is not contained by the desktop, by definition the item position is not free!
if (!area.contains(r, FALSE)) {
return false;
}
TQIconViewItem *it = firstItem();
for (; it; it = it->nextItem() ) {
if ( !it->rect().isValid() || it == item ) {
continue;
}
if ( it->intersects( r ) ) {
return false;
}
}
return true;
} }
bool KDIconView::isFreePosition( const TQIconViewItem *item ,const TQRect& rect) const bool KDIconView::isFreePosition( const TQIconViewItem *item, const TQRect& rect, const TQRect& currentIconArea) const
{ {
TQIconViewItem *it = firstItem(); TQRect area = currentIconArea;
for (; it; it = it->nextItem() ) if (area.isNull()) area = iconArea();
{
if ( !rect.isValid() || it == item )
continue;
if ( it->intersects( rect ) ) // If the proposed item rect is not contained by the desktop, by definition the item position is not free!
return false; if (!area.contains(rect, FALSE)) {
} return false;
}
return true; TQIconViewItem *it = firstItem();
for (; it; it = it->nextItem() ) {
if ( !rect.isValid() || it == item ) {
continue;
}
if ( it->intersects( rect ) ) {
return false;
}
}
return true;
} }
void KDIconView::setLastIconPosition( const TQPoint &_pos ) void KDIconView::setLastIconPosition( const TQPoint &_pos )
@ -1771,64 +1784,60 @@ void KDIconView::setLastIconPosition( const TQPoint &_pos )
m_lastDeletedIconPos = _pos; m_lastDeletedIconPos = _pos;
} }
void KDIconView::moveToFreePosition(TQIconViewItem *item ) void KDIconView::moveToFreePosition(TQIconViewItem *item, const TQRect &currentIconArea)
{ {
bool success; bool success = false;
// It may be that a file has been renamed. In this case, // It may be that a file has been renamed. In this case,
// m_lastDeletedIconPos is the position to use for this "apparently new" item. // m_lastDeletedIconPos is the position to use for this "apparently new" item.
// (We rely on deleteItem being now emitted before newItems). // (We rely on deleteItem being now emitted before newItems).
if ( !m_lastDeletedIconPos.isNull() ) if ( !m_lastDeletedIconPos.isNull() ) {
// Problem is: I'd like to compare those two file's attributes // Problem is: I'd like to compare those two file's attributes
// (size, creation time, modification time... etc.) but since renaming // (size, creation time, modification time... etc.) but since renaming
// is done by kpropsdlg, all of those can have changed (and creation time // is done by kpropsdlg, all of those can have changed (and creation time
// is different since the new file is a copy!) // is different since the new file is a copy!)
{ kdDebug(1214) << "Moving " << item->text() << " to position of last deleted icon." << endl;
kdDebug(1214) << "Moving " << item->text() << " to position of last deleted icon." << endl; item->move( m_lastDeletedIconPos );
item->move( m_lastDeletedIconPos ); m_lastDeletedIconPos = TQPoint();
m_lastDeletedIconPos = TQPoint(); return;
return; }
}
//try to find a free place to put the item, honouring the m_bVertAlign property
//try to find a free place to put the item, honouring the m_bVertAlign property TQRect rect=item->rect();
TQRect rect=item->rect(); if (m_bVertAlign) {
if (m_bVertAlign) kdDebug(1214)<<"moveToFreePosition for vertical alignment"<<endl;
{
kdDebug(1214)<<"moveToFreePosition for vertical alignment"<<endl; rect.moveTopLeft(TQPoint(currentIconArea.x()+spacing(),currentIconArea.y()+spacing()));
do {
success=false;
while (rect.bottom()<(currentIconArea.y()+currentIconArea.height())) {
if (!isFreePosition(item,rect,currentIconArea)) {
rect.moveBy(0,rect.height()+spacing());
}
else {
success=true;
break;
}
}
if (!success) {
rect.moveTopLeft(TQPoint(rect.right()+spacing(),spacing()));
}
else {
break;
}
} while (item->rect().right()<(currentIconArea.x()+currentIconArea.width()));
rect.moveTopLeft(TQPoint(spacing(),spacing())); if (success) {
do item->move(rect.x(),rect.y());
{
success=false;
while (rect.bottom()<height())
{
if (!isFreePosition(item,rect))
{
rect.moveBy(0,rect.height()+spacing());
} }
else else {
{ item->move(width()-spacing()-item->rect().width(),height()-spacing()-item->rect().height());
success=true; }
break; }
}
}
if (!success)
{
rect.moveTopLeft(TQPoint(rect.right()+spacing(),spacing()));
} else break;
}
while (item->rect().right()<width());
if (success)
item->move(rect.x(),rect.y());
else
item->move(width()-spacing()-item->rect().width(),height()-spacing()-item->rect().height());
}
} }
TQPoint KDIconView::findPlaceForIconCol( int column, int dx, int dy) TQPoint KDIconView::findPlaceForIconCol( int column, int dx, int dy, const TQRect &currentIconArea )
{ {
if (column < 0) if (column < 0)
return TQPoint(); return TQPoint();
@ -1843,16 +1852,18 @@ TQPoint KDIconView::findPlaceForIconCol( int column, int dx, int dy)
while ( rect.bottom() < viewport()->height() - spacing() ) while ( rect.bottom() < viewport()->height() - spacing() )
{ {
if ( !isFreePosition(0,rect) ) if ( !isFreePosition(0,rect,currentIconArea) ) {
rect.moveBy(0, rect.height()); rect.moveBy(0, rect.height());
else }
else {
return rect.topLeft(); return rect.topLeft();
}
} }
return TQPoint(); return TQPoint();
} }
TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy ) TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy, const TQRect &currentIconArea )
{ {
if (row < 0) if (row < 0)
return TQPoint(); return TQPoint();
@ -1867,7 +1878,7 @@ TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy )
while (rect.right() < viewport()->width() - spacing()) while (rect.right() < viewport()->width() - spacing())
{ {
if (!isFreePosition(0,rect)) if (!isFreePosition(0,rect,currentIconArea))
rect.moveBy(rect.width()+spacing(), 0); rect.moveBy(rect.width()+spacing(), 0);
else else
return rect.topLeft(); return rect.topLeft();
@ -1876,7 +1887,7 @@ TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy )
return TQPoint(); return TQPoint();
} }
TQPoint KDIconView::findPlaceForIcon( int column, int row) TQPoint KDIconView::findPlaceForIcon( int column, int row, const TQRect &currentIconArea )
{ {
int dx = gridXValue(), dy = 0; int dx = gridXValue(), dy = 0;
TQIconViewItem *item = firstItem(); TQIconViewItem *item = firstItem();
@ -1895,7 +1906,7 @@ TQPoint KDIconView::findPlaceForIcon( int column, int row)
do { do {
delta++; delta++;
res = findPlaceForIconCol(column + (delta / 2) * (-2 * (delta % 2) + 1), res = findPlaceForIconCol(column + (delta / 2) * (-2 * (delta % 2) + 1),
dx, dy); dx, dy, currentIconArea);
if (delta / 2 > QMAX(max_cols - column, column)) if (delta / 2 > QMAX(max_cols - column, column))
return res; return res;
} while (res.isNull()); } while (res.isNull());
@ -1909,7 +1920,7 @@ TQPoint KDIconView::findPlaceForIcon( int column, int row)
do { do {
delta++; delta++;
res = findPlaceForIconRow(row + (delta / 2) * (-2 * (delta % 2) + 1), res = findPlaceForIconRow(row + (delta / 2) * (-2 * (delta % 2) + 1),
dx, dy); dx, dy, currentIconArea);
if (delta / 2 > QMAX(max_rows - row, row)) if (delta / 2 > QMAX(max_rows - row, row))
return res; return res;
} while (res.isNull()); } while (res.isNull());

@ -110,9 +110,9 @@ public:
void startDirLister(); void startDirLister();
TQPoint findPlaceForIconCol( int column, int dx, int dy ); TQPoint findPlaceForIconCol( int column, int dx, int dy, const TQRect &currentIconArea );
TQPoint findPlaceForIconRow( int row, int dx, int dy ); TQPoint findPlaceForIconRow( int row, int dx, int dy, const TQRect &currentIconArea );
TQPoint findPlaceForIcon( int column, int row ); TQPoint findPlaceForIcon( int column, int row, const TQRect &currentIconArea = TQRect() );
protected slots: protected slots:
@ -173,9 +173,9 @@ protected:
bool makeFriendlyText( KFileIVI *fileIVI ); bool makeFriendlyText( KFileIVI *fileIVI );
static TQString stripDesktopExtension( const TQString & text ); static TQString stripDesktopExtension( const TQString & text );
bool isDesktopFile( KFileItem * _item ) const; bool isDesktopFile( KFileItem * _item ) const;
bool isFreePosition( const TQIconViewItem *item ) const; bool isFreePosition( const TQIconViewItem *item, const TQRect &currentIconArea ) const;
bool isFreePosition( const TQIconViewItem *item, const TQRect& rect ) const; bool isFreePosition( const TQIconViewItem *item, const TQRect& rect, const TQRect &currentIconArea ) const;
void moveToFreePosition(TQIconViewItem *item ); void moveToFreePosition(TQIconViewItem *item, const TQRect &currentIconArea );
bool deleteGlobalDesktopFiles(); bool deleteGlobalDesktopFiles();
void removeBuiltinIcon(TQString iconName); void removeBuiltinIcon(TQString iconName);

Loading…
Cancel
Save