Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
3.1 KB
Raw Blame
/* This file is part of the KDE project
 * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <[email protected]>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef KIS_INPUTMANAGER_H
#define KIS_INPUTMANAGER_H

#include <QObject>
#include <QPointer>

#include <kritaui_export.h>

#include <kis_tool_proxy.h>

class QPointF;
class QTouchEvent;
class KisCanvas2;
class KisToolInvocationAction;
class KoToolManager;
/**
 * \brief Central object to manage canvas input.
 *
 * The Input Manager class manages all canvas input. It is created
 * by KisCanvas2 and processes all events related to input sent to the
 * canvas.
 *
 * The Input Manager keeps track of a set of actions and a set of
 * shortcuts. The actions are pre-defined while the shortcuts are
 * set from configuration.
 *
 * For each event, it will try to determine if there is a shortcut that
 * matches the input. It will then activate this action and pass all
 * consecutive events on to this action.
 *
 * \sa KisAbstractInputAction
 */
class KRITAUI_EXPORT KisInputManager : public QObject
{
    Q_OBJECT

public:
    /**
     * Constructor.
     */
    KisInputManager(QObject *parent, KoToolManager *toolManager);

    /**
     * Destructor.
     */
    ~KisInputManager() override;

    void addTrackedCanvas(KisCanvas2 *canvas);
    void removeTrackedCanvas(KisCanvas2 *canvas);

    void registerPopupWidget(KisPopupWidgetInterface *popupWidget);

    void toggleTabletLogger();

    /**
     * Installs the input manager as an event filter for \p receiver.
     * Please note that KisInputManager is supposed to handle events
     * for a single receiver only. This is defined by the fact that it
     * resends some of the events back through the Qt's queue to the
     * receiver. That is why the input manager will assert when it gets
     * an event with wrong destination.
     */
    void setupAsEventFilter(QObject *receiver);

    /**
     * Event filter method. Overridden from QObject.
     */
    bool eventFilter(QObject* object, QEvent* event ) override;

    /**
     * @brief attachPriorityEventFilter
     * @param filter
     * @param priority
     */
    void attachPriorityEventFilter(QObject *filter, int priority = 0);

    /**
     * @brief detachPriorityEventFilter
     * @param filter
     */
    void detachPriorityEventFilter(QObject *filter);

    /**
     * Return the canvas this input manager is associated with.
     */
    KisCanvas2 *canvas() const;

    /**
     * The tool proxy of the current application.
     */
    QPointer<KisToolProxy> toolProxy() const;

    /**
     * The built-in action that forwards primary strokes to the active tool.
     */
    KisToolInvocationAction *defaultInputAction() const;

private Q_SLOTS:
    void slotAboutToChangeTool();
    void slotToolChanged();
    void slotTextModeChanged();
    void profileChanged();
    void slotCompressedMoveEvent();
    void deregisterPopupWidget();
    void slotConfigChanged();

private:
    bool eventFilterImpl(QEvent * event);
    template <class Event>
        bool compressMoveEventCommon(Event *event);

private:
    class Private;
    Private* const d;
};

#endif // KIS_INPUTMANAGER_H