2
0
forked from Ivasoft/DSView

fix: unable to switch language on windows

This commit is contained in:
dreamsourcelabTAI
2024-04-03 18:50:27 +08:00
parent bedf83f42b
commit 03534a036a
43 changed files with 589 additions and 359 deletions

View File

@@ -152,30 +152,4 @@ bool AppControl::TopWindowIsMaximized()
return _topWindow->isMaximized();
}
return false;
}
void AppControl::add_font_form(IFontForm *form)
{
assert(form);
_font_forms.push_back(form);
}
void AppControl::remove_font_form(IFontForm *form)
{
assert(form);
for (auto it = _font_forms.begin(); it != _font_forms.end(); it++)
{
if ( *(it) == form){
_font_forms.erase(it);
break;
}
}
}
void AppControl::update_font_forms()
{
for (auto f : _font_forms){
f->update_font();
}
}
}

View File

@@ -26,7 +26,6 @@
struct sr_context;
class QWidget;
class IFontForm;
namespace pv{
class SigSession;
@@ -66,15 +65,10 @@ public:
bool TopWindowIsMaximized();
void add_font_form(IFontForm *form);
void remove_font_form(IFontForm *form);
void update_font_forms();
public:
std::string _open_file_name;
private:
pv::SigSession *_session;
QWidget *_topWindow;
std::vector<IFontForm*> _font_forms;
QWidget *_topWindow;
};

View File

@@ -35,6 +35,8 @@
#include "../sigsession.h"
#include "../ui/langresource.h"
#include "../ui/msgbox.h"
#include "../ui/fn.h"
#include "../config/appconfig.h"
using namespace std;
@@ -96,22 +98,18 @@ Calibration::Calibration(QWidget *parent) :
connect(_reset_btn, SIGNAL(clicked()), this, SLOT(on_reset()));
connect(_exit_btn, SIGNAL(clicked()), this, SLOT(reject()));
retranslateUi();
ADD_UI(this);
}
Calibration::~Calibration(){
Calibration::~Calibration()
{
DESTROY_QT_OBJECT(_save_btn);
DESTROY_QT_OBJECT(_abort_btn);
DESTROY_QT_OBJECT(_reset_btn);
DESTROY_QT_OBJECT(_exit_btn);
DESTROY_QT_OBJECT(_flayout);
}
void Calibration::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
DSDialog::changeEvent(event);
REMOVE_UI(this);
}
void Calibration::retranslateUi()
@@ -349,5 +347,21 @@ void Calibration::on_reset()
}
}
void Calibration::UpdateLanguage()
{
retranslateUi();
}
void Calibration::UpdateTheme()
{
}
void Calibration::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
ui::set_form_font(this, font);
}
} // namespace dialogs
} // namespace pv

View File

@@ -28,10 +28,10 @@
#include <QLabel>
#include <QFormLayout>
#include <QSlider>
#include <list>
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/uimanager.h"
class DeviceAgent;
@@ -39,7 +39,7 @@ namespace pv {
namespace dialogs {
class Calibration : public DSDialog
class Calibration : public DSDialog, public IUiWindow
{
Q_OBJECT
@@ -59,9 +59,13 @@ protected:
void reject();
private:
void changeEvent(QEvent *event);
void retranslateUi();
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
private slots:
void set_value(int value);
void on_save();

View File

@@ -40,7 +40,7 @@ namespace dialogs {
class Shadow;
//DSView any dialog base class
class DSDialog : public QDialog, IFontForm
class DSDialog : public QDialog
{
Q_OBJECT
@@ -67,8 +67,7 @@ public:
void SetTitleSpace(int h);
//IFontForm
void update_font() override;
void update_font();
void show();

View File

@@ -20,10 +20,6 @@
*/
#include "lissajousoptions.h"
#include "../sigsession.h"
#include "../view/view.h"
#include "../view/lissajoustrace.h"
#include <QCheckBox>
#include <QVariant>
#include <QLabel>
@@ -31,9 +27,13 @@
#include <QBitmap>
#include <math.h>
#include "../sigsession.h"
#include "../view/view.h"
#include "../view/lissajoustrace.h"
#include "../ui/langresource.h"
#include "../ui/fn.h"
#include "../config/appconfig.h"
using namespace boost;
using namespace std;
using namespace pv::view;
@@ -140,14 +140,12 @@ LissajousOptions::LissajousOptions(SigSession *session, QWidget *parent) :
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
retranslateUi();
ADD_UI(this);
}
void LissajousOptions::changeEvent(QEvent *event)
LissajousOptions::~LissajousOptions()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
DSDialog::changeEvent(event);
REMOVE_UI(this);
}
void LissajousOptions::retranslateUi()
@@ -200,5 +198,22 @@ void LissajousOptions::reject()
QDialog::reject();
}
void LissajousOptions::UpdateLanguage()
{
retranslateUi();
}
void LissajousOptions::UpdateTheme()
{
}
void LissajousOptions::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
ui::set_form_font(this, font);
}
} // namespace dialogs
} // namespace pv

View File

