Merge branch 'upstream' into openkylin/yangtze

This commit is contained in:
huheng@kylinos.cn 2022-12-22 15:35:23 +08:00
commit 93bc44bcda
15 changed files with 148 additions and 698 deletions

View File

@ -53,9 +53,10 @@ public:
return;
};
/* id 的初始值必须为 0 */
static void getWindowId(quint32 *id) {
connect(kdk::WindowManager::self(), &kdk::WindowManager::windowAdded, [=](const kdk::WindowId &windowId) {
if (getpid() == kdk::WindowManager::getPid(windowId)) {
if (getpid() == (int)kdk::WindowManager::getPid(windowId) && *id == 0) {
*id = windowId.toLongLong();
}
});
@ -68,6 +69,12 @@ public:
return;
};
static void activateWindow(const quint32 id) {
kdk::WindowManager::activateWindow(id);
return;
}
};
}

View File

@ -3,5 +3,7 @@ Version=1.0.0.1
Type=Application
Name[zh_CN]=多端协同
Name=kylin-connectivity
Exec=/usr/bin/kylin-connectivity
Exec=/usr/bin/kylin-connectivity %u
Icon=kylin-multi-collaboration
Categories=Utility;kylin-connectivity;
X-KDE-Wayland-Interfaces=org_kde_plasma_window_management,org_kde_plasma_activation_feedback,org_kde_kwin_keystate,org_kde_kwin_fake_input,zkde_screencast_unstable_v1

View File

