Fixed crash in dropdown menu.
This commit is contained in:
		
							parent
							
								
									79146e54b9
								
							
						
					
					
						commit
						a6a2a8dde0
					
				
					 4 changed files with 24 additions and 6 deletions
				
			
		|  | @ -33,7 +33,7 @@ DropdownMenu::DropdownMenu(QWidget *parent, const style::DropdownMenu &st) : Inn | ||||||
| void DropdownMenu::init() { | void DropdownMenu::init() { | ||||||
| 	InnerDropdown::setHiddenCallback([this] { hideFinish(); }); | 	InnerDropdown::setHiddenCallback([this] { hideFinish(); }); | ||||||
| 
 | 
 | ||||||
| 	_menu->sizeValue( | 	_menu->resizesFromInner( | ||||||
| 	) | rpl::start_with_next([=] { | 	) | rpl::start_with_next([=] { | ||||||
| 		resizeToContent(); | 		resizeToContent(); | ||||||
| 	}, _menu->lifetime()); | 	}, _menu->lifetime()); | ||||||
|  |  | ||||||
|  | @ -133,7 +133,7 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) { | ||||||
| 				_actionWidgets, | 				_actionWidgets, | ||||||
| 				std::greater<>(), | 				std::greater<>(), | ||||||
| 				&ItemBase::width))->contentWidth(); | 				&ItemBase::width))->contentWidth(); | ||||||
| 		resize(newWidth, height()); | 		resizeFromInner(newWidth, height()); | ||||||
| 	}, widget->lifetime()); | 	}, widget->lifetime()); | ||||||
| 
 | 
 | ||||||
| 	_actionWidgets.push_back(std::move(widget)); | 	_actionWidgets.push_back(std::move(widget)); | ||||||
|  | @ -143,7 +143,7 @@ not_null<QAction*> Menu::addAction(base::unique_qptr<ItemBase> widget) { | ||||||
| 		0, | 		0, | ||||||
| 		ranges::plus(), | 		ranges::plus(), | ||||||
| 		&ItemBase::height); | 		&ItemBase::height); | ||||||
| 	resize(width(), newHeight); | 	resizeFromInner(width(), newHeight); | ||||||
| 	updateSelected(QCursor::pos()); | 	updateSelected(QCursor::pos()); | ||||||
| 
 | 
 | ||||||
| 	return action; | 	return action; | ||||||
|  | @ -164,7 +164,7 @@ void Menu::clearActions() { | ||||||
| 			delete action; | 			delete action; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	resize(_forceWidth ? _forceWidth : _st.widthMin, _st.skip * 2); | 	resizeFromInner(_forceWidth ? _forceWidth : _st.widthMin, _st.skip * 2); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Menu::finishAnimating() { | void Menu::finishAnimating() { | ||||||
|  | @ -177,6 +177,18 @@ bool Menu::empty() const { | ||||||
| 	return _actionWidgets.empty(); | 	return _actionWidgets.empty(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Menu::resizeFromInner(int w, int h) { | ||||||
|  | 	if ((w == width()) && (h == height())) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	resize(w, h); | ||||||
|  | 	_resizesFromInner.fire({}); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | rpl::producer<> Menu::resizesFromInner() const { | ||||||
|  | 	return _resizesFromInner.events(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Menu::setShowSource(TriggeredSource source) { | void Menu::setShowSource(TriggeredSource source) { | ||||||
| 	_mouseSelection = (source == TriggeredSource::Mouse); | 	_mouseSelection = (source == TriggeredSource::Mouse); | ||||||
| 	setSelected((source == TriggeredSource::Mouse || _actions.empty()) ? -1 : 0); | 	setSelected((source == TriggeredSource::Mouse || _actions.empty()) ? -1 : 0); | ||||||
|  | @ -188,7 +200,7 @@ const std::vector<not_null<QAction*>> &Menu::actions() const { | ||||||
| 
 | 
 | ||||||
| void Menu::setForceWidth(int forceWidth) { | void Menu::setForceWidth(int forceWidth) { | ||||||
| 	_forceWidth = forceWidth; | 	_forceWidth = forceWidth; | ||||||
| 	resize(_forceWidth, height()); | 	resizeFromInner(_forceWidth, height()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Menu::updateSelected(QPoint globalPosition) { | void Menu::updateSelected(QPoint globalPosition) { | ||||||
|  |  | ||||||
|  | @ -76,6 +76,8 @@ public: | ||||||
| 	} | 	} | ||||||
| 	void handleMouseRelease(QPoint globalPosition); | 	void handleMouseRelease(QPoint globalPosition); | ||||||
| 
 | 
 | ||||||
|  | 	rpl::producer<> resizesFromInner() const; | ||||||
|  | 
 | ||||||
| protected: | protected: | ||||||
| 	void keyPressEvent(QKeyEvent *e) override; | 	void keyPressEvent(QKeyEvent *e) override; | ||||||
| 	void mouseMoveEvent(QMouseEvent *e) override; | 	void mouseMoveEvent(QMouseEvent *e) override; | ||||||
|  | @ -98,6 +100,8 @@ private: | ||||||
| 
 | 
 | ||||||
| 	ItemBase *findSelectedAction() const; | 	ItemBase *findSelectedAction() const; | ||||||
| 
 | 
 | ||||||
|  | 	void resizeFromInner(int w, int h); | ||||||
|  | 
 | ||||||
| 	const style::Menu &_st; | 	const style::Menu &_st; | ||||||
| 
 | 
 | ||||||
| 	Fn<void(const CallbackData &data)> _activatedCallback; | 	Fn<void(const CallbackData &data)> _activatedCallback; | ||||||
|  | @ -118,6 +122,8 @@ private: | ||||||
| 	int _selected = -1; | 	int _selected = -1; | ||||||
| 	bool _childShown = false; | 	bool _childShown = false; | ||||||
| 
 | 
 | ||||||
|  | 	rpl::event_stream<> _resizesFromInner; | ||||||
|  | 
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } // namespace Ui::Menu
 | } // namespace Ui::Menu
 | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ void PopupMenu::init() { | ||||||
| 		hideMenu(true); | 		hideMenu(true); | ||||||
| 	}, lifetime()); | 	}, lifetime()); | ||||||
| 
 | 
 | ||||||
| 	_menu->sizeValue( | 	_menu->resizesFromInner( | ||||||
| 	) | rpl::start_with_next([=] { | 	) | rpl::start_with_next([=] { | ||||||
| 		handleMenuResize(); | 		handleMenuResize(); | ||||||
| 	}, _menu->lifetime()); | 	}, _menu->lifetime()); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 23rd
						23rd