Files
ResInsight/Fwk/AppFwk/CommonCode/cafMessagePanel.cpp

158 lines
5.2 KiB
C++
Raw Normal View History

//##################################################################################################
//
// 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.
//
//##################################################################################################
#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>
2020-06-19 07:53:59 +02:00
namespace caf
{
MessagePanel* MessagePanel::sm_messagePanelInstance = nullptr;
//==================================================================================================
///
/// \class MessagePanel
///
2020-06-19 07:53:59 +02:00
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
MessagePanel::MessagePanel( QDockWidget* parent )
: QWidget( parent )
{
2020-06-19 07:53:59 +02:00
m_textEdit = new QTextEdit( this );
m_textEdit->setReadOnly( true );
m_textEdit->setLineWrapMode( QTextEdit::NoWrap );
QVBoxLayout* layout = new QVBoxLayout();
2020-06-19 07:53:59 +02:00
layout->addWidget( m_textEdit );
setLayout( layout );
sm_messagePanelInstance = this;
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::showInfo( QString info )
{
2020-06-19 07:53:59 +02:00
convertStringToHTML( &info );
QString str = "<font color='green'>";
str += info;
str += "</font>";
2020-06-19 07:53:59 +02:00
m_textEdit->append( str );
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::showWarning( QString warn )
{
2020-06-19 07:53:59 +02:00
convertStringToHTML( &warn );
QString str = "<font color='maroon'>";
str += warn;
str += "</font>";
2020-06-19 07:53:59 +02:00
m_textEdit->append( str );
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::showError( QString error )
{
2020-06-19 07:53:59 +02:00
convertStringToHTML( &error );
QString str = "<b><font color='red'>";
str += error;
str += "</font></b>";
2020-06-19 07:53:59 +02:00
m_textEdit->append( str );
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
void MessagePanel::convertStringToHTML( QString* str )
{
2020-06-19 07:53:59 +02:00
str->replace( "\n", "<br>" );
str->replace( " ", "&nbsp;" );
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
QSize MessagePanel::sizeHint() const
{
// As small as possible fow now
2020-06-19 07:53:59 +02:00
return QSize( 20, 20 );
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
bool MessagePanel::isVisibleToUser()
{
2020-06-19 07:53:59 +02:00
if ( !isVisible() ) return false;
2020-06-19 07:53:59 +02:00
if ( !m_textEdit ) return false;
if ( !m_textEdit->isVisible() ) return false;
QRegion rgn = m_textEdit->visibleRegion();
2020-06-19 07:53:59 +02:00
if ( rgn.isEmpty() ) return false;
return true;
}
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
MessagePanel* MessagePanel::instance()
{
return sm_messagePanelInstance;
}
2020-06-19 07:53:59 +02:00
} // namespace caf