@ -85,11 +85,20 @@ int main(int argc, char *argv[])
kabase::WindowManage::removeHeader(MainWindow::getInstance());
/* 移动到窗口中间 */
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
MainWindow::getInstance()->move(availableGeometry.width() / 2 - MainWindow::getInstance()->width() / 2,
availableGeometry.height() / 2 - MainWindow::getInstance()->height() / 2);
// QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
// MainWindow::getInstance()->move(availableGeometry.width() / 2 - MainWindow::getInstance()->width() / 2,
// availableGeometry.height() / 2 - MainWindow::getInstance()->height() / 2);
app.setActivationWindow(MainWindow::getInstance());
/* wayland 下最小化拉起 */
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
QObject::connect(&app, &kdk::QtSingleApplication::messageReceived, [=]() {
kabase::WindowManage::activateWindow(MainWindow::getInstance()->getWinId());
});
}
MainWindow::getInstance()->show();
kabase::WindowManage::setMiddleOfScreen(MainWindow::getInstance());
if (!initVLC()) {
qCritical() << "vlc not installed!";

View File

@ -27,10 +27,6 @@ set(UI_FILEMANAGEVIEW_SOURCES
filemanageview/fileviewdelegate.cpp
filemanageview/fileview.h
filemanageview/fileview.cpp
filemanageview/timelineitem.h
filemanageview/timelineitem.cpp
filemanageview/timelinelistwidget.h
filemanageview/timelinelistwidget.cpp
)
source_group(filemanageview FILES ${UI_FILEMANAGEVIEW_SOURCES})
@ -95,6 +91,11 @@ target_include_directories(mobileui PUBLIC ${KYSDK_UKENV_INCLUDE_DIRS})
target_link_directories(mobileui PUBLIC ${KYSDK_UKENV_LIBRARY_DIRS})
target_link_libraries(mobileui PUBLIC ${KYSDK_UKENV_LIBRARIES})
pkg_check_modules(GSETTINGS gsettings-qt)
target_include_directories(mobileui PUBLIC ${GSETTINGS_INCLUDE_DIRS})
target_link_directories(mobileui PUBLIC ${GSETTINGS_LIBRARY_DIRS})
target_link_libraries(mobileui PUBLIC ${GSETTINGS_LIBRARIES})
set(TOP_DIR ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(mobileui PUBLIC ${TOP_DIR}/../kabase/Qt)

View File

@ -14,15 +14,20 @@ MessageDialog::MessageDialog(QWidget *parent) : kdk::KDialog(parent)
m_icon = new QLabel(this);
m_icon->resize(ICON_SIZE, ICON_SIZE);
QVBoxLayout *iconLayout = new QVBoxLayout;
iconLayout->setMargin(0);
iconLayout->setSpacing(0);
iconLayout->addWidget(m_icon);
iconLayout->addStretch();
m_textLayout = new QVBoxLayout;
m_textLayout->setMargin(0);
m_textLayout->setSpacing(0);
m_textLayout->addStretch();
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setMargin(0);
hLayout->setSpacing(0);
hLayout->addWidget(m_icon);
hLayout->addLayout(iconLayout);
hLayout->addSpacing(8);
hLayout->addLayout(m_textLayout);
hLayout->addStretch();
@ -45,21 +50,23 @@ MessageDialog::MessageDialog(QWidget *parent) : kdk::KDialog(parent)
void MessageDialog::setText(QString title, QString text)
{
m_titleLab = new QLabel(this);
m_titleLab->setAlignment(Qt::AlignLeft);
m_titleLab->setAlignment(Qt::AlignLeft | Qt::AlignTop);
m_titleLab->setText(title);
m_textLayout->addWidget(m_titleLab);
if (text.isEmpty()) {
setFixedSize(WIN_W, WIN_H);
} else {
setFixedSize(WIN_W, WIN_H + 20);
setFixedSize(WIN_W, WIN_H + 38);
QFont font;
font.setBold(true);
m_titleLab->setFont(font);
m_textLab = new QLabel(this);
m_textLab->setAlignment(Qt::AlignLeft);
m_textLab->setWordWrap(true);
m_textLab = new QTextEdit(this);
m_textLab->setFixedWidth(400);
m_textLab->setFrameStyle(QFrame::NoFrame);
m_textLab->setReadOnly(true);
m_textLab->setTextInteractionFlags(Qt::NoTextInteraction);
m_textLab->viewport()->setCursor(Qt::ArrowCursor);
m_textLab->setText(text);
m_textLayout->addSpacing(8);
m_textLayout->addWidget(m_textLab);

View File

@ -7,6 +7,7 @@
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QTextEdit>
#include <kdialog.h>
class MessageDialog : public kdk::KDialog
@ -25,7 +26,7 @@ Q_SIGNALS:
private:
QLabel *m_icon = nullptr;
QLabel *m_titleLab = nullptr;
QLabel *m_textLab = nullptr;
QTextEdit *m_textLab = nullptr;
QVBoxLayout *m_textLayout = nullptr;
QHBoxLayout *m_btnLayout = nullptr;
};

View File

@ -7,7 +7,7 @@
#include "generatetools.h"
QString CODE_TXT = "https://kylinos.cn/?connectip=%1&version=%2&verify=ky";
const QString APP_CODE_TXT = "https://www.ubuntukylin.com/public/software/ky_connectivity-1.0.0.1.apk";
const QString APP_CODE_TXT = "https://www.openkylin.top/public/software/ky_connectivity-1.0.0.1.apk";
MobileQRcode::MobileQRcode(QWidget *parent) : QWidget(parent)
{

View File

@ -83,9 +83,8 @@ void FileView::setModelFlag(PublicAttributes::Model model)
m_model = model;
}
QMap<QString, QStandardItem *> FileView::setViewInfo(const QMap<QString, FileInfo> &map)
void FileView::setViewInfo(const QMap<QString, FileInfo> &map)
{
setAdjustHeight(map.size());
QMap<QString, FileInfo> dirMap; // 临时存储目录项
QMap<QString, FileInfo> fileMap; // 临时存储非目录项
for (FileInfo info : map) {
@ -99,12 +98,11 @@ QMap<QString, QStandardItem *> FileView::setViewInfo(const QMap<QString, FileInf
setInfo(dirMap);
setInfo(fileMap);
return m_itemMap;
return;
}
QMap<QString, QStandardItem *> FileView::setViewInfo(const QList<FileInfo> &list)
void FileView::setViewInfo(const QList<FileInfo> &list)
{
setAdjustHeight(list.size());
QList<FileInfo> dirList; // 临时存储目录项
QList<FileInfo> fileList; // 临时存储非目录项
for (FileInfo info : list) {
@ -118,15 +116,11 @@ QMap<QString, QStandardItem *> FileView::setViewInfo(const QList<FileInfo> &list
setInfo(dirList);
setInfo(fileList);
return m_itemMap;
return;
}
void FileView::setDownloadBtn(bool isShow)
{
if (!m_isShowDownloadBtn) {
Q_EMIT sigSelectionModels(isShow);
return;
}
if (isShow) {
if (m_downloadBtn != nullptr) {
return;
@ -189,36 +183,52 @@ FileView::ItemSelectMode FileView::getItemMode() const
{
return m_itemMode;
}
void FileView::setThumbnailType(ThumbnailType type)
{
m_thumbnailType = type;
}
void FileView::setItemThumbnail(QString filePath)
{
if (m_itemMap.contains(filePath)) {
QPixmap thumbnail = QPixmap(filePath);
thumbnail = thumbnail.scaled(getIconSize(), Qt::KeepAspectRatio);
if (m_thumbnailType == ThumbnailType::Image) {
QIcon icon;
if (thumbnail.isNull()) {
icon = QIcon::fromTheme("image-x-generic");
} else {
icon = QIcon(thumbnail);
}
m_itemMap.find(filePath).value()->setIcon(icon);
} else if (m_thumbnailType == ThumbnailType::Video) {
QIcon icon;
if (thumbnail.isNull()) {
icon = QIcon(":/filemanageview/videodefault.svg");
} else {
QPixmap playPixmap(":/filemanageview/play.svg");
if (m_viewModel == QListView::IconMode) {
playPixmap = playPixmap.scaled(QSize(36, 36), Qt::KeepAspectRatio, Qt::SmoothTransformation);
} else {
playPixmap = playPixmap.scaled(QSize(24, 24), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
QPainter imagepainter(&thumbnail);
imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
imagepainter.drawPixmap((thumbnail.width() - playPixmap.width()) / 2,
(thumbnail.height() - playPixmap.height()) / 2, playPixmap);
imagepainter.end();
icon = QIcon(thumbnail);
}
m_itemMap.find(filePath).value()->setIcon(icon);
}
}
}
void FileView::setAllowDrag(bool isAllowDrag)
{
m_isAllowDrag = isAllowDrag;
}
void FileView::setNoDownloadBtn()
{
m_isShowDownloadBtn = false;
}
void FileView::setAdaptiveHeight()
{
m_isAdaptiveHeight = true;
verticalScrollBar()->setDisabled(true);
horizontalScrollBar()->setDisabled(true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// 设置右键菜单
setContextMenuPolicy(Qt::NoContextMenu);
}
void FileView::getSelectInfoList(QList<FileInfo> &list)
{
for (QModelIndex index : selectionModel()->selectedIndexes()) {
FileInfo fileInfo = index.data(Qt::DisplayRole + TAG_INFO).value<FileInfo>();
list.append(fileInfo);
}
}
void FileView::mousePressEvent(QMouseEvent *event)
{
if (!indexAt(event->pos()).isValid()) {
@ -305,8 +315,11 @@ void FileView::dropEvent(QDropEvent *event)
void FileView::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
setAdjustHeight(m_listModel->rowCount());
Q_EMIT sigSizeChanged(size());
if (m_downloadBtn != nullptr) {
m_downloadBtn->move(
QPoint(this->width() / 2 - m_downloadBtn->width() / 2, this->height() - 30 - m_downloadBtn->height()));
}
return QListView::resizeEvent(event);
}
@ -395,26 +408,6 @@ void FileView::sendDownloadInfo()
Q_EMIT sigDownFileInfo(filePath, fileList);
}
void FileView::setAdjustHeight(int count)
{
if (m_isAdaptiveHeight) {
if (m_viewModel == QListView::IconMode) {
int column = (size().width() - ICON_MODE_SPACING) / (ICON_MODE_SPACING + ICON_MODE_ITEM_WIDTH);
if (column == 0) {
column = 1;
}
int row = count / column;
if (row == 0 || (count % column) != 0) {
row = row + 1;
}
setFixedHeight((row * (ICON_MODE_ITEM_HEIGHT + ICON_MODE_SPACING)) + ICON_MODE_SPACING);
} else {
setFixedHeight(((LIST_MODE_ITEM_HEIGHT + LIST_MODE_SPACING + LIST_MODE_SPACING) * count)
+ LIST_MODE_SPACING);
}
}
}
void FileView::updateViewMode()
{
if (m_listModel->rowCount() == 0) {
@ -436,7 +429,6 @@ void FileView::updateViewMode()
}
}
}
setAdjustHeight(m_listModel->rowCount());
Q_EMIT sigSizeChanged(size());
}

View File

@ -26,21 +26,26 @@ public:
Edit, // 编辑模式
};
enum ThumbnailType {
Image = 0, // 图片缩略图
Video, // 视频缩略图
None // 无缩略图
};
void setViewMode(QListView::ViewMode mode);
QListView::ViewMode getViewMode() const;
void setModelFlag(PublicAttributes::Model model);
QMap<QString, QStandardItem *> setViewInfo(const QMap<QString, FileInfo> &map);
QMap<QString, QStandardItem *> setViewInfo(const QList<FileInfo> &list);
void setViewInfo(const QMap<QString, FileInfo> &map);
void setViewInfo(const QList<FileInfo> &list);
void setTheme(PublicAttributes::Theme theme);
PublicAttributes::Theme getTheme() const;
void changeFontSize(double fontSize);
void setItemMode(FileView::ItemSelectMode mode, bool isClear = false);
FileView::ItemSelectMode getItemMode() const;
void setThumbnailType(ThumbnailType type);
void setItemThumbnail(QString filePath);
void setDownloadBtn(bool isShow);
void setAllowDrag(bool isAllowDrag);
void setNoDownloadBtn();
void setAdaptiveHeight();
void getSelectInfoList(QList<FileInfo> &list);
protected:
void mousePressEvent(QMouseEvent *event) override;
@ -56,7 +61,6 @@ private:
void setInfo(const QList<FileInfo> &list);
void openFile(const QModelIndex &index);
void sendDownloadInfo();
void setAdjustHeight(int count);
void updateViewMode();
QSize getIconSize();
QIcon getPictureIcon(QString path);
@ -89,9 +93,8 @@ private:
PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 当前主题
double m_fontSize = 10;
FileView::ItemSelectMode m_itemMode = FileView::ItemSelectMode::Default; // 当前item视图模式
ThumbnailType m_thumbnailType = ThumbnailType::None; // 当前缩略图类型
bool m_isAllowDrag = true;
bool m_isShowDownloadBtn = true; // 是否需要下载按钮
bool m_isAdaptiveHeight = false; // 是否需要自适应高度
};
#endif // FILEVIEW_H

View File

@ -1,125 +0,0 @@
#include "timelineitem.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
const int HEIGHT = 40;
TimeLineItem::TimeLineItem(QWidget *parent) : QWidget(parent)
{
m_timeTitle = new QLabel(this);
m_dropDownBtn = new kdk::KToolButton(this);
connect(m_dropDownBtn, &kdk::KToolButton::clicked, this, &TimeLineItem::slotDropDownBtnClicked);
m_dropDownBtn->setIcon(QIcon::fromTheme("ukui-up-symbolic"));
m_dropDownBtn->setIconSize(QSize(16, 16));
m_dropDownBtn->setToolTip(tr("pack up"));
m_dropDownBtn->setType(kdk::KToolButtonType::Flat);
m_dropDownBtn->setCursor(Qt::PointingHandCursor);
m_dropDownBtn->setFocusPolicy(Qt::NoFocus);
m_fileView = new FileView(this);
connect(m_fileView, &FileView::sigOpenFile, this, &TimeLineItem::sigOpenFile);
connect(m_fileView, &FileView::sigItemSelectAll, this, &TimeLineItem::sigItemSelectAll);
connect(m_fileView, &FileView::sigSelectionModels, this, &TimeLineItem::sigSelectionModels);
connect(m_fileView, &FileView::sigSizeChanged, this, &TimeLineItem::slotSizeChanged);
connect(m_fileView, &FileView::sigCtrlAClicked, this, &TimeLineItem::sigCtrlAClicked);
m_fileView->setAllowDrag(false);
m_fileView->setNoDownloadBtn();
m_fileView->setAdaptiveHeight();
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setMargin(0);
hLayout->setSpacing(0);
hLayout->addSpacing(15);
hLayout->addWidget(m_timeTitle);
hLayout->addStretch();
hLayout->addWidget(m_dropDownBtn);
hLayout->addSpacing(5);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
layout->addLayout(hLayout);
layout->addWidget(m_fileView);
setLayout(layout);
}
void TimeLineItem::setViewMode(QListView::ViewMode mode)
{
m_fileView->setViewMode(mode);
}
void TimeLineItem::setModelFlag(PublicAttributes::Model model)
{
m_fileView->setModelFlag(model);
}
QMap<QString, QStandardItem *> TimeLineItem::setViewInfo(const QList<FileInfo> &list)
{
QString dateTime = list.value(0).getDate();
QString text = QString(dateTime + " (%1)").arg(QString::number(list.size()));
m_timeTitle->setText(text);
QMap<QString, QStandardItem *> map = m_fileView->setViewInfo(list);
setFixedHeight(m_fileView->height());
return map;
}
void TimeLineItem::setTheme(PublicAttributes::Theme theme)
{
m_fileView->setTheme(theme);
}
void TimeLineItem::changeFontSize(double fontSize)
{
m_fileView->changeFontSize(fontSize);
QFont font;
font.setPointSizeF(fontSize);
m_timeTitle->setFont(font);
}
void TimeLineItem::setItemMode(FileView::ItemSelectMode mode, bool isClear)
{
m_fileView->setItemMode(mode, isClear);
}
void TimeLineItem::selectAll()
{
m_fileView->selectAll();
}
void TimeLineItem::clearSelection()
{
m_fileView->clearSelection();
}
void TimeLineItem::getSelectInfoList(QList<FileInfo> &list)
{
m_fileView->getSelectInfoList(list);
}
void TimeLineItem::slotDropDownBtnClicked()
{
if (m_fileView->isHidden()) {
m_dropDownBtn->setIcon(QIcon::fromTheme("ukui-up-symbolic"));
m_dropDownBtn->setToolTip(tr("pack up"));
m_fileView->show();
setFixedHeight(m_fileView->height() + HEIGHT);
Q_EMIT sigSizeChanged(size());
} else {
m_dropDownBtn->setIcon(QIcon::fromTheme("ukui-down-symbolic"));
m_dropDownBtn->setToolTip(tr("lay down"));
m_fileView->hide();
setFixedHeight(HEIGHT);
Q_EMIT sigSizeChanged(size());
}
}
void TimeLineItem::slotSizeChanged(QSize viewSize)
{
setFixedHeight(viewSize.height() + HEIGHT);
Q_EMIT sigSizeChanged(size());
}

View File

@ -1,41 +0,0 @@
#ifndef TIMELINEITEM_H
#define TIMELINEITEM_H
#include <QWidget>
#include <QPushButton>
#include <ktoolbutton.h>
#include "fileview.h"
class TimeLineItem : public QWidget
{
Q_OBJECT
public:
TimeLineItem(QWidget *parent = nullptr);
void setViewMode(QListView::ViewMode mode);
void setModelFlag(PublicAttributes::Model model);
QMap<QString, QStandardItem *> setViewInfo(const QList<FileInfo> &list);
void setTheme(PublicAttributes::Theme theme);
void changeFontSize(double fontSize);
void setItemMode(FileView::ItemSelectMode mode, bool isClear = false);
void selectAll();
void clearSelection();
void getSelectInfoList(QList<FileInfo> &list);
Q_SIGNALS:
void sigOpenFile(FileInfo::FileType, QString);
void sigSelectionModels(bool);
void sigItemSelectAll(bool);
void sigSizeChanged(QSize);
void sigCtrlAClicked();
private Q_SLOTS:
void slotDropDownBtnClicked();
void slotSizeChanged(QSize viewSize);
private:
QLabel *m_timeTitle = nullptr; // 时间显示
kdk::KToolButton *m_dropDownBtn = nullptr; // 全选按钮
FileView *m_fileView = nullptr; // 文件视图
};
#endif // TIMELINEITEM_H

View File

@ -1,328 +0,0 @@
#include "timelinelistwidget.h"
#include <QScrollBar>
#include <QPainter>
#include <QSettings>
const QString CONFIG_PATH = getenv("HOME") + QString("/.connectivitycache/") + QString("setting.ini");
const QString CONFIG_KEY = "LastFilePath";
const QString DEFAULT_DOWNLOAD_PATH = getenv("HOME") + QString("/下载");
TimeLineListWidget::TimeLineListWidget(QWidget *parent) : QListWidget(parent)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setViewMode(QListView::ListMode);
// 自适应布局
setResizeMode(QListView::Adjust);
// 列表中的图标不可拖动
setMovement(QListView::Static);
// 去边框
setFrameShape(QListWidget::NoFrame);
// 设置边距
setSpacing(0);
// 不可选择项目
setSelectionMode(QListView::NoSelection);
setStyleSheet("QListWidget{background:transparent;}"
"QListWidget::Item{background:transparent;}"
"QListWidget::Item:Hover{background:transparent;}");
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &TimeLineListWidget::slotValueChanged);
}
void TimeLineListWidget::setViewMode(QListView::ViewMode mode)
{
m_viewModel = mode;
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->setViewMode(mode);
}
}
void TimeLineListWidget::setModelFlag(PublicAttributes::Model model)
{
m_model = model;
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->setModelFlag(model);
}
}
void TimeLineListWidget::setViewInfo(const QList<FileInfo> &list)
{
m_fileInfos = list;
loadItem(6);
}
void TimeLineListWidget::setTheme(PublicAttributes::Theme theme)
{
m_theme = theme;
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->setTheme(theme);
}
}
void TimeLineListWidget::changeFontSize(double fontSize)
{
m_fontSize = fontSize;
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->changeFontSize(fontSize);
}
if (m_downloadBtn != nullptr) {
m_downloadBtn->changeFontSize(m_fontSize);
}
}
void TimeLineListWidget::setItemMode(FileView::ItemSelectMode mode, bool isClear)
{
m_itemMode = mode;
if (mode == FileView::ItemSelectMode::Default) {
setDownloadBtn(false);
}
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->setItemMode(mode, isClear);
}
}
void TimeLineListWidget::setThumbnailType(ThumbnailType type)
{
m_thumbnailType = type;
}
void TimeLineListWidget::setItemThumbnail(QString filePath)
{
if (m_itemMap.contains(filePath)) {
QPixmap thumbnail = QPixmap(filePath);
thumbnail = thumbnail.scaled(getIconSize(), Qt::KeepAspectRatio);
if (m_thumbnailType == ThumbnailType::Image) {
QIcon icon;
if (thumbnail.isNull()) {
icon = QIcon::fromTheme("image-x-generic");
} else {
icon = QIcon(thumbnail);
}
m_itemMap.find(filePath).value()->setIcon(icon);
} else if (m_thumbnailType == ThumbnailType::Video) {
QIcon icon;
if (thumbnail.isNull()) {
icon = QIcon(":/filemanageview/videodefault.svg");
} else {
QPixmap playPixmap(":/filemanageview/play.svg");
if (m_viewModel == QListView::IconMode) {
playPixmap = playPixmap.scaled(QSize(36, 36), Qt::KeepAspectRatio, Qt::SmoothTransformation);
} else {
playPixmap = playPixmap.scaled(QSize(24, 24), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
QPainter imagepainter(&thumbnail);
imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
imagepainter.drawPixmap((thumbnail.width() - playPixmap.width()) / 2,
(thumbnail.height() - playPixmap.height()) / 2, playPixmap);
imagepainter.end();
icon = QIcon(thumbnail);
}
m_itemMap.find(filePath).value()->setIcon(icon);
}
}
}
void TimeLineListWidget::selectAll()
{
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->selectAll();
}
setDownloadBtn(true);
}
void TimeLineListWidget::clearSelection()
{
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_timeLineItems.value(i)->clearSelection();
}
setDownloadBtn(false);
}
void TimeLineListWidget::mousePressEvent(QMouseEvent *event)
{
clearSelection();
QListWidget::mousePressEvent(event);
}
// void TimeLineListWidget::mouseReleaseEvent(QMouseEvent *event)
// {
// QModelIndexList list = selectionModel()->selectedIndexes();
// if (list.size() >= 2) {
// if (list.size() == m_listModel->rowCount()) {
// Q_EMIT sigItemSelectAll(true);
// } else {
// Q_EMIT sigItemSelectAll(false);
// }
// setItemMode(FileView::ItemSelectMode::Edit);
// setDownloadBtn(true);
// }
// QListWidget::mouseReleaseEvent(event);
// }
void TimeLineListWidget::keyPressEvent(QKeyEvent *event)
{
if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_A)) {
Q_EMIT sigItemSelectAll(true);
selectAll();
}
QListWidget::keyPressEvent(event);
}
void TimeLineListWidget::loadItem(int num)
{
if (m_currentTimeLineIndex >= m_fileInfos.size()) {
return;
}
int i = 1;
QList<FileInfo> list; // 临时存储
for (; m_currentTimeLineIndex < m_fileInfos.size(); m_currentTimeLineIndex++) {
QString dateTime = m_fileInfos.value(m_currentTimeLineIndex).getDate();
if (m_currentTime != dateTime) {
if (!list.isEmpty()) {
setItem(list);
i++;
if (i >= num) {
return;
}
}
list.clear();
m_currentTime = dateTime;
list.append(m_fileInfos.value(m_currentTimeLineIndex));
} else {
list.append(m_fileInfos.value(m_currentTimeLineIndex));
}
}
if (!list.isEmpty()) {
setItem(list);
}
}
void TimeLineListWidget::setItem(QList<FileInfo> list)
{
QListWidgetItem *item = new QListWidgetItem(this);
TimeLineItem *itemWin = new TimeLineItem(this);
connect(itemWin, &TimeLineItem::sigOpenFile, this, &TimeLineListWidget::sigOpenFile);
connect(itemWin, &TimeLineItem::sigSelectionModels, this, [=](bool isShow) {
setDownloadBtn(isShow);
if (m_itemMode != FileView::ItemSelectMode::Edit) {
for (int i = 0; i < m_timeLineItems.size(); i++) {
if (m_timeLineItems.value(i) == itemWin) {
continue;
}
m_timeLineItems.value(i)->clearSelection();
}
}
if (!isShow) {
clearSelection();
}
});
connect(itemWin, &TimeLineItem::sigItemSelectAll, this, &TimeLineListWidget::slotItemSelecAll);
connect(itemWin, &TimeLineItem::sigSizeChanged, this, [=](QSize size) {
item->setSizeHint(size);
autoload();
});
connect(itemWin, &TimeLineItem::sigCtrlAClicked, this, [=]() {
selectAll();
});
m_timeLineItems.append(itemWin);
QMap<QString, QStandardItem *> map = itemWin->setViewInfo(list);
QMap<QString, QStandardItem *>::iterator it = map.begin();
while (it != map.end()) {
m_itemMap.insert(it.key(), it.value());
it++;
}
itemWin->setViewMode(m_viewModel);
itemWin->setModelFlag(m_model);
itemWin->setTheme(m_theme);
itemWin->setItemMode(m_itemMode);
item->setSizeHint(itemWin->size());
addItem(item);
setItemWidget(item, itemWin);
}
QSize TimeLineListWidget::getIconSize()
{
if (m_viewModel == QListView::IconMode) {
return QSize(64, 64);
} else {
return QSize(32, 32);
}
}
void TimeLineListWidget::setDownloadBtn(bool isShow)
{
if (isShow) {
if (m_downloadBtn != nullptr) {
return;
}
m_downloadBtn = new LevitationButton(this);
connect(m_downloadBtn, &LevitationButton::clicked, this, &TimeLineListWidget::slotDownloadBtnClicked);
m_downloadBtn->setIcon(":/filemanageview/download.svg");
m_downloadBtn->setText(tr("Download"));
m_downloadBtn->move(
QPoint(this->width() / 2 - m_downloadBtn->width() / 2, this->height() - 30 - m_downloadBtn->height()));
m_downloadBtn->changeFontSize(m_fontSize);
m_downloadBtn->show();
} else {
if (m_downloadBtn != nullptr) {
m_downloadBtn->deleteLater();
m_downloadBtn = nullptr;
}
}
}
void TimeLineListWidget::sendDownloadInfo()
{
QSettings setting(CONFIG_PATH, QSettings::IniFormat);
QString lastPath = setting.value(CONFIG_KEY).toString();
if (lastPath.isEmpty()) {
lastPath = DEFAULT_DOWNLOAD_PATH;
}
QFileDialog fileDialog;
QString filePath = fileDialog.getExistingDirectory(this, tr("Choose folder"), lastPath); // Choose folder选择文件夹
if (!filePath.isEmpty()) {
setting.setValue(CONFIG_KEY, filePath);
} else {
filePath = DEFAULT_DOWNLOAD_PATH;
}
QList<FileInfo> fileList;
for (int i = 0; i < m_timeLineItems.size(); i++) {
QList<FileInfo> list;
m_timeLineItems.value(i)->getSelectInfoList(list);
fileList.append(list);
}
Q_EMIT sigDownFileInfo(filePath, fileList);
}
void TimeLineListWidget::autoload()
{
int currentHeight = 0;
for (int i = 0; i < count(); i++) {
currentHeight += item(i)->sizeHint().height();
}
if (currentHeight <= height()) {
loadItem(2);
}
}
void TimeLineListWidget::slotValueChanged(int value)
{
if (value > (verticalScrollBar()->maximum() * 2 / 3)) {
loadItem(2);
}
}
void TimeLineListWidget::slotItemSelecAll(bool isSelectAll)
{
for (int i = 0; i < m_timeLineItems.size(); i++) {
m_itemMode = FileView::ItemSelectMode::Edit;
m_timeLineItems.value(i)->setItemMode(FileView::ItemSelectMode::Edit);
}
Q_EMIT sigItemSelectAll(isSelectAll);
}
void TimeLineListWidget::slotDownloadBtnClicked()
{
sendDownloadInfo();
}

