Debian Codegraph @

src/album/thumbnail/timelinedatewidget.cpp

raw
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
3 *
4 * Author: ZhangYong <[email protected]>
5 *
6 * Maintainer: ZhangYong <[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 "timelinedatewidget.h"
22
23 #include <QVBoxLayout>
24 #include <QHBoxLayout>
25
26 #include <DFontSizeManager>
27 #include <DApplicationHelper>
28
29 TimeLineDateWidget::TimeLineDateWidget(QStandardItem *item, const QString &time, const QString &num)
30 : m_chooseBtn(nullptr), m_pDate(nullptr), m_pNum(nullptr), m_currentItem(item)
31 {
32 this->setContentsMargins(0, 20, 0, 0);
33 this->setFixedHeight(90);
34 //时间线日期
35 m_pDate = new DLabel(this);
36 DFontSizeManager::instance()->bind(m_pDate, DFontSizeManager::T3, QFont::DemiBold);
37 QFont ft1 = DFontSizeManager::instance()->get(DFontSizeManager::T3);
38 ft1.setFamily("SourceHanSansSC");
39 ft1.setWeight(QFont::DemiBold);
40 DPalette color = DApplicationHelper::instance()->palette(m_pDate);
41 color.setBrush(DPalette::Text, color.color(DPalette::ToolTipText));
42 m_pDate->setFont(ft1);
43 m_pDate->setForegroundRole(DPalette::Text);
44 m_pDate->setPalette(color);
45 m_pDate->setText(time);
46
47 //数量
48 m_pNum = new DLabel(this);
49 //TODO:维语适配
50 // if (QLocale::system().language() == QLocale::Uighur) {
51 // m_pNum->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
52 // }
53 DFontSizeManager::instance()->bind(m_pNum, DFontSizeManager::T6, QFont::Medium);
54 QFont ft2 = DFontSizeManager::instance()->get(DFontSizeManager::T6);
55 ft2.setFamily("SourceHanSansSC");
56 ft2.setWeight(QFont::Medium);
57 DPalette pal = DApplicationHelper::instance()->palette(m_pNum);
58 QColor color_BT = pal.color(DPalette::BrightText);
59
60 m_pNum->setFont(ft2);
61 m_pNum->setForegroundRole(DPalette::Text);
62 m_pNum->setPalette(pal);
63 m_pNum->setText(num);
64
65 DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
66 if (themeType == DGuiApplicationHelper::LightType) {
67 color_BT.setAlphaF(0.5);
68 pal.setBrush(DPalette::Text, color_BT);
69 m_pNum->setForegroundRole(DPalette::Text);
70 m_pNum->setPalette(pal);
71 } else if (themeType == DGuiApplicationHelper::DarkType) {
72 color_BT.setAlphaF(0.75);
73 pal.setBrush(DPalette::Text, color_BT);
74 m_pNum->setForegroundRole(DPalette::Text);
75 m_pNum->setPalette(pal);
76 }
77
78 //选择按钮
79 m_chooseBtn = new DCommandLinkButton(QObject::tr("Select"));
80 connect(m_chooseBtn, &DCommandLinkButton::clicked, this, &TimeLineDateWidget::onChooseBtnCliked);
81 DFontSizeManager::instance()->bind(m_chooseBtn, DFontSizeManager::T5);
82 m_chooseBtn->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T5));
83 m_chooseBtn->setFocusPolicy(Qt::NoFocus);
84 m_chooseBtn->setVisible(false);
85 //占位btn,防止显影选择按钮时,ui变化
86 m_pbtn = new DCommandLinkButton(" ");
87 m_pbtn->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T5));
88 m_pbtn->setFocusPolicy(Qt::NoFocus);
89
90 QHBoxLayout *NumandBtnLayout = new QHBoxLayout();
91 NumandBtnLayout->setContentsMargins(0, 0, 0, 0);
92 NumandBtnLayout->addWidget(m_pNum);
93 NumandBtnLayout->addStretch();
94 NumandBtnLayout->addWidget(m_pbtn);
95 NumandBtnLayout->addWidget(m_chooseBtn);
96
97 QVBoxLayout *TitleViewLayout = new QVBoxLayout(this);
98 TitleViewLayout->setContentsMargins(6, 0, 23, 0);
99 TitleViewLayout->addWidget(m_pDate);
100 TitleViewLayout->addStretch();
101 TitleViewLayout->addLayout(NumandBtnLayout);
102 this->setLayout(TitleViewLayout);
103 }
104
105 void TimeLineDateWidget::onChooseBtnCliked()
106 {
107 if (QObject::tr("Select") == m_chooseBtn->text()) {
108 m_chooseBtn->setText(QObject::tr("Unselect"));
109 emit sigIsSelectCurrentDatePic(true, m_currentItem);
110 } else {
111 m_chooseBtn->setText(QObject::tr("Select"));
112 emit sigIsSelectCurrentDatePic(false, m_currentItem);
113 }
114 }
115
116 void TimeLineDateWidget::onChangeChooseBtnVisible(bool visible)
117 {
118 m_chooseBtn->setVisible(visible);
119 }
120
121 void TimeLineDateWidget::onTimeLinePicSelectAll(bool selectall)
122 {
123 if (selectall) { //已经全选,btn变为取消全选
124 m_chooseBtn->setText(QObject::tr("Unselect"));
125 } else { //非全选状态,btn变为全选
126 m_chooseBtn->setText(QObject::tr("Select"));
127 }
128 }
129
130 QString TimeLineDateWidget::onGetBtnStatus()
131 {
132 return m_chooseBtn->text();
133 }
134
135 importTimeLineDateWidget::importTimeLineDateWidget(QStandardItem *item, const QString &time, const QString &num)
136 : m_chooseBtn(nullptr), m_pDateandNum(nullptr), m_currentItem(item)
137 {
138 this->setContentsMargins(0, 0, 0, 0);
139 this->setFixedHeight(35);
140
141 //时间+照片数量
142 m_pDateandNum = new DLabel(this);
143 DFontSizeManager::instance()->bind(m_pDateandNum, DFontSizeManager::T6, QFont::Medium);
144 QFont ft1 = DFontSizeManager::instance()->get(DFontSizeManager::T6);
145 ft1.setFamily("SourceHanSansSC");
146 ft1.setWeight(QFont::Medium);
147 DPalette pal = DApplicationHelper::instance()->palette(m_pDateandNum);
148 QColor color_BT = pal.color(DPalette::BrightText);
149 m_pDateandNum->setFont(ft1);
150 m_pDateandNum->setForegroundRole(DPalette::Text);
151 m_pDateandNum->setPalette(pal);
152 QString tempTimeAndNumber = time + " " + num;
153 m_pDateandNum->setText(tempTimeAndNumber);
154
155 DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
156 if (themeType == DGuiApplicationHelper::LightType) {
157 color_BT.setAlphaF(0.5);
158 pal.setBrush(DPalette::Text, color_BT);
159 m_pDateandNum->setForegroundRole(DPalette::Text);
160 m_pDateandNum->setPalette(pal);
161 } else if (themeType == DGuiApplicationHelper::DarkType) {
162 color_BT.setAlphaF(0.75);
163 pal.setBrush(DPalette::Text, color_BT);
164 m_pDateandNum->setForegroundRole(DPalette::Text);
165 m_pDateandNum->setPalette(pal);
166 }
167
168 //选择按钮
169 m_chooseBtn = new DCommandLinkButton(QObject::tr("Select"));
170 connect(m_chooseBtn, &DCommandLinkButton::clicked, this, &importTimeLineDateWidget::onChooseBtnCliked);
171 DFontSizeManager::instance()->bind(m_chooseBtn, DFontSizeManager::T5);
172 m_chooseBtn->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T5));
173 m_chooseBtn->setFocusPolicy(Qt::NoFocus);
174 m_chooseBtn->setVisible(false);
175
176 //占位btn,防止显影选择按钮时,ui变化
177 m_pbtn = new DCommandLinkButton(" ");
178 m_pbtn->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T5));
179 m_pbtn->setFocusPolicy(Qt::NoFocus);
180
181 //开始布局
182 QHBoxLayout *TitleViewLayout = new QHBoxLayout(this);
183 TitleViewLayout->setContentsMargins(0, 0, 25, 0);
184 TitleViewLayout->addWidget(m_pDateandNum);
185 TitleViewLayout->addStretch();
186 TitleViewLayout->addWidget(m_pbtn);
187 TitleViewLayout->addWidget(m_chooseBtn);
188 this->setLayout(TitleViewLayout);
189 }
190
191 void importTimeLineDateWidget::onChooseBtnCliked()
192 {
193 if (QObject::tr("Select") == m_chooseBtn->text()) {
194 m_chooseBtn->setText(QObject::tr("Unselect"));
195 emit sigIsSelectCurrentDatePic(true, m_currentItem);
196 } else {
197 m_chooseBtn->setText(QObject::tr("Select"));
198 emit sigIsSelectCurrentDatePic(false, m_currentItem);
199 }
200 }
201
202 void importTimeLineDateWidget::onChangeChooseBtnVisible(bool visible)
203 {
204 m_chooseBtn->setVisible(visible);
205 }
206
207 void importTimeLineDateWidget::onTimeLinePicSelectAll(bool selectall)
208 {
209 if (selectall) { //已经全选,btn变为取消全选
210 m_chooseBtn->setText(QObject::tr("Unselect"));
211 } else { //非全选状态,btn变为全选
212 m_chooseBtn->setText(QObject::tr("Select"));
213 }
214 }
215
216 QString importTimeLineDateWidget::onGetBtnStatus()
217 {
218 return m_chooseBtn->text();
219 }