Added new tool 'Crappath'

Allows the user to select a path through a dialog window
This commit is contained in:
Valentino Orlandi 2024-02-05 20:08:09 +01:00
parent 6e9aa9b8cb
commit 13a2f1f082
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
3 changed files with 135 additions and 0 deletions

View File

@ -166,6 +166,9 @@ set(PROJECT_SOURCES
modules/crapinfo/modules/stylesheets.h
modules/crapinfo/modules/stylesheets.cpp
tools/crappath/crappath.h
tools/crappath/crappath.cpp
tools/crapnote/crapnote.ui
tools/crapnote/crapnote.h
tools/crapnote/crapnote.cpp

View File

@ -0,0 +1,116 @@
#include "crappath.h"
#include "globals/global_configs.h"
#include "modules/exceptions.h"
#include <unordered_map>
QString makeStyleSheet();
Crappath::Crappath( QWidget* parent )
: QFileDialog(parent)
{
QFileDialog::setViewMode( QFileDialog::Detail );
QFileDialog::setFileMode( QFileDialog::Directory );
QFileDialog::setOptions(
QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks |
QFileDialog::ReadOnly |
QFileDialog::DontUseCustomDirectoryIcons );
QFileDialog::setFilter(
QDir::Dirs |
QDir::NoDot |
QDir::NoSymLinks |
QDir::Hidden );
QFileDialog::setLabelText( QFileDialog::Accept, Crappath::tr("Choose") );
QFileDialog::setLabelText( QFileDialog::Reject, Crappath::tr("Cancel") );
switch ( GlobalConfigs::window_theme ) {
case WindowTheme::Native:
QFileDialog::setStyleSheet("");
break;
case WindowTheme::Light:
[[fallthrough]];
case WindowTheme::Dark:
QFileDialog::setStyleSheet( makeStyleSheet() );
break;
default:
// wrong
throw GenericException( "Unexpected WindowTheme: "+std::to_string(static_cast<themes_t>(GlobalConfigs::window_theme)), true );
break;
}
}
enum StyleId : uint32_t {
BUTTONS_BASE,
BUTTONS_BASE_HOVER,
BUTTONS_BASE_FLAT,
BUTTONS_BASE_DISABLED
};
using StyleMap = std::unordered_map<StyleId, QString>;
StyleMap makeStyleMap()
{
switch ( GlobalConfigs::window_theme ) {
case WindowTheme::Light:
return {
{BUTTONS_BASE,
"rgb( 99, 188, 255 )"},
{BUTTONS_BASE_HOVER,
"rgb( 123, 201, 255 )"},
{BUTTONS_BASE_FLAT,
"rgb( 200, 219, 238 )"},
{BUTTONS_BASE_DISABLED,
"rgb( 200, 219, 238 )"}
};
break;
case WindowTheme::Dark:
return {
{BUTTONS_BASE,
"rgb( 10, 155, 10 )"},
{BUTTONS_BASE_HOVER,
"rgb( 33, 162, 33 )"},
{BUTTONS_BASE_FLAT,
"rgb( 21, 71, 21 )"},
{BUTTONS_BASE_DISABLED,
"rgb( 21, 71, 21 )"}
};
break;
default:
throw GenericException( "Unexpected WindowTheme: "+std::to_string(static_cast<themes_t>(GlobalConfigs::window_theme)), true );
break;
}
}
QString makeStyleSheet()
{
const StyleMap style{ makeStyleMap() };
return
"QPushButton {"
" border: 0px;"
" border-radius: 8px;"
" padding-left: 4px;"
" padding-right: 4px;"
" background-color: "+style.at(BUTTONS_BASE)+";"
"}"
"QPushButton:hover {"
" background-color: "+style.at(BUTTONS_BASE_HOVER)+";"
"}"
"QPushButton::flat {"
" background-color: "+style.at(BUTTONS_BASE_FLAT)+";"
"}"
"QPushButton::disabled {"
" background-color: "+style.at(BUTTONS_BASE_DISABLED)+";"
"}";
}

View File

@ -0,0 +1,16 @@
#ifndef LOGDOCTOR__CRAPPATH_H
#define LOGDOCTOR__CRAPPATH_H
#include <QFileDialog>
class Crappath : public QFileDialog
{
Q_OBJECT
public:
explicit Crappath( QWidget* parent=nullptr );
};
#endif // LOGDOCTOR__CRAPPATH_H