//################################################################################################## // // Custom Visualization Core library // Copyright (C) 2011-2012 Ceetron AS // // 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 <> // for more details. // //################################################################################################## #include "cafMessagePanel.h" #include #include #include #include namespace caf { MessagePanel* MessagePanel::sm_messagePanelInstance = NULL; //================================================================================================== /// /// \class MessagePanel /// /// /// //================================================================================================== //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- MessagePanel::MessagePanel(QDockWidget* parent) : QWidget(parent) { m_textEdit = new QTextEdit(this); m_textEdit->setReadOnly(true); m_textEdit->setLineWrapMode(QTextEdit::NoWrap); QVBoxLayout* layout = new QVBoxLayout(); layout->addWidget(m_textEdit); setLayout(layout); sm_messagePanelInstance = this; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void MessagePanel::showInfo(QString info) { convertStringToHTML(&info); QString str = ""; str += info; str += ""; m_textEdit->append(str); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void MessagePanel::showWarning(QString warn) { convertStringToHTML(&warn); QString str = ""; str += warn; str += ""; m_textEdit->append(str); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void MessagePanel::showError(QString error) { convertStringToHTML(&error); QString str = ""; str += error; str += ""; m_textEdit->append(str); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void MessagePanel::convertStringToHTML(QString* str) { str->replace("\n", "
"); str->replace(" ", " "); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QSize MessagePanel::sizeHint () const { // As small as possible fow now return QSize(20, 20); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool MessagePanel::isVisibleToUser() { if (!isVisible()) return false; if (!m_textEdit) return false; if (!m_textEdit->isVisible()) return false; QRegion rgn = m_textEdit->visibleRegion(); if (rgn.isEmpty()) return false; return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- MessagePanel* MessagePanel::instance() { return sm_messagePanelInstance; } }