Adjustements to the ExceptionWidget behavior.

* Change: In Hurricane::ExceptionWidget,
    - Use a QTextLabel instead of a QLabel, make it "look like" a QLabel.
    - Always display using text mode. Not HTML (to preserve indentation).
    - Make the text of the error message selectable.
    - Make it resizable.
This commit is contained in:
Jean-Paul Chaput 2020-06-16 21:37:18 +02:00
parent 9c082230b5
commit 235a9eecea
2 changed files with 27 additions and 22 deletions

View File

@ -43,11 +43,11 @@ namespace Hurricane {
void ExceptionWidget::run ( Error& e )
{ run ( e.htmlWhat().c_str(), e.htmlWhere().c_str() ); }
{ run ( e.textWhat().c_str(), e.textWhere().c_str() ); }
void ExceptionWidget::run ( Exception& e )
{ run ( e.htmlWhat().c_str(), "" ); }
{ run ( e.textWhat().c_str(), "" ); }
void ExceptionWidget::run ( exception& e )
@ -107,7 +107,7 @@ namespace Hurricane {
ExceptionWidget::ExceptionWidget ( QWidget* parent )
: QDialog (parent)
, _header (new QLabel())
, _message (new QLabel())
, _message (new QTextEdit())
, _trace (new QTextEdit())
{
setAttribute ( Qt::WA_DeleteOnClose );
@ -119,9 +119,17 @@ namespace Hurricane {
_header->setTextFormat ( Qt::RichText );
_header->setText ( "<b>[ERROR]</b>" );
_message->setTextFormat ( Qt::RichText );
QString labelBackground = _header->palette().color( _header->backgroundRole() ).name();
//_message->setFrameStyle ( QFrame::NoFrame|QFrame::Plain );
_message->setStyleSheet ( QString("* { background-color: %1 }").arg(labelBackground) );
_message->setTextInteractionFlags( Qt::TextSelectableByMouse );
_message->setAcceptRichText ( false );
_message->setLineWrapMode ( QTextEdit::NoWrap );
_message->setWordWrapMode ( QTextOption::NoWrap );
_message->setMinimumSize ( Graphics::isHighDpi() ? QSize(2500,200) : QSize(800,100) );
//_message->setTextFormat ( Qt::RichText );
_message->setFont ( Graphics::getFixedFont(QFont::Normal,false,false) );
_message->setText ( "<b>Oups! I did it again!</b>" );
_message->setPlainText ( "Oups! I did it again!" );
_trace->setTextInteractionFlags ( Qt::TextBrowserInteraction );
_trace->setAcceptRichText ( true );
@ -172,7 +180,7 @@ namespace Hurricane {
vLayout1->addLayout ( hLayout2 , Qt::AlignCenter );
QHBoxLayout* hLayout1 = new QHBoxLayout ();
hLayout1->setSizeConstraint ( QLayout::SetFixedSize );
//hLayout1->setSizeConstraint ( QLayout::SetFixedSize );
hLayout1->setContentsMargins ( 0, 0, 0, 0 );
hLayout1->addWidget ( leftMargin );
hLayout1->addLayout ( vLayout1 );
@ -180,6 +188,7 @@ namespace Hurricane {
setLayout ( hLayout1 );
//setMinimumSize ( QSize(400,150) );
setSizePolicy ( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) );
setSizeGripEnabled( true );
connect ( contButton , SIGNAL(clicked()) , this, SLOT(accept()) );
connect ( abortButton, SIGNAL(clicked()) , this, SLOT(reject()) );
@ -204,7 +213,7 @@ namespace Hurricane {
} else
_header->setText ("<b>[UNKNOW]</b>");
_message->setText ( contents );
_message->setPlainText ( contents );
}

View File

@ -1,22 +1,20 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2018, All Rights Reserved
// Copyright (c) SU 2008-2020, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | C O R I O L I S |
// | V L S I B a c k e n d D a t a - B a s e |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./ExceptionWidget.h" |
// | C++ Header : "./hurricane/viewer/ExceptionWidget.h" |
// +-----------------------------------------------------------------+
#ifndef HURRICANE_EXCEPTION_WIDGET_H
#define HURRICANE_EXCEPTION_WIDGET_H
#pragma once
#include <exception>
#include <functional>
#include <QDialog>
@ -48,11 +46,9 @@ namespace Hurricane {
void _showTrace ( int state );
private:
QLabel* _header;
QLabel* _message;
QTextEdit* _message;
QTextEdit* _trace;
};
} // Hurricane namespace.
#endif // HURRICANE_EXCEPTION_WIDGET_H