#include "dolphin_detailsmodesettings.h"
#include "dolphin_generalsettings.h"
-#include <kdirmodel.h>
-#include <kdirlister.h>
-#include <klocale.h>
-#include <kmenu.h>
+#include <KDirModel>
+#include <KDirLister>
+#include <KLocale>
+#include <KMenu>
#include <QApplication>
#include <QHeaderView>
DolphinTreeView(parent),
m_autoResize(true),
m_dolphinViewController(dolphinViewController),
- m_viewModeController(viewModeController),
m_extensionsFactory(0),
m_expandableFoldersAction(0),
m_expandedUrls(),
m_decorationSize()
{
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
- Q_ASSERT(settings != 0);
- Q_ASSERT(dolphinViewController != 0);
- Q_ASSERT(viewModeController != 0);
+ Q_ASSERT(settings);
+ Q_ASSERT(dolphinViewController);
+ Q_ASSERT(viewModeController);
setLayoutDirection(Qt::LeftToRight);
setAcceptDrops(true);
setSortingEnabled(true);
- setUniformRowHeights(true);
setSelectionBehavior(SelectItems);
setDragDropMode(QAbstractItemView::DragDrop);
setDropIndicatorShown(false);
connect(view, SIGNAL(showPreviewChanged()),
this, SLOT(slotShowPreviewChanged()));
-
viewport()->installEventFilter(this);
connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)),
KDirLister *dirLister = qobject_cast<KDirModel*>(proxyModel->sourceModel())->dirLister();
connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(resizeColumns()));
-
- // setFocus() must be called after m_extensionsFactory is initialised (see bug 240374).
- setFocus();
}
DolphinDetailsView::~DolphinDetailsView()
void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
{
- if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
- event->acceptProposedAction();
- }
+ event->acceptProposedAction();
DolphinTreeView::dragEnterEvent(event);
}
void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
{
DolphinTreeView::dragMoveEvent(event);
-
- if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) {
- // Accept URL drops, independently from the destination item
- event->acceptProposedAction();
- }
+ event->acceptProposedAction();
}
void DolphinDetailsView::dropEvent(QDropEvent* event)
if (index.isValid() && (index.column() == DolphinModel::Name)) {
item = m_dolphinViewController->itemForIndex(index);
}
- m_dolphinViewController->indicateDroppedUrls(item, m_viewModeController->url(), event);
+ m_dolphinViewController->indicateDroppedUrls(item, event);
DolphinTreeView::dropEvent(event);
}
popup.addSeparator();
QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
- if (activatedAction != 0) {
+ if (activatedAction) {
const bool show = activatedAction->isChecked();
const int columnIndex = activatedAction->data().toInt();
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.
// Calculate the required width for the current column and consider only
// up to maxRowCount columns for performance reasons
if (rowCount > 0) {
- const QAbstractProxyModel* proxyModel = qobject_cast<const QAbstractProxyModel*>(model());
- const KDirModel* dirModel = qobject_cast<const KDirModel*>(proxyModel->sourceModel());
-
const int count = qMin(rowCount, maxRowCount);
- const QStyleOptionViewItem option = viewOptions();
for (int row = 0; row < count; ++row) {
- const QModelIndex index = dirModel->index(row, column);
- const int width = itemDelegate()->sizeHint(option, index).width();
+ 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();
- // TODO: check Qt-sources which left/right-gap is used for the headlines
- const int headlineWidth = fontMetrics.width(headline) + 20;
+ const int headlineWidth = fontMetrics.width(headline) + horizontalGap;
columnWidth[column] = qMax(columnWidth[column], headlineWidth);
}
Q_UNUSED(category);
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
- Q_ASSERT(settings != 0);
+ Q_ASSERT(settings);
if (settings->useSystemFont()) {
m_font = KGlobalSettings::generalFont();
}
}
}
+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 <fredrik@kde.org>
+ // 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"