Skip to content

Commit

Permalink
moodified qss load/copy
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Jul 11, 2024
1 parent a82415b commit 7fdd609
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 55 deletions.
1 change: 0 additions & 1 deletion modmanager.pro
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ win32 {
#native blur
LIBS += -ldwmapi


QMAKE_CXXFLAGS += $$system($$pkgConfigExecutable() --cflags libaria2)
LIBS += $$system($$pkgConfigExecutable() --libs libaria2 | sed 's/\/lib\b/\/bin/' | sed 's/-laria2/-laria2-0/')
equals(QT_MAJOR_VERSION, 5){
Expand Down
3 changes: 1 addition & 2 deletions src/gameversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

#include "curseforge/curseforgeapi.h"
#include "util/tutil.hpp"
#include "util/funcutil.h"
#include "config.hpp"

GameVersion GameVersion::Any = GameVersion("");

QList<GameVersion> GameVersion::mojangVersionList_;
QList<GameVersion> GameVersion::curseforgeVersionList_;

QList<GameVersion> GameVersion::cachedVersionList_{
GameVersion(1, 21),
GameVersion(1, 20, 6),
GameVersion(1, 20, 5),
GameVersion(1, 20, 4),
Expand Down
40 changes: 27 additions & 13 deletions src/qss/stylesheets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,34 @@ QMap<QString, QString> styleSheets()
return styleSheets;
}

QString styleSheetPath(const QString &name)
QString styleSheetPath(QString name)
{
if(!styleSheets().contains(name))
return QString("file:///:/stylesheet/%1.qss").arg("basic");
auto fileName = QDir(styleSheetsPath()).absoluteFilePath(name + ".qss");
if(!QFileInfo::exists(fileName) && builtinStyleSheets().contains(name)){
QFile builtinFile(QString(":/stylesheet/%1.qss").arg(name));
QFile newFile(fileName);
if(builtinFile.open(QIODevice::ReadOnly) && newFile.open(QIODevice::WriteOnly)){
newFile.write("/* This file is auto generated from built-in stylesheet\n"
" * you can create you own qss based on this file.\n"
" */\n\n");
newFile.write(builtinFile.readAll());
}
if(!styleSheets().keys().contains(name))
name = "basic";
if(builtinStyleSheets().keys().contains(name)){
QFile f(QString(":/stylesheet/%1.qss").arg(name));
if(f.open(QIODevice::ReadOnly))
return f.readAll();
}
auto fileName = QDir(styleSheetsPath()).absoluteFilePath(name + ".qss");
return fileName.prepend("file:///");
}

QString copyStyleSheet(const QString &name)
{
QFile oldFile;
if(builtinStyleSheets().keys().contains(name))
oldFile.setFileName(QString(":/stylesheet/%1.qss").arg(name));
else
oldFile.setFileName(QString("file:///:/stylesheet/%1.qss").arg(name));
auto newName = name+"-copy";
auto fileName = QDir(styleSheetsPath()).absoluteFilePath(newName + ".qss");
QFile newFile(fileName);
if(!newFile.exists() && oldFile.open(QIODevice::ReadOnly) && newFile.open(QIODevice::WriteOnly)){
newFile.write("/* This file is auto generated from existed stylesheet\n"
" * you can create you own qss based on this file.\n"
" */\n\n");
newFile.write(oldFile.readAll());
}
return newName;
}
3 changes: 2 additions & 1 deletion src/qss/stylesheets.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ const QString &styleSheetsPath();
const QMap<QString, QString> &builtinStyleSheets();
QMap<QString, QString> styleSheets();

QString styleSheetPath(const QString &name);
QString styleSheetPath(QString name);
QString copyStyleSheet(const QString &name);
#endif // STYLESHEETS_H
1 change: 0 additions & 1 deletion src/ui/framelesswrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ bool FramelessWrapper::nativeEvent(const QByteArray &eventType, void *message, l
switch(msg->message){
case WM_NCCALCSIZE:{
if(msg->wParam == FALSE) return false;

*result = WVR_REDRAW;
return true;
}
Expand Down
13 changes: 7 additions & 6 deletions src/ui/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ModManager::paintEvent(QPaintEvent *event[[maybe_unused]])
if(!widget->isVisible()) continue;
auto rect = widget->rect();
rect.translate(widget->pos());
p.fillRect(rect, QBrush(QColor(255, 50, 255, 210)));
p.fillRect(rect, QBrush(QColor(255, 255, 255, 210)));
}
}
#endif //defined (DE_KDE) || defined (Q_OS_WIN)
Expand All @@ -242,11 +242,12 @@ void ModManager::editLocalPath(int index)
void ModManager::on_actionPreferences_triggered()
{
auto preferences = new Preferences(this);
auto style = config_.getCustomStyle();
connect(preferences, &Preferences::accepted, this, [=]{
if(auto afterStyle = config_.getCustomStyle(); afterStyle != style)
qApp->setStyleSheet(styleSheetPath(afterStyle));
});
// TODO: mass performance
// auto style = config_.getCustomStyle();
// connect(preferences, &Preferences::accepted, this, [=]{
// if(auto afterStyle = config_.getCustomStyle(); afterStyle != style)
// qApp->setStyleSheet(styleSheetPath(afterStyle));
// });
connect(preferences, &Preferences::accepted, this, &ModManager::updateUi, Qt::UniqueConnection);
connect(preferences, &Preferences::accepted, this, &ModManager::setProxy, Qt::UniqueConnection);
connect(preferences, &Preferences::accepted, QAria2::qaria2(), &QAria2::updateOptions, Qt::UniqueConnection);
Expand Down
11 changes: 9 additions & 2 deletions src/ui/preferences.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "preferences.h"
#include "ui_preferences.h"

#include <QDesktopServices>
#include <QFileDialog>

#include "config.hpp"
Expand All @@ -19,8 +20,7 @@ Preferences::Preferences(QWidget *parent) :
#endif
auto s = styleSheets();
for(auto it = s.cbegin(); it != s.cend(); it++){
ui->customStyle->addItem(it.value());
ui->customStyle->setItemData(ui->customStyle->count() - 1, it.key());
ui->customStyle->addItem(it.value(), it.key());
}

ui->language->addItem(tr("Follow System"));
Expand Down Expand Up @@ -186,6 +186,13 @@ void Preferences::on_proxyType_currentIndexChanged(int index)
ui->proxyPassword->setEnabled(!noProxy);
}

void Preferences::on_copyQSSButton_clicked()
{
auto name = copyStyleSheet(ui->customStyle->currentData().toString());
ui->customStyle->insertItem(ui->customStyle->currentIndex() + 1, name, name);
ui->customStyle->setCurrentText(name);
QDesktopServices::openUrl(QUrl(styleSheetPath(name)));
}

void Preferences::on_useFramelessWindow_toggled(bool checked[[maybe_unused]])
{
Expand Down
2 changes: 2 additions & 0 deletions src/ui/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private slots:

void on_proxyType_currentIndexChanged(int index);

void on_copyQSSButton_clicked();

private:
Ui::Preferences *ui;
};
Expand Down
72 changes: 43 additions & 29 deletions src/ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>673</height>
<width>627</width>
<height>772</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -69,8 +69,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>589</height>
<width>599</width>
<height>683</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -209,26 +209,13 @@
</item>
<item>
<layout class="QFormLayout" name="formLayout_4">
<item row="1" column="1">
<widget class="QComboBox" name="customStyle"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>UI style:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_24">
<item row="0" column="0">
<widget class="QLabel" name="label_25">
<property name="text">
<string>Language:</string>
<string>Mod Manager update:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="language"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="autoCheckModManagerUpdate">
<item>
Expand All @@ -248,13 +235,40 @@
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_25">
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Mod Manager update:</string>
<string>UI style:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="customStyle"/>
</item>
<item>
<widget class="QToolButton" name="copyQSSButton">
<property name="text">
<string>Copy</string>
</property>
<property name="icon">
<iconset theme="edit-copy"/>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="language"/>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -309,8 +323,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<height>580</height>
<width>599</width>
<height>683</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -516,8 +530,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>585</height>
<width>599</width>
<height>683</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -834,8 +848,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<height>580</height>
<width>599</width>
<height>683</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_11">
Expand Down

0 comments on commit 7fdd609

Please sign in to comment.