Redesign pref pack GUI

This commit is contained in:
Chris Hennes
2021-09-24 16:09:17 -05:00
parent cc53377985
commit c2e1f9937d
3 changed files with 73 additions and 77 deletions

View File

@@ -99,9 +99,15 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTableWidget" name="PreferencePacks">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
@@ -112,7 +118,7 @@
<bool>false</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
@@ -136,10 +142,10 @@
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>75</number>
<number>30</number>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>200</number>
<number>100</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
@@ -175,22 +181,27 @@
</font>
</property>
</column>
<column>
<property name="text">
<string>Load</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="ApplyPreferencePack">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="text">
<string>Run</string>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item>
<widget class="QPushButton" name="SaveNewPreferencePack">
@@ -212,19 +223,6 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>

View File

@@ -95,8 +95,6 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent )
}
recreatePreferencePackMenu();
connect(ui->PreferencePacks, &QTableWidget::itemSelectionChanged, this, &DlgGeneralImp::preferencePackSelectionChanged);
connect(ui->ApplyPreferencePack, &QPushButton::clicked, this, &DlgGeneralImp::applyPreferencePackClicked);
connect(ui->SaveNewPreferencePack, &QPushButton::clicked, this, &DlgGeneralImp::saveAsNewPreferencePack);
// Future work: the Add-On Manager will be modified to include a section for Preference Packs, at which point this
@@ -328,45 +326,53 @@ void DlgGeneralImp::changeEvent(QEvent *e)
void DlgGeneralImp::recreatePreferencePackMenu()
{
// Populate the Preference Packs list
auto appearancePacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Appearance);
auto behaviorPacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Behavior);
auto combinationPacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Combination);
ui->PreferencePacks->setRowCount(0); // Begin by clearing whatever is there
ui->PreferencePacks->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
ui->PreferencePacks->setColumnCount(3);
ui->PreferencePacks->setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeMode::Stretch);
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeMode::ResizeToContents);
QStringList columnHeaders;
columnHeaders << tr("Preference Pack Name")
<< tr("Type", "Whether a preference pack sets appearance, behavior, or both")
<< QString(); // for the "Load" buttons
ui->PreferencePacks->setHorizontalHeaderLabels(columnHeaders);
ui->PreferencePacks->setRowCount(appearancePacks.size() + behaviorPacks.size() + combinationPacks.size());
// Populate the Preference Packs list
std::map<PreferencePack::Type, std::vector<std::string>> packNames;
packNames[PreferencePack::Type::Appearance] = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Appearance);
packNames[PreferencePack::Type::Behavior] = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Behavior);
packNames[PreferencePack::Type::Combination] = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Combination);
ui->PreferencePacks->setRowCount(
packNames[PreferencePack::Type::Appearance].size() +
packNames[PreferencePack::Type::Behavior].size() +
packNames[PreferencePack::Type::Combination].size());
int row = 0;
for (const auto& pack : appearancePacks) {
auto name = new QTableWidgetItem(QString::fromStdString(pack));
ui->PreferencePacks->setItem(row, 0, name);
auto kind = new QTableWidgetItem(tr("Appearance"));
ui->PreferencePacks->setItem(row, 1, kind);
++row;
}
for (const auto& pack : behaviorPacks) {
auto name = new QTableWidgetItem(QString::fromStdString(pack));
ui->PreferencePacks->setItem(row, 0, name);
auto kind = new QTableWidgetItem(tr("Behavior"));
ui->PreferencePacks->setItem(row, 1, kind);
++row;
}
for (const auto& pack : combinationPacks) {
auto name = new QTableWidgetItem(QString::fromStdString(pack));
ui->PreferencePacks->setItem(row, 0, name);
auto kind = new QTableWidgetItem(tr("Combination"));
ui->PreferencePacks->setItem(row, 1, kind);
++row;
for (const auto& packGroup : packNames) {
for (const auto& pack : packGroup.second) {
auto name = new QTableWidgetItem(QString::fromStdString(pack));
ui->PreferencePacks->setItem(row, 0, name);
QTableWidgetItem* kind;
switch (packGroup.first) {
case PreferencePack::Type::Appearance: kind = new QTableWidgetItem(tr("Appearance")); break;
case PreferencePack::Type::Behavior: kind = new QTableWidgetItem(tr("Behavior")); break;
case PreferencePack::Type::Combination: kind = new QTableWidgetItem(tr("Combination")); break;
default: kind = new QTableWidgetItem(QString::fromUtf8("[ERR: UNKNOWN TYPE]")); break;
}
ui->PreferencePacks->setItem(row, 1, kind);
auto button = new QPushButton(tr("Apply"));
button->setToolTip(tr("Apply the ") +
QString::fromStdString(pack) + QString::fromUtf8(" ") +
tr("Preference Pack"));
connect(button, &QPushButton::clicked, this, [this, pack]() { onLoadPreferencePackClicked(pack); });
ui->PreferencePacks->setCellWidget(row, 2, button);
++row;
}
}
ui->PreferencePacks->setRangeSelected(QTableWidgetSelectionRange(), true);
ui->ApplyPreferencePack->setEnabled(false);
}
void DlgGeneralImp::preferencePackSelectionChanged()
{
if (ui->PreferencePacks->selectedItems().isEmpty())
ui->ApplyPreferencePack->setEnabled(false);
else
ui->ApplyPreferencePack->setEnabled(true);
}
void DlgGeneralImp::saveAsNewPreferencePack()
@@ -402,19 +408,12 @@ void DlgGeneralImp::newPreferencePackDialogAccepted()
recreatePreferencePackMenu();
}
void DlgGeneralImp::applyPreferencePackClicked()
void DlgGeneralImp::onLoadPreferencePackClicked(const std::string& packName)
{
auto selectedPreferencePacks = ui->PreferencePacks->selectedItems();
for (const auto pack : selectedPreferencePacks) {
if (pack->column() == 0) {
auto packName = pack->text().toStdString();
if (Application::Instance->prefPackManager()->apply(packName)) {
auto parentDialog = qobject_cast<DlgPreferencesImp*> (this->window());
if (parentDialog)
parentDialog->reload();
}
}
if (Application::Instance->prefPackManager()->apply(packName)) {
auto parentDialog = qobject_cast<DlgPreferencesImp*> (this->window());
if (parentDialog)
parentDialog->reload();
}
}

View File

@@ -53,8 +53,7 @@ protected:
void changeEvent(QEvent *e);
protected Q_SLOTS:
void preferencePackSelectionChanged();
void applyPreferencePackClicked();
void onLoadPreferencePackClicked(const std::string &packName);
void recreatePreferencePackMenu();
void newPreferencePackDialogAccepted();