[FIX][文件管理器]三屏-投屏模式切换成镜像模式,在切换成扩展屏模式时,第二扩展屏的文件重叠显示在一个扩展屏上[LINK]123283

This commit is contained in:
杨 艳微 2022-07-29 11:32:49 +08:00 committed by Yue-Lan
parent c0b646c9c8
commit 911d9e9abc
5 changed files with 50 additions and 27 deletions

View File

@ -1536,7 +1536,7 @@ void DesktopIconView::rowsAboutToBeRemoved(const QModelIndex &parent, int start,
QPoint itemPos(-1, -1); QPoint itemPos(-1, -1);
setRestoreInfo(uri, itemPos); setRestoreInfo(uri, itemPos);
} }
qDebug() << "[DesktopIconView::rowsAboutToBeRemove] need relayout:" << m_model->m_items_need_relayout;
relayoutExsitingItems(m_model->m_items_need_relayout); relayoutExsitingItems(m_model->m_items_need_relayout);
QListView::rowsAboutToBeRemoved(parent, start, end); QListView::rowsAboutToBeRemoved(parent, start, end);
// QTimer::singleShot(1, this, [=](){ // QTimer::singleShot(1, this, [=](){
@ -2654,10 +2654,11 @@ void DesktopIconView::saveExtendItemInfo()
QStringList topLeft; QStringList topLeft;
topLeft<<QString::number(indexRect.top()); topLeft<<QString::number(indexRect.top());
topLeft<<QString::number(indexRect.left()); topLeft<<QString::number(indexRect.left());
topLeft<<QString::number(m_id);
QString uri = index.data(Qt::UserRole).toString(); QString uri = index.data(Qt::UserRole).toString();
auto metaInfo = FileMetaInfo::fromUri(uri); auto metaInfo = FileMetaInfo::fromUri(uri);
if (metaInfo) { if (metaInfo) {
qDebug() << "DesktopIconView::saveExtendItemInfo:"<<str<<" "<<topLeft; qDebug() << "[DesktopIconView::saveExtendItemInfo] uri:"<<str<<" topLeft:"<<topLeft;
metaInfo->setMetaInfoStringList(RESTORE_EXTEND_ITEM_POS_ATTRIBUTE, topLeft); metaInfo->setMetaInfoStringList(RESTORE_EXTEND_ITEM_POS_ATTRIBUTE, topLeft);
metaInfo->setMetaInfoInt("peony-qt-desktop-id", 0); metaInfo->setMetaInfoInt("peony-qt-desktop-id", 0);
QStringList tmp; QStringList tmp;
@ -2692,15 +2693,21 @@ void DesktopIconView::resetExtendItemInfo()
auto metaInfo = FileMetaInfo::fromUri(uri); auto metaInfo = FileMetaInfo::fromUri(uri);
auto str = index.data(Qt::UserRole).toString(); auto str = index.data(Qt::UserRole).toString();
if (metaInfo) { if (metaInfo) {
auto list = metaInfo->getMetaInfoStringList(RESTORE_EXTEND_ITEM_POS_ATTRIBUTE); QStringList list = metaInfo->getMetaInfoStringList(RESTORE_EXTEND_ITEM_POS_ATTRIBUTE);
if (list.count() == 2) { if (list.count() == 3) {
qDebug() << "DesktopIconView::resetExtendItemInfo:"<<str<<" :"<<list<<"id:"<<m_id; QString id = list.takeLast();
qDebug() << "[DesktopIconView::resetExtendItemInfo] uri:"<<str<<" peony-qt-desktop-restore-extend-item-position:"<<list<<" id:"<<m_id;
if (id.toInt() != m_id) {
continue;
}
metaInfo->setMetaInfoStringList(ITEM_POS_ATTRIBUTE, list); metaInfo->setMetaInfoStringList(ITEM_POS_ATTRIBUTE, list);
metaInfo->setMetaInfoInt("peony-qt-desktop-id", m_id); metaInfo->setMetaInfoInt("peony-qt-desktop-id", m_id);
QStringList tmp; QStringList tmp;
tmp<<""; tmp<<"";
metaInfo->setMetaInfoStringList(RESTORE_EXTEND_ITEM_POS_ATTRIBUTE, tmp); metaInfo->setMetaInfoStringList(RESTORE_EXTEND_ITEM_POS_ATTRIBUTE, tmp);
m_model->m_items_need_relayout.removeOne(uri); m_model->m_items_need_relayout.removeOne(uri);
qDebug() << "[DesktopIconView::resetExtendItemInfo] need relayout:"<<m_model->m_items_need_relayout;
} }
} }
} }

