void ActionsEditor::saveActionsTable() { QString s = MyFileDialog::getSaveFileName( this, tr("Choose a filename"), latest_dir, tr("Key files") +" (*.keys)" ); if (!s.isEmpty()) { // If filename has no extension, add it if (QFileInfo(s).suffix().isEmpty()) { s = s + ".keys"; } if (QFileInfo(s).exists()) { int res = QMessageBox::question( this, tr("Confirm overwrite?"), tr("The file %1 already exists.\n" "Do you want to overwrite?").arg(s), QMessageBox::Yes, QMessageBox::No, Qt::NoButton); if (res == QMessageBox::No ) { return; } } latest_dir = QFileInfo(s).absolutePath(); bool r = saveActionsTable(s); if (!r) { QMessageBox::warning(this, tr("Error"), tr("The file couldn't be saved"), QMessageBox::Ok, Qt::NoButton); } } }
ActionsEditor::ActionsEditor(QWidget * parent, Qt::WindowFlags f) : QWidget(parent, f) { latest_dir = Paths::shortcutsPath(); actionsTable = new QTableWidget(0, COL_NAME +1, this); actionsTable->setSelectionMode( QAbstractItemView::SingleSelection ); actionsTable->verticalHeader()->hide(); actionsTable->horizontalHeader()->setResizeMode(COL_DESC, QHeaderView::Stretch); actionsTable->horizontalHeader()->setResizeMode(COL_NAME, QHeaderView::Stretch); actionsTable->setAlternatingRowColors(true); #if USE_SHORTCUTGETTER actionsTable->setSelectionBehavior(QAbstractItemView::SelectRows); actionsTable->setSelectionMode(QAbstractItemView::ExtendedSelection); #endif //actionsTable->setItemDelegateForColumn( COL_SHORTCUT, new MyDelegate(actionsTable) ); #if !USE_SHORTCUTGETTER connect(actionsTable, SIGNAL(currentItemChanged(QTableWidgetItem *,QTableWidgetItem *)), this, SLOT(recordAction(QTableWidgetItem *)) ); connect(actionsTable, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(validateAction(QTableWidgetItem *)) ); #else connect(actionsTable, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(editShortcut()) ); #endif saveButton = new QPushButton(this); loadButton = new QPushButton(this); connect(saveButton, SIGNAL(clicked()), this, SLOT(saveActionsTable())); connect(loadButton, SIGNAL(clicked()), this, SLOT(loadActionsTable())); #if USE_SHORTCUTGETTER editButton = new QPushButton(this); connect( editButton, SIGNAL(clicked()), this, SLOT(editShortcut()) ); #endif QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->setSpacing(8); #if USE_SHORTCUTGETTER buttonLayout->addWidget(editButton); #endif buttonLayout->addStretch(1); buttonLayout->addWidget(loadButton); buttonLayout->addWidget(saveButton); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setMargin(8); mainLayout->setSpacing(8); mainLayout->addWidget(actionsTable); mainLayout->addLayout(buttonLayout); retranslateStrings(); }