Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jagannatharjun committed Oct 19, 2020
1 parent 17bfe54 commit a9162ab
Show file tree
Hide file tree
Showing 28 changed files with 422 additions and 181 deletions.
3 changes: 2 additions & 1 deletion Builds/build-breeze-dark.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
set SCRIPT_DIR=BreezeStyleSheets
make-resource.py -base-dir %SCRIPT_DIR%\ -find-files -output breeze-dark -style dark.qss
set ICONS_DIR=icons/nowshed
make-resource.py -base-dir %SCRIPT_DIR%\ -find-files -output breeze-dark -config dark-config.json -icons-dir %ICONS_DIR% -style dark.qss
8 changes: 7 additions & 1 deletion Builds/build-mumble-dark.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

set SCRIPT_DIR=mumble-theme
set PATH=%PATH%;C:\Users\Prince\Downloads\Compressed\qtsass_0.2.2_win64;
pushd %SCRIPT_DIR%\source
qtsass -o ../Dark.qss Dark.scss
popd
make-resource.py -base-dir %SCRIPT_DIR%\ -find-files -config dark-config.json -output mumble-dark -style dark.qss
rd /q /s mumble-icons
mkdir mumble-icons
fill-icons.py nowshed #e1bee7 mumble-icons
REM for /r icons/nowshed/ %%i in (*.svg) do powershell -Command "(gc %%~dpnxi) -replace '#4285f4', '#6a1b9a' | Out-File -encoding ASCII mumble-icons/%%~nxi"
make-resource.py -base-dir %SCRIPT_DIR%\ -find-files -config dark-config.json -icons-dir mumble-icons -output mumble-dark-nowshed-recolored -style dark.qss
rd /q /s mumble-icons
3 changes: 2 additions & 1 deletion Builds/build-qdarkstylesheet.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
set SCRIPT_DIR=QDarkStyleSheet\qdarkstyle
make-resource.py -base-dir %SCRIPT_DIR%\ -dir-prefix qss_icons -output darkstylesheet -style style.qss rc\* svg\*
set ICONS_DIR=icons/nowshed
make-resource.py -base-dir %SCRIPT_DIR%\ -config dark-config.json -dir-prefix qss_icons -output darkstylesheet -icons-dir %ICONS_DIR% -style style.qss rc\* svg\*
28 changes: 28 additions & 0 deletions Builds/fill-icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import os

icons_map = { 'originals': { 'color': '#375273', 'dir': 'icons/originals/' }, 'nowshed': { 'color': '#4285f4', 'dir': 'icons/nowshed/' } }

def change(icon_set, new_color, output_dir):
originals_dir = icons_map[icon_set]['dir']
original_color = icons_map[icon_set]['color']

if not os.path.exists(output_dir):
os.mkdir(output_dir)
for subdir, dirs, files in os.walk(originals_dir):
for file in files:
svg_file = os.path.join(subdir, file)
if not svg_file.endswith(".svg"):
continue
print(svg_file)
new_svg_file = os.path.join(output_dir, file)
content = open(svg_file, 'rb').read()
content = content.replace(original_color.encode('utf'), new_color.encode('utf'))
open(new_svg_file, 'wb').write(content)


if __name__ == "__main__":
change(sys.argv[1], sys.argv[2], sys.argv[3])



9 changes: 6 additions & 3 deletions Builds/icons-explorer/icons-explorer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ CONFIG += c++17
SOURCES += \
iconsview.cpp \
main.cpp \
mainwindow.cpp
mainwindow.cpp \
qbittorrentpreview.cpp

HEADERS += \
iconsview.hpp \
mainwindow.hpp
mainwindow.hpp \
qbittorrentpreview.hpp

FORMS += \
mainwindow.ui
mainwindow.ui \
qbittorrentpreview.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
Expand Down
65 changes: 40 additions & 25 deletions Builds/icons-explorer/iconsview.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "iconsview.hpp"

#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QListWidget>
#include <QRunnable>
#include <QThreadPool>

#include <filesystem>
Expand Down Expand Up @@ -43,36 +44,35 @@ void save(const QString &filePath, const QByteArray data) {
f.write(data);
}

