mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
New main menu in DialogsWidget.
Also "flip_horizontal" and "flip_vertical" modifiers support added. Also moving parts of MainWindow to Window::MainWindow.
This commit is contained in:
@@ -38,8 +38,8 @@ namespace codegen {
|
||||
namespace style {
|
||||
namespace {
|
||||
|
||||
constexpr int kErrorBadIconSize = 861;
|
||||
constexpr int kErrorBadIconFormat = 862;
|
||||
constexpr int kErrorBadIconSize = 861;
|
||||
constexpr int kErrorBadIconFormat = 862;
|
||||
|
||||
// crc32 hash, taken somewhere from the internet
|
||||
|
||||
@@ -1017,10 +1017,10 @@ QByteArray iconMaskValueSize(int width, int height) {
|
||||
QByteArray iconMaskValuePng(QString filepath) {
|
||||
QByteArray result;
|
||||
|
||||
auto inverted = filepath.endsWith("-invert");
|
||||
if (inverted) {
|
||||
filepath.chop(QLatin1String("-invert").size());
|
||||
}
|
||||
auto pathAndModifiers = filepath.split('-');
|
||||
filepath = pathAndModifiers[0];
|
||||
auto modifiers = pathAndModifiers.mid(1);
|
||||
|
||||
QImage png100x(filepath + ".png");
|
||||
QImage png200x(filepath + "@2x.png");
|
||||
png100x.setDevicePixelRatio(1.);
|
||||
@@ -1041,9 +1041,13 @@ QByteArray iconMaskValuePng(QString filepath) {
|
||||
common::logError(kErrorBadIconSize, filepath + ".png") << "bad icons size, 1x: " << png100x.width() << "x" << png100x.height() << ", 2x: " << png200x.width() << "x" << png200x.height();
|
||||
return result;
|
||||
}
|
||||
if (inverted) {
|
||||
png100x.invertPixels();
|
||||
png200x.invertPixels();
|
||||
for (auto modifierName : modifiers) {
|
||||
if (auto modifier = GetModifier(modifierName)) {
|
||||
modifier(png100x, png200x);
|
||||
} else {
|
||||
common::logError(common::kErrorInternal, filepath) << "modifier should be valid here, name: " << modifierName.toStdString();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
QImage png125x = png200x.scaled(structure::data::pxAdjust(png100x.width(), 5), structure::data::pxAdjust(png100x.height(), 5), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
QImage png150x = png200x.scaled(structure::data::pxAdjust(png100x.width(), 6), structure::data::pxAdjust(png100x.height(), 6), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
|
@@ -44,6 +44,7 @@ constexpr int kErrorIdentifierNotFound = 804;
|
||||
constexpr int kErrorAlreadyDefined = 805;
|
||||
constexpr int kErrorBadString = 806;
|
||||
constexpr int kErrorIconDuplicate = 807;
|
||||
constexpr int kErrorBadIconModifier = 808;
|
||||
|
||||
QString findInputFile(const Options &options) {
|
||||
for (const auto &dir : options.includePaths) {
|
||||
@@ -151,6 +152,25 @@ bool validateAlignString(const QString &value) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Modifier GetModifier(const QString &name) {
|
||||
static QMap<QString, Modifier> modifiers;
|
||||
if (modifiers.empty()) {
|
||||
modifiers.insert("invert", [](QImage &png100x, QImage &png200x) {
|
||||
png100x.invertPixels();
|
||||
png200x.invertPixels();
|
||||
});
|
||||
modifiers.insert("flip_horizontal", [](QImage &png100x, QImage &png200x) {
|
||||
png100x = png100x.mirrored(true, false);
|
||||
png200x = png200x.mirrored(true, false);
|
||||
});
|
||||
modifiers.insert("flip_vertical", [](QImage &png100x, QImage &png200x) {
|
||||
png100x = png100x.mirrored(false, true);
|
||||
png200x = png200x.mirrored(false, true);
|
||||
});
|
||||
}
|
||||
return modifiers.value(name);
|
||||
}
|
||||
|
||||
ParsedFile::ParsedFile(const Options &options)
|
||||
: filePath_(findInputFile(options))
|
||||
, file_(filePath_)
|
||||
@@ -821,21 +841,26 @@ structure::data::monoicon ParsedFile::readMonoIconFields() {
|
||||
QString ParsedFile::readMonoIconFilename() {
|
||||
if (auto filename = readValue()) {
|
||||
if (filename.type().tag == structure::TypeTag::String) {
|
||||
auto filepath = QString::fromStdString(filename.String());
|
||||
auto inverted = filepath.endsWith("-invert");
|
||||
if (inverted) {
|
||||
filepath.chop(QLatin1String("-invert").size());
|
||||
}
|
||||
for (const auto &path : options_.includePaths) {
|
||||
QFileInfo fileinfo(path + '/' + filepath + ".png");
|
||||
if (fileinfo.exists()) {
|
||||
return path + '/' + filepath + (inverted ? "-invert" : "");
|
||||
auto fullpath = QString::fromStdString(filename.String());
|
||||
auto pathAndModifiers = fullpath.split('-');
|
||||
auto filepath = pathAndModifiers[0];
|
||||
auto modifiers = pathAndModifiers.mid(1);
|
||||
for (auto modifierName : modifiers) {
|
||||
if (!GetModifier(modifierName)) {
|
||||
logError(kErrorBadIconModifier) << "unknown modifier: " << modifierName.toStdString();
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
for (const auto &path : options_.includePaths) {
|
||||
for (auto &path : options_.includePaths) {
|
||||
QFileInfo fileinfo(path + '/' + filepath + ".png");
|
||||
if (fileinfo.exists()) {
|
||||
return path + '/' + fullpath;
|
||||
}
|
||||
}
|
||||
for (auto &path : options_.includePaths) {
|
||||
QFileInfo fileinfo(path + "/icons/" + filepath + ".png");
|
||||
if (fileinfo.exists()) {
|
||||
return path + "/icons/" + filepath + (inverted ? "-invert" : "");
|
||||
return path + "/icons/" + fullpath;
|
||||
}
|
||||
}
|
||||
logError(common::kErrorFileNotFound) << "could not open icon file '" << filename.String() << "'";
|
||||
|
@@ -22,6 +22,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <QImage>
|
||||
#include "codegen/common/basic_tokenized_file.h"
|
||||
#include "codegen/style/options.h"
|
||||
#include "codegen/style/module.h"
|
||||
@@ -29,6 +31,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
namespace codegen {
|
||||
namespace style {
|
||||
|
||||
using Modifier = std::function<void(QImage &png100x, QImage &png200x)>;
|
||||
Modifier GetModifier(const QString &name);
|
||||
|
||||
// Parses an input file to the internal struct.
|
||||
class ParsedFile {
|
||||
public:
|
||||
@@ -44,7 +49,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool failed() const {
|
||||
return failed_ || file_.failed();
|
||||
}
|
||||
|
Reference in New Issue
Block a user