Debian Codegraph @

src/album/widgets/expansionpanel.cpp

raw
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co.,Ltd.
3 *
4 * Author: Ji XiangLong <[email protected]>
5 *
6 * Maintainer: WangYu <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "expansionpanel.h"
22
23 #include <QGraphicsDropShadowEffect>
24 #include <QVBoxLayout>
25 #include <iostream>
26
27 ExpansionPanel::ExpansionPanel(QWidget *parent)
28 : DBlurEffectWidget(parent)
29 {
30 this->setWindowFlag(Qt::Popup);
31 layout = new QVBoxLayout;
32
33 //设置圆角
34 setBlurRectXRadius(18);
35 setBlurRectYRadius(18);
36 setBlurEnabled(true);
37 setMode(DBlurEffectWidget::GaussianBlur);
38
39 //绘制背景阴影
40 setAttribute(Qt::WA_TranslucentBackground);
41 const int nMargin = 10; // 设置阴影宽度
42 shadow_effect = new QGraphicsDropShadowEffect(this);
43 shadow_effect->setOffset(0, 0);
44 shadow_effect->setBlurRadius(nMargin);
45 this->setGraphicsEffect(shadow_effect); //最外层的Frame
46
47 //设置边距
48 layout->setContentsMargins(0, 12, 0, 12);
49
50 setLayout(layout);
51 }
52
53 void ExpansionPanel::changeTheme(Dtk::Gui::DGuiApplicationHelper::ColorType themeType)
54 {
55 if (themeType == 1) {
56 //背景颜色及透明度
57 auto effect = QColor("#EBEBEB");
58 effect.setAlpha(80);
59 setMaskColor(effect);
60 shadow_effect->setColor(QColor(150, 150, 150));
61 } else {
62 //背景颜色及透明度
63 auto effect = QColor("#404040");
64 setMaskColor(effect);
65 shadow_effect->setColor(QColor("#404040"));
66 }
67 }
68
69 void ExpansionPanel::onButtonClicked(FilteData data)
70 {
71 emit currentItemChanged(data);
72 this->hide();
73 }
74
75 void ExpansionPanel::addNewButton(FilteData &data)
76 {
77 auto button = new ToolButton(this);
78 buttons[buttonCount++] = button;
79 button->setText(data.text);
80 button->setLIcon(data.icon_l);
81 button->setRIcon(data.icon_r);
82 button->setRWIcon((data.icon_r_path + "_hover"));
83 button->setFixedSize(190, 34);
84 layout->addWidget(button);
85 connect(button, &ToolButton::clicked, [data, this]() {
86 onButtonClicked(data);
87 });
88 }
89
90 void ExpansionPanel::focusOutEvent(QFocusEvent *e)
91 {
92 hide();
93 DBlurEffectWidget::focusOutEvent(e);
94 }