2022-02-19 10:54:26 -06:00
|
|
|
#include "SeerKeysConfigPage.h"
|
2022-02-19 11:29:13 -06:00
|
|
|
#include <QtWidgets/QKeySequenceEdit>
|
|
|
|
|
#include <QtWidgets/QLabel>
|
2022-02-19 10:54:26 -06:00
|
|
|
#include <QtWidgets/QWidget>
|
2023-04-25 19:01:28 -05:00
|
|
|
#include <QtCore/QDebug>
|
2022-02-19 10:54:26 -06:00
|
|
|
|
|
|
|
|
SeerKeysConfigPage::SeerKeysConfigPage(QWidget* parent) : QWidget(parent) {
|
|
|
|
|
|
|
|
|
|
// Set up the UI.
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
2022-07-20 19:51:38 -05:00
|
|
|
// Connect things.
|
|
|
|
|
|
2022-02-19 10:54:26 -06:00
|
|
|
// Setup the widgets
|
2022-02-19 12:02:19 -06:00
|
|
|
setKeySettings(SeerKeySettings::populate());
|
2022-02-19 10:54:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeerKeysConfigPage::~SeerKeysConfigPage() {
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 11:29:13 -06:00
|
|
|
void SeerKeysConfigPage::setKeySettings (const SeerKeySettings& settings) {
|
|
|
|
|
|
|
|
|
|
// Clear the table contents.
|
|
|
|
|
keysTableWidget->setRowCount(0);
|
|
|
|
|
|
|
|
|
|
// Get a list of keys from the highlighter.
|
2022-02-19 12:02:19 -06:00
|
|
|
QStringList keys = settings.keys();
|
2022-02-19 11:29:13 -06:00
|
|
|
|
|
|
|
|
// Loop through each key and get its info.
|
|
|
|
|
// Construct a table entry.
|
|
|
|
|
for (int r=0; r<keys.size(); r++) {
|
|
|
|
|
|
|
|
|
|
QString key = keys[r];
|
|
|
|
|
|
2022-02-19 12:02:19 -06:00
|
|
|
SeerKeySetting setting = settings.get(key);
|
2022-02-19 11:29:13 -06:00
|
|
|
|
|
|
|
|
keysTableWidget->insertRow(r);
|
|
|
|
|
|
|
|
|
|
// Insert the KeySequence editor.
|
|
|
|
|
QKeySequenceEdit* keySequenceEdit = new QKeySequenceEdit;
|
|
|
|
|
keySequenceEdit->setKeySequence(setting._sequence);
|
|
|
|
|
|
|
|
|
|
keysTableWidget->setCellWidget(r, 0, keySequenceEdit);
|
|
|
|
|
|
|
|
|
|
// Insert the Description.
|
2022-02-20 09:27:13 -06:00
|
|
|
QLabel* descriptionLabel = new QLabel(setting._description);
|
2022-02-19 11:29:13 -06:00
|
|
|
keysTableWidget->setCellWidget(r, 1, descriptionLabel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keysTableWidget->setVerticalHeaderLabels(keys);
|
|
|
|
|
|
|
|
|
|
keysTableWidget->resizeColumnToContents(0); // KeySequence
|
|
|
|
|
keysTableWidget->resizeColumnToContents(1); // Description
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 12:02:19 -06:00
|
|
|
SeerKeySettings SeerKeysConfigPage::keySettings() const {
|
|
|
|
|
|
|
|
|
|
SeerKeySettings settings;
|
|
|
|
|
|
2023-04-25 19:01:28 -05:00
|
|
|
if (keysTableWidget->rowCount() == 0) {
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keysTableWidget->columnCount() == 2) {
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 12:02:19 -06:00
|
|
|
for (int r=0; r<keysTableWidget->rowCount(); r++) {
|
|
|
|
|
|
|
|
|
|
// Get the key (label) for this row.
|
|
|
|
|
QString key = keysTableWidget->verticalHeaderItem(r)->text();
|
|
|
|
|
|
|
|
|
|
// Get widgets for this row.
|
|
|
|
|
QKeySequenceEdit* keySequenceEdit = dynamic_cast<QKeySequenceEdit*>(keysTableWidget->cellWidget(r,0));
|
|
|
|
|
QLabel* descriptionLabel = dynamic_cast<QLabel*>(keysTableWidget->cellWidget(r,1));
|
|
|
|
|
|
|
|
|
|
// Create key setting.
|
2023-04-25 19:01:28 -05:00
|
|
|
if (keySequenceEdit != 0 && descriptionLabel != 0) {
|
|
|
|
|
|
|
|
|
|
SeerKeySetting setting(key, keySequenceEdit->keySequence(), descriptionLabel->text());
|
|
|
|
|
|
|
|
|
|
// Add the setting to our settings.
|
|
|
|
|
settings.add(key, setting);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
if (keySequenceEdit == 0) {
|
|
|
|
|
qDebug() << "QKeySequenceEdit for row" << r << "is null!";
|
|
|
|
|
}
|
2022-02-19 12:02:19 -06:00
|
|
|
|
2023-04-25 19:01:28 -05:00
|
|
|
if (descriptionLabel == 0) {
|
|
|
|
|
qDebug() << "QLabel for row" << r << "is null!";
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-19 12:02:19 -06:00
|
|
|
}
|
2022-02-19 11:29:13 -06:00
|
|
|
|
2022-02-19 12:02:19 -06:00
|
|
|
return settings;
|
2022-02-19 11:29:13 -06:00
|
|
|
}
|
|
|
|
|
|
2022-07-20 19:51:38 -05:00
|
|
|
void SeerKeysConfigPage::reset () {
|
|
|
|
|
|
|
|
|
|
setKeySettings(SeerKeySettings::populate());
|
|
|
|
|
}
|
|
|
|
|
|