View File

@ -10,10 +10,9 @@
#include <QPlatformSurfaceEvent> #include <QPlatformSurfaceEvent>
#include "plasma-shell-manager.h" #include "plasma-shell-manager.h"
static int desktop_window_id = 0;
static QTimeLine *gTimeLine = nullptr; static QTimeLine *gTimeLine = nullptr;
DesktopBackgroundWindow::DesktopBackgroundWindow(QScreen *screen, QWidget *parent) : QMainWindow(parent) DesktopBackgroundWindow::DesktopBackgroundWindow(QScreen *screen, int desktopWindowId, QWidget *parent) : QMainWindow(parent)
{ {
connect(this, &DesktopBackgroundWindow::destroyed, this, &DesktopBackgroundWindow::invaidScreen); connect(this, &DesktopBackgroundWindow::destroyed, this, &DesktopBackgroundWindow::invaidScreen);
@ -31,9 +30,8 @@ DesktopBackgroundWindow::DesktopBackgroundWindow(QScreen *screen, QWidget *paren
m_screen = screen; m_screen = screen;
m_desktopIconView = new Peony::DesktopIconView(this); m_desktopIconView = new Peony::DesktopIconView(this);
m_desktopIconView->setId(desktop_window_id); m_desktopIconView->setId(desktopWindowId);
m_id = desktop_window_id; m_id = desktopWindowId;
desktop_window_id++;
move(screen->geometry().topLeft()); move(screen->geometry().topLeft());
setFixedSize(screen->geometry().size()); setFixedSize(screen->geometry().size());
setContentsMargins(0, 0, 0, 0); setContentsMargins(0, 0, 0, 0);
@ -98,7 +96,7 @@ DesktopBackgroundWindow::DesktopBackgroundWindow(QScreen *screen, QWidget *paren
DesktopBackgroundWindow::~DesktopBackgroundWindow() DesktopBackgroundWindow::~DesktopBackgroundWindow()
{ {
--desktop_window_id;
} }
void DesktopBackgroundWindow::paintEvent(QPaintEvent *event) void DesktopBackgroundWindow::paintEvent(QPaintEvent *event)

View File

@ -15,7 +15,7 @@ class DesktopBackgroundWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DesktopBackgroundWindow(QScreen *screen, QWidget *parent = nullptr); explicit DesktopBackgroundWindow(QScreen *screen, int desktopWindowId, QWidget *parent = nullptr);
~DesktopBackgroundWindow() override; ~DesktopBackgroundWindow() override;
int id() const; int id() const;

View File

@ -79,6 +79,7 @@ static bool has_daemon = false;
static bool has_background = false; static bool has_background = false;
static QRect max_size = QRect(0, 0, 0, 0); static QRect max_size = QRect(0, 0, 0, 0);
static Peony::DesktopItemModel *desktop_model = nullptr; static Peony::DesktopItemModel *desktop_model = nullptr;
static int desktop_window_id = 0;
/*! /*!
* \brief virtualDesktopWindow * \brief virtualDesktopWindow
@ -440,10 +441,14 @@ void PeonyDesktopApplication::relocateIconView()
} }
for (auto window : m_bg_windows) { for (auto window : m_bg_windows) {
qDebug() << "screen name :" << window->screen()->name() << " id:" << window->id() ;
Q_EMIT window->getIconView()->updateView(); Q_EMIT window->getIconView()->updateView();
window->setCentralWidget(window->getIconView()); window->setCentralWidget(window->getIconView());
KWindowSystem::raiseWindow(window->winId()); if (window->screen() != qApp->primaryScreen()) {
KWindowSystem::raiseWindow(window->winId());
}
} }
KWindowSystem::raiseWindow(primaryWindow->winId());
} }
@ -645,15 +650,18 @@ void PeonyDesktopApplication::updateVirtualDesktopGeometryByWindows()
void PeonyDesktopApplication::addBgWindow(QScreen *screen) void PeonyDesktopApplication::addBgWindow(QScreen *screen)
{ {
auto window = new DesktopBackgroundWindow(screen); int desktopWindowId = getDesktopWindowId();
auto window = new DesktopBackgroundWindow(screen, desktopWindowId );
if (screen == qApp->primaryScreen()) { if (screen == qApp->primaryScreen()) {
window->getIconView()->refresh(); window->getIconView()->refresh();
} }
m_bg_windows.append(window);
m_bg_windows.append(window);
desktop_window_id = m_bg_windows.count();
// recheck primary screen info. new screen might become // recheck primary screen info. new screen might become
// primary screen. // primary screen.
qDebug()<<"[PeonyDesktopApplication::addBgWindow] screen name:"<<window->screen()->name()<<" IP:"<<window->screen();
window->show(); window->show();
connect(screen, &QScreen::destroyed, this, [=](){ connect(screen, &QScreen::destroyed, this, [=](){
if (!isPrimaryScreen(screen)) { if (!isPrimaryScreen(screen)) {
@ -686,6 +694,7 @@ void PeonyDesktopApplication::addBgWindow(QScreen *screen)
for (auto bgWindow : m_bg_windows) { for (auto bgWindow : m_bg_windows) {
if (!isPrimaryScreen(bgWindow->screen())) { if (!isPrimaryScreen(bgWindow->screen())) {
bgWindow->getIconView()->saveExtendItemInfo(); bgWindow->getIconView()->saveExtendItemInfo();
// Q_EMIT bgWindow->getIconView()->updateView();
} }
} }
getIconView(qApp->primaryScreen())->updateView(); getIconView(qApp->primaryScreen())->updateView();
@ -693,7 +702,6 @@ void PeonyDesktopApplication::addBgWindow(QScreen *screen)
for (auto bgWindow : m_bg_windows) { for (auto bgWindow : m_bg_windows) {
if (!isPrimaryScreen(bgWindow->screen())) { if (!isPrimaryScreen(bgWindow->screen())) {
bgWindow->getIconView()->resetExtendItemInfo(); bgWindow->getIconView()->resetExtendItemInfo();
break;
} }
} }
@ -710,15 +718,6 @@ void PeonyDesktopApplication::addBgWindow(QScreen *screen)
} }
relocateIconView(); relocateIconView();
if (1 == mode){
for (auto bgWindow : m_bg_windows) {
if (isPrimaryScreen(bgWindow->screen())) {
bgWindow->setCentralWidget(bgWindow->getIconView());
KWindowSystem::raiseWindow(bgWindow->winId());
}
}
}
} }
void PeonyDesktopApplication::setupDesktop() void PeonyDesktopApplication::setupDesktop()
@ -727,7 +726,7 @@ void PeonyDesktopApplication::setupDesktop()
for (auto screen : qApp->screens()) { for (auto screen : qApp->screens()) {
addBgWindow(screen); addBgWindow(screen);
} }
relocateIconView(); //relocateIconView();
connect(qApp, &QApplication::screenAdded, this, &PeonyDesktopApplication::addBgWindow); connect(qApp, &QApplication::screenAdded, this, &PeonyDesktopApplication::addBgWindow);
connect(this, &PeonyDesktopApplication::primaryScreenChanged, this, &PeonyDesktopApplication::relocateIconView); connect(this, &PeonyDesktopApplication::primaryScreenChanged, this, &PeonyDesktopApplication::relocateIconView);
} }
@ -740,6 +739,24 @@ void PeonyDesktopApplication::setupBgAndDesktop()
has_background = true; has_background = true;
} }
int PeonyDesktopApplication::getDesktopWindowId()
{
int desktopWindowId = 0;
for (; desktopWindowId <= desktop_window_id; desktopWindowId++) {
bool find = false;
for (auto bgWindow : m_bg_windows) {
if (bgWindow->id() == desktopWindowId) {
find = true;
break;
}
}
if (!find) {
break;
}
}
return desktopWindowId;
}
void guessContentTypeCallback(GObject* object, GAsyncResult *res,gpointer data) void guessContentTypeCallback(GObject* object, GAsyncResult *res,gpointer data)
{ {
char **guessType; char **guessType;

View File

@ -87,6 +87,7 @@ private:
void setupDesktop(); void setupDesktop();
void setupBgAndDesktop(); void setupBgAndDesktop();
void clearIcons(const QStringList &args); void clearIcons(const QStringList &args);
int getDesktopWindowId();
bool m_first_parse = true; bool m_first_parse = true;