Fixed crash in BotKeyboard resize. Fixed elided single-line Text layout.

This commit is contained in:
John Preston 2016-06-17 16:27:21 +03:00
parent e38b7cd465
commit 963000386f
4 changed files with 30 additions and 55 deletions

View File

@ -2445,21 +2445,6 @@ int BotKeyboard::Style::minButtonWidth(HistoryMessageReplyMarkup::Button::Type t
return result; return result;
} }
void BotKeyboard::resizeEvent(QResizeEvent *e) {
if (!_impl) return;
updateStyle();
_height = _impl->naturalHeight() + st::botKbScroll.deltat + st::botKbScroll.deltab;
if (_maximizeSize) _height = qMax(_height, _maxOuterHeight);
if (height() != _height) {
resize(width(), _height);
return;
}
_impl->resize(width() - _st->margin - st::botKbScroll.width, _height - (st::botKbScroll.deltat + st::botKbScroll.deltab));
}
void BotKeyboard::mousePressEvent(QMouseEvent *e) { void BotKeyboard::mousePressEvent(QMouseEvent *e) {
_lastMousePos = e->globalPos(); _lastMousePos = e->globalPos();
updateSelected(); updateSelected();
@ -2529,14 +2514,8 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
} }
} }
updateStyle(); resizeToWidth(width(), _maxOuterHeight);
_height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
if (_maximizeSize) _height = qMax(_height, _maxOuterHeight);
if (height() != _height) {
resize(width(), _height);
} else {
resizeEvent(nullptr);
}
return true; return true;
} }
@ -2548,13 +2527,23 @@ bool BotKeyboard::forceReply() const {
return _forceReply; return _forceReply;
} }
void BotKeyboard::resizeToWidth(int width, int maxOuterHeight) { void BotKeyboard::resizeToWidth(int newWidth, int maxOuterHeight) {
updateStyle(width);
_height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
_maxOuterHeight = maxOuterHeight; _maxOuterHeight = maxOuterHeight;
if (_maximizeSize) _height = qMax(_height, _maxOuterHeight); updateStyle(newWidth);
resize(width, _height); _height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
if (_maximizeSize) {
accumulate_max(_height, _maxOuterHeight);
}
if (_impl) {
int implWidth = newWidth - _st->margin - st::botKbScroll.width;
int implHeight = _height - (st::botKbScroll.deltat + st::botKbScroll.deltab);
_impl->resize(implWidth, implHeight);
}
QSize newSize(newWidth, _height);
if (newSize != size()) {
resize(newSize);
}
} }
bool BotKeyboard::maximizeSize() const { bool BotKeyboard::maximizeSize() const {
@ -2565,10 +2554,10 @@ bool BotKeyboard::singleUse() const {
return _singleUse; return _singleUse;
} }
void BotKeyboard::updateStyle(int32 w) { void BotKeyboard::updateStyle(int newWidth) {
if (!_impl) return; if (!_impl) return;
int implWidth = ((w < 0) ? width() : w) - st::botKbButton.margin - st::botKbScroll.width; int implWidth = newWidth - st::botKbButton.margin - st::botKbScroll.width;
_st = _impl->isEnoughSpace(implWidth, st::botKbButton) ? &st::botKbButton : &st::botKbTinyButton; _st = _impl->isEnoughSpace(implWidth, st::botKbButton) ? &st::botKbButton : &st::botKbTinyButton;
_impl->setStyle(std_::make_unique<Style>(this, *_st)); _impl->setStyle(std_::make_unique<Style>(this, *_st));
@ -2594,13 +2583,6 @@ QString BotKeyboard::tooltipText() const {
return QString(); return QString();
} }
//void BotKeyboard::onParentScrolled() {
// // Holding scrollarea can fire scrolled() event from a resize() call before
// // the resizeEvent() is called, which prepares _impl for updateSelected() call.
// // Calling updateSelected() without delay causes _impl->getState() before _impl->resize().
// QMetaObject::invokeMethod(this, "updateSelected", Qt::QueuedConnection);
//}
void BotKeyboard::updateSelected() { void BotKeyboard::updateSelected() {
PopupTooltip::Show(1000, this); PopupTooltip::Show(1000, this);
@ -3086,8 +3068,6 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
_kbScroll.setWidget(&_keyboard); _kbScroll.setWidget(&_keyboard);
_kbScroll.hide(); _kbScroll.hide();
// connect(&_kbScroll, SIGNAL(scrolled()), &_keyboard, SLOT(onParentScrolled()));
updateScrollColors(); updateScrollColors();
_historyToEnd->installEventFilter(this); _historyToEnd->installEventFilter(this);

View File

@ -357,7 +357,6 @@ public:
BotKeyboard(); BotKeyboard();
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void mousePressEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
@ -371,7 +370,7 @@ public:
bool forceReply() const; bool forceReply() const;
void step_selected(uint64 ms, bool timer); void step_selected(uint64 ms, bool timer);
void resizeToWidth(int width, int maxOuterHeight); void resizeToWidth(int newWidth, int maxOuterHeight);
bool maximizeSize() const; bool maximizeSize() const;
bool singleUse() const; bool singleUse() const;
@ -388,18 +387,10 @@ public:
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
//public slots:
//
// void onParentScrolled();
//private slots:
private: private:
void updateSelected(); void updateSelected();
private: void updateStyle(int newWidth);
void updateStyle(int32 w = -1);
void clearSelection(); void clearSelection();
FullMsgId _wasForMsgId; FullMsgId _wasForMsgId;

View File

@ -78,8 +78,6 @@ extern f_PropVariantToString PropVariantToString;
typedef HRESULT (FAR STDAPICALLTYPE *f_RoGetActivationFactory)(_In_ HSTRING activatableClassId, _In_ REFIID iid, _COM_Outptr_ void ** factory); typedef HRESULT (FAR STDAPICALLTYPE *f_RoGetActivationFactory)(_In_ HSTRING activatableClassId, _In_ REFIID iid, _COM_Outptr_ void ** factory);
extern f_RoGetActivationFactory RoGetActivationFactory; extern f_RoGetActivationFactory RoGetActivationFactory;
// api-ms-win-core-winrt-string-l1-1-0.dll
typedef HRESULT (FAR STDAPICALLTYPE *f_WindowsCreateStringReference)(_In_reads_opt_(length + 1) PCWSTR sourceString, UINT32 length, _Out_ HSTRING_HEADER * hstringHeader, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string); typedef HRESULT (FAR STDAPICALLTYPE *f_WindowsCreateStringReference)(_In_reads_opt_(length + 1) PCWSTR sourceString, UINT32 length, _Out_ HSTRING_HEADER * hstringHeader, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string);
extern f_WindowsCreateStringReference WindowsCreateStringReference; extern f_WindowsCreateStringReference WindowsCreateStringReference;

View File

@ -943,12 +943,18 @@ public:
_y = top; _y = top;
_yFrom = yFrom + top; _yFrom = yFrom + top;
_yTo = (yTo < 0) ? -1 : (yTo + top); _yTo = (yTo < 0) ? -1 : (yTo + top);
if (_elideLast) {
_yToElide = _yTo;
}
_selection = selection; _selection = selection;
_fullWidthSelection = fullWidthSelection; _fullWidthSelection = fullWidthSelection;
_wLeft = _w = w; _wLeft = _w = w;
if (_elideLast) {
_yToElide = _yTo;
if (_elideRemoveFromEnd > 0 && !_t->_blocks.isEmpty()) {
int firstBlockHeight = countBlockHeight(_t->_blocks.front(), _t->_font);
if (_y + firstBlockHeight >= _yToElide) {
_wLeft -= _elideRemoveFromEnd;
}
}
}
_str = _t->_text.unicode(); _str = _t->_text.unicode();
if (_p) { if (_p) {