dolphincolumnview.cpp
dolphincolumnwidget.cpp
dolphindropcontroller.cpp
- dolphinsortfilterproxymodel.cpp
- draganddrophelper.cpp
+ dolphinfileitemdelegate.cpp
dolphinmodel.cpp
dolphinsettings.cpp
+ dolphinsortfilterproxymodel.cpp
dolphintooltip.cpp
dolphincategorydrawer.cpp
dolphinview.cpp
dolphinviewactionhandler.cpp
+ draganddrophelper.cpp
folderexpander.cpp
ktooltip.cpp
kballoontipdelegate.cpp
#include "dolphinmodel.h"
#include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
#include "dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
#include "draganddrophelper.h"
QRect DolphinDetailsView::nameColumnRect(const QModelIndex& index) const
{
- // TODO: The code guesses the width of the name, but it is defined
- // by KFileItemDelegate. Find a way to tell the item delegate to
- // use a specified width.
- QRect guessedItemContentRect = visualRect(index);
- const KFileItem fileItem = m_controller->itemForIndex(index);
- if (!fileItem.isNull()) {
- QStyleOptionViewItem itemStyle = viewOptions();
- QFontMetrics fontMetrics(itemStyle.font);
- const int itemContentWidth = itemStyle.decorationSize.width() + fontMetrics.width(fileItem.name());
- guessedItemContentRect.setWidth(itemContentWidth);
+ QRect rect = visualRect(index);
+ const KFileItem item = m_controller->itemForIndex(index);
+ if (!item.isNull()) {
+ const int width = DolphinFileItemDelegate::nameColumnWidth(item.name(), viewOptions());
+ rect.setWidth(width);
}
- return guessedItemContentRect;
+ return rect;
}
void DolphinDetailsView::setSelectionRecursive(const QModelIndex& startIndex,
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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 <QAbstractItemModel>
+#include <QAbstractProxyModel>
+#include <QFontMetrics>
+
+#include <kdirmodel.h>
+#include <kfileitem.h>
+
+DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) :
+ KFileItemDelegate(parent),
+ m_hasMinimizedNameColumn(false)
+{
+}
+
+DolphinFileItemDelegate::~DolphinFileItemDelegate()
+{
+}
+
+void DolphinFileItemDelegate::paint(QPainter* painter,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
+{
+ if (m_hasMinimizedNameColumn && (index.column() == KDirModel::Name)) {
+ QStyleOptionViewItemV4 opt(option);
+
+ const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(index.model());
+ const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
+ const QModelIndex dirIndex = proxyModel->mapToSource(index);
+ const KFileItem item = dirModel->itemForIndex(dirIndex);
+ if (!item.isNull()) {
+ const int width = nameColumnWidth(item.name(), opt);
+ opt.rect.setWidth(width);
+ }
+ KFileItemDelegate::paint(painter, opt, index);
+ } else {
+ KFileItemDelegate::paint(painter, option, index);
+ }
+}
+
+int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option)
+{
+ QFontMetrics fontMetrics(option.font);
+ return option.decorationSize.width() + fontMetrics.width(name) + 16;
+}
+
+#include "dolphinfileitemdelegate.moc"
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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.h>
+
+/**
+ * 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 DolphinDetailsView.
+ */
+class DolphinFileItemDelegate : public KFileItemDelegate
+{
+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:
+ bool m_hasMinimizedNameColumn;
+};
+
+inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized)
+{
+ m_hasMinimizedNameColumn = minimized;
+}
+
+inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const
+{
+ return m_hasMinimizedNameColumn;
+}
+
+#endif
#include <kactioncollection.h>
#include <kcolorscheme.h>
#include <kdirlister.h>
-#include <kfileitemdelegate.h>
#include <kfilepreviewgenerator.h>
#include <kiconeffect.h>
#include <klocale.h>
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphindetailsview.h"
#include "dolphin_detailsmodesettings.h"
m_controller->setItemView(view);
- m_fileItemDelegate = new KFileItemDelegate(view);
+ m_fileItemDelegate = new DolphinFileItemDelegate(view);
m_fileItemDelegate->setShowToolTipWhenElided(false);
+ m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView);
view->setItemDelegate(m_fileItemDelegate);
view->setModel(m_proxyModel);
class DolphinController;
class DolphinColumnView;
class DolphinDetailsView;
+class DolphinFileItemDelegate;
class DolphinIconsView;
class DolphinMainWindow;
class DolphinModel;
class KAction;
class KActionCollection;
class KDirLister;
-class KFileItemDelegate;
class KUrl;
class KToggleAction;
class ToolTipManager;
DolphinIconsView* m_iconsView;
DolphinDetailsView* m_detailsView;
DolphinColumnView* m_columnView;
- KFileItemDelegate* m_fileItemDelegate;
+ DolphinFileItemDelegate* m_fileItemDelegate;
QItemSelectionModel* m_selectionModel;
DolphinModel* m_dolphinModel;