]>
cloud.milkyroute.net Git - dolphin.git/blob - src/ktreeview.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by <haraldhv (at) stud.ntnu.no> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include <KGlobalSettings>
25 #include "ktreeview.h"
26 #include "ktreeview_p.h"
28 KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView
*parent
)
30 autoHorizontalScroll(true),
36 topLeftPoint(QPoint(10,10))
38 Q_ASSERT(parent
->verticalScrollBar());
40 considerDelayTimer
.setInterval(considerDelay
);
42 connect( &considerDelayTimer
,
45 SLOT(considerAutoScroll())
48 connect( parent
->verticalScrollBar(),
49 SIGNAL(rangeChanged(int, int)),
54 connect( parent
->verticalScrollBar(),
55 SIGNAL(valueChanged(int)),
61 SIGNAL( collapsed ( const QModelIndex
&)),
67 SIGNAL( expanded ( const QModelIndex
&)),
74 void KTreeView::KTreeViewPrivate::considerAutoScroll()
76 qDebug() << "Considering auto scroll";
78 QModelIndex i
= parent
->indexAt(topLeftPoint
);
79 int smallest
= parent
->width();
83 QRect r
= parent
->visualRect(i
);
84 if (r
.top() > parent
->height())
87 int leftSide
= r
.left();
89 smallest
= qMin(smallest
, leftSide
);
90 i
= parent
->indexBelow(i
);
93 int currentScroll
= parent
->horizontalScrollBar()->value();
95 setScrollTowards(smallest
+ currentScroll
- leftSideMargin
);
97 considerDelayTimer
.stop();
101 void KTreeView::KTreeViewPrivate::autoScrollTimeout()
106 QScrollBar
*scrollBar
= parent
->horizontalScrollBar();
107 if (scrollBar
== NULL
)
109 qDebug() << "Warning: no scrollbar present, but told to scroll.";
114 int currentScroll
= scrollBar
->value();
116 int difference
= currentScroll
- scrollTowards
;
118 if (qAbs(difference
) < scrollPixels
)
120 scrollBar
->setValue(scrollTowards
);
127 scrollBar
->setValue(currentScroll
+ scrollPixels
);
131 scrollBar
->setValue(currentScroll
- scrollPixels
);
135 void KTreeView::KTreeViewPrivate::setScrollTowards( int scrollTowards
)
137 if (scrollTowards
< 0)
139 this->scrollTowards
= scrollTowards
;
140 scrollTimer
.start(scrollDelay
);
143 //************************************************
145 KTreeView::KTreeView(QWidget
*parent
)
147 , d(new KTreeViewPrivate(this))
149 /* The graphicEffectsLevel was not available in the 4.0.3 version of
150 * the libs I was compiling with, so this is left out for now and
151 * enabled by default...
153 //if (KGlobalSettings::graphicEffectsLevel() >=
154 //KGlobalSettings::SimpleAnimationEffects)
156 setAutoHorizontalScroll(true);
162 SLOT(autoScrollTimeout())
167 void KTreeView::setAutoHorizontalScroll(bool value
)
169 d
->autoHorizontalScroll
= value
;
172 bool KTreeView::autoHorizontalScroll( void )
174 return d
->autoHorizontalScroll
;
177 #include "ktreeview.moc"
178 #include "ktreeview_p.moc"