Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Oct 15, 2023
1 parent 170bba5 commit 06f11bc
Show file tree
Hide file tree
Showing 9 changed files with 989 additions and 880 deletions.
Binary file added resources/MaterialIconsOutlined-Regular.otf
Binary file not shown.
1 change: 1 addition & 0 deletions resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="/fonts">
<file>Lato-Light.ttf</file>
<file>Lato-Regular.ttf</file>
<file>MaterialIconsOutlined-Regular.otf</file>
</qresource>
<qresource prefix="/images">
<file>checkmark.png</file>
Expand Down
5 changes: 2 additions & 3 deletions src/qvaboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "qvapplication.h"

#include <QFontDatabase>
#include <QJsonDocument>

QVAboutDialog::QVAboutDialog(QWidget *parent) :
Expand All @@ -25,8 +24,8 @@ QVAboutDialog::QVAboutDialog(QWidget *parent) :
#endif

// add fonts
QFontDatabase::addApplicationFont(":/fonts/Lato-Light.ttf");
QFontDatabase::addApplicationFont(":/fonts/Lato-Regular.ttf");
qvApp->ensureFontLoaded(":/fonts/Lato-Light.ttf");
qvApp->ensureFontLoaded(":/fonts/Lato-Regular.ttf");

int modifier = 0;
//set main title font
Expand Down
29 changes: 29 additions & 0 deletions src/qvapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QTimer>
#include <QFileDialog>
#include <QMessageBox>
#include <QFontDatabase>

QVApplication::QVApplication(int &argc, char **argv) : QApplication(argc, argv)
{
Expand Down Expand Up @@ -366,6 +367,34 @@ void QVApplication::defineFilterLists()
nameFilterList << tr("All Files") + " (*)";
}

void QVApplication::ensureFontLoaded(const QString &path)
{
if (loadedFontPaths.contains(path))
return;

QFontDatabase::addApplicationFont(path);
loadedFontPaths.insert(path);
}

QIcon QVApplication::iconFromFont(const QString &fontFamily, const QChar &codePoint, const int pixelSize, const qreal pixelRatio)
{
const int scaledPixelSize = qRound(pixelSize * pixelRatio);

QFont font(fontFamily);
font.setPixelSize(pixelSize);

QPixmap pixmap(scaledPixelSize, scaledPixelSize);
pixmap.fill(Qt::transparent);
pixmap.setDevicePixelRatio(pixelRatio);

QPainter painter(&pixmap);
painter.setFont(font);
painter.setPen(QApplication::palette().color(QPalette::WindowText));
painter.drawText(pixmap.rect(), codePoint);

return QIcon(pixmap);
}

bool QVApplication::supportsSessionPersistence()
{
#if defined(Q_OS_MACOS)
Expand Down
6 changes: 6 additions & 0 deletions src/qvapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class QVApplication : public QApplication

bool getShowSubmenuIcons() const { return showSubmenuIcons; }

void ensureFontLoaded(const QString &path);

static QIcon iconFromFont(const QString &fontFamily, const QChar &codePoint, const int pixelSize, const qreal pixelRatio);

static bool supportsSessionPersistence();

static bool tryRestoreLastSession();
Expand Down Expand Up @@ -134,6 +138,8 @@ protected slots:

UpdateChecker updateChecker;

QSet<QString> loadedFontPaths;

bool isApplicationQuitting {false};
bool userDeclinedSessionStateSave {false};
QList<ClosedWindowData> closedWindowData;
Expand Down
24 changes: 22 additions & 2 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint | Qt::CustomizeWindowHint));

qvApp->ensureFontLoaded(":/fonts/MaterialIconsOutlined-Regular.otf");

connect(ui->categoryList, &QListWidget::currentRowChanged, this, [this](int currentRow) { ui->stackedWidget->setCurrentIndex(currentRow); });
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &QVOptionsDialog::buttonBoxClicked);
connect(ui->shortcutsTable, &QTableWidget::cellDoubleClicked, this, &QVOptionsDialog::shortcutCellDoubleClicked);
connect(ui->bgColorCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::bgColorCheckboxStateChanged);
Expand All @@ -31,11 +34,12 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
connect(ui->windowResizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged);
connect(ui->langComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::languageComboBoxCurrentIndexChanged);

populateCategories();
populateComboBoxes();
populateLanguages();

QSettings settings;
ui->tabWidget->setCurrentIndex(settings.value("optionstab", 1).toInt());
ui->categoryList->setCurrentRow(settings.value("optionstab", 1).toInt());

// On macOS, the dialog should not be dependent on any window
#ifndef Q_OS_MACOS
Expand Down Expand Up @@ -101,7 +105,7 @@ void QVOptionsDialog::done(int r)
// Save window geometry
QSettings settings;
settings.setValue("optionsgeometry", saveGeometry());
settings.setValue("optionstab", ui->tabWidget->currentIndex());
settings.setValue("optionstab", ui->categoryList->currentRow());

QDialog::done(r);
}
Expand Down Expand Up @@ -519,6 +523,22 @@ void QVOptionsDialog::constrainImagePositionCheckboxStateChanged(int state)
ui->constrainCentersSmallImageCheckbox->setEnabled(static_cast<bool>(state));
}

void QVOptionsDialog::populateCategories()
{
const int iconSize = 24;
auto addItem = [this](const QChar &iconChar, const QString &text) {
ui->categoryList->addItem(new QListWidgetItem(qvApp->iconFromFont("Material Icons Outlined", iconChar, iconSize, devicePixelRatioF()), text));
};
ui->categoryList->setIconSize(QSize(iconSize, iconSize));
ui->categoryList->setFont(QApplication::font());
addItem(u'\ue069', tr("Window"));
addItem(u'\ue3f4', tr("Image"));
addItem(u'\ue429', tr("Miscellaneous"));
addItem(u'\ue312', tr("Shortcuts"));
addItem(u'\ue323', tr("Mouse"));
ui->categoryList->setFixedWidth(ui->categoryList->sizeHintForColumn(0) + ui->categoryList->frameWidth() + 2);
}

void QVOptionsDialog::populateLanguages()
{
ui->langComboBox->clear();
Expand Down
1 change: 1 addition & 0 deletions src/qvoptionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class QVOptionsDialog : public QDialog
void bgColorButtonClicked();
void updateBgColorButton();
void restartNotifyForCheckbox(const QString &key, const int state);
void populateCategories();
void populateLanguages();
void populateComboBoxes();

Expand Down
Loading

0 comments on commit 06f11bc

Please sign in to comment.