<label>Show hidden files</label>
<default>false</default>
</entry>
+ <entry name="AutoScrolling" type="Bool">
+ <label>Automatic scrolling</label>
+ <default>true</default>
+ </entry>
</group>
</kcfg>
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
+ * Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com> *
* *
* 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 *
#include <konq_operations.h>
#include <QApplication>
-#include <QItemSelection>
-#include <QTreeView>
#include <QBoxLayout>
+#include <QItemSelection>
#include <QModelIndex>
+#include <QPointer>
+#include <QTreeView>
#include <QScrollBar>
#include <QTimer>
return FoldersPanelSettings::showHiddenFiles();
}
+void FoldersPanel::setAutoScrolling(bool enable)
+{
+ m_treeView->setAutoHorizontalScroll(enable);
+ FoldersPanelSettings::setAutoScrolling(enable);
+}
+
+bool FoldersPanel::autoScrolling() const
+{
+ return FoldersPanelSettings::autoScrolling();
+}
+
void FoldersPanel::rename(const KFileItem& item)
{
if (DolphinSettings::instance().generalSettings()->renameInline()) {
m_dirLister->setDelayedMimeTypes(true);
m_dirLister->setAutoErrorHandlingEnabled(false, this);
m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles());
+ connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
Q_ASSERT(m_dolphinModel == 0);
m_dolphinModel = new DolphinModel(this);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_treeView);
+
+ setAutoScrolling(FoldersPanelSettings::autoScrolling());
+ setShowHiddenFiles(FoldersPanelSettings::showHiddenFiles());
}
loadTree(url());
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
}
- TreeViewContextMenu contextMenu(this, item);
- contextMenu.open();
+ QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, item);
+ contextMenu->open();
+ delete contextMenu;
}
void FoldersPanel::keyPressEvent(QKeyEvent* event)
{
m_treeView->setExpanded(index, true);
selectLeafDirectory();
- m_treeView->resizeColumnToContents(DolphinModel::Name);
}
void FoldersPanel::scrollToLeaf()
m_mouseButtons = QApplication::mouseButtons();
}
+void FoldersPanel::slotDirListerCompleted()
+{
+ m_treeView->resizeColumnToContents(DolphinModel::Name);
+
+ if (m_setLeafVisible) {
+ // Invoke scrollToLeaf() asynchronously. This assures that
+ // the horizontal scrollbar is shown after resizing the column
+ // (otherwise the scrollbar might hide the leaf).
+ QTimer::singleShot(0, this, SLOT(scrollToLeaf()));
+ m_setLeafVisible = false;
+ }
+}
+
void FoldersPanel::loadTree(const KUrl& url)
{
Q_ASSERT(m_dirLister != 0);
{
const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
- if (!proxyIndex.isValid()) {
- return;
- }
-
- if (m_setLeafVisible) {
- // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by
- // scrollToLeaf(). This assures that the scrolling is done after
- // the horizontal scrollbar gets visible (otherwise the scrollbar
- // might hide the leaf).
- QTimer::singleShot(100, this, SLOT(scrollToLeaf()));
- m_setLeafVisible = false;
+ if (proxyIndex.isValid()) {
+ QItemSelectionModel* selModel = m_treeView->selectionModel();
+ selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
}
-
- QItemSelectionModel* selModel = m_treeView->selectionModel();
- selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
}
#include "folderspanel.moc"
void setShowHiddenFiles(bool show);
bool showHiddenFiles() const;
+ void setAutoScrolling(bool enable);
+ bool autoScrolling() const;
+
void rename(const KFileItem& item);
signals:
void updateMouseButtons();
+ void slotDirListerCompleted();
+
private:
/**
* Initializes the base URL of the tree and expands all
KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView *parent) :
parent(parent),
autoHorizontalScroll(false),
- timeLine(0),
- startScrollTimer(0)
+ timeLine(0)
{
- startScrollTimer = new QTimer(this);
- startScrollTimer->setSingleShot(true);
- startScrollTimer->setInterval(300);
- connect(startScrollTimer, SIGNAL(timeout()),
- this, SLOT(startScrolling()));
-
- timeLine = new QTimeLine(300, this);
+ timeLine = new QTimeLine(500, this);
connect(timeLine, SIGNAL(frameChanged(int)),
this, SLOT(updateVerticalScrollBar(int)));
connect(parent->verticalScrollBar(), SIGNAL(rangeChanged(int, int)),
- startScrollTimer, SLOT(start()));
+ this, SLOT(startScrolling()));
connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)),
- startScrollTimer, SLOT(start()));
+ this, SLOT(startScrolling()));
connect(parent, SIGNAL(collapsed(const QModelIndex&)),
- startScrollTimer, SLOT(start()));
+ this, SLOT(startScrolling()));
connect(parent, SIGNAL(expanded(const QModelIndex&)),
- startScrollTimer, SLOT(start()));
+ this, SLOT(startScrolling()));
}
void KTreeView::KTreeViewPrivate::startScrolling()
{
- QModelIndex index;
-
- const int viewportHeight = parent->viewport()->height();
-
- // check whether there is a selected index which is partly visible
- const QModelIndexList selectedIndexes = parent->selectionModel()->selectedIndexes();
- if (selectedIndexes.count() == 1) {
- QModelIndex selectedIndex = selectedIndexes.first();
- const QRect rect = parent->visualRect(selectedIndex);
- if ((rect.bottom() >= 0) && (rect.top() <= viewportHeight)) {
- // the selected index is (at least partly) visible, use it as
- // scroll target
- index = selectedIndex;
- }
+ if (!autoHorizontalScroll) {
+ return;
}
- if (!index.isValid()) {
- // no partly selected index is visible, determine the most left visual index
- QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0));
- if (!visibleIndex.isValid()) {
- return;
- }
-
- index = visibleIndex;
- int minimum = parent->width();
- do {
- const QRect rect = parent->visualRect(visibleIndex);
- if (rect.top() > viewportHeight) {
- // 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());
+ // Determine the most left visual index
+ QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0));
+ if (!visibleIndex.isValid()) {
+ return;
}
- // start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible
+ 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();
+ QScrollBar* scrollBar = parent->horizontalScrollBar();
const int oldScrollBarPos = scrollBar->value();
const int itemRight = oldScrollBarPos + rect.left() + rect.width() - 1;
{
QScrollBar *scrollBar = parent->horizontalScrollBar();
scrollBar->setValue(value);
- startScrollTimer->stop();
}
// ************************************************
void KTreeView::setAutoHorizontalScroll(bool value)
{
- d->autoHorizontalScroll = value;
+ d->autoHorizontalScroll = value;
}
bool KTreeView::autoHorizontalScroll() const
{
- return d->autoHorizontalScroll;
+ return d->autoHorizontalScroll;
}
void KTreeView::setSelectionModel(QItemSelectionModel *selectionModel)
QTreeView::setSelectionModel(selectionModel);
connect(selectionModel,
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
- d->startScrollTimer, SLOT(start()));
+ this, SLOT(startScrolling()));
}
void KTreeView::scrollTo(const QModelIndex& index, ScrollHint hint)
{
- if (d->autoHorizontalScroll) {
- // assure that the value of the horizontal scrollbar stays on its current value,
- // KTreeView will adjust the value manually
- const int value = horizontalScrollBar()->value();
- QTreeView::scrollTo(index, hint);
- horizontalScrollBar()->setValue(value);
- } else {
- QTreeView::scrollTo(index, hint);
- }
+ const int value = horizontalScrollBar()->value();
+ QTreeView::scrollTo(index, hint);
+ horizontalScrollBar()->setValue(value);
}
void KTreeView::hideEvent(QHideEvent *event)
{
- d->startScrollTimer->stop();
d->timeLine->stop();
QTreeView::hideEvent(event);
}
#include "ktreeview.h"
-class QTimer;
class QTimeLine;
class KTreeView::KTreeViewPrivate : public QObject
public:
KTreeViewPrivate(KTreeView *parent);
KTreeView *parent;
- void setScrollTowards( int scrollTowards );
bool autoHorizontalScroll;
QTimeLine *timeLine;
- QTimer *startScrollTimer;
};
#endif /* ifndef KTREEVIEW_P_H */
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
- * Cvetoslav Ludmiloff *
+ * Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com> *
+ * Copyright (C) 2006 by Cvetoslav Ludmiloff *
* *
* 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 *
#include "treeviewcontextmenu.h"
-#include "dolphin_folderspanelsettings.h"
-
#include <kfileitem.h>
#include <kiconloader.h>
#include <kio/deletejob.h>
KConfigGroup configGroup(globalConfig, "KDE");
bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);
- const KUrl& url = m_fileInfo.url();
+ const KUrl url = m_fileInfo.url();
if (url.isLocalFile()) {
QAction* moveToTrashAction = new QAction(KIcon("user-trash"),
i18nc("@action:inmenu", "Move to Trash"), this);
QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
showHiddenFilesAction->setCheckable(true);
- showHiddenFilesAction->setChecked(FoldersPanelSettings::showHiddenFiles());
+ showHiddenFilesAction->setChecked(m_parent->showHiddenFiles());
popup->addAction(showHiddenFilesAction);
-
connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool)));
+ QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this);
+ autoScrollingAction->setCheckable(true);
+ autoScrollingAction->setChecked(m_parent->autoScrolling());
+ popup->addAction(autoScrollingAction);
+ connect(autoScrollingAction, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool)));
+
+
popup->exec(QCursor::pos());
popup->deleteLater();
}
m_parent->setShowHiddenFiles(show);
}
+void TreeViewContextMenu::setAutoScrolling(bool enable)
+{
+ m_parent->setAutoScrolling(enable);
+}
+
#include "treeviewcontextmenu.moc"
*/
void setShowHiddenFiles(bool show);
+ /**
+ * Sets the 'Automatic Scrolling' setting for the
+ * folders panel to \a enable.
+ */
+ void setAutoScrolling(bool enable);
+
private:
void populateMimeData(QMimeData* mimeData, bool cut);