void MainWindow::create_actions() { // file menu new_model_action = new QAction(tr("New voxel model"), this); connect(new_model_action, SIGNAL(triggered()), this, SLOT(new_model())); open_model_action = new QAction(tr("Open voxel model"), this); connect(open_model_action, SIGNAL(triggered()), this, SLOT(open_model())); clone_model_action = new QAction(tr("Clone voxel model"), this); connect(clone_model_action, SIGNAL(triggered()), this, SLOT(clone_model())); save_action = new QAction(tr("&Save"), this); save_action->setShortcuts(QKeySequence::Save); connect(save_action, SIGNAL(triggered()), this, SLOT(save())); save_as_action = new QAction(tr("Save &As..."), this); save_as_action->setShortcuts(QKeySequence::SaveAs); connect(save_as_action, SIGNAL(triggered()), this, SLOT(save_as())); exit_action = new QAction(tr("E&xit"), this); exit_action->setShortcuts(QKeySequence::Quit); exit_action->setStatusTip(tr("Exit the application")); connect(exit_action, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); /* cut_action = new QAction(tr("Cu&t"), this); cut_action->setShortcuts(QKeySequence::Cut); cut_action->setStatusTip(tr("Cut the current selection's contents to the " "clipboard")); connect(cut_action, SIGNAL(triggered()), this, SLOT(cut())); copy_action = new QAction(tr("&Copy"), this); copy_action->setShortcuts(QKeySequence::Copy); copy_action->setStatusTip(tr("Copy the current selection's contents to the " "clipboard")); connect(copy_action, SIGNAL(triggered()), this, SLOT(copy())); paste_action = new QAction(tr("&Paste"), this); paste_action->setShortcuts(QKeySequence::Paste); paste_action->setStatusTip(tr("Paste the clipboard's contents into the current " "selection")); connect(paste_action, SIGNAL(triggered()), this, SLOT(paste()));*/ // model menu double_size_action = new QAction(tr("Double size"), this); // new_action->setShortcuts(QKeySequence::New); connect(double_size_action, SIGNAL(triggered()), this, SLOT(double_size())); half_size_action = new QAction(tr("Half size"), this); // open_action->setShortcuts(QKeySequence::Open); connect(half_size_action, SIGNAL(triggered()), this, SLOT(half_size())); optimize_action = new QAction(tr("Optimize dimensions"), this); // save_action->setShortcuts(QKeySequence::Save); connect(optimize_action, SIGNAL(triggered()), this, SLOT(optimize())); rotate_action = new QAction(tr("Rotate 90 degrees"), this); // save_action->setShortcuts(QKeySequence::Save); connect(rotate_action, SIGNAL(triggered()), this, SLOT(rotate())); }
void MyMainWindow::start_crypto(int crypto_type) { // check if the password fields match if(ui->password_0->text() == ui->password_1->text()) { QString pass = ui->password_0->text(); QString encrypt_name; bool checked = false; // make sure that there is actually something selected in the model for cryptography for(int n = file_model->rowCount(), i = 0; i < n; i++) { if(file_model->data(file_model->index(i, MyFileSystemModelPublic::CHECKED_HEADER), Qt::CheckStateRole) == Qt::Checked) { checked = true; break; } } // check that the password is long enough if(pass.toUtf8().size() < MIN_PASS_LENGTH) { QString num_text = QString::number(MIN_PASS_LENGTH); QString warn_text = QString("The password entered was too short. ") + "Please enter a longer " "one (at least " + num_text + " ASCII characters/bytes) before continuing."; QMessageBox::warning(this, "Password too short!", warn_text); } // give the user a warning message if nothing was selected else if(!checked) { QString crypto_text = (crypto_type == START_ENCRYPT) ? "encryption!" : "decryption!"; QString warn_text = QString("There were no items selected for " + crypto_text); QMessageBox::warning(this, "Nothing selected!", warn_text); } else { // start the encryption process bool delete_success = ui->delete_success->isChecked(); MyFileSystemModelPtr clone_model(file_model->cloneByValue()); /* MyAbstractBarPtr ptr_mpb = (crypto_type == START_ENCRYPT) ? MyAbstractBarPtr(new MyEncryptBar(this, clone_model.get(), pass, delete_success)) : MyAbstractBarPtr(new MyDecryptBar(this, clone_model.get(), pass, delete_success)); */ MyAbstractBarPtr ptr_mpb; if(crypto_type == START_ENCRYPT) { // check if the user wants to rename the encrypted files to something else if(ui->encrypt_rename->isChecked()) { encrypt_name = ui->encrypt_filename->text(); ptr_mpb = MyAbstractBarPtr(new MyEncryptBar(this, clone_model.get(), pass, delete_success, &encrypt_name)); } else { ptr_mpb = MyAbstractBarPtr(new MyEncryptBar(this, clone_model.get(), pass, delete_success)); } } else ptr_mpb = MyAbstractBarPtr(new MyDecryptBar(this, clone_model.get(), pass, delete_success)); if(ptr_mpb != nullptr) ptr_mpb->exec(); // after crypto, replace the old model with the new one setModel(clone_model.release()); // clear the password fields when done ui->password_0->clear(); ui->password_1->clear(); } } else QMessageBox::warning(this, "Passwords do not match!", "The password fields do not match! " "Please make sure they were entered correctly and try again."); }