| 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 "statusbar.h" |
| 22 |
#include "ac-desktop-define.h" |
| 23 |
#include <QGraphicsDropShadowEffect> |
| 24 |
#include <QItemSelectionModel> |
| 25 |
|
| 26 |
StatusBar::StatusBar(QWidget *parent) |
| 27 |
: DBlurEffectWidget(parent), m_pAllPicNumLabel(nullptr), m_pSlider(nullptr) |
| 28 |
, m_pstacklabel(nullptr), m_pimporting(nullptr), TextLabel(nullptr) |
| 29 |
, m_pStackedWidget(nullptr), loadingicon(nullptr), m_allPicNum(0) |
| 30 |
, interval(0), pic_count(0), m_index(0) |
| 31 |
{ |
| 32 |
initUI(); |
| 33 |
} |
| 34 |
|
| 35 |
void StatusBar::initUI() |
| 36 |
{ |
| 37 |
setFixedHeight(27); |
| 38 |
|
| 39 |
m_allPicNum = DBManager::instance()->getImgsCount(); |
| 40 |
|
| 41 |
m_pAllPicNumLabel = new DLabel(); |
| 42 |
AC_SET_OBJECT_NAME(m_pAllPicNumLabel, All_Pic_Count); |
| 43 |
AC_SET_ACCESSIBLE_NAME(m_pAllPicNumLabel, All_Pic_Count); |
| 44 |
m_pAllPicNumLabel->setEnabled(false); |
| 45 |
m_pAllPicNumLabel->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T8, QFont::Normal)); |
| 46 |
m_pAllPicNumLabel->setAlignment(Qt::AlignCenter); |
| 47 |
|
| 48 |
m_pimporting = new DWidget(this); |
| 49 |
TextLabel = new DLabel(); |
| 50 |
TextLabel->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T8)); |
| 51 |
|
| 52 |
TextLabel->setText(""); |
| 53 |
TextLabel->adjustSize(); |
| 54 |
TextLabel->setEnabled(false); |
| 55 |
loadingicon = new DSpinner(m_pimporting); |
| 56 |
loadingicon->hide(); |
| 57 |
loadingicon->setFixedSize(20, 20); |
| 58 |
|
| 59 |
m_pStackedWidget = new DStackedWidget(this); |
| 60 |
m_pStackedWidget->addWidget(m_pAllPicNumLabel); |
| 61 |
m_pStackedWidget->addWidget(TextLabel); |
| 62 |
|
| 63 |
m_pSlider = new DSlider(Qt::Horizontal, this); |
| 64 |
m_pSlider->slider()->setFocusPolicy(Qt::NoFocus); |
| 65 |
AC_SET_OBJECT_NAME(m_pSlider, Thumbnail_Slider); |
| 66 |
AC_SET_ACCESSIBLE_NAME(m_pSlider, Thumbnail_Slider); |
| 67 |
m_pSlider->setFixedWidth(180); |
| 68 |
m_pSlider->setFixedHeight(27); |
| 69 |
m_pSlider->setMinimum(0); |
| 70 |
m_pSlider->setMaximum(9); |
| 71 |
m_pSlider->slider()->setSingleStep(1); |
| 72 |
m_pSlider->slider()->setTickInterval(1); |
| 73 |
m_pSlider->setValue(2); |
| 74 |
|
| 75 |
QHBoxLayout *pHBoxLayout = new QHBoxLayout(); |
| 76 |
pHBoxLayout->setContentsMargins(0, 0, 0, 3); |
| 77 |
pHBoxLayout->addWidget(m_pStackedWidget, Qt::AlignCenter); |
| 78 |
this->setLayout(pHBoxLayout); |
| 79 |
|
| 80 |
initConnections(); |
| 81 |
} |
| 82 |
|
| 83 |
void StatusBar::initConnections() |
| 84 |
{ |
| 85 |
qRegisterMetaType<QStringList>("QStringList &"); |
| 86 |
connect(dApp->signalM, &SignalManager::updateStatusBarImportLabel, this, [ = ](QStringList paths, int count, QString album) { |
| 87 |
if (isVisible()) { |
| 88 |
imgpaths = paths; |
| 89 |
pic_count = count; |
| 90 |
m_bcustalbum = !album.isEmpty(); |
| 91 |
m_alubm = album; |
| 92 |
|
| 93 |
TextLabel->setAlignment(Qt::AlignCenter); |
| 94 |
TextLabel->adjustSize(); |
| 95 |
m_pStackedWidget->setCurrentIndex(1); |
| 96 |
interval = startTimer(3); |
| 97 |
|
| 98 |
} |
| 99 |
}); |
| 100 |
// 处理导入图片完成后,弹出重复照片提示 |
| 101 |
connect(dApp->signalM, &SignalManager::RepeatImportingTheSamePhotos, this, [ = ](QStringList importPaths, QStringList duplicatePaths, const QString & albumName) { |
| 102 |
Q_UNUSED(albumName) |
| 103 |
// 导入的照片不全是重复照片提示 |
| 104 |
if (importPaths.size() > 0 && duplicatePaths.size() > 0) { |
| 105 |
m_baddDuplicatePhotos = true; |
| 106 |
} |
| 107 |
}); |
| 108 |
|
| 109 |
connect(dApp->signalM, &SignalManager::sigExporting, this, [ = ](QString path) { |
| 110 |
if (isVisible()) { |
| 111 |
m_pStackedWidget->setCurrentIndex(1); |
| 112 |
QString string = tr("Exporting: %1"); |
| 113 |
TextLabel->setAlignment(Qt::AlignCenter); |
| 114 |
TextLabel->setText(string.arg(path)); |
| 115 |
TextLabel->adjustSize(); |
| 116 |
QTime time; |
| 117 |
time.start(); |
| 118 |
while (time.elapsed() < 5) |
| 119 |
QCoreApplication::processEvents(); |
| 120 |
} |
| 121 |
}); |
| 122 |
connect(dApp->signalM, &SignalManager::sigExporting, this, [ = ](QString path) { |
| 123 |
Q_UNUSED(path); |
| 124 |
if (isVisible()) { |
| 125 |
m_pStackedWidget->setCurrentIndex(0); |
| 126 |
} |
| 127 |
}); |
| 128 |
} |
| 129 |
|
| 130 |
void StatusBar::resizeEvent(QResizeEvent *e) |
| 131 |
{ |
| 132 |
Q_UNUSED(e); |
| 133 |
m_pSlider->move(width() - 214, -1); |
| 134 |
} |
| 135 |
|
| 136 |
void StatusBar::paintEvent(QPaintEvent *event) |
| 137 |
{ |
| 138 |
setMaskColor(MaskColorType::AutoColor); |
| 139 |
|
| 140 |
QPalette palette = m_pAllPicNumLabel->palette(); |
| 141 |
QPalette palettebackground = this->palette(); |
| 142 |
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); |
| 143 |
if (themeType == DGuiApplicationHelper::DarkType) { |
| 144 |
QColor backcolor(192, 198, 212); |
| 145 |
backcolor.setAlphaF(0.7); |
| 146 |
palette.setColor(QPalette::WindowText, backcolor); |
| 147 |
|
| 148 |
} else { |
| 149 |
QColor backcolor(98, 110, 136); |
| 150 |
backcolor.setAlphaF(0.7); |
| 151 |
palette.setColor(QPalette::WindowText, backcolor); |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
m_pAllPicNumLabel->setPalette(palette); |
| 156 |
return DBlurEffectWidget::paintEvent(event); |
| 157 |
} |
| 158 |
//根据照片与视频数量刷新提示 |
| 159 |
void StatusBar::resetSelectedStatue(int photosCount, int videosCount) |
| 160 |
{ |
| 161 |
//只选择照片 |
| 162 |
if (photosCount > 0 && videosCount == 0) { |
| 163 |
QString photosStr; |
| 164 |
if (photosCount == 1) { |
| 165 |
photosStr = QObject::tr("1 photo selected"); |
| 166 |
m_pAllPicNumLabel->setText(photosStr); |
| 167 |
} else { |
| 168 |
photosStr = QObject::tr("%n photos selected", "", photosCount); |
| 169 |
m_pAllPicNumLabel->setText(photosStr); |
| 170 |
} |
| 171 |
} else if (photosCount == 0 && videosCount > 0) { |
| 172 |
QString videosStr; |
| 173 |
if (videosCount == 1) { |
| 174 |
videosStr = QObject::tr("1 video selected"); |
| 175 |
m_pAllPicNumLabel->setText(videosStr); |
| 176 |
} else { |
| 177 |
videosStr = QObject::tr("%n videos selected", "", videosCount); |
| 178 |
m_pAllPicNumLabel->setText(videosStr); |
| 179 |
} |
| 180 |
} else if (photosCount > 0 && videosCount > 0) { |
| 181 |
QString totalStr = QObject::tr("%n items selected", "", (videosCount + photosCount)); |
| 182 |
m_pAllPicNumLabel->setText(totalStr); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
void StatusBar::resetUnselectedStatue(int photosCount, int videosCount) |
| 187 |
{ |
| 188 |
QString photosStr; |
| 189 |
if (photosCount == 1) { |
| 190 |
photosStr = tr("1 photo"); |
| 191 |
} else if (photosCount > 1) { |
| 192 |
photosStr = tr("%n photos", "", photosCount); |
| 193 |
} |
| 194 |
|
| 195 |
QString videosStr; |
| 196 |
if (videosCount == 1) { |
| 197 |
videosStr = tr("1 video"); |
| 198 |
} else if (videosCount > 1) { |
| 199 |
videosStr = tr("%n videos", "", videosCount); |
| 200 |
} |
| 201 |
|
| 202 |
if (photosCount > 0 && videosCount == 0) { |
| 203 |
m_pAllPicNumLabel->setText(photosStr); |
| 204 |
} else if (photosCount == 0 && videosCount > 0) { |
| 205 |
m_pAllPicNumLabel->setText(videosStr); |
| 206 |
} else if (photosCount > 0 && videosCount > 0) { |
| 207 |
m_pAllPicNumLabel->setText(photosStr + " " + videosStr); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
void StatusBar::timerEvent(QTimerEvent *e) |
| 212 |
{ |
| 213 |
if (e->timerId() == interval) { |
| 214 |
loadingicon->move(TextLabel->x() + 102, 0); |
| 215 |
m_pStackedWidget->setCurrentIndex(1); |
| 216 |
QString string = tr("Importing: %1"); |
| 217 |
|
| 218 |
if (imgpaths.count() == 1) { |
| 219 |
m_index = 0; |
| 220 |
killTimer(interval); |
| 221 |
interval = 0; |
| 222 |
m_pStackedWidget->setCurrentIndex(0); |
| 223 |
if (m_bcustalbum) { |
| 224 |
emit dApp->signalM->sigAddToAlbToast(m_alubm); |
| 225 |
if (m_baddDuplicatePhotos) { |
| 226 |
m_baddDuplicatePhotos = false; |
| 227 |
emit dApp->signalM->sigAddDuplicatePhotos(); |
| 228 |
} |
| 229 |
} |
| 230 |
} else { |
| 231 |
if (m_index >= imgpaths.count() - 1) { |
| 232 |
m_index = 0; |
| 233 |
killTimer(interval); |
| 234 |
interval = 0; |
| 235 |
if (m_bcustalbum) { |
| 236 |
emit dApp->signalM->sigAddToAlbToast(m_alubm); |
| 237 |
if (m_baddDuplicatePhotos) { |
| 238 |
m_baddDuplicatePhotos = false; |
| 239 |
emit dApp->signalM->sigAddDuplicatePhotos(); |
| 240 |
} |
| 241 |
} else if (1 == pic_count) { |
| 242 |
// emit dApp->signalM->ImportSuccess();//与导入线程提示重复 |
| 243 |
if (m_baddDuplicatePhotos) { |
| 244 |
m_baddDuplicatePhotos = false; |
| 245 |
emit dApp->signalM->sigAddDuplicatePhotos(); |
| 246 |
} |
| 247 |
} else { |
| 248 |
emit dApp->signalM->ImportFailed(); |
| 249 |
} |
| 250 |
|
| 251 |
QTime time; |
| 252 |
time.start(); |
| 253 |
while (time.elapsed() < 500) |
| 254 |
QCoreApplication::processEvents(); |
| 255 |
|
| 256 |
m_pStackedWidget->setCurrentIndex(0); |
| 257 |
} else { |
| 258 |
m_pStackedWidget->setCurrentIndex(0); |
| 259 |
m_index++; |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
} |