@@ -30,11 +30,11 @@
#include <QCheckBox>
#include <QRadioButton>
#include <QSlider>
#include "../view/dsosignal.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/uimanager.h"
namespace pv {
@@ -46,7 +46,7 @@ class View;
namespace dialogs {
class LissajousOptions : public DSDialog
class LissajousOptions : public DSDialog, public IUiWindow
{
Q_OBJECT
@@ -56,10 +56,16 @@ private:
public:
LissajousOptions(SigSession *session, QWidget *parent);
private:
void changeEvent(QEvent *event);
~LissajousOptions();
private:
void retranslateUi();
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
protected:
void accept();
void reject();

View File

@@ -20,19 +20,19 @@
*/
#include "mathoptions.h"
#include "../sigsession.h"
#include "../view/view.h"
#include "../view/mathtrace.h"
#include "../data/mathstack.h"
#include <QCheckBox>
#include <QVariant>
#include <QLabel>
#include <QTabBar>
#include <QBitmap>
#include "../sigsession.h"
#include "../view/view.h"
#include "../view/mathtrace.h"
#include "../data/mathstack.h"
#include "../ui/langresource.h"
#include "../ui/fn.h"
#include "../config/appconfig.h"
using namespace boost;
using namespace std;
@@ -155,14 +155,12 @@ MathOptions::MathOptions(SigSession *session, QWidget *parent) :
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
retranslateUi();
ADD_UI(this);
}
void MathOptions::changeEvent(QEvent *event)
MathOptions::~MathOptions()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
DSDialog::changeEvent(event);
REMOVE_UI(this);
}
void MathOptions::retranslateUi()
@@ -228,5 +226,21 @@ void MathOptions::reject()
QDialog::reject();
}
void MathOptions::UpdateLanguage()
{
retranslateUi();
}
void MathOptions::UpdateTheme()
{
}
void MathOptions::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
ui::set_form_font(this, font);
}
} // namespace dialogs
} // namespace pv

View File

