Skip to content

Commit

Permalink
fix #378, add font bigger/smaller menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Jul 25, 2023
1 parent 5450744 commit 2088547
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 12 deletions.
32 changes: 29 additions & 3 deletions QtSLiM/QtSLiMAppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,13 @@ void QtSLiMAppDelegate::addActionsForGlobalMenuItems(QWidget *window)
}
{
QAction *actionPrettyprintScript = new QAction("Prettyprint Script", this);
actionPrettyprintScript->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Equal);
//actionPrettyprintScript->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Equal); // this now goes to actionBiggerFont
connect(actionPrettyprintScript, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_prettyprintScript);
window->addAction(actionPrettyprintScript);
}
{
QAction *actionReformatScript = new QAction("Reformat Script", this);
actionReformatScript->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_Equal);
QAction *actionReformatScript = new QAction("Reformat Script", this); // removed since the shortcut for actionPrettyprintScript was removed
//actionReformatScript->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::ALT + Qt::Key_Equal);
connect(actionReformatScript, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_reformatScript);
window->addAction(actionReformatScript);
}
Expand All @@ -916,6 +916,18 @@ void QtSLiMAppDelegate::addActionsForGlobalMenuItems(QWidget *window)
connect(actionShowScriptHelp, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_help);
window->addAction(actionShowScriptHelp);
}
{
QAction *actionBiggerFont = new QAction("Bigger Font", this);
actionBiggerFont->setShortcut(Qt::CTRL + Qt::Key_Plus);
connect(actionBiggerFont, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_biggerFont);
window->addAction(actionBiggerFont);
}
{
QAction *actionSmallerFont = new QAction("Smaller Font", this);
actionSmallerFont->setShortcut(Qt::CTRL + Qt::Key_Minus);
connect(actionSmallerFont, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_smallerFont);
window->addAction(actionSmallerFont);
}
{
QAction *actionShowEidosConsole = new QAction("Show Eidos Console", this);
actionShowEidosConsole->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_E);
Expand Down Expand Up @@ -1223,6 +1235,20 @@ void QtSLiMAppDelegate::dispatch_help(void)
helpWindow.activateWindow();
}

void QtSLiMAppDelegate::dispatch_biggerFont(void)
{
QtSLiMPreferencesNotifier &prefs = QtSLiMPreferencesNotifier::instance();

prefs.displayFontBigger();
}

void QtSLiMAppDelegate::dispatch_smallerFont(void)
{
QtSLiMPreferencesNotifier &prefs = QtSLiMPreferencesNotifier::instance();

prefs.displayFontSmaller();
}

void QtSLiMAppDelegate::dispatch_quit(void)
{
if (qApp)
Expand Down
3 changes: 3 additions & 0 deletions QtSLiM/QtSLiMAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public slots:
void dispatch_help(void);
void dispatch_quit(void);

void dispatch_biggerFont(void);
void dispatch_smallerFont(void);

void dispatch_newWF(void);
void dispatch_newWF_commentless(void);
void dispatch_newNonWF(void);
Expand Down
58 changes: 55 additions & 3 deletions QtSLiM/QtSLiMPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,53 @@ bool QtSLiMPreferencesNotifier::showSaveIfUntitledPref(void) const
return settings.value(QtSLiMShowSaveInUntitled, QVariant(false)).toBool();
}

void QtSLiMPreferencesNotifier::displayFontBigger(void)
{
QFont &defaultFont = defaultDisplayFont();
int defaultSize = defaultFont.pointSize();

QSettings settings;
int fontSize = settings.value(QtSLiMDisplayFontSize, QVariant(defaultSize)).toInt();

if (fontSize < 50) // matches value in QtSLiMPreferences.ui
{
// if the prefs window exists, we need to tell it to adjust itself
// if not, we send ourselves the message it would have sent us
QtSLiMPreferences *prefsWindow = QtSLiMPreferences::instanceForcingAllocation(false);

if (prefsWindow)
prefsWindow->ui->fontSizeSpinBox->setValue(fontSize + 1);
else
fontSizeChanged(fontSize + 1);
}
else
qApp->beep();
}

void QtSLiMPreferencesNotifier::displayFontSmaller(void)
{
QFont &defaultFont = defaultDisplayFont();
int defaultSize = defaultFont.pointSize();

QSettings settings;
int fontSize = settings.value(QtSLiMDisplayFontSize, QVariant(defaultSize)).toInt();

if (fontSize > 6) // matches value in QtSLiMPreferences.ui
{
// if the prefs window exists, we need to tell it to adjust itself
// if not, we send ourselves the message it would have sent us
QtSLiMPreferences *prefsWindow = QtSLiMPreferences::instanceForcingAllocation(false);

if (prefsWindow)
prefsWindow->ui->fontSizeSpinBox->setValue(fontSize - 1);
else
fontSizeChanged(fontSize - 1);
}
else
qApp->beep();
}


// slots; these update the settings and then emit new signals

void QtSLiMPreferencesNotifier::startupRadioChanged()
Expand Down Expand Up @@ -320,14 +367,19 @@ void QtSLiMPreferencesNotifier::resetSuppressedClicked()
// QtSLiMPreferences: the actual UI class
//

QtSLiMPreferences &QtSLiMPreferences::instance(void)
QtSLiMPreferences *QtSLiMPreferences::instanceForcingAllocation(bool force_allocation)
{
static QtSLiMPreferences *inst = nullptr;

if (!inst)
if (!inst && force_allocation)
inst = new QtSLiMPreferences(nullptr);

return *inst;
return inst;
}

