-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
207 lines (167 loc) · 4.33 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <QTabWidget>
#include <QShortcut>
#include <QFontDatabase>
#include "toolkit.h"
#include "setting.h"
#include "transferform.h"
#include "helpform.h"
#include "main.h"
#define SET_KEY_FTNM "/font/name"
#define SET_KEY_FTSZ "/font/size"
#define SET_KEY_LANG "/lang"
#define SET_VAL_LANG "transferer_chs"
#define SET_VAL_LANX ".qm"
extern "C" int __cdecl _purecall(void)
{
return 0;
}
Sokit::Sokit(int& argc, char** argv)
:QApplication(argc,argv)
{
}
Sokit::~Sokit()
{
}
void Sokit::show()
{
m_wnd.show();
}
void Sokit::close()
{
m_wnd.close();
}
void Sokit::initDefaultActionsName()
{
translate("QLineEdit", "&Undo");
translate("QLineEdit", "&Redo");
translate("QLineEdit", "Cu&t");
translate("QLineEdit", "&Copy");
translate("QLineEdit", "&Paste");
translate("QLineEdit", "Delete");
translate("QLineEdit", "Select All");
translate("QTextControl", "&Undo");
translate("QTextControl", "&Redo");
translate("QTextControl", "Cu&t");
translate("QTextControl", "&Copy");
translate("QTextControl", "&Paste");
translate("QTextControl", "Delete");
translate("QTextControl", "Select All");
}
bool Sokit::initTranslator()
{
QString file = Setting::get(SET_SEC_CFG, SET_KEY_LANG, SET_VAL_LANG);
QStringList paths;
paths << "."
<< "../share/" SET_APP_NAME
<< "../share/apps/" SET_APP_NAME
<< Setting::path();
foreach (QString p, paths)
{
if (m_trans.load(file, p, "", SET_VAL_LANX))
{
installTranslator(&m_trans);
Setting::set(SET_SEC_CFG, SET_KEY_LANG, file);
break;
}
}
return true;
}
void Sokit::initFont()
{
QFontDatabase db;
QStringList fs = db.families();
QFont font;
int match = 0;
QString family = Setting::get(SET_SEC_CFG, SET_KEY_FTNM, "").trimmed();
QString size = Setting::get(SET_SEC_CFG, SET_KEY_FTSZ, "").trimmed();
if (family.isEmpty() || fs.filter(family).isEmpty())
{
QStringList defs = translate("Transfer", "font").split(";", QString::SkipEmptyParts);
foreach (QString d, defs)
{
family = d.section(',', 0, 0).trimmed();
size = d.section(',', 1, 1).trimmed();
if (!family.isEmpty() && !fs.filter(family).isEmpty())
{
match = 2;
break;
}
}
}
else
{
match = 1;
}
if (match > 0)
{
font.setFamily(family);
if (db.isSmoothlyScalable(family))
font.setStyleStrategy((QFont::StyleStrategy)(QFont::PreferAntialias|QFont::PreferOutline|QFont::PreferQuality));
int nsize = size.toInt();
if (nsize > 0 && nsize < 20)
font.setPointSize(nsize);
setFont(font);
if (match > 1)
{
Setting::set(SET_SEC_CFG, SET_KEY_FTNM, family);
Setting::set(SET_SEC_CFG, SET_KEY_FTSZ, size);
}
}
}
bool Sokit::initUI()
{
initTranslator();
initFont();
HelpForm* h = new HelpForm(&m_wnd, Qt::WindowCloseButtonHint);
QShortcut* k = new QShortcut(QKeySequence(Qt::Key_F1), &m_wnd);
QShortcut* t = new QShortcut(QKeySequence(Qt::Key_F10), &m_wnd);
connect(k, SIGNAL(activated()), h, SLOT(exec()));
connect(t, SIGNAL(activated()), this, SLOT(ontop()));
m_wnd.InitTab();
// m_wnd.setWindowTitle(translate("Sokit", "sokit -- F1 for help"));
// m_wnd.setWindowIcon(QIcon(":/sokit.png"));
// QWidget* pnl = new QWidget(&m_wnd);
// m_wnd.setCentralWidget(pnl);
// BaseForm* server = new ServerForm();
// BaseForm* transf = new TransferForm();
// m_wnd.tabsList.push_back(transf);
// BaseForm* client = new ClientForm();
// NotepadForm* npd = new NotepadForm();
// QTabWidget* tab = new QTabWidget(pnl);
// m_wnd.InitTab(tab);
// tab->setTabsClosable(true);
// tab->setMovable(true);
// tab->addTab(server, server->windowTitle());
// tab->addTab(transf, transf->windowTitle());
// tab->addTab(client, client->windowTitle());
// tab->addTab(npd, npd->windowTitle());
// tab->setCurrentIndex(0);
// QLayout* lay = new QVBoxLayout(pnl);
// lay->setSpacing(5);
// lay->setContentsMargins(5, 5, 5, 5);
// lay->addWidget(tab);
// return server->init() && transf->init() &&
// client->init() && npd->init();
// if(!transf->init())
// return false;
return true;
}
void Sokit::ontop()
{
Qt::WindowFlags f = m_wnd.windowFlags();
if (f & Qt::WindowStaysOnTopHint)
f &= ~Qt::WindowStaysOnTopHint;
else
f |= Qt::WindowStaysOnTopHint;
m_wnd.setWindowFlags(f);
m_wnd.show();
}
int main(int argc, char *argv[])
{
Sokit a(argc, argv);
if (a.initUI())
a.show();
else
a.close();
return a.exec();
}