1 Star 0 Fork 1

AAA Elysia 猫猫侠 ⁧~喵/gxde-deb-installer

forked from GXDE OS/gxde-deb-installer 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
filechoosewidget.cpp 3.70 KB
一键复制 编辑 原始数据 按行查看 历史
Aleksandr Sokolovskii 提交于 2019-05-05 15:31 . refactor: fix typo
/*
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "filechoosewidget.h"
#include "utils.h"
#include <QDebug>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QUrl>
#include <QFileInfo>
#include <QDir>
#include <QPixmap>
#include <QPainter>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QLabel>
DWIDGET_USE_NAMESPACE
FileChooseWidget::FileChooseWidget(QWidget *parent)
: QWidget(parent),
m_settings("deepin", "deepin-deb-install")
{
const auto ratio = devicePixelRatioF();
QPixmap iconPix = Utils::renderSVG(":/images/icon.svg", QSize(140, 140));
iconPix.setDevicePixelRatio(ratio);
QLabel *iconImage = new QLabel;
iconImage->setFixedSize(140, 140);
iconImage->setPixmap(iconPix);
QLabel *dndTips = new QLabel;
dndTips->setText(tr("Drag and drop file here"));
dndTips->setAlignment(Qt::AlignCenter);
dndTips->setObjectName("DNDTips");
QVBoxLayout *centerWrapLayout = new QVBoxLayout;
centerWrapLayout->addWidget(iconImage);
centerWrapLayout->setAlignment(iconImage, Qt::AlignTop | Qt::AlignHCenter);
centerWrapLayout->addSpacing(20);
centerWrapLayout->addWidget(dndTips);
centerWrapLayout->setSpacing(0);
centerWrapLayout->setContentsMargins(0, 0, 0, 15);
QWidget *centerWidget = new QFrame;
centerWidget->setFixedWidth(240);
centerWidget->setLayout(centerWrapLayout);
centerWidget->setObjectName("CenterWidget");
QLabel *split_line = new QLabel;
split_line->setObjectName("SplitLine");
//split_line->setPixmap(QPixmap(":/images/split_line.svg"));
split_line->setAlignment(Qt::AlignCenter);
m_fileChooseBtn = new DLinkButton;
m_fileChooseBtn->setObjectName("FileChooseButton");
m_fileChooseBtn->setText(tr("Select File"));
QVBoxLayout *centralLayout = new QVBoxLayout;
centralLayout->addStretch();
centralLayout->addWidget(centerWidget);
centralLayout->setAlignment(centerWidget, Qt::AlignTop | Qt::AlignCenter);
centralLayout->addWidget(split_line);
centralLayout->addSpacing(20);
centralLayout->addWidget(m_fileChooseBtn);
centralLayout->setAlignment(m_fileChooseBtn, Qt::AlignCenter);
centralLayout->setSpacing(0);
centralLayout->setContentsMargins(0, 0, 0, 60);
setLayout(centralLayout);
connect(m_fileChooseBtn, &QPushButton::clicked, this, &FileChooseWidget::chooseFiles);
}
void FileChooseWidget::chooseFiles()
{
QString historyDir = m_settings.value("history_dir").toString();
if (historyDir.isEmpty()) {
historyDir = QDir::homePath();
}
QFileDialog dialog;
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter("Debian Package Files (*.deb)");
dialog.setDirectory(historyDir);
const int mode = dialog.exec();
// save the directory string to config file.
m_settings.setValue("history_dir", dialog.directoryUrl().toLocalFile());
if (mode != QDialog::Accepted)
return;
const QStringList selected_files = dialog.selectedFiles();
emit packagesSelected(selected_files);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qinyinan/gxde-deb-installer.git
git@gitee.com:qinyinan/gxde-deb-installer.git
qinyinan
gxde-deb-installer
gxde-deb-installer
master

搜索帮助