Files

157 lines
5.2 KiB
C++
Raw Permalink Normal View History

2012-05-18 09:45:23 +02:00
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
2012-05-18 09:45:23 +02:00
//
//##################################################################################################
#include "cafMessagePanel.h"
2020-06-19 07:53:59 +02:00
#include <QBoxLayout>
#include <QDockWidget>
#include <QTextEdit>
2020-06-19 07:53:59 +02:00
#include <QWidget>
2012-05-18 09:45:23 +02:00
2020-06-19 07:53:59 +02:00
namespace caf
{
2018-02-18 18:17:50 +01:00
MessagePanel* MessagePanel::sm_messagePanelInstance = nullptr;
2012-05-18 09:45:23 +02:00
//==================================================================================================
///
/// \class MessagePanel
///
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
MessagePanel::MessagePanel( QDockWidget* parent )
: QWidget( parent )
2012-05-18 09:45:23 +02:00
{
2020-06-19 07:53:59 +02:00
m_textEdit = new QTextEdit( this );
m_textEdit->setReadOnly( true );
m_textEdit->setLineWrapMode( QTextEdit::NoWrap );
2012-05-18 09:45:23 +02:00
QVBoxLayout* layout = new QVBoxLayout();
2020-06-19 07:53:59 +02:00
layout->addWidget( m_textEdit );
setLayout( layout );
2012-05-18 09:45:23 +02:00
sm_messagePanelInstance = this;
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::showInfo( QString info )
2012-05-18 09:45:23 +02:00
{
2020-06-19 07:53:59 +02:00
convertStringToHTML( &info );
2012-05-18 09:45:23 +02:00
QString str = "<font color='green'>";
str += info;
str += "</font>";
2012-05-18 09:45:23 +02:00
2020-06-19 07:53:59 +02:00
m_textEdit->append( str );
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::showWarning( QString warn )
2012-05-18 09:45:23 +02:00
{
2020-06-19 07:53:59 +02:00
convertStringToHTML( &warn );
2012-05-18 09:45:23 +02:00
QString str = "<font color='maroon'>";
str += warn;
str += "</font>";
2012-05-18 09:45:23 +02:00
2020-06-19 07:53:59 +02:00
m_textEdit->append( str );
}
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::showError( QString error )
2012-05-18 09:45:23 +02:00
{
2020-06-19 07:53:59 +02:00
convertStringToHTML( &error );
2012-05-18 09:45:23 +02:00
QString str = "<b><font color='red'>";
str += error;
str += "</font></b>";
2012-05-18 09:45:23 +02:00
2020-06-19 07:53:59 +02:00
m_textEdit->append( str );
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::convertStringToHTML( QString* str )
2012-05-18 09:45:23 +02:00
{
2020-06-19 07:53:59 +02:00
str->replace( "\n", "<br>" );
str->replace( " ", "&nbsp;" );
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
QSize MessagePanel::sizeHint() const
2012-05-18 09:45:23 +02:00
{
// As small as possible fow now
2020-06-19 07:53:59 +02:00
return QSize( 20, 20 );
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
bool MessagePanel::isVisibleToUser()
{
2020-06-19 07:53:59 +02:00
if ( !isVisible() ) return false;
2012-05-18 09:45:23 +02:00
2020-06-19 07:53:59 +02:00
if ( !m_textEdit ) return false;
if ( !m_textEdit->isVisible() ) return false;
2012-05-18 09:45:23 +02:00
QRegion rgn = m_textEdit->visibleRegion();
2020-06-19 07:53:59 +02:00
if ( rgn.isEmpty() ) return false;
2012-05-18 09:45:23 +02:00
return true;
2012-05-18 09:45:23 +02:00
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
2012-05-18 09:45:23 +02:00
//--------------------------------------------------------------------------------------------------
MessagePanel* MessagePanel::instance()
{
return sm_messagePanelInstance;
}
2020-06-19 07:53:59 +02:00
} // namespace caf