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"
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
class BoxContent;
|
2016-12-31 15:19:22 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
class Controller;
|
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();
|
|
|
|
QIcon CreateIcon();
|
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:
|
|
|
|
MainWindow();
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
Window::Controller *controller() const {
|
|
|
|
return _controller.get();
|
|
|
|
}
|
|
|
|
void setInactivePress(bool inactive);
|
|
|
|
bool wasInactivePress() const {
|
|
|
|
return _wasInactivePress;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
void clearWidgets();
|
|
|
|
virtual void clearWidgetsHook() {
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
virtual void updateWindowIcon();
|
|
|
|
|
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:
|
2017-06-21 21:38:31 +00:00
|
|
|
void checkAuthSession();
|
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
|
|
|
|
2018-06-05 18:14:38 +00:00
|
|
|
base::Timer _positionUpdatedTimer;
|
2016-11-04 11:14:47 +00:00
|
|
|
bool _positionInited = false;
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
std::unique_ptr<Window::Controller> _controller;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<TitleWidget> _title = { nullptr };
|
|
|
|
object_ptr<TWidget> _body;
|
2017-02-03 20:07:26 +00:00
|
|
|
object_ptr<TWidget> _rightColumn = { nullptr };
|
2018-06-03 13:30:40 +00:00
|
|
|
QPointer<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;
|
|
|
|
bool _wasInactivePress = false;
|
|
|
|
base::Timer _inactivePressTimer;
|
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
|