Debian Codegraph @

src/album/dialogs/albumdeletedialog.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 "albumdeletedialog.h"
22 #include "application.h"
23 #include "dbmanager/dbmanager.h"
24 #include "utils/baseutils.h"
25 #include "albumview/albumview.h"
26
27 #include <DLabel>
28 #include <DPushButton>
29 #include <DFontSizeManager>
30 #include <DTitlebar>
31
32 AlbumDeleteDialog::AlbumDeleteDialog(DWidget *parent)
33 {
34 Q_UNUSED(parent);
35 iniUI();
36 setAttribute(Qt::WA_DeleteOnClose, true);
37 }
38
39 void AlbumDeleteDialog::iniUI()
40 {
41 setModal(true);
42 //图标
43 QIcon icon = QIcon::fromTheme("deepin-album");
44 this->setIcon(icon);
45
46 //label
47 DLabel *m_label = new DLabel(this);
48 m_label->setAlignment(Qt::AlignCenter);
49 m_label->setText(tr("Are you sure you want to delete this album?"));
50 DWidget *contentWidget = new DWidget(this);
51 contentWidget->setFixedHeight(this->height() - 80);
52 contentWidget->setContentsMargins(0, 0, 0, 0);
53 QVBoxLayout *layout = new QVBoxLayout(contentWidget);
54 layout->setContentsMargins(0, 0, 0, 0);
55 layout->setSpacing(8);
56 layout->addStretch();
57 layout->addWidget(m_label);
58 layout->addStretch();
59 addContent(contentWidget);
60 insertButton(0, tr("Cancel"), false, DDialog::ButtonNormal);
61 insertButton(1, tr("Delete"), true, DDialog::ButtonWarning);
62 connect(this, &AlbumDeleteDialog::buttonClicked, this, &AlbumDeleteDialog::onButtonClicked);
63 //剔除Titlebar焦点
64 DTitlebar *titlebar = findChild<DTitlebar *>();
65 if (titlebar) {
66 titlebar->setFocusPolicy(Qt::ClickFocus);
67 }
68 }
69
70 void AlbumDeleteDialog::keyPressEvent(QKeyEvent *e)
71 {
72 switch (e->key()) {
73 case Qt::Key_Y:
74 case Qt::Key_Delete: {
75 emit deleteAlbum();
76 this->close();
77 }
78 break;
79 case Qt::Key_N:
80 case Qt::Key_Escape: {
81 this->deleteLater();
82 }
83 break;
84 default:
85 break;
86 }
87 }
88
89 void AlbumDeleteDialog::onButtonClicked(int index, const QString &text)
90 {
91 Q_UNUSED(text)
92 if (0 == index) {
93 deleteLater();
94 } else if (1 == index) {
95 emit deleteAlbum();
96 this->close();
97 }
98 }