add place and device icons

This commit is contained in:
like 2024-04-12 15:53:38 +08:00
parent 9798f66e56
commit a957b66c8b
34 changed files with 658 additions and 124 deletions

View File

@ -234,5 +234,27 @@
<file>resource/config/kylin-theme-builder-change.desktop</file>
<file>resource/config/kylin-theme-builder.txt</file>
<file>resource/config/theme-builder-change.conf</file>
<file>resource/devices/computer.png</file>
<file>resource/devices/cupsprinter.png</file>
<file>resource/devices/drive-harddisk.png</file>
<file>resource/devices/drive-removable-media-usb.png</file>
<file>resource/devices/input-keyboard.png</file>
<file>resource/devices/input-mouse.png</file>
<file>resource/devices/scanner.png</file>
<file>resource/places/document-open-recent.png</file>
<file>resource/places/folder-documents.png</file>
<file>resource/places/folder-download.png</file>
<file>resource/places/folder-dropbox.png</file>
<file>resource/places/folder-music.png</file>
<file>resource/places/folder-open.png</file>
<file>resource/places/folder-pictures.png</file>
<file>resource/places/folder-publicshare.png</file>
<file>resource/places/folder-templates.png</file>
<file>resource/places/folder-videos.png</file>
<file>resource/places/inode-directory.png</file>
<file>resource/places/user-desktop.png</file>
<file>resource/places/user-home.png</file>
<file>resource/places/user-trash-full.png</file>
<file>resource/places/user-trash.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -101,6 +101,20 @@ void Bridge::systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps)
+m_time+"/src/iconTheme/systemicon");
}
void Bridge::placeIconsMapChanged(QMap<QString, QString> *placeiconsmaps)
{
m_placeiconpathmap = placeiconsmaps;
m_configfilemanager->copyIcontoCacheDir(m_placeiconpathmap,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/placeicon");
}
void Bridge::deviceIconsMapChanged(QMap<QString, QString> *deviceiconpathmap)
{
m_deviceiconpathmap = deviceiconpathmap;
m_configfilemanager->copyIcontoCacheDir(m_deviceiconpathmap,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/deviceicon");
}
void Bridge::cursorMapChanged(QMap<QString, QString> *cursormap)
{
m_cursorpathmap = cursormap;
@ -176,28 +190,6 @@ void Bridge::createSavePathConfig()
m_configfilemanager->createSavePathConfig();
}
void Bridge::startCopy()
{
if(m_appsiconpathmap){
m_configfilemanager->copyIcontoCacheDir(m_appsiconpathmap,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/appicon");
}
if(m_systemiconpathmap){
m_configfilemanager->copyIcontoCacheDir(m_appsiconpathmap,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/systemicon");
}
if(m_cursorpathmap){
m_configfilemanager->copyIcontoCacheDir(m_cursorpathmap,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/cursorTheme/cursor");
}
if(m_timecursorpathmap){
m_configfilemanager->copyIcontoCacheDir(m_timecursorpathmap,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/cursorTheme/timecursor");
}
m_configfilemanager->copyPictoCacheDir(m_coverpath,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/globalTheme","cover");
}
void Bridge::updateIconCache(QMap<QString, QString> *iconsmaps, QString icontype)
{
if(icontype == "appicon"){
@ -206,6 +198,12 @@ void Bridge::updateIconCache(QMap<QString, QString> *iconsmaps, QString icontype
}else if(icontype == "systemicon"){
m_configfilemanager->copyIcontoCacheDir(iconsmaps,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/systemicon");
}else if(icontype == "placeicon"){
m_configfilemanager->copyIcontoCacheDir(iconsmaps,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/placeicon");
}else if(icontype == "deviceicon"){
m_configfilemanager->copyIcontoCacheDir(iconsmaps,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/iconTheme/deviceicon");
}else if(icontype == "cursor"){
m_configfilemanager->copyIcontoCacheDir(iconsmaps,QDir::homePath()+"/.cache/theme-build/"
+m_time+"/src/cursorTheme/cursor");

View File

@ -24,6 +24,8 @@ public:
void windowRadiusChanged(int windowradius);
void appIconsMapChanged(QMap<QString, QString> *appiconsmaps);
void systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps);
void placeIconsMapChanged(QMap<QString, QString> *placeiconsmaps);
void deviceIconsMapChanged(QMap<QString, QString> *deviceiconsmaps);
void cursorMapChanged(QMap<QString, QString> *cursormap);
void timeCursorMapChanged(QMap<QString, QString> *timecursormap);
void plymouthPathChanged(QString path);
@ -33,9 +35,9 @@ public:
void createGrub();
void createPlymouth();
void createSavePathConfig();
void startCopy();
void updateIconCache(QMap<QString, QString> *iconsmaps,QString icontype);
void ThemeNameChanged();
signals:
void updateInfo();
void updateThumbnail(QString thumbnailPath);
@ -48,6 +50,8 @@ private:
QMap<QString, QString> *m_appsiconpathmap = nullptr;
QMap<QString, QString> *m_systemiconpathmap = nullptr;
QMap<QString, QString> *m_placeiconpathmap = nullptr;
QMap<QString, QString> *m_deviceiconpathmap = nullptr;
QMap<QString, QString> *m_cursorpathmap = nullptr;
QMap<QString, QString> *m_timecursorpathmap = nullptr;

View File

@ -83,6 +83,8 @@ void FileProcess::FileCreate(const QString &m_themeType){
QDir cursorPath = m_builderPathSrc+ "/cursorTheme";
QDir appiconPath = m_builderPathSrc + "/iconTheme" + "/appicon";
QDir systemiconPath = m_builderPathSrc + "/iconTheme" + "/systemicon";
QDir placeiconPath = m_builderPathSrc + "/iconTheme" + "/placeicon";
QDir deviceiconPath = m_builderPathSrc + "/iconTheme" + "/deviceicon";
QDir cursorIconPath = m_builderPathSrc + "/cursorTheme" + "/cursor";
QDir timecursorPath = m_builderPathSrc + "/cursorTheme" + "/timecursor";
QDir plymouthPath = m_builderPathSrc+ "/plymouthTheme";
@ -93,6 +95,8 @@ void FileProcess::FileCreate(const QString &m_themeType){
cursorPath.mkdir(cursorPath.absolutePath());
appiconPath.mkdir(appiconPath.absolutePath());
systemiconPath.mkdir(systemiconPath.absolutePath());
placeiconPath.mkdir(placeiconPath.absolutePath());
deviceiconPath.mkdir(deviceiconPath.absolutePath());
cursorIconPath.mkdir(cursorIconPath.absolutePath());
timecursorPath.mkdir(timecursorPath.absolutePath());
plymouthPath.mkdir(plymouthPath.absolutePath());
@ -102,6 +106,8 @@ void FileProcess::FileCreate(const QString &m_themeType){
iconPath.mkdir(iconPath.absolutePath());
appiconPath.mkdir(appiconPath.absolutePath());
systemiconPath.mkdir(systemiconPath.absolutePath());
placeiconPath.mkdir(placeiconPath.absolutePath());
deviceiconPath.mkdir(deviceiconPath.absolutePath());
} else if (m_themeType == "cursorTheme"){
cursorPath.mkdir(cursorPath.absolutePath());

View File

@ -51,6 +51,12 @@ MainInterface::MainInterface(QWidget *parent) : QWidget(parent)
connect(m_iconthemewidget, &IconThemeWidget::newSystemIconsMap, this, [&]( QMap<QString, QString> *systemiconsmaps) {
emit systemIconsMapChanged(systemiconsmaps);
});
connect(m_iconthemewidget, &IconThemeWidget::newPlaceIconsMap, this, [&]( QMap<QString, QString> *placeiconsmaps) {
emit placeIconsMapChanged(placeiconsmaps);
});
connect(m_iconthemewidget, &IconThemeWidget::newDeviceIconsMap, this, [&]( QMap<QString, QString> *deviceiconsmaps) {
emit deviceIconsMapChanged(deviceiconsmaps);
});
connect(m_iconthemewidget, &IconThemeWidget::iconthemeChange, this, [&]( QMap<QString, bool> *iconthemeChangeMap){
emit iconthemeChange(iconthemeChangeMap);
});
@ -73,6 +79,7 @@ MainInterface::MainInterface(QWidget *parent) : QWidget(parent)
connect(m_grubthemewidget, &GrubThemeWidget::newGrubFilePath, this, [&](const QString& path) {
emit grubPathChanged(path);
});
}
/**
@ -338,6 +345,16 @@ QMap<QString, QString> *MainInterface::getSystemIconsMap()
return m_iconthemewidget->getSystemIconsMap();
}
QMap<QString, QString> *MainInterface::getPlaceIconsMap()
{
return m_iconthemewidget->getPlaceIconsMap();
}
QMap<QString, QString> *MainInterface::getDeviceIconsMap()
{
return m_iconthemewidget->getDeviceIconsMap();
}
QMap<QString, QString> *MainInterface::getCurosrMap()
{
//资源文件的cursoriconmap
@ -424,3 +441,8 @@ void MainInterface::useRestoreScale()
m_plymouththemewidget->useRestoreScale();
m_grubthemewidget->useRestoreScale();
}
void MainInterface::hideNavigation(bool isglobal)
{
m_navigationwidget->setHidden(!isglobal);
}

View File

@ -45,16 +45,19 @@ public:
//初始化和刷新时使用
QMap<QString, QString>* getAppIconsMap();
QMap<QString, QString>* getSystemIconsMap();
QMap<QString, QString>* getPlaceIconsMap();
QMap<QString, QString> *getDeviceIconsMap();
QMap<QString, QString>* getCurosrMap();
QMap<QString, QString>* getTimeCurosrMap();
void refresh(QString themeType);
void startShowPlymouth();
void useMaximumScale();
void useRestoreScale();
void hideNavigation(bool isglobal);
signals:
void wallpaperupdate(const QString& filePath);
void wallpaperPathChanged(QString path);
@ -66,6 +69,8 @@ signals:
void exteriorChanged(QColor exteriorcolor);
void appIconsMapChanged(QMap<QString, QString> *appiconsmap);
void systemIconsMapChanged(QMap<QString, QString> *systemiconsmap);
void placeIconsMapChanged(QMap<QString, QString> *placeiconsmap);
void deviceIconsMapChanged(QMap<QString, QString> *deviceiconsmap);
void cursorMapChanged(QMap<QString, QString> *appiconsmap);
void timeCursorMapChanged(QMap<QString, QString> *systemiconsmap);
void plymouthPathChanged(QString path);

View File

@ -47,6 +47,8 @@ MainWindow::MainWindow(QWidget *parent)
// });
connect(m_maininterface, &MainInterface::appIconsMapChanged, m_bridge, &Bridge::appIconsMapChanged);
connect(m_maininterface, &MainInterface::systemIconsMapChanged, m_bridge, &Bridge::systemIconsMapChanged);
connect(m_maininterface, &MainInterface::placeIconsMapChanged, m_bridge, &Bridge::placeIconsMapChanged);
connect(m_maininterface, &MainInterface::deviceIconsMapChanged, m_bridge, &Bridge::deviceIconsMapChanged);
connect(m_maininterface, &MainInterface::cursorMapChanged, m_bridge, &Bridge::cursorMapChanged);
connect(m_maininterface, &MainInterface::timeCursorMapChanged, m_bridge, &Bridge::timeCursorMapChanged);
connect(m_maininterface, &MainInterface::plymouthPathChanged, m_bridge, &Bridge::plymouthPathChanged);
@ -261,6 +263,8 @@ void MainWindow::initUI()
m_bridge->createFileManager(FileProcess::g_date);
m_bridge->updateIconCache(m_maininterface->getAppIconsMap(),"appicon");
m_bridge->updateIconCache(m_maininterface->getSystemIconsMap(),"systemicon");
m_bridge->updateIconCache(m_maininterface->getPlaceIconsMap(),"placeicon");
m_bridge->updateIconCache(m_maininterface->getDeviceIconsMap(),"deviceicon");
m_bridge->updateIconCache(m_maininterface->getCurosrMap(),"cursor");
m_bridge->updateIconCache(m_maininterface->getTimeCurosrMap(),"timecursor");
@ -273,6 +277,7 @@ void MainWindow::initUI()
m_maininterface->refresh("cursor");
m_maininterface->refresh("plymouth");
m_maininterface->refresh("grub");
m_maininterface->hideNavigation(true);
} else if (button == m_iconbtn) {
m_maininterface->setIconTheme();
@ -280,8 +285,10 @@ void MainWindow::initUI()
m_bridge->createFileManager(FileProcess::g_date);
m_bridge->updateIconCache(m_maininterface->getAppIconsMap(),"appicon");
m_bridge->updateIconCache(m_maininterface->getSystemIconsMap(),"systemicon");
m_bridge->updateIconCache(m_maininterface->getPlaceIconsMap(),"placeicon");
m_bridge->updateIconCache(m_maininterface->getDeviceIconsMap(),"deviceicon");
m_maininterface->refresh("icon");
m_maininterface->hideNavigation(false);
} else if (button == m_cursorbtn) {
m_maininterface->setCursorTheme();
m_fileProcess.FileCreate("cursorTheme");
@ -289,7 +296,7 @@ void MainWindow::initUI()
m_bridge->updateIconCache(m_maininterface->getCurosrMap(),"cursor");
m_bridge->updateIconCache(m_maininterface->getTimeCurosrMap(),"timecursor");
m_maininterface->refresh("cursor");
m_maininterface->hideNavigation(false);
}else if (button == m_plymouthbtn) {
m_maininterface->setPlymouthTheme();
m_fileProcess.FileCreate("plymouthTheme");
@ -297,12 +304,14 @@ void MainWindow::initUI()
m_bridge->createPlymouth();
startShowPlymouth();
m_maininterface->refresh("plymouth");
m_maininterface->hideNavigation(false);
}else if (button == m_grubbtn) {
m_maininterface->setGrubTheme();
m_fileProcess.FileCreate("grubTheme");
m_bridge->createFileManager(FileProcess::g_date);
m_bridge->createGrub();
m_maininterface->refresh("grub");
m_maininterface->hideNavigation(false);
}
if (false == m_historywidget->isVisible()) {

View File

@ -18,6 +18,9 @@ IconThemeWidget::IconThemeWidget(bool isHistory, QWidget *parent) : QWidget(pare
m_iconPresenceMap = new QMap<QString, bool>();
initMaps();
initSystemMaps();
initPlacesMaps();
initDevicesMaps();
initPreviewWidget();
initRightWidget();
QPushButton *line = new QPushButton();
@ -53,10 +56,14 @@ void IconThemeWidget::initPreviewWidget()
m_previewstack = new QStackedWidget(m_previewwidget);
m_preview = new ImageWidget(m_previewwidget,m_iconpathmap);
m_preview->updateIconMap(m_iconpathmap);
// m_preview->updateIconMap(m_iconpathmap);
m_systempreview = new ImageWidget(m_previewwidget,m_systemiconpathmap);
m_placepreview = new ImageWidget(m_previewwidget,m_placesiconpathmap);
m_previewstack->addWidget(m_preview);
m_previewstack->addWidget(m_systempreview);
m_previewstack->addWidget(m_placepreview);
QVBoxLayout *layout = new QVBoxLayout(m_previewwidget);
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
@ -67,9 +74,9 @@ void IconThemeWidget::initPreviewWidget()
connect(this,&IconThemeWidget::wallpaperupdate, m_preview,[=](const QString& filePath){
m_preview->updateImage(filePath);
});
layout->addItem(spacer);
// layout->addItem(spacer);
layout->addWidget(m_previewstack);
layout->addItem(spacer2);
// layout->addItem(spacer2);
m_previewwidget->setLayout(layout);
}
@ -268,6 +275,44 @@ void IconThemeWidget::updateCustomSyetemIconPathMap(QMap<QString, QString>*histo
}
}
void IconThemeWidget::updateCustomPlaceIconPathMap(QMap<QString, QString> *historyMap)
{
m_placescustomiconpathmap->clear();
m_placescustomiconpathmap = historyMap;
for (auto it = m_placespathWidgetMap->begin(); it != m_placespathWidgetMap->end(); ++it) {
const QString& widgetName = it.key();
IconEditWidget* widget = it.value();
m_themeChangeMap->insert(widgetName, false);
m_iconPresenceMap->insert(widgetName, false);
widget->setcustomicon(NULL);
if (m_placescustomiconpathmap->contains(widgetName)) {
m_themeChangeMap->insert(widgetName, false);
m_iconPresenceMap->insert(widgetName, false);
const QString& filePath = m_placescustomiconpathmap->value(widgetName);
// 判断文件类型为svg才显示
QFileInfo fileInfo(filePath);
if (fileInfo.suffix().toLower() == "svg") {
widget->setcustomicon(filePath);
m_preview->updateIcon(widgetName, filePath);
m_iconPresenceMap->insert(widgetName, true);
}
else {
// 如果文件类型不是svg直接跳过并不显示
continue;
}
}
}
}
void IconThemeWidget::updateCustomDeviceIconPathMap(QMap<QString, QString> *historyMap)
{
}
/**
* @brief
*
@ -377,17 +422,180 @@ void IconThemeWidget::initSystemEditWidget()
m_systemeditwidget->setLayout(mainWidgetLayout);
}
void IconThemeWidget::initPlaceandDeviceEditWidget()
{
m_placeeditwidget = new QWidget(m_stackedwidget);
m_placescrollArea = new QScrollArea(m_rightwidget);
m_placescrollArea->setWidgetResizable(true);
QWidget *viewportWidget = new QWidget(m_placescrollArea);
m_placescrollArea->setWidget(viewportWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(viewportWidget);
viewportWidget->setLayout(mainLayout);
// QMap<QString,QString>* appicon_name_CH = new QMap<QString,QString>;
// QList<QString> keys = m_placesiconpathmap->keys();
// appicon_name_CH = m_preview->initSystemIconName(appicon_name_CH,keys);
for (auto it = m_placesiconpathmap->begin(); it != m_placesiconpathmap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
IconEditWidget* widget = new IconEditWidget(viewportWidget);
widget->setdefaulticon(filePath);
widget->setdefaulticonname(it.key());
widget->setProperty("widgetname",widgetName);
QPushButton *line = new QPushButton();
line->setDisabled(true);
line->setFixedHeight(1);
mainLayout->addWidget(widget);
mainLayout->addWidget(line);
m_placespathWidgetMap->insert(widgetName, widget);
connect(widget->m_addiconbutton, &QPushButton::clicked, this, [=]() {
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
IconEditWidget* clickedWidget = nullptr;
QWidget *widget = clickedButton->parentWidget();
while (widget && !widget->inherits("IconEditWidget")) {
widget = widget->parentWidget();
}
clickedWidget = qobject_cast<IconEditWidget*>(widget);
if (clickedWidget) {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), QDir::homePath(), tr("SVG file (*.svg)"));
if (!newFilePath.isEmpty()) {
//check
if(FileCheck::isLegalIconFile(newFilePath)){
m_placescustomiconpathmap->insert(widgetName, newFilePath);
clickedWidget->setcustomicon(newFilePath);
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
m_placepreview->updateIcon(widgetName, newFilePath);
}
}
emit newPlaceIconsMap(m_placescustomiconpathmap);
}
}
});
connect(widget->m_addiconbutton,&DropButton::droprealicon,this,[=](const QString& path){
DropButton* clickedButton = qobject_cast<DropButton*>(sender());
if (clickedButton) {
IconEditWidget* clickedWidget = nullptr;
QWidget *widget = clickedButton->parentWidget();
while (widget && !widget->inherits("IconEditWidget")) {
widget = widget->parentWidget();
}
clickedWidget = qobject_cast<IconEditWidget*>(widget);
if (clickedWidget) {
if (!path.isEmpty()) {
m_placescustomiconpathmap->insert(widgetName, path);
clickedWidget->setcustomicon(path);
m_placepreview->updateIcon(widgetName, path);
}
emit newPlaceIconsMap(m_placescustomiconpathmap);
}
}
});
connect(widget,&IconEditWidget::deleteCustomIcon,this,[=](){
QString iconPath = ":/resource/places/"+widgetName+".png";
m_placepreview->updateIcon(widgetName, iconPath);
m_placescustomiconpathmap->insert(widgetName, iconPath);
emit newPlaceIconsMap(m_placescustomiconpathmap);
});
}
for (auto it = m_devicesiconpathmap->begin(); it != m_devicesiconpathmap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
IconEditWidget* widget = new IconEditWidget(viewportWidget);
widget->setdefaulticon(filePath);
widget->setdefaulticonname(it.key());
widget->setProperty("widgetname",widgetName);
QPushButton *line = new QPushButton();
line->setDisabled(true);
line->setFixedHeight(1);
mainLayout->addWidget(widget);
mainLayout->addWidget(line);
m_devicespathWidgetMap->insert(widgetName, widget);
connect(widget->m_addiconbutton, &QPushButton::clicked, this, [=]() {
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
IconEditWidget* clickedWidget = nullptr;
QWidget *widget = clickedButton->parentWidget();
while (widget && !widget->inherits("IconEditWidget")) {
widget = widget->parentWidget();
}
clickedWidget = qobject_cast<IconEditWidget*>(widget);
if (clickedWidget) {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), QDir::homePath(), tr("SVG file (*.svg)"));
if (!newFilePath.isEmpty()) {
if(FileCheck::isLegalIconFile(newFilePath)){
m_devicescustomiconpathmap->insert(widgetName, newFilePath);
clickedWidget->setcustomicon(newFilePath);
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
// m_placepreview->updateIcon(widgetName, newFilePath);
}
}
emit newDeviceIconsMap(m_devicescustomiconpathmap);
}
}
});
connect(widget->m_addiconbutton,&DropButton::droprealicon,this,[=](const QString& path){
DropButton* clickedButton = qobject_cast<DropButton*>(sender());
if (clickedButton) {
IconEditWidget* clickedWidget = nullptr;
QWidget *widget = clickedButton->parentWidget();
while (widget && !widget->inherits("IconEditWidget")) {
widget = widget->parentWidget();
}
clickedWidget = qobject_cast<IconEditWidget*>(widget);
if (clickedWidget) {
if (!path.isEmpty()) {
m_devicescustomiconpathmap->insert(widgetName, path);
clickedWidget->setcustomicon(path);
m_placepreview->updateIcon(widgetName, path);
}
emit newDeviceIconsMap(m_devicescustomiconpathmap);
}
}
});
connect(widget,&IconEditWidget::deleteCustomIcon,this,[=](){
QString iconPath = ":/resource/devices/"+widgetName+".png";
m_placepreview->updateIcon(widgetName, iconPath);
m_devicescustomiconpathmap->insert(widgetName, iconPath);
emit newDeviceIconsMap(m_devicescustomiconpathmap);
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout(m_placeeditwidget);
mainWidgetLayout->addWidget(m_placescrollArea);
m_placeeditwidget->setLayout(mainWidgetLayout);
}
void IconThemeWidget::initBatchEditWidget()
{
m_batchwidget = new QWidget(m_rightwidget);
DropBatchButton*bacthButton = new DropBatchButton(m_batchwidget);
QPushButton*buildButton = new QPushButton(m_batchwidget);
QHBoxLayout *layout = new QHBoxLayout(m_batchwidget);
layout->addWidget(bacthButton);
layout->addWidget(buildButton);
m_batchwidget->setFixedHeight(60);
connect(bacthButton,&DropBatchButton::clicked,this,[=](){
// 打开文件对话框选中文件夹filecheck之后把对应文件update到相应位置上
QString folderPath = QFileDialog::getExistingDirectory(this, tr("Select Batch"), QDir::homePath());
QStringList fileList;
QStringList fileList1;
QList<IconEditWidget*> childWidgets;
if(m_stackedwidget->currentIndex() == 0){
fileList = FileCheck::isLegalBatchIcon(folderPath, m_iconpathmap);
@ -396,7 +604,9 @@ void IconThemeWidget::initBatchEditWidget()
fileList = FileCheck::isLegalBatchIcon(folderPath, m_systemiconpathmap);
childWidgets = m_systemscrollArea->viewport()->findChildren<IconEditWidget*>();
} else if(m_stackedwidget->currentIndex() == 2){
fileList = FileCheck::isLegalBatchIcon(folderPath, m_placesiconpathmap);
fileList1 = FileCheck::isLegalBatchIcon(folderPath, m_devicesiconpathmap);
childWidgets = m_placescrollArea->viewport()->findChildren<IconEditWidget*>();
}
for (const QString &filePath : fileList) {
@ -418,6 +628,32 @@ void IconThemeWidget::initBatchEditWidget()
widget->setcustomicon(filePath);
m_systempreview->updateIcon(widgetName, filePath);
emit newSystemIconsMap(m_systemcustomiconpathmap);
}else if(m_stackedwidget->currentIndex() == 2){
m_placescustomiconpathmap->insert(widgetName, filePath);
m_devicescustomiconpathmap->insert(widgetName, filePath);
widget->setcustomicon(filePath);
m_placepreview->updateIcon(widgetName, filePath);
emit newPlaceIconsMap(m_placescustomiconpathmap);
emit newDeviceIconsMap(m_devicescustomiconpathmap);
}
}
break;
}
}
}
for (const QString &filePath : fileList1) {
QString fileName = QFileInfo(filePath).baseName();
for (IconEditWidget *widget : childWidgets) {
QString widgetName = widget->property("widgetname").toString();
if (fileName == widgetName) {
qDebug() << "File Path: " << filePath << " contains Widget Name: " << widgetName;
if(FileCheck::isLegalIconFile(filePath)){
if(m_stackedwidget->currentIndex() == 2){
m_devicescustomiconpathmap->insert(widgetName, filePath);
widget->setcustomicon(filePath);
m_placepreview->updateIcon(widgetName, filePath);
emit newDeviceIconsMap(m_devicescustomiconpathmap);
}
}
break;
@ -429,6 +665,8 @@ void IconThemeWidget::initBatchEditWidget()
// 打开文件对话框选中文件夹filecheck之后把对应文件update到相应位置上
// QString folderPath = QFileDialog::getExistingDirectory(this, tr("Select Batch"), QDir::homePath());
QStringList fileList;
QStringList fileList1;
QList<IconEditWidget*> childWidgets;
if(m_stackedwidget->currentIndex() == 0){
fileList = FileCheck::isLegalBatchIcon(folderPath, m_iconpathmap);
@ -437,14 +675,17 @@ void IconThemeWidget::initBatchEditWidget()
fileList = FileCheck::isLegalBatchIcon(folderPath, m_systemiconpathmap);
childWidgets = m_systemscrollArea->viewport()->findChildren<IconEditWidget*>();
} else if(m_stackedwidget->currentIndex() == 2){
fileList = FileCheck::isLegalBatchIcon(folderPath, m_placesiconpathmap);
fileList1 = FileCheck::isLegalBatchIcon(folderPath, m_devicesiconpathmap);
childWidgets = m_placescrollArea->viewport()->findChildren<IconEditWidget*>();
}
for (const QString &filePath : fileList) {
QString fileName = QFileInfo(filePath).baseName();
// 检查文件路径是否包含任何部件的名称
for (IconEditWidget *widget : childWidgets) {
QString widgetName = widget->property("widgetname").toString();
if (filePath.contains(widgetName)) {
if (fileName == widgetName) {
qDebug() << "File Path: " << filePath << " contains Widget Name: " << widgetName;
if(FileCheck::isLegalIconFile(filePath)){
if(m_stackedwidget->currentIndex() == 0){
@ -459,6 +700,31 @@ void IconThemeWidget::initBatchEditWidget()
widget->setcustomicon(filePath);
m_systempreview->updateIcon(widgetName, filePath);
emit newSystemIconsMap(m_systemcustomiconpathmap);
}else if(m_stackedwidget->currentIndex() == 2){
m_placescustomiconpathmap->insert(widgetName, filePath);
m_devicescustomiconpathmap->insert(widgetName, filePath);
widget->setcustomicon(filePath);
m_placepreview->updateIcon(widgetName, filePath);
emit newPlaceIconsMap(m_placescustomiconpathmap);
emit newDeviceIconsMap(m_devicescustomiconpathmap);
}
}
break;
}
}
}
for (const QString &filePath : fileList1) {
QString fileName = QFileInfo(filePath).baseName();
for (IconEditWidget *widget : childWidgets) {
QString widgetName = widget->property("widgetname").toString();
if (fileName == widgetName) {
qDebug() << "File Path: " << filePath << " contains Widget Name: " << widgetName;
if(FileCheck::isLegalIconFile(filePath)){
if(m_stackedwidget->currentIndex() == 2){
m_devicescustomiconpathmap->insert(widgetName, filePath);
widget->setcustomicon(filePath);
m_placepreview->updateIcon(widgetName, filePath);
emit newDeviceIconsMap(m_devicescustomiconpathmap);
}
}
break;
@ -534,6 +800,26 @@ QMap<QString, QString> *IconThemeWidget::getResourcesAppIconMap(QString Type)
m_systemiconpathmap->insert(widgetNames[i], cursorFileName);
}
return m_systemiconpathmap;
}else if("placesicon" == Type){
m_placesiconpathmap = new QMap<QString, QString> ;
QString directoryPath = ":/resource/places/";
QStringList widgetNames = getWidgetNamesFromFilesInDirectory(directoryPath);
for (int i = 0; i < widgetNames.size(); ++i) {
QString cursorFileName = directoryPath + widgetNames[i] + ".png";
m_placesiconpathmap->insert(widgetNames[i], cursorFileName);
}
return m_placesiconpathmap;
}else if("devicesicon" == Type){
m_devicesiconpathmap = new QMap<QString, QString> ;
QString directoryPath = ":/resource/devices/";
QStringList widgetNames = getWidgetNamesFromFilesInDirectory(directoryPath);
for (int i = 0; i < widgetNames.size(); ++i) {
QString cursorFileName = directoryPath + widgetNames[i] + ".png";
m_devicesiconpathmap->insert(widgetNames[i], cursorFileName);
}
return m_devicesiconpathmap;
}
}
@ -552,6 +838,32 @@ void IconThemeWidget::initSystemMaps()
m_systempathWidgetMap = new QMap<QString, IconEditWidget*>;
}
/**
* @brief
*
* QMap
*/
void IconThemeWidget::initPlacesMaps()
{
getResourcesAppIconMap("placesicon");
m_placescustomiconpathmap = m_placesiconpathmap;
m_placespathWidgetMap = new QMap<QString, IconEditWidget*>;
}
/**
* @brief
*
* QMap
*/
void IconThemeWidget::initDevicesMaps()
{
getResourcesAppIconMap("devicesicon");
m_devicescustomiconpathmap = m_devicesiconpathmap;
m_devicespathWidgetMap = new QMap<QString, IconEditWidget*>;
}
/**
* @brief
*
@ -574,7 +886,7 @@ void IconThemeWidget::initRightWidget()
m_tabbar->setTabBarStyle(kdk::KTabBarStyle::SegmentDark);
m_tabbar->addTab("AppIcons");
m_tabbar->addTab("SystemIcons");
m_tabbar->addTab("Mimetype");
m_tabbar->addTab("PlaceIcons");
layout->addWidget(m_tabbar);
layout->setContentsMargins(0,0,15,0);
@ -584,9 +896,12 @@ void IconThemeWidget::initRightWidget()
initEditWidget();
initSystemEditWidget();
initPlaceandDeviceEditWidget();
initBatchEditWidget();
m_stackedwidget->addWidget(m_editwidget);
m_stackedwidget->addWidget(m_systemeditwidget);
m_stackedwidget->addWidget(m_placeeditwidget);
m_stackedwidget->setCurrentIndex(0);
@ -596,8 +911,9 @@ void IconThemeWidget::initRightWidget()
});
m_rightwidgetlayout->addWidget(m_changebuttonwidget);
m_rightwidgetlayout->addWidget(m_batchwidget);
m_rightwidgetlayout->addWidget(m_stackedwidget);
m_rightwidgetlayout->addWidget(m_batchwidget);
m_rightwidget->setLayout(m_rightwidgetlayout);
}
@ -628,6 +944,18 @@ QMap<QString, QString> *IconThemeWidget::getSystemIconsMap()
return m_systemiconpathmap;
}
QMap<QString, QString> *IconThemeWidget::getPlaceIconsMap()
{
getResourcesAppIconMap("placesicon");
return m_placesiconpathmap;
}
QMap<QString, QString> *IconThemeWidget::getDeviceIconsMap()
{
getResourcesAppIconMap("devicesicon");
return m_devicesiconpathmap;
}
/**
* @brief
*
@ -674,6 +1002,30 @@ void IconThemeWidget::setHistorySystemIcon()
m_historysystemiconmap->insert(name, filePath);
}
}
void IconThemeWidget::setHistoryPlaceIcon()
{
QString directoryPath = m_info.filepath + "/src/iconTheme/placeicon/";
QDir directory(directoryPath);
QStringList filters;
filters << "*.png" << "*.svg";
QStringList fileList = directory.entryList(filters, QDir::Files);
m_historyplacesiconmap = new QMap<QString, QString>;
foreach (const QString& fileName, fileList) {
QString filePath = directoryPath + fileName; // 使用文件名构建文件路径
QString name = fileName.left(fileName.lastIndexOf('.'));
m_historyplacesiconmap->insert(name, filePath);
}
}
void IconThemeWidget::setHistoryDeviceIcon()
{
}
/**
* @brief
*
@ -684,12 +1036,19 @@ void IconThemeWidget::setHistorySystemIcon()
void IconThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
{
m_info = InfoData;
setHistoryAppIcon();
setHistorySystemIcon();
m_preview->updateIconMap(m_historyiconmap);
m_systempreview->updateIconMap(m_historysystemiconmap);
setHistoryPlaceIcon();
m_preview->updateIconMap(m_historyiconmap,"appicon");
m_systempreview->updateIconMap(m_historysystemiconmap,"systemicon");
m_placepreview->updateIconMap(m_historyplacesiconmap,"placeicon");
updateCustomIconPathMap(m_historyiconmap);
updateCustomSyetemIconPathMap(m_historysystemiconmap);
updateCustomPlaceIconPathMap(m_historyplacesiconmap);
if(m_info.wallpaperpath != nullptr){
m_preview->updateImage(m_info.wallpaperpath);
}else{
@ -705,11 +1064,21 @@ void IconThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
*/
void IconThemeWidget::refresh()
{
m_preview->updateIconMap(getResourcesAppIconMap("appicon"));
m_preview->updateIconMap(getResourcesAppIconMap("appicon"),"appicon");
updateCustomIconPathMap(m_iconpathmap);
m_systempreview->updateIconMap(getResourcesAppIconMap("systemicon"));
m_systempreview->updateIconMap(getResourcesAppIconMap("systemicon"),"systemicon");
updateCustomSyetemIconPathMap(m_systemiconpathmap);
getResourcesAppIconMap("placesicon");
getResourcesAppIconMap("devicesicon");
QMap<QString, QString> placesMap = *m_placesiconpathmap;
QMap<QString, QString> devicesMap = *m_devicesiconpathmap;
QMap<QString, QString> mergedMap = placesMap.unite(devicesMap);
m_placepreview->updateIconMap(&mergedMap,"placeicon");
// m_placepreview->updateIconMap(getResourcesAppIconMap("placesicon"),"placeicon");
// updateCustomPlaceIconPathMap(m_placesiconpathmap);
// m_placepreview->updateIconMap(getResourcesAppIconMap("devicesicon"),"deviceicon");
}
void IconThemeWidget::useMaximumScale()

View File

@ -29,19 +29,36 @@ class IconThemeWidget : public QWidget
public:
explicit IconThemeWidget(bool isHistory,QWidget *parent = nullptr);
void initPreviewWidget();
void initEditWidget();
void initSystemEditWidget();
void initPlaceandDeviceEditWidget();
void initDeviceEditWidget();
void initBatchEditWidget();
void initMaps();
QMap<QString, QString> *getResourcesAppIconMap(QString Type);
void initMaps();
void initSystemMaps();
void initPlacesMaps();
void initDevicesMaps();
void initRightWidget();
QMap<QString, QString>* getAppIconsMap();
QMap<QString, QString>* getSystemIconsMap();
QMap<QString, QString>* getPlaceIconsMap();
QMap<QString, QString>* getDeviceIconsMap();
void setHistoryAppIcon();
void setHistorySystemIcon();
void setHistoryPlaceIcon();
void setHistoryDeviceIcon();
void updateCustomIconPathMap(QMap<QString, QString>*historyMap);
void updateCustomSyetemIconPathMap(QMap<QString, QString>*historyMap);
void updateCustomPlaceIconPathMap(QMap<QString, QString>*historyMap);
void updateCustomDeviceIconPathMap(QMap<QString, QString>*historyMap);
void eidtInitWidget(const HistoryInfo &InfoData);
void refresh();
@ -50,10 +67,15 @@ public:
QMap<QString, bool> *m_iconPresenceMap;
void useMaximumScale();
void useRestoreScale();
signals:
void wallpaperupdate(const QString& filePath);
void newAppIconsMap(QMap<QString, QString> *appiconsmap);
void newSystemIconsMap(QMap<QString, QString> *systemiconsmap);
void newPlaceIconsMap(QMap<QString, QString> *placeiconsmap);
void newDeviceIconsMap(QMap<QString, QString> *deviceiconsmap);
void iconthemeChange(QMap<QString, bool> *iconthemeChangeMap);
void batchIconUpdate(const QString& filePath);
private:
@ -79,15 +101,31 @@ private:
QMap<QString, QString> *m_systemcustomiconpathmap;
QMap<QString, IconEditWidget*> *m_systempathWidgetMap;
QMap<QString, QString> *m_placesiconpathmap;
QMap<QString, QString> *m_historyplacesiconmap;
QMap<QString, QString> *m_placescustomiconpathmap;
QMap<QString, IconEditWidget*> *m_placespathWidgetMap;
QMap<QString, QString> *m_devicesiconpathmap;
QMap<QString, QString> *m_historydevicesiconmap;
QMap<QString, QString> *m_devicescustomiconpathmap;
QMap<QString, IconEditWidget*> *m_devicespathWidgetMap;
BasePreviewWidget *m_previewwidget;
ImageWidget *m_preview;
ImageWidget *m_systempreview;
ImageWidget *m_placepreview;
QStackedWidget *m_previewstack;
HistoryInfo m_info;
QWidget *m_editwidget;
QWidget *m_systemeditwidget;
QWidget *m_placeeditwidget;
QScrollArea *m_scrollArea;
QScrollArea *m_systemscrollArea;
QScrollArea *m_placescrollArea;
// QScrollArea *m_systemscrollArea;
};
#endif // ICONTHEMEWIDGET_H

View File

@ -127,96 +127,96 @@ ImageWidget::ImageWidget(QWidget *parent, const QMap<QString, QString>* iconMap)
// 显示视图
graphicsView->show();
// 如果图标映射表的大小等于11则进行特定的图片加载和添加操作
if (count == 11) {
// 获取图标映射表的所有键值对
QList<QString> keys = m_iconMap->keys();
// 根据特定的顺序创建键值的数组
QString positions[11] = { keys[0], keys[9], keys[4], keys[5], keys[6],
keys[3], keys[10], keys[8], keys[1], keys[7], keys[2] };
// 定义图片的位置数组
int posX[3] = { 208, 879, 1550 };
int posY[4] = { 275, 535, 795, 1055 };
int index = 0;
QMap<QString,QString>* systemicon_name_CH = new QMap<QString,QString>;
systemicon_name_CH = initSystemIconName(systemicon_name_CH,keys);
// 遍历位置数组,加载并添加图片到场景中
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 3; ++j) {
// 检查索引是否超出范围
if (index >= 11) {
break; // 处理超出索引范围的情况
}
// 根据键值获取图片路径,并加载图片
QString pixmapPath = m_iconMap->value(positions[index]);
QPixmap pixmap(pixmapPath);
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(100, 100));
// 设置图形的可选择和可聚焦属性,以触发选择和焦点事件
item->setFlag(QGraphicsItem::ItemIsSelectable); // 启用选择事件
item->setFlag(QGraphicsItem::ItemIsFocusable); // 启用焦点事件
// 将键值和图片路径保存到图形的数据中,以便后续使用
item->setData(0, keys[index]);
item->setData(1, pixmapPath);
// 设置图形的位置
item->setPos(posX[j], posY[i]);
// // 如果图标映射表的大小等于11则进行特定的图片加载和添加操作
// if (count == 11) {
// // 获取图标映射表的所有键值对
// QList<QString> keys = m_iconMap->keys();
// // 根据特定的顺序创建键值的数组
// QString positions[11] = { keys[0], keys[9], keys[4], keys[5], keys[6],
// keys[3], keys[10], keys[8], keys[1], keys[7], keys[2] };
// // 定义图片的位置数组
// int posX[3] = { 208, 879, 1550 };
// int posY[4] = { 275, 535, 795, 1055 };
// int index = 0;
// QMap<QString,QString>* systemicon_name_CH = new QMap<QString,QString>;
// systemicon_name_CH = initSystemIconName(systemicon_name_CH,keys);
// // 遍历位置数组,加载并添加图片到场景中
// for (int i = 0; i < 4; ++i) {
// for (int j = 0; j < 3; ++j) {
// // 检查索引是否超出范围
// if (index >= 11) {
// break; // 处理超出索引范围的情况
// }
// // 根据键值获取图片路径,并加载图片
// QString pixmapPath = m_iconMap->value(positions[index]);
// QPixmap pixmap(pixmapPath);
// QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(100, 100));
// // 设置图形的可选择和可聚焦属性,以触发选择和焦点事件
// item->setFlag(QGraphicsItem::ItemIsSelectable); // 启用选择事件
// item->setFlag(QGraphicsItem::ItemIsFocusable); // 启用焦点事件
// // 将键值和图片路径保存到图形的数据中,以便后续使用
// item->setData(0, keys[index]);
// item->setData(1, pixmapPath);
// // 设置图形的位置
// item->setPos(posX[j], posY[i]);
// 添加文字项
QGraphicsTextItem* textItem = scene->addText(systemicon_name_CH->value(keys[index]));
textItem->setPos(posX[j], posY[i] + 110);
textItem->setDefaultTextColor(Qt::black);
QRectF textRect = textItem->boundingRect();
textItem->setPos(posX[j] + (128 - textRect.width()) / 2 - 15, posY[i] + 110);
// // 添加文字项
// QGraphicsTextItem* textItem = scene->addText(systemicon_name_CH->value(keys[index]));
// textItem->setPos(posX[j], posY[i] + 110);
// textItem->setDefaultTextColor(Qt::black);
// QRectF textRect = textItem->boundingRect();
// textItem->setPos(posX[j] + (128 - textRect.width()) / 2 - 15, posY[i] + 110);
// 增加索引的值,准备处理下一个图片的加载和添加操作
++index;
}
}
}else{ // 如果图标映射表的大小不等于11则进行常规的图片加载和添加操作
// 定义列数和行数,以及初始的列和行索引值
int columnCount = 10;
int row = 1;
int col = 2;
// 遍历图标映射表的所有键值对,加载并添加图片到场景中
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
const QString& widgetName = it.key(); // 获取键值对应的名称,用于后续数据的保存和处理中用到此处名称的部分。
// 获取当前迭代器it的值
const QString& filePath = it.value();
// // 增加索引的值,准备处理下一个图片的加载和添加操作
// ++index;
// }
// }
// }else{ // 如果图标映射表的大小不等于11则进行常规的图片加载和添加操作
// // 定义列数和行数,以及初始的列和行索引值
// int columnCount = 10;
// int row = 1;
// int col = 2;
// // 遍历图标映射表的所有键值对,加载并添加图片到场景中
// for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
// const QString& widgetName = it.key(); // 获取键值对应的名称,用于后续数据的保存和处理中用到此处名称的部分。
// // 获取当前迭代器it的值
// const QString& filePath = it.value();
// 根据文件路径加载QPixmap对象这将加载文件并创建一个QPixmap对象
QPixmap pixmap(filePath);
// // 根据文件路径加载QPixmap对象这将加载文件并创建一个QPixmap对象
// QPixmap pixmap(filePath);
// 判断图片是否成功加载如果QPixmap对象为空说明加载失败
if (!pixmap.isNull()) {
// 如果图片加载成功则将图片添加到QGraphicsScene中并按照128x128的尺寸进行缩放
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
// // 判断图片是否成功加载如果QPixmap对象为空说明加载失败
// if (!pixmap.isNull()) {
// // 如果图片加载成功则将图片添加到QGraphicsScene中并按照128x128的尺寸进行缩放
// QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
// 设置该项可以被选择,即响应用户的点击选择事件
item->setFlag(QGraphicsItem::ItemIsSelectable);
// // 设置该项可以被选择,即响应用户的点击选择事件
// item->setFlag(QGraphicsItem::ItemIsSelectable);
// 设置该项在场景中的位置
item->setPos(col * 160, row * 160);
item->setScale(1.0);
// // 设置该项在场景中的位置
// item->setPos(col * 160, row * 160);
// item->setScale(1.0);
// 为该项设置一些自定义的数据这些数据可以通过调用QGraphicsItem::data方法来获取
item->setData(0, widgetName); // 将widgetName数据保存到该项的第一个数据槽中
item->setData(1, filePath); // 将filePath数据保存到该项的第二个数据槽中
// // 为该项设置一些自定义的数据这些数据可以通过调用QGraphicsItem::data方法来获取
// item->setData(0, widgetName); // 将widgetName数据保存到该项的第一个数据槽中
// item->setData(1, filePath); // 将filePath数据保存到该项的第二个数据槽中
// 增加列计数器
col++;
// // 增加列计数器
// col++;
// 如果列计数器超过了指定的列数,就重新开始行计数器,同时增加一行
if (col >= columnCount) {
col = 2; // 重新开始列计数器,但这次从第二列开始计数
row++; // 增加一行计数器
} else {
qDebug() << "Failed to load image:" << filePath;
}
}
}
// // 如果列计数器超过了指定的列数,就重新开始行计数器,同时增加一行
// if (col >= columnCount) {
// col = 2; // 重新开始列计数器,但这次从第二列开始计数
// row++; // 增加一行计数器
// } else {
// qDebug() << "Failed to load image:" << filePath;
// }
// }
// }
}
// }
// 设置初始缩放倍数为0.9倍
qreal initialScale = 2;
graphicsView->scale(initialScale, initialScale);
@ -229,7 +229,7 @@ ImageWidget::ImageWidget(QWidget *parent, const QMap<QString, QString>* iconMap)
*
* @param newIconMap
*/
void ImageWidget::updateIconMap(const QMap<QString, QString>* newIconMap)
void ImageWidget::updateIconMap(const QMap<QString, QString>* newIconMap, QString type)
{
m_iconMap = newIconMap;
@ -237,9 +237,9 @@ void ImageWidget::updateIconMap(const QMap<QString, QString>* newIconMap)
QGraphicsScene* scene = graphicsView->scene();
scene->clear();
// 判断新的iconMap大小
int count = m_iconMap->size();
if (count <= 22) {
// // 判断新的iconMap大小
// int count = m_iconMap->size();
if (type == "systemicon") {
// 更新背景图片
image = new QPixmap(":/resource/background/controlcenter-light.png");
if (image->isNull()) {
@ -282,7 +282,7 @@ void ImageWidget::updateIconMap(const QMap<QString, QString>* newIconMap)
++index;
}
}
} else {
} else if(type == "appicon") {
// 更新背景图片
image = new QPixmap(":/resource/background/background-light.png");
if (image->isNull()) {
@ -324,6 +324,65 @@ void ImageWidget::updateIconMap(const QMap<QString, QString>* newIconMap)
qDebug() << "Failed to load image:" << filePath;
}
}
}else if(type == "placeicon"){
// 更新背景图片
image = new QPixmap(":/resource/background/background-light.png");
if (image->isNull()) {
qDebug() << "Failed to load image.";
}
scene->addPixmap(*image);
// 创建有序的键值对列表
QList<QPair<QString, QString>> sortedList1;
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
sortedList1.append(qMakePair(it.key(), it.value()));
}
std::sort(sortedList1.begin(), sortedList1.end(), [](const QPair<QString, QString>& pair1, const QPair<QString, QString>& pair2){
// 按照指定顺序进行排序
QStringList order = QStringList() << "document-open-recent" << "folder-documents" << "folder-download" << "folder-dropbox" << "folder-music"
<< "folder-open"<< "folder-pictures" << "folder-publicshare"
<< "folder-templates" << "folder-videos" << "inode-directory" << "user-desktop"
<< "user-home" << "user-trash-full"<< "user-trash"
<< "computer" << "cupsprinter" << "drive-harddisk" << "drive-removable-media-usb" << "input-keyboard"
<< "input-mouse" << "scanner";
return order.indexOf(pair1.first) < order.indexOf(pair2.first);
});
// 重新布局图标
int columnCount = 10;
int row = 1;
int col = 2;
for (const auto& pair : sortedList1) {
const QString& widgetName = pair.first;
const QString& filePath = pair.second;
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
item->setFlag(QGraphicsItem::ItemIsSelectable); // 启用选择事件
item->setFlag(QGraphicsItem::ItemIsFocusable); // 启用焦点事件
item->setPos(col * 160, row * 160);
item->setScale(1.0);
item->setData(0, widgetName);
item->setData(1, filePath);
QGraphicsTextItem* textItem = scene->addText(widgetName);
textItem->setPos(col * 160, row * 160 + 128);
QRectF textRect = textItem->boundingRect();
textItem->setPos(col * 160 + (128 - textRect.width()) / 2, row * 160 + 120);
col++;
if (col >= columnCount) {
col = 2;
row++;
}
if (widgetName == "user-trash") {
col = 2;
row++;
}
} else {
qDebug() << "Failed to load image:" << filePath;
}
}
}
// 更新视图

View File

@ -60,7 +60,7 @@ public:
ImageWidget(QWidget *parent = nullptr, const QMap<QString,QString>* iconMap = nullptr);
void updateIcon(const QString& widgetName, const QString& newFilePath);
void updateImage(const QString& imagePath);
void updateIconMap(const QMap<QString, QString>* newIconMap);
void updateIconMap(const QMap<QString, QString>* newIconMap,QString type);
void maxscale();
void miniscale();
QMap<QString, QString> *initIconName(QMap<QString, QString> *name_CH, QList<QString> keys);

View File

@ -106,10 +106,12 @@ this->setContentsMargins(0,0,5,0);
layout->addStretch();
QHBoxLayout *buttonLayout = new QHBoxLayout();
QSpacerItem *spacer = new QSpacerItem(44, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
buttonLayout->addWidget(iconlabel);
buttonLayout->addWidget(title);
buttonLayout->addStretch();
buttonLayout->addSpacerItem(spacer);
buttonLayout->addWidget(m_gohomebtn);
buttonLayout->addStretch();
buttonLayout->addWidget(m_optionbtn);
buttonLayout->addWidget(m_minimumbtn);
buttonLayout->addWidget(m_maximumbtn);