summaryrefslogtreecommitdiffstats
path: root/kdesktop/kdiconview.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2021-03-05 15:34:53 +0200
committerMavridis Philippe <[email protected]>2021-03-30 16:39:25 +0300
commit94b98729138c6948c1e4fdbb1e0552f85783f263 (patch)
tree5e0b741dc58c987c5468c750d80f6e14d20cafcb /kdesktop/kdiconview.cpp
parentf06c728734b0102b131395f297de60877d4d0a66 (diff)
downloadtdebase-94b98729138c6948c1e4fdbb1e0552f85783f263.tar.gz
tdebase-94b98729138c6948c1e4fdbb1e0552f85783f263.zip
KDesktop: customizable icon spacing.
This commit introduces changes to KDesktop which allow for a custom icon spacing option, some new controls into the Desktop Behaviour module of KControl, as well as the KDesktop Ctrl+Mouse Scroll binding to manipulate the icon spacing. This commit depends on a previous (minor) change in LibKonq. Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'kdesktop/kdiconview.cpp')
-rw-r--r--kdesktop/kdiconview.cpp91
1 files changed, 69 insertions, 22 deletions
diff --git a/kdesktop/kdiconview.cpp b/kdesktop/kdiconview.cpp
index c8c5a1fe6..409887784 100644
--- a/kdesktop/kdiconview.cpp
+++ b/kdesktop/kdiconview.cpp
@@ -191,15 +191,13 @@ KDIconView::KDIconView( TQWidget *parent, const char* name )
if (!m_bEditableDesktopIcons)
{
- setItemsMovable(false);
- setAcceptDrops(false);
- viewport()->setAcceptDrops(false);
+ setIconsLocked(true);
}
}
KDIconView::~KDIconView()
{
- if (m_dotDirectory && !m_bEditableDesktopIcons) {
+ if (m_dotDirectory && !m_bEditableDesktopIcons || m_iconsLocked) {
m_dotDirectory->rollback(false); // Don't save positions
}
@@ -296,6 +294,7 @@ void KDIconView::initConfig( bool init )
m_bVertAlign = KDesktopSettings::vertAlign();
TQStringList oldPreview = previewSettings();
setPreviewSettings( KDesktopSettings::preview() );
+ setSpacing( KDesktopSettings::iconSpacing() );
// read arrange configuration
m_eSortCriterion = (SortCriterion)KDesktopSettings::sortCriterion();
@@ -486,6 +485,30 @@ void KDIconView::lineupIcons()
saveIconPositions();
}
+void KDIconView::incIconSpacing()
+{
+ if ( m_autoAlign && !KDesktopSettings::lockIcons() && KDesktopSettings::spacingCtrlScroll() )
+ {
+ setSpacing( ( spacing() + 1 ) );
+ lineupIcons();
+
+ KDesktopSettings::setIconSpacing( spacing() );
+ KDesktopSettings::writeConfig();
+ }
+}
+
+void KDIconView::decIconSpacing()
+{
+ if ( m_autoAlign && !KDesktopSettings::lockIcons() && KDesktopSettings::spacingCtrlScroll() && spacing() > 5 )
+ {
+ setSpacing( ( spacing() - 1 ) );
+ lineupIcons();
+
+ KDesktopSettings::setIconSpacing( spacing() );
+ KDesktopSettings::writeConfig();
+ }
+}
+
void KDIconView::setAutoAlign( bool b )
{
m_autoAlign = b;
@@ -517,6 +540,15 @@ void KDIconView::setAutoAlign( bool b )
}
}
+void KDIconView::setIconsLocked( bool lock )
+{
+ m_iconsLocked = lock;
+
+ setItemsMovable(!lock);
+ setAcceptDrops(!lock);
+ viewport()->setAcceptDrops(!lock);
+}
+
void KDIconView::startDirLister()
{
// if desktop is resized before start() is called (XRandr)
@@ -644,7 +676,22 @@ void KDIconView::wheelEvent( TQWheelEvent* e )
TQIconViewItem *item = findItem( e->pos() );
if ( !item )
{
- emit wheelRolled( e->delta() );
+ TQWheelEvent *we = TQT_TQWHEELEVENT(e);
+
+ if ( we->state() == ControlButton )
+ {
+ if ( we->delta() >= 0 )
+ incIconSpacing();
+ else
+ decIconSpacing();
+
+ we->accept();
+ }
+ else
+ {
+ emit wheelRolled( e->delta() );
+ }
+
return;
}
@@ -1726,25 +1773,25 @@ void KDIconView::viewportWheelEvent( TQWheelEvent * e )
void KDIconView::updateWorkArea( const TQRect &wr )
{
m_gotIconsArea = true; // now we have it!
-
+
if (( iconArea() == wr ) && (m_needDesktopAlign == false)) {
// nothing changed; avoid repaint/saveIconPosition ...
return;
}
-
+
TQRect oldArea = iconArea();
setIconArea( wr );
-
+
kdDebug(1204) << "KDIconView::updateWorkArea wr: " << wr.x() << "," << wr.y() << " " << wr.width() << "x" << wr.height() << endl;
kdDebug(1204) << " oldArea: " << oldArea.x() << "," << oldArea.y() << " " << oldArea.width() << "x" << oldArea.height() << endl;
-
+
bool needRepaint = false;
TQIconViewItem* item;
int dx, dy;
-
+
dx = wr.left() - oldArea.left();
dy = wr.top() - oldArea.top();
-
+
if ( dx != 0 || dy != 0 ) {
if ( (dx > 0) || (dy > 0) ) {
// the iconArea was shifted right/down; less space now
@@ -1762,14 +1809,14 @@ void KDIconView::updateWorkArea( const TQRect &wr )
// the iconArea was shifted left/up; more space now - use it
needRepaint = true;
}
-
+
if ( needRepaint ) {
for ( item = firstItem(); item; item = item->nextItem() ) {
item->moveBy( dx, dy );
}
}
}
-
+
for ( item = firstItem(); item; item = item->nextItem() ) {
TQRect r( item->rect() );
int dx = 0, dy = 0;
@@ -1789,7 +1836,7 @@ void KDIconView::updateWorkArea( const TQRect &wr )
repaint( FALSE );
saveIconPositions();
}
-
+
m_needDesktopAlign = false;
lineupIcons();
}
@@ -1861,18 +1908,18 @@ bool KDIconView::isFreePosition( const TQIconViewItem *item, const TQRect &curre
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;
}
@@ -1891,12 +1938,12 @@ bool KDIconView::isFreePosition( const TQIconViewItem *item, const TQRect& rect,
if ( !rect.isValid() || it == item ) {
continue;
}
-
+
if ( it->intersects( rect ) ) {
return false;
}
}
-
+
return true;
}
@@ -1921,12 +1968,12 @@ void KDIconView::moveToFreePosition(TQIconViewItem *item, const TQRect &currentI
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;
@@ -1939,7 +1986,7 @@ void KDIconView::moveToFreePosition(TQIconViewItem *item, const TQRect &currentI
break;
}
}
-
+
if (!success) {
rect.moveTopLeft(TQPoint(rect.right()+spacing(),spacing()));
}