| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | /* This file is part of the KDE libraries
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2011 Aurélien Gâteau <agateau@kde.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 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 | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 
					
						
							|  |  |  |  * 02110-1301  USA | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include "kmessagewidget.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QEvent>
 | 
					
						
							|  |  |  | #include <QGridLayout>
 | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | #include <QDialogButtonBox>
 | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | #include <QLabel>
 | 
					
						
							|  |  |  | #include <QPainter>
 | 
					
						
							|  |  |  | #include <QShowEvent>
 | 
					
						
							|  |  |  | #include <QTimeLine>
 | 
					
						
							|  |  |  | #include <QToolButton>
 | 
					
						
							|  |  |  | #include <QStyle>
 | 
					
						
							|  |  |  | #include <QAction>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidgetPrivate::init(KMessageWidget *q_ptr) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	q = q_ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	q->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	timeLine = new QTimeLine(500, q); | 
					
						
							|  |  |  | 	QObject::connect(timeLine, SIGNAL(valueChanged(qreal)), q, SLOT(slotTimeLineChanged(qreal))); | 
					
						
							|  |  |  | 	QObject::connect(timeLine, SIGNAL(finished()), q, SLOT(slotTimeLineFinished())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	content = new QFrame(q); | 
					
						
							|  |  |  | 	content->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wordWrap = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	iconLabel = new QLabel(content); | 
					
						
							|  |  |  | 	iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | 
					
						
							|  |  |  | 	iconLabel->hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	textLabel = new QLabel(content); | 
					
						
							|  |  |  | 	textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | 
					
						
							|  |  |  | 	textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QObject::connect(textLabel, SIGNAL(linkActivated(const QString &)), q, SIGNAL(linkActivated(const QString &))); | 
					
						
							|  |  |  | 	QObject::connect(textLabel, SIGNAL(linkHovered(const QString &)), q, SIGNAL(linkHovered(const QString &))); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QAction *closeAction = new QAction(QObject::tr("Close"), q); | 
					
						
							| 
									
										
										
										
											2013-05-22 08:10:02 -03:00
										 |  |  | 	q->connect(closeAction, SIGNAL(triggered(bool)), q, SLOT(animatedHide())); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	closeButton = new QToolButton(content); | 
					
						
							|  |  |  | 	closeButton->setAutoRaise(true); | 
					
						
							|  |  |  | 	closeButton->setDefaultAction(closeAction); | 
					
						
							| 
									
										
										
										
											2014-08-04 22:45:17 -07:00
										 |  |  | 	closeButton->setVisible(false); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 	q->setMessageType(KMessageWidget::Information); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidgetPrivate::createLayout() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete content->layout(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	content->resize(q->size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qDeleteAll(buttons); | 
					
						
							|  |  |  | 	buttons.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (QAction *action, q->actions()) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		QToolButton *button = new QToolButton(content); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		button->setDefaultAction(action); | 
					
						
							|  |  |  | 		button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 
					
						
							|  |  |  | 		buttons.append(button); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// AutoRaise reduces visual clutter, but we don't want to turn it on if
 | 
					
						
							|  |  |  | 	// there are other buttons, otherwise the close button will look different
 | 
					
						
							|  |  |  | 	// from the others.
 | 
					
						
							|  |  |  | 	closeButton->setAutoRaise(buttons.isEmpty()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wordWrap) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		QGridLayout *layout = new QGridLayout(content); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		// Set alignment to make sure icon does not move down if text wraps
 | 
					
						
							|  |  |  | 		layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop); | 
					
						
							|  |  |  | 		layout->addWidget(textLabel, 0, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 		QDialogButtonBox *buttonLayout = new QDialogButtonBox(); | 
					
						
							|  |  |  | 		//buttonLayout->addStretch();
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		Q_FOREACH (QToolButton *button, buttons) { | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 			// For some reason, calling show() is necessary if wordwrap is true,
 | 
					
						
							|  |  |  | 			// otherwise the buttons do not show up. It is not needed if
 | 
					
						
							|  |  |  | 			// wordwrap is false.
 | 
					
						
							|  |  |  | 			button->show(); | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 			buttonLayout->addButton(button, QDialogButtonBox::QDialogButtonBox::AcceptRole); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-08-04 22:30:09 -07:00
										 |  |  | 		buttonLayout->addButton(closeButton, QDialogButtonBox::RejectRole); | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 		layout->addWidget(buttonLayout, 1, 0, 1, 2, Qt::AlignHCenter | Qt::AlignTop); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-08-04 22:30:09 -07:00
										 |  |  | 		bool closeButtonVisible = closeButton->isVisible(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		QHBoxLayout *layout = new QHBoxLayout(content); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		layout->addWidget(iconLabel); | 
					
						
							|  |  |  | 		layout->addWidget(textLabel); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 		QDialogButtonBox *buttonLayout = new QDialogButtonBox(); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		Q_FOREACH (QToolButton *button, buttons) { | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 			buttonLayout->addButton(button, QDialogButtonBox::QDialogButtonBox::AcceptRole); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-04 22:30:09 -07:00
										 |  |  | 		buttonLayout->addButton(closeButton, QDialogButtonBox::RejectRole); | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 		// Something gets changed when added to the buttonLayout
 | 
					
						
							| 
									
										
										
										
											2014-08-04 22:30:09 -07:00
										 |  |  | 		closeButton->setVisible(closeButtonVisible); | 
					
						
							| 
									
										
										
										
											2014-07-02 22:59:32 +02:00
										 |  |  | 		layout->addWidget(buttonLayout); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (q->isVisible()) { | 
					
						
							|  |  |  | 		q->setFixedHeight(content->sizeHint().height()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	q->updateGeometry(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidgetPrivate::updateLayout() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (content->layout()) { | 
					
						
							|  |  |  | 		createLayout(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidgetPrivate::updateSnapShot() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Attention: updateSnapShot calls QWidget::render(), which causes the whole
 | 
					
						
							|  |  |  | 	// window layouts to be activated. Calling this method from resizeEvent()
 | 
					
						
							|  |  |  | 	// can lead to infinite recursion, see:
 | 
					
						
							|  |  |  | 	// https://bugs.kde.org/show_bug.cgi?id=311336
 | 
					
						
							|  |  |  | 	contentSnapShot = QPixmap(content->size()); | 
					
						
							|  |  |  | 	contentSnapShot.fill(Qt::transparent); | 
					
						
							|  |  |  | 	content->render(&contentSnapShot, QPoint(), QRegion(), QWidget::DrawChildren); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidgetPrivate::slotTimeLineChanged(qreal value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	q->setFixedHeight(qMin(value * 2, qreal(1.0)) * content->height()); | 
					
						
							|  |  |  | 	q->update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidgetPrivate::slotTimeLineFinished() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (timeLine->direction() == QTimeLine::Forward) { | 
					
						
							|  |  |  | 		// Show
 | 
					
						
							|  |  |  | 		// We set the whole geometry here, because it may be wrong if a
 | 
					
						
							|  |  |  | 		// KMessageWidget is shown right when the toplevel window is created.
 | 
					
						
							|  |  |  | 		content->setGeometry(0, 0, q->width(), bestContentHeight()); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// Hide
 | 
					
						
							|  |  |  | 		q->hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KMessageWidgetPrivate::bestContentHeight() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int height = content->heightForWidth(q->width()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (height == -1) { | 
					
						
							|  |  |  | 		height = content->sizeHint().height(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return height; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | // KMessageWidget
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | KMessageWidget::KMessageWidget(QWidget *parent) : QFrame(parent), d(new KMessageWidgetPrivate) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->init(this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | KMessageWidget::KMessageWidget(const QString &text, QWidget *parent) : QFrame(parent), d(new KMessageWidgetPrivate) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->init(this); | 
					
						
							|  |  |  | 	setText(text); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | KMessageWidget::~KMessageWidget() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete d; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString KMessageWidget::text() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return d->textLabel->text(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::setText(const QString &text) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->textLabel->setText(text); | 
					
						
							|  |  |  | 	updateGeometry(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | KMessageWidget::MessageType KMessageWidget::messageType() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return d->messageType; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidget::setMessageType(KMessageWidget::MessageType type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	d->messageType = type; | 
					
						
							|  |  |  | 	QColor bg0, bg1, bg2, border, fg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (type) { | 
					
						
							|  |  |  | 	case Positive: | 
					
						
							| 
									
										
										
										
											2013-05-17 22:52:04 -03:00
										 |  |  | 		bg1 = QColor("#72D594"); // nice green
 | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		fg = QColor(Qt::white); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case Information: | 
					
						
							| 
									
										
										
										
											2013-05-17 22:52:04 -03:00
										 |  |  | 		bg1 = QColor("#41A8E3"); // nice blue
 | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		fg = QColor(Qt::black); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case Warning: | 
					
						
							| 
									
										
										
										
											2013-05-17 22:52:04 -03:00
										 |  |  | 		bg1 = QColor("#72D594"); // nice yellow
 | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		fg = QColor(Qt::black); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case Error: | 
					
						
							| 
									
										
										
										
											2013-05-17 22:52:04 -03:00
										 |  |  | 		bg1 = QColor("#E4B7B7"); // nice red.
 | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		fg = QColor(Qt::black); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Colors
 | 
					
						
							|  |  |  | 	bg0 = bg1.lighter(110); | 
					
						
							|  |  |  | 	bg2 = bg1.darker(110); | 
					
						
							| 
									
										
										
										
											2013-05-17 22:52:04 -03:00
										 |  |  | 	border = bg2.darker(110); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 	d->content->setStyleSheet( | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		QString(".QFrame {" | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 			"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," | 
					
						
							|  |  |  | 			"    stop: 0 %1," | 
					
						
							|  |  |  | 			"    stop: 0.1 %2," | 
					
						
							|  |  |  | 			"    stop: 1.0 %3);" | 
					
						
							|  |  |  | 			"border-radius: 5px;" | 
					
						
							|  |  |  | 			"border: 1px solid %4;" | 
					
						
							|  |  |  | 			"margin: %5px;" | 
					
						
							|  |  |  | 			"}" | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			".QLabel { color: %6; }").arg(bg0.name()) | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 			.arg(bg1.name()) | 
					
						
							|  |  |  | 			.arg(bg2.name()) | 
					
						
							|  |  |  | 			.arg(border.name()) | 
					
						
							|  |  |  | 		/*
 | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		DefaultFrameWidth returns the size of the external margin + border width. | 
					
						
							|  |  |  | 		We know our border is 1px, so we subtract this from the frame | 
					
						
							|  |  |  | 		normal QStyle FrameWidth to get our margin | 
					
						
							|  |  |  | 		*/ | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 			.arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this) - 1) | 
					
						
							|  |  |  | 			.arg(fg.name())); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QSize KMessageWidget::sizeHint() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ensurePolished(); | 
					
						
							|  |  |  | 	return d->content->sizeHint(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QSize KMessageWidget::minimumSizeHint() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ensurePolished(); | 
					
						
							|  |  |  | 	return d->content->minimumSizeHint(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | bool KMessageWidget::event(QEvent *event) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (event->type() == QEvent::Polish && !d->content->layout()) { | 
					
						
							|  |  |  | 		d->createLayout(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return QFrame::event(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::resizeEvent(QResizeEvent *event) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	QFrame::resizeEvent(event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (d->timeLine->state() == QTimeLine::NotRunning) { | 
					
						
							|  |  |  | 		d->content->resize(width(), d->bestContentHeight()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int KMessageWidget::heightForWidth(int width) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ensurePolished(); | 
					
						
							|  |  |  | 	return d->content->heightForWidth(width); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::paintEvent(QPaintEvent *event) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	QFrame::paintEvent(event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (d->timeLine->state() == QTimeLine::Running) { | 
					
						
							|  |  |  | 		QPainter painter(this); | 
					
						
							|  |  |  | 		painter.setOpacity(d->timeLine->currentValue() * d->timeLine->currentValue()); | 
					
						
							|  |  |  | 		painter.drawPixmap(0, 0, d->contentSnapShot); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::showEvent(QShowEvent *event) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	// Keep this method here to avoid breaking binary compatibility:
 | 
					
						
							|  |  |  | 	// QFrame::showEvent() used to be reimplemented.
 | 
					
						
							|  |  |  | 	QFrame::showEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool KMessageWidget::wordWrap() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return d->wordWrap; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidget::setWordWrap(bool wordWrap) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	d->wordWrap = wordWrap; | 
					
						
							|  |  |  | 	d->textLabel->setWordWrap(wordWrap); | 
					
						
							|  |  |  | 	QSizePolicy policy = sizePolicy(); | 
					
						
							|  |  |  | 	policy.setHeightForWidth(wordWrap); | 
					
						
							|  |  |  | 	setSizePolicy(policy); | 
					
						
							|  |  |  | 	d->updateLayout(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Without this, when user does wordWrap -> !wordWrap -> wordWrap, a minimum
 | 
					
						
							|  |  |  | 	// height is set, causing the widget to be too high.
 | 
					
						
							|  |  |  | 	// Mostly visible in test programs.
 | 
					
						
							|  |  |  | 	if (wordWrap) { | 
					
						
							|  |  |  | 		setMinimumHeight(0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool KMessageWidget::isCloseButtonVisible() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return d->closeButton->isVisible(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidget::setCloseButtonVisible(bool show) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	d->closeButton->setVisible(show); | 
					
						
							|  |  |  | 	updateGeometry(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::addAction(QAction *action) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	QFrame::addAction(action); | 
					
						
							|  |  |  | 	d->updateLayout(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::removeAction(QAction *action) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	QFrame::removeAction(action); | 
					
						
							|  |  |  | 	d->updateLayout(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidget::animatedShow() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (isVisible()) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QFrame::show(); | 
					
						
							|  |  |  | 	setFixedHeight(0); | 
					
						
							|  |  |  | 	int wantedHeight = d->bestContentHeight(); | 
					
						
							|  |  |  | 	d->content->setGeometry(0, -wantedHeight, width(), wantedHeight); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	d->updateSnapShot(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	d->timeLine->setDirection(QTimeLine::Forward); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (d->timeLine->state() == QTimeLine::NotRunning) { | 
					
						
							|  |  |  | 		d->timeLine->start(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void KMessageWidget::animatedHide() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!isVisible()) { | 
					
						
							| 
									
										
										
										
											2013-09-18 23:23:04 -03:00
										 |  |  | 		hide(); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	d->content->move(0, -d->content->height()); | 
					
						
							|  |  |  | 	d->updateSnapShot(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	d->timeLine->setDirection(QTimeLine::Backward); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (d->timeLine->state() == QTimeLine::NotRunning) { | 
					
						
							|  |  |  | 		d->timeLine->start(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QIcon KMessageWidget::icon() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return d->icon; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void KMessageWidget::setIcon(const QIcon &icon) | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->icon = icon; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (d->icon.isNull()) { | 
					
						
							|  |  |  | 		d->iconLabel->hide(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		d->iconLabel->setPixmap(d->icon.pixmap(QSize(16, 16))); | 
					
						
							| 
									
										
										
										
											2013-05-17 21:58:49 -03:00
										 |  |  | 		d->iconLabel->show(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |