diff options
| author | Peter Penz <[email protected]> | 2011-11-20 19:32:52 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-11-20 19:35:01 +0100 |
| commit | b27e599429731337af4bb18b986933c968bea279 (patch) | |
| tree | e807863400a9c3f6f48194a0f69f4c3d450ca092 /src/panels/folders/ktreeview.cpp | |
| parent | 693f254252da3932d1307f65bc2a1bcaaad566ac (diff) | |
Initial draft for bringing back the "Folders" panel
The folders panel has been adjusted to use the new view-engine.
A lot of things don't work yet, but are mostly minor issues that
should be fixable during the next 10 days.
Diffstat (limited to 'src/panels/folders/ktreeview.cpp')
| -rw-r--r-- | src/panels/folders/ktreeview.cpp | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/src/panels/folders/ktreeview.cpp b/src/panels/folders/ktreeview.cpp deleted file mode 100644 index 765b934be..000000000 --- a/src/panels/folders/ktreeview.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by <haraldhv (at) stud.ntnu.no> * - * Copyright (C) 2008 by <[email protected]> * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "ktreeview.h" -#include "ktreeview_p.h" - -#include <KGlobalSettings> - -#include <QItemSelectionModel> -#include <QScrollBar> -#include <QTimer> -#include <QTimeLine> - -KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView *parent) : - parent(parent), - autoHorizontalScroll(false), - timeLine(0) -{ - timeLine = new QTimeLine(500, this); - connect(timeLine, SIGNAL(frameChanged(int)), - this, SLOT(updateVerticalScrollBar(int))); - - connect(parent->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), - this, SLOT(startScrolling())); - connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(startScrolling())); - connect(parent, SIGNAL(collapsed(QModelIndex)), - this, SLOT(startScrolling())); - connect(parent, SIGNAL(expanded(QModelIndex)), - this, SLOT(startScrolling())); -} - -void KTreeView::KTreeViewPrivate::startScrolling() -{ - if (!autoHorizontalScroll) { - return; - } - - // Determine the most left visual index - QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0)); - if (!visibleIndex.isValid()) { - return; - } - - QModelIndex index = visibleIndex; - int minimum = parent->width(); - do { - const QRect rect = parent->visualRect(visibleIndex); - if (rect.top() > parent->viewport()->height()) { - // the current index and all successors are not visible anymore - break; - } - if (rect.left() < minimum) { - minimum = rect.left(); - index = visibleIndex; - } - visibleIndex = parent->indexBelow(visibleIndex); - } while (visibleIndex.isValid()); - - // Start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible - Q_ASSERT(index.isValid()); - const QRect rect = parent->visualRect(index); - - QScrollBar* scrollBar = parent->horizontalScrollBar(); - const int oldScrollBarPos = scrollBar->value(); - - const int itemRight = oldScrollBarPos + rect.left() + rect.width() - 1; - const int availableWidth = parent->viewport()->width(); - int scrollBarPos = itemRight - availableWidth; - const int scrollBarPosMax = oldScrollBarPos + rect.left() - parent->indentation(); - if (scrollBarPos > scrollBarPosMax) { - scrollBarPos = scrollBarPosMax; - } - - if (scrollBarPos != oldScrollBarPos) { - timeLine->setFrameRange(oldScrollBarPos, scrollBarPos); - if (timeLine->state() == QTimeLine::Running) { - timeLine->stop(); - } - timeLine->start(); - } -} - -void KTreeView::KTreeViewPrivate::updateVerticalScrollBar(int value) -{ - QScrollBar *scrollBar = parent->horizontalScrollBar(); - scrollBar->setValue(value); -} - -// ************************************************ - -KTreeView::KTreeView(QWidget *parent) : - QTreeView(parent), - d(new KTreeViewPrivate(this)) -{ - if (KGlobalSettings::graphicEffectsLevel() >= KGlobalSettings::SimpleAnimationEffects) { - setAutoHorizontalScroll(true); - } -} - -KTreeView::~KTreeView() -{ -} - -void KTreeView::setAutoHorizontalScroll(bool enable) -{ - d->autoHorizontalScroll = enable; - if (!enable) { - d->timeLine->stop(); - } -} - -bool KTreeView::autoHorizontalScroll() const -{ - return d->autoHorizontalScroll; -} - -void KTreeView::scrollTo(const QModelIndex& index, ScrollHint hint) -{ - const int value = horizontalScrollBar()->value(); - QTreeView::scrollTo(index, hint); - horizontalScrollBar()->setValue(value); -} - -void KTreeView::hideEvent(QHideEvent *event) -{ - d->timeLine->stop(); - QTreeView::hideEvent(event); -} - -#include "ktreeview.moc" -#include "ktreeview_p.moc" |
