Skip to content

Commit

Permalink
Use macOS SF Symbols where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
IgKh committed Sep 27, 2024
1 parent 4c3e5d3 commit 68f189e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
32 changes: 16 additions & 16 deletions src/katvan_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ void MainWindow::setupActions()
QMenu* fileMenu = menuBar()->addMenu(tr("&File"));

QAction* newFileAction = fileMenu->addAction(tr("&New"), this, &MainWindow::newFile);
newFileAction->setIcon(QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg")));
newFileAction->setIcon(utils::themeIcon("document-new"));
newFileAction->setShortcut(QKeySequence::New);
newFileAction->setMenuRole(QAction::NoRole);

fileMenu->addSeparator();

QAction* openFileAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openFile);
openFileAction->setIcon(QIcon::fromTheme("document-open", QIcon(":/icons/document-open.svg")));
openFileAction->setIcon(utils::themeIcon("document-open"));
openFileAction->setShortcut(QKeySequence::Open);
openFileAction->setMenuRole(QAction::NoRole);

Expand All @@ -149,24 +149,24 @@ void MainWindow::setupActions()
fileMenu->addSeparator();

QAction* saveFileAction = fileMenu->addAction(tr("&Save"), this, &MainWindow::saveFile);
saveFileAction->setIcon(QIcon::fromTheme("document-save", QIcon(":/icons/document-save.svg")));
saveFileAction->setIcon(utils::themeIcon("document-save"));
saveFileAction->setShortcut(QKeySequence::Save);
saveFileAction->setMenuRole(QAction::NoRole);
connect(d_editor->document(), &QTextDocument::modificationChanged, saveFileAction, &QAction::setEnabled);

QAction* saveFileAsAction = fileMenu->addAction(tr("Save &As..."), this, &MainWindow::saveFileAs);
saveFileAsAction->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.svg")));
saveFileAsAction->setIcon(utils::themeIcon("document-save-as"));
saveFileAsAction->setShortcut(QKeySequence::SaveAs);
saveFileAsAction->setMenuRole(QAction::NoRole);

QAction* exportPdfAction = fileMenu->addAction(tr("&Export PDF..."), this, &MainWindow::exportPdf);
exportPdfAction->setIcon(QIcon::fromTheme("document-send", QIcon(":/icons/document-send.svg")));
exportPdfAction->setIcon(utils::themeIcon("document-send"));
exportPdfAction->setMenuRole(QAction::NoRole);

fileMenu->addSeparator();

QAction* quitAction = fileMenu->addAction(tr("&Quit"), qApp, &QCoreApplication::quit, Qt::QueuedConnection);
quitAction->setIcon(QIcon::fromTheme("application-exit", QIcon(":/icons/application-exit.svg")));
quitAction->setIcon(utils::themeIcon("application-exit"));
quitAction->setShortcut(QKeySequence::Quit);
quitAction->setMenuRole(QAction::QuitRole);

Expand All @@ -176,14 +176,14 @@ void MainWindow::setupActions()
QMenu* editMenu = menuBar()->addMenu(tr("&Edit"));

QAction* undoAction = editMenu->addAction(tr("&Undo"), d_editor, &QTextEdit::undo);
undoAction->setIcon(QIcon::fromTheme("edit-undo", QIcon(":/icons/edit-undo.svg")));
undoAction->setIcon(utils::themeIcon("edit-undo"));
undoAction->setShortcut(QKeySequence::Undo);
undoAction->setMenuRole(QAction::NoRole);
undoAction->setEnabled(false);
connect(d_editor, &QTextEdit::undoAvailable, undoAction, &QAction::setEnabled);

QAction* redoAction = editMenu->addAction(tr("&Redo"), d_editor, &QTextEdit::redo);
redoAction->setIcon(QIcon::fromTheme("edit-redo", QIcon(":/icons/edit-redo.svg")));
redoAction->setIcon(utils::themeIcon("edit-redo"));
redoAction->setShortcut(QKeySequence::Redo);
redoAction->setMenuRole(QAction::NoRole);
redoAction->setEnabled(false);
Expand All @@ -192,21 +192,21 @@ void MainWindow::setupActions()
editMenu->addSeparator();

QAction* cutAction = editMenu->addAction(tr("Cu&t"), d_editor, &QTextEdit::cut);
cutAction->setIcon(QIcon::fromTheme("edit-cut", QIcon(":/icons/edit-cut.svg")));
cutAction->setIcon(utils::themeIcon("edit-cut"));
cutAction->setShortcut(QKeySequence::Cut);
cutAction->setMenuRole(QAction::NoRole);
cutAction->setEnabled(false);
connect(d_editor, &QTextEdit::copyAvailable, cutAction, &QAction::setEnabled);

QAction* copyAction = editMenu->addAction(tr("&Copy"), d_editor, &QTextEdit::copy);
copyAction->setIcon(QIcon::fromTheme("edit-copy", QIcon(":/icons/edit-copy.svg")));
copyAction->setIcon(utils::themeIcon("edit-copy"));
copyAction->setShortcut(QKeySequence::Copy);
copyAction->setMenuRole(QAction::NoRole);
copyAction->setEnabled(false);
connect(d_editor, &QTextEdit::copyAvailable, copyAction, &QAction::setEnabled);

