22 #include "qgsnative.h"
23 #include <QHBoxLayout>
25 #include <QTextBrowser>
26 #include <QDesktopServices>
33 , mDuration( duration )
43 , mDuration( duration )
53 , mDuration( duration )
55 , mUserIcon( QIcon() )
64 , mDuration( duration )
66 , mUserIcon( QIcon() )
72 void QgsMessageBarItem::writeContent()
79 mLayout =
new QHBoxLayout(
this );
80 mLayout->setContentsMargins( 0, 0, 0, 0 );
81 mTextBrowser =
nullptr;
88 mLblIcon =
new QLabel(
this );
89 mLayout->addWidget( mLblIcon );
92 if ( !mUserIcon.isNull() )
98 QString msgIcon( QStringLiteral(
"/mIconInfo.svg" ) );
101 case Qgis::MessageLevel::Critical:
102 msgIcon = QStringLiteral(
"/mIconCritical.svg" );
104 case Qgis::MessageLevel::Warning:
105 msgIcon = QStringLiteral(
"/mIconWarning.svg" );
107 case Qgis::MessageLevel::Success:
108 msgIcon = QStringLiteral(
"/mIconSuccess.svg" );
115 const int iconSize = std::max( 24.0, fontMetrics().height() * 1.2 );
120 QString contentStyleSheet;
121 if ( mLevel == Qgis::MessageLevel::Success )
123 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #dff0d8; border: 1px solid #8e998a; } "
124 "QLabel,QTextEdit { color: black; } " );
125 contentStyleSheet = QStringLiteral(
"<style> a, a:visited, a:hover { color:#268300; } </style>" );
127 else if ( mLevel == Qgis::MessageLevel::Critical )
129 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #d65253; border: 1px solid #9b3d3d; } "
130 "QLabel,QTextEdit { color: white; } " );
131 contentStyleSheet = QStringLiteral(
"<style>a, a:visited, a:hover { color:#4e0001; }</style>" );
133 else if ( mLevel == Qgis::MessageLevel::Warning )
135 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #ffc800; border: 1px solid #e0aa00; } "
136 "QLabel,QTextEdit { color: black; } " );
137 contentStyleSheet = QStringLiteral(
"<style>a, a:visited, a:hover { color:#945a00; }</style>" );
139 else if ( mLevel == Qgis::MessageLevel::Info )
141 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #e7f5fe; border: 1px solid #b9cfe4; } "
142 "QLabel,QTextEdit { color: #2554a1; } " );
143 contentStyleSheet = QStringLiteral(
"<style>a, a:visited, a:hover { color:#3bb2fe; }</style>" );
145 mStyleSheet += QLatin1String(
"QLabel#mItemCount { font-style: italic; }" );
148 if ( mTitle.isEmpty() && mText.isEmpty() )
153 mTextBrowser =
nullptr;
160 mTextBrowser =
new QTextBrowser(
this );
161 mTextBrowser->setObjectName( QStringLiteral(
"textEdit" ) );
162 mTextBrowser->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
163 mTextBrowser->setReadOnly(
true );
164 mTextBrowser->setOpenLinks(
false );
165 connect( mTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsMessageBarItem::urlClicked );
167 mTextBrowser->setFrameShape( QFrame::NoFrame );
170 mTextBrowser->setStyleSheet(
"QTextEdit { background-color: rgba(0,0,0,0); margin-top: 0.25em; max-height: 1.75em; min-height: 1.75em; } "
171 "QScrollBar { background-color: rgba(0,0,0,0); } "
172 "QScrollBar::add-page,QScrollBar::sub-page,QScrollBar::handle { background-color: rgba(0,0,0,0); color: rgba(0,0,0,0); } "
173 "QScrollBar::up-arrow,QScrollBar::down-arrow { color: rgb(0,0,0); } " );
174 mLayout->addWidget( mTextBrowser );
176 QString content = mText;
177 if ( !mTitle.isEmpty() )
180 QString t = mTitle.trimmed();
181 if ( !content.isEmpty() && !t.endsWith(
':' ) && !t.endsWith( QLatin1String(
": " ) ) )
182 t += QLatin1String(
": " );
183 content.prepend( QStringLiteral(
"<b>" ) + t +
" </b>" );
185 content.prepend( contentStyleSheet );
186 mTextBrowser->setText( content );
192 QLayoutItem *item = mLayout->itemAt( 2 );
193 if ( !item || item->widget() != mWidget )
195 mLayout->addWidget( mWidget );
226 if (
level != mLevel )
245 QLayoutItem *item =
nullptr;
246 item = mLayout->itemAt( 2 );
247 if ( item->widget() == mWidget )
249 delete item->widget();
288 void QgsMessageBarItem::urlClicked(
const QUrl &url )
290 const QFileInfo file( url.toLocalFile() );
291 if ( file.exists() && !file.isDir() )
294 QDesktopServices::openUrl( url );