Commit f23e9496 authored by Peter Penz's avatar Peter Penz
Browse files

Merged very early alpha-version of Dolphin 2.0

Dolphin 2.0 will get a new view-engine with the
following improvements:
- Better performance
- Animated transitions
- No clipped filenames due to dynamic item-sizes
- Grouping support for all view-modes
- Non-rectangular selection areas
- Simplified code for better maintenance

More details will be provided in a blog-entry during
the next days.

Please note that the code is in a very
early alpha-stage and although the most tricky parts
have been implemented already very basic things like
drag and drop or selections have not been pushed yet.
Those things are rather trivial to implement but this
still will take some time.
parent 69e4007e
......@@ -3,6 +3,9 @@ macro_log_feature(Nepomuk_FOUND "Nepomuk" "Nepomuk" "http://www.kde.org" FALSE "
macro_bool_to_01(Nepomuk_FOUND HAVE_NEPOMUK)
configure_file(config-nepomuk.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-nepomuk.h )
macro_bool_to_01(X11_Xrender_FOUND HAVE_XRENDER)
configure_file(config-X11.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-X11.h )
include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} )
if (Nepomuk_FOUND)
......@@ -15,47 +18,49 @@ add_subdirectory(tests)
########### next target ###############
set(dolphinprivate_LIB_SRCS
kitemviews/kfileitemlistview.cpp
kitemviews/kfileitemlistwidget.cpp
kitemviews/kfileitemmodel.cpp
kitemviews/kfileitemmodelrolesupdater.cpp
kitemviews/kitemlistcontainer.cpp
kitemviews/kitemlistcontroller.cpp
kitemviews/kitemlistgroupheader.cpp
kitemviews/kitemlistselectionmanager.cpp
kitemviews/kitemlistsizehintresolver.cpp
kitemviews/kitemliststyleoption.cpp
kitemviews/kitemlistview.cpp
kitemviews/kitemlistviewanimation.cpp
kitemviews/kitemlistviewlayouter.cpp
kitemviews/kitemlistwidget.cpp
kitemviews/kitemmodelbase.cpp
kitemviews/kpixmapmodifier.cpp
settings/additionalinfodialog.cpp
settings/applyviewpropsjob.cpp
settings/dolphinsettings.cpp
settings/viewpropertiesdialog.cpp
settings/viewpropsprogressinfo.cpp
views/additionalinfoaccessor.cpp
views/dolphincategorydrawer.cpp
views/dolphindirlister.cpp
views/dolphinview.cpp
views/dolphindetailsview.cpp
views/dolphindetailsviewexpander.cpp
views/dolphinfileitemdelegate.cpp
views/dolphiniconsview.cpp
views/dolphincolumnview.cpp
views/dolphincolumnviewcontainer.cpp
views/dolphinmodel.cpp
views/dolphinitemlistcontainer.cpp
views/dolphinnewfilemenuobserver.cpp
views/dolphinremoteencoding.cpp
views/dolphinsortfilterproxymodel.cpp
views/dolphintreeview.cpp
views/dolphinviewactionhandler.cpp
views/dolphinviewautoscroller.cpp
views/dolphinviewcontroller.cpp
views/draganddrophelper.cpp
views/folderexpander.cpp
views/renamedialog.cpp
views/selectiontoggle.cpp
views/selectionmanager.cpp
views/tooltips/filemetadatatooltip.cpp
views/tooltips/tooltipmanager.cpp
views/versioncontrol/pendingthreadsmaintainer.cpp
views/versioncontrol/updateitemstatesthread.cpp
views/versioncontrol/versioncontrolobserver.cpp
views/viewextensionsfactory.cpp
views/viewmodecontroller.cpp
views/viewproperties.cpp
views/zoomlevelinfo.cpp
)
kde4_add_kcfg_files(dolphinprivate_LIB_SRCS
settings/dolphin_columnmodesettings.kcfgc
settings/dolphin_compactmodesettings.kcfgc
settings/dolphin_directoryviewpropertysettings.kcfgc
settings/dolphin_detailsmodesettings.kcfgc
settings/dolphin_iconsmodesettings.kcfgc
......@@ -69,6 +74,10 @@ target_link_libraries(dolphinprivate ${KDE4_KFILE_LIBS} konq ${KDE4_KNEWSTUFF3_L
if (Nepomuk_FOUND)
target_link_libraries(dolphinprivate ${NEPOMUK_LIBRARIES} ${NEPOMUK_QUERY_LIBRARIES} nepomukutils ${SOPRANO_LIBRARIES})
endif (Nepomuk_FOUND)
if(X11_Xrender_FOUND)
target_link_libraries(dolphinprivate ${X11_Xrender_LIB} )
endif(X11_Xrender_FOUND)
set_target_properties(dolphinprivate PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
......@@ -129,7 +138,6 @@ set(dolphin_SRCS
settings/servicemodel.cpp
settings/startup/startupsettingspage.cpp
settings/trash/trashsettingspage.cpp
settings/viewmodes/columnviewsettingspage.cpp
settings/viewmodes/detailsviewsettingspage.cpp
settings/viewmodes/dolphinfontrequester.cpp
settings/viewmodes/iconsizegroupbox.cpp
......@@ -144,6 +152,9 @@ set(dolphin_SRCS
kde4_add_kcfg_files(dolphin_SRCS
panels/folders/dolphin_folderspanelsettings.kcfgc
panels/information/dolphin_informationpanelsettings.kcfgc
settings/dolphin_compactmodesettings.kcfgc
settings/dolphin_detailsmodesettings.kcfgc
settings/dolphin_iconsmodesettings.kcfgc
search/dolphin_searchsettings.kcfgc
settings/dolphin_versioncontrolsettings.kcfgc
)
......@@ -190,7 +201,6 @@ install(TARGETS dolphin ${INSTALL_TARGETS_DEFAULT_ARGS})
set(kcm_dolphinviewmodes_PART_SRCS
settings/kcm/kcmdolphinviewmodes.cpp
settings/viewmodes/columnviewsettingspage.cpp
settings/viewmodes/detailsviewsettingspage.cpp
settings/viewmodes/dolphinfontrequester.cpp
settings/viewmodes/iconsizegroupbox.cpp
......@@ -221,7 +231,7 @@ set(kcm_dolphingeneral_PART_SRCS
settings/servicemodel.cpp)
kde4_add_kcfg_files(kcm_dolphinviewmodes_PART_SRCS
settings/dolphin_columnmodesettings.kcfgc
settings/dolphin_compactmodesettings.kcfgc
settings/dolphin_directoryviewpropertysettings.kcfgc
settings/dolphin_detailsmodesettings.kcfgc
settings/dolphin_iconsmodesettings.kcfgc
......@@ -273,7 +283,7 @@ install(TARGETS kio_filenamesearch DESTINATION ${PLUGIN_INSTALL_DIR})
install( PROGRAMS dolphin.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
install( FILES settings/dolphin_directoryviewpropertysettings.kcfg
settings/dolphin_generalsettings.kcfg
settings/dolphin_columnmodesettings.kcfg
settings/dolphin_compactmodesettings.kcfg
settings/dolphin_iconsmodesettings.kcfg
settings/dolphin_detailsmodesettings.kcfg
settings/dolphin_versioncontrolsettings.kcfg
......
#cmakedefine HAVE_XRENDER 1
......@@ -234,7 +234,7 @@ void DolphinContextMenu::openItemContextMenu()
// setup 'Create New' menu
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow);
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
newFileMenu->checkUpToDate();
newFileMenu->setPopupFiles(m_fileInfo.url());
newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
......@@ -320,7 +320,7 @@ void DolphinContextMenu::openViewportContextMenu()
// setup 'Create New' menu
KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu();
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
newFileMenu->checkUpToDate();
newFileMenu->setPopupFiles(m_baseUrl);
m_popup->addMenu(newFileMenu->menu());
......
......@@ -42,7 +42,6 @@
#include "statusbar/dolphinstatusbar.h"
#include "views/dolphinviewactionhandler.h"
#include "views/dolphinremoteencoding.h"
#include "views/draganddrophelper.h"
#include "views/viewproperties.h"
#ifndef Q_OS_WIN
......@@ -161,8 +160,8 @@ DolphinMainWindow::DolphinMainWindow() :
this, SLOT(showCommand(CommandType)));
connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
this, SLOT(showErrorMessage(const QString&)));
connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
this, SLOT(showErrorMessage(const QString&)));
//connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
// this, SLOT(showErrorMessage(const QString&)));
const DolphinSettings& settings = DolphinSettings::instance();
......@@ -725,14 +724,14 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group)
void DolphinMainWindow::updateNewMenu()
{
m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
m_newFileMenu->checkUpToDate();
m_newFileMenu->setPopupFiles(activeViewContainer()->url());
}
void DolphinMainWindow::createDirectory()
{
m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
m_newFileMenu->setPopupFiles(activeViewContainer()->url());
m_newFileMenu->createDirectory();
}
......@@ -1313,7 +1312,8 @@ void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
if (!urls.isEmpty() && tab != -1) {
const ViewTab& viewTab = m_viewTab[tab];
const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
Q_UNUSED(destPath);
//DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
}
}
......@@ -2178,7 +2178,7 @@ void DolphinMainWindow::createSecondaryView(int tabIndex)
const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
m_viewTab[tabIndex].secondaryView = createViewContainer(view->rootUrl(), 0);
m_viewTab[tabIndex].secondaryView = createViewContainer(view->url(), 0);
splitter->addWidget(m_viewTab[tabIndex].secondaryView);
splitter->setSizes(QList<int>() << newWidth << newWidth);
connectViewSignals(m_viewTab[tabIndex].secondaryView);
......
......@@ -44,8 +44,6 @@
#include "settings/dolphinsettings.h"
#include "views/dolphinview.h"
#include "views/dolphinviewactionhandler.h"
#include "views/dolphinsortfilterproxymodel.h"
#include "views/dolphinmodel.h"
#include "views/dolphinnewfilemenuobserver.h"
#include "views/dolphinremoteencoding.h"
#include "views/dolphindirlister.h"
......@@ -96,7 +94,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL
this, SLOT(slotSelectionChanged(KFileItemList)));
connect(m_view, SIGNAL(requestItemInfo(KFileItem)),
this, SLOT(slotRequestItemInfo(KFileItem)));
connect(m_view, SIGNAL(modeChanged()),
connect(m_view, SIGNAL(modeChanged(DolphinView::Mode,DolphinView::Mode)),
this, SIGNAL(viewModeChanged())); // relay signal
connect(m_view, SIGNAL(redirection(KUrl, KUrl)),
this, SLOT(slotRedirection(KUrl, KUrl)));
......@@ -531,7 +529,7 @@ void DolphinPart::updateNewMenu()
{
// As requested by KNewFileMenu :
m_newFileMenu->checkUpToDate();
m_newFileMenu->setViewShowsHiddenFiles(m_view->showHiddenFiles());
m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
// And set the files that the menu apply on :
m_newFileMenu->setPopupFiles(url());
}
......@@ -548,7 +546,7 @@ void DolphinPart::updateProgress(int percent)
void DolphinPart::createDirectory()
{
m_newFileMenu->setViewShowsHiddenFiles(m_view->showHiddenFiles());
m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
m_newFileMenu->setPopupFiles(url());
m_newFileMenu->createDirectory();
}
......
......@@ -271,7 +271,7 @@ Name[te]=వివరాలు
Name[tg]=Тафсилотҳо
Name[th]=รายละเอียด
Name[tr]=Ayrıntılar
Name[ug]=تەپسىلاتى
Name[ug]=تەپسىلاتلار
Name[uk]=Подробиці
Name[uz]=Tafsilotlar
Name[uz@cyrillic]=Тафсилотлар
......
......@@ -90,8 +90,8 @@
<Action name="go_forward" />
<Separator name="separator_1" />
<Action name="icons" />
<Action name="compact" />
<Action name="details" />
<Action name="columns" />
<Separator name="separator_0" />
<Action name="edit_find"/>
<Action name="show_preview" />
......@@ -104,8 +104,8 @@
<Action priority="0" name="go_home"/>
<Action priority="0" name="stop"/>
<Action priority="0" name="icons"/>
<Action priority="0" name="compact"/>
<Action priority="0" name="details"/>
<Action priority="0" name="columns"/>
<Action priority="0" name="view_zoom_in"/>
<Action priority="0" name="view_zoom_out"/>
<Action priority="0" name="edit_cut"/>
......
......@@ -51,12 +51,6 @@
#include "search/dolphinsearchbox.h"
#include "settings/dolphinsettings.h"
#include "statusbar/dolphinstatusbar.h"
#include "views/dolphincolumnview.h"
#include "views/dolphindetailsview.h"
#include "views/draganddrophelper.h"
#include "views/dolphiniconsview.h"
#include "views/dolphinmodel.h"
#include "views/dolphinviewcontroller.h"
#include "views/viewmodecontroller.h"
#include "views/viewproperties.h"
......@@ -115,11 +109,12 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
connect(m_view, SIGNAL(urlIsFileError(const KUrl&)), this, SLOT(openFile(const KUrl&)));
connect(m_view, SIGNAL(selectionChanged(const KFileItemList&)), this, SLOT(delayedStatusBarUpdate()));
connect(m_view, SIGNAL(operationCompletedMessage(const QString&)), this, SLOT(showOperationCompletedMessage(const QString&)));
connect(m_view, SIGNAL(urlAboutToBeChanged(const KUrl&)), this, SLOT(slotViewUrlAboutToBeChanged(const KUrl&)));
connect(m_urlNavigator, SIGNAL(urlAboutToBeChanged(const KUrl&)),
this, SLOT(slotUrlNavigatorLocationAboutToBeChanged(const KUrl&)));
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(slotUrlNavigatorLocationChanged(const KUrl&)));
connect(m_urlNavigator, SIGNAL(urlAboutToBeChanged(const KUrl&)),
this, SLOT(saveViewState()));
connect(m_urlNavigator, SIGNAL(historyChanged()),
this, SLOT(slotHistoryChanged()));
......@@ -378,6 +373,50 @@ void DolphinViewContainer::slotFinishedPathLoading()
}
}
void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
{
KUrl url = item.targetUrl();
if (item.isDir()) {
m_view->setUrl(url);
return;
}
const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
const bool browseThroughArchives = settings->browseThroughArchives();
if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
// Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
// zip:/<path>/ when clicking on a zip file, etc.
// The .protocol file specifies the mimetype that the kioslave handles.
// Note that we don't use mimetype inheritance since we don't want to
// open OpenDocument files as zip folders...
const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
if (!protocol.isEmpty()) {
url.setProtocol(protocol);
m_view->setUrl(url);
return;
}
}
if (item.mimetype() == QLatin1String("application/x-desktop")) {
// Redirect to the URL in Type=Link desktop files
KDesktopFile desktopFile(url.toLocalFile());
if (desktopFile.hasLinkType()) {
url = desktopFile.readUrl();
m_view->setUrl(url);
return;
}
}
item.run();
}
void DolphinViewContainer::openFile(const KUrl& url)
{
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
slotItemTriggered(item);
}
void DolphinViewContainer::showItemInfo(const KFileItem& item)
{
if (item.isNull()) {
......@@ -427,20 +466,36 @@ void DolphinViewContainer::activate()
setActive(true);
}
void DolphinViewContainer::saveViewState()
void DolphinViewContainer::slotViewUrlAboutToBeChanged(const KUrl& url)
{
QByteArray locationState;
QDataStream stream(&locationState, QIODevice::WriteOnly);
m_view->saveState(stream);
m_urlNavigator->saveLocationState(locationState);
// URL changes of the view can happen in two ways:
// 1. The URL navigator gets changed and will trigger the view to update its URL
// 2. The URL of the view gets changed and will trigger the URL navigator to update
// its URL (e.g. by clicking on an item)
// In this scope the view-state may only get saved in case 2:
if (url != m_urlNavigator->locationUrl()) {
saveViewState();
}
}
void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const KUrl& url)
{
// URL changes of the view can happen in two ways:
// 1. The URL navigator gets changed and will trigger the view to update its URL
// 2. The URL of the view gets changed and will trigger the URL navigator to update
// its URL (e.g. by clicking on an item)
// In this scope the view-state may only get saved in case 1:
if (url != m_view->url()) {
saveViewState();
}
}
void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
{
if (KProtocolManager::supportsListing(url)) {
setSearchModeEnabled(isSearchUrl(url));
m_view->setUrl(url);
if (isActive() && !isSearchUrl(url)) {
// When an URL has been entered, the view should get the focus.
// The focus must be requested asynchronously, as changing the URL might create
......@@ -476,7 +531,9 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
{
DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
Q_UNUSED(destination);
Q_UNUSED(event);
//DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
}
void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
......@@ -510,7 +567,6 @@ void DolphinViewContainer::saveUrlCompletionMode(KGlobalSettings::Completion com
void DolphinViewContainer::slotHistoryChanged()
{
QByteArray locationState = m_urlNavigator->locationState();
if (!locationState.isEmpty()) {
QDataStream stream(&locationState, QIODevice::ReadOnly);
m_view->restoreState(stream);
......@@ -543,48 +599,12 @@ bool DolphinViewContainer::isSearchUrl(const KUrl& url) const
return protocol.contains("search") || (protocol == QLatin1String("nepomuk"));
}
void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
{
KUrl url = item.targetUrl();
if (item.isDir()) {
m_view->setUrl(url);
return;
}
const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
const bool browseThroughArchives = settings->browseThroughArchives();
if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
// Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
// zip:/<path>/ when clicking on a zip file, etc.
// The .protocol file specifies the mimetype that the kioslave handles.
// Note that we don't use mimetype inheritance since we don't want to
// open OpenDocument files as zip folders...
const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
if (!protocol.isEmpty()) {
url.setProtocol(protocol);
m_view->setUrl(url);
return;
}
}
if (item.mimetype() == "application/x-desktop") {
// redirect to the url in Type=Link desktop files
KDesktopFile desktopFile(url.toLocalFile());
if (desktopFile.hasLinkType()) {
url = desktopFile.readUrl();
m_view->setUrl(url);
return;
}
}
item.run();
}
void DolphinViewContainer::openFile(const KUrl& url)
void DolphinViewContainer::saveViewState()
{
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
slotItemTriggered(item);
QByteArray locationState;
QDataStream stream(&locationState, QIODevice::WriteOnly);
m_view->saveState(stream);
m_urlNavigator->saveLocationState(locationState);
}
#include "dolphinviewcontainer.moc"
......@@ -42,7 +42,7 @@ class DolphinStatusBar;
* @short Represents a view for the directory content
* including the navigation bar, filter bar and status bar.
*
* View modes for icons, details and columns are supported. Currently
* View modes for icons, compact and details are supported. Currently
* Dolphin allows to have up to two views inside the main window.
*
* @see DolphinView
......@@ -212,10 +212,16 @@ private slots:
void activate();
/**
* Saves the state of the current view: contents position,
* root URL, ...
* Is invoked if the signal urlAboutToBeChanged() from the DolphinView
* is emitted. Tries to save the view-state.
*/
void saveViewState();
void slotViewUrlAboutToBeChanged(const KUrl& url);
/**
* Is invoked if the signal urlAboutToBeChanged() from the URL navigator
* is emitted. Tries to save the view-state.
*/
void slotUrlNavigatorLocationAboutToBeChanged(const KUrl& url);
/**
* Restores the current view to show \a url and assures
......@@ -266,6 +272,12 @@ private:
*/
bool isSearchUrl(const KUrl& url) const;
/**
* Saves the state of the current view: contents position,
* root URL, ...
*/
void saveViewState();
private:
QVBoxLayout* m_topLayout;
KUrlNavigator* m_urlNavigator;
......
/***************************************************************************
* Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
* *
* 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 "kfileitemlistview.h"
#include "kitemlistgroupheader.h"
#include "kfileitemmodelrolesupdater.h"
#include "kfileitemlistwidget.h"
#include "kfileitemmodel.h"
#include <KLocale>
#include <KStringHandler>
#include <KDebug>
#include <QTextLine>
#include <QTimer>
#define KFILEITEMLISTVIEW_DEBUG
namespace {
const int ShortInterval = 50;
const int LongInterval = 300;
}
KFileItemListView::KFileItemListView(QGraphicsWidget* parent) :
KItemListView(parent),
m_itemLayout(IconsLayout),
m_modelRolesUpdater(0),
m_updateVisibleIndexRangeTimer(0),
m_updateIconSizeTimer(0),
m_minimumRolesWidths()
{
setScrollOrientation(Qt::Vertical);
setWidgetCreator(new KItemListWidgetCreator<KFileItemListWidget>());
setGroupHeaderCreator(new KItemListGroupHeaderCreator<KItemListGroupHeader>());
m_updateVisibleIndexRangeTimer = new QTimer(this);
m_updateVisibleIndexRangeTimer->setSingleShot(true);
m_updateVisibleIndexRangeTimer->setInterval(ShortInterval);
connect(m_updateVisibleIndexRangeTimer, SIGNAL(timeout()), this, SLOT(updateVisibleIndexRange()));
m_updateIconSizeTimer = new QTimer(this);
m_updateIconSizeTimer->setSingleShot(true);
m_updateIconSizeTimer->setInterval(ShortInterval);
connect(m_updateIconSizeTimer, SIGNAL(timeout()), this, SLOT(updateIconSize()));
updateMinimumRolesWidths();
}
KFileItemListView::~KFileItemListView()
{
delete widgetCreator();
delete groupHeaderCreator();
delete m_modelRolesUpdater;
m_modelRolesUpdater = 0;
}
void KFileItemListView::setPreviewsShown(bool show)
{
if (m_modelRolesUpdater) {
m_modelRolesUpdater->setPreviewShown(show);
}
}
bool KFileItemListView::previewsShown() const
{
return m_modelRolesUpdater->isPreviewShown();
}
void KFileItemListView::setItemLayout(Layout layout)
{
if (m_itemLayout != layout) {
m_itemLayout = layout;
updateLayoutOfVisibleItems();
}
}
KFileItemListView::Layout KFileItemListView::itemLayout() const
{
return m_itemLayout;
}
QSizeF KFileItemListView::itemSizeHint(int index) const
{
const QHash<QByteArray, QVariant> values = model()->data(index);
const KItemListStyleOption& option = styleOption();
const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
switch (m_itemLayout) {
case IconsLayout: {
const QString text = KStringHandler::preProcessWrap(values["name"].toString());
const qreal maxWidth = itemSize().width() - 2 * option.margin;
int textLinesCount = 0;
QTextLine line;
// Calculate the number of lines required for wrapping the name
QTextOption textOption(Qt::AlignHCenter);
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
QTextLayout layout(text, option.font);