diff options
Diffstat (limited to 'src/views')
45 files changed, 1052 insertions, 8062 deletions
diff --git a/src/views/additionalinfoaccessor.cpp b/src/views/additionalinfoaccessor.cpp index 426d7a2c4..465a2b3dd 100644 --- a/src/views/additionalinfoaccessor.cpp +++ b/src/views/additionalinfoaccessor.cpp @@ -19,7 +19,6 @@ #include "additionalinfoaccessor.h" -#include "dolphinmodel.h" #include <KGlobal> #include <KLocale> @@ -35,31 +34,31 @@ AdditionalInfoAccessor& AdditionalInfoAccessor::instance() return s_additionalInfoManager->instance; } -KFileItemDelegate::InformationList AdditionalInfoAccessor::keys() const +QList<DolphinView::AdditionalInfo> AdditionalInfoAccessor::keys() const { - return m_information; + return m_infoList; } -KFileItemDelegate::Information AdditionalInfoAccessor::keyForColumn(int columnIndex) const +QByteArray AdditionalInfoAccessor::role(DolphinView::AdditionalInfo info) const { - KFileItemDelegate::Information info = KFileItemDelegate::NoInformation; - - switch (columnIndex) { - case DolphinModel::Size: info = KFileItemDelegate::Size; break; - case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break; - case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break; - case DolphinModel::Owner: info = KFileItemDelegate::Owner; break; - case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break; - case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break; - case DolphinModel::LinkDest: info = KFileItemDelegate::LinkDest; break; - case DolphinModel::LocalPathOrUrl: info = KFileItemDelegate::LocalPathOrUrl; break; + QByteArray role; + switch (info) { + case DolphinView::NameInfo: role = "name"; break; + case DolphinView::SizeInfo: role = "size"; break; + case DolphinView::DateInfo: role = "date"; break; + case DolphinView::PermissionsInfo: role = "permissions"; break; + case DolphinView::OwnerInfo: role = "owner"; break; + case DolphinView::GroupInfo: role = "group"; break; + case DolphinView::TypeInfo: role = "type"; break; + case DolphinView::DestinationInfo: role = "destination"; break; + case DolphinView::PathInfo: role = "path"; break; default: break; } - return info; + return role; } -QString AdditionalInfoAccessor::actionCollectionName(KFileItemDelegate::Information info, +QString AdditionalInfoAccessor::actionCollectionName(DolphinView::AdditionalInfo info, ActionCollectionType type) const { QString name; @@ -76,62 +75,56 @@ QString AdditionalInfoAccessor::actionCollectionName(KFileItemDelegate::Informat return name; } -QString AdditionalInfoAccessor::translation(KFileItemDelegate::Information info) const +QString AdditionalInfoAccessor::translation(DolphinView::AdditionalInfo info) const { return i18nc(m_map[info]->context, m_map[info]->translation); } -QString AdditionalInfoAccessor::value(KFileItemDelegate::Information info) const +QString AdditionalInfoAccessor::value(DolphinView::AdditionalInfo info) const { return m_map[info]->value; } -DolphinView::Sorting AdditionalInfoAccessor::sorting(KFileItemDelegate::Information info) const +DolphinView::Sorting AdditionalInfoAccessor::sorting(DolphinView::AdditionalInfo info) const { return m_map[info]->sorting; } -int AdditionalInfoAccessor::bitValue(KFileItemDelegate::Information info) const -{ - return m_map[info]->bitValue; -} - AdditionalInfoAccessor::AdditionalInfoAccessor() : - m_information(), + m_infoList(), m_map() { static const AdditionalInfoAccessor::AdditionalInfo additionalInfo[] = { // Entries for view-properties version 1: - { "size", I18N_NOOP2_NOSTRIP("@label", "Size"), "Size", DolphinView::SortBySize, 1 }, - { "date", I18N_NOOP2_NOSTRIP("@label", "Date"), "Date", DolphinView::SortByDate, 2 }, - { "permissions", I18N_NOOP2_NOSTRIP("@label", "Permissions"), "Permissions", DolphinView::SortByPermissions, 4 }, - { "owner", I18N_NOOP2_NOSTRIP("@label", "Owner"), "Owner", DolphinView::SortByOwner, 8 }, - { "group", I18N_NOOP2_NOSTRIP("@label", "Group"), "Group", DolphinView::SortByGroup, 16 }, - { "type", I18N_NOOP2_NOSTRIP("@label", "Type"), "Type", DolphinView::SortByType, 32 }, - { "destination", I18N_NOOP2_NOSTRIP("@label", "Link Destination"), "LinkDestination", DolphinView::SortByDestination, 64 }, - { "path", I18N_NOOP2_NOSTRIP("@label", "Path"), "Path", DolphinView::SortByPath, 128 } - // Entries for view-properties version >= 2 (the last column can be set to 0): + { "size", I18N_NOOP2_NOSTRIP("@label", "Size"), "Size", DolphinView::SortBySize}, + { "date", I18N_NOOP2_NOSTRIP("@label", "Date"), "Date", DolphinView::SortByDate}, + { "permissions", I18N_NOOP2_NOSTRIP("@label", "Permissions"), "Permissions", DolphinView::SortByPermissions}, + { "owner", I18N_NOOP2_NOSTRIP("@label", "Owner"), "Owner", DolphinView::SortByOwner}, + { "group", I18N_NOOP2_NOSTRIP("@label", "Group"), "Group", DolphinView::SortByGroup}, + { "type", I18N_NOOP2_NOSTRIP("@label", "Type"), "Type", DolphinView::SortByType}, + { "destination", I18N_NOOP2_NOSTRIP("@label", "Link Destination"), "LinkDestination", DolphinView::SortByDestination}, + { "path", I18N_NOOP2_NOSTRIP("@label", "Path"), "Path", DolphinView::SortByPath} }; - m_map.insert(KFileItemDelegate::Size, &additionalInfo[0]); - m_map.insert(KFileItemDelegate::ModificationTime, &additionalInfo[1]); - m_map.insert(KFileItemDelegate::Permissions, &additionalInfo[2]); - m_map.insert(KFileItemDelegate::Owner, &additionalInfo[3]); - m_map.insert(KFileItemDelegate::OwnerAndGroup, &additionalInfo[4]); - m_map.insert(KFileItemDelegate::FriendlyMimeType, &additionalInfo[5]); - m_map.insert(KFileItemDelegate::LinkDest, &additionalInfo[6]); - m_map.insert(KFileItemDelegate::LocalPathOrUrl, &additionalInfo[7]); + m_map.insert(DolphinView::SizeInfo, &additionalInfo[0]); + m_map.insert(DolphinView::DateInfo, &additionalInfo[1]); + m_map.insert(DolphinView::PermissionsInfo, &additionalInfo[2]); + m_map.insert(DolphinView::OwnerInfo, &additionalInfo[3]); + m_map.insert(DolphinView::GroupInfo, &additionalInfo[4]); + m_map.insert(DolphinView::TypeInfo, &additionalInfo[5]); + m_map.insert(DolphinView::DestinationInfo, &additionalInfo[6]); + m_map.insert(DolphinView::PathInfo, &additionalInfo[7]); - // The m_information list defines all available keys and the sort order - // (don't use m_information = m_map.keys(), as the order is undefined). - m_information.append(KFileItemDelegate::Size); - m_information.append(KFileItemDelegate::ModificationTime); - m_information.append(KFileItemDelegate::Permissions); - m_information.append(KFileItemDelegate::Owner); - m_information.append(KFileItemDelegate::OwnerAndGroup); - m_information.append(KFileItemDelegate::FriendlyMimeType); - m_information.append(KFileItemDelegate::LinkDest); - m_information.append(KFileItemDelegate::LocalPathOrUrl); + // The m_infoList defines all available keys and the sort order + // (don't use m_information = m_map.keys(), as the order would be undefined). + m_infoList.append(DolphinView::SizeInfo); + m_infoList.append(DolphinView::DateInfo); + m_infoList.append(DolphinView::PermissionsInfo); + m_infoList.append(DolphinView::OwnerInfo); + m_infoList.append(DolphinView::GroupInfo); + m_infoList.append(DolphinView::TypeInfo); + m_infoList.append(DolphinView::DestinationInfo); + m_infoList.append(DolphinView::PathInfo); } AdditionalInfoAccessor::~AdditionalInfoAccessor() diff --git a/src/views/additionalinfoaccessor.h b/src/views/additionalinfoaccessor.h index dbec097fd..d6dcc8e3f 100644 --- a/src/views/additionalinfoaccessor.h +++ b/src/views/additionalinfoaccessor.h @@ -60,31 +60,21 @@ public: * All entries of this list are keys for accessing the corresponding * data (see actionCollectionName(), translation(), bitValue()). */ - KFileItemDelegate::InformationList keys() const; + QList<DolphinView::AdditionalInfo> keys() const; - /** - * @return Key for the model column with the index \p columnIndex. - */ - KFileItemDelegate::Information keyForColumn(int columnIndex) const; + QByteArray role(DolphinView::AdditionalInfo info) const; - QString actionCollectionName(KFileItemDelegate::Information info, ActionCollectionType type) const; + QString actionCollectionName(DolphinView::AdditionalInfo info, ActionCollectionType type) const; - QString translation(KFileItemDelegate::Information info) const; + QString translation(DolphinView::AdditionalInfo info) const; /** * @return String representation of the value that is stored in the .directory * by ViewProperties. */ - QString value(KFileItemDelegate::Information info) const; - - DolphinView::Sorting sorting(KFileItemDelegate::Information info) const; + QString value(DolphinView::AdditionalInfo info) const; - /** - * @return Bitvalue for \p info that is stored in a ViewProperties instance. - * Is required only for backward compatibility with the version 1 of - * the view-properties. - */ - int bitValue(KFileItemDelegate::Information info) const; + DolphinView::Sorting sorting(DolphinView::AdditionalInfo info) const; protected: AdditionalInfoAccessor(); @@ -98,11 +88,10 @@ private: const char* const translation; const char* const value; const DolphinView::Sorting sorting; - const int bitValue; // for backward compatibility with version 1 of view-properties }; - KFileItemDelegate::InformationList m_information; - QMap<KFileItemDelegate::Information, const AdditionalInfo*> m_map; + QList<DolphinView::AdditionalInfo> m_infoList; + QMap<DolphinView::AdditionalInfo, const AdditionalInfo*> m_map; }; #endif diff --git a/src/views/dolphincategorydrawer.cpp b/src/views/dolphincategorydrawer.cpp deleted file mode 100644 index 1f39133ab..000000000 --- a/src/views/dolphincategorydrawer.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/* - * This file is part of the KDE project - * Copyright (C) 2007 Rafael Fernández López <[email protected]> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "dolphincategorydrawer.h" - -#include <config-nepomuk.h> - -#include <QPainter> -#include <QFile> -#include <QDir> -#include <QApplication> -#include <QStyleOption> - -#ifdef HAVE_NEPOMUK -#include <Nepomuk/KRatingPainter> -#endif - -#include <KIconLoader> -#include <KIconEffect> -#include <KCategorizedSortFilterProxyModel> -#include <KUser> -#include <KCategorizedView> - -#include "dolphinview.h" -#include "dolphinmodel.h" - -#define HORIZONTAL_HINT 3 - -DolphinCategoryDrawer::DolphinCategoryDrawer(KCategorizedView *view) - : KCategoryDrawerV3(view) - , hotSpotPressed(NoneHotSpot) - , selectAll(KIconLoader::global()->loadIcon("list-add", KIconLoader::Desktop, 16)) - , selectAllHovered(KIconLoader::global()->iconEffect()->apply(selectAll, KIconLoader::Desktop, KIconLoader::ActiveState)) - , selectAllDisabled(KIconLoader::global()->iconEffect()->apply(selectAll, KIconLoader::Desktop, KIconLoader::DisabledState)) - , unselectAll(KIconLoader::global()->loadIcon("list-remove", KIconLoader::Desktop, 16)) - , unselectAllHovered(KIconLoader::global()->iconEffect()->apply(unselectAll, KIconLoader::Desktop, KIconLoader::ActiveState)) - , unselectAllDisabled(KIconLoader::global()->iconEffect()->apply(unselectAll, KIconLoader::Desktop, KIconLoader::DisabledState)) -{ -} - -DolphinCategoryDrawer::~DolphinCategoryDrawer() -{ -} - -bool DolphinCategoryDrawer::allCategorySelected(const QString &category) const -{ - const QModelIndexList list = view()->block(category); - foreach (const QModelIndex &index, list) { - if (!view()->selectionModel()->isSelected(index)) { - return false; - } - } - return true; -} - -bool DolphinCategoryDrawer::someCategorySelected(const QString &category) const -{ - const QModelIndexList list = view()->block(category); - foreach (const QModelIndex &index, list) { - if (view()->selectionModel()->isSelected(index)) { - return true; - } - } - return false; -} - -void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole, - const QStyleOption &option, QPainter *painter) const -{ - Q_UNUSED(sortRole); - painter->setRenderHint(QPainter::Antialiasing); - - if (!index.isValid()) { - return; - } - - const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - const QRect optRect = option.rect; - QFont font(QApplication::font()); - font.setBold(true); - const QFontMetrics fontMetrics = QFontMetrics(font); - - QColor outlineColor = option.palette.text().color(); - outlineColor.setAlphaF(0.35); - - //BEGIN: top left corner - { - painter->save(); - painter->setPen(outlineColor); - const QPointF topLeft(optRect.topLeft()); - QRectF arc(topLeft, QSizeF(4, 4)); - arc.translate(0.5, 0.5); - painter->drawArc(arc, 1440, 1440); - painter->restore(); - } - //END: top left corner - - //BEGIN: left vertical line - { - QPoint start(optRect.topLeft()); - start.ry() += 3; - QPoint verticalGradBottom(optRect.topLeft()); - verticalGradBottom.ry() += fontMetrics.height() + 5; - QLinearGradient gradient(start, verticalGradBottom); - gradient.setColorAt(0, outlineColor); - gradient.setColorAt(1, Qt::transparent); - painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient); - } - //END: left vertical line - - //BEGIN: horizontal line - { - QPoint start(optRect.topLeft()); - start.rx() += 3; - QPoint horizontalGradTop(optRect.topLeft()); - horizontalGradTop.rx() += optRect.width() - 6; - painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor); - } - //END: horizontal line - - //BEGIN: top right corner - { - painter->save(); - painter->setPen(outlineColor); - QPointF topRight(optRect.topRight()); - topRight.rx() -= 4; - QRectF arc(topRight, QSizeF(4, 4)); - arc.translate(0.5, 0.5); - painter->drawArc(arc, 0, 1440); - painter->restore(); - } - //END: top right corner - - //BEGIN: right vertical line - { - QPoint start(optRect.topRight()); - start.ry() += 3; - QPoint verticalGradBottom(optRect.topRight()); - verticalGradBottom.ry() += fontMetrics.height() + 5; - QLinearGradient gradient(start, verticalGradBottom); - gradient.setColorAt(0, outlineColor); - gradient.setColorAt(1, Qt::transparent); - painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient); - } - //END: right vertical line - - const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small); - - //BEGIN: select/unselect all - { - if (this->category == category) { - QRect iconAllRect(option.rect); - iconAllRect.setTop(iconAllRect.top() + 4); - iconAllRect.setLeft(iconAllRect.right() - 16 - 7); - iconAllRect.setSize(QSize(iconSize, iconSize)); - if (!allCategorySelected(category)) { - if (iconAllRect.contains(pos)) { - painter->drawPixmap(iconAllRect, selectAllHovered); - } else { - painter->drawPixmap(iconAllRect, selectAll); - } - } else { - painter->drawPixmap(iconAllRect, selectAllDisabled); - } - QRect iconNoneRect(option.rect); - iconNoneRect.setTop(iconNoneRect.top() + 4); - iconNoneRect.setLeft(iconNoneRect.right() - 16 * 2 - 7 * 2); - iconNoneRect.setSize(QSize(iconSize, iconSize)); - if (someCategorySelected(category)) { - if (iconNoneRect.contains(pos)) { - painter->drawPixmap(iconNoneRect, unselectAllHovered); - } else { - painter->drawPixmap(iconNoneRect, unselectAll); - } - } else { - painter->drawPixmap(iconNoneRect, unselectAllDisabled); - } - } - } - //END: select/unselect all - - //BEGIN: category information - { - bool paintIcon; - QPixmap icon; - switch (index.column()) { - case KDirModel::Owner: { - paintIcon = true; - KUser user(category); - const QString faceIconPath = user.faceIconPath(); - if (faceIconPath.isEmpty()) { - icon = KIconLoader::global()->loadIcon("user-identity", KIconLoader::NoGroup, iconSize); - } else { - icon = QPixmap::fromImage(QImage(faceIconPath).scaledToHeight(iconSize, Qt::SmoothTransformation)); - } - } - break; - case KDirModel::Type: { - paintIcon = true; - const KCategorizedSortFilterProxyModel *proxyModel = static_cast<const KCategorizedSortFilterProxyModel*>(index.model()); - const DolphinModel *model = static_cast<const DolphinModel*>(proxyModel->sourceModel()); - KFileItem item = model->itemForIndex(proxyModel->mapToSource(index)); - // This is the only way of getting the icon right. Others will fail on corner - // cases like the item representing this group has been set a different icon, - // so the group icon drawn is that one particularly. This way assures the drawn - // icon is the one of the mimetype of the group itself. (ereslibre) - icon = KIconLoader::global()->loadMimeTypeIcon(item.mimeTypePtr()->iconName(), KIconLoader::NoGroup, iconSize); - } - break; - default: - paintIcon = false; - } - - if (paintIcon) { - QRect iconRect(option.rect); - iconRect.setTop(iconRect.top() + 4); - iconRect.setLeft(iconRect.left() + 7); - iconRect.setSize(QSize(iconSize, iconSize)); - - painter->drawPixmap(iconRect, icon); - } - - //BEGIN: text - { - QRect textRect(option.rect); - textRect.setTop(textRect.top() + 7); - textRect.setLeft(textRect.left() + 7 + (paintIcon ? (iconSize + 6) : 0)); - textRect.setHeight(qMax(fontMetrics.height(), iconSize)); - textRect.setRight(textRect.right() - 7); - textRect.setBottom(textRect.bottom() - 5); // only one pixel separation here (no gradient) - - painter->save(); - painter->setFont(font); - QColor penColor(option.palette.text().color()); - penColor.setAlphaF(0.6); - painter->setPen(penColor); - painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, category); - painter->restore(); - } - //END: text - } - //BEGIN: category information -} - -int DolphinCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &) const -{ - int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small); - QFont font(QApplication::font()); - font.setBold(true); - const QFontMetrics fontMetrics = QFontMetrics(font); - int heightWithoutIcon = fontMetrics.height() + (iconSize / 4) * 2 + 1; /* 1 pixel-width gradient */ - bool paintIcon; - - switch (index.column()) { - case KDirModel::Owner: - case KDirModel::Type: - paintIcon = true; - break; - default: - paintIcon = false; - } - - if (paintIcon) { - return qMax(heightWithoutIcon + 5, iconSize + 1 /* 1 pixel-width gradient */ - + 5 /* top and bottom separation */); - } - - return heightWithoutIcon + 5; -} - -void DolphinCategoryDrawer::mouseButtonPressed(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event) -{ - if (!index.isValid()) { - event->ignore(); - return; - } - const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small); - if (this->category == category) { - QRect iconAllRect(blockRect); - iconAllRect.setTop(iconAllRect.top() + 4); - iconAllRect.setLeft(iconAllRect.right() - 16 - 7); - iconAllRect.setSize(QSize(iconSize, iconSize)); - if (iconAllRect.contains(pos)) { - event->accept(); - hotSpotPressed = SelectAllHotSpot; - categoryPressed = index; - return; - } - QRect iconNoneRect(blockRect); - iconNoneRect.setTop(iconNoneRect.top() + 4); - iconNoneRect.setLeft(iconNoneRect.right() - 16 * 2 - 7 * 2); - iconNoneRect.setSize(QSize(iconSize, iconSize)); - if (iconNoneRect.contains(pos)) { - event->accept(); - hotSpotPressed = UnselectAllHotSpot; - categoryPressed = index; - return; - } - } - event->ignore(); -} - -void DolphinCategoryDrawer::mouseButtonReleased(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event) -{ - if (!index.isValid() || hotSpotPressed == NoneHotSpot || categoryPressed != index) { - event->ignore(); - return; - } - categoryPressed = QModelIndex(); - const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small); - if (this->category == category) { - QRect iconAllRect(blockRect); - iconAllRect.setTop(iconAllRect.top() + 4); - iconAllRect.setLeft(iconAllRect.right() - 16 - 7); - iconAllRect.setSize(QSize(iconSize, iconSize)); - if (iconAllRect.contains(pos)) { - if (hotSpotPressed == SelectAllHotSpot) { - event->accept(); - emit actionRequested(SelectAll, index); - } else { - event->ignore(); - hotSpotPressed = NoneHotSpot; - } - return; - } - QRect iconNoneRect(blockRect); - iconNoneRect.setTop(iconNoneRect.top() + 4); - iconNoneRect.setLeft(iconNoneRect.right() - 16 * 2 - 7 * 2); - iconNoneRect.setSize(QSize(iconSize, iconSize)); - if (iconNoneRect.contains(pos)) { - if (hotSpotPressed == UnselectAllHotSpot) { - event->accept(); - emit actionRequested(UnselectAll, index); - } else { - event->ignore(); - hotSpotPressed = NoneHotSpot; - } - return; - } - } - event->ignore(); -} - -void DolphinCategoryDrawer::mouseMoved(const QModelIndex &index, const QRect &, QMouseEvent *event) -{ - event->ignore(); - if (!index.isValid()) { - return; - } - pos = event->pos(); - category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); -} - -void DolphinCategoryDrawer::mouseLeft(const QModelIndex &, const QRect &) -{ - pos = QPoint(); - category.clear(); -} diff --git a/src/views/dolphincategorydrawer.h b/src/views/dolphincategorydrawer.h deleted file mode 100644 index 94c9e69ef..000000000 --- a/src/views/dolphincategorydrawer.h +++ /dev/null @@ -1,85 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007 Rafael Fernández López <[email protected]> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#ifndef DOLPHINCATEGORYDRAWER_H -#define DOLPHINCATEGORYDRAWER_H - -#include <kcategorydrawer.h> - -#include <QStyleOption> -#include <QModelIndex> - -#include <libdolphin_export.h> - -class LIBDOLPHINPRIVATE_EXPORT DolphinCategoryDrawer - : public KCategoryDrawerV3 -{ -public: - using KCategoryDrawerV2::mouseButtonPressed; - using KCategoryDrawerV2::mouseButtonReleased; - - enum Action { - SelectAll = 0, - UnselectAll - }; - - DolphinCategoryDrawer(KCategorizedView *view); - - virtual ~DolphinCategoryDrawer(); - - bool allCategorySelected(const QString &category) const; - - bool someCategorySelected(const QString &category) const; - - virtual void drawCategory(const QModelIndex &index, int sortRole, - const QStyleOption &option, QPainter *painter) const; - - virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const; - -protected: - virtual void mouseButtonPressed(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); - - virtual void mouseButtonReleased(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); - - virtual void mouseMoved(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); - - virtual void mouseLeft(const QModelIndex &index,const QRect &blockRect); - -private: - enum HotSpot { - NoneHotSpot = 0, - SelectAllHotSpot, - UnselectAllHotSpot - }; - - HotSpot hotSpotPressed; - QModelIndex categoryPressed; - - QPixmap selectAll; - QPixmap selectAllHovered; - QPixmap selectAllDisabled; - QPixmap unselectAll; - QPixmap unselectAllHovered; - QPixmap unselectAllDisabled; - - QPoint pos; - QString category; -}; - -#endif // DOLPHINCATEGORYDRAWER_H diff --git a/src/views/dolphincolumnview.cpp b/src/views/dolphincolumnview.cpp deleted file mode 100644 index 3425c460b..000000000 --- a/src/views/dolphincolumnview.cpp +++ /dev/null @@ -1,621 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Peter Penz <[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 "dolphincolumnview.h" - -#include "dolphinmodel.h" -#include "dolphincolumnviewcontainer.h" -#include "dolphinviewcontroller.h" -#include "dolphindirlister.h" -#include "dolphinfileitemdelegate.h" -#include "dolphinsortfilterproxymodel.h" -#include "settings/dolphinsettings.h" -#include "dolphinviewautoscroller.h" -#include "dolphin_columnmodesettings.h" -#include "dolphin_generalsettings.h" -#include "draganddrophelper.h" -#include "folderexpander.h" -#include "tooltips/tooltipmanager.h" -#include "viewextensionsfactory.h" -#include "viewmodecontroller.h" -#include "zoomlevelinfo.h" - -#include <KColorScheme> -#include <KDirLister> -#include <KFileItem> -#include <KIO/PreviewJob> -#include <KIcon> -#include <KIconEffect> -#include <KJob> -#include <KLocale> -#include <konqmimedata.h> - -#include <QApplication> -#include <QClipboard> -#include <QHeaderView> -#include <QLabel> -#include <QPainter> -#include <QPoint> -#include <QScrollBar> - -DolphinColumnView::DolphinColumnView(QWidget* parent, - DolphinColumnViewContainer* container, - const KUrl& url) : - DolphinTreeView(parent), - m_active(false), - m_container(container), - m_extensionsFactory(0), - m_url(url), - m_childUrl(), - m_font(), - m_decorationSize(), - m_dirLister(0), - m_dolphinModel(0), - m_proxyModel(0), - m_resizeWidget(0), - m_resizeXOrigin(-1) -{ - setMouseTracking(true); - setAcceptDrops(true); - setUniformRowHeights(true); - setSelectionBehavior(SelectItems); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - setRootIsDecorated(false); - setItemsExpandable(false); - setEditTriggers(QAbstractItemView::NoEditTriggers); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - setVerticalScrollMode(QTreeView::ScrollPerPixel); - - m_resizeWidget = new QLabel(this); - m_resizeWidget->setPixmap(KIcon("transform-move").pixmap(KIconLoader::SizeSmall)); - m_resizeWidget->setToolTip(i18nc("@info:tooltip", "Resize column")); - setCornerWidget(m_resizeWidget); - m_resizeWidget->installEventFilter(this); - - const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - Q_ASSERT(settings); - - if (settings->useSystemFont()) { - m_font = KGlobalSettings::generalFont(); - } else { - m_font = QFont(settings->fontFamily(), - qRound(settings->fontSize()), - settings->fontWeight(), - settings->italicFont()); - m_font.setPointSizeF(settings->fontSize()); - } - - setMinimumWidth(settings->fontSize() * 10); - setMaximumWidth(settings->columnWidth()); - - connect(this, SIGNAL(viewportEntered()), - m_container->m_dolphinViewController, SLOT(emitViewportEntered())); - connect(this, SIGNAL(entered(const QModelIndex&)), - this, SLOT(slotEntered(const QModelIndex&))); - - const DolphinView* dolphinView = m_container->m_dolphinViewController->view(); - connect(dolphinView, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - - m_dirLister = new DolphinDirLister(); - m_dirLister->setAutoUpdate(true); - m_dirLister->setMainWindow(window()); - m_dirLister->setDelayedMimeTypes(true); - const bool showHiddenFiles = m_container->m_dolphinViewController->view()->showHiddenFiles(); - m_dirLister->setShowingDotFiles(showHiddenFiles); - connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); - - m_dolphinModel = new DolphinModel(this); - m_dolphinModel->setDirLister(m_dirLister); - m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); - - m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dolphinModel); - m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - - m_proxyModel->setSorting(dolphinView->sorting()); - m_proxyModel->setSortOrder(dolphinView->sortOrder()); - m_proxyModel->setSortFoldersFirst(dolphinView->sortFoldersFirst()); - - setModel(m_proxyModel); - - connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), - this, SLOT(updateFont())); - - const ViewModeController* viewModeController = m_container->m_viewModeController; - connect(viewModeController, SIGNAL(zoomLevelChanged(int)), - this, SLOT(setZoomLevel(int))); - const QString nameFilter = viewModeController->nameFilter(); - if (!nameFilter.isEmpty()) { - m_proxyModel->setFilterFixedString(nameFilter); - } - - updateDecorationSize(dolphinView->showPreview()); - updateBackground(); - - DolphinViewController* dolphinViewController = m_container->m_dolphinViewController; - m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController); - m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true); - - m_dirLister->openUrl(url, KDirLister::NoFlags); -} - -DolphinColumnView::~DolphinColumnView() -{ - delete m_proxyModel; - m_proxyModel = 0; - delete m_dolphinModel; - m_dolphinModel = 0; - m_dirLister = 0; // deleted by m_dolphinModel -} - - -void DolphinColumnView::setActive(bool active) -{ - if (m_active != active) { - m_active = active; - - if (active) { - activate(); - } else { - deactivate(); - } - } -} - -bool DolphinColumnView::isActive() const -{ - return m_active; -} - -void DolphinColumnView::setChildUrl(const KUrl& url) -{ - m_childUrl = url; -} - -KUrl DolphinColumnView::childUrl() const -{ - return m_childUrl; -} - -void DolphinColumnView::setUrl(const KUrl& url) -{ - if (url != m_url) { - m_url = url; - m_dirLister->openUrl(url, KDirLister::NoFlags); - } -} - -KUrl DolphinColumnView::url() const -{ - return m_url; -} - -void DolphinColumnView::updateBackground() -{ - // TODO: The alpha-value 150 is copied from DolphinView::setActive(). When - // cleaning up the cut-indication of DolphinColumnView with the code from - // DolphinView a common helper-class should be available which can be shared - // by all view implementations -> no hardcoded value anymore - const QPalette::ColorRole role = viewport()->backgroundRole(); - QColor color = viewport()->palette().color(role); - color.setAlpha((m_active && m_container->m_active) ? 255 : 150); - - QPalette palette = viewport()->palette(); - palette.setColor(role, color); - viewport()->setPalette(palette); - - update(); -} - -KFileItem DolphinColumnView::itemAt(const QPoint& pos) const -{ - KFileItem item; - const QModelIndex index = indexAt(pos); - if (index.isValid() && (index.column() == DolphinModel::Name)) { - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - item = m_dolphinModel->itemForIndex(dolphinModelIndex); - } - return item; -} - -void DolphinColumnView::setSelectionModel(QItemSelectionModel* model) -{ - // If a change of the selection is done although the view is not active - // (e. g. by the selection markers), the column must be activated. This - // is done by listening to the current selectionChanged() signal. - if (selectionModel()) { - disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(requestActivation())); - } - - DolphinTreeView::setSelectionModel(model); - - connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(requestActivation())); -} - -QStyleOptionViewItem DolphinColumnView::viewOptions() const -{ - QStyleOptionViewItem viewOptions = DolphinTreeView::viewOptions(); - viewOptions.font = m_font; - viewOptions.fontMetrics = QFontMetrics(m_font); - viewOptions.decorationSize = m_decorationSize; - viewOptions.showDecorationSelected = true; - return viewOptions; -} - -bool DolphinColumnView::event(QEvent* event) -{ - if (event->type() == QEvent::Polish) { - // Hide all columns except of the 'Name' column - for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) { - hideColumn(i); - } - header()->hide(); - } - - return DolphinTreeView::event(event); -} - -void DolphinColumnView::startDrag(Qt::DropActions supportedActions) -{ - DragAndDropHelper::instance().startDrag(this, supportedActions, m_container->m_dolphinViewController); - DolphinTreeView::startDrag(supportedActions); -} - -void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event) -{ - event->acceptProposedAction(); - requestActivation(); - DolphinTreeView::dragEnterEvent(event); -} - -void DolphinColumnView::dragMoveEvent(QDragMoveEvent* event) -{ - DolphinTreeView::dragMoveEvent(event); - event->acceptProposedAction(); -} - -void DolphinColumnView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - m_container->m_dolphinViewController->setItemView(this); - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - const KFileItem item = m_dolphinModel->itemForIndex(dolphinModelIndex); - m_container->m_dolphinViewController->indicateDroppedUrls(item, event); - DolphinTreeView::dropEvent(event); -} - -void DolphinColumnView::paintEvent(QPaintEvent* event) -{ - if (!m_childUrl.isEmpty()) { - // Indicate the shown URL of the next column by highlighting the shown folder item - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_childUrl); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) { - QPainter painter(viewport()); - - QStyleOptionViewItemV4 option; - option.initFrom(this); - option.rect = visualRect(proxyIndex); - option.state = QStyle::State_Enabled | QStyle::State_HasFocus; - option.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; - style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this); - } - } - - DolphinTreeView::paintEvent(event); -} - -void DolphinColumnView::mousePressEvent(QMouseEvent* event) -{ - requestActivation(); - if (!indexAt(event->pos()).isValid() && (QApplication::mouseButtons() & Qt::MidButton)) { - m_container->m_dolphinViewController->replaceUrlByClipboard(); - } - - DolphinTreeView::mousePressEvent(event); -} - -void DolphinColumnView::keyPressEvent(QKeyEvent* event) -{ - const bool hadSelection = selectionModel()->hasSelection(); - DolphinTreeView::keyPressEvent(event); - - DolphinViewController* controller = m_container->m_dolphinViewController; - controller->handleKeyPressEvent(event); - switch (event->key()) { - case Qt::Key_Right: { - // Special key handling for the column: A Key_Right should - // open a new column for the currently selected folder. - QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(currentIndex()); - - // If there is no selection we automatically move to the child url - // instead of the first directory. - // See BUG:263110 - if (!hadSelection && !childUrl().isEmpty()) { - dolphinModelIndex = m_dolphinModel->indexForUrl(childUrl()); - } - - const KFileItem item = m_dolphinModel->itemForIndex(dolphinModelIndex); - if (!item.isNull() && item.isDir()) { - controller->emitItemTriggered(item); - } - break; - } - - case Qt::Key_Escape: - selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), - QItemSelectionModel::Current | - QItemSelectionModel::Clear); - break; - - default: - break; - } -} - -void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event) -{ - requestActivation(); - DolphinTreeView::contextMenuEvent(event); - m_container->m_dolphinViewController->triggerContextMenuRequest(event->pos()); -} - -void DolphinColumnView::wheelEvent(QWheelEvent* event) -{ - const int step = m_decorationSize.height(); - verticalScrollBar()->setSingleStep(step); - DolphinTreeView::wheelEvent(event); -} - -void DolphinColumnView::leaveEvent(QEvent* event) -{ - DolphinTreeView::leaveEvent(event); - // if the mouse is above an item and moved very fast outside the widget, - // no viewportEntered() signal might be emitted although the mouse has been moved - // above the viewport - m_container->m_dolphinViewController->emitViewportEntered(); -} - -void DolphinColumnView::currentChanged(const QModelIndex& current, const QModelIndex& previous) -{ - DolphinTreeView::currentChanged(current, previous); - m_extensionsFactory->handleCurrentIndexChange(current, previous); -} - -QRect DolphinColumnView::visualRect(const QModelIndex& index) const -{ - QRect rect = DolphinTreeView::visualRect(index); - - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - const KFileItem item = m_dolphinModel->itemForIndex(dolphinModelIndex); - if (!item.isNull()) { - const int width = DolphinFileItemDelegate::nameColumnWidth(item.text(), viewOptions()); - rect.setWidth(width); - } - - return rect; -} - -bool DolphinColumnView::acceptsDrop(const QModelIndex& index) const -{ - if (index.isValid() && (index.column() == DolphinModel::Name)) { - // Accept drops above directories - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - const KFileItem item = m_dolphinModel->itemForIndex(dolphinModelIndex); - return !item.isNull() && item.isDir(); - } - - return false; -} - -bool DolphinColumnView::eventFilter(QObject* watched, QEvent* event) -{ - if (watched == m_resizeWidget) { - switch (event->type()) { - case QEvent::MouseButtonPress: { - // Initiate the resizing of the column - QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); - m_resizeXOrigin = mouseEvent->globalX(); - m_resizeWidget->setMouseTracking(true); - event->accept(); - return true; - } - - case QEvent::MouseButtonDblClick: { - // Reset the column width to the default value - const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - setMaximumWidth(settings->columnWidth()); - m_container->layoutColumns(); - m_resizeWidget->setMouseTracking(false); - m_resizeXOrigin = -1; - event->accept(); - return true; - } - - case QEvent::MouseMove: { - // Resize the column and trigger a relayout of the container - QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); - int requestedWidth = maximumWidth() - m_resizeXOrigin + mouseEvent->globalX();; - if (requestedWidth < minimumWidth()) { - requestedWidth = minimumWidth(); - } - setMaximumWidth(requestedWidth); - - m_container->layoutColumns(); - - m_resizeXOrigin = mouseEvent->globalX(); - - event->accept(); - return true; - } - - case QEvent::MouseButtonRelease: { - // The resizing has been finished - m_resizeWidget->setMouseTracking(false); - m_resizeXOrigin = -1; - event->accept(); - return true; - } - - default: - break; - } - } - return DolphinTreeView::eventFilter(watched, event); -} -void DolphinColumnView::setZoomLevel(int level) -{ - const int size = ZoomLevelInfo::iconSizeForZoomLevel(level); - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - - const bool showPreview = m_container->m_dolphinViewController->view()->showPreview(); - if (showPreview) { - settings->setPreviewSize(size); - } else { - settings->setIconSize(size); - } - - updateDecorationSize(showPreview); -} - -void DolphinColumnView::slotEntered(const QModelIndex& index) -{ - m_container->m_dolphinViewController->setItemView(this); - m_container->m_dolphinViewController->emitItemEntered(index); -} - -void DolphinColumnView::requestActivation() -{ - m_container->m_dolphinViewController->requestActivation(); - if (!m_active) { - m_container->requestActivation(this); - selectionModel()->clear(); - } -} - -void DolphinColumnView::updateFont() -{ - const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - Q_ASSERT(settings); - - if (settings->useSystemFont()) { - m_font = KGlobalSettings::generalFont(); - } -} - -void DolphinColumnView::slotShowPreviewChanged() -{ - const DolphinView* view = m_container->m_dolphinViewController->view(); - updateDecorationSize(view->showPreview()); -} - -void DolphinColumnView::slotDirListerCompleted() -{ - if (!m_childUrl.isEmpty()) { - return; - } - - // Try to optimize the width of the column, so that no name gets clipped - const int requiredWidth = sizeHintForColumn(DolphinModel::Name); - - const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - if (requiredWidth > settings->columnWidth()) { - int frameAroundContents = 0; - if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) { - // TODO: Using 2 PM_DefaultFrameWidths are not sufficient. Check Qt-code - // for other pixelmetrics that should be added... - frameAroundContents = style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 4; - } - - const int scrollBarWidth = style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, verticalScrollBar()); - - setMaximumWidth(requiredWidth + frameAroundContents + scrollBarWidth); - m_container->layoutColumns(); - if (m_active) { - m_container->assureVisibleActiveColumn(); - } - } -} - -void DolphinColumnView::activate() -{ - setFocus(Qt::OtherFocusReason); - - connect(this, SIGNAL(clicked(const QModelIndex&)), - m_container->m_dolphinViewController, SLOT(requestTab(const QModelIndex&))); - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(const QModelIndex&)), - m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } else { - connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } - - if (selectionModel() && selectionModel()->currentIndex().isValid()) { - selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), QItemSelectionModel::SelectCurrent); - } - - updateBackground(); -} - -void DolphinColumnView::deactivate() -{ - clearFocus(); - - disconnect(this, SIGNAL(clicked(const QModelIndex&)), - m_container->m_dolphinViewController, SLOT(requestTab(const QModelIndex&))); - if (KGlobalSettings::singleClick()) { - disconnect(this, SIGNAL(clicked(const QModelIndex&)), - m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } else { - disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } - - // It is important to disconnect the connection to requestActivation() temporary, otherwise the internal - // clearing of the selection would result in activating the column again. - disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(requestActivation())); - const QModelIndex current = selectionModel()->currentIndex(); - selectionModel()->clear(); - selectionModel()->setCurrentIndex(current, QItemSelectionModel::NoUpdate); - connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(requestActivation())); - - updateBackground(); -} - -void DolphinColumnView::updateDecorationSize(bool showPreview) -{ - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - const int iconSize = showPreview ? settings->previewSize() : settings->iconSize(); - const QSize size(iconSize, iconSize); - setIconSize(size); - - m_decorationSize = size; - - doItemsLayout(); -} - -#include "dolphincolumnview.moc" diff --git a/src/views/dolphincolumnview.h b/src/views/dolphincolumnview.h deleted file mode 100644 index 2a4726afc..000000000 --- a/src/views/dolphincolumnview.h +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINCOLUMNVIEW_H -#define DOLPHINCOLUMNVIEW_H - -#include "dolphinview.h" -#include "dolphintreeview.h" - -#include <QFont> -#include <QSize> -#include <QStyleOption> - -#include <KUrl> - -class DolphinColumnViewContainer; -class DolphinModel; -class DolphinSortFilterProxyModel; -class DolphinDirLister; -class KFileItem; -class QLabel; -class SelectionManager; -class ViewExtensionsFactory; - -/** - * Represents one column inside the DolphinColumnViewContainer. - */ -class DolphinColumnView : public DolphinTreeView -{ - Q_OBJECT - -public: - DolphinColumnView(QWidget* parent, - DolphinColumnViewContainer* container, - const KUrl& url); - virtual ~DolphinColumnView(); - - /** - * An active column is defined as column, which shows the same URL - * as indicated by the URL navigator. The active column is usually - * drawn in a lighter color. All operations are applied to this column. - */ - void setActive(bool active); - bool isActive() const; - - /** - * Sets the directory URL of the child column that is shown next to - * this column. This property is used for a visual indication - * of the shown directory, it does not trigger a loading of the model. - * When no url is selected and the user presses right, then child - * url will be used as column. - */ - void setChildUrl(const KUrl& url); - KUrl childUrl() const; - - /** Sets the directory URL that is shown inside the column widget. */ - void setUrl(const KUrl& url); - - /** Returns the directory URL that is shown inside the column widget. */ - KUrl url() const; - - /** - * Updates the background color dependent from the activation state - * \a isViewActive of the column view. - */ - void updateBackground(); - - /** - * Returns the item on the position \a pos. The KFileItem instance - * is null if no item is below the position. - */ - KFileItem itemAt(const QPoint& pos) const; - - virtual void setSelectionModel(QItemSelectionModel* model); - -protected: - virtual QStyleOptionViewItem viewOptions() const; - virtual bool event(QEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dropEvent(QDropEvent* event); - virtual void paintEvent(QPaintEvent* event); - virtual void mousePressEvent(QMouseEvent* event); - virtual void keyPressEvent(QKeyEvent* event); - virtual void contextMenuEvent(QContextMenuEvent* event); - virtual void wheelEvent(QWheelEvent* event); - virtual void leaveEvent(QEvent* event); - virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); - virtual QRect visualRect(const QModelIndex& index) const; - virtual bool acceptsDrop(const QModelIndex& index) const; - virtual bool eventFilter(QObject* watched, QEvent* event); - -private slots: - void setZoomLevel(int level); - - void slotEntered(const QModelIndex& index); - void requestActivation(); - void updateFont(); - - void slotShowPreviewChanged(); - - void slotDirListerCompleted(); - -private: - /** Used by DolphinColumnView::setActive(). */ - void activate(); - - /** Used by DolphinColumnView::setActive(). */ - void deactivate(); - - void updateDecorationSize(bool showPreview); - -private: - bool m_active; - DolphinColumnViewContainer* m_container; - SelectionManager* m_selectionManager; - ViewExtensionsFactory* m_extensionsFactory; - KUrl m_url; // URL of the directory that is shown - KUrl m_childUrl; // URL of the next column that is shown - - QFont m_font; - QSize m_decorationSize; - - DolphinDirLister* m_dirLister; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; - - QLabel* m_resizeWidget; - int m_resizeXOrigin; - - friend class DolphinColumnViewContainer; -}; - -#endif diff --git a/src/views/dolphincolumnviewcontainer.cpp b/src/views/dolphincolumnviewcontainer.cpp deleted file mode 100644 index 3216dd2b6..000000000 --- a/src/views/dolphincolumnviewcontainer.cpp +++ /dev/null @@ -1,427 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Peter Penz <[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 "dolphincolumnviewcontainer.h" - -#include "dolphin_columnmodesettings.h" - -#include "dolphincolumnview.h" -#include "dolphinviewcontroller.h" -#include "dolphinsortfilterproxymodel.h" -#include "draganddrophelper.h" -#include "settings/dolphinsettings.h" -#include "viewmodecontroller.h" - -#include <QPoint> -#include <QScrollBar> -#include <QTimeLine> -#include <QTimer> - -DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController) : - QScrollArea(parent), - m_dolphinViewController(dolphinViewController), - m_viewModeController(viewModeController), - m_active(false), - m_index(-1), - m_contentX(0), - m_columns(), - m_emptyViewport(0), - m_animation(0), - m_dragSource(0), - m_activeUrlTimer(0), - m_assureVisibleActiveColumnTimer(0) -{ - Q_ASSERT(dolphinViewController); - Q_ASSERT(viewModeController); - - setAcceptDrops(true); - setFocusPolicy(Qt::NoFocus); - setFrameShape(QFrame::NoFrame); - setLayoutDirection(Qt::LeftToRight); - - connect(viewModeController, SIGNAL(activationChanged(bool)), - this, SLOT(updateColumnsBackground(bool))); - - connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(moveContentHorizontally(int))); - - m_animation = new QTimeLine(500, this); - connect(m_animation, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int))); - - m_activeUrlTimer = new QTimer(this); - m_activeUrlTimer->setSingleShot(true); - m_activeUrlTimer->setInterval(200); - connect(m_activeUrlTimer, SIGNAL(timeout()), - this, SLOT(updateActiveUrl())); - - // Assuring that the active column gets fully visible is done with a small delay. This - // prevents that for temporary activations an animation gets started (e. g. when clicking - // on any folder of the parent column, the child column gets activated). - m_assureVisibleActiveColumnTimer = new QTimer(this); - m_assureVisibleActiveColumnTimer->setSingleShot(true); - m_assureVisibleActiveColumnTimer->setInterval(200); - connect(m_assureVisibleActiveColumnTimer, SIGNAL(timeout()), - this, SLOT(slotAssureVisibleActiveColumn())); - - DolphinColumnView* column = new DolphinColumnView(viewport(), this, viewModeController->url()); - m_columns.append(column); - requestActivation(column); - - m_emptyViewport = new QFrame(viewport()); - m_emptyViewport->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); - - updateColumnsBackground(true); -} - -DolphinColumnViewContainer::~DolphinColumnViewContainer() -{ - delete m_dragSource; - m_dragSource = 0; -} - -KUrl DolphinColumnViewContainer::rootUrl() const -{ - return m_columns[0]->url(); -} - -QAbstractItemView* DolphinColumnViewContainer::activeColumn() const -{ - return m_columns[m_index]; -} - -void DolphinColumnViewContainer::showColumn(const KUrl& url) -{ - if (!rootUrl().isParentOf(url)) { - removeAllColumns(); - m_columns[0]->setUrl(url); - return; - } - - int columnIndex = 0; - foreach (DolphinColumnView* column, m_columns) { - if (column->url().equals(url, KUrl::CompareWithoutTrailingSlash)) { - // the column represents already the requested URL, hence activate it - requestActivation(column); - layoutColumns(); - return; - } else if (!column->url().isParentOf(url)) { - // the column is no parent of the requested URL, hence - // just delete all remaining columns - if (columnIndex > 0) { - QList<DolphinColumnView*>::iterator start = m_columns.begin() + columnIndex; - QList<DolphinColumnView*>::iterator end = m_columns.end(); - for (QList<DolphinColumnView*>::iterator it = start; it != end; ++it) { - deleteColumn(*it); - } - m_columns.erase(start, end); - - const int maxIndex = m_columns.count() - 1; - Q_ASSERT(maxIndex >= 0); - if (m_index > maxIndex) { - m_index = maxIndex; - } - break; - } - } - ++columnIndex; - } - - // Create missing columns. Assuming that the path is "/home/peter/Temp/" and - // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and - // "c" will be created. - const int lastIndex = m_columns.count() - 1; - Q_ASSERT(lastIndex >= 0); - - const KUrl& activeUrl = m_columns[lastIndex]->url(); - Q_ASSERT(activeUrl.isParentOf(url)); - Q_ASSERT(activeUrl != url); - - QString path = activeUrl.url(KUrl::AddTrailingSlash); - const QString targetPath = url.url(KUrl::AddTrailingSlash); - - columnIndex = lastIndex; - int slashIndex = path.count('/'); - bool hasSubPath = (slashIndex >= 0); - while (hasSubPath) { - const QString subPath = targetPath.section('/', slashIndex, slashIndex); - if (subPath.isEmpty()) { - hasSubPath = false; - } else { - path += subPath + '/'; - ++slashIndex; - - const KUrl childUrl = KUrl(path); - m_columns[columnIndex]->setChildUrl(childUrl); - columnIndex++; - - DolphinColumnView* column = new DolphinColumnView(viewport(), this, childUrl); - m_columns.append(column); - - // Before invoking layoutColumns() the column must be set visible temporary. - // To prevent a flickering the initial geometry is set to a hidden position. - column->setGeometry(QRect(-1, -1, 1, 1)); - column->show(); - layoutColumns(); - } - } - - requestActivation(m_columns[columnIndex]); -} - -void DolphinColumnViewContainer::mousePressEvent(QMouseEvent* event) -{ - m_dolphinViewController->requestActivation(); - QScrollArea::mousePressEvent(event); -} - -void DolphinColumnViewContainer::keyPressEvent(QKeyEvent* event) -{ - if (event->key() == Qt::Key_Left) { - if (m_index > 0) { - requestActivation(m_columns[m_index - 1]); - } - } else { - QScrollArea::keyPressEvent(event); - } -} - -void DolphinColumnViewContainer::resizeEvent(QResizeEvent* event) -{ - QScrollArea::resizeEvent(event); - layoutColumns(); - assureVisibleActiveColumn(); -} - -void DolphinColumnViewContainer::wheelEvent(QWheelEvent* event) -{ - // let Ctrl+wheel events propagate to the DolphinView for icon zooming - if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) { - event->ignore(); - } else { - QScrollArea::wheelEvent(event); - } -} - -void DolphinColumnViewContainer::moveContentHorizontally(int x) -{ - m_contentX = isRightToLeft() ? +x : -x; - layoutColumns(); -} - -void DolphinColumnViewContainer::updateColumnsBackground(bool active) -{ - if (active == m_active) { - return; - } - - m_active = active; - - // dim the background of the viewport - const QPalette::ColorRole role = viewport()->backgroundRole(); - QColor background = viewport()->palette().color(role); - background.setAlpha(0); // make background transparent - - QPalette palette = viewport()->palette(); - palette.setColor(role, background); - viewport()->setPalette(palette); - - foreach (DolphinColumnView* column, m_columns) { - column->updateBackground(); - } -} - -void DolphinColumnViewContainer::updateActiveUrl() -{ - const KUrl activeUrl = m_columns[m_index]->url(); - m_dolphinViewController->requestUrlChange(activeUrl); -} - -void DolphinColumnViewContainer::slotAssureVisibleActiveColumn() -{ - const int viewportWidth = viewport()->width(); - const int x = activeColumn()->x(); - - // When a column that is partly visible gets activated, - // it is useful to also assure that the neighbor column is partly visible. - // This allows the user to scroll to the first/last column without using the - // scrollbar and drag & drop operations to invisible columns. - const int neighborColumnGap = 3 * style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, verticalScrollBar()); - - const int width = activeColumn()->maximumWidth(); - if (x + width > viewportWidth) { - const int newContentX = m_contentX - x - width + viewportWidth; - if (isRightToLeft()) { - m_animation->setFrameRange(m_contentX, newContentX + neighborColumnGap); - } else { - m_animation->setFrameRange(-m_contentX, -newContentX + neighborColumnGap); - } - if (m_animation->state() != QTimeLine::Running) { - m_animation->start(); - } - } else if (x < 0) { - const int newContentX = m_contentX - x; - if (isRightToLeft()) { - m_animation->setFrameRange(m_contentX, newContentX - neighborColumnGap); - } else { - m_animation->setFrameRange(-m_contentX, -newContentX - neighborColumnGap); - } - if (m_animation->state() != QTimeLine::Running) { - m_animation->start(); - } - } -} - -void DolphinColumnViewContainer::assureVisibleActiveColumn() -{ - m_assureVisibleActiveColumnTimer->start(); -} - -void DolphinColumnViewContainer::layoutColumns() -{ - // Layout the position of the columns corresponding to their maximum width - QRect emptyViewportRect; - if (isRightToLeft()) { - int columnWidth = m_columns[0]->maximumWidth(); - int x = viewport()->width() - columnWidth + m_contentX; - foreach (DolphinColumnView* column, m_columns) { - columnWidth = column->maximumWidth(); - column->setGeometry(QRect(x, 0, columnWidth, viewport()->height())); - x -= columnWidth; - } - emptyViewportRect = QRect(0, 0, x + columnWidth, viewport()->height()); - } else { - int x = m_contentX; - foreach (DolphinColumnView* column, m_columns) { - const int columnWidth = column->maximumWidth(); - column->setGeometry(QRect(x, 0, columnWidth, viewport()->height())); - x += columnWidth; - } - emptyViewportRect = QRect(x, 0, viewport()->width() - x, viewport()->height()); - } - - // Show an empty viewport if the columns don't cover the whole viewport - if (emptyViewportRect.isValid()) { - m_emptyViewport->show(); - m_emptyViewport->setGeometry(emptyViewportRect); - } else { - m_emptyViewport->hide(); - } - - // Update the horizontal position indicator - int contentWidth = 0; - foreach (DolphinColumnView* column, m_columns) { - contentWidth += column->maximumWidth(); - } - - const int scrollBarMax = contentWidth - viewport()->width(); - const bool updateScrollBar = (horizontalScrollBar()->pageStep() != contentWidth) - || (horizontalScrollBar()->maximum() != scrollBarMax); - if (updateScrollBar) { - horizontalScrollBar()->setPageStep(contentWidth); - horizontalScrollBar()->setRange(0, scrollBarMax); - } -} - -void DolphinColumnViewContainer::requestActivation(DolphinColumnView* column) -{ - if (m_dolphinViewController->itemView() != column) { - m_dolphinViewController->setItemView(column); - } - if (focusProxy() != column) { - setFocusProxy(column); - } - - if (!column->isActive()) { - // Deactivate the currently active column - if (m_index >= 0) { - m_columns[m_index]->setActive(false); - } - - // Get the index of the column that should get activated - int index = 0; - foreach (DolphinColumnView* currColumn, m_columns) { - if (currColumn == column) { - break; - } - ++index; - } - - Q_ASSERT(index != m_index); - Q_ASSERT(index < m_columns.count()); - - // Activate the requested column - m_index = index; - m_columns[m_index]->setActive(true); - - m_activeUrlTimer->start(); // calls slot updateActiveUrl() - } - - assureVisibleActiveColumn(); -} - -void DolphinColumnViewContainer::removeAllColumns() -{ - QList<DolphinColumnView*>::iterator start = m_columns.begin() + 1; - QList<DolphinColumnView*>::iterator end = m_columns.end(); - for (QList<DolphinColumnView*>::iterator it = start; it != end; ++it) { - deleteColumn(*it); - } - m_columns.erase(start, end); - m_index = 0; - m_columns[0]->setActive(true); - assureVisibleActiveColumn(); -} - -void DolphinColumnViewContainer::deleteColumn(DolphinColumnView* column) -{ - if (!column) { - return; - } - - if (m_dolphinViewController->itemView() == column) { - m_dolphinViewController->setItemView(0); - } - // deleteWhenNotDragSource(column) does not necessarily delete column, - // and we want its preview generator destroyed immediately. - column->hide(); - // Prevent automatic destruction of column when this DolphinColumnViewContainer - // is destroyed. - column->setParent(0); - column->disconnect(); - - if (DragAndDropHelper::instance().isDragSource(column)) { - // The column is a drag source (the feature "Open folders - // during drag operations" is used). Deleting the view - // during an ongoing drag operation is not allowed, so - // this will postponed. - if (m_dragSource) { - // the old stored view is obviously not the drag source anymore - m_dragSource->deleteLater(); - m_dragSource = 0; - } - m_dragSource = column; - } else { - delete column; - column = 0; - } -} - -#include "dolphincolumnviewcontainer.moc" diff --git a/src/views/dolphincolumnviewcontainer.h b/src/views/dolphincolumnviewcontainer.h deleted file mode 100644 index af6259982..000000000 --- a/src/views/dolphincolumnviewcontainer.h +++ /dev/null @@ -1,150 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINCOLUMNVIEWCONTAINER_H -#define DOLPHINCOLUMNVIEWCONTAINER_H - -#include "dolphinview.h" - -#include <KUrl> - -#include <QList> -#include <QScrollArea> -#include <QString> - -class DolphinColumnView; -class DolphinViewController; -class QFrame; -class QTimeLine; -class QTimer; - -/** - * @brief Represents a container for columns represented as instances - * of DolphinColumnView. - * - * @see DolphinColumnView - */ -class DolphinColumnViewContainer : public QScrollArea -{ - Q_OBJECT - -public: - /** - * @param parent Parent widget. - * @param dolphinViewController Allows the DolphinColumnView to control the - * DolphinView in a limited way. - * @param viewModeController Controller that is used by the DolphinView - * to control the DolphinColumnView. The DolphinColumnView - * only has read access to the controller. - * @param model Directory that is shown. - */ - explicit DolphinColumnViewContainer(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController); - virtual ~DolphinColumnViewContainer(); - - KUrl rootUrl() const; - - QAbstractItemView* activeColumn() const; - - /** - * Shows the column which represents the URL \a url. If the column - * is already shown, it gets activated, otherwise it will be created. - */ - void showColumn(const KUrl& url); - -protected: - virtual void mousePressEvent(QMouseEvent* event); - virtual void keyPressEvent(QKeyEvent* event); - virtual void resizeEvent(QResizeEvent* event); - virtual void wheelEvent(QWheelEvent* event); - -private slots: - /** - * Moves the content of the columns view to represent - * the scrollbar position \a x. - */ - void moveContentHorizontally(int x); - - /** - * Updates the background color of the columns to respect - * the current activation state \a active. - */ - void updateColumnsBackground(bool active); - - /** - * Tells the Dolphin controller to update the active URL - * to m_activeUrl. The slot is called asynchronously with a - * small delay, as this prevents a flickering when a directory - * from an inactive column gets selected. - */ - void updateActiveUrl(); - - /** - * Invoked when m_assureVisibleActiveColumnTimer has been exceeded. - * Assures that the currently active column is fully visible - * by adjusting the horizontal position of the content. - */ - void slotAssureVisibleActiveColumn(); - -private: - /** - * Assures that the currently active column is fully visible - * by adjusting the horizontal position of the content. The - * adjustment is done with a small delay (see - * slotAssureVisibleActiveColumn(); - */ - void assureVisibleActiveColumn(); - - void layoutColumns(); - - /** - * Request the activation for the column \a column. It is assured - * that the columns gets fully visible by adjusting the horizontal - * position of the content. - */ - void requestActivation(DolphinColumnView* column); - - /** Removes all columns except of the root column. */ - void removeAllColumns(); - - /** - * Deletes the column. If the itemview of the controller is set to the column, - * the controllers itemview is set to 0. - */ - void deleteColumn(DolphinColumnView* column); - -private: - DolphinViewController* m_dolphinViewController; - const ViewModeController* m_viewModeController; - bool m_active; - int m_index; - int m_contentX; - QList<DolphinColumnView*> m_columns; - QFrame* m_emptyViewport; - QTimeLine* m_animation; - QAbstractItemView* m_dragSource; - - QTimer* m_activeUrlTimer; - QTimer* m_assureVisibleActiveColumnTimer; - - friend class DolphinColumnView; -}; - -#endif diff --git a/src/views/dolphindetailsview.cpp b/src/views/dolphindetailsview.cpp deleted file mode 100644 index 0ce26df33..000000000 --- a/src/views/dolphindetailsview.cpp +++ /dev/null @@ -1,706 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz ([email protected]) * - * Copyright (C) 2008 by Simon St. James ([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 "dolphindetailsview.h" - -#include "additionalinfoaccessor.h" -#include "dolphinmodel.h" -#include "dolphinviewcontroller.h" -#include "dolphinfileitemdelegate.h" -#include "settings/dolphinsettings.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphinviewautoscroller.h" -#include "draganddrophelper.h" -#include "viewextensionsfactory.h" -#include "viewmodecontroller.h" -#include "viewproperties.h" -#include "zoomlevelinfo.h" - -#include "dolphin_detailsmodesettings.h" -#include "dolphin_generalsettings.h" - -#include <KDirModel> -#include <KDirLister> -#include <KLocale> -#include <KMenu> - -#include <QApplication> -#include <QHeaderView> -#include <QScrollBar> - -DolphinDetailsView::DolphinDetailsView(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController, - DolphinSortFilterProxyModel* proxyModel) : - DolphinTreeView(parent), - m_autoResize(true), - m_dolphinViewController(dolphinViewController), - m_extensionsFactory(0), - m_expandableFoldersAction(0), - m_expandedUrls(), - m_font(), - m_decorationSize() -{ - const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - Q_ASSERT(settings); - Q_ASSERT(dolphinViewController); - Q_ASSERT(viewModeController); - - setLayoutDirection(Qt::LeftToRight); - setAcceptDrops(true); - setSortingEnabled(true); - setSelectionBehavior(SelectItems); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - setAlternatingRowColors(true); - setRootIsDecorated(settings->expandableFolders()); - setItemsExpandable(settings->expandableFolders()); - setEditTriggers(QAbstractItemView::NoEditTriggers); - setModel(proxyModel); - - setMouseTracking(true); - - const ViewProperties props(viewModeController->url()); - setSortIndicatorSection(props.sorting()); - setSortIndicatorOrder(props.sortOrder()); - - QHeaderView* headerView = header(); - connect(headerView, SIGNAL(sectionClicked(int)), - this, SLOT(synchronizeSortingState(int))); - headerView->setContextMenuPolicy(Qt::CustomContextMenu); - connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)), - this, SLOT(configureSettings(const QPoint&))); - connect(headerView, SIGNAL(sectionResized(int, int, int)), - this, SLOT(slotHeaderSectionResized(int, int, int))); - connect(headerView, SIGNAL(sectionHandleDoubleClicked(int)), - this, SLOT(disableAutoResizing())); - - connect(parent, SIGNAL(sortingChanged(DolphinView::Sorting)), - this, SLOT(setSortIndicatorSection(DolphinView::Sorting))); - connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(setSortIndicatorOrder(Qt::SortOrder))); - - connect(this, SIGNAL(clicked(const QModelIndex&)), - dolphinViewController, SLOT(requestTab(const QModelIndex&))); - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(const QModelIndex&)), - dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } else { - connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } - - connect(this, SIGNAL(entered(const QModelIndex&)), - this, SLOT(slotEntered(const QModelIndex&))); - connect(this, SIGNAL(viewportEntered()), - dolphinViewController, SLOT(emitViewportEntered())); - connect(viewModeController, SIGNAL(zoomLevelChanged(int)), - this, SLOT(setZoomLevel(int))); - connect(dolphinViewController->view(), SIGNAL(additionalInfoChanged()), - this, SLOT(updateColumnVisibility())); - connect(viewModeController, SIGNAL(activationChanged(bool)), - this, SLOT(slotActivationChanged(bool))); - - if (settings->useSystemFont()) { - m_font = KGlobalSettings::generalFont(); - } else { - m_font = QFont(settings->fontFamily(), - qRound(settings->fontSize()), - settings->fontWeight(), - settings->italicFont()); - m_font.setPointSizeF(settings->fontSize()); - } - - setVerticalScrollMode(QTreeView::ScrollPerPixel); - setHorizontalScrollMode(QTreeView::ScrollPerPixel); - - const DolphinView* view = dolphinViewController->view(); - connect(view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - - viewport()->installEventFilter(this); - - connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), - this, SLOT(slotGlobalSettingsChanged(int))); - - m_expandableFoldersAction = new QAction(i18nc("@option:check", "Expandable Folders"), this); - m_expandableFoldersAction->setCheckable(true); - connect(m_expandableFoldersAction, SIGNAL(toggled(bool)), - this, SLOT(setFoldersExpandable(bool))); - - connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(slotExpanded(const QModelIndex&))); - connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(slotCollapsed(const QModelIndex&))); - - updateDecorationSize(view->showPreview()); - - m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController); - m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true); - - KDirLister *dirLister = qobject_cast<KDirModel*>(proxyModel->sourceModel())->dirLister(); - connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(resizeColumns())); -} - -DolphinDetailsView::~DolphinDetailsView() -{ -} - -QSet<KUrl> DolphinDetailsView::expandedUrls() const -{ - return m_expandedUrls; -} - -bool DolphinDetailsView::event(QEvent* event) -{ - if (event->type() == QEvent::Polish) { - header()->setResizeMode(QHeaderView::Interactive); - updateColumnVisibility(); - } - - return DolphinTreeView::event(event); -} - -QStyleOptionViewItem DolphinDetailsView::viewOptions() const -{ - QStyleOptionViewItem viewOptions = DolphinTreeView::viewOptions(); - viewOptions.font = m_font; - viewOptions.fontMetrics = QFontMetrics(m_font); - viewOptions.showDecorationSelected = true; - viewOptions.decorationSize = m_decorationSize; - return viewOptions; -} - -void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event) -{ - DolphinTreeView::contextMenuEvent(event); - - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - m_expandableFoldersAction->setChecked(settings->expandableFolders()); - m_dolphinViewController->triggerContextMenuRequest(event->pos(), - QList<QAction*>() << m_expandableFoldersAction); -} - -void DolphinDetailsView::mousePressEvent(QMouseEvent* event) -{ - m_dolphinViewController->requestActivation(); - - DolphinTreeView::mousePressEvent(event); - - const QModelIndex index = indexAt(event->pos()); - if (!index.isValid() || (index.column() != DolphinModel::Name)) { - // The mouse press is done somewhere outside the filename column - if (QApplication::mouseButtons() & Qt::MidButton) { - m_dolphinViewController->replaceUrlByClipboard(); - } - } -} - -void DolphinDetailsView::startDrag(Qt::DropActions supportedActions) -{ - DragAndDropHelper::instance().startDrag(this, supportedActions, m_dolphinViewController); - DolphinTreeView::startDrag(supportedActions); -} - -void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event) -{ - event->acceptProposedAction(); - DolphinTreeView::dragEnterEvent(event); -} - -void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event) -{ - DolphinTreeView::dragMoveEvent(event); - event->acceptProposedAction(); -} - -void DolphinDetailsView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - KFileItem item; - if (index.isValid() && (index.column() == DolphinModel::Name)) { - item = m_dolphinViewController->itemForIndex(index); - } - m_dolphinViewController->indicateDroppedUrls(item, event); - DolphinTreeView::dropEvent(event); -} - -void DolphinDetailsView::keyPressEvent(QKeyEvent* event) -{ - DolphinTreeView::keyPressEvent(event); - m_dolphinViewController->handleKeyPressEvent(event); -} - -void DolphinDetailsView::resizeEvent(QResizeEvent* event) -{ - DolphinTreeView::resizeEvent(event); - if (m_autoResize) { - resizeColumns(); - } -} - -void DolphinDetailsView::wheelEvent(QWheelEvent* event) -{ - const int step = m_decorationSize.height(); - verticalScrollBar()->setSingleStep(step); - DolphinTreeView::wheelEvent(event); -} - -void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous) -{ - m_extensionsFactory->handleCurrentIndexChange(current, previous); - DolphinTreeView::currentChanged(current, previous); - - // If folders are expanded, the width which is available for editing may have changed - // because it depends on the level of the current item in the folder hierarchy. - adjustMaximumSizeForEditing(current); -} - -bool DolphinDetailsView::eventFilter(QObject* watched, QEvent* event) -{ - if ((watched == viewport()) && (event->type() == QEvent::Leave)) { - // If the mouse is above an item and moved very fast outside the widget, - // no viewportEntered() signal might be emitted although the mouse has been moved - // above the viewport. - m_dolphinViewController->emitViewportEntered(); - } - - return DolphinTreeView::eventFilter(watched, event); -} - -QRect DolphinDetailsView::visualRect(const QModelIndex& index) const -{ - QRect rect = DolphinTreeView::visualRect(index); - const KFileItem item = m_dolphinViewController->itemForIndex(index); - if (!item.isNull()) { - const int width = DolphinFileItemDelegate::nameColumnWidth(item.text(), viewOptions()); - - if (width < rect.width()) { - rect.setWidth(width); - } - } - - return rect; -} - -bool DolphinDetailsView::acceptsDrop(const QModelIndex& index) const -{ - if (index.isValid() && (index.column() == DolphinModel::Name)) { - // Accept drops above directories - const KFileItem item = m_dolphinViewController->itemForIndex(index); - return !item.isNull() && item.isDir(); - } - - return false; -} - -void DolphinDetailsView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -{ - removeExpandedIndexes(parent, start, end); - DolphinTreeView::rowsAboutToBeRemoved(parent, start, end); -} - -void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting) -{ - header()->setSortIndicator(sorting, header()->sortIndicatorOrder()); -} - -void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder) -{ - header()->setSortIndicator(header()->sortIndicatorSection(), sortOrder); -} - -void DolphinDetailsView::synchronizeSortingState(int column) -{ - // The sorting has already been changed in QTreeView if this slot is - // invoked, but Dolphin is not informed about this. - DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column); - const Qt::SortOrder sortOrder = header()->sortIndicatorOrder(); - m_dolphinViewController->indicateSortingChange(sorting); - m_dolphinViewController->indicateSortOrderChange(sortOrder); -} - -void DolphinDetailsView::slotEntered(const QModelIndex& index) -{ - if (index.column() == DolphinModel::Name) { - m_dolphinViewController->emitItemEntered(index); - } else { - m_dolphinViewController->emitViewportEntered(); - } -} - -void DolphinDetailsView::setZoomLevel(int level) -{ - const int size = ZoomLevelInfo::iconSizeForZoomLevel(level); - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - - const bool showPreview = m_dolphinViewController->view()->showPreview(); - if (showPreview) { - settings->setPreviewSize(size); - } else { - settings->setIconSize(size); - } - - updateDecorationSize(showPreview); -} - -void DolphinDetailsView::slotShowPreviewChanged() -{ - const DolphinView* view = m_dolphinViewController->view(); - updateDecorationSize(view->showPreview()); -} - -void DolphinDetailsView::configureSettings(const QPoint& pos) -{ - KMenu popup(this); - popup.addTitle(i18nc("@title:menu", "Columns")); - - // Add checkbox items for each column - QHeaderView* headerView = header(); - const int columns = model()->columnCount(); - for (int i = 0; i < columns; ++i) { - const int logicalIndex = headerView->logicalIndex(i); - const QString text = model()->headerData(logicalIndex, Qt::Horizontal).toString(); - if (!text.isEmpty()) { - QAction* action = popup.addAction(text); - action->setCheckable(true); - action->setChecked(!headerView->isSectionHidden(logicalIndex)); - action->setData(logicalIndex); - action->setEnabled(logicalIndex != DolphinModel::Name); - } - } - popup.addSeparator(); - - QAction* activatedAction = popup.exec(header()->mapToGlobal(pos)); - if (activatedAction) { - const bool show = activatedAction->isChecked(); - const int columnIndex = activatedAction->data().toInt(); - - KFileItemDelegate::InformationList list = m_dolphinViewController->view()->additionalInfo(); - const KFileItemDelegate::Information info = infoForColumn(columnIndex); - if (show) { - Q_ASSERT(!list.contains(info)); - list.append(info); - } else { - Q_ASSERT(list.contains(info)); - const int index = list.indexOf(info); - list.removeAt(index); - } - - m_dolphinViewController->indicateAdditionalInfoChange(list); - setColumnHidden(columnIndex, !show); - resizeColumns(); - } -} - -void DolphinDetailsView::updateColumnVisibility() -{ - QHeaderView* headerView = header(); - disconnect(headerView, SIGNAL(sectionMoved(int, int, int)), - this, SLOT(saveColumnPositions())); - - const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - const QList<int> columnPositions = settings->columnPositions(); - - const KFileItemDelegate::InformationList list = m_dolphinViewController->view()->additionalInfo(); - for (int i = DolphinModel::Name; i < DolphinModel::ExtraColumnCount; ++i) { - const KFileItemDelegate::Information info = infoForColumn(i); - const bool hide = !list.contains(info) && (i != DolphinModel::Name); - if (isColumnHidden(i) != hide) { - setColumnHidden(i, hide); - } - - // If the list columnPositions has been written by an older Dolphin version, - // its length might be smaller than DolphinModel::ExtraColumnCount. Therefore, - // we have to check if item number i exists before accessing it. - if (i < columnPositions.length()) { - const int position = columnPositions[i]; - - // The position might be outside the correct range if the list columnPositions - // has been written by a newer Dolphin version with more columns. - if (position < DolphinModel::ExtraColumnCount) { - const int from = headerView->visualIndex(i); - headerView->moveSection(from, position); - } - } - } - - resizeColumns(); - - connect(headerView, SIGNAL(sectionMoved(int, int, int)), - this, SLOT(saveColumnPositions())); -} - -void DolphinDetailsView::resizeColumns() -{ - // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes - // around 3 seconds for each (!) resize operation when having > 10000 items). - // This gets a problem especially when opening large directories, where several - // resize operations are received for showing the currently available items during - // loading (the application hangs around 20 seconds when loading > 10000 items). - - QHeaderView* headerView = header(); - const int rowCount = model()->rowCount(); - QFontMetrics fontMetrics(viewport()->font()); - const int horizontalGap = fontMetrics.height(); - - // Define the maximum number of rows, where an exact (but expensive) calculation - // of the widths is done. - const int maxRowCount = 200; - - // Calculate the required with for each column and store it in columnWidth[] - int columnWidth[DolphinModel::ExtraColumnCount]; - - for (int column = 0; column < DolphinModel::ExtraColumnCount; ++column) { - columnWidth[column] = 0; - if (!isColumnHidden(column)) { - // Calculate the required width for the current column and consider only - // up to maxRowCount columns for performance reasons - if (rowCount > 0) { - const int count = qMin(rowCount, maxRowCount); - for (int row = 0; row < count; ++row) { - const QModelIndex index = model()->index(row, column); - QString text; - if (column == DolphinModel::Size) { - // This is a workaround as KFileItemDelegate::sizeHint() does not - // work in a way that is required for calculating the size. - const QAbstractProxyModel* proxyModel = qobject_cast<const QAbstractProxyModel*>(model()); - const KDirModel* dirModel = qobject_cast<const KDirModel*>(proxyModel->sourceModel()); - const QModelIndex dirIndex = proxyModel->mapToSource(index); - text = itemSizeString(dirIndex, dirModel->itemForIndex(dirIndex)); - } else { - text = model()->data(index).toString(); - } - const int width = fontMetrics.width(text) + horizontalGap; - if (width > columnWidth[column]) { - columnWidth[column] = width; - } - } - } - - // Assure that the required width is sufficient for the header too - const int logicalIndex = headerView->logicalIndex(column); - const QString headline = model()->headerData(logicalIndex, Qt::Horizontal).toString(); - const int headlineWidth = fontMetrics.width(headline) + horizontalGap; - - columnWidth[column] = qMax(columnWidth[column], headlineWidth); - } - } - - // Resize all columns except of the name column - int requiredWidth = 0; - for (int column = KDirModel::Size; column < DolphinModel::ExtraColumnCount; ++column) { - if (!isColumnHidden(column)) { - requiredWidth += columnWidth[column]; - headerView->resizeSection(column, columnWidth[column]); - } - } - - // Resize the name column in a way that the whole available width is used - columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth; - - const int minNameWidth = 300; - if (columnWidth[KDirModel::Name] < minNameWidth) { - columnWidth[KDirModel::Name] = minNameWidth; - - if ((rowCount > 0) && (rowCount < maxRowCount)) { - // Try to decrease the name column width without clipping any text - const int nameWidth = sizeHintForColumn(DolphinModel::Name); - if (nameWidth + requiredWidth <= viewport()->width()) { - columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth; - } else if (nameWidth < minNameWidth) { - columnWidth[KDirModel::Name] = nameWidth; - } - } - } - - headerView->resizeSection(KDirModel::Name, columnWidth[KDirModel::Name]); -} - -void DolphinDetailsView::saveColumnPositions() -{ - QList<int> columnPositions; - for (int i = DolphinModel::Name; i < DolphinModel::ExtraColumnCount; ++i) { - columnPositions.append(header()->visualIndex(i)); - } - - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - settings->setColumnPositions(columnPositions); -} - -void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize) -{ - Q_UNUSED(logicalIndex); - Q_UNUSED(oldSize); - Q_UNUSED(newSize); - // If the user changes the size of the headers, the autoresize feature should be - // turned off. As there is no dedicated interface to find out whether the header - // section has been resized by the user or by a resize event, another approach is used. - // Attention: Take care when changing the if-condition to verify that there is no - // regression in combination with bug 178630 (see fix in comment #8). - if ((QApplication::mouseButtons() & Qt::LeftButton) && header()->underMouse()) { - disableAutoResizing(); - } - - adjustMaximumSizeForEditing(currentIndex()); -} - -void DolphinDetailsView::slotActivationChanged(bool active) -{ - setAlternatingRowColors(active); -} - -void DolphinDetailsView::disableAutoResizing() -{ - m_autoResize = false; -} - -void DolphinDetailsView::requestActivation() -{ - m_dolphinViewController->requestActivation(); -} - -void DolphinDetailsView::slotGlobalSettingsChanged(int category) -{ - Q_UNUSED(category); - - const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - Q_ASSERT(settings); - if (settings->useSystemFont()) { - m_font = KGlobalSettings::generalFont(); - } - // Disconnect then reconnect, since the settings have been changed, the connection requirements may have also. - disconnect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - } else { - connect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - } -} - - -void DolphinDetailsView::setFoldersExpandable(bool expandable) -{ - if (!expandable) { - // Collapse all expanded folders, as QTreeView::setItemsExpandable(false) - // does not do this task - const int rowCount = model()->rowCount(); - for (int row = 0; row < rowCount; ++row) { - setExpanded(model()->index(row, 0), false); - } - } - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - settings->setExpandableFolders(expandable); - setRootIsDecorated(expandable); - setItemsExpandable(expandable); - - // The width of the space which is available for editing has changed - // because of the (dis)appearance of the expanding toggles - adjustMaximumSizeForEditing(currentIndex()); -} - -void DolphinDetailsView::slotExpanded(const QModelIndex& index) -{ - KFileItem item = m_dolphinViewController->itemForIndex(index); - if (!item.isNull()) { - m_expandedUrls.insert(item.url()); - } -} - -void DolphinDetailsView::slotCollapsed(const QModelIndex& index) -{ - KFileItem item = m_dolphinViewController->itemForIndex(index); - if (!item.isNull()) { - m_expandedUrls.remove(item.url()); - } -} - -void DolphinDetailsView::removeExpandedIndexes(const QModelIndex& parent, int start, int end) -{ - if (m_expandedUrls.isEmpty()) { - return; - } - - for (int row = start; row <= end; row++) { - const QModelIndex index = model()->index(row, 0, parent); - if (isExpanded(index)) { - slotCollapsed(index); - removeExpandedIndexes(index, 0, model()->rowCount(index) - 1); - } - } -} - -void DolphinDetailsView::updateDecorationSize(bool showPreview) -{ - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - const int iconSize = showPreview ? settings->previewSize() : settings->iconSize(); - setIconSize(QSize(iconSize, iconSize)); - m_decorationSize = QSize(iconSize, iconSize); - - if (m_extensionsFactory) { - // The old maximumSize used by KFileItemDelegate is not valid any more after the icon size change. - // It must be discarded before doItemsLayout() is called (see bug 234600). - m_extensionsFactory->fileItemDelegate()->setMaximumSize(QSize()); - } - - doItemsLayout(); - - // Calculate the new maximumSize for KFileItemDelegate after the icon size change. - QModelIndex current = currentIndex(); - if (current.isValid()) { - adjustMaximumSizeForEditing(current); - } -} - -KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const -{ - return AdditionalInfoAccessor::instance().keyForColumn(columnIndex); -} - -void DolphinDetailsView::adjustMaximumSizeForEditing(const QModelIndex& index) -{ - // Make sure that the full width of the "Name" column is available for "Rename Inline". - // Before we do that, we have to check if m_extensionsFactory has been initialised because - // it is possible that we end up here before the constructor is finished (see bug 257035) - if (m_extensionsFactory) { - m_extensionsFactory->fileItemDelegate()->setMaximumSize(QTreeView::visualRect(index).size()); - } -} - -QString DolphinDetailsView::itemSizeString(const QModelIndex& index, const KFileItem& item) const -{ - // The following code has been copied from KFileItemDelegate::Private::itemSize() - // Copyright (c) 2006-2007, 2008 Fredrik Höglund <[email protected]> - // Ideally this should be handled by KFileItemDelegate::sizeHint(). - if (item.isFile()) { - return KGlobal::locale()->formatByteSize(item.size()); - } - - // Return the number of items in the directory - const QVariant value = index.data(KDirModel::ChildCountRole); - const int count = value.type() == QVariant::Int ? value.toInt() : KDirModel::ChildCountUnknown; - - if (count == KDirModel::ChildCountUnknown) { - return QString(); - } - - return i18ncp("Items in a folder", "1 item", "%1 items", count); -} - -#include "dolphindetailsview.moc" diff --git a/src/views/dolphindetailsview.h b/src/views/dolphindetailsview.h deleted file mode 100644 index 305035dd5..000000000 --- a/src/views/dolphindetailsview.h +++ /dev/null @@ -1,224 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2010 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINDETAILSVIEW_H -#define DOLPHINDETAILSVIEW_H - -#include "dolphintreeview.h" -#include <QTreeView> -#include <libdolphin_export.h> -#include <views/dolphinview.h> - -class DolphinViewController; -class DolphinSortFilterProxyModel; -class ViewExtensionsFactory; - -/** - * @brief Represents the details view which shows the name, size, - * date, permissions, owner and group of an item. - * - * The width of the columns is automatically adjusted in a way - * that full available width of the view is used by stretching the width - * of the name column. - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinDetailsView : public DolphinTreeView -{ - Q_OBJECT - -public: - /** - * @param parent Parent widget. - * @param dolphinViewController Allows the DolphinDetailsView to control the - * DolphinView in a limited way. - * @param viewModeController Controller that is used by the DolphinView - * to control the DolphinDetailsView. The DolphinDetailsView - * only has read access to the controller. - * @param model Directory that is shown. - */ - explicit DolphinDetailsView(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController, - DolphinSortFilterProxyModel* model); - virtual ~DolphinDetailsView(); - - /** - * Returns a set containing the URLs of all expanded items. - */ - QSet<KUrl> expandedUrls() const; - -public: - virtual QRect visualRect(const QModelIndex& index) const; - -protected: - virtual bool event(QEvent* event); - virtual QStyleOptionViewItem viewOptions() const; - virtual void contextMenuEvent(QContextMenuEvent* event); - virtual void mousePressEvent(QMouseEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dropEvent(QDropEvent* event); - virtual void keyPressEvent(QKeyEvent* event); - virtual void resizeEvent(QResizeEvent* event); - virtual void wheelEvent(QWheelEvent* event); - virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); - virtual bool eventFilter(QObject* watched, QEvent* event); - virtual bool acceptsDrop(const QModelIndex& index) const; - -protected slots: - virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); - -private slots: - /** - * Sets the sort indicator section of the header view - * corresponding to \a sorting. - */ - void setSortIndicatorSection(DolphinView::Sorting sorting); - - /** - * Sets the sort indicator order of the header view - * corresponding to \a sortOrder. - */ - void setSortIndicatorOrder(Qt::SortOrder sortOrder); - - /** - * Synchronizes the sorting state of the Dolphin menu 'View -> Sort' - * with the current state of the details view. - * @param column Index of the current sorting column. - */ - void synchronizeSortingState(int column); - - /** - * Is invoked when the mouse cursor has entered an item. The controller - * gets informed to emit the itemEntered() signal if the mouse cursor - * is above the name column. Otherwise the controller gets informed - * to emit the itemViewportEntered() signal (all other columns should - * behave as viewport area). - */ - void slotEntered(const QModelIndex& index); - - void setZoomLevel(int level); - - void slotShowPreviewChanged(); - - /** - * Opens a context menu at the position \a pos and allows to - * configure the visibility of the header columns and whether - * expandable folders should be shown. - */ - void configureSettings(const QPoint& pos); - - /** - * Updates the visibilty state of columns and their order. - */ - void updateColumnVisibility(); - - /** - * Resizes all columns in a way to use the whole available width of the view. - */ - void resizeColumns(); - - /** - * Saves order of the columns as global setting. - */ - void saveColumnPositions(); - - /** - * Disables the automatical resizing of columns, if the user has resized the columns - * with the mouse. - */ - void slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize); - - /** - * Changes the alternating row colors setting depending from - * the activation state \a active. - */ - void slotActivationChanged(bool active); - - /** - * Disables the automatical resizing of the columns. Per default all columns - * are resized to use the maximum available width of the view as good as possible. - */ - void disableAutoResizing(); - - void requestActivation(); - - void slotGlobalSettingsChanged(int category); - - /** - * If \a expandable is true, the details view acts as tree view. - * The current expandable state is remembered in the settings. - */ - void setFoldersExpandable(bool expandable); - - /** - * These slots update the list of expanded items. - */ - void slotExpanded(const QModelIndex& index); - void slotCollapsed(const QModelIndex& index); - -private: - /** - * Removes the URLs corresponding to the children of \a index in the rows - * between \a start and \a end inclusive from the set of expanded URLs. - */ - void removeExpandedIndexes(const QModelIndex& parent, int start, int end); - - /** - * Updates the size of the decoration dependent on the - * icon size of the DetailsModeSettings. The controller - * will get informed about possible zoom in/zoom out - * operations. - */ - void updateDecorationSize(bool showPreview); - - KFileItemDelegate::Information infoForColumn(int columnIndex) const; - - /** - * Sets the maximum size available for editing in the delegate. - */ - void adjustMaximumSizeForEditing(const QModelIndex& index); - - /** - * Helper method for DolphinDetailsView::resizeColumns(): Returns the - * string representation of the size-value for the given index. - */ - QString itemSizeString(const QModelIndex& index, const KFileItem& item) const; - -private: - bool m_autoResize; // if true, the columns are resized automatically to the available width - - DolphinViewController* m_dolphinViewController; - ViewExtensionsFactory* m_extensionsFactory; - QAction* m_expandableFoldersAction; - - // A set containing the URLs of all currently expanded folders. - // We cannot use a QSet<QModelIndex> because a QModelIndex is not guaranteed to remain valid over time. - // Also a QSet<QPersistentModelIndex> does not work as expected because it is not guaranteed that - // subsequent expand/collapse events of the same file item will yield the same QPersistentModelIndex. - QSet<KUrl> m_expandedUrls; - - QFont m_font; - QSize m_decorationSize; - - // For unit tests - friend class DolphinDetailsViewTest; -}; - -#endif diff --git a/src/views/dolphindetailsviewexpander.cpp b/src/views/dolphindetailsviewexpander.cpp deleted file mode 100644 index cc4bc67be..000000000 --- a/src/views/dolphindetailsviewexpander.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Frank Reininghaus ([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 "dolphindetailsviewexpander.h" - -#include "dolphindetailsview.h" -#include "dolphinmodel.h" -#include "dolphinsortfilterproxymodel.h" - -#include <KDirLister> -#include <KDirModel> - -DolphinDetailsViewExpander::DolphinDetailsViewExpander(DolphinDetailsView* parent, - const QSet<KUrl>& urlsToExpand) : - QObject(parent), - m_detailsView(parent), - m_dirLister(0), - m_dolphinModel(0), - m_proxyModel(0) -{ - Q_ASSERT(parent); - - m_proxyModel = qobject_cast<const DolphinSortFilterProxyModel*>(parent->model()); - Q_ASSERT(m_proxyModel); - - m_dolphinModel = qobject_cast<const DolphinModel*>(m_proxyModel->sourceModel()); - Q_ASSERT(m_dolphinModel); - - m_dirLister = m_dolphinModel->dirLister(); - Q_ASSERT(m_dirLister); - - // The URLs must be sorted. E.g. /home/user/ cannot be expanded before /home/ - // because it is not known to the dir model before. - m_urlsToExpand = urlsToExpand.toList(); - qSort(m_urlsToExpand); - - // The dir lister must have completed the folder listing before a subfolder can be expanded. - connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); -} - -DolphinDetailsViewExpander::~DolphinDetailsViewExpander() -{ -} - -void DolphinDetailsViewExpander::stop() -{ - disconnect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); - deleteLater(); -} - -void DolphinDetailsViewExpander::slotDirListerCompleted() -{ - QModelIndex dirIndex; - - while(!m_urlsToExpand.isEmpty() && !dirIndex.isValid()) { - const KUrl url = m_urlsToExpand.takeFirst(); - dirIndex = m_dolphinModel->indexForUrl(url); - } - - if(dirIndex.isValid()) { - // A valid model index was found. Note that only one item is expanded in each call of this slot - // because expanding any item will trigger KDirLister::openUrl(...) via KDirModel::fetchMore(...), - // and we can only continue when the dir lister is done. - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - m_detailsView->expand(proxyIndex); - } - else { - emit completed(); - stop(); - } -} diff --git a/src/views/dolphindetailsviewexpander.h b/src/views/dolphindetailsviewexpander.h deleted file mode 100644 index b4dc2fc72..000000000 --- a/src/views/dolphindetailsviewexpander.h +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Frank Reininghaus ([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 * - ***************************************************************************/ - -#ifndef DOLPHINDETAILSVIEWEXPANDER_H -#define DOLPHINDETAILSVIEWEXPANDER_H - -#include <QObject> -#include <QSet> -#include <QList> - -class DolphinDetailsView; -class KUrl; -class KDirLister; -class DolphinModel; -class DolphinSortFilterProxyModel; - -/** - * @brief Expands a given set of subfolders in collaboration with the dir lister and the dir model. - * - * Note that only one subfolder can be expanded at a time. Each expansion triggers KDirLister::openUrl(...), - * and further expansions can only be done the next time the dir lister emits its completed() signal. - */ -class DolphinDetailsViewExpander : public QObject -{ - Q_OBJECT - -public: - explicit DolphinDetailsViewExpander(DolphinDetailsView* parent, - const QSet<KUrl>& urlsToExpand); - - virtual ~DolphinDetailsViewExpander(); - - /** - * Stops the expansion and deletes the object via deleteLater(). - */ - void stop(); - -private slots: - /** - * This slot is invoked every time the dir lister has completed a listing. - * It expands the first URL from the list m_urlsToExpand that can be found in the dir model. - * If the list is empty, stop() is called. - */ - void slotDirListerCompleted(); - -signals: - /** - * Is emitted when the expander has finished expanding URLs in the details view. - */ - void completed(); - -private: - QList<KUrl> m_urlsToExpand; - - DolphinDetailsView* m_detailsView; - const KDirLister* m_dirLister; - const DolphinModel* m_dolphinModel; - const DolphinSortFilterProxyModel* m_proxyModel; -}; - -#endif diff --git a/src/views/dolphindirlister.cpp b/src/views/dolphindirlister.cpp index 568681fb7..b62abe167 100644 --- a/src/views/dolphindirlister.cpp +++ b/src/views/dolphindirlister.cpp @@ -21,8 +21,8 @@ #include <KLocale> #include <KIO/JobClasses> -DolphinDirLister::DolphinDirLister() : - KDirLister() +DolphinDirLister::DolphinDirLister(QObject* parent) : + KDirLister(parent) { setAutoErrorHandlingEnabled(false, 0); } diff --git a/src/views/dolphindirlister.h b/src/views/dolphindirlister.h index 662c7c0aa..0955df232 100644 --- a/src/views/dolphindirlister.h +++ b/src/views/dolphindirlister.h @@ -32,7 +32,7 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinDirLister : public KDirLister Q_OBJECT public: - DolphinDirLister(); + DolphinDirLister(QObject* parent = 0); virtual ~DolphinDirLister(); signals: diff --git a/src/views/dolphinfileitemdelegate.cpp b/src/views/dolphinfileitemdelegate.cpp deleted file mode 100644 index 4d66c73f1..000000000 --- a/src/views/dolphinfileitemdelegate.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[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 "dolphinfileitemdelegate.h" - -#include "dolphinmodel.h" -#include <KColorScheme> -#include <KFileItem> -#include <KGlobalSettings> -#include <KIcon> -#include <KIconLoader> -#include <KStringHandler> - -#include <QAbstractItemModel> -#include <QAbstractProxyModel> -#include <QFontMetrics> -#include <QPalette> -#include <QPainter> -#include <QStyleOptionViewItemV4> - -DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) : - KFileItemDelegate(parent), - m_hasMinimizedNameColumn(false), - m_cachedSize(), - m_cachedEmblems(), - m_cachedInactiveTextColorDirty(true) -{ - setJobTransfersVisible(true); - connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(handleDisplayPaletteChange())); -} - -DolphinFileItemDelegate::~DolphinFileItemDelegate() -{ -} - -void DolphinFileItemDelegate::paint(QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index) const -{ - const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(index.model()); - const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(proxyModel->sourceModel()); - const bool isNameColumn = (index.column() == KDirModel::Name); - - QStyleOptionViewItemV4 opt(option); - if (m_hasMinimizedNameColumn && isNameColumn) { - adjustOptionWidth(opt, proxyModel, dolphinModel, index); - } - - if (!isNameColumn) { - // Use the inactive text color for all columns except the name column. This indicates for the user that - // hovering other columns does not change the actions context. - QPalette palette = opt.palette; - if (m_cachedInactiveTextColorDirty) { - m_cachedInactiveTextColor = KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText).color(); - m_cachedInactiveTextColorDirty = false; - } - palette.setColor(QPalette::Text, m_cachedInactiveTextColor); - opt.palette = palette; - } - - if (dolphinModel->hasVersionData() && isNameColumn) { - // The currently shown items are under revision control. Show the current revision - // state by adding an emblem and changing the text tintColor. - const QModelIndex dirIndex = proxyModel->mapToSource(index); - const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Version, dirIndex.parent()); - const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole); - const KVersionControlPlugin::VersionState state = static_cast<KVersionControlPlugin::VersionState>(data.toInt()); - - adjustOptionTextColor(opt, state); - - KFileItemDelegate::paint(painter, opt, index); - - if (state != KVersionControlPlugin::UnversionedVersion) { - const QRect rect = iconRect(option, index); - const QPixmap emblem = emblemForState(state, rect.size()); - painter->drawPixmap(rect.x(), rect.y() + rect.height() - emblem.height(), emblem); - } - } else { - KFileItemDelegate::paint(painter, opt, index); - } -} - -int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option) -{ - QFontMetrics fontMetrics(option.font); - int width = option.decorationSize.width() + fontMetrics.width(KStringHandler::preProcessWrap(name)) + 16; - - const int defaultWidth = option.rect.width(); - if ((defaultWidth > 0) && (defaultWidth < width)) { - width = defaultWidth; - } - return width; -} - -void DolphinFileItemDelegate::handleDisplayPaletteChange() -{ - m_cachedInactiveTextColorDirty = true; -} - -void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option, - const QAbstractProxyModel* proxyModel, - const DolphinModel* dolphinModel, - const QModelIndex& index) -{ - const QModelIndex dirIndex = proxyModel->mapToSource(index); - const KFileItem item = dolphinModel->itemForIndex(dirIndex); - if (!item.isNull()) { - // symbolic links are displayed in an italic font - if (item.isLink()) { - option.font.setItalic(true); - } - - const int width = nameColumnWidth(item.text(), option); - option.rect.setWidth(width); - } -} - -void DolphinFileItemDelegate::adjustOptionTextColor(QStyleOptionViewItemV4& option, - KVersionControlPlugin::VersionState state) -{ - QColor tintColor; - - // Using hardcoded colors is generally a bad idea. In this case the colors just act - // as tint colors and are mixed with the current set text color. The tint colors - // have been optimized for the base colors of the corresponding Oxygen emblems. - switch (state) { - case KVersionControlPlugin::UpdateRequiredVersion: tintColor = Qt::yellow; break; - case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::darkGreen; break; - case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break; - case KVersionControlPlugin::AddedVersion: tintColor = Qt::green; break; - case KVersionControlPlugin::RemovedVersion: tintColor = Qt::darkRed; break; - case KVersionControlPlugin::ConflictingVersion: tintColor = Qt::red; break; - case KVersionControlPlugin::UnversionedVersion: - case KVersionControlPlugin::NormalVersion: - default: - // use the default text color - return; - } - - QPalette palette = option.palette; - const QColor textColor = palette.color(QPalette::Text); - tintColor = QColor((tintColor.red() + textColor.red()) / 2, - (tintColor.green() + textColor.green()) / 2, - (tintColor.blue() + textColor.blue()) / 2, - (tintColor.alpha() + textColor.alpha()) / 2); - palette.setColor(QPalette::Text, tintColor); - option.palette = palette; -} - -QPixmap DolphinFileItemDelegate::emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const -{ - Q_ASSERT(state <= KVersionControlPlugin::LocallyModifiedUnstagedVersion); - if (m_cachedSize != size) { - m_cachedSize = size; - - const int iconHeight = size.height(); - int emblemHeight = KIconLoader::SizeSmall; - if (iconHeight >= KIconLoader::SizeEnormous) { - emblemHeight = KIconLoader::SizeMedium; - } else if (iconHeight >= KIconLoader::SizeLarge) { - emblemHeight = KIconLoader::SizeSmallMedium; - } else if (iconHeight >= KIconLoader::SizeMedium) { - emblemHeight = KIconLoader::SizeSmall; - } else { - emblemHeight = KIconLoader::SizeSmall / 2; - } - - const QSize emblemSize(emblemHeight, emblemHeight); - for (int i = KVersionControlPlugin::NormalVersion; i <= KVersionControlPlugin::LocallyModifiedUnstagedVersion; ++i) { - QString iconName; - switch (i) { - case KVersionControlPlugin::NormalVersion: - iconName = "vcs-normal"; - break; - case KVersionControlPlugin::UpdateRequiredVersion: - iconName = "vcs-update-required"; - break; - case KVersionControlPlugin::LocallyModifiedVersion: - iconName = "vcs-locally-modified"; - break; - case KVersionControlPlugin::LocallyModifiedUnstagedVersion: - iconName = "vcs-locally-modified-unstaged"; - break; - case KVersionControlPlugin::AddedVersion: - iconName = "vcs-added"; - break; - case KVersionControlPlugin::RemovedVersion: - iconName = "vcs-removed"; - break; - case KVersionControlPlugin::ConflictingVersion: - iconName = "vcs-conflicting"; - break; - case KVersionControlPlugin::UnversionedVersion: - break; - default: - Q_ASSERT(false); - break; - } - - m_cachedEmblems[i] = KIcon(iconName).pixmap(emblemSize); - } - } - return m_cachedEmblems[state]; -} - diff --git a/src/views/dolphinfileitemdelegate.h b/src/views/dolphinfileitemdelegate.h deleted file mode 100644 index ab4a9fd20..000000000 --- a/src/views/dolphinfileitemdelegate.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINFILEITEMDELEGATE_H -#define DOLPHINFILEITEMDELEGATE_H - -#include <KFileItemDelegate> -#include <views/dolphinmodel.h> - -class QAbstractProxyModel; - -/** - * Extends KFileItemDelegate by the ability to show the hover effect - * and the selection in a minimized way for the name column of - * the details view. - * - * Note that this is a workaround, as Qt does not support having custom - * shapes within the visual rect of an item view. The visual part of - * workaround is handled inside DolphinFileItemDelegate, the behavior - * changes are handled in DolphinTreeView. - */ -class DolphinFileItemDelegate : public KFileItemDelegate -{ - Q_OBJECT -public: - explicit DolphinFileItemDelegate(QObject* parent = 0); - virtual ~DolphinFileItemDelegate(); - - /** - * If \a minimized is true, the hover effect and the selection are - * only drawn above the icon and text of an item. Per default - * \a minimized is false, which means that the whole visual rect is - * used like in KFileItemDelegate. - */ - void setMinimizedNameColumn(bool minimized); - bool hasMinimizedNameColumn() const; - - virtual void paint(QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index) const; - - /** - * Returns the minimized width of the name column for the name \a name. This method - * is also used in DolphinDetailsView to handle the selection of items correctly. - */ - static int nameColumnWidth(const QString& name, const QStyleOptionViewItem& option); - -private slots: - void handleDisplayPaletteChange(); - -private: - static void adjustOptionWidth(QStyleOptionViewItemV4& option, - const QAbstractProxyModel* proxyModel, - const DolphinModel* dolphinModel, - const QModelIndex& index); - - static void adjustOptionTextColor(QStyleOptionViewItemV4& option, - KVersionControlPlugin::VersionState state); - - QPixmap emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const; - -private: - bool m_hasMinimizedNameColumn; - mutable QSize m_cachedSize; - mutable QPixmap m_cachedEmblems[KVersionControlPlugin::LocallyModifiedUnstagedVersion + 1]; - mutable QColor m_cachedInactiveTextColor; - mutable bool m_cachedInactiveTextColorDirty; -}; - -inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized) -{ - m_hasMinimizedNameColumn = minimized; -} - -inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const -{ - return m_hasMinimizedNameColumn; -} - -#endif diff --git a/src/views/dolphiniconsview.cpp b/src/views/dolphiniconsview.cpp deleted file mode 100644 index a863de72d..000000000 --- a/src/views/dolphiniconsview.cpp +++ /dev/null @@ -1,524 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2009 by Peter Penz <[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 "dolphiniconsview.h" - -#include "dolphincategorydrawer.h" -#include "dolphinviewcontroller.h" -#include "settings/dolphinsettings.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphin_iconsmodesettings.h" -#include "dolphin_generalsettings.h" -#include "draganddrophelper.h" -#include "selectionmanager.h" -#include "viewextensionsfactory.h" -#include "viewmodecontroller.h" -#include "zoomlevelinfo.h" - -#include <KCategorizedSortFilterProxyModel> -#include <KDialog> -#include <KFileItemDelegate> - -#include <QAbstractProxyModel> -#include <QApplication> -#include <QScrollBar> - -DolphinIconsView::DolphinIconsView(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController, - DolphinSortFilterProxyModel* proxyModel) : - KCategorizedView(parent), - m_dolphinViewController(dolphinViewController), - m_categoryDrawer(new DolphinCategoryDrawer(this)), - m_extensionsFactory(0), - m_font(), - m_decorationSize(), - m_decorationPosition(QStyleOptionViewItem::Top), - m_displayAlignment(Qt::AlignHCenter), - m_itemSize(), - m_dropRect() -{ - Q_ASSERT(dolphinViewController); - Q_ASSERT(viewModeController); - - setModel(proxyModel); - setLayoutDirection(Qt::LeftToRight); - setViewMode(QListView::IconMode); - setResizeMode(QListView::Adjust); - setMovement(QListView::Static); - setDragEnabled(true); - setEditTriggers(QAbstractItemView::NoEditTriggers); - viewport()->setAcceptDrops(true); - - setMouseTracking(true); - - connect(this, SIGNAL(clicked(const QModelIndex&)), - dolphinViewController, SLOT(requestTab(const QModelIndex&))); - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(const QModelIndex&)), - dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } else { - connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - } - - connect(this, SIGNAL(entered(const QModelIndex&)), - dolphinViewController, SLOT(emitItemEntered(const QModelIndex&))); - connect(this, SIGNAL(viewportEntered()), - dolphinViewController, SLOT(emitViewportEntered())); - connect(viewModeController, SIGNAL(zoomLevelChanged(int)), - this, SLOT(setZoomLevel(int))); - - const DolphinView* view = dolphinViewController->view(); - connect(view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - connect(view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); - - // apply the icons mode settings to the widget - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - Q_ASSERT(settings); - - if (settings->useSystemFont()) { - m_font = KGlobalSettings::generalFont(); - } else { - m_font = QFont(settings->fontFamily(), - qRound(settings->fontSize()), - settings->fontWeight(), - settings->italicFont()); - m_font.setPointSizeF(settings->fontSize()); - } - - setWordWrap(settings->numberOfTextlines() > 1); - - if (settings->arrangement() == QListView::TopToBottom) { - setFlow(QListView::LeftToRight); - m_decorationPosition = QStyleOptionViewItem::Top; - m_displayAlignment = Qt::AlignHCenter; - } else { - setFlow(QListView::TopToBottom); - m_decorationPosition = QStyleOptionViewItem::Left; - m_displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; - } - - connect(m_categoryDrawer, SIGNAL(actionRequested(int,QModelIndex)), this, SLOT(categoryDrawerActionRequested(int,QModelIndex))); - setCategoryDrawer(m_categoryDrawer); - - connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), - this, SLOT(slotGlobalSettingsChanged(int))); - - updateGridSize(view->showPreview(), 0); - m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController); -} - -DolphinIconsView::~DolphinIconsView() -{ -} - -void DolphinIconsView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) -{ - KCategorizedView::dataChanged(topLeft, bottomRight); - - KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model()); - if (!proxyModel->isCategorizedModel()) { - // bypass a QListView issue that items are not layout correctly if the decoration size of - // an index changes - scheduleDelayedItemsLayout(); - } -} - -QStyleOptionViewItem DolphinIconsView::viewOptions() const -{ - QStyleOptionViewItem viewOptions = KCategorizedView::viewOptions(); - viewOptions.font = m_font; - viewOptions.fontMetrics = QFontMetrics(m_font); - viewOptions.decorationPosition = m_decorationPosition; - viewOptions.decorationSize = m_decorationSize; - viewOptions.displayAlignment = m_displayAlignment; - viewOptions.showDecorationSelected = true; - return viewOptions; -} - -void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) -{ - KCategorizedView::contextMenuEvent(event); - m_dolphinViewController->triggerContextMenuRequest(event->pos()); -} - -void DolphinIconsView::mousePressEvent(QMouseEvent* event) -{ - m_dolphinViewController->requestActivation(); - const QModelIndex index = indexAt(event->pos()); - if (index.isValid() && (event->button() == Qt::LeftButton)) { - // TODO: It should not be necessary to manually set the dragging state, but I could - // not reproduce this issue with a Qt-only example yet to find the root cause. - // Issue description: start Dolphin, split the view and drag an item from the - // inactive view to the active view by a very fast mouse movement. Result: - // the item gets selected instead of being dragged... - setState(QAbstractItemView::DraggingState); - } - - if (!index.isValid() && (QApplication::mouseButtons() & Qt::MidButton)) { - m_dolphinViewController->replaceUrlByClipboard(); - } - - KCategorizedView::mousePressEvent(event); -} - -void DolphinIconsView::startDrag(Qt::DropActions supportedActions) -{ - DragAndDropHelper::instance().startDrag(this, supportedActions, m_dolphinViewController); -} - -void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) -{ - event->acceptProposedAction(); -} - -void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) -{ - KCategorizedView::dragLeaveEvent(event); - setDirtyRegion(m_dropRect); -} - -void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) -{ - KCategorizedView::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.setSize(QSize()); // set as invalid - if (index.isValid()) { - const KFileItem item = m_dolphinViewController->itemForIndex(index); - if (!item.isNull() && item.isDir()) { - m_dropRect = visualRect(index); - } else { - m_dropRect.setSize(QSize()); // set as invalid - } - } - event->acceptProposedAction(); - - setDirtyRegion(m_dropRect); -} - -void DolphinIconsView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - const KFileItem item = m_dolphinViewController->itemForIndex(index); - m_dolphinViewController->indicateDroppedUrls(item, event); - // don't call KCategorizedView::dropEvent(event), as it moves - // the items which is not wanted -} - -QModelIndex DolphinIconsView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) -{ - const QModelIndex oldCurrent = currentIndex(); - - QModelIndex newCurrent = KCategorizedView::moveCursor(cursorAction, modifiers); - if (newCurrent != oldCurrent) { - return newCurrent; - } - - // The cursor has not been moved by the base implementation. Provide a - // wrap behavior, so that the cursor will go to the next item when reaching - // the border. - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - if (settings->arrangement() == QListView::LeftToRight) { - switch (cursorAction) { - case MoveUp: - if (newCurrent.row() == 0) { - return newCurrent; - } - newCurrent = KCategorizedView::moveCursor(MoveLeft, modifiers); - selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); - newCurrent = KCategorizedView::moveCursor(MovePageDown, modifiers); - break; - - case MoveDown: - if (newCurrent.row() == (model()->rowCount() - 1)) { - return newCurrent; - } - newCurrent = KCategorizedView::moveCursor(MovePageUp, modifiers); - selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); - newCurrent = KCategorizedView::moveCursor(MoveRight, modifiers); - break; - - default: - break; - } - } else { - QModelIndex current = oldCurrent; - switch (cursorAction) { - case MoveLeft: - if (newCurrent.row() == 0) { - return newCurrent; - } - newCurrent = KCategorizedView::moveCursor(MoveUp, modifiers); - do { - selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); - current = newCurrent; - newCurrent = KCategorizedView::moveCursor(MoveRight, modifiers); - } while (newCurrent != current); - break; - - case MoveRight: - if (newCurrent.row() == (model()->rowCount() - 1)) { - return newCurrent; - } - do { - selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); - current = newCurrent; - newCurrent = KCategorizedView::moveCursor(MoveLeft, modifiers); - } while (newCurrent != current); - newCurrent = KCategorizedView::moveCursor(MoveDown, modifiers); - break; - - default: - break; - } - } - - // Revert all changes of the current item to make sure that item selection works correctly - selectionModel()->setCurrentIndex(oldCurrent, QItemSelectionModel::NoUpdate); - return newCurrent; -} - -void DolphinIconsView::keyPressEvent(QKeyEvent* event) -{ - KCategorizedView::keyPressEvent(event); - m_dolphinViewController->handleKeyPressEvent(event); -} - -void DolphinIconsView::wheelEvent(QWheelEvent* event) -{ - horizontalScrollBar()->setSingleStep(m_itemSize.width() / 5); - verticalScrollBar()->setSingleStep(m_itemSize.height() / 5); - - KCategorizedView::wheelEvent(event); - // if the icons are aligned left to right, the vertical wheel event should - // be applied to the horizontal scrollbar - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const bool scrollHorizontal = (event->orientation() == Qt::Vertical) && - (settings->arrangement() == QListView::LeftToRight); - if (scrollHorizontal) { - QWheelEvent horizEvent(event->pos(), - event->delta(), - event->buttons(), - event->modifiers(), - Qt::Horizontal); - QApplication::sendEvent(horizontalScrollBar(), &horizEvent); - } -} - -void DolphinIconsView::showEvent(QShowEvent* event) -{ - KFileItemDelegate* delegate = dynamic_cast<KFileItemDelegate*>(itemDelegate()); - delegate->setMaximumSize(m_itemSize); - - KCategorizedView::showEvent(event); -} - -void DolphinIconsView::leaveEvent(QEvent* event) -{ - KCategorizedView::leaveEvent(event); - // if the mouse is above an item and moved very fast outside the widget, - // no viewportEntered() signal might be emitted although the mouse has been moved - // above the viewport - m_dolphinViewController->emitViewportEntered(); -} - -void DolphinIconsView::currentChanged(const QModelIndex& current, const QModelIndex& previous) -{ - KCategorizedView::currentChanged(current, previous); - m_extensionsFactory->handleCurrentIndexChange(current, previous); -} - -void DolphinIconsView::resizeEvent(QResizeEvent* event) -{ - KCategorizedView::resizeEvent(event); - const DolphinView* view = m_dolphinViewController->view(); - updateGridSize(view->showPreview(), view->additionalInfo().count()); -} - -void DolphinIconsView::slotShowPreviewChanged() -{ - const DolphinView* view = m_dolphinViewController->view(); - updateGridSize(view->showPreview(), additionalInfoCount()); -} - -void DolphinIconsView::slotAdditionalInfoChanged() -{ - const DolphinView* view = m_dolphinViewController->view(); - const bool showPreview = view->showPreview(); - updateGridSize(showPreview, view->additionalInfo().count()); -} - -void DolphinIconsView::setZoomLevel(int level) -{ - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - - const int oldIconSize = settings->iconSize(); - int newIconSize = oldIconSize; - - const bool showPreview = m_dolphinViewController->view()->showPreview(); - if (showPreview) { - const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(level); - settings->setPreviewSize(previewSize); - } else { - newIconSize = ZoomLevelInfo::iconSizeForZoomLevel(level); - settings->setIconSize(newIconSize); - } - - // increase also the grid size - const int diff = newIconSize - oldIconSize; - settings->setItemWidth(settings->itemWidth() + diff); - settings->setItemHeight(settings->itemHeight() + diff); - - updateGridSize(showPreview, additionalInfoCount()); -} - -void DolphinIconsView::requestActivation() -{ - m_dolphinViewController->requestActivation(); -} - -void DolphinIconsView::slotGlobalSettingsChanged(int category) -{ - Q_UNUSED(category); - - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - Q_ASSERT(settings); - if (settings->useSystemFont()) { - m_font = KGlobalSettings::generalFont(); - } - - disconnect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - } else { - connect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex))); - } -} - -void DolphinIconsView::categoryDrawerActionRequested(int action, const QModelIndex &index) -{ - const QSortFilterProxyModel *model = dynamic_cast<const QSortFilterProxyModel*>(index.model()); - const QModelIndex topLeft = model->index(index.row(), modelColumn()); - QModelIndex bottomRight = topLeft; - const QString category = model->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - QModelIndex current = topLeft; - while (true) { - current = model->index(current.row() + 1, modelColumn()); - const QString curCategory = model->data(model->index(current.row(), index.column()), KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); - if (!current.isValid() || category != curCategory) { - break; - } - bottomRight = current; - } - switch (action) { - case DolphinCategoryDrawer::SelectAll: - selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select); - break; - case DolphinCategoryDrawer::UnselectAll: - selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Deselect); - break; - default: - break; - } -} - -void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) -{ - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - Q_ASSERT(settings); - - int itemWidth = settings->itemWidth(); - int itemHeight = settings->itemHeight(); - int size = settings->iconSize(); - - if (showPreview) { - const int previewSize = settings->previewSize(); - const int diff = previewSize - size; - itemWidth += diff; - itemHeight += diff; - - size = previewSize; - } - - Q_ASSERT(additionalInfoCount >= 0); - itemHeight += additionalInfoCount * QFontMetrics(m_font).height(); - - // Optimize the item size of the grid in a way to prevent large gaps on the - // right border (= row arrangement) or the bottom border (= column arrangement). - // There is no public API in QListView to find out the used width of the viewport - // for the layout. The following calculation of 'contentWidth'/'contentHeight' - // is based on QListViewPrivate::prepareItemsLayout() (Copyright (C) 2009 Nokia Corporation). - int frameAroundContents = 0; - if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) { - frameAroundContents = style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2; - } - const int spacing = settings->gridSpacing(); - if (settings->arrangement() == QListView::TopToBottom) { - const int contentWidth = viewport()->width() - 1 - - frameAroundContents - - style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, horizontalScrollBar()); - const int gridWidth = itemWidth + spacing * 2; - const int horizItemCount = contentWidth / gridWidth; - if (horizItemCount > 0) { - itemWidth += (contentWidth - horizItemCount * gridWidth) / horizItemCount; - } - - // The decoration width indirectly defines the maximum - // width for the text wrapping. To use the maximum item width - // for text wrapping, it is used as decoration width. - m_decorationSize = QSize(itemWidth, size); - setIconSize(QSize(itemWidth, size)); - } else { - const int contentHeight = viewport()->height() - 1 - - frameAroundContents - - style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, verticalScrollBar()); - const int gridHeight = itemHeight + spacing; - const int vertItemCount = contentHeight / gridHeight; - if (vertItemCount > 0) { - itemHeight += (contentHeight - vertItemCount * gridHeight) / vertItemCount; - } - - m_decorationSize = QSize(size, size); - setIconSize(QSize(size, size)); - } - - m_itemSize = QSize(itemWidth, itemHeight); - setGridSizeOwn(QSize(itemWidth + spacing * 2, itemHeight + spacing)); - - KFileItemDelegate* delegate = dynamic_cast<KFileItemDelegate*>(itemDelegate()); - if (delegate) { - delegate->setMaximumSize(m_itemSize); - } -} - -int DolphinIconsView::additionalInfoCount() const -{ - const DolphinView* view = m_dolphinViewController->view(); - return view->additionalInfo().count(); -} - -#include "dolphiniconsview.moc" diff --git a/src/views/dolphiniconsview.h b/src/views/dolphiniconsview.h deleted file mode 100644 index 2dd1aa79f..000000000 --- a/src/views/dolphiniconsview.h +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2009 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINICONSVIEW_H -#define DOLPHINICONSVIEW_H - -#include <KCategorizedView> - -#include <KFileItem> -#include <KFileItemDelegate> - -#include <QFont> -#include <QSize> -#include <QStyleOption> - -#include <libdolphin_export.h> - -class DolphinViewController; -class DolphinCategoryDrawer; -class DolphinSortFilterProxyModel; -class ViewExtensionsFactory; -class ViewModeController; - -/** - * @brief Represents the view, where each item is shown as an icon. - * - * It is also possible that instead of the icon a preview of the item - * content is shown. - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinIconsView : public KCategorizedView -{ - Q_OBJECT - -public: - /** - * @param parent Parent widget. - * @param dolphinViewController Allows the DolphinIconsView to control the - * DolphinView in a limited way. - * @param viewModeController Controller that is used by the DolphinView - * to control the DolphinIconsView. The DolphinIconsView - * only has read access to the controller. - * @param model Directory that is shown. - */ - explicit DolphinIconsView(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController, - DolphinSortFilterProxyModel* proxyModel); - virtual ~DolphinIconsView(); - -protected slots: - virtual void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); - -protected: - virtual QStyleOptionViewItem viewOptions() const; - virtual void contextMenuEvent(QContextMenuEvent* event); - virtual void mousePressEvent(QMouseEvent* 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); - virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); - virtual void keyPressEvent(QKeyEvent* event); - virtual void wheelEvent(QWheelEvent* event); - virtual void showEvent(QShowEvent* event); - virtual void leaveEvent(QEvent* event); - virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); - virtual void resizeEvent(QResizeEvent* event); - -private slots: - void slotShowPreviewChanged(); - void slotAdditionalInfoChanged(); - void setZoomLevel(int level); - void requestActivation(); - void slotGlobalSettingsChanged(int category); - void categoryDrawerActionRequested(int action, const QModelIndex &index); - -private: - /** - * Updates the size of the grid depending on the state - * of \a showPreview and \a additionalInfoCount. - */ - void updateGridSize(bool showPreview, int additionalInfoCount); - - /** - * Returns the number of additional information lines that should - * be shown below the item name. - */ - int additionalInfoCount() const; - -private: - DolphinViewController* m_dolphinViewController; - DolphinCategoryDrawer* m_categoryDrawer; - ViewExtensionsFactory* m_extensionsFactory; - - QFont m_font; - QSize m_decorationSize; - QStyleOptionViewItem::Position m_decorationPosition; - Qt::Alignment m_displayAlignment; - - QSize m_itemSize; - QRect m_dropRect; -}; - -#endif diff --git a/src/views/dolphinitemlistcontainer.cpp b/src/views/dolphinitemlistcontainer.cpp new file mode 100644 index 000000000..9c9ad6de3 --- /dev/null +++ b/src/views/dolphinitemlistcontainer.cpp @@ -0,0 +1,279 @@ +/*************************************************************************** + * Copyright (C) 2011 by Peter Penz <[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 "dolphinitemlistcontainer.h" + +#include "dolphin_iconsmodesettings.h" +#include "dolphin_detailsmodesettings.h" +#include "dolphin_compactmodesettings.h" + +#include <kitemviews/kitemliststyleoption.h> +#include <kitemviews/kfileitemlistview.h> +#include <kitemviews/kfileitemmodel.h> +#include <kitemviews/kitemlistcontroller.h> +#include <kitemviews/kitemliststyleoption.h> + +#include <KDirLister> +#include <KGlobalSettings> + +#include <views/viewmodecontroller.h> + +#include "zoomlevelinfo.h" + + +DolphinItemListContainer::DolphinItemListContainer(KDirLister* dirLister, + QWidget* parent) : + KItemListContainer(parent), + m_zoomLevel(0), + m_fileItemListView(0) +{ + controller()->setModel(new KFileItemModel(dirLister, this)); + + m_fileItemListView = new KFileItemListView(); + controller()->setView(m_fileItemListView); + + KItemListStyleOption option; + + // TODO: + option.font = parent->font(); + option.fontMetrics = QFontMetrics(parent->font()); + + updateGridSize(); +/* + connect(this, SIGNAL(clicked(const QModelIndex&)), + dolphinViewController, SLOT(requestTab(const QModelIndex&)));*/ +/* + connect(this, SIGNAL(entered(const QModelIndex&)), + dolphinViewController, SLOT(emitItemEntered(const QModelIndex&))); + connect(this, SIGNAL(viewportEntered()), + dolphinViewController, SLOT(emitViewportEntered()));*/ + + // apply the icons mode settings to the widget + //const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + //Q_ASSERT(settings); + + /*if (settings->useSystemFont()) { + m_font = KGlobalSettings::generalFont(); + } else { + m_font = QFont(settings->fontFamily(), + qRound(settings->fontSize()), + settings->fontWeight(), + settings->italicFont()); + m_font.setPointSizeF(settings->fontSize()); + } + + setWordWrap(settings->numberOfTextlines() > 1); + + if (settings->arrangement() == QListView::TopToBottom) { + setFlow(QListView::LeftToRight); + m_decorationPosition = QStyleOptionViewItem::Top; + m_displayAlignment = Qt::AlignHCenter; + } else { + setFlow(QListView::TopToBottom); + m_decorationPosition = QStyleOptionViewItem::Left; + m_displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; + } + + connect(m_categoryDrawer, SIGNAL(actionRequested(int,QModelIndex)), this, SLOT(categoryDrawerActionRequested(int,QModelIndex))); + setCategoryDrawer(m_categoryDrawer); + + connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), + this, SLOT(slotGlobalSettingsChanged(int)));*/ + + //updateGridSize(dolphinView->showPreview(), 0); + /*m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController);*/ +} + +DolphinItemListContainer::~DolphinItemListContainer() +{ + IconsModeSettings::self()->writeConfig(); + CompactModeSettings::self()->writeConfig(); + DetailsModeSettings::self()->writeConfig(); + + KItemListView* view = controller()->view(); + controller()->setView(0); + delete view; +} + +void DolphinItemListContainer::setPreviewsShown(bool show) +{ + beginTransaction(); + m_fileItemListView->setPreviewsShown(show); + updateGridSize(); + endTransaction(); +} + +bool DolphinItemListContainer::previewsShown() const +{ + return m_fileItemListView->previewsShown(); +} + +void DolphinItemListContainer::setVisibleRoles(const QHash<QByteArray, int>& roles) +{ + m_fileItemListView->setVisibleRoles(roles); + updateGridSize(); +} + +QHash<QByteArray, int> DolphinItemListContainer::visibleRoles() const +{ + return m_fileItemListView->visibleRoles(); +} + +void DolphinItemListContainer::setZoomLevel(int level) +{ + if (level < ZoomLevelInfo::minimumLevel()) { + level = ZoomLevelInfo::minimumLevel(); + } else if (level > ZoomLevelInfo::maximumLevel()) { + level = ZoomLevelInfo::maximumLevel(); + } + + if (level == m_zoomLevel) { + return; + } + + m_zoomLevel = level; + + if (previewsShown()) { + const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(level); + + switch (itemLayout()) { + case KFileItemListView::IconsLayout: IconsModeSettings::setPreviewSize(previewSize); break; + case KFileItemListView::CompactLayout: CompactModeSettings::setPreviewSize(previewSize); break; + case KFileItemListView::DetailsLayout: DetailsModeSettings::setPreviewSize(previewSize); break; + default: Q_ASSERT(false); break; + } + } else { + const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(level); + switch (itemLayout()) { + case KFileItemListView::IconsLayout: IconsModeSettings::setIconSize(iconSize); break; + case KFileItemListView::CompactLayout: CompactModeSettings::setIconSize(iconSize); break; + case KFileItemListView::DetailsLayout: DetailsModeSettings::setIconSize(iconSize); break; + default: Q_ASSERT(false); break; + } + } + + updateGridSize(); +} + +int DolphinItemListContainer::zoomLevel() const +{ + return m_zoomLevel; +} + +void DolphinItemListContainer::setItemLayout(KFileItemListView::Layout layout) +{ + if (layout == itemLayout()) { + return; + } + + beginTransaction(); + m_fileItemListView->setItemLayout(layout); + + switch (layout) { + case KFileItemListView::IconsLayout: + case KFileItemListView::DetailsLayout: + m_fileItemListView->setScrollOrientation(Qt::Vertical); + break; + case KFileItemListView::CompactLayout: + m_fileItemListView->setScrollOrientation(Qt::Horizontal); + break; + default: + Q_ASSERT(false); + break; + } + + updateGridSize(); + endTransaction(); +} + +KFileItemListView::Layout DolphinItemListContainer::itemLayout() const +{ + return m_fileItemListView->itemLayout(); +} + +void DolphinItemListContainer::beginTransaction() +{ + m_fileItemListView->beginTransaction(); +} + +void DolphinItemListContainer::endTransaction() +{ + m_fileItemListView->endTransaction(); +} + +void DolphinItemListContainer::updateGridSize() +{ + // Calculate the size of the icon + int iconSize; + if (previewsShown()) { + switch (itemLayout()) { + case KFileItemListView::IconsLayout: iconSize = IconsModeSettings::previewSize(); break; + case KFileItemListView::CompactLayout: iconSize = CompactModeSettings::previewSize(); break; + case KFileItemListView::DetailsLayout: iconSize = DetailsModeSettings::previewSize(); break; + default: Q_ASSERT(false); break; + } + } else { + switch (itemLayout()) { + case KFileItemListView::IconsLayout: iconSize = IconsModeSettings::iconSize(); break; + case KFileItemListView::CompactLayout: iconSize = CompactModeSettings::iconSize(); break; + case KFileItemListView::DetailsLayout: iconSize = DetailsModeSettings::iconSize(); break; + default: Q_ASSERT(false); break; + } + } + + m_zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(QSize(iconSize, iconSize)); + KItemListStyleOption styleOption = m_fileItemListView->styleOption(); + + const int innerMargin = (iconSize >= KIconLoader::SizeSmallMedium) ? 4 : 2; + + // Calculate the item-width and item-height + int itemWidth; + int itemHeight; + switch (itemLayout()) { + case KFileItemListView::IconsLayout: { + const int minItemWidth = 64; + itemWidth = minItemWidth + IconsModeSettings::textWidthIndex() * 64; // TODO: + if (itemWidth < iconSize + innerMargin * 2) { + itemWidth = iconSize + innerMargin * 2; + } + itemHeight = innerMargin * 2 + iconSize + styleOption.fontMetrics.height(); + break; + } + case KFileItemListView::CompactLayout: { + itemWidth = innerMargin * 2; + const int textLinesCount = m_fileItemListView->visibleRoles().count(); + itemHeight = innerMargin * 2 + qMax(iconSize, textLinesCount * styleOption.fontMetrics.height()); + break; + } + case KFileItemListView::DetailsLayout: { + itemWidth = -1; + itemHeight = innerMargin * 2 + qMax(iconSize, styleOption.fontMetrics.height()); + break; + } + default: Q_ASSERT(false); break; + } + + // Apply the calculated values + styleOption.margin = innerMargin; + styleOption.iconSize = iconSize; + m_fileItemListView->setStyleOption(styleOption); + m_fileItemListView->setItemSize(QSizeF(itemWidth, itemHeight)); +} + +#include "dolphinitemlistcontainer.moc" diff --git a/src/views/dolphinitemlistcontainer.h b/src/views/dolphinitemlistcontainer.h new file mode 100644 index 000000000..599a4bd74 --- /dev/null +++ b/src/views/dolphinitemlistcontainer.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2011 by Peter Penz <[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 * + ***************************************************************************/ + +#ifndef DOLPHINITEMLISTCONTAINER_H +#define DOLPHINITEMLISTCONTAINER_H + +#include <kitemviews/kfileitemlistview.h> +#include <kitemviews/kitemlistcontainer.h> + +#include <libdolphin_export.h> + +class KDirLister; +class KFileItemListView; + +/** + * @brief Extends KItemListContainer by Dolphin specific properties. + * + * The view and model for KFileItems are created automatically when + * instantating KItemListContainer. + * + * The Dolphin settings of the icons-, compact- and details-view are + * converted internally to properties that can be used to configure e.g. + * the item-size and visible roles of the KItemListView. + */ +class LIBDOLPHINPRIVATE_EXPORT DolphinItemListContainer : public KItemListContainer +{ + Q_OBJECT + +public: + DolphinItemListContainer(KDirLister* dirLister, + QWidget* parent = 0); + + virtual ~DolphinItemListContainer(); + + void setPreviewsShown(bool show); + bool previewsShown() const; + + /** + * Sets the visible roles to \p roles. The integer-value defines + * the order of the visible role: Smaller values are ordered first. + */ + void setVisibleRoles(const QHash<QByteArray, int>& roles); + QHash<QByteArray, int> visibleRoles() const; + + void setZoomLevel(int level); + int zoomLevel() const; + + void setItemLayout(KFileItemListView::Layout layout); + KFileItemListView::Layout itemLayout() const; + + void beginTransaction(); + void endTransaction(); + +private: + void updateGridSize(); + +private: + int m_zoomLevel; + KFileItemListView* m_fileItemListView; +}; + +#endif diff --git a/src/views/dolphinmodel.cpp b/src/views/dolphinmodel.cpp deleted file mode 100644 index c999dfacd..000000000 --- a/src/views/dolphinmodel.cpp +++ /dev/null @@ -1,448 +0,0 @@ -/** - * This file is part of the KDE project - * Copyright (C) 2007 Rafael Fernández López <[email protected]> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "dolphinmodel.h" - -#include "dolphinsortfilterproxymodel.h" - -#include <KCategorizedView> -#include <KDateTime> -#include <KDirModel> -#include <KFileItem> -#include <KIconLoader> -#include <KLocale> -#include <KUrl> -#include <KUser> -#include <KMimeType> -#include <KStandardDirs> - -#include <QList> -#include <QSortFilterProxyModel> -#include <QPainter> -#include <QPersistentModelIndex> -#include <QDir> -#include <QFileInfo> - -const char* const DolphinModel::m_others = I18N_NOOP2("@title:group Name", "Others"); - -DolphinModel::DolphinModel(QObject* parent) : - KDirModel(parent), - m_hasVersionData(false), - m_revisionHash() -{ - setJobTransfersVisible(true); -} - -DolphinModel::~DolphinModel() -{ -} - -bool DolphinModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if ((index.column() == DolphinModel::Version) && (role == Qt::DecorationRole)) { - // TODO: remove data again when items are deleted... - - const QPersistentModelIndex key = index; - const KVersionControlPlugin::VersionState state = static_cast<KVersionControlPlugin::VersionState>(value.toInt()); - if (m_revisionHash.value(key, KVersionControlPlugin::UnversionedVersion) != state) { - if (!m_hasVersionData) { - connect(this, SIGNAL(rowsRemoved (const QModelIndex&, int, int)), - this, SLOT(slotRowsRemoved(const QModelIndex&, int, int))); - m_hasVersionData = true; - } - - m_revisionHash.insert(key, state); - emit dataChanged(index, index); - return true; - } - } - - return KDirModel::setData(index, value, role); -} - -QVariant DolphinModel::data(const QModelIndex& index, int role) const -{ - switch (role) { - case KCategorizedSortFilterProxyModel::CategoryDisplayRole: - return displayRoleData(index); - - case KCategorizedSortFilterProxyModel::CategorySortRole: - return sortRoleData(index); - - case Qt::DecorationRole: - if (index.column() == DolphinModel::Version) { - return m_revisionHash.value(index, KVersionControlPlugin::UnversionedVersion); - } - break; - - case Qt::DisplayRole: - switch (index.column()) { - case DolphinModel::LinkDest: { - const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model()); - const KFileItem item = dirModel->itemForIndex(index); - return item.linkDest(); - } - - case DolphinModel::LocalPathOrUrl: - const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model()); - const KFileItem item = dirModel->itemForIndex(index); - const KUrl url = item.mostLocalUrl(); - if (url.protocol() == QLatin1String("trash")) { - const KIO::UDSEntry udsEntry = item.entry(); - return udsEntry.stringValue(KIO::UDSEntry::UDS_EXTRA); - } - return url.directory(); - } - break; - - default: - break; - } - - return KDirModel::data(index, role); -} - -QVariant DolphinModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) { - switch (section) { - case DolphinModel::LinkDest: - return i18nc("@title::column", "Link Destination"); - case DolphinModel::LocalPathOrUrl: - return i18nc("@title::column", "Path"); - default: - return KDirModel::headerData(section, orientation, role); - } - } - return QVariant(); -} - -int DolphinModel::columnCount(const QModelIndex& parent) const -{ - return KDirModel::columnCount(parent) + (ExtraColumnCount - ColumnCount); -} - -void DolphinModel::clearVersionData() -{ - m_revisionHash.clear(); - m_hasVersionData = false; -} - -bool DolphinModel::hasVersionData() const -{ - return m_hasVersionData; -} - -void DolphinModel::slotRowsRemoved(const QModelIndex& parent, int start, int end) -{ - if (m_hasVersionData) { - const int column = parent.column(); - for (int row = start; row <= end; ++row) { - m_revisionHash.remove(parent.child(row, column)); - } - } -} - -QVariant DolphinModel::displayRoleData(const QModelIndex& index) const -{ - QString retString; - - if (!index.isValid()) { - return retString; - } - - const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model()); - KFileItem item = dirModel->itemForIndex(index); - - switch (index.column()) { - case KDirModel::Name: { - // KDirModel checks columns to know to which role are - // we talking about - const QModelIndex nameIndex = index.model()->index(index.row(), KDirModel::Name, index.parent()); - if (!nameIndex.isValid()) { - return retString; - } - const QVariant data = nameIndex.model()->data(nameIndex, Qt::DisplayRole); - const QString name = data.toString(); - if (!name.isEmpty()) { - if (!item.isHidden() && name.at(0).isLetter()) - retString = name.at(0).toUpper(); - else if (item.isHidden()) { - if (name.at(0) == '.') { - if (name.size() > 1 && name.at(1).isLetter()) { - retString = name.at(1).toUpper(); - } else { - retString = i18nc("@title:group Name", m_others); - } - } else { - retString = name.at(0).toUpper(); - } - } else { - bool validCategory = false; - - const QString str(name.toUpper()); - const QChar* currA = str.unicode(); - while (!currA->isNull() && !validCategory) { - if (currA->isLetter()) { - validCategory = true; - } else if (currA->isDigit()) { - return i18nc("@title:group Name", m_others); - } else { - ++currA; - } - } - - retString = validCategory ? *currA : i18nc("@title:group Name", m_others); - } - } - break; - } - - case KDirModel::Size: { - const KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U; - if (!item.isNull() && item.isDir()) { - retString = i18nc("@title:group Size", "Folders"); - } else if (fileSize < 5242880) { - retString = i18nc("@title:group Size", "Small"); - } else if (fileSize < 10485760) { - retString = i18nc("@title:group Size", "Medium"); - } else { - retString = i18nc("@title:group Size", "Big"); - } - break; - } - - case KDirModel::ModifiedTime: { - KDateTime modifiedTime = item.time(KFileItem::ModificationTime); - modifiedTime = modifiedTime.toLocalZone(); - - const QDate currentDate = KDateTime::currentLocalDateTime().date(); - const QDate modifiedDate = modifiedTime.date(); - - const int daysDistance = modifiedDate.daysTo(currentDate); - - int yearForCurrentWeek = 0; - int currentWeek = currentDate.weekNumber(&yearForCurrentWeek); - if (yearForCurrentWeek == currentDate.year() + 1) { - currentWeek = 53; - } - - int yearForModifiedWeek = 0; - int modifiedWeek = modifiedDate.weekNumber(&yearForModifiedWeek); - if (yearForModifiedWeek == modifiedDate.year() + 1) { - modifiedWeek = 53; - } - - if (currentDate.year() == modifiedDate.year() && currentDate.month() == modifiedDate.month()) { - if (modifiedWeek > currentWeek) { - // use case: modified date = 2010-01-01, current date = 2010-01-22 - // modified week = 53, current week = 3 - modifiedWeek = 0; - } - switch (currentWeek - modifiedWeek) { - case 0: - switch (daysDistance) { - case 0: retString = i18nc("@title:group Date", "Today"); break; - case 1: retString = i18nc("@title:group Date", "Yesterday"); break; - default: retString = modifiedTime.toString(i18nc("@title:group The week day name: %A", "%A")); - } - break; - case 1: - retString = i18nc("@title:group Date", "Last Week"); - break; - case 2: - retString = i18nc("@title:group Date", "Two Weeks Ago"); - break; - case 3: - retString = i18nc("@title:group Date", "Three Weeks Ago"); - break; - case 4: - case 5: - retString = i18nc("@title:group Date", "Earlier this Month"); - break; - default: - Q_ASSERT(false); - } - } else { - const QDate lastMonthDate = currentDate.addMonths(-1); - if (lastMonthDate.year() == modifiedDate.year() && lastMonthDate.month() == modifiedDate.month()) { - if (daysDistance == 1) { - retString = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Yesterday (%B, %Y)")); - } else if (daysDistance <= 7) { - retString = modifiedTime.toString(i18nc("@title:group The week day name: %A, %B is full month name in current locale, and %Y is full year number", "%A (%B, %Y)")); - } else if (daysDistance <= 7 * 2) { - retString = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Last Week (%B, %Y)")); - } else if (daysDistance <= 7 * 3) { - retString = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Two Weeks Ago (%B, %Y)")); - } else if (daysDistance <= 7 * 4) { - retString = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Three Weeks Ago (%B, %Y)")); - } else { - retString = modifiedTime.toString(i18nc("@title:group Date: %B is full month name in current locale, and %Y is full year number", "Earlier on %B, %Y")); - } - } else { - retString = modifiedTime.toString(i18nc("@title:group The month and year: %B is full month name in current locale, and %Y is full year number", "%B, %Y")); - } - } - break; - } - - case KDirModel::Permissions: { - QString user; - QString group; - QString others; - - QFileInfo info(item.url().pathOrUrl()); - - // set user string - if (info.permission(QFile::ReadUser)) { - user = i18nc("@item:intext Access permission, concatenated", "Read, "); - } - if (info.permission(QFile::WriteUser)) { - user += i18nc("@item:intext Access permission, concatenated", "Write, "); - } - if (info.permission(QFile::ExeUser)) { - user += i18nc("@item:intext Access permission, concatenated", "Execute, "); - } - user = user.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : user.mid(0, user.count() - 2); - - // set group string - if (info.permission(QFile::ReadGroup)) { - group = i18nc("@item:intext Access permission, concatenated", "Read, "); - } - if (info.permission(QFile::WriteGroup)) { - group += i18nc("@item:intext Access permission, concatenated", "Write, "); - } - if (info.permission(QFile::ExeGroup)) { - group += i18nc("@item:intext Access permission, concatenated", "Execute, "); - } - group = group.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : group.mid(0, group.count() - 2); - - // set permission string - if (info.permission(QFile::ReadOther)) { - others = i18nc("@item:intext Access permission, concatenated", "Read, "); - } - if (info.permission(QFile::WriteOther)) { - others += i18nc("@item:intext Access permission, concatenated", "Write, "); - } - if (info.permission(QFile::ExeOther)) { - others += i18nc("@item:intext Access permission, concatenated", "Execute, "); - } - others = others.isEmpty() ? i18nc("@item:intext Access permission, concatenated", "Forbidden") : others.mid(0, others.count() - 2); - - retString = i18nc("@title:group Files and folders by permissions", "(User: %1) (Group: %2) (Others: %3)", user, group, others); - break; - } - - case KDirModel::Owner: - retString = item.user(); - break; - - case KDirModel::Group: - retString = item.group(); - break; - - case KDirModel::Type: - retString = item.mimeComment(); - break; - - case DolphinModel::Version: - retString = "test"; - break; - } - - return retString; -} - -QVariant DolphinModel::sortRoleData(const QModelIndex& index) const -{ - QVariant retVariant; - - if (!index.isValid()) { - return retVariant; - } - - const KDirModel *dirModel = qobject_cast<const KDirModel*>(index.model()); - KFileItem item = dirModel->itemForIndex(index); - - switch (index.column()) { - case KDirModel::Name: { - retVariant = data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole); - if (retVariant == i18nc("@title:group Name", m_others)) { - // assure that the "Others" group is always the last categorization - retVariant = QString('Z').append(QChar::ReplacementCharacter); - } - break; - } - - case KDirModel::Size: { - const KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U; - if (item.isDir()) { - retVariant = 0; - } else if (fileSize < 5242880) { - retVariant = 1; - } else if (fileSize < 10485760) { - retVariant = 2; - } else { - retVariant = 3; - } - break; - } - - case KDirModel::ModifiedTime: { - KDateTime modifiedTime = item.time(KFileItem::ModificationTime); - modifiedTime = modifiedTime.toLocalZone(); - - const QDate currentDate = KDateTime::currentLocalDateTime().date(); - const QDate modifiedDate = modifiedTime.date(); - - retVariant = -modifiedDate.daysTo(currentDate); - break; - } - - case KDirModel::Permissions: { - QFileInfo info(item.url().pathOrUrl()); - - retVariant = -KDirSortFilterProxyModel::pointsForPermissions(info); - break; - } - - case KDirModel::Owner: - retVariant = item.user(); - break; - - case KDirModel::Group: - retVariant = item.group(); - break; - - case KDirModel::Type: - if (item.isDir()) { - // when sorting we want folders to be placed first - retVariant = QString(); // krazy:exclude=nullstrassign - } else { - retVariant = item.mimeComment(); - } - break; - - default: - break; - } - - return retVariant; -} diff --git a/src/views/dolphinmodel.h b/src/views/dolphinmodel.h deleted file mode 100644 index 2f6d1f02d..000000000 --- a/src/views/dolphinmodel.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of the KDE project - * Copyright (C) 2007 Rafael Fernández López <[email protected]> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#ifndef DOLPHINMODEL_H -#define DOLPHINMODEL_H - -#include <KDirModel> -#include <kversioncontrolplugin.h> -#include <libdolphin_export.h> - -#include <QHash> -#include <QPersistentModelIndex> - -class LIBDOLPHINPRIVATE_EXPORT DolphinModel : public KDirModel -{ - Q_OBJECT - -public: - enum AdditionalColumns { - LinkDest = KDirModel::ColumnCount, - LocalPathOrUrl, - // Assure that invisible columns are added as last entries: - Version, - ExtraColumnCount // Mandatory last entry - }; - - DolphinModel(QObject* parent = 0); - virtual ~DolphinModel(); - - virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; - - void clearVersionData(); - bool hasVersionData() const; - -private slots: - void slotRowsRemoved(const QModelIndex& parent, int start, int end); - -private: - QVariant displayRoleData(const QModelIndex& index) const; - QVariant sortRoleData(const QModelIndex& index) const; - -private: - bool m_hasVersionData; - QHash<QPersistentModelIndex, KVersionControlPlugin::VersionState> m_revisionHash; - - static const char* const m_others; -}; - -#endif // DOLPHINMODEL_H diff --git a/src/views/dolphinsortfilterproxymodel.cpp b/src/views/dolphinsortfilterproxymodel.cpp deleted file mode 100644 index a2d513ba4..000000000 --- a/src/views/dolphinsortfilterproxymodel.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2010 by Peter Penz <[email protected]> * - * Copyright (C) 2006 by Dominic Battre <[email protected]> * - * Copyright (C) 2006 by Martin Pool <[email protected]> * - * Copyright (C) 2007 by Rafael Fernández López <[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 "dolphinsortfilterproxymodel.h" - -DolphinSortFilterProxyModel::DolphinSortFilterProxyModel(QObject* parent) : - KDirSortFilterProxyModel(parent), - m_sorting(DolphinView::SortByName), - m_sortOrder(Qt::AscendingOrder) -{ -} - -DolphinSortFilterProxyModel::~DolphinSortFilterProxyModel() -{ -} - -void DolphinSortFilterProxyModel::setSorting(DolphinView::Sorting sorting) -{ - m_sorting = sorting; - KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), m_sortOrder); -} - -void DolphinSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder) -{ - m_sortOrder = sortOrder; - KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), m_sortOrder); -} - -void DolphinSortFilterProxyModel::setSortFoldersFirst(bool foldersFirst) -{ - if (foldersFirst != sortFoldersFirst()) { - KDirSortFilterProxyModel::setSortFoldersFirst(foldersFirst); - - // We need to make sure that the files and folders are really resorted. - // Without the following two lines, QSortFilterProxyModel::sort(int column, Qt::SortOrder order) - // would do nothing because neither the column nor the sort order have changed. - // TODO: remove this hack if we find a better way to force the ProxyModel to re-sort the data. - const Qt::SortOrder tmpSortOrder = (m_sortOrder == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder); - KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), tmpSortOrder); - - // Now comes the real sorting with the old column and sort order - KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), m_sortOrder); - } -} - -void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder) -{ - m_sorting = sortingForColumn(column); - m_sortOrder = sortOrder; - - emit sortingRoleChanged(); - KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting), sortOrder); -} - -DolphinView::Sorting DolphinSortFilterProxyModel::sortingForColumn(int column) -{ - Q_ASSERT(column >= 0); - Q_ASSERT(column <= DolphinView::MaxSortingEnum); - return static_cast<DolphinView::Sorting>(column); -} - -#include "dolphinsortfilterproxymodel.moc" diff --git a/src/views/dolphinsortfilterproxymodel.h b/src/views/dolphinsortfilterproxymodel.h deleted file mode 100644 index a4770e85e..000000000 --- a/src/views/dolphinsortfilterproxymodel.h +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2010 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINSORTFILTERPROXYMODEL_H -#define DOLPHINSORTFILTERPROXYMODEL_H - -#include <views/dolphinview.h> -#include <kdirsortfilterproxymodel.h> -#include <libdolphin_export.h> - -/** - * @brief Acts as proxy model for DolphinModel to sort and filter - * KFileItems. - * - * Per default a natural sorting is done. This means that items like: - * - item_10.png - * - item_1.png - * - item_2.png - * are sorted like - * - item_1.png - * - item_2.png - * - item_10.png - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinSortFilterProxyModel : public KDirSortFilterProxyModel -{ - Q_OBJECT - -public: - DolphinSortFilterProxyModel(QObject* parent = 0); - virtual ~DolphinSortFilterProxyModel(); - - void setSorting(DolphinView::Sorting sorting); - DolphinView::Sorting sorting() const; - - void setSortOrder(Qt::SortOrder sortOrder); - Qt::SortOrder sortOrder() const; - - void setSortFoldersFirst(bool foldersFirst); - - /** @reimplemented */ - virtual void sort(int column, - Qt::SortOrder order = Qt::AscendingOrder); - - /** - * Helper method to get the DolphinView::Sorting type for a given - * column \a column. If the column is smaller 0 or greater than the - * available columns, DolphinView::SortByName is returned. - */ - static DolphinView::Sorting sortingForColumn(int column); - -signals: - void sortingRoleChanged(); - -private: - DolphinView::Sorting m_sorting:16; - Qt::SortOrder m_sortOrder:16; -}; - -inline DolphinView::Sorting DolphinSortFilterProxyModel::sorting() const -{ - return m_sorting; -} - -inline Qt::SortOrder DolphinSortFilterProxyModel::sortOrder() const -{ - return m_sortOrder; -} - -#endif diff --git a/src/views/dolphintreeview.cpp b/src/views/dolphintreeview.cpp deleted file mode 100644 index 64b66aa84..000000000 --- a/src/views/dolphintreeview.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz <[email protected]> * - * Copyright (C) 2008 by Simon St. James <[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 "dolphintreeview.h" - -#include "dolphinmodel.h" - -#include <QApplication> -#include <QEvent> -#include <QHeaderView> -#include <QMouseEvent> -#include <QPainter> -#include <QScrollBar> - -DolphinTreeView::DolphinTreeView(QWidget* parent) : - QTreeView(parent), - m_expandingTogglePressed(false), - m_useDefaultIndexAt(true), - m_ignoreScrollTo(false), - m_dropRect(), - m_band() -{ - setUniformRowHeights(true); -} - -DolphinTreeView::~DolphinTreeView() -{ -} - -void DolphinTreeView::keyboardSearch(const QString & search) -{ - const QModelIndex oldCurrent = currentIndex(); - QTreeView::keyboardSearch(search); - if (currentIndex() != oldCurrent) { - // The current index has changed, but it is not selected yet. - // To select it, we call setCurrentIndex(...). - setCurrentIndex(currentIndex()); - } -} - -QRegion DolphinTreeView::visualRegionForSelection(const QItemSelection& selection) const -{ - // We have to make sure that the visualRect of each model index is inside the region. - // QTreeView::visualRegionForSelection does not do it right because it assumes implicitly - // that all visualRects have the same width, which is in general not the case here. - QRegion selectionRegion; - const QModelIndexList indexes = selection.indexes(); - - foreach(const QModelIndex& index, indexes) { - selectionRegion += visualRect(index); - } - - return selectionRegion; -} - -bool DolphinTreeView::acceptsDrop(const QModelIndex& index) const -{ - Q_UNUSED(index); - return false; -} - -bool DolphinTreeView::event(QEvent* event) -{ - switch (event->type()) { - case QEvent::Polish: - m_useDefaultIndexAt = false; - break; - default: - break; - } - return QTreeView::event(event); -} - -void DolphinTreeView::mousePressEvent(QMouseEvent* event) -{ - const QModelIndex current = currentIndex(); - QTreeView::mousePressEvent(event); - - m_expandingTogglePressed = isAboveExpandingToggle(event->pos()); - - const QModelIndex index = indexAt(event->pos()); - const bool updateState = index.isValid() && - (index.column() == DolphinModel::Name) && - (event->button() == Qt::LeftButton); - if (updateState) { - setState(QAbstractItemView::DraggingState); - } - - if (!index.isValid() || (index.column() != DolphinModel::Name)) { - const Qt::KeyboardModifiers mod = QApplication::keyboardModifiers(); - if (!m_expandingTogglePressed && !(mod & Qt::ShiftModifier) && !(mod & Qt::ControlModifier)) { - clearSelection(); - } - - // Restore the current index, other columns are handled as viewport area. - // setCurrentIndex(...) implicitly calls scrollTo(...), which we want to ignore. - m_ignoreScrollTo = true; - selectionModel()->setCurrentIndex(current, QItemSelectionModel::Current); - m_ignoreScrollTo = false; - - if ((event->button() == Qt::LeftButton) && !m_expandingTogglePressed) { - // Inform Qt about what we are doing - otherwise it starts dragging items around! - setState(DragSelectingState); - m_band.show = true; - // Incremental update data will not be useful - start from scratch. - m_band.ignoreOldInfo = true; - const QPoint scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value()); - m_band.origin = event->pos() + scrollPos; - m_band.destination = m_band.origin; - m_band.originalSelection = selectionModel()->selection(); - } - } -} - -void DolphinTreeView::mouseMoveEvent(QMouseEvent* event) -{ - if (m_expandingTogglePressed) { - // Per default QTreeView starts either a selection or a drag operation when dragging - // the expanding toggle button (Qt-issue - see TODO comment in DolphinIconsView::mousePressEvent()). - // Turn off this behavior in Dolphin to stay predictable: - setState(QAbstractItemView::NoState); - return; - } - - if (m_band.show) { - const QPoint mousePos = event->pos(); - const QModelIndex index = indexAt(mousePos); - if (!index.isValid()) { - // The destination of the selection rectangle is above the viewport. In this - // case QTreeView does no selection at all, which is not the wanted behavior - // in Dolphin. Select all items within the elastic band rectangle. - updateElasticBandSelection(); - } - - // TODO: Enable QTreeView::mouseMoveEvent(event) again, as soon - // as the Qt-issue #199631 has been fixed. - // QTreeView::mouseMoveEvent(event); - QAbstractItemView::mouseMoveEvent(event); - updateElasticBand(); - } else { - // TODO: Enable QTreeView::mouseMoveEvent(event) again, as soon - // as the Qt-issue #199631 has been fixed. - // QTreeView::mouseMoveEvent(event); - QAbstractItemView::mouseMoveEvent(event); - } -} - -void DolphinTreeView::mouseReleaseEvent(QMouseEvent* event) -{ - if (!m_expandingTogglePressed) { - const QModelIndex index = indexAt(event->pos()); - if (index.isValid() && (index.column() == DolphinModel::Name)) { - QTreeView::mouseReleaseEvent(event); - } else { - // don't change the current index if the cursor is released - // above any other column than the name column, as the other - // columns act as viewport - const QModelIndex current = currentIndex(); - QTreeView::mouseReleaseEvent(event); - selectionModel()->setCurrentIndex(current, QItemSelectionModel::Current); - } - } - m_expandingTogglePressed = false; - - if (m_band.show) { - setState(NoState); - updateElasticBand(); - m_band.show = false; - } -} - -void DolphinTreeView::startDrag(Qt::DropActions supportedActions) -{ - Q_UNUSED(supportedActions); - m_band.show = false; -} - -void DolphinTreeView::dragEnterEvent(QDragEnterEvent* event) -{ - Q_UNUSED(event); - if (m_band.show) { - updateElasticBand(); - m_band.show = false; - } -} - -void DolphinTreeView::dragMoveEvent(QDragMoveEvent* event) -{ - QTreeView::dragMoveEvent(event); - - setDirtyRegion(m_dropRect); - - const QModelIndex index = indexAt(event->pos()); - if (acceptsDrop(index)) { - m_dropRect = visualRect(index); - } else { - m_dropRect.setSize(QSize()); // set invalid - } - setDirtyRegion(m_dropRect); -} - -void DolphinTreeView::dragLeaveEvent(QDragLeaveEvent* event) -{ - QTreeView::dragLeaveEvent(event); - setDirtyRegion(m_dropRect); -} - -void DolphinTreeView::paintEvent(QPaintEvent* event) -{ - QTreeView::paintEvent(event); - if (m_band.show) { - // The following code has been taken from QListView - // and adapted to DolphinDetailsView. - // (C) 1992-2007 Trolltech ASA - QStyleOptionRubberBand opt; - opt.initFrom(this); - opt.shape = QRubberBand::Rectangle; - opt.opaque = false; - opt.rect = elasticBandRect(); - - QPainter painter(viewport()); - painter.save(); - style()->drawControl(QStyle::CE_RubberBand, &opt, &painter); - painter.restore(); - } -} - -QModelIndex DolphinTreeView::indexAt(const QPoint& point) const -{ - // The blank portion of the name column counts as empty space - const QModelIndex index = QTreeView::indexAt(point); - const bool isAboveEmptySpace = !m_useDefaultIndexAt && - (index.column() == KDirModel::Name) && - !visualRect(index).contains(point); - return isAboveEmptySpace ? QModelIndex() : index; -} - -void DolphinTreeView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command) -{ - // We must override setSelection() as Qt calls it internally and when this happens - // we must ensure that the default indexAt() is used. - if (!m_band.show) { - m_useDefaultIndexAt = true; - QTreeView::setSelection(rect, command); - m_useDefaultIndexAt = false; - } else { - // Use our own elastic band selection algorithm - updateElasticBandSelection(); - } -} - - -void DolphinTreeView::scrollTo(const QModelIndex & index, ScrollHint hint) -{ - if (!m_ignoreScrollTo) { - QTreeView::scrollTo(index, hint); - } -} - -void DolphinTreeView::updateElasticBandSelection() -{ - if (!m_band.show) { - return; - } - - // Ensure the elastic band itself is up-to-date, in - // case we are being called due to e.g. a drag event. - updateElasticBand(); - - // Clip horizontally to the name column, as some filenames will be - // longer than the column. We don't clip vertically as origin - // may be above or below the current viewport area. - const int nameColumnX = header()->sectionPosition(DolphinModel::Name); - const int nameColumnWidth = header()->sectionSize(DolphinModel::Name); - QRect selRect = elasticBandRect().normalized(); - QRect nameColumnArea(nameColumnX, selRect.y(), nameColumnWidth, selRect.height()); - selRect = nameColumnArea.intersect(selRect).normalized(); - // Get the last elastic band rectangle, expressed in viewpoint coordinates. - const QPoint scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value()); - QRect oldSelRect = QRect(m_band.lastSelectionOrigin - scrollPos, m_band.lastSelectionDestination - scrollPos).normalized(); - - if (selRect.isNull()) { - selectionModel()->select(m_band.originalSelection, QItemSelectionModel::ClearAndSelect); - m_band.ignoreOldInfo = true; - return; - } - - if (!m_band.ignoreOldInfo) { - // Do some quick checks to see if we can rule out the need to - // update the selection. - Q_ASSERT(uniformRowHeights()); - QModelIndex dummyIndex = model()->index(0, 0); - if (!dummyIndex.isValid()) { - // No items in the model presumably. - return; - } - - // If the elastic band does not cover the same rows as before, we'll - // need to re-check, and also invalidate the old item distances. - const int rowHeight = QTreeView::rowHeight(dummyIndex); - const bool coveringSameRows = - (selRect.top() / rowHeight == oldSelRect.top() / rowHeight) && - (selRect.bottom() / rowHeight == oldSelRect.bottom() / rowHeight); - if (coveringSameRows) { - // Covering the same rows, but have we moved far enough horizontally - // that we might have (de)selected some other items? - const bool itemSelectionChanged = - ((selRect.left() > oldSelRect.left()) && - (selRect.left() > m_band.insideNearestLeftEdge)) || - ((selRect.left() < oldSelRect.left()) && - (selRect.left() <= m_band.outsideNearestLeftEdge)) || - ((selRect.right() < oldSelRect.right()) && - (selRect.left() >= m_band.insideNearestRightEdge)) || - ((selRect.right() > oldSelRect.right()) && - (selRect.right() >= m_band.outsideNearestRightEdge)); - - if (!itemSelectionChanged) { - return; - } - } - } else { - // This is the only piece of optimization data that needs to be explicitly - // discarded. - m_band.lastSelectionOrigin = QPoint(); - m_band.lastSelectionDestination = QPoint(); - oldSelRect = selRect; - } - - // Do the selection from scratch. Force a update of the horizontal distances info. - m_band.insideNearestLeftEdge = nameColumnX + nameColumnWidth + 1; - m_band.insideNearestRightEdge = nameColumnX - 1; - m_band.outsideNearestLeftEdge = nameColumnX - 1; - m_band.outsideNearestRightEdge = nameColumnX + nameColumnWidth + 1; - - // Include the old selection rect as well, so we can deselect - // items that were inside it but not in the new selRect. - const QRect boundingRect = selRect.united(oldSelRect).normalized(); - if (boundingRect.isNull()) { - return; - } - - // Get the index of the item in this row in the name column. - // TODO - would this still work if the columns could be re-ordered? - QModelIndex startIndex = QTreeView::indexAt(boundingRect.topLeft()); - if (startIndex.parent().isValid()) { - startIndex = startIndex.parent().child(startIndex.row(), KDirModel::Name); - } else { - startIndex = model()->index(startIndex.row(), KDirModel::Name); - } - if (!startIndex.isValid()) { - selectionModel()->select(m_band.originalSelection, QItemSelectionModel::ClearAndSelect); - m_band.ignoreOldInfo = true; - return; - } - - // Go through all indexes between the top and bottom of boundingRect, and - // update the selection. - const int verticalCutoff = boundingRect.bottom(); - QModelIndex currIndex = startIndex; - QModelIndex lastIndex; - bool allItemsInBoundDone = false; - - // Calling selectionModel()->select(...) for each item that needs to be - // toggled is slow as each call emits selectionChanged(...) so store them - // and do the selection toggle in one batch. - QItemSelection itemsToToggle; - // QItemSelection's deal with continuous ranges of indexes better than - // single indexes, so try to portion items that need to be toggled into ranges. - bool formingToggleIndexRange = false; - QModelIndex toggleIndexRangeBegin = QModelIndex(); - - do { - QRect currIndexRect = visualRect(currIndex); - - // Update some optimization info as we go. - const int cr = currIndexRect.right(); - const int cl = currIndexRect.left(); - const int sl = selRect.left(); - const int sr = selRect.right(); - // "The right edge of the name is outside of the rect but nearer than m_outsideNearestLeft", etc - if ((cr < sl && cr > m_band.outsideNearestLeftEdge)) { - m_band.outsideNearestLeftEdge = cr; - } - if ((cl > sr && cl < m_band.outsideNearestRightEdge)) { - m_band.outsideNearestRightEdge = cl; - } - if ((cl >= sl && cl <= sr && cl > m_band.insideNearestRightEdge)) { - m_band.insideNearestRightEdge = cl; - } - if ((cr >= sl && cr <= sr && cr < m_band.insideNearestLeftEdge)) { - m_band.insideNearestLeftEdge = cr; - } - - bool currentlySelected = selectionModel()->isSelected(currIndex); - bool originallySelected = m_band.originalSelection.contains(currIndex); - bool intersectsSelectedRect = currIndexRect.intersects(selRect); - bool shouldBeSelected = (intersectsSelectedRect && !originallySelected) || (!intersectsSelectedRect && originallySelected); - bool needToToggleItem = (currentlySelected && !shouldBeSelected) || (!currentlySelected && shouldBeSelected); - if (needToToggleItem && !formingToggleIndexRange) { - toggleIndexRangeBegin = currIndex; - formingToggleIndexRange = true; - } - - // NOTE: indexBelow actually walks up and down expanded trees for us. - QModelIndex nextIndex = indexBelow(currIndex); - allItemsInBoundDone = !nextIndex.isValid() || currIndexRect.top() > verticalCutoff; - - const bool commitToggleIndexRange = formingToggleIndexRange && - (!needToToggleItem || - allItemsInBoundDone || - currIndex.parent() != toggleIndexRangeBegin.parent()); - if (commitToggleIndexRange) { - formingToggleIndexRange = false; - // If this is the last item in the bounds and it is also the beginning of a range, - // don't toggle lastIndex - it will already have been dealt with. - if (!allItemsInBoundDone || toggleIndexRangeBegin != currIndex) { - itemsToToggle.select(toggleIndexRangeBegin, lastIndex); - } - // Need to start a new range immediately with currIndex? - if (needToToggleItem) { - toggleIndexRangeBegin = currIndex; - formingToggleIndexRange = true; - } - if (allItemsInBoundDone && needToToggleItem) { - // Toggle the very last item in the bounds. - itemsToToggle.select(currIndex, currIndex); - } - } - - // Next item - lastIndex = currIndex; - currIndex = nextIndex; - } while (!allItemsInBoundDone); - - - selectionModel()->select(itemsToToggle, QItemSelectionModel::Toggle); - - m_band.lastSelectionOrigin = m_band.origin; - m_band.lastSelectionDestination = m_band.destination; - m_band.ignoreOldInfo = false; -} - -void DolphinTreeView::updateElasticBand() -{ - if (m_band.show) { - QRect dirtyRegion(elasticBandRect()); - const QPoint scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value()); - m_band.destination = viewport()->mapFromGlobal(QCursor::pos()) + scrollPos; - // Going above the (logical) top-left of the view causes complications during selection; - // we may as well prevent it. - if (m_band.destination.y() < 0) { - m_band.destination.setY(0); - } - if (m_band.destination.x() < 0) { - m_band.destination.setX(0); - } - dirtyRegion = dirtyRegion.united(elasticBandRect()); - setDirtyRegion(dirtyRegion); - } -} - -QRect DolphinTreeView::elasticBandRect() const -{ - const QPoint scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value()); - - const QPoint topLeft = m_band.origin - scrollPos; - const QPoint bottomRight = m_band.destination - scrollPos; - return QRect(topLeft, bottomRight).normalized(); -} - -bool DolphinTreeView::isAboveExpandingToggle(const QPoint& pos) const -{ - // QTreeView offers no public API to get the information whether an index has an - // expanding toggle and what boundaries the toggle has. The following approach - // also assumes a toggle for file items. - if (itemsExpandable()) { - const QModelIndex index = QTreeView::indexAt(pos); - if (index.isValid() && (index.column() == KDirModel::Name)) { - QRect rect = visualRect(index); - const int toggleSize = rect.height(); - if (isRightToLeft()) { - rect.moveRight(rect.right()); - } else { - rect.moveLeft(rect.x() - toggleSize); - } - rect.setWidth(toggleSize); - - QStyleOption opt; - opt.initFrom(this); - opt.rect = rect; - rect = style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, this); - - return rect.contains(pos); - } - } - return false; -} - -DolphinTreeView::ElasticBand::ElasticBand() : - show(false), - origin(), - destination(), - lastSelectionOrigin(), - lastSelectionDestination(), - ignoreOldInfo(true), - outsideNearestLeftEdge(0), - outsideNearestRightEdge(0), - insideNearestLeftEdge(0), - insideNearestRightEdge(0) -{ -} - -#include "dolphintreeview.moc" diff --git a/src/views/dolphintreeview.h b/src/views/dolphintreeview.h deleted file mode 100644 index c037d412a..000000000 --- a/src/views/dolphintreeview.h +++ /dev/null @@ -1,134 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz <[email protected]> * - * Copyright (C) 2008 by Simon St. James <[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 * - ***************************************************************************/ - -#ifndef DOLPHINTREEVIEW_H -#define DOLPHINTREEVIEW_H - -#include <QTreeView> -#include <libdolphin_export.h> - -/** - * @brief Extends QTreeView by a custom selection- and hover-mechanism. - * - * QTreeView does not respect the width of a cell for the hover-feedback - * and when selecting items. DolphinTreeView improves this by respecting the - * content-width of the first column. The selection-mechanism also - * respects the content-width. - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinTreeView : public QTreeView -{ - Q_OBJECT - -public: - explicit DolphinTreeView(QWidget* parent = 0); - virtual ~DolphinTreeView(); - - virtual QModelIndex indexAt (const QPoint& point) const; - virtual void keyboardSearch(const QString & search); - virtual QRegion visualRegionForSelection(const QItemSelection& selection) const; - -protected: - /** - * @return True, if the item with the index \p index accepts a drop. In this - * case a visual feedback for the user is given during dragging. Per - * default false is returned. - */ - virtual bool acceptsDrop(const QModelIndex& index) const; - - virtual bool event(QEvent* event); - virtual void mousePressEvent(QMouseEvent* event); - virtual void mouseMoveEvent(QMouseEvent* event); - virtual void mouseReleaseEvent(QMouseEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dragLeaveEvent(QDragLeaveEvent* event); - virtual void paintEvent(QPaintEvent* event); - virtual void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command); - virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible); - -private slots: - /** - * If the elastic band is currently shown, update the elastic band based on - * the current mouse position and ensure that the selection is the set of items - * intersecting it. - */ - void updateElasticBandSelection(); - - /** - * Updates the destination \a destination from - * the elastic band to the current mouse position and triggers - * an update. - */ - void updateElasticBand(); - - /** - * Returns the rectangle for the elastic band dependent from the - * origin \a origin, the current destination - * \a destination and the viewport position. - */ - QRect elasticBandRect() const; - -private: - /** - * Returns true, if \a pos is within the expanding toggle of a tree. - */ - bool isAboveExpandingToggle(const QPoint& pos) const; - -private: - bool m_expandingTogglePressed; - bool m_useDefaultIndexAt; // true, if QTreeView::indexAt() should be used - bool m_ignoreScrollTo; // true if calls to scrollTo(...) should do nothing. - - QRect m_dropRect; - - struct ElasticBand - { - ElasticBand(); - - // Elastic band origin and destination coordinates are relative to t - // he origin of the view, not the viewport. - bool show; - QPoint origin; - QPoint destination; - - // Optimization mechanisms for use with elastic band selection. - // Basically, allow "incremental" updates to the selection based - // on the last elastic band shape. - QPoint lastSelectionOrigin; - QPoint lastSelectionDestination; - - // If true, compute the set of selected elements from scratch (slower) - bool ignoreOldInfo; - - // Edges of the filenames that are closest to the edges of oldSelectionRect. - // Used to decide whether horizontal changes in the elastic band are likely - // to require us to re-check which items are selected. - int outsideNearestLeftEdge; - int outsideNearestRightEdge; - int insideNearestLeftEdge; - int insideNearestRightEdge; - // The set of items that were selected at the time this band was shown. - // NOTE: Unless CTRL was pressed when the band was created, this is always empty. - QItemSelection originalSelection; - } m_band; -}; - -#endif diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 681ce74f7..bcc682876 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -36,6 +36,10 @@ #include <KFileItem> #include <KFileItemListProperties> #include <KLocale> +#include <kitemviews/kfileitemmodel.h> +#include <kitemviews/kfileitemlistview.h> +#include <kitemviews/kitemlistview.h> +#include <kitemviews/kitemlistcontroller.h> #include <KIO/DeleteJob> #include <KIO/NetAccess> #include <KIO/PreviewJob> @@ -50,39 +54,36 @@ #include "additionalinfoaccessor.h" #include "dolphindirlister.h" -#include "dolphinmodel.h" -#include "dolphincolumnviewcontainer.h" -#include "dolphinviewcontroller.h" -#include "dolphindetailsview.h" -#include "dolphinfileitemdelegate.h" #include "dolphinnewfilemenuobserver.h" -#include "dolphinsortfilterproxymodel.h" #include "dolphin_detailsmodesettings.h" -#include "dolphiniconsview.h" #include "dolphin_generalsettings.h" -#include "draganddrophelper.h" #include "renamedialog.h" #include "settings/dolphinsettings.h" #include "viewmodecontroller.h" #include "viewproperties.h" #include "zoomlevelinfo.h" -#include "dolphindetailsviewexpander.h" + +// TODO: +#include "dolphinitemlistcontainer.h" + +namespace { + const int MaxModeEnum = DolphinView::CompactView; + const int MaxSortingEnum = DolphinView::SortByPath; +}; DolphinView::DolphinView(const KUrl& url, QWidget* parent) : QWidget(parent), m_active(true), - m_showPreview(false), - m_storedCategorizedSorting(false), m_tabsForFiles(false), - m_isContextMenuOpen(false), m_assureVisibleCurrentIndex(false), m_expanderActive(false), m_isFolderWritable(true), + m_url(url), m_mode(DolphinView::IconsView), + m_additionalInfoList(), m_topLayout(0), - m_dolphinViewController(0), - m_viewModeController(0), - m_viewAccessor(), + m_dirLister(0), + m_container(0), m_selectionChangedTimer(0), m_activeItemUrl(), m_restoredContentsPosition(), @@ -94,12 +95,12 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : m_topLayout->setSpacing(0); m_topLayout->setMargin(0); - m_dolphinViewController = new DolphinViewController(this); + //m_dolphinViewController = new DolphinViewController(this); - m_viewModeController = new ViewModeController(this); - m_viewModeController->setUrl(url); + //m_viewModeController = new ViewModeController(this); + //m_viewModeController->setUrl(url); - connect(m_viewModeController, SIGNAL(urlChanged(const KUrl&)), + /*connect(m_viewModeController, SIGNAL(urlChanged(const KUrl&)), this, SIGNAL(urlChanged(const KUrl&))); connect(m_dolphinViewController, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)), @@ -112,20 +113,20 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : this, SLOT(updateSortOrder(Qt::SortOrder))); connect(m_dolphinViewController, SIGNAL(sortFoldersFirstChanged(bool)), this, SLOT(updateSortFoldersFirst(bool))); - connect(m_dolphinViewController, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), - this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&))); - connect(m_dolphinViewController, SIGNAL(itemTriggered(const KFileItem&)), - this, SLOT(triggerItem(const KFileItem&))); - connect(m_dolphinViewController, SIGNAL(tabRequested(const KUrl&)), - this, SIGNAL(tabRequested(const KUrl&))); - connect(m_dolphinViewController, SIGNAL(activated()), + connect(m_dolphinViewController, SIGNAL(additionalInfoChanged(const QList<DolphinView::AdditionalInfo>&)), + this, SLOT(updateAdditionalInfo(const QList<DolphinView::AdditionalInfo>&)));*/ + //connect(m_dolphinViewController, SIGNAL(itemTriggered(const KFileItem&)), + // this, SLOT(triggerItem(const KFileItem&))); + //connect(m_dolphinViewController, SIGNAL(tabRequested(const KUrl&)), + // this, SIGNAL(tabRequested(const KUrl&))); + /*connect(m_dolphinViewController, SIGNAL(activated()), this, SLOT(activate())); connect(m_dolphinViewController, SIGNAL(itemEntered(const KFileItem&)), this, SLOT(showHoverInformation(const KFileItem&))); connect(m_dolphinViewController, SIGNAL(viewportEntered()), this, SLOT(clearHoverInformation())); connect(m_dolphinViewController, SIGNAL(urlChangeRequested(KUrl)), - this, SLOT(slotUrlChangeRequested(KUrl))); + this, SLOT(slotUrlChangeRequested(KUrl)));*/ // When a new item has been created by the "Create New..." menu, the item should // get selected and it must be assured that the item will get visible. As the @@ -139,8 +140,38 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : connect(m_selectionChangedTimer, SIGNAL(timeout()), this, SLOT(emitSelectionChangedSignal())); + m_dirLister = new DolphinDirLister(this); + m_dirLister->setAutoUpdate(true); + m_dirLister->setDelayedMimeTypes(true); + + connect(m_dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl))); + connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl))); + connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); + connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)), + this, SLOT(slotRefreshItems())); + + connect(m_dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged())); + connect(m_dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged())); + connect(m_dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); + connect(m_dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); + connect(m_dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int))); + connect(m_dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&))); + connect(m_dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged())); + + m_container = new DolphinItemListContainer(m_dirLister, this); + QHash<QByteArray, int> visibleRoles; + visibleRoles.insert("name", 0); + m_container->setVisibleRoles(visibleRoles); + + KItemListController* controller = m_container->controller(); + connect(controller, SIGNAL(itemClicked(int, Qt::MouseButton)), + this, SLOT(slotItemClicked(int, Qt::MouseButton))); + connect(controller, SIGNAL(itemExpansionToggleClicked(int)), this, SLOT(slotItemExpansionToggleClicked(int))); + applyViewProperties(); - m_topLayout->addWidget(m_viewAccessor.layoutTarget()); + m_topLayout->addWidget(m_container); + + loadDirectory(url); } DolphinView::~DolphinView() @@ -149,17 +180,7 @@ DolphinView::~DolphinView() KUrl DolphinView::url() const { - return m_viewModeController->url(); -} - -KUrl DolphinView::rootUrl() const -{ - const KUrl viewUrl = url(); - const KUrl root = m_viewAccessor.rootUrl(); - if (root.isEmpty() || !root.isParentOf(viewUrl)) { - return viewUrl; - } - return root; + return m_url; } void DolphinView::setActive(bool active) @@ -175,21 +196,26 @@ void DolphinView::setActive(bool active) color.setAlpha(150); } - QWidget* viewport = m_viewAccessor.itemView()->viewport(); - QPalette palette; - palette.setColor(viewport->backgroundRole(), color); - viewport->setPalette(palette); + /*QAbstractItemView* view = m_viewAccessor.itemView(); + QWidget* viewport = view ? view->viewport() : 0; + if (viewport) { + QPalette palette; + palette.setColor(viewport->backgroundRole(), color); + viewport->setPalette(palette); + }*/ update(); if (active) { - m_viewAccessor.itemView()->setFocus(); + //if (view) { + // view->setFocus(); + //} emit activated(); emitSelectionChangedSignal(); emit writeStateChanged(m_isFolderWritable); } - m_viewModeController->indicateActivationChange(active); + //m_viewModeController->indicateActivationChange(active); } bool DolphinView::isActive() const @@ -199,49 +225,13 @@ bool DolphinView::isActive() const void DolphinView::setMode(Mode mode) { - if (mode == m_mode) { - return; // the wished mode is already set - } + if (mode != m_mode) { + ViewProperties props(url()); + props.setViewMode(mode); + props.save(); - const int oldZoomLevel = m_viewModeController->zoomLevel(); - m_mode = mode; - - // remember the currently selected items, so that they will - // be restored after reloading the directory - m_selectedItems = selectedItems(); - - const bool hasFocus = m_viewAccessor.itemView()->hasFocus(); - deleteView(); - - const KUrl viewPropsUrl = rootUrl(); - ViewProperties props(viewPropsUrl); - props.setViewMode(m_mode); - createView(); - - if (hasFocus) { - m_viewAccessor.itemView()->setFocus(); - } - - // the file item delegate has been recreated, apply the current - // additional information manually - const KFileItemDelegate::InformationList infoList = props.additionalInfo(); - m_viewAccessor.itemDelegate()->setShowInformation(infoList); - emit additionalInfoChanged(); - - // Not all view modes support categorized sorting. Adjust the sorting model - // if changing the view mode results in a change of the categorized sorting - // capabilities. - m_storedCategorizedSorting = props.categorizedSorting(); - const bool categorized = m_storedCategorizedSorting && supportsCategorizedSorting(); - if (categorized != m_viewAccessor.proxyModel()->isCategorizedModel()) { - m_viewAccessor.proxyModel()->setCategorizedModel(categorized); - emit categorizedSortingChanged(); + applyViewProperties(); } - - emit modeChanged(); - - updateZoomLevel(oldZoomLevel); - loadDirectory(viewPropsUrl); } DolphinView::Mode DolphinView::mode() const @@ -249,46 +239,30 @@ DolphinView::Mode DolphinView::mode() const return m_mode; } -bool DolphinView::showPreview() const +bool DolphinView::previewsShown() const { - return m_showPreview; + return m_container->previewsShown(); } -bool DolphinView::showHiddenFiles() const +bool DolphinView::hiddenFilesShown() const { - return m_viewAccessor.dirLister()->showingDotFiles(); + return m_dirLister->showingDotFiles(); } bool DolphinView::categorizedSorting() const { - // If all view modes would support categorized sorting, returning - // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As - // currently only the icons view supports caterized sorting, we remember - // the stored view properties state in m_storedCategorizedSorting and - // return this state. The application takes care to disable the corresponding - // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate - // that this setting is not applied to the current view mode. - return m_storedCategorizedSorting; -} - -bool DolphinView::supportsCategorizedSorting() const -{ - return m_viewAccessor.supportsCategorizedSorting(); -} - -KFileItem DolphinView::rootItem() const -{ - return m_viewAccessor.dirLister()->rootItem(); + return false; //m_storedCategorizedSorting; } KFileItemList DolphinView::items() const { - return m_viewAccessor.dirLister()->items(); + return m_dirLister->items(); } KFileItemList DolphinView::selectedItems() const { - KFileItemList itemList; + return KFileItemList(); +/* KFileItemList itemList; const QAbstractItemView* view = m_viewAccessor.itemView(); if (!view) { return itemList; @@ -304,17 +278,18 @@ KFileItemList DolphinView::selectedItems() const } } - return itemList; + return itemList;*/ } int DolphinView::selectedItemsCount() const { - const QAbstractItemView* view = m_viewAccessor.itemView(); + return 0; + /*const QAbstractItemView* view = m_viewAccessor.itemView(); if (!view) { return 0; } - return view->selectionModel()->selectedIndexes().count(); + return view->selectionModel()->selectedIndexes().count();*/ } void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls) @@ -327,30 +302,27 @@ void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls) void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled) { - const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern); + Q_UNUSED(pattern); + Q_UNUSED(enabled); + /*const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern); const QItemSelectionModel::SelectionFlags command = enabled ? QItemSelectionModel::Select : QItemSelectionModel::Deselect; - m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command); + m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);*/ } void DolphinView::setZoomLevel(int level) { - if (level < ZoomLevelInfo::minimumLevel()) { - level = ZoomLevelInfo::minimumLevel(); - } else if (level > ZoomLevelInfo::maximumLevel()) { - level = ZoomLevelInfo::maximumLevel(); - } - - if (level != zoomLevel()) { - m_viewModeController->setZoomLevel(level); - emit zoomLevelChanged(level); + const int oldZoomLevel = zoomLevel(); + m_container->setZoomLevel(level); + if (zoomLevel() != oldZoomLevel) { + emit zoomLevelChanged(zoomLevel(), oldZoomLevel); } } int DolphinView::zoomLevel() const { - return m_viewModeController->zoomLevel(); + return m_container->zoomLevel(); } void DolphinView::setSorting(Sorting sorting) @@ -362,7 +334,8 @@ void DolphinView::setSorting(Sorting sorting) DolphinView::Sorting DolphinView::sorting() const { - return m_viewAccessor.proxyModel()->sorting(); + return DolphinView::SortByName; + //return m_viewAccessor.proxyModel()->sorting(); } void DolphinView::setSortOrder(Qt::SortOrder order) @@ -374,7 +347,7 @@ void DolphinView::setSortOrder(Qt::SortOrder order) Qt::SortOrder DolphinView::sortOrder() const { - return m_viewAccessor.proxyModel()->sortOrder(); + return Qt::AscendingOrder; // m_viewAccessor.proxyModel()->sortOrder(); } void DolphinView::setSortFoldersFirst(bool foldersFirst) @@ -386,26 +359,25 @@ void DolphinView::setSortFoldersFirst(bool foldersFirst) bool DolphinView::sortFoldersFirst() const { - return m_viewAccessor.proxyModel()->sortFoldersFirst(); + return true; // m_viewAccessor.proxyModel()->sortFoldersFirst(); } -void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info) +void DolphinView::setAdditionalInfoList(const QList<AdditionalInfo>& info) { - const KUrl viewPropsUrl = rootUrl(); - ViewProperties props(viewPropsUrl); - props.setAdditionalInfo(info); - m_viewAccessor.itemDelegate()->setShowInformation(info); + const QList<AdditionalInfo> previousList = info; - emit additionalInfoChanged(); + ViewProperties props(url()); + props.setAdditionalInfoList(info); - if (m_viewAccessor.reloadOnAdditionalInfoChange()) { - loadDirectory(viewPropsUrl); - } + m_additionalInfoList = info; + applyAdditionalInfoListToView(); + + emit additionalInfoListChanged(m_additionalInfoList, previousList); } -KFileItemDelegate::InformationList DolphinView::additionalInfo() const +QList<DolphinView::AdditionalInfo> DolphinView::additionalInfoList() const { - return m_viewAccessor.itemDelegate()->showInformation(); + return m_additionalInfoList; } void DolphinView::reload() @@ -424,16 +396,15 @@ void DolphinView::reload() void DolphinView::stopLoading() { - m_viewAccessor.dirLister()->stop(); + m_dirLister->stop(); } void DolphinView::refresh() { const bool oldActivationState = m_active; - const int oldZoomLevel = m_viewModeController->zoomLevel(); + const int oldZoomLevel = zoomLevel(); m_active = true; - createView(); applyViewProperties(); reload(); @@ -443,19 +414,20 @@ void DolphinView::refresh() void DolphinView::setNameFilter(const QString& nameFilter) { - m_viewModeController->setNameFilter(nameFilter); + Q_UNUSED(nameFilter); + //m_viewModeController->setNameFilter(nameFilter); } QString DolphinView::nameFilter() const { - return m_viewModeController->nameFilter(); + return QString(); //m_viewModeController->nameFilter(); } void DolphinView::calculateItemCount(int& fileCount, int& folderCount, KIO::filesize_t& totalFileSize) const { - foreach (const KFileItem& item, m_viewAccessor.dirLister()->items()) { + foreach (const KFileItem& item, m_dirLister->items()) { if (item.isDir()) { ++folderCount; } else { @@ -526,34 +498,31 @@ QString DolphinView::statusBarText() const QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const { - return m_dolphinViewController->versionControlActions(items); + Q_UNUSED(items); + return QList<QAction*>(); //m_dolphinViewController->versionControlActions(items); } void DolphinView::setUrl(const KUrl& url) { - if (m_viewModeController->url() == url) { + if (url == m_url) { return; } - const bool hadSelection = hasSelection(); - - // The selection model and directory lister might change in the case of the column view: - disconnectViewAccessor(); + emit urlAboutToBeChanged(url); + const bool hadSelection = hasSelection(); m_newFileNames.clear(); + m_url = url; - m_viewModeController->setUrl(url); // emits urlChanged, which we forward - m_viewAccessor.prepareUrlChange(url); + // It is important to clear the items from the model before + // applying the view properties, otherwise expensive operations + // might be done on the existing items although they get cleared + // anyhow afterwards by loadDirectory(). + fileItemModel()->clear(); applyViewProperties(); - - // When changing the URL there is no need to keep the version - // data of the previous URL. - m_viewAccessor.dirModel()->clearVersionData(); - - // Reconnect to the (probably) new selection model and directory lister - connectViewAccessor(); loadDirectory(url); + emit urlChanged(url); if (hadSelection || hasSelection()) { emitSelectionChangedSignal(); } @@ -561,12 +530,12 @@ void DolphinView::setUrl(const KUrl& url) void DolphinView::selectAll() { - m_viewAccessor.itemView()->selectAll(); + //m_viewAccessor.itemView()->selectAll(); } void DolphinView::invertSelection() { - // Implementation note: Using selectionModel->select(selection, QItemSelectionModel::Toggle) does not +/* // Implementation note: Using selectionModel->select(selection, QItemSelectionModel::Toggle) does not // work, as QItemSelectionModel::hasSelection() provides invalid values in this case. This might be a Qt-issue - // when changing the implementation with an updated Qt-version don't forget to run the Dolphin-unit-tests that // verify this usecase. @@ -583,11 +552,12 @@ void DolphinView::invertSelection() QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel(); selectionModel->select(invertedSelection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current); + */ } void DolphinView::clearSelection() { - m_viewAccessor.itemView()->clearSelection(); + //m_viewAccessor.itemView()->clearSelection(); } void DolphinView::renameSelectedItems() @@ -598,17 +568,17 @@ void DolphinView::renameSelectedItems() return; } - if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) { + /*if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) { const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first()); const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex); m_viewAccessor.itemView()->edit(proxyIndex); - } else { + } else {*/ RenameDialog* dialog = new RenameDialog(this, items); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); dialog->raise(); dialog->activateWindow(); - } + //} // assure that the current index remains visible when KDirLister // will notify the view about changed items @@ -662,40 +632,33 @@ void DolphinView::pasteIntoFolder() } } -void DolphinView::setShowPreview(bool show) +void DolphinView::setPreviewsShown(bool show) { - if (m_showPreview == show) { + if (previewsShown() == show) { return; } - const KUrl viewPropsUrl = rootUrl(); - ViewProperties props(viewPropsUrl); - props.setShowPreview(show); - - m_showPreview = show; - const int oldZoomLevel = m_viewModeController->zoomLevel(); - emit showPreviewChanged(); + ViewProperties props(url()); + props.setPreviewsShown(show); - // Enabling or disabling the preview might change the icon size of the view. - // As the view does not emit a signal when the icon size has been changed, - // the used zoom level of the controller must be adjusted manually: - updateZoomLevel(oldZoomLevel); + m_container->setPreviewsShown(show); + emit previewsShownChanged(show); } -void DolphinView::setShowHiddenFiles(bool show) +void DolphinView::setHiddenFilesShown(bool show) { - if (m_viewAccessor.dirLister()->showingDotFiles() == show) { + if (m_dirLister->showingDotFiles() == show) { return; } m_selectedItems = selectedItems(); - const KUrl viewPropsUrl = rootUrl(); - ViewProperties props(viewPropsUrl); - props.setShowHiddenFiles(show); + ViewProperties props(url()); + props.setHiddenFilesShown(show); - m_viewAccessor.dirLister()->setShowingDotFiles(show); - emit showHiddenFilesChanged(); + m_dirLister->setShowingDotFiles(show); + m_dirLister->emitChanges(); + emit hiddenFilesShownChanged(show); } void DolphinView::setCategorizedSorting(bool categorized) @@ -704,18 +667,13 @@ void DolphinView::setCategorizedSorting(bool categorized) return; } - // setCategorizedSorting(true) may only get invoked - // if the view supports categorized sorting - Q_ASSERT(!categorized || supportsCategorizedSorting()); - - ViewProperties props(rootUrl()); + ViewProperties props(url()); props.setCategorizedSorting(categorized); props.save(); - m_storedCategorizedSorting = categorized; - m_viewAccessor.proxyModel()->setCategorizedModel(categorized); + //m_viewAccessor.proxyModel()->setCategorizedModel(categorized); - emit categorizedSortingChanged(); + emit categorizedSortingChanged(categorized); } void DolphinView::mouseReleaseEvent(QMouseEvent* event) @@ -724,61 +682,16 @@ void DolphinView::mouseReleaseEvent(QMouseEvent* event) setActive(true); } -bool DolphinView::eventFilter(QObject* watched, QEvent* event) +void DolphinView::contextMenuEvent(QContextMenuEvent* event) { - switch (event->type()) { - case QEvent::FocusIn: - if (watched == m_viewAccessor.itemView()) { - m_dolphinViewController->requestActivation(); - } - break; - - case QEvent::DragEnter: - if (watched == m_viewAccessor.itemView()->viewport()) { - setActive(true); - } - break; - - case QEvent::KeyPress: - if (watched == m_viewAccessor.itemView()) { - // clear the selection when Escape has been pressed - QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); - if (keyEvent->key() == Qt::Key_Escape) { - clearSelection(); - } - } - break; - - case QEvent::Wheel: - if (watched == m_viewAccessor.itemView()->viewport()) { - // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed - // (the user is probably trying to scroll during a selection in that case) - QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event); - if (wheelEvent->modifiers() & Qt::ControlModifier && !(wheelEvent->buttons() & Qt::LeftButton)) { - const int delta = wheelEvent->delta(); - const int level = zoomLevel(); - if (delta > 0) { - setZoomLevel(level + 1); - } else if (delta < 0) { - setZoomLevel(level - 1); - } - return true; - } - } - break; + Q_UNUSED(event); - default: - break; - } - - return QWidget::eventFilter(watched, event); -} - -void DolphinView::showEvent(QShowEvent* event) -{ - QWidget::showEvent(event); - if (!event->spontaneous()) { - loadDirectory(url()); + const QPoint pos = m_container->mapFromGlobal(QCursor::pos()); + const KItemListView* view = m_container->controller()->view(); + if (view->itemAt(pos) < 0) { + // Only open the context-menu if the cursor is above the viewport + // (the context-menu for items is handled in slotItemClicked()) + requestContextMenu(KFileItem(), url(), QList<QAction*>()); } } @@ -787,21 +700,27 @@ void DolphinView::activate() setActive(true); } -void DolphinView::triggerItem(const KFileItem& item) +void DolphinView::slotItemClicked(int index, Qt::MouseButton button) { - const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); - if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) { - // items are selected by the user, hence don't trigger the - // item specified by 'index' - return; - } + const KFileItem item = fileItemModel()->fileItem(index); - // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192 - if (item.isNull() || m_isContextMenuOpen) { - return; + if (button & Qt::LeftButton) { + emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart + } else if (button & Qt::MidButton) { + if (item.isDir() || isTabsForFilesEnabled()) { + emit tabRequested(item.url()); + } + } else if (button & Qt::RightButton) { + // TODO: attach customActions for the details-view + emit requestContextMenu(item, url(), QList<QAction*>()); } +} - emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart +void DolphinView::slotItemExpansionToggleClicked(int index) +{ + KFileItemModel* model = fileItemModel(); + const bool expanded = model->isExpanded(index); + model->setExpanded(index, !expanded); } void DolphinView::slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) @@ -826,86 +745,63 @@ void DolphinView::emitSelectionChangedSignal() void DolphinView::openContextMenu(const QPoint& pos, const QList<QAction*>& customActions) { + Q_UNUSED(pos); KFileItem item; - const QModelIndex index = m_viewAccessor.itemView()->indexAt(pos); + /*QAbstractItemView* view = m_viewAccessor.itemView(); + QModelIndex index; + if (view) { + index = view->indexAt(pos); + } + if (index.isValid() && (index.column() == DolphinModel::Name)) { const QModelIndex dolphinModelIndex = m_viewAccessor.proxyModel()->mapToSource(index); item = m_viewAccessor.dirModel()->itemForIndex(dolphinModelIndex); - } + }*/ - m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192 emit requestContextMenu(item, url(), customActions); - m_isContextMenuOpen = false; } void DolphinView::dropUrls(const KFileItem& destItem, const KUrl& destPath, QDropEvent* event) { + Q_UNUSED(destItem); + Q_UNUSED(destPath); addNewFileNames(event->mimeData()); - DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this); + //DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this); } void DolphinView::updateSorting(DolphinView::Sorting sorting) { - ViewProperties props(rootUrl()); + ViewProperties props(url()); props.setSorting(sorting); - m_viewAccessor.proxyModel()->setSorting(sorting); + KItemModelBase* model = m_container->controller()->model(); + model->setSortRole(sortRoleForSorting(sorting)); emit sortingChanged(sorting); } void DolphinView::updateSortOrder(Qt::SortOrder order) { - ViewProperties props(rootUrl()); + ViewProperties props(url()); props.setSortOrder(order); - m_viewAccessor.proxyModel()->setSortOrder(order); + //m_viewAccessor.proxyModel()->setSortOrder(order); emit sortOrderChanged(order); } void DolphinView::updateSortFoldersFirst(bool foldersFirst) { - ViewProperties props(rootUrl()); + ViewProperties props(url()); props.setSortFoldersFirst(foldersFirst); - m_viewAccessor.proxyModel()->setSortFoldersFirst(foldersFirst); + //m_viewAccessor.proxyModel()->setSortFoldersFirst(foldersFirst); emit sortFoldersFirstChanged(foldersFirst); } -void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info) -{ - ViewProperties props(rootUrl()); - props.setAdditionalInfo(info); - props.save(); - - m_viewAccessor.itemDelegate()->setShowInformation(info); - - emit additionalInfoChanged(); -} - -void DolphinView::updateAdditionalInfoActions(KActionCollection* collection) -{ - const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - - const KFileItemDelegate::InformationList checkedInfo = m_viewAccessor.itemDelegate()->showInformation(); - const KFileItemDelegate::InformationList infoKeys = infoAccessor.keys(); - - const bool enable = (m_mode == DolphinView::DetailsView) || - (m_mode == DolphinView::IconsView); - - foreach (const KFileItemDelegate::Information& info, infoKeys) { - const QString name = infoAccessor.actionCollectionName(info, AdditionalInfoAccessor::AdditionalInfoType); - QAction* action = collection->action(name); - Q_ASSERT(action); - action->setEnabled(enable); - action->setChecked(checkedInfo.contains(info)); - } -} - QPair<bool, QString> DolphinView::pasteInfo() const { return KonqOperations::pasteInfo(url()); @@ -923,7 +819,7 @@ bool DolphinView::isTabsForFilesEnabled() const bool DolphinView::itemsExpandable() const { - return m_viewAccessor.itemsExpandable(); + return false; //m_viewAccessor.itemsExpandable(); } void DolphinView::restoreState(QDataStream& stream) @@ -931,81 +827,75 @@ void DolphinView::restoreState(QDataStream& stream) // Restore the URL of the current item that had the keyboard focus stream >> m_activeItemUrl; - // Restore the root URL - KUrl rootUrl; - stream >> rootUrl; - m_viewAccessor.setRootUrl(rootUrl); - // Restore the view position stream >> m_restoredContentsPosition; // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes) QSet<KUrl> urlsToExpand; stream >> urlsToExpand; - const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand); + /*const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand); if (expander) { m_expanderActive = true; connect (expander, SIGNAL(completed()), this, SLOT(slotLoadingCompleted())); } else { m_expanderActive = false; - } + }*/ } void DolphinView::saveState(QDataStream& stream) { // Save the URL of the current item that has the keyboard focus - KFileItem currentItem; - const QAbstractItemView* view = m_viewAccessor.itemView(); - - if (view) { - const QModelIndex proxyIndex = view->currentIndex(); - const QModelIndex dirModelIndex = m_viewAccessor.proxyModel()->mapToSource(proxyIndex); - currentItem = m_viewAccessor.dirModel()->itemForIndex(dirModelIndex); - } KUrl currentItemUrl; - if (!currentItem.isNull()) { - currentItemUrl = currentItem.url(); - } + //if (!currentItem.isNull()) { + // currentItemUrl = currentItem.url(); + //} stream << currentItemUrl; - // Save the root URL - stream << m_viewAccessor.rootUrl(); - // Save view position - const int x = view->horizontalScrollBar()->value(); - const int y = view->verticalScrollBar()->value(); + const qreal x = m_container->horizontalScrollBar()->value(); + const qreal y = m_container->verticalScrollBar()->value(); stream << QPoint(x, y); + kDebug() << "saving view state" << QPoint(x, y); // Save expanded folders (only relevant for the details view - the set will be empty in other view modes) - stream << m_viewAccessor.expandedUrls(); + //stream << m_viewAccessor.expandedUrls(); } bool DolphinView::hasSelection() const { - const QAbstractItemView* view = m_viewAccessor.itemView(); - return view && view->selectionModel()->hasSelection(); + //const QAbstractItemView* view = m_viewAccessor.itemView(); + //return view && view->selectionModel()->hasSelection(); + return false; +} + +KFileItem DolphinView::rootItem() const +{ + return m_dirLister->rootItem(); } void DolphinView::observeCreatedItem(const KUrl& url) { m_createdItemUrl = url; - connect(m_viewAccessor.dirModel(), SIGNAL(rowsInserted(const QModelIndex&, int, int)), - this, SLOT(selectAndScrollToCreatedItem())); + //connect(m_dirModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)), + // this, SLOT(selectAndScrollToCreatedItem())); } void DolphinView::selectAndScrollToCreatedItem() { - const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_createdItemUrl); + /*const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_createdItemUrl); if (dirIndex.isValid()) { const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex); - m_viewAccessor.itemView()->setCurrentIndex(proxyIndex); + QAbstractItemView* view = m_viewAccessor.itemView(); + if (view) { + view->setCurrentIndex(proxyIndex); + } } disconnect(m_viewAccessor.dirModel(), SIGNAL(rowsInserted(const QModelIndex&, int, int)), - this, SLOT(selectAndScrollToCreatedItem())); + this, SLOT(selectAndScrollToCreatedItem()));*/ m_createdItemUrl = KUrl(); } @@ -1013,7 +903,7 @@ void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl) { if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) { emit redirection(oldUrl, newUrl); - m_viewModeController->redirectToUrl(newUrl); // #186947 + m_url = newUrl; // #186947 } } @@ -1024,18 +914,16 @@ void DolphinView::restoreContentsPosition() const int y = m_restoredContentsPosition.y(); m_restoredContentsPosition = QPoint(); - QAbstractItemView* view = m_viewAccessor.itemView(); - Q_ASSERT(view); - view->horizontalScrollBar()->setValue(x); - view->verticalScrollBar()->setValue(y); + m_container->horizontalScrollBar()->setValue(x); + m_container->verticalScrollBar()->setValue(y); } } -void DolphinView::slotUrlChangeRequested(const KUrl& url) +/*void DolphinView::slotUrlChangeRequested(const KUrl& url) { m_viewModeController->setUrl(url); updateWritableState(); -} +}*/ void DolphinView::showHoverInformation(const KFileItem& item) { @@ -1077,18 +965,21 @@ void DolphinView::slotDirListerCompleted() if (!m_newFileNames.isEmpty()) { // select all newly added items created by a paste operation or // a drag & drop operation, and clear the previous selection - m_viewAccessor.itemView()->clearSelection(); - const int rowCount = m_viewAccessor.proxyModel()->rowCount(); - QItemSelection selection; - for (int row = 0; row < rowCount; ++row) { - const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->index(row, 0); - const QModelIndex dirIndex = m_viewAccessor.proxyModel()->mapToSource(proxyIndex); - const KUrl url = m_viewAccessor.dirModel()->itemForIndex(dirIndex).url(); - if (m_newFileNames.contains(url.fileName())) { - selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select); + /*QAbstractItemView* view = m_viewAccessor.itemView(); + if (view) { + view->clearSelection(); + const int rowCount = m_viewAccessor.proxyModel()->rowCount(); + QItemSelection selection; + for (int row = 0; row < rowCount; ++row) { + const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->index(row, 0); + const QModelIndex dirIndex = m_viewAccessor.proxyModel()->mapToSource(proxyIndex); + const KUrl url = m_viewAccessor.dirModel()->itemForIndex(dirIndex).url(); + if (m_newFileNames.contains(url.fileName())) { + selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select); + } } - } - m_viewAccessor.itemView()->selectionModel()->select(selection, QItemSelectionModel::Select); + view->selectionModel()->select(selection, QItemSelectionModel::Select); + }*/ m_newFileNames.clear(); } @@ -1102,21 +993,23 @@ void DolphinView::slotLoadingCompleted() if (!m_activeItemUrl.isEmpty()) { // assure that the current item remains visible - const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_activeItemUrl); + /*const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForUrl(m_activeItemUrl); if (dirIndex.isValid()) { const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex); QAbstractItemView* view = m_viewAccessor.itemView(); - const bool clearSelection = !hasSelection(); - view->setCurrentIndex(proxyIndex); - if (clearSelection) { - view->clearSelection(); + if (view) { + const bool clearSelection = !hasSelection(); + view->setCurrentIndex(proxyIndex); + if (clearSelection) { + view->clearSelection(); + } } m_activeItemUrl.clear(); - } + }*/ } if (!m_selectedItems.isEmpty()) { - const KUrl& baseUrl = url(); + /*const KUrl& baseUrl = url(); KUrl url; QItemSelection newSelection; foreach(const KFileItem& item, m_selectedItems) { @@ -1126,15 +1019,18 @@ void DolphinView::slotLoadingCompleted() newSelection.select(index, index); } } - m_viewAccessor.itemView()->selectionModel()->select(newSelection, + QAbstractItemView* view = m_viewAccessor.itemView(); + if (view) { + view->selectionModel()->select(newSelection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current); + }*/ m_selectedItems.clear(); } // Restore the contents position. This has to be done using a Qt::QueuedConnection // because the view might not be in its final state yet. - QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection); + QTimer::singleShot(0, this, SLOT(restoreContentsPosition())); emit finishedPathLoading(url()); } @@ -1143,10 +1039,18 @@ void DolphinView::slotRefreshItems() { if (m_assureVisibleCurrentIndex) { m_assureVisibleCurrentIndex = false; - m_viewAccessor.itemView()->scrollTo(m_viewAccessor.itemView()->currentIndex()); + //QAbstractItemView* view = m_viewAccessor.itemView(); + //if (view) { + // m_viewAccessor.itemView()->scrollTo(m_viewAccessor.itemView()->currentIndex()); + //} } } +KFileItemModel* DolphinView::fileItemModel() const +{ + return static_cast<KFileItemModel*>(m_container->controller()->model()); +} + void DolphinView::loadDirectory(const KUrl& url, bool reload) { if (!url.isValid()) { @@ -1159,50 +1063,61 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload) return; } - KDirLister* dirLister = m_viewAccessor.dirLister(); - dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags); + m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags); } void DolphinView::applyViewProperties() { - const ViewProperties props(rootUrl()); + m_container->beginTransaction(); + + const ViewProperties props(url()); const Mode mode = props.viewMode(); if (m_mode != mode) { - const int oldZoomLevel = m_viewModeController->zoomLevel(); - + const Mode previousMode = m_mode; m_mode = mode; - createView(); - emit modeChanged(); - updateZoomLevel(oldZoomLevel); - } - if (!m_viewAccessor.itemView()) { - createView(); - } + // Changing the mode might result in changing + // the zoom level. Remember the old zoom level so + // that zoomLevelChanged() can get emitted. + const int oldZoomLevel = m_container->zoomLevel(); + + switch (m_mode) { + case IconsView: m_container->setItemLayout(KFileItemListView::IconsLayout); break; + case CompactView: m_container->setItemLayout(KFileItemListView::CompactLayout); break; + case DetailsView: m_container->setItemLayout(KFileItemListView::DetailsLayout); break; + default: Q_ASSERT(false); break; + } + + emit modeChanged(m_mode, previousMode); - Q_ASSERT(m_viewAccessor.itemView()); - Q_ASSERT(m_viewAccessor.itemDelegate()); + if (m_container->zoomLevel() != oldZoomLevel) { + emit zoomLevelChanged(m_container->zoomLevel(), oldZoomLevel); + } + } - const bool showHiddenFiles = props.showHiddenFiles(); - if (showHiddenFiles != m_viewAccessor.dirLister()->showingDotFiles()) { - m_viewAccessor.dirLister()->setShowingDotFiles(showHiddenFiles); - emit showHiddenFilesChanged(); + const bool hiddenFilesShown = props.hiddenFilesShown(); + if (hiddenFilesShown != m_dirLister->showingDotFiles()) { + m_dirLister->setShowingDotFiles(hiddenFilesShown); + m_dirLister->emitChanges(); + emit hiddenFilesShownChanged(hiddenFilesShown); } - m_storedCategorizedSorting = props.categorizedSorting(); +/* m_storedCategorizedSorting = props.categorizedSorting(); const bool categorized = m_storedCategorizedSorting && supportsCategorizedSorting(); if (categorized != m_viewAccessor.proxyModel()->isCategorizedModel()) { m_viewAccessor.proxyModel()->setCategorizedModel(categorized); emit categorizedSortingChanged(); - } + }*/ const DolphinView::Sorting sorting = props.sorting(); - if (sorting != m_viewAccessor.proxyModel()->sorting()) { - m_viewAccessor.proxyModel()->setSorting(sorting); + KItemModelBase* model = m_container->controller()->model(); + const QByteArray newSortRole = sortRoleForSorting(sorting); + if (newSortRole != model->sortRole()) { + model->setSortRole(newSortRole); emit sortingChanged(sorting); } - +/* const Qt::SortOrder sortOrder = props.sortOrder(); if (sortOrder != m_viewAccessor.proxyModel()->sortOrder()) { m_viewAccessor.proxyModel()->setSortOrder(sortOrder); @@ -1214,72 +1129,45 @@ void DolphinView::applyViewProperties() m_viewAccessor.proxyModel()->setSortFoldersFirst(sortFoldersFirst); emit sortFoldersFirstChanged(sortFoldersFirst); } - - KFileItemDelegate::InformationList info = props.additionalInfo(); - if (info != m_viewAccessor.itemDelegate()->showInformation()) { - m_viewAccessor.itemDelegate()->setShowInformation(info); - emit additionalInfoChanged(); - } - - const bool showPreview = props.showPreview(); - if (showPreview != m_showPreview) { - m_showPreview = showPreview; - const int oldZoomLevel = m_viewModeController->zoomLevel(); - emit showPreviewChanged(); - - // Enabling or disabling the preview might change the icon size of the view. - // As the view does not emit a signal when the icon size has been changed, - // the used zoom level of the controller must be adjusted manually: - updateZoomLevel(oldZoomLevel); +*/ + const QList<DolphinView::AdditionalInfo> infoList = props.additionalInfoList(); + if (infoList != m_additionalInfoList) { + const QList<DolphinView::AdditionalInfo> previousList = m_additionalInfoList; + m_additionalInfoList = infoList; + applyAdditionalInfoListToView(); + emit additionalInfoListChanged(m_additionalInfoList, previousList); } -} - -void DolphinView::createView() -{ - deleteView(); - - Q_ASSERT(!m_viewAccessor.itemView()); - Q_ASSERT(!m_dolphinViewController->itemView()); - m_viewAccessor.createView(this, m_dolphinViewController, m_viewModeController, m_mode); - QAbstractItemView* view = m_viewAccessor.itemView(); - Q_ASSERT(view); - view->installEventFilter(this); - view->viewport()->installEventFilter(this); + const bool previewsShown = props.previewsShown(); + if (previewsShown != m_container->previewsShown()) { + const int oldZoomLevel = zoomLevel(); - m_dolphinViewController->setItemView(view); + m_container->setPreviewsShown(previewsShown); + emit previewsShownChanged(previewsShown); - const int zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(view->iconSize()); - m_viewModeController->setZoomLevel(zoomLevel); - - connectViewAccessor(); + // Changing the preview-state might result in a changed zoom-level + if (oldZoomLevel != zoomLevel()) { + emit zoomLevelChanged(zoomLevel(), oldZoomLevel); + } + } - setFocusProxy(m_viewAccessor.layoutTarget()); - m_topLayout->insertWidget(1, m_viewAccessor.layoutTarget()); + m_container->endTransaction(); } -void DolphinView::deleteView() +void DolphinView::applyAdditionalInfoListToView() { - QAbstractItemView* view = m_viewAccessor.itemView(); - Q_ASSERT(!m_dolphinViewController->itemView() || (m_dolphinViewController->itemView() == view)); - m_dolphinViewController->setItemView(0); - - if (view) { - disconnectViewAccessor(); - - if (hasFocus()) { - // It's important to set the keyboard focus to the parent - // before deleting the view: Otherwise when having a split - // view the other view will get the focus and will request - // an activation (see DolphinView::eventFilter()). - setFocusProxy(0); - setFocus(); - } + const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - m_viewModeController->disconnect(view); + QHash<QByteArray, int> visibleRoles; + visibleRoles.insert("name", 0); - m_viewAccessor.deleteView(); + int index = 1; + foreach (AdditionalInfo info, m_additionalInfoList) { + visibleRoles.insert(infoAccessor.role(info), index); + ++index; } + + m_container->setVisibleRoles(visibleRoles); } void DolphinView::pasteToUrl(const KUrl& url) @@ -1290,17 +1178,19 @@ void DolphinView::pasteToUrl(const KUrl& url) void DolphinView::updateZoomLevel(int oldZoomLevel) { - const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor.itemView()->iconSize()); + Q_UNUSED(oldZoomLevel); + /* const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor.itemView()->iconSize()); if (oldZoomLevel != newZoomLevel) { m_viewModeController->setZoomLevel(newZoomLevel); emit zoomLevelChanged(newZoomLevel); - } + }*/ } KUrl::List DolphinView::simplifiedSelectedUrls() const { + Q_ASSERT(false); // TODO KUrl::List urls; - +/* const KFileItemList items = selectedItems(); foreach (const KFileItem &item, items) { urls.append(item.url()); @@ -1309,17 +1199,18 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const if (itemsExpandable()) { urls = KDirModel::simplifiedUrlList(urls); - } + }*/ return urls; } QMimeData* DolphinView::selectionMimeData() const { - const QAbstractItemView* view = m_viewAccessor.itemView(); + /*const QAbstractItemView* view = m_viewAccessor.itemView(); Q_ASSERT((view) && (view->selectionModel())); const QItemSelection selection = m_viewAccessor.proxyModel()->mapSelectionToSource(view->selectionModel()->selection()); - return m_viewAccessor.dirModel()->mimeData(selection.indexes()); + return m_viewAccessor.dirModel()->mimeData(selection.indexes());*/ + return 0; } void DolphinView::addNewFileNames(const QMimeData* mimeData) @@ -1332,8 +1223,10 @@ void DolphinView::addNewFileNames(const QMimeData* mimeData) QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const { + Q_UNUSED(parent); + Q_UNUSED(pattern); QItemSelection matchingIndexes; - const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel(); + /*const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel(); const DolphinModel* dolphinModel = m_viewAccessor.dirModel(); const int rowCount = proxyModel->rowCount(parent); @@ -1349,61 +1242,17 @@ QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, c if (proxyModel->hasChildren(index)) { matchingIndexes += childrenMatchingPattern(index, pattern); } - } + }*/ return matchingIndexes; } -void DolphinView::connectViewAccessor() -{ - KDirLister* dirLister = m_viewAccessor.dirLister(); - connect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl))); - connect(dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl))); - connect(dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); - connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)), - this, SLOT(slotRefreshItems())); - - connect(dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged())); - connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged())); - connect(dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); - connect(dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); - connect(dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int))); - connect(dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&))); - connect(dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged())); - - QAbstractItemView* view = m_viewAccessor.itemView(); - connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); -} - -void DolphinView::disconnectViewAccessor() -{ - KDirLister* dirLister = m_viewAccessor.dirLister(); - disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl))); - disconnect(dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl))); - disconnect(dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); - disconnect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)), - this, SLOT(slotRefreshItems())); - - disconnect(dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged())); - disconnect(dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged())); - disconnect(dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); - disconnect(dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(errorMessage(const QString&))); - disconnect(dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int))); - disconnect(dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&))); - disconnect(dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged())); - - QAbstractItemView* view = m_viewAccessor.itemView(); - disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), - this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); -} - void DolphinView::updateWritableState() { const bool wasFolderWritable = m_isFolderWritable; m_isFolderWritable = true; - const KFileItem item = m_viewAccessor.dirLister()->rootItem(); + const KFileItem item; // = m_viewAccessor.dirLister()->rootItem(); if (!item.isNull()) { KFileItemListProperties capabilities(KFileItemList() << item); m_isFolderWritable = capabilities.supportsWriting(); @@ -1413,225 +1262,22 @@ void DolphinView::updateWritableState() } } -DolphinView::ViewAccessor::ViewAccessor() : - m_rootUrl(), - m_iconsView(0), - m_detailsView(0), - m_columnsContainer(0), - m_dolphinModel(0), - m_proxyModel(0), - m_dragSource(0) -{ - DolphinDirLister* dirLister = new DolphinDirLister(); - dirLister->setAutoUpdate(true); - dirLister->setDelayedMimeTypes(true); - - m_dolphinModel = new DolphinModel(); - m_dolphinModel->setDirLister(dirLister); // m_dolphinModel takes ownership of dirLister - m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); - - m_proxyModel = new DolphinSortFilterProxyModel(); - m_proxyModel->setSourceModel(m_dolphinModel); - m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -DolphinView::ViewAccessor::~ViewAccessor() -{ - delete m_proxyModel; - m_proxyModel = 0; - - delete m_dolphinModel; - m_dolphinModel = 0; - - delete m_dragSource; - m_dragSource = 0; -} - -void DolphinView::ViewAccessor::createView(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController, - Mode mode) -{ - Q_ASSERT(!itemView()); - - switch (mode) { - case IconsView: - m_iconsView = new DolphinIconsView(parent, - dolphinViewController, - viewModeController, - m_proxyModel); - break; - - case DetailsView: - m_detailsView = new DolphinDetailsView(parent, - dolphinViewController, - viewModeController, - m_proxyModel); - break; - - case ColumnView: - m_columnsContainer = new DolphinColumnViewContainer(parent, - dolphinViewController, - viewModeController); - if (!m_rootUrl.isEmpty() && m_rootUrl.isParentOf(viewModeController->url())) { - // The column-view must show several columns starting with m_rootUrl as - // first column and viewModeController->url() as last column. - m_columnsContainer->showColumn(m_rootUrl); - m_columnsContainer->showColumn(viewModeController->url()); - } - break; - - default: - Q_ASSERT(false); - } - - KDirLister* lister = dirLister(); - if (lister) { - lister->setMainWindow(parent->window()); - } -} - -void DolphinView::ViewAccessor::deleteView() -{ - if (m_columnsContainer) { - m_columnsContainer->close(); - m_columnsContainer->disconnect(); - m_columnsContainer->deleteLater(); - m_columnsContainer = 0; - } else { - QAbstractItemView* view = itemView(); - if (view) { - view->close(); - view->disconnect(); - - if (DragAndDropHelper::instance().isDragSource(view)) { - // The view is a drag source (the feature "Open folders - // during drag operations" is used). Deleting the view - // during an ongoing drag operation is not allowed, so - // this will postponed. - if (m_dragSource) { - // the old stored view is obviously not the drag source anymore - m_dragSource->deleteLater(); - m_dragSource = 0; - } - view->hide(); - m_dragSource = view; - } else { - view->deleteLater(); - view = 0; - } - } - - m_iconsView = 0; - m_detailsView = 0; - } -} - -void DolphinView::ViewAccessor::prepareUrlChange(const KUrl& url) -{ - if (m_columnsContainer) { - m_columnsContainer->showColumn(url); - } -} - -QAbstractItemView* DolphinView::ViewAccessor::itemView() const -{ - if (m_iconsView) { - return m_iconsView; - } - - if (m_detailsView) { - return m_detailsView; - } - - if (m_columnsContainer) { - return m_columnsContainer->activeColumn(); - } - - return 0; -} - -KFileItemDelegate* DolphinView::ViewAccessor::itemDelegate() const -{ - return static_cast<KFileItemDelegate*>(itemView()->itemDelegate()); -} - -QWidget* DolphinView::ViewAccessor::layoutTarget() const -{ - if (m_columnsContainer) { - return m_columnsContainer; - } - return itemView(); -} - -void DolphinView::ViewAccessor::setRootUrl(const KUrl& rootUrl) -{ - m_rootUrl = rootUrl; -} - -KUrl DolphinView::ViewAccessor::rootUrl() const -{ - return m_columnsContainer ? m_columnsContainer->rootUrl() : m_rootUrl; -} - -bool DolphinView::ViewAccessor::supportsCategorizedSorting() const -{ - return m_iconsView != 0; -} - -bool DolphinView::ViewAccessor::itemsExpandable() const -{ - return m_detailsView && m_detailsView->itemsExpandable(); -} - -QSet<KUrl> DolphinView::ViewAccessor::expandedUrls() const -{ - if (m_detailsView) { - return m_detailsView->expandedUrls(); - } - - return QSet<KUrl>(); -} - -const DolphinDetailsViewExpander* DolphinView::ViewAccessor::setExpandedUrls(const QSet<KUrl>& urlsToExpand) -{ - if (m_detailsView && m_detailsView->itemsExpandable() && !urlsToExpand.isEmpty()) { - // Check if another expander is already active and stop it if necessary. - if(!m_detailsViewExpander.isNull()) { - m_detailsViewExpander->stop(); - } - - m_detailsViewExpander = new DolphinDetailsViewExpander(m_detailsView, urlsToExpand); - return m_detailsViewExpander; - } - else { - return 0; - } -} - -bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const +QByteArray DolphinView::sortRoleForSorting(Sorting sorting) const { - // the details view requires no reloading of the directory, as it maps - // the file item delegate info to its columns internally - return m_detailsView != 0; -} - -DolphinModel* DolphinView::ViewAccessor::dirModel() const -{ - return static_cast<DolphinModel*>(proxyModel()->sourceModel()); -} - -DolphinSortFilterProxyModel* DolphinView::ViewAccessor::proxyModel() const -{ - if (m_columnsContainer) { - return static_cast<DolphinSortFilterProxyModel*>(m_columnsContainer->activeColumn()->model()); + switch (sorting) { + case SortByName: return "name"; + case SortBySize: return "size"; + case SortByDate: return "date"; + case SortByPermissions: return "permissions"; + case SortByOwner: return "owner"; + case SortByGroup: return "group"; + case SortByType: return "type"; + case SortByDestination: return "destination"; + case SortByPath: return "path"; + default: break; } - return m_proxyModel; -} -KDirLister* DolphinView::ViewAccessor::dirLister() const -{ - return dirModel()->dirLister(); + return QByteArray(); } #include "dolphinview.moc" diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 48967e62b..f5bc7d922 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -41,34 +41,25 @@ typedef KIO::FileUndoManager::CommandType CommandType; -class DolphinColumnViewContainer; -class DolphinDetailsView; -class DolphinDetailsViewExpander; -class DolphinIconsView; -class DolphinModel; -class DolphinSortFilterProxyModel; -class DolphinViewController; +class DolphinDirLister; +class DolphinItemListContainer; class KAction; class KActionCollection; -class KDirLister; +class KFileItemModel; class KUrl; -class ViewModeController; class ViewProperties; class QRegExp; /** * @short Represents a view for the directory content. * - * View modes for icons, details and columns are supported. It's + * View modes for icons, compact and details are supported. It's * possible to adjust: * - sort order * - sort type * - show hidden files * - show previews - * - * @see DolphinIconsView - * @see DolphinDetailsView - * @see DolphinColumnView + * - enable grouping */ class LIBDOLPHINPRIVATE_EXPORT DolphinView : public QWidget { @@ -76,31 +67,28 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinView : public QWidget public: /** - * Defines the view mode for a directory. The view mode - * can be defined when constructing a DolphinView. The + * Defines the view mode for a directory. The * view mode is automatically updated if the directory itself * defines a view mode (see class ViewProperties for details). */ enum Mode { /** - * The directory items are shown as icons including an - * icon name. + * The items are shown as icons with a name-label below. */ IconsView = 0, /** - * The icon, the name and at least the size of the directory - * items are shown in a table. It is possible to add columns - * for date, group and permissions. + * The icon, the name and the size of the items are + * shown per default as a table. */ DetailsView = 1, /** - * Each folder is shown in a separate column. + * The items are shown as icons with the name-label aligned + * to the right side. */ - ColumnView = 2, - MaxModeEnum = ColumnView + CompactView = 3 }; /** Defines the sort order for the items of a directory. */ @@ -114,15 +102,29 @@ public: SortByGroup, SortByType, SortByDestination, - SortByPath, - MaxSortingEnum = SortByPath + SortByPath + }; + + /** Defines the additional information shown for the items of a directory. */ + enum AdditionalInfo + { + NoInfo = 0, + NameInfo, + SizeInfo, + DateInfo, + PermissionsInfo, + OwnerInfo, + GroupInfo, + TypeInfo, + DestinationInfo, + PathInfo }; /** * @param url Specifies the content which should be shown. * @param parent Parent widget of the view. */ - DolphinView( const KUrl& url, QWidget* parent); + DolphinView(const KUrl& url, QWidget* parent); virtual ~DolphinView(); @@ -133,17 +135,6 @@ public: KUrl url() const; /** - * Returns the root URL of the view, which is defined as the first - * visible path of DolphinView::url(). Usually the root URL is - * equal to DolphinView::url(), but in the case of the column view - * when 2 columns are shown, the root URL might be: - * /home/peter/Documents - * and DolphinView::url() might return - * /home/peter/Documents/Music/ - */ - KUrl rootUrl() const; - - /** * If \a active is true, the view will marked as active. The active * view is defined as view where all actions are applied to. */ @@ -159,31 +150,16 @@ public: void setMode(Mode mode); Mode mode() const; - /** See setShowPreview */ - bool showPreview() const; + /** See setPreviewsShown */ + bool previewsShown() const; /** See setShowHiddenFiles */ - bool showHiddenFiles() const; + bool hiddenFilesShown() const; /** See setCategorizedSorting */ bool categorizedSorting() const; /** - * Returns true, if the categorized sorting is supported by the current - * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView - * supports categorizations. To check whether the categorized - * sorting is set, use DolphinView::categorizedSorting(). - */ - bool supportsCategorizedSorting() const; - - /** - * Returns the root item which represents the current URL. Note that the returned - * item can be null (KFileItem::isNull() will return true) in case that the directory - * has not been loaded. - */ - KFileItem rootItem() const; - - /** * Returns the items of the view. */ KFileItemList items() const; @@ -253,10 +229,10 @@ public: bool sortFoldersFirst() const; /** Sets the additional information which should be shown for the items. */ - void setAdditionalInfo(KFileItemDelegate::InformationList info); + void setAdditionalInfoList(const QList<AdditionalInfo>& info); /** Returns the additional information which should be shown for the items. */ - KFileItemDelegate::InformationList additionalInfo() const; + QList<AdditionalInfo> additionalInfoList() const; /** Reloads the current directory. */ void reload(); @@ -300,11 +276,6 @@ public: QList<QAction*> versionControlActions(const KFileItemList& items) const; /** - * Updates the state of the 'Additional Information' actions in \a collection. - */ - void updateAdditionalInfoActions(KActionCollection* collection); - - /** * Returns the state of the paste action: * first is whether the action should be enabled * second is the text for the action @@ -339,6 +310,13 @@ public: /** Returns true, if at least one item is selected. */ bool hasSelection() const; + /** + * Returns the root item which represents the current URL. Note that the returned + * item can be null (KFileItem::isNull() will return true) in case that the directory + * has not been loaded. + */ + KFileItem rootItem() const; + public slots: /** * Changes the directory to \a url. If the current directory is equal to @@ -403,7 +381,7 @@ public slots: * (GeneralSettings::globalViewProps() returns false), then the * preview setting will be stored automatically. */ - void setShowPreview(bool show); + void setPreviewsShown(bool show); /** * Shows all hidden files of the current directory, @@ -412,7 +390,7 @@ public slots: * (GeneralSettings::globalViewProps() returns false), then the * show hidden file setting will be stored automatically. */ - void setShowHiddenFiles(bool show); + void setHiddenFilesShown(bool show); /** * Summarizes all sorted items by their category \a categorized @@ -429,6 +407,13 @@ signals: */ void activated(); + /** + * Is emitted if the URL of the view will be changed to \a url. + * After the URL has been changed the signal urlChanged() will + * be emitted. + */ + void urlAboutToBeChanged(const KUrl& url); + /** Is emitted if URL of the view has been changed to \a url. */ void urlChanged(const KUrl& url); @@ -451,16 +436,16 @@ signals: * Is emitted if the view mode (IconsView, DetailsView, * PreviewsView) has been changed. */ - void modeChanged(); + void modeChanged(Mode current, Mode previous); /** Is emitted if the 'show preview' property has been changed. */ - void showPreviewChanged(); + void previewsShownChanged(bool shown); /** Is emitted if the 'show hidden files' property has been changed. */ - void showHiddenFilesChanged(); + void hiddenFilesShownChanged(bool shown); /** Is emitted if the 'categorized sorting' property has been changed. */ - void categorizedSortingChanged(); + void categorizedSortingChanged(bool sortCategorized); /** Is emitted if the sorting by name, size or date has been changed. */ void sortingChanged(DolphinView::Sorting sorting); @@ -472,10 +457,11 @@ signals: void sortFoldersFirstChanged(bool foldersFirst); /** Is emitted if the additional information shown for this view has been changed. */ - void additionalInfoChanged(); + void additionalInfoListChanged(const QList<DolphinView::AdditionalInfo>& current, + const QList<DolphinView::AdditionalInfo>& previous); /** Is emitted if the zoom level has been changed by zooming in or out. */ - void zoomLevelChanged(int level); + void zoomLevelChanged(int current, int previous); /** * Is emitted if information of an item is requested to be shown e. g. in the panel. @@ -556,10 +542,8 @@ signals: void writeStateChanged(bool isFolderWritable); protected: - /** @see QWidget::mouseReleaseEvent */ virtual void mouseReleaseEvent(QMouseEvent* event); - virtual bool eventFilter(QObject* watched, QEvent* event); - virtual void showEvent(QShowEvent* event); + virtual void contextMenuEvent(QContextMenuEvent* event); private slots: /** @@ -568,12 +552,9 @@ private slots: */ void activate(); - /** - * If the item \a item is a directory, then this - * directory will be loaded. If the item is a file, the corresponding - * application will get started. - */ - void triggerItem(const KFileItem& index); + void slotItemClicked(int index, Qt::MouseButton button); + + void slotItemExpansionToggleClicked(int index); /** * Emits the signal \a selectionChanged() with a small delay. This is @@ -625,12 +606,6 @@ private slots: void updateSortFoldersFirst(bool foldersFirst); /** - * Updates the view properties of the current URL to the - * additional information given by \a info. - */ - void updateAdditionalInfo(const KFileItemDelegate::InformationList& info); - - /** * Updates the status bar to show hover information for the * item \a item. If currently other items are selected, * no hover information is shown. @@ -699,9 +674,11 @@ private slots: */ void restoreContentsPosition(); - void slotUrlChangeRequested(const KUrl& url); + //void slotUrlChangeRequested(const KUrl& url); private: + KFileItemModel* fileItemModel() const; + void loadDirectory(const KUrl& url, bool reload = false); /** @@ -710,13 +687,7 @@ private: */ void applyViewProperties(); - /** - * Creates a new view representing the given view mode (DolphinView::mode()). - * The current view will get deleted. - */ - void createView(); - - void deleteView(); + void applyAdditionalInfoListToView(); /** * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder(). @@ -758,9 +729,6 @@ private: */ QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const; - void connectViewAccessor(); - void disconnectViewAccessor(); - /** * Updates m_isFolderWritable dependent on whether the folder represented by * the current URL is writable. If the state has changed, the signal @@ -768,88 +736,23 @@ private: */ void updateWritableState(); -private: - /** - * Abstracts the access to the different view implementations - * for icons-, details- and column-view. - */ - class ViewAccessor - { - public: - ViewAccessor(); - ~ViewAccessor(); - - void createView(QWidget* parent, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController, - Mode mode); - void deleteView(); - - /** - * Must be invoked before the URL has been changed and allows view implementations - * like the column view to create a new column. - */ - void prepareUrlChange(const KUrl& url); - - QAbstractItemView* itemView() const; - KFileItemDelegate* itemDelegate() const; - - /** - * Returns the widget that should be added to the layout as target. Usually - * the item view itself is returned, but in the case of the column view - * a container widget is returned. - */ - QWidget* layoutTarget() const; - - void setRootUrl(const KUrl& rootUrl); - KUrl rootUrl() const; - - bool supportsCategorizedSorting() const; - bool itemsExpandable() const; - QSet<KUrl> expandedUrls() const; - const DolphinDetailsViewExpander* setExpandedUrls(const QSet<KUrl>& urlsToExpand); - - /** - * Returns true, if a reloading of the items is required - * when the additional information properties have been changed - * by the user. - */ - bool reloadOnAdditionalInfoChange() const; - - DolphinModel* dirModel() const; - DolphinSortFilterProxyModel* proxyModel() const; - KDirLister* dirLister() const; - - private: - KUrl m_rootUrl; - DolphinIconsView* m_iconsView; - DolphinDetailsView* m_detailsView; - DolphinColumnViewContainer* m_columnsContainer; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; - QAbstractItemView* m_dragSource; - QPointer<DolphinDetailsViewExpander> m_detailsViewExpander; - - // For unit tests - friend class DolphinDetailsViewTest; - }; + QByteArray sortRoleForSorting(Sorting sorting) const; +private: bool m_active : 1; - bool m_showPreview : 1; - bool m_storedCategorizedSorting : 1; bool m_tabsForFiles : 1; - bool m_isContextMenuOpen : 1; // TODO: workaround for Qt-issue 207192 bool m_assureVisibleCurrentIndex : 1; bool m_expanderActive : 1; bool m_isFolderWritable : 1; + KUrl m_url; Mode m_mode; + QList<AdditionalInfo> m_additionalInfoList; QVBoxLayout* m_topLayout; - DolphinViewController* m_dolphinViewController; - ViewModeController* m_viewModeController; - ViewAccessor m_viewAccessor; + DolphinDirLister* m_dirLister; + DolphinItemListContainer* m_container; QTimer* m_selectionChangedTimer; diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index 6046abc8c..87e828dfa 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -36,6 +36,8 @@ #include <KRun> #include <KPropertiesDialog> +#include <KDebug> + DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) : QObject(parent), m_actionCollection(collection), @@ -49,29 +51,32 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view) { Q_ASSERT(view); - if (m_currentView) + if (m_currentView) { disconnect(m_currentView, 0, this, 0); + } m_currentView = view; - connect(view, SIGNAL(modeChanged()), + connect(view, SIGNAL(modeChanged(DolphinView::Mode, DolphinView::Mode)), this, SLOT(updateViewActions())); - connect(view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); + connect(view, SIGNAL(previewsShownChanged(bool)), + this, SLOT(slotPreviewsShownChanged(bool))); connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); connect(view, SIGNAL(sortFoldersFirstChanged(bool)), this, SLOT(slotSortFoldersFirstChanged(bool))); - connect(view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); - connect(view, SIGNAL(categorizedSortingChanged()), - this, SLOT(slotCategorizedSortingChanged())); - connect(view, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); + connect(view, SIGNAL(additionalInfoListChanged(QList<DolphinView::AdditionalInfo>, + QList<DolphinView::AdditionalInfo>)), + this, SLOT(slotAdditionalInfoListChanged(QList<DolphinView::AdditionalInfo>, + QList<DolphinView::AdditionalInfo>))); + connect(view, SIGNAL(categorizedSortingChanged(bool)), + this, SLOT(slotCategorizedSortingChanged(bool))); + connect(view, SIGNAL(hiddenFilesShownChanged(bool)), + this, SLOT(slotHiddenFilesShownChanged(bool))); connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), this, SLOT(slotSortingChanged(DolphinView::Sorting))); - connect(view, SIGNAL(zoomLevelChanged(int)), - this, SLOT(slotZoomLevelChanged(int))); + connect(view, SIGNAL(zoomLevelChanged(int, int)), + this, SLOT(slotZoomLevelChanged(int, int))); } DolphinView* DolphinViewActionHandler::currentView() @@ -130,14 +135,14 @@ void DolphinViewActionHandler::createActions() // View menu KToggleAction* iconsAction = iconsModeAction(); + KToggleAction* compactAction = compactModeAction(); KToggleAction* detailsAction = detailsModeAction(); - KToggleAction* columnsAction = columnsModeAction(); KSelectAction* viewModeActions = m_actionCollection->add<KSelectAction>("view_mode"); viewModeActions->setText(i18nc("@action:intoolbar", "View Mode")); viewModeActions->addAction(iconsAction); + viewModeActions->addAction(compactAction); viewModeActions->addAction(detailsAction); - viewModeActions->addAction(columnsAction); viewModeActions->setToolBarMode(KSelectAction::MenuMode); connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*))); @@ -214,8 +219,8 @@ QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup() const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - const KFileItemDelegate::InformationList infoKeys = infoAccessor.keys(); - foreach (KFileItemDelegate::Information info, infoKeys) { + const QList<DolphinView::AdditionalInfo> infoList = infoAccessor.keys(); + foreach (DolphinView::AdditionalInfo info, infoList) { const QString name = infoAccessor.actionCollectionName(info, AdditionalInfoAccessor::AdditionalInfoType); KToggleAction* action = m_actionCollection->add<KToggleAction>(name); action->setText(infoAccessor.translation(info)); @@ -239,8 +244,8 @@ QActionGroup* DolphinViewActionHandler::createSortByActionGroup() sortByActionGroup->addAction(sortByName); const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - const KFileItemDelegate::InformationList infoKeys = infoAccessor.keys(); - foreach (KFileItemDelegate::Information info, infoKeys) { + const QList<DolphinView::AdditionalInfo> infoList = infoAccessor.keys(); + foreach (DolphinView::AdditionalInfo info, infoList) { const QString name = infoAccessor.actionCollectionName(info, AdditionalInfoAccessor::SortByType); KToggleAction* action = m_actionCollection->add<KToggleAction>(name); action->setText(infoAccessor.translation(info)); @@ -289,11 +294,12 @@ void DolphinViewActionHandler::slotDeleteItems() void DolphinViewActionHandler::togglePreview(bool show) { emit actionBeingHandled(); - m_currentView->setShowPreview(show); + m_currentView->setPreviewsShown(show); } -void DolphinViewActionHandler::slotShowPreviewChanged() +void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown) { + Q_UNUSED(shown); // It is not enough to update the 'Show Preview' action, also // the 'Zoom In' and 'Zoom Out' actions must be adapted. updateViewActions(); @@ -306,8 +312,8 @@ QString DolphinViewActionHandler::currentViewModeActionName() const return "icons"; case DolphinView::DetailsView: return "details"; - case DolphinView::ColumnView: - return "columns"; + case DolphinView::CompactView: + return "compact"; } return QString(); // can't happen } @@ -328,17 +334,17 @@ void DolphinViewActionHandler::updateViewActions() } QAction* showPreviewAction = m_actionCollection->action("show_preview"); - showPreviewAction->setChecked(m_currentView->showPreview()); + showPreviewAction->setChecked(m_currentView->previewsShown()); slotSortOrderChanged(m_currentView->sortOrder()); slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst()); - slotAdditionalInfoChanged(); - slotCategorizedSortingChanged(); + slotAdditionalInfoListChanged(m_currentView->additionalInfoList(), QList<DolphinView::AdditionalInfo>()); + slotCategorizedSortingChanged(m_currentView->categorizedSorting()); slotSortingChanged(m_currentView->sorting()); - slotZoomLevelChanged(m_currentView->zoomLevel()); + slotZoomLevelChanged(m_currentView->zoomLevel(), -1); QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files"); - showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles()); + showHiddenFilesAction->setChecked(m_currentView->hiddenFilesShown()); } void DolphinViewActionHandler::zoomIn() @@ -385,10 +391,10 @@ void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action) { emit actionBeingHandled(); - const KFileItemDelegate::Information info = - static_cast<KFileItemDelegate::Information>(action->data().toInt()); + const DolphinView::AdditionalInfo info = + static_cast<DolphinView::AdditionalInfo>(action->data().toInt()); - KFileItemDelegate::InformationList list = m_currentView->additionalInfo(); + QList<DolphinView::AdditionalInfo> list = m_currentView->additionalInfoList(); const bool show = action->isChecked(); @@ -396,17 +402,30 @@ void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action) const bool containsInfo = (index >= 0); if (show && !containsInfo) { list.append(info); - m_currentView->setAdditionalInfo(list); + m_currentView->setAdditionalInfoList(list); } else if (!show && containsInfo) { list.removeAt(index); - m_currentView->setAdditionalInfo(list); + m_currentView->setAdditionalInfoList(list); Q_ASSERT(list.indexOf(info) < 0); } } -void DolphinViewActionHandler::slotAdditionalInfoChanged() +void DolphinViewActionHandler::slotAdditionalInfoListChanged(const QList<DolphinView::AdditionalInfo>& current, + const QList<DolphinView::AdditionalInfo>& previous) { - m_currentView->updateAdditionalInfoActions(m_actionCollection); + Q_UNUSED(previous); + + const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); + + const QList<DolphinView::AdditionalInfo> checkedInfo = current; + const QList<DolphinView::AdditionalInfo> infoList = infoAccessor.keys(); + + foreach (DolphinView::AdditionalInfo info, infoList) { + const QString name = infoAccessor.actionCollectionName(info, AdditionalInfoAccessor::AdditionalInfoType); + QAction* action = m_actionCollection->action(name); + Q_ASSERT(action); + action->setChecked(checkedInfo.contains(info)); + } } void DolphinViewActionHandler::toggleSortCategorization(bool categorizedSorting) @@ -414,23 +433,22 @@ void DolphinViewActionHandler::toggleSortCategorization(bool categorizedSorting) m_currentView->setCategorizedSorting(categorizedSorting); } -void DolphinViewActionHandler::slotCategorizedSortingChanged() +void DolphinViewActionHandler::slotCategorizedSortingChanged(bool sortCategorized) { QAction* showInGroupsAction = m_actionCollection->action("show_in_groups"); - showInGroupsAction->setChecked(m_currentView->categorizedSorting()); - showInGroupsAction->setEnabled(m_currentView->supportsCategorizedSorting()); + showInGroupsAction->setChecked(sortCategorized); } void DolphinViewActionHandler::toggleShowHiddenFiles(bool show) { emit actionBeingHandled(); - m_currentView->setShowHiddenFiles(show); + m_currentView->setHiddenFilesShown(show); } -void DolphinViewActionHandler::slotShowHiddenFilesChanged() +void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown) { QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files"); - showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles()); + showHiddenFilesAction->setChecked(shown); } @@ -445,28 +463,28 @@ KToggleAction* DolphinViewActionHandler::iconsModeAction() return iconsView; } +KToggleAction* DolphinViewActionHandler::compactModeAction() +{ + KToggleAction* iconsView = m_actionCollection->add<KToggleAction>("compact"); + iconsView->setText(i18nc("@action:inmenu View Mode", "Compact")); + iconsView->setToolTip(i18nc("@info", "Compact view mode")); + iconsView->setShortcut(Qt::CTRL | Qt::Key_2); + iconsView->setIcon(KIcon("view-list-details")); // TODO: discuss with Oxygen-team the wrong (?) name + iconsView->setData(QVariant::fromValue(DolphinView::CompactView)); + return iconsView; +} + KToggleAction* DolphinViewActionHandler::detailsModeAction() { KToggleAction* detailsView = m_actionCollection->add<KToggleAction>("details"); detailsView->setText(i18nc("@action:inmenu View Mode", "Details")); detailsView->setToolTip(i18nc("@info", "Details view mode")); - detailsView->setShortcut(Qt::CTRL | Qt::Key_2); - detailsView->setIcon(KIcon("view-list-details")); + detailsView->setShortcut(Qt::CTRL | Qt::Key_3); + detailsView->setIcon(KIcon("view-list-text")); detailsView->setData(QVariant::fromValue(DolphinView::DetailsView)); return detailsView; } -KToggleAction* DolphinViewActionHandler::columnsModeAction() -{ - KToggleAction* columnView = m_actionCollection->add<KToggleAction>("columns"); - columnView->setText(i18nc("@action:inmenu View Mode", "Columns")); - columnView->setToolTip(i18nc("@info", "Columns view mode")); - columnView->setShortcut(Qt::CTRL | Qt::Key_3); - columnView->setIcon(KIcon("view-file-columns")); - columnView->setData(QVariant::fromValue(DolphinView::ColumnView)); - return columnView; -} - void DolphinViewActionHandler::slotSortingChanged(DolphinView::Sorting sorting) { QAction* action = 0; @@ -474,8 +492,8 @@ void DolphinViewActionHandler::slotSortingChanged(DolphinView::Sorting sorting) action = m_actionCollection->action("sort_by_name"); } else { const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - const KFileItemDelegate::InformationList infoKeys = infoAccessor.keys(); - foreach (const KFileItemDelegate::Information info, infoKeys) { + const QList<DolphinView::AdditionalInfo> infoList = infoAccessor.keys(); + foreach (DolphinView::AdditionalInfo info, infoList) { if (sorting == infoAccessor.sorting(info)) { const QString name = infoAccessor.actionCollectionName(info, AdditionalInfoAccessor::SortByType); action = m_actionCollection->action(name); @@ -492,16 +510,18 @@ void DolphinViewActionHandler::slotSortingChanged(DolphinView::Sorting sorting) } } -void DolphinViewActionHandler::slotZoomLevelChanged(int level) +void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous) { + Q_UNUSED(previous); + QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn)); if (zoomInAction) { - zoomInAction->setEnabled(level < ZoomLevelInfo::maximumLevel()); + zoomInAction->setEnabled(current < ZoomLevelInfo::maximumLevel()); } QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomOut)); if (zoomOutAction) { - zoomOutAction->setEnabled(level > ZoomLevelInfo::minimumLevel()); + zoomOutAction->setEnabled(current > ZoomLevelInfo::minimumLevel()); } } diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h index 72e768375..4e5a0d32f 100644 --- a/src/views/dolphinviewactionhandler.h +++ b/src/views/dolphinviewactionhandler.h @@ -124,7 +124,7 @@ private Q_SLOTS: void togglePreview(bool); /** Updates the state of the 'Show preview' menu action. */ - void slotShowPreviewChanged(); + void slotPreviewsShownChanged(bool shown); /** Increases the size of the current set view mode. */ void zoomIn(); @@ -156,7 +156,7 @@ private Q_SLOTS: /** * Updates the state of the 'Zoom In' and 'Zoom Out' actions. */ - void slotZoomLevelChanged(int level); + void slotZoomLevelChanged(int current, int previous); /** * Switches on or off the displaying of additional information @@ -172,7 +172,8 @@ private Q_SLOTS: /** * Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(); + void slotAdditionalInfoListChanged(const QList<DolphinView::AdditionalInfo>& current, + const QList<DolphinView::AdditionalInfo>& previous); /** * Switches between sorting by categories or not. @@ -182,7 +183,7 @@ private Q_SLOTS: /** * Updates the state of the 'Categorized sorting' menu action. */ - void slotCategorizedSortingChanged(); + void slotCategorizedSortingChanged(bool sortCategorized); /** * Switches between showing and hiding of hidden marked files @@ -192,7 +193,7 @@ private Q_SLOTS: /** * Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); + void slotHiddenFilesShownChanged(bool shown); /** * Opens the view properties dialog, which allows to modify the properties @@ -234,16 +235,16 @@ private: KToggleAction* iconsModeAction(); /** - * Returns the "switch to details mode" action. + * Returns the "switch to compact mode" action. * Helper method for createActions(); */ - KToggleAction* detailsModeAction(); + KToggleAction* compactModeAction(); /** - * Returns the "switch to columns mode" action. + * Returns the "switch to details mode" action. * Helper method for createActions(); */ - KToggleAction* columnsModeAction(); + KToggleAction* detailsModeAction(); KActionCollection* m_actionCollection; DolphinView* m_currentView; diff --git a/src/views/dolphinviewcontroller.cpp b/src/views/dolphinviewcontroller.cpp deleted file mode 100644 index e182e48c1..000000000 --- a/src/views/dolphinviewcontroller.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz <[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 "dolphinviewcontroller.h" -#include "zoomlevelinfo.h" - -#include <KDirModel> -#include <KFileItemActions> -#include <QAbstractProxyModel> -#include <QApplication> -#include <QClipboard> -#include <QDir> - -Qt::MouseButtons DolphinViewController::m_mouseButtons = Qt::NoButton; - -DolphinViewController::DolphinViewController(DolphinView* dolphinView) : - QObject(dolphinView), - m_dolphinView(dolphinView), - m_itemView(0), - m_versionControlActions() -{ -} - -DolphinViewController::~DolphinViewController() -{ -} - -const DolphinView* DolphinViewController::view() const -{ - return m_dolphinView; -} - -void DolphinViewController::requestUrlChange(const KUrl& url) -{ - emit urlChangeRequested(url); -} - -void DolphinViewController::setItemView(QAbstractItemView* view) -{ - if (m_itemView) { - disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateMouseButtonState())); - } - - m_itemView = view; - - if (m_itemView) { - // TODO: this is a workaround until Qt-issue 176832 has been fixed - connect(m_itemView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateMouseButtonState())); - } -} - -QAbstractItemView* DolphinViewController::itemView() const -{ - return m_itemView; -} - -void DolphinViewController::triggerContextMenuRequest(const QPoint& pos, - const QList<QAction*>& customActions) -{ - emit activated(); - emit requestContextMenu(pos, customActions); -} - -void DolphinViewController::requestActivation() -{ - emit activated(); -} - -void DolphinViewController::indicateDroppedUrls(const KFileItem& destItem, QDropEvent* event) -{ - emit urlsDropped(destItem, m_dolphinView->url(), event); -} - - -void DolphinViewController::indicateSortingChange(DolphinView::Sorting sorting) -{ - emit sortingChanged(sorting); -} - -void DolphinViewController::indicateSortOrderChange(Qt::SortOrder order) -{ - emit sortOrderChanged(order); -} - -void DolphinViewController::indicateSortFoldersFirstChange(bool foldersFirst) -{ - emit sortFoldersFirstChanged(foldersFirst); -} - -void DolphinViewController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info) -{ - emit additionalInfoChanged(info); -} - -void DolphinViewController::setVersionControlActions(QList<QAction*> actions) -{ - m_versionControlActions = actions; -} - -QList<QAction*> DolphinViewController::versionControlActions(const KFileItemList& items) -{ - emit requestVersionControlActions(items); - // All view implementations are connected with the signal requestVersionControlActions() - // (see ViewExtensionFactory) and will invoke DolphinViewController::setVersionControlActions(), - // so that the context dependent actions can be returned. - return m_versionControlActions; -} - -void DolphinViewController::handleKeyPressEvent(QKeyEvent* event) -{ - if (!m_itemView) { - return; - } - - const QItemSelectionModel* selModel = m_itemView->selectionModel(); - const QModelIndex currentIndex = selModel->currentIndex(); - const bool trigger = currentIndex.isValid() - && ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)) - && !selModel->selectedIndexes().isEmpty(); - if (!trigger) { - return; - } - - // Collect selected files and selected directories - // as two separate lists. - QModelIndexList dirQueue; - const QModelIndexList indexList = selModel->selectedIndexes(); - KFileItemList fileOpenList; - foreach (const QModelIndex& index, indexList) { - if (itemForIndex(index).isDir()) { - dirQueue << index; - } else { - fileOpenList << itemForIndex(index); - } - } - - // Handle selected files - if (fileOpenList.count() == 1) { - emit itemTriggered(fileOpenList.first()); - } else { - KFileItemActions fileItemActions; - fileItemActions.runPreferredApplications(fileOpenList, "DesktopEntryName != 'dolphin'"); - } - - // Handle selected directories - if (dirQueue.count() == 1) { - // Open directory in the view - emit itemTriggered(itemForIndex(dirQueue[0])); - } else { - // Open directories in separate tabs - foreach(const QModelIndex& dir, dirQueue) { - emit tabRequested(itemForIndex(dir).url()); - } - } -} - -void DolphinViewController::replaceUrlByClipboard() -{ - const QClipboard* clipboard = QApplication::clipboard(); - QString text; - if (clipboard->mimeData(QClipboard::Selection)->hasText()) { - text = clipboard->mimeData(QClipboard::Selection)->text(); - } else if (clipboard->mimeData(QClipboard::Clipboard)->hasText()) { - text = clipboard->mimeData(QClipboard::Clipboard)->text(); - } - if (!text.isEmpty() && QDir::isAbsolutePath(text)) { - m_dolphinView->setUrl(KUrl(text)); - } -} - -void DolphinViewController::requestToolTipHiding() -{ - emit hideToolTip(); -} - -void DolphinViewController::emitItemTriggered(const KFileItem& item) -{ - emit itemTriggered(item); -} - -KFileItem DolphinViewController::itemForIndex(const QModelIndex& index) const -{ - if (m_itemView) { - QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_itemView->model()); - if (proxyModel) { - KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel()); - const QModelIndex dirIndex = proxyModel->mapToSource(index); - return dirModel->itemForIndex(dirIndex); - } - } - - return KFileItem(); -} - -void DolphinViewController::triggerItem(const QModelIndex& index) -{ - if (m_mouseButtons & Qt::LeftButton) { - const KFileItem item = itemForIndex(index); - if (index.isValid() && (index.column() == KDirModel::Name)) { - emit itemTriggered(item); - } else if (m_itemView) { - m_itemView->clearSelection(); - emit itemEntered(KFileItem()); - } - } -} - -void DolphinViewController::requestTab(const QModelIndex& index) -{ - if (m_mouseButtons & Qt::MidButton) { - const KFileItem item = itemForIndex(index); - const bool validRequest = index.isValid() && - (index.column() == KDirModel::Name) && - (item.isDir() || m_dolphinView->isTabsForFilesEnabled()); - if (validRequest) { - emit tabRequested(item.url()); - } - } -} - -void DolphinViewController::emitItemEntered(const QModelIndex& index) -{ - KFileItem item = itemForIndex(index); - if (!item.isNull()) { - emit itemEntered(item); - } -} - -void DolphinViewController::emitViewportEntered() -{ - emit viewportEntered(); -} - -void DolphinViewController::updateMouseButtonState() -{ - m_mouseButtons = QApplication::mouseButtons(); -} - -#include "dolphinviewcontroller.moc" diff --git a/src/views/dolphinviewcontroller.h b/src/views/dolphinviewcontroller.h deleted file mode 100644 index 0616e7fcd..000000000 --- a/src/views/dolphinviewcontroller.h +++ /dev/null @@ -1,311 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef DOLPHINVIEWCONTROLLER_H -#define DOLPHINVIEWCONTROLLER_H - -#include <views/dolphinview.h> -#include <KUrl> -#include <QObject> -#include <libdolphin_export.h> - -class QAbstractItemView; -class DolphinView; -class KUrl; -class QPoint; - -/** - * @brief Allows the view mode implementations (DolphinIconsView, DolphinDetailsView, DolphinColumnView) - * to do a limited control of the DolphinView. - * - * The DolphinView connects to the signals of DolphinViewController to react on changes - * that have been triggered by the view mode implementations. The view mode implementations - * have read access to the whole DolphinView by DolphinViewController::view(). Limited control of the - * DolphinView by the view mode implementations are defined by the public DolphinViewController methods. - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinViewController : public QObject -{ - Q_OBJECT - -public: - explicit DolphinViewController(DolphinView* dolphinView); - virtual ~DolphinViewController(); - - /** - * Allows read access for the view mode implementation - * to the DolphinView. - */ - const DolphinView* view() const; - - /** - * Requests the DolphinView to change the URL to \p url. The signal - * urlChangeRequested will be emitted. - */ - void requestUrlChange(const KUrl& url); - - /** - * Changes the current view mode implementation where the controller is working. - * This is only necessary for views like the column view, where internally - * several QAbstractItemView instances are used. - */ - void setItemView(QAbstractItemView* view); - QAbstractItemView* itemView() const; - - /** - * Requests a context menu for the position \a pos. DolphinView - * takes care itself to get the selected items depending from - * \a pos. It is possible to define a custom list of actions for - * the context menu by \a customActions. - */ - void triggerContextMenuRequest(const QPoint& pos, - const QList<QAction*>& customActions = QList<QAction*>()); - - /** - * Requests an activation of the DolphinView and emits the signal - * activated(). This method should be invoked by the view mode implementation - * if e. g. a mouse click on the view has been done. - */ - void requestActivation(); - - /** - * Indicates that URLs are dropped above a destination. The DolphinView - * will start the corresponding action (copy, move, link). - * @param destItem Item of the destination (can be null, see KFileItem::isNull()). - * @param event Drop event - */ - void indicateDroppedUrls(const KFileItem& destItem, QDropEvent* event); - - /** - * Informs the DolphinView about a sorting change done inside - * the view mode implementation. - */ - void indicateSortingChange(DolphinView::Sorting sorting); - - /** - * Informs the DolphinView about a sort order change done inside - * the view mode implementation. - */ - void indicateSortOrderChange(Qt::SortOrder order); - - /** - * Informs the DolphinView about a change between separate sorting - * (with folders first) and mixed sorting of files and folders done inside - * the view mode implementation. - */ - void indicateSortFoldersFirstChange(bool foldersFirst); - - /** - * Informs the DolphinView about an additional information change - * done inside the view mode implementation. - */ - void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info); - - /** - * Sets the available version control actions. Is called by the view - * mode implementation as soon as the DolphinView has requested them by the signal - * requestVersionControlActions(). - */ - void setVersionControlActions(QList<QAction*> actions); - - /** - * Emits the signal requestVersionControlActions(). The view mode implementation - * listens to the signal and will invoke a DolphinViewController::setVersionControlActions() - * and the result will be returned. - */ - QList<QAction*> versionControlActions(const KFileItemList& items); - - /** - * Must be be invoked in each view mode implementation whenever a key has been - * pressed. If the selection model of \a view is not empty and - * the return key has been pressed, the selected items will get triggered. - */ - void handleKeyPressEvent(QKeyEvent* event); - - /** - * Replaces the URL of the DolphinView with the content - * of the clipboard as URL. If the clipboard contains no text, - * nothing will be done. - */ - void replaceUrlByClipboard(); - - /** - * Requests the view mode implementation to hide tooltips. - */ - void requestToolTipHiding(); - - /** - * Emits the signal itemTriggered() for the item \a item. - * The method can be used by the view mode implementations to - * trigger an item directly without mouse interaction. - * If the item triggering is done by the mouse, it is recommended - * to use DolphinViewController::triggerItem(), as this will check - * the used mouse buttons to execute the correct action. - */ - void emitItemTriggered(const KFileItem& item); - - /** - * Returns the file item for the proxy index \a index of the DolphinView. - */ - KFileItem itemForIndex(const QModelIndex& index) const; - -public slots: - /** - * Emits the signal itemTriggered() if the file item for the index \a index - * is not null and the left mouse button has been pressed. If the item is - * null, the signal itemEntered() is emitted. - * The method should be invoked by the view mode implementations whenever the - * user has triggered an item with the mouse (see - * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()). - */ - void triggerItem(const QModelIndex& index); - - /** - * Emits the signal tabRequested(), if the file item for the index \a index - * represents a directory and when the middle mouse button has been pressed. - */ - void requestTab(const QModelIndex& index); - - /** - * Emits the signal itemEntered() if the file item for the index \a index - * is not null. The method should be invoked by the view mode implementation - * whenever the mouse cursor is above an item. - */ - void emitItemEntered(const QModelIndex& index); - - /** - * Emits the signal viewportEntered(). The method should be invoked by - * the view mode implementation whenever the mouse cursor is above the viewport. - */ - void emitViewportEntered(); - -signals: - void urlChangeRequested(const KUrl& url); - - /** - * Is emitted if a context menu should be opened (see triggerContextMenuRequest()). - * @param pos Position relative to the view widget where the - * context menu should be opened. It is recommended - * to get the corresponding model index from - * this position. - * @param customActions List of actions that is added to the context menu when - * the menu is opened above the viewport. - */ - void requestContextMenu(const QPoint& pos, QList<QAction*> customActions); - - /** - * Is emitted if the view has been activated by e. g. a mouse click. - */ - void activated(); - - /** - * Is emitted if URLs have been dropped to the destination - * path \a destPath. If the URLs have been dropped above an item of - * the destination path, the item is indicated by \a destItem - * (can be null, see KFileItem::isNull()). - */ - void urlsDropped(const KFileItem& destItem, - const KUrl& destPath, - QDropEvent* event); - - /** - * Is emitted if the sorting has been changed to \a sorting by - * the view mode implementation (see indicateSortingChanged(). - * The DolphinView connects to - * this signal to update its menu action. - */ - void sortingChanged(DolphinView::Sorting sorting); - - /** - * Is emitted if the sort order has been changed to \a order - * by the view mode implementation (see indicateSortOrderChanged(). - * The DolphinView connects - * to this signal to update its menu actions. - */ - void sortOrderChanged(Qt::SortOrder order); - - /** - * Is emitted if 'sort folders first' has been changed to \a foldersFirst - * by the view mode implementation (see indicateSortOrderChanged(). - * The DolphinView connects - * to this signal to update its menu actions. - */ - void sortFoldersFirstChanged(bool foldersFirst); - - /** - * Is emitted if the additional info has been changed to \a info - * by the view mode implementation. The DolphinView connects - * to this signal to update its menu actions. - */ - void additionalInfoChanged(const KFileItemDelegate::InformationList& info); - - /** - * Is emitted if the item \a item should be triggered. The abstract - * Dolphin view connects to this signal. If the item represents a directory, - * the directory is opened. On a file the corresponding application is opened. - * The item is null (see KFileItem::isNull()), when clicking on the viewport itself. - */ - void itemTriggered(const KFileItem& item); - - /** - * Is emitted if the mouse cursor has entered the item - * given by \a index (see emitItemEntered()). - */ - void itemEntered(const KFileItem& item); - - /** - * Is emitted if a new tab should be opened for the URL \a url. - */ - void tabRequested(const KUrl& url); - - /** - * Is emitted if the mouse cursor has entered - * the viewport (see emitViewportEntered()). - */ - void viewportEntered(); - - /** - * Is emitted, if DolphinViewController::requestToolTipHiding() is invoked - * and requests to hide all tooltips. - */ - void hideToolTip(); - - /** - * Is emitted if pending previews should be canceled (e. g. because of an URL change). - */ - void cancelPreviews(); - - /** - * Requests the view mode implementation to invoke DolphinViewController::setVersionControlActions(), - * so that they can be returned with DolphinViewController::versionControlActions() for - * the DolphinView. - */ - void requestVersionControlActions(const KFileItemList& items); - -private slots: - void updateMouseButtonState(); - -private: - static Qt::MouseButtons m_mouseButtons; // TODO: this is a workaround until Qt-issue 176832 has been fixed - - DolphinView* m_dolphinView; - QAbstractItemView* m_itemView; - QList<QAction*> m_versionControlActions; -}; - -#endif diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index 830884dc2..c0c6ad58c 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -65,12 +65,9 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : QLabel* editLabel = 0; if (m_renameOneItem) { - m_newName = items.first().name(); - editLabel = new QLabel(i18nc("@label:textbox", "Rename the item <filename>%1</filename> to:", - KStringHandler::csqueeze(m_newName)), page); - if (m_newName.size() > 40) { - editLabel->setToolTip(m_newName); // Set the filename as a the tool tip... - } + m_newName = items.first().name(); + editLabel = new QLabel(i18nc("@label:textbox", "Rename the item <filename>%1</filename> to:", m_newName), + page); } else { m_newName = i18nc("@info:status", "New name #"); editLabel = new QLabel(i18ncp("@label:textbox", diff --git a/src/views/selectionmanager.cpp b/src/views/selectionmanager.cpp deleted file mode 100644 index 7a9e81412..000000000 --- a/src/views/selectionmanager.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[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 "selectionmanager.h" - -#include "dolphinmodel.h" -#include "dolphin_generalsettings.h" -#include "selectiontoggle.h" -#include "settings/dolphinsettings.h" -#include <KDirModel> -#include <KGlobalSettings> -#include <KIconEffect> - -#include <QAbstractButton> -#include <QAbstractItemView> -#include <QAbstractProxyModel> -#include <QApplication> -#include <QModelIndex> -#include <QPainter> -#include <QPaintEvent> -#include <QRect> -#include <QTimeLine> - -SelectionManager::SelectionManager(QAbstractItemView* parent) : - QObject(parent), - m_view(parent), - m_toggle(0), - m_connected(false), - m_appliedPointingHandCursor(false) -{ - connect(parent, SIGNAL(entered(const QModelIndex&)), - this, SLOT(slotEntered(const QModelIndex&))); - connect(parent, SIGNAL(viewportEntered()), - this, SLOT(slotViewportEntered())); - - const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - if (settings->showSelectionToggle()) { - m_toggle = new SelectionToggle(m_view->viewport()); - m_toggle->setCheckable(true); - m_toggle->hide(); - connect(m_toggle, SIGNAL(clicked(bool)), - this, SLOT(setItemSelected(bool))); - m_toggle->installEventFilter(this); - } - - m_view->viewport()->installEventFilter(this); -} - -SelectionManager::~SelectionManager() -{ -} - -bool SelectionManager::eventFilter(QObject* watched, QEvent* event) -{ - if (watched == m_view->viewport()) { - switch (event->type()) { - case QEvent::Leave: - if (m_toggle) { - m_toggle->hide(); - } - restoreCursor(); - break; - - case QEvent::MouseButtonPress: { - // Set the toggle invisible, if a mouse button has been pressed - // outside the toggle boundaries. This e.g. assures, that the toggle - // gets invisible during dragging items. - if (m_toggle) { - const QRect toggleBounds(m_toggle->mapToGlobal(QPoint(0, 0)), m_toggle->size()); - m_toggle->setVisible(toggleBounds.contains(QCursor::pos())); - } - break; - } - - default: - break; - } - } else if (watched == m_toggle) { - switch (event->type()) { - case QEvent::Enter: - QApplication::changeOverrideCursor(Qt::ArrowCursor); - break; - - case QEvent::Leave: - QApplication::changeOverrideCursor(Qt::PointingHandCursor); - break; - - default: - break; - } - } - - return QObject::eventFilter(watched, event); -} - -void SelectionManager::reset() -{ - if (m_toggle) { - m_toggle->reset(); - } -} - -void SelectionManager::slotEntered(const QModelIndex& index) -{ - const bool isSelectionCandidate = index.isValid() && - (index.column() == DolphinModel::Name) && - (QApplication::mouseButtons() == Qt::NoButton); - - restoreCursor(); - if (isSelectionCandidate && KGlobalSettings::singleClick()) { - applyPointingHandCursor(); - } - - if (isSelectionCandidate) { - if (!m_connected) { - connect(m_view->model(), SIGNAL(rowsRemoved(const QModelIndex&, int, int)), - this, SLOT(slotRowsRemoved(const QModelIndex&, int, int))); - connect(m_view->selectionModel(), - SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, - SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&))); - m_connected = true; - } - } else { - disconnect(m_view->model(), SIGNAL(rowsRemoved(const QModelIndex&, int, int)), - this, SLOT(slotRowsRemoved(const QModelIndex&, int, int))); - disconnect(m_view->selectionModel(), - SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), - this, - SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&))); - m_connected = false; - } - - if (!m_toggle) { - return; - } - - m_toggle->hide(); - if (isSelectionCandidate) { - m_toggle->setUrl(urlForIndex(index)); - - // Increase the size of the toggle for large items - const int iconHeight = m_view->iconSize().height(); - - int toggleSize = KIconLoader::SizeSmall; - if (iconHeight >= KIconLoader::SizeEnormous) { - toggleSize = KIconLoader::SizeMedium; - } else if (iconHeight >= KIconLoader::SizeLarge) { - toggleSize = KIconLoader::SizeSmallMedium; - } - - // Add a small invisible margin, if the item-height is nearly - // equal to the toggleSize (#169494). - const QRect rect = m_view->visualRect(index); - int margin = (rect.height() - toggleSize) / 2; - if (margin > 4) { - margin = 0; - } - toggleSize += 2 * margin; - m_toggle->setMargin(margin); - m_toggle->resize(toggleSize, toggleSize); - m_toggle->move(rect.topLeft()); - - QItemSelectionModel* selModel = m_view->selectionModel(); - m_toggle->setChecked(selModel->isSelected(index)); - m_toggle->show(); - } else { - m_toggle->setUrl(KUrl()); - } -} - -void SelectionManager::slotViewportEntered() -{ - if (m_toggle) { - m_toggle->hide(); - } - restoreCursor(); -} - -void SelectionManager::setItemSelected(bool selected) -{ - emit selectionChanged(); - - if (m_toggle && !m_toggle->url().isEmpty()) { - const QModelIndex index = indexForUrl(m_toggle->url()); - if (index.isValid()) { - QItemSelectionModel* selModel = m_view->selectionModel(); - if (selected) { - selModel->select(index, QItemSelectionModel::Select); - } else { - selModel->select(index, QItemSelectionModel::Deselect); - } - selModel->setCurrentIndex(index, QItemSelectionModel::Current); - } - } -} - -void SelectionManager::slotRowsRemoved(const QModelIndex& parent, int start, int end) -{ - Q_UNUSED(parent); - Q_UNUSED(start); - Q_UNUSED(end); - if (m_toggle) { - m_toggle->hide(); - } - restoreCursor(); -} - -void SelectionManager::slotSelectionChanged(const QItemSelection& selected, - const QItemSelection& deselected) -{ - // The selection has been changed outside the scope of the selection manager - // (e. g. by the rubberband or the "Select All" action). Take care updating - // the state of the toggle button. - if (m_toggle && !m_toggle->url().isEmpty()) { - const QModelIndex index = indexForUrl(m_toggle->url()); - if (index.isValid()) { - if (selected.contains(index)) { - m_toggle->setChecked(true); - } - - if (deselected.contains(index)) { - m_toggle->setChecked(false); - } - } - } -} - -KUrl SelectionManager::urlForIndex(const QModelIndex& index) const -{ - QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_view->model()); - KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel()); - const QModelIndex dirIndex = proxyModel->mapToSource(index); - return dirModel->itemForIndex(dirIndex).url(); -} - -const QModelIndex SelectionManager::indexForUrl(const KUrl& url) const -{ - QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_view->model()); - KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel()); - const QModelIndex dirIndex = dirModel->indexForUrl(url); - return proxyModel->mapFromSource(dirIndex); -} - - -void SelectionManager::applyPointingHandCursor() -{ - if (!m_appliedPointingHandCursor) { - QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); - m_appliedPointingHandCursor = true; - } -} - -void SelectionManager::restoreCursor() -{ - if (m_appliedPointingHandCursor) { - QApplication::restoreOverrideCursor(); - m_appliedPointingHandCursor = false; - } -} - -#include "selectionmanager.moc" diff --git a/src/views/selectionmanager.h b/src/views/selectionmanager.h deleted file mode 100644 index 7a3a1946a..000000000 --- a/src/views/selectionmanager.h +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef SELECTIONMANAGER_H -#define SELECTIONMANAGER_H - -#include <KFileItem> - -#include <QObject> - -class QAbstractItemView; -class QModelIndex; -class QItemSelection; -class SelectionToggle; - -/** - * @brief Allows to select and deselect items for item views. - * - * Whenever an item is hovered by the mouse, a toggle button is shown - * which allows to select/deselect the current item. - */ -class SelectionManager : public QObject -{ - Q_OBJECT - -public: - SelectionManager(QAbstractItemView* parent); - virtual ~SelectionManager(); - virtual bool eventFilter(QObject* watched, QEvent* event); - -public slots: - /** - * Resets the selection manager so that the toggle button gets - * invisible. - */ - void reset(); - -signals: - /** Is emitted if the selection has been changed by the toggle button. */ - void selectionChanged(); - -private slots: - void slotEntered(const QModelIndex& index); - void slotViewportEntered(); - void setItemSelected(bool selected); - void slotRowsRemoved(const QModelIndex& parent, int start, int end); - void slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); - -private: - KUrl urlForIndex(const QModelIndex& index) const; - const QModelIndex indexForUrl(const KUrl& url) const; - void applyPointingHandCursor(); - void restoreCursor(); - -private: - QAbstractItemView* m_view; - SelectionToggle* m_toggle; - bool m_connected; - bool m_appliedPointingHandCursor; -}; - -#endif diff --git a/src/views/selectiontoggle.cpp b/src/views/selectiontoggle.cpp deleted file mode 100644 index d602600c5..000000000 --- a/src/views/selectiontoggle.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[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 "selectiontoggle.h" - -#include <KGlobalSettings> -#include <KIcon> -#include <KIconLoader> -#include <KIconEffect> -#include <KLocale> - -#include <QApplication> -#include <QPainter> -#include <QPaintEvent> -#include <QRect> -#include <QTimer> -#include <QTimeLine> - -#include <KDebug> - -SelectionToggle::SelectionToggle(QWidget* parent) : - QAbstractButton(parent), - m_isHovered(false), - m_leftMouseButtonPressed(false), - m_fadingValue(0), - m_margin(0), - m_icon(), - m_fadingTimeLine(0) -{ - setFocusPolicy(Qt::NoFocus); - parent->installEventFilter(this); - resize(sizeHint()); - setIconOverlay(isChecked()); - connect(this, SIGNAL(toggled(bool)), - this, SLOT(setIconOverlay(bool))); - connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), - this, SLOT(refreshIcon())); -} - -SelectionToggle::~SelectionToggle() -{ -} - -QSize SelectionToggle::sizeHint() const -{ - return QSize(16, 16); -} - -void SelectionToggle::reset() -{ - m_url = KUrl(); - hide(); -} - -void SelectionToggle::setUrl(const KUrl& url) -{ - m_url = url; - if (!url.isEmpty()) { - startFading(); - } -} - -void SelectionToggle::setMargin(int margin) -{ - if (margin != m_margin) { - m_margin = margin; - update(); - } -} - -int SelectionToggle::margin() const -{ - return m_margin; -} - -KUrl SelectionToggle::url() const -{ - return m_url; -} - -void SelectionToggle::setVisible(bool visible) -{ - QAbstractButton::setVisible(visible); - - stopFading(); - if (visible) { - startFading(); - } - -} - -bool SelectionToggle::eventFilter(QObject* obj, QEvent* event) -{ - if ((obj == parent()) && (event->type() == QEvent::MouseMove) && m_leftMouseButtonPressed) { - // Don't forward mouse move events to the viewport, - // otherwise a rubberband selection will be shown when - // clicking on the selection toggle and moving the mouse - // above the viewport. - return true; - } - - return QAbstractButton::eventFilter(obj, event); -} - -void SelectionToggle::enterEvent(QEvent* event) -{ - QAbstractButton::enterEvent(event); - - // if the mouse cursor is above the selection toggle, display - // it immediately without fading timer - m_isHovered = true; - if (m_fadingTimeLine) { - m_fadingTimeLine->stop(); - } - m_fadingValue = 255; - setToolTip(isChecked() ? i18nc("@info:tooltip", "Deselect Item") : - i18nc("@info:tooltip", "Select Item")); - update(); -} - -void SelectionToggle::leaveEvent(QEvent* event) -{ - QAbstractButton::leaveEvent(event); - - m_isHovered = false; - update(); -} - -void SelectionToggle::mousePressEvent(QMouseEvent* event) -{ - QAbstractButton::mousePressEvent(event); - m_leftMouseButtonPressed = (event->buttons() & Qt::LeftButton); -} - -void SelectionToggle::mouseReleaseEvent(QMouseEvent* event) -{ - QAbstractButton::mouseReleaseEvent(event); - m_leftMouseButtonPressed = (event->buttons() & Qt::LeftButton); -} - -void SelectionToggle::resizeEvent(QResizeEvent* event) -{ - QAbstractButton::resizeEvent(event); - setIconOverlay(isChecked()); -} - -void SelectionToggle::paintEvent(QPaintEvent* event) -{ - QPainter painter(this); - painter.setClipRect(event->rect()); - - // draw the icon overlay - const QPoint pos(m_margin, m_margin); - if (m_isHovered) { - KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); - QPixmap activeIcon = iconEffect->apply(m_icon, KIconLoader::Desktop, KIconLoader::ActiveState); - painter.drawPixmap(pos, activeIcon); - } else { - if (m_fadingValue < 255) { - // apply an alpha mask respecting the fading value to the icon - QPixmap icon = m_icon; - QPixmap alphaMask(icon.width(), icon.height()); - const QColor color(m_fadingValue, m_fadingValue, m_fadingValue); - alphaMask.fill(color); - icon.setAlphaChannel(alphaMask); - painter.drawPixmap(pos, icon); - } else { - // no fading is required - painter.drawPixmap(pos, m_icon); - } - } - -} - -void SelectionToggle::setFadingValue(int value) -{ - m_fadingValue = value; - if (m_fadingValue >= 255) { - Q_ASSERT(m_fadingTimeLine); - m_fadingTimeLine->stop(); - } - update(); -} - -void SelectionToggle::setIconOverlay(bool checked) -{ - const char* icon = checked ? "list-remove" : "list-add"; - const int size = qMin(width() - 2 * m_margin, height() - 2 * m_margin); - m_icon = KIconLoader::global()->loadIcon(icon, - KIconLoader::NoGroup, - size); - update(); -} - -void SelectionToggle::refreshIcon() -{ - setIconOverlay(isChecked()); -} - -void SelectionToggle::startFading() -{ - Q_ASSERT(!m_fadingTimeLine); - - const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects; - const int duration = animate ? 600 : 1; - - m_fadingTimeLine = new QTimeLine(duration, this); - connect(m_fadingTimeLine, SIGNAL(frameChanged(int)), - this, SLOT(setFadingValue(int))); - m_fadingTimeLine->setFrameRange(0, 255); - m_fadingTimeLine->start(); - m_fadingValue = 0; -} - -void SelectionToggle::stopFading() -{ - if (m_fadingTimeLine) { - m_fadingTimeLine->stop(); - delete m_fadingTimeLine; - m_fadingTimeLine = 0; - } - m_fadingValue = 0; -} - -#include "selectiontoggle.moc" diff --git a/src/views/selectiontoggle.h b/src/views/selectiontoggle.h deleted file mode 100644 index 221ab0745..000000000 --- a/src/views/selectiontoggle.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef SELECTIONTOGGLE_H -#define SELECTIONTOGGLE_H - -#include <KUrl> - -#include <QAbstractButton> -#include <QPixmap> - -class QTimeLine; - -/** - * @brief Toggle button for changing the selection of an hovered item. - * - * The toggle button is visually invisible until it is displayed at least - * for one second. - * - * @see SelectionManager - */ -class SelectionToggle : public QAbstractButton -{ - Q_OBJECT - -public: - explicit SelectionToggle(QWidget* parent); - virtual ~SelectionToggle(); - virtual QSize sizeHint() const; - - /** - * Resets the selection toggle so that it is hidden and stays - * visually invisible for at least one second after it is shown again. - */ - void reset(); - - void setUrl(const KUrl& url); - KUrl url() const; - - /** - * Sets the margin around the selection-icon in pixels. Per default - * the value is 0. - */ - void setMargin(int margin); - int margin() const; - -public slots: - virtual void setVisible(bool visible); - -protected: - virtual bool eventFilter(QObject* obj, QEvent* event); - virtual void enterEvent(QEvent* event); - virtual void leaveEvent(QEvent* event); - virtual void mousePressEvent(QMouseEvent* event); - virtual void mouseReleaseEvent(QMouseEvent* event); - virtual void resizeEvent(QResizeEvent* event); - virtual void paintEvent(QPaintEvent* event); - -private slots: - /** - * Sets the alpha value for the fading animation and is - * connected with m_fadingTimeLine. - */ - void setFadingValue(int value); - - void setIconOverlay(bool checked); - void refreshIcon(); - -private: - void startFading(); - void stopFading(); - -private: - bool m_isHovered; - bool m_leftMouseButtonPressed; - int m_fadingValue; - int m_margin; - QPixmap m_icon; - QTimeLine* m_fadingTimeLine; - KUrl m_url; -}; - -#endif diff --git a/src/views/tooltips/tooltipmanager.cpp b/src/views/tooltips/tooltipmanager.cpp index 69ed1e3be..e532bee82 100644 --- a/src/views/tooltips/tooltipmanager.cpp +++ b/src/views/tooltips/tooltipmanager.cpp @@ -26,19 +26,14 @@ #include <QApplication> #include <QDesktopWidget> +#include <QLayout> #include <QScrollArea> #include <QScrollBar> #include <QTimer> -#include <views/dolphinmodel.h> -#include <views/dolphinsortfilterproxymodel.h> - -ToolTipManager::ToolTipManager(QAbstractItemView* parent, - DolphinSortFilterProxyModel* model) : +ToolTipManager::ToolTipManager(QWidget* parent) : QObject(parent), m_view(parent), - m_dolphinModel(0), - m_proxyModel(model), m_showToolTipTimer(0), m_contentRetrievalTimer(0), m_fileMetaDataToolTip(0), @@ -48,11 +43,11 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent, m_item(), m_itemRect() { - m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel()); - connect(parent, SIGNAL(entered(const QModelIndex&)), - this, SLOT(requestToolTip(const QModelIndex&))); - connect(parent, SIGNAL(viewportEntered()), - this, SLOT(hideToolTip())); + //m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel()); + //connect(parent, SIGNAL(entered(const QModelIndex&)), + // this, SLOT(requestToolTip(const QModelIndex&))); + //connect(parent, SIGNAL(viewportEntered()), + // this, SLOT(hideToolTip())); // Initialize timers m_showToolTipTimer = new QTimer(this); @@ -70,14 +65,14 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent, // When the mousewheel is used, the items don't get a hovered indication // (Qt-issue #200665). To assure that the tooltip still gets hidden, // the scrollbars are observed. - connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), + /*connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip())); connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(hideToolTip())); + this, SLOT(hideToolTip()));*/ Q_ASSERT(m_view); - m_view->viewport()->installEventFilter(this); - m_view->installEventFilter(this); + //m_view->viewport()->installEventFilter(this); + //m_view->installEventFilter(this); } ToolTipManager::~ToolTipManager() @@ -103,7 +98,7 @@ void ToolTipManager::hideToolTip() bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) { - if (watched == m_view->viewport()) { + /*if (watched == m_view->viewport()) { switch (event->type()) { case QEvent::Leave: case QEvent::MouseButtonPress: @@ -114,24 +109,25 @@ bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) } } else if ((watched == m_view) && (event->type() == QEvent::KeyPress)) { hideToolTip(); - } + }*/ return QObject::eventFilter(watched, event); } void ToolTipManager::requestToolTip(const QModelIndex& index) { + Q_UNUSED(index); hideToolTip(); // Only request a tooltip for the name column and when no selection or // drag & drop operation is done (indicated by the left mouse button) - if ((index.column() == DolphinModel::Name) && !(QApplication::mouseButtons() & Qt::LeftButton)) { - m_itemRect = m_view->visualRect(index); - const QPoint pos = m_view->viewport()->mapToGlobal(m_itemRect.topLeft()); + if (!(QApplication::mouseButtons() & Qt::LeftButton)) { + m_itemRect = QRect(); //m_view->visualRect(index); + const QPoint pos; // = m_view->viewport()->mapToGlobal(m_itemRect.topLeft()); m_itemRect.moveTo(pos); - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - m_item = m_dolphinModel->itemForIndex(dirIndex); + //const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + //m_item = m_dolphinModel->itemForIndex(dirIndex); // Only start the retrieving of the content, when the mouse has been over this // item for 200 milliseconds. This prevents a lot of useless preview jobs and diff --git a/src/views/tooltips/tooltipmanager.h b/src/views/tooltips/tooltipmanager.h index f8bcd3dfd..11ef3d3ac 100644 --- a/src/views/tooltips/tooltipmanager.h +++ b/src/views/tooltips/tooltipmanager.h @@ -44,8 +44,7 @@ class ToolTipManager : public QObject Q_OBJECT public: - explicit ToolTipManager(QAbstractItemView* parent, - DolphinSortFilterProxyModel* model); + explicit ToolTipManager(QWidget* parent); virtual ~ToolTipManager(); public slots: @@ -68,7 +67,7 @@ private slots: void showToolTip(); private: - QAbstractItemView* m_view; + QWidget* m_view; DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp index 62f50f30b..02329866f 100644 --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -35,23 +35,21 @@ #include <QMutexLocker> #include <QTimer> -#include <views/dolphinmodel.h> - -VersionControlObserver::VersionControlObserver(QAbstractItemView* view) : +VersionControlObserver::VersionControlObserver(QWidget* view) : QObject(view), m_pendingItemStatesUpdate(false), m_versionedDirectory(false), m_silentUpdate(false), m_view(view), - m_dirLister(0), - m_dolphinModel(0), + //m_dirLister(0), + //m_dolphinModel(0), m_dirVerificationTimer(0), m_plugin(0), m_updateItemStatesThread(0) { Q_ASSERT(view); - QAbstractProxyModel* proxyModel = qobject_cast<QAbstractProxyModel*>(view->model()); + /*QAbstractProxyModel* proxyModel = qobject_cast<QAbstractProxyModel*>(view->model()); m_dolphinModel = proxyModel ? qobject_cast<DolphinModel*>(proxyModel->sourceModel()) : qobject_cast<DolphinModel*>(view->model()); @@ -71,7 +69,7 @@ VersionControlObserver::VersionControlObserver(QAbstractItemView* view) : m_dirVerificationTimer->setInterval(500); connect(m_dirVerificationTimer, SIGNAL(timeout()), this, SLOT(verifyDirectory())); - } + }*/ } VersionControlObserver::~VersionControlObserver() @@ -133,7 +131,7 @@ void VersionControlObserver::silentDirectoryVerification() void VersionControlObserver::verifyDirectory() { - const KUrl versionControlUrl = m_dirLister->url(); + const KUrl versionControlUrl; // = m_dirLister->url(); if (!versionControlUrl.isLocalFile()) { return; } @@ -143,7 +141,7 @@ void VersionControlObserver::verifyDirectory() } m_plugin = searchPlugin(versionControlUrl); - if (m_plugin) { + /*if (m_plugin) { connect(m_plugin, SIGNAL(versionStatesChanged()), this, SLOT(silentDirectoryVerification())); connect(m_plugin, SIGNAL(infoMessage(QString)), @@ -176,7 +174,7 @@ void VersionControlObserver::verifyDirectory() this, SLOT(delayedDirectoryVerification())); disconnect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), this, SLOT(delayedDirectoryVerification())); - } + }*/ } void VersionControlObserver::slotThreadFinished() @@ -195,7 +193,7 @@ void VersionControlObserver::slotThreadFinished() // (a detailed description of the root cause is given in the class KFilePreviewGenerator // from kdelibs). To bypass this bottleneck, the signals of the model are temporary blocked. // This works as the update of the data does not require a relayout of the views used in Dolphin. - const bool signalsBlocked = m_dolphinModel->signalsBlocked(); + /*const bool signalsBlocked = m_dolphinModel->signalsBlocked(); m_dolphinModel->blockSignals(true); const QList<ItemState> itemStates = m_updateItemStatesThread->itemStates(); @@ -218,7 +216,7 @@ void VersionControlObserver::slotThreadFinished() if (m_pendingItemStatesUpdate) { m_pendingItemStatesUpdate = false; updateItemStates(); - } + }*/ } void VersionControlObserver::updateItemStates() @@ -249,7 +247,9 @@ void VersionControlObserver::updateItemStates() void VersionControlObserver::addDirectory(const QModelIndex& parentIndex, QList<ItemState>& itemStates) { - const int rowCount = m_dolphinModel->rowCount(parentIndex); + Q_UNUSED(parentIndex); + Q_UNUSED(itemStates); + /*const int rowCount = m_dolphinModel->rowCount(parentIndex); for (int row = 0; row < rowCount; ++row) { const QModelIndex index = m_dolphinModel->index(row, DolphinModel::Version, parentIndex); addDirectory(index, itemStates); @@ -260,7 +260,7 @@ void VersionControlObserver::addDirectory(const QModelIndex& parentIndex, QList< itemState.version = KVersionControlPlugin::UnversionedVersion; itemStates.append(itemState); - } + }*/ } KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& directory) const @@ -296,7 +296,8 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director // Verify whether the current directory contains revision information // like .svn, .git, ... - foreach (KVersionControlPlugin* plugin, plugins) { + Q_UNUSED(directory); + /*foreach (KVersionControlPlugin* plugin, plugins) { // Use the KDirLister cache to check for .svn, .git, ... files KUrl dirUrl(directory); KUrl fileUrl = dirUrl; @@ -324,14 +325,14 @@ KVersionControlPlugin* VersionControlObserver::searchPlugin(const KUrl& director upUrl = dirUrl.upUrl(); } } - } + }*/ return 0; } bool VersionControlObserver::isVersioned() const { - return m_dolphinModel->hasVersionData() && m_plugin; + return false; //m_dolphinModel->hasVersionData() && m_plugin; } #include "versioncontrolobserver.moc" diff --git a/src/views/versioncontrol/versioncontrolobserver.h b/src/views/versioncontrol/versioncontrolobserver.h index 214c072cd..71405fabd 100644 --- a/src/views/versioncontrol/versioncontrolobserver.h +++ b/src/views/versioncontrol/versioncontrolobserver.h @@ -51,7 +51,7 @@ class LIBDOLPHINPRIVATE_EXPORT VersionControlObserver : public QObject Q_OBJECT public: - VersionControlObserver(QAbstractItemView* view); + VersionControlObserver(QWidget* parent); virtual ~VersionControlObserver(); QList<QAction*> contextMenuActions(const KFileItemList& items) const; @@ -133,9 +133,9 @@ private: bool m_silentUpdate; // if true, no messages will be send during the update // of version states - QAbstractItemView* m_view; - KDirLister* m_dirLister; - DolphinModel* m_dolphinModel; + QWidget* m_view; + //KDirLister* m_dirLister; + //DolphinModel* m_dolphinModel; QTimer* m_dirVerificationTimer; diff --git a/src/views/viewextensionsfactory.cpp b/src/views/viewextensionsfactory.cpp deleted file mode 100644 index a52871ff4..000000000 --- a/src/views/viewextensionsfactory.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Peter Penz <[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 "viewextensionsfactory.h" - -#include "dolphinfileitemdelegate.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphinview.h" -#include "dolphinviewcontroller.h" -#include "dolphinviewautoscroller.h" -#include "folderexpander.h" -#include "selectionmanager.h" -#include "settings/dolphinsettings.h" -#include "tooltips/tooltipmanager.h" -#include "versioncontrol/versioncontrolobserver.h" -#include "viewmodecontroller.h" - -#include "dolphin_generalsettings.h" - -#include <KDirLister> -#include <KDirModel> -#include <KFilePreviewGenerator> -#include <QAbstractItemView> -#include <QApplication> - -ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController) : - QObject(view), - m_view(view), - m_dolphinViewController(dolphinViewController), - m_toolTipManager(0), - m_previewGenerator(0), - m_selectionManager(0), - m_autoScroller(0), - m_fileItemDelegate(0), - m_versionControlObserver(0) -{ - view->setSelectionMode(QAbstractItemView::ExtendedSelection); - - GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - - // initialize tooltips - if (settings->showToolTips()) { - DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(view->model()); - m_toolTipManager = new ToolTipManager(view, proxyModel); - - connect(dolphinViewController, SIGNAL(hideToolTip()), - m_toolTipManager, SLOT(hideToolTip())); - } - - // initialize preview generator - Q_ASSERT(view->iconSize().isValid()); - m_previewGenerator = new KFilePreviewGenerator(view); - m_previewGenerator->setPreviewShown(dolphinViewController->view()->showPreview()); - connect(viewModeController, SIGNAL(zoomLevelChanged(int)), - this, SLOT(slotZoomLevelChanged())); - connect(viewModeController, SIGNAL(cancelPreviews()), - this, SLOT(cancelPreviews())); - - // slotPreviewChanged() is connected as Qt::QueuedConnection to prevent performance - // issues when the directory lister changes its URL after the preview-changes have - // been applied. Usecase: Switch from directory A having no previews to - // directory B with previews (see sequence in DolphinView::setUrl()). - connect(dolphinViewController->view(), SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged()), - Qt::QueuedConnection); - - // initialize selection manager - m_selectionManager = new SelectionManager(view); - connect(m_selectionManager, SIGNAL(selectionChanged()), - this, SLOT(requestActivation())); - connect(viewModeController, SIGNAL(urlChanged(const KUrl&)), - m_selectionManager, SLOT(reset())); - - // initialize auto scroller - m_autoScroller = new DolphinViewAutoScroller(view); - - // initialize file item delegate - m_fileItemDelegate = new DolphinFileItemDelegate(view); - m_fileItemDelegate->setShowToolTipWhenElided(false); - view->setItemDelegate(m_fileItemDelegate); - - // initialize version control observer - const DolphinView* dolphinView = dolphinViewController->view(); - m_versionControlObserver = new VersionControlObserver(view); - connect(m_versionControlObserver, SIGNAL(infoMessage(const QString&)), - dolphinView, SIGNAL(infoMessage(const QString&))); - connect(m_versionControlObserver, SIGNAL(errorMessage(const QString&)), - dolphinView, SIGNAL(errorMessage(const QString&))); - connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(const QString&)), - dolphinView, SIGNAL(operationCompletedMessage(const QString&))); - connect(dolphinViewController, SIGNAL(requestVersionControlActions(const KFileItemList&)), - this, SLOT(slotRequestVersionControlActions(const KFileItemList&))); - - // react on view property changes - connect(dolphinView, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(dolphinView, SIGNAL(sortingChanged(DolphinView::Sorting)), - this, SLOT(slotSortingChanged(DolphinView::Sorting))); - connect(dolphinView, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(dolphinView, SIGNAL(sortFoldersFirstChanged(bool)), - this, SLOT(slotSortFoldersFirstChanged(bool))); - - // Give the view the ability to auto-expand its directories on hovering - // (the column view takes care about this itself). If the details view - // uses expandable folders, the auto-expanding should be used always. - m_folderExpander = new FolderExpander(view, proxyModel()); - m_folderExpander->setEnabled(settings->autoExpandFolders()); - connect(m_folderExpander, SIGNAL(enterDir(const QModelIndex&)), - dolphinViewController, SLOT(triggerItem(const QModelIndex&))); - - // react on namefilter changes - connect(viewModeController, SIGNAL(nameFilterChanged(const QString&)), - this, SLOT(slotNameFilterChanged(const QString&))); - - view->viewport()->installEventFilter(this); -} - -ViewExtensionsFactory::~ViewExtensionsFactory() -{ -} - -void ViewExtensionsFactory::handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous) -{ - m_autoScroller->handleCurrentIndexChange(current, previous); -} - -DolphinFileItemDelegate* ViewExtensionsFactory::fileItemDelegate() const -{ - return m_fileItemDelegate; -} - -void ViewExtensionsFactory::setAutoFolderExpandingEnabled(bool enabled) -{ - m_folderExpander->setEnabled(enabled); -} - -bool ViewExtensionsFactory::autoFolderExpandingEnabled() const -{ - return m_folderExpander->enabled(); -} - -bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event) -{ - Q_UNUSED(watched); - if ((event->type() == QEvent::Wheel) && m_selectionManager) { - m_selectionManager->reset(); - } - return false; -} - -void ViewExtensionsFactory::slotZoomLevelChanged() -{ - m_previewGenerator->updateIcons(); - if (m_selectionManager) { - m_selectionManager->reset(); - } -} - -void ViewExtensionsFactory::cancelPreviews() -{ - m_previewGenerator->cancelPreviews(); -} - -void ViewExtensionsFactory::slotShowPreviewChanged() -{ - const bool show = m_dolphinViewController->view()->showPreview(); - m_previewGenerator->setPreviewShown(show); -} - -void ViewExtensionsFactory::slotShowHiddenFilesChanged() -{ - KDirModel* dirModel = static_cast<KDirModel*>(proxyModel()->sourceModel()); - KDirLister* dirLister = dirModel->dirLister(); - - dirLister->stop(); - - const bool show = m_dolphinViewController->view()->showHiddenFiles(); - dirLister->setShowingDotFiles(show); - - const KUrl url = dirLister->url(); - if (url.isValid()) { - dirLister->openUrl(url, KDirLister::NoFlags); - } -} - -void ViewExtensionsFactory::slotSortingChanged(DolphinView::Sorting sorting) -{ - proxyModel()->setSorting(sorting); -} - -void ViewExtensionsFactory::slotSortOrderChanged(Qt::SortOrder order) -{ - proxyModel()->setSortOrder(order); -} - -void ViewExtensionsFactory::slotSortFoldersFirstChanged(bool foldersFirst) -{ - proxyModel()->setSortFoldersFirst(foldersFirst); -} - -void ViewExtensionsFactory::slotNameFilterChanged(const QString& nameFilter) -{ - proxyModel()->setFilterFixedString(nameFilter); -} - -void ViewExtensionsFactory::slotRequestVersionControlActions(const KFileItemList& items) -{ - QList<QAction*> actions; - if (items.isEmpty()) { - const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel()->sourceModel()); - const KUrl url = dirModel->dirLister()->url(); - actions = m_versionControlObserver->contextMenuActions(url.path(KUrl::AddTrailingSlash)); - } else { - actions = m_versionControlObserver->contextMenuActions(items); - } - m_dolphinViewController->setVersionControlActions(actions); -} - -void ViewExtensionsFactory::requestActivation() -{ - m_dolphinViewController->requestActivation(); -} - -DolphinSortFilterProxyModel* ViewExtensionsFactory::proxyModel() const -{ - return static_cast<DolphinSortFilterProxyModel*>(m_view->model()); -} - -#include "viewextensionsfactory.moc" - diff --git a/src/views/viewextensionsfactory.h b/src/views/viewextensionsfactory.h deleted file mode 100644 index 134868bce..000000000 --- a/src/views/viewextensionsfactory.h +++ /dev/null @@ -1,105 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Peter Penz <[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 * - ***************************************************************************/ - -#ifndef VIEWEXTENSIONSFACTORY_H -#define VIEWEXTENSIONSFACTORY_H - -#include <QObject> - -#include "dolphinview.h" - -class DolphinFileItemDelegate; -class DolphinSortFilterProxyModel; -class DolphinViewAutoScroller; -class KFilePreviewGenerator; -class FolderExpander; -class QModelIndex; -class SelectionManager; -class ToolTipManager; -class QAbstractItemView; -class VersionControlObserver; -class ViewModeController; - -/** - * @brief Responsible for creating extensions like tooltips and previews - * that are available in all view implementations. - * - * Each view implementation (iconsview, detailsview, columnview) must - * instantiate an instance of this class to assure having - * a common behavior that is independent from the custom functionality of - * a view implementation. - */ -class ViewExtensionsFactory : public QObject -{ - Q_OBJECT - -public: - explicit ViewExtensionsFactory(QAbstractItemView* view, - DolphinViewController* dolphinViewController, - const ViewModeController* viewModeController); - virtual ~ViewExtensionsFactory(); - - /** - * Must be invoked by the item view, when QAbstractItemView::currentChanged() - * has been called. Assures that the current item stays visible when it has been - * changed by the keyboard. - */ - void handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous); - - DolphinFileItemDelegate* fileItemDelegate() const; - - /** - * Enables the automatically expanding of a folder when dragging - * items above the folder. - */ - void setAutoFolderExpandingEnabled(bool enabled); - bool autoFolderExpandingEnabled() const; - -protected: - virtual bool eventFilter(QObject* watched, QEvent* event); - -private slots: - void slotZoomLevelChanged(); - void cancelPreviews(); - void slotShowPreviewChanged(); - void slotShowHiddenFilesChanged(); - void slotSortingChanged(DolphinView::Sorting sorting); - void slotSortOrderChanged(Qt::SortOrder order); - void slotSortFoldersFirstChanged(bool foldersFirst); - void slotNameFilterChanged(const QString& nameFilter); - void slotRequestVersionControlActions(const KFileItemList& items); - void requestActivation(); - -private: - DolphinSortFilterProxyModel* proxyModel() const; - -private: - QAbstractItemView* m_view; - DolphinViewController* m_dolphinViewController; - ToolTipManager* m_toolTipManager; - KFilePreviewGenerator* m_previewGenerator; - SelectionManager* m_selectionManager; - DolphinViewAutoScroller* m_autoScroller; - DolphinFileItemDelegate* m_fileItemDelegate; - VersionControlObserver* m_versionControlObserver; - FolderExpander* m_folderExpander; -}; - -#endif - diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index d0c6fcf1e..aeea67428 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -38,7 +38,7 @@ namespace { // String representation to mark the additional properties of // the details view as customized by the user. See - // ViewProperties::additionalInfoV2() for more information. + // ViewProperties::additionalInfoList() for more information. const char* CustomizedDetailsString = "CustomizedDetails"; } @@ -83,7 +83,7 @@ ViewProperties::ViewProperties(const KUrl& url) : if (useDefaultProps) { if (useDetailsViewWithPath) { setViewMode(DolphinView::DetailsView); - setAdditionalInfo(KFileItemDelegate::InformationList() << KFileItemDelegate::LocalPathOrUrl); + setAdditionalInfoList(QList<DolphinView::AdditionalInfo>() << DolphinView::PathInfo); } else { // The global view-properties act as default for directories without // any view-property configuration @@ -121,23 +121,23 @@ DolphinView::Mode ViewProperties::viewMode() const return static_cast<DolphinView::Mode>(m_node->viewMode()); } -void ViewProperties::setShowPreview(bool show) +void ViewProperties::setPreviewsShown(bool show) { - if (m_node->showPreview() != show) { - m_node->setShowPreview(show); + if (m_node->previewsShown() != show) { + m_node->setPreviewsShown(show); update(); } } -bool ViewProperties::showPreview() const +bool ViewProperties::previewsShown() const { - return m_node->showPreview(); + return m_node->previewsShown(); } -void ViewProperties::setShowHiddenFiles(bool show) +void ViewProperties::setHiddenFilesShown(bool show) { - if (m_node->showHiddenFiles() != show) { - m_node->setShowHiddenFiles(show); + if (m_node->hiddenFilesShown() != show) { + m_node->setHiddenFilesShown(show); update(); } } @@ -155,9 +155,9 @@ bool ViewProperties::categorizedSorting() const return m_node->categorizedSorting(); } -bool ViewProperties::showHiddenFiles() const +bool ViewProperties::hiddenFilesShown() const { - return m_node->showHiddenFiles(); + return m_node->hiddenFilesShown(); } void ViewProperties::setSorting(DolphinView::Sorting sorting) @@ -199,13 +199,13 @@ bool ViewProperties::sortFoldersFirst() const return m_node->sortFoldersFirst(); } -void ViewProperties::setAdditionalInfo(const KFileItemDelegate::InformationList& list) +void ViewProperties::setAdditionalInfoList(const QList<DolphinView::AdditionalInfo>& list) { - // See ViewProperties::additionalInfoV2() for the storage format + // See ViewProperties::additionalInfoList() for the storage format // of the additional information. // Remove the old values stored for the current view-mode - const QStringList oldInfoStringList = m_node->additionalInfoV2(); + const QStringList oldInfoStringList = m_node->additionalInfo(); const QString prefix = viewModePrefix(); QStringList newInfoStringList = oldInfoStringList; for (int i = newInfoStringList.count() - 1; i >= 0; --i) { @@ -216,7 +216,7 @@ void ViewProperties::setAdditionalInfo(const KFileItemDelegate::InformationList& // Add the updated values for the current view-mode AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - foreach (KFileItemDelegate::Information info, list) { + foreach (DolphinView::AdditionalInfo info, list) { newInfoStringList.append(prefix + infoAccessor.value(info)); } @@ -232,10 +232,6 @@ void ViewProperties::setAdditionalInfo(const KFileItemDelegate::InformationList& } if (changed) { - if (m_node->version() < 2) { - m_node->setVersion(2); - } - const bool markCustomizedDetails = (m_node->viewMode() == DolphinView::DetailsView) && !newInfoStringList.contains(CustomizedDetailsString); if (markCustomizedDetails) { @@ -246,35 +242,80 @@ void ViewProperties::setAdditionalInfo(const KFileItemDelegate::InformationList& newInfoStringList.append(CustomizedDetailsString); } - m_node->setAdditionalInfoV2(newInfoStringList); + m_node->setAdditionalInfo(newInfoStringList); update(); } } -KFileItemDelegate::InformationList ViewProperties::additionalInfo() const +QList<DolphinView::AdditionalInfo> ViewProperties::additionalInfoList() const { - KFileItemDelegate::InformationList usedInfo; + // The shown additional information is stored for each view-mode separately as + // string with the view-mode as prefix. Example: + // + // AdditionalInfo=Details_Size,Details_Date,Details_Owner,Icon_Size + // + // To get the representation as QList<DolphinView::AdditionalInfo>, the current + // view-mode must be checked and the values of this mode added to the list. + // + // For the details-view a special case must be respected: Per default the size + // and date should be shown without creating a .directory file. Only if + // the user explictly has modified the properties of the details view (marked + // by "CustomizedDetails"), also a details-view with no additional information + // is accepted. - switch (m_node->version()) { - case 1: usedInfo = additionalInfoV1(); break; - case 2: usedInfo = additionalInfoV2(); break; - default: kWarning() << "Unknown version of the view properties"; + QList<DolphinView::AdditionalInfo> usedInfo; + + // infoHash allows to get the mapped DolphinView::AdditionalInfo value + // for a stored string-value in a fast way + static QHash<QString, DolphinView::AdditionalInfo> infoHash; + if (infoHash.isEmpty()) { + AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); + const QList<DolphinView::AdditionalInfo> keys = infoAccessor.keys(); + foreach (DolphinView::AdditionalInfo key, keys) { + infoHash.insert(infoAccessor.value(key), key); + } + } + + // Iterate through all stored keys stored as strings and map them to + // the corresponding DolphinView::AdditionalInfo values. + const QString prefix = viewModePrefix(); + const int prefixLength = prefix.length(); + const QStringList infoStringList = m_node->additionalInfo(); + foreach (const QString& infoString, infoStringList) { + if (infoString.startsWith(prefix)) { + const QString key = infoString.right(infoString.length() - prefixLength); + if (infoHash.contains(key)) { + usedInfo.append(infoHash.value(key)); + } else { + kWarning() << "Did not find the key" << key << "in the information string"; + } + } + } + + // For the details view the size and date should be shown per default + // until the additional information has been explicitly changed by the user + const bool useDefaultValues = usedInfo.isEmpty() + && (m_node->viewMode() == DolphinView::DetailsView) + && !infoStringList.contains(CustomizedDetailsString); + Q_UNUSED(useDefaultValues); + if (useDefaultValues) { + usedInfo.append(DolphinView::SizeInfo); + usedInfo.append(DolphinView::DateInfo); } return usedInfo; } - void ViewProperties::setDirProperties(const ViewProperties& props) { setViewMode(props.viewMode()); - setShowPreview(props.showPreview()); - setShowHiddenFiles(props.showHiddenFiles()); + setPreviewsShown(props.previewsShown()); + setHiddenFilesShown(props.hiddenFilesShown()); setCategorizedSorting(props.categorizedSorting()); setSorting(props.sorting()); setSortOrder(props.sortOrder()); setSortFoldersFirst(props.sortFoldersFirst()); - setAdditionalInfo(props.additionalInfo()); + setAdditionalInfoList(props.additionalInfoList()); } void ViewProperties::setAutoSaveEnabled(bool autoSave) @@ -291,22 +332,6 @@ void ViewProperties::update() { m_changedProps = true; m_node->setTimestamp(QDateTime::currentDateTime()); - - // If the view-properties are stored in an older format, take - // care to update them to the current format. - switch (m_node->version()) { - case 1: { - const KFileItemDelegate::InformationList infoList = additionalInfoV1(); - m_node->setVersion(2); - setAdditionalInfo(infoList); - break; - } - case 2: - // Current version. Nothing needs to get converted. - break; - default: - kWarning() << "Unknown version of the view properties"; - } } void ViewProperties::save() @@ -330,107 +355,14 @@ QString ViewProperties::destinationDir(const QString& subDir) const return KStandardDirs::locateLocal("data", basePath); } -KFileItemDelegate::InformationList ViewProperties::additionalInfoV1() const -{ - KFileItemDelegate::InformationList usedInfo; - - int decodedInfo = m_node->additionalInfo(); - - switch (viewMode()) { - case DolphinView::DetailsView: - decodedInfo = decodedInfo & 0xFF; - if (decodedInfo == 0) { - // A details view without any additional info makes no sense, hence - // provide at least a size-info and date-info as fallback - AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - decodedInfo = infoAccessor.bitValue(KFileItemDelegate::Size) | - infoAccessor.bitValue(KFileItemDelegate::ModificationTime); - } - break; - case DolphinView::IconsView: - decodedInfo = (decodedInfo >> 8) & 0xFF; - break; - case DolphinView::ColumnView: - decodedInfo = (decodedInfo >> 16) & 0xFF; - break; - default: break; - } - - AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - const KFileItemDelegate::InformationList infoKeys = infoAccessor.keys(); - - foreach (const KFileItemDelegate::Information info, infoKeys) { - if (decodedInfo & infoAccessor.bitValue(info)) { - usedInfo.append(info); - } - } - - return usedInfo; -} - -KFileItemDelegate::InformationList ViewProperties::additionalInfoV2() const -{ - // The shown additional information is stored for each view-mode separately as - // string with the view-mode as prefix. Example: - // - // AdditionalInfoV2=Details_Size,Details_Date,Details_Owner,Icon_Size - // - // To get the representation as KFileItemDelegate::InformationList, the current - // view-mode must be checked and the values of this mode added to the list. - // - // For the details-view a special case must be respected: Per default the size - // and date should be shown without creating a .directory file. Only if - // the user explictly has modified the properties of the details view (marked - // by "CustomizedDetails"), also a details-view with no additional information - // is accepted. - - KFileItemDelegate::InformationList usedInfo; - - // infoHash allows to get the mapped KFileItemDelegate::Information value - // for a stored string-value in a fast way - static QHash<QString, KFileItemDelegate::Information> infoHash; - if (infoHash.isEmpty()) { - AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance(); - const KFileItemDelegate::InformationList keys = infoAccessor.keys(); - foreach (const KFileItemDelegate::Information key, keys) { - infoHash.insert(infoAccessor.value(key), key); - } - } - - // Iterate through all stored keys stored as strings and map them to - // the corresponding KFileItemDelegate::Information values. - const QString prefix = viewModePrefix(); - const int prefixLength = prefix.length(); - const QStringList infoStringList = m_node->additionalInfoV2(); - foreach (const QString& infoString, infoStringList) { - if (infoString.startsWith(prefix)) { - const QString key = infoString.right(infoString.length() - prefixLength); - Q_ASSERT(infoHash.contains(key)); - usedInfo.append(infoHash.value(key)); - } - } - - // For the details view the size and date should be shown per default - // until the additional information has been explicitly changed by the user - const bool useDefaultValues = usedInfo.isEmpty() - && (m_node->viewMode() == DolphinView::DetailsView) - && !infoStringList.contains(CustomizedDetailsString); - if (useDefaultValues) { - usedInfo.append(KFileItemDelegate::Size); - usedInfo.append(KFileItemDelegate::ModificationTime); - } - - return usedInfo; -} - QString ViewProperties::viewModePrefix() const { QString prefix; switch (m_node->viewMode()) { - case DolphinView::DetailsView: prefix = "Details_"; break; case DolphinView::IconsView: prefix = "Icons_"; break; - case DolphinView::ColumnView: prefix = "Column_"; break; + case DolphinView::CompactView: prefix = "Compact_"; break; + case DolphinView::DetailsView: prefix = "Details_"; break; default: kWarning() << "Unknown view-mode of the view properties"; } diff --git a/src/views/viewproperties.h b/src/views/viewproperties.h index ac373d677..c95134a15 100644 --- a/src/views/viewproperties.h +++ b/src/views/viewproperties.h @@ -37,7 +37,7 @@ class ViewPropertySettings; * \code * ViewProperties props(KUrl("/home/peter/Documents")); * const DolphinView::Mode mode = props.viewMode(); - * const bool showHiddenFiles = props.isShowHiddenFilesEnabled(); + * const bool hiddenFilesShown = props.hiddenFilesShown(); * \endcode * * When modifying a view property, the '.directory' file is automatically updated @@ -56,11 +56,11 @@ public: void setViewMode(DolphinView::Mode mode); DolphinView::Mode viewMode() const; - void setShowPreview(bool show); - bool showPreview() const; + void setPreviewsShown(bool show); + bool previewsShown() const; - void setShowHiddenFiles(bool show); - bool showHiddenFiles() const; + void setHiddenFilesShown(bool show); + bool hiddenFilesShown() const; void setCategorizedSorting(bool categorized); bool categorizedSorting() const; @@ -79,14 +79,14 @@ public: * Note that the additional-info property is the only property where * the value is dependent from another property (in this case the view-mode). */ - void setAdditionalInfo(const KFileItemDelegate::InformationList& info); + void setAdditionalInfoList(const QList<DolphinView::AdditionalInfo>& info); /** * Returns the additional information for the current set view-mode. * Note that the additional-info property is the only property where * the value is dependent from another property (in this case the view-mode). */ - KFileItemDelegate::InformationList additionalInfo() const; + QList<DolphinView::AdditionalInfo> additionalInfoList() const; /** * Sets the directory properties view mode, show preview, @@ -132,18 +132,6 @@ private: QString destinationDir(const QString& subDir) const; /** - * Helper method for ViewProperties::additionalInfo(): Returns - * the additional info for the outdated version 1 of the view-properties. - */ - KFileItemDelegate::InformationList additionalInfoV1() const; - - /** - * Helper method for ViewProperties::additionalInfo(): Returns - * the additional info for the current version 2 of the view-properties. - */ - KFileItemDelegate::InformationList additionalInfoV2() const; - - /** * Returns the view-mode prefix when storing additional properties for * a view-mode. */ |
