parent
c169287336
commit
80a58cd729
|
@ -40,6 +40,7 @@ const QString VSettings::SettingConfigurationSendReportState = QStringLiteral("
|
||||||
const QString VSettings::SettingConfigurationLocale = QStringLiteral("configuration/locale");
|
const QString VSettings::SettingConfigurationLocale = QStringLiteral("configuration/locale");
|
||||||
const QString VSettings::SettingConfigurationUnit = QStringLiteral("configuration/unit");
|
const QString VSettings::SettingConfigurationUnit = QStringLiteral("configuration/unit");
|
||||||
const QString VSettings::SettingConfigurationLabelLanguage = QStringLiteral("configuration/label_language");
|
const QString VSettings::SettingConfigurationLabelLanguage = QStringLiteral("configuration/label_language");
|
||||||
|
const QString VSettings::SettingConfigurationConfirmItemDeletion= QStringLiteral("configuration/confirm_item_deletion");
|
||||||
|
|
||||||
const QString VSettings::SettingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements");
|
const QString VSettings::SettingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements");
|
||||||
const QString VSettings::SettingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements");
|
const QString VSettings::SettingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements");
|
||||||
|
@ -164,6 +165,18 @@ void VSettings::SetLabelLanguage(const QString &value)
|
||||||
setValue(SettingConfigurationLabelLanguage, value);
|
setValue(SettingConfigurationLabelLanguage, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool VSettings::GetConfirmItemDelete() const
|
||||||
|
{
|
||||||
|
return value(SettingConfigurationConfirmItemDeletion, 1).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VSettings::SetConfirmItemDelete(const bool &value)
|
||||||
|
{
|
||||||
|
setValue(SettingConfigurationConfirmItemDeletion, value);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VSettings::GetPathIndividualMeasurements() const
|
QString VSettings::GetPathIndividualMeasurements() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,6 +61,9 @@ public:
|
||||||
QString GetLabelLanguage() const;
|
QString GetLabelLanguage() const;
|
||||||
void SetLabelLanguage(const QString &value);
|
void SetLabelLanguage(const QString &value);
|
||||||
|
|
||||||
|
bool GetConfirmItemDelete() const;
|
||||||
|
void SetConfirmItemDelete(const bool &value);
|
||||||
|
|
||||||
QString GetPathIndividualMeasurements() const;
|
QString GetPathIndividualMeasurements() const;
|
||||||
void SetPathIndividualMeasurements(const QString &value);
|
void SetPathIndividualMeasurements(const QString &value);
|
||||||
|
|
||||||
|
@ -133,6 +136,7 @@ private:
|
||||||
static const QString SettingConfigurationLocale;
|
static const QString SettingConfigurationLocale;
|
||||||
static const QString SettingConfigurationUnit;
|
static const QString SettingConfigurationUnit;
|
||||||
static const QString SettingConfigurationLabelLanguage;
|
static const QString SettingConfigurationLabelLanguage;
|
||||||
|
static const QString SettingConfigurationConfirmItemDeletion;
|
||||||
|
|
||||||
static const QString SettingPathsIndividualMeasurements;
|
static const QString SettingPathsIndividualMeasurements;
|
||||||
static const QString SettingPathsStandardMeasurements;
|
static const QString SettingPathsStandardMeasurements;
|
||||||
|
|
|
@ -51,11 +51,13 @@ ConfigurationPage::ConfigurationPage(QWidget *parent)
|
||||||
QGroupBox *saveGroup = SaveGroup();
|
QGroupBox *saveGroup = SaveGroup();
|
||||||
QGroupBox *langGroup = LangGroup();
|
QGroupBox *langGroup = LangGroup();
|
||||||
QGroupBox *sendGroup = SendGroup();
|
QGroupBox *sendGroup = SendGroup();
|
||||||
|
QGroupBox *drawGroup = DrawGroup();
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addWidget(saveGroup);
|
mainLayout->addWidget(saveGroup);
|
||||||
mainLayout->addWidget(langGroup);
|
mainLayout->addWidget(langGroup);
|
||||||
mainLayout->addWidget(sendGroup);
|
mainLayout->addWidget(sendGroup);
|
||||||
|
mainLayout->addWidget(drawGroup);
|
||||||
mainLayout->addStretch(1);
|
mainLayout->addStretch(1);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +75,7 @@ void ConfigurationPage::Apply()
|
||||||
|
|
||||||
qApp->getSettings()->SetOsSeparator(osOptionCheck->isChecked());
|
qApp->getSettings()->SetOsSeparator(osOptionCheck->isChecked());
|
||||||
qApp->getSettings()->SetSendReportState(sendReportCheck->isChecked());
|
qApp->getSettings()->SetSendReportState(sendReportCheck->isChecked());
|
||||||
|
qApp->getSettings()->SetConfirmItemDelete(askPointDeletionCheck->isChecked());
|
||||||
|
|
||||||
if (langChanged)
|
if (langChanged)
|
||||||
{
|
{
|
||||||
|
@ -271,6 +274,21 @@ QGroupBox *ConfigurationPage::SendGroup()
|
||||||
return sendGroup;
|
return sendGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QGroupBox *ConfigurationPage::DrawGroup()
|
||||||
|
{
|
||||||
|
QGroupBox *drawGroup = new QGroupBox(tr("Pattern Editing"));
|
||||||
|
|
||||||
|
askPointDeletionCheck = new QCheckBox(tr("Confirm item deletion"));
|
||||||
|
askPointDeletionCheck->setChecked(qApp->getSettings()->GetConfirmItemDelete());
|
||||||
|
|
||||||
|
QVBoxLayout *editLayout = new QVBoxLayout;
|
||||||
|
editLayout->addWidget(askPointDeletionCheck);
|
||||||
|
|
||||||
|
drawGroup->setLayout(editLayout);
|
||||||
|
return drawGroup;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void ConfigurationPage::SetLabelComboBox(const QStringList &list)
|
void ConfigurationPage::SetLabelComboBox(const QStringList &list)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,10 +59,12 @@ private:
|
||||||
bool unitChanged;
|
bool unitChanged;
|
||||||
bool labelLangChanged;
|
bool labelLangChanged;
|
||||||
QCheckBox *sendReportCheck;
|
QCheckBox *sendReportCheck;
|
||||||
|
QCheckBox *askPointDeletionCheck;
|
||||||
|
|
||||||
QGroupBox *SaveGroup();
|
QGroupBox *SaveGroup();
|
||||||
QGroupBox *LangGroup();
|
QGroupBox *LangGroup();
|
||||||
QGroupBox *SendGroup();
|
QGroupBox *SendGroup();
|
||||||
|
QGroupBox *DrawGroup();
|
||||||
void SetLabelComboBox(const QStringList &list);
|
void SetLabelComboBox(const QStringList &list);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ void VToolSinglePoint::DeleteTool(bool ask)
|
||||||
qApp->getSceneView()->itemClicked(nullptr);
|
qApp->getSceneView()->itemClicked(nullptr);
|
||||||
if (ask)
|
if (ask)
|
||||||
{
|
{
|
||||||
if (ConfirmDeletion() == QMessageBox::Cancel)
|
if (ConfirmDeletion() == QMessageBox::No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,15 @@
|
||||||
|
|
||||||
#include "vabstracttool.h"
|
#include "vabstracttool.h"
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QMessageBox>
|
#include <QStyle>
|
||||||
|
#include <QtCore/qmath.h>
|
||||||
|
#include "checkablemessagebox.h"
|
||||||
#include "../undocommands/deltool.h"
|
#include "../undocommands/deltool.h"
|
||||||
#include "../core/vapplication.h"
|
#include "../core/vapplication.h"
|
||||||
#include "../geometry/vpointf.h"
|
#include "../geometry/vpointf.h"
|
||||||
#include "../undocommands/savetooloptions.h"
|
#include "../undocommands/savetooloptions.h"
|
||||||
#include "../widgets/vmaingraphicsview.h"
|
#include "../widgets/vmaingraphicsview.h"
|
||||||
#include <QtCore/qmath.h>
|
#include "../core/vsettings.h"
|
||||||
|
|
||||||
const QString VAbstractTool::AttrType = QStringLiteral("type");
|
const QString VAbstractTool::AttrType = QStringLiteral("type");
|
||||||
const QString VAbstractTool::AttrMx = QStringLiteral("mx");
|
const QString VAbstractTool::AttrMx = QStringLiteral("mx");
|
||||||
|
@ -154,7 +156,7 @@ void VAbstractTool::DeleteTool(bool ask)
|
||||||
qApp->getSceneView()->itemClicked(nullptr);
|
qApp->getSceneView()->itemClicked(nullptr);
|
||||||
if (ask)
|
if (ask)
|
||||||
{
|
{
|
||||||
if (ConfirmDeletion() == QMessageBox::Cancel)
|
if (ConfirmDeletion() == QMessageBox::No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -165,6 +167,27 @@ void VAbstractTool::DeleteTool(bool ask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VAbstractTool::ConfirmDeletion()
|
||||||
|
{
|
||||||
|
if (false == qApp->getSettings()->GetConfirmItemDelete())
|
||||||
|
return QMessageBox::Yes;
|
||||||
|
|
||||||
|
Utils::CheckableMessageBox msgBox(qApp->getMainWindow());
|
||||||
|
msgBox.setWindowTitle(tr("Confirm deletion"));
|
||||||
|
msgBox.setText(tr("Do you really want to delete?"));
|
||||||
|
msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
|
||||||
|
msgBox.setDefaultButton(QDialogButtonBox::No);
|
||||||
|
msgBox.setIconPixmap(qApp->style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32,32) );
|
||||||
|
|
||||||
|
int dialogResult = msgBox.exec();
|
||||||
|
|
||||||
|
if (dialogResult == QDialog::Accepted)
|
||||||
|
qApp->getSettings()->SetConfirmItemDelete(not msgBox.isChecked());
|
||||||
|
|
||||||
|
return dialogResult == QDialog::Accepted ? QMessageBox::Yes : QMessageBox::No;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief LineStyle return pen style for current line style.
|
* @brief LineStyle return pen style for current line style.
|
||||||
|
@ -294,18 +317,6 @@ QMap<QString, quint32> VAbstractTool::PointsList() const
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
int VAbstractTool::ConfirmDeletion()
|
|
||||||
{
|
|
||||||
QMessageBox msgBox;
|
|
||||||
msgBox.setText(tr("Confirm the deletion."));
|
|
||||||
msgBox.setInformativeText(tr("Do you really want delete?"));
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
||||||
msgBox.setIcon(QMessageBox::Question);
|
|
||||||
return msgBox.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VAbstractTool::SaveOption(QSharedPointer<VGObject> &obj)
|
void VAbstractTool::SaveOption(QSharedPointer<VGObject> &obj)
|
||||||
{
|
{
|
||||||
|
|
|
@ -522,7 +522,7 @@ void VToolDetail::DeleteTool(bool ask)
|
||||||
DeleteDetail *delDet = new DeleteDetail(doc, id);
|
DeleteDetail *delDet = new DeleteDetail(doc, id);
|
||||||
if (ask)
|
if (ask)
|
||||||
{
|
{
|
||||||
if (ConfirmDeletion() == QMessageBox::Cancel)
|
if (ConfirmDeletion() == QMessageBox::No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
441
src/libs/vpropertyexplorer/checkablemessagebox.cpp
Normal file
441
src/libs/vpropertyexplorer/checkablemessagebox.cpp
Normal file
|
@ -0,0 +1,441 @@
|
||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
** Modified work Copyright 2015 Felix Ulber <felix.ulber(at)gmx.de>
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://www.qt.io/licensing. For further information
|
||||||
|
** use the contact form at http://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 or version 3 as published by the Free
|
||||||
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||||
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||||
|
** following information to ensure the GNU Lesser General Public License
|
||||||
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "checkablemessagebox.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\class Utils::CheckableMessageBox
|
||||||
|
|
||||||
|
\brief The CheckableMessageBox class implements a message box suitable for
|
||||||
|
questions with a
|
||||||
|
"Do not ask me again" checkbox.
|
||||||
|
|
||||||
|
Emulates the QMessageBox API with
|
||||||
|
static conveniences. The message label can open external URLs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const char kDoNotAskAgainKey[] = "DoNotAskAgain";
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
class CheckableMessageBoxPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CheckableMessageBoxPrivate(QDialog *q)
|
||||||
|
: clickedButton(0)
|
||||||
|
{
|
||||||
|
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||||
|
|
||||||
|
pixmapLabel = new QLabel(q);
|
||||||
|
sizePolicy.setHorizontalStretch(0);
|
||||||
|
sizePolicy.setVerticalStretch(0);
|
||||||
|
sizePolicy.setHeightForWidth(pixmapLabel->sizePolicy().hasHeightForWidth());
|
||||||
|
pixmapLabel->setSizePolicy(sizePolicy);
|
||||||
|
pixmapLabel->setVisible(false);
|
||||||
|
|
||||||
|
QSpacerItem *pixmapSpacer =
|
||||||
|
new QSpacerItem(0, 5, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
||||||
|
|
||||||
|
messageLabel = new QLabel(q);
|
||||||
|
messageLabel->setMinimumSize(QSize(300, 0));
|
||||||
|
messageLabel->setWordWrap(true);
|
||||||
|
messageLabel->setOpenExternalLinks(true);
|
||||||
|
messageLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse);
|
||||||
|
|
||||||
|
QSpacerItem *checkBoxRightSpacer =
|
||||||
|
new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
|
QSpacerItem *buttonSpacer =
|
||||||
|
new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
|
||||||
|
checkBox = new QCheckBox(q);
|
||||||
|
checkBox->setText(CheckableMessageBox::tr("Do not ask again"));
|
||||||
|
|
||||||
|
buttonBox = new QDialogButtonBox(q);
|
||||||
|
buttonBox->setOrientation(Qt::Horizontal);
|
||||||
|
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||||
|
|
||||||
|
QVBoxLayout *verticalLayout = new QVBoxLayout();
|
||||||
|
verticalLayout->addWidget(pixmapLabel);
|
||||||
|
verticalLayout->addItem(pixmapSpacer);
|
||||||
|
|
||||||
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
||||||
|
horizontalLayout_2->addLayout(verticalLayout);
|
||||||
|
horizontalLayout_2->addWidget(messageLabel);
|
||||||
|
|
||||||
|
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
||||||
|
horizontalLayout->addWidget(checkBox);
|
||||||
|
horizontalLayout->addItem(checkBoxRightSpacer);
|
||||||
|
|
||||||
|
QVBoxLayout *verticalLayout_2 = new QVBoxLayout(q);
|
||||||
|
verticalLayout_2->addLayout(horizontalLayout_2);
|
||||||
|
verticalLayout_2->addLayout(horizontalLayout);
|
||||||
|
verticalLayout_2->addItem(buttonSpacer);
|
||||||
|
verticalLayout_2->addWidget(buttonBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *pixmapLabel;
|
||||||
|
QLabel *messageLabel;
|
||||||
|
QCheckBox *checkBox;
|
||||||
|
QDialogButtonBox *buttonBox;
|
||||||
|
QAbstractButton *clickedButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
d(new CheckableMessageBoxPrivate(this))
|
||||||
|
{
|
||||||
|
setModal(true);
|
||||||
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
|
connect(d->buttonBox, SIGNAL(accepted()), SLOT(accept()));
|
||||||
|
connect(d->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
||||||
|
connect(d->buttonBox, SIGNAL(clicked(QAbstractButton*)),
|
||||||
|
SLOT(slotClicked(QAbstractButton*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckableMessageBox::~CheckableMessageBox()
|
||||||
|
{
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::slotClicked(QAbstractButton *b)
|
||||||
|
{
|
||||||
|
d->clickedButton = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAbstractButton *CheckableMessageBox::clickedButton() const
|
||||||
|
{
|
||||||
|
return d->clickedButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButton CheckableMessageBox::clickedStandardButton() const
|
||||||
|
{
|
||||||
|
if (d->clickedButton)
|
||||||
|
return d->buttonBox->standardButton(d->clickedButton);
|
||||||
|
return QDialogButtonBox::NoButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CheckableMessageBox::text() const
|
||||||
|
{
|
||||||
|
return d->messageLabel->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setText(const QString &t)
|
||||||
|
{
|
||||||
|
d->messageLabel->setText(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap CheckableMessageBox::iconPixmap() const
|
||||||
|
{
|
||||||
|
if (const QPixmap *p = d->pixmapLabel->pixmap())
|
||||||
|
return QPixmap(*p);
|
||||||
|
return QPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
|
||||||
|
{
|
||||||
|
d->pixmapLabel->setPixmap(p);
|
||||||
|
d->pixmapLabel->setVisible(!p.isNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckableMessageBox::isChecked() const
|
||||||
|
{
|
||||||
|
return d->checkBox->isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setChecked(bool s)
|
||||||
|
{
|
||||||
|
d->checkBox->setChecked(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CheckableMessageBox::checkBoxText() const
|
||||||
|
{
|
||||||
|
return d->checkBox->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setCheckBoxText(const QString &t)
|
||||||
|
{
|
||||||
|
d->checkBox->setText(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckableMessageBox::isCheckBoxVisible() const
|
||||||
|
{
|
||||||
|
return d->checkBox->isVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setCheckBoxVisible(bool v)
|
||||||
|
{
|
||||||
|
d->checkBox->setVisible(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButtons CheckableMessageBox::standardButtons() const
|
||||||
|
{
|
||||||
|
return d->buttonBox->standardButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s)
|
||||||
|
{
|
||||||
|
d->buttonBox->setStandardButtons(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton *CheckableMessageBox::button(QDialogButtonBox::StandardButton b) const
|
||||||
|
{
|
||||||
|
return d->buttonBox->button(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton *CheckableMessageBox::addButton(const QString &text, QDialogButtonBox::ButtonRole role)
|
||||||
|
{
|
||||||
|
return d->buttonBox->addButton(text, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButton CheckableMessageBox::defaultButton() const
|
||||||
|
{
|
||||||
|
foreach (QAbstractButton *b, d->buttonBox->buttons())
|
||||||
|
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
|
||||||
|
if (pb->isDefault())
|
||||||
|
return d->buttonBox->standardButton(pb);
|
||||||
|
return QDialogButtonBox::NoButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s)
|
||||||
|
{
|
||||||
|
if (QPushButton *b = d->buttonBox->button(s)) {
|
||||||
|
b->setDefault(true);
|
||||||
|
b->setFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButton
|
||||||
|
CheckableMessageBox::question(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &question,
|
||||||
|
const QString &checkBoxText,
|
||||||
|
bool *checkBoxSetting,
|
||||||
|
QDialogButtonBox::StandardButtons buttons,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton)
|
||||||
|
{
|
||||||
|
CheckableMessageBox mb(parent);
|
||||||
|
mb.setWindowTitle(title);
|
||||||
|
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
||||||
|
mb.setText(question);
|
||||||
|
mb.setCheckBoxText(checkBoxText);
|
||||||
|
mb.setChecked(*checkBoxSetting);
|
||||||
|
mb.setStandardButtons(buttons);
|
||||||
|
mb.setDefaultButton(defaultButton);
|
||||||
|
mb.exec();
|
||||||
|
*checkBoxSetting = mb.isChecked();
|
||||||
|
return mb.clickedStandardButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButton
|
||||||
|
CheckableMessageBox::information(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &text,
|
||||||
|
const QString &checkBoxText,
|
||||||
|
bool *checkBoxSetting,
|
||||||
|
QDialogButtonBox::StandardButtons buttons,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton)
|
||||||
|
{
|
||||||
|
CheckableMessageBox mb(parent);
|
||||||
|
mb.setWindowTitle(title);
|
||||||
|
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Information));
|
||||||
|
mb.setText(text);
|
||||||
|
mb.setCheckBoxText(checkBoxText);
|
||||||
|
mb.setChecked(*checkBoxSetting);
|
||||||
|
mb.setStandardButtons(buttons);
|
||||||
|
mb.setDefaultButton(defaultButton);
|
||||||
|
mb.exec();
|
||||||
|
*checkBoxSetting = mb.isChecked();
|
||||||
|
return mb.clickedStandardButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db)
|
||||||
|
{
|
||||||
|
return static_cast<QMessageBox::StandardButton>(int(db));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool askAgain(QSettings *settings, const QString &settingsSubKey)
|
||||||
|
{
|
||||||
|
//QTC_CHECK(settings);
|
||||||
|
if (settings) {
|
||||||
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
|
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
||||||
|
settings->endGroup();
|
||||||
|
if (shouldNotAsk)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DoNotAskAgainType{Question, Information};
|
||||||
|
|
||||||
|
void initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString &title,
|
||||||
|
const QString &text, QDialogButtonBox::StandardButtons buttons,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton,
|
||||||
|
DoNotAskAgainType type)
|
||||||
|
{
|
||||||
|
messageBox.setWindowTitle(title);
|
||||||
|
messageBox.setIconPixmap(QMessageBox::standardIcon(type == Information
|
||||||
|
? QMessageBox::Information
|
||||||
|
: QMessageBox::Question));
|
||||||
|
messageBox.setText(text);
|
||||||
|
messageBox.setCheckBoxVisible(true);
|
||||||
|
messageBox.setCheckBoxText(type == Information ? CheckableMessageBox::msgDoNotShowAgain()
|
||||||
|
: CheckableMessageBox::msgDoNotAskAgain());
|
||||||
|
messageBox.setChecked(false);
|
||||||
|
messageBox.setStandardButtons(buttons);
|
||||||
|
messageBox.setDefaultButton(defaultButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doNotAskAgain(QSettings *settings, const QString &settingsSubKey)
|
||||||
|
{
|
||||||
|
if (!settings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
|
settings->setValue(settingsSubKey, true);
|
||||||
|
settings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Shows a message box with given \a title and \a text, and a \gui {Do not ask again} check box.
|
||||||
|
If the user checks the check box and accepts the dialog with the \a acceptButton,
|
||||||
|
further invocations of this function with the same \a settings and \a settingsSubKey will not
|
||||||
|
show the dialog, but instantly return \a acceptButton.
|
||||||
|
|
||||||
|
Returns the clicked button, or QDialogButtonBox::NoButton if the user rejects the dialog
|
||||||
|
with the escape key, or \a acceptButton if the dialog is suppressed.
|
||||||
|
*/
|
||||||
|
QDialogButtonBox::StandardButton
|
||||||
|
CheckableMessageBox::doNotAskAgainQuestion(QWidget *parent, const QString &title,
|
||||||
|
const QString &text, QSettings *settings,
|
||||||
|
const QString &settingsSubKey,
|
||||||
|
QDialogButtonBox::StandardButtons buttons,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton,
|
||||||
|
QDialogButtonBox::StandardButton acceptButton)
|
||||||
|
|
||||||
|
{
|
||||||
|
if (!askAgain(settings, settingsSubKey))
|
||||||
|
return acceptButton;
|
||||||
|
|
||||||
|
CheckableMessageBox messageBox(parent);
|
||||||
|
initDoNotAskAgainMessageBox(messageBox, title, text, buttons, defaultButton, Question);
|
||||||
|
messageBox.exec();
|
||||||
|
if (messageBox.isChecked() && (messageBox.clickedStandardButton() == acceptButton))
|
||||||
|
doNotAskAgain(settings, settingsSubKey);
|
||||||
|
|
||||||
|
return messageBox.clickedStandardButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Shows a message box with given \a title and \a text, and a \gui {Do not show again} check box.
|
||||||
|
If the user checks the check box and quits the dialog, further invocations of this
|
||||||
|
function with the same \a settings and \a settingsSubKey will not show the dialog, but instantly return.
|
||||||
|
|
||||||
|
Returns the clicked button, or QDialogButtonBox::NoButton if the user rejects the dialog
|
||||||
|
with the escape key, or \a defaultButton if the dialog is suppressed.
|
||||||
|
*/
|
||||||
|
QDialogButtonBox::StandardButton
|
||||||
|
CheckableMessageBox::doNotShowAgainInformation(QWidget *parent, const QString &title,
|
||||||
|
const QString &text, QSettings *settings,
|
||||||
|
const QString &settingsSubKey,
|
||||||
|
QDialogButtonBox::StandardButtons buttons,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton)
|
||||||
|
|
||||||
|
{
|
||||||
|
if (!askAgain(settings, settingsSubKey))
|
||||||
|
return defaultButton;
|
||||||
|
|
||||||
|
CheckableMessageBox messageBox(parent);
|
||||||
|
initDoNotAskAgainMessageBox(messageBox, title, text, buttons, defaultButton, Information);
|
||||||
|
messageBox.exec();
|
||||||
|
if (messageBox.isChecked())
|
||||||
|
doNotAskAgain(settings, settingsSubKey);
|
||||||
|
|
||||||
|
return messageBox.clickedStandardButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Resets all suppression settings for doNotAskAgainQuestion() found in \a settings,
|
||||||
|
so all these message boxes are shown again.
|
||||||
|
*/
|
||||||
|
void CheckableMessageBox::resetAllDoNotAskAgainQuestions(QSettings *settings)
|
||||||
|
{
|
||||||
|
//Q_ASSERT(settings, return);
|
||||||
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
|
settings->remove(QString());
|
||||||
|
settings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns whether any message boxes from doNotAskAgainQuestion() are suppressed
|
||||||
|
in the \a settings.
|
||||||
|
*/
|
||||||
|
bool CheckableMessageBox::hasSuppressedQuestions(QSettings *settings)
|
||||||
|
{
|
||||||
|
//Q_ASSERT(settings, return false);
|
||||||
|
bool hasSuppressed = false;
|
||||||
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
||||||
|
foreach (const QString &subKey, settings->childKeys()) {
|
||||||
|
if (settings->value(subKey, false).toBool()) {
|
||||||
|
hasSuppressed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings->endGroup();
|
||||||
|
return hasSuppressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the standard \gui {Do not ask again} check box text.
|
||||||
|
\sa doNotAskAgainQuestion()
|
||||||
|
*/
|
||||||
|
QString CheckableMessageBox::msgDoNotAskAgain()
|
||||||
|
{
|
||||||
|
return QApplication::translate("Utils::CheckableMessageBox", "Do not &ask again");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the standard \gui {Do not show again} check box text.
|
||||||
|
\sa doNotShowAgainInformation()
|
||||||
|
*/
|
||||||
|
QString CheckableMessageBox::msgDoNotShowAgain()
|
||||||
|
{
|
||||||
|
return QApplication::translate("Utils::CheckableMessageBox", "Do not &show again");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Utils
|
141
src/libs/vpropertyexplorer/checkablemessagebox.h
Normal file
141
src/libs/vpropertyexplorer/checkablemessagebox.h
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
** Modified work Copyright 2015 Felix Ulber <felix.ulber(at)gmx.de>
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://www.qt.io/licensing. For further information
|
||||||
|
** use the contact form at http://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 or version 3 as published by the Free
|
||||||
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||||
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||||
|
** following information to ensure the GNU Lesser General Public License
|
||||||
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CHECKABLEMESSAGEBOX_H
|
||||||
|
#define CHECKABLEMESSAGEBOX_H
|
||||||
|
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QSettings;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
class CheckableMessageBoxPrivate;
|
||||||
|
|
||||||
|
class Q_DECL_EXPORT CheckableMessageBox : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString text READ text WRITE setText)
|
||||||
|
Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
|
||||||
|
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
|
||||||
|
Q_PROPERTY(QString checkBoxText READ checkBoxText WRITE setCheckBoxText)
|
||||||
|
Q_PROPERTY(QDialogButtonBox::StandardButtons buttons READ standardButtons WRITE setStandardButtons)
|
||||||
|
Q_PROPERTY(QDialogButtonBox::StandardButton defaultButton READ defaultButton WRITE setDefaultButton)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CheckableMessageBox(QWidget *parent);
|
||||||
|
virtual ~CheckableMessageBox();
|
||||||
|
|
||||||
|
static QDialogButtonBox::StandardButton
|
||||||
|
question(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &question,
|
||||||
|
const QString &checkBoxText,
|
||||||
|
bool *checkBoxSetting,
|
||||||
|
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No);
|
||||||
|
|
||||||
|
static QDialogButtonBox::StandardButton
|
||||||
|
information(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &text,
|
||||||
|
const QString &checkBoxText,
|
||||||
|
bool *checkBoxSetting,
|
||||||
|
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton);
|
||||||
|
|
||||||
|
static QDialogButtonBox::StandardButton
|
||||||
|
doNotAskAgainQuestion(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &text,
|
||||||
|
QSettings *settings,
|
||||||
|
const QString &settingsSubKey,
|
||||||
|
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No,
|
||||||
|
QDialogButtonBox::StandardButton acceptButton = QDialogButtonBox::Yes);
|
||||||
|
|
||||||
|
static QDialogButtonBox::StandardButton
|
||||||
|
doNotShowAgainInformation(QWidget *parent,
|
||||||
|
const QString &title,
|
||||||
|
const QString &text,
|
||||||
|
QSettings *settings,
|
||||||
|
const QString &settingsSubKey,
|
||||||
|
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
|
||||||
|
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton);
|
||||||
|
|
||||||
|
QString text() const;
|
||||||
|
void setText(const QString &);
|
||||||
|
|
||||||
|
bool isChecked() const;
|
||||||
|
void setChecked(bool s);
|
||||||
|
|
||||||
|
QString checkBoxText() const;
|
||||||
|
void setCheckBoxText(const QString &);
|
||||||
|
|
||||||
|
bool isCheckBoxVisible() const;
|
||||||
|
void setCheckBoxVisible(bool);
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButtons standardButtons() const;
|
||||||
|
void setStandardButtons(QDialogButtonBox::StandardButtons s);
|
||||||
|
QPushButton *button(QDialogButtonBox::StandardButton b) const;
|
||||||
|
QPushButton *addButton(const QString &text, QDialogButtonBox::ButtonRole role);
|
||||||
|
|
||||||
|
QDialogButtonBox::StandardButton defaultButton() const;
|
||||||
|
void setDefaultButton(QDialogButtonBox::StandardButton s);
|
||||||
|
|
||||||
|
// See static QMessageBox::standardPixmap()
|
||||||
|
QPixmap iconPixmap() const;
|
||||||
|
void setIconPixmap (const QPixmap &p);
|
||||||
|
|
||||||
|
// Query the result
|
||||||
|
QAbstractButton *clickedButton() const;
|
||||||
|
QDialogButtonBox::StandardButton clickedStandardButton() const;
|
||||||
|
|
||||||
|
// Conversion convenience
|
||||||
|
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
|
||||||
|
static void resetAllDoNotAskAgainQuestions(QSettings *settings);
|
||||||
|
static bool hasSuppressedQuestions(QSettings *settings);
|
||||||
|
static QString msgDoNotAskAgain();
|
||||||
|
static QString msgDoNotShowAgain();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slotClicked(QAbstractButton *b);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CheckableMessageBoxPrivate *d;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
|
||||||
|
#endif // CHECKABLEMESSAGEBOX_H
|
|
@ -29,7 +29,8 @@ SOURCES += \
|
||||||
$$PWD/plugins/vobjectproperty.cpp \
|
$$PWD/plugins/vobjectproperty.cpp \
|
||||||
$$PWD/stable.cpp \
|
$$PWD/stable.cpp \
|
||||||
$$PWD/plugins/vlinetypeproperty.cpp \
|
$$PWD/plugins/vlinetypeproperty.cpp \
|
||||||
$$PWD/plugins/vlinecolorproperty.cpp
|
$$PWD/plugins/vlinecolorproperty.cpp \
|
||||||
|
$$PWD/checkablemessagebox.cpp
|
||||||
|
|
||||||
HEADERS +=\
|
HEADERS +=\
|
||||||
$$PWD/vpropertyexplorer_global.h \
|
$$PWD/vpropertyexplorer_global.h \
|
||||||
|
@ -71,4 +72,5 @@ HEADERS +=\
|
||||||
$$PWD/vproperties.h \
|
$$PWD/vproperties.h \
|
||||||
$$PWD/stable.h \
|
$$PWD/stable.h \
|
||||||
$$PWD/plugins/vlinetypeproperty.h \
|
$$PWD/plugins/vlinetypeproperty.h \
|
||||||
$$PWD/plugins/vlinecolorproperty.h
|
$$PWD/plugins/vlinecolorproperty.h \
|
||||||
|
$$PWD/checkablemessagebox.h
|
||||||
|
|
Loading…
Reference in New Issue
Block a user