mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 12:26:11 +00:00
Adjust buttons to theme (Fix #89)
This commit is contained in:
parent
f7cb84994a
commit
2417963329
@ -114,6 +114,9 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#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()));
|
||||
|
@ -277,20 +277,19 @@ border-top: 0px;
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">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);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="movable">
|
||||
|
@ -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 \
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -42,6 +42,7 @@ namespace qhelpers
|
||||
|
||||
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
|
||||
|
||||
QByteArray applyColorToSvg(const QByteArray &data, QColor color);
|
||||
QByteArray applyColorToSvg(const QString &filename, QColor color);
|
||||
}
|
||||
|
||||
|
54
src/utils/SvgIconEngine.cpp
Normal file
54
src/utils/SvgIconEngine.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
#include "SvgIconEngine.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QFile>
|
||||
|
||||
#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;
|
||||
}
|
25
src/utils/SvgIconEngine.h
Normal file
25
src/utils/SvgIconEngine.h
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
#ifndef SVGICONENGINE_H
|
||||
#define SVGICONENGINE_H
|
||||
|
||||
#include <QIconEngine>
|
||||
|
||||
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
|
@ -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
|
||||
|
@ -105,23 +105,28 @@
|
||||
<string>Execute command</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">/*
|
||||
border: none;
|
||||
padding: 2px;
|
||||
*/
|
||||
|
||||
<string notr="true">
|
||||
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);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
Loading…
Reference in New Issue
Block a user