* ./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.
This commit is contained in:
Jean-Paul Chaput 2010-12-15 15:10:58 +00:00
parent c356715d80
commit daab8a8b8f
5 changed files with 77 additions and 35 deletions

View File

@ -127,7 +127,7 @@ namespace Hurricane {
ostringstream where; ostringstream where;
for ( size_t depth=0 ; depth<_stack.size() ; ++depth ) for ( size_t depth=0 ; depth<_stack.size() ; ++depth )
where << "<tt>[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "</tt><br>"; where << "<tt>[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "</tt><br>\n";
return where.str(); return where.str();
} }

View File

@ -219,12 +219,13 @@ namespace Hurricane {
_scriptAction->setObjectName ( "viewer.menuBar.tools.script" ); _scriptAction->setObjectName ( "viewer.menuBar.tools.script" );
_scriptAction->setStatusTip ( tr("Run Python Script") ); _scriptAction->setStatusTip ( tr("Run Python Script") );
_scriptAction->setIcon ( QIcon(":/images/python-logo-v3.png") ); _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 = new QAction ( tr("Stratus"), this );
_stratusAction->setObjectName ( "viewer.menuBar.tools.stratusScript" ); _stratusAction->setObjectName ( "viewer.menuBar.tools.stratusScript" );
_stratusAction->setStatusTip ( tr("Run Stratus Script") ); _stratusAction->setStatusTip ( tr("Run Stratus Script") );
_stratusAction->setIcon ( QIcon(":/images/stratus-cloud.png") ); _stratusAction->setIcon ( QIcon(":/images/stratus-cloud.png") );
_stratusAction->setShortcut ( QKeySequence(tr("SHIFT+P,SHIFT+S")) );
} }

View File

@ -23,13 +23,28 @@
// x-----------------------------------------------------------------x // x-----------------------------------------------------------------x
# include <cassert> #include <cassert>
# include "hurricane/Error.h" #include "hurricane/Error.h"
# include "hurricane/viewer/DisplayStyle.h" #include "hurricane/viewer/DisplayStyle.h"
# include "hurricane/viewer/Graphics.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 { namespace Hurricane {
@ -124,7 +139,8 @@ namespace Hurricane {
{ {
assert ( _color != NULL ); assert ( _color != NULL );
return _color->darker ( darkening ); //return _color->darker ( darkening );
return modifySaturation(*_color,darkening);
} }
@ -133,7 +149,9 @@ namespace Hurricane {
assert ( _pen != NULL ); assert ( _pen != NULL );
QPen pen ( *_pen ); QPen pen ( *_pen );
pen.setColor ( _color->darker(darkening) ); //pen.setColor ( _color->darker(darkening) );
pen.setColor ( modifySaturation(*_color,darkening) );
return pen; return pen;
} }
@ -143,7 +161,8 @@ namespace Hurricane {
assert ( _brush != NULL ); assert ( _brush != NULL );
QBrush brush ( *_brush ); QBrush brush ( *_brush );
brush.setColor ( _color->darker(darkening) ); //brush.setColor ( _color->darker(darkening) );
brush.setColor ( modifySaturation(*_color,darkening) );
return brush; return brush;
} }

View File

@ -27,11 +27,15 @@
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QCheckBox> #include <QCheckBox>
#include <QScrollArea>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QFrame> #include <QFrame>
#include <QFont>
#include <QFontMetrics>
#include "hurricane/Exception.h" #include "hurricane/Exception.h"
#include "hurricane/viewer/Graphics.h"
#include "hurricane/viewer/ExceptionWidget.h" #include "hurricane/viewer/ExceptionWidget.h"
@ -39,10 +43,11 @@ namespace Hurricane {
ExceptionWidget::ExceptionWidget ( QWidget* parent ) ExceptionWidget::ExceptionWidget ( QWidget* parent )
: QDialog (parent) : QDialog (parent)
, _header (new QLabel()) , _header (new QLabel())
, _message(new QLabel()) , _message (new QLabel())
, _trace (new QLabel()) , _trace (new QLabel())
, _traceArea(new QScrollArea())
{ {
setAttribute ( Qt::WA_DeleteOnClose ); setAttribute ( Qt::WA_DeleteOnClose );
setModal ( true ); setModal ( true );
@ -56,18 +61,24 @@ namespace Hurricane {
_message->setTextFormat ( Qt::RichText ); _message->setTextFormat ( Qt::RichText );
_message->setText ( "<b>Oups! I did it again!</b>" ); _message->setText ( "<b>Oups! I did it again!</b>" );
_trace->setTextFormat ( Qt::RichText ); _trace->setTextFormat ( Qt::RichText );
_trace->setText ( "<b>No program trace sets yet.</b>" ); _trace->setText ( "<b>No program trace sets yet.</b>" );
_trace->hide (); _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 (); QCheckBox* showTrace = new QCheckBox ();
showTrace->setText ( "Show Program Trace" ); showTrace->setText ( "Show Program Trace" );
showTrace->setChecked ( false ); showTrace->setChecked ( false );
QLabel* ok = new QLabel (); QLabel* leftMargin = new QLabel ();
ok->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding ); leftMargin->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
ok->setPixmap ( QPixmap(":/images/gnome-core.png") ); leftMargin->setPixmap ( QPixmap(":/images/gnome-core.png") );
ok->setStyleSheet ( "QLabel { background-color: #FF9999;" leftMargin->setStyleSheet ( "QLabel { background-color: #FF9999;"
" padding: 5px }" ); " padding: 5px }" );
QPushButton* abortButton = new QPushButton (); QPushButton* abortButton = new QPushButton ();
@ -92,21 +103,23 @@ namespace Hurricane {
QVBoxLayout* vLayout1 = new QVBoxLayout (); QVBoxLayout* vLayout1 = new QVBoxLayout ();
vLayout1->setContentsMargins ( 10, 10, 10, 10 ); vLayout1->setContentsMargins ( 10, 10, 10, 10 );
vLayout1->setSpacing ( 0 ); vLayout1->setSpacing ( 0 );
vLayout1->addWidget ( _header , Qt::AlignCenter ); vLayout1->addWidget ( _header , 0, Qt::AlignLeft );
vLayout1->addWidget ( _message , Qt::AlignCenter ); vLayout1->addWidget ( _message , 0, Qt::AlignLeft );
vLayout1->addWidget ( separator ); vLayout1->addWidget ( separator );
vLayout1->addWidget ( showTrace , Qt::AlignLeft ); vLayout1->addWidget ( showTrace , 0, Qt::AlignLeft );
vLayout1->addWidget ( _trace , Qt::AlignCenter ); vLayout1->addWidget ( _traceArea, 0, Qt::AlignLeft );
vLayout1->addSpacing ( 10 ); vLayout1->addSpacing ( 10 );
vLayout1->addLayout ( hLayout2 , Qt::AlignCenter ); vLayout1->addLayout ( hLayout2 , Qt::AlignCenter );
QHBoxLayout* hLayout1 = new QHBoxLayout (); QHBoxLayout* hLayout1 = new QHBoxLayout ();
hLayout1->setSizeConstraint ( QLayout::SetFixedSize ); hLayout1->setSizeConstraint ( QLayout::SetFixedSize );
hLayout1->setContentsMargins ( 0, 0, 0, 0 ); hLayout1->setContentsMargins ( 0, 0, 0, 0 );
hLayout1->addWidget ( ok ); hLayout1->addWidget ( leftMargin );
hLayout1->addLayout ( vLayout1 ); 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 ( contButton , SIGNAL(clicked()) , this, SLOT(accept()) );
connect ( abortButton, SIGNAL(clicked()) , this, SLOT(reject()) ); connect ( abortButton, SIGNAL(clicked()) , this, SLOT(reject()) );
@ -139,14 +152,22 @@ namespace Hurricane {
void ExceptionWidget::setTrace ( const QString& where ) 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->setText ( where );
_trace->resize ( textSize );
} }
void ExceptionWidget::_showTrace ( int state ) void ExceptionWidget::_showTrace ( int state )
{ {
if ( state == Qt::Checked ) _trace->show (); if ( state == Qt::Checked ) _traceArea->show ();
else _trace->hide (); else _traceArea->hide ();
} }

View File

@ -29,6 +29,7 @@
#include <QDialog> #include <QDialog>
class QLabel; class QLabel;
class QScrollArea;
namespace Hurricane { namespace Hurricane {
@ -40,18 +41,18 @@ namespace Hurricane {
ExceptionWidget ( QWidget* parent=NULL); ExceptionWidget ( QWidget* parent=NULL);
void setMessage ( const QString& ); void setMessage ( const QString& );
void setTrace ( const QString& ); void setTrace ( const QString& );
private:
QLabel* _header;
QLabel* _message;
QLabel* _trace;
protected: protected:
virtual void closeEvent ( QCloseEvent* ); virtual void closeEvent ( QCloseEvent* );
private slots: private slots:
void _showTrace ( int state ); void _showTrace ( int state );
private:
QLabel* _header;
QLabel* _message;
QLabel* _trace;
QScrollArea* _traceArea;
}; };
} // End of Hurricane namespace. } // End of Hurricane namespace.
#endif // __HURRICANE_EXCEPTION_WIDGET__ #endif // __HURRICANE_EXCEPTION_WIDGET__