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-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-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"
|
|
|
|
|
2007-02-06 06:43:34 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <kdirmodel.h>
|
2007-01-25 22:28:04 +00:00
|
|
|
#include <QHeaderView>
|
|
|
|
|
2007-02-14 21:54:24 +00:00
|
|
|
DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
|
2007-01-25 22:28:04 +00:00
|
|
|
QTreeView(parent),
|
2007-02-14 21:54:24 +00:00
|
|
|
m_controller(controller)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-02-14 21:54:24 +00:00
|
|
|
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-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-02-06 06:43:34 +00:00
|
|
|
connect(header(), SIGNAL(sectionClicked(int)),
|
|
|
|
this, SLOT(synchronizeSortingState(int)));
|
|
|
|
|
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
|
|
|
|
|
|
|
connect(this, SIGNAL(clicked(const QModelIndex&)),
|
|
|
|
controller, SLOT(triggerItem(const QModelIndex&)));
|
2007-02-27 20:46:21 +00:00
|
|
|
|
|
|
|
// apply the details mode settings to the widget
|
|
|
|
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
|
|
|
assert(settings != 0);
|
|
|
|
|
|
|
|
m_viewOptions = QTreeView::viewOptions();
|
|
|
|
m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize());
|
|
|
|
const int iconSize = settings->iconSize();
|
|
|
|
m_viewOptions.decorationSize = QSize(iconSize, iconSize);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DolphinDetailsView::~DolphinDetailsView()
|
|
|
|
{
|
|
|
|
}
|
2007-01-25 22:28:04 +00:00
|
|
|
|
|
|
|
bool DolphinDetailsView::event(QEvent* event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Polish) {
|
|
|
|
// Assure that by respecting the available width that:
|
|
|
|
// - the 'Name' column is stretched as large as possible
|
|
|
|
// - the remaining columns are as small as possible
|
|
|
|
QHeaderView* headerView = header();
|
|
|
|
headerView->setStretchLastSection(false);
|
|
|
|
headerView->setResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
headerView->setResizeMode(0, QHeaderView::Stretch);
|
2007-02-28 06:00:58 +00:00
|
|
|
|
|
|
|
// hide columns if this is indicated by the settings
|
|
|
|
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
|
|
|
assert(settings != 0);
|
|
|
|
if (!settings->showDate()) {
|
|
|
|
hideColumn(KDirModel::ModifiedTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!settings->showPermissions()) {
|
|
|
|
hideColumn(KDirModel::Permissions);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!settings->showOwner()) {
|
|
|
|
hideColumn(KDirModel::Owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!settings->showGroup()) {
|
|
|
|
hideColumn(KDirModel::Group);
|
|
|
|
}
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QTreeView::event(event);
|
|
|
|
}
|
|
|
|
QStyleOptionViewItem DolphinDetailsView::viewOptions() const
|
|
|
|
{
|
2007-02-27 20:46:21 +00:00
|
|
|
return m_viewOptions;
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::contextMenuEvent(event);
|
2007-02-16 17:03:02 +00:00
|
|
|
m_controller->triggerContextMenuRequest(event->pos());
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
QTreeView::mouseReleaseEvent(event);
|
2007-02-14 21:54:24 +00:00
|
|
|
m_controller->triggerActivation();
|
2007-01-25 22:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinDetailsView::dropEvent(QDropEvent* event)
|
|
|
|
{
|
2007-02-16 17:03:02 +00:00
|
|
|
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
|
|
|
if (urls.isEmpty() || (event->source() == this)) {
|
|
|
|
QTreeView::dropEvent(event);
|
|
|
|
}
|
|
|
|
else {
|
2007-01-25 22:28:04 +00:00
|
|
|
event->acceptProposedAction();
|
2007-02-16 17:03:02 +00:00
|
|
|
m_controller->indicateDroppedUrls(urls, event->pos());
|
|
|
|
}
|
2007-01-25 22:28:04 +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
|
|
|
}
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
#include "dolphindetailsview.moc"
|