22#include " publicdata.h"
33#include " ui_settingdialog.h"
44#include < QCheckBox>
5- #include < QFileDialog>
65#include < QDebug>
7- #include < QSettings>
8- #include < QMessageBox>
96#include < QDesktopServices>
7+ #include < QFileDialog>
8+ #include < QMessageBox>
109#include < QRegularExpression>
10+ #include < QSettings>
1111
12- SettingDialog::SettingDialog (QWidget * parent) :
13- QDialog(parent),
14- ui(new Ui::SettingDialog)
12+ SettingDialog::SettingDialog (QWidget* parent)
13+ : QDialog(parent)
14+ , ui(new Ui::SettingDialog)
1515{
1616 ui->setupUi (this );
1717
@@ -21,9 +21,9 @@ SettingDialog::SettingDialog(QWidget *parent) :
2121 ui->listWidgetSetting ->addItem (new QListWidgetItem (tabBar->tabIcon (i), tabBar->tabText (i), ui->listWidgetSetting ));
2222 }
2323
24- readAndInitSettings (); // 进行初始设置
24+ readAndInitSettings (); // 进行初始设置
2525
26- initConnect (); // 在控件状态(选中、值等)发生改变时改变PublicData里的值
26+ initConnect (); // 在控件状态(选中、值等)发生改变时改变PublicData里的值
2727}
2828
2929SettingDialog::~SettingDialog ()
@@ -38,67 +38,67 @@ SettingDialog::~SettingDialog()
3838
3939void SettingDialog::initConnect ()
4040{
41- connect (ui->listWidgetSetting , &QListWidget::currentRowChanged, this , [=](int currentRow){
41+ connect (ui->listWidgetSetting , &QListWidget::currentRowChanged, this , [=](int currentRow) {
4242 ui->tabWidgetSetting ->setCurrentIndex (currentRow);
4343 });
4444
45- connect (ui->comboBoxSnapMethod , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index){
45+ connect (ui->comboBoxSnapMethod , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index) {
4646 if (index < SNAPMETHOD) {
4747 PublicData::snapMethod = index;
4848 }
4949 });
5050
51- connect (ui->keySequenceEditHotKey , &QKeySequenceEdit::keySequenceChanged, this , [=](const QKeySequence & keySequence){
51+ connect (ui->keySequenceEditHotKey , &QKeySequenceEdit::keySequenceChanged, this , [=](const QKeySequence& keySequence) {
5252 PublicData::snapTypeItems[ui->comboBoxSnapType ->currentIndex ()].hotKey = keySequence.toString ();
5353 });
5454
55- connect (ui->checkBoxNoBorder , &QCheckBox::stateChanged, this , [=](int state){
55+ connect (ui->checkBoxNoBorder , &QCheckBox::stateChanged, this , [=](int state) {
5656 PublicData::noBorder = state;
5757 });
5858
59- connect (ui->horizontalSliderWaitTime , &QAbstractSlider::valueChanged, this , [=](int value){
59+ connect (ui->horizontalSliderWaitTime , &QAbstractSlider::valueChanged, this , [=](int value) {
6060 ui->labelWaitTime ->setText (tr (" 截图前等待时间: " ) + QString::number (value) + tr (" s" ));
6161 if (ui->comboBoxSnapType ->currentIndex () <= ScreenShotHelper::ShotType::Count) {
6262 PublicData::snapTypeItems[ui->comboBoxSnapType ->currentIndex ()].waitTime = value;
6363 }
6464 });
6565
66- connect (ui->cbManualSaveAfterShot , &QCheckBox::stateChanged, this , [=](int state){
66+ connect (ui->cbManualSaveAfterShot , &QCheckBox::stateChanged, this , [=](int state) {
6767 int index = ui->comboBoxSnapType ->currentIndex ();
6868 if (index <= (int )(sizeof (PublicData::snapTypeItems) / sizeof (ShotTypeItem))) {
6969 PublicData::snapTypeItems[index].isManualSave = state;
7070 }
7171 });
7272
73- connect (ui->toolButtonDeleteHotKey , &QAbstractButton::clicked, this , [=](){
73+ connect (ui->toolButtonDeleteHotKey , &QAbstractButton::clicked, this , [=]() {
7474 ui->keySequenceEditHotKey ->clear ();
7575 });
7676
77- connect (ui->checkBoxRunWithWindows , &QCheckBox::stateChanged, this , [=](int state){
77+ connect (ui->checkBoxRunWithWindows , &QCheckBox::stateChanged, this , [=](int state) {
7878 runWithWindows (state);
7979 });
8080
81- connect (ui->toolButtonAutoSavePath , &QAbstractButton::clicked, this , [=](){
81+ connect (ui->toolButtonAutoSavePath , &QAbstractButton::clicked, this , [=]() {
8282 QString dirPath = QFileDialog::getExistingDirectory (this , tr (" 选择目录" ),
83- PublicData::snapTypeItems[ui->comboBoxSnapType ->currentIndex ()].autoSavePath , QFileDialog::ShowDirsOnly);
83+ PublicData::snapTypeItems[ui->comboBoxSnapType ->currentIndex ()].autoSavePath , QFileDialog::ShowDirsOnly);
8484 if (!dirPath.isEmpty ()) {
8585 ui->lineEditAutoSavePath ->setText (dirPath);
8686 }
8787 });
8888
89- connect (ui->toolButtonQssPath , &QAbstractButton::clicked, this , [=](){
89+ connect (ui->toolButtonQssPath , &QAbstractButton::clicked, this , [=]() {
9090 QString dirPath = QFileDialog::getOpenFileName (this , tr (" 选择QSS文件" ),
91- PublicData::qssPath, tr (" QSS文件(*.qss);;CSS文件(*.css);;所有文件(*.*)" ));
91+ PublicData::qssPath, tr (" QSS文件(*.qss);;CSS文件(*.css);;所有文件(*.*)" ));
9292 if (!dirPath.isEmpty ()) {
9393 ui->lineEditQssPath ->setText (dirPath);
9494 }
9595 });
9696
97- connect (ui->pushButtonOpenConfigFile , &QAbstractButton::clicked, this , [=](){
97+ connect (ui->pushButtonOpenConfigFile , &QAbstractButton::clicked, this , [=]() {
9898 QDesktopServices::openUrl (QUrl::fromLocalFile (PublicData::getConfigFilePath ()));
9999 });
100100
101- connect (ui->cbAutoSaveAfterShot , &QCheckBox::stateChanged, this , [=](int state){
101+ connect (ui->cbAutoSaveAfterShot , &QCheckBox::stateChanged, this , [=](int state) {
102102 int index = ui->comboBoxSnapType ->currentIndex ();
103103 if (index <= (int )(sizeof (PublicData::snapTypeItems) / sizeof (ShotTypeItem))) {
104104 PublicData::snapTypeItems[index].isAutoSave = state;
@@ -108,71 +108,75 @@ void SettingDialog::initConnect()
108108 ui->comboBoxAutoSaveExtName ->setEnabled (state);
109109 });
110110
111- connect (ui->lineEditAutoSavePath , &QLineEdit::editingFinished, this , [=](){
111+ connect (ui->lineEditAutoSavePath , &QLineEdit::editingFinished, this , [=]() {
112112 int index = ui->comboBoxSnapType ->currentIndex ();
113113 if (index <= (int )(sizeof (PublicData::snapTypeItems) / sizeof (ShotTypeItem))) {
114114 PublicData::snapTypeItems[index].autoSavePath = ui->lineEditAutoSavePath ->text ();
115115 }
116116 });
117117
118- connect (ui->lineEditAutoSavePath , &QLineEdit::textChanged, this , [=](const QString & text){
118+ connect (ui->lineEditAutoSavePath , &QLineEdit::textChanged, this , [=](const QString& text) {
119119 int index = ui->comboBoxSnapType ->currentIndex ();
120120 if (index <= (int )(sizeof (PublicData::snapTypeItems) / sizeof (ShotTypeItem))) {
121121 PublicData::snapTypeItems[index].autoSavePath = text;
122122 }
123123 });
124124
125- connect (ui->lineEditQssPath , &QLineEdit::editingFinished, this , [=](){
125+ connect (ui->lineEditQssPath , &QLineEdit::editingFinished, this , [=]() {
126126 PublicData::qssPath = ui->lineEditQssPath ->text ();
127127 });
128128
129- connect (ui->lineEditQssPath , &QLineEdit::textChanged, this , [=](const QString & text){
129+ connect (ui->lineEditQssPath , &QLineEdit::textChanged, this , [=](const QString& text) {
130130 PublicData::qssPath = text;
131131 });
132132
133- connect (ui->lineEditFileNameTemplate , &QLineEdit::editingFinished, this , [=](){
133+ connect (ui->lineEditFileNameTemplate , &QLineEdit::editingFinished, this , [=]() {
134134 PublicData::fileNameTemplate = ui->lineEditFileNameTemplate ->text ();
135135 });
136136
137- connect (ui->lineEditFileNameTemplate , &QLineEdit::textChanged, this , [=](const QString & text){
137+ connect (ui->lineEditFileNameTemplate , &QLineEdit::textChanged, this , [=](const QString& text) {
138138 PublicData::fileNameTemplate = text;
139139 ui->lineEditFileNamePreview ->setText (
140- ScreenShotHelper::getPictureName (ScreenShotHelper::ScreenShot));
140+ ScreenShotHelper::getPictureName (ScreenShotHelper::ScreenShot));
141141 });
142142
143143 // 自动保存格式,有信号重载
144- connect (ui->comboBoxAutoSaveExtName , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index){
144+ connect (ui->comboBoxAutoSaveExtName , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index) {
145145 int i = ui->comboBoxSnapType ->currentIndex ();
146146 if (i <= ScreenShotHelper::ShotType::Count) {
147147 PublicData::snapTypeItems[i].autoSaveExtName = ui->comboBoxAutoSaveExtName ->itemData (index).value <QString>();
148148 }
149149 });
150150
151- connect (ui->checkBoxClickCloseToTray , &QCheckBox::stateChanged, this , [=](int state){
151+ connect (ui->checkBoxClickCloseToTray , &QCheckBox::stateChanged, this , [=](int state) {
152152 PublicData::clickCloseToTray = state;
153153 });
154154
155- connect (ui->checkBoxPlaySound , &QCheckBox::stateChanged, this , [=](int state){
155+ connect (ui->checkBoxPlaySound , &QCheckBox::stateChanged, this , [=](int state) {
156156 PublicData::isPlaySound = state;
157157 });
158158
159- connect (ui->comboBoxMdiWindowInitState , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index){
159+ connect (ui->comboBoxMdiWindowInitState , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index) {
160160 PublicData::mdiWindowInitState = ui->comboBoxMdiWindowInitState ->itemData (index).value <Qt::WindowState>();
161161 });
162162
163- connect (ui->checkBoxHotKeyNoWait , &QCheckBox::stateChanged, this , [=](int state){
163+ connect (ui->checkBoxHotKeyNoWait , &QCheckBox::stateChanged, this , [=](int state) {
164164 PublicData::hotKeyNoWait = state;
165165 });
166166
167- connect (ui->checkBoxIncludeCursor , &QCheckBox::stateChanged, this , [=](int state){
167+ connect (ui->checkBoxIncludeCursor , &QCheckBox::stateChanged, this , [=](int state) {
168168 PublicData::includeCursor = state;
169169 });
170170
171- connect (ui->checkBoxCopyToClipBoardAfterSnap , &QCheckBox::stateChanged, this , [=](int state){
171+ connect (ui->checkBoxCopyToClipBoardAfterSnap , &QCheckBox::stateChanged, this , [=](int state) {
172172 PublicData::copyToClipBoardAfterSnap = state;
173173 });
174174
175- connect (ui->spinBoxImageQuality , &QSpinBox::valueChanged, this , [=](int i){
175+ connect (ui->checkBoxFreeSnapReleaseMouseCapture , &QCheckBox::stateChanged, this , [=](int state) {
176+ PublicData::freeSnapReleaseMouseCapture = state;
177+ });
178+
179+ connect (ui->spinBoxImageQuality , &QSpinBox::valueChanged, this , [=](int i) {
176180 PublicData::saveImageQuality = i;
177181 });
178182}
@@ -183,7 +187,7 @@ void SettingDialog::readAndInitSettings()
183187 ui->comboBoxAutoSaveExtName ->addItem (item.second , item.first );
184188 }
185189
186- connect (ui->comboBoxSnapType , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index){
190+ connect (ui->comboBoxSnapType , QOverload<int >::of (&QComboBox::currentIndexChanged), this , [=](int index) {
187191 if (index <= ScreenShotHelper::ShotType::Count) {
188192 ui->labelWaitTime ->setText (tr (" 截图前等待时间: " ) + QString::number (PublicData::snapTypeItems[index].waitTime ) + tr (" s" ));
189193 ui->horizontalSliderWaitTime ->setValue (PublicData::snapTypeItems[index].waitTime );
@@ -215,7 +219,7 @@ void SettingDialog::readAndInitSettings()
215219 ui->comboBoxSnapMethod ->addItem (tr (" 方式1\n (Aero开启时部分区域会透明;截取例如QQ等部分窗体为黑色)" ));
216220 ui->comboBoxSnapMethod ->addItem (tr (" 方式2" ));
217221
218- for ( auto key : PublicData::mdiWindowInitStates.keys ()) {
222+ foreach ( const auto & key, PublicData::mdiWindowInitStates.keys ()) {
219223 ui->comboBoxMdiWindowInitState ->addItem (PublicData::mdiWindowInitStates[key], key);
220224 }
221225 ui->comboBoxMdiWindowInitState ->setCurrentText (PublicData::mdiWindowInitStates[PublicData::mdiWindowInitState]);
@@ -227,6 +231,7 @@ void SettingDialog::readAndInitSettings()
227231 ui->spinBoxImageQuality ->setValue (PublicData::saveImageQuality);
228232 ui->checkBoxNoBorder ->setChecked (PublicData::noBorder);
229233 ui->checkBoxCopyToClipBoardAfterSnap ->setChecked (PublicData::copyToClipBoardAfterSnap);
234+ ui->checkBoxFreeSnapReleaseMouseCapture ->setChecked (PublicData::freeSnapReleaseMouseCapture);
230235 ui->comboBoxSnapMethod ->setCurrentIndex (PublicData::snapMethod);
231236 ui->lineEditQssPath ->setText (PublicData::qssPath);
232237 ui->lineEditFileNameTemplate ->setText (PublicData::fileNameTemplate);
@@ -236,16 +241,16 @@ void SettingDialog::readAndInitSettings()
236241 QSettings qSettings (" HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , QSettings::NativeFormat);
237242 QString value = qSettings.value (QApplication::applicationName ()).toString ();
238243 QString appPath = QApplication::applicationFilePath ();
239- appPath = appPath.replace (" /" ," \\ " );
244+ appPath = appPath.replace (" /" , " \\ " );
240245 ui->checkBoxRunWithWindows ->setChecked (value == " \" " + appPath + " \" " + " -autorun" );
241246}
242247
243248void SettingDialog::runWithWindows (bool enable)
244249{
245- QSettings qSettings (" HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" ,QSettings::NativeFormat);
250+ QSettings qSettings (" HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , QSettings::NativeFormat);
246251 QString appPath = QApplication::applicationFilePath ();
247252 QString appName = QApplication::applicationName ();
248- appPath = appPath.replace (" /" ," \\ " );
253+ appPath = appPath.replace (" /" , " \\ " );
249254 if (enable) {
250255 qSettings.setValue (appName, " \" " + appPath + " \" " + " -autorun" );
251256 } else {
0 commit comments