Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ec9585

Browse files
committed
Update & refactor
1 parent2b42ac8 commit0ec9585

File tree

10 files changed

+87
-104
lines changed

10 files changed

+87
-104
lines changed

‎.vscode/settings.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"qapplication":"cpp",
1616
"qclipboard":"cpp",
1717
"qeventtransition":"cpp",
18-
"qtranslator":"cpp"
18+
"qtranslator":"cpp",
19+
"atomic":"cpp",
20+
"memory":"cpp",
21+
"filesystem":"cpp"
1922
},
2023
"files.exclude": {
2124
"**/qt5-vcpkg":true

‎src/components/toggle.ui‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
<height>48</height>
1717
</size>
1818
</property>
19-
<propertyname="windowTitle">
20-
<string>Form</string>
21-
</property>
2219
<propertyname="locale">
2320
<localelanguage="English"country="UnitedStates"/>
2421
</property>
@@ -36,11 +33,7 @@
3633
<number>0</number>
3734
</property>
3835
<item>
39-
<widgetclass="QLabel"name="label">
40-
<propertyname="text">
41-
<string>TextLabel</string>
42-
</property>
43-
</widget>
36+
<widgetclass="QLabel"name="label"/>
4437
</item>
4538
<item>
4639
<widgetclass="QtMaterialToggle"name="toggle"native="true">

‎src/main.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
1313

1414
QApplicationa(argc, argv);
1515

16-
QFontfont("Source Han Sans");
16+
QFontfont("Microsoft YaHei");
1717
font.setStyleHint(QFont::SansSerif);
1818
QApplication::setFont(font);
1919

‎src/ui/mainwindow.cpp‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
2929
hotkey =newQHotkey(this);
3030
translator =newQTranslator(this);
3131

32+
ui->setupUi(this);
33+
34+
settingsBtn = ui->bottomWidget->findChild<QtMaterialFlatButton *>("settingsBtn");
35+
aboutBtn = ui->bottomWidget->findChild<QtMaterialFlatButton *>("aboutBtn");
36+
settingsWindow =nullptr;
37+
3238
initUI();
3339

3440
Language::initLanguage();
@@ -58,6 +64,8 @@ MainWindow *MainWindow::getInstance()
5864
voidMainWindow::changeEvent(QEvent *event)
5965
{
6066
if (event->type() == QEvent::LanguageChange) {
67+
ui->retranslateUi(this);
68+
6169
// 更新文本, 用于翻译
6270
updateText();
6371
}
@@ -67,33 +75,13 @@ void MainWindow::changeEvent(QEvent *event)
6775

6876
voidMainWindow::initUI()
6977
{
70-
ui->setupUi(this);
71-
72-
setFocusPolicy(Qt::ClickFocus);
73-
74-
setWindowIcon(QIcon(":/icons/copy"));
75-
7678
ui->autoToggle->setText(tr("Auto Mode"));
7779
ui->hotkeyToggle->setText(tr("Hotkey Mode"));
7880

79-
settingsBtn = ui->bottomWidget->findChild<QtMaterialFlatButton *>("settingsBtn");
80-
aboutBtn = ui->bottomWidget->findChild<QtMaterialFlatButton *>("aboutBtn");
81-
82-
// settingsBtn->setIcon(QIcon(":/icons/settings"));
83-
settingsBtn->setRole(Material::Primary);
84-
settingsBtn->setBackgroundMode(Qt::OpaqueMode);
81+
setFlatBtnStyle(aboutBtn);
82+
setFlatBtnStyle(settingsBtn);
8583

86-
// aboutBtn->setIcon(QIcon(":/icons/settings"));
87-
aboutBtn->setRole(Material::Primary);
88-
aboutBtn->setBackgroundMode(Qt::OpaqueMode);
89-
90-
//setFixedSize(size()); // 放到最后,更新并固定窗口大小
91-
92-
settingsWindow =nullptr;
93-
94-
// 设置按钮
95-
// floatBtn = new QtMaterialFloatingActionButton(QIcon(":/icons/settings"),this);
96-
// floatBtn->setMini(true);
84+
setFixedSize(size());// 放到最后,更新并固定窗口大小
9785

9886
#ifdef Q_OS_MAC
9987
// mac 暂不支持自动合并
@@ -113,6 +101,14 @@ void MainWindow::updateText()
113101
// ui->keySequenceEdit->lineEdit->setPlaceholderText(tr("快捷键"));
114102
}
115103

104+
voidMainWindow::setFlatBtnStyle(QtMaterialFlatButton *fBtn)
105+
{
106+
// fBtn->setIcon(QIcon(":/icons/settings"));
107+
fBtn->setRole(Material::Primary);
108+
fBtn->setBackgroundMode(Qt::OpaqueMode);
109+
fBtn->setFont(QFont("Microsoft YaHei"));
110+
}
111+
116112
voidMainWindow::initConnections()
117113
{
118114
connect(ui->autoToggle, &Toggle::toggled,this, &MainWindow::autoToggleChecked);
@@ -128,7 +124,7 @@ void MainWindow::initConnections()
128124
settingsWindow =newSettingsWindow(this);
129125

130126
connect(settingsWindow, &SettingsWindow::closed,this, [&]() { settingsWindow =nullptr; });
131-
127+
132128
settingsWindow->show();
133129
settingsWindow->raise();
134130
settingsWindow->activateWindow();

‎src/ui/mainwindow.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class MainWindow : public QMainWindow
3434
voidloadSettings();
3535
voidsaveSettings();
3636

37+
voidsetFlatBtnStyle(QtMaterialFlatButton *fBtn);
38+
3739
voidautoToggleChecked(bool status);
3840
voidhotkeyToggleChecked(bool status);
3941

‎src/ui/mainwindow.ui‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
<x>0</x>
88
<y>0</y>
99
<width>260</width>
10-
<height>320</height>
10+
<height>300</height>
1111
</rect>
1212
</property>
13+
<propertyname="focusPolicy">
14+
<enum>Qt::ClickFocus</enum>
15+
</property>
1316
<propertyname="windowTitle">
1417
<string>CopyPlusPlus</string>
1518
</property>
19+
<propertyname="windowIcon">
20+
<iconsetresource="../../resources.qrc">
21+
<normaloff>:/icons/copy</normaloff>:/icons/copy</iconset>
22+
</property>
1623
<propertyname="locale">
1724
<localelanguage="English"country="UnitedStates"/>
1825
</property>
@@ -115,26 +122,6 @@
115122
</item>
116123
</layout>
117124
</widget>
118-
<widgetclass="QMenuBar"name="menubar">
119-
<propertyname="geometry">
120-
<rect>
121-
<x>0</x>
122-
<y>0</y>
123-
<width>260</width>
124-
<height>21</height>
125-
</rect>
126-
</property>
127-
<widgetclass="QMenu"name="menuAppMenu">
128-
<propertyname="locale">
129-
<localelanguage="English"country="UnitedStates"/>
130-
</property>
131-
<propertyname="title">
132-
<string>AppMenu</string>
133-
</property>
134-
<addactionname="actionAbout"/>
135-
</widget>
136-
<addactionname="menuAppMenu"/>
137-
</widget>
138125
<widgetclass="QStatusBar"name="statusbar"/>
139126
<actionname="actionAbout">
140127
<propertyname="text">
@@ -155,6 +142,8 @@
155142
<headerlocation="global">qtmaterialflatbutton.h</header>
156143
</customwidget>
157144
</customwidgets>
158-
<resources/>
145+
<resources>
146+
<includelocation="../../resources.qrc"/>
147+
</resources>
159148
<connections/>
160149
</ui>

‎src/ui/settingswindow.cpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
#include"ui_settingswindow.h"
55
#include"utils/language.h"
66

7+
#include"Windows.h"
8+
79
#include<QSettings>
810

911
SettingsWindow::SettingsWindow(QWidget *parent) : QMainWindow(parent),
1012
ui(new Ui::SettingsWindow)
1113
{
1214
ui->setupUi(this);
1315

14-
setFixedSize(260,295);
15-
setWindowFlags(Qt::Tool);
16+
setWindowFlags(Qt::Dialog);
1617

17-
updateText();
18+
// Remove question mark from the title bar
19+
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
1820

19-
QSettings settings;
20-
ui->languageList->setCurrentIndex(settings.value("language","0").toInt());
21+
updateText();
2122

2223
// 函数指针
2324
void (QComboBox::*currentIndexChanged)(int) = &QComboBox::currentIndexChanged;
2425
connect(ui->languageList, currentIndexChanged,MainWindow::getInstance(), &Language::updateLanguage);
26+
27+
QSettings settings;
28+
ui->languageList->setCurrentIndex(settings.value("language","0").toInt());
2529
}
2630

2731
SettingsWindow::~SettingsWindow()

‎src/ui/settingswindow.ui‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
<uiversion="4.0">
33
<class>SettingsWindow</class>
44
<widgetclass="QMainWindow"name="SettingsWindow">
5+
<propertyname="windowModality">
6+
<enum>Qt::ApplicationModal</enum>
7+
</property>
58
<propertyname="geometry">
69
<rect>
710
<x>0</x>
811
<y>0</y>
9-
<width>201</width>
10-
<height>254</height>
12+
<width>190</width>
13+
<height>200</height>
1114
</rect>
1215
</property>
1316
<propertyname="windowTitle">
@@ -21,6 +24,18 @@
2124
<itemalignment="Qt::AlignTop">
2225
<widgetclass="QWidget"name="horizontalWidget"native="true">
2326
<layoutclass="QHBoxLayout"name="horizontalLayout">
27+
<propertyname="leftMargin">
28+
<number>0</number>
29+
</property>
30+
<propertyname="topMargin">
31+
<number>2</number>
32+
</property>
33+
<propertyname="rightMargin">
34+
<number>0</number>
35+
</property>
36+
<propertyname="bottomMargin">
37+
<number>2</number>
38+
</property>
2439
<item>
2540
<widgetclass="QLabel"name="languageLable">
2641
<propertyname="text">

‎src/utils/language.cpp‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include<QString>
77
#include<QTranslator>
88

9-
QStringList Language::allLanguages = {"中文","English"};
9+
QStringList Language::allLanguages = {"English","中文"};
1010

1111
QHash<QString, QString> Language::languageName = {
12-
{"中文","zh_CN"},
13-
{"English","en_US"}};
12+
{"English","en_US"},
13+
{"中文","zh_CN"}};
1414

1515
voidLanguage::initLanguage()
1616
{
@@ -21,7 +21,7 @@ void Language::initLanguage()
2121
// settings.remove("language");
2222
// }
2323

24-
//if no language setting, read system language
24+
//If there is no language setting, read system language
2525
if (!settings.contains("language")) {
2626
QString sysLang =QLocale::system().name();
2727

@@ -44,9 +44,8 @@ void Language::updateLanguage(const int &newLangIndex)
4444
qApp->removeTranslator(translator);
4545

4646
if (newLangIndex !=0) {
47-
const QString baseName ="CopyPlusPlus-Qt_" + languageName[allLanguages[newLangIndex]];
48-
49-
if (translator->load(":/i18n/" + baseName)) {
47+
const QString baseName ="CopyPlusPlus_" + languageName[allLanguages[newLangIndex]];
48+
if (translator->load(baseName)) {
5049
qApp->installTranslator(translator);
5150
}
5251
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp