2016-10-26 16:43:13 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
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
|
2016-10-26 16:43:13 +00:00
|
|
|
*/
|
|
|
|
#include "history/history_drag_area.h"
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/sticker_set_box.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "inline_bots/inline_bot_result.h"
|
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
|
|
|
#include "dialogs/dialogs_layout.h"
|
2017-06-29 10:27:09 +00:00
|
|
|
#include "history/history_widget.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
DragArea::DragArea(QWidget *parent) : TWidget(parent) {
|
2016-10-26 16:43:13 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
setAcceptDrops(true);
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool DragArea::overlaps(const QRect &globalRect) {
|
|
|
|
if (isHidden() || _a_opacity.animating()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto inner = innerRect();
|
|
|
|
auto testRect = QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size());
|
|
|
|
return inner.marginsRemoved(QMargins(st::boxRadius, 0, st::boxRadius, 0)).contains(testRect)
|
|
|
|
|| inner.marginsRemoved(QMargins(0, st::boxRadius, 0, st::boxRadius)).contains(testRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void DragArea::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
if (_hiding) return;
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
auto in = QRect(st::dragPadding.left(), st::dragPadding.top(), width() - st::dragPadding.left() - st::dragPadding.right(), height() - st::dragPadding.top() - st::dragPadding.bottom()).contains(e->pos());
|
|
|
|
setIn(in);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::dragMoveEvent(QDragMoveEvent *e) {
|
|
|
|
QRect r(st::dragPadding.left(), st::dragPadding.top(), width() - st::dragPadding.left() - st::dragPadding.right(), height() - st::dragPadding.top() - st::dragPadding.bottom());
|
2016-12-07 13:32:25 +00:00
|
|
|
setIn(r.contains(e->pos()));
|
2016-10-26 16:43:13 +00:00
|
|
|
e->setDropAction(_in ? Qt::CopyAction : Qt::IgnoreAction);
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
void DragArea::setIn(bool in) {
|
|
|
|
if (_in != in) {
|
|
|
|
_in = in;
|
2016-12-13 17:07:56 +00:00
|
|
|
_a_in.start([this] { update(); }, _in ? 0. : 1., _in ? 1. : 0., st::boxDuration);
|
2016-12-07 13:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void DragArea::setText(const QString &text, const QString &subtext) {
|
|
|
|
_text = text;
|
|
|
|
_subtext = subtext;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
auto ms = getms();
|
|
|
|
auto opacity = _a_opacity.current(ms, _hiding ? 0. : 1.);
|
|
|
|
if (!_a_opacity.animating() && _hiding) {
|
|
|
|
return;
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
2016-12-07 13:32:25 +00:00
|
|
|
p.setOpacity(opacity);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto inner = innerRect();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_cache.isNull()) {
|
|
|
|
p.drawPixmapLeft(inner.x() - st::boxRoundShadow.extend.left(), inner.y() - st::boxRoundShadow.extend.top(), width(), _cache);
|
|
|
|
return;
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::Shadow::paint(p, inner, width(), st::boxRoundShadow);
|
|
|
|
App::roundRect(p, inner, st::boxBg, BoxCorners);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
p.setPen(anim::pen(st::dragColor, st::dragDropColor, _a_in.current(ms, _in ? 1. : 0.)));
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::dragFont);
|
2016-10-26 16:43:13 +00:00
|
|
|
p.drawText(QRect(0, (height() - st::dragHeight) / 2, width(), st::dragFont->height), _text, QTextOption(style::al_top));
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::dragSubfont);
|
2016-10-26 16:43:13 +00:00
|
|
|
p.drawText(QRect(0, (height() + st::dragHeight) / 2 - st::dragSubfont->height, width(), st::dragSubfont->height * 2), _subtext, QTextOption(style::al_top));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::dragEnterEvent(QDragEnterEvent *e) {
|
|
|
|
static_cast<HistoryWidget*>(parentWidget())->dragEnterEvent(e);
|
|
|
|
e->setDropAction(Qt::IgnoreAction);
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::dragLeaveEvent(QDragLeaveEvent *e) {
|
|
|
|
static_cast<HistoryWidget*>(parentWidget())->dragLeaveEvent(e);
|
2016-12-07 13:32:25 +00:00
|
|
|
setIn(false);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::dropEvent(QDropEvent *e) {
|
|
|
|
static_cast<HistoryWidget*>(parentWidget())->dropEvent(e);
|
2016-11-28 15:45:07 +00:00
|
|
|
if (e->isAccepted() && _droppedCallback) {
|
|
|
|
_droppedCallback(e->mimeData());
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::otherEnter() {
|
|
|
|
showStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::otherLeave() {
|
|
|
|
hideStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::hideFast() {
|
2016-12-07 13:32:25 +00:00
|
|
|
_a_opacity.finish();
|
2016-10-26 16:43:13 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::hideStart() {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_hiding || isHidden()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_cache.isNull()) {
|
|
|
|
_cache = myGrab(this, innerRect().marginsAdded(st::boxRoundShadow.extend));
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
_hiding = true;
|
2016-12-07 13:32:25 +00:00
|
|
|
setIn(false);
|
2016-12-13 17:07:56 +00:00
|
|
|
_a_opacity.start([this] { opacityAnimationCallback(); }, 1., 0., st::boxDuration);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::hideFinish() {
|
|
|
|
hide();
|
|
|
|
_in = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
_a_in.finish();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DragArea::showStart() {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_hiding && !isHidden()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
_hiding = false;
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_cache.isNull()) {
|
|
|
|
_cache = myGrab(this, innerRect().marginsAdded(st::boxRoundShadow.extend));
|
|
|
|
}
|
2016-10-26 16:43:13 +00:00
|
|
|
show();
|
2016-12-13 17:07:56 +00:00
|
|
|
_a_opacity.start([this] { opacityAnimationCallback(); }, 0., 1., st::boxDuration);
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
void DragArea::opacityAnimationCallback() {
|
|
|
|
update();
|
|
|
|
if (!_a_opacity.animating()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_cache = QPixmap();
|
2016-10-26 16:43:13 +00:00
|
|
|
if (_hiding) {
|
|
|
|
hideFinish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|