diff --git a/logdoctor/CMakeLists.txt b/logdoctor/CMakeLists.txt index 78949ec8..091c21d1 100644 --- a/logdoctor/CMakeLists.txt +++ b/logdoctor/CMakeLists.txt @@ -172,6 +172,8 @@ set(PROJECT_SOURCES tools/crapnote/crapnote.ui tools/crapnote/crapnote.h tools/crapnote/crapnote.cpp + tools/crapnote/modules/stylesheets.h + tools/crapnote/modules/stylesheets.cpp games/game_dialog.ui games/game_dialog.h diff --git a/logdoctor/mainwindow.cpp b/logdoctor/mainwindow.cpp index 83b7ea5b..d63b5a18 100644 --- a/logdoctor/mainwindow.cpp +++ b/logdoctor/mainwindow.cpp @@ -2268,9 +2268,7 @@ void MainWindow::menu_actionBlockNote_triggered() this->crapnote->activateWindow(); } else { - this->crapnote.reset( new Crapnote() ); - this->crapnote->setTextFont( this->TB.getFont() ); - this->crapnote->setColorScheme( this->TB.getColorSchemeID() ); + this->crapnote.reset( new Crapnote( this->TB.getColorSchemeID(), this->TB.getFont() ) ); this->crapnote->show(); } } diff --git a/logdoctor/tools/crapnote/crapnote.cpp b/logdoctor/tools/crapnote/crapnote.cpp index a18bfab2..c8710652 100644 --- a/logdoctor/tools/crapnote/crapnote.cpp +++ b/logdoctor/tools/crapnote/crapnote.cpp @@ -2,53 +2,61 @@ #include "crapnote.h" #include "ui_crapnote.h" +#include "globals/global_configs.h" + +#include "modules/stylesheets.h" + #include "modules/exceptions.h" -Crapnote::Crapnote(QWidget *parent) +Crapnote::Crapnote( const int color_scheme_id, QFont font, QWidget* parent ) : QWidget{ parent } , ui{ new Ui::Crapnote } { ui->setupUi(this); + + this->setColorScheme( color_scheme_id ); + this->setTextFont( font ); } -void Crapnote::setTextFont( const QFont& font ) noexcept +void Crapnote::setTextFont( QFont font ) noexcept { - QFont f{ font }; - f.setPointSize( this->font_size ); - this->ui->textEdit->setFont( f ); + font.setPointSize( this->font_size ); + this->ui->text_Note->setFont( font ); } -void Crapnote::setColorScheme( const int& color_scheme_id ) +void Crapnote::setColorScheme( const int color_scheme_id ) { - QColor b, t; - // update the colors palette - switch ( color_scheme_id ) { - case 0: - this->ui->textEdit->setPalette( QPalette() ); - break; - case 1: - // breeze - b = QColor(255,198,102); - t = QColor(31,28,27); - this->ui->textEdit->setPalette( QPalette(t,b,b,b,b,t,b) ); - break; - case 2: - // monokai - b = QColor(166,226,46); - t = QColor(39,40,34); - this->ui->textEdit->setPalette( QPalette(t,b,b,b,b,t,b) ); - break; - case 3: - // radical - b = QColor(20,19,34); - t = QColor(213,53,143); - this->ui->textEdit->setPalette( QPalette(t,b,b,b,b,t,b) ); - break; - default: - // wrong - throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( color_scheme_id ), true ); // leave un-catched + if ( GlobalConfigs::window_theme != WindowTheme::Native ) { + this->setStyleSheet( StyleSec::Crapnote::getStyleSheet( color_scheme_id ) ); + } else { + this->setStyleSheet(""); + QPalette p; + // update the colors palette + switch ( color_scheme_id ) { + case 0: + break; + case 1: + // breeze + p.setColor( QPalette::Base, QColor( 255, 198, 102 ) ); + p.setColor( QPalette::Text, QColor( 31, 28, 27 ) ); + break; + case 2: + // monokai + p.setColor( QPalette::Base, QColor( 166, 226, 46 ) ); + p.setColor( QPalette::Text, QColor( 39, 40, 34 ) ); + break; + case 3: + // radical + p.setColor( QPalette::Base, QColor( 20, 19, 34 ) ); + p.setColor( QPalette::Text, QColor( 213, 53, 143 ) ); + break; + default: + // wrong + throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( color_scheme_id ), true ); // leave un-catched + } + this->ui->text_Note->setPalette( p ); } } @@ -56,7 +64,7 @@ void Crapnote::setColorScheme( const int& color_scheme_id ) void Crapnote::on_spinBox_FontSize_valueChanged(int arg1) { this->font_size = arg1; - this->setTextFont( this->ui->textEdit->font() ); + this->setTextFont( this->ui->text_Note->font() ); } diff --git a/logdoctor/tools/crapnote/crapnote.h b/logdoctor/tools/crapnote/crapnote.h index 0780e16a..7ac7abe9 100644 --- a/logdoctor/tools/crapnote/crapnote.h +++ b/logdoctor/tools/crapnote/crapnote.h @@ -19,13 +19,13 @@ class Crapnote final : public QWidget Q_OBJECT public: - explicit Crapnote( QWidget* parent=nullptr ); + explicit Crapnote( const int color_scheme_id, QFont font, QWidget* parent=nullptr ); //! Sets the given font - void setTextFont( const QFont& font ) noexcept; + void setTextFont( QFont font ) noexcept; //! Sets the given color-scheme - void setColorScheme( const int& color_scheme_id ); + void setColorScheme( const int color_scheme_id ); private slots: diff --git a/logdoctor/tools/crapnote/crapnote.ui b/logdoctor/tools/crapnote/crapnote.ui index 0f948dc7..1e12736e 100644 --- a/logdoctor/tools/crapnote/crapnote.ui +++ b/logdoctor/tools/crapnote/crapnote.ui @@ -161,7 +161,7 @@ 16 - + diff --git a/logdoctor/tools/crapnote/modules/stylesheets.cpp b/logdoctor/tools/crapnote/modules/stylesheets.cpp new file mode 100644 index 00000000..6a0eda29 --- /dev/null +++ b/logdoctor/tools/crapnote/modules/stylesheets.cpp @@ -0,0 +1,172 @@ + +#include "stylesheets.h" + +#include "globals/global_configs.h" + +#include "modules/exceptions.h" + +#include +#include + +#include + + +namespace /*private*/ +{ + +enum StyleId : uint32_t { + TEXT, + WINDOW, + BORDER_PRIMARY, + BORDER_SECONDARY, + SPINBOX_TEXT, + SPINBOX_BASE, + SPINBOX_BASE_FOCUS, + SPINBOX_BASE_SELECTION +}; + +using StyleMap = std::unordered_map; + +StyleMap makeStyleMap() +{ + switch ( GlobalConfigs::window_theme ) { + case WindowTheme::Light: + return { + {TEXT, + "rgb( 22, 11, 0 )"}, + {WINDOW, + "rgb( 230, 230, 230 )"}, + {BORDER_PRIMARY, + "rgb( 205, 200, 200 )"}, + {BORDER_SECONDARY, + "rgb( 124, 119, 119 )"}, + {SPINBOX_TEXT, + "rgb( 88, 80, 80 )"}, + {SPINBOX_BASE, + "rgb( 216, 216, 216 )"}, + {SPINBOX_BASE_FOCUS, + "rgb( 209, 209, 209 )"}, + {SPINBOX_BASE_SELECTION, + "rgb( 153, 211, 255 )"} + }; + case WindowTheme::Dark: + return { + {TEXT, + "rgb( 248, 248, 248 )"}, + {WINDOW, + "rgb( 27, 30, 33 )"}, + {BORDER_PRIMARY, + "rgb( 50, 55, 59 )"}, + {BORDER_SECONDARY, + "rgb( 107, 107, 107 )"}, + {SPINBOX_TEXT, + "rgb( 210, 210, 210 )"}, + {SPINBOX_BASE, + "rgb( 41, 44, 44 )"}, + {SPINBOX_BASE_FOCUS, + "rgb( 57, 60, 60 )"}, + {SPINBOX_BASE_SELECTION, + "rgb( 47, 99, 47 )"} + }; + default: + throw GenericException( "Unexpected WindowTheme: "+std::to_string(static_cast(GlobalConfigs::window_theme)), true ); + } +} + +} // namespacce (private) + + +namespace StyleSec::Crapnote +{ + +QString getStyleSheet( const int color_scheme ) +{ + QString icons_theme; + switch ( GlobalConfigs::window_theme ) { + case WindowTheme::Native: + return ""; + case WindowTheme::Light: + icons_theme = "dark"; + break; + case WindowTheme::Dark: + icons_theme = "light"; + break; + default: + throw GenericException( "Unexpected WindowTheme: "+std::to_string(static_cast(GlobalConfigs::window_theme)), true ); + } + QString note_bg, note_txt; + // update the colors palette + switch ( color_scheme ) { + case 0: + if ( GlobalConfigs::window_theme == WindowTheme::Light ) { + note_bg = "rgb( 255, 255, 255 )"; + note_txt = "rgb( 0, 0, 0 )"; + } else { + note_bg = "rgb( 0, 0, 0 )"; + note_txt = "rgb( 255, 255, 255 )"; + } + break; + case 1: + // breeze + note_bg = "rgb( 255, 198, 102 )"; + note_txt = "rgb( 31, 28, 27 )"; + break; + case 2: + // monokai + note_bg = "rgb( 166, 226, 46 )"; + note_txt = "rgb( 39, 40, 34 )"; + break; + case 3: + // radical + note_bg = "rgb( 20, 19, 34 )"; + note_txt = "rgb( 213, 53, 143 )"; + break; + default: + // wrong + throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( color_scheme ), true ); // leave un-catched + } + + const StyleMap style{ makeStyleMap() }; + return + "* {" + " color: "% style.at(TEXT) %";" + "}" + "QWidget#Crapnote {" + " background-color: "% style.at(WINDOW) %";" + "}" + "QFrame {" + " background-color: transparent;" + "}" + "QTextEdit {" + " color: "% note_txt %";" + " background-color: "% note_bg %";" + "}" + "QPushButton {" + " border: 1px solid "% style.at(BORDER_PRIMARY) %";" + " border-radius: 16px;" + " background-color: transparent;" + "}" + "QPushButton:hover {" + " border: 1px solid "% style.at(BORDER_SECONDARY) %";" + "}" + "QSpinBox {" + " border: 0px solid;" + " border-radius: 4px;" + " color: "% style.at(SPINBOX_TEXT) %";" + " background-color: "% style.at(SPINBOX_BASE) %";" + " selection-color: "% style.at(SPINBOX_TEXT) %";" + " selection-background-color: "% style.at(SPINBOX_BASE_SELECTION) %";" + "}" + "QSpinBox::focus {" + " border: 1px solid "% style.at(BORDER_SECONDARY) %";" + " background-color: "% style.at(SPINBOX_BASE_FOCUS) %";" + "}" + "QPushButton#button_FontSize_Minus {" + " image: url(:/icons/icons/"% icons_theme %"/list_rem.png);" + "}" + "QPushButton#button_FontSize_Plus {" + " image: url(:/icons/icons/"% icons_theme %"/list_add.png);" + "}"; +} + +} // namespacce StyleSec::Crapnote diff --git a/logdoctor/tools/crapnote/modules/stylesheets.h b/logdoctor/tools/crapnote/modules/stylesheets.h new file mode 100644 index 00000000..6fef42a4 --- /dev/null +++ b/logdoctor/tools/crapnote/modules/stylesheets.h @@ -0,0 +1,16 @@ +#ifndef LOGDOCTOR__CRAPNOTE__STYLESHEETS_H +#define LOGDOCTOR__CRAPNOTE__STYLESHEETS_H + + +class QString; + + +namespace StyleSec::Crapnote +{ + +QString getStyleSheet( const int color_scheme ); + +} // namespacce StyleSec::Crapnote + + +#endif // LOGDOCTOR__CRAPNOTE__STYLESHEETS_H