2021-12-04 21:23:58 +00:00
|
|
|
#include "SvgToolButton.hpp"
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
namespace Bloom::Widgets
|
|
|
|
|
{
|
|
|
|
|
SvgToolButton::SvgToolButton(QWidget* parent): QToolButton(parent) {
|
|
|
|
|
this->setButtonWidth(10);
|
|
|
|
|
this->setButtonHeight(10);
|
|
|
|
|
}
|
2021-12-04 21:23:58 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
void SvgToolButton::childEvent(QChildEvent* childEvent) {
|
|
|
|
|
if ((childEvent->added() || childEvent->polished()) && childEvent->child()->isWidgetType()) {
|
|
|
|
|
/*
|
|
|
|
|
* If a menu widget has been added as a child to this SvgToolButton, associate the menu with the button
|
|
|
|
|
* via QToolButton::setMenu().
|
|
|
|
|
*/
|
|
|
|
|
auto* menuWidget = qobject_cast<QMenu*>(childEvent->child());
|
|
|
|
|
if (menuWidget != nullptr && menuWidget != this->menu()) {
|
2022-07-17 15:39:24 +01:00
|
|
|
if (this->contextMenuEnabled) {
|
|
|
|
|
this->contextMenu = menuWidget;
|
|
|
|
|
this->setContextMenuPolicy(Qt::ContextMenuPolicy::DefaultContextMenu);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this->setMenu(menuWidget);
|
|
|
|
|
}
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-12-04 21:23:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-17 15:39:24 +01:00
|
|
|
|
|
|
|
|
void SvgToolButton::contextMenuEvent(QContextMenuEvent* event) {
|
|
|
|
|
if (this->contextMenu != nullptr) {
|
|
|
|
|
this->contextMenu->exec(this->mapToGlobal(QPoint(0, this->height())));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-04 21:23:58 +00:00
|
|
|
}
|