void Worker::doWork(QVector<ColorPair> colorPairs, QString tempPath,
void Worker::doWork(QVector<ColorPair> colorPairs, QString destDir,
QString dir) {
if (!dir.isEmpty()) {
qDebug() << "worker temp path" << tempPath;
qDebug() << "worker temp path" << destDir;
std::error_code ec;
std::filesystem::copy(dir.toStdWString(), tempPath.toStdWString(), ec);
std::filesystem::copy(dir.toStdWString(), destDir.toStdWString(), ec);
if (ec) {
qDebug() << "error while copying files" << ec.message().c_str();
}
}

for (const auto &file :
std::filesystem::recursive_directory_iterator(tempPath.toStdWString())) {
std::filesystem::recursive_directory_iterator(destDir.toStdWString())) {
const auto path = file.path();
if (path.extension() != ".svg" && path.extension() != ".png")
continue;

qDebug("hello");
auto content = readAll(path.string().c_str());
for (const auto &cp : colorPairs) {
qDebug() << cp.oldColor.name().toUtf8() << cp.newColor.name().toUtf8();
content.replace(cp.oldColor.name().toUtf8(), cp.newColor.name().toUtf8());
if (path.extension() == ".svg") {
auto content = readAll(path.string().c_str());
for (const auto &cp : colorPairs) {
qDebug() << cp.oldColor.name().toUtf8() << cp.newColor.name().toUtf8();
content.replace(cp.oldColor.name().toUtf8(),
cp.newColor.name().toUtf8());
}
save(path.string().c_str(), content);
}
save(path.string().c_str(), content);

QListWidgetItem *item = new QListWidgetItem();
item->setIcon(
path.extension() == ".svg"
? QIcon(path.string().c_str())
: QIcon(QPixmap::fromImage(QImage(path.string().c_str()))));
item->setIcon(QIcon(QPixmap::fromImage(QImage(path.string().c_str()))));
item->setText(path.filename().string().c_str());
item->setToolTip(path.string().c_str());
emit newItem(item);
Expand Down Expand Up @@ -107,32 +107,47 @@ IconsView::IconsView(QWidget *parent) : QListWidget(parent) {
IconsView::~IconsView() {
m_workerThread.quit();
m_workerThread.wait();

if (std::filesystem::exists(m_tempPath.toStdWString()))
std::filesystem::remove_all(m_tempPath.toStdWString());
}

QVector<IconsSet> IconsView::availableIconsSet() const {
return {
IconsSet{
R"(C:\Users\Prince\Desktop\Projects\qbt-theme\Builds\icons\nowshed)",
{QColor("#f25022"), QColor("#4285f4"), QColor("#6cc24a")}},
IconsSet{
R"(C:\Users\Prince\Desktop\Projects\qbt-theme\Builds\icons\originals)",
{QColor("#427337"), QColor("#375273")}}};
}

QString IconsView::iconsDir() const { return m_iconsDir; }

void IconsView::setIconsDir(const QString &iconsDir) {
void IconsView::setIconsDir(const QString &newIconsDir) {
if (newIconsDir == iconsDir())
return;

assert(!m_loading);
m_iconsDir = newIconsDir;

m_iconsDir = iconsDir;
if (std::filesystem::exists(m_tempPath.toStdWString()))
std::filesystem::remove_all(m_tempPath.toStdWString());
m_tempPath = getTempDir().string().c_str();
std::filesystem::create_directory(m_tempPath.toStdWString());
loadIcons();
}

void IconsView::loadIcons() {
m_loading = true;
clear();

if (std::filesystem::exists(m_tempPath.toStdWString()))
std::filesystem::remove_all(m_tempPath.toStdWString());
m_tempPath = getTempDir().string().c_str();
std::filesystem::create_directory(m_tempPath.toStdWString());

emit loadingChanged();
emit startLoading(m_colorPairs, m_tempPath, m_iconsDir);
}

bool IconsView::loading() const
{
return m_loading;
}
bool IconsView::loading() const { return m_loading; }

QVector<ColorPair> IconsView::colorPairs() const { return m_colorPairs; }

Expand Down
9 changes: 8 additions & 1 deletion Builds/icons-explorer/iconsview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ struct ColorPair {
QColor oldColor, newColor;
};

struct IconsSet {
QString dir;
QVector<QColor> colors;
};

class Worker : public QObject {
Q_OBJECT
public:
using QObject::QObject;

public slots:
void doWork(QVector<ColorPair> colorPairs, QString tempPath, QString dir);
void doWork(QVector<ColorPair> colorPairs, QString destDir, QString dir);

signals:
void newItem(QListWidgetItem *item);
Expand All @@ -26,6 +31,8 @@ class IconsView : public QListWidget {
IconsView(QWidget *parent = nullptr);
~IconsView();

QVector<IconsSet> availableIconsSet() const;

QString iconsDir() const;
void setIconsDir(const QString &iconsDir);

Expand Down
98 changes: 67 additions & 31 deletions Builds/icons-explorer/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ QByteArray readAll(const QString &filePath);

class ColorEdit : public QLineEdit {
public:
ColorEdit(QWidget *parent = nullptr)
ColorEdit(QColor initialColor = {}, bool readOnly = false,
QWidget *parent = nullptr)
: QLineEdit(parent), m_colorPixmap(QSize(18, 18)) {
setTextMargins(20, 1, 1, 1);
connect(this, &QLineEdit::textChanged, this, [this](const QString text) {
Expand All @@ -22,15 +23,20 @@ class ColorEdit : public QLineEdit {
setPalette(QPalette());
m_colorPixmap.fill(color);
});

QAction *colorDiag =
addAction(QIcon("://color-dropper.png"), QLineEdit::TrailingPosition);
connect(colorDiag, &QAction::triggered, this, [this](bool) {
QColor newColor =
QColorDialog::getColor(QColor(text()), this, "Choose Color");
if (newColor.isValid())
setText(newColor.name());
});
if (initialColor.isValid())
setText(initialColor.name());

if (!readOnly) {
QAction *colorDiag =
addAction(QIcon("://color-dropper.png"), QLineEdit::TrailingPosition);
connect(colorDiag, &QAction::triggered, this, [this](bool) {
QColor newColor =
QColorDialog::getColor(QColor(text()), this, "Choose Color");
if (newColor.isValid())
setText(newColor.name());
});
setReadOnly(readOnly);
}
}

QColor color() { return QColor(text()); }
Expand Down Expand Up @@ -59,44 +65,74 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
on_iconsView_loadingChanged();
ui->iconsDirEdit->setText(ui->iconsView->iconsDir());
for (const auto &iconSet : ui->iconsView->availableIconsSet()) {
ui->iconsDirCombo->addItem(iconSet.dir,
QVariant::fromValue(iconSet.colors));
}

auto styleSheetBrowseIcon = ui->stylesheetEdit->addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), QLineEdit::TrailingPosition);
connect(styleSheetBrowseIcon, &QAction::triggered, this, [this]() {
const QString styleSheet = QFileDialog::getOpenFileName(this, "Open StyleSheet", {}, "*.qss");
if (styleSheet.isEmpty())
return;
QFile f(styleSheet);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
return;
qApp->setStyleSheet(f.readAll());
});
}

MainWindow::~MainWindow() { delete ui; }

void MainWindow::on_new_row_clicked() {
const int row = ui->colorTable->rowCount();
ui->colorTable->setRowCount(row + 1);
ui->colorTable->setCellWidget(row, 0, new ColorEdit(this));
ui->colorTable->setCellWidget(row, 1, new ColorEdit(this));
}

void MainWindow::on_applyColors_clicked() {
QVector<ColorPair> colorPairs;
for (int i = 0; i < ui->colorTable->rowCount(); i++) {
colorPairs.push_back(
{dynamic_cast<ColorEdit *>(ui->colorTable->cellWidget(i, 0))->color(),
dynamic_cast<ColorEdit *>(ui->colorTable->cellWidget(i, 1))->color()});
const auto oldColor =
dynamic_cast<ColorEdit *>(ui->colorTable->cellWidget(i, 1))->color();
const auto newColor =
dynamic_cast<ColorEdit *>(ui->colorTable->cellWidget(i, 0))->color();
if (!oldColor.isValid() || !newColor.isValid())
continue;
colorPairs.push_back({newColor, oldColor});
}
ui->iconsView->setColorPairs(colorPairs);
}

void MainWindow::on_iconsView_currentItemChanged(QListWidgetItem *,
QListWidgetItem *) {
ui->contentView->setText(readAll(ui->iconsView->currentFilePath()));
}

void MainWindow::on_pushButton_clicked() {
const QString dir = QFileDialog::getExistingDirectory(
this, "Browse Icons", ui->iconsView->iconsDir());
if (!dir.isEmpty()) {
ui->iconsView->setIconsDir(dir);
ui->iconsDirEdit->setText(ui->iconsView->iconsDir());
}
setPreview();
}

void MainWindow::on_iconsView_loadingChanged() {
bool loading = ui->iconsView->loading();
ui->folderGroup->setEnabled(!loading);
ui->colorGroup->setEnabled(!loading);
}

void MainWindow::on_showPicture_toggled(bool checked) { setPreview(); }

void MainWindow::setPreview() {
const QFileInfo f = ui->iconsView->currentFilePath();
if (ui->showPicture->isChecked()) {
ui->contentView->setText(
QString("<img src=\"%1\" alt='failure' width=128 height=128></img>")
.arg(QUrl::fromLocalFile(ui->iconsView->currentFilePath())
.toString()));
} else {
ui->contentView->setText(readAll(ui->iconsView->currentFilePath()));
}
}

void MainWindow::on_iconsDirCombo_currentIndexChanged(int index) {
ui->iconsView->setIconsDir(ui->iconsDirCombo->currentText());
const QVector<QColor> colors =
ui->iconsDirCombo->currentData().value<QVector<QColor>>();

ui->colorTable->setRowCount(0);
for (const auto &color : colors) {
const int row = ui->colorTable->rowCount();
ui->colorTable->setRowCount(row + 1);
ui->colorTable->setCellWidget(row, 0, new ColorEdit(color, true, this));
ui->colorTable->setCellWidget(row, 1, new ColorEdit(QColor{}, false, this));
}
}
10 changes: 6 additions & 4 deletions Builds/icons-explorer/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ class MainWindow : public QMainWindow
~MainWindow();

private slots:
void on_new_row_clicked();

void on_applyColors_clicked();

void on_iconsView_currentItemChanged(QListWidgetItem *, QListWidgetItem *);

void on_pushButton_clicked();

void on_iconsView_loadingChanged();

void on_showPicture_toggled(bool checked);

void on_iconsDirCombo_currentIndexChanged(int index);

private:
Ui::MainWindow *ui;

void setPreview();
};
Loading

0 comments on commit a9162ab

Please sign in to comment.