@@ -30,11 +30,10 @@
#include <QCheckBox>
#include <QRadioButton>
#include <QSlider>
#include "../view/dsosignal.h"
#include "../toolbars/titlebar.h"
#include "dsdialog.h"
#include "../ui/uimanager.h"
namespace pv {
@@ -46,7 +45,7 @@ class View;
namespace dialogs {
class MathOptions : public DSDialog
class MathOptions : public DSDialog, public IUiWindow
{
Q_OBJECT
@@ -55,11 +54,16 @@ private:
public:
MathOptions(SigSession *session, QWidget *parent);
~MathOptions();
private:
void changeEvent(QEvent *event);
private:
void retranslateUi();
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
protected:
void accept();
void reject();

View File

@@ -170,22 +170,12 @@ DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession *session) :
//_widget->setGeometry(0, 0, sizeHint().width(), sizeHint().height());
_widget->setObjectName("dsoTriggerWidget");
retranslateUi();
update_font();
ADD_UI(this);
}
DsoTriggerDock::~DsoTriggerDock()
{
}
void DsoTriggerDock::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QScrollArea::changeEvent(event);
REMOVE_UI(this);
}
void DsoTriggerDock::retranslateUi()
@@ -487,7 +477,17 @@ void DsoTriggerDock::update_view()
connect(_margin_slider, SIGNAL(valueChanged(int)), this, SLOT(margin_changed(int)));
}
void DsoTriggerDock::update_font()
void DsoTriggerDock::UpdateLanguage()
{
retranslateUi();
}
void DsoTriggerDock::UpdateTheme()
{
reStyle();
}
void DsoTriggerDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -29,11 +29,11 @@
#include <QScrollArea>
#include <QLabel>
#include <QRadioButton>
#include <vector>
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include "../ui/uimanager.h"
namespace pv {
@@ -41,7 +41,7 @@ class SigSession;
namespace dock {
class DsoTriggerDock : public QScrollArea, public IFontForm
class DsoTriggerDock : public QScrollArea, public IUiWindow
{
Q_OBJECT
@@ -55,13 +55,14 @@ public:
private:
void paintEvent(QPaintEvent *e);
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
bool check_trig_channel();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
signals:
void set_trig_pos(int percent);

View File

@@ -143,8 +143,6 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) :
_widget->setGeometry(0, 0, sizeHint().width(), 2000);
_widget->setObjectName("measureWidget");
retranslateUi();
add_dist_measure();
connect(_dist_add_btn, SIGNAL(clicked()), this, SLOT(add_dist_measure()));
@@ -152,20 +150,12 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) :
connect(_fen_checkBox, SIGNAL(stateChanged(int)), &_view, SLOT(set_measure_en(int)));
connect(&_view, SIGNAL(measure_updated()), this, SLOT(measure_updated()));
update_font();
ADD_UI(this);
}
MeasureDock::~MeasureDock()
{
}
void MeasureDock::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QScrollArea::changeEvent(event);
REMOVE_UI(this);
}
void MeasureDock::retranslateUi()
@@ -860,7 +850,17 @@ void MeasureDock::del_cursor()
_view.update();
}
void MeasureDock::update_font()
void MeasureDock::UpdateLanguage()
{
retranslateUi();
}
void MeasureDock::UpdateTheme()
{
reStyle();
}
void MeasureDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -42,6 +42,7 @@
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
namespace pv {
@@ -73,7 +74,7 @@ struct cursor_opt_info
view::Cursor *cursor;
};
class MeasureDock : public QScrollArea, public IFontForm
class MeasureDock : public QScrollArea, public IUiWindow
{
Q_OBJECT
@@ -87,12 +88,13 @@ public:
void reload();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
void build_dist_pannel();
void build_edge_pannel();

View File

@@ -204,8 +204,6 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
this->setWidget(split_widget);
split_widget->setObjectName("protocolWidget");
retranslateUi();
connect(_dn_nav_button, SIGNAL(clicked()),this, SLOT(nav_table_view()));
connect(_bot_save_button, SIGNAL(clicked()),this, SLOT(export_table_view()));
connect(_bot_set_button, SIGNAL(clicked()),this, SLOT(set_model()));
@@ -224,7 +222,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
connect(_pro_search_button, SIGNAL(clicked()), this, SLOT(show_protocol_select()));
update_font();
ADD_UI(this);
}
ProtocolDock::~ProtocolDock()
@@ -237,6 +235,8 @@ ProtocolDock::~ProtocolDock()
//clear protocol infos list
RELEASE_ARRAY(_decoderInfoList);
REMOVE_UI(this);
}
void ProtocolDock::retranslateUi()
@@ -271,15 +271,6 @@ void ProtocolDock::reStyle()
}
}
void ProtocolDock::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QScrollArea::changeEvent(event);
}
int ProtocolDock::decoder_name_cmp(const void *a, const void *b)
{
return strcmp(((const srd_decoder*)a)->name,
@@ -1060,7 +1051,17 @@ bool ProtocolDock::protocol_sort_callback(const DecoderInfoItem *o1, const Decod
}
}
void ProtocolDock::update_font()
void ProtocolDock::UpdateLanguage()
{
retranslateUi();
}
void ProtocolDock::UpdateTheme()
{
reStyle();
}
void ProtocolDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -46,6 +46,7 @@
#include "searchcombobox.h"
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
struct DecoderInfoItem{
void *_data_handle; //srd_decoder* type
@@ -73,7 +74,7 @@ public IProtocolItemLayerCallback,
public IKeywordActive,
public ISearchItemClick,
public IDecoderPannel,
public IFontForm
public IUiWindow
{
Q_OBJECT
@@ -91,7 +92,6 @@ public:
void update_view_status();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
int get_protocol_index_by_id(QString id);
@@ -116,8 +116,10 @@ private:
//IDecoderPannel
void update_deocder_item_name(void *trace_handel, const char *name) override;
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
signals:
void protocol_updated();

View File

@@ -82,25 +82,15 @@ SearchDock::SearchDock(QWidget *parent, View &view, SigSession *session) :
setLayout(layout);
retranslateUi();
update_font();
connect(&_pre_button, SIGNAL(clicked()), this, SLOT(on_previous()));
connect(&_nxt_button, SIGNAL(clicked()),this, SLOT(on_next()));
ADD_UI(this);
}
SearchDock::~SearchDock()
{
}
void SearchDock::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QWidget::changeEvent(event);
REMOVE_UI(this);
}
void SearchDock::retranslateUi()
@@ -253,7 +243,17 @@ void SearchDock::on_set()
}
}
void SearchDock::update_font()
void SearchDock::UpdateLanguage()
{
retranslateUi();
}
void SearchDock::UpdateTheme()
{
reStyle();
}
void SearchDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -44,6 +44,7 @@
#include "../widgets/fakelineedit.h"
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include "../ui/uimanager.h"
namespace pv {
@@ -59,7 +60,7 @@ namespace widgets {
namespace dock {
class SearchDock : public QWidget, public IFontForm
class SearchDock : public QWidget, public IUiWindow
{
Q_OBJECT
@@ -69,13 +70,14 @@ public:
void paintEvent(QPaintEvent *);
private:
void changeEvent(QEvent *event);
private:
void retranslateUi();
void reStyle();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
public slots:
void on_previous();

View File

@@ -131,22 +131,12 @@ TriggerDock::TriggerDock(QWidget *parent, SigSession *session) :
this->setWidget(_widget);
_widget->setObjectName("triggerWidget");
retranslateUi();
update_font();
ADD_UI(this);
}
TriggerDock::~TriggerDock()
{
}
void TriggerDock::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QScrollArea::changeEvent(event);
REMOVE_UI(this);
}
void TriggerDock::retranslateUi()
@@ -196,10 +186,6 @@ void TriggerDock::reStyle()
{
}
void TriggerDock::paintEvent(QPaintEvent *)
{
}
void TriggerDock::simple_trigger()
{
_stages_label->setDisabled(true);
@@ -1071,7 +1057,17 @@ void TriggerDock::on_serial_hex_changed()
_is_serial_val_setting = false;
}
void TriggerDock::update_font()
void TriggerDock::UpdateLanguage()
{
retranslateUi();
}
void TriggerDock::UpdateTheme()
{
reStyle();
}
void TriggerDock::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -42,6 +42,7 @@
#include <vector>
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include "../ui/uimanager.h"
namespace pv {
@@ -49,7 +50,7 @@ class SigSession;
namespace dock {
class TriggerDock : public QScrollArea, public IFontForm
class TriggerDock : public QScrollArea, public IUiWindow
{
Q_OBJECT
@@ -60,8 +61,6 @@ public:
TriggerDock(QWidget *parent, SigSession *session);
~TriggerDock();
void paintEvent(QPaintEvent *);
void update_view();
QJsonObject get_session();
@@ -72,7 +71,6 @@ public:
void try_commit_trigger();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
@@ -86,8 +84,10 @@ private:
*/
bool commit_trigger();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
private slots:
void simple_trigger();

View File

@@ -109,13 +109,8 @@ public:
virtual void update_deocder_item_name(void *trace_handel, const char *name)=0;
};
class IFontForm
enum ParentNativeEvent
{
public:
virtual void update_font()=0;
};
enum ParentNativeEvent{
PARENT_EVENT_DISPLAY_CHANGED = 0,
};

View File

@@ -102,6 +102,7 @@
#include "mainframe.h"
#include "dsvdef.h"
#include <thread>
#include "ui/uimanager.h"
namespace pv
{
@@ -120,7 +121,6 @@ namespace pv
assert(_frame);
_title_bar = title_bar;
AppControl::Instance()->add_font_form(title_bar);
_session = AppControl::Instance()->GetSession();
_session->set_callback(this);
@@ -193,11 +193,6 @@ namespace pv
addToolBar(_file_bar);
addToolBar(_logo_bar);
AppControl::Instance()->add_font_form(_sampling_bar);
AppControl::Instance()->add_font_form(_trig_bar);
AppControl::Instance()->add_font_form(_file_bar);
AppControl::Instance()->add_font_form(_logo_bar);
// Setup the dockWidget
_protocol_dock = new QDockWidget(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_PROTOCOL_DOCK_TITLE), "Decode Protocol"), this);
_protocol_dock->setObjectName("protocol_dock");
@@ -252,20 +247,8 @@ namespace pv
switchLanguage(app.frameOptions.language);
switchTheme(app.frameOptions.style);
retranslateUi();
_sampling_bar->set_view(_view);
// Add the font form
AppControl::Instance()->add_font_form(_protocol_widget);
AppControl::Instance()->add_font_form(_dso_trigger_widget);
AppControl::Instance()->add_font_form(_measure_widget);
AppControl::Instance()->add_font_form(_search_widget);
AppControl::Instance()->add_font_form(_trigger_widget);
AppControl::Instance()->add_font_form(_view->get_time_view());
AppControl::Instance()->add_font_form(_view);
// event
connect(&_event, SIGNAL(session_error()), this, SLOT(on_session_error()));
connect(&_event, SIGNAL(signals_changed()), this, SLOT(on_signals_changed()));
@@ -1395,22 +1378,20 @@ namespace pv
if (language == LAN_CN)
{
_qtTrans.load(":/qt_" + QString::number(language));
qApp->installTranslator(&_qtTrans);
_myTrans.load(":/my_" + QString::number(language));
qApp->installTranslator(&_myTrans);
retranslateUi();
// _qtTrans.load(":/qt_" + QString::number(language));
//qApp->installTranslator(&_qtTrans);
//_myTrans.load(":/my_" + QString::number(language));
// qApp->installTranslator(&_myTrans);
}
else if (language == LAN_EN)
{
qApp->removeTranslator(&_qtTrans);
qApp->removeTranslator(&_myTrans);
retranslateUi();
// qApp->removeTranslator(&_qtTrans);
// qApp->removeTranslator(&_myTrans);
}
// QEvent langEvent(QEvent::LanguageChange);
// QApplication::sendEvent(QApplication::instance(), &langEvent);
// QCoreApplication::sendPostedEvents();
retranslateUi();
UiManager::Instance()->Update(UI_UPDATE_ACTION_LANG);
}
void MainWindow::switchTheme(QString style)
@@ -1428,7 +1409,8 @@ namespace pv
qss.open(QFile::ReadOnly | QFile::Text);
qApp->setStyleSheet(qss.readAll());
qss.close();
UiManager::Instance()->Update(UI_UPDATE_ACTION_THEME);
data_updated();
}
@@ -2112,7 +2094,7 @@ namespace pv
break;
case DSV_MSG_FONT_OPTIONS_CHANGED:
AppControl::Instance()->update_font_forms();
UiManager::Instance()->Update(UI_UPDATE_ACTION_FONT);
break;
case DSV_MSG_DATA_POOL_CHANGED:
_view->check_measure();

View File

@@ -85,8 +85,6 @@ FileBar::FileBar(SigSession *session, QWidget *parent) :
_file_button.setMenu(_menu);
addWidget(&_file_button);
retranslateUi();
connect(_action_load, SIGNAL(triggered()), this, SLOT(on_actionLoad_triggered()));
connect(_action_store, SIGNAL(triggered()), this, SLOT(on_actionStore_triggered()));
connect(_action_default, SIGNAL(triggered()), this, SLOT(on_actionDefault_triggered()));
@@ -95,16 +93,12 @@ FileBar::FileBar(SigSession *session, QWidget *parent) :
connect(_action_export, SIGNAL(triggered()), this, SIGNAL(sig_export()));
connect(_action_capture, SIGNAL(triggered()), this, SLOT(on_actionCapture_triggered()));
update_font();
ADD_UI(this);
}
void FileBar::changeEvent(QEvent *event)
FileBar::~FileBar()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QToolBar::changeEvent(event);
REMOVE_UI(this);
}
void FileBar::retranslateUi()
@@ -255,7 +249,17 @@ void FileBar::update_view_status()
_menu_session->setEnabled(bEnable && is_hardware);
}
void FileBar::update_font()
void FileBar::UpdateLanguage()
{
retranslateUi();
}
void FileBar::UpdateTheme()
{
reStyle();
}
void FileBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -30,30 +30,34 @@
#include "../sigsession.h"
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
namespace pv {
namespace toolbars {
//toolbar button,referenced by MainWindow
//TODO: load session file, sorte session, load log data file, sorte data, export data
class FileBar : public QToolBar, public IFontForm
class FileBar : public QToolBar, public IUiWindow
{
Q_OBJECT
public:
explicit FileBar(SigSession *session, QWidget *parent = 0);
~FileBar();
void update_view_status();
QString genDefaultSessionFile();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
signals:
void sig_load_file(QString);

View File

@@ -114,8 +114,6 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
margin->setMinimumWidth(20);
addWidget(margin);
retranslateUi();
connect(_action_en, SIGNAL(triggered()), this, SLOT(on_actionEn_triggered()));
connect(_action_cn, SIGNAL(triggered()), this, SLOT(on_actionCn_triggered()));
connect(_about, SIGNAL(triggered()), this, SLOT(on_actionAbout_triggered()));
@@ -124,16 +122,12 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
connect(_update, SIGNAL(triggered()), this, SLOT(on_action_update()));
connect(_log, SIGNAL(triggered()), this, SLOT(on_action_setting_log()));
update_font();
ADD_UI(this);
}
void LogoBar::changeEvent(QEvent *event)
LogoBar::~LogoBar()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QToolBar::changeEvent(event);
REMOVE_UI(this);
}
void LogoBar::retranslateUi()
@@ -348,7 +342,17 @@ void LogoBar::on_clear_log_file()
}
}
void LogoBar::update_font()
void LogoBar::UpdateLanguage()
{
retranslateUi();
}
void LogoBar::UpdateTheme()
{
reStyle();
}
void LogoBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -32,18 +32,20 @@
#include "../sigsession.h"
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
namespace pv {
namespace toolbars {
//The tool button for help,is a ui class,referenced by MainWindow
//TODO: switch language,submit bug descript,
class LogoBar : public QToolBar, public IFontForm
class LogoBar : public QToolBar, public IUiWindow
{
Q_OBJECT
public:
explicit LogoBar(SigSession *session, QWidget *parent = 0);
~LogoBar();
void enable_toggle(bool enable);
@@ -55,12 +57,13 @@ public:
}
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
signals:
//post event message to open user help document, MainWindow class receive it

View File

@@ -128,7 +128,6 @@ namespace pv
_instant_action = addWidget(&_instant_button);
update_view_status();
update_font();
connect(&_device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(on_device_selected()));
connect(&_configure_button, SIGNAL(clicked()), this, SLOT(on_configure()));
@@ -139,15 +138,13 @@ namespace pv
connect(_action_repeat, SIGNAL(triggered()), this, SLOT(on_collect_mode()));
connect(_action_loop, SIGNAL(triggered()), this, SLOT(on_collect_mode()));
connect(&_sample_rate, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplerate_sel(int)));
ADD_UI(this);
}
void SamplingBar::changeEvent(QEvent *event)
SamplingBar::~SamplingBar()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QToolBar::changeEvent(event);
REMOVE_UI(this);
}
void SamplingBar::retranslateUi()
@@ -1244,7 +1241,6 @@ namespace pv
_mode_button.setIcon(QIcon(iconPath + SINGLE_ACTION_ICON));
}
void SamplingBar::run_or_stop()
{
on_run_stop();
@@ -1255,7 +1251,17 @@ namespace pv
on_instant_stop();
}
void SamplingBar::update_font()
void SamplingBar::UpdateLanguage()
{
retranslateUi();
}
void SamplingBar::UpdateTheme()
{
reStyle();
}
void SamplingBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -27,14 +27,14 @@
#include <stdint.h>
#include <list>
#include <map>
#include <QDialog>
#include <QToolBar>
#include <QAction>
#include <QMenu>
#include "../ui/dscombobox.h"
#include "../interface/icallbacks.h"
#include <QDialog>
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
struct st_dev_inst;
class QAction;
@@ -59,7 +59,7 @@ namespace pv
namespace toolbars
{
class SamplingBar : public QToolBar, public IFontForm
class SamplingBar : public QToolBar, public IUiWindow
{
Q_OBJECT
@@ -76,7 +76,8 @@ namespace pv
public:
SamplingBar(SigSession *session, QWidget *parent);
SamplingBar(SigSession *session, QWidget *parent);
~SamplingBar();
double hori_knob(int dir);
double get_hori_res();
@@ -104,8 +105,7 @@ namespace pv
signals:
void sig_store_session_data();
private:
void changeEvent(QEvent *event);
private:
void retranslateUi();
void reStyle();
void set_sample_rate(uint64_t sample_rate);
@@ -123,8 +123,10 @@ namespace pv
bool action_run_stop();
bool action_instant_stop();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
private slots:
void on_collect_mode();

View File

@@ -98,21 +98,16 @@ TitleBar::TitleBar(bool top, QWidget *parent, ITitleParent *titleParent, bool ha
lay1->setSpacing(0);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
update_font();
ADD_UI(this);
}
TitleBar::~TitleBar(){
DESTROY_QT_OBJECT(_minimizeButton);
DESTROY_QT_OBJECT(_maximizeButton);
DESTROY_QT_OBJECT(_closeButton);
}
void TitleBar::changeEvent(QEvent *event)
{
if (event->type() == QEvent::StyleChange)
reStyle();
QWidget::changeEvent(event);
REMOVE_UI(this);
}
void TitleBar::reStyle()
@@ -314,7 +309,17 @@ void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
}
}
void TitleBar::update_font()
void TitleBar::UpdateLanguage()
{
}
void TitleBar::UpdateTheme()
{
reStyle();
}
void TitleBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize+1);

