Erste Version

This commit is contained in:
2026-05-23 13:14:30 +02:00
commit 36e074f43d
39 changed files with 3430 additions and 0 deletions

105
src/core/AboutDialog.cpp Normal file
View File

@@ -0,0 +1,105 @@
#include "AboutDialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QFrame>
#include <QFont>
#include <QApplication>
AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("Über BareCode"));
setFixedSize(440, 310);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *root = new QVBoxLayout(this);
root->setContentsMargins(0, 0, 0, 0);
root->setSpacing(0);
// -----------------------------------------------------------------------
// Header-Banner
// -----------------------------------------------------------------------
QFrame *banner = new QFrame(this);
banner->setFixedHeight(88);
banner->setStyleSheet(
"background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
" stop:0 #1a1a2e, stop:1 #16213e);"
);
QVBoxLayout *bannerLayout = new QVBoxLayout(banner);
bannerLayout->setContentsMargins(24, 10, 24, 10);
bannerLayout->setSpacing(2);
QLabel *appName = new QLabel("BareCode", banner);
QFont nameFont = appName->font();
nameFont.setPointSize(22);
nameFont.setBold(true);
appName->setFont(nameFont);
appName->setStyleSheet("color: #e0e0ff; background: transparent;");
QLabel *tagline = new QLabel(tr("Modularer Code-Editor"), banner);
tagline->setStyleSheet("color: #8888bb; background: transparent;");
bannerLayout->addWidget(appName);
bannerLayout->addWidget(tagline);
root->addWidget(banner);
// -----------------------------------------------------------------------
// Info-Tabelle
// -----------------------------------------------------------------------
QVBoxLayout *info = new QVBoxLayout();
info->setContentsMargins(28, 20, 28, 8);
info->setSpacing(10);
auto makeRow = [&](const QString &label, const QString &value)
{
QHBoxLayout *row = new QHBoxLayout();
row->setSpacing(12);
QLabel *lbl = new QLabel(label, this);
QFont boldFont = lbl->font();
boldFont.setBold(true);
lbl->setFont(boldFont);
lbl->setFixedWidth(100);
lbl->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
QLabel *val = new QLabel(value, this);
val->setTextInteractionFlags(Qt::TextSelectableByMouse);
row->addWidget(lbl);
row->addWidget(val, 1);
info->addLayout(row);
};
makeRow(tr("Version"), "1.0.0");
makeRow(tr("Entwickler"), "Dany Thinnes");
makeRow(tr("Projekt"), "Projekt Hirnfrei");
makeRow(tr("Framework"), QString("Qt %1").arg(qVersion()));
makeRow(tr("Sprache"), "C++17");
root->addLayout(info);
root->addStretch();
// -----------------------------------------------------------------------
// Trennlinie + Schließen-Button
// -----------------------------------------------------------------------
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
root->addWidget(line);
QHBoxLayout *btnRow = new QHBoxLayout();
btnRow->setContentsMargins(12, 8, 12, 12);
btnRow->addStretch();
QPushButton *btnClose = new QPushButton(tr("Schließen"), this);
btnClose->setDefault(true);
btnClose->setFixedWidth(110);
connect(btnClose, &QPushButton::clicked, this, &QDialog::accept);
btnRow->addWidget(btnClose);
root->addLayout(btnRow);
}

14
src/core/AboutDialog.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <QDialog>
// ---------------------------------------------------------------------------
// AboutDialog Zeigt Versionsinformationen und Entwicklerangaben.
// ---------------------------------------------------------------------------
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = nullptr);
};

28
src/core/CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
set(CORE_SOURCES
MainWindow.cpp
MainWindow.h
IPlugin.h
ProjectManager.cpp
ProjectManager.h
Settings.cpp
Settings.h
ThemeManager.cpp
ThemeManager.h
AboutDialog.cpp
AboutDialog.h
)
add_library(BareCode_Core STATIC ${CORE_SOURCES})
target_link_libraries(BareCode_Core PUBLIC
Qt6::Core
Qt6::Gui
Qt6::Widgets
BareCode_Editor
BareCode_FileTree
)
target_include_directories(BareCode_Core PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/..
)

