Debian Codegraph @

src/album/importview/importview.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 "importview.h"
22 #include <DApplicationHelper>
23 #include <DFileDialog>
24 #include <QGraphicsDropShadowEffect>
25 #include <DSuggestButton>
26 #include <DGuiApplicationHelper>
27 #include <dgiovolumemanager.h>
28 #include <dgiofile.h>
29 #include <dgiofileinfo.h>
30 #include <dgiovolume.h>
31 #include "utils/baseutils.h"
32 #include "utils/imageutils.h"
33 #include "utils/unionimage.h"
34 #include "imageengine/imageengineapi.h"
35 #include "imagedataservice.h"
36 #include "ac-desktop-define.h"
37 #include "movieservice.h"
38
39 ImportView::ImportView()
40 : m_pImportBtn(nullptr), pLabel(nullptr)
41 {
42 setAcceptDrops(true);
43 AC_SET_OBJECT_NAME(this, Import_Image_View);
44 AC_SET_ACCESSIBLE_NAME(this, Import_Image_View);
45 initUI();
46 initConnections();
47 }
48
49 void ImportView::initConnections()
50 {
51 connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &ImportView::onThemeTypeChanged);
52 }
53
54 void ImportView::initUI()
55 {
56 QVBoxLayout *pImportFrameLayout = new QVBoxLayout();
57 pLabel = new DLabel();
58 pLabel->setFixedSize(128, 128);
59 QPixmap pixmap;
60 DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
61 if (themeType == DGuiApplicationHelper::LightType) {
62 pixmap = utils::base::renderSVG(":/resources/images/other/icon_import_photo.svg", QSize(128, 128));
63 }
64 if (themeType == DGuiApplicationHelper::DarkType) {
65 pixmap = utils::base::renderSVG(":/resources/images/other/icon_import_photo_dark.svg", QSize(128, 128));
66 }
67 pLabel->setPixmap(pixmap);
68 m_pImportBtn = new DSuggestButton();
69 AC_SET_OBJECT_NAME(m_pImportBtn, Import_Image_View_Button);
70 AC_SET_ACCESSIBLE_NAME(m_pImportBtn, Import_Image_View_Button);
71 DFontSizeManager::instance()->bind(m_pImportBtn, DFontSizeManager::T6, QFont::ExtraLight);
72 m_pImportBtn->setText(tr("Import Photos and Videos"));
73 m_pImportBtn->setFixedSize(302, 36);
74 m_pImportBtn->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T6));
75
76 pDragLabel = new DLabel();
77 DFontSizeManager::instance()->bind(pDragLabel, DFontSizeManager::T9, QFont::ExtraLight);
78 pDragLabel->setForegroundRole(DPalette::TextTips);
79 pDragLabel->setFixedHeight(18);
80 pDragLabel->setText(tr("Or drag them here"));
81
82 //#BUG90879,字体风格调整
83 DPalette palette = DApplicationHelper::instance()->palette(pDragLabel);
84 QColor color_TTT = palette.color(DPalette::ToolTipText);
85 if (themeType == DGuiApplicationHelper::LightType) {
86 color_TTT.setAlphaF(0.4);
87 palette.setBrush(DPalette::Text, color_TTT);
88 pDragLabel->setForegroundRole(DPalette::Text);
89 pDragLabel->setPalette(palette);
90 } else if (themeType == DGuiApplicationHelper::DarkType) {
91 color_TTT.setAlphaF(0.5);
92 palette.setBrush(DPalette::Text, color_TTT);
93 pDragLabel->setForegroundRole(DPalette::Text);
94 pDragLabel->setPalette(palette);
95 }
96
97 pImportFrameLayout->setMargin(0);
98 pImportFrameLayout->addStretch();
99 pImportFrameLayout->addWidget(pLabel, 0, Qt::AlignCenter);
100 pImportFrameLayout->addSpacing(5);
101 pImportFrameLayout->addWidget(m_pImportBtn, 0, Qt::AlignCenter);
102 pImportFrameLayout->addSpacing(10);
103 pImportFrameLayout->addWidget(pDragLabel, 0, Qt::AlignCenter);
104 pImportFrameLayout->addStretch();
105 setLayout(pImportFrameLayout);
106 }
107
108 void ImportView::mousePressEvent(QMouseEvent *e)
109 {
110 setFocus();
111 DWidget::mousePressEvent(e);
112 }
113
114 void ImportView::dragEnterEvent(QDragEnterEvent *e)
115 {
116 bool bData = utils::base::checkMimeUrls(e->mimeData()->urls());
117 if (!bData) {
118 return;
119 }
120 e->setDropAction(Qt::CopyAction);
121 e->accept();
122 }
123
124 void ImportView::dropEvent(QDropEvent *event)
125 {
126 QList<QUrl> urls = event->mimeData()->urls();
127 if (urls.isEmpty()) {
128 return;
129 }
130 ImageEngineApi::instance()->ImportImagesFromUrlList(urls, m_albumname, this);
131 event->accept();
132 }
133
134 void ImportView::dragMoveEvent(QDragMoveEvent *event)
135 {
136 event->accept();
137 }
138
139 void ImportView::onThemeTypeChanged()
140 {
141 QPixmap pixmap;
142 DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
143 if (themeType == DGuiApplicationHelper::LightType) {
144 pixmap = utils::base::renderSVG(":/resources/images/other/icon_import_photo.svg", QSize(128, 128));
145 }
146 if (themeType == DGuiApplicationHelper::DarkType) {
147 pixmap = utils::base::renderSVG(":/resources/images/other/icon_import_photo_dark.svg", QSize(128, 128));
148 }
149 pLabel->setPixmap(pixmap);
150
151 //#BUG90879,字体风格调整
152 DPalette palette = DApplicationHelper::instance()->palette(pDragLabel);
153 QColor color_TTT = palette.color(DPalette::ToolTipText);
154 if (themeType == DGuiApplicationHelper::LightType) {
155 color_TTT.setAlphaF(0.4);
156 palette.setBrush(DPalette::Text, color_TTT);
157 pDragLabel->setForegroundRole(DPalette::Text);
158 pDragLabel->setPalette(palette);
159 } else if (themeType == DGuiApplicationHelper::DarkType) {
160 color_TTT.setAlphaF(0.5);
161 palette.setBrush(DPalette::Text, color_TTT);
162 pDragLabel->setForegroundRole(DPalette::Text);
163 pDragLabel->setPalette(palette);
164 }
165 }
166
167 void ImportView::onImprotBtnClicked(bool useDialog, const QStringList &list)
168 {
169 static QStringList sList;
170 for (const QString &i : UnionImage_NameSpace::unionImageSupportFormat())
171 sList << ("*." + i);
172 //添加视频过滤
173 for (const QString &i : utils::base::m_videoFiletypes) {
174 sList << i;
175 }
176 QString filter = tr("All photos and videos");
177 filter.append('(');
178 filter.append(sList.join(" "));
179 filter.append(')');
180 static QString cfgGroupName = QStringLiteral("General"), cfgLastOpenPath = QStringLiteral("LastOpenPath");
181 QString pictureFolder = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
182 QDir existChecker(pictureFolder);
183 if (!existChecker.exists()) {
184 pictureFolder = QDir::currentPath();
185 }
186 pictureFolder = dApp->setter->value(cfgGroupName, cfgLastOpenPath, pictureFolder).toString();
187 DFileDialog dialog(this);
188 dialog.setObjectName("ImportViewDialog");
189 dialog.setFileMode(DFileDialog::ExistingFiles);
190 dialog.setDirectory(pictureFolder);
191 dialog.setNameFilter(filter);
192 dialog.setOption(QFileDialog::HideNameFilterDetails);
193 dialog.setWindowTitle(tr("Import Photos and Videos"));
194 dialog.setAllowMixedSelection(true);
195
196 if (useDialog) {
197 if (dialog.exec() != QDialog::Accepted) {
198 emit dApp->signalM->sigImportFailedToView();
199 return;
200 }
201 }
202
203 QStringList file_list = useDialog ? dialog.selectedFiles() : list;
204 if (file_list.isEmpty()) {
205 qDebug() << "file_list.isEmpty()";
206 emit dApp->signalM->sigImportFailedToView();
207 emit dApp->signalM->ImportFailed();
208 return;
209 }
210
211 // ImageEngineApi::instance()->makeThumbnailByPaths(file_list);
212 ImageEngineApi::instance()->ImportImagesFromFileList(file_list, m_albumname, this, true);
213 }
214
215
216 bool ImportView::imageImported(bool success)
217 {
218 emit dApp->signalM->closeWaitDialog();
219 if (!success) {
220 emit dApp->signalM->sigImportFailedToView();
221 }
222 return true;
223 }
224
225 void ImportView::setAlbumname(const QString &name)
226 {
227 m_albumname = name;
228 }
229
230
231