View File

@@ -25,6 +25,7 @@
#include <QWidget>
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
class QHBoxLayout;
@@ -44,7 +45,7 @@ public:
namespace toolbars {
class TitleBar : public QWidget, public IFontForm
class TitleBar : public QWidget, public IUiWindow
{
Q_OBJECT
@@ -55,17 +56,22 @@ public:
void setTitle(QString title);
QString title();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
inline void set_native(){
_is_native = true;
}
inline void update_font(){
UpdateFont();
}
void EnableAbleDrag(bool bEnabled);
private:
void changeEvent(QEvent *event);
private:
void reStyle();
bool ParentIsMaxsized();

View File

@@ -108,8 +108,6 @@ TrigBar::TrigBar(SigSession *session, QWidget *parent) :
_search_action = addWidget(&_search_button);
_function_action = addWidget(&_function_button);
_display_action = addWidget(&_setting_button); //must be created
retranslateUi();
connect(&_trig_button, SIGNAL(clicked()),this, SLOT(trigger_clicked()));
connect(&_protocol_button, SIGNAL(clicked()),this, SLOT(protocol_clicked()));
@@ -123,17 +121,12 @@ TrigBar::TrigBar(SigSession *session, QWidget *parent) :
connect(_light_style, SIGNAL(triggered()), this, SLOT(on_actionLight_triggered()));
connect(_action_dispalyOptions, SIGNAL(triggered()), this, SLOT(on_display_setting()));
update_font();
ADD_UI(this);
}
//语言变化
void TrigBar::changeEvent(QEvent *event)
TrigBar::~TrigBar()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
else if (event->type() == QEvent::StyleChange)
reStyle();
QToolBar::changeEvent(event);
REMOVE_UI(this);
}
void TrigBar::retranslateUi()
@@ -371,7 +364,17 @@ void TrigBar::update_checked_status()
_search_button.setChecked(opt->searchDock);
}
void TrigBar::update_font()
void TrigBar::UpdateLanguage()
{
retranslateUi();
}
void TrigBar::UpdateTheme()
{
reStyle();
}
void TrigBar::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -28,6 +28,7 @@
#include <QMenu>
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
class DockOptions;
@@ -39,24 +40,26 @@ namespace toolbars {
//boolbar, referenced by MainWindow
//TODO:show the property panel about protocol\trigger
class TrigBar : public QToolBar, public IFontForm
class TrigBar : public QToolBar, public IUiWindow
{
Q_OBJECT
public:
explicit TrigBar(SigSession *session, QWidget *parent = 0);
~TrigBar();
void reload();
void update_view_status();
private:
void changeEvent(QEvent *event);
void retranslateUi();
void reStyle();
DockOptions* getDockOptions();
void update_checked_status();
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
signals:
void sig_setTheme(QString style);

View File

@@ -147,40 +147,4 @@ namespace ui
}
}
void adjust_form_size(QWidget *wid)
{
assert(wid);
auto labels = wid->findChildren<QLabel*>();
for(auto o : labels)
{
QSize size = o->sizeHint();
size.setWidth(size.width() + 5);
o->setFixedWidth(size.width());
}
int groupMaxWith = 0;
auto groups = wid->findChildren<QGroupBox*>();
for(auto o : groups)
{
QSize size = o->sizeHint();
int w = size.width() + 5;
if (w > groupMaxWith){
groupMaxWith = w;
}
}
auto groups2 = wid->findChildren<QGroupBox*>();
for(auto o : groups2)
{
o->setFixedWidth(groupMaxWith);
QWidget *parent = dynamic_cast<QWidget*>(o->parent());
if (parent != NULL){
parent->setFixedWidth(groupMaxWith + 10);
}
}
}
} // namespace ui

