-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qt: Expose branding color #670
Open
CarlSchwan
wants to merge
1
commit into
ximion:main
Choose a base branch
from
CarlSchwan:work/carl/branding-qt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
qt: Expose branding color
- Loading branch information
commit 8e9ab6f4ae2f917c575ec5cc9330885554ff72bc
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu> | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#include "branding.h" | ||
#include "appstream.h" | ||
#include "chelpers.h" | ||
|
||
using namespace AppStream; | ||
|
||
class AppStream::BrandingData : public QSharedData | ||
{ | ||
public: | ||
BrandingData() | ||
{ | ||
brandingp = as_branding_new(); | ||
} | ||
|
||
BrandingData(AsBranding *branding) | ||
: brandingp(branding) | ||
{ | ||
g_object_ref(brandingp); | ||
} | ||
|
||
~BrandingData() | ||
{ | ||
g_object_unref(brandingp); | ||
} | ||
|
||
bool operator==(const BrandingData &rd) const | ||
{ | ||
return rd.brandingp == brandingp; | ||
} | ||
|
||
AsBranding *brandingp; | ||
}; | ||
|
||
Branding::Branding() | ||
: d(new BrandingData) | ||
{ | ||
} | ||
|
||
Branding::Branding(_AsBranding *devp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
: d(new BrandingData(devp)) | ||
{ | ||
} | ||
|
||
Branding::Branding(const Branding &devp) = default; | ||
|
||
Branding::~Branding() = default; | ||
|
||
Branding &Branding::operator=(const Branding &devp) = default; | ||
|
||
bool Branding::operator==(const Branding &other) const | ||
{ | ||
if (this->d == other.d) { | ||
return true; | ||
} | ||
if (this->d && other.d) { | ||
return *(this->d) == *other.d; | ||
} | ||
return false; | ||
} | ||
|
||
_AsBranding *Branding::cPtr() const | ||
{ | ||
return d->brandingp; | ||
} | ||
|
||
QString Branding::colorKindToString(Branding::ColorKind colorKind) | ||
{ | ||
return valueWrap(as_color_kind_to_string(static_cast<AsColorKind>(colorKind))); | ||
} | ||
|
||
Branding::ColorKind Branding::colorKindfromString(const QString &string) | ||
{ | ||
return static_cast<Branding::ColorKind>(as_color_kind_from_string(qPrintable(string))); | ||
} | ||
|
||
QString Branding::colorSchemeToString(ColorSchemeKind colorScheme) | ||
{ | ||
return valueWrap(as_color_scheme_kind_to_string(static_cast<AsColorSchemeKind>(colorScheme))); | ||
} | ||
|
||
Branding::ColorSchemeKind Branding::colorSchemefromString(const QString &string) | ||
{ | ||
return static_cast<Branding::ColorSchemeKind>(as_color_scheme_kind_from_string(qPrintable(string))); | ||
} | ||
|
||
void Branding::setColor(Branding::ColorKind kind, Branding::ColorSchemeKind scheme, const QString &color) | ||
{ | ||
as_branding_set_color(d->brandingp, static_cast<AsColorKind>(kind), static_cast<AsColorSchemeKind>(scheme), qPrintable(color)); | ||
} | ||
|
||
void Branding::removeColor(Branding::ColorKind kind, Branding::ColorSchemeKind scheme) | ||
{ | ||
as_branding_remove_color(d->brandingp, static_cast<AsColorKind>(kind), static_cast<AsColorSchemeKind>(scheme)); | ||
} | ||
|
||
QString Branding::color(Branding::ColorKind kind, Branding::ColorSchemeKind scheme) | ||
{ | ||
return valueWrap(as_branding_get_color(d->brandingp, static_cast<AsColorKind>(kind), static_cast<AsColorSchemeKind>(scheme))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu> | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
#pragma once | ||
|
||
#include <QObject> | ||
#include <QSharedDataPointer> | ||
#include "appstreamqt_export.h" | ||
|
||
class _AsBranding; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
|
||
namespace AppStream | ||
{ | ||
|
||
class BrandingData; | ||
|
||
class APPSTREAMQT_EXPORT Branding | ||
{ | ||
Q_GADGET | ||
|
||
public: | ||
enum class ColorSchemeKind { | ||
Unknown, | ||
Light, | ||
Dark, | ||
}; | ||
|
||
enum class ColorKind { | ||
Unknow, | ||
Primary, | ||
}; | ||
|
||
Branding(); | ||
Branding(_AsBranding *); | ||
Branding(const Branding &devp); | ||
~Branding(); | ||
|
||
Branding &operator=(const Branding &devp); | ||
bool operator==(const Branding &r) const; | ||
|
||
/** | ||
* Converts the ColorKind enumerated value to an text representation. | ||
*/ | ||
static QString colorKindToString(ColorKind colorKind); | ||
|
||
/** | ||
* Converts the text representation to an ColorKind enumerated value. | ||
*/ | ||
static ColorKind colorKindfromString(const QString &string); | ||
|
||
/** | ||
* Converts the ColorScheme enumerated value to an text representation. | ||
*/ | ||
static QString colorSchemeToString(ColorSchemeKind colorScheme); | ||
|
||
/** | ||
* Converts the text representation to an ColorScheme enumerated value. | ||
*/ | ||
static ColorSchemeKind colorSchemefromString(const QString &string); | ||
|
||
/** | ||
* Sets a new accent color. If a color of the given kind with the given scheme preference already exists, | ||
* it will be overriden with the new color code. | ||
*/ | ||
void setColor(ColorKind kind, ColorSchemeKind scheme, const QString &color); | ||
|
||
/** | ||
* Deletes a color that matches the given type and scheme preference. | ||
*/ | ||
void removeColor(ColorKind kind, ColorSchemeKind scheme); | ||
|
||
/** | ||
* Retrieve a color of the given @kind that matches @scheme_kind. | ||
* If a color has no scheme preference defined, it will be returned for either scheme type, | ||
* unless a more suitable color was found. | ||
*/ | ||
QString color(ColorKind kind, ColorSchemeKind scheme); | ||
|
||
/** | ||
* \returns the internally stored AsBranding | ||
*/ | ||
_AsBranding *cPtr() const; | ||
|
||
private: | ||
QSharedDataPointer<BrandingData> d; | ||
}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the full copyright please, like in all other files? I do like the SPDX strings, but I think it will be easier to convert everything all at once at a future point, rather than having one outlier file.