add global UI
This commit is contained in:
parent
df5da75447
commit
db08176957
|
@ -2,7 +2,8 @@
|
|||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QPalette>
|
||||
|
||||
#include <QButtonGroup>
|
||||
#include <QIcon>
|
||||
GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : WidgetBase(parent)
|
||||
{
|
||||
this->initThemeLabel("创建全局主题");
|
||||
|
@ -13,16 +14,18 @@ GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : WidgetBase(parent)
|
|||
|
||||
void GlobalThemeWidget::init()
|
||||
{
|
||||
QString name = qgetenv("USER");
|
||||
m_globalpath = HOMEPATH +name + "/.cache/theme-build/global/";
|
||||
m_allLayout->takeAt(1);
|
||||
|
||||
initglobalwidget();
|
||||
initGlobalWidget();
|
||||
|
||||
int index = m_allLayout->indexOf(m_buttonWidget);
|
||||
m_allLayout->insertWidget(index, m_globalwidget);
|
||||
|
||||
}
|
||||
|
||||
void GlobalThemeWidget::initglobalwidget()
|
||||
void GlobalThemeWidget::initGlobalWidget()
|
||||
{
|
||||
m_globalwidget = new QWidget(this);
|
||||
m_globallayout = new QVBoxLayout();
|
||||
|
@ -39,20 +42,31 @@ void GlobalThemeWidget::initglobalwidget()
|
|||
label->setText("主题强调色:");
|
||||
m_accentcolorlayout->addWidget(label);
|
||||
m_accentcolorlayout->addSpacing(10);
|
||||
QMap<QString, QPushButton*> colorButtonMap;
|
||||
|
||||
QButtonGroup * box = new QButtonGroup;
|
||||
box->setExclusive(true);
|
||||
|
||||
m_colorlist = QStringList{"#3790fa", "#7873f5", "#eb3096", "#f3222d", "#f68c27", "#f9c53d", "#52c429"};
|
||||
m_numberList = QStringList{"daybreakBlue", "jamPurple", "magenta", "sunRed", "sunsetOrange", "dustGold", "polarGreen"};
|
||||
|
||||
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);
|
||||
for (int i = 0; i < m_colorlist.size(); ++i) {
|
||||
QPushButton *button = new QPushButton;
|
||||
button->setFixedSize(QSize(24, 24));
|
||||
button->setStyleSheet(QString("background-color:%1").arg(m_colorlist.at(i)));
|
||||
if (m_accentcolorlayout) {
|
||||
m_accentcolorlayout->addWidget(button);
|
||||
}
|
||||
m_accentcolorlayout->addWidget(button);
|
||||
box->addButton(button, i);
|
||||
}
|
||||
|
||||
QObject::connect(box, QOverload<int>::of(&QButtonGroup::buttonClicked), [&](int id) {
|
||||
if (id >= 0 && id < m_numberList.size()) {
|
||||
m_color = m_numberList.at(id);
|
||||
qDebug() << m_color;
|
||||
}
|
||||
});
|
||||
|
||||
m_accentcolorlayout->addStretch(1);
|
||||
|
||||
m_coverwidget = new QWidget(m_globalwidget);
|
||||
|
@ -81,6 +95,11 @@ void GlobalThemeWidget::initglobalwidget()
|
|||
buttonlayout->addWidget(iconLabel);
|
||||
buttonlayout->addWidget(textLabel);
|
||||
buttonlayout->addStretch(1);
|
||||
|
||||
connect(m_coverbutton,&QPushButton::clicked,[=](){
|
||||
importCover();
|
||||
});
|
||||
|
||||
m_coverlayout->addWidget(coverlabel);
|
||||
m_coverlayout->addWidget(m_coverbutton);
|
||||
m_coverlayout->addStretch(1);
|
||||
|
@ -109,6 +128,9 @@ void GlobalThemeWidget::initglobalwidget()
|
|||
buttonlayout1->addWidget(iconLabel1);
|
||||
buttonlayout1->addWidget(textLabel1);
|
||||
buttonlayout1->addStretch(1);
|
||||
connect(m_wallpaperbutton,&QPushButton::clicked,[=](){
|
||||
importWallpaper();
|
||||
});
|
||||
|
||||
|
||||
m_wallpaperlayout->addWidget(wallpaperlabel);
|
||||
|
@ -119,4 +141,99 @@ void GlobalThemeWidget::initglobalwidget()
|
|||
m_globallayout->addWidget(m_coverwidget);
|
||||
m_globallayout->addWidget(m_wallpaperwidget);
|
||||
m_globalwidget->setLayout(m_globallayout);
|
||||
|
||||
}
|
||||
|
||||
void GlobalThemeWidget::importCover()
|
||||
{
|
||||
QString filters = tr("Cover files(*.png *.jpg)");
|
||||
m_fd= new QFileDialog(this);
|
||||
m_fd->setFileMode(QFileDialog::Directory);
|
||||
m_fd->setViewMode(QFileDialog::List);
|
||||
m_fd->setNameFilter(filters);
|
||||
m_fd->setFileMode(QFileDialog::ExistingFile);
|
||||
m_fd->setDirectory(HOMEPATH+qgetenv("USER"));
|
||||
m_fd->setWindowTitle(tr("Select Import Wallpapers"));
|
||||
m_fd->setLabelText(QFileDialog::Accept, tr("Select"));
|
||||
m_fd->setLabelText(QFileDialog::Reject, tr("Cancel"));
|
||||
|
||||
connect(m_fd, &QFileDialog::fileSelected, this, [this](const QString &file){
|
||||
|
||||
QFileInfo fileInfo(file);
|
||||
QPixmap pixmap(fileInfo.absoluteFilePath());
|
||||
|
||||
m_coverbutton->setIcon(pixmap);
|
||||
m_coverbutton->setIconSize(m_coverbutton->size());
|
||||
|
||||
QLayout* layout = m_coverbutton->layout();
|
||||
if (layout != nullptr) {
|
||||
QLayoutItem* item;
|
||||
while ((item = layout->takeAt(0)) != nullptr) {
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
delete layout;
|
||||
}
|
||||
});
|
||||
|
||||
openFileDialog();
|
||||
}
|
||||
|
||||
void GlobalThemeWidget::importWallpaper()
|
||||
{
|
||||
QString filters = tr("Wallpaper files(*.png *.jpg)");
|
||||
m_fd= new QFileDialog(this);
|
||||
m_fd->setFileMode(QFileDialog::Directory);
|
||||
m_fd->setViewMode(QFileDialog::List);
|
||||
m_fd->setNameFilter(filters);
|
||||
m_fd->setFileMode(QFileDialog::ExistingFile);
|
||||
m_fd->setDirectory(HOMEPATH+qgetenv("USER"));
|
||||
m_fd->setWindowTitle(tr("Select Import Wallpapers"));
|
||||
m_fd->setLabelText(QFileDialog::Accept, tr("Select"));
|
||||
m_fd->setLabelText(QFileDialog::Reject, tr("Cancel"));
|
||||
|
||||
connect(m_fd, &QFileDialog::fileSelected, this, [this](const QString &file){
|
||||
|
||||
QFileInfo fileInfo(file);
|
||||
QPixmap pixmap(fileInfo.absoluteFilePath());
|
||||
|
||||
m_wallpaperbutton->setIcon(pixmap);
|
||||
m_wallpaperbutton->setIconSize(m_wallpaperbutton->size());
|
||||
|
||||
QLayout* layout = m_wallpaperbutton->layout();
|
||||
if (layout != nullptr) {
|
||||
QLayoutItem* item;
|
||||
while ((item = layout->takeAt(0)) != nullptr) {
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
delete layout;
|
||||
}
|
||||
});
|
||||
|
||||
openFileDialog();
|
||||
}
|
||||
|
||||
void GlobalThemeWidget::openFileDialog()
|
||||
{
|
||||
if (m_fd->exec() != QDialog::Accepted)
|
||||
return;
|
||||
QString path = m_globalpath;
|
||||
|
||||
QDir dir(path);
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(path);
|
||||
}
|
||||
QString sourceFilePath = m_fd->selectedFiles().first();
|
||||
|
||||
if (sourceFilePath.isEmpty())
|
||||
return;
|
||||
|
||||
QFileInfo fileInfo(sourceFilePath);
|
||||
QString destinationFolderPath = m_globalpath; // 替换为目标文件夹的路径
|
||||
|
||||
QString destinationFilePath = destinationFolderPath + "/" + fileInfo.fileName();
|
||||
|
||||
QFile::copy(sourceFilePath, destinationFilePath);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "widgetbase.h"
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
#include <QFileDialog>
|
||||
|
||||
class GlobalThemeWidget : public WidgetBase
|
||||
{
|
||||
|
@ -12,9 +13,14 @@ class GlobalThemeWidget : public WidgetBase
|
|||
public:
|
||||
explicit GlobalThemeWidget(QWidget *parent = nullptr);
|
||||
void init();
|
||||
void initglobalwidget();
|
||||
void initGlobalWidget();
|
||||
void importCover();
|
||||
void importWallpaper();
|
||||
void openFileDialog();
|
||||
signals:
|
||||
private:
|
||||
QString m_globalpath = "";
|
||||
|
||||
QWidget *m_globalwidget;
|
||||
QVBoxLayout *m_globallayout;
|
||||
QWidget *m_accentcolorwidget;
|
||||
|
@ -22,7 +28,8 @@ private:
|
|||
QMap<QString, QPushButton*> m_colorbuttonmap;
|
||||
QMap<QString, QColor> m_colormap;
|
||||
QStringList m_colorlist;
|
||||
|
||||
QString m_color = "";
|
||||
QStringList m_numberList;
|
||||
QWidget *m_coverwidget;
|
||||
QHBoxLayout *m_coverlayout;
|
||||
QPushButton *m_coverbutton;
|
||||
|
@ -30,6 +37,10 @@ private:
|
|||
QWidget *m_wallpaperwidget;
|
||||
QHBoxLayout *m_wallpaperlayout;
|
||||
QPushButton *m_wallpaperbutton;
|
||||
|
||||
QFileDialog *m_fd;
|
||||
QString m_iconpath;
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ void WallpaperthemeWidget::importWallpaper()
|
|||
m_fd->setViewMode(QFileDialog::List);
|
||||
m_fd->setNameFilter(filters);
|
||||
m_fd->setFileMode(QFileDialog::ExistingFile);
|
||||
m_fd->setDirectory(HOMEPATH+qgetenv("USER"));
|
||||
m_fd->setWindowTitle(tr("Select Import Wallpapers"));
|
||||
m_fd->setLabelText(QFileDialog::Accept, tr("Select"));
|
||||
m_fd->setLabelText(QFileDialog::Reject, tr("Cancel"));
|
||||
|
|
Loading…
Reference in New Issue