2016-06-16 12:59:54 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-16 12:59:54 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-07-25 21:30:56 +00:00
|
|
|
#include "ui/widgets/rp_window.h"
|
2017-06-21 21:38:31 +00:00
|
|
|
#include "base/timer.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2021-05-27 22:11:16 +00:00
|
|
|
#include "core/core_settings.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtWidgets/QSystemTrayIcon>
|
|
|
|
|
2019-06-06 11:59:00 +00:00
|
|
|
namespace Main {
|
2020-06-15 16:25:02 +00:00
|
|
|
class Session;
|
2019-06-06 11:59:00 +00:00
|
|
|
class Account;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
namespace Ui {
|
|
|
|
class BoxContent;
|
2020-07-07 13:54:39 +00:00
|
|
|
class PlainShadow;
|
2019-09-18 11:19:05 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2021-08-10 12:41:25 +00:00
|
|
|
namespace Core {
|
|
|
|
struct WindowPosition;
|
|
|
|
} // namespace Core
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
class Controller;
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2016-11-04 11:14:47 +00:00
|
|
|
class TitleWidget;
|
2018-06-03 13:30:40 +00:00
|
|
|
struct TermsLock;
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
QImage LoadLogo();
|
|
|
|
QImage LoadLogoNoMargin();
|
2020-06-15 16:25:02 +00:00
|
|
|
QIcon CreateIcon(Main::Session *session = nullptr);
|
2018-10-07 11:45:46 +00:00
|
|
|
void ConvertIconToBlack(QImage &image);
|
2017-05-12 15:27:19 +00:00
|
|
|
|
2021-07-25 21:30:56 +00:00
|
|
|
class MainWindow : public Ui::RpWindow {
|
2016-06-16 12:59:54 +00:00
|
|
|
public:
|
2019-06-06 11:20:21 +00:00
|
|
|
explicit MainWindow(not_null<Controller*> controller);
|
2021-02-25 15:12:51 +00:00
|
|
|
virtual ~MainWindow();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
[[nodiscard]] Window::Controller &controller() const {
|
2019-06-06 11:59:00 +00:00
|
|
|
return *_controller;
|
2017-06-21 21:38:31 +00:00
|
|
|
}
|
2020-06-15 16:25:02 +00:00
|
|
|
[[nodiscard]] Main::Account &account() const;
|
|
|
|
[[nodiscard]] Window::SessionController *sessionController() const;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool hideNoQuit();
|
|
|
|
|
2021-01-22 12:16:18 +00:00
|
|
|
void showFromTray();
|
|
|
|
void quitFromTray();
|
|
|
|
void activate();
|
|
|
|
virtual void showFromTrayMenu() {
|
|
|
|
showFromTray();
|
|
|
|
}
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
[[nodiscard]] QRect desktopRect() const;
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void init();
|
2020-06-17 09:36:25 +00:00
|
|
|
|
|
|
|
void updateIsActive();
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
[[nodiscard]] bool isActive() const {
|
2017-01-01 16:45:20 +00:00
|
|
|
return _isActive;
|
|
|
|
}
|
2021-02-25 15:12:51 +00:00
|
|
|
[[nodiscard]] virtual bool isActiveForTrayMenu() {
|
2021-01-22 12:16:18 +00:00
|
|
|
updateIsActive();
|
|
|
|
return isActive();
|
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
bool positionInited() const {
|
|
|
|
return _positionInited;
|
|
|
|
}
|
|
|
|
void positionUpdated();
|
|
|
|
|
2018-06-05 18:14:38 +00:00
|
|
|
void reActivateWindow();
|
2017-01-01 17:49:44 +00:00
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
void showRightColumn(object_ptr<TWidget> widget);
|
2017-11-16 16:43:52 +00:00
|
|
|
int maximalExtendBy() const;
|
|
|
|
bool canExtendNoMove(int extendBy) const;
|
|
|
|
|
|
|
|
// Returns how much could the window get extended.
|
|
|
|
int tryToExtendWidthBy(int addToWidth);
|
2017-02-03 20:07:26 +00:00
|
|
|
|
2021-02-23 00:55:14 +00:00
|
|
|
virtual void updateTrayMenu() {
|
2017-01-01 16:45:20 +00:00
|
|
|
}
|
2020-07-07 13:54:39 +00:00
|
|
|
virtual void fixOrder() {
|
|
|
|
}
|
2021-02-25 15:12:51 +00:00
|
|
|
virtual void setInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
Ui::RpWidget *bodyWidget() {
|
2016-12-13 17:07:56 +00:00
|
|
|
return _body.data();
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 12:42:26 +00:00
|
|
|
void launchDrag(std::unique_ptr<QMimeData> data, Fn<void()> &&callback);
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
rpl::producer<> leaveEvents() const;
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
virtual void updateWindowIcon();
|
|
|
|
|
2019-08-16 12:44:20 +00:00
|
|
|
void clearWidgets();
|
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
int computeMinWidth() const;
|
|
|
|
int computeMinHeight() const;
|
|
|
|
|
2020-07-07 13:54:39 +00:00
|
|
|
void recountGeometryConstraints();
|
2020-03-03 12:07:22 +00:00
|
|
|
virtual void updateControlsGeometry();
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool minimizeToTray();
|
2017-01-01 16:45:20 +00:00
|
|
|
void updateGlobalMenu() {
|
|
|
|
updateGlobalMenuHook();
|
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
protected:
|
2016-11-04 11:14:47 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2018-06-03 13:30:40 +00:00
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
void savePosition(Qt::WindowState state = Qt::WindowActive);
|
2017-05-19 14:02:55 +00:00
|
|
|
void handleStateChanged(Qt::WindowState state);
|
|
|
|
void handleActiveChanged();
|
2020-09-18 09:09:05 +00:00
|
|
|
void handleVisibleChanged(bool visible);
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
virtual void initHook() {
|
|
|
|
}
|
|
|
|
|
2021-06-18 15:22:36 +00:00
|
|
|
virtual void activeChangedHook() {
|
2017-01-01 16:45:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 12:46:34 +00:00
|
|
|
virtual void handleActiveChangedHook() {
|
|
|
|
}
|
|
|
|
|
2020-09-18 09:09:05 +00:00
|
|
|
virtual void handleVisibleChangedHook(bool visible) {
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual void clearWidgetsHook() {
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:17:39 +00:00
|
|
|
virtual void stateChangedHook(Qt::WindowState state) {
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2016-11-09 08:34:38 +00:00
|
|
|
virtual void unreadCounterChangedHook() {
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
virtual void closeWithoutDestroy() {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual void updateGlobalMenuHook() {
|
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
virtual void initTrayMenuHook() {
|
|
|
|
}
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual bool hasTrayIcon() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void showTrayTooltip() {
|
|
|
|
}
|
|
|
|
|
2021-05-27 22:11:16 +00:00
|
|
|
virtual void workmodeUpdated(Core::Settings::WorkMode mode) {
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
virtual void createGlobalMenu() {
|
|
|
|
}
|
|
|
|
|
2021-08-10 12:41:25 +00:00
|
|
|
virtual bool initGeometryFromSystem() {
|
2021-01-16 12:33:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
// This one is overriden in Windows for historical reasons.
|
|
|
|
virtual int32 screenNameChecksum(const QString &name) const;
|
|
|
|
|
|
|
|
void setPositionInited();
|
2019-04-12 13:21:01 +00:00
|
|
|
void attachToTrayIcon(not_null<QSystemTrayIcon*> icon);
|
|
|
|
virtual void handleTrayIconActication(
|
|
|
|
QSystemTrayIcon::ActivationReason reason) = 0;
|
2020-06-18 11:17:58 +00:00
|
|
|
void updateUnreadCounter();
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
virtual QRect computeDesktopRect() const;
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
private:
|
2020-07-07 13:54:39 +00:00
|
|
|
void refreshTitleWidget();
|
|
|
|
void updateMinimumSize();
|
2016-12-31 13:34:41 +00:00
|
|
|
void updatePalette();
|
2021-08-10 12:41:25 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Core::WindowPosition positionFromSettings() const;
|
|
|
|
[[nodiscard]] QRect countInitialGeometry(Core::WindowPosition position);
|
|
|
|
void initGeometry();
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool computeIsActive() const;
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
not_null<Window::Controller*> _controller;
|
|
|
|
|
2018-06-05 18:14:38 +00:00
|
|
|
base::Timer _positionUpdatedTimer;
|
2016-11-04 11:14:47 +00:00
|
|
|
bool _positionInited = false;
|
|
|
|
|
2020-07-07 13:54:39 +00:00
|
|
|
object_ptr<Ui::PlainShadow> _titleShadow = { nullptr };
|
2019-06-03 22:34:34 +00:00
|
|
|
object_ptr<Ui::RpWidget> _outdated;
|
2020-03-03 12:07:22 +00:00
|
|
|
object_ptr<Ui::RpWidget> _body;
|
2017-02-03 20:07:26 +00:00
|
|
|
object_ptr<TWidget> _rightColumn = { nullptr };
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
QIcon _icon;
|
2018-10-07 11:45:46 +00:00
|
|
|
bool _usingSupportIcon = false;
|
2016-11-09 08:34:38 +00:00
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool _isActive = false;
|
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
rpl::event_stream<> _leaveEvents;
|
2017-11-16 16:43:52 +00:00
|
|
|
|
2020-09-18 09:09:05 +00:00
|
|
|
bool _maximizedBeforeHide = false;
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
mutable QRect _monitorRect;
|
|
|
|
mutable crl::time _monitorLastGot = 0;
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Window
|