Prefer standard buttons instead of custom buttons + translation update

This commit is contained in:
Cubitect 2023-11-05 17:28:56 +01:00
parent f6bf97dc9d
commit 9e5816fa81
9 changed files with 141 additions and 191 deletions

View File

@ -27,7 +27,10 @@ BiomeColorDialog::BiomeColorDialog(MainWindow *parent, QString initrc, int mc, i
, modified()
{
ui->setupUi(this);
ui->buttonOk->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton));
connect(ui->buttonRemove, &QPushButton::clicked, this, &BiomeColorDialog::onRemove);
connect(ui->buttonSaveAs, &QPushButton::clicked, this, &BiomeColorDialog::onSaveAs);
connect(ui->buttonExport, &QPushButton::clicked, this, &BiomeColorDialog::onExport);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &BiomeColorDialog::onAccept);
memcpy(colors, g_biomeColors, sizeof(colors));
memset(buttons, 0, sizeof(buttons));
@ -35,12 +38,13 @@ BiomeColorDialog::BiomeColorDialog(MainWindow *parent, QString initrc, int mc, i
unsigned char coldefault[256][3];
initBiomeColors(coldefault);
QPushButton *button;
ui->gridLayout->setSpacing(2);
separator = new QLabel(tr("Currently inactive biomes:"), this);
separator->setVisible(false);
QPushButton *button;
button = new QPushButton(getColorIcon(QColor(0,0,0,0), QPen(Qt::transparent)), tr("Import..."), this);
connect(button, &QPushButton::clicked, this, &BiomeColorDialog::onImport);
ui->gridLayout->addWidget(button, 0, 0);
@ -277,7 +281,7 @@ void BiomeColorDialog::on_comboColormaps_currentIndexChanged(int index)
if (modified)
{
if (activerc.isEmpty())
on_buttonSaveAs_clicked();
onSaveAs();
else
saveColormap(activerc, "");
}
@ -286,7 +290,7 @@ void BiomeColorDialog::on_comboColormaps_currentIndexChanged(int index)
loadColormap(activerc, true);
}
void BiomeColorDialog::on_buttonSaveAs_clicked()
void BiomeColorDialog::onSaveAs()
{
QString rc;
int n;
@ -310,7 +314,7 @@ void BiomeColorDialog::on_buttonSaveAs_clicked()
activerc = rc;
}
void BiomeColorDialog::on_buttonExport_clicked()
void BiomeColorDialog::onExport()
{
QFileInfo finfo(mainwindow->prevdir);
QString fnam = QFileDialog::getSaveFileName(
@ -333,7 +337,7 @@ void BiomeColorDialog::on_buttonExport_clicked()
}
}
void BiomeColorDialog::on_buttonRemove_clicked()
void BiomeColorDialog::onRemove()
{
QString rc = qvariant_cast<QString>(ui->comboColormaps->currentData());
if (!rc.isEmpty())
@ -345,7 +349,7 @@ void BiomeColorDialog::on_buttonRemove_clicked()
}
}
void BiomeColorDialog::on_buttonOk_clicked()
void BiomeColorDialog::onAccept()
{
on_comboColormaps_currentIndexChanged(ui->comboColormaps->currentIndex());
emit yieldBiomeColorRc(activerc);

View File

@ -33,16 +33,15 @@ public slots:
private slots:
void on_comboColormaps_currentIndexChanged(int index);
void on_buttonSaveAs_clicked();
void on_buttonRemove_clicked();
void on_buttonOk_clicked();
void onSaveAs();
void onExport();
void onRemove();
void onAccept();
void onImport();
void onColorHelp();
void onAllToDefault();
void onAllToDimmed();
void on_buttonExport_clicked();
private:
Ui::BiomeColorDialog *ui;

View File

@ -33,16 +33,16 @@
<item row="3" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="buttonSaveAs">
<widget class="QPushButton" name="buttonExport">
<property name="text">
<string>Save as...</string>
<string>Export...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonExport">
<widget class="QPushButton" name="buttonSaveAs">
<property name="text">
<string>Export...</string>
<string>Save as...</string>
</property>
</widget>
</item>
@ -54,9 +54,9 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonOk">
<property name="text">
<string>Ok</string>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>

View File

@ -48,6 +48,9 @@ ConditionDialog::ConditionDialog(FormConditions *parent, Config *config, int mcv
memset(&cond, 0, sizeof(cond));
ui->setupUi(this);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ConditionDialog::onAccept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ConditionDialog::onReject);
textDescription = new QTextEdit(this);
textDescription->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
ui->collapseDescription->init(tr("Description/Notes"), textDescription, true);
@ -637,7 +640,7 @@ void ConditionDialog::updateMode()
ui->lineEditZ1->setToolTip(lowtip);
ui->lineEditX2->setToolTip(uptip);
ui->lineEditZ2->setToolTip(uptip);
ui->buttonOk->setEnabled(filterindex != F_SELECT);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(filterindex != F_SELECT);
textDescription->setText(QApplication::translate("Filter", ft.description));
}
@ -862,97 +865,6 @@ int ConditionDialog::warnIfBad(Condition cond)
return QMessageBox::Ok;
}
void ConditionDialog::on_comboBoxType_activated(int)
{
updateMode();
}
void ConditionDialog::on_comboBoxRelative_activated(int)
{
QPalette pal;
if (ui->comboBoxRelative->currentText().contains(WARNING_CHAR))
pal.setColor(QPalette::Normal, QPalette::Button, QColor(255,0,0,127));
ui->comboBoxRelative->setPalette(pal);
}
void ConditionDialog::on_buttonUncheck_clicked()
{
for (const auto& it : biomecboxes)
it.second->setCheckState(Qt::Unchecked);
}
void ConditionDialog::on_buttonInclude_clicked()
{
for (const auto& it : biomecboxes)
it.second->setCheckState(it.second->isEnabled() ? Qt::PartiallyChecked : Qt::Unchecked);
}
void ConditionDialog::on_buttonExclude_clicked()
{
for (const auto& it : biomecboxes)
it.second->setCheckState(it.second->isEnabled() ? Qt::Checked : Qt::Unchecked);
}
void ConditionDialog::on_buttonAreaInfo_clicked()
{
QMessageBox mb(this);
mb.setIcon(QMessageBox::Information);
mb.setWindowTitle(tr("Help: area entry"));
mb.setText(tr(
"<html><head/><body><p>"
"The area can be entered via <b>custom</b> rectangle, that is defined "
"by its two opposing corners, relative to a center point. These bounds "
"are inclusive."
"</p><p>"
"Alternatively, the area can be defined as a <b>centered square</b> "
"with a certain side length. In this case the area has the bounds: "
"[-X/2, -X/2] on both axes, rounding down and bounds included. For "
"example a centered square with side 3 will go from -2 to 1 for both "
"the X and Z axes."
"</p><p>"
"Important to note is that some filters have a scaling associated with "
"them. This means that the area is not defined in blocks, but on a grid "
"with the given spacing (such as chunks instead of blocks). A scaling "
"of 1:16, for example, means that the aforementioned centered square of "
"side 3 will range from -32 to 31 in block coordinates. (Chunk 1 has "
"blocks 16 to 31.)"
"</p></body></html>"
));
mb.exec();
}
void ConditionDialog::on_checkRadius_toggled(bool)
{
updateMode();
}
void ConditionDialog::on_radioSquare_toggled(bool)
{
updateMode();
}
void ConditionDialog::on_radioCustom_toggled(bool)
{
updateMode();
}
void ConditionDialog::on_lineSquare_editingFinished()
{
int v = ui->lineSquare->text().toInt();
int area = (v+1) * (v+1);
for (int i = 0; i < 9; i++)
{
if (tempsboxes[i])
tempsboxes[i]->setMaximum(area);
}
}
void ConditionDialog::on_buttonCancel_clicked()
{
on_comboLua_currentIndexChanged(-1);
close();
}
static uint16_t tristateFlags(QCheckBox *cb, uint16_t flg)
{
uint16_t ret = 0;
@ -965,7 +877,14 @@ static uint16_t tristateFlags(QCheckBox *cb, uint16_t flg)
return ret;
}
void ConditionDialog::on_buttonOk_clicked()
void ConditionDialog::onReject()
{
on_comboLua_currentIndexChanged(-1);
close();
}
void ConditionDialog::onAccept()
{
on_pushLuaSave_clicked();
@ -1110,6 +1029,91 @@ void ConditionDialog::on_buttonOk_clicked()
close();
}
void ConditionDialog::on_comboBoxType_activated(int)
{
updateMode();
}
void ConditionDialog::on_comboBoxRelative_activated(int)
{
QPalette pal;
if (ui->comboBoxRelative->currentText().contains(WARNING_CHAR))
pal.setColor(QPalette::Normal, QPalette::Button, QColor(255,0,0,127));
ui->comboBoxRelative->setPalette(pal);
}
void ConditionDialog::on_buttonUncheck_clicked()
{
for (const auto& it : biomecboxes)
it.second->setCheckState(Qt::Unchecked);
}
void ConditionDialog::on_buttonInclude_clicked()
{
for (const auto& it : biomecboxes)
it.second->setCheckState(it.second->isEnabled() ? Qt::PartiallyChecked : Qt::Unchecked);
}
void ConditionDialog::on_buttonExclude_clicked()
{
for (const auto& it : biomecboxes)
it.second->setCheckState(it.second->isEnabled() ? Qt::Checked : Qt::Unchecked);
}
void ConditionDialog::on_buttonAreaInfo_clicked()
{
QMessageBox mb(this);
mb.setIcon(QMessageBox::Information);
mb.setWindowTitle(tr("Help: area entry"));
mb.setText(tr(
"<html><head/><body><p>"
"The area can be entered via <b>custom</b> rectangle, that is defined "
"by its two opposing corners, relative to a center point. These bounds "
"are inclusive."
"</p><p>"
"Alternatively, the area can be defined as a <b>centered square</b> "
"with a certain side length. In this case the area has the bounds: "
"[-X/2, -X/2] on both axes, rounding down and bounds included. For "
"example a centered square with side 3 will go from -2 to 1 for both "
"the X and Z axes."
"</p><p>"
"Important to note is that some filters have a scaling associated with "
"them. This means that the area is not defined in blocks, but on a grid "
"with the given spacing (such as chunks instead of blocks). A scaling "
"of 1:16, for example, means that the aforementioned centered square of "
"side 3 will range from -32 to 31 in block coordinates. (Chunk 1 has "
"blocks 16 to 31.)"
"</p></body></html>"
));
mb.exec();
}
void ConditionDialog::on_checkRadius_toggled(bool)
{
updateMode();
}
void ConditionDialog::on_radioSquare_toggled(bool)
{
updateMode();
}
void ConditionDialog::on_radioCustom_toggled(bool)
{
updateMode();
}
void ConditionDialog::on_lineSquare_editingFinished()
{
int v = ui->lineSquare->text().toInt();
int area = (v+1) * (v+1);
for (int i = 0; i < 9; i++)
{
if (tempsboxes[i])
tempsboxes[i]->setMaximum(area);
}
}
void ConditionDialog::on_ConditionDialog_finished(int result)
{
if (item)

View File

@ -188,6 +188,9 @@ public:
void updateBiomeSelection();
int warnIfBad(Condition cond);
void onReject();
void onAccept();
void getClimateLimits(int limok[6][2], int limex[6][2]);
void getClimateLimits(LabeledRange *ranges[6], int limits[6][2]);
void setClimateLimits(LabeledRange *ranges[6], int limits[6][2], bool complete);
@ -213,10 +216,6 @@ private slots:
void on_lineSquare_editingFinished();
//void on_lineRadius_editingFinished();
void on_buttonCancel_clicked();
void on_buttonOk_clicked();
void on_ConditionDialog_finished(int result);
void on_comboBoxCat_currentIndexChanged(int);

View File

@ -1635,40 +1635,9 @@ QPushButton:hover {
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonCancel">
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset theme="dialog-cancel">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonOk">
<property name="text">
<string>Ok</string>
</property>
<property name="icon">
<iconset theme="dialog-ok">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="default">
<bool>true</bool>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
@ -1700,8 +1669,6 @@ QPushButton:hover {
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonOk</tabstop>
<tabstop>buttonCancel</tabstop>
<tabstop>comboBoxCat</tabstop>
<tabstop>comboBoxType</tabstop>
<tabstop>spinBox</tabstop>

View File

@ -7,6 +7,13 @@
static
int term_prompt(const QString& title, const QString& text, QMessageBox::StandardButtons buttons)
{
// translations for QGnomeTheme as they may override QPlatformThemes
QApplication::translate("QGnomeTheme", "&OK");
QApplication::translate("QGnomeTheme", "&Save");
QApplication::translate("QGnomeTheme", "&Cancel");
QApplication::translate("QGnomeTheme", "&Close");
QApplication::translate("QGnomeTheme", "Close without Saving");
QTextStream out (stdout);
out << QString("[%1]\n%2\n---\n").arg(title).arg(text);
std::vector<std::pair<QString, int>> opts;

View File

@ -60,8 +60,8 @@ PresetDialog::PresetDialog(QWidget *parent, WorldInfo wi, bool showEamples)
resize(fontMetrics().horizontalAdvance('x') * 128, fontMetrics().height() * 32);
ui->labelMC->setText(tr("MC ") + mc2str(wi.mc));
connect(ui->buttonOk, &QPushButton::clicked, this, &QDialog::accept);
connect(ui->buttonCancel, &QPushButton::clicked, this, &QDialog::reject);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
if (showEamples)
ui->tabWidget->setCurrentWidget(ui->tabExamples);
@ -203,13 +203,13 @@ void PresetDialog::updateSelection()
ui->formCond->on_buttonRemoveAll_clicked();
for (Condition& c : presets[rc].condvec)
ui->formCond->addItemCondition(new QListWidgetItem(), c);
ui->buttonOk->setEnabled(true);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
else
{
ui->textDesc->clear();
ui->formCond->on_buttonRemoveAll_clicked();
ui->buttonOk->setEnabled(false);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
}

View File

@ -116,41 +116,11 @@
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonOk">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCancel">
<property name="text">
<string>Cancel</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>