View File

@ -1,75 +0,0 @@
#ifndef TIMELINELISTWIDGET_H
#define TIMELINELISTWIDGET_H
#include <QWidget>
#include <QListWidget>
#include <QListWidgetItem>
#include <QStandardItem>
#include <QList>
#include <QMap>
#include "timelineitem.h"
#include "fileinfo.h"
#include "levitationbutton.h"
class TimeLineListWidget : public QListWidget
{
Q_OBJECT
public:
TimeLineListWidget(QWidget *parent = nullptr);
enum ThumbnailType {
Image = 0, // 图片缩略图
Video, // 视频缩略图
None // 无缩略图
};
void setViewMode(QListView::ViewMode mode);
void setModelFlag(PublicAttributes::Model model);
void setViewInfo(const QList<FileInfo> &list);
void setTheme(PublicAttributes::Theme theme);
void changeFontSize(double fontSize);
void setItemMode(FileView::ItemSelectMode mode, bool isClear = false);
void setThumbnailType(ThumbnailType type);
void setItemThumbnail(QString filePath);
void selectAll();
void clearSelection();
protected:
void mousePressEvent(QMouseEvent *event) override;
// void mouseReleaseEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private:
void loadItem(int num);
void setItem(QList<FileInfo> list);
QSize getIconSize();
void setDownloadBtn(bool isShow);
void sendDownloadInfo();
void autoload();
Q_SIGNALS:
void sigOpenFile(FileInfo::FileType, QString);
void sigDownFileInfo(QString, QList<FileInfo> &fileList);
void sigItemSelectAll(bool);
private Q_SLOTS:
void slotValueChanged(int value);
void slotItemSelecAll(bool isSelectAll);
void slotDownloadBtnClicked();
private:
LevitationButton *m_downloadBtn = nullptr; // 下载悬浮按钮
QList<TimeLineItem *> m_timeLineItems;
QList<FileInfo> m_fileInfos;
QMap<QString, QStandardItem *> m_itemMap; // 用于缩略图
ThumbnailType m_thumbnailType = ThumbnailType::None; // 当前缩略图类型
PublicAttributes::Model m_model = PublicAttributes::Model::PcModel; // 当前设备模式
QListView::ViewMode m_viewModel = QListView::IconMode; // 当前视图模式
PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 当前主题
double m_fontSize = 10;
FileView::ItemSelectMode m_itemMode = FileView::ItemSelectMode::Default; // 当前item视图模式
QString m_currentTime = "";
int m_currentTimeLineIndex = 0;
};
#endif // TIMELINELISTWIDGET_H

