2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2015-06-28 14:18:06 +00:00
|
|
|
#include <QStyle>
|
2014-12-18 01:30:50 +00:00
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QStyleOptionToolButton>
|
|
|
|
#include <QStylePainter>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "IconToolButton.h"
|
2014-12-18 01:30:50 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
IconToolButton::IconToolButton(QWidget* parent)
|
|
|
|
: QToolButton(parent)
|
2014-12-18 01:30:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QSize IconToolButton::sizeHint() const
|
2015-06-28 14:18:06 +00:00
|
|
|
{
|
2023-07-18 15:20:17 +00:00
|
|
|
auto option = QStyleOptionToolButton{};
|
2017-04-19 12:04:45 +00:00
|
|
|
initStyleOption(&option);
|
|
|
|
option.features = QStyleOptionToolButton::None;
|
|
|
|
option.toolButtonStyle = Qt::ToolButtonIconOnly;
|
2017-04-20 16:02:19 +00:00
|
|
|
QSize const size = style()->sizeFromContents(QStyle::CT_ToolButton, &option, iconSize(), this);
|
2015-06-28 14:18:06 +00:00
|
|
|
|
2023-07-18 15:20:17 +00:00
|
|
|
return size.expandedTo(iconSize() + QSize{ 4, 4 });
|
2015-06-28 14:18:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void IconToolButton::paintEvent(QPaintEvent* /*event*/)
|
2014-12-18 01:30:50 +00:00
|
|
|
{
|
2023-07-18 15:20:17 +00:00
|
|
|
auto painter = QStylePainter{ this };
|
|
|
|
auto option = QStyleOptionToolButton{};
|
2017-04-19 12:04:45 +00:00
|
|
|
initStyleOption(&option);
|
|
|
|
option.features = QStyleOptionToolButton::None;
|
|
|
|
option.toolButtonStyle = Qt::ToolButtonIconOnly;
|
|
|
|
painter.drawComplexControl(QStyle::CC_ToolButton, option);
|
2014-12-18 01:30:50 +00:00
|
|
|
}
|