diff --git a/QKeyMapper/main.cpp b/QKeyMapper/main.cpp index ff08c7d..972e52b 100644 --- a/QKeyMapper/main.cpp +++ b/QKeyMapper/main.cpp @@ -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 @@ -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(); } diff --git a/QKeyMapper/qkeymapper.cpp b/QKeyMapper/qkeymapper.cpp index bdedd61..ff410cd 100644 --- a/QKeyMapper/qkeymapper.cpp +++ b/QKeyMapper/qkeymapper.cpp @@ -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"); @@ -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); @@ -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))); @@ -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) @@ -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 @@ -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("

Load invalid keymapdata from ini file.

Reset to default values.

")); return false; } else{ + if (true == autoStartMappingChecked) { + on_keymapButton_clicked(); + } return true; } } @@ -1484,6 +1512,7 @@ void QKeyMapper::setControlCustomFont(const QString &fontname) customFont.setPointSize(14); ui->disableWinKeyCheckBox->setFont(customFont); + ui->autoStartMappingCheckBox->setFont(customFont); } void QKeyMapper::changeControlEnableStatus(bool status) @@ -1491,6 +1520,7 @@ 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); diff --git a/QKeyMapper/qkeymapper.h b/QKeyMapper/qkeymapper.h index b45f4e1..ab2f537 100644 --- a/QKeyMapper/qkeymapper.h +++ b/QKeyMapper/qkeymapper.h @@ -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; diff --git a/QKeyMapper/qkeymapper.ui b/QKeyMapper/qkeymapper.ui index aec679e..c37139f 100644 --- a/QKeyMapper/qkeymapper.ui +++ b/QKeyMapper/qkeymapper.ui @@ -338,7 +338,7 @@ 810 - 550 + 555 121 21 @@ -1102,6 +1102,25 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 620 + 555 + 151 + 21 + + + + Qt::NoFocus + + + Auto Start Mapping + + + false + +