Commit 4019af4f authored by Stan Hammon's avatar Stan Hammon Committed by Kitware Robot
Browse files

Merge topic 'qtMessageDialog'

75e86d5a Changed pqNerscLoginBehavior::onLoginComplete() dialog to qtProgressDialog
194db38d Added dialogs that warn the user when a remote server is about to timeout
bbe0d74c

 Added qtMessageDialog - a class that adds a auto-close timer to QMessageBox
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Merge-request: !76
parents cb59c486 75e86d5a
......@@ -16,7 +16,6 @@
#include "pqCoreUtilities.h"
#include <QDebug>
#include <QMessageBox>
//-----------------------------------------------------------------------------
pqACE3PJobsReaction::pqACE3PJobsReaction(QAction* parentObject)
......
......@@ -28,7 +28,6 @@
#include <QDebug>
#include <QDialog>
#include <QDir>
#include <QMessageBox>
//-----------------------------------------------------------------------------
pqACE3POpenReaction::pqACE3POpenReaction(QAction* parentObject)
......
......@@ -10,6 +10,7 @@
#include "pqACE3PRemoteParaViewBehavior.h"
#include "plugin/modelbuilder_cori_pvsc.h"
#include "smtk/simulation/ace3p/qt/qtMessageDialog.h"
#include "pqActiveObjects.h"
#include "pqApplicationCore.h"
......@@ -158,6 +159,23 @@ bool pqACE3PRemoteParaViewBehavior::startRemoteServer(const QString& machine)
// And disconnect until next time
QObject::disconnect(model, &pqServerManagerModel::serverAdded, this, nullptr);
// these connections notify user when the remote server is about to time out
QObject::connect(
server,
&pqServer::fiveMinuteTimeoutWarning,
this,
&pqACE3PRemoteParaViewBehavior::serverTimeoutIn5Mins);
QObject::connect(
server,
&pqServer::finalTimeoutWarning,
this,
&pqACE3PRemoteParaViewBehavior::serverTimeoutIn1Min);
QObject::connect(
server,
&pqServer::serverSideDisconnected,
this,
&pqACE3PRemoteParaViewBehavior::serverTimeout);
}
});
......@@ -170,3 +188,37 @@ bool pqACE3PRemoteParaViewBehavior::startRemoteServer(const QString& machine)
pqServerConnectReaction::connectToServerUsingConfiguration(config);
return true;
}
// warn user when the server connection is about to expire
void pqACE3PRemoteParaViewBehavior::serverTimeoutIn5Mins()
{
qtMessageDialog dialog(pqCoreUtilities::mainWidget());
dialog.setIcon(QMessageBox::Warning);
dialog.setWindowTitle("Remote Server Warning");
dialog.setText("The remote server connection will timeout in 5 mimutes.");
dialog.setAutoClose(true);
dialog.setAutoCloseDelay(15);
dialog.show();
}
// warn user when the server connection is about to expire
void pqACE3PRemoteParaViewBehavior::serverTimeoutIn1Min()
{
qtMessageDialog dialog(pqCoreUtilities::mainWidget());
dialog.setIcon(QMessageBox::Warning);
dialog.setWindowTitle("Remote Server Warning");
dialog.setText("The remote server connection will timeout in 1 mimute.");
dialog.setAutoClose(true);
dialog.setAutoCloseDelay(15);
dialog.show();
}
// notify user when the server connection has expired
void pqACE3PRemoteParaViewBehavior::serverTimeout()
{
qtMessageDialog dialog(pqCoreUtilities::mainWidget());
dialog.setIcon(QMessageBox::Critical);
dialog.setWindowTitle("Remote Server Disconnected");
dialog.setText("The remote server connection has timed out.");
dialog.show();
}
......@@ -68,6 +68,11 @@ protected:
// Store <machine, pqServer> dictionary
QMap<QString, pqServer*> m_serverMap;
private slots:
void serverTimeoutIn5Mins();
void serverTimeoutIn1Min();
void serverTimeout();
private:
Q_DISABLE_COPY(pqACE3PRemoteParaViewBehavior);
};
......
......@@ -15,7 +15,6 @@
#include "pqCoreUtilities.h"
#include <QDebug>
#include <QMessageBox>
#include <QStyle>
#include <QTimer>
......
......@@ -11,6 +11,7 @@
#include "smtk/newt/qtNewtInterface.h"
#include "smtk/newt/qtNewtLoginDialog.h"
#include "smtk/simulation/ace3p/qt/qtMessageDialog.h"
#include "pqCoreUtilities.h"
......@@ -171,7 +172,15 @@ void pqNerscLoginBehavior::onLoginComplete(const QString userName)
#if MOCK_LOGIN
#else
QWidget* parentWidget = pqCoreUtilities::mainWidget();
QMessageBox::information(parentWidget, "NERSC Login Complete", text);
// display auto-closing dialog
qtMessageDialog dialog(parentWidget);
dialog.setIcon(QMessageBox::Information);
dialog.setWindowTitle("NERSC Login Complete");
dialog.setText(text);
dialog.setAutoClose(true);
dialog.setAutoCloseDelay(5);
dialog.show();
#endif
QObject::disconnect(this);
......
......@@ -18,7 +18,6 @@
#include <QCommandLineParser>
#include <QDebug>
#include <QDialog>
#include <QMessageBox>
#include <QSslSocket>
#include <QStringList>
......
......@@ -10,6 +10,7 @@
#include "smtk/simulation/ace3p/examples/cxx/qtProgressDialogTestWidget.h"
#include "smtk/simulation/ace3p/qt/qtMessageDialog.h"
#include "smtk/simulation/ace3p/qt/qtProgressDialog.h"
#include "ui_qtProgressDialogTestWidget.h"
......@@ -137,6 +138,15 @@ void qtProgressDialogTestWidget::updateProgress()
}
}
void qtProgressDialogTestWidget::on_pushButton_MessageDialog_clicked()
{
qtMessageDialog* pMessageBox = new qtMessageDialog(this);
pMessageBox->setText("This an example autoclose dialog.");
pMessageBox->setAutoClose(this->ui->checkBox_AutoClose->isChecked());
pMessageBox->setAutoCloseDelay(this->ui->spinBox_CloseDelay->value());
pMessageBox->show();
}
} // namespace ace3p
} // namespace simulation
} // namespace smtk
......@@ -47,6 +47,7 @@ public:
private slots:
void on_pushButton_Start_clicked();
void on_pushButton_MessageDialog_clicked();
void updateProgress();
private:
......
......@@ -263,6 +263,19 @@
</property>
</item>
</widget>
<widget class="QPushButton" name="pushButton_MessageDialog">
<property name="geometry">
<rect>
<x>450</x>
<y>70</y>
<width>161</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>qtMessageDialog</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
......
......@@ -15,6 +15,7 @@ set(qt_sources
# qtCumulusJobTracker.cxx
qtJobsModel.cxx
qtJobsWidget.cxx
qtMessageDialog.cxx
qtModeSelectDialog.cxx
qtNerscFileItem.cxx
qtNewProjectMeshPage.cxx
......@@ -35,6 +36,7 @@ set(qt_headers
# qtCumulusJobTracker.h
qtJobsModel.h
qtJobsWidget.h
qtMessageDialog.h
qtModeSelectDialog.h
qtNerscFileItem.h
qtNewProjectMeshPage.h
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "qtMessageDialog.h"
#include <QAbstractButton>
#include <QApplication>
#include <QBuffer>
#include <QCommonStyle>
#include <QCoreApplication>
#include <QMutex>
#include <QProgressDialog>
#include <QTimer>
// minimal constructor
qtMessageDialog::qtMessageDialog(QWidget* parent)
: QMessageBox(parent)
{
initialize();
}
// constructor
qtMessageDialog::qtMessageDialog(
Icon icon,
const QString& title,
const QString& text,
StandardButtons buttons,
QWidget* parent,
Qt::WindowFlags flag)
: QMessageBox(icon, title, text, buttons, parent, flag)
{
initialize();
}
// common initialization
void qtMessageDialog::initialize()
{
setWindowTitle("Information");
m_autocloseTimer = new QTimer(this);
QObject::connect(
m_autocloseTimer, &QTimer::timeout, this, &qtMessageDialog::processAutoCloseTimer);
m_countdownButton = QMessageBox::Ok;
m_bAutoClose = false;
m_autoCloseDelay = 0;
}
// destructor
qtMessageDialog::~qtMessageDialog()
{
;
}
void qtMessageDialog::centerOnParent()
{
if (!parentWidget())
{
return;
}
int width = this->width();
int height = this->height();
int x = parentWidget()->pos().x() + parentWidget()->width() / 2 - width / 2;
int y = parentWidget()->pos().y() + parentWidget()->height() / 2 - height / 2;
this->setGeometry(x, y, width, height);
}
int qtMessageDialog::exec()
{
centerOnParent();
startAutocloseTimer();
return QMessageBox::exec();
}
void qtMessageDialog::show()
{
centerOnParent();
startAutocloseTimer();
QMessageBox::show();
}
void qtMessageDialog::startAutocloseTimer()
{
if (m_bAutoClose)
{
if (m_autoCloseDelay == 0)
{
this->close();
return;
}
if (this->buttons().size() == 0)
{
this->setStandardButtons(m_countdownButton);
}
m_remainingAutoCloseSeconds = m_autoCloseDelay;
QAbstractButton* button = this->button(m_countdownButton);
m_originalButtonText = button->text();
button->setText(QString("%1 (%2)").arg(m_originalButtonText).arg(m_remainingAutoCloseSeconds));
m_autocloseTimer->start(1000);
}
}
// sets the dialog to automatically close upon progress bar completion
void qtMessageDialog::setAutoClose(bool bAutoClose)
{
m_bAutoClose = bAutoClose;
}
// imposes a delay after the completion of a run, before auto-close is triggered
void qtMessageDialog::setAutoCloseDelay(uint delay)
{
m_autoCloseDelay = delay;
}
// process auto-close timer ticks
void qtMessageDialog::processAutoCloseTimer()
{
m_remainingAutoCloseSeconds -= 1;
if (m_remainingAutoCloseSeconds <= 0)
{
m_autocloseTimer->stop();
this->close();
}
else
{
QAbstractButton* button = this->button(m_countdownButton);
button->setText(QString("%1 (%2)").arg(m_originalButtonText).arg(m_remainingAutoCloseSeconds));
}
}
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef smtk_simulation_ace3p_qt_qtMessageDialog
#define smtk_simulation_ace3p_qt_qtMessageDialog
#include <QMessageBox>
#include <QMutex>
#include <QPixmap>
#include <QTime>
#include <QTimer>
#include "smtk/simulation/ace3p/qt/Exports.h"
/**
* \brief Message Dialog with more features than the standard QMessageBox.
* \details Message Dialog with more features than the standard QMessageBox, including:
* 1) auto-close feature upon completion (with or without a countdown delay)
* 2) imposing a minimum duration before auto-close to prevent "strobing" dialog on and
* rapidly off
*/
class SMTKACE3PQTEXT_EXPORT qtMessageDialog : public QMessageBox
{
Q_OBJECT
signals:
public slots:
public:
explicit qtMessageDialog(QWidget* parent = nullptr);
qtMessageDialog(
Icon icon,
const QString& title,
const QString& text,
StandardButtons buttons = NoButton,
QWidget* parent = nullptr,
Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
~qtMessageDialog();
/** \brief Displays the Message Dialog in a blocking role. */
int exec();
/** \brief Displays the Message Dialog in a non-blocking role. */
void show();
/** \brief Centers the Message Dialog on its parent window. */
void centerOnParent();
/** \brief Set whether the progress dialog automatically closes after some delay. */
void setAutoClose(bool bAutoClose);
/** \brief Specify the delay used when closing the Message Dialog (in seconds). */
void setAutoCloseDelay(uint delay);
/** \brief Specify which button will be used to show autoclose countdown. */
void setCountdownButton(StandardButton button) { m_countdownButton = button; }
private slots:
void processAutoCloseTimer();
private:
void initialize(); // common initialization
void startAutocloseTimer();
QTimer* m_autocloseTimer;
StandardButton m_countdownButton;
QString m_originalButtonText;
bool m_bAutoClose; // tracks if autoClose will be used
uint m_autoCloseDelay; // user-specified delay of closing after maxProgress has been reached
uint m_remainingAutoCloseSeconds; // keeps track of remaining seconds as timer ticks down
};
#endif // smtk_simulation_ace3p_qt_qtMessageDialog
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment