StelActionMgr.hpp   StelActionMgr.hpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _STELACTIONMGR_HPP_ #ifndef _STELACTIONMGR_HPP_
#define _STELACTIONMGR_HPP_ #define _STELACTIONMGR_HPP_
#include <QObject> #include "StelPropertyMgr.hpp"
#include <QKeySequence> #include <QKeySequence>
#include <QList> #include <QList>
//! Wrapper around an argumentless QObject slot or a bool Q_PROPERTY with W
RITE method,
//! allowing the slot to be called/property to be toggled using this action
object.
//! The action object can be identified by a unique string, and found throu
gh StelActionMgr::findAction.
//! Use StelActionMgr::addAction to define a new action.
//! In StelModule subclasses, one can also use StelModule::addAction for co
nvenience.
//!
//! StelAction objects are intended for user interaction. They automaticall
y show up in the hotkey configuration dialog
//! (ShortcutsDialog), and can be bound to interface buttons (StelButton).
//!
//! StelAction internally uses a StelProperty, if connected to a property.
//! A new StelProperty with the name of the action is registered automatica
lly in this case.
//! A NOTIFY signal should be provided, though not strictly necessary, it i
s really recommended.
//! @note If you want to have a globally accessible reference to arbitrary
Q_PROPERTY instances (not just bool),
//! or don't want to expose the property to the user you could use a StelPr
operty directly registered through the StelPropertyMgr instead.
//! @see StelActionMgr, StelProperty
class StelAction : public QObject class StelAction : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
friend class StelActionMgr; //! When the StelAction is @ref checkable, this may be used to get/s
et the current value.
//! Note that the @ref toggled signal may not be emitted on all chan
ges of the connected property
//! @warning If used on a non-checkable action, the program may cras
h.
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggl ed) Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggl ed)
//! If this is true, this StelAction can be toggled.
//! Don't use this constructor, this is just there to ease the migra //! This is the case when connected to a boolean Q_PROPERTY.
tion from QAction. //! This means the @ref checked property as well as the toggle() fun
StelAction(QObject *parent) ction may be used
: QObject(parent) //! If false, the StelAction represents a simple argumentless slot c
, checkable(false) all. Using @ref checked or toggle() may
, checked(false) //! result in an error.
, global(false) Q_PROPERTY(bool checkable READ isCheckable)
, target(NULL)
, property(NULL) //! @see checkable
#ifndef USE_QUICKVIEW bool isCheckable() const {return boolProperty;}
, qAction(NULL) //! @see checked
#endif bool isChecked() const {return boolProperty ? boolProperty->getValue
{} ().toBool() : false; }
StelAction(const QString& actionId,
const QString& groupId,
const QString& text,
const QString& primaryKey="",
const QString& altKey="",
bool global=false);
//! Connect the action to an object property or slot.
//! @param slot A property or a slot name. The slot can either have
the signature `func()`, and in that
//! case the action is made not checkable, or have the signature `fu
nc(bool)` and in that case the action
//! is made checkable. When linked to a property the action is alwa
ys made checkable.
void connectToObject(QObject* obj, const char* slot);
//! Don't use setCheckable, connectToObject can automatically determ
ine if the action is checkable or not.
//! This is just there to ease the migration from QAction.
void setCheckable(bool value) {checkable = value; emit changed();}
bool isCheckable() const {return checkable;}
bool isChecked() const {return checked;}
bool isGlobal() const {return global;} bool isGlobal() const {return global;}
//! Defines the key-combination used to call this action
void setShortcut(const QString& key); void setShortcut(const QString& key);
//! Defines an alternative key-combination
void setAltShortcut(const QString& key); void setAltShortcut(const QString& key);
QKeySequence::SequenceMatch matches(const QKeySequence& seq) const; QKeySequence::SequenceMatch matches(const QKeySequence& seq) const;
//! The ID of this action. Must be unique.
QString getId() const {return objectName();} QString getId() const {return objectName();}
QString getGroup() const {return group;} QString getGroup() const {return group;}
const QKeySequence getShortcut() const {return keySequence;} const QKeySequence getShortcut() const {return keySequence;}
const QKeySequence getAltShortcut() const {return altKeySequence;} const QKeySequence getAltShortcut() const {return altKeySequence;}
QString getText() const; QString getText() const;
void setText(const QString& value) {text = value; emit changed();} void setText(const QString& value) {text = value; emit changed();}
signals: signals:
//! Emitted when the boolean state of this StelAction changes.
//! When the action is connected to a StelProperty,
//! this is equivalent to the StelProperty::valueChanged signal.
//! In the other cases, this state may not always be emitted correct
ly
//! (i.e. when the state changes through other mechanisms than StelA
ction)
void toggled(bool); void toggled(bool);
//! Emitted after an argumentless slot has been called
void triggered(); void triggered();
//! Emitted when additional data associated with this action changed (i.e. shortcuts, text,...)
void changed(); void changed();
public slots: public slots:
//! @see checked
//! @warning If used on a non-checkable action, the program may cras
h.
void setChecked(bool); void setChecked(bool);
//! If the action is @ref checkable, toggle() is called.
//! Otherwise, the connected slot is invoked.
void trigger(); void trigger();
//! If the action is @ref checkable, this toggles the value of
//! the connected boolean property.
//! @warning If used on a non-checkable action, the program may cras
h.
void toggle(); void toggle();
private slots: private slots:
void propertyChanged(bool); void propertyChanged(bool);
private: private:
bool checkable; friend class StelActionMgr;
bool checked;
//! Constructor is used by StelActionMgr
StelAction(const QString& actionId,
const QString& groupId,
const QString& text,
const QString& primaryKey="",
const QString& altKey="",
bool global=false);
//! Connect the action to an object property or slot.
//! @param slot A property or a slot name. The slot can either have
the signature `func()`, and in that
//! case the action is made not checkable, or have the signature `fu
nc(bool)` and in that case the action
//! is made checkable. When linked to a property the action is alwa
ys made checkable.
void connectToObject(QObject* target, const char* slot);
QString group; QString group;
QString text; QString text;
bool global; bool global;
QKeySequence keySequence; QKeySequence keySequence;
QKeySequence altKeySequence; QKeySequence altKeySequence;
const QKeySequence defaultKeySequence; const QKeySequence defaultKeySequence;
const QKeySequence defaultAltKeySequence; const QKeySequence defaultAltKeySequence;
QObject* target; QObject* target;
const char* property; //If the StelAction is connected to a boolean property with a NOTIFY
signal, a StelProperty is used for the connection
StelProperty* boolProperty;
QMetaMethod slot;
// Currently, there is no proper way to handle shortcuts with non la tin // Currently, there is no proper way to handle shortcuts with non la tin
// keyboards layouts. So for the moment, if we don't use QuickView, we // keyboards layouts. So for the moment, if we don't use QuickView, we
// create a QAction added to the main view that will trigger the // create a QAction added to the main view that will trigger the
// StelAction when the shortcut is typed. // StelAction when the shortcut is typed.
#ifndef USE_QUICKVIEW #ifndef USE_QUICKVIEW
private slots: private slots:
void onChanged(); void onChanged();
private: private:
class QAction* qAction; class QAction* qAction;
#endif #endif
}; };
//! Manager for StelAction instances. Allows registration of new actions, a nd finding an existing one by name.
class StelActionMgr : public QObject class StelActionMgr : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
StelActionMgr(); StelActionMgr();
~StelActionMgr(); ~StelActionMgr();
//! Create and add a new StelAction, connected to an object property or slot. //! Create and add a new StelAction, connected to an object property or slot.
//! @param id Global identifier. //! @param id Global identifier.
//! @param groupId Group identifier. //! @param groupId Group identifier.
//! @param text Short human-readable description in English. //! @param text Short human-readable description in English.
//! @param shortcut Default shortcut.
//! @param target The QObject the action is linked to. //! @param target The QObject the action is linked to.
//! @param slot The target slot or property that the action will tri gger. //! @param slot The target slot or property that the action will tri gger.
//! Either a slot name of the form 'func()' and in that case the //! Either a slot name of the form 'func()' and in that case the
//! action is made non checkable, a slot name of the for m //! action is made non checkable, a slot name of the for m
//! 'func(bool)' and in that case the action is made che ckable, //! 'func(bool)' and in that case the action is made che ckable,
//! or a property name and in that case the action is ma de //! or a property name and in that case the action is ma de
//! checkable. //! checkable.
//! @param shortcut Default shortcut/key combination for this action
//! @param altShortcut Alternative shortcut
//! @param global determines QAction shortcut context (not necessary
anymore?)
StelAction* addAction(const QString& id, const QString& groupId, con st QString& text, StelAction* addAction(const QString& id, const QString& groupId, con st QString& text,
QObject* target, const cha r* slot, QObject* target, const cha r* slot,
const QString& shortcut="" , const QString& altShortcut="", const QString& shortcut="" , const QString& altShortcut="",
bool global=false); bool global=false);
StelAction* findAction(const QString& id); StelAction* findAction(const QString& id);
bool pushKey(int key, bool global=false); bool pushKey(int key, bool global=false);
//! Returns a list of all current StelAction groups
QStringList getGroupList() const; QStringList getGroupList() const;
//! Returns all StelActions in the specified group
QList<StelAction*> getActionList(const QString& group) const; QList<StelAction*> getActionList(const QString& group) const;
//! Returns all registered StelActions
QList<StelAction*> getActionList() const;
//! Save current shortcuts to file. //! Save current shortcuts to file.
void saveShortcuts(); void saveShortcuts();
//! Restore the default shortcuts combinations //! Restore the default shortcuts combinations
void restoreDefaultShortcuts(); void restoreDefaultShortcuts();
signals:
//! Emitted when any action registered with this StelActionMgr is to
ggled
//! @param id The id of the action that was toggled
//! @param value The new value of the action
void actionToggled(const QString& id, bool value);
public slots: public slots:
//! Enable/disable all actions of application. //! Enable/disable all actions of application.
//! need for editing shortcuts without trigging any actions //! need for editing shortcuts without trigging any actions
//! @todo find out if this is really necessary and why. //! @todo find out if this is really necessary and why.
void setAllActionsEnabled(bool value) {actionsEnabled = value;} void setAllActionsEnabled(bool value) {actionsEnabled = value;}
private slots:
void onStelActionToggled(bool val);
private: private:
bool actionsEnabled; bool actionsEnabled;
QList<int> keySequence; QList<int> keySequence;
}; };
#endif // _STELACTIONMGR_HPP_ #endif // _STELACTIONMGR_HPP_
 End of changes. 24 change blocks. 
42 lines changed or deleted 109 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/