2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2014-06-14 19:32:11 +00:00
|
|
|
#include "application.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-06-14 19:32:11 +00:00
|
|
|
|
2016-01-30 16:31:10 +00:00
|
|
|
namespace Fonts {
|
|
|
|
|
|
|
|
bool Started = false;
|
|
|
|
void start() {
|
|
|
|
if (!Started) {
|
|
|
|
Started = true;
|
|
|
|
|
|
|
|
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Regular.ttf"));
|
|
|
|
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Bold.ttf"));
|
|
|
|
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Semibold.ttf"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
namespace {
|
2015-04-02 10:33:19 +00:00
|
|
|
void _sendResizeEvents(QWidget *target) {
|
|
|
|
QResizeEvent e(target->size(), QSize());
|
|
|
|
QApplication::sendEvent(target, &e);
|
|
|
|
|
|
|
|
const QObjectList children = target->children();
|
|
|
|
for (int i = 0; i < children.size(); ++i) {
|
|
|
|
QWidget *child = static_cast<QWidget*>(children.at(i));
|
|
|
|
if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) {
|
|
|
|
_sendResizeEvents(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:39:51 +00:00
|
|
|
bool TWidget::inFocusChain() const {
|
|
|
|
return !isHidden() && App::wnd() && (App::wnd()->focusWidget() == this || isAncestorOf(App::wnd()->focusWidget()));
|
|
|
|
}
|
|
|
|
|
2015-07-17 19:17:37 +00:00
|
|
|
void myEnsureResized(QWidget *target) {
|
|
|
|
if (target && (target->testAttribute(Qt::WA_PendingResizeEvent) || !target->testAttribute(Qt::WA_WState_Created))) {
|
|
|
|
_sendResizeEvents(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
QPixmap myGrab(TWidget *target, QRect rect, QColor bg) {
|
2016-01-30 16:31:10 +00:00
|
|
|
myEnsureResized(target);
|
2015-10-17 14:52:26 +00:00
|
|
|
if (rect.isNull()) rect = target->rect();
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = QPixmap(rect.size() * cIntRetinaFactor());
|
2015-10-18 23:01:18 +00:00
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!target->testAttribute(Qt::WA_OpaquePaintEvent)) {
|
|
|
|
result.fill(bg);
|
|
|
|
}
|
2015-10-17 14:52:26 +00:00
|
|
|
|
|
|
|
target->grabStart();
|
2016-12-20 13:03:51 +00:00
|
|
|
target->render(&result, QPoint(0, 0), rect, QWidget::DrawChildren | QWidget::IgnoreMask);
|
2015-10-17 14:52:26 +00:00
|
|
|
target->grabFinish();
|
|
|
|
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
QImage myGrabImage(TWidget *target, QRect rect, QColor bg) {
|
2016-11-24 19:28:23 +00:00
|
|
|
myEnsureResized(target);
|
|
|
|
if (rect.isNull()) rect = target->rect();
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = QImage(rect.size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
2016-11-24 19:28:23 +00:00
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
if (!target->testAttribute(Qt::WA_OpaquePaintEvent)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
result.fill(bg);
|
2016-11-24 19:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
target->grabStart();
|
|
|
|
target->render(&result, QPoint(0, 0), rect, QWidget::DrawChildren | QWidget::IgnoreMask);
|
|
|
|
target->grabFinish();
|
|
|
|
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2016-06-15 17:13:46 +00:00
|
|
|
void sendSynteticMouseEvent(QWidget *widget, QEvent::Type type, Qt::MouseButton button, const QPoint &globalPoint) {
|
2016-08-27 17:52:05 +00:00
|
|
|
if (auto windowHandle = widget->window()->windowHandle()) {
|
|
|
|
auto localPoint = windowHandle->mapFromGlobal(globalPoint);
|
2016-08-31 20:06:12 +00:00
|
|
|
QMouseEvent ev(type
|
|
|
|
, localPoint
|
|
|
|
, localPoint
|
|
|
|
, globalPoint
|
|
|
|
, button
|
|
|
|
, QGuiApplication::mouseButtons() | button
|
|
|
|
, QGuiApplication::keyboardModifiers()
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-08-31 20:06:12 +00:00
|
|
|
, Qt::MouseEventSynthesizedByApplication
|
2016-08-30 05:24:16 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2016-08-31 20:06:12 +00:00
|
|
|
);
|
2016-08-27 17:52:05 +00:00
|
|
|
ev.setTimestamp(getms());
|
|
|
|
QGuiApplication::sendEvent(windowHandle, &ev);
|
|
|
|
}
|
2016-06-15 17:13:46 +00:00
|
|
|
}
|