QtSLiMPreferences &QtSLiMPreferences::instance(void)
{
return *QtSLiMPreferences::instanceForcingAllocation(true);
}

QtSLiMPreferences::QtSLiMPreferences(QWidget *p_parent) : QDialog(p_parent), ui(new Ui::QtSLiMPreferences)
Expand Down
5 changes: 5 additions & 0 deletions QtSLiM/QtSLiMPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class QtSLiMPreferencesNotifier : public QObject
bool autosaveOnRecyclePref(void) const;
bool showSaveIfUntitledPref(void) const;

// Change preferences values in ways other than the Preferences panel itself
void displayFontBigger(void);
void displayFontSmaller(void);

signals:
// Get notified when a pref value changes
void appStartupPrefChanged(void);
Expand Down Expand Up @@ -92,6 +96,7 @@ class QtSLiMPreferences : public QDialog
Q_OBJECT

public:
static QtSLiMPreferences *instanceForcingAllocation(bool force_allocation);
static QtSLiMPreferences &instance(void);

private:
Expand Down
5 changes: 5 additions & 0 deletions QtSLiM/QtSLiMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,8 @@ void QtSLiMWindow::updateMenuEnablingACTIVE(QWidget *p_focusWidget)
ui->actionPrettyprintScript->setEnabled(!continuousPlayOn_);
ui->actionReformatScript->setEnabled(!continuousPlayOn_);
ui->actionShowScriptHelp->setEnabled(true);
ui->actionBiggerFont->setEnabled(true);
ui->actionSmallerFont->setEnabled(true);
ui->actionShowEidosConsole->setEnabled(true);
ui->actionShowVariableBrowser->setEnabled(true);
ui->actionShowDebuggingOutput->setEnabled(true);
Expand Down Expand Up @@ -2823,6 +2825,9 @@ void QtSLiMWindow::updateMenuEnablingSHARED(QWidget *p_focusWidget)
ui->actionDelete->setEnabled(hasEnabledModifiableDestination);
ui->actionSelectAll->setEnabled(hasEnabledDestination);

ui->actionBiggerFont->setEnabled(true);
ui->actionSmallerFont->setEnabled(true);

// actions handled by QtSLiMScriptTextEdit only
QtSLiMScriptTextEdit *scriptEdit = dynamic_cast<QtSLiMScriptTextEdit*>(p_focusWidget);
bool isModifiableScriptTextEdit = (scriptEdit && !scriptEdit->isReadOnly());
Expand Down
25 changes: 19 additions & 6 deletions QtSLiM/QtSLiMWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,9 @@ QSlider::handle:horizontal:disabled {
<addaction name="actionReformatScript"/>
<addaction name="actionShowScriptHelp"/>
<addaction name="separator"/>
<addaction name="actionBiggerFont"/>
<addaction name="actionSmallerFont"/>
<addaction name="separator"/>
<addaction name="actionShowVariableBrowser"/>
<addaction name="actionShowEidosConsole"/>
<addaction name="actionShowDebuggingOutput"/>
Expand Down Expand Up @@ -1638,9 +1641,6 @@ QSlider::handle:horizontal:disabled {
<property name="text">
<string>Prettyprint Script</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+=</string>
</property>
</action>
<action name="actionShowScriptHelp">
<property name="text">
Expand Down Expand Up @@ -1875,9 +1875,6 @@ QSlider::handle:horizontal:disabled {
<property name="text">
<string>Reformat Script</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+Shift+=</string>
</property>
</action>
<action name="actionShowDebuggingOutput">
<property name="text">
Expand Down Expand Up @@ -2004,6 +2001,22 @@ QSlider::handle:horizontal:disabled {
<string>Ctrl+2</string>
</property>
</action>
<action name="actionBiggerFont">
<property name="text">
<string>Bigger Font</string>
</property>
<property name="shortcut">
<string>Ctrl++</string>
</property>
</action>
<action name="actionSmallerFont">
<property name="text">
<string>Smaller Font</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
2 changes: 2 additions & 0 deletions QtSLiM/QtSLiMWindow_glue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ void QtSLiMWindow::glueUI(void)
connect(ui->actionPrettyprintScript, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_prettyprintScript);
connect(ui->actionReformatScript, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_reformatScript);
connect(ui->actionShowScriptHelp, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_help);
connect(ui->actionBiggerFont, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_biggerFont);
connect(ui->actionSmallerFont, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_smallerFont);
connect(ui->actionShowEidosConsole, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_showEidosConsole);
connect(ui->actionShowVariableBrowser, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_showVariableBrowser);
connect(ui->actionClearOutput, &QAction::triggered, qtSLiMAppDelegate, &QtSLiMAppDelegate::dispatch_clearOutput);
Expand Down
2 changes: 2 additions & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ development head (in the master branch):
bug fix: #361, more than 2 billion mutations overflows without a good error message
bug fix: #365, problems loading a tree sequence; what I fixed is to catch the uncaught raise from std::stoll() in Species::DerivedStatesFromAscii()
bug fix in pyslim to announce: https://github.com/tskit-dev/pyslim/issues/307
feature request: #378, add font bigger (command +) and font smaller (command -) menu items and shortcuts, so the user doesn't have to open the prefs window; note that with command = the shift key is needed
this meant removal of the shortcuts for prettyprint script and reformat script, since they conflicted (well, prettyprint conflicted); probably nobody cares


version 4.0.1 (Eidos version 3.0.1):
Expand Down

0 comments on commit 2088547

Please sign in to comment.