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()
76 mLayout =
new QHBoxLayout(
this );
77 mLayout->setContentsMargins( 0, 0, 0, 0 );
78 mTextBrowser =
nullptr;
85 mLblIcon =
new QLabel(
this );
86 mLayout->addWidget( mLblIcon );
89 if ( !mUserIcon.isNull() )
95 QString msgIcon( QStringLiteral(
"/mIconInfo.svg" ) );
99 msgIcon = QStringLiteral(
"/mIconCritical.svg" );
102 msgIcon = QStringLiteral(
"/mIconWarning.svg" );
105 msgIcon = QStringLiteral(
"/mIconSuccess.svg" );
112 const int iconSize = std::max( 24.0, fontMetrics().height() * 1.2 );
117 QString contentStyleSheet;
120 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #dff0d8; border: 1px solid #8e998a; } "
121 "QLabel,QTextEdit { color: black; } " );
122 contentStyleSheet = QStringLiteral(
"<style> a, a:visited, a:hover { color:#268300; } </style>" );
126 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #d65253; border: 1px solid #9b3d3d; } "
127 "QLabel,QTextEdit { color: white; } " );
128 contentStyleSheet = QStringLiteral(
"<style>a, a:visited, a:hover { color:#4e0001; }</style>" );
132 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #ffc800; border: 1px solid #e0aa00; } "
133 "QLabel,QTextEdit { color: black; } " );
134 contentStyleSheet = QStringLiteral(
"<style>a, a:visited, a:hover { color:#945a00; }</style>" );
138 mStyleSheet = QStringLiteral(
"QgsMessageBar { background-color: #e7f5fe; border: 1px solid #b9cfe4; } "
139 "QLabel,QTextEdit { color: #2554a1; } " );
140 contentStyleSheet = QStringLiteral(
"<style>a, a:visited, a:hover { color:#3bb2fe; }</style>" );
142 mStyleSheet += QStringLiteral(
"QLabel#mItemCount { font-style: italic; }" );
145 if ( mTitle.isEmpty() && mText.isEmpty() )
150 mTextBrowser =
nullptr;
157 mTextBrowser =
new QTextBrowser(
this );
158 mTextBrowser->setObjectName( QStringLiteral(
"textEdit" ) );
159 mTextBrowser->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
160 mTextBrowser->setReadOnly(
true );
161 mTextBrowser->setOpenLinks(
false );
162 connect( mTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsMessageBarItem::urlClicked );
164 mTextBrowser->setFrameShape( QFrame::NoFrame );
167 mTextBrowser->setStyleSheet(
"QTextEdit { background-color: rgba(0,0,0,0); margin-top: 0.25em; max-height: 1.75em; min-height: 1.75em; } "
168 "QScrollBar { background-color: rgba(0,0,0,0); } "
169 "QScrollBar::add-page,QScrollBar::sub-page,QScrollBar::handle { background-color: rgba(0,0,0,0); color: rgba(0,0,0,0); } "
170 "QScrollBar::up-arrow,QScrollBar::down-arrow { color: rgb(0,0,0); } " );
171 mLayout->addWidget( mTextBrowser );
173 QString content = mText;
174 if ( !mTitle.isEmpty() )
177 QString t = mTitle.trimmed();
178 if ( !content.isEmpty() && !t.endsWith(
':' ) && !t.endsWith( QLatin1String(
": " ) ) )
179 t += QLatin1String(
": " );
180 content.prepend( QStringLiteral(
"<b>" ) + t +
" </b>" );
182 content.prepend( contentStyleSheet );
183 mTextBrowser->setText( content );
189 QLayoutItem *item = mLayout->itemAt( 2 );
190 if ( !item || item->widget() != mWidget )
192 mLayout->addWidget( mWidget );
223 if (
level != mLevel )
242 QLayoutItem *item =
nullptr;
243 item = mLayout->itemAt( 2 );
244 if ( item->widget() == mWidget )
246 delete item->widget();
285 void QgsMessageBarItem::urlClicked(
const QUrl &url )
287 QFileInfo file( url.toLocalFile() );
288 if ( file.exists() && !file.isDir() )
291 QDesktopServices::openUrl( url );