Use QOpenGLWidget for macOS media viewer overlay.

Also move mediaview to media/view/media_view_overlay_widget.
This commit is contained in:
John Preston 2019-02-12 14:00:47 +03:00
parent 4caf26d069
commit c1a0dad2b7
9 changed files with 205 additions and 191 deletions

View file

@ -32,7 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "observer_peer.h" #include "observer_peer.h"
#include "storage/storage_databases.h" #include "storage/storage_databases.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "mediaview.h" #include "media/view/media_view_overlay_widget.h"
#include "mtproto/dc_options.h" #include "mtproto/dc_options.h"
#include "mtproto/mtp_instance.h" #include "mtproto/mtp_instance.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
@ -129,7 +129,7 @@ void Application::run() {
_window->init(); _window->init();
auto currentGeometry = _window->geometry(); auto currentGeometry = _window->geometry();
_mediaView = std::make_unique<MediaView>(); _mediaView = std::make_unique<Media::View::OverlayWidget>();
_window->setGeometry(currentGeometry); _window->setGeometry(currentGeometry);
QCoreApplication::instance()->installEventFilter(this); QCoreApplication::instance()->installEventFilter(this);

View file

@ -16,7 +16,6 @@ class AuthSessionSettings;
class MainWidget; class MainWidget;
class FileUploader; class FileUploader;
class Translator; class Translator;
class MediaView;
class BoxContent; class BoxContent;
namespace Storage { namespace Storage {
@ -43,6 +42,9 @@ namespace Media {
namespace Audio { namespace Audio {
class Instance; class Instance;
} // namespace Audio } // namespace Audio
namespace View {
class OverlayWidget;
} // namespace View
} // namespace Media } // namespace Media
namespace Lang { namespace Lang {
@ -81,7 +83,7 @@ public:
return &_globalShortcutParent; return &_globalShortcutParent;
} }
// MediaView interface. // Media view interface.
void checkMediaViewActivation(); void checkMediaViewActivation();
bool hideMediaView(); bool hideMediaView();
void showPhoto(not_null<const PhotoOpenClickHandler*> link); void showPhoto(not_null<const PhotoOpenClickHandler*> link);
@ -244,7 +246,7 @@ private:
std::unique_ptr<Storage::Databases> _databases; std::unique_ptr<Storage::Databases> _databases;
std::unique_ptr<MainWindow> _window; std::unique_ptr<MainWindow> _window;
std::unique_ptr<MediaView> _mediaView; std::unique_ptr<Media::View::OverlayWidget> _mediaView;
std::unique_ptr<Lang::Instance> _langpack; std::unique_ptr<Lang::Instance> _langpack;
std::unique_ptr<Lang::CloudManager> _langCloudManager; std::unique_ptr<Lang::CloudManager> _langCloudManager;
std::unique_ptr<Lang::Translator> _translator; std::unique_ptr<Lang::Translator> _translator;

View file

@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/add_contact_box.h" #include "boxes/add_contact_box.h"
#include "boxes/connection_box.h" #include "boxes/connection_box.h"
#include "observer_peer.h" #include "observer_peer.h"
#include "mediaview.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "settings/settings_intro.h" #include "settings/settings_intro.h"

View file

@ -232,7 +232,7 @@ void Controller::paintEvent(QPaintEvent *e) {
} }
void Controller::mousePressEvent(QMouseEvent *e) { void Controller::mousePressEvent(QMouseEvent *e) {
e->accept(); // Don't pass event to the MediaView. e->accept(); // Don't pass event to the Media::View::OverlayWidget.
} }
Controller::~Controller() = default; Controller::~Controller() = default;

View file

@ -7,24 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "ui/rp_widget.h"
#include "ui/widgets/dropdown_menu.h" #include "ui/widgets/dropdown_menu.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
#include "data/data_shared_media.h" #include "data/data_shared_media.h"
#include "data/data_user_photos.h" #include "data/data_user_photos.h"
#include "data/data_web_page.h" #include "data/data_web_page.h"
namespace Media {
namespace Player {
struct TrackState;
} // namespace Player
namespace Clip {
class Controller;
} // namespace Clip
namespace View {
class GroupThumbs;
} // namespace View
} // namespace Media
namespace Ui { namespace Ui {
class PopupMenu; class PopupMenu;
class LinkButton; class LinkButton;
@ -41,13 +30,29 @@ namespace Notify {
struct PeerUpdate; struct PeerUpdate;
} // namespace Notify } // namespace Notify
class MediaView : public TWidget, private base::Subscriber, public ClickHandlerHost {
namespace Media {
namespace Player {
struct TrackState;
} // namespace Player
namespace Clip {
class Controller;
} // namespace Clip
namespace View {
class GroupThumbs;
#if defined Q_OS_MAC && !defined OS_MAC_OLD
using OverlayParent = Ui::RpWidgetWrap<QOpenGLWidget>;
#else // Q_OS_MAC && !OS_MAC_OLD
using OverlayParent = Ui::RpWidget;
#endif // Q_OS_MAC && !OS_MAC_OLD
class OverlayWidget final : public OverlayParent, private base::Subscriber, public ClickHandlerHost {
Q_OBJECT Q_OBJECT
public: public:
MediaView(); OverlayWidget();
void setVisible(bool visible) override;
void showPhoto(not_null<PhotoData*> photo, HistoryItem *context); void showPhoto(not_null<PhotoData*> photo, HistoryItem *context);
void showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context); void showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context);
@ -70,27 +75,12 @@ public:
void clearData(); void clearData();
~MediaView(); ~OverlayWidget();
// ClickHandlerHost interface // ClickHandlerHost interface
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
protected:
void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void touchEvent(QTouchEvent *e);
bool event(QEvent *e) override;
bool eventFilter(QObject *obj, QEvent *e) override;
private slots: private slots:
void onHideControls(bool force = false); void onHideControls(bool force = false);
@ -135,17 +125,34 @@ private:
OverIcon, OverIcon,
OverVideo, OverVideo,
}; };
void updateOver(QPoint mpos);
void moveToScreen();
bool moveToNext(int delta);
void preloadData(int delta);
struct Entity { struct Entity {
base::optional_variant< base::optional_variant<
not_null<PhotoData*>, not_null<PhotoData*>,
not_null<DocumentData*>> data; not_null<DocumentData*>> data;
HistoryItem *item; HistoryItem *item;
}; };
void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void touchEvent(QTouchEvent *e);
bool eventHook(QEvent *e) override;
bool eventFilter(QObject *obj, QEvent *e) override;
void setVisibleHook(bool visible) override;
void updateOver(QPoint mpos);
void moveToScreen();
bool moveToNext(int delta);
void preloadData(int delta);
Entity entityForUserPhotos(int index) const; Entity entityForUserPhotos(int index) const;
Entity entityForSharedMedia(int index) const; Entity entityForSharedMedia(int index) const;
Entity entityForCollage(int index) const; Entity entityForCollage(int index) const;
@ -411,3 +418,6 @@ private:
object_ptr<Ui::RoundButton> _themeCancel = { nullptr }; object_ptr<Ui::RoundButton> _themeCancel = { nullptr };
}; };
} // namespace View
} // namespace Media

View file

@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/sandbox.h" #include "core/sandbox.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "mediaview.h"
#include "auth_session.h" #include "auth_session.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "mainwindow.h" #include "mainwindow.h"

View file

@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h" #include "base/timer.h"
class BoxContent; class BoxContent;
class MediaView;
namespace Window { namespace Window {

View file

@ -438,6 +438,8 @@
<(src_loc)/media/view/media_clip_playback.h <(src_loc)/media/view/media_clip_playback.h
<(src_loc)/media/view/media_view_group_thumbs.cpp <(src_loc)/media/view/media_view_group_thumbs.cpp
<(src_loc)/media/view/media_view_group_thumbs.h <(src_loc)/media/view/media_view_group_thumbs.h
<(src_loc)/media/view/media_view_overlay_widget.cpp
<(src_loc)/media/view/media_view_overlay_widget.h
<(src_loc)/media/media_audio.cpp <(src_loc)/media/media_audio.cpp
<(src_loc)/media/media_audio.h <(src_loc)/media/media_audio.h
<(src_loc)/media/media_audio_capture.cpp <(src_loc)/media/media_audio_capture.cpp
@ -824,8 +826,6 @@
<(src_loc)/mainwidget.h <(src_loc)/mainwidget.h
<(src_loc)/mainwindow.cpp <(src_loc)/mainwindow.cpp
<(src_loc)/mainwindow.h <(src_loc)/mainwindow.h
<(src_loc)/mediaview.cpp
<(src_loc)/mediaview.h
<(src_loc)/observer_peer.cpp <(src_loc)/observer_peer.cpp
<(src_loc)/observer_peer.h <(src_loc)/observer_peer.h
<(src_loc)/qt_static_plugins.cpp <(src_loc)/qt_static_plugins.cpp