Adjust the height of deocder list pannel

This commit is contained in:
dreamsourcelabTAI 2024-04-19 18:48:52 +08:00
parent e3a66a12a1
commit 1409d5205b
2 changed files with 32 additions and 3 deletions

View File

@ -133,6 +133,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio
_top_layout = new QVBoxLayout(); _top_layout = new QVBoxLayout();
_top_layout->addLayout(pro_search_lay); _top_layout->addLayout(pro_search_lay);
_top_layout->addStretch(1); _top_layout->addStretch(1);
_top_layout->setSpacing(5);
top_panel->setLayout(_top_layout); top_panel->setLayout(_top_layout);
//-----------------------------bottom panel //-----------------------------bottom panel
@ -410,6 +411,8 @@ bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list<pv::dat
protocol_updated(); protocol_updated();
connect(decode_sigs.back(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progress(int))); connect(decode_sigs.back(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progress(int)));
adjustPannelSize();
return true; return true;
} }
@ -439,6 +442,8 @@ void ProtocolDock::del_all_protocol()
_protocol_lay_items.clear(); _protocol_lay_items.clear();
this->update(); this->update();
protocol_updated(); protocol_updated();
adjustPannelSize();
} }
} }
@ -875,13 +880,15 @@ void ProtocolDock::OnProtocolDelete(void *handle){
{ {
auto lay = (*it); auto lay = (*it);
void *key_handel = lay->get_protocol_key_handel(); void *key_handel = lay->get_protocol_key_handel();
_protocol_lay_items.erase(it); _protocol_lay_items.erase(it);
DESTROY_QT_LATER(lay); DESTROY_QT_LATER(lay);
_session->remove_decoder_by_key_handel(key_handel); _session->remove_decoder_by_key_handel(key_handel);
protocol_updated(); protocol_updated();
break; break;
} }
} }
adjustPannelSize();
} }
void ProtocolDock::OnProtocolFormatChanged(QString format, void *handle){ void ProtocolDock::OnProtocolFormatChanged(QString format, void *handle){
@ -1082,7 +1089,27 @@ void ProtocolDock::UpdateFont()
QString style = "#DecodedDataView QHeaderView{font-size: %1pt}"; QString style = "#DecodedDataView QHeaderView{font-size: %1pt}";
style = style.arg(AppConfig::Instance().appOptions.fontSize); style = style.arg(AppConfig::Instance().appOptions.fontSize);
_table_view->setStyleSheet(style); _table_view->setStyleSheet(style);
adjustPannelSize();
}
void ProtocolDock::adjustPannelSize()
{
QString str = "DECODER";
QFont font = this->font();
font.setPointSizeF(AppConfig::Instance().appOptions.fontSize);
QFontMetrics fm(font);
QRect rc = fm.boundingRect(str);
int lineHeight = rc.height() + 15;
_pro_keyword_edit->setFixedHeight(rc.height() + 5);
int pannelHeight = lineHeight * _protocol_lay_items.size() + _pro_keyword_edit->height();
if (pannelHeight < 100){
pannelHeight = 100;
}
_top_panel->setFixedHeight(pannelHeight);
} }
} // namespace dock } // namespace dock

View File

@ -121,6 +121,8 @@ private:
void UpdateTheme() override; void UpdateTheme() override;
void UpdateFont() override; void UpdateFont() override;
void adjustPannelSize();
signals: signals:
void protocol_updated(); void protocol_updated();