mirror of https://github.com/procxx/kepka.git
				
				
				
			Fixed some ClickHandler bugs, bot keyboard active/pressed
states done, handling enterEvent() for ClickHandler activate.
This commit is contained in:
		
							parent
							
								
									7f6cf32cdd
								
							
						
					
					
						commit
						3210aecbd2
					
				| 
						 | 
					@ -2012,6 +2012,7 @@ namespace App {
 | 
				
			||||||
			::cornersMask[i]->setDevicePixelRatio(cRetinaFactor());
 | 
								::cornersMask[i]->setDevicePixelRatio(cRetinaFactor());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		prepareCorners(BlackCorners, st::msgRadius, st::black);
 | 
							prepareCorners(BlackCorners, st::msgRadius, st::black);
 | 
				
			||||||
 | 
							prepareCorners(WhiteCorners, st::msgRadius, st::white);
 | 
				
			||||||
		prepareCorners(ServiceCorners, st::msgRadius, st::msgServiceBg);
 | 
							prepareCorners(ServiceCorners, st::msgRadius, st::msgServiceBg);
 | 
				
			||||||
		prepareCorners(ServiceSelectedCorners, st::msgRadius, st::msgServiceSelectBg);
 | 
							prepareCorners(ServiceSelectedCorners, st::msgRadius, st::msgServiceSelectBg);
 | 
				
			||||||
		prepareCorners(SelectedOverlayCorners, st::msgRadius, st::msgSelectOverlay);
 | 
							prepareCorners(SelectedOverlayCorners, st::msgRadius, st::msgSelectOverlay);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,6 +83,11 @@ void FlatLabel::mouseReleaseEvent(QMouseEvent *e) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void FlatLabel::enterEvent(QEvent *e) {
 | 
				
			||||||
 | 
						_lastMousePos = QCursor::pos();
 | 
				
			||||||
 | 
						updateHover();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FlatLabel::leaveEvent(QEvent *e) {
 | 
					void FlatLabel::leaveEvent(QEvent *e) {
 | 
				
			||||||
	ClickHandler::clearActive(this);
 | 
						ClickHandler::clearActive(this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,7 @@ public:
 | 
				
			||||||
	void mouseMoveEvent(QMouseEvent *e);
 | 
						void mouseMoveEvent(QMouseEvent *e);
 | 
				
			||||||
	void mousePressEvent(QMouseEvent *e);
 | 
						void mousePressEvent(QMouseEvent *e);
 | 
				
			||||||
	void mouseReleaseEvent(QMouseEvent *e);
 | 
						void mouseReleaseEvent(QMouseEvent *e);
 | 
				
			||||||
 | 
						void enterEvent(QEvent *e);
 | 
				
			||||||
	void leaveEvent(QEvent *e);
 | 
						void leaveEvent(QEvent *e);
 | 
				
			||||||
	void updateLink();
 | 
						void updateLink();
 | 
				
			||||||
	void setOpacity(float64 o);
 | 
						void setOpacity(float64 o);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2830,34 +2830,36 @@ void ReplyKeyboard::getState(ClickHandlerPtr &lnk, int x, int y) const {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ReplyKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
 | 
					void ReplyKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
 | 
				
			||||||
	/*if (newSel != _sel) {
 | 
						if (!p) return;
 | 
				
			||||||
		if (newSel < 0) {
 | 
					
 | 
				
			||||||
			setCursor(style::cur_default);
 | 
						bool startAnimation = false;
 | 
				
			||||||
		} else if (_sel < 0) {
 | 
						for (int i = 0, rows = _rows.size(); i != rows; ++i) {
 | 
				
			||||||
			setCursor(style::cur_pointer);
 | 
							const ButtonRow &row(_rows.at(i));
 | 
				
			||||||
		}
 | 
							for (int j = 0, cols = row.size(); j != cols; ++j) {
 | 
				
			||||||
		bool startanim = false;
 | 
								if (row.at(j).link == p) {
 | 
				
			||||||
		if (_sel >= 0) {
 | 
									bool startAnimation = _animations.isEmpty();
 | 
				
			||||||
			_animations.remove(_sel + 1);
 | 
					
 | 
				
			||||||
			if (_animations.find(-_sel - 1) == _animations.end()) {
 | 
									int indexForAnimation = i * MatrixRowShift + j + 1;
 | 
				
			||||||
				if (_animations.isEmpty()) startanim = true;
 | 
									if (!active) {
 | 
				
			||||||
				_animations.insert(-_sel - 1, getms());
 | 
										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) {
 | 
					void ReplyKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
 | 
				
			||||||
 | 
						_st->repaint(_item);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ReplyKeyboard::step_selected(uint64 ms, bool timer) {
 | 
					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 {
 | 
					void HistoryMessage::KeyboardStyle::paintButtonBg(Painter &p, const QRect &rect, bool down, float64 howMuchOver) const {
 | 
				
			||||||
	App::roundRect(p, rect, App::msgServiceBg(), ServiceCorners);
 | 
						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)
 | 
					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()) {
 | 
						if (const ReplyKeyboard *keyboard = inlineReplyKeyboard()) {
 | 
				
			||||||
		int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
 | 
							int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
 | 
				
			||||||
		height -= h;
 | 
							height -= h;
 | 
				
			||||||
		int top = marginTop() + height;
 | 
							int top = height + st::msgBotKbButton.margin - marginBottom();
 | 
				
			||||||
		p.translate(left, top);
 | 
							p.translate(left, top);
 | 
				
			||||||
		keyboard->paint(p, r.translated(-left, -top));
 | 
							keyboard->paint(p, r.translated(-left, -top));
 | 
				
			||||||
		p.translate(-left, -top);
 | 
							p.translate(-left, -top);
 | 
				
			||||||
| 
						 | 
					@ -7312,7 +7322,7 @@ void HistoryMessage::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i
 | 
				
			||||||
	if (const ReplyKeyboard *keyboard = inlineReplyKeyboard()) {
 | 
						if (const ReplyKeyboard *keyboard = inlineReplyKeyboard()) {
 | 
				
			||||||
		int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
 | 
							int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
 | 
				
			||||||
		height -= h;
 | 
							height -= h;
 | 
				
			||||||
		int top = marginTop() + height;
 | 
							int top = height + st::msgBotKbButton.margin - marginBottom();
 | 
				
			||||||
		if (x >= left && x < left + width && y >= top && y < _height - marginBottom()) {
 | 
							if (x >= left && x < left + width && y >= top && y < _height - marginBottom()) {
 | 
				
			||||||
			return keyboard->getState(lnk, x - left, y - top);
 | 
								return keyboard->getState(lnk, x - left, y - top);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1244,7 +1244,7 @@ public:
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	HistoryMedia *_p;
 | 
						HistoryMedia *_p = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1483,6 +1483,7 @@ void HistoryInner::updateSize() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HistoryInner::enterEvent(QEvent *e) {
 | 
					void HistoryInner::enterEvent(QEvent *e) {
 | 
				
			||||||
 | 
						dragActionUpdate(QCursor::pos());
 | 
				
			||||||
	return QWidget::enterEvent(e);
 | 
						return QWidget::enterEvent(e);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1685,10 +1686,11 @@ void HistoryInner::onUpdateSelected() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if (item) {
 | 
						} else if (item) {
 | 
				
			||||||
		item->getState(lnk, cursorState, m.x(), m.y());
 | 
							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 (!lnk && m.x() >= st::msgMargin.left() && m.x() < st::msgMargin.left() + st::msgPhotoSize) {
 | 
				
			||||||
			if (HistoryMessage *msg = item->toHistoryMessage()) {
 | 
								if (HistoryMessage *msg = item->toHistoryMessage()) {
 | 
				
			||||||
				if (msg->hasFromPhoto()) {
 | 
									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
 | 
											// stop enumeration if the userpic is above our point
 | 
				
			||||||
						if (userpicTop + st::msgPhotoSize <= point.y()) {
 | 
											if (userpicTop + st::msgPhotoSize <= point.y()) {
 | 
				
			||||||
							return false;
 | 
												return false;
 | 
				
			||||||
| 
						 | 
					@ -1697,7 +1699,7 @@ void HistoryInner::onUpdateSelected() {
 | 
				
			||||||
						// stop enumeration if we've found a userpic under the cursor
 | 
											// stop enumeration if we've found a userpic under the cursor
 | 
				
			||||||
						if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
 | 
											if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
 | 
				
			||||||
							lnk = message->from()->openLink();
 | 
												lnk = message->from()->openLink();
 | 
				
			||||||
							lnkhost = msg;
 | 
												lnkhost = message;
 | 
				
			||||||
							return false;
 | 
												return false;
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						return true;
 | 
											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) {
 | 
					void BotKeyboard::leaveEvent(QEvent *e) {
 | 
				
			||||||
	_lastMousePos = QPoint(-1, -1);
 | 
						_lastMousePos = QPoint(-1, -1);
 | 
				
			||||||
	updateSelected();
 | 
						updateSelected();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BotKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
 | 
					void BotKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
 | 
				
			||||||
 | 
						if (!_impl) return;
 | 
				
			||||||
 | 
						_impl->clickHandlerActiveChanged(p, active);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BotKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
 | 
					void BotKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
 | 
				
			||||||
 | 
						if (!_impl) return;
 | 
				
			||||||
 | 
						_impl->clickHandlerPressedChanged(p, pressed);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool BotKeyboard::updateMarkup(HistoryItem *to) {
 | 
					bool BotKeyboard::updateMarkup(HistoryItem *to) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -311,6 +311,7 @@ public:
 | 
				
			||||||
	void mousePressEvent(QMouseEvent *e);
 | 
						void mousePressEvent(QMouseEvent *e);
 | 
				
			||||||
	void mouseMoveEvent(QMouseEvent *e);
 | 
						void mouseMoveEvent(QMouseEvent *e);
 | 
				
			||||||
	void mouseReleaseEvent(QMouseEvent *e);
 | 
						void mouseReleaseEvent(QMouseEvent *e);
 | 
				
			||||||
 | 
						void enterEvent(QEvent *e);
 | 
				
			||||||
	void leaveEvent(QEvent *e);
 | 
						void leaveEvent(QEvent *e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool updateMarkup(HistoryItem *last);
 | 
						bool updateMarkup(HistoryItem *last);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,7 @@ const TextParseOptions &itemTextNoMonoOptions(History *h, PeerData *f);
 | 
				
			||||||
enum RoundCorners {
 | 
					enum RoundCorners {
 | 
				
			||||||
	NoneCorners = 0x00, // for images
 | 
						NoneCorners = 0x00, // for images
 | 
				
			||||||
	BlackCorners,
 | 
						BlackCorners,
 | 
				
			||||||
 | 
						WhiteCorners,
 | 
				
			||||||
	ServiceCorners,
 | 
						ServiceCorners,
 | 
				
			||||||
	ServiceSelectedCorners,
 | 
						ServiceSelectedCorners,
 | 
				
			||||||
	SelectedOverlayCorners,
 | 
						SelectedOverlayCorners,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue