From df5da75447d8c470ee9a11baeb074bd5b1214e78 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Wed, 28 Jun 2023 09:59:18 +0800 Subject: [PATCH] add globaltheme UI --- src/baseUI/globalthemewidget.cpp | 116 +++++++++++++++++++++++++ src/baseUI/globalthemewidget.h | 22 ++++- src/baseUI/iconthemewidget.cpp | 2 - src/baseUI/mainwindow.h | 3 - src/baseUI/themescheck/themescheck.cpp | 12 ++- src/baseUI/themescheck/themescheck.h | 2 +- src/baseUI/wallpaperthemewidget.cpp | 11 +-- src/baseUI/wallpaperthemewidget.h | 1 + src/baseUI/widgetbase.cpp | 4 +- 9 files changed, 158 insertions(+), 15 deletions(-) diff --git a/src/baseUI/globalthemewidget.cpp b/src/baseUI/globalthemewidget.cpp index 62a09ee..1eff3ee 100644 --- a/src/baseUI/globalthemewidget.cpp +++ b/src/baseUI/globalthemewidget.cpp @@ -1,6 +1,122 @@ #include "globalthemewidget.h" +#include +#include +#include GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : WidgetBase(parent) { + this->initThemeLabel("创建全局主题"); + m_importButton->deleteLater(); +// m_headWidget->setFixedHeight(62); + init(); +} + +void GlobalThemeWidget::init() +{ + m_allLayout->takeAt(1); + + initglobalwidget(); + + int index = m_allLayout->indexOf(m_buttonWidget); + m_allLayout->insertWidget(index, m_globalwidget); } + +void GlobalThemeWidget::initglobalwidget() +{ + m_globalwidget = new QWidget(this); + m_globallayout = new QVBoxLayout(); + + m_globalwidget->setFixedHeight(291); + m_globalwidget->setFixedWidth(480); + + m_accentcolorwidget = new QWidget(m_globalwidget); + m_accentcolorwidget->setFixedHeight(68); + m_accentcolorlayout = new QHBoxLayout(m_accentcolorwidget); + + QPalette pal = qApp->palette(); + QLabel *label = new QLabel(m_accentcolorwidget); + label->setText("主题强调色:"); + m_accentcolorlayout->addWidget(label); + m_accentcolorlayout->addSpacing(10); + QMap colorButtonMap; + + m_colorlist = QStringList{"#3790fa", "#7873f5", "#eb3096", "#f3222d", "#f68c27", "#f9c53d", "#52c429"}; + + for (const QString& color : m_colorlist) { + QPushButton* pushButton = new QPushButton(); + pushButton->setProperty("isRoundButton", true); + + pushButton->setFixedSize(QSize(24,24)); + pal.setColor(QPalette::Button,QColor(color)); + pushButton->setPalette(pal); + colorButtonMap.insert(color, pushButton); + m_accentcolorlayout->addWidget(pushButton); + } + m_accentcolorlayout->addStretch(1); + + m_coverwidget = new QWidget(m_globalwidget); + m_coverwidget->setFixedHeight(133); + m_coverlayout = new QHBoxLayout(m_coverwidget); + + QLabel *coverlabel = new QLabel(m_coverwidget); + coverlabel->setText("主题封面"); + + + m_coverbutton = new QPushButton(m_coverwidget); + m_coverbutton->setFixedSize(QSize(140,100)); + + QVBoxLayout *buttonlayout = new QVBoxLayout(m_coverbutton); + + QLabel *iconLabel = new QLabel; + QIcon icon = QIcon::fromTheme("list-add-symbolic"); + iconLabel->setPixmap(icon.pixmap(QSize(24, 24))); + iconLabel->setAlignment(Qt::AlignHCenter); + QLabel *textLabel = new QLabel("支持 png/jpg ,不超过 5 M"); + textLabel->setAlignment(Qt::AlignHCenter); + textLabel->setWordWrap(true); + textLabel->setMaximumWidth(120); + textLabel->setStyleSheet("font-size: 12px;"); + + buttonlayout->addWidget(iconLabel); + buttonlayout->addWidget(textLabel); + buttonlayout->addStretch(1); + m_coverlayout->addWidget(coverlabel); + m_coverlayout->addWidget(m_coverbutton); + m_coverlayout->addStretch(1); + + m_wallpaperwidget = new QWidget(m_globalwidget); + m_wallpaperwidget->setFixedHeight(133); + m_wallpaperlayout = new QHBoxLayout(m_wallpaperwidget); + + QLabel *wallpaperlabel = new QLabel(m_wallpaperwidget); + wallpaperlabel->setText("桌面壁纸"); + + m_wallpaperbutton = new QPushButton(m_wallpaperwidget); + m_wallpaperbutton->setFixedSize(QSize(140,100)); + + QVBoxLayout *buttonlayout1 = new QVBoxLayout(m_wallpaperbutton); + + QLabel *iconLabel1 = new QLabel; + iconLabel1->setPixmap(icon.pixmap(QSize(24, 24))); + iconLabel1->setAlignment(Qt::AlignHCenter); + QLabel *textLabel1 = new QLabel("支持 png/jpg ,不超过 10 M"); + textLabel1->setAlignment(Qt::AlignHCenter); + textLabel1->setWordWrap(true); + textLabel1->setMaximumWidth(120); + textLabel1->setStyleSheet("font-size: 12px;"); + + buttonlayout1->addWidget(iconLabel1); + buttonlayout1->addWidget(textLabel1); + buttonlayout1->addStretch(1); + + + m_wallpaperlayout->addWidget(wallpaperlabel); + m_wallpaperlayout->addWidget(m_wallpaperbutton); + m_wallpaperlayout->addStretch(); + + m_globallayout->addWidget(m_accentcolorwidget); + m_globallayout->addWidget(m_coverwidget); + m_globallayout->addWidget(m_wallpaperwidget); + m_globalwidget->setLayout(m_globallayout); +} diff --git a/src/baseUI/globalthemewidget.h b/src/baseUI/globalthemewidget.h index b994984..ae8ba6a 100644 --- a/src/baseUI/globalthemewidget.h +++ b/src/baseUI/globalthemewidget.h @@ -4,14 +4,34 @@ #include "widgetbase.h" #include +#include class GlobalThemeWidget : public WidgetBase { Q_OBJECT public: explicit GlobalThemeWidget(QWidget *parent = nullptr); - + void init(); + void initglobalwidget(); signals: +private: + QWidget *m_globalwidget; + QVBoxLayout *m_globallayout; + QWidget *m_accentcolorwidget; + QHBoxLayout *m_accentcolorlayout; + QMap m_colorbuttonmap; + QMap m_colormap; + QStringList m_colorlist; + + QWidget *m_coverwidget; + QHBoxLayout *m_coverlayout; + QPushButton *m_coverbutton; + + QWidget *m_wallpaperwidget; + QHBoxLayout *m_wallpaperlayout; + QPushButton *m_wallpaperbutton; +private slots: + }; diff --git a/src/baseUI/iconthemewidget.cpp b/src/baseUI/iconthemewidget.cpp index fbfc99a..af133e8 100644 --- a/src/baseUI/iconthemewidget.cpp +++ b/src/baseUI/iconthemewidget.cpp @@ -23,13 +23,11 @@ IconThemeWidget::IconThemeWidget(QWidget *parent) : WidgetBase(parent) connect(m_importButton , &QPushButton::clicked, this, [=](){ this->importIcons(); }); -// connect(this,&IconThemeWidget::onConfirmButtonClicked,this, &IconThemeWidget::check); } void IconThemeWidget::init() { QString name = qgetenv("USER"); - qDebug()<<"QString name = qgetenv;"<insertWidget(new QLabel(tr("WidgetA"))); // 创建新的 widget diff --git a/src/baseUI/mainwindow.h b/src/baseUI/mainwindow.h index baa13ae..83b6e23 100644 --- a/src/baseUI/mainwindow.h +++ b/src/baseUI/mainwindow.h @@ -75,8 +75,5 @@ private: void backToCreateInterface(); void buildThemesCheck(); - - - }; #endif // MAINWINDOW_H diff --git a/src/baseUI/themescheck/themescheck.cpp b/src/baseUI/themescheck/themescheck.cpp index 164e617..f7df98b 100644 --- a/src/baseUI/themescheck/themescheck.cpp +++ b/src/baseUI/themescheck/themescheck.cpp @@ -76,6 +76,14 @@ bool ThemesCheck::checkIconsDir(QString folderPath) bool ThemesCheck::checkWallpaperDir(QString folderPath) { - //检查图片大小。 -// folderPath +// //检查图片大小。 +// QFile pic = QFile(folderPath); +// QFileInfo info = QFileInfo(pic); +// // 检查文件大小 +// const qint64 maxSize = 10 * 1024 * 1024; // 10MB +// if (info.size() > maxSize) +// { +// return false; +// } +// return true; } diff --git a/src/baseUI/themescheck/themescheck.h b/src/baseUI/themescheck/themescheck.h index 94555e6..bf35102 100644 --- a/src/baseUI/themescheck/themescheck.h +++ b/src/baseUI/themescheck/themescheck.h @@ -12,7 +12,7 @@ public: static bool checkIconsDir(QString folderPath); static bool checkCursorDir(QString folderPath); - static bool checkPaperDir(QString folderPath); + static bool checkWallpaperDir(QString folderPath); signals: diff --git a/src/baseUI/wallpaperthemewidget.cpp b/src/baseUI/wallpaperthemewidget.cpp index fdb0d6b..06a1d74 100644 --- a/src/baseUI/wallpaperthemewidget.cpp +++ b/src/baseUI/wallpaperthemewidget.cpp @@ -14,7 +14,6 @@ WallpaperthemeWidget::WallpaperthemeWidget(QWidget *parent) : WidgetBase(parent) void WallpaperthemeWidget::init() { QString name = qgetenv("USER"); - qDebug()<<"QString name = qgetenv;"<setFixedSize(newWidget->size()); m_listwidget->setFlow(QListView::LeftToRight); m_listwidget->setMovement(QListView::Static); - m_listwidget->setIconSize(QSize(100, 56)); + m_listwidget->setIconSize(QSize(100, 57)); // 初始化固定路径 QString fixedPath = m_wallpaperpath; @@ -38,7 +37,7 @@ void WallpaperthemeWidget::init() QStringList fileNames = QDir(fixedPath).entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); foreach (QString fileName, fileNames) { QString imgpath = m_wallpaperpath+fileName; - QListWidgetItem *item = new QListWidgetItem(fileName); + QListWidgetItem *item = new QListWidgetItem(/*fileName*/); item->setIcon(QIcon(imgpath)); m_listwidget->addItem(item); @@ -77,8 +76,10 @@ void WallpaperthemeWidget::importWallpaper() QFileInfo fileInfo(file); - QListWidgetItem *item = new QListWidgetItem(fileInfo.fileName()); - item->setIcon(QIcon(fileInfo.fileName())); + QListWidgetItem *item = new QListWidgetItem(/*fileInfo.fileName()*/); +// QListWidgetItem *item = new QListWidgetItem(fileInfo.absoluteFilePath()); + + item->setIcon(QIcon(fileInfo.absoluteFilePath())); // item->setSizeHint(QSize(100, 100)); item->setData(Qt::UserRole, fileInfo.fileName()); diff --git a/src/baseUI/wallpaperthemewidget.h b/src/baseUI/wallpaperthemewidget.h index a4194e7..d22649a 100644 --- a/src/baseUI/wallpaperthemewidget.h +++ b/src/baseUI/wallpaperthemewidget.h @@ -3,6 +3,7 @@ #include "widgetbase.h" +#include "themescheck/themescheck.h" #include #include diff --git a/src/baseUI/widgetbase.cpp b/src/baseUI/widgetbase.cpp index a6bc349..48743a9 100644 --- a/src/baseUI/widgetbase.cpp +++ b/src/baseUI/widgetbase.cpp @@ -8,11 +8,13 @@ WidgetBase::WidgetBase(QWidget *parent) : QWidget(parent) m_headWidget = new QWidget(this); m_headWidget->setFixedHeight(112); + m_headWidget->setContentsMargins(0,0,0,0); m_themeLabel = new QLabel(m_headWidget); // m_themeLabel->setText(QString("创建主题图标")); m_nameLineEdit = new QLineEdit(m_headWidget); + m_importButton = new QPushButton(m_headWidget); m_importButton->setFixedSize(QSize(96,36)); // m_importButton->setText(QString("导入图标")); @@ -21,7 +23,7 @@ WidgetBase::WidgetBase(QWidget *parent) : QWidget(parent) headlayout->addWidget(m_themeLabel); headlayout->addWidget(m_nameLineEdit); headlayout->addWidget(m_importButton); - + headlayout->setContentsMargins(0,0,0,0); m_headWidget->setLayout(headlayout); m_buttonWidget = new QWidget(this);