QAction* pasteAction = editMenu->addAction(tr("&Paste"), d_editor, &QTextEdit::paste);
pasteAction->setIcon(QIcon::fromTheme("edit-paste", QIcon(":/icons/edit-paste.svg")));
pasteAction->setIcon(utils::themeIcon("edit-paste"));
pasteAction->setShortcut(QKeySequence::Paste);
pasteAction->setMenuRole(QAction::NoRole);
pasteAction->setEnabled(d_editor->canPaste());
Expand All @@ -223,12 +223,12 @@ void MainWindow::setupActions()
editMenu->addSeparator();

QAction* findAction = editMenu->addAction(tr("&Find..."), d_searchBar, &SearchBar::ensureFindVisible);
findAction->setIcon(QIcon::fromTheme("edit-find", QIcon(":/icons/edit-find.svg")));
findAction->setIcon(utils::themeIcon("edit-find"));
findAction->setShortcut(QKeySequence::Find);
findAction->setMenuRole(QAction::NoRole);

QAction* replaceAction = editMenu->addAction(tr("&Replace..."), d_searchBar, &SearchBar::ensureReplaceVisible);
replaceAction->setIcon(QIcon::fromTheme("edit-find-replace", QIcon(":/icons/edit-find-replace.svg")));
replaceAction->setIcon(utils::themeIcon("edit-find-replace"));
replaceAction->setShortcut(QKeySequence::Replace);
replaceAction->setMenuRole(QAction::NoRole);

Expand Down Expand Up @@ -259,7 +259,7 @@ void MainWindow::setupActions()
QMenu* toolsMenu = menuBar()->addMenu(tr("&Tools"));

QAction* spellingAction = toolsMenu->addAction(tr("&Spell Checking..."), this, &MainWindow::changeSpellCheckingDictionary);
spellingAction->setIcon(QIcon::fromTheme("tools-check-spelling", QIcon(":/icons/tools-check-spelling.svg")));
spellingAction->setIcon(utils::themeIcon("tools-check-spelling"));
spellingAction->setMenuRole(QAction::NoRole);

