mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-01 07:05:13 +00:00
sticker packs management done, conversations list context menu added
This commit is contained in:
@@ -30,6 +30,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
||||
#include "apiwrap.h"
|
||||
|
||||
#include "boxes/confirmbox.h"
|
||||
#include "boxes/stickersetbox.h"
|
||||
|
||||
Dropdown::Dropdown(QWidget *parent, const style::dropdown &st) : TWidget(parent),
|
||||
_ignore(false), _selected(-1), _st(st), _width(_st.width), _hiding(false), a_opacity(0), _shadow(_st.shadow) {
|
||||
@@ -1195,15 +1196,19 @@ void EmojiPanInner::showEmojiPack(DBIEmojiTab packIndex) {
|
||||
update();
|
||||
}
|
||||
|
||||
StickerPanInner::StickerPanInner() : _maxHeight(st::emojiPanMaxHeight),
|
||||
_top(0), _selected(-1), _pressedSel(-1) {
|
||||
resize(st::emojiPanWidth - st::emojiScroll.width, countHeight());
|
||||
StickerPanInner::StickerPanInner() : TWidget()
|
||||
, _top(0)
|
||||
, _selected(-1)
|
||||
, _pressedSel(-1)
|
||||
, _settings(this, lang(lng_stickers_you_have)) {
|
||||
setMaxHeight(st::emojiPanMaxHeight);
|
||||
|
||||
setMouseTracking(true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
|
||||
connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update()));
|
||||
connect(&_settings, SIGNAL(clicked()), this, SLOT(onSettings()));
|
||||
|
||||
refreshStickers();
|
||||
}
|
||||
@@ -1211,6 +1216,7 @@ _top(0), _selected(-1), _pressedSel(-1) {
|
||||
void StickerPanInner::setMaxHeight(int32 h) {
|
||||
_maxHeight = h;
|
||||
resize(st::emojiPanWidth - st::emojiScroll.width, countHeight());
|
||||
_settings.moveToLeft((st::emojiPanWidth - _settings.width()) / 2, height() / 3);
|
||||
}
|
||||
|
||||
void StickerPanInner::setScrollTop(int top) {
|
||||
@@ -1228,7 +1234,7 @@ int StickerPanInner::countHeight() {
|
||||
if (i == _sets.size() - 1 && h < minLastH) h = minLastH;
|
||||
result += h;
|
||||
}
|
||||
return result + st::stickerPanPadding;
|
||||
return qMax(minLastH, result) + st::stickerPanPadding;
|
||||
}
|
||||
|
||||
QRect StickerPanInner::stickerRect(int tab, int sel) {
|
||||
@@ -1461,6 +1467,8 @@ void StickerPanInner::refreshStickers() {
|
||||
int32 h = countHeight();
|
||||
if (h != height()) resize(width(), h);
|
||||
|
||||
_settings.setVisible(_sets.isEmpty());
|
||||
|
||||
emit refreshIcons();
|
||||
|
||||
updateSelected();
|
||||
@@ -1512,7 +1520,7 @@ uint64 StickerPanInner::currentSet(int yOffset) const {
|
||||
void StickerPanInner::appendSet(uint64 setId) {
|
||||
const StickerSets &sets(cStickerSets());
|
||||
StickerSets::const_iterator it = sets.constFind(setId);
|
||||
if (it == sets.cend() || it->stickers.isEmpty()) return;
|
||||
if (it == sets.cend() || (it->flags & MTPDstickerSet::flag_disabled) || it->stickers.isEmpty()) return;
|
||||
|
||||
StickerPack pack;
|
||||
pack.reserve(it->stickers.size());
|
||||
@@ -1710,6 +1718,10 @@ void StickerPanInner::updateSelected() {
|
||||
if (startanim) anim::start(this);
|
||||
}
|
||||
|
||||
void StickerPanInner::onSettings() {
|
||||
App::showLayer(new StickersBox());
|
||||
}
|
||||
|
||||
bool StickerPanInner::animStep(float64 ms) {
|
||||
uint64 now = getms();
|
||||
QRegion toUpdate;
|
||||
@@ -1976,6 +1988,8 @@ void EmojiPan::paintEvent(QPaintEvent *e) {
|
||||
p.fillRect(myrtlrect(r.x() + r.width() - st::emojiScroll.width, r.y(), st::emojiScroll.width, e_scroll.height()), st::white->b);
|
||||
if (_stickersShown) {
|
||||
p.fillRect(r.left(), _iconsTop, r.width(), st::rbEmoji.height, st::emojiPanCategories->b);
|
||||
p.drawSpriteLeft(_iconsLeft + 7 * st::rbEmoji.width + st::rbEmojiRecent.imagePos.x(), _iconsTop + st::rbEmojiRecent.imagePos.y(), width(), st::stickersSettings);
|
||||
|
||||
if (!_icons.isEmpty()) {
|
||||
int32 x = _iconsLeft, i = 0, selxrel = _iconSelX.current(), selx = x + selxrel - _iconsX.current();
|
||||
if (!_icons.at(i).sticker) {
|
||||
@@ -1996,13 +2010,13 @@ void EmojiPan::paintEvent(QPaintEvent *e) {
|
||||
++i;
|
||||
}
|
||||
|
||||
QRect clip(x, _iconsTop, _iconsLeft + 8 * st::rbEmoji.width - x, st::rbEmoji.height);
|
||||
QRect clip(x, _iconsTop, _iconsLeft + 7 * st::rbEmoji.width - x, st::rbEmoji.height);
|
||||
if (rtl()) clip.moveLeft(width() - x - clip.width());
|
||||
p.setClipRect(clip);
|
||||
|
||||
i += _iconsX.current() / int(st::rbEmoji.width);
|
||||
x -= _iconsX.current() % int(st::rbEmoji.width);
|
||||
for (int32 l = qMin(_icons.size(), i + 8 + (_icons.at(0).sticker ? 1 : 0)); i < l; ++i) {
|
||||
for (int32 l = qMin(_icons.size(), i + 7 + (_icons.at(0).sticker ? 1 : 0)); i < l; ++i) {
|
||||
const StickerIcon &s(_icons.at(i));
|
||||
s.sticker->thumb->load();
|
||||
QPixmap pix(s.sticker->thumb->pix(s.pixw, s.pixh));
|
||||
@@ -2028,7 +2042,7 @@ void EmojiPan::paintEvent(QPaintEvent *e) {
|
||||
float64 o_right = snap(float64(_iconsMax - _iconsX.current()) / st::stickerIconRight.pxWidth(), 0., 1.);
|
||||
if (o_right > 0) {
|
||||
p.setOpacity(o_right);
|
||||
p.drawSpriteRight(QRect(width() - _iconsLeft - 8 * st::rbEmoji.width, _iconsTop, st::stickerIconRight.pxWidth(), st::rbEmoji.height), width(), st::stickerIconRight);
|
||||
p.drawSpriteRight(QRect(width() - _iconsLeft - 7 * st::rbEmoji.width, _iconsTop, st::stickerIconRight.pxWidth(), st::rbEmoji.height), width(), st::stickerIconRight);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2100,27 +2114,31 @@ void EmojiPan::otherLeave() {
|
||||
}
|
||||
|
||||
void EmojiPan::mousePressEvent(QMouseEvent *e) {
|
||||
if (!_stickersShown || _icons.isEmpty()) return;
|
||||
if (!_stickersShown) return;
|
||||
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
||||
updateSelected();
|
||||
|
||||
_iconDown = _iconOver;
|
||||
_iconsMouseDown = _iconsMousePos;
|
||||
_iconsStartX = _iconsX.current();
|
||||
if (_iconOver == _icons.size()) {
|
||||
App::showLayer(new StickersBox());
|
||||
} else {
|
||||
_iconDown = _iconOver;
|
||||
_iconsMouseDown = _iconsMousePos;
|
||||
_iconsStartX = _iconsX.current();
|
||||
}
|
||||
}
|
||||
|
||||
void EmojiPan::mouseMoveEvent(QMouseEvent *e) {
|
||||
if (!_stickersShown || _icons.isEmpty()) return;
|
||||
if (!_stickersShown) return;
|
||||
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
||||
updateSelected();
|
||||
|
||||
if (!_iconsDragging && _iconDown >= (_icons.at(0).sticker ? 0 : 1)) {
|
||||
if (!_iconsDragging && !_icons.isEmpty() && _iconDown >= (_icons.at(0).sticker ? 0 : 1)) {
|
||||
if ((_iconsMousePos - _iconsMouseDown).manhattanLength() >= QApplication::startDragDistance()) {
|
||||
_iconsDragging = true;
|
||||
}
|
||||
}
|
||||
if (_iconsDragging) {
|
||||
int32 newX = snap(_iconsStartX + _iconsMouseDown.x() - _iconsMousePos.x(), 0, _iconsMax);
|
||||
int32 newX = snap(_iconsStartX + (rtl() ? -1 : 1) * (_iconsMouseDown.x() - _iconsMousePos.x()), 0, _iconsMax);
|
||||
if (newX != _iconsX.current()) {
|
||||
_iconsX = anim::ivalue(newX, newX);
|
||||
_iconsStartAnim = 0;
|
||||
@@ -2150,7 +2168,7 @@ void EmojiPan::mouseReleaseEvent(QMouseEvent *e) {
|
||||
} else {
|
||||
updateSelected();
|
||||
|
||||
if (wasDown == _iconOver && _iconOver >= 0) {
|
||||
if (wasDown == _iconOver && _iconOver >= 0 && _iconOver < _icons.size()) {
|
||||
_iconSelX = anim::ivalue(_iconOver * st::rbEmoji.width, _iconOver * st::rbEmoji.width);
|
||||
s_inner.showStickerSet(_icons.at(_iconOver).setId);
|
||||
}
|
||||
@@ -2160,7 +2178,7 @@ void EmojiPan::mouseReleaseEvent(QMouseEvent *e) {
|
||||
bool EmojiPan::event(QEvent *e) {
|
||||
if (e->type() == QEvent::TouchBegin) {
|
||||
int a = 0;
|
||||
} else if (e->type() == QEvent::Wheel && _iconOver >= ((_icons.isEmpty() || _icons.at(0).sticker) ? 0 : 1) && _iconDown < 0) {
|
||||
} else if (e->type() == QEvent::Wheel && !_icons.isEmpty() && _iconOver >= (_icons.at(0).sticker ? 0 : 1) && _iconOver < _icons.size() && _iconDown < 0) {
|
||||
QWheelEvent *ev = static_cast<QWheelEvent*>(e);
|
||||
bool hor = (ev->angleDelta().x() != 0 || ev->orientation() == Qt::Horizontal);
|
||||
bool ver = (ev->angleDelta().y() != 0 || ev->orientation() == Qt::Vertical);
|
||||
@@ -2213,7 +2231,7 @@ void EmojiPan::onRefreshIcons() {
|
||||
_iconsMax = 0;
|
||||
} else {
|
||||
_iconHovers = QVector<float64>(_icons.size(), 0);
|
||||
_iconsMax = qMax(int((_icons.size() - 8) * st::rbEmoji.width), 0);
|
||||
_iconsMax = qMax(int((_icons.size() - 7) * st::rbEmoji.width), 0);
|
||||
}
|
||||
updatePanelsPositions(s_panels, s_scroll.scrollTop());
|
||||
updateSelected();
|
||||
@@ -2237,23 +2255,29 @@ void EmojiPan::leaveToChildEvent(QEvent *e) {
|
||||
}
|
||||
|
||||
void EmojiPan::updateSelected() {
|
||||
if (_icons.isEmpty() || _iconDown >= 0) return;
|
||||
if (_iconDown >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPoint p(mapFromGlobal(_iconsMousePos));
|
||||
int32 x = p.x(), y = p.y(), newOver = -1;
|
||||
if (rtl()) x = width() - x;
|
||||
x -= _iconsLeft;
|
||||
if (y >= _iconsTop && y < _iconsTop + st::rbEmoji.height && x >= 0 && x < 8 * st::rbEmoji.width && x < _icons.size() * st::rbEmoji.width) {
|
||||
if (!_icons.at(0).sticker) {
|
||||
if (x < st::rbEmoji.width) {
|
||||
newOver = 0;
|
||||
} else {
|
||||
x -= st::rbEmoji.width;
|
||||
if (x >= st::rbEmoji.width * 7 && x < st::rbEmoji.width * 8 && y >= _iconsTop && y < _iconsTop + st::rbEmoji.height) {
|
||||
newOver = _icons.size();
|
||||
} else if (!_icons.isEmpty()) {
|
||||
if (y >= _iconsTop && y < _iconsTop + st::rbEmoji.height && x >= 0 && x < 7 * st::rbEmoji.width && x < _icons.size() * st::rbEmoji.width) {
|
||||
if (!_icons.at(0).sticker) {
|
||||
if (x < st::rbEmoji.width) {
|
||||
newOver = 0;
|
||||
} else {
|
||||
x -= st::rbEmoji.width;
|
||||
}
|
||||
}
|
||||
if (newOver < 0) {
|
||||
x += _iconsX.current();
|
||||
newOver = qFloor(x / st::rbEmoji.width) + (_icons.at(0).sticker ? 0 : 1);
|
||||
}
|
||||
}
|
||||
if (newOver < 0) {
|
||||
x += _iconsX.current();
|
||||
newOver = qFloor(x / st::rbEmoji.width) + (_icons.at(0).sticker ? 0 : 1);
|
||||
}
|
||||
}
|
||||
if (newOver != _iconOver) {
|
||||
@@ -2263,7 +2287,7 @@ void EmojiPan::updateSelected() {
|
||||
setCursor(style::cur_pointer);
|
||||
}
|
||||
bool startanim = false;
|
||||
if (_iconOver >= 0) {
|
||||
if (_iconOver >= 0 && _iconOver < _icons.size()) {
|
||||
_iconAnimations.remove(_iconOver + 1);
|
||||
if (_iconAnimations.find(-_iconOver - 1) == _iconAnimations.end()) {
|
||||
if (_iconAnimations.isEmpty() && !_iconsStartAnim) startanim = true;
|
||||
@@ -2271,7 +2295,7 @@ void EmojiPan::updateSelected() {
|
||||
}
|
||||
}
|
||||
_iconOver = newOver;
|
||||
if (_iconOver >= 0) {
|
||||
if (_iconOver >= 0 && _iconOver < _icons.size()) {
|
||||
_iconAnimations.remove(-_iconOver - 1);
|
||||
if (_iconAnimations.find(_iconOver + 1) == _iconAnimations.end()) {
|
||||
if (_iconAnimations.isEmpty() && !_iconsStartAnim) startanim = true;
|
||||
@@ -2645,7 +2669,7 @@ void EmojiPan::onRemoveSetSure() {
|
||||
}
|
||||
cRefStickerSets().erase(it);
|
||||
cRefStickerSetsOrder().removeOne(_removingSetId);
|
||||
cSetStickersHash(QByteArray());
|
||||
cSetStickersHash(stickersCountHash());
|
||||
refreshStickers();
|
||||
Local::writeStickers();
|
||||
if (writeRecent) Local::writeUserSettings();
|
||||
|
Reference in New Issue
Block a user