Fixed some ClickHandler bugs, bot keyboard active/pressed

states done, handling enterEvent() for ClickHandler activate.
This commit is contained in:
John Preston 2016-03-30 12:03:29 +04:00
parent 7f6cf32cdd
commit 3210aecbd2
8 changed files with 58 additions and 28 deletions

View File

@ -2012,6 +2012,7 @@ namespace App {
::cornersMask[i]->setDevicePixelRatio(cRetinaFactor());
}
prepareCorners(BlackCorners, st::msgRadius, st::black);
prepareCorners(WhiteCorners, st::msgRadius, st::white);
prepareCorners(ServiceCorners, st::msgRadius, st::msgServiceBg);
prepareCorners(ServiceSelectedCorners, st::msgRadius, st::msgServiceSelectBg);
prepareCorners(SelectedOverlayCorners, st::msgRadius, st::msgSelectOverlay);

View File

@ -83,6 +83,11 @@ void FlatLabel::mouseReleaseEvent(QMouseEvent *e) {
}
}
void FlatLabel::enterEvent(QEvent *e) {
_lastMousePos = QCursor::pos();
updateHover();
}
void FlatLabel::leaveEvent(QEvent *e) {
ClickHandler::clearActive(this);
}

View File

@ -33,6 +33,7 @@ public:
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
void updateLink();
void setOpacity(float64 o);

View File

@ -2830,34 +2830,36 @@ void ReplyKeyboard::getState(ClickHandlerPtr &lnk, int x, int y) const {
}
void ReplyKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
/*if (newSel != _sel) {
if (newSel < 0) {
setCursor(style::cur_default);
} else if (_sel < 0) {
setCursor(style::cur_pointer);
}
bool startanim = false;
if (_sel >= 0) {
_animations.remove(_sel + 1);
if (_animations.find(-_sel - 1) == _animations.end()) {
if (_animations.isEmpty()) startanim = true;
_animations.insert(-_sel - 1, getms());
if (!p) return;
bool startAnimation = false;
for (int i = 0, rows = _rows.size(); i != rows; ++i) {
const ButtonRow &row(_rows.at(i));
for (int j = 0, cols = row.size(); j != cols; ++j) {
if (row.at(j).link == p) {
bool startAnimation = _animations.isEmpty();
int indexForAnimation = i * MatrixRowShift + j + 1;
if (!active) {
indexForAnimation = -indexForAnimation;
}
_animations.remove(-indexForAnimation);
if (!_animations.contains(indexForAnimation)) {
_animations.insert(indexForAnimation, getms());
}
if (startAnimation && !_a_selected.animating()) {
_a_selected.start();
}
return;
}
}
_sel = newSel;
if (_sel >= 0) {
_animations.remove(-_sel - 1);
if (_animations.find(_sel + 1) == _animations.end()) {
if (_animations.isEmpty()) startanim = true;
_animations.insert(_sel + 1, getms());
}
}
if (startanim && !_a_selected.animating()) _a_selected.start();
}*/
}
}
void ReplyKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
_st->repaint(_item);
}
void ReplyKeyboard::step_selected(uint64 ms, bool timer) {
@ -6451,6 +6453,14 @@ void HistoryMessage::KeyboardStyle::repaint(const HistoryItem *item) const {
void HistoryMessage::KeyboardStyle::paintButtonBg(Painter &p, const QRect &rect, bool down, float64 howMuchOver) const {
App::roundRect(p, rect, App::msgServiceBg(), ServiceCorners);
if (down) {
howMuchOver = 1.;
}
if (howMuchOver > 0) {
p.setOpacity(howMuchOver * 0.1);
App::roundRect(p, rect, st::white, WhiteCorners);
p.setOpacity(1);
}
}
HistoryMessage::HistoryMessage(History *history, const MTPDmessage &msg)
@ -7055,7 +7065,7 @@ void HistoryMessage::draw(Painter &p, const QRect &r, uint32 selection, uint64 m
if (const ReplyKeyboard *keyboard = inlineReplyKeyboard()) {
int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
height -= h;
int top = marginTop() + height;
int top = height + st::msgBotKbButton.margin - marginBottom();
p.translate(left, top);
keyboard->paint(p, r.translated(-left, -top));
p.translate(-left, -top);
@ -7312,7 +7322,7 @@ void HistoryMessage::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i
if (const ReplyKeyboard *keyboard = inlineReplyKeyboard()) {
int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
height -= h;
int top = marginTop() + height;
int top = height + st::msgBotKbButton.margin - marginBottom();
if (x >= left && x < left + width && y >= top && y < _height - marginBottom()) {
return keyboard->getState(lnk, x - left, y - top);
}

View File

@ -1244,7 +1244,7 @@ public:
}
private:
HistoryMedia *_p;
HistoryMedia *_p = nullptr;
};

View File

@ -1483,6 +1483,7 @@ void HistoryInner::updateSize() {
}
void HistoryInner::enterEvent(QEvent *e) {
dragActionUpdate(QCursor::pos());
return QWidget::enterEvent(e);
}
@ -1685,10 +1686,11 @@ void HistoryInner::onUpdateSelected() {
}
} else if (item) {
item->getState(lnk, cursorState, m.x(), m.y());
lnkhost = item;
if (!lnk && m.x() >= st::msgMargin.left() && m.x() < st::msgMargin.left() + st::msgPhotoSize) {
if (HistoryMessage *msg = item->toHistoryMessage()) {
if (msg->hasFromPhoto()) {
enumerateUserpics([&lnk, &lnkhost, msg, &point](HistoryMessage *message, int userpicTop) -> bool {
enumerateUserpics([&lnk, &lnkhost, &point](HistoryMessage *message, int userpicTop) -> bool {
// stop enumeration if the userpic is above our point
if (userpicTop + st::msgPhotoSize <= point.y()) {
return false;
@ -1697,7 +1699,7 @@ void HistoryInner::onUpdateSelected() {
// stop enumeration if we've found a userpic under the cursor
if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
lnk = message->from()->openLink();
lnkhost = msg;
lnkhost = message;
return false;
}
return true;
@ -2204,15 +2206,24 @@ void BotKeyboard::mouseReleaseEvent(QMouseEvent *e) {
}
}
void BotKeyboard::enterEvent(QEvent *e) {
_lastMousePos = QCursor::pos();
updateSelected();
}
void BotKeyboard::leaveEvent(QEvent *e) {
_lastMousePos = QPoint(-1, -1);
updateSelected();
}
void BotKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
if (!_impl) return;
_impl->clickHandlerActiveChanged(p, active);
}
void BotKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
if (!_impl) return;
_impl->clickHandlerPressedChanged(p, pressed);
}
bool BotKeyboard::updateMarkup(HistoryItem *to) {

View File

@ -311,6 +311,7 @@ public:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
bool updateMarkup(HistoryItem *last);

View File

@ -31,6 +31,7 @@ const TextParseOptions &itemTextNoMonoOptions(History *h, PeerData *f);
enum RoundCorners {
NoneCorners = 0x00, // for images
BlackCorners,
WhiteCorners,
ServiceCorners,
ServiceSelectedCorners,
SelectedOverlayCorners,