/*
Expand All @@ -268,13 +268,13 @@ void MainWindow::setupActions()
QMenu* helpMenu = menuBar()->addMenu(tr("&Help"));

QAction* docsAction = helpMenu->addAction(tr("Typst &Documentation..."), this, &MainWindow::showTypstDocs);
docsAction->setIcon(QIcon::fromTheme("help-contents", QIcon(":/icons/help-contents.svg")));
docsAction->setIcon(utils::themeIcon("help-contents"));
docsAction->setMenuRole(QAction::NoRole);

helpMenu->addSeparator();

QAction* aboutAction = helpMenu->addAction(tr("&About..."), this, &MainWindow::showAbout);
aboutAction->setIcon(QIcon::fromTheme("help-about", QIcon(":/icons/help-about.svg")));
aboutAction->setIcon(utils::themeIcon("help-about"));
aboutAction->setMenuRole(QAction::AboutRole);
}

Expand Down
7 changes: 4 additions & 3 deletions src/katvan_previewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "katvan_previewer.h"
#include "katvan_previewerview.h"
#include "katvan_typstdriverwrapper.h"
#include "katvan_utils.h"

#include <QComboBox>
#include <QHBoxLayout>
Expand Down Expand Up @@ -63,12 +64,12 @@ Previewer::Previewer(TypstDriverWrapper* driver, QWidget* parent)
d_zoomComboBox->addItem("200%", "2.0");

QAction* zoomOutAction = new QAction(this);
zoomOutAction->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/icons/zoom-out.svg")));
zoomOutAction->setIcon(utils::themeIcon("zoom-out", "minus.magnifyingglass"));
zoomOutAction->setToolTip(tr("Zoom Out Preview"));
connect(zoomOutAction, &QAction::triggered, this, &Previewer::zoomOut);

QAction* zoomInAction = new QAction(this);
zoomInAction->setIcon(QIcon::fromTheme("zoom-in", QIcon(":/icons/zoom-in.svg")));
zoomInAction->setIcon(utils::themeIcon("zoom-in", "plus.magnifyingglass"));
zoomInAction->setToolTip(tr("Zoom In Preview"));
connect(zoomInAction, &QAction::triggered, this, &Previewer::zoomIn);

Expand All @@ -77,7 +78,7 @@ Previewer::Previewer(TypstDriverWrapper* driver, QWidget* parent)
d_currentPageLabel->setAlignment(Qt::AlignCenter);

d_followEditorCursorAction = new QAction(this);
d_followEditorCursorAction->setIcon(QIcon::fromTheme("debug-execute-from-cursor", QIcon(":/icons/debug-execute-from-cursor.svg")));
d_followEditorCursorAction->setIcon(utils::themeIcon("debug-execute-from-cursor", "text.cursor"));
d_followEditorCursorAction->setToolTip(tr("Follow Editor Cursor"));
d_followEditorCursorAction->setCheckable(true);
connect(d_followEditorCursorAction, &QAction::toggled, this, &Previewer::followEditorCursorChanged);
Expand Down
2 changes: 1 addition & 1 deletion src/katvan_recentfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void RecentFiles::rebuildMenu()
}

QAction* clearAction = d_menu->addAction(tr("Clear"), this, &RecentFiles::clear);
clearAction->setIcon(QIcon::fromTheme("edit-clear-history", QIcon(":/icons/edit-clear-history.svg")));
clearAction->setIcon(utils::themeIcon("edit-clear-history"));
clearAction->setEnabled(!d_fileList.isEmpty());
}

Expand Down
14 changes: 10 additions & 4 deletions src/katvan_searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "katvan_searchbar.h"
#include "katvan_utils.h"

#include <QActionGroup>
#include <QCoreApplication>
Expand Down Expand Up @@ -125,21 +126,21 @@ void SearchBar::setupUI()
connect(d_replaceWith, &QLineEdit::returnPressed, this, &SearchBar::replaceNext);

QToolButton* findNextButton = new QToolButton();
findNextButton->setIcon(QIcon::fromTheme("go-down", QIcon(":/icons/go-down.svg")));
findNextButton->setIcon(utils::themeIcon("go-down", "chevron.right"));
findNextButton->setShortcut(QKeySequence::FindNext);
findNextButton->setToolTip(processToolTip(tr("Go to next match (%1)"), QKeySequence::FindNext));
connect(findNextButton, &QToolButton::clicked, this, &SearchBar::findNext);

QToolButton* findPrevButton = new QToolButton();
findPrevButton->setIcon(QIcon::fromTheme("go-up", QIcon(":/icons/go-up.svg")));
findPrevButton->setIcon(utils::themeIcon("go-up", "chevron.left"));
findPrevButton->setShortcut(QKeySequence::FindPrevious);
findPrevButton->setToolTip(processToolTip(tr("Go to previous match (%1)"), QKeySequence::FindPrevious));
connect(findPrevButton, &QToolButton::clicked, this, &SearchBar::findPrevious);

QToolButton* settingsButton = new QToolButton();
settingsButton->setMenu(settingsMenu);
settingsButton->setPopupMode(QToolButton::InstantPopup);
settingsButton->setIcon(QIcon::fromTheme("settings-configure", QIcon(":/icons/settings-configure.svg")));
settingsButton->setIcon(utils::themeIcon("settings-configure", "gear"));
settingsButton->setToolTip(tr("Find settings"));

QToolButton* replaceButton = new QToolButton();
Expand All @@ -153,14 +154,19 @@ void SearchBar::setupUI()
connect(replaceAllButton, &QToolButton::clicked, this, &SearchBar::replaceAll);

QToolButton* closeButton = new QToolButton();
closeButton->setIcon(QIcon::fromTheme("window-close", QIcon(":/icons/window-close.svg")));
closeButton->setIcon(utils::themeIcon("window-close", "xmark.circle"));
closeButton->setToolTip(tr("Close search bar"));
connect(closeButton, &QToolButton::clicked, this, &QWidget::hide);

QHBoxLayout* findLayout = new QHBoxLayout();
findLayout->addWidget(d_searchTerm, 1);
#if defined(Q_OS_MACOS)
findLayout->addWidget(findPrevButton);
findLayout->addWidget(findNextButton);
#else
findLayout->addWidget(findNextButton);
findLayout->addWidget(findPrevButton);
#endif
findLayout->addWidget(settingsButton);

QHBoxLayout* replaceLayout = new QHBoxLayout();
Expand Down
19 changes: 19 additions & 0 deletions src/katvan_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ namespace katvan::utils {
static constexpr QChar LRI_MARK = (ushort)0x2066;
static constexpr QChar PDI_MARK = (ushort)0x2069;

QIcon themeIcon(const char* xdgIcon)
{
QString fallbackPath = QLatin1String(":/icons/%1.svg").arg(QLatin1String(xdgIcon));
return QIcon::fromTheme(QLatin1String(xdgIcon), QIcon(fallbackPath));
}

QIcon themeIcon(const char* xdgIcon, const char* macIcon)
{
#if !defined(Q_OS_MACOS)
return themeIcon(xdgIcon);
#else
QIcon icon = QIcon::fromTheme(QLatin1String(macIcon));
if (icon.isNull()) {
icon = themeIcon(xdgIcon);
}
return icon;
#endif
}

QString formatFilePath(QString path)
{
path = QDir::toNativeSeparators(path);
Expand Down
4 changes: 4 additions & 0 deletions src/katvan_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
#pragma once

#include <QIcon>
#include <QString>

QT_BEGIN_NAMESPACE
Expand All @@ -25,6 +26,9 @@ QT_END_NAMESPACE

namespace katvan::utils {

QIcon themeIcon(const char* xdgIcon);
QIcon themeIcon(const char* xdgIcon, const char* macIcon);

QString formatFilePath(QString path);

Qt::LayoutDirection naturalTextDirection(const QString& text);
Expand Down

0 comments on commit 68f189e

Please sign in to comment.