diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a7d85307..3e0f32f8 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -114,6 +114,9 @@ MainWindow::~MainWindow() { } +#include +#include "utils/SvgIconEngine.h" + void MainWindow::initUI() { ui->setupUi(this); @@ -134,10 +137,11 @@ void MainWindow::initUI() spacer4->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); spacer4->setMinimumSize(10, 10); ui->mainToolBar->insertWidget(ui->actionForward, spacer4); + ui->actionForward->setIcon(QIcon(new SvgIconEngine(QString(":/img/icons/arrow_right.svg"), palette().buttonText().color()))); // Popup menu on theme toolbar button QToolButton *backButton = new QToolButton(this); - backButton->setIcon(QIcon(":/img/icons/arrow_left.svg")); + backButton->setIcon(QIcon(new SvgIconEngine(QString(":/img/icons/arrow_left.svg"), palette().buttonText().color()))); //backButton->setPopupMode(QToolButton::DelayedPopup); ui->mainToolBar->insertWidget(ui->actionForward, backButton); connect(backButton, SIGNAL(clicked()), this, SLOT(backButton_clicked())); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index a3a8c79c..be272e53 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -277,20 +277,19 @@ border-top: 0px; QToolButton { /* all types of tool button */ - border: 0px solid rgb(255, 255, 255); - border-radius: 6px; margin-bottom: 1px; margin-top: 1px; margin-left: 2px; margin-right: 2px; - background-color: rgb(255, 255, 255); padding: 2px; padding-left: 7px; padding-right: 7px; - color: rgb(255, 0, 0); + background-color: palette(light); + border-radius: 6px; } -QToolButton .svg-icon path { - fill: #ff0000; + +QToolButton:pressed { + background-color: palette(dark); } diff --git a/src/cutter.pro b/src/cutter.pro index 1407b8cb..083ece24 100644 --- a/src/cutter.pro +++ b/src/cutter.pro @@ -78,7 +78,8 @@ SOURCES += \ utils/Configuration.cpp \ utils/Colors.cpp \ dialogs/SaveProjectDialog.cpp \ - utils/TempConfig.cpp + utils/TempConfig.cpp \ + utils/SvgIconEngine.cpp HEADERS += \ cutter.h \ @@ -127,7 +128,8 @@ HEADERS += \ utils/Configuration.h \ utils/Colors.h \ dialogs/SaveProjectDialog.h \ - utils/TempConfig.h + utils/TempConfig.h \ + utils/SvgIconEngine.h FORMS += \ dialogs/AboutDialog.ui \ diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index cc72af30..81c36a44 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -58,8 +58,6 @@ static QString formatBytecount(const long bytecount) return stream.readAll(); } -#include "utils/Helpers.h" - NewFileDialog::NewFileDialog(QWidget *parent) : QDialog(parent), ui(new Ui::NewFileDialog) @@ -69,8 +67,8 @@ NewFileDialog::NewFileDialog(QWidget *parent) : ui->recentsListWidget->addAction(ui->actionRemove_item); ui->recentsListWidget->addAction(ui->actionClear_all); - QColor logoColor = (palette().window().color().value() < 127) ? QColor(255, 255, 255) : QColor(0, 0, 0); - ui->logoSvgWidget->load(qhelpers::applyColorToSvg(":/img/cutter.svg", logoColor)); + QString logoFile = (palette().window().color().value() < 127) ? ":/img/cutter_white.svg" : ":/img/cutter.svg"; + ui->logoSvgWidget->load(logoFile); fillRecentFilesList(); bool projectsExist = fillProjectsList(); diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 2fd908ba..1fbd5842 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -25,8 +25,8 @@ OptionsDialog::OptionsDialog(MainWindow *main): ui->progressBar->setVisible(0); ui->statusLabel->setVisible(0); - QColor logoColor = (palette().window().color().value() < 127) ? QColor(255, 255, 255) : QColor(0, 0, 0); - ui->logoSvgWidget->load(qhelpers::applyColorToSvg(":/img/cutter.svg", logoColor)); + QString logoFile = (palette().window().color().value() < 127) ? ":/img/cutter_white.svg" : ":/img/cutter.svg"; + ui->logoSvgWidget->load(logoFile); ui->analSlider->setValue(defaultAnalLevel); diff --git a/src/utils/Helpers.cpp b/src/utils/Helpers.cpp index b6aa066b..9c67da79 100644 --- a/src/utils/Helpers.cpp +++ b/src/utils/Helpers.cpp @@ -127,17 +127,14 @@ namespace qhelpers / fontMetrics.lineSpacing(); } - - QByteArray applyColorToSvg(const QString &filename, QColor color) + QByteArray applyColorToSvg(const QByteArray &data, QColor color) { - static QRegularExpression styleRegExp("(?:style=\".*fill:(.*?);.*?\")|(?:fill=\"(.*?)\")"); + static const QRegularExpression styleRegExp("(?:style=\".*fill:(.*?);.*?\")|(?:fill=\"(.*?)\")"); QString replaceStr = QString("#%1").arg(color.rgb() & 0xffffff, 6, 16, QLatin1Char('0')); int replaceStrLen = replaceStr.length(); - QFile file(filename); - file.open(QIODevice::ReadOnly); - QString xml = QString::fromUtf8(file.readAll()); + QString xml = QString::fromUtf8(data); int offset = 0; while(true) @@ -156,4 +153,12 @@ namespace qhelpers return xml.toUtf8(); } + QByteArray applyColorToSvg(const QString &filename, QColor color) + { + QFile file(filename); + file.open(QIODevice::ReadOnly); + + return applyColorToSvg(file.readAll(), color); + } + } // end namespace diff --git a/src/utils/Helpers.h b/src/utils/Helpers.h index 285adc4d..b7bf8313 100644 --- a/src/utils/Helpers.h +++ b/src/utils/Helpers.h @@ -42,6 +42,7 @@ namespace qhelpers int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit); + QByteArray applyColorToSvg(const QByteArray &data, QColor color); QByteArray applyColorToSvg(const QString &filename, QColor color); } diff --git a/src/utils/SvgIconEngine.cpp b/src/utils/SvgIconEngine.cpp new file mode 100644 index 00000000..96c600a7 --- /dev/null +++ b/src/utils/SvgIconEngine.cpp @@ -0,0 +1,54 @@ + +#include "SvgIconEngine.h" + +#include +#include +#include + +#include "Helpers.h" + +SvgIconEngine::SvgIconEngine(const QString &filename) +{ + QFile file(filename); + file.open(QFile::ReadOnly); + this->svgData = file.readAll(); +} + +SvgIconEngine::SvgIconEngine(const QByteArray &svgData) +{ + this->svgData = svgData; +} + +SvgIconEngine::SvgIconEngine(const QString &filename, QColor tintColor) : SvgIconEngine(filename) +{ + this->svgData = qhelpers::applyColorToSvg(svgData, tintColor); +} + +SvgIconEngine::SvgIconEngine(const QByteArray &svgData, QColor tintColor) +{ + this->svgData = qhelpers::applyColorToSvg(svgData, tintColor); +} + +void SvgIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) +{ + QSvgRenderer renderer(svgData); + renderer.render(painter, rect); +} + +QIconEngine *SvgIconEngine::clone() const +{ + return new SvgIconEngine(*this); +} + +QPixmap SvgIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) +{ + QImage img(size, QImage::Format_ARGB32); + img.fill(qRgba(0, 0, 0, 0)); + QPixmap pix = QPixmap::fromImage(img, Qt::NoFormatConversion); + { + QPainter painter(&pix); + QRect r(QPoint(0.0, 0.0), size); + this->paint(&painter, r, mode, state); + } + return pix; +} diff --git a/src/utils/SvgIconEngine.h b/src/utils/SvgIconEngine.h new file mode 100644 index 00000000..a6471217 --- /dev/null +++ b/src/utils/SvgIconEngine.h @@ -0,0 +1,25 @@ + +#ifndef SVGICONENGINE_H +#define SVGICONENGINE_H + +#include + +class SvgIconEngine: public QIconEngine +{ +private: + QByteArray svgData; + +public: + explicit SvgIconEngine(const QString &filename); + explicit SvgIconEngine(const QByteArray &svgData); + + SvgIconEngine(const QString &filename, QColor tintColor); + SvgIconEngine(const QByteArray &svgData, QColor tintColor); + + void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; + QIconEngine *clone() const override; + QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; + +}; + +#endif //SVGICONENGINE_H diff --git a/src/widgets/ConsoleWidget.cpp b/src/widgets/ConsoleWidget.cpp index b8a23233..0713966d 100644 --- a/src/widgets/ConsoleWidget.cpp +++ b/src/widgets/ConsoleWidget.cpp @@ -8,6 +8,7 @@ #include "ConsoleWidget.h" #include "ui_ConsoleWidget.h" #include "utils/Helpers.h" +#include "utils/SvgIconEngine.h" // TODO: Find a way to get to this without copying it here @@ -89,8 +90,6 @@ static bool isForbidden(const QString &input) return false; } - - ConsoleWidget::ConsoleWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ConsoleWidget), @@ -103,6 +102,8 @@ ConsoleWidget::ConsoleWidget(QWidget *parent) : // Adjust console lineedit ui->inputLineEdit->setTextMargins(10, 0, 0, 0); + ui->execButton->setIcon(QIcon(new SvgIconEngine(QString(":/img/icons/arrow_right.svg"), palette().buttonText().color()))); + setupFont(); // Adjust text margins of consoleOutputTextEdit diff --git a/src/widgets/ConsoleWidget.ui b/src/widgets/ConsoleWidget.ui index 67d05e85..2a46aa25 100644 --- a/src/widgets/ConsoleWidget.ui +++ b/src/widgets/ConsoleWidget.ui @@ -105,23 +105,28 @@ Execute command - /* -border: none; -padding: 2px; -*/ - + QToolButton { /* all types of tool button */ - border: 0px solid rgb(255, 255, 255); - border-radius: 6px; - border-top: 2px solid rgb(255, 255, 255); - border-bottom: 2px solid rgb(255, 255, 255); - border-left: 2px solid rgb(255, 255, 255); - border-right: 2px solid rgb(255, 255, 255); margin-bottom: 1px; margin-top: 1px; padding-left: 8px; padding-right: 5px; - background-color: rgb(255, 255, 255); + padding-top: 1px; + padding-bottom: 1px; + background-color: palette(light); + border-radius: 6px; + border-top: 2px solid palette(light); + border-bottom: 2px solid palette(light); + border-left: 2px solid palette(light); + border-right: 2px solid palette(light); +} + +QToolButton:pressed { + background-color: palette(dark); + border-top: 2px solid palette(dark); + border-bottom: 2px solid palette(dark); + border-left: 2px solid palette(dark); + border-right: 2px solid palette(dark); }