add globaltheme UI

This commit is contained in:
likehomedream 2023-06-28 09:59:18 +08:00
parent 33945dcc4a
commit df5da75447
9 changed files with 158 additions and 15 deletions

View File

@ -1,6 +1,122 @@
#include "globalthemewidget.h"
#include <QApplication>
#include <QDebug>
#include <QPalette>
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<QString, QPushButton*> 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);
}

View File

@ -4,14 +4,34 @@
#include "widgetbase.h"
#include <QWidget>
#include <QMap>
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<QString, QPushButton*> m_colorbuttonmap;
QMap<QString, QColor> 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:
};

View File

@ -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;"<<name;
m_iconpath = HOMEPATH +name + "/.cache/theme-build/icon/";
// m_allLayout->insertWidget(new QLabel(tr("WidgetA")));
// 创建新的 widget

View File

@ -75,8 +75,5 @@ private:
void backToCreateInterface();
void buildThemesCheck();
};
#endif // MAINWINDOW_H

View File

@ -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;
}

View File

@ -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:

View File

@ -14,7 +14,6 @@ WallpaperthemeWidget::WallpaperthemeWidget(QWidget *parent) : WidgetBase(parent)
void WallpaperthemeWidget::init()
{
QString name = qgetenv("USER");
qDebug()<<"QString name = qgetenv;"<<name;
m_wallpaperpath = HOMEPATH +name + "/.cache/theme-build/wallpapers/";
QWidget* newWidget = new QWidget(this);
@ -29,7 +28,7 @@ void WallpaperthemeWidget::init()
m_listwidget->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());

View File

@ -3,6 +3,7 @@
#include "widgetbase.h"
#include "themescheck/themescheck.h"
#include <QWidget>
#include <QListWidget>

View File

@ -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);