util.h 3.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
    Copyright 2011-2012 Heikki Holstila <heikki.holstila@gmail.com>

    This file is part of FingerTerm.

    FingerTerm is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    FingerTerm is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FingerTerm.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef UTIL_H
#define UTIL_H

#include <QtCore>

class Terminal;
class MainWindow;
class TextRender;
John Brooks's avatar
John Brooks committed
28
class QQuickView;
29 30 31 32 33 34 35

class Util : public QObject
{
    Q_OBJECT
public:
    explicit Util(QSettings* settings, QObject *parent = 0);
    virtual ~Util();
John Brooks's avatar
John Brooks committed
36
    void setWindow(QQuickView* win);
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    void setWindowTitle(QString title);
    Q_INVOKABLE QString currentWindowTitle();
    void setTerm(Terminal* term) { iTerm = term; }
    void setRenderer(TextRender* r) { iRenderer = r; }

    Q_INVOKABLE void windowMinimize();
    Q_INVOKABLE void openNewWindow();
    Q_INVOKABLE void updateSwipeLock(bool suggestedState);

    Q_INVOKABLE QString versionString();
    Q_INVOKABLE QString configPath();
    Q_INVOKABLE QVariant settingsValue(QString key);
    Q_INVOKABLE void setSettingsValue(QString key, QVariant value);

    Q_INVOKABLE int uiFontSize();

    Q_INVOKABLE void keyPressFeedback();
    Q_INVOKABLE void keyReleaseFeedback();
    Q_INVOKABLE void notifyText(QString text);

    Q_INVOKABLE void copyTextToClipboard(QString str);
    Q_INVOKABLE bool canPaste();
    Q_INVOKABLE bool terminalHasSelection();

    void bellAlert();
    void selectionFinished();

    bool allowGestures() { return iAllowGestures; }
    void setAllowGestures(bool a) { if(iAllowGestures!=a) { iAllowGestures=a; emit allowGesturesChanged(); } }

    Q_PROPERTY(bool allowGestures READ allowGestures WRITE setAllowGestures NOTIFY allowGesturesChanged)

69 70
    static bool charIsHexDigit(QChar ch);

71 72
public slots:
    void onMainWinFocusChanged(bool in);
73 74 75
    void mousePress(float eventX, float eventY);
    void mouseMove(float eventX, float eventY);
    void mouseRelease(float eventX, float eventY);
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

signals:
    void visualBell();
    void allowGesturesChanged();
    void gestureNotify(QString msg);
    void clipboardOrSelectionChanged();
    void windowTitleChanged();

private:
    Q_DISABLE_COPY(Util)
    enum PanGesture { PanNone, PanLeft, PanRight, PanUp, PanDown };

    bool swipeModeSet;
    bool swipeAllowed;

91 92 93 94 95 96 97 98
    /**
     * Scroll the back buffer on drag.
     *
     * @param now The current position
     * @param last The last position (or start position)
     * @return The new value for last (modified by any consumed offset)
     **/
    QPointF scrollBackBuffer(QPointF now, QPointF last);
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    void doGesture(PanGesture gesture);
    void clearNotifications();
    void selectionHelper(QPointF scenePos);

    QPointF dragOrigin;

    bool iAllowGestures;
    bool newSelection;

    QString iCurrentWinTitle;

    QSettings* iSettings;
    MainWindow* iWindow;
    Terminal* iTerm;
    TextRender* iRenderer;
};

#endif // UTIL_H