Enhance renaming in Konqueror listview

This relates to Bug 1677
pull/16/head
Michele Calgaro 12 years ago committed by Slávek Banko
parent 645993e7d8
commit 6bf8e926c7

@ -17,6 +17,7 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#include "config.h" #include "config.h"
#include <tqdragobject.h> #include <tqdragobject.h>
@ -106,6 +107,8 @@ public:
{ {
renameable.append(0); renameable.append(0);
connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int))); connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int)));
connect(editor, TQT_SIGNAL(renameNext(TQListViewItem*,int)), listview, TQT_SLOT(renameNextProxy(TQListViewItem*,int)));
connect(editor, TQT_SIGNAL(renamePrev(TQListViewItem*,int)), listview, TQT_SLOT(renamePrevProxy(TQListViewItem*,int)));
} }
~TDEListViewPrivate () ~TDEListViewPrivate ()
@ -176,7 +179,7 @@ public:
TDEListViewLineEdit::TDEListViewLineEdit(TDEListView *parent) TDEListViewLineEdit::TDEListViewLineEdit(TDEListView *parent)
: KLineEdit(parent->viewport()), item(0), col(0), p(parent) : KLineEdit(parent->viewport()), item(0), col(0), p(parent), m_renSett()
{ {
setFrame( false ); setFrame( false );
hide(); hide();
@ -328,23 +331,44 @@ bool TDEListViewLineEdit::event (TQEvent *pe)
if (pe->type() == TQEvent::KeyPress) if (pe->type() == TQEvent::KeyPress)
{ {
TQKeyEvent *k = (TQKeyEvent*)pe; TQKeyEvent *k = (TQKeyEvent*)pe;
KKey kk(k);
if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && if (m_renSett.m_useRenameSignals &&
(m_renSett.m_SCNext.contains(kk) || m_renSett.m_SCPrev.contains(kk)))
{
keyPressEvent(k);
return true;
}
else if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) &&
p->tabOrderedRenaming() && p->itemsRenameable() && p->tabOrderedRenaming() && p->itemsRenameable() &&
!(k->state() & ControlButton || k->state() & AltButton)) !(k->state() & ControlButton || k->state() & AltButton))
{ {
selectNextCell(item, col, selectNextCell(item, col, (k->key() == Key_Tab && !(k->state() & ShiftButton)));
(k->key() == Key_Tab && !(k->state() & ShiftButton)));
return true; return true;
} }
} }
return KLineEdit::event(pe); return KLineEdit::event(pe);
} }
void TDEListViewLineEdit::keyPressEvent(TQKeyEvent *e) void TDEListViewLineEdit::keyPressEvent(TQKeyEvent *e)
{ {
if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) KKey kk(e);
if (m_renSett.m_useRenameSignals &&
(m_renSett.m_SCNext.contains(kk) || m_renSett.m_SCPrev.contains(kk)))
{
TQListViewItem *i=item;
int c=col;
terminate(true);
KLineEdit::keyPressEvent(e);
if (m_renSett.m_SCNext.contains(kk))
{
emit renameNext(i,c);
}
else
{
emit renamePrev(i,c);
}
}
else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)
terminate(true); terminate(true);
else if(e->key() == Qt::Key_Escape) else if(e->key() == Qt::Key_Escape)
terminate(false); terminate(false);
@ -425,8 +449,7 @@ void TDEListViewLineEdit::slotItemRemoved(TQListViewItem *i)
TDEListView::TDEListView( TQWidget *parent, const char *name ) TDEListView::TDEListView( TQWidget *parent, const char *name )
: TQListView( parent, name ), : TQListView(parent, name), d(new TDEListViewPrivate(this))
d (new TDEListViewPrivate (this))
{ {
setDragAutoScroll(true); setDragAutoScroll(true);
@ -1416,6 +1439,17 @@ void TDEListView::doneEditing(TQListViewItem *item, int row)
emit itemRenamed(item); emit itemRenamed(item);
} }
void TDEListView::renameNextProxy(TQListViewItem *item, int col)
{
emit renameNext(item, col);
}
void TDEListView::renamePrevProxy(TQListViewItem *item, int col)
{
emit renamePrev(item, col);
}
bool TDEListView::acceptDrag(TQDropEvent* e) const bool TDEListView::acceptDrag(TQDropEvent* e) const
{ {
return acceptDrops() && itemsMovable() && (e->source()==viewport()); return acceptDrops() && itemsMovable() && (e->source()==viewport());
@ -2424,6 +2458,11 @@ bool TDEListView::useSmallExecuteArea() const
return d->useSmallExecuteArea; return d->useSmallExecuteArea;
} }
void TDEListView::setRenameSettings(const TDEListViewRenameSettings &renSett)
{
d->editor->setRenameSettings(renSett);
}
void TDEListView::virtual_hook( int, void* ) void TDEListView::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ } { /*BASE::virtual_hook( id, data );*/ }

