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
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
#include "window/window_title.h"
|
2018-06-03 13:30:40 +00:00
|
|
|
#include "ui/rp_widget.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"
|
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 {
|
|
|
|
class Account;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
namespace Ui {
|
|
|
|
class BoxContent;
|
|
|
|
} // namespace Ui
|
|
|
|
|
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();
|
2019-06-06 11:59:00 +00:00
|
|
|
QIcon CreateIcon(Main::Account *account = nullptr);
|
2018-10-07 11:45:46 +00:00
|
|
|
void ConvertIconToBlack(QImage &image);
|
2017-05-12 15:27:19 +00:00
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
class MainWindow : public Ui::RpWidget, protected base::Subscriber {
|
2016-11-04 11:14:47 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
public:
|
2019-06-06 11:20:21 +00:00
|
|
|
explicit MainWindow(not_null<Controller*> controller);
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2019-06-06 11:59:00 +00:00
|
|
|
Window::Controller &controller() const {
|
|
|
|
return *_controller;
|
2017-06-21 21:38:31 +00:00
|
|
|
}
|
2019-06-06 11:59:00 +00:00
|
|
|
Main::Account &account() const;
|
2019-06-06 11:20:21 +00:00
|
|
|
Window::SessionController *sessionController() const;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool hideNoQuit();
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void init();
|
|
|
|
HitTestResult hitTest(const QPoint &p) const;
|
2017-01-01 16:45:20 +00:00
|
|
|
void updateIsActive(int timeout);
|
|
|
|
bool isActive() const {
|
|
|
|
return _isActive;
|
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
bool positionInited() const {
|
|
|
|
return _positionInited;
|
|
|
|
}
|
|
|
|
void positionUpdated();
|
|
|
|
|
2016-11-09 08:34:38 +00:00
|
|
|
bool titleVisible() const;
|
|
|
|
void setTitleVisible(bool visible);
|
|
|
|
QString titleText() const {
|
|
|
|
return _titleText;
|
|
|
|
}
|
2016-11-08 14:07:25 +00:00
|
|
|
|
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
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual void updateTrayMenu(bool force = false) {
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
virtual ~MainWindow();
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
TWidget *bodyWidget() {
|
2016-12-13 17:07:56 +00:00
|
|
|
return _body.data();
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void launchDrag(std::unique_ptr<QMimeData> data);
|
|
|
|
base::Observable<void> &dragFinished() {
|
|
|
|
return _dragFinished;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
public slots:
|
|
|
|
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();
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
virtual void initHook() {
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual void updateIsActiveHook() {
|
|
|
|
}
|
|
|
|
|
2017-11-15 12:46:34 +00:00
|
|
|
virtual void handleActiveChangedHook() {
|
|
|
|
}
|
|
|
|
|
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 titleVisibilityChangedHook() {
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasTrayIcon() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void showTrayTooltip() {
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
virtual void workmodeUpdated(DBIWorkMode mode) {
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
virtual void updateControlsGeometry();
|
|
|
|
|
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;
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-31 13:34:41 +00:00
|
|
|
void updatePalette();
|
2016-11-09 08:34:38 +00:00
|
|
|
void updateUnreadCounter();
|
2016-11-04 11:14:47 +00:00
|
|
|
void initSize();
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool computeIsActive() const;
|
2018-06-03 13:30:40 +00:00
|
|
|
void checkLockByTerms();
|
|
|
|
void showTermsDecline();
|
|
|
|
void showTermsDelete();
|
2017-01-01 16:45:20 +00:00
|
|
|
|
2019-06-03 14:41:23 +00:00
|
|
|
int computeMinHeight() 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;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<TitleWidget> _title = { nullptr };
|
2019-06-03 22:34:34 +00:00
|
|
|
object_ptr<Ui::RpWidget> _outdated;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<TWidget> _body;
|
2017-02-03 20:07:26 +00:00
|
|
|
object_ptr<TWidget> _rightColumn = { nullptr };
|
2019-09-18 11:19:05 +00:00
|
|
|
QPointer<Ui::BoxContent> _termsBox;
|
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
|
|
|
QString _titleText;
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool _isActive = false;
|
2017-06-21 21:38:31 +00:00
|
|
|
base::Timer _isActiveTimer;
|
2017-01-01 16:45:20 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
base::Observable<void> _dragFinished;
|
2017-11-21 10:27:37 +00:00
|
|
|
rpl::event_stream<> _leaveEvents;
|
2017-11-16 16:43:52 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Window
|