New Dialog for Quenstions and Warnings and the usage in Assembly

This commit is contained in:
jriegel 2014-02-02 14:46:45 +01:00 committed by Stefan Tröger
parent ad8ae753d9
commit a08fdaa648
5 changed files with 532 additions and 0 deletions

View File

@ -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

View File

@ -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 <QHeaderView>
#endif
#include "DlgCheckableMessageBox.h"
#include "ui_DlgCheckableMessageBox.h"
#include <QtGui/QPushButton>
#include <QtCore/QDebug>
#include "MainWindow.h"
#include <App/Application.h>
//#include <App/Parameter.h>
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<QPushButton *>(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<QMessageBox::StandardButton>(int(db));
}
} // namespace Dialog
} // namespace Gui
#include "moc_DlgCheckableMessageBox.cpp"

View File

@ -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 <QtGui/QDialogButtonBox>
#include <QtGui/QMessageBox>
#include <QtGui/QDialog>
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

View File

@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::DlgCheckableMessageBox</class>
<widget class="QDialog" name="Gui::Dialog::DlgCheckableMessageBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>195</width>
<height>107</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="pixmapLabel"/>
</item>
<item>
<spacer name="pixmapSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="checkBoxLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<spacer name="checkBoxRightSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="buttonSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Utils::CheckableMessageBox</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Utils::CheckableMessageBox</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -33,6 +33,8 @@
#include <Gui/ToolBarManager.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/DlgCheckableMessageBox.h>
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(
"<h2>The <b>Assembly</b> module of FreeCAD is in <b>Alpha state</b>! </h2>"
"Use for <b>testing purpose only!</b> The object structure is still changing.<br>"
"You might not be able to load your work in a newer Version of FreeCAD. <br><br>"
"For further information see the Assembly project page:<br>"
" <a href=\"http://www.freecadweb.org/wiki/index.php?title=Assembly_project\">http://www.freecadweb.org/wiki/index.php?title=Assembly_project</a> <br>"
"Or the Assembly dedicated portion of our forum:<br>"
" <a href=\"http://forum.freecadweb.org/viewforum.php?f=20&sid=2a1a326251c44576f450739e4a74c37d\">http://forum.freecadweb.org/</a> <br>"
),
false,
QString::fromLatin1("Don't tell me again, I know the risk!")
);
// now we should have a document!
assert(doc);