View File

@ -13,6 +13,7 @@
#include "tipwidget.h"
#include "generatetools.h"
#include "config.h"
#include "windowmanage.hpp"
#define KYLIN_STATUS_MANAGER_PATH "/"
#define KYLIN_STATUS_MANAGER_NAME "com.kylin.statusmanager.interface"
@ -51,6 +52,11 @@ MainWindow *MainWindow::getInstance()
return &instance;
}
quint32 MainWindow::getWinId()
{
return m_winId;
}
QString MainWindow::getDeviceName()
{
return m_connectInfo.deviceName;
@ -112,6 +118,7 @@ void MainWindow::changeEvent(QEvent *event)
MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
{
kabase::WindowManage::getWindowId(&m_winId);
qRegisterMetaType<QMap<QString, FileInfo>>("QMap<QString,FileInfo>");
initUI();
initGsetting();
@ -188,6 +195,10 @@ void MainWindow::initGsetting()
changeFontSize();
connect(kdk::GsettingMonitor::getInstance(), &kdk::GsettingMonitor::systemFontSizeChange, this,
&MainWindow::changeFontSize);
if (QGSettings::isSchemaInstalled(UKUI_STYLE_GSETTING_PATH)) {
m_fontData = new QGSettings(UKUI_STYLE_GSETTING_PATH);
connect(m_fontData, &QGSettings::changed, this, &MainWindow::changeFont);
}
}
void MainWindow::initDbus()
@ -508,23 +519,24 @@ void MainWindow::updateResult()
} else {
QList<FileInfo> list;
m_fileSyncManage->getClassifiedFileList(m_fileKey, m_downFileType, list);
m_timeLineView = new TimeLineListWidget(this);
connect(m_timeLineView, &TimeLineListWidget::sigOpenFile, this, &MainWindow::slotOpenFile);
connect(m_timeLineView, &TimeLineListWidget::sigDownFileInfo, this, &MainWindow::slotDownFile);
connect(m_timeLineView, &TimeLineListWidget::sigItemSelectAll, this, &MainWindow::slotFileItemSelecAll);
m_timeLineView->setViewInfo(list);
m_timeLineView->setViewMode(m_viewMode);
m_timeLineView->setModelFlag(m_model);
m_timeLineView->setTheme(m_theme);
m_timeLineView->setItemMode(FileView::ItemSelectMode::Default, true);
m_timeLineView->changeFontSize(m_fontSize);
m_fileManageWin->setWidget(m_timeLineView, FileManageWin::TabType::Default);
m_fileView = new FileView(this);
connect(m_fileView, &FileView::sigOpenFile, this, &MainWindow::slotOpenFile);
connect(m_fileView, &FileView::sigDownFileInfo, this, &MainWindow::slotDownFile);
connect(m_fileView, &FileView::sigItemSelectAll, this, &MainWindow::slotFileItemSelecAll);
m_fileView->setViewInfo(list);
m_fileView->setViewMode(m_viewMode);
m_fileView->setModelFlag(m_model);
m_fileView->setTheme(m_theme);
m_fileView->setItemMode(FileView::ItemSelectMode::Default, true);
m_fileView->setAllowDrag(false);
m_fileView->changeFontSize(m_fontSize);
m_fileManageWin->setWidget(m_fileView, FileManageWin::TabType::Default);
if (m_downFileType == FileSyncManage::FileType::Picture) {
m_timeLineView->setThumbnailType(TimeLineListWidget::ThumbnailType::Image);
m_fileView->setThumbnailType(FileView::ThumbnailType::Image);
m_isDownloadingThumbanil = true;
m_fileSyncManage->downThumb(m_fileKey, m_downFileType);
} else if (m_downFileType == FileSyncManage::FileType::Video) {
m_timeLineView->setThumbnailType(TimeLineListWidget::ThumbnailType::Video);
m_fileView->setThumbnailType(FileView::ThumbnailType::Video);
m_isDownloadingThumbanil = true;
m_fileSyncManage->downThumb(m_fileKey, m_downFileType);
}
@ -572,10 +584,6 @@ void MainWindow::clearView()
m_fileView->deleteLater();
m_fileView = nullptr;
}
if (m_timeLineView != nullptr) {
m_timeLineView->deleteLater();
m_timeLineView = nullptr;
}
}
void MainWindow::setToolTipWin(QString msg, kdk::TipType type)
@ -904,9 +912,6 @@ void MainWindow::changeTheme()
if (m_fileView != nullptr) {
m_fileView->setTheme(m_theme);
}
if (m_timeLineView != nullptr) {
m_timeLineView->setTheme(m_theme);
}
}
void MainWindow::changeFontSize()
@ -936,11 +941,17 @@ void MainWindow::changeFontSize()
if (m_fileView != nullptr) {
m_fileView->changeFontSize(m_fontSize);
}
if (m_timeLineView != nullptr) {
m_timeLineView->changeFontSize(m_fontSize);
}
void MainWindow::changeFont(const QString &key)
{
if (key == "systemFont") {
qDebug() << "The font changes...";
changeFontSize();
}
}
void MainWindow::slotVolumeConnected(QString volumeName)
{
// todo
@ -1221,8 +1232,8 @@ void MainWindow::slotDownFileFinish(QString flag, QString filepath)
{
if (!flag.isEmpty()) {
// flag不为空一个缩略图下载完成
if (m_timeLineView != nullptr) {
m_timeLineView->setItemThumbnail(filepath);
if (m_fileView != nullptr) {
m_fileView->setItemThumbnail(filepath);
}
}
}
@ -1443,9 +1454,6 @@ void MainWindow::slotModeChanged(bool isTable)
if (m_fileView != nullptr) {
m_fileView->setModelFlag(m_model);
}
if (m_timeLineView != nullptr) {
m_timeLineView->setModelFlag(m_model);
}
}
void MainWindow::slotSearchLoadFail()
@ -1548,9 +1556,6 @@ void MainWindow::slotFileManageBtnClicked(FileManageWin::BtnType type)
if (m_fileView != nullptr) {
m_fileView->setItemMode(FileView::ItemSelectMode::Edit);
}
if (m_timeLineView != nullptr) {
m_timeLineView->setItemMode(FileView::ItemSelectMode::Edit);
}
} break;
case FileManageWin::BtnType::ListModeBtn: {
// 切换视图埋点
@ -1559,9 +1564,6 @@ void MainWindow::slotFileManageBtnClicked(FileManageWin::BtnType type)
if (m_fileView != nullptr) {
m_fileView->setViewMode(m_viewMode);
}
if (m_timeLineView != nullptr) {
m_timeLineView->setViewMode(m_viewMode);
}
} break;
case FileManageWin::BtnType::IconModeBtn: {
// 切换视图埋点
@ -1570,9 +1572,6 @@ void MainWindow::slotFileManageBtnClicked(FileManageWin::BtnType type)
if (m_fileView != nullptr) {
m_fileView->setViewMode(m_viewMode);
}
if (m_timeLineView != nullptr) {
m_timeLineView->setViewMode(m_viewMode);
}
} break;
case FileManageWin::BtnType::RefreshBtn: {
// 刷新列表埋点
@ -1585,26 +1584,17 @@ void MainWindow::slotFileManageBtnClicked(FileManageWin::BtnType type)
m_fileView->selectAll();
m_fileView->setDownloadBtn(true);
}
if (m_timeLineView != nullptr) {
m_timeLineView->selectAll();
}
} break;
case FileManageWin::BtnType::CancelSelectBtn: {
if (m_fileView != nullptr) {
m_fileView->clearSelection();
m_fileView->setDownloadBtn(false);
}
if (m_timeLineView != nullptr) {
m_timeLineView->clearSelection();
}
} break;
case FileManageWin::BtnType::EditFinishBtn: {
if (m_fileView != nullptr) {
m_fileView->setItemMode(FileView::ItemSelectMode::Default, true);
}
if (m_timeLineView != nullptr) {
m_timeLineView->setItemMode(FileView::ItemSelectMode::Default, true);
}
} break;
}
}

