Skip to content

Commit

Permalink
add double width cursor plus highlight focus cleanups plus dark fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Apr 15, 2024
1 parent 51dcfdf commit 8689b0a
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MainUI/BookBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}


Expand Down
1 change: 0 additions & 1 deletion src/MainUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/MainUI/PreviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Misc/FindReplaceQLineEdit.cpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
** Copyright (C) 2012 Dave Heiland
** Copyright (C) 2012 Grant Drake
Expand Down Expand Up @@ -32,8 +32,8 @@
#include <QPointer>

#include "Misc/Utility.h"
#include "Misc/FindReplaceQLineEdit.h"
#include "MiscEditors/SearchEditorModel.h"
#include "Misc/FindReplaceQLineEdit.h"

FindReplaceQLineEdit::FindReplaceQLineEdit(QWidget *parent)
: QLineEdit(parent),
Expand Down
7 changes: 4 additions & 3 deletions src/Misc/FindReplaceQLineEdit.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/************************************************************************
**
** Copyright (C) 2012 John Schember <[email protected]>
** Copyright (C) 2012 Dave Heiland
** Copyright (C) 2012 Grant Drake
** Copyright (C) 2020-2024 Kevin Hendricks, Stratford, ON Canada
** Copyright (C) 2012 John Schember <[email protected]>
** Copyright (C) 2012 Dave Heiland
** Copyright (C) 2012 Grant Drake
**
** This file is part of Sigil.
**
Expand Down
17 changes: 17 additions & 0 deletions src/Resource_Files/dark/closedock-macstyle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/Resource_Files/dark/dark.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
<file>win_dark_scrollbar.css</file>
<file>mac_dark_scrollbar.css</file>
<file>sigil_logo_blue.png</file>
<file>closedock-macstyle.svg</file>
<file>dockdock-macstyle.svg</file>
</qresource>
</RCC>
19 changes: 19 additions & 0 deletions src/Resource_Files/dark/dockdock-macstyle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Tabs/FlowTab.cpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
** Copyright (C) 2012 Dave Heiland
** Copyright (C) 2012 Grant Drake
Expand Down
4 changes: 3 additions & 1 deletion src/ViewEditors/CodeViewEditor.cpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
** Copyright (C) 2012-2013 Dave Heiland
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}


Expand Down
31 changes: 31 additions & 0 deletions src/Widgets/CaretStyle.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/

#include <QStyle>
#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);
}
41 changes: 41 additions & 0 deletions src/Widgets/CaretStyle.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/

#pragma once
#ifndef CARETSTYLE_H
#define CARETSTYLE_H

#include <QProxyStyle>
#include <QCommonStyle>

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
49 changes: 42 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <QCoreApplication>
#include <QDir>
#include <QLibraryInfo>
#include <QStyleFactory>
#include <QTextCodec>
#include <QThreadPool>
#include <QTranslator>
Expand All @@ -39,6 +38,8 @@
#include <QFileInfo>
#include <QTextStream>
#include <QFontMetrics>
#include <QStyle>
#include <QStyleFactory>
#include <QtWebEngineWidgets>
#include <QtWebEngineCore>

Expand All @@ -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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()));

This comment has been minimized.

Copy link
@dougmassay

dougmassay Apr 17, 2024

Contributor

I think something here is stomping on Windows Dark Mode application style. From the setStyle documentation:

The string must be one of the QStyleFactory::keys(), typically one of "windows", "windowsvista", "fusion", or "macos".

}

#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
Expand Down

0 comments on commit 8689b0a

Please sign in to comment.