26
src/core/IPlugin.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include <QString>
#include <QWidget>
// ---------------------------------------------------------------------------
// IPlugin Interface that every BareCode module / plugin must implement.
// This allows components to be swapped or extended without touching the core.
// ---------------------------------------------------------------------------
class IPlugin
{
public:
virtual ~IPlugin() = default;
// Human-readable name of the plugin
virtual QString pluginName() const = 0;
// Version string, e.g. "1.0.0"
virtual QString pluginVersion() const = 0;
// Called once after all plugins are loaded so plugins can cross-reference
virtual void initialize() {}
// Called before the application shuts down
virtual void shutdown() {}
};

316
src/core/MainWindow.cpp Normal file
View File

@@ -0,0 +1,316 @@
#include "MainWindow.h"
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QCloseEvent>
#include <QSettings>
#include "AboutDialog.h"
#include "filetree/FileTreePanel.h"
#include "editor/EditorPanel.h"
// ---------------------------------------------------------------------------
// Konstruktor
// ---------------------------------------------------------------------------
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_projectManager(std::make_unique<ProjectManager>())
, m_settings(std::make_unique<Settings>())
, m_themeManager(std::make_unique<ThemeManager>())
{
setWindowTitle("BareCode");
setMinimumSize(900, 600);
setupUi();
setupMenuBar();
setupStatusBar();
connectSignals();
restoreWindowState();
applyInitialTheme();
// Letztes Projekt wieder öffnen
const QString lastPath = m_settings->lastProjectPath();
if (!lastPath.isEmpty())
{
m_projectManager->openProject(lastPath);
}
}
MainWindow::~MainWindow() = default;
// ---------------------------------------------------------------------------
// UI aufbauen
// ---------------------------------------------------------------------------
void MainWindow::setupUi()
{
m_splitter = new QSplitter(Qt::Horizontal, this);
setCentralWidget(m_splitter);
m_fileTree = new FileTreePanel(m_splitter);
m_editor = new EditorPanel(m_settings.get(), m_splitter);
m_splitter->addWidget(m_fileTree);
m_splitter->addWidget(m_editor);
const int treeWidth = m_settings->fileTreeWidth();
m_splitter->setSizes({treeWidth, width() - treeWidth});
m_splitter->setStretchFactor(0, 0);
m_splitter->setStretchFactor(1, 1);
}
// ---------------------------------------------------------------------------
// Menüleiste
// ---------------------------------------------------------------------------
void MainWindow::setupMenuBar()
{
// ---- Datei ----
QMenu *mDatei = menuBar()->addMenu(tr("&Datei"));
m_actNewFile = mDatei->addAction(tr("&Neue Datei…"), this, &MainWindow::onNewFile);
m_actNewFile->setShortcut(QKeySequence::New);
mDatei->addSeparator();
m_actOpenFile = mDatei->addAction(tr("Datei &öffnen…"), this, &MainWindow::onOpenFile);
m_actOpenFile->setShortcut(QKeySequence::Open);
m_actOpenProject = mDatei->addAction(tr("&Projekt öffnen…"), this, &MainWindow::onOpenProject);
m_actOpenProject->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_O);
m_actClose = mDatei->addAction(tr("Projekt &schließen"), this, &MainWindow::onCloseProject);
mDatei->addSeparator();
m_actSave = mDatei->addAction(tr("&Speichern"), this, &MainWindow::onSave);
m_actSave->setShortcut(QKeySequence::Save);
m_actSaveAs = mDatei->addAction(tr("Speichern &unter…"), this, &MainWindow::onSaveAs);
m_actSaveAs->setShortcut(QKeySequence::SaveAs);
m_actSaveAll = mDatei->addAction(tr("&Alles speichern"), this, &MainWindow::onSaveAll);
m_actSaveAll->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_S);
mDatei->addSeparator();
m_actQuit = mDatei->addAction(tr("&Beenden"), qApp, &QApplication::quit);
m_actQuit->setShortcut(QKeySequence::Quit);
// ---- Bearbeiten ----
QMenu *mBearbeiten = menuBar()->addMenu(tr("&Bearbeiten"));
m_actUndo = mBearbeiten->addAction(tr("&Rückgängig"), this, &MainWindow::onUndo);
m_actUndo->setShortcut(QKeySequence::Undo);
m_actRedo = mBearbeiten->addAction(tr("&Wiederholen"), this, &MainWindow::onRedo);
m_actRedo->setShortcut(QKeySequence::Redo);
mBearbeiten->addSeparator();
m_actSearch = mBearbeiten->addAction(tr("&Suchen / Ersetzen…"), this, &MainWindow::onShowSearch);
m_actSearch->setShortcut(QKeySequence::Find);
// ---- Ansicht ----
QMenu *mAnsicht = menuBar()->addMenu(tr("&Ansicht"));
m_actDarkMode = mAnsicht->addAction(tr("&Dark Mode"));
m_actDarkMode->setCheckable(true);
m_actDarkMode->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_D);
connect(m_actDarkMode, &QAction::toggled, this, &MainWindow::onToggleDarkMode);
// ---- Hilfe ----
QMenu *mHilfe = menuBar()->addMenu(tr("&Hilfe"));
m_actAbout = mHilfe->addAction(tr("&Über BareCode…"), this, &MainWindow::onAbout);
}
void MainWindow::setupStatusBar()
{
statusBar()->showMessage(tr("Bereit"));
}
// ---------------------------------------------------------------------------
// Signale verbinden
// ---------------------------------------------------------------------------
void MainWindow::connectSignals()
{
connect(m_projectManager.get(), &ProjectManager::projectOpened,
this, &MainWindow::onProjectOpened);
connect(m_projectManager.get(), &ProjectManager::projectClosed,
this, &MainWindow::onProjectClosed);
// Dateibaum → Editor
connect(m_fileTree, &FileTreePanel::fileActivated,
m_editor, &EditorPanel::openFile);
connect(m_fileTree, &FileTreePanel::fileCreated,
m_editor, &EditorPanel::openFile);
// Gespeichert → Statusleiste
connect(m_editor, &EditorPanel::currentFileSaved, this, [this](const QString &path)
{
statusBar()->showMessage(tr("Gespeichert: %1").arg(path), 3000);
});
// Splitter-Breite merken
connect(m_splitter, &QSplitter::splitterMoved, this, [this](int pos, int)
{
m_settings->setFileTreeWidth(pos);
});
}
// ---------------------------------------------------------------------------
// Theme beim Start
// ---------------------------------------------------------------------------
void MainWindow::applyInitialTheme()
{
const bool dark = m_settings->darkMode();
// Block damit toggled-Signal nicht doppelt feuert
m_actDarkMode->blockSignals(true);
m_actDarkMode->setChecked(dark);
m_actDarkMode->blockSignals(false);
m_themeManager->applyTheme(dark ? ThemeManager::Theme::Dark
: ThemeManager::Theme::Light);
}
// ---------------------------------------------------------------------------
// Slots Datei
// ---------------------------------------------------------------------------
void MainWindow::onNewFile()
{
m_fileTree->triggerNewFile();
}
void MainWindow::onOpenFile()
{
const QString path = QFileDialog::getOpenFileName(
this,
tr("Datei öffnen"),
m_settings->lastProjectPath()
);
if (!path.isEmpty())
{
m_editor->openFile(path);
}
}
void MainWindow::onOpenProject()
{
const QString path = QFileDialog::getExistingDirectory(
this,
tr("Projektverzeichnis öffnen"),
m_settings->lastProjectPath()
);
if (!path.isEmpty())
{
m_projectManager->openProject(path);
m_settings->setLastProjectPath(path);
}
}
void MainWindow::onCloseProject()
{
m_projectManager->closeProject();
}
void MainWindow::onSave()
{
m_editor->saveCurrentFile();
}
void MainWindow::onSaveAs()
{
m_editor->saveCurrentFileAs();
}
void MainWindow::onSaveAll()
{
m_editor->saveAllFiles();
statusBar()->showMessage(tr("Alle Dateien gespeichert"), 3000);
}
// ---------------------------------------------------------------------------
// Slots Bearbeiten
// ---------------------------------------------------------------------------
void MainWindow::onUndo()
{
m_editor->undo();
}
void MainWindow::onRedo()
{
m_editor->redo();
}
void MainWindow::onShowSearch()
{
m_editor->showSearchPanel();
}
// ---------------------------------------------------------------------------
// Slots Ansicht
// ---------------------------------------------------------------------------
void MainWindow::onToggleDarkMode(bool checked)
{
m_themeManager->applyTheme(checked ? ThemeManager::Theme::Dark
: ThemeManager::Theme::Light);
m_settings->setDarkMode(checked);
}
// ---------------------------------------------------------------------------
// Slots Hilfe
// ---------------------------------------------------------------------------
void MainWindow::onAbout()
{
AboutDialog dlg(this);
dlg.exec();
}
// ---------------------------------------------------------------------------
// Slots Projekt
// ---------------------------------------------------------------------------
void MainWindow::onProjectOpened(const QString &path)
{
setWindowTitle(QString("BareCode %1").arg(path));
m_fileTree->setRootPath(path);
statusBar()->showMessage(tr("Projekt geöffnet: %1").arg(path), 4000);
}
void MainWindow::onProjectClosed()
{
setWindowTitle("BareCode");
m_fileTree->clearRoot();
statusBar()->showMessage(tr("Projekt geschlossen"), 3000);
}
// ---------------------------------------------------------------------------
// Fenster-Zustand
// ---------------------------------------------------------------------------
void MainWindow::saveWindowState()
{
QSettings s(QSettings::IniFormat, QSettings::UserScope, "BareCode", "BareCode");
s.setValue("window/geometry", saveGeometry());
s.setValue("window/state", saveState());
}
void MainWindow::restoreWindowState()
{
QSettings s(QSettings::IniFormat, QSettings::UserScope, "BareCode", "BareCode");
if (s.contains("window/geometry"))
{
restoreGeometry(s.value("window/geometry").toByteArray());
}
if (s.contains("window/state"))
{
restoreState(s.value("window/state").toByteArray());
}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
saveWindowState();
event->accept();
}

