From 235a9eeceaff6f4c818f160663e326730238304b Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Tue, 16 Jun 2020 21:37:18 +0200 Subject: [PATCH] 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. --- hurricane/src/viewer/ExceptionWidget.cpp | 31 ++++++++++++------- .../viewer/hurricane/viewer/ExceptionWidget.h | 18 +++++------ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/hurricane/src/viewer/ExceptionWidget.cpp b/hurricane/src/viewer/ExceptionWidget.cpp index 90b487a4..ffae5124 100644 --- a/hurricane/src/viewer/ExceptionWidget.cpp +++ b/hurricane/src/viewer/ExceptionWidget.cpp @@ -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 ( "[ERROR]" ); - _message->setTextFormat ( Qt::RichText ); - _message->setFont ( Graphics::getFixedFont(QFont::Normal,false,false) ); - _message->setText ( "Oups! I did it again!" ); + 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->setPlainText ( "Oups! I did it again!" ); _trace->setTextInteractionFlags ( Qt::TextBrowserInteraction ); _trace->setAcceptRichText ( true ); @@ -172,14 +180,15 @@ 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 ); - setLayout ( hLayout1 ); - //setMinimumSize ( QSize(400,150) ); - setSizePolicy ( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ); + 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 ("[UNKNOW]"); - _message->setText ( contents ); + _message->setPlainText ( contents ); } diff --git a/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h b/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h index ca35d045..f78aae84 100644 --- a/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h +++ b/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h @@ -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 #include #include @@ -47,12 +45,10 @@ namespace Hurricane { private slots: void _showTrace ( int state ); private: - QLabel* _header; - QLabel* _message; - QTextEdit* _trace; + QLabel* _header; + QTextEdit* _message; + QTextEdit* _trace; }; } // Hurricane namespace. - -#endif // HURRICANE_EXCEPTION_WIDGET_H