From 2ee09b82577e0f09c42520ddc9bfa5eb539429c9 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Fri, 16 Jun 2023 17:40:07 +0800 Subject: [PATCH] The font for device options,channel label editer,decoder trace format select --- DSView/pv/dialogs/deviceoptions.cpp | 81 ++++++++++++++++------------ DSView/pv/dialogs/deviceoptions.h | 1 - DSView/pv/dock/protocolitemlayer.cpp | 7 +-- DSView/pv/view/header.cpp | 5 ++ 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index e88948e5..576182fa 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -52,22 +52,26 @@ ChannelLabel::ChannelLabel(IChannelCheck *check, QWidget *parent, int chanIndex) _checked = check; _index = chanIndex; - this->setFixedSize(30, 40); - - QVBoxLayout *lay = new QVBoxLayout(); + QGridLayout *lay = new QGridLayout(); lay->setContentsMargins(0,0,0,0); lay->setSpacing(0); this->setLayout(lay); - QHBoxLayout *h1 = new QHBoxLayout(); - QHBoxLayout *h2 = new QHBoxLayout(); - h2->setAlignment(Qt::AlignCenter); - lay->addLayout(h1); - lay->addLayout(h2); - QLabel *lab = new QLabel(QString::number(chanIndex)); - lab->setAlignment(Qt::AlignCenter); - h1->addWidget(lab); + QLabel *lb = new QLabel(QString::number(chanIndex)); + lb->setAlignment(Qt::AlignCenter); _box = new QCheckBox(); - h2->addWidget(_box); + _box->setFixedSize(20,20); + lay->addWidget(lb, 0, 0, Qt::AlignCenter); + lay->addWidget(_box, 1, 0, Qt::AlignCenter); + + QFont font = this->font(); + font.setPointSizeF(AppConfig::Instance().appOptions.fontSize); + lb->setFont(font); + + int fh = lb->fontMetrics().height(); + int w = lb->fontMetrics().width(lb->text()) + 5; + w = w < 30 ? 30 : w; + int h = fh + _box->height() + 2; + setFixedSize(w, h); connect(_box, SIGNAL(released()), this, SLOT(on_checked())); } @@ -271,7 +275,6 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) int row1 = 0; int row2 = 0; - int index = 0; int vld_ch_num = 0; int cur_ch_num = 0; int contentHeight = 0; @@ -317,37 +320,45 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) _device_agent->get_config_int16(SR_CONF_VLD_CH_NUM, vld_ch_num); // channels - QHBoxLayout *line_lay = NULL; + QWidget *channel_pannel = new QWidget(); + QGridLayout *channel_grid = new QGridLayout(); + channel_grid->setContentsMargins(0,0,0,0); + channel_grid->setSpacing(0); + channel_pannel->setLayout(channel_grid); + + int channel_row = 0; + int channel_column = 0; + int channel_line_height = 0; + row2++; for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; - assert(probe); - + if (probe->enabled) cur_ch_num++; if (cur_ch_num > vld_ch_num) probe->enabled = false; - if (line_lay == NULL){ - line_lay = new QHBoxLayout(); - layout.addLayout(line_lay); - _sub_lays.push_back(line_lay); - row2++; - } + ChannelLabel *ch_item = new ChannelLabel(this, NULL, probe->index); + channel_grid->addWidget(ch_item, channel_row, channel_column++, Qt::AlignCenter); + _probes_checkBox_list.push_back(ch_item->getCheckBox()); + ch_item->getCheckBox()->setCheckState(probe->enabled ? Qt::Checked : Qt::Unchecked); + channel_line_height = ch_item->height(); - ChannelLabel *lab = new ChannelLabel(this, NULL, probe->index); - line_lay->addWidget(lab); - _probes_checkBox_list.push_back(lab->getCheckBox()); - lab->getCheckBox()->setCheckState(probe->enabled ? Qt::Checked : Qt::Unchecked); - index++; - - if (index % 8 == 0){ - line_lay = NULL; - } + if (channel_column == 8){ + channel_column = 0; + channel_row++; + + if (l->next != NULL){ + row2++; + } + } } + layout.addWidget(channel_pannel); + // space QWidget *space = new QWidget(); space->setFixedHeight(10); @@ -355,9 +366,8 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) contentHeight += 10; // buttons - line_lay = new QHBoxLayout(); + QHBoxLayout *line_lay = new QHBoxLayout(); layout.addLayout(line_lay); - _sub_lays.push_back(line_lay); line_lay->setSpacing(10); QPushButton *enable_all_probes = new QPushButton(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_ENABLE_ALL), "Enable All")); @@ -365,9 +375,10 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) enable_all_probes->setMaximumHeight(30); disable_all_probes->setMaximumHeight(30); - this->update_font(); + this->update_font(); + contentHeight += enable_all_probes->sizeHint().height(); - contentHeight += row2 * 40; + contentHeight += channel_line_height * row2 + 50; connect(enable_all_probes, SIGNAL(clicked()), this, SLOT(enable_all_probes())); diff --git a/DSView/pv/dialogs/deviceoptions.h b/DSView/pv/dialogs/deviceoptions.h index 28cc5212..202fae81 100644 --- a/DSView/pv/dialogs/deviceoptions.h +++ b/DSView/pv/dialogs/deviceoptions.h @@ -128,7 +128,6 @@ private slots: private: std::vector _probes_checkBox_list; - std::vector _sub_lays; QTimer _mode_check_timer; int _opt_mode; diff --git a/DSView/pv/dock/protocolitemlayer.cpp b/DSView/pv/dock/protocolitemlayer.cpp index 9f39b053..c347ad31 100644 --- a/DSView/pv/dock/protocolitemlayer.cpp +++ b/DSView/pv/dock/protocolitemlayer.cpp @@ -136,7 +136,7 @@ void ProtocolItemLayer::LoadFormatSelect(bool bSingle) _format_combox->addItem("oct"); _format_combox->addItem("bin"); } - _format_combox->addItem("ascii"); + _format_combox->addItem("ascii"); _format_combox->setCurrentIndex(0); m_bSetting = false; @@ -149,14 +149,14 @@ void ProtocolItemLayer::LoadFormatSelect(bool bSingle) m_bSetting = true; int dex = DecoderDataFormat::Parse(format); if (dex < (int)_format_combox->count()){ - _format_combox->setCurrentIndex(dex); + _format_combox->setCurrentIndex(dex); } m_bSetting = false; } void ProtocolItemLayer::enable_format(bool flag) { - _format_combox->setDisabled(!flag); + _format_combox->setDisabled(!flag); } void ProtocolItemLayer::set_label_name(QString name) @@ -169,6 +169,7 @@ void ProtocolItemLayer::LoadFormatSelect(bool bSingle) QFont font = _protocol_label->font(); font.setPointSizeF(AppConfig::Instance().appOptions.fontSize); _protocol_label->setFont(font); + _format_combox->setFont(font); } } //dock diff --git a/DSView/pv/view/header.cpp b/DSView/pv/view/header.cpp index ae6b83a7..6c94ed32 100644 --- a/DSView/pv/view/header.cpp +++ b/DSView/pv/view/header.cpp @@ -377,6 +377,11 @@ void Header::changeName(QMouseEvent *event) && event->button() == Qt::LeftButton) { header_resize(); + QFont font = this->font(); + float fsize = AppConfig::Instance().appOptions.fontSize; + font.setPointSizeF(fsize <= 10 ? fsize: 10); + nameEdit->setFont(font); + nameEdit->setText(_context_trace->get_name()); nameEdit->selectAll(); nameEdit->setFocus();