Skip to content

Commit

Permalink
Add a tag type, tag2filters map, and a tag selector menu
Browse files Browse the repository at this point in the history
  • Loading branch information
c-koi committed Sep 16, 2021
1 parent 1c181e0 commit 7b70143
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -332,6 +332,7 @@ set (gmic_qt_SRCS
src/FilterSelector/FiltersView/FiltersView.h
src/FilterSelector/FiltersView/TreeView.h
src/FilterSelector/FiltersVisibilityMap.h
src/FilterSelector/FilterTagMap.h
src/CroppedImageListProxy.h
src/CroppedActiveLayerProxy.h
src/FilterSyncRunner.h
Expand All @@ -354,6 +355,7 @@ set (gmic_qt_SRCS
src/MainWindow.h
src/ParametersCache.h
src/TimeLogger.h
src/Tags.h
src/Updater.h
src/Utils.h
src/Misc.h
Expand All @@ -371,6 +373,7 @@ set (gmic_qt_SRCS
src/Widgets/SearchFieldWidget.h
src/Widgets/LanguageSelectionWidget.h
src/Widgets/ProgressInfoWindow.h
src/Widgets/VisibleTagSelector.h
src/ZoomConstraint.h

${GMIC_PATH}/gmic.h
Expand Down Expand Up @@ -406,6 +409,7 @@ set (gmic_qt_SRCS
src/FilterSelector/FiltersView/FiltersView.cpp
src/FilterSelector/FiltersView/TreeView.cpp
src/FilterSelector/FiltersVisibilityMap.cpp
src/FilterSelector/FilterTagMap.cpp
src/CroppedImageListProxy.cpp
src/CroppedActiveLayerProxy.cpp
src/FilterSyncRunner.cpp
Expand All @@ -427,6 +431,7 @@ set (gmic_qt_SRCS
src/MainWindow.cpp
src/ParametersCache.cpp
src/TimeLogger.cpp
src/Tags.cpp
src/Updater.cpp
src/Utils.cpp
src/Misc.cpp
Expand All @@ -444,6 +449,7 @@ set (gmic_qt_SRCS
src/Widgets/SearchFieldWidget.cpp
src/Widgets/LanguageSelectionWidget.cpp
src/Widgets/ProgressInfoWindow.cpp
src/Widgets/VisibleTagSelector.cpp
)

set (gmic_qt_FORMS
Expand Down
6 changes: 6 additions & 0 deletions gmic_qt.pro
Expand Up @@ -282,6 +282,7 @@ HEADERS += \
src/FilterSelector/FiltersView/FiltersView.h \
src/FilterSelector/FiltersView/TreeView.h \
src/FilterSelector/FiltersVisibilityMap.h \
src/FilterSelector/FilterTagMap.h \
src/CroppedImageListProxy.h \
src/CroppedActiveLayerProxy.h \
src/FilterSyncRunner.h \
Expand All @@ -302,9 +303,11 @@ HEADERS += \
src/MainWindow.h \
src/Misc.h \
src/ParametersCache.h \
src/Tags.h \
src/TimeLogger.h \
src/Updater.h \
src/Utils.h \
src/Widgets/VisibleTagSelector.h \
src/ZoomConstraint.h \
src/FilterSelector/FiltersView/FilterTreeFolder.h \
src/FilterSelector/FiltersView/FilterTreeItem.h \
Expand Down Expand Up @@ -357,6 +360,7 @@ SOURCES += \
src/FilterSelector/FiltersView/FiltersView.cpp \
src/FilterSelector/FiltersView/TreeView.cpp \
src/FilterSelector/FiltersVisibilityMap.cpp \
src/FilterSelector/FilterTagMap.cpp \
src/CroppedImageListProxy.cpp \
src/CroppedActiveLayerProxy.cpp \
src/FilterSyncRunner.cpp \
Expand All @@ -376,6 +380,7 @@ SOURCES += \
src/Logger.cpp \
src/MainWindow.cpp \
src/ParametersCache.cpp \
src/Tags.cpp \
src/TimeLogger.cpp \
src/Updater.cpp \
src/Utils.cpp \
Expand All @@ -390,6 +395,7 @@ SOURCES += \
src/Widgets/PreviewWidget.cpp \
src/Widgets/ProgressInfoWidget.cpp \
src/Widgets/InOutPanel.cpp \
src/Widgets/VisibleTagSelector.cpp \
src/Widgets/ZoomLevelSelector.cpp \
src/Widgets/SearchFieldWidget.cpp \
src/Widgets/LanguageSelectionWidget.cpp \
Expand Down
2 changes: 2 additions & 0 deletions gmic_qt.qrc
Expand Up @@ -51,5 +51,7 @@
<file>resources/gmic_hat.png</file>
<file>resources/logos.png</file>
<file>resources/transparency.png</file>
<file>icons/color-wheel.png</file>
<file>icons/dark/color-wheel.png</file>
</qresource>
</RCC>
Binary file added icons/color-wheel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions icons/color-wheel.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/dark/color-wheel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 151 additions & 0 deletions src/FilterSelector/FilterTagMap.cpp
@@ -0,0 +1,151 @@
/** -*- mode: c++ ; c-basic-offset: 2 -*-
*
* @file FilterTagMap.h
*
* Copyright 2017 Sebastien Fourey
*
* This file is part of G'MIC-Qt, a generic plug-in for raster graphics
* editors, offering hundreds of filters thanks to the underlying G'MIC
* image processing framework.
*
* gmic_qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gmic_qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gmic_qt. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "FilterTagMap.h"
#include <QBuffer>
#include <QByteArray>
#include <QDataStream>
#include <QDebug>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QSet>
#include "Common.h"
#include "Globals.h"
#include "GmicQt.h"
#include "Logger.h"
#include "Utils.h"

namespace GmicQt
{

QSet<QString> FiltersTagMap::_colorToHashes[static_cast<unsigned int>(TagColor::Count)];

TagColor FiltersTagMap::filterTag(const QString & hash)
{
return TagColor::None;
}

void FiltersTagMap::setColor(const QString & hash, TagColor color)
{
for (QSet<QString> & hashSet : _colorToHashes) {
if (hashSet.remove(hash) && color == TagColor::None) {
return;
}
}
if (color != TagColor::None) {
_colorToHashes[static_cast<unsigned int>(color)].insert(hash);
}
}

void FiltersTagMap::load()
{
for (QSet<QString> & hashes : _colorToHashes) {
hashes.clear();
}
QString jsonFilename = QString("%1%2").arg(gmicConfigPath(true), FILTERS_TAGS_FILENAME);
QFile jsonFile(jsonFilename);
if (!jsonFile.exists()) {
return;
}
if (jsonFile.open(QFile::ReadOnly)) {
#ifdef _GMIC_QT_DEBUG_
QJsonDocument jsonDoc;
QByteArray allFile = jsonFile.readAll();
if (allFile.startsWith("{")) {
jsonDoc = QJsonDocument::fromJson(allFile);
} else {
jsonDoc = QJsonDocument::fromJson(qUncompress(allFile));
}
#else
QJsonDocument jsonDoc = QJsonDocument::fromJson(qUncompress(jsonFile.readAll()));
#endif
if (jsonDoc.isNull()) {
Logger::warning(QString("Cannot parse ") + jsonFilename);
Logger::warning("Fiter tags are lost!");
} else {
if (!jsonDoc.isObject()) {
Logger::error(QString("JSON file format is not correct (") + jsonFilename + ")");
} else {
QJsonObject documentObject = jsonDoc.object();

for (int color = (int)TagColor::None + 1; color != (int)TagColor::Count; ++color) {
QJsonObject::const_iterator it = documentObject.find(TagColorNames[color]);
QSet<QString> & hashes = _colorToHashes[color];
if (it != documentObject.constEnd()) {
QJsonArray array = it.value().toArray();
for (const QJsonValueRef & value : array) {
hashes.insert(value.toString());
}
}
}
}
}
} else {
Logger::error("Cannot open " + jsonFilename);
Logger::error("Parameters cannot be restored");
}
}

void FiltersTagMap::save()
{
QJsonObject documentObject;

for (int color = (int)TagColor::None + 1; color != (int)TagColor::Count; ++color) {
QJsonArray array;
const QSet<QString> & hashes = _colorToHashes[color];
for (const QString & hash : hashes) {
array.push_back(QJsonValue(hash));
}
documentObject.insert(TagColorNames[color], array);
}

QJsonDocument jsonDoc(documentObject);
QString jsonFilename = QString("%1%2").arg(gmicConfigPath(true), FILTERS_TAGS_FILENAME);
QFile jsonFile(jsonFilename);
if (QFile::exists(jsonFilename)) {
QString bakFilename = QString("%1%2").arg(gmicConfigPath(false), FILTERS_TAGS_FILENAME ".bak");
QFile::remove(bakFilename);
QFile::copy(jsonFilename, bakFilename);
}

qint64 count = -1;
if (jsonFile.open(QFile::WriteOnly | QFile::Truncate)) {
#ifdef _GMIC_QT_DEBUG_
count = jsonFile.write(jsonDoc.toJson());
#else
count = jsonFile.write(qCompress(jsonDoc.toJson(QJsonDocument::Compact)));
#endif
jsonFile.close();
}

if (count == -1) {
Logger::error("Cannot write " + jsonFilename);
Logger::error("Parameters cannot be saved");
}
}

} // namespace GmicQt
49 changes: 49 additions & 0 deletions src/FilterSelector/FilterTagMap.h
@@ -0,0 +1,49 @@
/** -*- mode: c++ ; c-basic-offset: 2 -*-
*
* @file FilterTagMap.h
*
* Copyright 2017 Sebastien Fourey
*
* This file is part of G'MIC-Qt, a generic plug-in for raster graphics
* editors, offering hundreds of filters thanks to the underlying G'MIC
* image processing framework.
*
* gmic_qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gmic_qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gmic_qt. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GMIC_QT_FILTERTAGMAP_H
#define GMIC_QT_FILTERTAGMAP_H

#include <QSet>

#include "Tags.h"

namespace GmicQt
{
class FiltersTagMap {
public:
static TagColor filterTag(const QString & hash);
static void setColor(const QString & hash, TagColor color);
static void load();
static void save();

protected:
private:
static QSet<QString> _colorToHashes[static_cast<unsigned int>(TagColor::Count)];
FiltersTagMap() = delete;
};

} // namespace GmicQt

#endif // GMIC_QT_FILTERTAGMAP_H
12 changes: 10 additions & 2 deletions src/FilterSelector/FiltersView/FilterTreeItemDelegate.cpp
Expand Up @@ -31,6 +31,7 @@
#include "DialogSettings.h"
#include "FilterSelector/FiltersView/FilterTreeAbstractItem.h"
#include "FilterSelector/FiltersView/FilterTreeItem.h"
#include "Tags.h"

namespace GmicQt
{
Expand All @@ -49,13 +50,20 @@ void FilterTreeItemDelegate::paint(QPainter * painter, const QStyleOptionViewIte
Q_ASSERT_X(item, "FiltersTreeItemDelegate::paint()", "No item");
auto filter = dynamic_cast<const FilterTreeItem *>(item);

const int width = 0.5 * options.rect.height();
QString tag = TagAssets::markerHtml(TagColor::Green, width);

QTextDocument doc;
if (!item->isCheckable() && filter && !filter->isVisible()) {
QColor textColor;
textColor = DialogSettings::UnselectedFilterTextColor;
doc.setHtml(QString("<span style=\"color:%1\">%2</span>").arg(textColor.name()).arg(options.text));
doc.setHtml(QString("<span style=\"color:%1\">%2</span>&nbsp;%3").arg(textColor.name()).arg(options.text).arg(tag));
} else {
doc.setHtml(options.text);
if (filter) {
doc.setHtml(options.text + "&nbsp;" + tag);
} else {
doc.setHtml(options.text);
}
}
options.text = "";
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
Expand Down
2 changes: 1 addition & 1 deletion src/FilterSelector/FiltersView/TreeView.cpp
Expand Up @@ -38,6 +38,6 @@ void TreeView::keyPressEvent(QKeyEvent * event)
QTreeView::keyPressEvent(event);
}

TreeView::~TreeView() = default;
TreeView::~TreeView() {}

} // namespace GmicQt
1 change: 1 addition & 0 deletions src/Globals.h
Expand Up @@ -40,6 +40,7 @@ const char WarningPrefix = '!';
#define SLIDER_MIN_WIDTH 60
#define PARAMETERS_CACHE_FILENAME "gmic_qt_params.dat"
#define FILTERS_VISIBILITY_FILENAME "gmic_qt_visibility.dat"
#define FILTERS_TAGS_FILENAME "gmic_qt_tags.dat"

#define FAVE_FOLDER_TEXT "<b>Faves</b>"
#define FAVES_IMPORT_KEY "Faves/ImportedGTK179"
Expand Down

0 comments on commit 7b70143

Please sign in to comment.