View File

@@ -37,8 +37,6 @@ namespace ui
void set_form_font(QWidget *wid, QFont font);
void adjust_form_size(QWidget *wid);
} // namespace ui
#endif

View File

@@ -0,0 +1,88 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2024 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "uimanager.h"
#include <assert.h>
UiManager::UiManager()
{
}
UiManager* UiManager::Instance()
{
static UiManager *ins = nullptr;
if (ins == nullptr){
ins = new UiManager();
}
return ins;
}
void UiManager::AddWindow(IUiWindow *w)
{
assert(w);
for (auto it = m_widgets.begin(); it != m_widgets.end(); ++it)
{
if ((*it) == w){
return;
}
}
m_widgets.push_back(w);
//Init the ui.
w->UpdateLanguage();
w->UpdateTheme();
w->UpdateFont();
}
void UiManager::RemoveWindow(IUiWindow *w)
{
assert(w);
for (auto it = m_widgets.begin(); it != m_widgets.end(); ++it)
{
if ((*it) == w){
m_widgets.erase(it);
break;
}
}
}
void UiManager::Update(UiUpdateAction action)
{
for (auto it = m_widgets.begin(); it != m_widgets.end(); ++it)
{
IUiWindow *w = (*it);
if (action == UI_UPDATE_ACTION_LANG){
w->UpdateLanguage();
}
else if (action == UI_UPDATE_ACTION_THEME){
w->UpdateTheme();
}
else if (action == UI_UPDATE_ACTION_FONT){
w->UpdateFont();
}
}
}

