Skip to content

Commit

Permalink
Add auto start mapping checkbox for autostart mapping at startup.
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin Li <[email protected]>
  • Loading branch information
Zalafina committed Nov 27, 2022
1 parent 3926264 commit 7e1d50c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
11 changes: 9 additions & 2 deletions QKeyMapper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char *argv[])
QApplication::setStyle(QStyleFactory::create("Fusion"));

#ifdef DEBUG_LOGOUT_ON
qSetMessagePattern("%{time [hh:mm:ss.zzz]} Message:%{message}");
qSetMessagePattern("%{time [hh:mm:ss.zzz]} %{message}");
#endif

#ifdef ADJUST_PRIVILEGES
Expand All @@ -33,7 +33,14 @@ int main(int argc, char *argv[])
flags |= Qt::WindowCloseButtonHint;
w.setWindowFlags(flags);

w.show();
if (true == w.getAutoStartMappingStatus()) {
#ifdef DEBUG_LOGOUT_ON
qDebug() << "Auto Start Mapping = TRUE, hide QKeyMapper window at startup.";
#endif
}
else {
w.show();
}

return a.exec();
}
42 changes: 36 additions & 6 deletions QKeyMapper/qkeymapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static const QString PROCESSINFO_FILEPATH("ProcessInfo/FilePath");
static const QString PROCESSINFO_FILENAME_CHECKED("ProcessInfo/FileNameChecked");
static const QString PROCESSINFO_WINDOWTITLE_CHECKED("ProcessInfo/WindowTitleChecked");
static const QString PROCESSINFO_DISABLEWINKEY_CHECKED("ProcessInfo/DisableWinKeyChecked");
static const QString PROCESSINFO_AUTOSTARTMAPPING_CHECKED("ProcessInfo/AutoStartMappingChecked");

static const QString SAO_FONTFILENAME(":/sao_ui.otf");

Expand Down Expand Up @@ -111,10 +112,14 @@ QKeyMapper::QKeyMapper(QWidget *parent) :
initProcessInfoTable();
ui->nameCheckBox->setFocusPolicy(Qt::NoFocus);
ui->titleCheckBox->setFocusPolicy(Qt::NoFocus);
ui->disableWinKeyCheckBox->setFocusPolicy(Qt::NoFocus);
ui->nameLineEdit->setFocusPolicy(Qt::NoFocus);
ui->titleLineEdit->setFocusPolicy(Qt::NoFocus);

m_SysTrayIcon = new QSystemTrayIcon(this);
m_SysTrayIcon->setIcon(QIcon(":/AppIcon.ico"));
m_SysTrayIcon->setToolTip("QKeyMapper(Idle)");
m_SysTrayIcon->show();

initKeyMappingDataTable();
bool loadresult = loadKeyMapSetting();
Q_UNUSED(loadresult);
Expand Down Expand Up @@ -161,11 +166,6 @@ QKeyMapper::QKeyMapper(QWidget *parent) :
}
}

m_SysTrayIcon = new QSystemTrayIcon(this);
m_SysTrayIcon->setIcon(QIcon(":/AppIcon.ico"));
m_SysTrayIcon->setToolTip("QKeyMapper(Idle)");
m_SysTrayIcon->show();

QObject::connect(m_SysTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(SystrayIconActivated(QSystemTrayIcon::ActivationReason)));
QObject::connect(&m_CycleCheckTimer, SIGNAL(timeout()), this, SLOT(cycleCheckProcessProc()));
QObject::connect(ui->keymapdataTable, SIGNAL(cellChanged(int,int)), this, SLOT(on_cellChanged(int,int)));
Expand Down Expand Up @@ -1002,6 +1002,16 @@ void QKeyMapper::EnumProcessFunction(void)

}

bool QKeyMapper::getAutoStartMappingStatus()
{
if (true == ui->autoStartMappingCheckBox->isChecked()) {
return true;
}
else {
return false;
}
}

void QKeyMapper::changeEvent(QEvent *event)
{
if(event->type()==QEvent::WindowStateChange)
Expand Down Expand Up @@ -1233,6 +1243,7 @@ void QKeyMapper::saveKeyMapSetting(void)
settingFile.setValue(PROCESSINFO_FILENAME_CHECKED, ui->nameCheckBox->isChecked());
settingFile.setValue(PROCESSINFO_WINDOWTITLE_CHECKED, ui->titleCheckBox->isChecked());
settingFile.setValue(PROCESSINFO_DISABLEWINKEY_CHECKED, ui->disableWinKeyCheckBox->isChecked());
settingFile.setValue(PROCESSINFO_AUTOSTARTMAPPING_CHECKED, ui->autoStartMappingCheckBox->isChecked());
}
else{
#ifdef DEBUG_LOGOUT_ON
Expand Down Expand Up @@ -1408,11 +1419,28 @@ bool QKeyMapper::loadKeyMapSetting(void)
#endif
}

bool autoStartMappingChecked = false;
if (true == settingFile.contains(PROCESSINFO_AUTOSTARTMAPPING_CHECKED)){
autoStartMappingChecked = settingFile.value(PROCESSINFO_AUTOSTARTMAPPING_CHECKED).toBool();
if (true == autoStartMappingChecked) {
ui->autoStartMappingCheckBox->setChecked(true);
}
else {
ui->autoStartMappingCheckBox->setChecked(false);
}
#ifdef DEBUG_LOGOUT_ON
qDebug() << "[loadKeyMapSetting]" << "AutoStartMappingChecked =" << autoStartMappingChecked;
#endif
}

if (false == datavalidflag){
QMessageBox::warning(this, tr("QKeyMapper"), tr("<html><head/><body><p align=\"center\">Load invalid keymapdata from ini file.</p><p align=\"center\">Reset to default values.</p></body></html>"));
return false;
}
else{
if (true == autoStartMappingChecked) {
on_keymapButton_clicked();
}
return true;
}
}
Expand Down Expand Up @@ -1484,13 +1512,15 @@ void QKeyMapper::setControlCustomFont(const QString &fontname)

customFont.setPointSize(14);
ui->disableWinKeyCheckBox->setFont(customFont);
ui->autoStartMappingCheckBox->setFont(customFont);
}

void QKeyMapper::changeControlEnableStatus(bool status)
{
ui->nameCheckBox->setEnabled(status);
ui->titleCheckBox->setEnabled(status);
ui->disableWinKeyCheckBox->setEnabled(status);
ui->autoStartMappingCheckBox->setEnabled(status);
ui->burstpressComboBox->setEnabled(status);
ui->burstreleaseComboBox->setEnabled(status);
//ui->nameLineEdit->setEnabled(status);
Expand Down
2 changes: 2 additions & 0 deletions QKeyMapper/qkeymapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ class QKeyMapper : public QDialog
static void EnumProcessFunction(void);
// unused enum all process function <<<

bool getAutoStartMappingStatus(void);

protected:
void changeEvent(QEvent *event);
void timerEvent(QTimerEvent *event) override;
Expand Down
21 changes: 20 additions & 1 deletion QKeyMapper/qkeymapper.ui
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
<property name="geometry">
<rect>
<x>810</x>
<y>550</y>
<y>555</y>
<width>121</width>
<height>21</height>
</rect>
Expand Down Expand Up @@ -1102,6 +1102,25 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QCheckBox" name="autoStartMappingCheckBox">
<property name="geometry">
<rect>
<x>620</x>
<y>555</y>
<width>151</width>
<height>21</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Auto Start Mapping</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
Expand Down

0 comments on commit 7e1d50c

Please sign in to comment.