Currently a custom item delegate has been made for Dolphin, but we'll discuss whether it makes sense providing this feature already in KFileItemDelegate...
BUG: 155378
BUG: 155575
CCMAIL: fredrik@kde.org
svn path=/trunk/KDE/kdebase/apps/; revision=788095
dolphincolumnview.cpp
dolphincolumnwidget.cpp
dolphindropcontroller.cpp
+ dolphinfileitemdelegate.cpp
dolphinsortfilterproxymodel.cpp
draganddrophelper.cpp
dolphinmodel.cpp
--- /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"
+
+DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) :
+ KFileItemDelegate(parent),
+ m_maxSize(0, 0)
+{
+}
+
+DolphinFileItemDelegate::~DolphinFileItemDelegate()
+{
+}
+
+void DolphinFileItemDelegate::setMaximumSize(const QSize& size)
+{
+ m_maxSize = size;
+}
+
+
+QSize DolphinFileItemDelegate::maximumSize() const
+{
+ return m_maxSize;
+}
+
+QSize DolphinFileItemDelegate::sizeHint(const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
+{
+ QSize size = KFileItemDelegate::sizeHint(option, index);
+
+ const int maxWidth = m_maxSize.width();
+ if ((maxWidth > 0) && (size.width() > maxWidth)) {
+ size.setWidth(maxWidth);
+ }
+
+ const int maxHeight = m_maxSize.height();
+ if ((maxHeight > 0) && (size.height() > maxHeight)) {
+ size.setHeight(maxHeight);
+ }
+
+ return size;
+}
+
+#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>
+
+/**
+ * @brief Extends KFileItemDelegate with the ability to set
+ * a maximum size.
+ */
+class DolphinFileItemDelegate : public KFileItemDelegate
+{
+ Q_OBJECT
+
+public:
+ explicit DolphinFileItemDelegate(QObject* parent = 0);
+ virtual ~DolphinFileItemDelegate();
+
+ void setMaximumSize(const QSize& size);
+ QSize maximumSize() const;
+
+ /** @see QItemDelegate::sizeHint() */
+ virtual QSize sizeHint(const QStyleOptionViewItem& option,
+ const QModelIndex& index) const;
+
+private:
+ QSize m_maxSize;
+};
+
+#endif
#include "dolphincategorydrawer.h"
#include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
#include "dolphinsettings.h"
#include "dolphin_iconsmodesettings.h"
#include "dolphin_generalsettings.h"
m_categoryDrawer = 0;
}
-QRect DolphinIconsView::visualRect(const QModelIndex& index) const
-{
- const bool leftToRightFlow = (flow() == QListView::LeftToRight);
-
- QRect itemRect = KCategorizedView::visualRect(index);
-
- const int maxWidth = m_itemSize.width();
- const int maxHeight = m_itemSize.height();
-
- if (itemRect.width() > maxWidth) {
- // assure that the maximum item width is not exceeded
- if (leftToRightFlow) {
- const int left = itemRect.left() + (itemRect.width() - maxWidth) / 2;
- itemRect.setLeft(left);
- }
- itemRect.setWidth(maxWidth);
- }
-
- if (itemRect.height() > maxHeight) {
- // assure that the maximum item height is not exceeded
- if (!leftToRightFlow) {
- const int top = itemRect.top() + (itemRect.height() - maxHeight) / 2;
- itemRect.setTop(top);
- }
- itemRect.setHeight(maxHeight);
- }
-
- KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
- if (leftToRightFlow && !proxyModel->isCategorizedModel()) {
- // TODO: QListView::visualRect() calculates a wrong position of the items under
- // certain circumstances (e. g. if the text is too long). This issue is bypassed
- // by the following code (I'll try create a patch for Qt but as Dolphin must also work with
- // Qt 4.3.0 this workaround must get applied at least for KDE 4.0).
- const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
- const int margin = settings->gridSpacing();
- const int gridWidth = gridSize().width();
- const int gridIndex = (itemRect.left() - margin + 1) / gridWidth;
- const int centerInc = (maxWidth - itemRect.width()) / 2;
- itemRect.moveLeft((gridIndex * gridWidth) + margin + centerInc);
- }
-
- return itemRect;
-}
-
QStyleOptionViewItem DolphinIconsView::viewOptions() const
{
QStyleOptionViewItem viewOptions = KCategorizedView::viewOptions();
m_controller->setZoomInPossible(isZoomInPossible());
m_controller->setZoomOutPossible(isZoomOutPossible());
+
+ DolphinFileItemDelegate* delegate = qobject_cast<DolphinFileItemDelegate*>(itemDelegate());
+ if (delegate != 0) {
+ delegate->setMaximumSize(m_itemSize);
+ }
}
int DolphinIconsView::additionalInfoCount() const
explicit DolphinIconsView(QWidget* parent, DolphinController* controller);
virtual ~DolphinIconsView();
- /** @see QAbstractItemView::visualRect() */
- virtual QRect visualRect(const QModelIndex& index) const;
-
protected:
virtual QStyleOptionViewItem viewOptions() const;
virtual void contextMenuEvent(QContextMenuEvent* event);
#include <kactioncollection.h>
#include <kcolorscheme.h>
#include <kdirlister.h>
-#include <kfileitemdelegate.h>
#include <kiconeffect.h>
#include <klocale.h>
#include <kio/deletejob.h>
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphindetailsview.h"
#include "dolphiniconsview.h"
m_controller->setItemView(view);
- m_fileItemDelegate = new KFileItemDelegate(view);
+ m_fileItemDelegate = new DolphinFileItemDelegate(view);
view->setItemDelegate(m_fileItemDelegate);
view->setModel(m_proxyModel);
class DolphinController;
class DolphinColumnView;
class DolphinDetailsView;
+class DolphinFileItemDelegate;
class DolphinIconsView;
class DolphinMainWindow;
class DolphinModel;
DolphinIconsView* m_iconsView;
DolphinDetailsView* m_detailsView;
DolphinColumnView* m_columnView;
- KFileItemDelegate* m_fileItemDelegate;
+ DolphinFileItemDelegate* m_fileItemDelegate;
QItemSelectionModel* m_selectionModel;
DolphinModel* m_dolphinModel;