forked from MrBesen/soundboard
edit button width
This commit is contained in:
parent
129140331a
commit
ae224728c0
|
@ -18,9 +18,11 @@ public:
|
|||
|
||||
const std::string& getName() const;
|
||||
const std::string& getKey() const;
|
||||
uint8_t getWidth() const;
|
||||
|
||||
void setName(const std::string& name);
|
||||
void setKey(const std::string& key);
|
||||
void setWidth(uint8_t w);
|
||||
|
||||
private slots:
|
||||
void editName(const QString& text);
|
||||
|
|
|
@ -229,6 +229,7 @@ void ButtonItem::edit() {
|
|||
EditButton editor;
|
||||
editor.setName(buttonConf.name);
|
||||
editor.setKey(buttonConf.key);
|
||||
editor.setWidth(buttonConf.width);
|
||||
editor.exec();
|
||||
|
||||
if(editor.result() == 0) {
|
||||
|
@ -238,6 +239,9 @@ void ButtonItem::edit() {
|
|||
|
||||
buttonConf.name = editor.getName();
|
||||
buttonConf.key = editor.getKey();
|
||||
buttonConf.width = editor.getWidth();
|
||||
|
||||
setData(1, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(buttonConf.name)));
|
||||
}
|
||||
|
||||
void ButtonItem::remove() {
|
||||
|
|
|
@ -20,9 +20,18 @@ public:
|
|||
EditButton::EditButton(QWidget *parent) : QDialog(parent), ui(new Ui::EditButton) {
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->buttonName->setValidator(new QRegExpValidator(QRegExp("\\w{1,64}")));
|
||||
ui->buttonName->setValidator(new QRegExpValidator(QRegExp("(\\w+ \\w+)|(\\w+)")));
|
||||
ui->buttonKey->setValidator(new MyKeysequenceValidtor());
|
||||
|
||||
ui->buttonWidth->addItem("1/6", 1);
|
||||
ui->buttonWidth->addItem("1/3", 2);
|
||||
ui->buttonWidth->addItem("1/2", 3);
|
||||
ui->buttonWidth->addItem("2/3", 4);
|
||||
ui->buttonWidth->addItem("Normal", 6);
|
||||
ui->buttonWidth->addItem("1 + 1/3", 8);
|
||||
ui->buttonWidth->addItem("1 + 2/3", 10);
|
||||
ui->buttonWidth->addItem("Double", 12);
|
||||
|
||||
QObject::connect(ui->buttonName, SIGNAL( textEdited(const QString&) ), this, SLOT( editName(const QString&) ));
|
||||
QObject::connect(ui->buttonKey, SIGNAL( textEdited(const QString&) ), this, SLOT( editShortcut(const QString&) ));
|
||||
}
|
||||
|
@ -39,16 +48,30 @@ const std::string& EditButton::getKey() const {
|
|||
return key;
|
||||
}
|
||||
|
||||
uint8_t EditButton::getWidth() const {
|
||||
QVariant var = ui->buttonWidth->currentData();
|
||||
assert(var.type() == QVariant::Type::Int);
|
||||
return var.toUInt();
|
||||
}
|
||||
|
||||
|
||||
void EditButton::setName(const std::string& name) {
|
||||
this->name = name;
|
||||
ui->buttonName->setText(QString::fromStdString(this->name));
|
||||
}
|
||||
|
||||
void EditButton::setKey(const std::string& key) {
|
||||
this->key = key;
|
||||
ui->buttonKey->setText(QString::fromStdString(this->key));
|
||||
}
|
||||
|
||||
void EditButton::setWidth(uint8_t w) {
|
||||
int index = ui->buttonWidth->findData((int) w);
|
||||
if(index == -1) index = 4; // default to "normal"
|
||||
|
||||
ui->buttonWidth->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void EditButton::editName(const QString& text) {
|
||||
// neded without const
|
||||
QString copy(text);
|
||||
|
@ -75,4 +98,4 @@ bool EditButton::setTextValid(QLineEdit* box, QString& newtext) const {
|
|||
box->setStyleSheet(QString("QLineEdit { border: 1px solid red; border-radius: 0.1em; text-decoration: underline; }"));
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,20 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonWidthRow">
|
||||
<item>
|
||||
<widget class="QLabel" name="buttonWidthLabel">
|
||||
<property name="text">
|
||||
<string>Width:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="buttonWidth"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
Loading…
Reference in New Issue