55using namespace FluentQt ;
66using namespace WorkbenchPagePrivate ;
77
8+ namespace {
9+
10+ bool isReceiveHexMode (const QString &mode)
11+ {
12+ return mode == QStringLiteral (" hex" );
13+ }
14+
15+ QString shortcutReceiveDisplayModeLabel (bool hexMode)
16+ {
17+ return hexMode ? QStringLiteral (" HEX" ) : AppI18n::text (" 文本" );
18+ }
19+
20+ QString nextReceiveDisplayMode (bool hexMode)
21+ {
22+ return hexMode ? QStringLiteral (" text" ) : QStringLiteral (" hex" );
23+ }
24+
25+ } // namespace
26+
827QWidget *WorkbenchPage::createTerminalSection ()
928{
1029 auto *section = new HeaderCardWidget (this );
1130 hideCardTitle (section);
1231 auto *root = cardBody (section, 10 );
1332 section->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
1433
15- section->headerLayout ()->addStretch (1 );
1634 section->headerLayout ()->addWidget (new BodyLabel (QStringLiteral (" RX" ), section));
1735 m_rxCounterLabel = new StrongBodyLabel (QStringLiteral (" 0 B" ), section);
1836 section->headerLayout ()->addWidget (m_rxCounterLabel);
@@ -27,6 +45,7 @@ QWidget *WorkbenchPage::createTerminalSection()
2745 section->headerLayout ()->addWidget (m_txRateLabel);
2846 m_connectionTimeLabel = new CaptionLabel (AppI18n::text (" 未连接" ), section);
2947 section->headerLayout ()->addWidget (m_connectionTimeLabel);
48+ section->headerLayout ()->addStretch (1 );
3049
3150 auto *searchButton = new TransparentToolButton (icon (FluentIcon::Search), section);
3251 searchButton->setToolTip (AppI18n::text (" 搜索" ));
@@ -36,9 +55,11 @@ QWidget *WorkbenchPage::createTerminalSection()
3655 themeButton->setToolTip (AppI18n::text (" 切换主题" ));
3756 auto *languageButton = new TransparentToolButton (icon (FluentIcon::Language), section);
3857 languageButton->setToolTip (AppI18n::text (" 切换语言" ));
58+ m_receiveModeButton = new TransparentToolButton (icon (FluentIcon::Font), section);
3959 auto *settingsButton = new TransparentToolButton (icon (FluentIcon::Setting), section);
4060 settingsButton->setToolTip (AppI18n::text (" 设置" ));
41- for (ToolButton *button : {searchButton, plotButton, themeButton, languageButton, settingsButton}) {
61+ for (ToolButton *button : {searchButton, plotButton, themeButton, languageButton, m_receiveModeButton,
62+ settingsButton}) {
4263 button->setFixedSize (CompactControlHeight, CompactControlHeight);
4364 button->setIconSize (QSize (16 , 16 ));
4465 }
@@ -47,6 +68,7 @@ QWidget *WorkbenchPage::createTerminalSection()
4768 section->headerLayout ()->addWidget (plotButton);
4869 section->headerLayout ()->addWidget (themeButton);
4970 section->headerLayout ()->addWidget (languageButton);
71+ section->headerLayout ()->addWidget (m_receiveModeButton);
5072 section->headerLayout ()->addWidget (settingsButton);
5173
5274 auto *searchView = new FlyoutView (AppI18n::text (" 终端搜索" ), QString (), icon (FluentIcon::Search), QPixmap (), true );
@@ -132,10 +154,12 @@ QWidget *WorkbenchPage::createTerminalSection()
132154 FluentConfig::instance ()->save ();
133155 ThemeManager::instance ()->setTheme (next);
134156 });
135- connect (languageButton, &TransparentToolButton::clicked, this , [this ]() {
136- const QString localeName = AppI18n::applyLocale (AppI18n::toggledChineseEnglishLocaleName ());
137- showSuccess (AppI18n::text (" 语言已切换" ),
138- AppI18n::text (" 当前:%1" ).arg (AppI18n::localeDisplayName (localeName)));
157+ connect (languageButton, &TransparentToolButton::clicked, this ,
158+ []() { AppI18n::applyLocale (AppI18n::toggledChineseEnglishLocaleName ()); });
159+ connect (m_receiveModeButton, &TransparentToolButton::clicked, this , [this ]() {
160+ if (m_displayModeSegment) {
161+ m_displayModeSegment->setCurrentItem (nextReceiveDisplayMode (isReceiveHexMode (currentDisplayMode ())));
162+ }
139163 });
140164 connect (settingsButton, &TransparentToolButton::clicked, this , &WorkbenchPage::settingsRequested);
141165 connect (m_terminalSearchEdit, &SearchLineEdit::textChanged, this , [this ]() {
@@ -159,10 +183,25 @@ QWidget *WorkbenchPage::createTerminalSection()
159183 renderTerminal ();
160184 });
161185 connect (m_terminalFilterCombo, &ComboBox::currentIndexChanged, this , [this ](int ) { renderTerminal (); });
186+ updateReceiveModeButton ();
162187
163188 return section;
164189}
165190
191+ void WorkbenchPage::updateReceiveModeButton ()
192+ {
193+ if (!m_receiveModeButton) {
194+ return ;
195+ }
196+
197+ const bool hexMode = isReceiveHexMode (currentDisplayMode ());
198+ const QString currentLabel = shortcutReceiveDisplayModeLabel (hexMode);
199+ const QString nextLabel = shortcutReceiveDisplayModeLabel (!hexMode);
200+ m_receiveModeButton->setIcon (icon (hexMode ? FluentIcon::Code : FluentIcon::Font));
201+ m_receiveModeButton->setToolTip (
202+ AppI18n::text (" 当前接收显示为 %1,点击切换为 %2" ).arg (currentLabel, nextLabel));
203+ }
204+
166205QWidget *WorkbenchPage::createSendSection ()
167206{
168207 auto *section = new HeaderCardWidget (this );
@@ -179,6 +218,12 @@ QWidget *WorkbenchPage::createSendSection()
179218 m_sendEdit->installEventFilter (this );
180219 sendRow->addWidget (m_sendEdit, 1 );
181220
221+ m_sendModeButton = new PushButton (section);
222+ setFixedControlWidth (m_sendModeButton, 72 );
223+ m_sendModeButton->setMinimumHeight (112 );
224+ m_sendModeButton->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
225+ sendRow->addWidget (m_sendModeButton);
226+
182227 m_sendButton = new PrimaryPushButton (icon (FluentIcon::Send), QString (), section);
183228 m_sendButton->setToolTip (AppI18n::text (" 发送" ));
184229 m_sendButton->setIconSize (QSize (40 , 40 ));
@@ -188,7 +233,25 @@ QWidget *WorkbenchPage::createSendSection()
188233
189234 root->addLayout (sendRow);
190235
236+ connect (m_sendModeButton, &PushButton::clicked, this , [this ]() {
237+ if (m_hexSendCheck) {
238+ m_hexSendCheck->setChecked (!m_hexSendCheck->isChecked ());
239+ }
240+ });
191241 connect (m_sendButton, &PrimaryPushButton::clicked, this , &WorkbenchPage::sendCurrentPayload);
242+ updateSendModeButton ();
192243
193244 return section;
194245}
246+
247+ void WorkbenchPage::updateSendModeButton ()
248+ {
249+ if (!m_sendModeButton) {
250+ return ;
251+ }
252+
253+ const bool hexMode = m_hexSendCheck && m_hexSendCheck->isChecked ();
254+ m_sendModeButton->setText (hexMode ? QStringLiteral (" HEX" ) : AppI18n::text (" 文本" ));
255+ m_sendModeButton->setToolTip (hexMode ? AppI18n::text (" 当前为 HEX 发送,点击切换为文本" )
256+ : AppI18n::text (" 当前为文本发送,点击切换为 HEX" ));
257+ }
0 commit comments