mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Track clipboard state and update UI accordingly
This commit is contained in:
@@ -48,6 +48,37 @@ StartGameTab::StartGameTab(QWidget * parent)
|
|||||||
#ifndef ENABLE_EDITOR
|
#ifndef ENABLE_EDITOR
|
||||||
ui->buttonGameEditor->hide();
|
ui->buttonGameEditor->hide();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto clipboard = QGuiApplication::clipboard();
|
||||||
|
|
||||||
|
connect(clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartGameTab::clipboardDataChanged()
|
||||||
|
{
|
||||||
|
ui->buttonPresetExport->setIcon(QIcon{});// reset icon, if any
|
||||||
|
|
||||||
|
auto clipboard = QGuiApplication::clipboard();
|
||||||
|
QString clipboardText = clipboard->text().trimmed();
|
||||||
|
|
||||||
|
if (clipboardText.isEmpty())
|
||||||
|
{
|
||||||
|
ui->buttonPresetImport->setEnabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// this *may* be json, try parsing it
|
||||||
|
if (clipboardText.startsWith('{'))
|
||||||
|
{
|
||||||
|
QByteArray presetBytes(clipboardText.toUtf8());
|
||||||
|
const JsonNode presetJson(reinterpret_cast<const std::byte*>(presetBytes.data()), presetBytes.size(), "preset in clipboard");
|
||||||
|
bool presetValid = !presetJson["name"].String().empty() && !presetJson["mods"].Vector().empty();
|
||||||
|
|
||||||
|
ui->buttonPresetImport->setEnabled(presetValid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ui->buttonPresetImport->setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StartGameTab::~StartGameTab()
|
StartGameTab::~StartGameTab()
|
||||||
@@ -70,6 +101,8 @@ void StartGameTab::refreshState()
|
|||||||
refreshTranslation(getMainWindow()->getTranslationStatus());
|
refreshTranslation(getMainWindow()->getTranslationStatus());
|
||||||
refreshPresets();
|
refreshPresets();
|
||||||
refreshMods();
|
refreshMods();
|
||||||
|
|
||||||
|
clipboardDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartGameTab::refreshPresets()
|
void StartGameTab::refreshPresets()
|
||||||
@@ -361,6 +394,8 @@ void StartGameTab::on_buttonPresetExport_clicked()
|
|||||||
JsonNode presetJson = getMainWindow()->getModView()->exportCurrentPreset();
|
JsonNode presetJson = getMainWindow()->getModView()->exportCurrentPreset();
|
||||||
QString presetString = QString::fromStdString(presetJson.toCompactString());
|
QString presetString = QString::fromStdString(presetJson.toCompactString());
|
||||||
QGuiApplication::clipboard()->setText(presetString);
|
QGuiApplication::clipboard()->setText(presetString);
|
||||||
|
|
||||||
|
ui->buttonPresetExport->setIcon(QIcon{":/icons/mod-enabled.png"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartGameTab::on_buttonPresetImport_clicked()
|
void StartGameTab::on_buttonPresetImport_clicked()
|
||||||
|
@@ -65,19 +65,14 @@ private slots:
|
|||||||
void on_buttonMissingVideoHelp_clicked();
|
void on_buttonMissingVideoHelp_clicked();
|
||||||
void on_buttonMissingFilesHelp_clicked();
|
void on_buttonMissingFilesHelp_clicked();
|
||||||
void on_buttonMissingCampaignsHelp_clicked();
|
void on_buttonMissingCampaignsHelp_clicked();
|
||||||
|
|
||||||
void on_buttonPresetExport_clicked();
|
void on_buttonPresetExport_clicked();
|
||||||
|
|
||||||
void on_buttonPresetImport_clicked();
|
void on_buttonPresetImport_clicked();
|
||||||
|
|
||||||
void on_buttonPresetNew_clicked();
|
void on_buttonPresetNew_clicked();
|
||||||
|
|
||||||
void on_buttonPresetDelete_clicked();
|
void on_buttonPresetDelete_clicked();
|
||||||
|
|
||||||
void on_comboBoxModPresets_currentTextChanged(const QString &arg1);
|
void on_comboBoxModPresets_currentTextChanged(const QString &arg1);
|
||||||
|
|
||||||
void on_buttonPresetRename_clicked();
|
void on_buttonPresetRename_clicked();
|
||||||
|
|
||||||
|
void clipboardDataChanged();
|
||||||
private:
|
private:
|
||||||
Ui::StartGameTab * ui;
|
Ui::StartGameTab * ui;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user