2022-06-19 16:17:38 +08:00
|
|
|
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2019-09-29 01:40:19 +08:00
|
|
|
#include "bottombuttongroup.h"
|
|
|
|
|
2019-10-06 14:58:01 +08:00
|
|
|
#include "opacityhelper.h"
|
|
|
|
|
2019-09-30 23:02:44 +08:00
|
|
|
#include <functional>
|
|
|
|
|
2021-07-02 00:06:23 +08:00
|
|
|
#include <QToolButton>
|
2019-09-29 01:40:19 +08:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2021-07-02 00:06:23 +08:00
|
|
|
BottomButtonGroup::BottomButtonGroup(const std::vector<QAction *> &actionList, QWidget *parent)
|
2019-09-29 01:40:19 +08:00
|
|
|
: QGroupBox (parent)
|
2019-10-06 14:58:01 +08:00
|
|
|
, m_opacityHelper(new OpacityHelper(this))
|
2019-09-29 01:40:19 +08:00
|
|
|
{
|
|
|
|
QHBoxLayout * mainLayout = new QHBoxLayout(this);
|
|
|
|
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
this->setLayout(mainLayout);
|
|
|
|
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
|
this->setStyleSheet("BottomButtonGroup {"
|
|
|
|
"border: 1px solid gray;"
|
|
|
|
"border-top-left-radius: 10px;"
|
|
|
|
"border-top-right-radius: 10px;"
|
2019-09-29 22:18:38 +08:00
|
|
|
"border-style: none;"
|
|
|
|
"background-color:rgba(0,0,0,120)"
|
2019-09-29 01:40:19 +08:00
|
|
|
"}"
|
2021-07-02 00:06:23 +08:00
|
|
|
"QToolButton {"
|
2021-09-27 18:59:00 +08:00
|
|
|
"background:transparent;"
|
2021-09-30 01:41:20 +08:00
|
|
|
"}"
|
|
|
|
"QToolButton:!focus {"
|
|
|
|
"border-style: none;"
|
2019-09-29 01:40:19 +08:00
|
|
|
"}");
|
|
|
|
|
2021-07-02 00:06:23 +08:00
|
|
|
auto newActionBtn = [this](QAction * action) -> QToolButton * {
|
|
|
|
QToolButton * btn = new QToolButton(this);
|
|
|
|
btn->setDefaultAction(action);
|
2022-09-29 13:11:21 +08:00
|
|
|
btn->setIconSize(QSize(32, 32));
|
2019-09-29 01:40:19 +08:00
|
|
|
btn->setFixedSize(40, 40);
|
|
|
|
return btn;
|
|
|
|
};
|
2021-07-02 00:06:23 +08:00
|
|
|
|
|
|
|
for (QAction * action : actionList) {
|
|
|
|
addButton(newActionBtn(action));
|
|
|
|
}
|
2019-09-29 01:40:19 +08:00
|
|
|
}
|
|
|
|
|
2019-10-06 14:58:01 +08:00
|
|
|
void BottomButtonGroup::setOpacity(qreal opacity, bool animated)
|
|
|
|
{
|
|
|
|
m_opacityHelper->setOpacity(opacity, animated);
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:40:19 +08:00
|
|
|
void BottomButtonGroup::addButton(QAbstractButton *button)
|
|
|
|
{
|
|
|
|
layout()->addWidget(button);
|
|
|
|
updateGeometry();
|
|
|
|
}
|