• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KFile

kdiroperatordetailview.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at>                      *
00003  *                                                                           *
00004  * This library is free software; you can redistribute it and/or             *
00005  * modify it under the terms of the GNU Library General Public               *
00006  * License version 2 as published by the Free Software Foundation.           *
00007  *                                                                           *
00008  * This library is distributed in the hope that it will be useful,           *
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00011  * Library General Public License for more details.                          *
00012  *                                                                           *
00013  * You should have received a copy of the GNU Library General Public License *
00014  * along with this library; see the file COPYING.LIB.  If not, write to      *
00015  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
00016  * Boston, MA 02110-1301, USA.                                               *
00017  *****************************************************************************/
00018 
00019 #include "kdiroperatordetailview_p.h"
00020 
00021 #include <kdirlister.h>
00022 #include <kdirmodel.h>
00023 
00024 #include <QtCore/QEvent>
00025 #include <QtCore/QTimer>
00026 #include <QtGui/QAbstractProxyModel>
00027 #include <QtGui/QApplication>
00028 #include <QtGui/QHeaderView>
00029 #include <QtGui/QListView>
00030 #include <QtGui/QResizeEvent>
00031 #include <QtGui/QScrollBar>
00032 
00033 KDirOperatorDetailView::KDirOperatorDetailView(QWidget *parent) :
00034     QTreeView(parent),
00035     m_resizeColumns(true)
00036 {
00037     setRootIsDecorated(false);
00038     setSortingEnabled(true);
00039     setUniformRowHeights(true);
00040     setDragDropMode(QListView::DragOnly);
00041     setSelectionBehavior(QAbstractItemView::SelectRows);
00042     setEditTriggers(QAbstractItemView::NoEditTriggers);
00043     setVerticalScrollMode(QListView::ScrollPerPixel);
00044     setHorizontalScrollMode(QListView::ScrollPerPixel);
00045 }
00046 
00047 KDirOperatorDetailView::~KDirOperatorDetailView()
00048 {
00049 }
00050 
00051 void KDirOperatorDetailView::setModel(QAbstractItemModel *model)
00052 {
00053     if (model->rowCount() == 0) {
00054         // The model is empty. Assure that the columns get automatically resized
00055         // until the loading has been finished.
00056         QAbstractProxyModel *proxyModel = static_cast<QAbstractProxyModel*>(model);
00057         KDirModel *dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
00058         connect(dirModel->dirLister(), SIGNAL(completed()),
00059                 this, SLOT(resetResizing()));
00060     } else {
00061         resetResizing();
00062     }
00063 
00064     QTreeView::setModel(model);
00065 }
00066 
00067 bool KDirOperatorDetailView::event(QEvent *event)
00068 {
00069     if (event->type() == QEvent::Polish) {
00070         QHeaderView *headerView = header();
00071         headerView->setResizeMode(QHeaderView::Interactive);
00072         headerView->setStretchLastSection(false);
00073         headerView->setMovable(false);
00074 
00075         hideColumn(KDirModel::Permissions);
00076         hideColumn(KDirModel::Owner);
00077         hideColumn(KDirModel::Group);
00078     }
00079     else if (event->type() == QEvent::UpdateRequest) {
00080         // A wheel movement will scroll 4 items
00081         if (model()->rowCount())
00082             verticalScrollBar()->setSingleStep((sizeHintForRow(0) / 3) * 4);
00083     }
00084 
00085     return QTreeView::event(event);
00086 }
00087 
00088 void KDirOperatorDetailView::dragEnterEvent(QDragEnterEvent *event)
00089 {
00090     if (event->mimeData()->hasUrls()) {
00091         event->acceptProposedAction();
00092     }
00093 }
00094 
00095 void KDirOperatorDetailView::resizeEvent(QResizeEvent *event)
00096 {
00097     QTreeView::resizeEvent(event);
00098 
00099     if (m_resizeColumns) {
00100         QHeaderView *headerView = header();
00101         headerView->resizeSections(QHeaderView::ResizeToContents);
00102 
00103         // calculate the required width for all columns except the name column
00104         int requiredWidth = 0;
00105         const int count = headerView->count();
00106         for (int i = 1; i < count; ++i) {
00107             requiredWidth += headerView->sectionSize(i);
00108         }
00109 
00110         // try to stretch the name column if enough width is available
00111         const int oldNameColumnWidth = headerView->sectionSize(KDirModel::Name);
00112         int nameColumnWidth = viewport()->width() - requiredWidth;
00113         if (nameColumnWidth < oldNameColumnWidth) {
00114             nameColumnWidth = oldNameColumnWidth;
00115         }
00116         headerView->resizeSection(KDirModel::Name, nameColumnWidth);
00117     }
00118 }
00119 
00120 void KDirOperatorDetailView::mousePressEvent(QMouseEvent *event)
00121 {
00122     QTreeView::mousePressEvent(event);
00123 
00124     const QModelIndex index = indexAt(event->pos());
00125     if (!index.isValid() || (index.column() != KDirModel::Name)) {
00126         const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
00127         if (!(modifiers & Qt::ShiftModifier) && !(modifiers & Qt::ControlModifier)) {
00128             clearSelection();
00129         }
00130     }
00131 }
00132 
00133 void KDirOperatorDetailView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
00134 {
00135     QTreeView::currentChanged(current, previous);
00136     selectionModel()->select(current, QItemSelectionModel::ClearAndSelect);
00137 }
00138 
00139 void KDirOperatorDetailView::resetResizing()
00140 {
00141     QTimer::singleShot(300, this, SLOT(disableColumnResizing()));
00142 }
00143 
00144 void KDirOperatorDetailView::disableColumnResizing()
00145 {
00146     m_resizeColumns = false;
00147 }

KFile

Skip menu "KFile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal