From daab8a8b8fee47dd825a569416855550f5ec64ae Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Wed, 15 Dec 2010 15:10:58 +0000 Subject: [PATCH] * ./hurricane/src/viewer: - In CellViewer, adds a shortcut for launching Stratus scipts: SHIFT+P,S and one for pure Python scripts: SHIFT+P,P. - In ExceptionWidget, put the trace inside a QScrollArea so all the call stack can be viewed regardless of the window's size. It seems that QFontMetrics has problems to compute the right text size when using a Qt::RichText enabled widget. Adds some "manual" corrections, hope they will be sufficiently portables. --- hurricane/src/hurricane/Backtrace.cpp | 2 +- hurricane/src/viewer/CellViewer.cpp | 3 +- hurricane/src/viewer/DisplayStyle.cpp | 33 ++++++++--- hurricane/src/viewer/ExceptionWidget.cpp | 59 +++++++++++++------ .../viewer/hurricane/viewer/ExceptionWidget.h | 15 ++--- 5 files changed, 77 insertions(+), 35 deletions(-) diff --git a/hurricane/src/hurricane/Backtrace.cpp b/hurricane/src/hurricane/Backtrace.cpp index 13e9425c..b1bd9080 100644 --- a/hurricane/src/hurricane/Backtrace.cpp +++ b/hurricane/src/hurricane/Backtrace.cpp @@ -127,7 +127,7 @@ namespace Hurricane { ostringstream where; for ( size_t depth=0 ; depth<_stack.size() ; ++depth ) - where << "[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "
"; + where << "[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "
\n"; return where.str(); } diff --git a/hurricane/src/viewer/CellViewer.cpp b/hurricane/src/viewer/CellViewer.cpp index a9775090..8fccf918 100644 --- a/hurricane/src/viewer/CellViewer.cpp +++ b/hurricane/src/viewer/CellViewer.cpp @@ -219,12 +219,13 @@ namespace Hurricane { _scriptAction->setObjectName ( "viewer.menuBar.tools.script" ); _scriptAction->setStatusTip ( tr("Run Python Script") ); _scriptAction->setIcon ( QIcon(":/images/python-logo-v3.png") ); - //_scriptAction->setShortcut ( QKeySequence(tr("CTRL+I")) ); + _scriptAction->setShortcut ( QKeySequence(tr("SHIFT+P,SHIFT+P")) ); _stratusAction = new QAction ( tr("Stratus"), this ); _stratusAction->setObjectName ( "viewer.menuBar.tools.stratusScript" ); _stratusAction->setStatusTip ( tr("Run Stratus Script") ); _stratusAction->setIcon ( QIcon(":/images/stratus-cloud.png") ); + _stratusAction->setShortcut ( QKeySequence(tr("SHIFT+P,SHIFT+S")) ); } diff --git a/hurricane/src/viewer/DisplayStyle.cpp b/hurricane/src/viewer/DisplayStyle.cpp index 01f2c2f9..12345d4f 100644 --- a/hurricane/src/viewer/DisplayStyle.cpp +++ b/hurricane/src/viewer/DisplayStyle.cpp @@ -23,13 +23,28 @@ // x-----------------------------------------------------------------x -# include +#include -# include "hurricane/Error.h" -# include "hurricane/viewer/DisplayStyle.h" -# include "hurricane/viewer/Graphics.h" +#include "hurricane/Error.h" +#include "hurricane/viewer/DisplayStyle.h" +#include "hurricane/viewer/Graphics.h" +namespace { + + QColor modifySaturation ( const QColor& color, int darkening ) + { + QColor hsvColor = color.toHsv(); + if ( darkening != 100 ) { + qreal darkSat = color.saturationF(); + qreal darkValue = color.valueF(); + hsvColor.setHsvF ( color.hueF(), darkSat/3.0, darkValue/2.5 ); + } + return hsvColor; + } + + +} // End of anonymous namespace. namespace Hurricane { @@ -124,7 +139,8 @@ namespace Hurricane { { assert ( _color != NULL ); - return _color->darker ( darkening ); + //return _color->darker ( darkening ); + return modifySaturation(*_color,darkening); } @@ -133,7 +149,9 @@ namespace Hurricane { assert ( _pen != NULL ); QPen pen ( *_pen ); - pen.setColor ( _color->darker(darkening) ); + //pen.setColor ( _color->darker(darkening) ); + pen.setColor ( modifySaturation(*_color,darkening) ); + return pen; } @@ -143,7 +161,8 @@ namespace Hurricane { assert ( _brush != NULL ); QBrush brush ( *_brush ); - brush.setColor ( _color->darker(darkening) ); + //brush.setColor ( _color->darker(darkening) ); + brush.setColor ( modifySaturation(*_color,darkening) ); return brush; } diff --git a/hurricane/src/viewer/ExceptionWidget.cpp b/hurricane/src/viewer/ExceptionWidget.cpp index 19121ec0..66a53935 100644 --- a/hurricane/src/viewer/ExceptionWidget.cpp +++ b/hurricane/src/viewer/ExceptionWidget.cpp @@ -27,11 +27,15 @@ #include #include #include +#include #include #include #include +#include +#include #include "hurricane/Exception.h" +#include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/ExceptionWidget.h" @@ -39,10 +43,11 @@ namespace Hurricane { ExceptionWidget::ExceptionWidget ( QWidget* parent ) - : QDialog (parent) - , _header (new QLabel()) - , _message(new QLabel()) - , _trace (new QLabel()) + : QDialog (parent) + , _header (new QLabel()) + , _message (new QLabel()) + , _trace (new QLabel()) + , _traceArea(new QScrollArea()) { setAttribute ( Qt::WA_DeleteOnClose ); setModal ( true ); @@ -56,18 +61,24 @@ namespace Hurricane { _message->setTextFormat ( Qt::RichText ); _message->setText ( "Oups! I did it again!" ); - _trace->setTextFormat ( Qt::RichText ); - _trace->setText ( "No program trace sets yet." ); - _trace->hide (); + _trace->setTextFormat ( Qt::RichText ); + _trace->setText ( "No program trace sets yet." ); + _trace->setSizePolicy ( QSizePolicy::Ignored, QSizePolicy::Ignored ); + + + _traceArea->setWidget ( _trace ); + _traceArea->hide (); + //_traceArea->setSizePolicy ( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ); + _traceArea->setMinimumSize ( QSize(700,500) ); QCheckBox* showTrace = new QCheckBox (); showTrace->setText ( "Show Program Trace" ); showTrace->setChecked ( false ); - QLabel* ok = new QLabel (); - ok->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding ); - ok->setPixmap ( QPixmap(":/images/gnome-core.png") ); - ok->setStyleSheet ( "QLabel { background-color: #FF9999;" + QLabel* leftMargin = new QLabel (); + leftMargin->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding ); + leftMargin->setPixmap ( QPixmap(":/images/gnome-core.png") ); + leftMargin->setStyleSheet ( "QLabel { background-color: #FF9999;" " padding: 5px }" ); QPushButton* abortButton = new QPushButton (); @@ -92,21 +103,23 @@ namespace Hurricane { QVBoxLayout* vLayout1 = new QVBoxLayout (); vLayout1->setContentsMargins ( 10, 10, 10, 10 ); vLayout1->setSpacing ( 0 ); - vLayout1->addWidget ( _header , Qt::AlignCenter ); - vLayout1->addWidget ( _message , Qt::AlignCenter ); + vLayout1->addWidget ( _header , 0, Qt::AlignLeft ); + vLayout1->addWidget ( _message , 0, Qt::AlignLeft ); vLayout1->addWidget ( separator ); - vLayout1->addWidget ( showTrace , Qt::AlignLeft ); - vLayout1->addWidget ( _trace , Qt::AlignCenter ); + vLayout1->addWidget ( showTrace , 0, Qt::AlignLeft ); + vLayout1->addWidget ( _traceArea, 0, Qt::AlignLeft ); vLayout1->addSpacing ( 10 ); vLayout1->addLayout ( hLayout2 , Qt::AlignCenter ); QHBoxLayout* hLayout1 = new QHBoxLayout (); hLayout1->setSizeConstraint ( QLayout::SetFixedSize ); hLayout1->setContentsMargins ( 0, 0, 0, 0 ); - hLayout1->addWidget ( ok ); + hLayout1->addWidget ( leftMargin ); hLayout1->addLayout ( vLayout1 ); - setLayout ( hLayout1 ); + setLayout ( hLayout1 ); + //setMinimumSize ( QSize(400,150) ); + setSizePolicy ( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ); connect ( contButton , SIGNAL(clicked()) , this, SLOT(accept()) ); connect ( abortButton, SIGNAL(clicked()) , this, SLOT(reject()) ); @@ -139,14 +152,22 @@ namespace Hurricane { void ExceptionWidget::setTrace ( const QString& where ) { + QFont font = Graphics::getFixedFont(QFont::Bold); + QFontMetrics metrics = QFontMetrics ( font ); + QSize textSize = metrics.size ( 0, where ); + + //textSize.setWidth ( textSize.width () / 2 ); + textSize.setHeight ( textSize.height() + 70 ); + _trace->setText ( where ); + _trace->resize ( textSize ); } void ExceptionWidget::_showTrace ( int state ) { - if ( state == Qt::Checked ) _trace->show (); - else _trace->hide (); + if ( state == Qt::Checked ) _traceArea->show (); + else _traceArea->hide (); } diff --git a/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h b/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h index 66126e7c..cce6af0a 100644 --- a/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h +++ b/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h @@ -29,6 +29,7 @@ #include class QLabel; +class QScrollArea; namespace Hurricane { @@ -40,18 +41,18 @@ namespace Hurricane { ExceptionWidget ( QWidget* parent=NULL); void setMessage ( const QString& ); void setTrace ( const QString& ); - private: - QLabel* _header; - QLabel* _message; - QLabel* _trace; protected: - virtual void closeEvent ( QCloseEvent* ); + virtual void closeEvent ( QCloseEvent* ); private slots: - void _showTrace ( int state ); + void _showTrace ( int state ); + private: + QLabel* _header; + QLabel* _message; + QLabel* _trace; + QScrollArea* _traceArea; }; } // End of Hurricane namespace. - #endif // __HURRICANE_EXCEPTION_WIDGET__