mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 23:47:21 +00:00
add contextual actions to the main table
This commit is contained in:
parent
028546540c
commit
a845e32960
@ -166,6 +166,7 @@ void MainWindow::createActions()
|
||||
connect(ui->pushButton_mainStart, SIGNAL(clicked(bool)), this, SLOT(mainTabStartProfile()));
|
||||
connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile()));
|
||||
connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(mainTabRefreshButtons(QTableWidgetItem *, QTableWidgetItem *)));
|
||||
connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint)));
|
||||
|
||||
// profile tab events
|
||||
connect(ui->lineEdit_profile, SIGNAL(returnPressed()), this, SLOT(profileTabLoadProfile()));
|
||||
@ -308,6 +309,60 @@ void MainWindow::updateWifiTab()
|
||||
|
||||
|
||||
// main tab slots
|
||||
void MainWindow::mainTabContextualMenu(const QPoint &pos)
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]";
|
||||
|
||||
// create menu
|
||||
QMenu menu(this);
|
||||
QAction *refreshTable = menu.addAction(QApplication::translate("MainWindow", "Refresh"));
|
||||
menu.addSeparator();
|
||||
QAction *startProfile = menu.addAction(QApplication::translate("MainWindow", "Start profile"));
|
||||
QAction *restartProfile = menu.addAction(QApplication::translate("MainWindow", "Restart profile"));
|
||||
QAction *enableProfile = menu.addAction(QApplication::translate("MainWindow", "Enable profile"));
|
||||
menu.addSeparator();
|
||||
QAction *removeProfile = menu.addAction(QApplication::translate("MainWindow", "Remove profile"));
|
||||
|
||||
// set text
|
||||
QString item = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text();
|
||||
if (!checkState(QString("inactive"), item)) {
|
||||
restartProfile->setVisible(true);
|
||||
startProfile->setText(QApplication::translate("MainWindow", "Stop profile"));
|
||||
}
|
||||
else {
|
||||
restartProfile->setVisible(false);
|
||||
startProfile->setText(QApplication::translate("MainWindow", "Start profile"));
|
||||
}
|
||||
if (checkState(QString("enabled"), item))
|
||||
enableProfile->setText(QApplication::translate("MainWindow", "Disable profile"));
|
||||
else
|
||||
enableProfile->setText(QApplication::translate("MainWindow", "Enable profile"));
|
||||
|
||||
// actions
|
||||
QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos));
|
||||
if (action == refreshTable) {
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Refresh table";
|
||||
updateMainTab();
|
||||
}
|
||||
else if (action == startProfile) {
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Start profile";
|
||||
mainTabStartProfile();
|
||||
}
|
||||
else if (action == restartProfile) {
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Restart profile";
|
||||
mainTabRestartProfile();
|
||||
}
|
||||
else if (action == enableProfile) {
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Enable profile";
|
||||
mainTabEnableProfile();
|
||||
}
|
||||
else if (action == removeProfile) {
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabContextualMenu]" << "Remove profile";
|
||||
mainTabRemoveProfile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::mainTabRemoveProfile()
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[mainTabRemoveProfile]";
|
||||
|
@ -70,6 +70,7 @@ private slots:
|
||||
void updateProfileTab();
|
||||
void updateWifiTab();
|
||||
// main tab slots
|
||||
void mainTabContextualMenu(const QPoint &pos);
|
||||
void mainTabRemoveProfile();
|
||||
void mainTabEnableProfile();
|
||||
void mainTabRestartProfile();
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>491</width>
|
||||
<height>519</height>
|
||||
<width>489</width>
|
||||
<height>517</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -27,6 +27,9 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_main">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
@ -200,8 +203,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>96</width>
|
||||
<height>26</height>
|
||||
<width>457</width>
|
||||
<height>359</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -365,7 +368,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>491</width>
|
||||
<width>489</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
Loading…
Reference in New Issue
Block a user