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 );
113 mLblIcon->setPixmap( icon.pixmap( iconSize ) );
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 );
238 QLayoutItem *item =
nullptr;
239 item = mLayout->itemAt( 2 );
240 if ( item->widget() == mWidget )
242 delete item->widget();
281 void QgsMessageBarItem::urlClicked(
const QUrl &url )
283 QFileInfo file( url.toLocalFile() );
284 if ( file.exists() && !file.isDir() )
287 QDesktopServices::openUrl( url );
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
QString title() const
Returns the title for the message.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
int duration() const
returns the duration in second of the message
MessageLevel
Level for messages This will be used both for message log and message bar in application.
static QgsGui * instance()
Returns a pointer to the singleton instance.
QIcon icon() const
Returns the icon for the message.
QgsMessageBarItem * setTitle(const QString &title)
Qgis::MessageLevel level() const
Returns the message level for the message.
QgsMessageBarItem * setWidget(QWidget *widget)
QgsMessageBarItem * setText(const QString &text)
QgsMessageBarItem * setIcon(const QIcon &icon)
bool popWidget(QgsMessageBarItem *item)
Remove the passed widget from the bar (if previously added), then display the next one in the stack i...
void dismiss()
Dismisses the item, removing it from the message bar and deleting it.
QString text() const
Returns the text for the message.
QgsMessageBarItem(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=0, QWidget *parent=nullptr)
make out a widget containing a message to be displayed on the bar
QgsMessageBarItem * setDuration(int duration)
QWidget * widget() const
Returns the widget for the message.
void styleChanged(const QString &styleSheet)
emitted when the message level has changed
QgsMessageBarItem * setLevel(Qgis::MessageLevel level)