85
src/core/MainWindow.h Normal file
View File

@@ -0,0 +1,85 @@
#pragma once
#include <QMainWindow>
#include <QSplitter>
#include <QMenuBar>
#include <QStatusBar>
#include <QAction>
#include <memory>
#include "ProjectManager.h"
#include "Settings.h"
#include "ThemeManager.h"
class FileTreePanel;
class EditorPanel;
// ---------------------------------------------------------------------------
// MainWindow Hauptfenster. Besitzt alle zentralen Dienste und das Layout.
// ---------------------------------------------------------------------------
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
void closeEvent(QCloseEvent *event) override;
private slots:
// Datei
void onNewFile();
void onOpenFile();
void onOpenProject();
void onCloseProject();
void onSave();
void onSaveAs();
void onSaveAll();
// Bearbeiten
void onUndo();
void onRedo();
void onShowSearch();
// Ansicht
void onToggleDarkMode(bool checked);
// Hilfe
void onAbout();
// Intern
void onProjectOpened(const QString &path);
void onProjectClosed();
private:
void setupUi();
void setupMenuBar();
void setupStatusBar();
void connectSignals();
void applyInitialTheme();
void saveWindowState();
void restoreWindowState();
// Dienste
std::unique_ptr<ProjectManager> m_projectManager;
std::unique_ptr<Settings> m_settings;
std::unique_ptr<ThemeManager> m_themeManager;
// Layout
QSplitter *m_splitter = nullptr;
FileTreePanel *m_fileTree = nullptr;
EditorPanel *m_editor = nullptr;
// Aktionen
QAction *m_actNewFile = nullptr;
QAction *m_actOpenFile = nullptr;
QAction *m_actOpenProject = nullptr;
QAction *m_actClose = nullptr;
QAction *m_actSave = nullptr;
QAction *m_actSaveAs = nullptr;
QAction *m_actSaveAll = nullptr;
QAction *m_actQuit = nullptr;
QAction *m_actUndo = nullptr;
QAction *m_actRedo = nullptr;
QAction *m_actSearch = nullptr;
QAction *m_actDarkMode = nullptr;
QAction *m_actAbout = nullptr;
};

