File indexing completed on 2024-04-28 07:27:21

0001 /*
0002     SPDX-FileCopyrightText: 2002-2003 Jeff Roush <jeff@mousetool.com>
0003     SPDX-FileCopyrightText: 2003 Olaf Schmidt <ojschmidt@kde.org>
0004     SPDX-FileCopyrightText: 2003 Gunnar Schmi Dt <gunnar@schmi-dt.de>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMOUSETOOL_H
0009 #define KMOUSETOOL_H
0010 
0011 #include <QLabel>
0012 #include <QTimerEvent>
0013 #include <QWidget>
0014 
0015 #include "mtstroke.h"
0016 #include "ui_kmousetoolui.h"
0017 #include <KStatusNotifierItem>
0018 
0019 class QLabel;
0020 class QAction;
0021 class QMediaPlayer;
0022 class KAudioPlayer;
0023 class KHelpMenu;
0024 class KMouseToolTray;
0025 
0026 /**
0027  * KMouseTool is the base class of the project
0028  *
0029  * It is the main widget for the dialog
0030  *
0031  */
0032 
0033 class KMouseTool : public QWidget, public Ui::KMouseToolUI
0034 {
0035     Q_OBJECT
0036 
0037 private:
0038     MTStroke mStroke;
0039 
0040     // boolean flags to keep track of program states
0041     int mMouse_is_down;
0042     int mContinue_timer;
0043     int mTick_count;
0044     int mDwell_time;
0045     int mDrag_time;
0046     int mMax_ticks;
0047     int mMin_movement;
0048     bool mSmart_drag_on;
0049     bool mPlaySound;
0050     bool mMousetool_is_running;
0051     bool mMousetool_just_started;
0052     bool mMoving;
0053     bool mStrokesEnabled;
0054 
0055     QString mAutostartdirname;
0056     QString mAppfilename;
0057     QString mSoundFileName;
0058     QMediaPlayer *mPlayer = nullptr;
0059     KMouseToolTray *mTrayIcon = nullptr;
0060 
0061     KHelpMenu *mHelpMenu = nullptr;
0062     QPushButton *mButtonQuit = nullptr;
0063 
0064     /**
0065      * Initialize all variables
0066      */
0067     void init_vars();
0068 
0069     /**
0070      * Take care of details of playing .wav file
0071      *
0072      * Currently uses KAudioPlayer::play(), which has an annoying delay.
0073      *
0074      * The solution seems to be to use MCOP, but I haven't been able to get that to work yet.
0075      */
0076     void playTickSound();
0077 
0078     /**
0079      * Load state of program from "kmousetool.rc" in the user's local .kde folder,
0080      *
0081      */
0082     void loadOptions();
0083 
0084     /**
0085      * Save state of program under the user's local .kde folder,
0086      * in a file named "kmousetool.rc"
0087      *
0088      */
0089     void saveOptions();
0090 
0091     /**
0092      * This function changes text on button depending on
0093      * state of time (either "start", or "stop").
0094      **/
0095     void updateStartStopText();
0096 
0097     /**
0098      * Returns true if the current values in the settings window are different
0099      * from the settings currently used
0100      **/
0101     bool newSettings();
0102 
0103     /**
0104      * Returns true if the current values in the settings window are identical
0105      * with the default settings
0106      **/
0107     bool defaultSettings();
0108 
0109     /**
0110      * Resets the values in the settings window to the settings currently used
0111      **/
0112     void resetSettings();
0113 
0114     /**
0115      * Sets the values in the settings window to the default settings
0116      **/
0117     void setDefaultSettings();
0118 
0119     /**
0120      * Applies the current values in the settings window
0121      **/
0122     bool applySettings();
0123 
0124     bool isAutostart();
0125     void setAutostart(bool start);
0126 
0127 public Q_SLOTS:
0128     /**
0129      * This slot is called whenever a value in the settings window was changed.
0130      * It enabled and disables the three buttons "Defaults", "Reset" and "Apply".
0131      **/
0132     void settingsChanged();
0133 
0134     void startStopSelected();
0135 
0136     void defaultSelected();
0137     void resetSelected();
0138     void applySelected();
0139 
0140     void helpSelected();
0141     void closeSelected();
0142     void quitSelected();
0143 
0144     void aboutSelected();
0145     void configureSelected();
0146 
0147 public:
0148     /**
0149      * This function runs the show; it is called once every
0150      * 1/10 second.
0151      *
0152      * It checks to see if SmartDrag is on, and compares the
0153      * current mouse position to its previous position to see
0154      * whether to send a down click, and up click, or wait.
0155      */
0156     void timerEvent(QTimerEvent *e) override;
0157 
0158     /**
0159      * This generates a normal click event --
0160      * down, up, or down-up, depending on smart-drag settings and current state
0161      */
0162     void normalClick();
0163 
0164     /**
0165      *  construtor
0166      */
0167     explicit KMouseTool(QWidget *parent = nullptr, const char *name = nullptr);
0168 
0169     /** destructor */
0170     ~KMouseTool() override;
0171 };
0172 
0173 class KMouseToolTray : public KStatusNotifierItem
0174 {
0175     Q_OBJECT
0176 public:
0177     explicit KMouseToolTray(QWidget *parent = nullptr);
0178     ~KMouseToolTray() override;
0179 
0180     void updateStartStopText(bool mousetool_is_running);
0181 Q_SIGNALS:
0182     void startStopSelected();
0183     void configureSelected();
0184     void aboutSelected();
0185     void helpSelected();
0186 
0187 private:
0188     QAction *mStartStopAct = nullptr;
0189 };
0190 #endif