2006-11-21 06:02:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 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., *
|
2006-12-08 21:24:08 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
2006-11-21 06:02:05 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dolphindetailsview.h"
|
2007-02-05 23:18:22 +00:00
|
|
|
|
2007-09-17 04:02:17 +00:00
|
|
|
#include "dolphinmodel.h"
|
2007-02-14 21:54:24 +00:00
|
|
|
#include "dolphincontroller.h"
|
2007-02-27 20:46:21 +00:00
|
|
|
#include "dolphinsettings.h"
|
2007-02-07 06:19:06 +00:00
|
|
|
#include "dolphinsortfilterproxymodel.h"
|
2007-11-20 21:11:48 +00:00
|
|
|
#include "draganddrophelper.h"
|
2008-01-26 21:45:28 +00:00
|
|
|
#include "selectionmanager.h"
|
2007-02-05 23:18:22 +00:00
|
|
|
#include "viewproperties.h"
|
2007-02-06 06:43:34 +00:00
|
|
|
|
2007-02-27 20:46:21 +00:00
|
|
|
#include "dolphin_detailsmodesettings.h"
|
2008-01-26 21:45:28 +00:00
|
|
|
#include "dolphin_generalsettings.h"
|
2007-02-27 20:46:21 +00:00
|
|
|
|
2007-10-05 21:00:44 +00:00
|
|
|
#include <kdirmodel.h>
|
2007-09-27 08:56:38 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <kmenu.h>
|
|
|
|
|
2007-10-05 21:00:44 +00:00
|
|
|
#include <QAbstractProxyModel>
|
2007-09-27 08:56:38 +00:00
|
|
|
#include <QAction>
|
2007-06-02 15:03:03 +00:00
|
|
|
#include <QApplication>
|
2007-05-31 16:14:47 +00:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QRubberBand>
|
2007-05-31 20:08:06 +00:00
|
|
|
#include <QPainter>
|
2007-05-31 16:14:47 +00:00
|
|
|
#include <QScrollBar>
|
2007-01-25 22:28:04 +00:00
|
|
|
|
2007-02-14 21:54:24 +00:00
|
|
|
DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
|
2007-05-06 17:41:49 +00:00
|
|
|
QTreeView(parent),
|
2008-01-16 22:14:34 +00:00
|
|
|
m_autoResize(true),
|
2007-05-31 16:14:47 +00:00
|
|
|
m_controller(controller),
|
2007-12-06 21:06:45 +00:00
|
|
|
m_font(),
|
|
|
|
m_decorationSize(),
|
2007-06-02 17:28:59 +00:00
|
|
|
m_dragging(false),
|
2007-05-31 20:08:06 +00:00
|
|
|
m_showElasticBand(false),
|
|
|
|
m_elasticBandOrigin(),
|
|
|
|
m_elasticBandDestination()
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-03-01 20:22:03 +00:00
|
|
|
Q_ASSERT(controller != 0);
|
2007-02-05 23:18:22 +00:00
|
|
|
|
2007-01-25 22:28:04 +00:00
|
|
|
setAcceptDrops(true);
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setSortingEnabled(true);
|
|
|
|
setUniformRowHeights(true);
|
2007-03-08 05:43:33 +00:00
|
|
|
setSelectionBehavior(SelectItems);
|
2007-03-11 11:13:07 +00:00
|
|
|
setDragDropMode(QAbstractItemView::DragDrop);
|
|
|
|
setDropIndicatorShown(false);
|
2007-07-28 14:19:38 +00:00
|
|
|
setAlternatingRowColors(true);
|
2007-12-01 09:59:13 +00:00
|
|
|
setItemsExpandable(false);
|
2007-03-08 05:43:33 +00:00
|
|
|
|
2007-05-12 10:22:01 +00:00
|
|
|
setMouseTracking(true);
|
2007-03-08 05:43:33 +00:00
|
|
|
viewport()->setAttribute(Qt::WA_Hover);
|
2007-02-05 23:18:22 +00:00
|
|
|
|
2007-02-14 21:54:24 +00:00
|
|
|
const ViewProperties props(controller->url());
|
2007-02-05 23:18:22 +00:00
|
|
|
setSortIndicatorSection(props.sorting());
|
|
|
|
setSortIndicatorOrder(props.sortOrder());
|
|
|
|
|
2007-09-27 08:56:38 +00:00
|
|
|
QHeaderView* headerView = header();
|
|
|
|
connect(headerView, SIGNAL(sectionClicked(int)),
|
2007-02-06 06:43:34 +00:00
|
|
|
this, SLOT(synchronizeSortingState(int)));
|
2007-09-27 08:56:38 +00:00
|
|
|
headerView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
|
|
|
|
this, SLOT(configureColumns(const QPoint&)));
|
2008-01-16 22:14:34 +00:00
|
|
|
connect(headerView, SIGNAL(sectionResized(int, int, int)),
|
|
|
|
this, SLOT(slotHeaderSectionResized(int, int, int)));
|
|
|
|
connect(headerView, SIGNAL(sectionHandleDoubleClicked(int)),
|
|
|
|
this, SLOT(disableAutoResizing()));
|
2007-02-06 06:43:34 +00:00
|
|
|
|
2007-02-05 23:18:22 +00:00
|
|
|
connect(parent, SIGNAL(sortingChanged(DolphinView::Sorting)),
|
|
|
|
this, SLOT(setSortIndicatorSection(DolphinView::Sorting)));
|
|
|
|
connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)),
|
|
|
|
this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
|
2007-02-14 21:54:24 +00:00
|
|
|
|
2007-09-09 18:38:04 +00:00
|
|
|
// TODO: Connecting to the signal 'activated()' is not possible, as kstyle
|
|
|
|
// does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
|
|
|
|
// necessary connecting the signal 'singleClick()' or 'doubleClick' and to handle the
|
|
|
|
// RETURN-key in keyPressEvent().
|
2007-05-01 09:12:24 +00:00
|
|
|
if (KGlobalSettings::singleClick()) {
|
|
|
|
connect(this, SIGNAL(clicked(const QModelIndex&)),
|
2007-10-05 22:32:13 +00:00
|
|
|
this, SLOT(triggerItem(const QModelIndex&)));
|
2008-01-26 21:45:28 +00:00
|
|
|
if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
|
|
|
|
SelectionManager* selManager = new SelectionManager(this);
|
|
|
|
connect(selManager, SIGNAL(selectionChanged()),
|
|
|
|
this, SLOT(requestActivation()));
|
2008-01-26 22:32:24 +00:00
|
|
|
connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
|
|
|
|
selManager, SLOT(reset()));
|
2008-01-26 21:45:28 +00:00
|
|
|
}
|
2007-05-01 09:12:24 +00:00
|
|
|
} else {
|
|
|
|
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
|
2007-10-05 22:32:13 +00:00
|
|
|
this, SLOT(triggerItem(const QModelIndex&)));
|
2007-05-01 09:12:24 +00:00
|
|
|
}
|
2007-05-12 10:22:01 +00:00
|
|
|
connect(this, SIGNAL(entered(const QModelIndex&)),
|
2007-05-12 13:41:31 +00:00
|
|
|
this, SLOT(slotEntered(const QModelIndex&)));
|
2007-05-12 10:22:01 +00:00
|
|
|
connect(this, SIGNAL(viewportEntered()),
|
|
|
|
controller, SLOT(emitViewportEntered()));
|
2007-03-01 20:22:03 +00:00
|
|
|
connect(controller, SIGNAL(zoomIn()),
|
|
|
|
this, SLOT(zoomIn()));
|
|
|
|
connect(controller, SIGNAL(zoomOut()),
|
|
|
|
this, SLOT(zoomOut()));
|
2008-01-22 01:38:45 +00:00
|
|
|
connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()),
|
2007-10-26 17:36:16 +00:00
|
|
|
this, SLOT(updateColumnVisibility()));
|
2007-03-01 20:22:03 +00:00
|
|
|
|
2007-02-28 19:17:26 +00:00
|
|
|
// apply the details mode settings to the widget
|
2007-02-27 20:46:21 +00:00
|
|
|
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
2007-03-01 20:22:03 +00:00
|
|
|
Q_ASSERT(settings != 0);
|
2007-02-27 20:46:21 +00:00
|
|
|
|
2007-12-06 21:06:45 +00:00
|
|
|
m_font = QFont(settings->fontFamily(), settings->fontSize());
|
2007-03-13 19:46:49 +00:00
|
|
|
|
2007-10-04 15:15:24 +00:00
|
|
|
// TODO: Remove this check when 4.3.2 is released and KDE requires it... this
|
|
|
|
// check avoids a division by zero happening on versions before 4.3.1.
|
|
|
|
// Right now KDE in theory can be shipped with Qt 4.3.0 and above.
|
|
|
|
// ereslibre
|
2007-10-04 16:16:24 +00:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
|
2007-10-04 15:15:24 +00:00
|
|
|
setVerticalScrollMode(QTreeView::ScrollPerPixel);
|
|
|
|
setHorizontalScrollMode(QTreeView::ScrollPerPixel);
|
|
|
|
#endif
|
2007-10-04 01:35:53 +00:00
|
|
|
|
2007-03-01 20:22:03 +00:00
|
|
|
updateDecorationSize();
|
2007-10-16 22:24:52 +00:00
|
|
|
|
|
|
|
setFocus();
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DolphinDetailsView::~DolphinDetailsView()
|
2007-05-31 16:14:47 +00:00
|
|
|
{
|
|
|
|
}
|
2007-01-25 22:28:04 +00:00
|
|
|
|
|
|
|
bool DolphinDetailsView::event(QEvent* event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Polish) {
|
|
|
|
QHeaderView* headerView = header();
|
2007-12-01 09:49:51 +00:00
|
|
|
headerView->setResizeMode(QHeaderView::Interactive);
|
2007-10-03 21:47:47 +00:00
|
|
|
headerView->setMovable(false);
|
2007-02-28 06:00:58 +00:00
|
|
|
|
2007-10-26 17:36:16 +00:00
|
|
|
updateColumnVisibility();
|
2007-09-26 00:47:33 +00:00
|
|
|
|
|
|
|
hideColumn(DolphinModel::Rating);
|
|
|
|
hideColumn(DolphinModel::Tags);
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
2007-10-04 15:15:24 +00:00
|
|
|
// TODO: Remove this check when 4.3.2 is released and KDE requires it... this
|
|
|
|
// check avoids a division by zero happening on versions before 4.3.1.
|
|
|
|
// Right now KDE in theory can be shipped with Qt 4.3.0 and above.
|
|
|
|
// ereslibre
|
2007-10-04 16:16:24 +00:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
|
2007-10-04 01:35:53 +00:00
|
|
|
else if (event->type() == QEvent::UpdateRequest) {
|
2007-10-04 05:59:46 +00:00
|
|
|
// a wheel movement will scroll 4 items
|
|
|
|
if (model()->rowCount() > 0) {
|
2007-10-04 01:35:53 +00:00
|
|
|
verticalScrollBar()->setSingleStep((sizeHintForRow(0) / 3) * 4);
|
2007-10-04 05:59:46 +00:00
|
|
|
}
|
2007-10-04 01:35:53 +00:00
|
|
|
}
|
2007-10-04 15:15:24 +00:00
|
|
|
#endif
|
2007-01-25 22:28:04 +00:00
|
|
|
|
|
|
|
return QTreeView::event(event);
|
|
|
|
}
|
2007-03-11 00:56:43 +00:00
|
|
|
|
2007-01-25 22:28:04 +00:00
|
|
|
QStyleOptionViewItem DolphinDetailsView::viewOptions() const
|
|
|
|
{
|
2007-12-06 21:06:45 +00:00
|
|
|
QStyleOptionViewItem viewOptions = QTreeView::viewOptions();
|
|
|
|
viewOptions.font = m_font;
|
|
|
|
viewOptions.showDecorationSelected = true;
|
|
|
|
viewOptions.decorationSize = m_decorationSize;
|
|
|
|
return viewOptions;
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::contextMenuEvent(event);
|
2007-11-18 14:22:36 +00:00
|
|
|
m_controller->triggerContextMenuRequest(event->pos());
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 16:14:47 +00:00
|
|
|
void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
2007-10-07 10:53:33 +00:00
|
|
|
m_controller->requestActivation();
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2007-06-06 20:32:03 +00:00
|
|
|
QTreeView::mousePressEvent(event);
|
|
|
|
|
|
|
|
const QModelIndex index = indexAt(event->pos());
|
2007-09-17 04:02:17 +00:00
|
|
|
if (!index.isValid() || (index.column() != DolphinModel::Name)) {
|
2007-06-02 15:03:03 +00:00
|
|
|
const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
|
|
|
|
if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-31 16:14:47 +00:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
2007-05-31 20:08:06 +00:00
|
|
|
m_showElasticBand = true;
|
2007-05-31 16:14:47 +00:00
|
|
|
|
|
|
|
const QPoint pos(contentsPos());
|
2007-05-31 20:08:06 +00:00
|
|
|
m_elasticBandOrigin = event->pos();
|
|
|
|
m_elasticBandOrigin.setX(m_elasticBandOrigin.x() + pos.x());
|
|
|
|
m_elasticBandOrigin.setY(m_elasticBandOrigin.y() + pos.y());
|
|
|
|
m_elasticBandDestination = event->pos();
|
2007-05-31 16:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
2007-05-31 20:08:06 +00:00
|
|
|
if (m_showElasticBand) {
|
2007-12-15 16:25:23 +00:00
|
|
|
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
|
|
|
|
clearSelection();
|
2007-12-15 17:11:13 +00:00
|
|
|
|
|
|
|
const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
|
|
|
|
QRect selRect = QRect(m_elasticBandOrigin, m_elasticBandDestination).normalized();
|
|
|
|
const QRect nameColumnsRect(0, 0, nameColumnWidth, viewport()->height());
|
|
|
|
selRect = nameColumnsRect.intersected(selRect);
|
|
|
|
|
|
|
|
setSelection(selRect, QItemSelectionModel::Select);
|
2007-12-15 16:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTreeView::mouseMoveEvent(event);
|
2007-05-31 20:08:06 +00:00
|
|
|
updateElasticBand();
|
2007-12-15 16:25:23 +00:00
|
|
|
} else {
|
|
|
|
QTreeView::mouseMoveEvent(event);
|
2007-05-31 16:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-25 22:28:04 +00:00
|
|
|
void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::mouseReleaseEvent(event);
|
2007-06-02 15:03:03 +00:00
|
|
|
if (m_showElasticBand) {
|
|
|
|
updateElasticBand();
|
|
|
|
m_showElasticBand = false;
|
|
|
|
}
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
2007-11-20 21:11:48 +00:00
|
|
|
void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
|
|
|
|
{
|
|
|
|
DragAndDropHelper::startDrag(this, supportedActions);
|
|
|
|
}
|
|
|
|
|
2007-01-25 22:28:04 +00:00
|
|
|
void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2007-06-02 15:03:03 +00:00
|
|
|
|
|
|
|
if (m_showElasticBand) {
|
|
|
|
updateElasticBand();
|
|
|
|
m_showElasticBand = false;
|
|
|
|
}
|
2007-06-02 17:28:59 +00:00
|
|
|
m_dragging = true;
|
|
|
|
}
|
|
|
|
|
2007-06-02 17:42:43 +00:00
|
|
|
void DolphinDetailsView::dragLeaveEvent(QDragLeaveEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::dragLeaveEvent(event);
|
|
|
|
|
|
|
|
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
|
|
|
|
m_dragging = false;
|
|
|
|
setDirtyRegion(m_dropRect);
|
|
|
|
}
|
|
|
|
|
2007-06-02 17:28:59 +00:00
|
|
|
void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::dragMoveEvent(event);
|
|
|
|
|
|
|
|
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
|
|
|
|
setDirtyRegion(m_dropRect);
|
2007-06-06 18:08:30 +00:00
|
|
|
const QModelIndex index = indexAt(event->pos());
|
2007-09-17 04:02:17 +00:00
|
|
|
if (!index.isValid() || (index.column() != DolphinModel::Name)) {
|
2007-06-06 18:08:30 +00:00
|
|
|
m_dragging = false;
|
|
|
|
} else {
|
|
|
|
m_dragging = true;
|
2007-11-28 17:07:08 +00:00
|
|
|
const KFileItem item = itemForIndex(index);
|
|
|
|
if (!item.isNull() && item.isDir()) {
|
2007-10-30 19:44:55 +00:00
|
|
|
m_dropRect = visualRect(index);
|
|
|
|
} else {
|
|
|
|
m_dropRect.setSize(QSize()); // set as invalid
|
|
|
|
}
|
2007-06-06 18:08:30 +00:00
|
|
|
setDirtyRegion(m_dropRect);
|
|
|
|
}
|
2007-12-18 21:04:26 +00:00
|
|
|
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
// accept url drops, independently from the destination item
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::dropEvent(QDropEvent* event)
|
|
|
|
{
|
2007-02-16 17:03:02 +00:00
|
|
|
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
2007-03-11 11:13:07 +00:00
|
|
|
if (!urls.isEmpty()) {
|
2007-01-25 22:28:04 +00:00
|
|
|
event->acceptProposedAction();
|
2007-10-26 17:36:16 +00:00
|
|
|
const QModelIndex index = indexAt(event->pos());
|
2007-10-30 19:44:55 +00:00
|
|
|
KFileItem item;
|
2007-10-26 17:36:16 +00:00
|
|
|
if (index.isValid() && (index.column() == DolphinModel::Name)) {
|
2007-10-30 19:44:55 +00:00
|
|
|
item = itemForIndex(index);
|
2007-10-26 17:36:16 +00:00
|
|
|
}
|
2007-10-30 19:44:55 +00:00
|
|
|
m_controller->indicateDroppedUrls(urls,
|
|
|
|
m_controller->url(),
|
|
|
|
item);
|
2007-02-16 17:03:02 +00:00
|
|
|
}
|
2007-03-11 11:13:07 +00:00
|
|
|
QTreeView::dropEvent(event);
|
2007-06-02 17:28:59 +00:00
|
|
|
m_dragging = false;
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 20:08:06 +00:00
|
|
|
void DolphinDetailsView::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::paintEvent(event);
|
|
|
|
if (m_showElasticBand) {
|
|
|
|
// 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();
|
|
|
|
}
|
2007-06-02 17:28:59 +00:00
|
|
|
|
2007-06-13 17:42:16 +00:00
|
|
|
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
|
2007-06-02 17:28:59 +00:00
|
|
|
if (m_dragging) {
|
2007-12-06 21:06:45 +00:00
|
|
|
const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
|
2007-12-16 20:56:24 +00:00
|
|
|
DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
|
2007-06-02 17:28:59 +00:00
|
|
|
}
|
2007-05-31 20:08:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 18:38:04 +00:00
|
|
|
void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::keyPressEvent(event);
|
2007-09-09 18:54:32 +00:00
|
|
|
|
|
|
|
const QItemSelectionModel* selModel = selectionModel();
|
|
|
|
const QModelIndex currentIndex = selModel->currentIndex();
|
2007-10-05 22:32:13 +00:00
|
|
|
const bool trigger = currentIndex.isValid()
|
|
|
|
&& (event->key() == Qt::Key_Return)
|
|
|
|
&& (selModel->selectedIndexes().count() <= 1);
|
|
|
|
if (trigger) {
|
|
|
|
triggerItem(currentIndex);
|
2007-09-09 18:38:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-26 13:15:16 +00:00
|
|
|
void DolphinDetailsView::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
2008-01-16 22:14:34 +00:00
|
|
|
if (m_autoResize) {
|
2007-12-01 09:49:51 +00:00
|
|
|
resizeColumns();
|
|
|
|
}
|
2008-02-11 21:09:07 +00:00
|
|
|
QTreeView::resizeEvent(event);
|
2007-09-26 13:15:16 +00:00
|
|
|
}
|
|
|
|
|
2007-02-05 23:18:22 +00:00
|
|
|
void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
|
|
|
|
{
|
|
|
|
QHeaderView* headerView = header();
|
|
|
|
headerView->setSortIndicator(sorting, headerView->sortIndicatorOrder());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
|
|
|
|
{
|
|
|
|
QHeaderView* headerView = header();
|
|
|
|
headerView->setSortIndicator(headerView->sortIndicatorSection(), sortOrder);
|
|
|
|
}
|
|
|
|
|
2007-02-06 06:43:34 +00:00
|
|
|
void DolphinDetailsView::synchronizeSortingState(int column)
|
|
|
|
{
|
|
|
|
// The sorting has already been changed in QTreeView if this slot is
|
2007-02-14 21:54:24 +00:00
|
|
|
// invoked, but Dolphin is not informed about this.
|
2007-02-07 06:19:06 +00:00
|
|
|
DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
|
|
|
|
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
|
2007-02-14 21:54:24 +00:00
|
|
|
m_controller->indicateSortingChange(sorting);
|
|
|
|
m_controller->indicateSortOrderChange(sortOrder);
|
2007-02-06 06:43:34 +00:00
|
|
|
}
|
|
|
|
|
2007-05-12 13:41:31 +00:00
|
|
|
void DolphinDetailsView::slotEntered(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
const QPoint pos = viewport()->mapFromGlobal(QCursor::pos());
|
2007-09-17 04:02:17 +00:00
|
|
|
const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
|
2007-05-12 13:41:31 +00:00
|
|
|
if (pos.x() < nameColumnWidth) {
|
2007-10-05 21:00:44 +00:00
|
|
|
m_controller->emitItemEntered(itemForIndex(index));
|
2007-05-12 13:41:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_controller->emitViewportEntered();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-31 20:08:06 +00:00
|
|
|
void DolphinDetailsView::updateElasticBand()
|
2007-05-31 16:14:47 +00:00
|
|
|
{
|
2007-12-16 11:43:39 +00:00
|
|
|
if (m_showElasticBand) {
|
|
|
|
QRect dirtyRegion(elasticBandRect());
|
|
|
|
m_elasticBandDestination = viewport()->mapFromGlobal(QCursor::pos());
|
|
|
|
dirtyRegion = dirtyRegion.united(elasticBandRect());
|
|
|
|
setDirtyRegion(dirtyRegion);
|
|
|
|
}
|
2007-05-31 16:14:47 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 21:00:44 +00:00
|
|
|
QRect DolphinDetailsView::elasticBandRect() const
|
|
|
|
{
|
|
|
|
const QPoint pos(contentsPos());
|
|
|
|
const QPoint topLeft(m_elasticBandOrigin.x() - pos.x(), m_elasticBandOrigin.y() - pos.y());
|
|
|
|
return QRect(topLeft, m_elasticBandDestination).normalized();
|
|
|
|
}
|
|
|
|
|
2007-03-01 20:22:03 +00:00
|
|
|
void DolphinDetailsView::zoomIn()
|
|
|
|
{
|
|
|
|
if (isZoomInPossible()) {
|
|
|
|
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
|
|
|
switch (settings->iconSize()) {
|
2007-10-01 15:09:41 +00:00
|
|
|
case KIconLoader::SizeSmall: settings->setIconSize(KIconLoader::SizeMedium); break;
|
|
|
|
case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); break;
|
2007-04-09 19:12:54 +00:00
|
|
|
default: Q_ASSERT(false); break;
|
2007-03-01 20:22:03 +00:00
|
|
|
}
|
|
|
|
updateDecorationSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::zoomOut()
|
|
|
|
{
|
|
|
|
if (isZoomOutPossible()) {
|
|
|
|
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
|
|
|
switch (settings->iconSize()) {
|
2007-10-01 15:09:41 +00:00
|
|
|
case KIconLoader::SizeLarge: settings->setIconSize(KIconLoader::SizeMedium); break;
|
|
|
|
case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
|
2007-04-09 19:12:54 +00:00
|
|
|
default: Q_ASSERT(false); break;
|
2007-03-01 20:22:03 +00:00
|
|
|
}
|
|
|
|
updateDecorationSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-05 22:32:13 +00:00
|
|
|
void DolphinDetailsView::triggerItem(const QModelIndex& index)
|
2007-09-26 13:15:16 +00:00
|
|
|
{
|
2007-10-05 22:32:13 +00:00
|
|
|
const KFileItem item = itemForIndex(index);
|
2007-09-26 13:15:16 +00:00
|
|
|
if (index.isValid() && (index.column() == KDirModel::Name)) {
|
2007-10-05 22:32:13 +00:00
|
|
|
m_controller->triggerItem(item);
|
2007-09-26 13:15:16 +00:00
|
|
|
} else {
|
|
|
|
clearSelection();
|
2007-10-05 22:32:13 +00:00
|
|
|
m_controller->emitItemEntered(item);
|
2007-09-26 13:15:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-27 08:56:38 +00:00
|
|
|
void DolphinDetailsView::configureColumns(const QPoint& pos)
|
|
|
|
{
|
|
|
|
KMenu popup(this);
|
|
|
|
popup.addTitle(i18nc("@title:menu", "Columns"));
|
|
|
|
|
|
|
|
QHeaderView* headerView = header();
|
2007-10-26 17:36:16 +00:00
|
|
|
for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
|
2007-09-27 08:56:38 +00:00
|
|
|
const int logicalIndex = headerView->logicalIndex(i);
|
|
|
|
const QString text = model()->headerData(i, Qt::Horizontal).toString();
|
|
|
|
QAction* action = popup.addAction(text);
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(!headerView->isSectionHidden(logicalIndex));
|
|
|
|
action->setData(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
|
|
|
|
if (activatedAction != 0) {
|
|
|
|
const bool show = activatedAction->isChecked();
|
|
|
|
const int columnIndex = activatedAction->data().toInt();
|
2007-10-26 17:36:16 +00:00
|
|
|
|
|
|
|
KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
|
2007-11-06 07:16:23 +00:00
|
|
|
const KFileItemDelegate::Information info = infoForColumn(columnIndex);
|
2007-09-27 08:56:38 +00:00
|
|
|
if (show) {
|
2007-10-26 17:36:16 +00:00
|
|
|
Q_ASSERT(!list.contains(info));
|
|
|
|
list.append(info);
|
2007-09-27 08:56:38 +00:00
|
|
|
} else {
|
2007-10-26 17:36:16 +00:00
|
|
|
Q_ASSERT(list.contains(info));
|
|
|
|
const int index = list.indexOf(info);
|
|
|
|
list.removeAt(index);
|
2007-09-27 08:56:38 +00:00
|
|
|
}
|
2007-10-26 17:36:16 +00:00
|
|
|
|
|
|
|
m_controller->indicateAdditionalInfoChange(list);
|
|
|
|
setColumnHidden(columnIndex, !show);
|
2007-09-27 08:56:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 17:36:16 +00:00
|
|
|
void DolphinDetailsView::updateColumnVisibility()
|
|
|
|
{
|
2008-01-05 22:09:07 +00:00
|
|
|
const KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
|
2007-11-06 07:16:23 +00:00
|
|
|
for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
|
|
|
|
const KFileItemDelegate::Information info = infoForColumn(i);
|
|
|
|
const bool hide = !list.contains(info);
|
|
|
|
if (isColumnHidden(i) != hide) {
|
|
|
|
setColumnHidden(i, hide);
|
|
|
|
}
|
|
|
|
}
|
2007-11-07 22:55:15 +00:00
|
|
|
|
|
|
|
resizeColumns();
|
2007-10-26 17:36:16 +00:00
|
|
|
}
|
|
|
|
|
2008-01-16 22:14:34 +00:00
|
|
|
void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize)
|
|
|
|
{
|
|
|
|
Q_UNUSED(logicalIndex);
|
|
|
|
Q_UNUSED(oldSize);
|
|
|
|
Q_UNUSED(newSize);
|
|
|
|
if (QApplication::mouseButtons() & Qt::LeftButton) {
|
|
|
|
disableAutoResizing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::disableAutoResizing()
|
|
|
|
{
|
|
|
|
m_autoResize = false;
|
|
|
|
}
|
|
|
|
|
2008-01-26 21:45:28 +00:00
|
|
|
void DolphinDetailsView::requestActivation()
|
|
|
|
{
|
|
|
|
m_controller->requestActivation();
|
|
|
|
}
|
|
|
|
|
2007-03-01 20:22:03 +00:00
|
|
|
bool DolphinDetailsView::isZoomInPossible() const
|
|
|
|
{
|
|
|
|
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
2007-10-01 15:09:41 +00:00
|
|
|
return settings->iconSize() < KIconLoader::SizeLarge;
|
2007-03-01 20:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DolphinDetailsView::isZoomOutPossible() const
|
|
|
|
{
|
|
|
|
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
2007-10-01 15:09:41 +00:00
|
|
|
return settings->iconSize() > KIconLoader::SizeSmall;
|
2007-03-01 20:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::updateDecorationSize()
|
|
|
|
{
|
|
|
|
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
|
|
|
const int iconSize = settings->iconSize();
|
2008-01-26 12:48:03 +00:00
|
|
|
setIconSize(QSize(iconSize, iconSize));
|
2007-12-06 21:06:45 +00:00
|
|
|
m_decorationSize = QSize(iconSize, iconSize);
|
2007-03-01 20:22:03 +00:00
|
|
|
|
|
|
|
m_controller->setZoomInPossible(isZoomInPossible());
|
|
|
|
m_controller->setZoomOutPossible(isZoomOutPossible());
|
|
|
|
|
|
|
|
doItemsLayout();
|
|
|
|
}
|
|
|
|
|
2007-05-31 16:14:47 +00:00
|
|
|
QPoint DolphinDetailsView::contentsPos() const
|
|
|
|
{
|
|
|
|
// implementation note: the horizonal position is ignored currently, as no
|
|
|
|
// horizontal scrolling is done anyway during a selection
|
|
|
|
const QScrollBar* scrollbar = verticalScrollBar();
|
|
|
|
Q_ASSERT(scrollbar != 0);
|
|
|
|
|
|
|
|
const int maxHeight = maximumViewportSize().height();
|
|
|
|
const int height = scrollbar->maximum() - scrollbar->minimum() + 1;
|
|
|
|
const int visibleHeight = model()->rowCount() + 1 - height;
|
|
|
|
if (visibleHeight <= 0) {
|
|
|
|
return QPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int y = scrollbar->sliderPosition() * maxHeight / visibleHeight;
|
|
|
|
return QPoint(0, y);
|
|
|
|
}
|
|
|
|
|
2007-10-05 21:00:44 +00:00
|
|
|
KFileItem DolphinDetailsView::itemForIndex(const QModelIndex& index) const
|
2007-08-28 17:50:54 +00:00
|
|
|
{
|
2007-10-05 21:00:44 +00:00
|
|
|
QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
|
|
|
|
KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
|
|
|
|
const QModelIndex dirIndex = proxyModel->mapToSource(index);
|
|
|
|
return dirModel->itemForIndex(dirIndex);
|
2007-08-28 17:50:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-06 07:16:23 +00:00
|
|
|
KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) 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;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2007-11-07 22:55:15 +00:00
|
|
|
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();
|
|
|
|
QFontMetrics fontMetrics(viewport()->font());
|
|
|
|
|
|
|
|
int columnWidth[KDirModel::ColumnCount];
|
|
|
|
columnWidth[KDirModel::Size] = fontMetrics.width("00000 Items");
|
|
|
|
columnWidth[KDirModel::ModifiedTime] = fontMetrics.width("0000-00-00 00:00");
|
|
|
|
columnWidth[KDirModel::Permissions] = fontMetrics.width("xxxxxxxxxx");
|
|
|
|
columnWidth[KDirModel::Owner] = fontMetrics.width("xxxxxxxxxx");
|
|
|
|
columnWidth[KDirModel::Group] = fontMetrics.width("xxxxxxxxxx");
|
|
|
|
columnWidth[KDirModel::Type] = fontMetrics.width("XXXX Xxxxxxx");
|
|
|
|
|
|
|
|
int requiredWidth = 0;
|
|
|
|
for (int i = KDirModel::Size; i <= KDirModel::Type; ++i) {
|
|
|
|
if (!isColumnHidden(i)) {
|
|
|
|
columnWidth[i] += 20; // provide a default gap
|
|
|
|
requiredWidth += columnWidth[i];
|
|
|
|
headerView->resizeSection(i, columnWidth[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// resize the name column in a way that the whole available width is used
|
|
|
|
columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;
|
|
|
|
if (columnWidth[KDirModel::Name] < 120) {
|
|
|
|
columnWidth[KDirModel::Name] = 120;
|
|
|
|
}
|
|
|
|
headerView->resizeSection(KDirModel::Name, columnWidth[KDirModel::Name]);
|
|
|
|
}
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
#include "dolphindetailsview.moc"
|