2017-04-08 13:27:53 +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
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "history/history_inner_widget.h"
|
|
|
|
|
2017-10-30 19:24:20 +00:00
|
|
|
#include <rpl/merge.h>
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "styles/style_history.h"
|
|
|
|
#include "core/file_utilities.h"
|
2017-06-22 15:11:41 +00:00
|
|
|
#include "history/history_message.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "history/history_service_layout.h"
|
|
|
|
#include "history/history_media_types.h"
|
|
|
|
#include "ui/widgets/popup_menu.h"
|
|
|
|
#include "window/window_controller.h"
|
2017-12-15 18:36:28 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2017-08-02 20:57:49 +00:00
|
|
|
#include "chat_helpers/stickers.h"
|
2017-06-29 10:27:09 +00:00
|
|
|
#include "history/history_widget.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "auth_session.h"
|
2017-08-08 09:31:48 +00:00
|
|
|
#include "messenger.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "apiwrap.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kScrollDateHideTimeout = 1000;
|
|
|
|
|
|
|
|
class DateClickHandler : public ClickHandler {
|
|
|
|
public:
|
|
|
|
DateClickHandler(PeerData *peer, QDate date) : _peer(peer), _date(date) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDate(QDate date) {
|
|
|
|
_date = date;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onClick(Qt::MouseButton) const override {
|
2017-08-01 11:43:50 +00:00
|
|
|
App::wnd()->controller()->showJumpToDate(_peer, _date);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PeerData *_peer = nullptr;
|
|
|
|
QDate _date;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Helper binary search for an item in a list that is not completely
|
|
|
|
// above the given top of the visible area or below the given bottom of the visible area
|
|
|
|
// is applied once for blocks list in a history and once for items list in the found block.
|
|
|
|
template <bool TopToBottom, typename T>
|
|
|
|
int BinarySearchBlocksOrItems(const T &list, int edge) {
|
|
|
|
// static_cast to work around GCC bug #78693
|
|
|
|
auto start = 0, end = static_cast<int>(list.size());
|
|
|
|
while (end - start > 1) {
|
|
|
|
auto middle = (start + end) / 2;
|
|
|
|
auto top = list[middle]->y();
|
|
|
|
auto chooseLeft = (TopToBottom ? (top <= edge) : (top < edge));
|
|
|
|
if (chooseLeft) {
|
|
|
|
start = middle;
|
|
|
|
} else {
|
|
|
|
end = middle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// flick scroll taken from http://qt-project.org/doc/qt-4.8/demos-embedded-anomaly-src-flickcharm-cpp.html
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
class HistoryInner::BotAbout : public ClickHandlerHost {
|
|
|
|
public:
|
|
|
|
BotAbout(not_null<HistoryInner*> parent, not_null<BotInfo*> info);
|
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
|
|
|
|
|
|
|
|
not_null<BotInfo*> info;
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
QRect rect;
|
|
|
|
|
|
|
|
private:
|
|
|
|
not_null<HistoryInner*> _parent;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
HistoryInner::BotAbout::BotAbout(
|
|
|
|
not_null<HistoryInner*> parent,
|
|
|
|
not_null<BotInfo*> info)
|
|
|
|
: info(info)
|
|
|
|
, _parent(parent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::BotAbout::clickHandlerActiveChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool active) {
|
|
|
|
_parent->update(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::BotAbout::clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool pressed) {
|
|
|
|
_parent->update(rect);
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
HistoryInner::HistoryInner(
|
2017-12-06 14:15:41 +00:00
|
|
|
not_null<HistoryWidget*> historyWidget,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
Ui::ScrollArea *scroll,
|
2017-12-06 14:15:41 +00:00
|
|
|
not_null<History*> history)
|
2017-10-05 15:35:52 +00:00
|
|
|
: RpWidget(nullptr)
|
2017-04-08 13:27:53 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _peer(history->peer)
|
2017-08-31 17:53:03 +00:00
|
|
|
, _migrated(history->migrateFrom())
|
2017-04-08 13:27:53 +00:00
|
|
|
, _history(history)
|
|
|
|
, _widget(historyWidget)
|
|
|
|
, _scroll(scroll)
|
|
|
|
, _scrollDateCheck([this] { onScrollDateCheck(); }) {
|
|
|
|
_touchSelectTimer.setSingleShot(true);
|
|
|
|
connect(&_touchSelectTimer, SIGNAL(timeout()), this, SLOT(onTouchSelect()));
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
connect(&_touchScrollTimer, SIGNAL(timeout()), this, SLOT(onTouchScrollTimer()));
|
|
|
|
|
|
|
|
_trippleClickTimer.setSingleShot(true);
|
|
|
|
|
|
|
|
connect(&_scrollDateHideTimer, SIGNAL(timeout()), this, SLOT(onScrollDateHideByTimer()));
|
|
|
|
|
|
|
|
notifyIsBotChanged();
|
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
subscribe(_controller->gifPauseLevelChanged(), [this] {
|
|
|
|
if (!_controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any)) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
});
|
2017-06-21 21:38:31 +00:00
|
|
|
subscribe(_controller->window()->dragFinished(), [this] {
|
|
|
|
mouseActionUpdate(QCursor::pos());
|
|
|
|
});
|
2017-10-30 19:24:20 +00:00
|
|
|
Auth().data().itemRemoved()
|
|
|
|
| rpl::start_with_next(
|
|
|
|
[this](auto item) { itemRemoved(item); },
|
|
|
|
lifetime());
|
|
|
|
rpl::merge(
|
|
|
|
Auth().data().historyUnloaded(),
|
|
|
|
Auth().data().historyCleared())
|
|
|
|
| rpl::filter([this](not_null<const History*> history) {
|
|
|
|
return (_history == history);
|
|
|
|
})
|
|
|
|
| rpl::start_with_next([this] {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionCancel();
|
2017-10-30 19:24:20 +00:00
|
|
|
}, lifetime());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::messagesReceived(PeerData *peer, const QVector<MTPMessage> &messages) {
|
|
|
|
if (_history && _history->peer == peer) {
|
|
|
|
_history->addOlderSlice(messages);
|
|
|
|
} else if (_migrated && _migrated->peer == peer) {
|
|
|
|
bool newLoaded = (_migrated && _migrated->isEmpty() && !_history->isEmpty());
|
|
|
|
_migrated->addOlderSlice(messages);
|
|
|
|
if (newLoaded) {
|
|
|
|
_migrated->addNewerSlice(QVector<MTPMessage>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::messagesReceivedDown(PeerData *peer, const QVector<MTPMessage> &messages) {
|
|
|
|
if (_history && _history->peer == peer) {
|
|
|
|
bool oldLoaded = (_migrated && _history->isEmpty() && !_migrated->isEmpty());
|
|
|
|
_history->addNewerSlice(messages);
|
|
|
|
if (oldLoaded) {
|
|
|
|
_history->addOlderSlice(QVector<MTPMessage>());
|
|
|
|
}
|
|
|
|
} else if (_migrated && _migrated->peer == peer) {
|
|
|
|
_migrated->addNewerSlice(messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::repaintItem(const HistoryItem *item) {
|
|
|
|
if (!item || item->detached() || !_history) return;
|
|
|
|
int32 msgy = itemTop(item);
|
|
|
|
if (msgy >= 0) {
|
|
|
|
update(0, msgy, width(), item->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool TopToBottom, typename Method>
|
|
|
|
void HistoryInner::enumerateItemsInHistory(History *history, int historytop, Method method) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// No displayed messages in this history.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (historytop < 0 || history->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_visibleAreaBottom <= historytop || historytop + history->height <= _visibleAreaTop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto searchEdge = TopToBottom ? _visibleAreaTop : _visibleAreaBottom;
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Binary search for blockIndex of the first block that is not completely below the visible area.
|
|
|
|
auto blockIndex = BinarySearchBlocksOrItems<TopToBottom>(history->blocks, searchEdge - historytop);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Binary search for itemIndex of the first item that is not completely below the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
auto block = history->blocks.at(blockIndex);
|
2017-05-12 13:53:08 +00:00
|
|
|
auto blocktop = historytop + block->y();
|
|
|
|
auto blockbottom = blocktop + block->height();
|
2017-06-22 01:31:02 +00:00
|
|
|
auto itemIndex = BinarySearchBlocksOrItems<TopToBottom>(block->items, searchEdge - blocktop);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
auto item = block->items.at(itemIndex);
|
2017-05-12 13:53:08 +00:00
|
|
|
auto itemtop = blocktop + item->y();
|
2017-04-08 13:27:53 +00:00
|
|
|
auto itembottom = itemtop + item->height();
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Binary search should've skipped all the items that are above / below the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(itembottom > _visibleAreaTop);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(itemtop < _visibleAreaBottom);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!method(item, itemtop, itembottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Skip all the items that are below / above the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
|
|
|
if (itembottom >= _visibleAreaBottom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (itemtop <= _visibleAreaTop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TopToBottom) {
|
|
|
|
if (++itemIndex >= block->items.size()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (--itemIndex < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Skip all the rest blocks that are below / above the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
|
|
|
if (blockbottom >= _visibleAreaBottom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (blocktop <= _visibleAreaTop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TopToBottom) {
|
|
|
|
if (++blockIndex >= history->blocks.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (--blockIndex < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
block = history->blocks[blockIndex];
|
|
|
|
blocktop = historytop + block->y();
|
|
|
|
blockbottom = blocktop + block->height();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
|
|
|
itemIndex = 0;
|
|
|
|
} else {
|
|
|
|
itemIndex = block->items.size() - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Method>
|
|
|
|
void HistoryInner::enumerateUserpics(Method method) {
|
|
|
|
if ((!_history || !_history->canHaveFromPhotos()) && (!_migrated || !_migrated->canHaveFromPhotos())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Find and remember the top of an attached messages pack
|
|
|
|
// -1 means we didn't find an attached to next message yet.
|
2017-04-08 13:27:53 +00:00
|
|
|
int lowestAttachedItemTop = -1;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
auto userpicCallback = [this, &lowestAttachedItemTop, &method](not_null<HistoryItem*> item, int itemtop, int itembottom) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// Skip all service messages.
|
2017-04-08 13:27:53 +00:00
|
|
|
auto message = item->toHistoryMessage();
|
|
|
|
if (!message) return true;
|
|
|
|
|
|
|
|
if (lowestAttachedItemTop < 0 && message->isAttachedToNext()) {
|
|
|
|
lowestAttachedItemTop = itemtop + message->marginTop();
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call method on a userpic for all messages that have it and for those who are not showing it
|
|
|
|
// because of their attachment to the next message if they are bottom-most visible.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (message->displayFromPhoto() || (message->hasFromPhoto() && itembottom >= _visibleAreaBottom)) {
|
|
|
|
if (lowestAttachedItemTop < 0) {
|
|
|
|
lowestAttachedItemTop = itemtop + message->marginTop();
|
|
|
|
}
|
2017-06-22 01:31:02 +00:00
|
|
|
// Attach userpic to the bottom of the visible area with the same margin as the last message.
|
2017-04-08 13:27:53 +00:00
|
|
|
auto userpicMinBottomSkip = st::historyPaddingBottom + st::msgMargin.bottom();
|
|
|
|
auto userpicBottom = qMin(itembottom - message->marginBottom(), _visibleAreaBottom - userpicMinBottomSkip);
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Do not let the userpic go above the attached messages pack top line.
|
2017-04-08 13:27:53 +00:00
|
|
|
userpicBottom = qMax(userpicBottom, lowestAttachedItemTop + st::msgPhotoSize);
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call the template callback function that was passed
|
|
|
|
// and return if it finished everything it needed.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!method(message, userpicBottom - st::msgPhotoSize)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Forget the found top of the pack, search for the next one from scratch.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!message->isAttachedToNext()) {
|
|
|
|
lowestAttachedItemTop = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
enumerateItems<EnumItemsDirection::TopToBottom>(userpicCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Method>
|
|
|
|
void HistoryInner::enumerateDates(Method method) {
|
2017-06-22 01:31:02 +00:00
|
|
|
auto drawtop = historyDrawTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Find and remember the bottom of an single-day messages pack
|
|
|
|
// -1 means we didn't find a same-day with previous message yet.
|
|
|
|
auto lowestInOneDayItemBottom = -1;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
auto dateCallback = [this, &lowestInOneDayItemBottom, &method, drawtop](not_null<HistoryItem*> item, int itemtop, int itembottom) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (lowestInOneDayItemBottom < 0 && item->isInOneDayWithPrevious()) {
|
|
|
|
lowestInOneDayItemBottom = itembottom - item->marginBottom();
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call method on a date for all messages that have it and for those who are not showing it
|
|
|
|
// because they are in a one day together with the previous message if they are top-most visible.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (item->displayDate() || (!item->isEmpty() && itemtop <= _visibleAreaTop)) {
|
|
|
|
// skip the date of history migrate item if it will be in migrated
|
|
|
|
if (itemtop < drawtop && item->history() == _history) {
|
|
|
|
if (itemtop > _visibleAreaTop) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// Previous item (from the _migrated history) is drawing date now.
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
} else if (item == _history->blocks.front()->items.front() && item->isGroupMigrate()
|
|
|
|
&& _migrated->blocks.back()->items.back()->isGroupMigrate()) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// This item is completely invisible and should be completely ignored.
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lowestInOneDayItemBottom < 0) {
|
|
|
|
lowestInOneDayItemBottom = itembottom - item->marginBottom();
|
|
|
|
}
|
2017-06-22 01:31:02 +00:00
|
|
|
// Attach date to the top of the visible area with the same margin as it has in service message.
|
2017-04-08 13:27:53 +00:00
|
|
|
int dateTop = qMax(itemtop, _visibleAreaTop) + st::msgServiceMargin.top();
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Do not let the date go below the single-day messages pack bottom line.
|
2017-04-08 13:27:53 +00:00
|
|
|
int dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top();
|
|
|
|
dateTop = qMin(dateTop, lowestInOneDayItemBottom - dateHeight);
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call the template callback function that was passed
|
|
|
|
// and return if it finished everything it needed.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!method(item, itemtop, dateTop)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Forget the found bottom of the pack, search for the next one from scratch.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!item->isInOneDayWithPrevious()) {
|
|
|
|
lowestInOneDayItemBottom = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
enumerateItems<EnumItemsDirection::BottomToTop>(dateCallback);
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
TextSelection HistoryInner::computeRenderSelection(
|
|
|
|
not_null<const SelectedItems*> selected,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto itemSelection = [&](not_null<HistoryItem*> item) {
|
|
|
|
auto i = selected->find(item);
|
|
|
|
if (i != selected->end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return TextSelection();
|
|
|
|
};
|
|
|
|
const auto group = item->Get<HistoryMessageGroup>();
|
|
|
|
if (group) {
|
|
|
|
if (group->leader != item) {
|
|
|
|
return TextSelection();
|
|
|
|
}
|
|
|
|
auto result = TextSelection();
|
|
|
|
auto allFullSelected = true;
|
|
|
|
const auto count = int(group->others.size());
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
if (itemSelection(group->others[i]) == FullSelection) {
|
|
|
|
result = AddGroupItemSelection(result, i);
|
|
|
|
} else {
|
|
|
|
allFullSelected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto leaderSelection = itemSelection(item);
|
|
|
|
if (leaderSelection == FullSelection) {
|
|
|
|
return allFullSelected
|
|
|
|
? FullSelection
|
|
|
|
: AddGroupItemSelection(result, count);
|
|
|
|
} else if (leaderSelection != TextSelection()) {
|
|
|
|
return leaderSelection;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return itemSelection(item);
|
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
TextSelection HistoryInner::itemRenderSelection(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int selfromy,
|
|
|
|
int seltoy) const {
|
|
|
|
Expects(!item->detached());
|
|
|
|
|
|
|
|
const auto y = item->block()->y() + item->y();
|
|
|
|
if (y >= selfromy && y < seltoy) {
|
|
|
|
if (_dragSelecting && !item->serviceMsg() && item->id > 0) {
|
|
|
|
return FullSelection;
|
|
|
|
}
|
|
|
|
} else if (!_selected.empty()) {
|
2017-12-16 15:00:20 +00:00
|
|
|
return computeRenderSelection(&_selected, item);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
return TextSelection();
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::paintEvent(QPaintEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (Ui::skipPaintEvent(this, e)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hasPendingResizedItems()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Painter p(this);
|
2017-06-21 21:38:31 +00:00
|
|
|
auto clip = e->rect();
|
2017-04-08 13:27:53 +00:00
|
|
|
auto ms = getms();
|
|
|
|
|
|
|
|
bool historyDisplayedEmpty = (_history->isDisplayedEmpty() && (!_migrated || _migrated->isDisplayedEmpty()));
|
|
|
|
bool noHistoryDisplayed = _firstLoading || historyDisplayedEmpty;
|
|
|
|
if (!_firstLoading && _botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (clip.y() < _botAbout->rect.y() + _botAbout->rect.height() && clip.y() + clip.height() > _botAbout->rect.y()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
p.setTextPalette(st::inTextPalette);
|
|
|
|
App::roundRect(p, _botAbout->rect, st::msgInBg, MessageInCorners, &st::msgInShadow);
|
|
|
|
|
|
|
|
p.setFont(st::msgNameFont);
|
|
|
|
p.setPen(st::dialogsNameFg);
|
|
|
|
p.drawText(_botAbout->rect.left() + st::msgPadding.left(), _botAbout->rect.top() + st::msgPadding.top() + st::msgNameFont->ascent, lang(lng_bot_description));
|
|
|
|
|
|
|
|
p.setPen(st::historyTextInFg);
|
|
|
|
_botAbout->info->text.draw(p, _botAbout->rect.left() + st::msgPadding.left(), _botAbout->rect.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip, _botAbout->width);
|
|
|
|
|
|
|
|
p.restoreTextPalette();
|
|
|
|
}
|
|
|
|
} else if (noHistoryDisplayed) {
|
|
|
|
HistoryLayout::paintEmpty(p, width(), height());
|
|
|
|
}
|
|
|
|
if (!noHistoryDisplayed) {
|
2017-12-07 13:02:24 +00:00
|
|
|
auto readMentions = base::flat_set<not_null<HistoryItem*>>();
|
2017-08-11 07:16:07 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
adjustCurrent(clip.top());
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
auto drawToY = clip.y() + clip.height();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
auto selfromy = itemTop(_dragSelFrom);
|
|
|
|
auto seltoy = itemTop(_dragSelTo);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selfromy < 0 || seltoy < 0) {
|
|
|
|
selfromy = seltoy = -1;
|
|
|
|
} else {
|
|
|
|
seltoy += _dragSelTo->height();
|
|
|
|
}
|
|
|
|
|
2017-05-12 13:53:08 +00:00
|
|
|
auto mtop = migratedTop();
|
|
|
|
auto htop = historyTop();
|
|
|
|
auto hdrawtop = historyDrawTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (mtop >= 0) {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto iBlock = (_curHistory == _migrated ? _curBlock : (_migrated->blocks.size() - 1));
|
|
|
|
auto block = _migrated->blocks[iBlock];
|
|
|
|
auto iItem = (_curHistory == _migrated ? _curItem : (block->items.size() - 1));
|
|
|
|
auto item = block->items[iItem];
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-05-12 13:53:08 +00:00
|
|
|
auto y = mtop + block->y() + item->y();
|
2017-04-08 13:27:53 +00:00
|
|
|
p.save();
|
|
|
|
p.translate(0, y);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (clip.y() < y + item->height()) while (y < drawToY) {
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto selection = itemRenderSelection(
|
|
|
|
item,
|
|
|
|
selfromy - mtop,
|
|
|
|
seltoy - mtop);
|
|
|
|
item->draw(p, clip.translated(0, -y), selection, ms);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (item->hasViews()) {
|
|
|
|
App::main()->scheduleViewIncrement(item);
|
|
|
|
}
|
2017-08-11 07:16:07 +00:00
|
|
|
if (item->mentionsMe() && item->isMediaUnread()) {
|
|
|
|
readMentions.insert(item);
|
2017-08-25 15:17:46 +00:00
|
|
|
_widget->enqueueMessageHighlight(item);
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
int32 h = item->height();
|
|
|
|
p.translate(0, h);
|
|
|
|
y += h;
|
|
|
|
|
|
|
|
++iItem;
|
|
|
|
if (iItem == block->items.size()) {
|
|
|
|
iItem = 0;
|
|
|
|
++iBlock;
|
|
|
|
if (iBlock == _migrated->blocks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
block = _migrated->blocks[iBlock];
|
|
|
|
}
|
|
|
|
item = block->items[iItem];
|
|
|
|
}
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
if (htop >= 0) {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto iBlock = (_curHistory == _history ? _curBlock : 0);
|
|
|
|
auto block = _history->blocks[iBlock];
|
|
|
|
auto iItem = (_curHistory == _history ? _curItem : 0);
|
|
|
|
auto item = block->items[iItem];
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
auto hclip = clip.intersected(QRect(0, hdrawtop, width(), clip.top() + clip.height()));
|
2017-05-12 13:53:08 +00:00
|
|
|
auto y = htop + block->y() + item->y();
|
2017-04-08 13:27:53 +00:00
|
|
|
p.save();
|
|
|
|
p.translate(0, y);
|
|
|
|
while (y < drawToY) {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto h = item->height();
|
2017-12-15 16:25:47 +00:00
|
|
|
if (hclip.y() < y + h && hdrawtop < y + h) {
|
|
|
|
const auto selection = itemRenderSelection(
|
|
|
|
item,
|
|
|
|
selfromy - htop,
|
|
|
|
seltoy - htop);
|
|
|
|
item->draw(p, hclip.translated(0, -y), selection, ms);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (item->hasViews()) {
|
|
|
|
App::main()->scheduleViewIncrement(item);
|
|
|
|
}
|
2017-08-11 07:16:07 +00:00
|
|
|
if (item->mentionsMe() && item->isMediaUnread()) {
|
|
|
|
readMentions.insert(item);
|
2017-08-25 15:17:46 +00:00
|
|
|
_widget->enqueueMessageHighlight(item);
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
p.translate(0, h);
|
|
|
|
y += h;
|
|
|
|
|
|
|
|
++iItem;
|
|
|
|
if (iItem == block->items.size()) {
|
|
|
|
iItem = 0;
|
|
|
|
++iBlock;
|
|
|
|
if (iBlock == _history->blocks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
block = _history->blocks[iBlock];
|
|
|
|
}
|
|
|
|
item = block->items[iItem];
|
|
|
|
}
|
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
|
2017-08-11 07:16:07 +00:00
|
|
|
if (!readMentions.empty() && App::wnd()->doWeReadMentions()) {
|
|
|
|
App::main()->mediaMarkRead(readMentions);
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
if (mtop >= 0 || htop >= 0) {
|
2017-08-17 08:31:24 +00:00
|
|
|
enumerateUserpics([&p, &clip](not_null<HistoryMessage*> message, int userpicTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop the enumeration if the userpic is below the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (userpicTop >= clip.top() + clip.height()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// paint the userpic if it intersects the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (userpicTop + st::msgPhotoSize > clip.top()) {
|
2017-12-05 16:14:28 +00:00
|
|
|
message->displayFrom()->paintUserpicLeft(p, st::historyPhotoLeft, userpicTop, message->history()->width, st::msgPhotoSize);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
int dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top();
|
|
|
|
//QDate lastDate;
|
|
|
|
//if (!_history->isEmpty()) {
|
|
|
|
// lastDate = _history->blocks.back()->items.back()->date.date();
|
|
|
|
//}
|
|
|
|
|
|
|
|
//// if item top is before this value always show date as a floating date
|
|
|
|
//int showFloatingBefore = height() - 2 * (_visibleAreaBottom - _visibleAreaTop) - dateHeight;
|
|
|
|
|
|
|
|
auto scrollDateOpacity = _scrollDateOpacity.current(ms, _scrollDateShown ? 1. : 0.);
|
2017-08-17 08:31:24 +00:00
|
|
|
enumerateDates([&p, &clip, scrollDateOpacity, dateHeight/*, lastDate, showFloatingBefore*/](not_null<HistoryItem*> item, int itemtop, int dateTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop the enumeration if the date is above the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dateTop + dateHeight <= clip.top()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool displayDate = item->displayDate();
|
|
|
|
bool dateInPlace = displayDate;
|
|
|
|
if (dateInPlace) {
|
|
|
|
int correctDateTop = itemtop + st::msgServiceMargin.top();
|
|
|
|
dateInPlace = (dateTop < correctDateTop + dateHeight);
|
|
|
|
}
|
|
|
|
//bool noFloatingDate = (item->date.date() == lastDate && displayDate);
|
|
|
|
//if (noFloatingDate) {
|
|
|
|
// if (itemtop < showFloatingBefore) {
|
|
|
|
// noFloatingDate = false;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
// paint the date if it intersects the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dateTop < clip.top() + clip.height()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
auto opacity = (dateInPlace/* || noFloatingDate*/) ? 1. : scrollDateOpacity;
|
|
|
|
if (opacity > 0.) {
|
|
|
|
p.setOpacity(opacity);
|
|
|
|
int dateY = /*noFloatingDate ? itemtop :*/ (dateTop - st::msgServiceMargin.top());
|
|
|
|
int width = item->history()->width;
|
|
|
|
if (auto date = item->Get<HistoryMessageDate>()) {
|
|
|
|
date->paint(p, dateY, width);
|
|
|
|
} else {
|
|
|
|
HistoryLayout::ServiceMessagePainter::paintDate(p, item->date, dateY, width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
bool HistoryInner::eventHook(QEvent *e) {
|
|
|
|
if (e->type() == QEvent::TouchBegin
|
|
|
|
|| e->type() == QEvent::TouchUpdate
|
|
|
|
|| e->type() == QEvent::TouchEnd
|
|
|
|
|| e->type() == QEvent::TouchCancel) {
|
2017-04-08 13:27:53 +00:00
|
|
|
QTouchEvent *ev = static_cast<QTouchEvent*>(e);
|
|
|
|
if (ev->device()->type() == QTouchDevice::TouchScreen) {
|
|
|
|
touchEvent(ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
return RpWidget::eventHook(e);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onTouchScrollTimer() {
|
|
|
|
auto nowTime = getms();
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Acceleration && _touchWaitingAcceleration && (nowTime - _touchAccelerationTime) > 40) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
touchResetSpeed();
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Auto || _touchScrollState == Ui::TouchScrollState::Acceleration) {
|
|
|
|
int32 elapsed = int32(nowTime - _touchTime);
|
|
|
|
QPoint delta = _touchSpeed * elapsed / 1000;
|
|
|
|
bool hasScrolled = _widget->touchScroll(delta);
|
|
|
|
|
|
|
|
if (_touchSpeed.isNull() || !hasScrolled) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
_touchScroll = false;
|
|
|
|
_touchScrollTimer.stop();
|
|
|
|
} else {
|
|
|
|
_touchTime = nowTime;
|
|
|
|
}
|
|
|
|
touchDeaccelerate(elapsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchUpdateSpeed() {
|
|
|
|
const auto nowTime = getms();
|
|
|
|
if (_touchPrevPosValid) {
|
|
|
|
const int elapsed = nowTime - _touchSpeedTime;
|
|
|
|
if (elapsed) {
|
|
|
|
const QPoint newPixelDiff = (_touchPos - _touchPrevPos);
|
|
|
|
const QPoint pixelsPerSecond = newPixelDiff * (1000 / elapsed);
|
|
|
|
|
|
|
|
// fingers are inacurates, we ignore small changes to avoid stopping the autoscroll because
|
|
|
|
// of a small horizontal offset when scrolling vertically
|
|
|
|
const int newSpeedY = (qAbs(pixelsPerSecond.y()) > FingerAccuracyThreshold) ? pixelsPerSecond.y() : 0;
|
|
|
|
const int newSpeedX = (qAbs(pixelsPerSecond.x()) > FingerAccuracyThreshold) ? pixelsPerSecond.x() : 0;
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
|
|
|
const int oldSpeedY = _touchSpeed.y();
|
|
|
|
const int oldSpeedX = _touchSpeed.x();
|
|
|
|
if ((oldSpeedY <= 0 && newSpeedY <= 0) || ((oldSpeedY >= 0 && newSpeedY >= 0)
|
|
|
|
&& (oldSpeedX <= 0 && newSpeedX <= 0)) || (oldSpeedX >= 0 && newSpeedX >= 0)) {
|
|
|
|
_touchSpeed.setY(snap((oldSpeedY + (newSpeedY / 4)), -MaxScrollAccelerated, +MaxScrollAccelerated));
|
|
|
|
_touchSpeed.setX(snap((oldSpeedX + (newSpeedX / 4)), -MaxScrollAccelerated, +MaxScrollAccelerated));
|
|
|
|
} else {
|
|
|
|
_touchSpeed = QPoint();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we average the speed to avoid strange effects with the last delta
|
|
|
|
if (!_touchSpeed.isNull()) {
|
|
|
|
_touchSpeed.setX(snap((_touchSpeed.x() / 4) + (newSpeedX * 3 / 4), -MaxScrollFlick, +MaxScrollFlick));
|
|
|
|
_touchSpeed.setY(snap((_touchSpeed.y() / 4) + (newSpeedY * 3 / 4), -MaxScrollFlick, +MaxScrollFlick));
|
|
|
|
} else {
|
|
|
|
_touchSpeed = QPoint(newSpeedX, newSpeedY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_touchPrevPosValid = true;
|
|
|
|
}
|
|
|
|
_touchSpeedTime = nowTime;
|
|
|
|
_touchPrevPos = _touchPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchResetSpeed() {
|
|
|
|
_touchSpeed = QPoint();
|
|
|
|
_touchPrevPosValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchDeaccelerate(int32 elapsed) {
|
|
|
|
int32 x = _touchSpeed.x();
|
|
|
|
int32 y = _touchSpeed.y();
|
|
|
|
_touchSpeed.setX((x == 0) ? x : (x > 0) ? qMax(0, x - elapsed) : qMin(0, x + elapsed));
|
|
|
|
_touchSpeed.setY((y == 0) ? y : (y > 0) ? qMax(0, y - elapsed) : qMin(0, y + elapsed));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchEvent(QTouchEvent *e) {
|
|
|
|
const Qt::TouchPointStates &states(e->touchPointStates());
|
|
|
|
if (e->type() == QEvent::TouchCancel) { // cancel
|
|
|
|
if (!_touchInProgress) return;
|
|
|
|
_touchInProgress = false;
|
|
|
|
_touchSelectTimer.stop();
|
|
|
|
_touchScroll = _touchSelect = false;
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e->touchPoints().isEmpty()) {
|
|
|
|
_touchPrevPos = _touchPos;
|
|
|
|
_touchPos = e->touchPoints().cbegin()->screenPos().toPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (e->type()) {
|
2017-11-30 18:18:39 +00:00
|
|
|
case QEvent::TouchBegin: {
|
|
|
|
if (_menu) {
|
|
|
|
e->accept();
|
|
|
|
return; // ignore mouse press, that was hiding context menu
|
|
|
|
}
|
|
|
|
if (_touchInProgress) return;
|
|
|
|
if (e->touchPoints().isEmpty()) return;
|
|
|
|
|
|
|
|
_touchInProgress = true;
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Acceleration;
|
|
|
|
_touchWaitingAcceleration = true;
|
2017-04-08 13:27:53 +00:00
|
|
|
_touchAccelerationTime = getms();
|
2017-11-30 18:18:39 +00:00
|
|
|
touchUpdateSpeed();
|
|
|
|
_touchStart = _touchPos;
|
|
|
|
} else {
|
|
|
|
_touchScroll = false;
|
|
|
|
_touchSelectTimer.start(QApplication::startDragTime());
|
|
|
|
}
|
|
|
|
_touchSelect = false;
|
|
|
|
_touchStart = _touchPrevPos = _touchPos;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::TouchUpdate: {
|
|
|
|
if (!_touchInProgress) return;
|
|
|
|
if (_touchSelect) {
|
|
|
|
mouseActionUpdate(_touchPos);
|
|
|
|
} else if (!_touchScroll && (_touchPos - _touchStart).manhattanLength() >= QApplication::startDragDistance()) {
|
|
|
|
_touchSelectTimer.stop();
|
|
|
|
_touchScroll = true;
|
|
|
|
touchUpdateSpeed();
|
|
|
|
}
|
|
|
|
if (_touchScroll) {
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Manual) {
|
|
|
|
touchScrollUpdated(_touchPos);
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Acceleration) {
|
|
|
|
touchUpdateSpeed();
|
|
|
|
_touchAccelerationTime = getms();
|
|
|
|
if (_touchSpeed.isNull()) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:18:39 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::TouchEnd: {
|
|
|
|
if (!_touchInProgress) return;
|
|
|
|
_touchInProgress = false;
|
|
|
|
auto weak = make_weak(this);
|
|
|
|
if (_touchSelect) {
|
|
|
|
mouseActionFinish(_touchPos, Qt::RightButton);
|
|
|
|
QContextMenuEvent contextMenu(QContextMenuEvent::Mouse, mapFromGlobal(_touchPos), _touchPos);
|
|
|
|
showContextMenu(&contextMenu, true);
|
2017-04-08 13:27:53 +00:00
|
|
|
_touchScroll = false;
|
2017-11-30 18:18:39 +00:00
|
|
|
} else if (_touchScroll) {
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Manual) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Auto;
|
|
|
|
_touchPrevPosValid = false;
|
|
|
|
_touchScrollTimer.start(15);
|
|
|
|
_touchTime = getms();
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
_touchScroll = false;
|
|
|
|
touchResetSpeed();
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Acceleration) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Auto;
|
|
|
|
_touchWaitingAcceleration = false;
|
|
|
|
_touchPrevPosValid = false;
|
|
|
|
}
|
|
|
|
} else { // One short tap is like left mouse click.
|
|
|
|
mouseActionStart(_touchPos, Qt::LeftButton);
|
|
|
|
mouseActionFinish(_touchPos, Qt::LeftButton);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-11-30 18:18:39 +00:00
|
|
|
if (weak) {
|
|
|
|
_touchSelectTimer.stop();
|
|
|
|
_touchSelect = false;
|
|
|
|
}
|
|
|
|
} break;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mouseMoveEvent(QMouseEvent *e) {
|
2017-05-16 13:41:47 +00:00
|
|
|
static auto lastGlobalPosition = e->globalPos();
|
|
|
|
auto reallyMoved = (lastGlobalPosition != e->globalPos());
|
2017-04-08 13:27:53 +00:00
|
|
|
auto buttonsPressed = (e->buttons() & (Qt::LeftButton | Qt::MiddleButton));
|
2017-06-21 21:38:31 +00:00
|
|
|
if (!buttonsPressed && _mouseAction != MouseAction::None) {
|
2017-04-08 13:27:53 +00:00
|
|
|
mouseReleaseEvent(e);
|
|
|
|
}
|
2017-05-16 13:41:47 +00:00
|
|
|
if (reallyMoved) {
|
|
|
|
lastGlobalPosition = e->globalPos();
|
|
|
|
if (!buttonsPressed || (_scrollDateLink && ClickHandler::getPressed() == _scrollDateLink)) {
|
|
|
|
keepScrollDateForNow();
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(e->globalPos());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionUpdate(const QPoint &screenPos) {
|
|
|
|
_mousePosition = screenPos;
|
2017-04-08 13:27:53 +00:00
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchScrollUpdated(const QPoint &screenPos) {
|
|
|
|
_touchPos = screenPos;
|
|
|
|
_widget->touchScroll(_touchPos - _touchPrevPos);
|
|
|
|
touchUpdateSpeed();
|
|
|
|
}
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
QPoint HistoryInner::mapPointToItem(QPoint p, HistoryItem *item) {
|
2017-04-08 13:27:53 +00:00
|
|
|
int32 msgy = itemTop(item);
|
|
|
|
if (msgy < 0) return QPoint(0, 0);
|
|
|
|
|
|
|
|
p.setY(p.y() - msgy);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (_menu) {
|
|
|
|
e->accept();
|
|
|
|
return; // ignore mouse press, that was hiding context menu
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionStart(e->globalPos(), e->button());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton button) {
|
|
|
|
mouseActionUpdate(screenPos);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (button != Qt::LeftButton) return;
|
|
|
|
|
|
|
|
ClickHandler::pressed();
|
|
|
|
if (App::pressedItem() != App::hoveredItem()) {
|
|
|
|
repaintItem(App::pressedItem());
|
|
|
|
App::pressedItem(App::hoveredItem());
|
|
|
|
repaintItem(App::pressedItem());
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
_mouseActionItem = App::mousedItem();
|
2017-06-21 23:54:38 +00:00
|
|
|
_dragStartPosition = mapPointToItem(mapFromGlobal(screenPos), _mouseActionItem);
|
2017-06-21 21:38:31 +00:00
|
|
|
_pressWasInactive = _controller->window()->wasInactivePress();
|
|
|
|
if (_pressWasInactive) _controller->window()->setInactivePress(false);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (ClickHandler::getPressed()) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareDrag;
|
2017-10-05 15:35:52 +00:00
|
|
|
} else if (!_selected.empty()) {
|
|
|
|
if (_selected.cbegin()->second == FullSelection) {
|
2017-12-15 16:25:47 +00:00
|
|
|
if (_dragStateItem
|
|
|
|
&& _selected.find(_dragStateItem) != _selected.cend()
|
|
|
|
&& App::hoveredItem()) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareDrag; // start items drag
|
|
|
|
} else if (!_pressWasInactive) {
|
|
|
|
_mouseAction = MouseAction::PrepareSelect; // start items select
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::None && _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
HistoryTextState dragState;
|
|
|
|
if (_trippleClickTimer.isActive() && (screenPos - _trippleClickPoint).manhattanLength() < QApplication::startDragDistance()) {
|
|
|
|
HistoryStateRequest request;
|
|
|
|
request.flags = Text::StateRequest::Flag::LookupSymbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
dragState = _mouseActionItem->getState(_dragStartPosition, request);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.cursor == HistoryInTextCursorState) {
|
|
|
|
TextSelection selStatus = { dragState.symbol, dragState.symbol };
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selStatus != FullSelection && (_selected.empty() || _selected.cbegin()->second != FullSelection)) {
|
|
|
|
if (!_selected.empty()) {
|
|
|
|
repaintItem(_selected.cbegin()->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(_mouseActionItem, selStatus);
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseTextSymbol = dragState.symbol;
|
|
|
|
_mouseAction = MouseAction::Selecting;
|
|
|
|
_mouseSelectType = TextSelectType::Paragraphs;
|
|
|
|
mouseActionUpdate(_mousePosition);
|
2017-04-08 13:27:53 +00:00
|
|
|
_trippleClickTimer.start(QApplication::doubleClickInterval());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (App::pressedItem()) {
|
|
|
|
HistoryStateRequest request;
|
|
|
|
request.flags = Text::StateRequest::Flag::LookupSymbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
dragState = _mouseActionItem->getState(_dragStartPosition, request);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseSelectType != TextSelectType::Paragraphs) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (App::pressedItem()) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseTextSymbol = dragState.symbol;
|
2017-04-08 13:27:53 +00:00
|
|
|
bool uponSelected = (dragState.cursor == HistoryInTextCursorState);
|
|
|
|
if (uponSelected) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty()
|
|
|
|
|| _selected.cbegin()->second == FullSelection
|
|
|
|
|| _selected.cbegin()->first != _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = false;
|
|
|
|
} else {
|
2017-10-05 15:35:52 +00:00
|
|
|
uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseTextSymbol < selFrom || _mouseTextSymbol >= selTo) {
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uponSelected) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareDrag; // start text drag
|
|
|
|
} else if (!_pressWasInactive) {
|
|
|
|
if (dynamic_cast<HistorySticker*>(App::pressedItem()->getMedia()) || _mouseCursorState == HistoryInDateCursorState) {
|
|
|
|
_mouseAction = MouseAction::PrepareDrag; // start sticker drag or by-date drag
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dragState.afterSymbol) ++_mouseTextSymbol;
|
|
|
|
TextSelection selStatus = { _mouseTextSymbol, _mouseTextSymbol };
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selStatus != FullSelection && (_selected.empty() || _selected.cbegin()->second != FullSelection)) {
|
|
|
|
if (!_selected.empty()) {
|
|
|
|
repaintItem(_selected.cbegin()->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(_mouseActionItem, selStatus);
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::Selecting;
|
|
|
|
repaintItem(_mouseActionItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareSelect;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (!_pressWasInactive) {
|
|
|
|
_mouseAction = MouseAction::PrepareSelect; // start items select
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (!_mouseActionItem) {
|
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
} else if (_mouseAction == MouseAction::None) {
|
|
|
|
_mouseActionItem = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionCancel() {
|
|
|
|
_mouseActionItem = nullptr;
|
2017-12-15 16:25:47 +00:00
|
|
|
_dragStateItem = nullptr;
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
_dragStartPosition = QPoint(0, 0);
|
|
|
|
_dragSelFrom = _dragSelTo = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
_wasSelectedText = false;
|
|
|
|
_widget->noSelectingScroll();
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::performDrag() {
|
|
|
|
if (_mouseAction != MouseAction::Dragging) return;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
bool uponSelected = false;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseActionItem) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && _selected.cbegin()->second == FullSelection) {
|
2017-12-15 16:25:47 +00:00
|
|
|
uponSelected = _dragStateItem
|
|
|
|
&& (_selected.find(_dragStateItem) != _selected.cend());
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
HistoryStateRequest request;
|
|
|
|
request.flags |= Text::StateRequest::Flag::LookupSymbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
auto dragState = _mouseActionItem->getState(_dragStartPosition, request);
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = (dragState.cursor == HistoryInTextCursorState);
|
|
|
|
if (uponSelected) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty()
|
|
|
|
|| _selected.cbegin()->second == FullSelection
|
|
|
|
|| _selected.cbegin()->first != _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = false;
|
|
|
|
} else {
|
2017-10-05 15:35:52 +00:00
|
|
|
uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.symbol < selFrom || dragState.symbol >= selTo) {
|
|
|
|
uponSelected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto pressedHandler = ClickHandler::getPressed();
|
|
|
|
|
|
|
|
if (dynamic_cast<VoiceSeekClickHandler*>(pressedHandler.data())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities sel;
|
|
|
|
QList<QUrl> urls;
|
|
|
|
if (uponSelected) {
|
|
|
|
sel = getSelectedText();
|
|
|
|
} else if (pressedHandler) {
|
|
|
|
sel = { pressedHandler->dragText(), EntitiesInText() };
|
|
|
|
//if (!sel.isEmpty() && sel.at(0) != '/' && sel.at(0) != '@' && sel.at(0) != '#') {
|
|
|
|
// urls.push_back(QUrl::fromEncoded(sel.toUtf8())); // Google Chrome crashes in Mac OS X O_o
|
|
|
|
//}
|
|
|
|
}
|
2017-06-22 01:31:02 +00:00
|
|
|
if (auto mimeData = MimeDataFromTextWithEntities(sel)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
updateDragSelection(0, 0, false);
|
|
|
|
_widget->noSelectingScroll();
|
|
|
|
|
|
|
|
if (!urls.isEmpty()) mimeData->setUrls(urls);
|
2017-04-27 21:17:00 +00:00
|
|
|
if (uponSelected && !Adaptive::OneColumn()) {
|
|
|
|
auto selectedState = getSelectionState();
|
|
|
|
if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) {
|
|
|
|
mimeData->setData(qsl("application/x-td-forward-selected"), "1");
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
_controller->window()->launchDrag(std::move(mimeData));
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
auto forwardMimeType = QString();
|
|
|
|
auto pressedMedia = static_cast<HistoryMedia*>(nullptr);
|
|
|
|
if (auto pressedItem = App::pressedItem()) {
|
|
|
|
pressedMedia = pressedItem->getMedia();
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseCursorState == HistoryInDateCursorState || (pressedMedia && pressedMedia->dragItem())) {
|
2017-04-08 13:27:53 +00:00
|
|
|
forwardMimeType = qsl("application/x-td-forward-pressed");
|
|
|
|
}
|
|
|
|
}
|
2017-12-16 07:20:04 +00:00
|
|
|
if (const auto pressedLnkItem = _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if ((pressedMedia = pressedLnkItem->getMedia())) {
|
|
|
|
if (forwardMimeType.isEmpty() && pressedMedia->dragItemByHandler(pressedHandler)) {
|
|
|
|
forwardMimeType = qsl("application/x-td-forward-pressed-link");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!forwardMimeType.isEmpty()) {
|
|
|
|
auto mimeData = std::make_unique<QMimeData>();
|
|
|
|
mimeData->setData(forwardMimeType, "1");
|
|
|
|
if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
|
|
|
|
auto filepath = document->filepath(DocumentData::FilePathResolveChecked);
|
|
|
|
if (!filepath.isEmpty()) {
|
|
|
|
QList<QUrl> urls;
|
|
|
|
urls.push_back(QUrl::fromLocalFile(filepath));
|
|
|
|
mimeData->setUrls(urls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
// This call enters event loop and can destroy any QObject.
|
|
|
|
_controller->window()->launchDrag(std::move(mimeData));
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
void HistoryInner::itemRemoved(not_null<const HistoryItem*> item) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_history != item->history() && _migrated != item->history()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!App::main()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto i = _selected.find(item);
|
|
|
|
if (i != _selected.cend()) {
|
|
|
|
_selected.erase(i);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseActionItem == item) {
|
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
if (_dragStateItem == item) {
|
|
|
|
_dragStateItem = nullptr;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (_dragSelFrom == item || _dragSelTo == item) {
|
|
|
|
_dragSelFrom = 0;
|
|
|
|
_dragSelTo = 0;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton button) {
|
|
|
|
mouseActionUpdate(screenPos);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
auto activated = ClickHandler::unpressed();
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Dragging) {
|
2017-04-08 13:27:53 +00:00
|
|
|
activated.clear();
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if (_mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// if we are in selecting items mode perhaps we want to
|
|
|
|
// toggle selection instead of activating the pressed link
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_mouseAction == MouseAction::PrepareDrag && !_pressWasInactive && !_selected.empty() && _selected.cbegin()->second == FullSelection && button != Qt::RightButton) {
|
2017-12-15 16:25:47 +00:00
|
|
|
if (auto media = _mouseActionItem->getMedia()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (media->toggleSelectionByHandlerClick(activated)) {
|
|
|
|
activated.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (App::pressedItem()) {
|
|
|
|
repaintItem(App::pressedItem());
|
|
|
|
App::pressedItem(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
_wasSelectedText = false;
|
|
|
|
|
|
|
|
if (activated) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
App::activateClickHandler(activated, button);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
if ((_mouseAction == MouseAction::PrepareSelect)
|
|
|
|
&& !_pressWasInactive
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& (_selected.cbegin()->second == FullSelection)) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(
|
2017-12-15 16:25:47 +00:00
|
|
|
&_selected,
|
|
|
|
_mouseActionItem,
|
|
|
|
SelectAction::Invert);
|
2017-06-21 21:38:31 +00:00
|
|
|
repaintItem(_mouseActionItem);
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if ((_mouseAction == MouseAction::PrepareDrag)
|
|
|
|
&& !_pressWasInactive
|
|
|
|
&& _dragStateItem
|
|
|
|
&& (button != Qt::RightButton)) {
|
|
|
|
auto i = _selected.find(_dragStateItem);
|
2017-10-05 15:35:52 +00:00
|
|
|
if (i != _selected.cend() && i->second == FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.erase(i);
|
2017-06-21 21:38:31 +00:00
|
|
|
repaintItem(_mouseActionItem);
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if ((i == _selected.cend())
|
|
|
|
&& !_dragStateItem->serviceMsg()
|
|
|
|
&& (_dragStateItem->id > 0)
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& _selected.cbegin()->second == FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_selected.size() < MaxSelectedItems) {
|
2017-12-15 16:25:47 +00:00
|
|
|
_selected.emplace(_dragStateItem, FullSelection);
|
2017-06-21 21:38:31 +00:00
|
|
|
repaintItem(_mouseActionItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_selected.clear();
|
|
|
|
update();
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseAction == MouseAction::Selecting) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_dragSelFrom && _dragSelTo) {
|
|
|
|
applyDragSelection();
|
|
|
|
_dragSelFrom = _dragSelTo = 0;
|
2017-10-05 15:35:52 +00:00
|
|
|
} else if (!_selected.empty() && !_pressWasInactive) {
|
|
|
|
auto sel = _selected.cbegin()->second;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (sel != FullSelection && sel.from == sel.to) {
|
|
|
|
_selected.clear();
|
2017-06-21 21:38:31 +00:00
|
|
|
App::wnd()->setInnerFocus();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
_mouseActionItem = nullptr;
|
|
|
|
_mouseSelectType = TextSelectType::Letters;
|
2017-04-08 13:27:53 +00:00
|
|
|
_widget->noSelectingScroll();
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
|
|
|
|
#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && _selected.cbegin()->second != FullSelection) {
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto [item, selection] = *_selected.cbegin();
|
|
|
|
setToClipboard(item->selectedText(selection), QClipboard::Selection);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
#endif // Q_OS_LINUX32 || Q_OS_LINUX64
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mouseReleaseEvent(QMouseEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionFinish(e->globalPos(), e->button());
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!rect().contains(e->pos())) {
|
|
|
|
leaveEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mouseDoubleClickEvent(QMouseEvent *e) {
|
|
|
|
if (!_history) return;
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionStart(e->globalPos(), e->button());
|
2017-10-05 15:35:52 +00:00
|
|
|
if (((_mouseAction == MouseAction::Selecting && !_selected.empty() && _selected.cbegin()->second != FullSelection) || (_mouseAction == MouseAction::None && (_selected.empty() || _selected.cbegin()->second != FullSelection))) && _mouseSelectType == TextSelectType::Letters && _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
HistoryStateRequest request;
|
|
|
|
request.flags |= Text::StateRequest::Flag::LookupSymbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
auto dragState = _mouseActionItem->getState(_dragStartPosition, request);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.cursor == HistoryInTextCursorState) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseTextSymbol = dragState.symbol;
|
|
|
|
_mouseSelectType = TextSelectType::Words;
|
|
|
|
if (_mouseAction == MouseAction::None) {
|
|
|
|
_mouseAction = MouseAction::Selecting;
|
2017-04-08 13:27:53 +00:00
|
|
|
TextSelection selStatus = { dragState.symbol, dragState.symbol };
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty()) {
|
|
|
|
repaintItem(_selected.cbegin()->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(_mouseActionItem, selStatus);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
mouseMoveEvent(e);
|
|
|
|
|
|
|
|
_trippleClickPoint = e->globalPos();
|
|
|
|
_trippleClickTimer.start(QApplication::doubleClickInterval());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-15 21:05:57 +00:00
|
|
|
void HistoryInner::contextMenuEvent(QContextMenuEvent *e) {
|
|
|
|
showContextMenu(e);
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
|
|
|
if (_menu) {
|
|
|
|
_menu->deleteLater();
|
2017-06-24 10:11:29 +00:00
|
|
|
_menu = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (e->reason() == QContextMenuEvent::Mouse) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(e->globalPos());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
2017-12-06 14:15:41 +00:00
|
|
|
auto canSendMessages = _peer->canWrite();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
// -2 - has full selected items, but not over, -1 - has selection, but no over, 0 - no selection, 1 - over text, 2 - over full selected items
|
2017-06-24 10:11:29 +00:00
|
|
|
auto isUponSelected = 0;
|
|
|
|
auto hasSelected = 0;;
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
isUponSelected = -1;
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.cbegin()->second == FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
hasSelected = 2;
|
2017-12-15 18:36:28 +00:00
|
|
|
if (_dragStateItem && _selected.find(_dragStateItem) != _selected.cend()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
isUponSelected = 2;
|
|
|
|
} else {
|
|
|
|
isUponSelected = -2;
|
|
|
|
}
|
|
|
|
} else {
|
2017-10-05 15:35:52 +00:00
|
|
|
uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to;
|
2017-04-08 13:27:53 +00:00
|
|
|
hasSelected = (selTo > selFrom) ? 1 : 0;
|
|
|
|
if (App::mousedItem() && App::mousedItem() == App::hoveredItem()) {
|
2017-06-21 23:54:38 +00:00
|
|
|
auto mousePos = mapPointToItem(mapFromGlobal(_mousePosition), App::mousedItem());
|
2017-04-08 13:27:53 +00:00
|
|
|
HistoryStateRequest request;
|
|
|
|
request.flags |= Text::StateRequest::Flag::LookupSymbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
auto dragState = App::mousedItem()->getState(mousePos, request);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.cursor == HistoryInTextCursorState && dragState.symbol >= selFrom && dragState.symbol < selTo) {
|
|
|
|
isUponSelected = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showFromTouch && hasSelected && isUponSelected < hasSelected) {
|
|
|
|
isUponSelected = hasSelected;
|
|
|
|
}
|
|
|
|
|
|
|
|
_menu = new Ui::PopupMenu(nullptr);
|
|
|
|
|
2017-06-24 10:11:29 +00:00
|
|
|
_contextMenuLink = ClickHandler::getActive();
|
2017-12-15 16:25:47 +00:00
|
|
|
auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(_contextMenuLink.data());
|
|
|
|
auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data());
|
2017-12-10 10:26:58 +00:00
|
|
|
auto lnkIsVideo = lnkDocument ? lnkDocument->document()->isVideoFile() : false;
|
|
|
|
auto lnkIsVoice = lnkDocument ? lnkDocument->document()->isVoiceMessage() : false;
|
|
|
|
auto lnkIsAudio = lnkDocument ? lnkDocument->document()->isAudioFile() : false;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (lnkPhoto || lnkDocument) {
|
2017-12-16 12:13:08 +00:00
|
|
|
const auto item = _dragStateItem;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (isUponSelected > 0) {
|
2017-06-29 08:12:23 +00:00
|
|
|
_menu->addAction(lang((isUponSelected > 1) ? lng_context_copy_selected_items : lng_context_copy_selected), this, SLOT(copySelectedText()))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (item && item->id > 0 && isUponSelected != 2 && isUponSelected != -2) {
|
|
|
|
if (canSendMessages) {
|
|
|
|
_menu->addAction(lang(lng_context_reply_msg), _widget, SLOT(onReplyToMessage()));
|
|
|
|
}
|
|
|
|
if (item->canEdit(::date(unixtime()))) {
|
|
|
|
_menu->addAction(lang(lng_context_edit_msg), _widget, SLOT(onEditMessage()));
|
|
|
|
}
|
|
|
|
if (item->canPin()) {
|
2017-11-21 13:23:56 +00:00
|
|
|
auto isPinned = item->isPinned();
|
|
|
|
_menu->addAction(lang(isPinned ? lng_context_unpin_msg : lng_context_pin_msg), _widget, isPinned ? SLOT(onUnpinMessage()) : SLOT(onPinMessage()));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-16 12:13:08 +00:00
|
|
|
App::contextItem(item);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (lnkPhoto) {
|
|
|
|
_menu->addAction(lang(lng_context_save_image), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, photo = lnkPhoto->photo()] {
|
|
|
|
savePhotoToFile(photo);
|
|
|
|
}))->setEnabled(true);
|
2017-06-24 10:11:29 +00:00
|
|
|
_menu->addAction(lang(lng_context_copy_image), [this, photo = lnkPhoto->photo()] {
|
|
|
|
copyContextImage(photo);
|
|
|
|
})->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
auto document = lnkDocument->document();
|
|
|
|
if (document->loading()) {
|
|
|
|
_menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
if (document->loaded() && document->isGifv()) {
|
2017-05-18 13:22:57 +00:00
|
|
|
if (!cAutoPlayGif()) {
|
|
|
|
_menu->addAction(lang(lng_context_open_gif), this, SLOT(openContextGif()))->setEnabled(true);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
_menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true);
|
|
|
|
}
|
|
|
|
if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
|
|
|
|
_menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true);
|
|
|
|
}
|
2017-12-10 10:26:58 +00:00
|
|
|
_menu->addAction(lang(lnkIsVideo ? lng_context_save_video : (lnkIsVoice ? lng_context_save_audio : (lnkIsAudio ? lng_context_save_audio_file : lng_context_save_file))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
2017-04-08 13:27:53 +00:00
|
|
|
saveDocumentToFile(document);
|
|
|
|
}))->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
|
2017-07-11 17:21:24 +00:00
|
|
|
_menu->addAction(lang(item->history()->peer->isMegagroup() ? lng_context_copy_link : lng_context_copy_post_link), _widget, SLOT(onCopyPostLink()));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (isUponSelected > 1) {
|
2017-04-27 21:17:00 +00:00
|
|
|
if (selectedState.count > 0 && selectedState.canForwardCount == selectedState.count) {
|
|
|
|
_menu->addAction(lang(lng_context_forward_selected), _widget, SLOT(onForwardSelected()));
|
|
|
|
}
|
|
|
|
if (selectedState.count > 0 && selectedState.canDeleteCount == selectedState.count) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_menu->addAction(lang(lng_context_delete_selected), base::lambda_guarded(this, [this] {
|
|
|
|
_widget->confirmDeleteSelectedItems();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
_menu->addAction(lang(lng_context_clear_selection), _widget, SLOT(onClearSelected()));
|
2017-12-16 12:13:08 +00:00
|
|
|
} else if (item) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (isUponSelected != -2) {
|
2017-12-16 12:13:08 +00:00
|
|
|
if (item->canForward()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
_menu->addAction(lang(lng_context_forward_msg), base::lambda_guarded(this, [this] {
|
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
forwardItem(item);
|
|
|
|
}
|
|
|
|
}))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-16 12:13:08 +00:00
|
|
|
if (item->canDelete()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_menu->addAction(lang(lng_context_delete_msg), base::lambda_guarded(this, [this] {
|
2017-12-15 18:36:28 +00:00
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
deleteItem(item);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
2017-12-16 12:13:08 +00:00
|
|
|
if (item && item->id > 0 && !item->serviceMsg()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
_menu->addAction(lang(lng_context_select_msg), base::lambda_guarded(this, [this] {
|
2017-12-15 18:36:28 +00:00
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
if (!item->detached()) {
|
|
|
|
changeSelection(&_selected, item, SelectAction::Select);
|
|
|
|
repaintItem(item);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
}))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-16 12:13:08 +00:00
|
|
|
App::contextItem(item);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else { // maybe cursor on some text history item?
|
2017-12-16 12:13:08 +00:00
|
|
|
auto item = App::hoveredItem()
|
|
|
|
? App::hoveredItem()
|
|
|
|
: App::hoveredLinkItem();
|
2017-12-17 07:25:02 +00:00
|
|
|
if (const auto group = item ? item->getFullGroup() : nullptr) {
|
2017-12-16 12:13:08 +00:00
|
|
|
item = group->others.empty()
|
|
|
|
? group->leader
|
|
|
|
: group->others.front().get();
|
|
|
|
}
|
2017-12-17 07:25:02 +00:00
|
|
|
const auto canDelete = item
|
|
|
|
&& item->canDelete()
|
|
|
|
&& (item->id > 0 || !item->serviceMsg());
|
|
|
|
const auto canForward = item
|
|
|
|
&& item->canForward();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-04-27 21:17:00 +00:00
|
|
|
auto msg = dynamic_cast<HistoryMessage*>(item);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (isUponSelected > 0) {
|
2017-06-29 08:12:23 +00:00
|
|
|
_menu->addAction(lang((isUponSelected > 1) ? lng_context_copy_selected_items : lng_context_copy_selected), this, SLOT(copySelectedText()))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (item && item->id > 0 && isUponSelected != 2) {
|
|
|
|
if (canSendMessages) {
|
|
|
|
_menu->addAction(lang(lng_context_reply_msg), _widget, SLOT(onReplyToMessage()));
|
|
|
|
}
|
|
|
|
if (item->canEdit(::date(unixtime()))) {
|
|
|
|
_menu->addAction(lang(lng_context_edit_msg), _widget, SLOT(onEditMessage()));
|
|
|
|
}
|
|
|
|
if (item->canPin()) {
|
2017-11-21 13:23:56 +00:00
|
|
|
auto isPinned = item->isPinned();
|
|
|
|
_menu->addAction(lang(isPinned ? lng_context_unpin_msg : lng_context_pin_msg), _widget, isPinned ? SLOT(onUnpinMessage()) : SLOT(onPinMessage()));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (item && item->id > 0 && isUponSelected != -2) {
|
|
|
|
if (canSendMessages) {
|
|
|
|
_menu->addAction(lang(lng_context_reply_msg), _widget, SLOT(onReplyToMessage()));
|
|
|
|
}
|
|
|
|
if (item->canEdit(::date(unixtime()))) {
|
|
|
|
_menu->addAction(lang(lng_context_edit_msg), _widget, SLOT(onEditMessage()));
|
|
|
|
}
|
|
|
|
if (item->canPin()) {
|
2017-11-21 13:23:56 +00:00
|
|
|
auto isPinned = item->isPinned();
|
|
|
|
_menu->addAction(lang(isPinned ? lng_context_unpin_msg : lng_context_pin_msg), _widget, isPinned ? SLOT(onUnpinMessage()) : SLOT(onPinMessage()));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item && !isUponSelected) {
|
|
|
|
auto mediaHasTextForCopy = false;
|
|
|
|
if (auto media = (msg ? msg->getMedia() : nullptr)) {
|
|
|
|
mediaHasTextForCopy = media->hasTextForCopy();
|
|
|
|
if (media->type() == MediaTypeWebPage && static_cast<HistoryWebPage*>(media)->attach()) {
|
|
|
|
media = static_cast<HistoryWebPage*>(media)->attach();
|
|
|
|
}
|
|
|
|
if (media->type() == MediaTypeSticker) {
|
|
|
|
if (auto document = media->getDocument()) {
|
|
|
|
if (document->sticker() && document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
|
2017-08-02 20:57:49 +00:00
|
|
|
_menu->addAction(lang(document->sticker()->setInstalled() ? lng_context_pack_info : lng_context_pack_add), [this, document] { showStickerPackInfo(document); });
|
|
|
|
_menu->addAction(lang(Stickers::IsFaved(document) ? lng_faved_stickers_remove : lng_faved_stickers_add), [this, document] { toggleFavedSticker(document); });
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
_menu->addAction(lang(lng_context_save_image), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
|
|
|
saveDocumentToFile(document);
|
|
|
|
}))->setEnabled(true);
|
|
|
|
}
|
2017-06-24 10:11:29 +00:00
|
|
|
} else if (media->type() == MediaTypeGif && !_contextMenuLink) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (auto document = media->getDocument()) {
|
|
|
|
if (document->loading()) {
|
|
|
|
_menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
if (document->isGifv()) {
|
2017-05-18 13:22:57 +00:00
|
|
|
if (!cAutoPlayGif()) {
|
|
|
|
_menu->addAction(lang(lng_context_open_gif), this, SLOT(openContextGif()))->setEnabled(true);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
_menu->addAction(lang(lng_context_save_gif), this, SLOT(saveContextGif()))->setEnabled(true);
|
|
|
|
}
|
|
|
|
if (!document->filepath(DocumentData::FilePathResolveChecked).isEmpty()) {
|
|
|
|
_menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true);
|
|
|
|
}
|
|
|
|
_menu->addAction(lang(lng_context_save_file), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, document] {
|
|
|
|
saveDocumentToFile(document);
|
|
|
|
}))->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 10:11:29 +00:00
|
|
|
if (msg && !_contextMenuLink && (!msg->emptyText() || mediaHasTextForCopy)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_menu->addAction(lang(lng_context_copy_text), this, SLOT(copyContextText()))->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-24 10:11:29 +00:00
|
|
|
auto linkCopyToClipboardText = _contextMenuLink ? _contextMenuLink->copyToClipboardContextItemText() : QString();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!linkCopyToClipboardText.isEmpty()) {
|
|
|
|
_menu->addAction(linkCopyToClipboardText, this, SLOT(copyContextUrl()))->setEnabled(true);
|
|
|
|
}
|
2017-07-14 09:51:02 +00:00
|
|
|
if (linkCopyToClipboardText.isEmpty()) {
|
|
|
|
if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
|
|
|
|
_menu->addAction(lang(item->history()->peer->isMegagroup() ? lng_context_copy_link : lng_context_copy_post_link), _widget, SLOT(onCopyPostLink()));
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (isUponSelected > 1) {
|
2017-04-27 21:17:00 +00:00
|
|
|
if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) {
|
|
|
|
_menu->addAction(lang(lng_context_forward_selected), _widget, SLOT(onForwardSelected()));
|
|
|
|
}
|
|
|
|
if (selectedState.count > 0 && selectedState.count == selectedState.canDeleteCount) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_menu->addAction(lang(lng_context_delete_selected), base::lambda_guarded(this, [this] {
|
|
|
|
_widget->confirmDeleteSelectedItems();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
_menu->addAction(lang(lng_context_clear_selection), _widget, SLOT(onClearSelected()));
|
|
|
|
} else if (item && ((isUponSelected != -2 && (canForward || canDelete)) || item->id > 0)) {
|
|
|
|
if (isUponSelected != -2) {
|
|
|
|
if (canForward) {
|
2017-12-15 18:36:28 +00:00
|
|
|
_menu->addAction(lang(lng_context_forward_msg), base::lambda_guarded(this, [this] {
|
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
forwardAsGroup(item);
|
|
|
|
}
|
|
|
|
}))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (canDelete) {
|
|
|
|
_menu->addAction(lang((msg && msg->uploading()) ? lng_context_cancel_upload : lng_context_delete_msg), base::lambda_guarded(this, [this] {
|
2017-12-15 18:36:28 +00:00
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
deleteAsGroup(item);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item->id > 0 && !item->serviceMsg()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
_menu->addAction(lang(lng_context_select_msg), base::lambda_guarded(this, [this] {
|
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
if (!item->detached()) {
|
|
|
|
changeSelectionAsGroup(&_selected, item, SelectAction::Select);
|
|
|
|
repaintItem(item);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (App::mousedItem() && !App::mousedItem()->serviceMsg() && App::mousedItem()->id > 0) {
|
2017-12-15 18:36:28 +00:00
|
|
|
_menu->addAction(lang(lng_context_select_msg), base::lambda_guarded(this, [this] {
|
|
|
|
if (const auto item = App::contextItem()) {
|
|
|
|
if (!item->detached()) {
|
|
|
|
changeSelectionAsGroup(&_selected, item, SelectAction::Select);
|
|
|
|
repaintItem(item);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}))->setEnabled(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
item = App::mousedItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
App::contextItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_menu->actions().isEmpty()) {
|
|
|
|
delete _menu;
|
|
|
|
_menu = 0;
|
|
|
|
} else {
|
|
|
|
connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroy(QObject*)));
|
|
|
|
_menu->popup(e->globalPos());
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onMenuDestroy(QObject *obj) {
|
|
|
|
if (_menu == obj) {
|
|
|
|
_menu = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::copySelectedText() {
|
|
|
|
setToClipboard(getSelectedText());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::copyContextUrl() {
|
2017-06-24 10:11:29 +00:00
|
|
|
if (_contextMenuLink) {
|
|
|
|
_contextMenuLink->copyToClipboard();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::savePhotoToFile(PhotoData *photo) {
|
|
|
|
if (!photo || !photo->date || !photo->loaded()) return;
|
|
|
|
|
|
|
|
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
|
|
|
FileDialog::GetWritePath(lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")), base::lambda_guarded(this, [this, photo](const QString &result) {
|
|
|
|
if (!result.isEmpty()) {
|
|
|
|
photo->full->pix().toImage().save(result, "JPG");
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-06-24 10:11:29 +00:00
|
|
|
void HistoryInner::copyContextImage(PhotoData *photo) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!photo || !photo->date || !photo->loaded()) return;
|
|
|
|
|
|
|
|
QApplication::clipboard()->setPixmap(photo->full->pix());
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
void HistoryInner::showStickerPackInfo(DocumentData *document) {
|
|
|
|
if (auto sticker = document->sticker()) {
|
|
|
|
if (sticker->set.type() != mtpc_inputStickerSetEmpty) {
|
|
|
|
App::main()->stickersBox(sticker->set);
|
2017-06-24 10:11:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
void HistoryInner::toggleFavedSticker(DocumentData *document) {
|
|
|
|
auto unfave = Stickers::IsFaved(document);
|
|
|
|
MTP::send(MTPmessages_FaveSticker(document->mtpInput(), MTP_bool(unfave)), rpcDone([document, unfave](const MTPBool &result) {
|
|
|
|
Stickers::SetFaved(document, !unfave);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::cancelContextDownload() {
|
2017-06-24 10:11:29 +00:00
|
|
|
if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data())) {
|
2017-04-08 13:27:53 +00:00
|
|
|
lnkDocument->document()->cancel();
|
2017-06-24 10:11:29 +00:00
|
|
|
} else if (auto item = App::contextItem()) {
|
|
|
|
if (auto media = item->getMedia()) {
|
|
|
|
if (auto doc = media->getDocument()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
doc->cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::showContextInFolder() {
|
|
|
|
QString filepath;
|
2017-06-24 10:11:29 +00:00
|
|
|
if (auto lnkDocument = dynamic_cast<DocumentClickHandler*>(_contextMenuLink.data())) {
|
2017-04-08 13:27:53 +00:00
|
|
|
filepath = lnkDocument->document()->filepath(DocumentData::FilePathResolveChecked);
|
2017-06-24 10:11:29 +00:00
|
|
|
} else if (auto item = App::contextItem()) {
|
|
|
|
if (auto media = item->getMedia()) {
|
|
|
|
if (auto doc = media->getDocument()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
filepath = doc->filepath(DocumentData::FilePathResolveChecked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!filepath.isEmpty()) {
|
|
|
|
File::ShowInFolder(filepath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::saveDocumentToFile(DocumentData *document) {
|
|
|
|
DocumentSaveClickHandler::doSave(document, true);
|
|
|
|
}
|
|
|
|
|
2017-05-18 13:22:57 +00:00
|
|
|
void HistoryInner::openContextGif() {
|
|
|
|
if (auto item = App::contextItem()) {
|
|
|
|
if (auto media = item->getMedia()) {
|
|
|
|
if (auto document = media->getDocument()) {
|
2017-08-08 09:31:48 +00:00
|
|
|
Messenger::Instance().showDocument(document, item);
|
2017-05-18 13:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::saveContextGif() {
|
|
|
|
if (auto item = App::contextItem()) {
|
|
|
|
if (auto media = item->getMedia()) {
|
|
|
|
if (auto document = media->getDocument()) {
|
|
|
|
_widget->saveGif(document);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::copyContextText() {
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto item = App::contextItem();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!item || (item->getMedia() && item->getMedia()->type() == MediaTypeSticker)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-16 15:00:20 +00:00
|
|
|
const auto group = item->getFullGroup();
|
|
|
|
const auto leader = group ? group->leader : item;
|
|
|
|
setToClipboard(leader->selectedText(FullSelection));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::setToClipboard(const TextWithEntities &forClipboard, QClipboard::Mode mode) {
|
2017-06-22 01:31:02 +00:00
|
|
|
if (auto data = MimeDataFromTextWithEntities(forClipboard)) {
|
2017-06-21 21:38:31 +00:00
|
|
|
QApplication::clipboard()->setMimeData(data.release(), mode);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::resizeEvent(QResizeEvent *e) {
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities HistoryInner::getSelectedText() const {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto selected = _selected;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting && _dragSelFrom && _dragSelTo) {
|
2017-12-15 16:25:47 +00:00
|
|
|
applyDragSelection(&selected);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
if (selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return TextWithEntities();
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
if (selected.cbegin()->second != FullSelection) {
|
|
|
|
const auto [item, selection] = *selected.cbegin();
|
|
|
|
return item->selectedText(selection);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
const auto timeFormat = qsl(", [dd.MM.yy hh:mm]\n");
|
|
|
|
auto groupLeadersAdded = base::flat_set<not_null<HistoryItem*>>();
|
|
|
|
auto fullSize = 0;
|
|
|
|
auto texts = base::flat_map<std::pair<int, MsgId>, TextWithEntities>();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
const auto addItem = [&](
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
TextSelection selection) {
|
2017-10-05 15:35:52 +00:00
|
|
|
auto time = item->date.toString(timeFormat);
|
2017-12-16 15:00:20 +00:00
|
|
|
auto part = TextWithEntities();
|
|
|
|
auto unwrapped = item->selectedText(selection);
|
|
|
|
auto size = item->author()->name.size()
|
|
|
|
+ time.size()
|
|
|
|
+ unwrapped.text.size();
|
2017-04-08 13:27:53 +00:00
|
|
|
part.text.reserve(size);
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
auto y = itemTop(item);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (y >= 0) {
|
|
|
|
part.text.append(item->author()->name).append(time);
|
2017-07-06 11:37:42 +00:00
|
|
|
TextUtilities::Append(part, std::move(unwrapped));
|
2017-12-16 15:00:20 +00:00
|
|
|
texts.emplace(std::make_pair(y, item->id), part);
|
2017-04-08 13:27:53 +00:00
|
|
|
fullSize += size;
|
|
|
|
}
|
2017-12-16 15:00:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto [item, selection] : selected) {
|
|
|
|
if (item->detached()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const auto group = item->Get<HistoryMessageGroup>()) {
|
|
|
|
if (groupLeadersAdded.contains(group->leader)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto leaderSelection = computeRenderSelection(
|
|
|
|
&selected,
|
|
|
|
group->leader);
|
|
|
|
if (leaderSelection == FullSelection) {
|
|
|
|
groupLeadersAdded.emplace(group->leader);
|
|
|
|
addItem(group->leader, FullSelection);
|
|
|
|
} else if (item == group->leader) {
|
|
|
|
const auto leaderFullSelection = AddGroupItemSelection(
|
|
|
|
TextSelection(),
|
|
|
|
int(group->others.size()));
|
|
|
|
addItem(item, leaderFullSelection);
|
|
|
|
} else {
|
|
|
|
addItem(item, FullSelection);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addItem(item, FullSelection);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
auto result = TextWithEntities();
|
2017-04-08 13:27:53 +00:00
|
|
|
auto sep = qsl("\n\n");
|
|
|
|
result.text.reserve(fullSize + (texts.size() - 1) * sep.size());
|
2017-12-16 15:00:20 +00:00
|
|
|
for (auto i = texts.begin(), e = texts.end(); i != e;) {
|
|
|
|
TextUtilities::Append(result, std::move(i->second));
|
|
|
|
if (++i != e) {
|
2017-04-08 13:27:53 +00:00
|
|
|
result.text.append(sep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
_widget->onListEscapePressed();
|
2017-10-05 15:35:52 +00:00
|
|
|
} else if (e == QKeySequence::Copy && !_selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
copySelectedText();
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
} else if (e->key() == Qt::Key_E && e->modifiers().testFlag(Qt::ControlModifier)) {
|
|
|
|
setToClipboard(getSelectedText(), QClipboard::FindBuffer);
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
} else if (e == QKeySequence::Delete) {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
|
|
|
if (selectedState.count > 0 && selectedState.canDeleteCount == selectedState.count) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_widget->confirmDeleteSelectedItems();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
void HistoryInner::recountHistoryGeometry() {
|
2017-04-08 13:27:53 +00:00
|
|
|
int visibleHeight = _scroll->height();
|
|
|
|
int oldHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
accumulate_max(oldHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
_history->resizeGetHeight(_scroll->width());
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->resizeGetHeight(_scroll->width());
|
|
|
|
}
|
|
|
|
|
|
|
|
// with migrated history we perhaps do not need to display first _history message
|
|
|
|
// (if last _migrated message and first _history message are both isGroupMigrate)
|
|
|
|
// or at least we don't need to display first _history date (just skip it by height)
|
|
|
|
_historySkipHeight = 0;
|
|
|
|
if (_migrated) {
|
|
|
|
if (!_migrated->isEmpty() && !_history->isEmpty() && _migrated->loadedAtBottom() && _history->loadedAtTop()) {
|
|
|
|
if (_migrated->blocks.back()->items.back()->date.date() == _history->blocks.front()->items.front()->date.date()) {
|
|
|
|
if (_migrated->blocks.back()->items.back()->isGroupMigrate() && _history->blocks.front()->items.front()->isGroupMigrate()) {
|
|
|
|
_historySkipHeight += _history->blocks.front()->items.front()->height();
|
|
|
|
} else {
|
|
|
|
_historySkipHeight += _history->blocks.front()->items.front()->displayedDateHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateBotInfo(false);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
|
|
|
|
if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
|
|
|
|
tw -= st::msgPadding.left() + st::msgPadding.right();
|
|
|
|
int32 mw = qMax(_botAbout->info->text.maxWidth(), st::msgNameFont->width(lang(lng_bot_description)));
|
|
|
|
if (tw > mw) tw = mw;
|
|
|
|
|
|
|
|
_botAbout->width = tw;
|
|
|
|
_botAbout->height = _botAbout->info->text.countHeight(_botAbout->width);
|
|
|
|
|
|
|
|
int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
|
|
|
|
int32 descMaxWidth = _scroll->width();
|
|
|
|
if (Adaptive::ChatWide()) {
|
|
|
|
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
|
|
|
|
int32 descAtY = qMin(_historyPaddingTop - descH, qMax(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
|
|
|
|
|
|
|
|
_botAbout->rect = QRect(descAtX, descAtY, _botAbout->width + st::msgPadding.left() + st::msgPadding.right(), descH - st::msgMargin.top() - st::msgMargin.bottom());
|
|
|
|
} else if (_botAbout) {
|
|
|
|
_botAbout->width = _botAbout->height = 0;
|
|
|
|
_botAbout->rect = QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
int newHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
accumulate_max(newHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto historyPaddingTopDelta = (newHistoryPaddingTop - oldHistoryPaddingTop);
|
|
|
|
if (historyPaddingTopDelta != 0) {
|
|
|
|
if (_history->scrollTopItem) {
|
|
|
|
_history->scrollTopOffset += historyPaddingTopDelta;
|
|
|
|
} else if (_migrated && _migrated->scrollTopItem) {
|
|
|
|
_migrated->scrollTopOffset += historyPaddingTopDelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::updateBotInfo(bool recount) {
|
|
|
|
int newh = 0;
|
|
|
|
if (_botAbout && !_botAbout->info->description.isEmpty()) {
|
|
|
|
if (_botAbout->info->text.isEmpty()) {
|
|
|
|
_botAbout->info->text.setText(st::messageTextStyle, _botAbout->info->description, _historyBotNoMonoOptions);
|
|
|
|
if (recount) {
|
|
|
|
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
|
|
|
|
if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
|
|
|
|
tw -= st::msgPadding.left() + st::msgPadding.right();
|
|
|
|
int32 mw = qMax(_botAbout->info->text.maxWidth(), st::msgNameFont->width(lang(lng_bot_description)));
|
|
|
|
if (tw > mw) tw = mw;
|
|
|
|
|
|
|
|
_botAbout->width = tw;
|
|
|
|
newh = _botAbout->info->text.countHeight(_botAbout->width);
|
|
|
|
}
|
|
|
|
} else if (recount) {
|
|
|
|
newh = _botAbout->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (recount && _botAbout) {
|
|
|
|
if (_botAbout->height != newh) {
|
|
|
|
_botAbout->height = newh;
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
if (_botAbout->height > 0) {
|
|
|
|
int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
|
|
|
|
int32 descAtX = (_scroll->width() - _botAbout->width) / 2 - st::msgPadding.left();
|
|
|
|
int32 descAtY = qMin(_historyPaddingTop - descH, (_scroll->height() - descH) / 2) + st::msgMargin.top();
|
|
|
|
|
|
|
|
_botAbout->rect = QRect(descAtX, descAtY, _botAbout->width + st::msgPadding.left() + st::msgPadding.right(), descH - st::msgMargin.top() - st::msgMargin.bottom());
|
|
|
|
} else {
|
|
|
|
_botAbout->width = 0;
|
|
|
|
_botAbout->rect = QRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::wasSelectedText() const {
|
|
|
|
return _wasSelectedText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::setFirstLoading(bool loading) {
|
|
|
|
_firstLoading = loading;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::visibleAreaUpdated(int top, int bottom) {
|
2017-05-16 13:41:47 +00:00
|
|
|
auto scrolledUp = (top < _visibleAreaTop);
|
2017-04-08 13:27:53 +00:00
|
|
|
_visibleAreaTop = top;
|
|
|
|
_visibleAreaBottom = bottom;
|
|
|
|
|
|
|
|
// if history has pending resize events we should not update scrollTopItem
|
|
|
|
if (hasPendingResizedItems()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom >= _historyPaddingTop + historyHeight() + st::historyPaddingBottom) {
|
|
|
|
_history->forgetScrollState();
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->forgetScrollState();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int htop = historyTop(), mtop = migratedTop();
|
|
|
|
if ((htop >= 0 && top >= htop) || mtop < 0) {
|
|
|
|
_history->countScrollState(top - htop);
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->forgetScrollState();
|
|
|
|
}
|
|
|
|
} else if (mtop >= 0 && top >= mtop) {
|
|
|
|
_history->forgetScrollState();
|
|
|
|
_migrated->countScrollState(top - mtop);
|
|
|
|
} else {
|
|
|
|
_history->countScrollState(top - htop);
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->forgetScrollState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 13:41:47 +00:00
|
|
|
if (scrolledUp) {
|
|
|
|
_scrollDateCheck.call();
|
|
|
|
} else {
|
|
|
|
onScrollDateHideByTimer();
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::displayScrollDate() const {
|
|
|
|
return (_visibleAreaTop <= height() - 2 * (_visibleAreaBottom - _visibleAreaTop));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onScrollDateCheck() {
|
|
|
|
if (!_history) return;
|
|
|
|
|
|
|
|
auto newScrollDateItem = _history->scrollTopItem ? _history->scrollTopItem : (_migrated ? _migrated->scrollTopItem : nullptr);
|
|
|
|
auto newScrollDateItemTop = _history->scrollTopItem ? _history->scrollTopOffset : (_migrated ? _migrated->scrollTopOffset : 0);
|
|
|
|
//if (newScrollDateItem && !displayScrollDate()) {
|
|
|
|
// if (!_history->isEmpty() && newScrollDateItem->date.date() == _history->blocks.back()->items.back()->date.date()) {
|
|
|
|
// newScrollDateItem = nullptr;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
if (!newScrollDateItem) {
|
|
|
|
_scrollDateLastItem = nullptr;
|
|
|
|
_scrollDateLastItemTop = 0;
|
|
|
|
scrollDateHide();
|
|
|
|
} else if (newScrollDateItem != _scrollDateLastItem || newScrollDateItemTop != _scrollDateLastItemTop) {
|
|
|
|
// Show scroll date only if it is not the initial onScroll() event (with empty _scrollDateLastItem).
|
|
|
|
if (_scrollDateLastItem && !_scrollDateShown) {
|
|
|
|
toggleScrollDateShown();
|
|
|
|
}
|
|
|
|
_scrollDateLastItem = newScrollDateItem;
|
|
|
|
_scrollDateLastItemTop = newScrollDateItemTop;
|
|
|
|
_scrollDateHideTimer.start(kScrollDateHideTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onScrollDateHideByTimer() {
|
|
|
|
_scrollDateHideTimer.stop();
|
2017-05-16 13:41:47 +00:00
|
|
|
if (!_scrollDateLink || ClickHandler::getPressed() != _scrollDateLink) {
|
2017-04-08 13:27:53 +00:00
|
|
|
scrollDateHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::scrollDateHide() {
|
|
|
|
if (_scrollDateShown) {
|
|
|
|
toggleScrollDateShown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::keepScrollDateForNow() {
|
|
|
|
if (!_scrollDateShown && _scrollDateLastItem && _scrollDateOpacity.animating()) {
|
|
|
|
toggleScrollDateShown();
|
|
|
|
}
|
|
|
|
_scrollDateHideTimer.start(kScrollDateHideTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::toggleScrollDateShown() {
|
|
|
|
_scrollDateShown = !_scrollDateShown;
|
|
|
|
auto from = _scrollDateShown ? 0. : 1.;
|
|
|
|
auto to = _scrollDateShown ? 1. : 0.;
|
|
|
|
_scrollDateOpacity.start([this] { repaintScrollDateCallback(); }, from, to, st::historyDateFadeDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::repaintScrollDateCallback() {
|
|
|
|
int updateTop = _visibleAreaTop;
|
|
|
|
int updateHeight = st::msgServiceMargin.top() + st::msgServicePadding.top() + st::msgServiceFont->height + st::msgServicePadding.bottom();
|
|
|
|
update(0, updateTop, width(), updateHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::updateSize() {
|
|
|
|
int visibleHeight = _scroll->height();
|
|
|
|
int newHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
accumulate_max(newHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_botAbout && _botAbout->height > 0) {
|
|
|
|
int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
|
|
|
|
int32 descMaxWidth = _scroll->width();
|
|
|
|
if (Adaptive::ChatWide()) {
|
|
|
|
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
|
|
|
|
int32 descAtY = qMin(newHistoryPaddingTop - descH, qMax(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
|
|
|
|
|
|
|
|
_botAbout->rect = QRect(descAtX, descAtY, _botAbout->width + st::msgPadding.left() + st::msgPadding.right(), descH - st::msgMargin.top() - st::msgMargin.bottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
_historyPaddingTop = newHistoryPaddingTop;
|
|
|
|
|
|
|
|
int newHeight = _historyPaddingTop + historyHeight() + st::historyPaddingBottom;
|
|
|
|
if (width() != _scroll->width() || height() != newHeight) {
|
|
|
|
resize(_scroll->width(), newHeight);
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(QCursor::pos());
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::enterEventHook(QEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(QCursor::pos());
|
2017-04-08 13:27:53 +00:00
|
|
|
return TWidget::enterEventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::leaveEventHook(QEvent *e) {
|
|
|
|
if (auto item = App::hoveredItem()) {
|
|
|
|
repaintItem(item);
|
|
|
|
App::hoveredItem(nullptr);
|
|
|
|
}
|
|
|
|
ClickHandler::clearActive();
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
if (!ClickHandler::getPressed() && _cursor != style::cur_default) {
|
|
|
|
_cursor = style::cur_default;
|
|
|
|
setCursor(_cursor);
|
|
|
|
}
|
|
|
|
return TWidget::leaveEventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryInner::~HistoryInner() {
|
|
|
|
delete _menu;
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::focusNextPrevChild(bool next) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return TWidget::focusNextPrevChild(next);
|
|
|
|
} else {
|
|
|
|
clearSelectedItems();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::adjustCurrent(int32 y) const {
|
|
|
|
int32 htop = historyTop(), hdrawtop = historyDrawTop(), mtop = migratedTop();
|
|
|
|
_curHistory = 0;
|
|
|
|
if (mtop >= 0) {
|
|
|
|
adjustCurrent(y - mtop, _migrated);
|
|
|
|
}
|
|
|
|
if (htop >= 0 && hdrawtop >= 0 && (mtop < 0 || y >= hdrawtop)) {
|
|
|
|
adjustCurrent(y - htop, _history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::adjustCurrent(int32 y, History *history) const {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(!history->isEmpty());
|
2017-04-08 13:27:53 +00:00
|
|
|
_curHistory = history;
|
|
|
|
if (_curBlock >= history->blocks.size()) {
|
|
|
|
_curBlock = history->blocks.size() - 1;
|
|
|
|
_curItem = 0;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
while (history->blocks[_curBlock]->y() > y && _curBlock > 0) {
|
2017-04-08 13:27:53 +00:00
|
|
|
--_curBlock;
|
|
|
|
_curItem = 0;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
while (history->blocks[_curBlock]->y() + history->blocks[_curBlock]->height() <= y && _curBlock + 1 < history->blocks.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
++_curBlock;
|
|
|
|
_curItem = 0;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
auto block = history->blocks[_curBlock];
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_curItem >= block->items.size()) {
|
|
|
|
_curItem = block->items.size() - 1;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
auto by = block->y();
|
|
|
|
while (block->items[_curItem]->y() + by > y && _curItem > 0) {
|
2017-04-08 13:27:53 +00:00
|
|
|
--_curItem;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
while (block->items[_curItem]->y() + block->items[_curItem]->height() + by <= y && _curItem + 1 < block->items.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
++_curItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *HistoryInner::prevItem(HistoryItem *item) {
|
|
|
|
if (!item || item->detached()) return nullptr;
|
|
|
|
|
|
|
|
HistoryBlock *block = item->block();
|
|
|
|
int blockIndex = block->indexInHistory(), itemIndex = item->indexInBlock();
|
|
|
|
if (itemIndex > 0) {
|
|
|
|
return block->items.at(itemIndex - 1);
|
|
|
|
}
|
|
|
|
if (blockIndex > 0) {
|
|
|
|
return item->history()->blocks.at(blockIndex - 1)->items.back();
|
|
|
|
}
|
|
|
|
if (item->history() == _history && _migrated && _history->loadedAtTop() && !_migrated->isEmpty() && _migrated->loadedAtBottom()) {
|
|
|
|
return _migrated->blocks.back()->items.back();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *HistoryInner::nextItem(HistoryItem *item) {
|
|
|
|
if (!item || item->detached()) return nullptr;
|
|
|
|
|
|
|
|
HistoryBlock *block = item->block();
|
|
|
|
int blockIndex = block->indexInHistory(), itemIndex = item->indexInBlock();
|
|
|
|
if (itemIndex + 1 < block->items.size()) {
|
|
|
|
return block->items.at(itemIndex + 1);
|
|
|
|
}
|
|
|
|
if (blockIndex + 1 < item->history()->blocks.size()) {
|
|
|
|
return item->history()->blocks.at(blockIndex + 1)->items.front();
|
|
|
|
}
|
|
|
|
if (item->history() == _migrated && _history && _migrated->loadedAtBottom() && _history->loadedAtTop() && !_history->isEmpty()) {
|
|
|
|
return _history->blocks.front()->items.front();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::canCopySelected() const {
|
2017-10-05 15:35:52 +00:00
|
|
|
return !_selected.empty();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::canDeleteSelected() const {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
|
|
|
return (selectedState.count > 0) && (selectedState.count == selectedState.canDeleteCount);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 08:05:56 +00:00
|
|
|
HistoryTopBarWidget::SelectedState HistoryInner::getSelectionState() const {
|
|
|
|
auto result = HistoryTopBarWidget::SelectedState {};
|
2017-10-05 15:35:52 +00:00
|
|
|
for (auto &selected : _selected) {
|
|
|
|
if (selected.second == FullSelection) {
|
2017-04-27 21:17:00 +00:00
|
|
|
++result.count;
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selected.first->canDelete()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
++result.canDeleteCount;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selected.first->canForward()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
++result.canForwardCount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result.textSelected = true;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-27 21:17:00 +00:00
|
|
|
return result;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::clearSelectedItems(bool onlyTextSelection) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && (!onlyTextSelection || _selected.cbegin()->second != FullSelection)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
_widget->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
MessageIdsList HistoryInner::getSelectedItems() const {
|
|
|
|
using namespace ranges;
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty() || _selected.cbegin()->second != FullSelection) {
|
2017-12-06 10:13:38 +00:00
|
|
|
return {};
|
2017-06-16 20:33:35 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
auto result = make_iterator_range(
|
|
|
|
_selected.begin(),
|
|
|
|
_selected.end()
|
|
|
|
) | view::filter([](const auto &selected) {
|
|
|
|
const auto item = selected.first;
|
|
|
|
return item && item->toHistoryMessage() && (item->id > 0);
|
|
|
|
}) | view::transform([](const auto &selected) {
|
|
|
|
return selected.first->fullId();
|
|
|
|
}) | to_vector;
|
|
|
|
|
|
|
|
result |= action::sort(ordered_less{}, [](const FullMsgId &msgId) {
|
|
|
|
return msgId.channel ? msgId.msg : (msgId.msg - ServerMaxMsgId);
|
|
|
|
});
|
2017-06-16 20:33:35 +00:00
|
|
|
return result;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void HistoryInner::selectItem(not_null<HistoryItem*> item) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && _selected.cbegin()->second != FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if (_selected.size() == MaxSelectedItems
|
|
|
|
&& _selected.find(item) == _selected.cend()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(item, FullSelection);
|
2017-04-08 13:27:53 +00:00
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
_widget->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onTouchSelect() {
|
|
|
|
_touchSelect = true;
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionStart(_touchPos, Qt::LeftButton);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onUpdateSelected() {
|
|
|
|
if (!_history || hasPendingResizedItems()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
auto mousePos = mapFromGlobal(_mousePosition);
|
2017-04-08 13:27:53 +00:00
|
|
|
auto point = _widget->clampMousePosition(mousePos);
|
|
|
|
|
|
|
|
HistoryBlock *block = 0;
|
|
|
|
HistoryItem *item = 0;
|
|
|
|
QPoint m;
|
|
|
|
|
|
|
|
adjustCurrent(point.y());
|
|
|
|
if (_curHistory && !_curHistory->isEmpty()) {
|
|
|
|
block = _curHistory->blocks[_curBlock];
|
|
|
|
item = block->items[_curItem];
|
|
|
|
|
|
|
|
App::mousedItem(item);
|
2017-06-21 23:54:38 +00:00
|
|
|
m = mapPointToItem(point, item);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (item->hasPoint(m)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (App::hoveredItem() != item) {
|
|
|
|
repaintItem(App::hoveredItem());
|
|
|
|
App::hoveredItem(item);
|
|
|
|
repaintItem(App::hoveredItem());
|
|
|
|
}
|
|
|
|
} else if (App::hoveredItem()) {
|
|
|
|
repaintItem(App::hoveredItem());
|
|
|
|
App::hoveredItem(0);
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseActionItem && _mouseActionItem->detached()) {
|
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistoryTextState dragState;
|
|
|
|
ClickHandlerHost *lnkhost = nullptr;
|
2017-12-15 16:25:47 +00:00
|
|
|
auto selectingText = (item == _mouseActionItem)
|
|
|
|
&& (item == App::hoveredItem())
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& (_selected.cbegin()->second != FullSelection);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (point.y() < _historyPaddingTop) {
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) {
|
2017-12-15 16:25:47 +00:00
|
|
|
dragState = HistoryTextState(nullptr, _botAbout->info->text.getState(
|
|
|
|
point - _botAbout->rect.topLeft() - QPoint(st::msgPadding.left(), st::msgPadding.top() + st::botDescSkip + st::msgNameFont->height),
|
|
|
|
_botAbout->width));
|
|
|
|
_dragStateItem = App::histItemById(dragState.itemId);
|
2017-04-08 13:27:53 +00:00
|
|
|
lnkhost = _botAbout.get();
|
|
|
|
}
|
|
|
|
} else if (item) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (item != _mouseActionItem || (m - _dragStartPosition).manhattanLength() >= QApplication::startDragDistance()) {
|
|
|
|
if (_mouseAction == MouseAction::PrepareDrag) {
|
|
|
|
_mouseAction = MouseAction::Dragging;
|
|
|
|
InvokeQueued(this, [this] { performDrag(); });
|
|
|
|
} else if (_mouseAction == MouseAction::PrepareSelect) {
|
|
|
|
_mouseAction = MouseAction::Selecting;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top();
|
|
|
|
auto scrollDateOpacity = _scrollDateOpacity.current(_scrollDateShown ? 1. : 0.);
|
2017-12-15 16:25:47 +00:00
|
|
|
enumerateDates([&](not_null<HistoryItem*> item, int itemtop, int dateTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop enumeration if the date is above our point
|
|
|
|
if (dateTop + dateHeight <= point.y()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool displayDate = item->displayDate();
|
|
|
|
bool dateInPlace = displayDate;
|
|
|
|
if (dateInPlace) {
|
|
|
|
int correctDateTop = itemtop + st::msgServiceMargin.top();
|
|
|
|
dateInPlace = (dateTop < correctDateTop + dateHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop enumeration if we've found a date under the cursor
|
|
|
|
if (dateTop <= point.y()) {
|
|
|
|
auto opacity = (dateInPlace/* || noFloatingDate*/) ? 1. : scrollDateOpacity;
|
|
|
|
if (opacity > 0.) {
|
|
|
|
auto dateWidth = 0;
|
|
|
|
if (auto date = item->Get<HistoryMessageDate>()) {
|
|
|
|
dateWidth = date->_width;
|
|
|
|
} else {
|
|
|
|
dateWidth = st::msgServiceFont->width(langDayOfMonthFull(item->date.date()));
|
|
|
|
}
|
|
|
|
dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right();
|
|
|
|
auto dateLeft = st::msgServiceMargin.left();
|
|
|
|
auto maxwidth = item->history()->width;
|
|
|
|
if (Adaptive::ChatWide()) {
|
|
|
|
maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
|
|
|
|
|
|
|
|
dateLeft += (widthForDate - dateWidth) / 2;
|
|
|
|
|
|
|
|
if (point.x() >= dateLeft && point.x() < dateLeft + dateWidth) {
|
|
|
|
if (!_scrollDateLink) {
|
|
|
|
_scrollDateLink = MakeShared<DateClickHandler>(item->history()->peer, item->date.date());
|
|
|
|
} else {
|
|
|
|
static_cast<DateClickHandler*>(_scrollDateLink.data())->setDate(item->date.date());
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
dragState = HistoryTextState(
|
|
|
|
nullptr,
|
|
|
|
_scrollDateLink);
|
|
|
|
_dragStateItem = App::histItemById(dragState.itemId);
|
2017-04-08 13:27:53 +00:00
|
|
|
lnkhost = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if (!dragState.link) {
|
|
|
|
HistoryStateRequest request;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting) {
|
2017-04-08 13:27:53 +00:00
|
|
|
request.flags |= Text::StateRequest::Flag::LookupSymbol;
|
|
|
|
} else {
|
|
|
|
selectingText = false;
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
dragState = item->getState(m, request);
|
2017-12-15 16:25:47 +00:00
|
|
|
_dragStateItem = App::histItemById(dragState.itemId);
|
2017-04-08 13:27:53 +00:00
|
|
|
lnkhost = item;
|
|
|
|
if (!dragState.link && m.x() >= st::historyPhotoLeft && m.x() < st::historyPhotoLeft + st::msgPhotoSize) {
|
|
|
|
if (auto msg = item->toHistoryMessage()) {
|
|
|
|
if (msg->hasFromPhoto()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
enumerateUserpics([&](not_null<HistoryMessage*> message, int userpicTop) -> bool {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop enumeration if the userpic is below our point
|
|
|
|
if (userpicTop > point.y()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop enumeration if we've found a userpic under the cursor
|
|
|
|
if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
|
2017-12-15 16:25:47 +00:00
|
|
|
dragState = HistoryTextState(
|
|
|
|
nullptr,
|
|
|
|
message->displayFrom()->openLink());
|
|
|
|
_dragStateItem = App::histItemById(dragState.itemId);
|
2017-04-08 13:27:53 +00:00
|
|
|
lnkhost = message;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto lnkChanged = ClickHandler::setActive(dragState.link, lnkhost);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (lnkChanged || dragState.cursor != _mouseCursorState) {
|
2017-04-08 13:27:53 +00:00
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
if (dragState.link || dragState.cursor == HistoryInDateCursorState || dragState.cursor == HistoryInForwardedCursorState) {
|
|
|
|
Ui::Tooltip::Show(1000, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::CursorShape cur = style::cur_default;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::None) {
|
|
|
|
_mouseCursorState = dragState.cursor;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.link) {
|
|
|
|
cur = style::cur_pointer;
|
2017-10-05 15:35:52 +00:00
|
|
|
} else if (_mouseCursorState == HistoryInTextCursorState && (_selected.empty() || _selected.cbegin()->second != FullSelection)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
cur = style::cur_text;
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseCursorState == HistoryInDateCursorState) {
|
2017-12-15 16:25:47 +00:00
|
|
|
//cur = style::cur_cross;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else if (item) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting) {
|
2017-04-08 13:27:53 +00:00
|
|
|
auto canSelectMany = (_history != nullptr);
|
|
|
|
if (selectingText) {
|
|
|
|
uint16 second = dragState.symbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dragState.afterSymbol && _mouseSelectType == TextSelectType::Letters) {
|
2017-04-08 13:27:53 +00:00
|
|
|
++second;
|
|
|
|
}
|
2017-06-23 19:28:42 +00:00
|
|
|
auto selState = TextSelection { qMin(second, _mouseTextSymbol), qMax(second, _mouseTextSymbol) };
|
|
|
|
if (_mouseSelectType != TextSelectType::Letters) {
|
2017-06-24 10:11:29 +00:00
|
|
|
selState = _mouseActionItem->adjustSelection(selState, _mouseSelectType);
|
2017-06-23 19:28:42 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_selected[_mouseActionItem] != selState) {
|
|
|
|
_selected[_mouseActionItem] = selState;
|
|
|
|
repaintItem(_mouseActionItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (!_wasSelectedText && (selState == FullSelection || selState.from != selState.to)) {
|
|
|
|
_wasSelectedText = true;
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
updateDragSelection(0, 0, false);
|
|
|
|
} else if (canSelectMany) {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto selectingDown = (itemTop(_mouseActionItem) < itemTop(item)) || (_mouseActionItem == item && _dragStartPosition.y() < m.y());
|
|
|
|
auto dragSelFrom = _mouseActionItem, dragSelTo = item;
|
|
|
|
if (!dragSelFrom->hasPoint(_dragStartPosition)) { // maybe exclude dragSelFrom
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selectingDown) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_dragStartPosition.y() >= dragSelFrom->height() - dragSelFrom->marginBottom() || ((item == dragSelFrom) && (m.y() < _dragStartPosition.y() + QApplication::startDragDistance() || m.y() < dragSelFrom->marginTop()))) {
|
2017-04-08 13:27:53 +00:00
|
|
|
dragSelFrom = (dragSelFrom == dragSelTo) ? 0 : nextItem(dragSelFrom);
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_dragStartPosition.y() < dragSelFrom->marginTop() || ((item == dragSelFrom) && (m.y() >= _dragStartPosition.y() - QApplication::startDragDistance() || m.y() >= dragSelFrom->height() - dragSelFrom->marginBottom()))) {
|
2017-04-08 13:27:53 +00:00
|
|
|
dragSelFrom = (dragSelFrom == dragSelTo) ? 0 : prevItem(dragSelFrom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseActionItem != item) { // maybe exclude dragSelTo
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selectingDown) {
|
|
|
|
if (m.y() < dragSelTo->marginTop()) {
|
|
|
|
dragSelTo = (dragSelFrom == dragSelTo) ? 0 : prevItem(dragSelTo);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m.y() >= dragSelTo->height() - dragSelTo->marginBottom()) {
|
|
|
|
dragSelTo = (dragSelFrom == dragSelTo) ? 0 : nextItem(dragSelTo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto dragSelecting = false;
|
|
|
|
auto dragFirstAffected = dragSelFrom;
|
|
|
|
while (dragFirstAffected && (dragFirstAffected->id < 0 || dragFirstAffected->serviceMsg())) {
|
|
|
|
dragFirstAffected = (dragFirstAffected == dragSelTo) ? 0 : (selectingDown ? nextItem(dragFirstAffected) : prevItem(dragFirstAffected));
|
|
|
|
}
|
|
|
|
if (dragFirstAffected) {
|
2017-10-05 15:35:52 +00:00
|
|
|
auto i = _selected.find(dragFirstAffected);
|
|
|
|
dragSelecting = (i == _selected.cend() || i->second != FullSelection);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
updateDragSelection(dragSelFrom, dragSelTo, dragSelecting);
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseAction == MouseAction::Dragging) {
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ClickHandler::getPressed()) {
|
|
|
|
cur = style::cur_pointer;
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if ((_mouseAction == MouseAction::Selecting)
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& (_selected.cbegin()->second != FullSelection)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!_dragSelFrom || !_dragSelTo) {
|
|
|
|
cur = style::cur_text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Voice message seek support.
|
2017-12-15 16:25:47 +00:00
|
|
|
if (const auto pressedItem = _dragStateItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!pressedItem->detached()) {
|
|
|
|
if (pressedItem->history() == _history || pressedItem->history() == _migrated) {
|
2017-06-21 23:54:38 +00:00
|
|
|
auto adjustedPoint = mapPointToItem(point, pressedItem);
|
2017-06-21 21:38:31 +00:00
|
|
|
pressedItem->updatePressed(adjustedPoint);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_widget->checkSelectingScroll(mousePos);
|
|
|
|
} else {
|
|
|
|
updateDragSelection(0, 0, false);
|
|
|
|
_widget->noSelectingScroll();
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::None && (lnkChanged || cur != _cursor)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
setCursor(_cursor = cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
void HistoryInner::updateDragSelection(HistoryItem *dragSelFrom, HistoryItem *dragSelTo, bool dragSelecting) {
|
|
|
|
if (_dragSelFrom == dragSelFrom && _dragSelTo == dragSelTo && _dragSelecting == dragSelecting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_dragSelFrom = dragSelFrom;
|
|
|
|
_dragSelTo = dragSelTo;
|
|
|
|
int32 fromy = itemTop(_dragSelFrom), toy = itemTop(_dragSelTo);
|
|
|
|
if (fromy >= 0 && toy >= 0 && fromy > toy) {
|
|
|
|
qSwap(_dragSelFrom, _dragSelTo);
|
|
|
|
}
|
|
|
|
_dragSelecting = dragSelecting;
|
|
|
|
if (!_wasSelectedText && _dragSelFrom && _dragSelTo && _dragSelecting) {
|
|
|
|
_wasSelectedText = true;
|
|
|
|
setFocus();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyHeight() const {
|
|
|
|
int result = 0;
|
|
|
|
if (!_history || _history->isEmpty()) {
|
|
|
|
result += _migrated ? _migrated->height : 0;
|
|
|
|
} else {
|
|
|
|
result += _history->height - _historySkipHeight + (_migrated ? _migrated->height : 0);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyScrollTop() const {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto htop = historyTop();
|
|
|
|
auto mtop = migratedTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (htop >= 0 && _history->scrollTopItem) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(!_history->scrollTopItem->detached());
|
2017-05-12 13:53:08 +00:00
|
|
|
return htop + _history->scrollTopItem->block()->y() + _history->scrollTopItem->y() + _history->scrollTopOffset;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (mtop >= 0 && _migrated->scrollTopItem) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(!_migrated->scrollTopItem->detached());
|
2017-05-12 13:53:08 +00:00
|
|
|
return mtop + _migrated->scrollTopItem->block()->y() + _migrated->scrollTopItem->y() + _migrated->scrollTopOffset;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return ScrollMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::migratedTop() const {
|
|
|
|
return (_migrated && !_migrated->isEmpty()) ? _historyPaddingTop : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyTop() const {
|
|
|
|
int mig = migratedTop();
|
|
|
|
return (_history && !_history->isEmpty()) ? (mig >= 0 ? (mig + _migrated->height - _historySkipHeight) : _historyPaddingTop) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyDrawTop() const {
|
2017-05-21 16:06:33 +00:00
|
|
|
auto top = historyTop();
|
|
|
|
return (top >= 0) ? (top + _historySkipHeight) : -1;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::itemTop(const HistoryItem *item) const { // -1 if should not be visible, -2 if bad history()
|
|
|
|
if (!item) return -2;
|
|
|
|
if (item->detached()) return -1;
|
|
|
|
|
2017-05-21 16:06:33 +00:00
|
|
|
auto top = (item->history() == _history) ? historyTop() : (item->history() == _migrated ? migratedTop() : -2);
|
2017-05-12 13:53:08 +00:00
|
|
|
return (top < 0) ? top : (top + item->y() + item->block()->y());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::notifyIsBotChanged() {
|
2017-12-16 15:00:20 +00:00
|
|
|
const auto newinfo = (_history && _history->peer->isUser())
|
|
|
|
? _history->peer->asUser()->botInfo.get()
|
|
|
|
: nullptr;
|
|
|
|
if ((!newinfo && !_botAbout)
|
|
|
|
|| (newinfo && _botAbout && _botAbout->info == newinfo)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newinfo) {
|
2017-12-16 15:00:20 +00:00
|
|
|
_botAbout = std::make_unique<BotAbout>(this, newinfo);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (newinfo && !newinfo->inited) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestFullPeer(_peer);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_botAbout = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::notifyMigrateUpdated() {
|
2017-08-31 17:53:03 +00:00
|
|
|
_migrated = _history->migrateFrom();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::moveScrollFollowingInlineKeyboard(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) {
|
|
|
|
if (item == App::mousedItem()) {
|
|
|
|
int top = itemTop(item);
|
|
|
|
if (top >= oldKeyboardTop) {
|
|
|
|
return newKeyboardTop - oldKeyboardTop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::applyDragSelection() {
|
|
|
|
applyDragSelection(&_selected);
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:36:28 +00:00
|
|
|
bool HistoryInner::isSelected(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto i = toItems->find(item);
|
|
|
|
return (i != toItems->cend()) && (i->second == FullSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::isSelectedAsGroup(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
2017-12-15 21:23:20 +00:00
|
|
|
if (const auto group = item->getFullGroup()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
if (!isSelected(toItems, group->leader)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (const auto other : group->others) {
|
2017-12-15 18:36:28 +00:00
|
|
|
if (!isSelected(toItems, other)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isSelected(toItems, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::goodForSelection(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int &totalCount) const {
|
|
|
|
if (item->id <= 0 || item->serviceMsg()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
if (toItems->find(item) == toItems->end()) {
|
|
|
|
++totalCount;
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:36:28 +00:00
|
|
|
void HistoryInner::addToSelection(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto i = toItems->find(item);
|
|
|
|
if (i == toItems->cend()) {
|
|
|
|
toItems->emplace(item, FullSelection);
|
|
|
|
} else if (i->second != FullSelection) {
|
|
|
|
i->second = FullSelection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::removeFromSelection(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto i = toItems->find(item);
|
|
|
|
if (i != toItems->cend()) {
|
|
|
|
toItems->erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::changeSelection(
|
2017-12-15 16:25:47 +00:00
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
SelectAction action) const {
|
|
|
|
if (action == SelectAction::Invert) {
|
2017-12-15 18:36:28 +00:00
|
|
|
action = isSelected(toItems, item)
|
2017-12-15 16:25:47 +00:00
|
|
|
? SelectAction::Deselect
|
|
|
|
: SelectAction::Select;
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
auto total = int(toItems->size());
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto add = (action == SelectAction::Select);
|
2017-12-15 18:36:28 +00:00
|
|
|
if (add
|
|
|
|
&& goodForSelection(toItems, item, total)
|
|
|
|
&& total <= MaxSelectedItems) {
|
|
|
|
addToSelection(toItems, item);
|
|
|
|
} else {
|
|
|
|
removeFromSelection(toItems, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::changeSelectionAsGroup(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
SelectAction action) const {
|
2017-12-15 21:23:20 +00:00
|
|
|
const auto group = item->getFullGroup();
|
2017-12-15 18:36:28 +00:00
|
|
|
if (!group) {
|
|
|
|
return changeSelection(toItems, item, action);
|
|
|
|
}
|
|
|
|
if (action == SelectAction::Invert) {
|
|
|
|
action = isSelectedAsGroup(toItems, item)
|
|
|
|
? SelectAction::Deselect
|
|
|
|
: SelectAction::Select;
|
|
|
|
}
|
|
|
|
auto total = int(toItems->size());
|
|
|
|
const auto add = (action == SelectAction::Select);
|
|
|
|
|
|
|
|
const auto adding = [&] {
|
|
|
|
if (!add || !goodForSelection(toItems, group->leader, total)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
for (const auto other : group->others) {
|
|
|
|
if (!goodForSelection(toItems, other, total)) {
|
|
|
|
return false;
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
return (total <= MaxSelectedItems);
|
2017-12-15 16:25:47 +00:00
|
|
|
}();
|
2017-12-15 18:36:28 +00:00
|
|
|
if (adding) {
|
|
|
|
addToSelection(toItems, group->leader);
|
|
|
|
for (const auto other : group->others) {
|
|
|
|
addToSelection(toItems, other);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-12-15 18:36:28 +00:00
|
|
|
removeFromSelection(toItems, group->leader);
|
|
|
|
for (const auto other : group->others) {
|
|
|
|
removeFromSelection(toItems, other);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:36:28 +00:00
|
|
|
void HistoryInner::forwardItem(not_null<HistoryItem*> item) {
|
|
|
|
Window::ShowForwardMessagesBox({ 1, item->fullId() });
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::forwardAsGroup(not_null<HistoryItem*> item) {
|
2017-12-15 21:23:20 +00:00
|
|
|
if (const auto group = item->getFullGroup()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
auto items = Auth().data().itemsToIds(group->others);
|
|
|
|
items.push_back(group->leader->fullId());
|
|
|
|
Window::ShowForwardMessagesBox(std::move(items));
|
|
|
|
} else {
|
|
|
|
Window::ShowForwardMessagesBox({ 1, item->fullId() });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::deleteItem(not_null<HistoryItem*> item) {
|
|
|
|
if (auto message = item->toHistoryMessage()) {
|
|
|
|
if (message->uploading()) {
|
|
|
|
App::main()->cancelUploadLayer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto suggestModerateActions = true;
|
|
|
|
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::deleteAsGroup(not_null<HistoryItem*> item) {
|
2017-12-15 21:23:20 +00:00
|
|
|
const auto group = item->getFullGroup();
|
2017-12-15 18:36:28 +00:00
|
|
|
if (!group || group->others.empty()) {
|
|
|
|
return deleteItem(item);
|
|
|
|
}
|
|
|
|
auto items = Auth().data().itemsToIds(group->others);
|
|
|
|
items.push_back(group->leader->fullId());
|
2017-12-15 21:23:20 +00:00
|
|
|
Ui::show(Box<DeleteMessagesBox>(Auth().data().groupToIds(group)));
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void HistoryInner::addSelectionRange(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<History*> history,
|
|
|
|
int fromblock,
|
|
|
|
int fromitem,
|
|
|
|
int toblock,
|
|
|
|
int toitem) const {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (fromblock >= 0 && fromitem >= 0 && toblock >= 0 && toitem >= 0) {
|
|
|
|
for (; fromblock <= toblock; ++fromblock) {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto block = history->blocks[fromblock];
|
|
|
|
for (int cnt = (fromblock < toblock) ? block->items.size() : (toitem + 1); fromitem < cnt; ++fromitem) {
|
2017-10-05 15:35:52 +00:00
|
|
|
auto item = block->items[fromitem];
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(toItems, item, SelectAction::Select);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (toItems->size() >= MaxSelectedItems) break;
|
|
|
|
fromitem = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void HistoryInner::applyDragSelection(
|
|
|
|
not_null<SelectedItems*> toItems) const {
|
|
|
|
const auto selfromy = itemTop(_dragSelFrom);
|
|
|
|
const auto seltoy = [&] {
|
|
|
|
auto result = itemTop(_dragSelTo);
|
|
|
|
return (result < 0) ? result : (result + _dragSelTo->height());
|
|
|
|
}();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selfromy < 0 || seltoy < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!toItems->empty() && toItems->cbegin()->second != FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
toItems->clear();
|
|
|
|
}
|
|
|
|
if (_dragSelecting) {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto fromblock = _dragSelFrom->block()->indexInHistory();
|
|
|
|
auto fromitem = _dragSelFrom->indexInBlock();
|
|
|
|
auto toblock = _dragSelTo->block()->indexInHistory();
|
|
|
|
auto toitem = _dragSelTo->indexInBlock();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_migrated) {
|
|
|
|
if (_dragSelFrom->history() == _migrated) {
|
|
|
|
if (_dragSelTo->history() == _migrated) {
|
2017-12-15 16:25:47 +00:00
|
|
|
addSelectionRange(toItems, _migrated, fromblock, fromitem, toblock, toitem);
|
2017-04-08 13:27:53 +00:00
|
|
|
toblock = -1;
|
|
|
|
toitem = -1;
|
|
|
|
} else {
|
2017-12-15 16:25:47 +00:00
|
|
|
addSelectionRange(toItems, _migrated, fromblock, fromitem, _migrated->blocks.size() - 1, _migrated->blocks.back()->items.size() - 1);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
fromblock = 0;
|
|
|
|
fromitem = 0;
|
|
|
|
} else if (_dragSelTo->history() == _migrated) { // wtf
|
|
|
|
toblock = -1;
|
|
|
|
toitem = -1;
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
addSelectionRange(toItems, _history, fromblock, fromitem, toblock, toitem);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto toRemove = std::vector<not_null<HistoryItem*>>();
|
|
|
|
for (auto i = toItems->begin(); i != toItems->cend(); ++i) {
|
2017-10-05 15:35:52 +00:00
|
|
|
auto iy = itemTop(i->first);
|
2017-12-15 16:25:47 +00:00
|
|
|
if (iy < -1) {
|
|
|
|
toRemove.push_back(i->first);
|
|
|
|
} else if (iy >= 0 && iy >= selfromy && iy < seltoy) {
|
|
|
|
toRemove.push_back(i->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
for (const auto item : toRemove) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(toItems, item, SelectAction::Deselect);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HistoryInner::tooltipText() const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseCursorState == HistoryInDateCursorState && _mouseAction == MouseAction::None) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (App::hoveredItem()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto dateText = App::hoveredItem()->date.toString(QLocale::system().dateTimeFormat(QLocale::LongFormat));
|
2017-12-16 16:32:10 +00:00
|
|
|
auto editedDate = App::hoveredItem()->displayedEditDate();
|
|
|
|
if (!editedDate.isNull()) {
|
|
|
|
dateText += '\n' + lng_edited_date(lt_date, editedDate.toString(QLocale::system().dateTimeFormat(QLocale::LongFormat)));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-20 22:05:38 +00:00
|
|
|
if (auto forwarded = App::hoveredItem()->Get<HistoryMessageForwarded>()) {
|
|
|
|
dateText += '\n' + lng_forwarded_date(lt_date, forwarded->_originalDate.toString(QLocale::system().dateTimeFormat(QLocale::LongFormat)));
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
return dateText;
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseCursorState == HistoryInForwardedCursorState && _mouseAction == MouseAction::None) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (App::hoveredItem()) {
|
2017-04-30 12:44:17 +00:00
|
|
|
if (auto forwarded = App::hoveredItem()->Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->_text.originalText(AllTextSelection, ExpandLinksNone);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-27 21:17:00 +00:00
|
|
|
} else if (auto lnk = ClickHandler::getActive()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return lnk->tooltip();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint HistoryInner::tooltipPos() const {
|
2017-06-21 21:38:31 +00:00
|
|
|
return _mousePosition;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onParentGeometryChanged() {
|
|
|
|
auto mousePos = QCursor::pos();
|
|
|
|
auto mouseOver = _widget->rect().contains(_widget->mapFromGlobal(mousePos));
|
2017-06-21 21:38:31 +00:00
|
|
|
auto needToUpdate = (_mouseAction != MouseAction::None || _touchScroll || mouseOver);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (needToUpdate) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(mousePos);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|