diff options
author | Timothy Pearson <[email protected]> | 2013-04-07 22:15:56 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-04-07 22:15:56 -0500 |
commit | 4dc80faf840ee48bd4c0b8d5338a5274de013c39 (patch) | |
tree | 77257053afc0e124bc8832bdb8f4433f87625628 /kdesktop | |
parent | 5124f6367b90b101ccc5dba1d1c59fae8ce7de8d (diff) | |
download | tdebase-4dc80faf840ee48bd4c0b8d5338a5274de013c39.tar.gz tdebase-4dc80faf840ee48bd4c0b8d5338a5274de013c39.zip |
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
Diffstat (limited to 'kdesktop')
-rw-r--r-- | kdesktop/kdiconview.cc | 197 | ||||
-rw-r--r-- | kdesktop/kdiconview.h | 12 |
2 files changed, 110 insertions, 99 deletions
diff --git a/kdesktop/kdiconview.cc b/kdesktop/kdiconview.cc index 6dbc09270..9b8311828 100644 --- a/kdesktop/kdiconview.cc +++ b/kdesktop/kdiconview.cc @@ -1136,9 +1136,9 @@ void KDIconView::slotNewItems( const KFileItemList & entries ) TQRect oldPos = fileIVI->rect(); 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! TQRect r = fileIVI->rect(); @@ -1152,7 +1152,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries ) if ( it->intersects( r ) ) { - moveToFreePosition(it); + moveToFreePosition(it, area); } } } @@ -1165,7 +1165,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries ) } else { - if (!isFreePosition( fileIVI )) + if (!isFreePosition( fileIVI, area )) { kdDebug(1214)<<"slotNewItems() pos was not free :-("<<endl; // 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 ) ) { - 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 kdDebug(1214)<<"slotNewItems(): New item without position information, try to find a sane location"<<endl; - newItemsList.append(fileIVI); } } @@ -1204,7 +1203,7 @@ void KDIconView::slotNewItems( const KFileItemList & entries ) for ( newitemit = newItemsList.begin(); newitemit != newItemsList.end(); ++newitemit ) { fileIVI = (*newitemit); - moveToFreePosition(fileIVI); + moveToFreePosition(fileIVI, area); 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 ¤tIconArea ) const { - TQRect r = item->rect(); - TQIconViewItem *it = firstItem(); - for (; it; it = it->nextItem() ) - { - if ( !it->rect().isValid() || it == item ) - { - continue; - } - - if ( it->intersects( r ) ) - { - return false; - } - } + TQRect r = item->rect(); + TQRect area = currentIconArea; + if (area.isNull()) area = iconArea(); - 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(); - for (; it; it = it->nextItem() ) - { - if ( !rect.isValid() || it == item ) - continue; + TQRect area = currentIconArea; + if (area.isNull()) area = iconArea(); - if ( it->intersects( rect ) ) - return false; - } + // If the proposed item rect is not contained by the desktop, by definition the item position is not free! + 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 ) @@ -1771,64 +1784,60 @@ void KDIconView::setLastIconPosition( const TQPoint &_pos ) m_lastDeletedIconPos = _pos; } -void KDIconView::moveToFreePosition(TQIconViewItem *item ) -{ - bool success; - // It may be that a file has been renamed. In this case, - // m_lastDeletedIconPos is the position to use for this "apparently new" item. - // (We rely on deleteItem being now emitted before newItems). - if ( !m_lastDeletedIconPos.isNull() ) - // Problem is: I'd like to compare those two file's attributes - // (size, creation time, modification time... etc.) but since renaming - // is done by kpropsdlg, all of those can have changed (and creation time - // is different since the new file is a copy!) - { - kdDebug(1214) << "Moving " << item->text() << " to position of last deleted icon." << endl; - item->move( m_lastDeletedIconPos ); - m_lastDeletedIconPos = TQPoint(); - return; - } - - //try to find a free place to put the item, honouring the m_bVertAlign property - TQRect rect=item->rect(); - if (m_bVertAlign) - { - kdDebug(1214)<<"moveToFreePosition for vertical alignment"<<endl; +void KDIconView::moveToFreePosition(TQIconViewItem *item, const TQRect ¤tIconArea) +{ + bool success = false; + // It may be that a file has been renamed. In this case, + // m_lastDeletedIconPos is the position to use for this "apparently new" item. + // (We rely on deleteItem being now emitted before newItems). + if ( !m_lastDeletedIconPos.isNull() ) { + // Problem is: I'd like to compare those two file's attributes + // (size, creation time, modification time... etc.) but since renaming + // is done by kpropsdlg, all of those can have changed (and creation time + // is different since the new file is a copy!) + kdDebug(1214) << "Moving " << item->text() << " to position of last deleted icon." << endl; + item->move( m_lastDeletedIconPos ); + m_lastDeletedIconPos = TQPoint(); + return; + } + + //try to find a free place to put the item, honouring the m_bVertAlign property + TQRect rect=item->rect(); + if (m_bVertAlign) { + 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())); - do - { - success=false; - while (rect.bottom()<height()) - { - if (!isFreePosition(item,rect)) - { - rect.moveBy(0,rect.height()+spacing()); + if (success) { + item->move(rect.x(),rect.y()); } - else - { - 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()); - - } - + 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 ¤tIconArea ) { if (column < 0) return TQPoint(); @@ -1843,16 +1852,18 @@ TQPoint KDIconView::findPlaceForIconCol( int column, int dx, int dy) while ( rect.bottom() < viewport()->height() - spacing() ) { - if ( !isFreePosition(0,rect) ) + if ( !isFreePosition(0,rect,currentIconArea) ) { rect.moveBy(0, rect.height()); - else + } + else { return rect.topLeft(); + } } return TQPoint(); } -TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy ) +TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy, const TQRect ¤tIconArea ) { if (row < 0) return TQPoint(); @@ -1867,7 +1878,7 @@ TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy ) while (rect.right() < viewport()->width() - spacing()) { - if (!isFreePosition(0,rect)) + if (!isFreePosition(0,rect,currentIconArea)) rect.moveBy(rect.width()+spacing(), 0); else return rect.topLeft(); @@ -1876,7 +1887,7 @@ TQPoint KDIconView::findPlaceForIconRow( int row, int dx, int dy ) return TQPoint(); } -TQPoint KDIconView::findPlaceForIcon( int column, int row) +TQPoint KDIconView::findPlaceForIcon( int column, int row, const TQRect ¤tIconArea ) { int dx = gridXValue(), dy = 0; TQIconViewItem *item = firstItem(); @@ -1895,7 +1906,7 @@ TQPoint KDIconView::findPlaceForIcon( int column, int row) do { delta++; res = findPlaceForIconCol(column + (delta / 2) * (-2 * (delta % 2) + 1), - dx, dy); + dx, dy, currentIconArea); if (delta / 2 > QMAX(max_cols - column, column)) return res; } while (res.isNull()); @@ -1909,7 +1920,7 @@ TQPoint KDIconView::findPlaceForIcon( int column, int row) do { delta++; res = findPlaceForIconRow(row + (delta / 2) * (-2 * (delta % 2) + 1), - dx, dy); + dx, dy, currentIconArea); if (delta / 2 > QMAX(max_rows - row, row)) return res; } while (res.isNull()); diff --git a/kdesktop/kdiconview.h b/kdesktop/kdiconview.h index bc24308f6..c18b0d9d5 100644 --- a/kdesktop/kdiconview.h +++ b/kdesktop/kdiconview.h @@ -110,9 +110,9 @@ public: void startDirLister(); - TQPoint findPlaceForIconCol( int column, int dx, int dy ); - TQPoint findPlaceForIconRow( int row, int dx, int dy ); - TQPoint findPlaceForIcon( int column, int row ); + TQPoint findPlaceForIconCol( int column, int dx, int dy, const TQRect ¤tIconArea ); + TQPoint findPlaceForIconRow( int row, int dx, int dy, const TQRect ¤tIconArea ); + TQPoint findPlaceForIcon( int column, int row, const TQRect ¤tIconArea = TQRect() ); protected slots: @@ -173,9 +173,9 @@ protected: bool makeFriendlyText( KFileIVI *fileIVI ); static TQString stripDesktopExtension( const TQString & text ); bool isDesktopFile( KFileItem * _item ) const; - bool isFreePosition( const TQIconViewItem *item ) const; - bool isFreePosition( const TQIconViewItem *item, const TQRect& rect ) const; - void moveToFreePosition(TQIconViewItem *item ); + bool isFreePosition( const TQIconViewItem *item, const TQRect ¤tIconArea ) const; + bool isFreePosition( const TQIconViewItem *item, const TQRect& rect, const TQRect ¤tIconArea ) const; + void moveToFreePosition(TQIconViewItem *item, const TQRect ¤tIconArea ); bool deleteGlobalDesktopFiles(); void removeBuiltinIcon(TQString iconName); |