Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jul 27, 2023
1 parent c5161c4 commit 54daf84
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Guitar.pri
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ SOURCES += \
src/common/misc.cpp \
src/darktheme/DarkStyle.cpp \
src/darktheme/NinePatch.cpp \
src/darktheme/StandardStyle.cpp \
src/darktheme/LightStyle.cpp \
src/darktheme/TraditionalWindowsStyleTreeControl.cpp \
src/gpg.cpp \
src/gunzip.cpp \
Expand Down Expand Up @@ -375,7 +375,7 @@ HEADERS += \
src/common/misc.h \
src/darktheme/DarkStyle.h \
src/darktheme/NinePatch.h \
src/darktheme/StandardStyle.h \
src/darktheme/LightStyle.h \
src/darktheme/TraditionalWindowsStyleTreeControl.h \
src/dtl/Diff.hpp \
src/dtl/Diff3.hpp \
Expand Down
2 changes: 1 addition & 1 deletion src/SettingGeneralForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SettingGeneralForm::SettingGeneralForm(QWidget *parent)

langs = languages();

themes.push_back(Languages::Item("standard", tr("Standard")));
themes.push_back(Languages::Item("light", tr("Light")));
themes.push_back(Languages::Item("dark", tr("Dark")));

updateLanguage();
Expand Down
20 changes: 10 additions & 10 deletions src/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@



// StandardTheme
// LightTheme

#include "darktheme/StandardStyle.h"
#include "darktheme/LightStyle.h"

QStyle *StandardTheme::newStyle()
QStyle *LightTheme::newStyle()
{
return new StandardStyle();
return new LightStyle();
}

QImage StandardTheme::graphColorMap()
QImage LightTheme::graphColorMap()
{
QImage image;
image.load(":/image/graphcolor.png");
return image;
}

QPixmap StandardTheme::resource_clear_png()
QPixmap LightTheme::resource_clear_png()
{
return QPixmap(":/image/clear.png");
}

QPixmap StandardTheme::resource_maximize_png()
QPixmap LightTheme::resource_maximize_png()
{
return QPixmap(":/image/maximize.png");
}

QPixmap StandardTheme::resource_menu_png()
QPixmap LightTheme::resource_menu_png()
{
return QPixmap(":/image/menu.png");
}

