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 "storage/storage_databases.h"
#include "mainwidget.h"
#include "mediaview.h"
#include "media/view/media_view_overlay_widget.h"
#include "mtproto/dc_options.h"
#include "mtproto/mtp_instance.h"
#include "media/player/media_player_instance.h"
@ -129,7 +129,7 @@ void Application::run() {
_window->init();
auto currentGeometry = _window->geometry();
_mediaView = std::make_unique<MediaView>();
_mediaView = std::make_unique<Media::View::OverlayWidget>();
_window->setGeometry(currentGeometry);
QCoreApplication::instance()->installEventFilter(this);

View File

@ -16,7 +16,6 @@ class AuthSessionSettings;
class MainWidget;
class FileUploader;
class Translator;
class MediaView;
class BoxContent;
namespace Storage {
@ -43,6 +42,9 @@ namespace Media {
namespace Audio {
class Instance;
} // namespace Audio
namespace View {
class OverlayWidget;
} // namespace View
} // namespace Media
namespace Lang {
@ -81,7 +83,7 @@ public:
return &_globalShortcutParent;
}
// MediaView interface.
// Media view interface.
void checkMediaViewActivation();
bool hideMediaView();
void showPhoto(not_null<const PhotoOpenClickHandler*> link);
@ -244,7 +246,7 @@ private:
std::unique_ptr<Storage::Databases> _databases;
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::CloudManager> _langCloudManager;
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/connection_box.h"
#include "observer_peer.h"
#include "mediaview.h"
#include "storage/localstorage.h"
#include "apiwrap.h"
#include "settings/settings_intro.h"

View File

@ -232,7 +232,7 @@ void Controller::paintEvent(QPaintEvent *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;

View File

@ -7,24 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/rp_widget.h"
#include "ui/widgets/dropdown_menu.h"
#include "ui/effects/radial_animation.h"
#include "data/data_shared_media.h"
#include "data/data_user_photos.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 {
class PopupMenu;
class LinkButton;
@ -41,13 +30,29 @@ namespace Notify {
struct PeerUpdate;
} // 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
public:
MediaView();
void setVisible(bool visible) override;
OverlayWidget();
void showPhoto(not_null<PhotoData*> photo, HistoryItem *context);
void showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context);
@ -70,27 +75,12 @@ public:
void clearData();
~MediaView();
~OverlayWidget();
// ClickHandlerHost interface
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) 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:
void onHideControls(bool force = false);
@ -135,17 +125,34 @@ private:
OverIcon,
OverVideo,
};
void updateOver(QPoint mpos);
void moveToScreen();
bool moveToNext(int delta);
void preloadData(int delta);
struct Entity {
base::optional_variant<
not_null<PhotoData*>,
not_null<DocumentData*>> data;
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 entityForSharedMedia(int index) const;
Entity entityForCollage(int index) const;
@ -411,3 +418,6 @@ private:
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 "lang/lang_keys.h"
#include "data/data_session.h"
#include "mediaview.h"
#include "auth_session.h"
#include "apiwrap.h"
#include "mainwindow.h"

View File

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

View File

@ -438,6 +438,8 @@
<(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.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.h
<(src_loc)/media/media_audio_capture.cpp
@ -824,8 +826,6 @@
<(src_loc)/mainwidget.h
<(src_loc)/mainwindow.cpp
<(src_loc)/mainwindow.h
<(src_loc)/mediaview.cpp
<(src_loc)/mediaview.h
<(src_loc)/observer_peer.cpp
<(src_loc)/observer_peer.h
<(src_loc)/qt_static_plugins.cpp