Skip to content

Commit

Permalink
Encoding combobox optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
LiaoCheng authored and LiaoCheng committed Jan 30, 2023
1 parent 4d08f3b commit a30e842
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,22 @@ MainWindow::MainWindow(QWidget *parent)
qtAvaEcs.removeOne(top); }
encodingList += qtAvaEcs;

ui->comboBox_EncodingSrc->blockSignals(true);
ui->comboBox_EncodingDest->blockSignals(true);
QFontMetrics fm = fontMetrics();
int cbboxMaxWidth = 0;
for (auto &ec: encodingList) {
QStringList aliases = ec.split(" / ");
ui->comboBox_EncodingSrc->addItem(ec, aliases.first());
ui->comboBox_EncodingDest->addItem(ec, aliases.first());
int tmp = fm.width(ec + " "); // 3 space to distinguish with " / "
if (tmp > cbboxMaxWidth)
cbboxMaxWidth = tmp;
}
ui->comboBox_EncodingSrc->blockSignals(false);
ui->comboBox_EncodingDest->blockSignals(false);
ui->comboBox_EncodingSrc->view()->setFixedWidth(cbboxMaxWidth + 20); // 20: scroll bar width
ui->comboBox_EncodingDest->view()->setFixedWidth(cbboxMaxWidth + 20);

sIniPath = "config.ini";
IniSetting cfg(sIniPath);
Expand Down
11 changes: 9 additions & 2 deletions MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>820</width>
<height>500</height>
</rect>
</property>
Expand All @@ -30,6 +30,9 @@
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_EncodingSrc">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<item>
<property name="text">
<string>Auto detect (Support UTF and System encoding)</string>
Expand All @@ -47,7 +50,11 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,0">
<item>
<widget class="QComboBox" name="comboBox_EncodingDest"/>
<widget class="QComboBox" name="comboBox_EncodingDest">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_BomDest">
Expand Down

0 comments on commit a30e842

Please sign in to comment.