diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 26d9d46a4..765623134 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -199,6 +199,7 @@ set(Gui_MOC_HDRS DlgSettingsMacroImp.h DlgSettingsUnitsImp.h DlgTipOfTheDayImp.h + DlgCheckableMessageBox.h DlgToolbarsImp.h DlgWorkbenchesImp.h TaskDlgRelocation.h @@ -305,6 +306,7 @@ SET(Gui_UIC_SRCS DlgSettingsDocument.ui DlgSettingsImage.ui DlgSettingsMacro.ui + DlgCheckableMessageBox.ui DlgTipOfTheDay.ui DlgToolbars.ui DlgWorkbenches.ui @@ -376,6 +378,7 @@ SET(Dialog_CPP_SRCS DlgTipOfTheDayImp.cpp DlgExpressionInput.cpp TaskDlgRelocation.cpp + DlgCheckableMessageBox.cpp DlgUndoRedo.cpp InputVector.cpp Placement.cpp @@ -405,6 +408,7 @@ SET(Dialog_HPP_SRCS DlgProjectInformationImp.h DlgProjectUtility.h DlgPropertyLink.h + DlgCheckableMessageBox.h DlgTipOfTheDayImp.h DlgExpressionInput.h TaskDlgRelocation.h @@ -443,6 +447,7 @@ SET(Dialog_SRCS DlgProjectUtility.ui DlgPropertyLink.ui DlgTipOfTheDay.ui + DlgCheckableMessageBox.ui DlgTreeWidget.ui DlgExpressionInput.ui DownloadManager.ui diff --git a/src/Gui/DlgCheckableMessageBox.cpp b/src/Gui/DlgCheckableMessageBox.cpp new file mode 100644 index 000000000..5dbba1f9d --- /dev/null +++ b/src/Gui/DlgCheckableMessageBox.cpp @@ -0,0 +1,239 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include "DlgCheckableMessageBox.h" +#include "ui_DlgCheckableMessageBox.h" + +#include +#include + +#include "MainWindow.h" + +#include +//#include + + +namespace Gui { +namespace Dialog { +QByteArray toParamEntry(QString name) +{ + QString tmp = QString::fromLatin1(name.toLatin1()); + name.replace(QString::fromLatin1(" "),QString::fromLatin1("_")); + return name.toLatin1(); +} + +void DlgCheckableMessageBox::showMessage(QString header, QString message, bool check,QString checkText ) +{ + bool checked = App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->GetBool(toParamEntry(header)); + + if(!checked){ + DlgCheckableMessageBox *mb = new DlgCheckableMessageBox(Gui::getMainWindow()); + mb->setWindowTitle(header); + mb->setIconPixmap(QMessageBox::standardIcon(QMessageBox::Warning)); + mb->setText(message); + mb->setPrefEntry(header); + mb->setCheckBoxText(checkText); + mb->setChecked(check); + mb->setStandardButtons(QDialogButtonBox::Ok); + mb->setDefaultButton(QDialogButtonBox::Ok); + mb->show(); + } +} + + +struct DlgCheckableMessageBoxPrivate { + DlgCheckableMessageBoxPrivate() : clickedButton(0) {} + + Ui::DlgCheckableMessageBox ui; + QAbstractButton *clickedButton; +}; + +DlgCheckableMessageBox::DlgCheckableMessageBox(QWidget *parent) : + QDialog(parent), + m_d(new DlgCheckableMessageBoxPrivate) +{ + setModal(true); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + m_d->ui.setupUi(this); + m_d->ui.pixmapLabel->setVisible(false); + connect(m_d->ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(m_d->ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(m_d->ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotClicked(QAbstractButton*))); +} + +DlgCheckableMessageBox::~DlgCheckableMessageBox() +{ + delete m_d; +} + +void DlgCheckableMessageBox::setPrefEntry( const QString& entry ) +{ + paramEntry = toParamEntry(entry); + bool checked = App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->GetBool(paramEntry); + setChecked(checked); +} + + +void DlgCheckableMessageBox::slotClicked(QAbstractButton *b) +{ + m_d->clickedButton = b; +} + +QAbstractButton *DlgCheckableMessageBox::clickedButton() const +{ + return m_d->clickedButton; +} + +QDialogButtonBox::StandardButton DlgCheckableMessageBox::clickedStandardButton() const +{ + if (m_d->clickedButton) + return m_d->ui.buttonBox->standardButton(m_d->clickedButton); + return QDialogButtonBox::NoButton; +} + +QString DlgCheckableMessageBox::text() const +{ + return m_d->ui.messageLabel->text(); +} + +void DlgCheckableMessageBox::setText(const QString &t) +{ + m_d->ui.messageLabel->setText(t); +} + +QPixmap DlgCheckableMessageBox::iconPixmap() const +{ + if (const QPixmap *p = m_d->ui.pixmapLabel->pixmap()) + return QPixmap(*p); + return QPixmap(); +} + +void DlgCheckableMessageBox::setIconPixmap(const QPixmap &p) +{ + m_d->ui.pixmapLabel->setPixmap(p); + m_d->ui.pixmapLabel->setVisible(!p.isNull()); +} + +bool DlgCheckableMessageBox::isChecked() const +{ + return m_d->ui.checkBox->isChecked(); +} + +void DlgCheckableMessageBox::setChecked(bool s) +{ + m_d->ui.checkBox->setChecked(s); +} + +QString DlgCheckableMessageBox::checkBoxText() const +{ + return m_d->ui.checkBox->text(); +} + +void DlgCheckableMessageBox::setCheckBoxText(const QString &t) +{ + m_d->ui.checkBox->setText(t); +} + +QDialogButtonBox::StandardButtons DlgCheckableMessageBox::standardButtons() const +{ + return m_d->ui.buttonBox->standardButtons(); +} + +void DlgCheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s) +{ + m_d->ui.buttonBox->setStandardButtons(s); +} + +QDialogButtonBox::StandardButton DlgCheckableMessageBox::defaultButton() const +{ + Q_FOREACH (QAbstractButton *b, m_d->ui.buttonBox->buttons()) + if (QPushButton *pb = qobject_cast(b)) + if (pb->isDefault()) + return m_d->ui.buttonBox->standardButton(pb); + return QDialogButtonBox::NoButton; +} + +void DlgCheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s) +{ + if (QPushButton *b = m_d->ui.buttonBox->button(s)) { + b->setDefault(true); + b->setFocus(); + } +} + +void DlgCheckableMessageBox::accept() +{ + if(!paramEntry.isEmpty()) + App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->SetBool(paramEntry,isChecked()); + QDialog::accept(); +} + +void DlgCheckableMessageBox::reject() +{ + if(!paramEntry.isEmpty()) + App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/CheckMessages"))->SetBool(paramEntry,isChecked()); + QDialog::reject(); +} + +QDialogButtonBox::StandardButton + DlgCheckableMessageBox::question(QWidget *parent, + const QString &title, + const QString &question, + const QString &checkBoxText, + bool *checkBoxSetting, + QDialogButtonBox::StandardButtons buttons, + QDialogButtonBox::StandardButton defaultButton) +{ + DlgCheckableMessageBox 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(); +} + +QMessageBox::StandardButton DlgCheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db) +{ + return static_cast(int(db)); +} + +} // namespace Dialog +} // namespace Gui + +#include "moc_DlgCheckableMessageBox.cpp" \ No newline at end of file diff --git a/src/Gui/DlgCheckableMessageBox.h b/src/Gui/DlgCheckableMessageBox.h new file mode 100644 index 000000000..9c42a2a28 --- /dev/null +++ b/src/Gui/DlgCheckableMessageBox.h @@ -0,0 +1,116 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef CHECKABLEMESSAGEBOX_H +#define CHECKABLEMESSAGEBOX_H + +//#include "utils_global.h" + +#include +#include +#include + +namespace Gui { +namespace Dialog { + +struct DlgCheckableMessageBoxPrivate; + +/* A messagebox suitable for questions with a + * "Do not ask me again" checkbox. Emulates the QMessageBox API with + * static conveniences. */ + +class GuiExport DlgCheckableMessageBox : 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 prefEntry WRITE setPrefEntry) + 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 DlgCheckableMessageBox(QWidget *parent); + virtual ~DlgCheckableMessageBox(); + + 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); + + QString text() const; + void setText(const QString &); + + void setPrefEntry( const QString& entry ); + + virtual void accept(); + virtual void reject(); + + bool isChecked() const; + void setChecked(bool s); + + QString checkBoxText() const; + void setCheckBoxText(const QString &); + + QDialogButtonBox::StandardButtons standardButtons() const; + void setStandardButtons(QDialogButtonBox::StandardButtons s); + + 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); + + // conviniant show method + static void showMessage(QString haeder, QString message, bool check=false,QString checkText = QString::fromLatin1("Don't show me again")); + +private Q_SLOTS: + void slotClicked(QAbstractButton *b); + +private: + DlgCheckableMessageBoxPrivate *m_d; + QByteArray paramEntry; +}; + +} // namespace Dialog +} // namespace Gui + +#endif // CHECKABLEMESSAGEBOX_H diff --git a/src/Gui/DlgCheckableMessageBox.ui b/src/Gui/DlgCheckableMessageBox.ui new file mode 100644 index 000000000..c918eeeca --- /dev/null +++ b/src/Gui/DlgCheckableMessageBox.ui @@ -0,0 +1,154 @@ + + + Gui::Dialog::DlgCheckableMessageBox + + + + 0 + 0 + 195 + 107 + + + + Dialog + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 0 + 5 + + + + + + + + + + TextLabel + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + CheckBox + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 0 + 5 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + + + buttonBox + accepted() + Utils::CheckableMessageBox + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Utils::CheckableMessageBox + reject() + + + 316 + 260 + + + 286 + 274 + + + + + \ No newline at end of file diff --git a/src/Mod/Assembly/Gui/Workbench.cpp b/src/Mod/Assembly/Gui/Workbench.cpp index 6e01dc1c0..2fde0237f 100644 --- a/src/Mod/Assembly/Gui/Workbench.cpp +++ b/src/Mod/Assembly/Gui/Workbench.cpp @@ -33,6 +33,8 @@ #include #include #include +#include + using namespace AssemblyGui; @@ -126,6 +128,22 @@ void Workbench::activated() doc = App::GetApplication().getActiveDocument(); } + // show a warning about the Alpha state of FreeCAD Assembly + Gui::Dialog::DlgCheckableMessageBox::showMessage( + QString::fromLatin1("Assembly warning"), + QString::fromLatin1( + "

The Assembly module of FreeCAD is in Alpha state!

" + "Use for testing purpose only! The object structure is still changing.
" + "You might not be able to load your work in a newer Version of FreeCAD.

" + "For further information see the Assembly project page:
" + " http://www.freecadweb.org/wiki/index.php?title=Assembly_project
" + "Or the Assembly dedicated portion of our forum:
" + " http://forum.freecadweb.org/
" + ), + false, + QString::fromLatin1("Don't tell me again, I know the risk!") + ); + // now we should have a document! assert(doc);