31 #include <QGridLayout>
32 #include <QHBoxLayout>
37 #include <QToolButton>
43 class KMessageWidgetPrivate
58 QPixmap contentSnapShot;
61 void updateSnapShot();
63 void slotTimeLineChanged(qreal);
64 void slotTimeLineFinished();
66 int bestContentHeight()
const;
73 q->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
75 timeLine =
new QTimeLine(500, q);
76 QObject::connect(timeLine, SIGNAL(valueChanged(qreal)), q, SLOT(slotTimeLineChanged(qreal)));
77 QObject::connect(timeLine, SIGNAL(finished()), q, SLOT(slotTimeLineFinished()));
80 content->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
84 iconLabel =
new QLabel(content);
85 iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
87 textLabel =
new QLabel(content);
88 textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
89 textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
90 QObject::connect(textLabel, SIGNAL(linkActivated(
const QString&)), q, SIGNAL(linkActivated(
const QString&)));
95 closeButton->setAutoRaise(
true);
96 closeButton->setDefaultAction(closeAction);
101 void KMessageWidgetPrivate::createLayout()
103 delete content->layout();
105 content->resize(q->size());
110 Q_FOREACH(
QAction* action, q->actions()) {
112 button->setDefaultAction(action);
113 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
114 buttons.append(button);
120 closeButton->setAutoRaise(buttons.isEmpty());
123 QGridLayout* layout =
new QGridLayout(content);
125 layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
126 layout->addWidget(textLabel, 0, 1);
128 QHBoxLayout* buttonLayout =
new QHBoxLayout;
129 buttonLayout->addStretch();
135 buttonLayout->addWidget(button);
137 buttonLayout->addWidget(closeButton);
138 layout->addItem(buttonLayout, 1, 0, 1, 2);
140 QHBoxLayout* layout =
new QHBoxLayout(content);
141 layout->addWidget(iconLabel);
142 layout->addWidget(textLabel);
145 layout->addWidget(button);
148 layout->addWidget(closeButton);
151 if (q->isVisible()) {
152 q->setFixedHeight(content->sizeHint().height());
157 void KMessageWidgetPrivate::updateLayout()
159 if (content->layout()) {
164 void KMessageWidgetPrivate::updateSnapShot()
170 contentSnapShot = QPixmap(content->size());
171 contentSnapShot.fill(Qt::transparent);
172 content->render(&contentSnapShot,
QPoint(), QRegion(), QWidget::DrawChildren);
175 void KMessageWidgetPrivate::slotTimeLineChanged(qreal value)
177 q->setFixedHeight(qMin(value * 2, qreal(1.0)) * content->height());
181 void KMessageWidgetPrivate::slotTimeLineFinished()
187 content->setGeometry(0, 0, q->width(), bestContentHeight());
194 int KMessageWidgetPrivate::bestContentHeight()
const
196 int height = content->heightForWidth(q->width());
198 height = content->sizeHint().height();
209 , d(new KMessageWidgetPrivate)
216 , d(new KMessageWidgetPrivate)
229 return d->textLabel->text();
234 d->textLabel->setText(text);
240 return d->messageType;
252 d->messageType = type;
254 QColor bg0, bg1, bg2, border, fg;
257 icon =
KIcon(
"dialog-ok");
261 icon =
KIcon(
"dialog-information");
264 bg1 = palette().highlight().color();
265 fg = palette().highlightedText().color();
268 icon =
KIcon(
"dialog-warning");
272 icon =
KIcon(
"dialog-error");
278 bg0 = bg1.lighter(110);
279 bg2 = bg1.darker(110);
282 d->content->setStyleSheet(
284 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
288 "border-radius: 5px;"
289 "border: 1px solid %4;"
292 ".QLabel { color: %6; }"
299 .arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0,
this) -1)
305 d->iconLabel->setPixmap(icon.pixmap(size));
311 return d->content->sizeHint();
317 return d->content->minimumSizeHint();
322 if (event->type() == QEvent::Polish && !d->content->layout()) {
325 return QFrame::event(event);
330 QFrame::resizeEvent(event);
332 if (d->timeLine->state() == QTimeLine::NotRunning) {
333 d->content->resize(width(), d->bestContentHeight());
340 return d->content->heightForWidth(width);
345 QFrame::paintEvent(event);
346 if (d->timeLine->state() == QTimeLine::Running) {
347 QPainter painter(
this);
348 painter.setOpacity(d->timeLine->currentValue() * d->timeLine->currentValue());
349 painter.drawPixmap(0, 0, d->contentSnapShot);
357 QFrame::showEvent(event);
368 d->textLabel->setWordWrap(wordWrap);
369 QSizePolicy policy = sizePolicy();
370 policy.setHeightForWidth(wordWrap);
371 setSizePolicy(policy);
383 return d->closeButton->isVisible();
388 d->closeButton->setVisible(show);
394 QFrame::addAction(action);
400 QFrame::removeAction(action);
417 int wantedHeight = d->bestContentHeight();
418 d->content->setGeometry(0, -wantedHeight, width(), wantedHeight);
423 if (d->timeLine->state() == QTimeLine::NotRunning) {
424 d->timeLine->start();
439 d->content->move(0, -d->content->height());
442 d->timeLine->setDirection(QTimeLine::Backward);
443 if (d->timeLine->state() == QTimeLine::NotRunning) {
444 d->timeLine->start();
448 #include "kmessagewidget.moc"