Example #1
0
void MainWindow::checkForFileChanges(const FileCheckMoment &moment)
{
	if (moment == FocusIn)
	{
		QDateTime lastExternalModifiedDateTime(QFileInfo(m_currentUrl.path()).lastModified());
		if (lastExternalModifiedDateTime > m_lastInternalModifiedDateTime)
			m_isModifiedExternally = true;
		else // when the fileChangedWarningMessageBox below is cancelled, the main window is focused in again with m_isModifiedExternally == true so this slot is called again, but now m_lastInternalModifiedDateTime has been updated (during focusOut) and now we don't want to show the dialog again
			return;
	}

	if (!m_isModifiedExternally)
		return;

	m_isModifiedExternally = false;
	QPointer<QMessageBox> fileChangedWarningMessageBox = new QMessageBox(this);
	fileChangedWarningMessageBox->setText(tr("The document was modified by another program.\nWhat do you want to do?"));
	fileChangedWarningMessageBox->setWindowTitle(KtikzApplication::applicationName());
	fileChangedWarningMessageBox->setIcon(QMessageBox::Warning);
	QAbstractButton *overwriteButton = fileChangedWarningMessageBox->addButton(tr("&Overwrite"), QMessageBox::AcceptRole);
	QAbstractButton *reloadButton;
	switch (moment)
	{
		case Saving:
			reloadButton = fileChangedWarningMessageBox->addButton(tr("&Save under another name"), QMessageBox::AcceptRole);
			break;
		case Closing:
			reloadButton = fileChangedWarningMessageBox->addButton(tr("&Close without saving"), QMessageBox::AcceptRole);
			break;
		case FocusIn:
		default:
			reloadButton = fileChangedWarningMessageBox->addButton(tr("&Reload file"), QMessageBox::AcceptRole);
			break;
	}
	fileChangedWarningMessageBox->addButton(QMessageBox::Cancel);
	fileChangedWarningMessageBox->exec();
	if (fileChangedWarningMessageBox->clickedButton() == overwriteButton)
		saveUrl(m_currentUrl);
	else if (fileChangedWarningMessageBox->clickedButton() == reloadButton)
		switch (moment)
		{
			case Saving:
				saveAs();
				break;
			case Closing:
				// do nothing since the file will be closed anyway
				break;
			case FocusIn:
			default:
				reload();
				break;
		}
	else // cancel (check again on "Save" or "Close")
		m_isModifiedExternally = true;
	delete fileChangedWarningMessageBox;
}
Example #2
0
GetQuantityDialog::GetQuantityDialog(QString prompt, int min, int max, int value)
{
    QPointer<QVBoxLayout> main_layout = new QVBoxLayout;

    QPointer<QLabel> header_main = new QLabel(QString("<b><h2>%1</h2></b>") .arg(prompt));
    header_main->setAlignment(Qt::AlignCenter);
    main_layout->addWidget(header_main);

    setLayout(main_layout);
    setWindowTitle(tr("Please select a quantity:"));

    this_quantity = new QSpinBox;
    this_quantity->setRange(min, max);
    this_quantity->setValue(value);

    current_quantity = value;

    main_layout->addWidget(this_quantity);

    connect(this_quantity, SIGNAL(valueChanged(int)), this, SLOT(update_quantity(int)));

    // Add buttons for min value, max value, OK, and cancel
    QPointer<QDialogButtonBox> buttons = new QDialogButtonBox();
    QPointer<QPushButton> min_button = new QPushButton();
    min_button->setText(QString("Min - %1") .arg(min));
    min_button->setToolTip("Use the minimum possible value");
    connect(min_button, SIGNAL(clicked()), this, SLOT(min_number_button()));
    buttons->addButton(min_button, QDialogButtonBox::ActionRole);
    QPointer<QPushButton> max_button = new QPushButton();
    max_button->setText(QString("Max - %1") .arg(max));
    max_button->setToolTip("Use the maximum possible value");
    connect(max_button, SIGNAL(clicked()), this, SLOT(max_number_button()));
    buttons->addButton(max_button, QDialogButtonBox::ActionRole);
    buttons->addButton(QDialogButtonBox::Ok);
    buttons->addButton(QDialogButtonBox::Cancel);
    connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
    main_layout->addWidget(buttons);

    setLayout(main_layout);
}