View File

@ -15,6 +15,7 @@
#include <QScreen>
#include <QMetaType>
#include <QMutex>
#include <QGSettings>
#include <kballontip.h>
#include "connectionservice.h"
@ -44,13 +45,14 @@
#include "multimediawin.h"
#include "androidhomepage.h"
#include "fileview.h"
#include "timelinelistwidget.h"
#include "messagedialog.h"
#define KYLIN_CONNECTIVITY_SEND_SERVICE "com.kylin.connectivity.send"
#define KYLIN_CONNECTIVITY_SEND_PATH "/com/kylin/connectivity"
#define KYLIN_CONNECTIVITY_SEND_INTERFACE "com.kylin.connectivity.send"
#define UKUI_STYLE_GSETTING_PATH "org.ukui.style"
const QString MOUNT_DIR = "/var/lib/mult";
using namespace KMobileProjection;
@ -63,6 +65,8 @@ class MainWindow : public QWidget
public:
static MainWindow *getInstance();
quint32 getWinId();
// 提供给dbus的接口
// 获取当前是否有设备连接
QString getDeviceName();
@ -173,6 +177,7 @@ public Q_SLOTS:
// UI
void changeTheme();
void changeFontSize();
void changeFont(const QString &key);
void slotAboutWinShow();
void slotSearchResult(const QMap<QString, FileInfo> &searchResult);
void slotUSBConnectOnClicked();
@ -198,6 +203,8 @@ public Q_SLOTS:
void slotSearchInfoFinish(QString searchInfoPath);
private:
quint32 m_winId = 0;
ConnectionService *m_connectionService = nullptr; // 连接服务
KMobileDiscovery::Discovery *m_discovery = nullptr; // 搜索手机设备信息
FtpManager *m_ftpClient = nullptr; // ftp服务器
@ -218,6 +225,7 @@ private:
// disc
QProcess *m_discServer = nullptr;
QProcess *m_discClient = nullptr;
QGSettings *m_fontData = nullptr; // 字体变化
Titlebar *m_titlebar = nullptr; // 标题栏
HomePage *m_homepage = nullptr; // 首页
@ -227,7 +235,6 @@ private:
FileManageWin *m_fileManageWin = nullptr; // 文件管理title
AndroidHomePage *m_androidHomePage = nullptr; // 安卓文件管理首页
MultiMediaWin *m_multiMediaWin = nullptr; // QQ | 微信文件首页
TimeLineListWidget *m_timeLineView = nullptr; // 图片视频列表
FileView *m_fileView = nullptr; // 文件信息列表
kdk::KAboutDialog *m_aboutWindow = nullptr; // 关于窗口
TransmissionDialog *m_transmissionDialog = nullptr; // 传输进度窗口