View File

@@ -0,0 +1,33 @@
#include "ProjectManager.h"
ProjectManager::ProjectManager(QObject *parent)
: QObject(parent)
{
}
QString ProjectManager::currentProjectPath() const
{
return m_projectPath;
}
void ProjectManager::openProject(const QString &path)
{
if (m_projectPath == path)
{
return;
}
m_projectPath = path;
emit projectOpened(m_projectPath);
}
void ProjectManager::closeProject()
{
if (m_projectPath.isEmpty())
{
return;
}
m_projectPath.clear();
emit projectClosed();
}

27
src/core/ProjectManager.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
#include <QObject>
#include <QString>
// ---------------------------------------------------------------------------
// ProjectManager Tracks the currently open project directory and emits
// signals when the project changes so other components can react.
// ---------------------------------------------------------------------------
class ProjectManager : public QObject
{
Q_OBJECT
public:
explicit ProjectManager(QObject *parent = nullptr);
QString currentProjectPath() const;
void openProject(const QString &path);
void closeProject();
signals:
void projectOpened(const QString &path);
void projectClosed();
private:
QString m_projectPath;
};

90
src/core/Settings.cpp Normal file
View File

@@ -0,0 +1,90 @@
#include "Settings.h"
Settings::Settings(QObject *parent)
: QObject(parent)
, m_settings(QSettings::IniFormat, QSettings::UserScope, "BareCode", "BareCode")
{
}
// ---------------------------------------------------------------------------
// Editor font
// ---------------------------------------------------------------------------
QFont Settings::editorFont() const
{
QFont defaultFont("Monospace", 11);
defaultFont.setStyleHint(QFont::Monospace);
return m_settings.value("editor/font", defaultFont).value<QFont>();
}
void Settings::setEditorFont(const QFont &font)
{
m_settings.setValue("editor/font", font);
emit settingsChanged();
}
// ---------------------------------------------------------------------------
// Tab size
// ---------------------------------------------------------------------------
int Settings::tabSize() const
{
return m_settings.value("editor/tabSize", 4).toInt();
}
void Settings::setTabSize(int size)
{
m_settings.setValue("editor/tabSize", size);
emit settingsChanged();
}
// ---------------------------------------------------------------------------
// Spaces vs. tabs
// ---------------------------------------------------------------------------
bool Settings::useSpacesForTabs() const
{
return m_settings.value("editor/useSpacesForTabs", true).toBool();
}
void Settings::setUseSpacesForTabs(bool use)
{
m_settings.setValue("editor/useSpacesForTabs", use);
emit settingsChanged();
}
// ---------------------------------------------------------------------------
// File tree width
// ---------------------------------------------------------------------------
int Settings::fileTreeWidth() const
{
return m_settings.value("layout/fileTreeWidth", 240).toInt();
}
void Settings::setFileTreeWidth(int width)
{
m_settings.setValue("layout/fileTreeWidth", width);
}
// ---------------------------------------------------------------------------
// Dark mode
// ---------------------------------------------------------------------------
bool Settings::darkMode() const
{
return m_settings.value("appearance/darkMode", false).toBool();
}
void Settings::setDarkMode(bool dark)
{
m_settings.setValue("appearance/darkMode", dark);
}
// ---------------------------------------------------------------------------
// Last project path
// ---------------------------------------------------------------------------
QString Settings::lastProjectPath() const
{
return m_settings.value("project/lastPath", QString()).toString();
}
void Settings::setLastProjectPath(const QString &path)
{
m_settings.setValue("project/lastPath", path);
}

