X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b8ef5ebca1662526e994815d6e044652ce7ccf4a..6a3f8086a372ca1c21ab474c7934e8f8e4b238f5:/src/panels/places/placespanel.cpp diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 429c5399a..61c15a7a1 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -23,6 +23,8 @@ #include "placespanel.h" +#include "dolphin_generalsettings.h" + #include #include #include @@ -33,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -42,6 +43,7 @@ #include "placesitemlistgroupheader.h" #include "placesitemlistwidget.h" #include "placesitemmodel.h" +#include "placesview.h" #include #include #include @@ -52,7 +54,10 @@ PlacesPanel::PlacesPanel(QWidget* parent) : m_controller(0), m_model(0), m_storageSetupFailedUrl(), - m_triggerStorageSetupButton() + m_triggerStorageSetupButton(), + m_itemDropEventIndex(-1), + m_itemDropEventMimeData(0), + m_itemDropEvent(0) { } @@ -62,9 +67,27 @@ PlacesPanel::~PlacesPanel() bool PlacesPanel::urlChanged() { + if (!url().isValid() || url().protocol().contains("search")) { + // Skip results shown by a search, as possible identical + // directory names are useless without parent-path information. + return false; + } + + if (m_controller) { + selectClosestItem(); + } + return true; } +void PlacesPanel::readSettings() +{ + if (m_controller) { + const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; + m_controller->setAutoActivationDelay(delay); + } +} + void PlacesPanel::showEvent(QShowEvent* event) { if (event->spontaneous()) { @@ -81,13 +104,16 @@ void PlacesPanel::showEvent(QShowEvent* event) connect(m_model, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString))); - KStandardItemListView* view = new KStandardItemListView(); - view->setWidgetCreator(new KItemListWidgetCreator()); - view->setGroupHeaderCreator(new KItemListGroupHeaderCreator()); + m_view = new PlacesView(); + m_view->setWidgetCreator(new KItemListWidgetCreator()); + m_view->setGroupHeaderCreator(new KItemListGroupHeaderCreator()); - m_controller = new KItemListController(m_model, view, this); + m_controller = new KItemListController(m_model, m_view, this); m_controller->setSelectionBehavior(KItemListController::SingleSelection); m_controller->setSingleClickActivation(true); + + readSettings(); + connect(m_controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int))); connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int))); connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF))); @@ -190,6 +216,41 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) showAllAction->setChecked(m_model->hiddenItemsShown()); } + menu.addSeparator(); + KMenu* iconSizeSubMenu = new KMenu(i18nc("@item:inmenu", "Icon Size"), &menu); + + struct IconSizeInfo + { + int size; + const char* context; + const char* text; + }; + + const int iconSizeCount = 4; + static const IconSizeInfo iconSizes[iconSizeCount] = { + {KIconLoader::SizeSmall, I18N_NOOP2_NOSTRIP("Small icon size", "Small (%1x%2)")}, + {KIconLoader::SizeSmallMedium, I18N_NOOP2_NOSTRIP("Medium icon size", "Medium (%1x%2)")}, + {KIconLoader::SizeMedium, I18N_NOOP2_NOSTRIP("Large icon size", "Large (%1x%2)")}, + {KIconLoader::SizeLarge, I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")} + }; + + QMap iconSizeActionMap; + QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu); + + for (int i = 0; i < iconSizeCount; ++i) { + const int size = iconSizes[i].size; + const QString text = i18nc(iconSizes[i].context, iconSizes[i].text, + size, size); + + QAction* action = iconSizeSubMenu->addAction(text); + iconSizeActionMap.insert(action, size); + action->setActionGroup(iconSizeGroup); + action->setCheckable(true); + action->setChecked(m_view->iconSize() == size); + } + + menu.addMenu(iconSizeSubMenu); + menu.addSeparator(); foreach (QAction* action, customContextMenuActions()) { menu.addAction(action); @@ -216,6 +277,8 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) m_model->requestTeardown(index); } else if (action == ejectAction) { m_model->requestEject(index); + } else if (iconSizeActionMap.contains(action)) { + m_view->setIconSize(iconSizeActionMap.value(action)); } } @@ -258,6 +321,30 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even return; } + if (m_model->storageSetupNeeded(index)) { + connect(m_model, SIGNAL(storageSetupDone(int,bool)), + this, SLOT(slotItemDropEventStorageSetupDone(int,bool))); + + m_itemDropEventIndex = index; + + // Make a full copy of the Mime-Data + m_itemDropEventMimeData = new QMimeData; + m_itemDropEventMimeData->setText(event->mimeData()->text()); + m_itemDropEventMimeData->setHtml(event->mimeData()->html()); + m_itemDropEventMimeData->setUrls(event->mimeData()->urls()); + m_itemDropEventMimeData->setImageData(event->mimeData()->imageData()); + m_itemDropEventMimeData->setColorData(event->mimeData()->colorData()); + + m_itemDropEvent = new QDropEvent(event->pos().toPoint(), + event->possibleActions(), + m_itemDropEventMimeData, + event->buttons(), + event->modifiers()); + + m_model->requestStorageSetup(index); + return; + } + KUrl destUrl = m_model->placesItem(index)->url(); QDropEvent dropEvent(event->pos().toPoint(), event->possibleActions(), @@ -268,6 +355,27 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even DragAndDropHelper::dropUrls(KFileItem(), destUrl, &dropEvent); } +void PlacesPanel::slotItemDropEventStorageSetupDone(int index, bool success) +{ + disconnect(m_model, SIGNAL(storageSetupDone(int,bool)), + this, SLOT(slotItemDropEventStorageSetupDone(int,bool))); + + if ((index == m_itemDropEventIndex) && m_itemDropEvent && m_itemDropEventMimeData) { + if (success) { + KUrl destUrl = m_model->placesItem(index)->url(); + + DragAndDropHelper::dropUrls(KFileItem(), destUrl, m_itemDropEvent); + } + + delete m_itemDropEventMimeData; + delete m_itemDropEvent; + + m_itemDropEventIndex = -1; + m_itemDropEventMimeData = 0; + m_itemDropEvent = 0; + } +} + void PlacesPanel::slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event) { m_model->dropMimeDataBefore(index, event->mimeData());