61
DSView/pv/ui/uimanager.h Normal file
View File

@@ -0,0 +1,61 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2024 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef UI_MANAGER_H
#define UI_MANAGER_H
#include <vector>
class IUiWindow
{
public:
virtual void UpdateLanguage()=0;
virtual void UpdateTheme()=0;
virtual void UpdateFont()=0;
};
enum UiUpdateAction
{
UI_UPDATE_ACTION_LANG = 0,
UI_UPDATE_ACTION_THEME = 1,
UI_UPDATE_ACTION_FONT = 2,
};
class UiManager
{
private:
UiManager();
public:
static UiManager* Instance();
void AddWindow(IUiWindow *w);
void RemoveWindow(IUiWindow *w);
void Update(UiUpdateAction action);
private:
std::vector<IUiWindow*> m_widgets;
};
#define ADD_UI(o) UiManager::Instance()->AddWindow(o);
#define REMOVE_UI(o) UiManager::Instance()->RemoveWindow(o);
#endif

View File

@@ -90,19 +90,14 @@ DevMode::DevMode(QWidget *parent, SigSession *session) :
layout->setStretch(1, 100);
setLayout(layout);
update_font();
connect(_close_button, SIGNAL(clicked()), this, SLOT(on_close()));
ADD_UI(this);
}
void DevMode::changeEvent(QEvent *event)
DevMode::~DevMode()
{
if (event->type() == QEvent::LanguageChange)
set_device();
else if (event->type() == QEvent::StyleChange)
set_device();
QWidget::changeEvent(event);
REMOVE_UI(this);
}
void DevMode::set_device()
@@ -173,7 +168,7 @@ void DevMode::set_device()
_bFile = true;
}
update_font();
UpdateFont();
update();
}
@@ -232,7 +227,7 @@ void DevMode::on_mode_change()
}
}
update_font();
UpdateFont();
}
void DevMode::on_close()
@@ -280,7 +275,17 @@ const struct dev_mode_name* DevMode::get_mode_name(int mode)
assert(false);
}
void DevMode::update_font()
void DevMode::UpdateLanguage()
{
set_device();
}
void DevMode::UpdateTheme()
{
set_device();
}
void DevMode::UpdateFont()
{
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);

