From bbd35238daf6ca1402c83931c456f5c3ff02d88b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 29 Jan 2020 18:02:15 +0300 Subject: [PATCH 1/7] Don't force floating panel. In case of StaysOnTop windows it looks like it is floating already. But in case of manually setting floating here it has a strange bug with non-activatable always on top tool window (picture-in-picture). When first time shown it doesn't act as a stays-on-top window, if you click on another app it is shown above the PiP. Only if you activate the main window once more the PiP will become stays-on-top window. This way it works from the first show. --- ui/platform/mac/ui_utility_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/platform/mac/ui_utility_mac.mm b/ui/platform/mac/ui_utility_mac.mm index 76d986d..9166f01 100644 --- a/ui/platform/mac/ui_utility_mac.mm +++ b/ui/platform/mac/ui_utility_mac.mm @@ -43,8 +43,8 @@ void InitOnTopPanel(not_null panel) { auto platformPanel = static_cast(platformWindow); [platformPanel setLevel:NSPopUpMenuWindowLevel]; [platformPanel setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorFullScreenAuxiliary|NSWindowCollectionBehaviorIgnoresCycle]; - [platformPanel setFloatingPanel:YES]; [platformPanel setHidesOnDeactivate:NO]; + //[platformPanel setFloatingPanel:YES]; Integration::Instance().activationFromTopPanel(); } From 33ea14969edfbe2546726d82925a1a66ae49310e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 29 Jan 2020 18:54:25 +0300 Subject: [PATCH 2/7] Use StartTranslucentPaint only on OpenGL widgets on macOS. --- ui/platform/linux/ui_utility_linux.h | 2 +- ui/platform/mac/ui_utility_mac.mm | 8 ++++---- ui/platform/ui_platform_utility.h | 2 +- ui/platform/win/ui_utility_win.cpp | 2 ++ ui/platform/win/ui_utility_win.h | 2 +- ui/widgets/popup_menu.cpp | 4 ---- ui/widgets/tooltip.cpp | 2 -- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ui/platform/linux/ui_utility_linux.h b/ui/platform/linux/ui_utility_linux.h index c2f49dc..73bfff9 100644 --- a/ui/platform/linux/ui_utility_linux.h +++ b/ui/platform/linux/ui_utility_linux.h @@ -12,7 +12,7 @@ class QPaintEvent; namespace Ui { namespace Platform { -inline void StartTranslucentPaint(QPainter &p, QPaintEvent *e) { +inline void StartTranslucentPaint(QPainter &p, gsl::span rects) { } inline void InitOnTopPanel(not_null panel) { diff --git a/ui/platform/mac/ui_utility_mac.mm b/ui/platform/mac/ui_utility_mac.mm index 9166f01..3cac656 100644 --- a/ui/platform/mac/ui_utility_mac.mm +++ b/ui/platform/mac/ui_utility_mac.mm @@ -67,12 +67,12 @@ void ReInitOnTopPanel(not_null panel) { [platformPanel setCollectionBehavior:newBehavior]; } -void StartTranslucentPaint(QPainter &p, QPaintEvent *e) { -#ifdef OS_MAC_OLD +void StartTranslucentPaint(QPainter &p, gsl::span rects) { p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(e->rect(), Qt::transparent); + for (const auto &r : rects) { + p.fillRect(r, Qt::transparent); + } p.setCompositionMode(QPainter::CompositionMode_SourceOver); -#endif // OS_MAC_OLD } void ShowOverAll(not_null widget, bool canFocus) { diff --git a/ui/platform/ui_platform_utility.h b/ui/platform/ui_platform_utility.h index dec7e12..4398ed7 100644 --- a/ui/platform/ui_platform_utility.h +++ b/ui/platform/ui_platform_utility.h @@ -16,7 +16,7 @@ namespace Platform { [[nodiscard]] bool IsApplicationActive(); [[nodiscard]] bool TranslucentWindowsSupported(QPoint globalPosition); -void StartTranslucentPaint(QPainter &p, QPaintEvent *e); +void StartTranslucentPaint(QPainter &p, gsl::span rects); void InitOnTopPanel(not_null panel); void DeInitOnTopPanel(not_null panel); diff --git a/ui/platform/win/ui_utility_win.cpp b/ui/platform/win/ui_utility_win.cpp index b9ddcbd..9187e50 100644 --- a/ui/platform/win/ui_utility_win.cpp +++ b/ui/platform/win/ui_utility_win.cpp @@ -30,6 +30,8 @@ void UpdateOverlayed(not_null widget) { } void IgnoreAllActivation(not_null widget) { + widget->createWinId(); + const auto handle = reinterpret_cast(widget->winId()); Assert(handle != nullptr); diff --git a/ui/platform/win/ui_utility_win.h b/ui/platform/win/ui_utility_win.h index 091ba4a..dcd82b2 100644 --- a/ui/platform/win/ui_utility_win.h +++ b/ui/platform/win/ui_utility_win.h @@ -27,7 +27,7 @@ inline void DeInitOnTopPanel(not_null panel) { inline void ReInitOnTopPanel(not_null panel) { } -inline void StartTranslucentPaint(QPainter &p, QPaintEvent *e) { +inline void StartTranslucentPaint(QPainter &p, gsl::span rects) { } inline void ShowOverAll(not_null widget, bool canFocus) { diff --git a/ui/widgets/popup_menu.cpp b/ui/widgets/popup_menu.cpp index 64ef28b..dc472f2 100644 --- a/ui/widgets/popup_menu.cpp +++ b/ui/widgets/popup_menu.cpp @@ -121,10 +121,6 @@ const std::vector> &PopupMenu::actions() const { void PopupMenu::paintEvent(QPaintEvent *e) { QPainter p(this); - if (_useTransparency) { - Platform::StartTranslucentPaint(p, e); - } - if (_a_show.animating()) { if (auto opacity = _a_opacity.value(_hiding ? 0. : 1.)) { _showAnimation->paintFrame(p, 0, 0, width(), _a_show.value(1.), opacity); diff --git a/ui/widgets/tooltip.cpp b/ui/widgets/tooltip.cpp index 5841e8a..04d0b95 100644 --- a/ui/widgets/tooltip.cpp +++ b/ui/widgets/tooltip.cpp @@ -132,8 +132,6 @@ void Tooltip::paintEvent(QPaintEvent *e) { Painter p(this); if (_useTransparency) { - Platform::StartTranslucentPaint(p, e); - p.setPen(_st->textBorder); p.setBrush(_st->textBg); PainterHighQualityEnabler hq(p); From 0ec26f2e106db75ed60cd19ff0c20212979b8f3f Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 31 Jan 2020 12:54:25 +0300 Subject: [PATCH 3/7] Add new colors for video player. --- ui/colors.palette | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/colors.palette b/ui/colors.palette index 3796680..7e154c3 100644 --- a/ui/colors.palette +++ b/ui/colors.palette @@ -521,6 +521,14 @@ mediaviewPlaybackInactiveOver: #474747; // video playback progress upcoming (not mediaviewPlaybackProgressFg: #ffffffc7; // video playback progress text mediaviewPlaybackIconFg: mediaviewPlaybackActive; // video playback controls icon mediaviewPlaybackIconFgOver: mediaviewPlaybackActiveOver; // video playback controls icon with mouse over +mediaviewPlaybackIconRipple: #ffffff14; // video playback controls ripple effect + +mediaviewPipControlsFg: #ffffffd9; // picture-in-picture controls +mediaviewPipControlsFgOver: #ffffff; // picture-in-picture controls with mouse over +mediaviewPipFade: #00000095; // picture-in-picture gradient fade controls background +mediaviewPipPlaybackActive: #ffffffda; // picture-in-picture playback progress already played part +mediaviewPipPlaybackInactive: #ffffff26; // picture-in-picture playback progress upcoming (not played yet) part + mediaviewTransparentBg: #ffffff; // transparent filling part (when viewing a transparent .png file in Media Viewer) mediaviewTransparentFg: #cccccc; // another transparent filling part From 18ba60ec86f1494d994ce507bb3e43ebe1766c20 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 31 Jan 2020 15:11:56 +0300 Subject: [PATCH 4/7] Support more options for popup menu. --- ui/widgets/menu.cpp | 4 +++- ui/widgets/popup_menu.cpp | 30 +++++++++++++++++++++++++----- ui/widgets/popup_menu.h | 2 ++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ui/widgets/menu.cpp b/ui/widgets/menu.cpp index c9ed185..2597c47 100644 --- a/ui/widgets/menu.cpp +++ b/ui/widgets/menu.cpp @@ -90,7 +90,9 @@ void Menu::init() { setMouseTracking(true); - setAttribute(Qt::WA_OpaquePaintEvent); + if (_st.itemBg->c.alpha() == 255) { + setAttribute(Qt::WA_OpaquePaintEvent); + } } not_null Menu::addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon, const style::icon *iconOver) { diff --git a/ui/widgets/popup_menu.cpp b/ui/widgets/popup_menu.cpp index dc472f2..164f8af 100644 --- a/ui/widgets/popup_menu.cpp +++ b/ui/widgets/popup_menu.cpp @@ -300,7 +300,11 @@ void PopupMenu::childHiding(PopupMenu *child) { } void PopupMenu::setOrigin(PanelAnimation::Origin origin) { - _origin = origin; + _origin = _forcedOrigin.value_or(origin); +} + +void PopupMenu::setForcedOrigin(PanelAnimation::Origin origin) { + _forcedOrigin = origin; } void PopupMenu::showAnimated(PanelAnimation::Origin origin) { @@ -457,14 +461,28 @@ void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource sou } _parent = parent; - auto origin = PanelAnimation::Origin::TopLeft; + using Origin = PanelAnimation::Origin; + auto origin = Origin::TopLeft; + const auto forceLeft = _forcedOrigin + && (*_forcedOrigin == Origin::TopLeft + || *_forcedOrigin == Origin::BottomLeft); + const auto forceTop = _forcedOrigin + && (*_forcedOrigin == Origin::TopLeft + || *_forcedOrigin == Origin::TopRight); + const auto forceRight = _forcedOrigin + && (*_forcedOrigin == Origin::TopRight + || *_forcedOrigin == Origin::BottomRight); + const auto forceBottom = _forcedOrigin + && (*_forcedOrigin == Origin::BottomLeft + || *_forcedOrigin == Origin::BottomRight); auto w = p - QPoint(0, _padding.top()); auto r = QApplication::desktop()->screenGeometry(p); _useTransparency = Platform::TranslucentWindowsSupported(p); setAttribute(Qt::WA_OpaquePaintEvent, !_useTransparency); handleCompositingUpdate(); if (style::RightToLeft()) { - if (w.x() - width() < r.x() - _padding.left()) { + const auto badLeft = (w.x() - width() < r.x() - _padding.left()); + if (forceRight || (badLeft && !forceLeft)) { if (_parent && w.x() + _parent->width() - _padding.left() - _padding.right() + width() - _padding.right() <= r.x() + r.width()) { w.setX(w.x() + _parent->width() - _padding.left() - _padding.right()); } else { @@ -474,7 +492,8 @@ void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource sou w.setX(w.x() - width()); } } else { - if (w.x() + width() - _padding.right() > r.x() + r.width()) { + const auto badLeft = (w.x() + width() - _padding.right() > r.x() + r.width()); + if (forceRight || (badLeft && !forceLeft)) { if (_parent && w.x() - _parent->width() + _padding.left() + _padding.right() - width() + _padding.right() >= r.x() - _padding.left()) { w.setX(w.x() + _padding.left() + _padding.right() - _parent->width() - width() + _padding.left() + _padding.right()); } else { @@ -483,7 +502,8 @@ void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource sou origin = PanelAnimation::Origin::TopRight; } } - if (w.y() + height() - _padding.bottom() > r.y() + r.height()) { + const auto badTop = (w.y() + height() - _padding.bottom() > r.y() + r.height()); + if (forceBottom || (badTop && !forceTop)) { if (_parent) { w.setY(r.y() + r.height() - height() + _padding.bottom()); } else { diff --git a/ui/widgets/popup_menu.h b/ui/widgets/popup_menu.h index be6be85..03f8583 100644 --- a/ui/widgets/popup_menu.h +++ b/ui/widgets/popup_menu.h @@ -32,6 +32,7 @@ public: void deleteOnHide(bool del); void popup(const QPoint &p); void hideMenu(bool fast = false); + void setForcedOrigin(PanelAnimation::Origin origin); void setDestroyedCallback(Fn callback) { _destroyedCallback = std::move(callback); @@ -109,6 +110,7 @@ private: SubmenuPointer _activeSubmenu; PanelAnimation::Origin _origin = PanelAnimation::Origin::TopLeft; + std::optional _forcedOrigin; std::unique_ptr _showAnimation; Animations::Simple _a_show; From 1888853b52291c32ce5bbca7212e67c262c76cee Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Feb 2020 15:38:11 +0400 Subject: [PATCH 5/7] Allow simple round rects with not all corners. --- ui/round_rect.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- ui/round_rect.h | 4 ++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ui/round_rect.cpp b/ui/round_rect.cpp index cade79f..0af480b 100644 --- a/ui/round_rect.cpp +++ b/ui/round_rect.cpp @@ -23,8 +23,8 @@ void DrawRoundedRect( const auto y = rect.y(); const auto w = rect.width(); const auto h = rect.height(); - auto cornerWidth = corners[0].width() / pixelRatio; - auto cornerHeight = corners[0].height() / pixelRatio; + const auto cornerWidth = corners[0].width() / pixelRatio; + const auto cornerHeight = corners[0].height() / pixelRatio; if (w < 2 * cornerWidth || h < 2 * cornerHeight) return; if (w > 2 * cornerWidth) { if (parts & RectPart::Top) { @@ -85,4 +85,47 @@ void RoundRect::paint( DrawRoundedRect(p, rect, _color, _corners, parts); } +void RoundRect::paintSomeRounded( + QPainter &p, + const QRect &rect, + RectParts corners) const { + DrawRoundedRect( + p, + rect, + _color, + _corners, + corners | RectPart::Top | RectPart::NoTopBottom | RectPart::Bottom); + + const auto pixelRatio = style::DevicePixelRatio(); + const auto cornerWidth = _corners[0].width() / pixelRatio; + const auto cornerHeight = _corners[0].height() / pixelRatio; + if (!(corners & RectPart::TopLeft)) { + p.fillRect(rect.x(), rect.y(), cornerWidth, cornerHeight, _color); + } + if (!(corners & RectPart::TopRight)) { + p.fillRect( + rect.x() + rect.width() - cornerWidth, + rect.y(), + cornerWidth, + cornerHeight, + _color); + } + if (!(corners & RectPart::BottomRight)) { + p.fillRect( + rect.x() + rect.width() - cornerWidth, + rect.y() + rect.height() - cornerHeight, + cornerWidth, + cornerHeight, + _color); + } + if (!(corners & RectPart::BottomLeft)) { + p.fillRect( + rect.x(), + rect.y() + rect.height() - cornerHeight, + cornerWidth, + cornerHeight, + _color); + } +} + } // namespace Ui diff --git a/ui/round_rect.h b/ui/round_rect.h index ee59179..4d65f4a 100644 --- a/ui/round_rect.h +++ b/ui/round_rect.h @@ -30,6 +30,10 @@ public: QPainter &p, const QRect &rect, RectParts parts = RectPart::Full) const; + void paintSomeRounded( + QPainter &p, + const QRect &rect, + RectParts corners) const; private: style::color _color; From 9cea7f117e0abd0e9db9901c02f72284f73f18ca Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 4 Feb 2020 12:23:19 +0400 Subject: [PATCH 6/7] Fix rendering of 'Mathematical Alphanumeric Symbols' on macOS. --- ui/style/style_core_font.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/style/style_core_font.cpp b/ui/style/style_core_font.cpp index e08ee84..a73e169 100644 --- a/ui/style/style_core_font.cpp +++ b/ui/style/style_core_font.cpp @@ -165,6 +165,7 @@ void StartFonts() { #endif // !DESKTOP_APP_USE_PACKAGED_FONTS #ifdef Q_OS_MAC auto list = QStringList(); + list.append("STIXGeneral"); list.append(".SF NS Text"); list.append("Helvetica Neue"); list.append("Lucida Grande"); From 628d3b9ab6443acd352617ac78cc3131ba41dbbc Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 5 Feb 2020 18:49:17 +0400 Subject: [PATCH 7/7] Improve transparent popup menus. --- ui/widgets/menu.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/widgets/menu.cpp b/ui/widgets/menu.cpp index 2597c47..2605a8a 100644 --- a/ui/widgets/menu.cpp +++ b/ui/widgets/menu.cpp @@ -263,6 +263,9 @@ void Menu::paintEvent(QPaintEvent *e) { } else { auto enabled = action->isEnabled(); auto selected = ((i == _selected || i == _pressed) && enabled); + if (selected && _st.itemBgOver->c.alpha() < 255) { + p.fillRect(0, 0, width(), actionHeight, _st.itemBg); + } p.fillRect(0, 0, width(), actionHeight, selected ? _st.itemBgOver : _st.itemBg); if (data.ripple) { data.ripple->paint(p, 0, 0, width());