Skip to content

Commit

Permalink
Add blinking cursor option to keyboard cursor submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
UffeJakobsen committed Apr 20, 2021
1 parent 235df3c commit 75bb1bd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ MainWindow::MainWindow(TerminalConfig &cfg,
tabPosition(nullptr),
scrollBarPosition(nullptr),
keyboardCursorShape(nullptr),
keyboardCursorBlink(nullptr),
tabPosMenu(nullptr),
scrollPosMenu(nullptr),
keyboardCursorShapeMenu(nullptr),
Expand Down Expand Up @@ -518,13 +519,36 @@ void MainWindow::setup_ViewMenu_Actions()
consoleTabulator, &TabWidget::changeKeyboardCursorShape);
}

if (keyboardCursorBlink == nullptr) {
keyboardCursorBlink = new QActionGroup(this);
QAction *blink = new QAction(tr("&BlinkingCursor"), this);
keyboardCursorBlink->addAction(blink);
keyboardCursorBlink->setExclusive(false);

for (int i = 0; i < keyboardCursorBlink->actions().size(); ++i) {
keyboardCursorBlink->actions().at(i)->setCheckable(true);
}
keyboardCursorBlink->actions().at(0)->setChecked(Properties::Instance()->keyboardCursorBlink);

connect(keyboardCursorBlink, &QActionGroup::triggered,
consoleTabulator, &TabWidget::changeKeyboardCursorBlink);
}

if (keyboardCursorShapeMenu == nullptr) {
keyboardCursorShapeMenu = new QMenu(tr("&Keyboard Cursor Shape"), menu_Window);
keyboardCursorShapeMenu->setObjectName(QStringLiteral("keyboardCursorShapeMenu"));

for(int i=0; i < keyboardCursorShape->actions().size(); ++i) {
keyboardCursorShapeMenu->addAction(keyboardCursorShape->actions().at(i));
}

keyboardCursorShapeMenu->addSeparator();

// Blinking cursor
for (int i=0; i < keyboardCursorBlink->actions().size(); ++i) {
keyboardCursorShapeMenu->addAction(keyboardCursorBlink->actions().at(i));
}

}

menu_Window->addMenu(keyboardCursorShapeMenu);
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MainWindow : public QMainWindow, private Ui::mainWindow, public DBusAddres
bool event(QEvent* event) override;

private:
QActionGroup *tabPosition, *scrollBarPosition, *keyboardCursorShape;
QActionGroup *tabPosition, *scrollBarPosition, *keyboardCursorShape, *keyboardCursorBlink;
QMenu *tabPosMenu, *scrollPosMenu, *keyboardCursorShapeMenu;

// A parent object for QObjects that are created dynamically based on settings
Expand Down
2 changes: 2 additions & 0 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void Properties::loadSettings()
tabsPos = m_settings->value(QLatin1String("TabsPosition"), 0).toInt();
/* default to BlockCursor */
keyboardCursorShape = m_settings->value(QLatin1String("KeyboardCursorShape"), 0).toInt();
keyboardCursorBlink = m_settings->value(QLatin1String("KeyboardCursorBlink"), false).toBool();
hideTabBarWithOneTab = m_settings->value(QLatin1String("HideTabBarWithOneTab"), false).toBool();
// For "Motion after paste", 2 (scrolling to bottom) makes more sense
m_motionAfterPaste = m_settings->value(QLatin1String("MotionAfterPaste"), 2).toInt();
Expand Down Expand Up @@ -225,6 +226,7 @@ void Properties::saveSettings()
m_settings->setValue(QLatin1String("ScrollbarPosition"), scrollBarPos);
m_settings->setValue(QLatin1String("TabsPosition"), tabsPos);
m_settings->setValue(QLatin1String("KeyboardCursorShape"), keyboardCursorShape);
m_settings->setValue(QLatin1String("KeyboardCursorBlink"), keyboardCursorBlink);
m_settings->setValue(QLatin1String("HideTabBarWithOneTab"), hideTabBarWithOneTab);
m_settings->setValue(QLatin1String("MotionAfterPaste"), m_motionAfterPaste);
m_settings->setValue(QLatin1String("DisableBracketedPasteMode"), m_disableBracketedPasteMode);
Expand Down
1 change: 1 addition & 0 deletions src/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Properties
int scrollBarPos;
int tabsPos;
int keyboardCursorShape;
bool keyboardCursorBlink;
bool hideTabBarWithOneTab;
int m_motionAfterPaste;
bool m_disableBracketedPasteMode;
Expand Down
14 changes: 14 additions & 0 deletions src/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,20 @@ void TabWidget::changeKeyboardCursorShape(QAction *triggered)
propertiesChanged();
}

void TabWidget::changeKeyboardCursorBlink(QAction *triggered)
{
QActionGroup *keyboardCursorBlink = static_cast<QActionGroup *>(sender());
if (!keyboardCursorBlink)
qFatal("keyboardCursorBlink is NULL");

const int index = keyboardCursorBlink->actions().indexOf(triggered);
const bool flag = keyboardCursorBlink->actions().at(index)->isChecked();

Properties::Instance()->keyboardCursorBlink = flag;
Properties::Instance()->saveSettings();
propertiesChanged();
}

void TabWidget::propertiesChanged()
{
for (int i = 0; i < count(); ++i)
Expand Down
1 change: 1 addition & 0 deletions src/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public slots:
void changeTabPosition(QAction *);
void changeScrollPosition(QAction *);
void changeKeyboardCursorShape(QAction *);
void changeKeyboardCursorBlink(QAction *);
void propertiesChanged();

void clearActiveTerminal();
Expand Down
2 changes: 2 additions & 0 deletions src/termwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void TermWidgetImpl::propertiesChanged()
break;
}

setBlinkingCursor(Properties::Instance()->keyboardCursorBlink);

update();
}

Expand Down

0 comments on commit 75bb1bd

Please sign in to comment.