From 0e3d1576d5d369ce49985eb75df39693336fc354 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 24 Nov 2006 22:10:33 +0000 Subject: [PATCH] Initial step for moving to KDirModel. Large code parts have been deleted, as a step by step migration makes no sense. Check KDE3 version of Dolphin as reference how things have been done before. svn path=/trunk/playground/utils/dolphin/; revision=607513 --- src/CMakeLists.txt | 73 ++-- src/dolphindetailsview.cpp | 788 +--------------------------------- src/dolphindetailsview.h | 181 +------- src/dolphiniconsview.cpp | 484 +-------------------- src/dolphiniconsview.h | 134 +----- src/dolphinview.cpp | 266 ++++-------- src/dolphinview.h | 21 +- src/iconsviewsettingspage.cpp | 10 +- src/iconsviewsettingspage.h | 4 +- src/itemeffectsmanager.cpp | 189 -------- src/itemeffectsmanager.h | 120 ------ src/viewsettingspage.cpp | 5 +- 12 files changed, 152 insertions(+), 2123 deletions(-) delete mode 100644 src/itemeffectsmanager.cpp delete mode 100644 src/itemeffectsmanager.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66acfa1e1b..c701e14a75 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,47 +7,46 @@ include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) ########### next target ############### -set(dolphin_SRCS - main.cpp - dolphin.cpp - dolphinview.cpp - urlnavigator.cpp - urlnavigatorbutton.cpp - viewpropertiesdialog.cpp - dolphinstatusbar.cpp - dolphindirlister.cpp - viewproperties.cpp - dolphindetailsview.cpp - dolphiniconsview.cpp - dolphinsettings.cpp - bookmarkselector.cpp - urlbutton.cpp - itemeffectsmanager.cpp - dolphincontextmenu.cpp - undomanager.cpp - progressindicator.cpp - iconsviewsettingspage.cpp - pixmapviewer.cpp - dolphinsettingsdialog.cpp - viewsettingspage.cpp - detailsviewsettingspage.cpp - statusbarmessagelabel.cpp - generalsettingspage.cpp - bookmarkssettingspage.cpp - editbookmarkdialog.cpp - settingspagebase.cpp - sidebar.cpp - sidebarpage.cpp - bookmarkssidebarpage.cpp - infosidebarpage.cpp - statusbarspaceinfo.cpp - renamedialog.cpp - filterbar.cpp +set(dolphin_SRCS + main.cpp + dolphin.cpp + dolphinview.cpp + urlnavigator.cpp + urlnavigatorbutton.cpp + viewpropertiesdialog.cpp + dolphinstatusbar.cpp + dolphindirlister.cpp + viewproperties.cpp + dolphindetailsview.cpp + dolphiniconsview.cpp + dolphinsettings.cpp + bookmarkselector.cpp + urlbutton.cpp + dolphincontextmenu.cpp + undomanager.cpp + progressindicator.cpp + iconsviewsettingspage.cpp + pixmapviewer.cpp + dolphinsettingsdialog.cpp + viewsettingspage.cpp + detailsviewsettingspage.cpp + statusbarmessagelabel.cpp + generalsettingspage.cpp + bookmarkssettingspage.cpp + editbookmarkdialog.cpp + settingspagebase.cpp + sidebar.cpp + sidebarpage.cpp + bookmarkssidebarpage.cpp + infosidebarpage.cpp + statusbarspaceinfo.cpp + renamedialog.cpp + filterbar.cpp protocolcombo.cpp ) kde4_automoc(${dolphin_SRCS}) -kde4_add_kcfg_files(dolphin_SRCS +kde4_add_kcfg_files(dolphin_SRCS directoryviewpropertysettings.kcfgc generalsettings.kcfgc iconsmodesettings.kcfgc diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 9e1e0ab270..ad86302384 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -19,800 +19,14 @@ ***************************************************************************/ #include "dolphindetailsview.h" - -#include -#include -#include -#include -#include -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "dolphinview.h" -#include "viewproperties.h" -#include "dolphin.h" -#include "kiconeffect.h" -#include "dolphinsettings.h" -#include "dolphinstatusbar.h" -#include "detailsmodesettings.h" DolphinDetailsView::DolphinDetailsView(DolphinView* parent) : - KFileDetailView(parent), - m_dolphinView(parent), - m_resizeTimer(0), - m_scrollTimer(0), - m_rubber(0) + QListView(parent) { - m_resizeTimer = new QTimer(this); - connect(m_resizeTimer, SIGNAL(timeout()), - this, SLOT(updateColumnsWidth())); - - setAcceptDrops(true); - setSelectionMode(KFile::Extended); - setHScrollBarMode(Q3ScrollView::AlwaysOff); - - setColumnAlignment(SizeColumn, Qt::AlignRight); - for (int i = DateColumn; i <= GroupColumn; ++i) { - setColumnAlignment(i, Qt::AlignHCenter); - } - - Dolphin& dolphin = Dolphin::mainWin(); - - connect(this, SIGNAL(onItem(Q3ListViewItem*)), - this, SLOT(slotOnItem(Q3ListViewItem*))); - connect(this, SIGNAL(onViewport()), - this, SLOT(slotOnViewport())); - connect(this, SIGNAL(contextMenuRequested(Q3ListViewItem*, const QPoint&, int)), - this, SLOT(slotContextMenuRequested(Q3ListViewItem*, const QPoint&, int))); - connect(this, SIGNAL(selectionChanged()), - &dolphin, SLOT(slotSelectionChanged())); - connect(&dolphin, SIGNAL(activeViewChanged()), - this, SLOT(slotActivationUpdate())); - connect(this, SIGNAL(itemRenamed(Q3ListViewItem*, const QString&, int)), - this, SLOT(slotItemRenamed(Q3ListViewItem*, const QString&, int))); - connect(this, SIGNAL(dropped(QDropEvent*, const KUrl::List&, const KUrl&)), - parent, SLOT(slotUrlListDropped(QDropEvent*, const KUrl::List&, const KUrl&))); - - QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(slotUpdateDisabledItems())); - - Q3Header* viewHeader = header(); - viewHeader->setResizeEnabled(false); - viewHeader->setMovingEnabled(false); - connect(viewHeader, SIGNAL(clicked(int)), - this, SLOT(slotHeaderClicked(int))); - - setMouseTracking(true); - setDefaultRenameAction(Q3ListView::Accept); - - refreshSettings(); } DolphinDetailsView::~DolphinDetailsView() { - delete m_rubber; - m_rubber = 0; -} - -void DolphinDetailsView::beginItemUpdates() -{ -} - -void DolphinDetailsView::endItemUpdates() -{ - updateDisabledItems(); - - // Restore the current item. Use the information stored in the history if - // available. Otherwise use the first item as current item. - - const KFileListViewItem* item = static_cast(firstChild()); - if (item != 0) { - setCurrentItem(item->fileInfo()); - } - - int index = 0; - const Q3ValueList history = m_dolphinView->urlHistory(index); - if (!history.isEmpty()) { - KFileView* fileView = static_cast(this); - fileView->setCurrentItem(history[index].currentFileName()); - setContentsPos(history[index].contentsX(), history[index].contentsY()); - } - - updateColumnsWidth(); -} - -void DolphinDetailsView::insertItem(KFileItem* fileItem) -{ - KFileView::insertItem(fileItem); - - DolphinListViewItem* item = new DolphinListViewItem(static_cast(this), fileItem); - - QDir::SortFlags spec = KFileView::sorting(); - if (spec & QDir::Time) { - item->setKey(sortingKey(fileItem->time(KIO::UDS_MODIFICATION_TIME), - fileItem->isDir(), - spec)); - } - else if (spec & QDir::Size) { - item->setKey(sortingKey(fileItem->size(), fileItem->isDir(), spec)); - } - else { - item->setKey(sortingKey(fileItem->text(), fileItem->isDir(), spec)); - } - - fileItem->setExtraData(this, item); -} - -bool DolphinDetailsView::isOnFilename(const Q3ListViewItem* item, const QPoint& pos) const -{ - const QPoint absPos(mapToGlobal(QPoint(0, 0))); - return (pos.x() - absPos.x()) <= filenameWidth(item); -} - -void DolphinDetailsView::refreshSettings() -{ - const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - assert(settings != 0); - - if (!settings->showGroup()) { - removeColumn(GroupColumn); - } - if (!settings->showOwner()) { - removeColumn(OwnerColumn); - } - if (!settings->showPermissions()) { - removeColumn(PermissionsColumn); - } - if (!settings->showDate()) { - removeColumn(DateColumn); - } - - QFont adjustedFont(font()); - adjustedFont.setFamily(settings->fontFamily()); - adjustedFont.setPointSize(settings->fontSize()); - setFont(adjustedFont); - - updateView(true); -} - -void DolphinDetailsView::zoomIn() -{ - if (isZoomInPossible()) { - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - switch (settings->iconSize()) { - case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break; - case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break; - default: assert(false); break; - } - ItemEffectsManager::zoomIn(); - } -} - -void DolphinDetailsView::zoomOut() -{ - if (isZoomOutPossible()) { - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - switch (settings->iconSize()) { - case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break; - case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break; - default: assert(false); break; - } - ItemEffectsManager::zoomOut(); - } -} - -bool DolphinDetailsView::isZoomInPossible() const -{ - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - return settings->iconSize() < K3Icon::SizeLarge; -} - -bool DolphinDetailsView::isZoomOutPossible() const -{ - DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - return settings->iconSize() > K3Icon::SizeSmall; -} - -void DolphinDetailsView::resizeContents(int width, int height) -{ - KFileDetailView::resizeContents(width, height); - - // When loading several 1000 items a punch of resize events - // drops in. As updating the column width is a quite expensive - // operation, this operation will be postponed until there is - // no resize event for at least 50 milliseconds. - m_resizeTimer->stop(); - m_resizeTimer->start(50, true); -} - -void DolphinDetailsView::slotOnItem(Q3ListViewItem* item) -{ - if (isOnFilename(item, QCursor::pos())) { - activateItem(item); - KFileItem* fileItem = static_cast(item)->fileInfo(); - m_dolphinView->requestItemInfo(fileItem->url()); - } - else { - resetActivatedItem(); - } -} - -void DolphinDetailsView::slotOnViewport() -{ - resetActivatedItem(); - m_dolphinView->requestItemInfo(KUrl()); -} - -void DolphinDetailsView::setContextPixmap(void* context, - const QPixmap& pixmap) -{ - reinterpret_cast(context)->setPixmap(0, pixmap); -} - -const QPixmap* DolphinDetailsView::contextPixmap(void* context) -{ - return reinterpret_cast(context)->pixmap(0); -} - -void* DolphinDetailsView::firstContext() -{ - return reinterpret_cast(firstChild()); -} - -void* DolphinDetailsView::nextContext(void* context) -{ - KFileListViewItem* listViewItem = reinterpret_cast(context); - return reinterpret_cast(listViewItem->nextSibling()); -} - -KFileItem* DolphinDetailsView::contextFileInfo(void* context) -{ - return reinterpret_cast(context)->fileInfo(); -} - - -void DolphinDetailsView::contentsDragMoveEvent(QDragMoveEvent* event) -{ - KFileDetailView::contentsDragMoveEvent(event); - - // If a dragging is done above a directory, show the icon as 'active' for - // a visual feedback - KFileListViewItem* item = static_cast(itemAt(event->pos())); - - bool showActive = false; - if (item != 0) { - const KFileItem* fileInfo = item->fileInfo(); - showActive = (fileInfo != 0) && fileInfo->isDir(); - } - - if (showActive) { - slotOnItem(item); - } - else { - slotOnViewport(); - } -} - -void DolphinDetailsView::resizeEvent(QResizeEvent* event) -{ - KFileDetailView::resizeEvent(event); - - // When loading several 1000 items a punch of resize events - // drops in. As updating the column width is a quite expensive - // operation, this operation will be postponed until there is - // no resize event for at least 50 milliseconds. - m_resizeTimer->stop(); - m_resizeTimer->start(50, true); -} - -bool DolphinDetailsView::acceptDrag(QDropEvent* event) const -{ - KUrl::List uriList = KUrl::List::fromMimeData( event->mimeData() ); - bool accept = !uriList.isEmpty() && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link); - if (accept) { - if (static_cast(event->source()) == this) { - KFileListViewItem* item = static_cast(itemAt(event->pos())); - accept = (item != 0); - if (accept) { - KFileItem* fileItem = item->fileInfo(); - accept = fileItem->isDir(); - } - } - } - - return accept; -} - -void DolphinDetailsView::contentsDropEvent(QDropEvent* event) -{ - // KFileDetailView::contentsDropEvent does not care whether the mouse - // cursor is above a filename or not, the destination Url is always - // the Url of the item. This is fixed here in a way that the destination - // Url is only the Url of the item if the cursor is above the filename. - const QPoint pos(QCursor::pos()); - const QPoint viewportPos(viewport()->mapToGlobal(QPoint(0, 0))); - Q3ListViewItem* item = itemAt(QPoint(pos.x() - viewportPos.x(), pos.y() - viewportPos.y())); - if ((item == 0) || ((item != 0) && isOnFilename(item, pos))) { - // dropping is done on the viewport or directly above a filename - KFileDetailView::contentsDropEvent(event); - return; - } - - // Dropping is done above an item, but the mouse cursor is not above the file name. - // In this case the signals of the base implementation will be blocked and send - // in a corrected manner afterwards. - assert(item != 0); - const bool block = signalsBlocked(); - blockSignals(true); - KFileDetailView::contentsDropEvent(event); - blockSignals(block); - - if (!acceptDrag(event)) { - return; - } - - emit dropped(event, 0); - KUrl::List urls = KUrl::List::fromMimeData( event->mimeData() ); - if (!urls.isEmpty()) { - emit dropped(event, urls, KUrl()); - sig->dropURLs(0, event, urls); - } -} - -void DolphinDetailsView::contentsMousePressEvent(QMouseEvent* event) -{ - if (m_rubber != 0) { - drawRubber(); - delete m_rubber; - m_rubber = 0; - } - - // Swallow the base implementation of the mouse press event - // if the mouse cursor is not above the filename. This prevents - // that the item gets selected and simulates an equal usability - // like in the icon view. - const QPoint pos(QCursor::pos()); - const QPoint viewportPos(viewport()->mapToGlobal(QPoint(0, 0))); - Q3ListViewItem* item = itemAt(QPoint(pos.x() - viewportPos.x(), pos.y() - viewportPos.y())); - if ((item != 0) && isOnFilename(item, pos)) { - KFileDetailView::contentsMousePressEvent(event); - } - else if (event->button() == Qt::LeftButton) { - const Qt::KeyboardModifiers keyboardState = QApplication::keyboardModifiers(); - const bool isSelectionActive = (keyboardState & Qt::ShiftModifier) || - (keyboardState & Qt::ControlModifier); - if (!isSelectionActive) { - clearSelection(); - } - - assert(m_rubber == 0); - m_rubber = new QRect(event->x(), event->y(), 0, 0); - } - - resetActivatedItem(); - emit signalRequestActivation(); - - m_dolphinView->statusBar()->clear(); -} - -void DolphinDetailsView::contentsMouseMoveEvent(QMouseEvent* event) -{ - if (m_rubber != 0) { - slotAutoScroll(); - return; - } - - KFileDetailView::contentsMouseMoveEvent(event); - - const QPoint& pos = event->globalPos(); - const QPoint viewportPos = viewport()->mapToGlobal(QPoint(0, 0)); - Q3ListViewItem* item = itemAt(QPoint(pos.x() - viewportPos.x(), pos.y() - viewportPos.y())); - if ((item != 0) && isOnFilename(item, pos)) { - activateItem(item); - } - else { - resetActivatedItem(); - } -} - -void DolphinDetailsView::contentsMouseReleaseEvent(QMouseEvent* event) -{ - if (m_rubber != 0) { - drawRubber(); - delete m_rubber; - m_rubber = 0; - } - - if (m_scrollTimer != 0) { - disconnect(m_scrollTimer, SIGNAL(timeout()), - this, SLOT(slotAutoScroll())); - m_scrollTimer->stop(); - delete m_scrollTimer; - m_scrollTimer = 0; - } - - KFileDetailView::contentsMouseReleaseEvent(event); -} - -void DolphinDetailsView::paintEmptyArea(QPainter* painter, const QRect& rect) -{ - if (m_dolphinView->isActive()) { - KFileDetailView::paintEmptyArea(painter, rect); - } - else { - const QBrush brush(colorGroup().background()); - painter->fillRect(rect, brush); - } -} - -void DolphinDetailsView::drawRubber() -{ - // Parts of the following code have been taken - // from the class KonqBaseListViewWidget located in - // konqueror/listview/konq_listviewwidget.h of Konqueror. - // (Copyright (C) 1998, 1999 Torben Weis - // 2001, 2002, 2004 Michael Brade ) - if (m_rubber == 0) { - return; - } - - QPainter p; - p.begin(viewport()); - //p.setRasterOp(NotROP); - p.setPen(QPen(Qt::color0, 1)); - p.setBrush(Qt::NoBrush); - - QPoint point(m_rubber->x(), m_rubber->y()); - point = contentsToViewport(point); - QStyleOptionFocusRect option; - option.initFrom(this); - option.rect = QRect(point.x(), point.y(), m_rubber->width(), m_rubber->height()); - style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p); - p.end(); -} - -void DolphinDetailsView::viewportPaintEvent(QPaintEvent* paintEvent) -{ - drawRubber(); - KFileDetailView::viewportPaintEvent(paintEvent); - drawRubber(); -} - -void DolphinDetailsView::leaveEvent(QEvent* event) -{ - KFileDetailView::leaveEvent(event); - slotOnViewport(); -} - -void DolphinDetailsView::slotActivationUpdate() -{ - update(); - - // TODO: there must be a simpler way to say - // "update all children" - const QList list = children(); - if (list.isEmpty()) { - return; - } - - QListIterator it(list); - QObject* object = 0; - while (it.hasNext()) { - object = it.next(); - if (object->inherits("QWidget")) { - QWidget* widget = static_cast(object); - widget->update(); - } - } -} - -void DolphinDetailsView::slotContextMenuRequested(Q3ListViewItem* item, - const QPoint& pos, - int /* col */) -{ - KFileItem* fileInfo = 0; - if ((item != 0) && isOnFilename(item, pos)) { - fileInfo = static_cast(item)->fileInfo(); - } - m_dolphinView->openContextMenu(fileInfo, pos); - -} - -void DolphinDetailsView::slotUpdateDisabledItems() -{ - updateDisabledItems(); -} - -void DolphinDetailsView::slotAutoScroll() -{ - // Parts of the following code have been taken - // from the class KonqBaseListViewWidget located in - // konqueror/listview/konq_listviewwidget.h of Konqueror. - // (Copyright (C) 1998, 1999 Torben Weis - // 2001, 2002, 2004 Michael Brade ) - - const QPoint pos(viewport()->mapFromGlobal(QCursor::pos())); - const QPoint vc(viewportToContents(pos)); - - if (vc == m_rubber->bottomRight()) { - return; - } - - drawRubber(); - - m_rubber->setBottomRight(vc); - - Q3ListViewItem* item = itemAt(QPoint(0,0)); - - const bool block = signalsBlocked(); - blockSignals(true); - - const QRect rubber(m_rubber->normalize()); - const int bottom = contentsY() + visibleHeight() - 1; - - // select all items which intersect with the rubber, deselect all others - bool bottomReached = false; - while ((item != 0) && !bottomReached) { - QRect rect(itemRect(item)); - rect.setWidth(filenameWidth(item)); - rect = QRect(viewportToContents(rect.topLeft()), - viewportToContents(rect.bottomRight())); - if (rect.isValid() && (rect.top() <= bottom)) { - const KFileItem* fileItem = static_cast(item)->fileInfo(); - setSelected(fileItem, rect.intersects(rubber)); - item = item->itemBelow(); - } - else { - bottomReached = true; - } - } - - blockSignals(block); - emit selectionChanged(); - - drawRubber(); - - // scroll the viewport if the top or bottom margin is reached - const int scrollMargin = 40; - ensureVisible(vc.x(), vc.y(), scrollMargin, scrollMargin); - const bool scroll = !QRect(scrollMargin, - scrollMargin, - viewport()->width() - 2 * scrollMargin, - viewport()->height() - 2 * scrollMargin).contains(pos); - if (scroll) { - if (m_scrollTimer == 0) { - m_scrollTimer = new QTimer( this ); - connect(m_scrollTimer, SIGNAL(timeout()), - this, SLOT(slotAutoScroll())); - m_scrollTimer->start(100, false); - } - } - else if (m_scrollTimer != 0) { - disconnect(m_scrollTimer, SIGNAL(timeout()), - this, SLOT(slotAutoScroll())); - m_scrollTimer->stop(); - delete m_scrollTimer; - m_scrollTimer = 0; - } -} - -void DolphinDetailsView::updateColumnsWidth() -{ - const int columnCount = columns(); - int requiredWidth = 0; - for (int i = 1; i < columnCount; ++i) { - // When a directory contains no items, a minimum width for - // the column must be available, so that the header is readable. - // TODO: use header data instead of the hardcoded 64 value... - int columnWidth = 64; - QFontMetrics fontMetrics(font()); - for (Q3ListViewItem* item = firstChild(); item != 0; item = item->nextSibling()) { - const int width = item->width(fontMetrics, this, i); - if (width > columnWidth) { - columnWidth = width; - } - } - columnWidth += 16; // add custom margin - setColumnWidth(i, columnWidth); - requiredWidth += columnWidth; - } - - // resize the first column in a way that the - // whole available width is used - int firstColumnWidth = visibleWidth() - requiredWidth; - if (firstColumnWidth < 128) { - firstColumnWidth = 128; - } - setColumnWidth(0, firstColumnWidth); -} - -void DolphinDetailsView::slotItemRenamed(Q3ListViewItem* item, - const QString& name, - int /* column */) -{ - KFileItem* fileInfo = static_cast(item)->fileInfo(); - m_dolphinView->rename(KUrl(fileInfo->url()), name); -} - -void DolphinDetailsView::slotHeaderClicked(int /* section */) -{ - // The sorting has already been changed in QListView if this slot is - // invoked, but Dolphin was not informed about this (no signal is available - // which indicates a change of the sorting). This is bypassed by changing - // the sorting and sort order to a temporary other value and readjust it again. - const int column = sortColumn(); - if (column <= DateColumn) { - DolphinView::Sorting sorting = DolphinView::SortByName; - switch (column) { - case SizeColumn: sorting = DolphinView::SortBySize; break; - case DateColumn: sorting = DolphinView::SortByDate; break; - case NameColumn: - default: break; - } - - const Qt::SortOrder currSortOrder = sortOrder(); - - // temporary adjust the sorting and sort order to different values... - const DolphinView::Sorting tempSorting = (sorting == DolphinView::SortByName) ? - DolphinView::SortBySize : - DolphinView::SortByName; - m_dolphinView->setSorting(tempSorting); - const Qt::SortOrder tempSortOrder = (currSortOrder == Qt::Ascending) ? - Qt::Descending : Qt::Ascending; - m_dolphinView->setSortOrder(tempSortOrder); - - // ... so that setting them again results in storing the new setting. - m_dolphinView->setSorting(sorting); - m_dolphinView->setSortOrder(currSortOrder); - } -} - -DolphinDetailsView::DolphinListViewItem::DolphinListViewItem(Q3ListView* parent, - KFileItem* fileItem) : - KFileListViewItem(parent, fileItem) -{ - const int iconSize = DolphinSettings::instance().detailsModeSettings()->iconSize(); - KFileItem* info = fileInfo(); - setPixmap(DolphinDetailsView::NameColumn, info->pixmap(iconSize)); - - // The base class KFileListViewItem represents the column 'Size' only as byte values. - // Adjust those values in a way that a mapping to GBytes, MBytes, KBytes and Bytes - // is done. As the file size for directories is useless (only the size of the directory i-node - // is given), it is removed completely. - if (fileItem->isDir()) { - setText(SizeColumn, " - "); - } - else { - QString sizeText(KIO::convertSize(fileItem->size())); - sizeText.append(" "); - setText(SizeColumn, sizeText); - } - - // Dolphin allows to remove specific columns, but the base class KFileListViewItem - // is not aware about this (or at least the class KFileDetailView does not react on - // QListView::remove()). Therefore the columns are rearranged here. - const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); - assert(settings != 0); - - int column_idx = DateColumn; // the columns for 'name' and 'size' cannot get removed - for (int i = DolphinDetailsView::DateColumn; i <= DolphinDetailsView::GroupColumn; ++i) { - if (column_idx < i) { - setText(column_idx, text(i)); - } - - bool inc = false; - switch (i) { - case DateColumn: inc = settings->showDate(); break; - case PermissionsColumn: inc = settings->showPermissions(); break; - case OwnerColumn: inc = settings->showOwner(); break; - case GroupColumn: inc = settings->showGroup(); break; - default: break; - } - - if (inc) { - ++column_idx; - } - } -} - -DolphinDetailsView::DolphinListViewItem::~DolphinListViewItem() -{ -} - -void DolphinDetailsView::DolphinListViewItem::paintCell(QPainter* painter, - const QColorGroup& colorGroup, - int column, - int cellWidth, - int alignment) -{ - const Q3ListView* view = listView(); - const bool isActive = view->parent() == Dolphin::mainWin().activeView(); - if (isSelected()) { - // Per default the selection is drawn above the whole width of the item. As a consistent - // behavior with the icon view is wanted, only the the column containing the file name - // should be shown as selected. - QColorGroup defaultColorGroup(colorGroup); - const QColor highlightColor(isActive ? backgroundColor(column) : view->colorGroup().background()); - defaultColorGroup.setColor(QColorGroup::Highlight , highlightColor); - defaultColorGroup.setColor(QColorGroup::HighlightedText, colorGroup.color(QColorGroup::Text)); - KFileListViewItem::paintCell(painter, defaultColorGroup, column, cellWidth, alignment); - - if (column == 0) { - // draw the selection only on the first column - Q3ListView* parent = listView(); - const int itemWidth = width(parent->fontMetrics(), parent, 0); - if (isActive) { - KFileListViewItem::paintCell(painter, colorGroup, column, itemWidth, alignment); - } - else { - Q3ListViewItem::paintCell(painter, colorGroup, column, itemWidth, alignment); - } - } - } - else { - if (isActive) { - KFileListViewItem::paintCell(painter, colorGroup, column, cellWidth, alignment); - } - else { - Q3ListViewItem::paintCell(painter, colorGroup, column, cellWidth, alignment); - } - } - - if (column < listView()->columns() - 1) { - // draw a separator between columns - painter->setPen(KGlobalSettings::buttonBackground()); - painter->drawLine(cellWidth - 1, 0, cellWidth - 1, height() - 1); - } -} - -void DolphinDetailsView::DolphinListViewItem::paintFocus(QPainter* painter, - const QColorGroup& colorGroup, - const QRect& rect) -{ - // draw the focus consistently with the selection (see implementation notes - // in DolphinListViewItem::paintCell) - Q3ListView* parent = listView(); - int visibleWidth = width(parent->fontMetrics(), parent, 0); - const int colWidth = parent->columnWidth(0); - if (visibleWidth > colWidth) { - visibleWidth = colWidth; - } - - QRect focusRect(rect); - focusRect.setWidth(visibleWidth); - - KFileListViewItem::paintFocus(painter, colorGroup, focusRect); -} - -int DolphinDetailsView::filenameWidth(const Q3ListViewItem* item) const -{ - assert(item != 0); - - int visibleWidth = item->width(fontMetrics(), this, 0); - const int colWidth = columnWidth(0); - if (visibleWidth > colWidth) { - visibleWidth = colWidth; - } - - return visibleWidth; } #include "dolphindetailsview.moc" diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 86f579cce6..237880c4f9 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -21,19 +21,8 @@ #ifndef DOLPHINDETAILSVIEW_H #define DOLPHINDETAILSVIEW_H -#include -#include -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#include +#include -class QRect; -class QTimer; class DolphinView; /** @@ -46,179 +35,13 @@ class DolphinView; * * @author Peter Penz */ -class DolphinDetailsView : public KFileDetailView, public ItemEffectsManager +class DolphinDetailsView : public QListView { Q_OBJECT public: - /** - * Maps the column indices of KFileDetailView to a - * descriptive column name. - */ - enum ColumnName { - NameColumn = 0, - SizeColumn = 1, - DateColumn = 2, - PermissionsColumn = 3, - OwnerColumn = 4, - GroupColumn = 5 - }; - DolphinDetailsView(DolphinView* parent); - virtual ~DolphinDetailsView(); - - /** @see ItemEffectsManager::updateItems */ - virtual void beginItemUpdates(); - - /** @see ItemEffectsManager::updateItems */ - virtual void endItemUpdates(); - - /** @see KFileView::insertItem */ - virtual void insertItem(KFileItem* fileItem); - - /** - * @return True, if the position \a pos is above the name of - * item \a item. - */ - bool isOnFilename(const Q3ListViewItem* item, const QPoint& pos) const; - - /** - * Reads out the dolphin settings for the details view and refreshs - * the details view. - */ - // TODO: Other view implementations use a similar interface. When using - // Interview in Qt4 this method should be moved to a base class (currently - // not possible due to having different base classes for the views). - void refreshSettings(); - - /** @see ItemEffectsManager::zoomIn() */ - virtual void zoomIn(); - - /** @see ItemEffectsManager::zoomOut() */ - virtual void zoomOut(); - - /** @see ItemEffectsManager::isZoomInPossible() */ - virtual bool isZoomInPossible() const; - - /** @see ItemEffectsManager::isZoomOutPossible() */ - virtual bool isZoomOutPossible() const; - -signals: - /** - * Is send, if the details view should be activated. Usually an activation - * is triggered by a mouse click. - */ - void signalRequestActivation(); - -public slots: - /** @see KFileDetailView::resizeContents */ - virtual void resizeContents(int width, int height); - - /** Is connected to the onItem-signal from KFileDetailView. */ - void slotOnItem(Q3ListViewItem* item); - - /** Is connected to the onViewport-signal from KFileDetailView. */ - void slotOnViewport(); - -protected: - /** @see ItemEffectsManager::setContextPixmap() */ - virtual void setContextPixmap(void* context, - const QPixmap& pixmap); - - /** @see ItemEffectsManager::setContextPixmap() */ - virtual const QPixmap* contextPixmap(void* context); - - /** @see ItemEffectsManager::setContextPixmap() */ - virtual void* firstContext(); - - /** @see ItemEffectsManager::setContextPixmap() */ - virtual void* nextContext(void* context); - - /** @see ItemEffectsManager::setContextPixmap() */ - virtual KFileItem* contextFileInfo(void* context); - - /** @see KFileDetailView::contentsDragMoveEvent() */ - virtual void contentsDragMoveEvent(QDragMoveEvent* event); - - /** @see KFileDetailView::resizeEvent() */ - virtual void resizeEvent(QResizeEvent* event); - - /** @see KFileDetailView::acceptDrag() */ - virtual bool acceptDrag (QDropEvent* event) const; - - /** @see KFileDetailView::contentsDropEvent() */ - virtual void contentsDropEvent(QDropEvent* event); - - /** @see KFileDetailView::contentsMousePressEvent() */ - virtual void contentsMousePressEvent(QMouseEvent* event); - - /** @see KFileDetailView::contentsMouseMoveEvent() */ - virtual void contentsMouseMoveEvent(QMouseEvent* event); - - /** @see KFileDetailView::contentsMouseReleaseEvent() */ - virtual void contentsMouseReleaseEvent(QMouseEvent* event); - - /** @see QListView::paintEmptyArea() */ - virtual void paintEmptyArea(QPainter* painter, const QRect& rect); - - /** Draws the selection rubber. */ - void drawRubber(); - - /** @see QListView::viewportPaintEvent() */ - virtual void viewportPaintEvent(QPaintEvent* paintEvent); - - /** @see QWidget::leaveEvent() */ - virtual void leaveEvent(QEvent* event); - -private slots: - void slotActivationUpdate(); - void slotContextMenuRequested(Q3ListViewItem* item, - const QPoint& pos, - int col); - void slotUpdateDisabledItems(); - void slotAutoScroll(); - void updateColumnsWidth(); - void slotItemRenamed(Q3ListViewItem* item, - const QString& name, - int column); - - /** - * Is invoked when a section from the header has - * been clicked and stores the sort column and sort - * order. - */ - void slotHeaderClicked(int section); - -private: - class DolphinListViewItem : public KFileListViewItem { - public: - DolphinListViewItem(Q3ListView* parent, - KFileItem* fileItem); - virtual ~DolphinListViewItem(); - virtual void paintCell(QPainter* painter, - const QColorGroup& colorGroup, - int column, - int cellWidth, - int alignment); - - virtual void paintFocus(QPainter* painter, - const QColorGroup& colorGroup, - const QRect& rect); - }; - - DolphinView* m_dolphinView; - QTimer* m_resizeTimer; - QTimer* m_scrollTimer; - QRect* m_rubber; - - /** - * Returns the width of the filename in pixels including - * the icon. It is assured that the returned width is - * <= the width of the filename column. - */ - int filenameWidth(const Q3ListViewItem* item) const; - }; #endif diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 30dd7bb4d5..e9a53d53ef 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -19,495 +19,15 @@ ***************************************************************************/ #include "dolphiniconsview.h" -#include -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "dolphinview.h" -#include "viewproperties.h" -#include "dolphin.h" -#include "dolphinstatusbar.h" -#include "dolphinsettings.h" -#include "iconsmodesettings.h" -DolphinIconsView::DolphinIconsView(DolphinView* parent, LayoutMode layoutMode) : - KFileIconView(parent, 0), - m_previewIconSize(-1), - m_layoutMode(layoutMode), - m_dolphinView(parent) +DolphinIconsView::DolphinIconsView(DolphinView* parent) : + QListView(parent) { - setAcceptDrops(true); - setMode(K3IconView::Execute); - setSelectionMode(KFile::Extended); - Dolphin& dolphin = Dolphin::mainWin(); - - connect(this, SIGNAL(onItem(Q3IconViewItem*)), - this, SLOT(slotOnItem(Q3IconViewItem*))); - connect(this, SIGNAL(onViewport()), - this, SLOT(slotOnViewport())); - connect(this, SIGNAL(contextMenuRequested(Q3IconViewItem*, const QPoint&)), - this, SLOT(slotContextMenuRequested(Q3IconViewItem*, const QPoint&))); - connect(this, SIGNAL(selectionChanged()), - &dolphin, SLOT(slotSelectionChanged())); - connect(&dolphin, SIGNAL(activeViewChanged()), - this, SLOT(slotActivationUpdate())); - connect(this, SIGNAL(itemRenamed(Q3IconViewItem*, const QString&)), - this, SLOT(slotItemRenamed(Q3IconViewItem*, const QString&))); - connect(this, SIGNAL(dropped(QDropEvent*, const KUrl::List&, const KUrl&)), - parent, SLOT(slotUrlListDropped(QDropEvent*, const KUrl::List&, const KUrl&))); - - QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(slotUpdateDisabledItems())); - - // KFileIconView creates two actions for zooming, which are directly connected to the - // slots KFileIconView::zoomIn() and KFileIconView::zoomOut(). As this behavior is not - // wanted and the slots are not virtual, the actions are disabled here. - KAction* zoomInAction = actionCollection()->action("zoomIn"); - assert(zoomInAction != 0); - zoomInAction->setEnabled(false); - - KAction* zoomOutAction = actionCollection()->action("zoomOut"); - assert(zoomOutAction != 0); - zoomOutAction->setEnabled(false); - - setItemsMovable(true); - setWordWrapIconText(true); - if (m_layoutMode == Previews) { - showPreviews(); - } - refreshSettings(); } DolphinIconsView::~DolphinIconsView() { } -void DolphinIconsView::setLayoutMode(LayoutMode mode) -{ - if (m_layoutMode != mode) { - m_layoutMode = mode; - refreshSettings(); - } -} - -void DolphinIconsView::beginItemUpdates() -{ -} - -void DolphinIconsView::endItemUpdates() -{ - arrangeItemsInGrid(); - - // TODO: KFileIconView does not emit any signal when the preview - // has been finished. Using a delay of 300 ms is a temporary workaround - // until the DolphinIconsView will implement the previews by it's own in - // future releases. - QTimer::singleShot(300, this, SLOT(slotUpdateDisabledItems())); - - const KFileIconViewItem* item = static_cast(firstItem()); - if (item != 0) { - setCurrentItem(item->fileInfo()); - } - - int index = 0; - const Q3ValueList history = m_dolphinView->urlHistory(index); - if (!history.isEmpty()) { - KFileView* fileView = static_cast(this); - fileView->setCurrentItem(history[index].currentFileName()); - setContentsPos(history[index].contentsX(), history[index].contentsY()); - } -} - -void DolphinIconsView::refreshSettings() -{ - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - assert(settings != 0); - - setIconSize(settings->iconSize()); - - const Q3IconView::Arrangement arrangement = settings->arrangement() == "LeftToRight" ? // TODO: use enum directly in settings - Q3IconView::LeftToRight : Q3IconView::TopToBottom; - const Q3IconView::ItemTextPos textPos = (arrangement == Q3IconView::LeftToRight) ? - Q3IconView::Bottom : - Q3IconView::Right; - setArrangement(arrangement); - setItemTextPos(textPos); - - // TODO: tempory crash; will get changed anyway for KDE 4 - /*setGridX(settings->gridWidth()); - setGridY(settings->gridHeight()); - setSpacing(settings->gridSpacing());*/ - - QFont adjustedFont(font()); - adjustedFont.setFamily(settings->fontFamily()); - adjustedFont.setPointSize(settings->fontSize()); - setFont(adjustedFont); - setIconTextHeight(settings->numberOfTexlines()); - - if (m_layoutMode == Previews) { - // There is no getter method for the current size in KFileIconView. To - // prevent a flickering the current size is stored in m_previewIconSize and - // setPreviewSize is only invoked if the size really has changed. - showPreviews(); - - const int size = settings->previewSize(); - if (size != m_previewIconSize) { - m_previewIconSize = size; - setPreviewSize(size); - } - } -} - -void DolphinIconsView::zoomIn() -{ - if (isZoomInPossible()) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4 - - const int iconSize = increasedIconSize(settings->iconSize()); - settings->setIconSize(iconSize); - - if (m_layoutMode == Previews) { - const int previewSize = increasedIconSize(settings->previewSize()); - settings->setPreviewSize(previewSize); - } - - DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4 - ItemEffectsManager::zoomIn(); - } -} - -void DolphinIconsView::zoomOut() -{ - if (isZoomOutPossible()) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4 - - const int iconSize = decreasedIconSize(settings->iconSize()); - settings->setIconSize(iconSize); - - if (m_layoutMode == Previews) { - const int previewSize = decreasedIconSize(settings->previewSize()); - settings->setPreviewSize(previewSize); - } - - DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4 - ItemEffectsManager::zoomOut(); - } -} - -bool DolphinIconsView::isZoomInPossible() const -{ - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int size = (m_layoutMode == Icons) ? settings->iconSize() : settings->previewSize(); - return size < K3Icon::SizeEnormous; -} - -bool DolphinIconsView::isZoomOutPossible() const -{ - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - return settings->iconSize() > K3Icon::SizeSmall; -} - -void DolphinIconsView::arrangeItemsInGrid( bool updated ) -{ - - KFileIconView::arrangeItemsInGrid(updated); - - if (m_layoutMode == Previews) { - // The class KFileIconView has a bug when the size of the previews differs from the size - // of the icons: For specific MIME types the y-position and the height is calculated in - // a wrong manner. The following code bypasses this issue. No bugreport has been submitted - // as this functionality is not used by any KDE3 application and the core developers are - // busy enough for KDE4 now :-) - - KFileIconViewItem* item = static_cast(Q3IconView::firstItem()); - QString mimetype; - while (item != 0) { - mimetype = item->fileInfo()->mimetype(); - const bool fixSize = mimetype.contains("text") || - mimetype.contains("application/x-"); - if (fixSize) { - item->setPixmapSize(QSize(m_previewIconSize, m_previewIconSize)); - } - item = static_cast(item->nextItem()); - } - } -} - -void DolphinIconsView::setContextPixmap(void* context, - const QPixmap& pixmap) -{ - reinterpret_cast(context)->setPixmap(pixmap); -} - -const QPixmap* DolphinIconsView::contextPixmap(void* context) -{ - return reinterpret_cast(context)->pixmap(); -} - -void* DolphinIconsView::firstContext() -{ - return reinterpret_cast(firstItem()); -} - -void* DolphinIconsView::nextContext(void* context) -{ - KFileIconViewItem* iconViewItem = reinterpret_cast(context); - return reinterpret_cast(iconViewItem->nextItem()); -} - -KFileItem* DolphinIconsView::contextFileInfo(void* context) -{ - return reinterpret_cast(context)->fileInfo(); -} - -void DolphinIconsView::contentsMousePressEvent(QMouseEvent* event) -{ - KFileIconView::contentsMousePressEvent(event); - resetActivatedItem(); - emit signalRequestActivation(); - m_dolphinView->statusBar()->clear(); -} - -void DolphinIconsView::contentsMouseReleaseEvent(QMouseEvent* event) -{ - KFileIconView::contentsMouseReleaseEvent(event); - - // The KFileIconView does not send any selectionChanged signal if - // a selection is done by using the "select-during-button-pressed" feature. - // Hence inform Dolphin about the selection change manually: - Dolphin::mainWin().slotSelectionChanged(); -} - -void DolphinIconsView::drawBackground(QPainter* painter, const QRect& rect) -{ - if (m_dolphinView->isActive()) { - KFileIconView::drawBackground(painter, rect); - } - else { - const QBrush brush(colorGroup().background()); - painter->fillRect(0, 0, width(), height(), brush); - } -} - -Q3DragObject* DolphinIconsView::dragObject() -{ - KUrl::List urls; - QListIterator it(*KFileView::selectedItems()); - while (it.hasNext()) { - KFileItem *item = it.next(); - urls.append(item->url()); - } - - QPixmap pixmap; - if(urls.count() > 1) { - pixmap = DesktopIcon("kmultiple", iconSize()); - } - else { - KFileIconViewItem* item = static_cast(currentItem()); - if ((item != 0) && (item->pixmap() != 0)) { - pixmap = *(item->pixmap()); - } - } - - if (pixmap.isNull()) { - pixmap = currentFileItem()->pixmap(iconSize()); - } - - /* This should be ported to QMimeData - Q3DragObject* dragObj = new KUrlDrag(urls, widget()); - dragObj->setPixmap(pixmap); - return dragObj; - */ - return 0; -} - -void DolphinIconsView::contentsDragEnterEvent(QDragEnterEvent* event) -{ - // TODO: The method KFileIconView::contentsDragEnterEvent() does - // not allow drag and drop inside itself, which prevents the possability - // to move a file into a directory. As the method KFileIconView::acceptDrag() - // is not virtual, we must overwrite the method - // KFileIconView::contentsDragEnterEvent() and do some cut/copy/paste for this - // usecase. Corresponding to the documentation the method KFileIconView::acceptDrag() - // will get virtual in KDE 4, which will simplify the code. - - if (event->source() != this) { - KFileIconView::contentsDragEnterEvent(event); - return; - } - - KUrl::List uriList = KUrl::List::fromMimeData( event->mimeData() ); - const bool accept = !uriList.isEmpty() && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link ); - if (accept) { - event->acceptAction(); - } - else { - event->ignore(); - } -} - -void DolphinIconsView::contentsDragMoveEvent(QDragMoveEvent* event) -{ - KFileIconView::contentsDragMoveEvent(event); - - // If a dragging is done above a directory, show the icon as 'active' for - // a visual feedback - KFileIconViewItem* item = static_cast(findItem(contentsToViewport(event->pos()))); - - bool showActive = false; - if (item != 0) { - const KFileItem* fileInfo = item->fileInfo(); - showActive = (fileInfo != 0) && fileInfo->isDir(); - } - - if (showActive) { - slotOnItem(item); - } - else { - slotOnViewport(); - } -} - -void DolphinIconsView::contentsDropEvent(QDropEvent* event) -{ - // TODO: Most of the following code is a copy of - // KFileIconView::contentsDropEvent. See comment in - // DolphinIconsView::contentsDragEnterEvent for details. - - if (event->source() != this) { - KFileIconView::contentsDropEvent(event); - return; - } - - KFileIconViewItem* item = static_cast(findItem(contentsToViewport(event->pos()))); - KUrl::List urls = KUrl::List::fromMimeData( event->mimeData() ); - const bool accept = !urls.isEmpty() && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link ) && - (item != 0); - if (!accept) { - return; - } - - KFileItem* fileItem = item->fileInfo(); - if (!fileItem->isDir()) { - // the file is not a directory, hence don't accept any drop - return; - } - emit dropped(event, fileItem); - if (!urls.isEmpty()) { - emit dropped(event, urls, fileItem != 0 ? fileItem->url() : KUrl()); - sig->dropURLs(fileItem, event, urls); - } -} - -void DolphinIconsView::slotOnItem(Q3IconViewItem* item) -{ - assert(item != 0); - activateItem(reinterpret_cast(item)); - - KFileItem* fileItem = static_cast(item)->fileInfo(); - m_dolphinView->requestItemInfo(fileItem->url()); -} - -void DolphinIconsView::slotOnViewport() -{ - resetActivatedItem(); - m_dolphinView->requestItemInfo(KUrl()); -} - -void DolphinIconsView::slotContextMenuRequested(Q3IconViewItem* item, - const QPoint& pos) -{ - KFileItem* fileInfo = 0; - if (item != 0) { - fileInfo = static_cast(item)->fileInfo(); - } - m_dolphinView->openContextMenu(fileInfo, pos); -} - -void DolphinIconsView::slotItemRenamed(Q3IconViewItem* item, - const QString& name) -{ - KFileItem* fileInfo = static_cast(item)->fileInfo(); - m_dolphinView->rename(KUrl(fileInfo->url()), name); -} - -void DolphinIconsView::slotActivationUpdate() -{ - update(); - - // TODO: there must be a simpler way to say - // "update all children" - const QList list = children(); - if (list.isEmpty()) { - return; - } - - QListIterator it(list); - QObject* object = 0; - while (it.hasNext()) { - object = it.next(); - if (object->inherits("QWidget")) { - QWidget* widget = static_cast(object); - widget->update(); - } - } -} - -void DolphinIconsView::slotUpdateDisabledItems() -{ - updateDisabledItems(); -} - -int DolphinIconsView::increasedIconSize(int size) const -{ - int incSize = 0; - switch (size) { - case K3Icon::SizeSmall: incSize = K3Icon::SizeSmallMedium; break; - case K3Icon::SizeSmallMedium: incSize = K3Icon::SizeMedium; break; - case K3Icon::SizeMedium: incSize = K3Icon::SizeLarge; break; - case K3Icon::SizeLarge: incSize = K3Icon::SizeHuge; break; - case K3Icon::SizeHuge: incSize = K3Icon::SizeEnormous; break; - default: assert(false); break; - } - return incSize; -} - -int DolphinIconsView::decreasedIconSize(int size) const -{ - int decSize = 0; - switch (size) { - case K3Icon::SizeSmallMedium: decSize = K3Icon::SizeSmall; break; - case K3Icon::SizeMedium: decSize = K3Icon::SizeSmallMedium; break; - case K3Icon::SizeLarge: decSize = K3Icon::SizeMedium; break; - case K3Icon::SizeHuge: decSize = K3Icon::SizeLarge; break; - case K3Icon::SizeEnormous: decSize = K3Icon::SizeHuge; break; - default: assert(false); break; - } - return decSize; -} - #include "dolphiniconsview.moc" diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 30ab3140d2..f83f6f1a96 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -21,15 +21,7 @@ #ifndef DOLPHINICONSVIEW_H #define DOLPHINICONSVIEW_H -#include -#include -//Added by qt3to4: -#include -#include -#include -#include -#include -#include +#include class DolphinView; @@ -41,133 +33,13 @@ class DolphinView; * * @author Peter Penz */ -class DolphinIconsView : public KFileIconView, public ItemEffectsManager +class DolphinIconsView : public QListView { Q_OBJECT public: - enum LayoutMode { - Icons, - Previews - }; - - DolphinIconsView(DolphinView *parent, LayoutMode layoutMode); - + DolphinIconsView(DolphinView* parent); virtual ~DolphinIconsView(); - - void setLayoutMode(LayoutMode mode); - LayoutMode layoutMode() const { return m_layoutMode; } - - /** @see ItemEffectsManager::updateItems */ - virtual void beginItemUpdates(); - - /** @see ItemEffectsManager::updateItems */ - virtual void endItemUpdates(); - - /** - * Reads out the dolphin settings for the icons view and refreshs - * the details view. - */ - // TODO: Other view implementations use a similar interface. When using - // Interview in Qt4 this method should be moved to a base class (currently - // not possible due to having different base classes for the views). - void refreshSettings(); - - /** @see ItemEffectsManager::zoomIn() */ - virtual void zoomIn(); - - /** @see ItemEffectsManager::zoomOut() */ - virtual void zoomOut(); - - /** @see ItemEffectsManager::isZoomInPossible() */ - virtual bool isZoomInPossible() const; - - /** @see ItemEffectsManager::isZoomOutPossible() */ - virtual bool isZoomOutPossible() const; - -public slots: - /** - * Bypass a layout issue in KFileIconView in combination with previews. - * @see KFileIconView::arrangeItemsInGrid - */ - virtual void arrangeItemsInGrid(bool updated = true); - -signals: - /** - * Is send, if the details view should be activated. Usually an activation - * is triggered by a mouse click. - */ - void signalRequestActivation(); - -protected: - /** @see ItemEffectsManager::setContextPixmap */ - virtual void setContextPixmap(void* context, - const QPixmap& pixmap); - - /** @see ItemEffectsManager::contextPixmap */ - virtual const QPixmap* contextPixmap(void* context); - - /** @see ItemEffectsManager::firstContext */ - virtual void* firstContext(); - - /** @see ItemEffectsManager::nextContext */ - virtual void* nextContext(void* context); - - /** @see ItemEffectsManager::contextFileInfo */ - virtual KFileItem* contextFileInfo(void* context); - - /** @see KFileIconView::contentsMousePressEvent */ - virtual void contentsMousePressEvent(QMouseEvent* event); - - /** @see KFileIconView::contentsMouseReleaseEvent */ - virtual void contentsMouseReleaseEvent(QMouseEvent* event); - - /** @see KFileIconView::drawBackground */ - virtual void drawBackground(QPainter* painter, const QRect& rect); - - /** @see KFileIconView::dragObject */ - virtual Q3DragObject* dragObject(); - - /** @see KFileIconView::contentsDragEnterEvent */ - virtual void contentsDragEnterEvent(QDragEnterEvent* event); - - /** @see KFileIconView::contentsDragMoveEvent */ - virtual void contentsDragMoveEvent(QDragMoveEvent* event); - - /** @see KFileIconView::contentsDropEvent */ - virtual void contentsDropEvent(QDropEvent* event); - -private slots: - /** Is connected to the onItem-signal from KFileIconView. */ - void slotOnItem(Q3IconViewItem* item); - - /** Is connected to the onViewport-signal from KFileIconView. */ - void slotOnViewport(); - - /** - * Opens the context menu for the item \a item on the given - * position \a pos. - */ - void slotContextMenuRequested(Q3IconViewItem* item, - const QPoint& pos); - - /** Renames the item \a item to the name \a name. */ - void slotItemRenamed(Q3IconViewItem* item, - const QString& name); - - void slotActivationUpdate(); - void slotUpdateDisabledItems(); - -private: - int m_previewIconSize; - LayoutMode m_layoutMode; - DolphinView* m_dolphinView; - - /** Returns the increased icon size for the size \a size. */ - int increasedIconSize(int size) const; - - /** Returns the decreased icon size for the size \a size. */ - int decreasedIconSize(int size) const; }; #endif diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index bcf17a6204..04a63c124c 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -20,6 +20,9 @@ #include "dolphinview.h" +#include + + #include //Added by qt3to4: #include @@ -54,8 +57,6 @@ DolphinView::DolphinView(QWidget *parent, m_refreshing(false), m_showProgress(false), m_mode(mode), - m_iconsView(0), - m_detailsView(0), m_statusBar(0), m_iconSize(0), m_folderCount(0), @@ -102,25 +103,28 @@ DolphinView::DolphinView(QWidget *parent, this, SLOT(slotInfoMessage(const QString&))); connect(m_dirLister, SIGNAL(errorMessage(const QString&)), this, SLOT(slotErrorMessage(const QString&))); - connect(m_dirLister, SIGNAL(refreshItems(const KFileItemList&)), - this, SLOT(slotRefreshItems(const KFileItemList&))); - connect(m_dirLister, SIGNAL(redirection(const KUrl&, const KUrl&)), - this, SIGNAL(redirection(const KUrl&, const KUrl&))); - connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), - this, SLOT(slotAddItems(const KFileItemList&))); + + m_iconsView = new DolphinIconsView(this); + connect(m_iconsView, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(triggerItem(const QModelIndex&))); + + KDirModel* model = new KDirModel(); + model->setDirLister(m_dirLister); + m_iconsView->setModel(model); m_iconSize = K3Icon::SizeMedium; - m_topLayout->addWidget(m_urlNavigator); - createView(); - m_filterBar = new FilterBar(this); m_filterBar->hide(); - m_topLayout->addWidget(m_filterBar); connect(m_filterBar, SIGNAL(signalFilterChanged(const QString&)), this, SLOT(slotChangeNameFilter(const QString&))); + m_topLayout->addWidget(m_urlNavigator); + m_topLayout->addWidget(m_iconsView); + m_topLayout->addWidget(m_filterBar); m_topLayout->addWidget(m_statusBar); + + startDirLister(m_urlNavigator->url()); } DolphinView::~DolphinView() @@ -155,23 +159,13 @@ void DolphinView::setMode(Mode mode) return; // the wished mode is already set } - QWidget* view = (m_iconsView != 0) ? static_cast(m_iconsView) : - static_cast(m_detailsView); - if (view != 0) { - m_topLayout->remove(view); - view->close(); - view->deleteLater(); - m_iconsView = 0; - m_detailsView = 0; - } - m_mode = mode; - createView(); - ViewProperties props(m_urlNavigator->url()); props.setViewMode(m_mode); + startDirLister(m_urlNavigator->url()); + emit signalModeChanged(); } @@ -279,11 +273,12 @@ void DolphinView::renameSelectedItems() // Only one item has been selected for renaming. Use the custom // renaming mechanism from the views. assert(urls.count() == 1); - if (m_mode == DetailsView) { - Q3ListViewItem* item = m_detailsView->firstChild(); + // TODO: + /*if (m_mode == DetailsView) { + Q3ListViewItem* item = m_iconsView->firstChild(); while (item != 0) { if (item->isSelected()) { - m_detailsView->rename(item, DolphinDetailsView::NameColumn); + m_iconsView->rename(item, DolphinDetailsView::NameColumn); break; } item = item->nextSibling(); @@ -298,18 +293,18 @@ void DolphinView::renameSelectedItems() } item = static_cast(item->nextItem()); } - } + }*/ } } void DolphinView::selectAll() { - fileView()->selectAll(); + //fileView()->selectAll(); } void DolphinView::invertSelection() { - fileView()->invertSelection(); + //fileView()->invertSelection(); } DolphinStatusBar* DolphinView::statusBar() const @@ -319,33 +314,18 @@ DolphinStatusBar* DolphinView::statusBar() const int DolphinView::contentsX() const { - return scrollView()->contentsX(); + + return 0; //scrollView()->contentsX(); } int DolphinView::contentsY() const { - return scrollView()->contentsY(); + return 0; //scrollView()->contentsY(); } void DolphinView::refreshSettings() { - if (m_iconsView != 0) { - m_iconsView->refreshSettings(); - } - - if (m_detailsView != 0) { - // TODO: There is no usable interface in QListView/KFileDetailView - // to hide/show columns. The easiest approach is to delete - // the current instance and recreate a new one, which automatically - // refreshs the settings. If a proper interface is available in Qt4 - // m_detailsView->refreshSettings() would be enough. - m_topLayout->remove(m_detailsView); - m_detailsView->close(); - m_detailsView->deleteLater(); - m_detailsView = 0; - - createView(); - } + startDirLister(m_urlNavigator->url()); } void DolphinView::updateStatusBar() @@ -383,28 +363,28 @@ bool DolphinView::isUrlEditable() const void DolphinView::zoomIn() { - itemEffectsManager()->zoomIn(); + //itemEffectsManager()->zoomIn(); } void DolphinView::zoomOut() { - itemEffectsManager()->zoomOut(); + //itemEffectsManager()->zoomOut(); } bool DolphinView::isZoomInPossible() const { - return itemEffectsManager()->isZoomInPossible(); + return false; //itemEffectsManager()->isZoomInPossible(); } bool DolphinView::isZoomOutPossible() const { - return itemEffectsManager()->isZoomOutPossible(); + return false; //itemEffectsManager()->isZoomOutPossible(); } void DolphinView::setSorting(Sorting sorting) { if (sorting != this->sorting()) { - KFileView* view = fileView(); + /*KFileView* view = fileView(); int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted; switch (sorting) { @@ -419,13 +399,13 @@ void DolphinView::setSorting(Sorting sorting) view->setSorting(static_cast(spec)); - emit signalSortingChanged(sorting); + emit signalSortingChanged(sorting);*/ } } DolphinView::Sorting DolphinView::sorting() const { - const QDir::SortFlags spec = fileView()->sorting(); + /*const QDir::SortFlags spec = fileView()->sorting(); if (spec & QDir::Time) { return SortByDate; @@ -433,7 +413,7 @@ DolphinView::Sorting DolphinView::sorting() const if (spec & QDir::Size) { return SortBySize; - } + }*/ return SortByName; } @@ -441,7 +421,7 @@ DolphinView::Sorting DolphinView::sorting() const void DolphinView::setSortOrder(Qt::SortOrder order) { if (sortOrder() != order) { - KFileView* view = fileView(); + /*KFileView* view = fileView(); int sorting = view->sorting(); sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) : (sorting | QDir::Reversed); @@ -451,13 +431,14 @@ void DolphinView::setSortOrder(Qt::SortOrder order) view->setSorting(static_cast(sorting)); - emit signalSortOrderChanged(order); + emit signalSortOrderChanged(order);*/ } } Qt::SortOrder DolphinView::sortOrder() const { - return fileView()->isReversed() ? Qt::Descending : Qt::Ascending; + //return fileView()->isReversed() ? Qt::Descending : Qt::Ascending; + return Qt::Descending; } void DolphinView::goBack() @@ -498,14 +479,14 @@ bool DolphinView::hasSelection() const const KFileItemList* DolphinView::selectedItems() const { - return fileView()->selectedItems(); + return 0; //fileView()->selectedItems(); } KUrl::List DolphinView::selectedUrls() const { KUrl::List urls; - const KFileItemList* list = fileView()->selectedItems(); + /*const KFileItemList* list = fileView()->selectedItems(); if (list != 0) { KFileItemList::const_iterator it = list->begin(); const KFileItemList::const_iterator end = list->end(); @@ -514,14 +495,14 @@ KUrl::List DolphinView::selectedUrls() const urls.append(item->url()); ++it; } - } + }*/ return urls; } const KFileItem* DolphinView::currentFileItem() const { - return fileView()->currentFileItem(); + return 0; // fileView()->currentFileItem(); } void DolphinView::openContextMenu(KFileItem* fileInfo, const QPoint& pos) @@ -661,37 +642,43 @@ void DolphinView::triggerIconsViewItem(Q3IconViewItem* item) } } -void DolphinView::triggerDetailsViewItem(Q3ListViewItem* item, - const QPoint& pos, - int /* column */) +void DolphinView::triggerItem(const QModelIndex& index) { + KDirModel* dirModel = static_cast(m_iconsView->model()); + KFileItem* item = dirModel->itemForIndex(index); if (item == 0) { return; } - if (m_detailsView->isOnFilename(item, pos)) { - // Updating the Url must be done outside the scope of this slot, - // as listview items will get deleted. - QTimer::singleShot(0, this, SLOT(updateUrl())); - Dolphin::mainWin().setActiveView(this); + if (item->isDir()) { + // Prefer the local path over the Url. This assures that the + // volume space information is correct. Assuming that the Url is media:/sda1, + // and the local path is /windows/C: For the Url the space info is related + // to the root partition (and hence wrong) and for the local path the space + // info is related to the windows partition (-> correct). + //m_dirLister->stop(); + //m_dirLister->openUrl(item->url()); + //return; + + const QString localPath(item->localPath()); + if (localPath.isEmpty()) { + setUrl(item->url()); + } + else { + setUrl(KUrl(localPath)); + } } else { - m_detailsView->clearSelection(); + item->run(); } } -void DolphinView::triggerDetailsViewItem(Q3ListViewItem* item) -{ - const QPoint pos(0, item->itemPos()); - triggerDetailsViewItem(item, pos, 0); -} - void DolphinView::updateUrl() { - KFileView* fileView = (m_iconsView != 0) ? static_cast(m_iconsView) : - static_cast(m_detailsView); + //KFileView* fileView = (m_iconsView != 0) ? static_cast(m_iconsView) : + // static_cast(m_iconsView); - KFileItem* fileItem = fileView->currentFileItem(); + KFileItem* fileItem = 0; // TODO: fileView->currentFileItem(); if (fileItem == 0) { return; } @@ -724,13 +711,13 @@ void DolphinView::slotPercent(int percent) void DolphinView::slotClear() { - fileView()->clearView(); + //fileView()->clearView(); updateStatusBar(); } void DolphinView::slotDeleteItem(KFileItem* item) { - fileView()->removeItem(item); + //fileView()->removeItem(item); updateStatusBar(); } @@ -738,17 +725,17 @@ void DolphinView::slotCompleted() { m_refreshing = true; - KFileView* view = fileView(); - view->clearView(); + //KFileView* view = fileView(); + //view->clearView(); // TODO: in Qt4 the code should get a lot // simpler and nicer due to Interview... - if (m_iconsView != 0) { + /*if (m_iconsView != 0) { m_iconsView->beginItemUpdates(); } - if (m_detailsView != 0) { - m_detailsView->beginItemUpdates(); - } + if (m_iconsView != 0) { + m_iconsView->beginItemUpdates(); + }*/ if (m_showProgress) { m_statusBar->setProgressText(QString::null); @@ -765,7 +752,7 @@ void DolphinView::slotCompleted() while (it != end) { KFileItem* item = *it; - view->insertItem(item); + //view->insertItem(item); if (item->isDir()) { ++m_folderCount; } @@ -777,26 +764,17 @@ void DolphinView::slotCompleted() updateStatusBar(); - if (m_iconsView != 0) { + /*if (m_iconsView != 0) { // Prevent a flickering of the icon view widget by giving a small // timeslot to swallow asynchronous update events. m_iconsView->setUpdatesEnabled(false); QTimer::singleShot(10, this, SLOT(slotDelayedUpdate())); } - if (m_detailsView != 0) { - m_detailsView->endItemUpdates(); - m_refreshing = false; - } -} - -void DolphinView::slotDelayedUpdate() -{ if (m_iconsView != 0) { - m_iconsView->setUpdatesEnabled(true); m_iconsView->endItemUpdates(); - } - m_refreshing = false; + m_refreshing = false; + }*/ } void DolphinView::slotInfoMessage(const QString& msg) @@ -809,17 +787,6 @@ void DolphinView::slotErrorMessage(const QString& msg) m_statusBar->setMessage(msg, DolphinStatusBar::Error); } -void DolphinView::slotRefreshItems(const KFileItemList& /* list */) -{ - QTimer::singleShot(0, this, SLOT(reload())); -} - -void DolphinView::slotAddItems(const KFileItemList& list) -{ - fileView()->addItemList(list); - fileView()->updateView(); -} - void DolphinView::slotGrabActivation() { Dolphin::mainWin().setActiveView(this); @@ -835,76 +802,21 @@ void DolphinView::slotContentsMoving(int x, int y) } } -void DolphinView::createView() +/*KFileView* DolphinView::fileView() const { - assert(m_iconsView == 0); - assert(m_detailsView == 0); - - switch (m_mode) { - case IconsView: - case PreviewsView: { - const DolphinIconsView::LayoutMode layoutMode = (m_mode == IconsView) ? - DolphinIconsView::Icons : - DolphinIconsView::Previews; - m_iconsView = new DolphinIconsView(this, layoutMode); - m_topLayout->insertWidget(1, m_iconsView); - setFocusProxy(m_iconsView); - - connect(m_iconsView, SIGNAL(executed(Q3IconViewItem*)), - this, SLOT(triggerIconsViewItem(Q3IconViewItem*))); - connect(m_iconsView, SIGNAL(returnPressed(Q3IconViewItem*)), - this, SLOT(triggerIconsViewItem(Q3IconViewItem*))); - connect(m_iconsView, SIGNAL(signalRequestActivation()), - this, SLOT(slotGrabActivation())); - - m_iconsView->endItemUpdates(); - m_iconsView->show(); - m_iconsView->setFocus(); - break; - } - - case DetailsView: { - m_detailsView = new DolphinDetailsView(this); - m_topLayout->insertWidget(1, m_detailsView); - setFocusProxy(m_detailsView); - - connect(m_detailsView, SIGNAL(executed(Q3ListViewItem*, const QPoint&, int)), - this, SLOT(triggerDetailsViewItem(Q3ListViewItem*, const QPoint&, int))); - connect(m_detailsView, SIGNAL(returnPressed(Q3ListViewItem*)), - this, SLOT(triggerDetailsViewItem(Q3ListViewItem*))); - connect(m_detailsView, SIGNAL(signalRequestActivation()), - this, SLOT(slotGrabActivation())); - m_detailsView->show(); - m_detailsView->setFocus(); - break; - } - - default: - break; - } - - connect(scrollView(), SIGNAL(contentsMoving(int, int)), - this, SLOT(slotContentsMoving(int, int))); - - startDirLister(m_urlNavigator->url()); -} - -KFileView* DolphinView::fileView() const -{ - return (m_mode == DetailsView) ? static_cast(m_detailsView) : + return (m_mode == DetailsView) ? static_cast(m_iconsView) : static_cast(m_iconsView); -} +}*/ Q3ScrollView* DolphinView::scrollView() const { - return (m_mode == DetailsView) ? static_cast(m_detailsView) : - static_cast(m_iconsView); + return 0; //(m_mode == DetailsView) ? static_cast(m_iconsView) : + // static_cast(m_iconsView); } ItemEffectsManager* DolphinView::itemEffectsManager() const { - return (m_mode == DetailsView) ? static_cast(m_detailsView) : - static_cast(m_iconsView); + return 0; } void DolphinView::startDirLister(const KUrl& url, bool reload) @@ -1069,14 +981,14 @@ void DolphinView::slotChangeNameFilter(const QString& nameFilter) // stay as they are by filtering, only an inserting of an item // results to an automatic adjusting of the item position. In Qt4/KDE4 // this workaround should get obsolete due to Interview. - KFileView* view = fileView(); + /*KFileView* view = fileView(); if (view == m_iconsView) { KFileItem* first = view->firstFileItem(); if (first != 0) { view->removeItem(first); view->insertItem(first); } - } + }*/ } bool DolphinView::isFilterBarVisible() diff --git a/src/dolphinview.h b/src/dolphinview.h index b71af3a624..46bee5bd09 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -34,15 +34,18 @@ #include #include +#include + class QPainter; class KUrl; +class KDirModel; class QLineEdit; class UrlNavigator; class QTimer; class Q3IconViewItem; class Q3ListViewItem; class Q3VBoxLayout; -class KFileView; +//class KFileView; class Dolphin; class DolphinDirLister; class DolphinStatusBar; @@ -53,6 +56,9 @@ class Q3ScrollView; class KProgress; class ItemEffectsManager; class FilterBar; + +class QModelIndex; + /** * @short Represents a view for the directory content * including the navigation bar and status bar. @@ -378,21 +384,15 @@ protected: private slots: void slotUrlChanged(const KUrl& kurl); void triggerIconsViewItem(Q3IconViewItem *item); - void triggerDetailsViewItem(Q3ListViewItem* item, - const QPoint& pos, - int column); - void triggerDetailsViewItem(Q3ListViewItem* item); + void triggerItem(const QModelIndex& index); void updateUrl(); void slotPercent(int percent); void slotClear(); void slotDeleteItem(KFileItem* item); void slotCompleted(); - void slotDelayedUpdate(); void slotInfoMessage(const QString& msg); void slotErrorMessage(const QString& msg); - void slotRefreshItems(const KFileItemList& list); - void slotAddItems(const KFileItemList& list); void slotGrabActivation(); @@ -411,8 +411,7 @@ private slots: void slotChangeNameFilter(const QString& nameFilter); private: - void createView(); - KFileView* fileView() const; + //KFileView* fileView() const; Q3ScrollView* scrollView() const; ItemEffectsManager* itemEffectsManager() const; void startDirLister(const KUrl& url, bool reload = false); @@ -441,9 +440,7 @@ private: Q3VBoxLayout* m_topLayout; UrlNavigator* m_urlNavigator; - DolphinIconsView* m_iconsView; - DolphinDetailsView* m_detailsView; DolphinStatusBar* m_statusBar; int m_iconSize; diff --git a/src/iconsviewsettingspage.cpp b/src/iconsviewsettingspage.cpp index 562953dcc5..69d700e57a 100644 --- a/src/iconsviewsettingspage.cpp +++ b/src/iconsviewsettingspage.cpp @@ -39,10 +39,10 @@ #define GRID_SPACING_BASE 8 #define GRID_SPACING_INC 12 -IconsViewSettingsPage::IconsViewSettingsPage(DolphinIconsView::LayoutMode mode, +IconsViewSettingsPage::IconsViewSettingsPage(/*DolphinIconsView::LayoutMode mode,*/ QWidget* parent) : KVBox(parent), - m_mode(mode), + //m_mode(mode), m_iconSizeSlider(0), m_previewSizeSlider(0), m_textWidthBox(0), @@ -89,7 +89,7 @@ IconsViewSettingsPage::IconsViewSettingsPage(DolphinIconsView::LayoutMode mode, m_iconSizeViewer->setEraseColor(iconBackgroundColor); slotIconSizeChanged(m_iconSizeSlider->value()); - if (m_mode == DolphinIconsView::Previews) { + if (false /*m_mode == DolphinIconsView::Previews*/) { // create 'Preview Size' group including slider and preview Q3GroupBox* previewSizeGroup = new Q3GroupBox(2, Qt::Vertical, i18n("Preview Size"), sizesLayout); previewSizeGroup->setSizePolicy(sizePolicy); @@ -173,8 +173,8 @@ void IconsViewSettingsPage::applySettings() const int defaultSize = iconSize(m_iconSizeSlider->value()); settings->setIconSize(defaultSize); - int previewSize = (m_mode == DolphinIconsView::Previews) ? - iconSize(m_previewSizeSlider->value()) : + int previewSize = //(m_mode == DolphinIconsView::Previews) ? + //iconSize(m_previewSizeSlider->value()) : defaultSize; if (previewSize < defaultSize) { // assure that the preview size is never smaller than the icon size diff --git a/src/iconsviewsettingspage.h b/src/iconsviewsettingspage.h index bd539057ab..6293491d21 100644 --- a/src/iconsviewsettingspage.h +++ b/src/iconsviewsettingspage.h @@ -55,7 +55,7 @@ class IconsViewSettingsPage : public KVBox Q_OBJECT public: - IconsViewSettingsPage(DolphinIconsView::LayoutMode mode, + IconsViewSettingsPage(/*DolphinIconsView::LayoutMode mode,*/ QWidget* parent); virtual ~IconsViewSettingsPage(); @@ -71,7 +71,7 @@ private slots: void slotPreviewSizeChanged(int value); private: - DolphinIconsView::LayoutMode m_mode; + //DolphinIconsView::LayoutMode m_mode; QSlider* m_iconSizeSlider; PixmapViewer* m_iconSizeViewer; diff --git a/src/itemeffectsmanager.cpp b/src/itemeffectsmanager.cpp deleted file mode 100644 index 782dfe3c50..0000000000 --- a/src/itemeffectsmanager.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/*************************************************************************** - * 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., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "itemeffectsmanager.h" -#include -#include -#include -//Added by qt3to4: -#include -#include -#include -#include - -#include "dolphin.h" -#include "dolphinstatusbar.h" - -ItemEffectsManager::ItemEffectsManager() -{ - m_pixmapCopy = new QPixmap(); -} - -ItemEffectsManager::~ItemEffectsManager() -{ - delete m_pixmapCopy; - m_pixmapCopy = 0; - - m_highlightedUrl = 0; -} - -void ItemEffectsManager::zoomIn() -{ - Dolphin::mainWin().refreshViews(); -} - -void ItemEffectsManager::zoomOut() -{ - Dolphin::mainWin().refreshViews(); -} - -void ItemEffectsManager::activateItem(void* context) -{ - KFileItem* fileInfo = contextFileInfo(context); - const KUrl itemUrl(fileInfo->url()); - if (m_highlightedUrl == itemUrl) { - // the item is already highlighted - return; - } - - resetActivatedItem(); - - const QPixmap* itemPixmap = contextPixmap(context); - if (itemPixmap != 0) { - // remember the pixmap and item to be able to - // restore it to the old state later - *m_pixmapCopy = *itemPixmap; - m_highlightedUrl = itemUrl; - - // apply an icon effect to the item below the mouse pointer - KIconEffect iconEffect; - QPixmap pixmap = iconEffect.apply(*itemPixmap, - K3Icon::Desktop, - K3Icon::ActiveState); - setContextPixmap(context, pixmap); - } - - if (!Dolphin::mainWin().activeView()->hasSelection()) { - DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar(); - statusBar->setMessage(statusBarText(fileInfo), DolphinStatusBar::Default); - } -} - -void ItemEffectsManager::resetActivatedItem() -{ - if (m_highlightedUrl.isEmpty()) { - return; - } - - for (void* context = firstContext(); context != 0; context = nextContext(context)) { - KUrl itemUrl(contextFileInfo(context)->url()); - if (itemUrl == m_highlightedUrl) { - // the highlighted item has been found and is restored to the default state - KIconEffect iconEffect; - QPixmap pixmap = iconEffect.apply(*m_pixmapCopy, - K3Icon::Desktop, - K3Icon::DefaultState); - - // TODO: KFileIconView does not emit any signal when the preview has been finished. - // Hence check the size to prevent that a preview is hidden by restoring a - // non-preview pixmap. - const QPixmap* highlightedPixmap = contextPixmap(context); - const bool restore = (pixmap.width() == highlightedPixmap->width()) && - (pixmap.height() == highlightedPixmap->height()); - if (restore) { - setContextPixmap(context, pixmap); - } - break; - } - } - - m_highlightedUrl = 0; - - DolphinStatusBar* statusBar = Dolphin::mainWin().activeView()->statusBar(); - statusBar->clear(); -} - -void ItemEffectsManager::updateDisabledItems() -{ - if (!m_disabledItems.isEmpty()) { - // restore all disabled items with their original pixmap - for (void* context = firstContext(); context != 0; context = nextContext(context)) { - const KFileItem* fileInfo = contextFileInfo(context); - const KUrl& fileUrl = fileInfo->url(); - Q3ValueListIterator it = m_disabledItems.begin(); - while (it != m_disabledItems.end()) { - if (fileUrl == (*it).url) { - setContextPixmap(context, (*it).pixmap); - } - ++it; - } - } - m_disabledItems.clear(); - } - - if (!Dolphin::mainWin().clipboardContainsCutData()) { - return; - } - - QClipboard* clipboard = QApplication::clipboard(); - const QMimeData* data = clipboard->mimeData(); - KUrl::List urls = KUrl::List::fromMimeData(data); - if (urls.isEmpty()) { - return; - } - - // The clipboard contains items, which have been cutted. Change the pixmaps of all those - // items to the disabled state. - for (void* context = firstContext(); context != 0; context = nextContext(context)) { - const KFileItem* fileInfo = contextFileInfo(context); - const KUrl& fileUrl = fileInfo->url(); - for(KUrl::List::ConstIterator it = urls.begin(); it != urls.end(); ++it) { - if (fileUrl == (*it)) { - const QPixmap* itemPixmap = contextPixmap(context); - if (itemPixmap != 0) { - // remember old pixmap - DisabledItem disabledItem; - disabledItem.url = fileUrl; - disabledItem.pixmap = *itemPixmap; - m_disabledItems.append(disabledItem); - - KIconEffect iconEffect; - QPixmap disabledPixmap = iconEffect.apply(*itemPixmap, - K3Icon::Desktop, - K3Icon::DisabledState); - setContextPixmap(context, disabledPixmap); - } - break; - } - } - } -} - -QString ItemEffectsManager::statusBarText(KFileItem* fileInfo) const -{ - if (fileInfo->isDir()) { - // KFileItem::getStatusBar() returns "MyDocuments/ Folder" as - // status bar text for a folder 'MyDocuments'. This is adjusted - // to "MyDocuments (Folder)" in Dolphin. - return i18n("%1 (Folder)",fileInfo->name()); - } - - return fileInfo->getStatusBarInfo(); -} diff --git a/src/itemeffectsmanager.h b/src/itemeffectsmanager.h deleted file mode 100644 index b442adce02..0000000000 --- a/src/itemeffectsmanager.h +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************** - * 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., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef ITEMEFFECTSMANAGER_H -#define ITEMEFFECTSMANAGER_H - -#include -#include -#include -#include -class KFileItem; - -/** - * @brief Abstract class to implement item effects for a Dolphin view. - * - * Derived classes must implement the following pure virtual methods: - * - ItemEffectsManager::setContextPixmap() - * - ItemEffectsManager::contextPixmap() - * - ItemEffectsManager::firstContext() - * - ItemEffectsManager::nextContext() - * - ItemEffectsManager::contextFileInfo() - * - * The item effects manager highlights currently active items and also - * respects cutted items. A 'context' is defined as abstract data type, - * which usually is represented by a KFileListViewItem or - * a KFileIconViewItem. - * - * In Qt4 the item effects manager should get integrated as part of Interview - * and hence no abstract context handling should be necessary anymore. The main - * purpose of the current interface is to prevent code duplication as there is - * no common model shared by QListView and QIconView of Qt3. - * - * @see DolphinIconsView - * @see DolphinDetailsView - * @author Peter Penz - */ -class ItemEffectsManager -{ -public: - ItemEffectsManager(); - virtual ~ItemEffectsManager(); - - /** Is invoked before the items get updated. */ - virtual void beginItemUpdates() = 0; - - /** Is invoked after the items have been updated. */ - virtual void endItemUpdates() = 0; - - /** - * Increases the size of the current set view mode and refreshes - * all views. Derived implementations must invoke the base implementation - * if zooming in had been done. - */ - virtual void zoomIn(); - - /** - * Decreases the size of the current set view mode and refreshes - * all views. Derived implementations must invoke the base implementation - * if zooming out had been done. - */ - virtual void zoomOut(); - - /** - * Returns true, if zooming in is possible. If false is returned, - * the minimal zoom size is possible. - */ - virtual bool isZoomInPossible() const = 0; - - /** - * Returns true, if zooming in is possible. If false is returned, - * the minimal zoom size is possible. - */ - virtual bool isZoomOutPossible() const = 0; - -protected: - virtual void setContextPixmap(void* context, - const QPixmap& pixmap) = 0; - virtual const QPixmap* contextPixmap(void* context) = 0; - virtual void* firstContext() = 0; - virtual void* nextContext(void* context) = 0; - virtual KFileItem* contextFileInfo(void* context) = 0; - - void activateItem(void* context); - void resetActivatedItem(); - void updateDisabledItems(); - -private: - struct DisabledItem { - KUrl url; - QPixmap pixmap; - }; - - QPixmap* m_pixmapCopy; - KUrl m_highlightedUrl; - - // contains all items which have been disabled by a 'cut' operation - Q3ValueList m_disabledItems; - - /** Returns the text for the statusbar for an activated item. */ - QString statusBarText(KFileItem* fileInfo) const; -}; - -#endif diff --git a/src/viewsettingspage.cpp b/src/viewsettingspage.cpp index a0f65cfadb..d352266af6 100644 --- a/src/viewsettingspage.cpp +++ b/src/viewsettingspage.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "iconsviewsettingspage.h" #include "detailsviewsettingspage.h" @@ -40,7 +41,7 @@ ViewSettingsPage::ViewSettingsPage(QWidget *parent) : QTabWidget* tabWidget = new QTabWidget(parent); // initialize 'Icons' tab - m_iconsPage = new IconsViewSettingsPage(DolphinIconsView::Icons, tabWidget); + m_iconsPage = new IconsViewSettingsPage(/*DolphinIconsView::Icons,*/ tabWidget); tabWidget->addTab(m_iconsPage, SmallIcon("view_icon"), i18n("Icons")); // initialize 'Details' tab @@ -48,7 +49,7 @@ ViewSettingsPage::ViewSettingsPage(QWidget *parent) : tabWidget->addTab(m_detailsPage, SmallIcon("view_text"), i18n("Details")); // initialize 'Previews' tab - m_previewsPage = new IconsViewSettingsPage(DolphinIconsView::Previews, tabWidget); + m_previewsPage = new IconsViewSettingsPage(/*DolphinIconsView::Previews,*/ tabWidget); tabWidget->addTab(m_previewsPage, SmallIcon("gvdirpart"), i18n("Previews")); topLayout->addWidget(tabWidget, 0, 0 );