File indexing completed on 2024-04-14 04:49:11

0001 /*
0002     This file belong to the KMPlayer project, a movie player plugin for Konqueror
0003     SPDX-FileCopyrightText: 2007 Koos Vriezen <koos.vriezen@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMPLAYER_VIEW_AREA_H
0009 #define KMPLAYER_VIEW_AREA_H
0010 
0011 #include <QWidget>
0012 #include <QAbstractNativeEventFilter>
0013 typedef QWidget QX11EmbedContainer;
0014 #include <QList>
0015 
0016 #include "mediaobject.h"
0017 #include "surface.h"
0018 
0019 class QPaintEngine;
0020 class KActionCollection;
0021 
0022 namespace KMPlayer {
0023 
0024 class View;
0025 class IViewer;
0026 class ViewerAreaPrivate;
0027 class VideoOutput;
0028 
0029 /*
0030  * The area in which the video widget and controlpanel are laid out
0031  */
0032 class KMPLAYERCOMMON_EXPORT ViewArea : public QWidget, public QAbstractNativeEventFilter
0033 {
0034     friend class VideoOutput;
0035     Q_OBJECT
0036 public:
0037     ViewArea(QWidget* parent, View *view, bool paint_bg);
0038     ~ViewArea() override;
0039     KMPLAYERCOMMON_NO_EXPORT bool isFullScreen () const { return m_fullscreen; }
0040     KMPLAYERCOMMON_NO_EXPORT bool isMinimalMode () const { return m_minimal; }
0041     KMPLAYERCOMMON_NO_EXPORT KActionCollection * actionCollection () const { return m_collection; }
0042     KMPLAYERCOMMON_NO_EXPORT QRect topWindowRect () const { return m_topwindow_rect; }
0043     Surface *getSurface(Mrl* mrl) KMPLAYERCOMMON_NO_EXPORT;
0044     void mouseMoved() KMPLAYERCOMMON_NO_EXPORT;
0045     void scheduleRepaint(const IRect& rect) KMPLAYERCOMMON_NO_EXPORT;
0046     ConnectionList* updaters() KMPLAYERCOMMON_NO_EXPORT;
0047     void resizeEvent(QResizeEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0048     void enableUpdaters(bool enable, unsigned int off_time) KMPLAYERCOMMON_NO_EXPORT;
0049     void minimalMode ();
0050     IViewer *createVideoWidget ();
0051     void destroyVideoWidget (IViewer *widget);
0052     void setVideoWidgetVisible (bool show);
0053 Q_SIGNALS:
0054     void fullScreenChanged ();
0055 public Q_SLOTS:
0056     void fullScreen() KMPLAYERCOMMON_NO_EXPORT;
0057     void accelActivated() KMPLAYERCOMMON_NO_EXPORT;
0058     void scale(int) KMPLAYERCOMMON_NO_EXPORT;
0059 protected:
0060     void showEvent(QShowEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0061     void keyPressEvent(QKeyEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0062     void mouseMoveEvent(QMouseEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0063     void mousePressEvent(QMouseEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0064     void mouseDoubleClickEvent(QMouseEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0065     void dragEnterEvent(QDragEnterEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0066     void dropEvent(QDropEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0067     void contextMenuEvent(QContextMenuEvent* e) override KMPLAYERCOMMON_NO_EXPORT;
0068     void paintEvent(QPaintEvent*) override KMPLAYERCOMMON_NO_EXPORT;
0069     void timerEvent(QTimerEvent* e) override KMPLAYERCOMMON_NO_EXPORT;
0070     void closeEvent(QCloseEvent* e) override KMPLAYERCOMMON_NO_EXPORT;
0071     bool nativeEventFilter(const QByteArray& eventType, void * message, long *result) override;
0072     QPaintEngine *paintEngine () const override;
0073 private:
0074     void syncVisual() KMPLAYERCOMMON_NO_EXPORT;
0075     void updateSurfaceBounds() KMPLAYERCOMMON_NO_EXPORT;
0076     void stopTimers() KMPLAYERCOMMON_NO_EXPORT;
0077 
0078     ConnectionList m_updaters;
0079     ViewerAreaPrivate *d;
0080     View * m_view;
0081     KActionCollection * m_collection;
0082     SurfacePtr surface;
0083     IRect m_repaint_rect;
0084     IRect m_update_rect;
0085     QRect m_topwindow_rect;
0086     typedef QList <IViewer *> VideoWidgetList;
0087     VideoWidgetList video_widgets;
0088     int m_mouse_invisible_timer;
0089     int m_repaint_timer;
0090     int m_restore_fullscreen_timer;
0091     bool m_fullscreen;
0092     bool m_minimal;
0093     bool m_updaters_enabled;
0094     bool m_paint_background;
0095 };
0096 
0097 /*
0098  * The video widget
0099  */
0100 class VideoOutput : public QX11EmbedContainer, public IViewer
0101 {
0102     Q_OBJECT
0103 public:
0104     VideoOutput(QWidget* parent, View* view);
0105     ~VideoOutput() override;
0106 
0107     int heightForWidth(int w) const override;
0108 
0109     WindowId windowHandle () override;
0110     WindowId clientHandle () override;
0111     WindowId ownHandle() override;
0112     using QWidget::setGeometry;
0113     void setGeometry (const IRect &rect) override;
0114     void setAspect (float a) override;
0115     float aspect () override { return m_aspect; }
0116     void useIndirectWidget (bool) override;
0117     void setMonitoring(Monitor m) override;
0118     void map() override;
0119     void unmap() override;
0120 
0121     long inputMask () const { return m_input_mask; }
0122     void setBackgroundColor(const QColor& c);
0123     void resetBackgroundColor();
0124     void setCurrentBackgroundColor(const QColor& c);
0125     View * view () const { return m_view; }
0126 
0127     WindowId clientWinId() { return m_client_window; }
0128     void discardClient() {}
0129     void embedded(WindowId handle) override;
0130 public Q_SLOTS:
0131     void fullScreenChanged();
0132 protected:
0133     void resizeEvent(QResizeEvent*) override;
0134     void timerEvent(QTimerEvent*) override;
0135     void dragEnterEvent(QDragEnterEvent*) override;
0136     void dropEvent(QDropEvent*) override;
0137     void contextMenuEvent(QContextMenuEvent* e) override;
0138     //virtual void windowChanged( WId w );
0139 private:
0140     WId m_plain_window;
0141     WId m_client_window;
0142     int resized_timer;
0143     unsigned int m_bgcolor;
0144     float m_aspect;
0145     View * m_view;
0146     long m_input_mask;
0147 };
0148 
0149 } // namespace KMPlayer
0150 
0151 #endif