[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: KApplication::cut()....
From: Benjamin Meyer <ben () meyerhome ! net>
Date: 2005-09-23 15:32:14
Message-ID: 200509231132.16654.ben () meyerhome ! net
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
On Friday 23 September 2005 10:42 am, Simon Hausmann wrote:
> On Friday 23 September 2005 16:50, Benjamin Meyer wrote:
> > On Friday 23 September 2005 9:22 am, Joseph Wenninger wrote:
> > > Hi !
> > >
> > > 1) Why do I have to retrieve the action object, if I just want to cut
> > > or copy from the currently focused widget ? The focus widget doesn't
> > > have to be the mainwindow, but could be a child widget, right ? Ok, the
> > > advantage would be that you don't have to call the slots
> > > cut/copy/paste, ...
> >
> > yah having functions named cut() was a bad idea and a bad polution of the
> > name space, I have moved it into the private class
> >
> > > 2) If there are methods like createAutomaticCutActions, they should
> > > check if the action collection already has a cut action and only create
> > > a new one , if it doesn't , otherwise return the already existing
> >
> > If we want that funcionality KStdAction::create should really do that,
> > not createAutomaticCutActions.
> >
> > Ok attached is a new diff. Let me know what you think.
>
> Looks good to me. But you don't have to make KMainWindowPrivate a QObject
> or add a separate _p.h header file. Just keep everything as it is and add
> to KMainWindow's class declaration at the end:
>
> private:
> Q_PRIVATE_SLOT(d, void cut());
> Q_PRIVATE_SLOT(d, void copy());
> ...
>
> And have the slots as regular methods in the private:
>
> class KMainWindowPrivate
> {
> ...
> inline void copy() { invokeEditSlot(SLOT(copy()); }
> ...
> };
>
> Feel the power of Qt4's moc! ;-)
>
> Simon
Very cool. Attached is the modified version
-Benjamin Meyer
--
aka icefox
Public Key: http://www.icefox.net/public_key.asc
["diff" (text/x-diff)]
Index: kdecore/kapplication.h
===================================================================
--- kdecore/kapplication.h (revision 463257)
+++ kdecore/kapplication.h (working copy)
@@ -54,7 +54,6 @@
*
* Only one object of this class can be instantiated in a single app.
* This instance is always accessible via the 'kapp' global variable.
-* See cut() for an example.
*
* This class provides the following services to all KDE applications.
*
@@ -394,71 +393,6 @@
**/
void setTopWidget( QWidget *topWidget );
-public slots:
-
- /**
- * If the widget with focus provides a cut() slot, call that slot. Thus for a
- * simple application cut can be implemented as:
- * \code
- * KStdAction::cut( kapp, SLOT( cut() ), actionCollection() );
- * \endcode
- */
- void cut();
-
- /**
- * If the widget with focus provides a copy() slot, call that slot. Thus for a
- * simple application copy can be implemented as:
- * \code
- * KStdAction::copy( kapp, SLOT( copy() ), actionCollection() );
- * \endcode
- */
- void copy();
-
- /**
- * If the widget with focus provides a paste() slot, call that slot. Thus for a
- * simple application copy can be implemented as:
- * \code
- * KStdAction::paste( kapp, SLOT( paste() ), actionCollection() );
- * \endcode
- */
- void paste();
-
- /**
- * If the widget with focus provides a clear() slot, call that slot. Thus for a
- * simple application clear() can be implemented as:
- * \code
- * new KAction( i18n( "Clear" ), "editclear", 0, kapp, SLOT( clear() ), \
actionCollection(), "clear" );
- * \endcode
- *
- * Note that for some widgets, this may not provide the intended bahavior. For
- * example if you make use of the code above and a KListView has the focus, \
clear()
- * will clear all of the items in the list. If this is not the intened behavior
- * and you want to make use of this slot, you can subclass KListView and \
reimplement
- * this slot. For example the following code would implement a KListView without \
this
- * behavior:
- *
- * \code
- * class MyListView : public KListView {
- * Q_OBJECT
- * public:
- * MyListView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : \
KListView( parent, name, f ) {}
- * virtual ~MyListView() {}
- * public slots:
- * virtual void clear() {}
- * };
- * \endcode
- */
- void clear();
-
- /**
- * If the widget with focus provides a selectAll() slot, call that slot. Thus for \
a
- * simple application select all can be implemented as:
- * \code
- * KStdAction::selectAll( kapp, SLOT( selectAll() ), actionCollection() );
- * \endcode
- */
- void selectAll();
-
public:
/**
* Returns the DCOP name of the service launcher. This will be something like
@@ -477,7 +411,6 @@
*/
QString caption() const;
-
/**
* Builds a caption that contains the application name along with the
* userCaption using a standard layout.
@@ -722,39 +655,8 @@
static KApplication *KApp;
int pArgc;
- /**
- * This method is used internally to determine which edit slots are implemented
- * by the widget that has the focus, and to invoke those slots if available.
- *
- * @param slot is the slot as returned using the SLOT() macro, for example SLOT( \
cut() )
- *
- * This method can be used in KApplication subclasses to implement application \
wide
- * edit actions not supported by the KApplication class. For example (in your \
subclass):
- *
- * \code
- * void MyApplication::deselect()
- * {
- * invokeEditSlot( SLOT( deselect() ) );
- * }
- * \endcode
- *
- * Now in your application calls to MyApplication::deselect() will call this slot \
on the
- * focused widget if it provides this slot. You can combine this with KAction \
with:
- *
- * \code
- * KStdAction::deselect( static_cast<MyApplication *>( kapp ), SLOT( cut() ), \
actionCollection() );
- * \endcode
- *
- * @see cut()
- * @see copy()
- * @see paste()
- * @see clear()
- * @see selectAll()
- *
- * @since 3.2
- */
- void invokeEditSlot( const char *slot );
+
private slots:
void dcopFailure(const QString &);
void dcopBlockUserInput( bool );
Index: kdecore/kapplication.cpp
===================================================================
--- kdecore/kapplication.cpp (revision 463257)
+++ kdecore/kapplication.cpp (working copy)
@@ -1615,12 +1615,6 @@
#endif
}
-void KApplication::invokeEditSlot( const char *slot )
-{
- if ( focusWidget() );
- QMetaObject::invokeMethod( focusWidget(), slot );
-}
-
void KApplication::addKipcEventMask(int id)
{
if (id >= 32)
@@ -1943,31 +1937,6 @@
#endif
}
-void KApplication::cut()
-{
- invokeEditSlot( SLOT( cut() ) );
-}
-
-void KApplication::copy()
-{
- invokeEditSlot( SLOT( copy() ) );
-}
-
-void KApplication::paste()
-{
- invokeEditSlot( SLOT( paste() ) );
-}
-
-void KApplication::clear()
-{
- invokeEditSlot( SLOT( clear() ) );
-}
-
-void KApplication::selectAll()
-{
- invokeEditSlot( SLOT( selectAll() ) );
-}
-
QByteArray
KApplication::launcher()
{
Index: kdeui/kmainwindow.h
===================================================================
--- kdeui/kmainwindow.h (revision 463257)
+++ kdeui/kmainwindow.h (working copy)
@@ -641,6 +641,70 @@
// KDE4 remove
virtual void setIcon( const QPixmap & );
+ /**
+ * If the widget with focus provides a cut() slot, call that slot. Thus for a
+ * simple application cut can be implemented as:
+ * \code
+ * createAutomaticCutAction(actionCollection());
+ * \endcode
+ */
+ KAction *createAutomaticCutAction(KActionCollection *collection) const;
+
+ /**
+ * If the widget with focus provides a copy() slot, call that slot. Thus for a
+ * simple application copy can be implemented as:
+ * \code
+ * createAutomaticCopyAction(actionCollection());
+ * \endcode
+ */
+ KAction *createAutomaticCopyAction(KActionCollection *collection) const;
+
+ /**
+ * If the widget with focus provides a paste() slot, call that slot. Thus for a
+ * simple application copy can be implemented as:
+ * \code
+ * createAutomaticPasteAction(actionCollection());
+ * \endcode
+ */
+ KAction *createAutomaticPasteAction(KActionCollection *collection) const;
+
+ /**
+ * If the widget with focus provides a clear() slot, call that slot. Thus for a
+ * simple application clear() can be implemented as:
+ * \code
+ * new KAction( i18n( "Clear" ), "editclear", 0, this, SLOT( clear() ), \
actionCollection(), "clear" ); + * \endcode
+ *
+ * Note that for some widgets, this may not provide the intended bahavior. For
+ * example if you make use of the code above and a KListView has the focus, \
clear() + * will clear all of the items in the list. If this is not the intened \
behavior + * and you want to make use of this slot, you can subclass KListView \
and reimplement + * this slot. For example the following code would implement a \
KListView without this + * behavior:
+ *
+ * \code
+ * class MyListView : public KListView {
+ * Q_OBJECT
+ * public:
+ * MyListView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : \
KListView( parent, name, f ) {} + * virtual ~MyListView() {}
+ * public slots:
+ * virtual void clear() {}
+ * };
+ * \endcode
+ */
+ KAction *createAutomaticClearAction(KActionCollection *collection) const;
+
+ /**
+ * If the widget with focus provides a selectAll() slot, call that slot. Thus \
for a + * simple application select all can be implemented as:
+ * \code
+ * KStdAction::selectAll( this, SLOT( selectAll() ), actionCollection() );
+ * \endcode
+ */
+ KAction *createAutomaticSelectAllAction(KActionCollection *collection) const;
+
+
public slots:
/**
* Show a standard configure toolbar dialog.
@@ -977,6 +1041,13 @@
* List of members of KMainWindow class.
*/
static Q3PtrList<KMainWindow>* mMemberList;
+
+ Q_PRIVATE_SLOT(d, void cut());
+ Q_PRIVATE_SLOT(d, void copy());
+ Q_PRIVATE_SLOT(d, void paste());
+ Q_PRIVATE_SLOT(d, void clear());
+ Q_PRIVATE_SLOT(d, void selectAll());
+
protected:
virtual void virtual_hook( int id, void* data );
private:
Index: kdeui/kmainwindow.cpp
===================================================================
--- kdeui/kmainwindow.cpp (revision 463257)
+++ kdeui/kmainwindow.cpp (working copy)
@@ -65,6 +65,44 @@
class KMainWindowPrivate {
public:
+ /**
+ * This method is used internally to determine which edit slots are implemented
+ * by the widget that has the focus, and to invoke those slots if available.
+ *
+ * @param slot is the slot as returned using the SLOT() macro, for example SLOT( \
cut() ) + *
+ * This method can be used in KApplication subclasses to implement application \
wide + * edit actions not supported by the KApplication class. For example (in \
your subclass): + *
+ * \code
+ * void MyApplication::deselect()
+ * {
+ * invokeEditSlot( SLOT( deselect() ) );
+ * }
+ * \endcode
+ *
+ * Now in your application calls to MyApplication::deselect() will call this \
slot on the + * focused widget if it provides this slot. You can combine this \
with KAction with: + *
+ * \code
+ * KStdAction::deselect( this, SLOT( cut() ), actionCollection() );
+ * \endcode
+ *
+ * @see cut()
+ * @see copy()
+ * @see paste()
+ * @see clear()
+ * @see selectAll()
+ *
+ * @since 3.2
+ */
+ inline void invokeEditSlot( const char *slot );
+ inline void cut(){ invokeEditSlot(SLOT(cut())); };
+ inline void copy(){ invokeEditSlot(SLOT(copy())); };
+ inline void paste(){ invokeEditSlot(SLOT(paste())); };
+ inline void clear(){ invokeEditSlot(SLOT(clear())); };
+ inline void selectAll(){ invokeEditSlot(SLOT(selectAll())); };
+
bool showHelpMenu:1;
bool autoSaveSettings:1;
@@ -1180,6 +1218,36 @@
KXMLGUIClient::virtual_hook( id, data ); }
+KAction *KMainWindow::createAutomaticCutAction(KActionCollection *actionCollection) \
const +{
+ return KStdAction::cut( this, SLOT(cut()), actionCollection );
+}
+KAction *KMainWindow::createAutomaticCopyAction(KActionCollection *actionCollection) \
const +{
+ return KStdAction::copy( this, SLOT(copy()), actionCollection );
+}
+
+KAction *KMainWindow::createAutomaticPasteAction(KActionCollection \
*actionCollection) const +{
+ return KStdAction::paste( this, SLOT(paste()), actionCollection );
+}
+
+KAction *KMainWindow::createAutomaticClearAction(KActionCollection \
*actionCollection) const +{
+ return KStdAction::clear( this, SLOT(clear()), actionCollection );
+}
+
+KAction *KMainWindow::createAutomaticSelectAllAction(KActionCollection \
*actionCollection) const +{
+ return KStdAction::selectAll( this, SLOT(selectAll()), actionCollection );
+}
+
+void KMainWindowPrivate::invokeEditSlot( const char *slot )
+{
+ if ( qApp->focusWidget() );
+ QMetaObject::invokeMethod( qApp->focusWidget(), slot );
+}
+
#include "kmainwindow.moc"
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic