Subversion Repositories tpanel

Rev

Rev 23 | Blame | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */
#ifndef __TQTMAIN_H__
#define __TQTMAIN_H__

#include <QMainWindow>
#include <QMetaType>

#include "tpagemanager.h"
#include "tobject.h"
#include "terror.h"

extern bool prg_stopped;

QT_BEGIN_NAMESPACE
class QAction;
class QMenu;
class QSessionManager;
class QLabel;
class QWidget;
class QByteArray;
class QMouseEvent;
class QMoveEvent;
class QEvent;
class TQtSettings;
QT_END_NAMESPACE

Q_DECLARE_METATYPE(size_t)

int qtmain(int argc, char **argv, TPageManager *pmanager);

class MainWindow : public QMainWindow, TObject
{
    Q_OBJECT

    public:
        MainWindow();
        void setConfigFile(const std::string& file) { mFileConfig = file; }
        void setSetChange(bool state) { settingsChanged = state; }

    signals:
        void sigDisplayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
        void sigSetPage(ulong handle, int width, int height);
        void sigSetSubPage(ulong handle, int left, int top, int width, int height);
        void sigSetBackground(ulong handle, QByteArray image, size_t rowBytes, ulong color);
        void sigSetText(ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, Button::TEXT_ORIENTATION ori, Button::TEXT_EFFECT effect, bool ww);
        void sigDropPage(ulong handle);
        void sigDropSubPage(ulong handle);
        void sigPlayVideo(ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw);

    protected:
        void closeEvent(QCloseEvent *event) override;
        void mousePressEvent(QMouseEvent* event) override;
        void mouseReleaseEvent(QMouseEvent* event) override;
        bool eventFilter(QObject *obj, QEvent *ev) override;

    private slots:
        void settings();
        void about();
#ifndef QT_NO_SESSIONMANAGER
        void commitData(QSessionManager &);
#endif
        void displayButton(ulong handle, ulong parent, QByteArray buffer, int width, int height, int pixline, int left, int top);
        void setPage(ulong handle, int width, int height);
        void setSubPage(ulong hanlde, int left, int top, int width, int height);
        void setBackground(ulong handle, QByteArray image, size_t rowBytes, ulong color);
        void setText(ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, Button::TEXT_ORIENTATION ori, Button::TEXT_EFFECT effect, bool ww);
        void dropPage(ulong handle);
        void dropSubPage(ulong handle);
        void playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw);
        void appStateChanged(Qt::ApplicationState state);

    private:
        void createActions();
        void writeSettings();
        void removeFromShowList(ulong handle);
        void playShowList();

        void _displayButton(ulong handle, ulong parent, unsigned char* buffer, int width, int height, int pixline, int left, int top);
        void _setPage(ulong handle, int width, int height);
        void _setSubPage(ulong handle, int left, int top, int width, int height);
        void _setBackground(ulong handle, unsigned char *image, size_t size, size_t rowBytes, ulong color);
        void _setText(ulong handle, const std::string& text, const std::string& font, const std::string& family, int size, int x, int y, ulong color, ulong effectColor, FONT_STYLE style, Button::TEXT_ORIENTATION ori, Button::TEXT_EFFECT effect, bool ww);
        void _dropPage(ulong handle);
        void _dropSubPage(ulong handle);
        void _playVideo(ulong handle, ulong parent, int left, int top, int width, int height, const std::string& url, const std::string& user, const std::string& pw);

        TQtSettings *mSettings{nullptr};    // The pointer to the settings dialog
        bool settingsChanged{false};        // true = settings have changed
        QWidget *mBackground{nullptr};      // The background of the visible page
        std::string mVideoURL;              // If the button is a video, this is the URL where it plays from.
        std::string mFileConfig;            // Path and file name of the config file
        bool mHasFocus{true};               // If this is FALSE, no output to sceen is allowed.
        std::map<ulong, QWidget *> mToShow; // List of widgets to show after focus is restored
};

#endif