@@ -43,7 +43,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
4343
4444MainWindow::~MainWindow ()
4545{
46- instance = nullptr ;
46+ delete instance ;
4747delete ui;
4848}
4949
@@ -112,25 +112,28 @@ void MainWindow::initConnections()
112112
113113connect (hotkey, &QHotkey::activated,this , &MainWindow::shortcutTriggered);
114114
115- // connect(floatBtn, &QtMaterialFloatingActionButton::clicked, this, [&]() {
116- // if (settingsWindow == nullptr) {
117- // settingsWindow = new SettingsWindow(this);
115+ connect (floatBtn, &QtMaterialFloatingActionButton::clicked,this , [&]() {
116+ if (settingsWindow ==nullptr ) {
117+ settingsWindow =new SettingsWindow (this );
118118
119- // connect(settingsWindow, &SettingsWindow::closed, this, [&]() { settingsWindow = nullptr; });
120- // settingsWindow->show();
121- // settingsWindow->raise();
122- // settingsWindow->activateWindow();
123- // }
124- // });
119+ connect (settingsWindow, &SettingsWindow::closed,this , [&]() { settingsWindow =nullptr ; });
120+ settingsWindow->show ();
121+ settingsWindow->raise ();
122+ settingsWindow->activateWindow ();
123+ }
124+ });
125125}
126126
127127void MainWindow::loadSettings ()
128128{
129129// QSettings settings(settingsIniFile, QSettings::IniFormat);
130130
131- // if (settings.value("autoToggle", false).toBool()) {
132- // autoToggle->setChecked(true);
133- // }
131+ if (settings.value (" autoToggle" ,false ).toBool ()) {
132+ ui->autoToggle ->setChecked (true );
133+ }
134+ if (settings.value (" hotkeyToggle" ,false ).toBool ()) {
135+ ui->hotkeyToggle ->setChecked (true );
136+ }
134137
135138registerShortcut (settings.value (" shortcut" ," Ctrl+Shift+C" ).toString ());
136139}
@@ -139,9 +142,10 @@ void MainWindow::saveSettings()
139142{
140143// QSettings settings(settingsIniFile, QSettings::IniFormat, this);
141144
142- // settings.setValue("autoToggle", autoToggle->isChecked());
143- settings.setValue (" shortcut " ,hotkey-> shortcut (). toString ());
145+ settings.setValue (" autoToggle" ,ui-> autoToggle ->isChecked ());
146+ settings.setValue (" hotkeyToggle " ,ui-> hotkeyToggle -> isChecked ());
144147
148+ settings.setValue (" shortcut" , hotkey->shortcut ().toString ());
145149qDebug () <<" Save shortcut:" << hotkey->shortcut ().toString ();
146150}
147151
@@ -155,25 +159,25 @@ void MainWindow::autoToggleChecked(bool status)
155159{
156160if (status) {
157161qDebug () <<" Auto enabled" ;
158- // connect(QGuiApplication::clipboard(), &QClipboard::changed, this, &MainWindow::afterChanged);
162+ connect (QGuiApplication::clipboard (), &QClipboard::changed,this , &MainWindow::afterChanged);
159163 }else {
160164qDebug () <<" Auto disabled" ;
161- // disconnect(QGuiApplication::clipboard(), &QClipboard::changed, this, &MainWindow::afterChanged);
165+ disconnect (QGuiApplication::clipboard (), &QClipboard::changed,this , &MainWindow::afterChanged);
162166 }
163167}
164168
165- // void MainWindow::toggleShortcutChecked (bool status)
166- // {
167- // // TODO:快捷键为空、冲突时, 应该有提醒
168- // QString seq = settings.value("shortcut", "Ctrl+Shift+C").toString();
169- // if (status) {
170- // qDebug() << "Shortcut enabled";
171- // registerShortcut(seq);
172- // } else {
173- // qDebug() << "Shortcut disabled";
174- // hotkey->resetShortcut();
175- // }
176- // }
169+ void MainWindow::hotkeyToggleChecked (bool status)
170+ {
171+ // TODO:快捷键为空、冲突时, 应该有提醒
172+ QString seq = settings.value (" shortcut" ," Ctrl+Shift+C" ).toString ();
173+ if (status) {
174+ qDebug () <<" Shortcut enabled" ;
175+ registerShortcut (seq);
176+ }else {
177+ qDebug () <<" Shortcut disabled" ;
178+ hotkey->resetShortcut ();
179+ }
180+ }
177181
178182// Register shortcut
179183void MainWindow::registerShortcut (const QKeySequence &keySequence)