Commit 8f900139 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD #228] message dock now able to show log messages and to filter them

parent 25aa0b5d
......@@ -1102,6 +1102,8 @@ void WMainWindow::saveWindowState()
// NOTE: Qt Doc says that saveState also saves geometry. But this somehow is wrong (at least for 4.6.3)
WQt4Gui::getSettings().setValue( "MainWindowGeometry", saveGeometry() );
WQt4Gui::getSettings().setValue( "GLDockWindowGeometry", m_glDock->saveGeometry() );
m_messageDock->saveSettings();
}
QSettings& WMainWindow::getSettings()
......
......@@ -280,6 +280,7 @@ int WQt4Gui::run()
int qtRetCode = appl.exec();
delete m_mainWindow;
m_mainWindow = NULL; // the log slot needs this to be null now
// signal everybody to shut down properly.
WKernel::getRunningKernel()->wait( true );
......@@ -298,8 +299,11 @@ void WQt4Gui::slotUpdateTextureSorter()
void WQt4Gui::slotAddLog( const WLogEntry& entry )
{
// emit event?
QCoreApplication::postEvent( m_mainWindow, new WLogEvent( entry ) );
// emit event but the main window might not be available. Chick this.
if( m_mainWindow )
{
QCoreApplication::postEvent( m_mainWindow, new WLogEvent( entry ) );
}
}
void WQt4Gui::slotAddDatasetOrModuleToTree( boost::shared_ptr< WModule > module )
......
......@@ -22,6 +22,8 @@
//
//---------------------------------------------------------------------------
#include <iostream>
#include <QtGui/QAction>
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
......@@ -31,6 +33,7 @@
#include <QtGui/QComboBox>
#include "WQt4Gui.h"
#include "WMainWindow.h"
#include "WQtMessagePopup.h"
#include "WQtMessageDock.h"
......@@ -54,13 +57,15 @@ WQtMessageDock::WQtMessageDock( QString dockTitle, QWidget* parent ):
m_logList = new QListWidget( this );
// filter list
/* QLabel* filterLabel = new QLabel( "Filter Messages" );
QLabel* filterLabel = new QLabel( "Filter Messages" );
m_filterCombo = new QComboBox();
m_filterCombo->addItem( "Debug" );
m_filterCombo->addItem( "Info" );
m_filterCombo->addItem( "Warning" );
m_filterCombo->addItem( "Error" );
m_filterCombo->setCurrentIndex( 2 ); // warning is the default
m_filterCombo->setCurrentIndex(
WMainWindow::getSettings().value( "MessageDockFilterIndex", 2 ).toInt()
); // warning is the default
// the filter widgets reside in a common layout:
QHBoxLayout* filterLayout = new QHBoxLayout();
......@@ -71,8 +76,10 @@ WQtMessageDock::WQtMessageDock( QString dockTitle, QWidget* parent ):
// compose them together into the panel
panelLayout->addWidget( filterWidget );
*/
panelLayout->addWidget( m_logList );
// connect filter combo
connect( m_filterCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( handleFilterUpdate() ) );
}
WQtMessageDock::~WQtMessageDock()
......@@ -97,9 +104,34 @@ void WQtMessageDock::addMessage( QString title, QString message, WQtMessagePopup
WQtMessagePopup* w = new WQtMessagePopup( m_logList, title, message, type );
w->setAutoClose( false );
w->setShowCloseButton( false );
w->setAutoPosition( false );
QListWidgetItem* item = new QListWidgetItem( m_logList );
item->setSizeHint( QSize( 0, w->sizeHint().height() ) );
m_logList->addItem( item );
m_logList->setItemWidget( item, w );
m_logList->scrollToItem( item, QAbstractItemView::PositionAtBottom );
// hide messages not matching the filter
item->setHidden( type < m_filterCombo->currentIndex() );
}
void WQtMessageDock::saveSettings()
{
WMainWindow::getSettings().setValue( "MessageDockFilterIndex", m_filterCombo->currentIndex() );
}
void WQtMessageDock::handleFilterUpdate()
{
size_t i = 0;
for( size_t i = 0; i < m_logList->count(); ++i )
{
QListWidgetItem* li = m_logList->item( i );
QWidget* w = m_logList->itemWidget( li );
WQtMessagePopup* popup = dynamic_cast< WQtMessagePopup* >( w );
if( popup )
{
li->setHidden( popup->getType() < m_filterCombo->currentIndex() );
}
}
}
......@@ -77,6 +77,17 @@ public:
* \param entry use this log entry
*/
void addLogMessage( const WLogEntry& entry );
/**
* Save state to settings
*/
void saveSettings();
protected slots:
/**
* Handles changes in the filter combo
*/
void handleFilterUpdate();
private:
/**
* The list
......
......@@ -51,13 +51,14 @@ WQtMessagePopup::WQtMessagePopup( QWidget* parent, const QString& title, const Q
QDialog( parent, Qt::Popup | Qt::FramelessWindowHint ),
m_title( title ),
m_message( message ),
m_type( type )
m_type( type ),
m_autoClose( true ),
m_autoMove( true )
{
setAutoClose( true );
// these settings seem to be ignored somehow
setWindowModality( Qt::NonModal );
setModal( false );
// determine a width and height for the popup
unsigned int w = std::min( parent->width() - ( 2 * OUTERMARGIN ), MAXWIDTH );
......@@ -175,11 +176,14 @@ WQtMessagePopup::WQtMessagePopup( QWidget* parent, const QString& title, const Q
void WQtMessagePopup::showEvent( QShowEvent* event )
{
// move widget to correct position
// get top left corner
QPoint p = parentWidget()->mapToGlobal( QPoint( parentWidget()->width() / 2, parentWidget()->height() ) );
if( m_autoMove )
{
// get top left corner
QPoint p = parentWidget()->mapToGlobal( QPoint( parentWidget()->width() / 2, parentWidget()->height() ) );
// set position, include margins
move( p.x() - width() / 2 - OUTERMARGIN / 2, p.y() - height()- OUTERMARGIN );
// set position, include margins
move( p.x() - width() / 2 - OUTERMARGIN / 2, p.y() - height()- OUTERMARGIN );
}
QDialog::showEvent( event );
}
......@@ -218,11 +222,11 @@ void WQtMessagePopup::setAutoClose( bool autoClose )
// use popup type of window if auto close is enabled
if( autoClose )
{
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
setWindowFlags( Qt::Popup );
}
else
{
setWindowFlags( Qt::Widget | Qt::FramelessWindowHint );
setWindowFlags( Qt::Widget );
}
}
......@@ -236,3 +240,13 @@ void WQtMessagePopup::setShowCloseButton( bool showCloseButton )
{
m_closeBtn->setHidden( !showCloseButton );
}
void WQtMessagePopup::setAutoPosition( bool autoPosition )
{
m_autoMove = autoPosition;
}
WQtMessagePopup::MessageType WQtMessagePopup::getType() const
{
return m_type;
}
......@@ -65,14 +65,30 @@ public:
*
* \param autoClose close flag
*/
void setAutoClose( bool autoClose = true );
/**
* Show or hide the close button
*
* \param showCloseButton true to show
*/
void setShowCloseButton( bool showCloseButton = true );
void setAutoClose( bool autoClose = true );
/**
* Show or hide the close button
*
* \param showCloseButton true to show
*/
void setShowCloseButton( bool showCloseButton = true );
/**
* If true, the widget moves itself to the bottom of its parent widget. As this is not useful sometimes, you can disable this by using
* false here.
*
* \param autoPosition false if widget should not move automatically
*/
void setAutoPosition( bool autoPosition = true );
/**
* Get this popups message type.
*
* \return the type
*/
MessageType getType() const;
signals:
/**
* Called when closing the popup
......@@ -120,9 +136,14 @@ private:
QPushButton* m_closeBtn;
/**
* See \ref setAutoClose
* See \ref setAutoClose.
*/
bool m_autoClose;
/**
* See \ref setAutoPosition.
*/
bool m_autoMove;
};
#endif // WQTMESSAGEPOPUP_H
......
......@@ -45,7 +45,7 @@ public:
/**
* destructor
**/
~WLogEvent();
virtual ~WLogEvent();
/**
* To access the WLogEntry of associated with the event.
......@@ -55,7 +55,6 @@ public:
const WLogEntry& getEntry() const;
protected:
private:
/**
* The associated WLogEntry to the event.
......
Markdown is supported
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