Adjust logo in NewFileDialog and OptionsDialog to palette #89

This commit is contained in:
Florian Märkl 2017-12-03 15:46:22 +01:00
parent fde759b6ae
commit f7cb84994a
6 changed files with 823 additions and 826 deletions

View File

@ -58,6 +58,8 @@ static QString formatBytecount(const long bytecount)
return stream.readAll();
}
#include "utils/Helpers.h"
NewFileDialog::NewFileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewFileDialog)
@ -67,6 +69,9 @@ 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));
fillRecentFilesList();
bool projectsExist = fillProjectsList();

View File

@ -14,57 +14,37 @@
<string>Open File</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="Logo">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>96</width>
<height>96</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>96</width>
<height>96</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../resources.qrc">:/img/cutter.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>8</number>
</property>
</widget>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item alignment="Qt::AlignHCenter">
<widget class="QSvgWidget" name="logoSvgWidget" native="true">
<property name="minimumSize">
<size>
<width>88</width>
<height>88</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>88</width>
<height>88</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -462,6 +442,14 @@
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QSvgWidget</class>
<extends>QWidget</extends>
<header>qsvgwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../resources.qrc"/>
<include location="../resources.qrc"/>

View File

@ -25,6 +25,9 @@ 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));
ui->analSlider->setValue(defaultAnalLevel);
// Fill the plugins combo
@ -121,7 +124,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
ui->analSlider->setValue(level);
this->setEnabled(0);
ui->logo->setEnabled(true);
// Show Progress Bar
ui->progressBar->setEnabled(1);

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,6 @@
#include <QAbstractItemView>
#include <QAbstractButton>
#include <QDockWidget>
#include <QtGui/QtGui>
static QAbstractItemView::ScrollMode scrollMode()
@ -128,4 +127,33 @@ namespace qhelpers
/ fontMetrics.lineSpacing();
}
QByteArray applyColorToSvg(const QString &filename, QColor color)
{
static 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());
int offset = 0;
while(true)
{
QRegularExpressionMatch match = styleRegExp.match(xml, offset);
if (!match.hasMatch())
{
break;
}
int captureIndex = match.captured(1).isNull() ? 2 : 1;
xml.replace(match.capturedStart(captureIndex), match.capturedLength(captureIndex), replaceStr);
offset = match.capturedStart(captureIndex) + replaceStrLen;
}
return xml.toUtf8();
}
} // end namespace

View File

@ -2,6 +2,7 @@
#define QHELPERS_H
#include <QString>
#include <QColor>
#include <QSizePolicy>
class QPlainTextEdit;
@ -40,6 +41,8 @@ namespace qhelpers
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
QByteArray applyColorToSvg(const QString &filename, QColor color);
}
#endif // HELPERS_H