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.
views/dolphinviewactionhandler.cpp
views/dolphinviewautoscroller.cpp
views/draganddrophelper.cpp
- views/folderexpander.cpp
views/renamedialog.cpp
views/tooltips/filemetadatatooltip.cpp
views/tooltips/tooltipmanager.cpp
panels/information/informationpanelcontent.cpp
panels/information/pixmapviewer.cpp
panels/information/phononwidget.cpp
- panels/folders/ktreeview.cpp
panels/places/placespanel.cpp
panels/panel.cpp
panels/folders/treeviewcontextmenu.cpp
panels/folders/folderspanel.cpp
- panels/folders/paneltreeview.cpp
search/dolphinsearchbox.cpp
search/dolphinsearchinformation.cpp
settings/general/behaviorsettingspage.cpp
m_updateIconSizeTimer->setInterval(ShortInterval);
connect(m_updateIconSizeTimer, SIGNAL(timeout()), this, SLOT(updateIconSize()));
+ setVisibleRoles(QList<QByteArray>() << "name");
+
updateMinimumRolesWidths();
}
default: Q_ASSERT(false); break;
}
- fileItemListWidget->setAlternatingBackgroundColors(m_itemLayout == DetailsLayout);
+ fileItemListWidget->setAlternatingBackgroundColors(m_itemLayout == DetailsLayout &&
+ visibleRoles().count() > 1);
}
bool KFileItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const
m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this);
const int size = styleOption().iconSize;
m_modelRolesUpdater->setIconSize(QSize(size, size));
+
+ applyRolesToModel();
}
void KFileItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
Q_UNUSED(current);
Q_UNUSED(previous);
applyRolesToModel();
+
+ if (m_itemLayout == DetailsLayout) {
+ // Only enable the alternating background colors if more than one role
+ // is visible
+ const int previousCount = previous.count();
+ const int currentCount = current.count();
+ if ((previousCount <= 1 && currentCount > 1) || (previousCount > 1 && currentCount <= 1)) {
+ const bool enabled = (currentCount > 1);
+ foreach (KItemListWidget* widget, visibleItemListWidgets()) {
+ widget->setAlternatingBackgroundColors(enabled);
+ }
+ }
+ }
}
void KFileItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous)
void KFileItemListView::triggerVisibleIndexRangeUpdate()
{
+ if (!model()) {
+ return;
+ }
m_modelRolesUpdater->setPaused(true);
m_updateVisibleIndexRangeTimer->start();
}
void KFileItemListView::triggerIconSizeUpdate()
{
+ if (!model()) {
+ return;
+ }
m_modelRolesUpdater->setPaused(true);
m_updateIconSizeTimer->start();
}
void KFileItemListView::updateLayoutOfVisibleItems()
{
+ if (!model()) {
+ return;
+ }
+
foreach (KItemListWidget* widget, visibleItemListWidgets()) {
initializeItemListWidget(widget);
}
void KFileItemListView::applyRolesToModel()
{
+ if (!model()) {
+ return;
+ }
+
Q_ASSERT(qobject_cast<KFileItemModel*>(model()));
KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model());
m_groups(),
m_rootExpansionLevel(-1),
m_expandedUrls(),
- m_restoredExpandedUrls()
+ m_urlsToExpand()
{
// Apply default roles that should be determined
resetRoles();
return m_expandedUrls;
}
-void KFileItemModel::restoreExpandedUrls(const QSet<KUrl>& urls)
+void KFileItemModel::setExpanded(const QSet<KUrl>& urls)
{
- m_restoredExpandedUrls = urls;
+
+ const KDirLister* dirLister = m_dirLister.data();
+ if (!dirLister) {
+ return;
+ }
+
+ const int pos = dirLister->url().url().length();
+
+ // Assure that each sub-path of the URLs that should be
+ // expanded is added to m_urlsToExpand too. KDirLister
+ // does not care whether the parent-URL has already been
+ // expanded.
+ QSetIterator<KUrl> it1(urls);
+ while (it1.hasNext()) {
+ const KUrl& url = it1.next();
+
+ KUrl urlToExpand = dirLister->url();
+ const QStringList subDirs = url.url().mid(pos).split(QDir::separator());
+ for (int i = 0; i < subDirs.count(); ++i) {
+ urlToExpand.addPath(subDirs.at(i));
+ m_urlsToExpand.insert(urlToExpand);
+ }
+ }
+
+ // KDirLister::open() must called at least once to trigger an initial
+ // loading. The pending URLs that must be restored are handled
+ // in slotCompleted().
+ QSetIterator<KUrl> it2(m_urlsToExpand);
+ while (it2.hasNext()) {
+ const int idx = index(it2.next());
+ if (idx >= 0 && !isExpanded(idx)) {
+ setExpanded(idx, true);
+ break;
+ }
+ }
}
void KFileItemModel::onGroupedSortingChanged(bool current)
void KFileItemModel::slotCompleted()
{
- if (m_restoredExpandedUrls.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) {
+ if (m_urlsToExpand.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) {
// dispatchPendingItems() will be called when the timer
// has been expired.
m_pendingEmitLoadingCompleted = true;
m_pendingEmitLoadingCompleted = false;
dispatchPendingItemsToInsert();
- if (!m_restoredExpandedUrls.isEmpty()) {
+ if (!m_urlsToExpand.isEmpty()) {
// Try to find a URL that can be expanded.
// Note that the parent folder must be expanded before any of its subfolders become visible.
// Therefore, some URLs in m_restoredExpandedUrls might not be visible yet
// -> we expand the first visible URL we find in m_restoredExpandedUrls.
- foreach(const KUrl& url, m_restoredExpandedUrls) {
+ foreach(const KUrl& url, m_urlsToExpand) {
const int index = m_items.value(url, -1);
if (index >= 0) {
- // We have found an expandable URL. Expand it and return - when
- // the dir lister has finished, this slot will be called again.
- m_restoredExpandedUrls.remove(url);
- setExpanded(index, true);
- return;
+ m_urlsToExpand.remove(url);
+ if (setExpanded(index, true)) {
+ // The dir lister has been triggered. This slot will be called
+ // again after the directory has been expanded.
+ return;
+ }
}
}
// None of the URLs in m_restoredExpandedUrls could be found in the model. This can happen
// if these URLs have been deleted in the meantime.
- m_restoredExpandedUrls.clear();
+ m_urlsToExpand.clear();
}
emit loadingCompleted();
bool isExpanded(int index) const;
bool isExpandable(int index) const;
QSet<KUrl> expandedUrls() const;
- void restoreExpandedUrls(const QSet<KUrl>& urls);
+
+ /**
+ * Expands all parent-items of each URL given by \a urls.
+ */
+ void setExpanded(const QSet<KUrl>& urls);
signals:
void loadingCompleted();
// Stores the URLs of the expanded folders.
QSet<KUrl> m_expandedUrls;
- // Stores the URLs which have to be expanded in order to restore a previous state of the model.
- QSet<KUrl> m_restoredExpandedUrls;
+ // URLs that must be expanded. The expanding is initially triggered in setExpanded()
+ // and done step after step in slotCompleted().
+ QSet<KUrl> m_urlsToExpand;
friend class KFileItemModelTest; // For unit testing
};
void KItemListContainer::initialize()
{
- if (!m_controller) {
+ if (m_controller) {
+ if (m_controller->model()) {
+ slotModelChanged(m_controller->model(), 0);
+ }
+ if (m_controller->view()) {
+ slotViewChanged(m_controller->view(), 0);
+ }
+ } else {
m_controller = new KItemListController(this);
}
#include "kitemliststyleoption.h"
+#include <KIconLoader>
+
KItemListStyleOption::KItemListStyleOption() :
rect(),
font(),
fontMetrics(QFont()),
palette(),
margin(0),
- iconSize(0)
+ iconSize(KIconLoader::SizeMedium)
{
}
}
m_model = model;
- m_layouter->setModel(model);
+ m_layouter->setModel(model);
m_grouped = model->groupedSorting();
if (m_model) {
m_layoutTimer->stop();
}
- if (m_model->count() < 0 || m_activeTransactions > 0) {
+ if (!m_model || m_model->count() < 0 || m_activeTransactions > 0) {
return;
}
void KItemListView::updateVisibleRolesSizes()
{
+ if (!m_model) {
+ return;
+ }
+
const int itemCount = m_model->count();
if (itemCount > 0) {
updateVisibleRolesSizes(KItemRangeList() << KItemRange(0, itemCount));
void KItemListView::updateStretchedVisibleRolesSizes()
{
- if (!m_itemSize.isEmpty() || m_useHeaderWidths) {
+ if (!m_itemSize.isEmpty() || m_useHeaderWidths || m_visibleRoles.isEmpty()) {
return;
}
// size does not use the available view-size it the size of the
// first role will get stretched.
m_stretchedVisibleRolesSizes = m_visibleRolesSizes;
- const QByteArray role = visibleRoles().first();
+ const QByteArray role = m_visibleRoles.first();
QSizeF firstRoleSize = m_stretchedVisibleRolesSizes.value(role);
QSizeF dynamicItemSize = m_itemSize;
#include "dolphin_folderspanelsettings.h"
#include "dolphin_generalsettings.h"
-#include "paneltreeview.h"
#include "treeviewcontextmenu.h"
+#include <kitemviews/kitemlistselectionmanager.h>
+#include <kitemviews/kfileitemlistview.h>
+#include <kitemviews/kfileitemlistwidget.h>
+#include <kitemviews/kitemlistcontainer.h>
+#include <kitemviews/kitemlistcontroller.h>
+#include <kitemviews/kfileitemmodel.h>
+
#include <KDirLister>
#include <KFileItem>
#include <konq_operations.h>
#include <QApplication>
#include <QBoxLayout>
-#include <QItemSelection>
-#include <QModelIndex>
-#include <QPointer>
-#include <QTreeView>
-#include <QScrollBar>
+#include <QGraphicsView>
#include <QTimer>
-#include <views/dolphinview.h>
-#include <views/folderexpander.h>
#include <views/renamedialog.h>
+#include <KDebug>
+
FoldersPanel::FoldersPanel(QWidget* parent) :
Panel(parent),
m_setLeafVisible(false),
m_mouseButtons(Qt::NoButton),
m_dirLister(0),
- //m_dolphinModel(0),
- //m_proxyModel(0),
- m_treeView(0),
+ m_controller(0),
m_leafDir()
{
setLayoutDirection(Qt::LeftToRight);
{
FoldersPanelSettings::self()->writeConfig();
- //delete m_proxyModel;
- //m_proxyModel = 0;
- //delete m_dolphinModel;
- //m_dolphinModel = 0;
+ KItemListView* view = m_controller->view();
+ m_controller->setView(0);
+ delete view;
+
delete m_dirLister;
m_dirLister = 0;
}
{
FoldersPanelSettings::setHiddenFilesShown(show);
if (m_dirLister) {
+ KFileItemModel* model = fileItemModel();
+ const QSet<KUrl> expandedUrls = model->expandedUrls();
m_dirLister->setShowingDotFiles(show);
m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload);
+ model->setExpanded(expandedUrls);
}
}
void FoldersPanel::setAutoScrolling(bool enable)
{
- m_treeView->setAutoHorizontalScroll(enable);
+ //m_treeView->setAutoHorizontalScroll(enable);
FoldersPanelSettings::setAutoScrolling(enable);
}
m_dirLister->setDelayedMimeTypes(true);
m_dirLister->setAutoErrorHandlingEnabled(false, this);
m_dirLister->setShowingDotFiles(FoldersPanelSettings::hiddenFilesShown());
- connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
-
- /*Q_ASSERT(!m_dolphinModel);
- m_dolphinModel = new DolphinModel(this);
- m_dolphinModel->setDirLister(m_dirLister);
- m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory);
- connect(m_dolphinModel, SIGNAL(expand(QModelIndex)),
- this, SLOT(expandToDir(QModelIndex)));
-
- Q_ASSERT(!m_proxyModel);
- m_proxyModel = new DolphinSortFilterProxyModel(this);
- m_proxyModel->setSourceModel(m_dolphinModel);
-
- Q_ASSERT(!m_treeView);
- m_treeView = new PanelTreeView(this);
- m_treeView->setModel(m_proxyModel);
- m_proxyModel->setSorting(DolphinView::SortByName);
- m_proxyModel->setSortOrder(Qt::AscendingOrder);
- m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
-
- new FolderExpander(m_treeView, m_proxyModel);
-
- connect(m_treeView, SIGNAL(clicked(QModelIndex)),
- this, SLOT(updateActiveView(QModelIndex)));
- connect(m_treeView, SIGNAL(urlsDropped(QModelIndex,QDropEvent*)),
- this, SLOT(dropUrls(QModelIndex,QDropEvent*)));
- connect(m_treeView, SIGNAL(pressed(QModelIndex)),
- this, SLOT(updateMouseButtons()));
-
- connect(m_treeView->horizontalScrollBar(), SIGNAL(sliderMoved(int)),
- this, SLOT(slotHorizontalScrollBarMoved(int)));
- connect(m_treeView->verticalScrollBar(), SIGNAL(valueChanged(int)),
- this, SLOT(slotVerticalScrollBarMoved(int)));
+
+ KFileItemListView* view = new KFileItemListView();
+ view->setWidgetCreator(new KItemListWidgetCreator<KFileItemListWidget>());
+
+ KItemListStyleOption styleOption = view->styleOption();
+ styleOption.margin = 2;
+ styleOption.iconSize = KIconLoader::SizeSmall;
+ view->setStyleOption(styleOption);
+
+ const qreal itemHeight = qMax(int(KIconLoader::SizeSmall), styleOption.fontMetrics.height());
+ view->setItemSize(QSizeF(-1, itemHeight + 2 * styleOption.margin));
+ view->setItemLayout(KFileItemListView::DetailsLayout);
+
+ KFileItemModel* model = new KFileItemModel(m_dirLister, this);
+ // Use a QueuedConnection to give the view the possibility to react first on the
+ // finished loading.
+ connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection);
+
+ KItemListContainer* container = new KItemListContainer(this);
+ m_controller = container->controller();
+ m_controller->setView(view);
+ m_controller->setModel(model);
+
+ // TODO: Check whether it makes sense to make an explicit API for KItemListContainer
+ // to make the background transparent.
+ container->setFrameShape(QFrame::NoFrame);
+ QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(container->viewport());
+ if (graphicsView) {
+ // Make the background of the container transparent and apply the window-text color
+ // to the text color, so that enough contrast is given for all color
+ // schemes
+ QPalette p = graphicsView->palette();
+ p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
+ p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
+ p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
+ graphicsView->setPalette(p);
+ graphicsView->viewport()->setAutoFillBackground(false);
+ }
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
- layout->addWidget(m_treeView);*/
+ layout->addWidget(container);
}
loadTree(url());
const int key = event->key();
if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) {
event->accept();
- updateActiveView(m_treeView->currentIndex());
+ //updateActiveView(m_treeView->currentIndex());
} else {
Panel::keyPressEvent(event);
}
}
-void FoldersPanel::updateActiveView(const QModelIndex& index)
-{
- Q_UNUSED(index);
- /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
- const KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
- if (!item.isNull()) {
- emit changeUrl(item.url(), m_mouseButtons);
- }*/
-}
-
-void FoldersPanel::dropUrls(const QModelIndex& index, QDropEvent* event)
-{
- Q_UNUSED(event);
- if (index.isValid()) {
- /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
- KFileItem item = m_dolphinModel->itemForIndex(dirIndex);
- Q_ASSERT(!item.isNull());
- if (item.isDir()) {
- Q_UNUSED(event);
- //DragAndDropHelper::instance().dropUrls(item, item.url(), event, this);
- }*/
- }
-}
-
-void FoldersPanel::expandToDir(const QModelIndex& index)
-{
- m_treeView->setExpanded(index, true);
- selectLeafDirectory();
-}
-
-void FoldersPanel::scrollToLeaf()
-{
- /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
- const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
- if (proxyIndex.isValid()) {
- m_treeView->scrollTo(proxyIndex);
- }*/
-}
-
void FoldersPanel::updateMouseButtons()
{
m_mouseButtons = QApplication::mouseButtons();
}
-void FoldersPanel::slotDirListerCompleted()
+void FoldersPanel::slotLoadingCompleted()
{
-// m_treeView->resizeColumnToContents(DolphinModel::Name);
+ const int index = fileItemModel()->index(url());
+ if (index >= 0) {
+ m_controller->selectionManager()->setCurrentItem(index);
+ }
}
void FoldersPanel::slotHorizontalScrollBarMoved(int value)
Q_UNUSED(value);
// Disable the auto-scrolling until the vertical scrollbar has
// been moved by the user.
- m_treeView->setAutoHorizontalScroll(false);
+ //m_treeView->setAutoHorizontalScroll(false);
}
void FoldersPanel::slotVerticalScrollBarMoved(int value)
Q_UNUSED(value);
// Enable the auto-scrolling again (it might have been disabled by
// moving the horizontal scrollbar).
- m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
+ //m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling());
}
void FoldersPanel::loadTree(const KUrl& url)
KUrl baseUrl;
if (url.isLocalFile()) {
- // use the root directory as base for local URLs (#150941)
+ // Use the root directory as base for local URLs (#150941)
baseUrl = QDir::rootPath();
} else {
- // clear the path for non-local URLs and use it as base
+ // Clear the path for non-local URLs and use it as base
baseUrl = url;
baseUrl.setPath(QString('/'));
}
m_dirLister->stop();
m_dirLister->openUrl(baseUrl, KDirLister::Reload);
}
- //m_dolphinModel->expandToUrl(m_leafDir);
+
+ KFileItemModel* model = fileItemModel();
+ const int index = model->index(url);
+ if (index >= 0) {
+ m_controller->selectionManager()->setCurrentItem(index);
+ } else {
+ model->setExpanded(QSet<KUrl>() << url);
+ }
}
void FoldersPanel::selectLeafDirectory()
}*/
}
+KFileItemModel* FoldersPanel::fileItemModel() const
+{
+ return static_cast<KFileItemModel*>(m_controller->model());
+}
+
#include "folderspanel.moc"
#include <panels/panel.h>
class KDirLister;
-class DolphinModel;
-
-class DolphinSortFilterProxyModel;
-class PanelTreeView;
-class QModelIndex;
+class KFileItemModel;
+class KItemListController;
/**
* @brief Shows a tree view of the directories starting from
* Updates the active view to the URL
* which is given by the item with the index \a index.
*/
- void updateActiveView(const QModelIndex& index);
+ //void updateActiveView(const QModelIndex& index);
/**
* Is emitted if URLs have been dropped
* to the index \a index.
*/
- void dropUrls(const QModelIndex& index, QDropEvent* event);
+ //void dropUrls(const QModelIndex& index, QDropEvent* event);
/**
* Expands the treeview to show the directory
* specified by \a index.
*/
- void expandToDir(const QModelIndex& index);
+ //void expandToDir(const QModelIndex& index);
/**
* Assures that the leaf folder gets visible.
*/
- void scrollToLeaf();
+ //void scrollToLeaf();
void updateMouseButtons();
- void slotDirListerCompleted();
+ void slotLoadingCompleted();
void slotHorizontalScrollBarMoved(int value);
*/
void selectLeafDirectory();
+ KFileItemModel* fileItemModel() const;
+
private:
bool m_setLeafVisible;
Qt::MouseButtons m_mouseButtons;
KDirLister* m_dirLister;
- //DolphinModel* m_dolphinModel;
- //DolphinSortFilterProxyModel* m_proxyModel;
- PanelTreeView* m_treeView;
+ KItemListController* m_controller;
KUrl m_leafDir;
};
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2008 by <haraldhv (at) stud.ntnu.no> *
- * Copyright (C) 2008 by <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 *
- * 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"
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2008 by <haraldhv (at) stud.ntnu.no> *
- * Copyright (C) 2008 by <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 *
- * 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 *
- ***************************************************************************/
-
-#ifndef KTREEVIEW_H
-#define KTREEVIEW_H
-
-#include <QTreeView>
-
-class KTreeView : public QTreeView
-{
- Q_OBJECT
-
-public:
- KTreeView(QWidget *parent = 0);
- virtual ~KTreeView();
-
- void setAutoHorizontalScroll(bool enable);
- bool autoHorizontalScroll() const;
-
- virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
-
-protected:
- virtual void hideEvent(QHideEvent *event);
-
-private:
- class KTreeViewPrivate;
- KTreeViewPrivate *d;
-};
-
-#endif /* ifndef KTREEVIEW_H */
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2006 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 *
- * 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 "paneltreeview.h"
-
-#include <KFileItemDelegate>
-#include <QListView>
-#include <QKeyEvent>
-#include <QPainter>
-#include <QHeaderView>
-#include <QScrollBar>
-
-PanelTreeView::PanelTreeView(QWidget* parent) :
- KTreeView(parent)
-{
- setAcceptDrops(true);
- setUniformRowHeights(true);
- setSelectionMode(QAbstractItemView::SingleSelection);
- setEditTriggers(QAbstractItemView::NoEditTriggers);
- setSortingEnabled(true);
- setFrameStyle(QFrame::NoFrame);
- setDragDropMode(QAbstractItemView::DragDrop);
- setDropIndicatorShown(false);
-
- setVerticalScrollMode(QListView::ScrollPerPixel);
- setHorizontalScrollMode(QListView::ScrollPerPixel);
-
- viewport()->setAttribute(Qt::WA_Hover);
-
- // make the background transparent and apply the window-text color
- // to the text color, so that enough contrast is given for all color
- // schemes
- QPalette p = palette();
- p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
- p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
- p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
- setPalette(p);
- viewport()->setAutoFillBackground(false);
-
- KFileItemDelegate* delegate = new KFileItemDelegate(this);
- setItemDelegate(delegate);
-}
-
-PanelTreeView::~PanelTreeView()
-{
-}
-
-bool PanelTreeView::event(QEvent* event)
-{
- switch (event->type()) {
- case QEvent::Polish:
- // Hide all columns except of the 'Name' column
- /*for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) {
- hideColumn(i);
- }
- header()->hide();*/
- break;
-
- case QEvent::Show:
- // TODO: The opening/closing animation of subtrees flickers in combination with the
- // panel when using the Oxygen style. As workaround the animation is turned off:
- setAnimated(false);
- break;
-
- case QEvent::UpdateRequest:
- // a wheel movement will scroll 1 item
- if (model()->rowCount() > 0) {
- verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
- }
- break;
-
- default:
- break;
- }
-
- return KTreeView::event(event);
-}
-
-void PanelTreeView::startDrag(Qt::DropActions supportedActions)
-{
- Q_UNUSED(supportedActions);
- //DragAndDropHelper::instance().startDrag(this, supportedActions);
-}
-
-void PanelTreeView::dragEnterEvent(QDragEnterEvent* event)
-{
- KTreeView::dragEnterEvent(event);
- if (event->mimeData()->hasUrls()) {
- event->acceptProposedAction();
- }
-}
-
-void PanelTreeView::dragLeaveEvent(QDragLeaveEvent* event)
-{
- KTreeView::dragLeaveEvent(event);
- setDirtyRegion(m_dropRect);
-}
-
-void PanelTreeView::dragMoveEvent(QDragMoveEvent* event)
-{
- KTreeView::dragMoveEvent(event);
-
- // TODO: remove this code when the issue #160611 is solved in Qt 4.4
- const QModelIndex index = indexAt(event->pos());
- setDirtyRegion(m_dropRect);
- m_dropRect = visualRect(index);
- setDirtyRegion(m_dropRect);
-
- if (event->mimeData()->hasUrls()) {
- // accept url drops, independently from the destination item
- event->acceptProposedAction();
- }
-}
-
-void PanelTreeView::dropEvent(QDropEvent* event)
-{
- const QModelIndex index = indexAt(event->pos());
- if (index.isValid()) {
- emit urlsDropped(index, event);
- }
- KTreeView::dropEvent(event);
-}
-
-#include "paneltreeview.moc"
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2006 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 *
- * 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 *
- ***************************************************************************/
-
-#ifndef PANELTREEVIEW_H
-#define PANELTREEVIEW_H
-
-#include <KUrl>
-#include <panels/folders/ktreeview.h>
-
-/**
- * @brief Tree view widget which is used for the folders panel.
- *
- * @see FoldersPanel
- */
-class PanelTreeView : public KTreeView
-{
- Q_OBJECT
-
-public:
- explicit PanelTreeView(QWidget* parent = 0);
- virtual ~PanelTreeView();
-
-signals:
- /**
- * Is emitted if the URL have been dropped to
- * the index \a index.
- */
- void urlsDropped(const QModelIndex& index, QDropEvent* event);
-
-protected:
- virtual bool event(QEvent* event);
- virtual void startDrag(Qt::DropActions supportedActions);
- virtual void dragEnterEvent(QDragEnterEvent* event);
- virtual void dragLeaveEvent(QDragLeaveEvent* event);
- virtual void dragMoveEvent(QDragMoveEvent* event);
- virtual void dropEvent(QDropEvent* event);
-
-private:
- QRect m_dropRect;
-};
-
-#endif
QVERIFY(m_model->expandedUrls().empty());
m_dirLister->openUrl(m_testDir->url());
- m_model->restoreExpandedUrls(allFolders);
+ m_model->setExpanded(allFolders);
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout));
QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
QVERIFY(m_model->isExpanded(0));
CompactModeSettings::self()->writeConfig();
DetailsModeSettings::self()->writeConfig();
- KItemListView* view = controller()->view();
controller()->setView(0);
- delete view;
+ delete m_fileItemListView;
+ m_fileItemListView = 0;
}
void DolphinItemListContainer::setPreviewsShown(bool show)
// Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
QSet<KUrl> urls;
stream >> urls;
- fileItemModel()->restoreExpandedUrls(urls);
+ fileItemModel()->setExpanded(urls);
}
void DolphinView::saveState(QDataStream& stream)
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2008 by Simon St James <kdedevel@etotheipiplusone.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 *
- * 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 "folderexpander.h"
-
-#include <QTimer>
-#include <QAbstractItemView>
-#include <QTreeView>
-#include <QScrollBar>
-
-#include <QEvent>
-#include <QDragMoveEvent>
-
-#include <QSortFilterProxyModel>
-
-#include <KDirModel>
-
-FolderExpander::FolderExpander(QAbstractItemView *view, QSortFilterProxyModel *proxyModel) :
- QObject(view),
- m_enabled(true),
- m_view(view),
- m_proxyModel(proxyModel),
- m_autoExpandTriggerTimer(0),
- m_autoExpandPos()
-{
- if (!m_view || !m_proxyModel) {
- return;
- }
- KDirModel *m_dirModel = qobject_cast<KDirModel*>(m_proxyModel->sourceModel());
- if (!m_dirModel) {
- return;
- }
-
- // Initialise auto-expand timer.
- m_autoExpandTriggerTimer = new QTimer(this);
- m_autoExpandTriggerTimer->setSingleShot(true);
- connect(m_autoExpandTriggerTimer, SIGNAL(timeout()),
- this, SLOT(autoExpandTimeout()));
-
- // The view scrolling complicates matters, so we want to
- // be informed if they occur.
- connect(m_view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
- this, SLOT(viewScrolled()));
- connect(m_view->verticalScrollBar(), SIGNAL(valueChanged(int)),
- this, SLOT(viewScrolled()));
-
- // "Dragging" events are sent to the QAbstractItemView's viewport.
- m_view->viewport()->installEventFilter(this);
-}
-
-void FolderExpander::setEnabled(bool enabled)
-{
- m_enabled = enabled;
-}
-
-bool FolderExpander::enabled() const
-{
- return m_enabled;
-}
-
-FolderExpander::~FolderExpander()
-{
-}
-
-void FolderExpander::viewScrolled()
-{
- if (m_autoExpandTriggerTimer->isActive()) {
- m_autoExpandTriggerTimer->start(AUTO_EXPAND_DELAY);
- }
-}
-
-void FolderExpander::autoExpandTimeout()
-{
- if (!m_enabled) {
- return;
- }
-
- // We want to find whether the file currently being hovered over is a
- // directory. TODO - is there a simpler way, preferably without
- // needing to pass in m_proxyModel that has a KDirModel as its sourceModel() ... ?
- QModelIndex proxyIndexToExpand = m_view->indexAt(m_autoExpandPos);
- QModelIndex indexToExpand = m_proxyModel->mapToSource(proxyIndexToExpand);
- KDirModel* m_dirModel = qobject_cast< KDirModel* >(m_proxyModel->sourceModel());
- Q_ASSERT(m_dirModel);
- KFileItem itemToExpand = m_dirModel->itemForIndex(indexToExpand);
-
- if (itemToExpand.isNull() || itemToExpand == m_dirModel->itemForIndex(QModelIndex())) {
- // The second clause occurs when we are expanding the folder represented
- // by the view, which is a case we should ignore (#182618).
- return;
- }
-
- if (itemToExpand.isDir()) {
- QTreeView* treeView = qobject_cast<QTreeView*>(m_view);
- if (treeView && treeView->itemsExpandable()) {
- // Toggle expanded state of this directory.
- treeView->setExpanded(proxyIndexToExpand, !treeView->isExpanded(proxyIndexToExpand));
- }
- else {
- emit enterDir(proxyIndexToExpand);
- }
- }
-}
-
-bool FolderExpander::eventFilter(QObject* watched, QEvent* event)
-{
- Q_UNUSED(watched);
- // We're interested in reading Drag* events, but not filtering them,
- // so always return false.
- // We just store the position of the hover, here; actually working out
- // what the hovered item is and whether it is expandable is done in
- // autoExpandTimeout.
- if (event->type() == QEvent::DragMove) {
- QDragMoveEvent *dragMoveEvent = static_cast<QDragMoveEvent*>(event);
- // (Re-)set the timer while we're still moving and dragging.
- m_autoExpandTriggerTimer->start(AUTO_EXPAND_DELAY);
- m_autoExpandPos = dragMoveEvent->pos();
- } else if (event->type() == QEvent::DragLeave || event->type() == QEvent::Drop) {
- m_autoExpandTriggerTimer->stop();
- }
- return false;
-}
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2008 by Simon St James <kdedevel@etotheipiplusone.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 *
- * 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 *
- ***************************************************************************/
-
-#ifndef FOLDEREXPANDER_H
-#define FOLDEREXPANDER_H
-
-// Needs to be exported as FoldersPanel uses it.
-#include "libdolphin_export.h"
-
-#include <QObject>
-#include <QPoint>
-
-class QAbstractItemView;
-class QTreeView;
-class QTimer;
-class QSortFilterProxyModel;
-class QModelIndex;
-
-/**
- * Grants auto expanding functionality to the provided item view.
- * Qt has its own auto expand mechanism, but this works only
- * for QTreeView. Auto expanding of folders is turned on
- * per default.
- *
- * If the provided view is an instance of the class QTreeView, the
- * expansion of the directory is automatically done on hover. Otherwise
- * the enterDir() signal is emitted and the caller needs to ensure that
- * the requested directory is entered.
- *
- * The FolderExpander becomes a child of the provided view.
- */
-class LIBDOLPHINPRIVATE_EXPORT FolderExpander : public QObject
-{
- Q_OBJECT
-
-public:
- FolderExpander(QAbstractItemView* view, QSortFilterProxyModel* proxyModel);
- virtual ~FolderExpander();
-
- void setEnabled(bool enabled);
- bool enabled() const;
-
-signals:
- /**
- * Is emitted if the directory \a dirModelIndex should be entered. The
- * signal is not emitted when a QTreeView is used, as the entering of
- * the directory is already provided by expanding the tree node.
- */
- void enterDir(const QModelIndex& dirModelIndex);
-
-
-private slots:
- void viewScrolled();
- void autoExpandTimeout();
-
-private:
- bool m_enabled;
-
- QAbstractItemView* m_view;
- QSortFilterProxyModel* m_proxyModel;
-
- QTimer* m_autoExpandTriggerTimer;
- QPoint m_autoExpandPos;
-
- static const int AUTO_EXPAND_DELAY = 700;
-
- /**
- * Watchs the drag/move events for the view to decide
- * whether auto expanding of a folder should be triggered.
- */
- bool eventFilter(QObject* watched, QEvent* event);
-};
-#endif