diff options
author | Michele Calgaro <[email protected]> | 2013-11-06 19:48:25 +0100 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2013-11-06 19:51:41 +0100 |
commit | 6bf8e926c7ec585e83451444fa81fd1cec1d2a6b (patch) | |
tree | b4898b78519b17970b191607a3682f9aeb21f272 | |
parent | 645993e7d8ffafbd9d4d0d70cc53f04cfd0c6c3a (diff) | |
download | tdelibs-6bf8e926c7ec585e83451444fa81fd1cec1d2a6b.tar.gz tdelibs-6bf8e926c7ec585e83451444fa81fd1cec1d2a6b.zip |
Enhance renaming in Konqueror listview
This relates to Bug 1677
-rw-r--r-- | tdeui/tdelistview.cpp | 91 | ||||
-rw-r--r-- | tdeui/tdelistview.h | 76 | ||||
-rw-r--r-- | tdeui/tdelistviewlineedit.h | 29 |
3 files changed, 166 insertions, 30 deletions
diff --git a/tdeui/tdelistview.cpp b/tdeui/tdelistview.cpp index c60070d4a..32e7273af 100644 --- a/tdeui/tdelistview.cpp +++ b/tdeui/tdelistview.cpp @@ -17,6 +17,7 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + #include "config.h" #include <tqdragobject.h> @@ -72,8 +73,8 @@ public: autoSelectDelay(0), useSmallExecuteArea(false), dragOverItem(0), - dragDelay (TDEGlobalSettings::dndEventDelay()), - editor (new TDEListViewLineEdit (listview)), + dragDelay(TDEGlobalSettings::dndEventDelay()), + editor(new TDEListViewLineEdit(listview)), cursorInExecuteArea(false), itemsMovable (true), selectedBySimpleMove(false), @@ -106,6 +107,8 @@ public: { renameable.append(0); 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 () @@ -176,13 +179,13 @@ public: 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 ); - hide(); - connect( parent, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() )); - connect( parent, TQT_SIGNAL( itemRemoved( TQListViewItem * ) ), - TQT_SLOT( slotItemRemoved( TQListViewItem * ) )); + setFrame( false ); + hide(); + connect( parent, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() )); + connect( parent, TQT_SIGNAL( itemRemoved( TQListViewItem * ) ), + TQT_SLOT( slotItemRemoved( TQListViewItem * ) )); } TDEListViewLineEdit::~TDEListViewLineEdit() @@ -323,37 +326,58 @@ void TDEListViewLineEdit::selectNextCell (TQListViewItem *pitem, int column, boo #undef KeyPress #endif -bool TDEListViewLineEdit::event (TQEvent *pe) +bool TDEListViewLineEdit::event(TQEvent *pe) { if (pe->type() == TQEvent::KeyPress) { - TQKeyEvent *k = (TQKeyEvent *) pe; - - if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && - p->tabOrderedRenaming() && p->itemsRenameable() && - !(k->state() & ControlButton || k->state() & AltButton)) + TQKeyEvent *k = (TQKeyEvent*)pe; + KKey kk(k); + 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() && + !(k->state() & ControlButton || k->state() & AltButton)) { - selectNextCell(item, col, - (k->key() == Key_Tab && !(k->state() & ShiftButton))); + selectNextCell(item, col, (k->key() == Key_Tab && !(k->state() & ShiftButton))); return true; - } + } } - return KLineEdit::event(pe); } 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); else if(e->key() == Qt::Key_Escape) terminate(false); - else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) - { + else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) + { terminate(true); - KLineEdit::keyPressEvent(e); - } - else + KLineEdit::keyPressEvent(e); + } + else KLineEdit::keyPressEvent(e); } @@ -425,8 +449,7 @@ void TDEListViewLineEdit::slotItemRemoved(TQListViewItem *i) TDEListView::TDEListView( TQWidget *parent, const char *name ) - : TQListView( parent, name ), - d (new TDEListViewPrivate (this)) + : TQListView(parent, name), d(new TDEListViewPrivate(this)) { setDragAutoScroll(true); @@ -1416,6 +1439,17 @@ void TDEListView::doneEditing(TQListViewItem *item, int row) 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 { return acceptDrops() && itemsMovable() && (e->source()==viewport()); @@ -2424,6 +2458,11 @@ bool TDEListView::useSmallExecuteArea() const return d->useSmallExecuteArea; } +void TDEListView::setRenameSettings(const TDEListViewRenameSettings &renSett) +{ + d->editor->setRenameSettings(renSett); +} + void TDEListView::virtual_hook( int, void* ) { /*BASE::virtual_hook( id, data );*/ } diff --git a/tdeui/tdelistview.h b/tdeui/tdelistview.h index 7de7117fb..950ce253a 100644 --- a/tdeui/tdelistview.h +++ b/tdeui/tdelistview.h @@ -17,18 +17,48 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + #ifndef TDELISTVIEW_H #define TDELISTVIEW_H #include <tqheader.h> #include <tqlistview.h> - +#include <tdeshortcut.h> #include <tqptrlist.h> #include <tdelibs_export.h> class TQDragObject; class TDEConfig; 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 * wide settings for Single Click/Double Click mode, AutoSelection and @@ -419,6 +449,17 @@ public: */ 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: /** @@ -571,11 +612,37 @@ signals: * @param i is the item for which the menu should be shown. May be 0L. * @param p is the point at which the menu should be shown. */ - void contextMenu (TDEListView* l, TQListViewItem* i, const TQPoint& p); + void contextMenu(TDEListView* l, TQListViewItem* i, const TQPoint& p); void itemAdded(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: /** * Rename column @p c of @p item. @@ -942,10 +1009,11 @@ protected slots: * @internal */ void slotSettingsChanged(int); - void slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ); 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. */ diff --git a/tdeui/tdelistviewlineedit.h b/tdeui/tdelistviewlineedit.h index 00b898f9f..0a87394ab 100644 --- a/tdeui/tdelistviewlineedit.h +++ b/tdeui/tdelistviewlineedit.h @@ -15,6 +15,7 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + #ifndef TDELISTVIEWLINEEDIT_H #define TDELISTVIEWLINEEDIT_H @@ -33,9 +34,36 @@ public: ~TDEListViewLineEdit(); TQListViewItem *currentItem() const; + void setRenameSettings(const TDEListViewRenameSettings &renSett) { m_renSett = renSett; }; signals: 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: void terminate(); @@ -53,6 +81,7 @@ protected: TQListViewItem *item; int col; TDEListView* const p; + TDEListViewRenameSettings m_renSett; protected slots: void slotSelectionChanged(); |