45
src/core/Settings.h Normal file
View File

@@ -0,0 +1,45 @@
#pragma once
#include <QObject>
#include <QSettings>
#include <QString>
#include <QFont>
// ---------------------------------------------------------------------------
// Settings Centralised persistent application settings.
// ---------------------------------------------------------------------------
class Settings : public QObject
{
Q_OBJECT
public:
explicit Settings(QObject *parent = nullptr);
// Editor
QFont editorFont() const;
void setEditorFont(const QFont &font);
int tabSize() const;
void setTabSize(int size);
bool useSpacesForTabs() const;
void setUseSpacesForTabs(bool use);
// Layout
int fileTreeWidth() const;
void setFileTreeWidth(int width);
// Recent
QString lastProjectPath() const;
void setLastProjectPath(const QString &path);
// Erscheinungsbild
bool darkMode() const;
void setDarkMode(bool dark);
signals:
void settingsChanged();
private:
QSettings m_settings;
};

115
src/core/ThemeManager.cpp Normal file
View File

@@ -0,0 +1,115 @@
#include "ThemeManager.h"
#include <QApplication>
#include <QStyleFactory>
ThemeManager::ThemeManager(QObject *parent)
: QObject(parent)
{
}
void ThemeManager::applyTheme(Theme theme)
{
m_currentTheme = theme;
QApplication::setStyle(QStyleFactory::create("Fusion"));
if (theme == Theme::Dark)
{
QApplication::setPalette(buildDarkPalette());
}
else
{
QApplication::setPalette(buildLightPalette());
}
emit themeChanged(theme);
}
ThemeManager::Theme ThemeManager::currentTheme() const
{
return m_currentTheme;
}
QPalette ThemeManager::buildDarkPalette()
{
QPalette p;
const QColor bg = QColor("#1e1e1e");
const QColor widget = QColor("#252526");
const QColor alt = QColor("#2d2d30");
const QColor hi = QColor("#264f78");
const QColor hiText = QColor("#ffffff");
const QColor text = QColor("#d4d4d4");
const QColor disabled = QColor("#6d6d6d");
const QColor btn = QColor("#3c3c3c");
const QColor mid = QColor("#333333");
const QColor dark = QColor("#1a1a1a");
const QColor light = QColor("#454545");
const QColor link = QColor("#569cd6");
p.setColor(QPalette::Window, bg);
p.setColor(QPalette::WindowText, text);
p.setColor(QPalette::Base, widget);
p.setColor(QPalette::AlternateBase, alt);
p.setColor(QPalette::Text, text);
p.setColor(QPalette::Button, btn);
p.setColor(QPalette::ButtonText, text);
p.setColor(QPalette::Highlight, hi);
p.setColor(QPalette::HighlightedText, hiText);
p.setColor(QPalette::Link, link);
p.setColor(QPalette::LinkVisited, link.darker(120));
p.setColor(QPalette::Mid, mid);
p.setColor(QPalette::Dark, dark);
p.setColor(QPalette::Light, light);
p.setColor(QPalette::Shadow, QColor("#000000"));
p.setColor(QPalette::ToolTipBase, widget);
p.setColor(QPalette::ToolTipText, text);
p.setColor(QPalette::PlaceholderText, disabled);
p.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
p.setColor(QPalette::Disabled, QPalette::Text, disabled);
p.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
return p;
}
QPalette ThemeManager::buildLightPalette()
{
// Fusion-Standard-Palette
QPalette p;
const QColor bg = QColor("#f3f3f3");
const QColor widget = QColor("#ffffff");
const QColor alt = QColor("#e8e8e8");
const QColor hi = QColor("#0078d4");
const QColor hiText = QColor("#ffffff");
const QColor text = QColor("#1e1e1e");
const QColor disabled = QColor("#a0a0a0");
const QColor btn = QColor("#e1e1e1");
const QColor mid = QColor("#c8c8c8");
const QColor dark = QColor("#a0a0a0");
const QColor light = QColor("#ffffff");
const QColor link = QColor("#0078d4");
p.setColor(QPalette::Window, bg);
p.setColor(QPalette::WindowText, text);
p.setColor(QPalette::Base, widget);
p.setColor(QPalette::AlternateBase, alt);
p.setColor(QPalette::Text, text);
p.setColor(QPalette::Button, btn);
p.setColor(QPalette::ButtonText, text);
p.setColor(QPalette::Highlight, hi);
p.setColor(QPalette::HighlightedText, hiText);
p.setColor(QPalette::Link, link);
p.setColor(QPalette::LinkVisited, link.darker(130));
p.setColor(QPalette::Mid, mid);
p.setColor(QPalette::Dark, dark);
p.setColor(QPalette::Light, light);
p.setColor(QPalette::PlaceholderText, disabled);
p.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
p.setColor(QPalette::Disabled, QPalette::Text, disabled);
p.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
return p;
}

29
src/core/ThemeManager.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include <QObject>
#include <QPalette>
// ---------------------------------------------------------------------------
// ThemeManager Schaltet zwischen Hell- und Dunkelmodus um.
// ---------------------------------------------------------------------------
class ThemeManager : public QObject
{
Q_OBJECT
public:
enum class Theme { Light, Dark };
explicit ThemeManager(QObject *parent = nullptr);
void applyTheme(Theme theme);
Theme currentTheme() const;
signals:
void themeChanged(Theme theme);
private:
static QPalette buildDarkPalette();
static QPalette buildLightPalette();
Theme m_currentTheme = Theme::Light;
};