From 8689b0a4176b8d603ea3f2c3330534543540767c Mon Sep 17 00:00:00 2001 From: Kevin Hendricks Date: Sun, 14 Apr 2024 20:02:21 -0400 Subject: [PATCH] add double width cursor plus highlight focus cleanups plus dark fixups --- src/CMakeLists.txt | 2 + src/MainUI/BookBrowser.cpp | 1 + src/MainUI/MainWindow.cpp | 1 - src/MainUI/PreviewWindow.cpp | 9 +++- src/Misc/FindReplaceQLineEdit.cpp | 4 +- src/Misc/FindReplaceQLineEdit.h | 7 +-- .../dark/closedock-macstyle.svg | 17 +++++++ src/Resource_Files/dark/dark.qrc | 2 + src/Resource_Files/dark/dockdock-macstyle.svg | 19 +++++++ src/Tabs/FlowTab.cpp | 2 +- src/ViewEditors/CodeViewEditor.cpp | 4 +- src/Widgets/CaretStyle.cpp | 31 ++++++++++++ src/Widgets/CaretStyle.h | 41 ++++++++++++++++ src/main.cpp | 49 ++++++++++++++++--- 14 files changed, 173 insertions(+), 16 deletions(-) create mode 100644 src/Resource_Files/dark/closedock-macstyle.svg create mode 100644 src/Resource_Files/dark/dockdock-macstyle.svg create mode 100644 src/Widgets/CaretStyle.cpp create mode 100644 src/Widgets/CaretStyle.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d78333ad6..719607cae3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -234,6 +234,8 @@ set( WIDGET_FILES Widgets/TextDocument.cpp Widgets/TVLineNumberArea.cpp Widgets/TVLineNumberArea.h + Widgets/CaretStyle.cpp + Widgets/CaretStyle.h ) set( EXPORTER_FILES diff --git a/src/MainUI/BookBrowser.cpp b/src/MainUI/BookBrowser.cpp index d1b2952b5a..4b5dd16223 100644 --- a/src/MainUI/BookBrowser.cpp +++ b/src/MainUI/BookBrowser.cpp @@ -108,6 +108,7 @@ BookBrowser::BookBrowser(QWidget *parent) m_OpenWithContextMenu->addAction(m_OpenWithEditor4); m_OpenWithContextMenu->addAction(m_OpenWith); setFocusPolicy(Qt::StrongFocus); + setWindowTitle(tr("Book Browser")); } diff --git a/src/MainUI/MainWindow.cpp b/src/MainUI/MainWindow.cpp index 4831ab11e4..bc813ed0b4 100644 --- a/src/MainUI/MainWindow.cpp +++ b/src/MainUI/MainWindow.cpp @@ -5946,7 +5946,6 @@ void MainWindow::ExtendUI() m_PreviewWindow = new PreviewWindow(this); m_PreviewWindow->setObjectName(PREVIEW_WINDOW_NAME); - m_PreviewWindow->setStyleSheet("QDockWidget {border: none;}"); addDockWidget(Qt::RightDockWidgetArea, m_PreviewWindow); // Now that Book View is gone, show Preview by default on new installations // tabified with the TOC widget in the RightDockWidgetArea diff --git a/src/MainUI/PreviewWindow.cpp b/src/MainUI/PreviewWindow.cpp index f52e7fccd4..c15e027470 100644 --- a/src/MainUI/PreviewWindow.cpp +++ b/src/MainUI/PreviewWindow.cpp @@ -552,7 +552,14 @@ bool PreviewWindow::eventFilter(QObject *object, QEvent *event) case QEvent::FocusIn: // track focus in change events of m_Preview (or one of its child focus proxies) if (m_use_focus_highlight) { - m_wrapper->setStyleSheet("border: 1px solid red;"); + // a bit hackish as this should match what we do in main.cpp + // so we should probably create a sigil_constant for this value + // and fix both places to use it +#ifdef Q_OS_MAC + m_wrapper->setStyleSheet("border: 1px solid #2B5FFE;"); +#else + m_wrapper->setStyleSheet("border: 1px solid red"); +#endif } DBG qDebug() << "focus in event: " << object; break; diff --git a/src/Misc/FindReplaceQLineEdit.cpp b/src/Misc/FindReplaceQLineEdit.cpp index e08a96783b..f26a7cd749 100644 --- a/src/Misc/FindReplaceQLineEdit.cpp +++ b/src/Misc/FindReplaceQLineEdit.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** -** Copyright (C) 2015-2020 Kevin B. Hendricks, Stratford Ontario Canada +** Copyright (C) 2015-2024 Kevin B. Hendricks, Stratford Ontario Canada ** Copyright (C) 2012 John Schember ** Copyright (C) 2012 Dave Heiland ** Copyright (C) 2012 Grant Drake @@ -32,8 +32,8 @@ #include #include "Misc/Utility.h" -#include "Misc/FindReplaceQLineEdit.h" #include "MiscEditors/SearchEditorModel.h" +#include "Misc/FindReplaceQLineEdit.h" FindReplaceQLineEdit::FindReplaceQLineEdit(QWidget *parent) : QLineEdit(parent), diff --git a/src/Misc/FindReplaceQLineEdit.h b/src/Misc/FindReplaceQLineEdit.h index deb9a4eb85..d64cda3c81 100644 --- a/src/Misc/FindReplaceQLineEdit.h +++ b/src/Misc/FindReplaceQLineEdit.h @@ -1,8 +1,9 @@ /************************************************************************ ** -** Copyright (C) 2012 John Schember -** Copyright (C) 2012 Dave Heiland -** Copyright (C) 2012 Grant Drake +** Copyright (C) 2020-2024 Kevin Hendricks, Stratford, ON Canada +** Copyright (C) 2012 John Schember +** Copyright (C) 2012 Dave Heiland +** Copyright (C) 2012 Grant Drake ** ** This file is part of Sigil. ** diff --git a/src/Resource_Files/dark/closedock-macstyle.svg b/src/Resource_Files/dark/closedock-macstyle.svg new file mode 100644 index 0000000000..7a8c8f0f2f --- /dev/null +++ b/src/Resource_Files/dark/closedock-macstyle.svg @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/src/Resource_Files/dark/dark.qrc b/src/Resource_Files/dark/dark.qrc index b28edc7a91..7a0289596f 100644 --- a/src/Resource_Files/dark/dark.qrc +++ b/src/Resource_Files/dark/dark.qrc @@ -15,5 +15,7 @@ win_dark_scrollbar.css mac_dark_scrollbar.css sigil_logo_blue.png + closedock-macstyle.svg + dockdock-macstyle.svg diff --git a/src/Resource_Files/dark/dockdock-macstyle.svg b/src/Resource_Files/dark/dockdock-macstyle.svg new file mode 100644 index 0000000000..41cc633a3f --- /dev/null +++ b/src/Resource_Files/dark/dockdock-macstyle.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + diff --git a/src/Tabs/FlowTab.cpp b/src/Tabs/FlowTab.cpp index d945e88550..c04673735c 100644 --- a/src/Tabs/FlowTab.cpp +++ b/src/Tabs/FlowTab.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** -** Copyright (C) 2016-2023 Kevin B Hendricks, Stratford, Ontario, Canada +** Copyright (C) 2016-2024 Kevin B Hendricks, Stratford, Ontario, Canada ** Copyright (C) 2012 John Schember ** Copyright (C) 2012 Dave Heiland ** Copyright (C) 2012 Grant Drake diff --git a/src/ViewEditors/CodeViewEditor.cpp b/src/ViewEditors/CodeViewEditor.cpp index 9c08841078..e2b00f1313 100644 --- a/src/ViewEditors/CodeViewEditor.cpp +++ b/src/ViewEditors/CodeViewEditor.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** -** Copyright (C) 2019-2023 Doug Massay +** Copyright (C) 2019-2024 Doug Massay ** Copyright (C) 2015-2024 Kevin B. Hendricks, Stratford Ontario Canada ** Copyright (C) 2012 John Schember ** Copyright (C) 2012-2013 Dave Heiland @@ -191,6 +191,7 @@ void CodeViewEditor::CustomSetDocument(TextDocument &ndocument) ResetFont(); m_isLoadFinished = true; m_regen_taglist = true; + if (qEnvironmentVariableIsSet("SIGIL_DOUBLE_TEXTCURSOR_WIDTH")) setCursorWidth(2); emit DocumentSet(); } @@ -2201,6 +2202,7 @@ void CodeViewEditor::focusInEvent(QFocusEvent *event) emit FocusGained(this); QPlainTextEdit::focusInEvent(event); HighlightCurrentLine(false); + if (qEnvironmentVariableIsSet("SIGIL_DOUBLE_TEXTCURSOR_WIDTH")) setCursorWidth(2); } diff --git a/src/Widgets/CaretStyle.cpp b/src/Widgets/CaretStyle.cpp new file mode 100644 index 0000000000..62fafab32c --- /dev/null +++ b/src/Widgets/CaretStyle.cpp @@ -0,0 +1,31 @@ +/************************************************************************ +** +** Copyright (C) 2024 Kevin B. Hendricks, Stratford, Ontario Canada +** +** This file is part of Sigil. +** +** Sigil is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Sigil is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Sigil. If not, see . +** +*************************************************************************/ + +#include +#include "Widgets/CaretStyle.h" + +int CaretStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const +{ + if (metric == QStyle::PM_TextCursorWidth) + return 2; + + return QProxyStyle::pixelMetric(metric,option,widget); +} diff --git a/src/Widgets/CaretStyle.h b/src/Widgets/CaretStyle.h new file mode 100644 index 0000000000..ef6ab3031a --- /dev/null +++ b/src/Widgets/CaretStyle.h @@ -0,0 +1,41 @@ +/************************************************************************ +** +** Copyright (C) 2024 Kevin B. Hendricks, Stratford, Ontario Canada +** +** This file is part of Sigil. +** +** Sigil is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** Sigil is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Sigil. If not, see . +** +*************************************************************************/ + +#pragma once +#ifndef CARETSTYLE_H +#define CARETSTYLE_H + +#include +#include + +class QStyle; +class QStyleOption; + +class CaretStyle : public QProxyStyle +{ +public: + CaretStyle(QStyle *style = 0) : QProxyStyle(style) { } + + int pixelMetric(QCommonStyle::PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const; + +}; + +#endif // CARETSTYLE_H diff --git a/src/main.cpp b/src/main.cpp index 4bb5000933..cbc345a9f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -39,6 +38,8 @@ #include #include #include +#include +#include #include #include @@ -57,6 +58,7 @@ #include "Misc/UpdateChecker.h" #include "Misc/Utility.h" #include "Misc/WebProfileMgr.h" +#include "Widgets/CaretStyle.h" #include "sigil_constants.h" #include "sigil_exception.h" @@ -85,6 +87,19 @@ extern void removeMacosSpecificMenuItems(); #define QT_ENUM_KEEPEMPTYPARTS QString::KeepEmptyParts #endif +const QString MAC_DOCK_TITLEBAR_FIX = + "QDockWidget { " + " titlebar-close-icon: url(:/dark/closedock-macstyle.svg);" + " titlebar-normal-icon: url(:/dark/dockdock-macstyle.svg);" + "}"; + +const QString FOCUS_HIGHLIGHT_QSS = + "QLineEdit:focus, QPlainTextEdit:focus, QTextEdit:focus, " + "QTreeView::focus, QListView:focus, QScrollArea:focus { " + " border: 1px solid HIGHLIGHT_COLOR;" + "}"; + + // Creates a MainWindow instance depending // on command line arguments static MainWindow *GetMainWindow(const QStringList &arguments) @@ -564,8 +579,9 @@ int main(int argc, char *argv[]) app.installTranslator(&sigilTranslator); #ifdef Q_OS_MAC - QApplication::setStyle("macOS"); - // app.setPalette(QApplication::style()->standardPalette()); + // QApplication::setStyle("macOS"); + QStyle* astyle = QStyleFactory::create("macOS"); + app.setStyle(astyle); #endif #ifndef Q_OS_MAC // Custom dark style/palette for Windows and Linux @@ -653,12 +669,31 @@ int main(int argc, char *argv[]) } #endif // End of UI font stuff - + + // finally for styles handle the new CaretStyle (double width cursor) + // last after all other application Styles + // Use environment variable until a proper setting is created + // Must update CodeViewEditor.cpp in two places when changing this to a setting + if (qEnvironmentVariableIsSet("SIGIL_DOUBLE_TEXTCURSOR_WIDTH")) { + QApplication::setStyle(new CaretStyle(QApplication::style())); + } + +#ifdef Q_OS_MAC + // macOS need to fix broken QDockWidgets under dark mode + app.setStyleSheet(app.styleSheet().append(MAC_DOCK_TITLEBAR_FIX)); +#endif + // allow user to highlight focus widget if (settings.uiHighlightFocusWidgetEnabled()) { - QString current_stylesheet = app.styleSheet(); - current_stylesheet.append(":focus { border: 1px solid red; } }"); - app.setStyleSheet(current_stylesheet); + QString focus_qss = FOCUS_HIGHLIGHT_QSS; + // See PreviewWindow.cpp in the eventFilter routine in FocusIn + // where the same platform constant is used - keep in sync +#ifdef Q_OS_MAC + focus_qss.replace("HIGHLIGHT_COLOR", "#2B5FFE"); +#else //Linux and Windows + focus_qss.replace("HIGHLIGHT_COLOR", "red"); +#endif + app.setStyleSheet(app.styleSheet().append(focus_qss)); } // Check for existing qt_styles.qss in Prefs dir and load it if present