22 #include <QHBoxLayout> 24 #include <QTextBrowser> 25 #include <QDesktopServices> 31 , mDuration( duration )
41 , mDuration( duration )
51 , mDuration( duration )
53 , mUserIcon( QIcon() )
62 , mDuration( duration )
64 , mUserIcon( QIcon() )
70 void QgsMessageBarItem::writeContent()
74 mLayout =
new QHBoxLayout(
this );
75 mLayout->setContentsMargins( 0, 0, 0, 0 );
76 mTextBrowser =
nullptr;
83 mLblIcon =
new QLabel(
this );
84 mLayout->addWidget( mLblIcon );
87 if ( !mUserIcon.isNull() )
93 QString msgIcon( QStringLiteral(
"/mIconInfo.svg" ) );
97 msgIcon = QStringLiteral(
"/mIconCritical.svg" );
100 msgIcon = QStringLiteral(
"/mIconWarning.svg" );
103 msgIcon = QStringLiteral(
"/mIconSuccess.svg" );
110 mLblIcon->setPixmap( icon.pixmap( 24 ) );
114 QString contentStyleSheet;
117 mStyleSheet =
"QgsMessageBar { background-color: #dff0d8; border: 1px solid #8e998a; } " 118 "QLabel,QTextEdit { color: black; } ";
119 contentStyleSheet =
"<style> a, a:visited, a:hover { color:#268300; } </style>";
123 mStyleSheet =
"QgsMessageBar { background-color: #d65253; border: 1px solid #9b3d3d; } " 124 "QLabel,QTextEdit { color: white; } ";
125 contentStyleSheet =
"<style>a, a:visited, a:hover { color:#4e0001; }</style>";
129 mStyleSheet =
"QgsMessageBar { background-color: #ffc800; border: 1px solid #e0aa00; } " 130 "QLabel,QTextEdit { color: black; } ";
131 contentStyleSheet =
"<style>a, a:visited, a:hover { color:#945a00; }</style>";
135 mStyleSheet =
"QgsMessageBar { background-color: #e7f5fe; border: 1px solid #b9cfe4; } " 136 "QLabel,QTextEdit { color: #2554a1; } ";
137 contentStyleSheet =
"<style>a, a:visited, a:hover { color:#3bb2fe; }</style>";
139 mStyleSheet += QLatin1String(
"QLabel#mItemCount { font-style: italic; }" );
142 if ( mTitle.isEmpty() && mText.isEmpty() )
147 mTextBrowser =
nullptr;
154 mTextBrowser =
new QTextBrowser(
this );
155 mTextBrowser->setObjectName( QStringLiteral(
"textEdit" ) );
156 mTextBrowser->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
157 mTextBrowser->setReadOnly(
true );
158 mTextBrowser->setOpenLinks(
false );
159 connect( mTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsMessageBarItem::urlClicked );
161 mTextBrowser->setFrameShape( QFrame::NoFrame );
164 mTextBrowser->setStyleSheet(
"QTextEdit { background-color: rgba(0,0,0,0); margin-top: 0.25em; max-height: 1.75em; min-height: 1.75em; } " 165 "QScrollBar { background-color: rgba(0,0,0,0); } " 166 "QScrollBar::add-page,QScrollBar::sub-page,QScrollBar::handle { background-color: rgba(0,0,0,0); color: rgba(0,0,0,0); } " 167 "QScrollBar::up-arrow,QScrollBar::down-arrow { color: rgb(0,0,0); } " );
168 mLayout->addWidget( mTextBrowser );
170 QString content = mText;
171 if ( !mTitle.isEmpty() )
174 QString t = mTitle.trimmed();
175 if ( !content.isEmpty() && !t.endsWith(
':' ) && !t.endsWith( QLatin1String(
": " ) ) )
176 t += QLatin1String(
": " );
177 content.prepend( QStringLiteral(
"<b>" ) + t +
" </b>" );
179 content.prepend( contentStyleSheet );
180 mTextBrowser->setText( content );
186 QLayoutItem *item = mLayout->itemAt( 2 );
187 if ( !item || item->widget() != mWidget )
189 mLayout->addWidget( mWidget );
235 QLayoutItem *item =
nullptr;
236 item = mLayout->itemAt( 2 );
237 if ( item->widget() == mWidget )
239 delete item->widget();
270 void QgsMessageBarItem::urlClicked(
const QUrl &url )
272 QDesktopServices::openUrl( url );
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.
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)
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)