View Single Post
Old 06-30-2022, 04:57 AM   #25
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
Posts: 846
Karma: 3341026
Join Date: Jan 2017
Location: Poland
Device: Various
I found the problem described by @RbnJrg interesting. I thought it was just a special case that could be solved by the trivial editing of custom_preview_style.css, however, some toggler of custom stylesheets could be a nice addition.

I absolutely do not suggest adding this clunky solution should be added to the release, but it may be useful for two or three people in the world among Sigil users who build the code themselves. An additional advantage is the lack of any changes to the settings – the selected mode works until the Sigil is closed. I also used an existing icon to simplify it.

Three-stage toggler works cyclically:
a) custom_preview_style.css
b) custom_preview_style_invert.css
c) disable custom css

This is how it works in practice:


Code:
Spoiler:
Code:
--- W:\Develop\Sigil\Sigil-master\src\MainUI\before\PreviewWindow.cpp	2022-06-26 15:25:04.000000000 +0200
+++ W:\Develop\Sigil\Sigil-master\src\MainUI\after\PreviewWindow.cpp	2022-06-30 09:26:39.921443500 +0200
@@ -238,12 +238,16 @@
 
     m_reloadAction  = new QAction(QIcon(":/main/reload-page.svg"),"", this);
     m_reloadAction->setToolTip(tr("Update Preview Window"));
+    
+    m_toggleCSSAction  = new QAction(QIcon(":/main/emblem-favorite.svg"),"", this);
+    m_toggleCSSAction->setToolTip(tr("Toggle Custom CSS File"));
 
     QToolBar * tb = new QToolBar();
     tb->addAction(m_inspectAction);
     tb->addAction(m_selectAction);
     tb->addAction(m_copyAction);
     tb->addAction(m_reloadAction);
+    tb->addAction(m_toggleCSSAction);
     tb->addWidget(m_progress);
 
     m_buttons->addWidget(tb);
@@ -443,6 +447,30 @@
     }
 }
 
+void PreviewWindow::ToggleCSS() {
+    QString default_user_css = "file:///" + Utility::DefinePrefsDir() + "/custom_preview_style.css";
+    QString invert_user_css  = "file:///" + Utility::DefinePrefsDir() + "/custom_preview_style_invert.css";
+
+    if (toggleCustomCSS < 1 || toggleCustomCSS > 3) {
+    	toggleCustomCSS = 2;
+    }
+    switch (toggleCustomCSS) {
+        case 1:
+            m_usercssurl = default_user_css;
+            toggleCustomCSS = 2;
+            break;
+        case 2:
+            m_usercssurl = invert_user_css;
+            toggleCustomCSS = 3;
+            break;
+        case 3:
+            m_usercssurl = "";
+            toggleCustomCSS = 1;
+            break;
+    }
+    ReloadPreview();
+}
+
 QList<ElementIndex> PreviewWindow::GetCaretLocation()
 {
     DBG qDebug() << "PreviewWindow in GetCaretLocation";
@@ -638,6 +666,7 @@
     connect(m_selectAction,  SIGNAL(triggered()),           this, SLOT(SelectAllPreview()));
     connect(m_copyAction,    SIGNAL(triggered()),           this, SLOT(CopyPreview()));
     connect(m_reloadAction,  SIGNAL(triggered()),           this, SLOT(ReloadPreview()));
+    connect(m_toggleCSSAction,  SIGNAL(triggered()),        this, SLOT(ToggleCSS()));
     connect(m_Inspector,     SIGNAL(finished(int)),         this, SLOT(InspectorClosed(int)));
     connect(this,     SIGNAL(topLevelChanged(bool)),        this, SLOT(previewFloated(bool)));
 }
Code:
--- W:\Develop\Sigil\Sigil-master\src\MainUI\before\PreviewWindow.h	2022-06-26 15:25:04.000000000 +0200
+++ W:\Develop\Sigil\Sigil-master\src\MainUI\after\PreviewWindow.h	2022-06-30 09:13:31.106294200 +0200
@@ -81,6 +81,7 @@
      */
     void setTitleText(const QString &text);
     void previewFloated(bool wasFloated);
+    void ToggleCSS();
 
 signals:
     void Shown();
@@ -142,11 +143,13 @@
     QAction * m_selectAction;
     QAction * m_copyAction;
     QAction * m_reloadAction;
+    QAction * m_toggleCSSAction;
 
     QList<ElementIndex> m_location;
     
     QTimer m_OverlayTimer;
     bool m_updatingPage;
+    int toggleCustomCSS;
     bool m_usingMathML;
 };
BeckyEbook is offline   Reply With Quote