@ -17,18 +17,48 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#ifndef TDELISTVIEW_H #ifndef TDELISTVIEW_H
#define TDELISTVIEW_H #define TDELISTVIEW_H
#include <tqheader.h> #include <tqheader.h>
#include <tqlistview.h> #include <tqlistview.h>
#include <tdeshortcut.h>
#include <tqptrlist.h> #include <tqptrlist.h>
#include <tdelibs_export.h> #include <tdelibs_export.h>
class TQDragObject; class TQDragObject;
class TDEConfig; class TDEConfig;
class KLineEdit; class KLineEdit;
// Used to set the 'move to next/previous item' after renaming is completed
class TDEListViewRenameSettings
{
public:
bool m_useRenameSignals; // if true, emits renameNext/renamePrev signals
TDEShortcut m_SCNext; // the shortcut key for moving to the next cell
TDEShortcut m_SCPrev; // the shortcut key for moving to the previous cell
TDEListViewRenameSettings()
: m_useRenameSignals(false), m_SCNext(), m_SCPrev() {}
TDEListViewRenameSettings(bool useRenameSignals, TDEShortcut scNext, TDEShortcut scPrev)
: m_useRenameSignals(useRenameSignals), m_SCNext(scNext), m_SCPrev(scPrev) {}
TDEListViewRenameSettings(const TDEListViewRenameSettings &that)
: m_useRenameSignals(that.m_useRenameSignals), m_SCNext(that.m_SCNext), m_SCPrev(that.m_SCPrev) {}
TDEListViewRenameSettings& operator=(const TDEListViewRenameSettings &that)
{
if (this==&that) return *this;
m_useRenameSignals = that.m_useRenameSignals;
m_SCNext = that.m_SCNext;
m_SCPrev = that.m_SCPrev;
return *this;
}
};
/** /**
* This Widget extends the functionality of TQListView to honor the system * This Widget extends the functionality of TQListView to honor the system
* wide settings for Single Click/Double Click mode, AutoSelection and * wide settings for Single Click/Double Click mode, AutoSelection and
@ -419,6 +449,17 @@ public:
*/ */
bool useSmallExecuteArea() const; bool useSmallExecuteArea() const;
/**
* Allows to set the rename settings for the TDEListViewLineEdit editor.
* It is possible to select whether to move or not the item selection when the rename
* operation is completed and which shortcuts to use to move to the next or previous item.
* @param renSett A TDEListViewRenameSettings object containing the specified settings.
*
* @since 14.0
*/
void setRenameSettings(const TDEListViewRenameSettings &renSett);
signals: signals:
/** /**
@ -576,6 +617,32 @@ signals:
void itemAdded(TQListViewItem *item); void itemAdded(TQListViewItem *item);
void itemRemoved(TQListViewItem *item); void itemRemoved(TQListViewItem *item);
/**
* This signal is emitted when item renaming is completed by a TAB.
* It signals the receiver that the sender would like to start renaming the next item.
* This is not hardcoded in TDEListView because the next item is application depended
* (for example it could be the next column or the next row or something completely different)
*
* @param item is the renamed item.
* @param col is the renamed column.
*
* @since 14.0
*/
void renameNext(TQListViewItem* item, int col);
/**
* This signal is emitted when item renaming is completed by a Shift+TAB.
* It signals the receiver that the sender would like to start renaming the previous item.
* This is not hardcoded in TDEListView because the next item is application depended
* (for example it could be the next column or the next row or something completely different)
*
* @param item is the renamed item.
* @param col is the renamed column.
*
* @since 14.0
*/
void renamePrev(TQListViewItem* item, int col);
public slots: public slots:
/** /**
* Rename column @p c of @p item. * Rename column @p c of @p item.
@ -942,9 +1009,10 @@ protected slots:
* @internal * @internal
*/ */
void slotSettingsChanged(int); void slotSettingsChanged(int);
void slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ); void slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c );
void doneEditing(TQListViewItem *item, int row); void doneEditing(TQListViewItem *item, int row);
void renameNextProxy(TQListViewItem *item, int col);
void renamePrevProxy(TQListViewItem *item, int col);
/** /**
* Repaint the rect where I was drawing the drop line. * Repaint the rect where I was drawing the drop line.

@ -15,6 +15,7 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#ifndef TDELISTVIEWLINEEDIT_H #ifndef TDELISTVIEWLINEEDIT_H
#define TDELISTVIEWLINEEDIT_H #define TDELISTVIEWLINEEDIT_H
@ -33,10 +34,37 @@ public:
~TDEListViewLineEdit(); ~TDEListViewLineEdit();
TQListViewItem *currentItem() const; TQListViewItem *currentItem() const;
void setRenameSettings(const TDEListViewRenameSettings &renSett) { m_renSett = renSett; };
signals: signals:
void done(TQListViewItem*, int); void done(TQListViewItem*, int);
/**
* This signal is emitted when item renaming is completed by a TAB.
* It signals the receiver that the sender would like to start renaming the next item.
* This is not hardcoded in TDEListView because the next item is application depended
* (for example it could be the next column or the next row or something completely different)
*
* @param item is the renamed item.
* @param col is the renamed column.
*
* @since 14.0
*/
void renameNext(TQListViewItem* item, int col);
/**
* This signal is emitted when item renaming is completed by a Shift+TAB.
* It signals the receiver that the sender would like to start renaming the previous item.
* This is not hardcoded in TDEListView because the next item is application depended
* (for example it could be the next column or the next row or something completely different)
*
* @param item is the renamed item.
* @param col is the renamed column.
*
* @since 14.0
*/
void renamePrev(TQListViewItem* item, int col);
public slots: public slots:
void terminate(); void terminate();
void load(TQListViewItem *i, int c); void load(TQListViewItem *i, int c);
@ -53,6 +81,7 @@ protected:
TQListViewItem *item; TQListViewItem *item;
int col; int col;
TDEListView* const p; TDEListView* const p;
TDEListViewRenameSettings m_renSett;
protected slots: protected slots:
void slotSelectionChanged(); void slotSelectionChanged();

Loading…
Cancel
Save