Adds theme support:

This commit is contained in:
Felix (xq) Queißner 2020-06-09 11:00:01 +02:00
parent 976522e195
commit 661ddc2447
9 changed files with 167 additions and 5 deletions

View File

@ -23,6 +23,7 @@ Kristall Changelog
- Added support for block quotes
- Added help file
- Added shortcut to focus URL bar
- Added possibility to save/load/share theme presets. Make everything colorful!
== 0.1
- Initial release

View File

@ -127,10 +127,11 @@ ln -s Kristall.desktop ~/.local/share/applications/kristall.desktop
- [ ] For favourites
- [ ] For documents
- [ ] Image Zoom and Pan
- [ ] Save/load/share theme preset
- [ ] Improve Unicode/Emoji support
- Seems to need multiple font families per font?
- [ ] Add text/kristall-theme mime
- [ ] Will use a preview document instead of displaying the content
- [ ] Allow import of themes
## Bugs
> <styan> xq: When using torsocks(1) on kristall QNetworkInterface complains loudly about not being permitted to create an IPv6 socket..

21
presets/black.kthm Normal file
View File

@ -0,0 +1,21 @@
[General]
background_color=#250108
blockquote_color=#4f0507
cross_scheme_link_color=#0a7dd4
external_link_color=#0e8fff
external_link_prefix="\x21d2 "
h1_color=#d60003
h1_font="Sans Serif,20,-1,5,50,0,0,0,0,0"
h2_color=#d90032
h2_font="Sans Serif,15,-1,5,50,0,0,0,0,0"
h3_color=#ea5600
h3_font="Sans Serif,12,-1,5,50,0,0,0,0,0"
internal_link_color=#0e8fff
internal_link_prefix="\x2192 "
margins=55
name=Black
preformatted_color=#ffd0f7
preformatted_font="Source Code Pro,10,-1,5,50,0,0,0,0,0,Regular"
standard_color=#e7c0c1
standard_font="Fira Sans,10,-1,5,50,0,0,0,0,0,Regular"
theme=0

21
presets/bloo Normal file
View File

@ -0,0 +1,21 @@
[General]
background_color=#250108
blockquote_color=#4f0507
cross_scheme_link_color=#0a7dd4
external_link_color=#0e8fff
external_link_prefix="\x21d2 "
h1_color=#d60003
h1_font="Sans Serif,20,-1,5,50,0,0,0,0,0"
h2_color=#d90032
h2_font="Sans Serif,15,-1,5,50,0,0,0,0,0"
h3_color=#ea5600
h3_font="Sans Serif,12,-1,5,50,0,0,0,0,0"
internal_link_color=#0e8fff
internal_link_prefix="\x2192 "
margins=55
name=Black
preformatted_color=#ffd0f7
preformatted_font="Source Code Pro,10,-1,5,50,0,0,0,0,0,Regular"
standard_color=#e7c0c1
standard_font="Fira Sans,10,-1,5,50,0,0,0,0,0,Regular"
theme=0

21
presets/default.kthm Normal file
View File

@ -0,0 +1,21 @@
[General]
background_color=#edefff
blockquote_color=#1380d4
cross_scheme_link_color=#0960a7
external_link_color=#0e8fff
external_link_prefix="\x21d2 "
h1_color=#022f90
h1_font="Sans Serif,20,-1,5,50,0,0,0,0,0"
h2_color=#022f90
h2_font="Sans Serif,15,-1,5,50,0,0,0,0,0"
h3_color=#022f90
h3_font="Sans Serif,12,-1,5,50,0,0,0,0,0"
internal_link_color=#0e8fff
internal_link_prefix="\x2192 "
margins=55
name=Default
preformatted_color=#000000
preformatted_font="Source Code Pro,10,-1,5,50,0,0,0,0,0,Regular"
standard_color=#000000
standard_font="Fira Sans,10,-1,5,50,0,0,0,0,0,Regular"
theme=0

21
presets/orange.kthm Normal file
View File

@ -0,0 +1,21 @@
[General]
background_color=#ff9e27
blockquote_color=#1380d4
cross_scheme_link_color=#0960a7
external_link_color=#0e8fff
external_link_prefix="\x21d2 "
h1_color=#022f90
h1_font="Sans Serif,20,-1,5,50,0,0,0,0,0"
h2_color=#022f90
h2_font="Sans Serif,15,-1,5,50,0,0,0,0,0"
h3_color=#022f90
h3_font="Sans Serif,12,-1,5,50,0,0,0,0,0"
internal_link_color=#0e8fff
internal_link_prefix="\x2192 "
margins=55
name=Orange
preformatted_color=#000000
preformatted_font="Source Code Pro,10,-1,5,50,0,0,0,0,0,Regular"
standard_color=#000000
standard_font="Fira Sans,10,-1,5,50,0,0,0,0,0,Regular"
theme=0

View File

@ -5,6 +5,7 @@
#include <QStyle>
#include <QSettings>
#include <QInputDialog>
#include <QFileDialog>
#include <QMessageBox>
#include "kristall.hpp"
@ -452,3 +453,74 @@ void SettingsDialog::on_SettingsDialog_accepted()
}
global_settings.endArray();
}
void SettingsDialog::on_preset_import_clicked()
{
QFileDialog dialog { this };
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.selectNameFilter("Kristall Theme (*.kthm)");
if(dialog.exec() !=QFileDialog::Accepted)
return;
QString fileName = dialog.selectedFiles().at(0);
QSettings import_settings { fileName, QSettings::IniFormat };
QString name;
name = import_settings.value("name").toString();
while(name.isEmpty())
{
QInputDialog dlg { this };
dlg.setInputMode(QInputDialog::TextInput);
dlg.setOkButtonText("Save");
dlg.setCancelButtonText("Cancel");
dlg.setLabelText("Imported preset has no name.\r\nPlease enter a name for the preset:");
if(dlg.exec() != QDialog::Accepted)
return;
name = dlg.textValue();
}
bool override = false;
if(this->predefined_styles.contains(name))
{
auto response = QMessageBox::question(this, "Kristall", QString("Do you want to override the style '%1'?").arg(name));
if(response != QMessageBox::Yes)
return;
override = true;
}
DocumentStyle style;
style.load(import_settings);
this->predefined_styles.insert(name, style);
if(not override)
{
this->ui->presets->addItem(name);
}
}
void SettingsDialog::on_preset_export_clicked()
{
QString name = this->ui->presets->currentText();
if(name.isEmpty())
return;
QFileDialog dialog { this };
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.selectNameFilter("Kristall Theme (*.kthm)");
dialog.selectFile(QString("%1.kthm").arg(name));
if(dialog.exec() !=QFileDialog::Accepted)
return;
QString fileName = dialog.selectedFiles().at(0);
QSettings export_settings { fileName, QSettings::IniFormat };
export_settings.setValue("name", name);
this->predefined_styles.value(name).save(export_settings);
export_settings.sync();
}

View File

@ -85,6 +85,10 @@ private slots:
void on_preset_load_clicked();
void on_preset_import_clicked();
void on_preset_export_clicked();
private:
void reloadStylePreview();

View File

@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="generic">
<attribute name="title">
@ -720,7 +720,7 @@
<item>
<widget class="QLabel" name="quote_preview">
<property name="text">
<string> </string>
<string/>
</property>
</widget>
</item>
@ -811,8 +811,8 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="textRenderingBtnGroup"/>
<buttongroup name="textHighlightsBtnGroup"/>
<buttongroup name="textRenderingBtnGroup"/>
<buttongroup name="gophermapBtnGroup"/>
</buttongroups>
</ui>