-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace QML based ControlColors with C++ version (that handles palett…
…e changes better)
- Loading branch information
Showing
10 changed files
with
150 additions
and
33 deletions.
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
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
31 changes: 0 additions & 31 deletions
31
source/shared/ui/qml/app/graphia/Shared/Controls/ControlColors.qml
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
|
||
import QtQuick | ||
|
||
import app.graphia | ||
|
||
Rectangle | ||
{ | ||
property bool outlineVisible: true | ||
|
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
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,85 @@ | ||
/* Copyright © 2013-2023 Graphia Technologies Ltd. | ||
* | ||
* This file is part of Graphia. | ||
* | ||
* Graphia 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. | ||
* | ||
* Graphia 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 Graphia. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "qmlcontrolcolors.h" | ||
|
||
#include "shared/utils/static_block.h" | ||
|
||
#include <QGuiApplication> | ||
#include <QQmlEngine> | ||
#include <QStyleHints> | ||
|
||
QmlControlColors::QmlControlColors(QObject* parent) : | ||
QObject(parent) | ||
{ | ||
QCoreApplication::instance()->installEventFilter(this); | ||
|
||
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, | ||
this, &QmlControlColors::paletteChanged); | ||
|
||
connect(this, &QmlControlColors::paletteChanged, [this] | ||
{ | ||
_palette = QGuiApplication::palette(); | ||
_palette.setCurrentColorGroup(QPalette::ColorGroup::Active); | ||
}); | ||
} | ||
|
||
QObject* QmlControlColors::qmlInstance(QQmlEngine*, QJSEngine*) | ||
{ | ||
return new QmlControlColors; | ||
} | ||
|
||
bool QmlControlColors::eventFilter(QObject* watched, QEvent* event) | ||
{ | ||
bool watchedQObjectIsApplication = (watched == QCoreApplication::instance()); | ||
|
||
if(watchedQObjectIsApplication && event->type() == QEvent::ApplicationPaletteChange) | ||
emit paletteChanged(); | ||
|
||
return QObject::eventFilter(watched, event); | ||
} | ||
|
||
QColor QmlControlColors::outline() const | ||
{ | ||
auto colorScheme = QGuiApplication::styleHints()->colorScheme(); | ||
|
||
return colorScheme == Qt::ColorScheme::Light ? | ||
_palette.color(QPalette::Mid) : _palette.color(QPalette::Dark); | ||
} | ||
|
||
QColor QmlControlColors::background() const | ||
{ | ||
return _palette.color(QPalette::Light); | ||
} | ||
|
||
QColor QmlControlColors::tableRow1() const | ||
{ | ||
return _palette.color(QPalette::Light); | ||
} | ||
|
||
QColor QmlControlColors::tableRow2() const | ||
{ | ||
return _palette.color(QPalette::Button); | ||
} | ||
|
||
static_block | ||
{ | ||
qmlRegisterSingletonType<QmlControlColors>( | ||
APP_URI, APP_MAJOR_VERSION, APP_MINOR_VERSION, "ControlColors", &QmlControlColors::qmlInstance); | ||
} | ||
|
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,58 @@ | ||
/* Copyright © 2013-2023 Graphia Technologies Ltd. | ||
* | ||
* This file is part of Graphia. | ||
* | ||
* Graphia 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. | ||
* | ||
* Graphia 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 Graphia. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef QMLCONTROLCOLORS_H | ||
#define QMLCONTROLCOLORS_H | ||
|
||
#include <QObject> | ||
#include <QColor> | ||
#include <QPalette> | ||
|
||
class QQmlEngine; | ||
class QJSEngine; | ||
|
||
class QmlControlColors : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(QmlControlColors) | ||
|
||
Q_PROPERTY(QColor outline READ outline NOTIFY paletteChanged) | ||
Q_PROPERTY(QColor background READ background NOTIFY paletteChanged) | ||
Q_PROPERTY(QColor tableRow1 READ tableRow1 NOTIFY paletteChanged) | ||
Q_PROPERTY(QColor tableRow2 READ tableRow2 NOTIFY paletteChanged) | ||
|
||
public: | ||
explicit QmlControlColors(QObject* parent = nullptr); | ||
static QObject* qmlInstance(QQmlEngine*, QJSEngine*); | ||
|
||
QColor outline() const; | ||
QColor background() const; | ||
QColor tableRow1() const; | ||
QColor tableRow2() const; | ||
|
||
protected: | ||
bool eventFilter(QObject* watched, QEvent* event) override; | ||
|
||
private: | ||
QPalette _palette; | ||
|
||
signals: | ||
void paletteChanged(); | ||
}; | ||
|
||
#endif // QMLCONTROLCOLORS_H |