Version upgrade 4.00 #45
14 changed files with 180 additions and 159 deletions
|
@ -50,7 +50,7 @@
|
|||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow{ parent }
|
||||
, ui{ new Ui::MainWindow }
|
||||
, tb_color_schemes{ ColorSec::getColorSchemes() }
|
||||
, tb_colors_schemes{ ColorSec::getColorSchemes() }
|
||||
, colors{ ColorSec::getColors() }
|
||||
{
|
||||
//////////////////
|
||||
|
@ -95,7 +95,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
this->ui->mainwidget->setFont( this->fonts.at( "main_big" ) );
|
||||
|
||||
// TextBrowser for the LogFiles
|
||||
this->TB.setColorScheme( 1, this->tb_color_schemes.at( 1 ) );
|
||||
this->TB.setColorScheme( ColorsScheme::Breeze, this->tb_colors_schemes.at( ColorsScheme::Breeze ) );
|
||||
this->TB.setFont( this->fonts.at( "main" ) );
|
||||
this->ui->textLogFiles->setFont( this->TB.getFont() );
|
||||
|
||||
|
@ -211,7 +211,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
// text browser
|
||||
this->ui->box_ConfTextBrowser_Font->setCurrentText( this->TB.getFontFamily() );
|
||||
this->ui->checkBox_ConfTextBrowser_WideLines->setChecked( this->TB.getWideLinesUsage() );
|
||||
this->ui->box_ConfTextBrowser_ColorScheme->setCurrentIndex( this->TB.getColorSchemeID() );
|
||||
this->ui->box_ConfTextBrowser_ColorScheme->setCurrentIndex( static_cast<int>(this->TB.getColorSchemeID()) );
|
||||
this->refreshTextBrowserPreview();
|
||||
// charts
|
||||
this->ui->box_ConfCharts_Theme->setCurrentIndex( static_cast<int>(GlobalConfigs::charts_theme) );
|
||||
|
@ -519,7 +519,9 @@ void MainWindow::readConfigs()
|
|||
|
||||
} else if ( var == "ColorScheme" ) {
|
||||
try {
|
||||
this->on_box_ConfTextBrowser_ColorScheme_currentIndexChanged( std::stoi( val ) );
|
||||
const int v{ std::stoi( val ) };
|
||||
GlobalConfigs::colors_scheme = static_cast<ColorsScheme>( v );
|
||||
this->on_box_ConfTextBrowser_ColorScheme_currentIndexChanged( v );
|
||||
} catch ( const std::exception& ) {
|
||||
invalid_lines.emplaceBack( QString::fromStdString( line ) );
|
||||
}
|
||||
|
@ -966,7 +968,7 @@ void MainWindow::writeConfigs()
|
|||
configs += "\n\n[TextBrowser]";
|
||||
configs += "\nFont=" + std::to_string( this->ui->box_ConfTextBrowser_Font->currentIndex() );
|
||||
configs += "\nWideLines=" + this->b2s.at( this->TB.getWideLinesUsage() );
|
||||
configs += "\nColorScheme=" + std::to_string( this->TB.getColorSchemeID() );
|
||||
configs += "\nColorScheme=" + std::to_string( static_cast<themes_t>(GlobalConfigs::colors_scheme) );
|
||||
//// CRAPLOG ////
|
||||
configs += "\n\n[Craplog]";
|
||||
configs += "\nCraplogDialogsLevel=" + toString( this->craplog.getDialogsLevel() );
|
||||
|
@ -4509,9 +4511,11 @@ void MainWindow::on_checkBox_ConfTextBrowser_WideLines_clicked(bool checked)
|
|||
}
|
||||
void MainWindow::on_box_ConfTextBrowser_ColorScheme_currentIndexChanged(int index)
|
||||
{
|
||||
this->TB.setColorScheme( index, this->tb_color_schemes.at( index ) );
|
||||
ColorsScheme cs{ static_cast<ColorsScheme>( index ) };
|
||||
GlobalConfigs::colors_scheme = cs;
|
||||
this->TB.setColorScheme( cs, this->tb_colors_schemes.at( cs ) );
|
||||
if ( !this->crapnote.isNull() ) {
|
||||
this->crapnote->setColorScheme( index );
|
||||
this->crapnote->setColorScheme( cs );
|
||||
}
|
||||
this->refreshTextBrowserPreview();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class QTranslator;
|
|||
class QTreeWidgetItem;
|
||||
|
||||
enum class LogField;
|
||||
enum class ColorsScheme : unsigned char;
|
||||
|
||||
|
||||
namespace Ui {
|
||||
|
@ -701,7 +702,7 @@ private:
|
|||
};
|
||||
|
||||
// color schemes
|
||||
const std::unordered_map<int, std::unordered_map<std::string, QString>> tb_color_schemes;
|
||||
const std::unordered_map<ColorsScheme, std::unordered_map<std::string, QString>> tb_colors_schemes;
|
||||
|
||||
// colors
|
||||
const std::unordered_map<std::string, QColor> colors;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include "craphelp.h"
|
||||
#include "ui_craphelp.h"
|
||||
|
||||
#include "globals/global_configs.h"
|
||||
|
||||
#include "modules/exceptions.h"
|
||||
|
||||
#include "utilities/io.h"
|
||||
|
@ -15,11 +17,10 @@ Craphelp::Craphelp(QWidget *parent)
|
|||
}
|
||||
|
||||
|
||||
std::unordered_map<std::string, QString> Craphelp::getColorScheme( const int scheme_id ) const
|
||||
std::unordered_map<std::string, QString> Craphelp::getColorScheme( const ColorsScheme scheme_id ) const
|
||||
{
|
||||
switch ( scheme_id ) {
|
||||
case 0:
|
||||
// none
|
||||
case ColorsScheme::None:
|
||||
return {
|
||||
{"background", ""},
|
||||
{"text", ""},
|
||||
|
@ -27,8 +28,7 @@ std::unordered_map<std::string, QString> Craphelp::getColorScheme( const int sch
|
|||
{"h3", ""},
|
||||
{"code", ""},
|
||||
{"link", ""} };
|
||||
case 1:
|
||||
// breeze
|
||||
case ColorsScheme::Breeze:
|
||||
return {
|
||||
{"background", "#ffffff"},
|
||||
{"text", "#1f1c1b"},
|
||||
|
@ -38,8 +38,7 @@ std::unordered_map<std::string, QString> Craphelp::getColorScheme( const int sch
|
|||
{"code", "#644a9b"},
|
||||
{"link", "#d24f4f"} };
|
||||
|
||||
case 2:
|
||||
// monokai
|
||||
case ColorsScheme::Monokai:
|
||||
return {
|
||||
{"background", "#272822"},
|
||||
{"text", "#d1d1cb"},
|
||||
|
@ -49,8 +48,7 @@ std::unordered_map<std::string, QString> Craphelp::getColorScheme( const int sch
|
|||
{"code", "#57adbc"},
|
||||
{"link", "#f92672"} };
|
||||
|
||||
case 3:
|
||||
// radical
|
||||
case ColorsScheme::Radical:
|
||||
return {
|
||||
{"background", "#141322"},
|
||||
{"text", "#a8c0c2"},
|
||||
|
@ -62,18 +60,18 @@ std::unordered_map<std::string, QString> Craphelp::getColorScheme( const int sch
|
|||
|
||||
default:
|
||||
// wrong, shouldn't be here
|
||||
throw GenericException( "Unexpected ColorScheme ID: "+std::to_string( scheme_id ), true ); // leave un-catched
|
||||
throw GenericException( "Unexpected ColorScheme ID: "+std::to_string( static_cast<themes_t>(scheme_id) ), true ); // leave un-catched
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Craphelp::helpLogsFormat( const std::string& path, const QFont& font, const int color_scheme_id ) const noexcept
|
||||
void Craphelp::helpLogsFormat( const std::string& path, const QFont& font, const ColorsScheme colors_scheme_id ) const noexcept
|
||||
{
|
||||
std::unordered_map<std::string, QString> color_scheme{ this->getColorScheme( color_scheme_id ) };
|
||||
std::unordered_map<std::string, QString> colors_scheme{ this->getColorScheme( colors_scheme_id ) };
|
||||
std::string aux;
|
||||
IOutils::readFile( path, aux );
|
||||
QString content;
|
||||
if ( color_scheme_id == 0 ) {
|
||||
if ( colors_scheme_id == ColorsScheme::None ) {
|
||||
// remove the style for the colors
|
||||
while (true) {
|
||||
const size_t start{ aux.find( "background-color:" ) };
|
||||
|
@ -96,13 +94,13 @@ void Craphelp::helpLogsFormat( const std::string& path, const QFont& font, const
|
|||
} else {
|
||||
// replace with colors
|
||||
content = QString::fromStdString( aux )
|
||||
.replace( "$BG$", color_scheme.at("background") )
|
||||
.replace( "$TEXT$", color_scheme.at("text") )
|
||||
.replace( "$IT$", color_scheme.at("italic") )
|
||||
.replace( "$H1$", color_scheme.at("h1") )
|
||||
.replace( "$H3$", color_scheme.at("h3") )
|
||||
.replace( "$CODE$", color_scheme.at("code") )
|
||||
.replace( "$LINK$", color_scheme.at("link") );
|
||||
.replace( "$BG$", colors_scheme.at("background") )
|
||||
.replace( "$TEXT$", colors_scheme.at("text") )
|
||||
.replace( "$IT$", colors_scheme.at("italic") )
|
||||
.replace( "$H1$", colors_scheme.at("h1") )
|
||||
.replace( "$H3$", colors_scheme.at("h3") )
|
||||
.replace( "$CODE$", colors_scheme.at("code") )
|
||||
.replace( "$LINK$", colors_scheme.at("link") );
|
||||
}
|
||||
// show the content
|
||||
this->ui->helpBrowser->setText( content );
|
||||
|
@ -111,9 +109,9 @@ void Craphelp::helpLogsFormat( const std::string& path, const QFont& font, const
|
|||
}
|
||||
|
||||
|
||||
void Craphelp::helpLogsFormatDefault( std::string_view file_name, const QFont& font, const int color_scheme_id ) const noexcept
|
||||
void Craphelp::helpLogsFormatDefault( std::string_view file_name, const QFont& font, const ColorsScheme colors_scheme_id ) const noexcept
|
||||
{
|
||||
std::unordered_map<std::string, QString> color_scheme = this->getColorScheme( color_scheme_id );
|
||||
std::unordered_map<std::string, QString> colors_scheme = this->getColorScheme( colors_scheme_id );
|
||||
std::string aux;
|
||||
if ( file_name == "apache_format" ) {
|
||||
this->defaultApacheFormat( aux );
|
||||
|
@ -123,7 +121,7 @@ void Craphelp::helpLogsFormatDefault( std::string_view file_name, const QFont& f
|
|||
this->defaultIisFormat( aux );
|
||||
}
|
||||
QString content;
|
||||
if ( color_scheme_id == 0 ) {
|
||||
if ( colors_scheme_id == ColorsScheme::None ) {
|
||||
// remove the style for the colors
|
||||
while (true) {
|
||||
const size_t start{ aux.find( "background-color:" ) };
|
||||
|
@ -146,13 +144,13 @@ void Craphelp::helpLogsFormatDefault( std::string_view file_name, const QFont& f
|
|||
} else {
|
||||
// replace with colors
|
||||
content = QString::fromStdString( aux )
|
||||
.replace( "$BG$", color_scheme.at("background") )
|
||||
.replace( "$TEXT$", color_scheme.at("text") )
|
||||
.replace( "$IT$", color_scheme.at("italic") )
|
||||
.replace( "$H1$", color_scheme.at("h1") )
|
||||
.replace( "$H3$", color_scheme.at("h3") )
|
||||
.replace( "$CODE$", color_scheme.at("code") )
|
||||
.replace( "$LINK$", color_scheme.at("link") );
|
||||
.replace( "$BG$", colors_scheme.at("background") )
|
||||
.replace( "$TEXT$", colors_scheme.at("text") )
|
||||
.replace( "$IT$", colors_scheme.at("italic") )
|
||||
.replace( "$H1$", colors_scheme.at("h1") )
|
||||
.replace( "$H3$", colors_scheme.at("h3") )
|
||||
.replace( "$CODE$", colors_scheme.at("code") )
|
||||
.replace( "$LINK$", colors_scheme.at("link") );
|
||||
}
|
||||
// show the content
|
||||
this->ui->helpBrowser->setText( content );
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <unordered_map>
|
||||
|
||||
|
||||
enum class ColorsScheme : unsigned char;
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class Craphelp;
|
||||
}
|
||||
|
@ -27,9 +30,9 @@ public:
|
|||
/*!
|
||||
\param path The path of the file resource to be displayed
|
||||
\param font The font to be used
|
||||
\param color_scheme_id The ID of the color-scheme to be used
|
||||
\param colors_scheme_id The ID of the color-scheme to be used
|
||||
*/
|
||||
void helpLogsFormat( const std::string& path, const QFont& font, const int color_scheme_id ) const noexcept;
|
||||
void helpLogsFormat( const std::string& path, const QFont& font, const ColorsScheme colors_scheme_id ) const noexcept;
|
||||
|
||||
//! Provides help about log formats
|
||||
/*!
|
||||
|
@ -37,14 +40,14 @@ public:
|
|||
for the currently selected locale was not found or unreadable
|
||||
\param file_name The file that was supposed to be shown
|
||||
\param font The font to be used
|
||||
\param color_scheme_id The ID of the color-scheme to be used
|
||||
\param colors_scheme_id The ID of the color-scheme to be used
|
||||
*/
|
||||
void helpLogsFormatDefault( std::string_view file_name, const QFont& font, const int color_scheme_id ) const noexcept;
|
||||
void helpLogsFormatDefault( std::string_view file_name, const QFont& font, const ColorsScheme colors_scheme_id ) const noexcept;
|
||||
|
||||
private:
|
||||
QSharedPointer<Ui::Craphelp> ui;
|
||||
|
||||
std::unordered_map<std::string, QString> getColorScheme( const int scheme_id ) const;
|
||||
std::unordered_map<std::string, QString> getColorScheme( const ColorsScheme scheme_id ) const;
|
||||
|
||||
void defaultApacheFormat( std::string& str ) const noexcept;
|
||||
void defaultNginxFormat( std::string& str ) const noexcept;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "tb.h"
|
||||
|
||||
#include "globals/global_configs.h"
|
||||
|
||||
|
||||
// getters
|
||||
bool TextBrowser::getWideLinesUsage() const noexcept
|
||||
|
@ -8,14 +10,14 @@ bool TextBrowser::getWideLinesUsage() const noexcept
|
|||
return this->wide_lines;
|
||||
}
|
||||
|
||||
int TextBrowser::getColorSchemeID() const noexcept
|
||||
ColorsScheme TextBrowser::getColorSchemeID() const noexcept
|
||||
{
|
||||
return this->color_scheme_id;
|
||||
return this->colors_scheme_id;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, QString>& TextBrowser::getColorScheme() const noexcept
|
||||
{
|
||||
return this->color_scheme;
|
||||
return this->colors_scheme;
|
||||
}
|
||||
|
||||
/*const int& TextBrowser::getFontSize() noexcept
|
||||
|
@ -35,15 +37,15 @@ const QFont& TextBrowser::getFont() const noexcept
|
|||
|
||||
|
||||
// setters
|
||||
void TextBrowser::setWideLinesUsage( const bool& use_wide_lines ) noexcept
|
||||
void TextBrowser::setWideLinesUsage( const bool use_wide_lines ) noexcept
|
||||
{
|
||||
this->wide_lines = use_wide_lines;
|
||||
}
|
||||
|
||||
void TextBrowser::setColorScheme( const int& color_scheme_id, const std::unordered_map<std::string, QString>& color_scheme ) noexcept
|
||||
void TextBrowser::setColorScheme( const ColorsScheme colors_scheme_id, const std::unordered_map<std::string, QString>& colors_scheme ) noexcept
|
||||
{
|
||||
this->color_scheme_id = color_scheme_id;
|
||||
this->color_scheme = color_scheme;
|
||||
this->colors_scheme_id = colors_scheme_id;
|
||||
this->colors_scheme = colors_scheme;
|
||||
}
|
||||
|
||||
/*void TextBrowser::setFontSize( const int& font_size ) noexcept
|
||||
|
@ -66,13 +68,15 @@ void TextBrowser::setFont( const QFont& font ) noexcept
|
|||
// preview
|
||||
void TextBrowser::makePreview( QString& content ) const noexcept
|
||||
{
|
||||
const bool using_colors_scheme{ this->colors_scheme_id != ColorsScheme::None };
|
||||
|
||||
const QString span_template{ QStringLiteral("<span style=\"color:%1\">") };
|
||||
|
||||
content += "<!DOCTYPE html><html><head></head><body";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += QStringLiteral(" style=\"background:%1; color:%2\"")
|
||||
.arg( this->color_scheme.at("background"),
|
||||
this->color_scheme.at("text") );
|
||||
.arg( this->colors_scheme.at("background"),
|
||||
this->colors_scheme.at("text") );
|
||||
}
|
||||
content += ">";
|
||||
/*if ( this->wide_lines ) {
|
||||
|
@ -82,81 +86,81 @@ void TextBrowser::makePreview( QString& content ) const noexcept
|
|||
content += "<p>";
|
||||
|
||||
content += "<b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("time") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("time") );
|
||||
}
|
||||
content += "2000-01-01 23:59:59";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>";
|
||||
|
||||
content += " <b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("req") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("req") );
|
||||
}
|
||||
content += "HTTP/1.1 GET /index.php query=x";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>";
|
||||
|
||||
content += " <b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("res") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("res") );
|
||||
}
|
||||
content += "404</b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>";
|
||||
|
||||
content += " <b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("x") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("x") );
|
||||
}
|
||||
content += "123 1234 1000";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>";
|
||||
|
||||
content += " \"<b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("x") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("x") );
|
||||
}
|
||||
content += "http://www.referrer.site";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>\"";
|
||||
|
||||
content += " \"<b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("x") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("x") );
|
||||
}
|
||||
content += "aCookie=abc123";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>\"";
|
||||
|
||||
content += " \"<b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("ua") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("ua") );
|
||||
}
|
||||
content += "UserAgent/3.0 (Details stuff) Info/123";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>\"";
|
||||
|
||||
content += " <b>";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
content += span_template.arg( this->color_scheme.at("ip") );
|
||||
if ( using_colors_scheme ) {
|
||||
content += span_template.arg( this->colors_scheme.at("ip") );
|
||||
}
|
||||
content += "192.168.1.123";
|
||||
if ( this->color_scheme_id > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
content += "</span>";
|
||||
}
|
||||
content += "</b>";
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#include <unordered_map>
|
||||
|
||||
|
||||
enum class ColorsScheme : unsigned char;
|
||||
|
||||
|
||||
//! TextBrowser
|
||||
/*!
|
||||
Perform operations for files visualization
|
||||
|
@ -23,7 +26,7 @@ public:
|
|||
bool getWideLinesUsage() const noexcept;
|
||||
|
||||
//! Returns the ID of the color scheme in use
|
||||
int getColorSchemeID() const noexcept;
|
||||
ColorsScheme getColorSchemeID() const noexcept;
|
||||
|
||||
//! Returns the color scheme in use
|
||||
const std::unordered_map<std::string, QString>& getColorScheme() const noexcept;
|
||||
|
@ -41,10 +44,10 @@ public:
|
|||
//// SETTERS ////
|
||||
|
||||
//! Sets whether to use wide lines or not
|
||||
void setWideLinesUsage( const bool& use_wide_lines ) noexcept;
|
||||
void setWideLinesUsage( const bool use_wide_lines ) noexcept;
|
||||
|
||||
//! Stes the given color scheme as the one in use
|
||||
void setColorScheme( const int& color_scheme_id, const std::unordered_map<std::string, QString>& color_scheme ) noexcept;
|
||||
void setColorScheme( const ColorsScheme colors_scheme_id, const std::unordered_map<std::string, QString>& colors_scheme ) noexcept;
|
||||
|
||||
/*void setFontSize( const int& font_size ) noexcept;
|
||||
void setFontFamily( const QString& font_family ) noexcept;*/
|
||||
|
@ -66,8 +69,8 @@ public:
|
|||
private:
|
||||
|
||||
bool wide_lines{ false };
|
||||
int color_scheme_id{ 1 };
|
||||
std::unordered_map<std::string, QString> color_scheme;
|
||||
ColorsScheme colors_scheme_id;
|
||||
std::unordered_map<std::string, QString> colors_scheme;
|
||||
/*int font_size = 13;*/
|
||||
QString font_family;
|
||||
QFont font;
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
#include "modules/exceptions.h"
|
||||
|
||||
|
||||
Crapnote::Crapnote( const int color_scheme_id, QFont font, QWidget* parent )
|
||||
Crapnote::Crapnote( const ColorsScheme colors_scheme, QFont font, QWidget* parent )
|
||||
: QWidget{ parent }
|
||||
, ui{ new Ui::Crapnote }
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setColorScheme( color_scheme_id );
|
||||
this->setColorScheme( colors_scheme );
|
||||
this->setTextFont( font );
|
||||
}
|
||||
|
||||
|
@ -26,35 +26,32 @@ void Crapnote::setTextFont( QFont font ) noexcept
|
|||
this->ui->text_Note->setFont( font );
|
||||
}
|
||||
|
||||
void Crapnote::setColorScheme( const int color_scheme_id )
|
||||
void Crapnote::setColorScheme( const ColorsScheme colors_scheme )
|
||||
{
|
||||
if ( GlobalConfigs::window_theme != WindowTheme::Native ) {
|
||||
this->setStyleSheet( StyleSec::Crapnote::getStyleSheet( color_scheme_id ) );
|
||||
this->setStyleSheet( StyleSec::Crapnote::getStyleSheet( colors_scheme ) );
|
||||
} else {
|
||||
this->setStyleSheet("");
|
||||
QPalette p;
|
||||
// update the colors palette
|
||||
switch ( color_scheme_id ) {
|
||||
case 0:
|
||||
switch ( colors_scheme ) {
|
||||
case ColorsScheme::None:
|
||||
break;
|
||||
case 1:
|
||||
// breeze
|
||||
case ColorsScheme::Breeze:
|
||||
p.setColor( QPalette::Base, QColor( 255, 198, 102 ) );
|
||||
p.setColor( QPalette::Text, QColor( 31, 28, 27 ) );
|
||||
break;
|
||||
case 2:
|
||||
// monokai
|
||||
case ColorsScheme::Monokai:
|
||||
p.setColor( QPalette::Base, QColor( 166, 226, 46 ) );
|
||||
p.setColor( QPalette::Text, QColor( 39, 40, 34 ) );
|
||||
break;
|
||||
case 3:
|
||||
// radical
|
||||
case ColorsScheme::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
|
||||
throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( static_cast<themes_t>(colors_scheme) ), true ); // leave un-catched
|
||||
}
|
||||
this->ui->text_Note->setPalette( p );
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include <QWidget>
|
||||
|
||||
|
||||
enum class ColorsScheme : unsigned char;
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class Crapnote;
|
||||
}
|
||||
|
@ -19,13 +22,13 @@ class Crapnote final : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Crapnote( const int color_scheme_id, QFont font, QWidget* parent=nullptr );
|
||||
explicit Crapnote( const ColorsScheme colors_scheme, QFont font, QWidget* parent=nullptr );
|
||||
|
||||
//! Sets the given font
|
||||
void setTextFont( QFont font ) noexcept;
|
||||
|
||||
//! Sets the given color-scheme
|
||||
void setColorScheme( const int color_scheme_id );
|
||||
void setColorScheme( const ColorsScheme colors_scheme );
|
||||
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -79,7 +79,7 @@ StyleMap makeStyleMap()
|
|||
namespace StyleSec::Crapnote
|
||||
{
|
||||
|
||||
QString getStyleSheet( const int color_scheme )
|
||||
QString getStyleSheet( const ColorsScheme colors_scheme )
|
||||
{
|
||||
QString icons_theme;
|
||||
switch ( GlobalConfigs::window_theme ) {
|
||||
|
@ -95,9 +95,8 @@ QString getStyleSheet( const int color_scheme )
|
|||
throw GenericException( "Unexpected WindowTheme: "+std::to_string(static_cast<themes_t>(GlobalConfigs::window_theme)), true );
|
||||
}
|
||||
QString note_bg, note_txt;
|
||||
// update the colors palette
|
||||
switch ( color_scheme ) {
|
||||
case 0:
|
||||
switch ( colors_scheme ) {
|
||||
case ColorsScheme::None:
|
||||
if ( GlobalConfigs::window_theme == WindowTheme::Light ) {
|
||||
note_bg = "rgb( 255, 255, 255 )";
|
||||
note_txt = "rgb( 0, 0, 0 )";
|
||||
|
@ -106,24 +105,21 @@ QString getStyleSheet( const int color_scheme )
|
|||
note_txt = "rgb( 255, 255, 255 )";
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// breeze
|
||||
case ColorsScheme::Breeze:
|
||||
note_bg = "rgb( 255, 198, 102 )";
|
||||
note_txt = "rgb( 31, 28, 27 )";
|
||||
break;
|
||||
case 2:
|
||||
// monokai
|
||||
case ColorsScheme::Monokai:
|
||||
note_bg = "rgb( 166, 226, 46 )";
|
||||
note_txt = "rgb( 39, 40, 34 )";
|
||||
break;
|
||||
case 3:
|
||||
// radical
|
||||
case ColorsScheme::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
|
||||
throw GenericException( "Unexpected ColorScheme ID for Crapnote: "+std::to_string( static_cast<themes_t>(colors_scheme) ), true ); // leave un-catched
|
||||
}
|
||||
|
||||
const StyleMap style{ makeStyleMap() };
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
#define LOGDOCTOR__CRAPNOTE__STYLESHEETS_H
|
||||
|
||||
|
||||
enum class ColorsScheme : unsigned char;
|
||||
|
||||
class QString;
|
||||
|
||||
|
||||
namespace StyleSec::Crapnote
|
||||
{
|
||||
|
||||
QString getStyleSheet( const int color_scheme );
|
||||
QString getStyleSheet( const ColorsScheme colors_scheme );
|
||||
|
||||
} // namespacce StyleSec::Crapnote
|
||||
|
||||
|
|
|
@ -31,49 +31,53 @@ std::unordered_map<std::string, QColor> getColors() noexcept
|
|||
}
|
||||
|
||||
|
||||
std::unordered_map<int, std::unordered_map<std::string, QString>> getColorSchemes() noexcept
|
||||
std::unordered_map<ColorsScheme, std::unordered_map<std::string, QString>> getColorSchemes() noexcept
|
||||
{
|
||||
return {
|
||||
// none
|
||||
{0,{{"background",""},
|
||||
{"text",""},
|
||||
{"x",""},
|
||||
{"ip",""},
|
||||
{"byte",""},
|
||||
{"time",""},
|
||||
{"ua",""},
|
||||
{"req",""},
|
||||
{"res",""} }},
|
||||
// breeze
|
||||
{1,{{"background","#ffffff"},
|
||||
{"text","#9c9c9b"},
|
||||
{"x","#1f1c1b"},
|
||||
{"ip","#644a9b"},
|
||||
{"byte","#d5bc79"},
|
||||
{"time","#d685d6"},
|
||||
{"ua","#006e28"},
|
||||
{"req","#54b8ff"},
|
||||
{"res","#d24f4f"} }},
|
||||
// monokai
|
||||
{2,{{"background","#272822"},
|
||||
{"text","#706c5a"},
|
||||
{"x","#a6a6a0"},
|
||||
{"ip","#57adbc"},
|
||||
{"byte","#c1b864"},
|
||||
{"time","#9773db"},
|
||||
{"ua","#a6e22e"},
|
||||
{"req","#d1d1cb"},
|
||||
{"res","#f92672"} }},
|
||||
// radical
|
||||
{3,{{"background","#141322"},
|
||||
{"text","#749295"},
|
||||
{"x","#7c9c9e"},
|
||||
{"ip","#fda8bc"},
|
||||
{"byte","#ff85a1"},
|
||||
{"time","#a8c0c2"},
|
||||
{"ua","#42a784"},
|
||||
{"req","#d5358f"},
|
||||
{"res","#56e8e4"} }}
|
||||
{ColorsScheme::None,{
|
||||
{"background", ""},
|
||||
{"text", ""},
|
||||
{"x", ""},
|
||||
{"ip", ""},
|
||||
{"byte", ""},
|
||||
{"time", ""},
|
||||
{"ua", ""},
|
||||
{"req", ""},
|
||||
{"res", ""}}
|
||||
},
|
||||
{ColorsScheme::Breeze,{
|
||||
{"background", "#ffffff"},
|
||||
{"text", "#9c9c9b"},
|
||||
{"x", "#1f1c1b"},
|
||||
{"ip", "#644a9b"},
|
||||
{"byte", "#d5bc79"},
|
||||
{"time", "#d685d6"},
|
||||
{"ua", "#006e28"},
|
||||
{"req", "#54b8ff"},
|
||||
{"res", "#d24f4f"}}
|
||||
},
|
||||
{ColorsScheme::Monokai,{
|
||||
{"background", "#272822"},
|
||||
{"text", "#706c5a"},
|
||||
{"x", "#a6a6a0"},
|
||||
{"ip", "#57adbc"},
|
||||
{"byte", "#c1b864"},
|
||||
{"time", "#9773db"},
|
||||
{"ua", "#a6e22e"},
|
||||
{"req", "#d1d1cb"},
|
||||
{"res", "#f92672"}}
|
||||
},
|
||||
{ColorsScheme::Radical,{
|
||||
{"background", "#141322"},
|
||||
{"text", "#749295"},
|
||||
{"x", "#7c9c9e"},
|
||||
{"ip", "#fda8bc"},
|
||||
{"byte", "#ff85a1"},
|
||||
{"time", "#a8c0c2"},
|
||||
{"ua", "#42a784"},
|
||||
{"req", "#d5358f"},
|
||||
{"res", "#56e8e4"}}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ class QString;
|
|||
class QColor;
|
||||
class QFont;
|
||||
|
||||
enum class ColorsScheme : unsigned char;
|
||||
|
||||
|
||||
//! ColorSec
|
||||
/*!
|
||||
|
@ -22,7 +24,7 @@ namespace ColorSec
|
|||
std::unordered_map<std::string, QColor> getColors() noexcept;
|
||||
|
||||
//! Provides a map with pre-made color-schemes for the TextBrowser
|
||||
std::unordered_map<int, std::unordered_map<std::string, QString>> getColorSchemes() noexcept;
|
||||
std::unordered_map<ColorsScheme, std::unordered_map<std::string, QString>> getColorSchemes() noexcept;
|
||||
|
||||
//! Applies the choosen theme to the given chart
|
||||
/*!
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
|
||||
#include "rtf.h"
|
||||
|
||||
#include "utilities/strings.h"
|
||||
#include "modules/craplog/modules/lib.h"
|
||||
#include "globals/global_configs.h"
|
||||
|
||||
#include "modules/tb.h"
|
||||
|
||||
#include "modules/craplog/modules/lib.h"
|
||||
|
||||
#include "utilities/strings.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
void RichText::enrichLogs( QString& rich_content, const std::string& content, const LogsFormat& logs_format, TextBrowser& TB )
|
||||
void RichText::enrichLogs( QString& rich_content, const std::string& content, const LogsFormat& logs_format, const TextBrowser& TB )
|
||||
{
|
||||
const std::unordered_map<std::string, QString>& colors{ TB.getColorScheme() };
|
||||
const int color_scheme{ TB.getColorSchemeID() };
|
||||
const bool using_colors_scheme{ TB.getColorSchemeID() != ColorsScheme::None };
|
||||
const bool wide_lines{ TB.getWideLinesUsage() };
|
||||
// enrich the text
|
||||
rich_content.clear();
|
||||
rich_content.reserve( static_cast<int>(content.size()*2ul) );
|
||||
rich_content += "<!DOCTYPE html><html><head></head><body";
|
||||
if ( color_scheme > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
rich_content += QStringLiteral(R"( style="background:%1; color:%2")")
|
||||
.arg( colors.at("background"), colors.at("text") );
|
||||
}
|
||||
|
@ -155,7 +159,7 @@ void RichText::enrichLogs( QString& rich_content, const std::string& content, co
|
|||
}
|
||||
rich_line += "<b>";
|
||||
class_name.clear();
|
||||
if ( color_scheme > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
class_name += R"(<span style="color:)";
|
||||
if ( fld == "client" ) {
|
||||
class_name += colors.at("ip");
|
||||
|
@ -177,7 +181,7 @@ void RichText::enrichLogs( QString& rich_content, const std::string& content, co
|
|||
// add the class name as span
|
||||
rich_line += class_name;
|
||||
rich_line += QString::fromStdString( fld_str );
|
||||
if ( color_scheme > 0 ) {
|
||||
if ( using_colors_scheme ) {
|
||||
rich_line += "</span>";
|
||||
}
|
||||
rich_line += "</b>";
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
QString& rich_content,
|
||||
const std::string& content,
|
||||
const LogsFormat& logs_format,
|
||||
TextBrowser& TB
|
||||
const TextBrowser& TB
|
||||
);
|
||||
|
||||
//! Provides the default string
|
||||
|
|
Loading…
Reference in a new issue