-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔵 commands: added custom static commands (#46)
- Loading branch information
Showing
9 changed files
with
344 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>CommandsWindow</class> | ||
<widget class="QDialog" name="CommandsWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>640</width> | ||
<height>480</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Commands</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="2" column="0"> | ||
<spacer name="horizontalSpacer"> | ||
<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 row="2" column="1"> | ||
<widget class="QPushButton" name="addCommandBtn"> | ||
<property name="enabled"> | ||
<bool>true</bool> | ||
</property> | ||
<property name="text"> | ||
<string>Add Command</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="2"> | ||
<widget class="QPushButton" name="removeCommandBtn"> | ||
<property name="text"> | ||
<string>Remove Command</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0" colspan="3"> | ||
<widget class="QTableWidget" name="commandsTable"> | ||
<property name="alternatingRowColors"> | ||
<bool>true</bool> | ||
</property> | ||
<attribute name="horizontalHeaderCascadingSectionResizes"> | ||
<bool>false</bool> | ||
</attribute> | ||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0"> | ||
<bool>false</bool> | ||
</attribute> | ||
<attribute name="horizontalHeaderStretchLastSection"> | ||
<bool>true</bool> | ||
</attribute> | ||
<attribute name="verticalHeaderVisible"> | ||
<bool>false</bool> | ||
</attribute> | ||
<row> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</row> | ||
<row> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</row> | ||
<column> | ||
<property name="text"> | ||
<string>Command</string> | ||
</property> | ||
</column> | ||
<column> | ||
<property name="text"> | ||
<string>Reply</string> | ||
</property> | ||
</column> | ||
<item row="0" column="0"> | ||
<property name="text"> | ||
<string>!np</string> | ||
</property> | ||
<property name="flags"> | ||
<set>NoItemFlags</set> | ||
</property> | ||
</item> | ||
<item row="0" column="1"> | ||
<property name="text"> | ||
<string>-</string> | ||
</property> | ||
<property name="flags"> | ||
<set>NoItemFlags</set> | ||
</property> | ||
</item> | ||
<item row="1" column="0"> | ||
<property name="text"> | ||
<string>!skin</string> | ||
</property> | ||
<property name="flags"> | ||
<set>NoItemFlags</set> | ||
</property> | ||
</item> | ||
<item row="1" column="1"> | ||
<property name="text"> | ||
<string>-</string> | ||
</property> | ||
<property name="flags"> | ||
<set>NoItemFlags</set> | ||
</property> | ||
</item> | ||
</widget> | ||
</item> | ||
<item row="4" column="0" colspan="3"> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>CommandsWindow</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>CommandsWindow</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include "commandswindow.h" | ||
#include "ui_commandswindow.h" | ||
|
||
CommandsWindow::CommandsWindow(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::CommandsWindow) | ||
{ | ||
ui->setupUi(this); | ||
loadData(); | ||
connect(ui->addCommandBtn, &QPushButton::clicked, this, &CommandsWindow::on_addCommandBtn_clicked); | ||
connect(ui->removeCommandBtn, &QPushButton::clicked, this, &CommandsWindow::on_removeCommandBtn_clicked); | ||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &CommandsWindow::on_saveBtn_clicked); | ||
} | ||
|
||
CommandsWindow::~CommandsWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void CommandsWindow::loadData() | ||
{ | ||
qDebug() << "[Commands] Loading data"; | ||
QSettings settings; | ||
settings.beginGroup("command"); | ||
QStringList commands = settings.childKeys(); | ||
|
||
for (QString command: commands) { | ||
addRow(command, settings.value(command).toString()); | ||
} | ||
} | ||
|
||
void CommandsWindow::addRow(QString command, QString response) | ||
{ | ||
// adding new line | ||
ui->commandsTable->insertRow(ui->commandsTable->rowCount()); | ||
QTableWidgetItem *commandNameItem = new QTableWidgetItem(command); | ||
QTableWidgetItem *commandResponseItem = new QTableWidgetItem(response); | ||
|
||
// Command name column | ||
ui->commandsTable->setItem( | ||
ui->commandsTable->rowCount() - 1, | ||
0, | ||
commandNameItem | ||
); | ||
|
||
// Command response column | ||
ui->commandsTable->setItem( | ||
ui->commandsTable->rowCount() - 1, | ||
1, | ||
commandResponseItem | ||
); | ||
} | ||
|
||
void CommandsWindow::on_addCommandBtn_clicked() | ||
{ | ||
int lastRow = ui->commandsTable->rowCount() - 1; | ||
auto lastCommand = ui->commandsTable->item(lastRow, 0); | ||
auto lastResponse = ui->commandsTable->item(lastRow, 1); | ||
|
||
bool isLastCommandEmpty = lastCommand != nullptr && lastCommand->text().isEmpty(); | ||
bool isLastResponseEmpty = lastResponse != nullptr && lastResponse->text().isEmpty(); | ||
|
||
if (!isLastCommandEmpty && !isLastResponseEmpty){ | ||
addRow("",""); | ||
} | ||
} | ||
|
||
void CommandsWindow::on_removeCommandBtn_clicked() | ||
{ | ||
QSettings settings; | ||
auto selectionModel = ui->commandsTable->selectionModel(); | ||
if (!selectionModel->hasSelection()){ | ||
return; | ||
} | ||
|
||
auto selected = selectionModel->selectedIndexes(); | ||
for (auto selection : selected) { | ||
int row = selection.row(); | ||
QString command = ui->commandsTable->item(row, 0)->text(); | ||
|
||
settings.remove(QString("command/%1").arg(command)); | ||
ui->commandsTable->removeRow(row); | ||
} | ||
} | ||
|
||
void CommandsWindow::on_saveBtn_clicked() | ||
{ | ||
qDebug() << "[Commands] Saving data..."; | ||
QSettings settings; | ||
|
||
for (int row = 2; row < ui->commandsTable->rowCount(); row++) { | ||
QTableWidgetItem *commandNameItem = ui->commandsTable->item(row, 0); | ||
QTableWidgetItem *commandResponseItem = ui->commandsTable->item(row, 1); | ||
|
||
if (commandResponseItem == nullptr || commandNameItem == nullptr) { | ||
return; | ||
} | ||
|
||
QString commandName = commandNameItem->text(); | ||
QString commandResponse = commandResponseItem->text(); | ||
|
||
if (!commandName.startsWith("!")) { | ||
commandName.prepend("!"); | ||
} | ||
|
||
QString key = QString("command/%1").arg(commandName); | ||
settings.setValue(key, commandResponse); | ||
qDebug() << "[Commands] " << commandName << "has been saved"; | ||
} | ||
qDebug() << "[Commands] Data saved"; | ||
accept(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef COMMANDSWINDOW_H | ||
#define COMMANDSWINDOW_H | ||
|
||
#include <QDialog> | ||
#include <QMessageBox> | ||
#include <QSettings> | ||
|
||
namespace Ui { | ||
class CommandsWindow; | ||
} | ||
|
||
class CommandsWindow : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit CommandsWindow(QWidget *parent = nullptr); | ||
~CommandsWindow(); | ||
|
||
private: | ||
void on_addCommandBtn_clicked(); | ||
void on_removeCommandBtn_clicked(); | ||
void on_saveBtn_clicked(); | ||
|
||
void loadData(); | ||
void addRow(QString command, QString response); | ||
|
||
Ui::CommandsWindow *ui; | ||
}; | ||
|
||
#endif // COMMANDSWINDOW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.