View File

@@ -35,6 +35,7 @@
#include "../interface/icallbacks.h"
#include "../ui/xtoolbutton.h"
#include "../ui/uimanager.h"
struct dev_mode_name{
int _mode;
@@ -50,7 +51,7 @@ class SigSession;
namespace view {
//devece work mode select list
class DevMode : public QWidget, public IFontForm
class DevMode : public QWidget, public IUiWindow
{
Q_OBJECT
@@ -60,6 +61,8 @@ private:
public:
DevMode(QWidget *parent, SigSession *session);
~DevMode();
private:
void paintEvent(QPaintEvent *event);
@@ -67,12 +70,13 @@ private:
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void leaveEvent(QEvent *event);
void changeEvent(QEvent *event);
void leaveEvent(QEvent *event);
const dev_mode_name* get_mode_name(int mode);
//IFontForm
void update_font() override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
public slots:
void set_device();

View File

@@ -73,14 +73,13 @@ Header::Header(View &parent) :
connect(nameEdit, SIGNAL(editingFinished()),
this, SLOT(on_action_set_name_triggered()));
retranslateUi();
ADD_UI(this);
}
void Header::changeEvent(QEvent *event)
Header::~Header()
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();
QWidget::changeEvent(event);
REMOVE_UI(this);
}
void Header::retranslateUi()
@@ -512,6 +511,20 @@ void Header::header_resize()
}
}
void Header::UpdateLanguage()
{
retranslateUi();
}
void Header::UpdateTheme()
{
retranslateUi();
}
void Header::UpdateFont()
{
}
} // namespace view
} // namespace pv