ThemePtr createStandardTheme()
ThemePtr createLightTheme()
{
AbstractTheme *p = new StandardTheme;
AbstractTheme *p = new LightTheme;
p->text_editor_theme = TextEditorTheme::Light();

p->dialog_header_frame_bg = Qt::white;
Expand Down
6 changes: 3 additions & 3 deletions src/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ class AbstractTheme {

using ThemePtr = std::shared_ptr<AbstractTheme>;

class StandardTheme : public AbstractTheme {
class LightTheme : public AbstractTheme {
public:
StandardTheme() = default;
LightTheme() = default;
QStyle *newStyle() override;
QImage graphColorMap() override;
QPixmap resource_clear_png() override;
QPixmap resource_maximize_png() override;
QPixmap resource_menu_png() override;
};
ThemePtr createStandardTheme();
ThemePtr createLightTheme();

#ifdef USE_DARK_THEME

Expand Down
19 changes: 9 additions & 10 deletions src/darktheme/DarkStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,11 @@ int DarkStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const
break;
case PM_IndicatorHeight:
case PM_IndicatorWidth:
#ifdef Q_OS_WIN
val = 11;
break;
#endif
// fallthru
case PM_ExclusiveIndicatorHeight:
case PM_ExclusiveIndicatorWidth:
val = 16;
Expand Down Expand Up @@ -1316,12 +1321,6 @@ void DarkStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *option, Q
}
#endif
if (pe == PE_IndicatorCheckBox) {
// if (option->state & State_NoChange) {
// p->setPen(option->palette.windowText().color());
// p->fillRect(option->rect, option->palette.brush(QPalette::Button));
// p->drawRect(option->rect);
// p->drawLine(option->rect.topLeft(), option->rect.bottomRight());
// } else
{
QRect rect = indicatorRect(option, widget, option->rect);
int x = rect.x();
Expand All @@ -1335,7 +1334,7 @@ void DarkStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *option, Q
p->setPen(QPen(option->palette.windowText(), 2));
int w = extent - 4;
int h = extent - 4;
p->setClipRect(0, 0, w, h);
p->setClipRect(2, 2, w -3, h -3);
int x0 = w - 1;
int y0 = 1;
int n = w * 0.6;
Expand All @@ -1352,9 +1351,9 @@ void DarkStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *option, Q
return;
}
if (pe == PE_IndicatorRadioButton) {
QRectF rect = indicatorRect(option, widget, option->rect);
QRect rect = indicatorRect(option, widget, option->rect);
p->setPen(option->palette.dark().color());
drawShadeEllipse(p, option->rect, option->palette, QStyle::State_Sunken);
drawShadeEllipse(p, rect, option->palette, QStyle::State_Sunken);
if (option->state & (State_Sunken | State_On)) {
const int N = 3;
rect.adjust(N, N, -N, -N);
Expand Down Expand Up @@ -2038,7 +2037,7 @@ void DarkStyle::drawControl(ControlElement ce, const QStyleOption *option, QPain

QColor color(0, 128, 255);

bool horz = true; //@ = (o->orientation == Qt::Horizontal);
bool horz = o->state & QStyle::State_Horizontal;

QString key;
QImage const *image;
Expand Down
34 changes: 34 additions & 0 deletions src/darktheme/DarkStylePlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "DarkStyle.h"
#include "DarkStylePlugin.h"
#include "LightStyle.h"
#include "TraditionalWindowsStyleTreeControl.h"

#include <QApplication>

QStyle *DarkStylePlugin::createLightStyle()
{
return new LightStyle();
}

QStyle *DarkStylePlugin::createDarkStyle()
{
return new DarkStyle();
}

void DarkStylePlugin::applyDarkStyle(QApplication *app)
{
QStyle *style = createDarkStyle();
app->setStyle(style);
app->setPalette(style->standardPalette());
}

void DarkStylePlugin::applyLightStyle(QApplication *app)
{
QStyle *style = createLightStyle();
app->setStyle(style);
#ifndef Q_OS_WIN
app->setPalette(style->standardPalette());
#endif
}


22 changes: 22 additions & 0 deletions src/darktheme/DarkStylePlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef DARKSTYLEPLUGIN_H
#define DARKSTYLEPLUGIN_H

#include "../DarkStyleInterface.h"

#include <QObject>

class TraditionalWindowsStyleTreeControl;

class DarkStylePlugin : public QObject, public DarkStyleInterface {
Q_OBJECT
Q_PLUGIN_METADATA(IID "jp.soramimi.DarkStylePlugin" FILE "darkstyleplugin.json")
Q_INTERFACES(DarkStyleInterface)
private:
QStyle *createLightStyle();
QStyle *createDarkStyle();
public:
void applyDarkStyle(QApplication *app) override;
void applyLightStyle(QApplication *app) override;
};

#endif // DARKSTYLEPLUGIN_H
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "StandardStyle.h"
#include "LightStyle.h"

void StandardStyle::drawPrimitive(PrimitiveElement element, QStyleOption const *option, QPainter *painter, QWidget const *widget) const
void LightStyle::drawPrimitive(PrimitiveElement element, QStyleOption const *option, QPainter *painter, QWidget const *widget) const
{
if (element == QStyle::PE_IndicatorBranch) {
if (legacy_windows_.drawPrimitive(element, option, painter, widget)) {
Expand Down
12 changes: 5 additions & 7 deletions src/darktheme/StandardStyle.h → src/darktheme/LightStyle.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#ifndef STANDARDSTYLE_H
#define STANDARDSTYLE_H
#ifndef LIGHTSTYLE_H
#define LIGHTSTYLE_H

#include "TraditionalWindowsStyleTreeControl.h"

#include <QProxyStyle>


class StandardStyle : public QProxyStyle {
class LightStyle : public QProxyStyle {
private:
TraditionalWindowsStyleTreeControl legacy_windows_;
public:
StandardStyle()
LightStyle()
: QProxyStyle(nullptr)
{
}
void drawPrimitive(PrimitiveElement element, QStyleOption const *option, QPainter *painter, QWidget const *widget = nullptr) const override;
};

#endif // STANDARDSTYLE_H
#endif // LIGHTSTYLE_H
3 changes: 3 additions & 0 deletions src/darktheme/TraditionalWindowsStyleTreeControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class QPainter;
class QWidget;

/**
* @brief Windows95スタイルのツリーコントロールの見た目にする
*/
class TraditionalWindowsStyleTreeControl {
private:
QBrush br_branch;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(int argc, char *argv[])
a.setStyle(global->theme->newStyle());
a.setPalette(a.style()->standardPalette());
} else {
global->theme = createStandardTheme();
global->theme = createLightTheme();
a.setStyle(global->theme->newStyle());
#ifndef Q_OS_WIN
a.setPalette(a.style()->standardPalette());
Expand Down

0 comments on commit 54daf84

Please sign in to comment.