Skip to content

Commit

Permalink
Adding system theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrKudrya committed Feb 7, 2025
1 parent fd7e8c9 commit 01e0691
Show file tree
Hide file tree
Showing 47 changed files with 271 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ mkdir -p "$PWD"/../data/plugins/editors
mkdir -p "$PWD"/../data/plugins/tools
rsync -a "$BIN_DIR"/help "$PWD"/../data
rsync -a "$BIN_DIR"/images "$PWD"/../data
rsync -a "$BIN_DIR"/palettes "$PWD"/../data
rsync -a "$BIN_DIR"/externalToolsConfig "$PWD"/../data
rsync -a "$BIN_DIR"/splashscreen.png "$PWD"/../data
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CommentItem::CommentItem(const QPointF &begin, const QPointF &end)

QAction *CommentItem::commentTool()
{
QAction * const result = new QAction(QIcon(":/icons/2d_comment.svg"), tr("Text (T)"), nullptr);
auto * const result = new QAction(loadTextColorIcon(":/icons/2d_comment.svg"), tr("Text (T)"), nullptr);
result->setShortcuts({QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_0)});
result->setCheckable(true);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ AbstractItem *CurveItem::clone() const

QAction *CurveItem::curveTool()
{
QAction * const result = new QAction(QIcon(":/icons/2d_bezier.svg"), tr("Bezier Curve (Z)"), nullptr);
QAction * const result = new QAction(loadTextColorIcon(":/icons/2d_bezier.svg"), tr("Bezier Curve (Z)"), nullptr);
result->setShortcuts({QKeySequence(Qt::Key_Z), QKeySequence(Qt::Key_6)});
result->setCheckable(true);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ QPainterPath ImageItem::resizeArea() const

QAction *ImageItem::imageTool()
{
QAction * const result = new QAction(QIcon(":/icons/2d_image.svg"), tr("Image (I)"), nullptr);
auto * const result = new QAction(loadTextColorIcon(":/icons/2d_image.svg"), tr("Image (I)"), nullptr);
result->setShortcuts({QKeySequence(Qt::Key_I), QKeySequence(Qt::Key_Minus)});
result->setCheckable(false);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AbstractItem *RectangleItem::clone() const

QAction *RectangleItem::rectangleTool()
{
QAction * const result = new QAction(QIcon(":/icons/2d_rectangle.svg"), tr("Rectangle (R)"), nullptr);
QAction * const result = new QAction(loadTextColorIcon(":/icons/2d_rectangle.svg"), tr("Rectangle (R)"), nullptr);
result->setShortcuts({QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_7)});
result->setCheckable(true);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ AbstractItem *StylusItem::clone() const
}

QAction *StylusItem::stylusTool()
{
QAction * const result = new QAction(QIcon(":/icons/2d_pencil.png"), tr("Stylus (S)"), nullptr);
{
QAction * const result = new QAction(loadTextColorIcon(":/icons/2d_pencil.png"), tr("Stylus (S)"), nullptr);
result->setShortcuts({QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_9)});
result->setCheckable(true);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@
* limitations under the License. */

#include "actionsBox.h"
#include <qrutils/graphicsUtils/abstractItem.h>

using namespace graphicsUtils;
using namespace twoDModel::view;

ActionsBox::ActionsBox(QObject *parent)
: QObject(parent)
, mSceneModeActions(this)
, mScrollHandModeAction(new QAction(QIcon(":/icons/2d_hand.png"), tr("Hand dragging mode"), this))
, mScrollHandModeAction(new QAction(AbstractItem::loadTextColorIcon(":/icons/2d_hand.png")
, tr("Hand dragging mode"), this))
, mMultiSelectionModeAction(new QAction(QIcon(":/icons/2d_multiselection.png"), tr("Multiselection mode"), this))
, mSeparator1(new QAction(this))
, mSaveWorldModelAction(new QAction(QIcon(":/icons/2d_save.png"), tr("Save world model..."), this))
, mLoadWorldModelAction(new QAction(QIcon(":/icons/2d_open.png"), tr("Load world model..."), this))
, mLoadWorldWithoutRobotAction(new QAction(QIcon(":/icons/2d_open.png")
, tr("Load world model without robot configuration..."), this))
, mSeparator2(new QAction(this))
, mDeleteAllAction(new QAction(QIcon(":/icons/2d_clear.png"), tr("Clear items"), this))
, mClearFloorAction(new QAction(QIcon(":/icons/2d_clear_floor.svg"), tr("Clear floor"), this))
, mDeleteAllAction(new QAction(AbstractItem::loadTextColorIcon(":/icons/2d_clear.png")
, tr("Clear items"), this))
, mClearFloorAction(new QAction(AbstractItem::loadTextColorIcon(":/icons/2d_clear_floor.svg")
, tr("Clear floor"), this))
{
mScrollHandModeAction->setCheckable(true);
mMultiSelectionModeAction->setCheckable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpinBox>

#include <qrutils/graphicsUtils/abstractItem.h>
#include <qrkernel/settingsManager.h>

#include "src/engine/view/scene/robotItem.h"
Expand Down Expand Up @@ -94,7 +94,9 @@ QWidget *RobotItemPopup::initSetStartButton()

QAbstractButton *RobotItemPopup::initButton(const QString &icon, const QString &toolTip)
{
QPushButton * const result = new QPushButton(QIcon(icon), QString(), this);
QPushButton * const result = new QPushButton(
graphicsUtils::AbstractItem::loadThemedIcon(icon, Qt::red), QString(), this
);
result->setToolTip(toolTip);
result->setFlat(true);
result->setFixedSize(24, 24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ void TwoDModelWidget::initWidget()
};
toggleRulers();

mUi->speedUpButton->setIcon(AbstractItem::loadTextColorIcon(":/icons/2d_plus.svg"));
mUi->speedDownButton->setIcon(AbstractItem::loadTextColorIcon(":/icons/2d_minus.svg"));
mUi->initialStateButton->setIcon(AbstractItem::loadTextColorIcon(":/icons/2d_robot_back.png"));
mUi->trainingModeButton->setIcon(AbstractItem::loadTextColorIcon(":/icons/2d_training.svg"));
mUi->toggleDetailsButton->setIcon(AbstractItem::loadTextColorIcon(":/icons/2d_left.png"));

connect(mUi->gridParametersBox, &twoDModel::view::GridParameters::parametersChanged
, &*mScene, [&]() { mScene->update(); });
connect(mUi->gridParametersBox, &GridParameters::parametersChanged, this, toggleRulers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#include "interpreterCore/managers/actionsManager.h"

#include <QtCore/QSignalMapper>

#include <QtWidgets/QApplication>
#include <QPainter>
#include <qrkernel/settingsManager.h>
#include <kitBase/robotModel/robotModelUtils.h>
#include <qrutils/graphicsUtils/abstractItem.h>

using namespace interpreterCore;

Expand All @@ -32,8 +34,14 @@ ActionsManager::ActionsManager(KitPluginManager &kitPluginManager, RobotModelMan
, mConnectToRobotAction(new QAction(QIcon(":/icons/robots_connect.svg"), QObject::tr("Connect to robot"), this))
, mRobotSettingsAction(QIcon(":/icons/robots_settings.png"), QObject::tr("Robot settings"), this)
, mExportExerciseAction(QIcon(), QObject::tr("Save as task..."), this)
, mDebugModeAction(new QAction(QIcon(":/icons/main_tabbar_debug.svg"), QObject::tr("Debug"), this))
, mEditModeAction(new QAction(QIcon(":/icons/main_tabbar_edit.svg"), QObject::tr("Edit"), this))
, mDebugModeAction(new QAction(
graphicsUtils::AbstractItem::loadTextColorIcon(":/icons/main_tabbar_debug.svg"),
QObject::tr("Debug"),
this))
, mEditModeAction(new QAction(
graphicsUtils::AbstractItem::loadTextColorIcon(":/icons/main_tabbar_edit.svg"),
QObject::tr("Edit"),
this))
, mHomeAction(new QAction(QIcon(":/icons/home.svg"), tr("To main page"), this))
, mSeparator1(this)
, mSeparator2(this)
Expand Down
2 changes: 2 additions & 0 deletions qrgui/brandManager/brandManager.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ HEADERS += \

SOURCES += \
$$PWD/brandManager.cpp \
$$PWD/styles.cpp \

RESOURCES += \
$$PWD/fonts/fonts.qrc \
Expand All @@ -38,3 +39,4 @@ DEFINES += QRGUI_BRAND_MANAGER_LIBRARY
links(qrkernel qrutils qrgui-plugin-manager)
includes(qrgui)

copyToDestdir(styles/palettes, now)
63 changes: 63 additions & 0 deletions qrgui/brandManager/styles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright 2007-2015 QReal Research Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */

#include "styles.h"

#include <QApplication>
#include <QSettings>
#include <QPalette>
#include <QColor>

using namespace qReal;

QPalette Styles::loadPalette(const QString& pathToPalette) const {
QSettings settings(pathToPalette, QSettings::IniFormat);
QPalette palette;

static QMap<QString, QPalette::ColorRole> colorRoles = {
{"Window", QPalette::Window},
{"WindowText", QPalette::WindowText},
{"Base", QPalette::Base},
{"AlternateBase", QPalette::AlternateBase},
{"ToolTipBase", QPalette::ToolTipBase},
{"ToolTipText", QPalette::ToolTipText},
{"Text", QPalette::Text},
{"Dark", QPalette::Dark},
{"Shadow", QPalette::Shadow},
{"Button", QPalette::Button},
{"ButtonText", QPalette::ButtonText},
{"BrightText", QPalette::BrightText},
{"Link", QPalette::Link},
{"Highlight", QPalette::Highlight},
{"HighlightedText", QPalette::HighlightedText}
};

for (const auto &group : {"PaletteActive", "PaletteDisabled"}) {
QPalette::ColorGroup colorGroup = (QString(group) == "PaletteDisabled") ? QPalette::Disabled : QPalette::Active;

for (auto it = colorRoles.begin(); it != colorRoles.end(); ++it) {
QStringList rgb = settings.value(QString(group) + "/" + it.key()).toStringList();
if (!rgb.isEmpty()) {
QColor color(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
if (colorGroup == QPalette::Disabled) {
palette.setColor(colorGroup, it.value(), color);
} else {
palette.setColor(it.value(), color);
}
}
}
}

return palette;
}
36 changes: 24 additions & 12 deletions qrgui/brandManager/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <QtWidgets/QApplication>
#include <QPalette>

#include <qrutils/inFile.h>
#include "fonts.h"
Expand All @@ -31,65 +32,76 @@ class Styles
{
}


virtual ~Styles() = default;

/// Returns json stylesheet for start tab background
virtual QString startTabBackgroundStyle() const
{
return utils::InFile::readAll(startTabBackgroundStylePath());
return loadSystemPallete(utils::InFile::readAll(startTabBackgroundStylePath()));
}

/// Returns json stylesheet for start tab substrate background
virtual QString startTabSubstrateBackgroundStyle() const
{
return utils::InFile::readAll(startTabSubstrateBackgroundStylePath());
return loadSystemPallete(utils::InFile::readAll(startTabSubstrateBackgroundStylePath()));
}

/// Returns json stylesheet for start tab header background
virtual QString startTabHeaderBackgroundStyle() const
{
return utils::InFile::readAll(startTabHeaderBackgroundStylePath());
return loadSystemPallete(utils::InFile::readAll(startTabHeaderBackgroundStylePath()));
}

/// Returns json stylesheet for recent projects section background on start tab
virtual QString startTabRecentProjectsBackgroundStyle() const
{
return utils::InFile::readAll(startTabRecentProjectsBackgroundStylePath());
return loadSystemPallete(utils::InFile::readAll(startTabRecentProjectsBackgroundStylePath()));
}

/// Returns json stylesheet for projects management section background on start tab
virtual QString startTabProjectsManagementBackgroundStyle() const
{
return utils::InFile::readAll(startTabProjectsManagementBackgroundStylePath());
return loadSystemPallete(utils::InFile::readAll(startTabProjectsManagementBackgroundStylePath()));
}

/// Returns json stylesheet for command buttons on start tab
virtual QString startTabButtonStyle() const
{
return utils::InFile::readAll(startTabButtonStylePath())
.replace("@@FONT@@", mFonts.commandButtonsFont());
return loadSystemPallete(utils::InFile::readAll(startTabButtonStylePath()));
}

/// Returns json stylesheet for styled text on start tab of level 1 heading
virtual QString startTabLabelLevel1Style() const
{
return utils::InFile::readAll(startTabLabelLevel1StylePath())
.replace("@@FONT@@", mFonts.styledTextFont());
return loadSystemPallete(utils::InFile::readAll(startTabLabelLevel1StylePath()));
}

/// Returns json stylesheet for styled text on start tab of level 2 heading
virtual QString startTabLabelLevel2Style() const
{
return utils::InFile::readAll(startTabLabelLevel2StylePath())
.replace("@@FONT@@", mFonts.styledTextFont());
return loadSystemPallete(utils::InFile::readAll(startTabLabelLevel2StylePath()));
}

virtual QString splashscreenStyle() const
{
return utils::InFile::readAll(splashscreenStylePath());
return loadSystemPallete(utils::InFile::readAll(splashscreenStylePath()));
}

QPalette loadPalette(const QString& pathToPalette) const;

protected:
QString loadSystemPallete(QString style) const {
auto systemPalette(QApplication::palette());
return style
.replace("@@Window@@", systemPalette.color(QPalette::Window).name())
.replace("@@Base@@", systemPalette.color(QPalette::Base).name())
.replace("@@Font@@", mFonts.commandButtonsFont())
.replace("@@Light@@", systemPalette.color(QPalette::Light).name())
.replace("@@Highlight@@", systemPalette.color(QPalette::Highlight).name())
.replace("@@Text@@", systemPalette.color(QPalette::Text).name());
}

/// Returns a path to a file with json stylesheet for start tab background
virtual QString startTabBackgroundStylePath() const
{
Expand Down
23 changes: 23 additions & 0 deletions qrgui/brandManager/styles/palettes/darkWindowsPalette.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[PaletteActive]
Window=56,56,56
WindowText=255,255,255
Base=42,42,42
AlternateBase=66,66,66
ToolTipBase=255,255,255
ToolTipText=255,255,255
Text=255,255,255
Dark=35,35,35
Shadow=20,20,20
Button=53,53,53
ButtonText=255,255,255
BrightText=255,0,0
Link=42,130,218
Highlight=42,130,218
HighlightedText=255,255,255

[PaletteDisabled]
WindowText=127,127,127
Text=127,127,127
ButtonText=127,127,127
Highlight=80,80,80
HighlightedText=127,127,127
2 changes: 1 addition & 1 deletion qrgui/brandManager/styles/splashscreen/splashscreen.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
QProgressBar::chunk {
background-color: #001A42;
background-color: #084200;
}
2 changes: 1 addition & 1 deletion qrgui/brandManager/styles/startTab/background.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
background-color: white;
background-color: @@Base@@;
8 changes: 4 additions & 4 deletions qrgui/brandManager/styles/startTab/button.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
QLabel {
background-color: transparent;
font-family: "Segoe UI";
color: black;
color: @@Text@@;
font: 20px;
text-align: left;
}
Expand All @@ -12,14 +12,14 @@ QLabel#withoutIcon {

QPushButton {
border-style: solid;
border-color: rgb(236, 236, 236);
background-color: rgb(236, 236, 236);
border-color: @@Window@@;
background-color: @@Window@@;
}

QPushButton#withIcon {
border-width: 10px;
}

QPushButton:hover, QPushButton:pressed {
background-color: rgb(216, 216, 216);
background-color: @@Highlight@@;
}
4 changes: 2 additions & 2 deletions qrgui/brandManager/styles/startTab/header.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
* {
background-color: rgb(255, 255, 255);
background-color: @@Window@@;
}

QWidget#header {
border-bottom: 3px solid;
border-bottom-color: rgb(236, 236, 236);
border-bottom-color: @@Window@@;
}
2 changes: 1 addition & 1 deletion qrgui/brandManager/styles/startTab/labelLevel1.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
font-family: "Segoe UI";
font: 35px;
text-transform: uppercase;
color: black;
color: @@Text@@;
Loading

0 comments on commit 01e0691

Please sign in to comment.