mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Assure that when requesting the context menu for the column-view, that the correct items are used.
TODO for 4.2: get rid of those 'if (isColumnViewActive())' special cases and provide a generic model which also works with the way the column view is implemented BUG: 164146 svn path=/trunk/KDE/kdebase/apps/; revision=821903
This commit is contained in:
parent
91607d4c4d
commit
b8a4e0fac2
|
@ -92,9 +92,7 @@ DolphinColumnView::~DolphinColumnView()
|
|||
QModelIndex DolphinColumnView::indexAt(const QPoint& point) const
|
||||
{
|
||||
foreach (DolphinColumnWidget* column, m_columns) {
|
||||
const QPoint topLeft = column->frameGeometry().topLeft();
|
||||
const QPoint adjustedPoint(point.x() - topLeft.x(), point.y() - topLeft.y());
|
||||
const QModelIndex index = column->indexAt(adjustedPoint);
|
||||
const QModelIndex index = column->indexAt(columnPosition(column, point));
|
||||
if (index.isValid()) {
|
||||
return index;
|
||||
}
|
||||
|
@ -103,6 +101,18 @@ QModelIndex DolphinColumnView::indexAt(const QPoint& point) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
KFileItem DolphinColumnView::itemAt(const QPoint& point) const
|
||||
{
|
||||
foreach (DolphinColumnWidget* column, m_columns) {
|
||||
KFileItem item = column->itemAt(columnPosition(column, point));
|
||||
if (!item.isNull()) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return KFileItem();
|
||||
}
|
||||
|
||||
void DolphinColumnView::scrollTo(const QModelIndex& index, ScrollHint hint)
|
||||
{
|
||||
activeColumn()->scrollTo(index, hint);
|
||||
|
@ -254,6 +264,11 @@ void DolphinColumnView::editItem(const KFileItem& item)
|
|||
activeColumn()->editItem(item);
|
||||
}
|
||||
|
||||
KFileItemList DolphinColumnView::selectedItems() const
|
||||
{
|
||||
return activeColumn()->selectedItems();
|
||||
}
|
||||
|
||||
void DolphinColumnView::selectAll()
|
||||
{
|
||||
activeColumn()->selectAll();
|
||||
|
@ -587,4 +602,10 @@ void DolphinColumnView::removeAllColumns()
|
|||
assureVisibleActiveColumn();
|
||||
}
|
||||
|
||||
QPoint DolphinColumnView::columnPosition(DolphinColumnWidget* column, const QPoint& point) const
|
||||
{
|
||||
const QPoint topLeft = column->frameGeometry().topLeft();
|
||||
return QPoint(point.x() - topLeft.x(), point.y() - topLeft.y());
|
||||
}
|
||||
|
||||
#include "dolphincolumnview.moc"
|
||||
|
|
|
@ -50,8 +50,19 @@ public:
|
|||
explicit DolphinColumnView(QWidget* parent, DolphinController* controller);
|
||||
virtual ~DolphinColumnView();
|
||||
|
||||
/** @see QAbstractItemView::indexAt() */
|
||||
virtual QModelIndex indexAt(const QPoint& point) const;
|
||||
|
||||
/**
|
||||
* Returns the item on the position \a pos. The KFileItem instance
|
||||
* is null if no item is below the position.
|
||||
*/
|
||||
KFileItem itemAt(const QPoint& point) const;
|
||||
|
||||
/** @see QAbstractItemView::scrollTo() */
|
||||
virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
|
||||
|
||||
/** @see QAbstractItemView::visualRect() */
|
||||
virtual QRect visualRect(const QModelIndex& index) const;
|
||||
|
||||
/** Inverts the selection of the currently active column. */
|
||||
|
@ -97,6 +108,11 @@ public:
|
|||
*/
|
||||
void editItem(const KFileItem& item);
|
||||
|
||||
/**
|
||||
* Returns the selected items of the active column.
|
||||
*/
|
||||
KFileItemList selectedItems() const;
|
||||
|
||||
public slots:
|
||||
/** @see QAbstractItemView::selectAll() */
|
||||
virtual void selectAll();
|
||||
|
@ -175,6 +191,12 @@ private:
|
|||
/** Removes all columns except of the root column. */
|
||||
void removeAllColumns();
|
||||
|
||||
/**
|
||||
* Returns the position of the point \a point relative to the column
|
||||
* \a column.
|
||||
*/
|
||||
QPoint columnPosition(DolphinColumnWidget* column, const QPoint& point) const;
|
||||
|
||||
private:
|
||||
DolphinController* m_controller;
|
||||
bool m_active;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "dolphin_columnmodesettings.h"
|
||||
#include "dolphin_generalsettings.h"
|
||||
#include "draganddrophelper.h"
|
||||
#include "iconmanager.h"
|
||||
#include "selectionmanager.h"
|
||||
#include "tooltipmanager.h"
|
||||
|
||||
|
@ -39,8 +40,6 @@
|
|||
#include <kjob.h>
|
||||
#include <konqmimedata.h>
|
||||
|
||||
#include "iconmanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QPainter>
|
||||
|
@ -246,6 +245,33 @@ void DolphinColumnWidget::editItem(const KFileItem& item)
|
|||
}
|
||||
}
|
||||
|
||||
KFileItem DolphinColumnWidget::itemAt(const QPoint& pos) const
|
||||
{
|
||||
KFileItem item;
|
||||
const QModelIndex index = indexAt(pos);
|
||||
if (index.isValid() && (index.column() == DolphinModel::Name)) {
|
||||
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
|
||||
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
KFileItemList DolphinColumnWidget::selectedItems() const
|
||||
{
|
||||
const QItemSelection selection = m_proxyModel->mapSelectionToSource(selectionModel()->selection());
|
||||
KFileItemList itemList;
|
||||
|
||||
const QModelIndexList indexList = selection.indexes();
|
||||
foreach (const QModelIndex &index, indexList) {
|
||||
KFileItem item = m_dolphinModel->itemForIndex(index);
|
||||
if (!item.isNull()) {
|
||||
itemList.append(item);
|
||||
}
|
||||
}
|
||||
|
||||
return itemList;
|
||||
}
|
||||
|
||||
QStyleOptionViewItem DolphinColumnWidget::viewOptions() const
|
||||
{
|
||||
QStyleOptionViewItem viewOptions = QListView::viewOptions();
|
||||
|
@ -364,6 +390,10 @@ void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
QListView::contextMenuEvent(event);
|
||||
|
||||
const QModelIndex index = indexAt(event->pos());
|
||||
if (!index.isValid()) {
|
||||
clearSelection();
|
||||
}
|
||||
|
||||
if (index.isValid() || m_active) {
|
||||
// Only open a context menu above an item or if the mouse is above
|
||||
// the active column.
|
||||
|
|
|
@ -104,6 +104,14 @@ public:
|
|||
*/
|
||||
void editItem(const KFileItem& item);
|
||||
|
||||
/**
|
||||
* Returns the item on the position \a pos. The KFileItem instance
|
||||
* is null if no item is below the position.
|
||||
*/
|
||||
KFileItem itemAt(const QPoint& pos) const;
|
||||
|
||||
KFileItemList selectedItems() const;
|
||||
|
||||
protected:
|
||||
virtual QStyleOptionViewItem viewOptions() const;
|
||||
virtual void startDrag(Qt::DropActions supportedActions);
|
||||
|
|
|
@ -337,7 +337,8 @@ QString DolphinContextMenu::placesName(const KUrl& url) const
|
|||
QAction* DolphinContextMenu::createPasteAction()
|
||||
{
|
||||
QAction* action = 0;
|
||||
if ((m_selectedItems.count() == 1) && m_fileInfo.isDir()) {
|
||||
const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
|
||||
if (isDir && (m_selectedItems.count() == 1)) {
|
||||
action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
|
||||
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
||||
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
|
||||
|
|
|
@ -295,6 +295,10 @@ void DolphinView::clearSelection()
|
|||
|
||||
KFileItemList DolphinView::selectedItems() const
|
||||
{
|
||||
if (isColumnViewActive()) {
|
||||
return m_columnView->selectedItems();
|
||||
}
|
||||
|
||||
const QAbstractItemView* view = itemView();
|
||||
|
||||
// Our view has a selection, we will map them back to the DolphinModel
|
||||
|
@ -325,12 +329,6 @@ KUrl::List DolphinView::selectedUrls() const
|
|||
return urls;
|
||||
}
|
||||
|
||||
KFileItem DolphinView::fileItem(const QModelIndex& index) const
|
||||
{
|
||||
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
|
||||
return m_dolphinModel->itemForIndex(dolphinModelIndex);
|
||||
}
|
||||
|
||||
void DolphinView::setContentsPosition(int x, int y)
|
||||
{
|
||||
QAbstractItemView* view = itemView();
|
||||
|
@ -774,10 +772,14 @@ void DolphinView::emitSelectionChangedSignal()
|
|||
void DolphinView::openContextMenu(const QPoint& pos)
|
||||
{
|
||||
KFileItem item;
|
||||
|
||||
const QModelIndex index = itemView()->indexAt(pos);
|
||||
if (index.isValid() && (index.column() == DolphinModel::Name)) {
|
||||
item = fileItem(index);
|
||||
if (isColumnViewActive()) {
|
||||
item = m_columnView->itemAt(pos);
|
||||
} else {
|
||||
const QModelIndex index = itemView()->indexAt(pos);
|
||||
if (index.isValid() && (index.column() == DolphinModel::Name)) {
|
||||
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
|
||||
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_toolTipManager != 0) {
|
||||
|
|
|
@ -218,11 +218,6 @@ public:
|
|||
*/
|
||||
KUrl::List selectedUrls() const;
|
||||
|
||||
/**
|
||||
* Returns the file item for the given model index \a index.
|
||||
*/
|
||||
KFileItem fileItem(const QModelIndex& index) const;
|
||||
|
||||
/**
|
||||
* Sets the upper left position of the view content
|
||||
* to (x,y). The content of the view might be larger than the visible area
|
||||
|
|
Loading…
Reference in a new issue