View File

@@ -26,9 +26,9 @@
#include <list>
#include <utility>
#include <QWidget>
#include <QLineEdit>
#include "../ui/uimanager.h"
namespace pv {
namespace view {
@@ -38,18 +38,19 @@ class View;
//the left panel of main graph
//created by View
class Header : public QWidget
class Header : public QWidget, public IUiWindow
{
Q_OBJECT
public:
Header(View &parent);
~Header();
private:
pv::view::Trace* get_mTrace(int &action, const QPoint &pt);
private:
void changeEvent(QEvent *event);
void retranslateUi();
void paintEvent(QPaintEvent *event);
@@ -65,6 +66,11 @@ private:
void changeName(QMouseEvent *event);
void changeColor(QMouseEvent *event);
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
public:
int get_nameEditWidth();
void header_resize();

View File

@@ -122,8 +122,6 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget
_header = new Header(*this);
_devmode = new DevMode(this, session);
AppControl::Instance()->add_font_form(_devmode);
setViewportMargins(headerWidth(), RulerHeight, 0, 0);
// windows splitter
@@ -202,11 +200,15 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget
connect(_header, SIGNAL(traces_moved()),this, SLOT(on_traces_moved()));
connect(_header, SIGNAL(header_updated()),this, SLOT(header_updated()));
ADD_UI(this);
}
View::~View(){
View::~View()
{
DESTROY_OBJECT(_trig_cursor);
DESTROY_OBJECT(_search_cursor);
REMOVE_UI(this);
}
void View::show_wait_trigger()
@@ -1422,5 +1424,20 @@ Cursor* View::get_cursor_by_index(int index)
return NULL;
}
void View::UpdateLanguage()
{
}
void View::UpdateTheme()
{
}
void View::UpdateFont()
{
update_font();
}
} // namespace view
} // namespace pv

View File

@@ -43,6 +43,7 @@
#include "viewstatus.h"
#include "../dsvdef.h"
#include "../interface/icallbacks.h"
#include "../ui/uimanager.h"
class DeviceAgent;
@@ -69,7 +70,8 @@ class Viewport;
class LissajousFigure;
//created by MainWindow
class View : public QScrollArea, public IFontForm{
class View : public QScrollArea, public IUiWindow
{
Q_OBJECT
private:
@@ -324,11 +326,15 @@ public:
return _time_viewport;
}
//IFontForm
void update_font() override;
void update_font();
void check_measure();
bool header_is_draging();
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
signals:
void hover_point_changed();
void cursor_update();

View File

@@ -115,6 +115,13 @@ Viewport::Viewport(View &parent, View_type type) :
connect(yAction, SIGNAL(triggered(bool)), this, SLOT(add_cursor_y()));
connect(xAction, SIGNAL(triggered(bool)), this, SLOT(add_cursor_x()));
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(show_contextmenu(const QPoint&)));
ADD_UI(this);
}
Viewport::~Viewport()
{
REMOVE_UI(this);
}
int Viewport::get_total_height()
@@ -2066,5 +2073,18 @@ void Viewport::update_lang()
_xAction->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_ADD_X_CURSOR), "Add X-cursor"));
}
void Viewport::UpdateLanguage()
{
}
void Viewport::UpdateTheme()
{
}
void Viewport::UpdateFont()
{
update_font();
}
} // namespace view
} // namespace pv

View File

@@ -36,6 +36,7 @@
#include "../view/view.h"
#include "../dsvdef.h"
#include "../interface/icallbacks.h"
#include "../ui/uimanager.h"
class QPainter;
class QPaintEvent;
@@ -62,7 +63,7 @@ class View;
//main graph view port, in the middle region
//draw the left and right rule scale
//created by View
class Viewport : public QWidget, public IFontForm
class Viewport : public QWidget, public IUiWindow
{
Q_OBJECT
@@ -102,6 +103,7 @@ public:
public:
explicit Viewport(View &parent, View_type type);
~Viewport();
int get_total_height();
QPoint get_mouse_point();
@@ -118,18 +120,19 @@ public:
void show_wait_trigger();
void update_lang();
//IFontForm
void update_font() override;
void update_font();
void measure();
void update(int event);
protected:
bool event(QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
//IUiWindow
void UpdateLanguage() override;
void UpdateTheme() override;
void UpdateFont() override;
private:
void doPaint();
void mousePressEvent(QMouseEvent *event) override;