Skip to content
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

Separate some functions of LibreMinesGui #38

Merged
merged 2 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ add_executable(${PROJECT_NAME} WIN32
src/common.cpp
src/common.h
src/main.cpp
src/libreminespreferencesdialog.cpp
src/libreminespreferencesdialog.h
src/libreminespreferencesdialog.ui
src/libreminesapptheme.cpp
src/libreminesapptheme.h
src/libreminesgameengine.cpp
src/libreminesgameengine.h
src/libreminesgui.cpp
src/libreminesgui.h
src/libreminespreferencesdialog.cpp
src/libreminespreferencesdialog.h
src/libreminespreferencesdialog.ui
src/libreminespreferencessaver.cpp
src/libreminespreferencessaver.h
src/libreminesscore.cpp
src/libreminesscore.h
src/libreminesscoresdialog.cpp
Expand Down
109 changes: 109 additions & 0 deletions src/libreminesapptheme.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "libreminesapptheme.h"

#include <QApplication>
#include <QPalette>
#include <QMessageBox>
#include <QStyleFactory>
#include <QDebug>
#include <QFile>

bool LibreMinesAppTheme::bSetApplicationTheme(const QString& theme)
{
static bool firstTimeHere = true;

bool restartNeeded = false;

if(theme.compare("default", Qt::CaseInsensitive) == 0)
{
if(!firstTimeHere)
{
restartNeeded = true;
}
}
else if(theme.compare("FusionDark", Qt::CaseInsensitive) == 0)
{
qApp->setStyleSheet("");
qApp->setStyle(QStyleFactory::create ("Fusion"));
QPalette palette;
palette.setColor(QPalette::BrightText, Qt::red);
palette.setColor(QPalette::WindowText, Qt::white);
palette.setColor(QPalette::ToolTipBase, Qt::white);
palette.setColor(QPalette::ToolTipText, Qt::white);
palette.setColor(QPalette::Text, Qt::white);
palette.setColor(QPalette::ButtonText, Qt::white);
palette.setColor(QPalette::HighlightedText, Qt::black);
palette.setColor(QPalette::Window, QColor (53, 53, 53));
palette.setColor(QPalette::Base, QColor (25, 25, 25));
palette.setColor(QPalette::AlternateBase, QColor (53, 53, 53));
palette.setColor(QPalette::Button, QColor (53, 53, 53));
palette.setColor(QPalette::Link, QColor (42, 130, 218));
palette.setColor(QPalette::Highlight, QColor (42, 130, 218));

qApp->setPalette(palette);
}
else if(theme.compare("FusionLight", Qt::CaseInsensitive) == 0)
{
qApp->setStyleSheet("");
qApp->setStyle(QStyleFactory::create ("Fusion"));
QPalette palette;
palette.setColor(QPalette::BrightText, Qt::cyan);
palette.setColor(QPalette::WindowText, Qt::black);
palette.setColor(QPalette::ToolTipBase, Qt::black);
palette.setColor(QPalette::ToolTipText, Qt::black);
palette.setColor(QPalette::Text, Qt::black);
palette.setColor(QPalette::ButtonText, Qt::black);
palette.setColor(QPalette::HighlightedText, Qt::white);
palette.setColor(QPalette::Window, QColor (202, 202, 202));
palette.setColor(QPalette::Base, QColor (228, 228, 228));
palette.setColor(QPalette::AlternateBase, QColor (202, 202, 202));
palette.setColor(QPalette::Button, QColor (202, 202, 202));
palette.setColor(QPalette::Link, QColor (213, 125, 37));
palette.setColor(QPalette::Highlight, QColor (42, 130, 218));

qApp->setPalette(palette);
}
else if(QStyleFactory::keys().contains(theme))
{
qApp->setStyleSheet("");
qApp->setPalette(QPalette());
qApp->setStyle(QStyleFactory::create(theme));
}
else
{
qApp->setPalette(QPalette());
qApp->setStyle("");

QString prefix;

if(theme.compare("ConsoleStyle", Qt::CaseInsensitive) == 0)
prefix = ":/qss/ConsoleStyle.qss";
else if(theme.compare("NeonButtons", Qt::CaseInsensitive) == 0)
prefix = ":/qss/NeonButtons.qss";
else if(theme.compare("QDarkStyle", Qt::CaseInsensitive) == 0)
prefix = ":/qdarkstyle/dark/style.qss";
else if(theme.compare("QDarkStyleLight", Qt::CaseInsensitive) == 0)
prefix = ":/qdarkstyle/light/style.qss";
else if(theme.compare("BreezeDark", Qt::CaseInsensitive) == 0)
prefix = ":/breeze/dark.qss";
else if(theme.compare("BreezeLight", Qt::CaseInsensitive) == 0)
prefix = ":/breeze/light.qss";


QFile fileQSS(prefix);

if (!fileQSS.exists())
{
qWarning() << "Unable to set stylesheet, file not found";
}
else
{
fileQSS.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&fileQSS);
qApp->setStyleSheet(ts.readAll());
}
}

firstTimeHere = false;

return restartNeeded;
}
17 changes: 17 additions & 0 deletions src/libreminesapptheme.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LIBREMINESAPPTHEME_H
#define LIBREMINESAPPTHEME_H

#include <QString>

namespace LibreMinesAppTheme
{

///
/// \brief Change the application theme according to the parameter _theme_
/// \param
/// \return True if the app needs to restart to apply the changes
///
bool bSetApplicationTheme(const QString& theme);
};

#endif // LIBREMINESAPPTHEME_H
Loading