31 #include <QGridLayout>
32 #include <QHBoxLayout>
37 #include <QToolButton>
43 class KMessageWidgetPrivate
59 QPixmap contentSnapShot;
62 void updateSnapShot();
64 void slotTimeLineChanged(qreal);
65 void slotTimeLineFinished();
67 int bestContentHeight()
const;
74 q->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
76 timeLine =
new QTimeLine(500, q);
77 QObject::connect(timeLine, SIGNAL(valueChanged(qreal)), q, SLOT(slotTimeLineChanged(qreal)));
78 QObject::connect(timeLine, SIGNAL(finished()), q, SLOT(slotTimeLineFinished()));
81 content->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
85 iconLabel =
new QLabel(content);
86 iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
89 textLabel =
new QLabel(content);
90 textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
91 textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
92 QObject::connect(textLabel, SIGNAL(linkActivated(
const QString&)), q, SIGNAL(linkActivated(
const QString&)));
93 QObject::connect(textLabel, SIGNAL(linkHovered(
const QString&)), q, SIGNAL(linkHovered(
const QString&)));
98 closeButton->setAutoRaise(
true);
99 closeButton->setDefaultAction(closeAction);
104 void KMessageWidgetPrivate::createLayout()
106 delete content->layout();
108 content->resize(q->size());
113 Q_FOREACH(
QAction* action, q->actions()) {
115 button->setDefaultAction(action);
116 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
117 buttons.append(button);
123 closeButton->setAutoRaise(buttons.isEmpty());
126 QGridLayout* layout =
new QGridLayout(content);
128 layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
129 layout->addWidget(textLabel, 0, 1);
131 QHBoxLayout* buttonLayout =
new QHBoxLayout;
132 buttonLayout->addStretch();
138 buttonLayout->addWidget(button);
140 buttonLayout->addWidget(closeButton);
141 layout->addItem(buttonLayout, 1, 0, 1, 2);
143 QHBoxLayout* layout =
new QHBoxLayout(content);
144 layout->addWidget(iconLabel);
145 layout->addWidget(textLabel);
148 layout->addWidget(button);
151 layout->addWidget(closeButton);
154 if (q->isVisible()) {
155 q->setFixedHeight(content->sizeHint().height());
160 void KMessageWidgetPrivate::updateLayout()
162 if (content->layout()) {
167 void KMessageWidgetPrivate::updateSnapShot()
173 contentSnapShot = QPixmap(content->size());
174 contentSnapShot.fill(Qt::transparent);
175 content->render(&contentSnapShot,
QPoint(), QRegion(), QWidget::DrawChildren);
178 void KMessageWidgetPrivate::slotTimeLineChanged(qreal value)
180 q->setFixedHeight(qMin(value * 2, qreal(1.0)) * content->height());
184 void KMessageWidgetPrivate::slotTimeLineFinished()
190 content->setGeometry(0, 0, q->width(), bestContentHeight());
197 int KMessageWidgetPrivate::bestContentHeight()
const
199 int height = content->heightForWidth(q->width());
201 height = content->sizeHint().height();
212 , d(new KMessageWidgetPrivate)
219 , d(new KMessageWidgetPrivate)
232 return d->textLabel->text();
237 d->textLabel->setText(text);
243 return d->messageType;
255 d->messageType = type;
256 QColor bg0, bg1, bg2, border, fg;
264 bg1 = palette().highlight().color();
265 fg = palette().highlightedText().color();
276 bg0 = bg1.lighter(110);
277 bg2 = bg1.darker(110);
280 d->content->setStyleSheet(
282 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
286 "border-radius: 5px;"
287 "border: 1px solid %4;"
290 ".QLabel { color: %6; }"
297 .arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0,
this) -1)
305 return d->content->sizeHint();
311 return d->content->minimumSizeHint();
316 if (event->type() == QEvent::Polish && !d->content->layout()) {
319 return QFrame::event(event);
324 QFrame::resizeEvent(event);
326 if (d->timeLine->state() == QTimeLine::NotRunning) {
327 d->content->resize(width(), d->bestContentHeight());
334 return d->content->heightForWidth(width);
339 QFrame::paintEvent(event);
340 if (d->timeLine->state() == QTimeLine::Running) {
341 QPainter painter(
this);
342 painter.setOpacity(d->timeLine->currentValue() * d->timeLine->currentValue());
343 painter.drawPixmap(0, 0, d->contentSnapShot);
351 QFrame::showEvent(event);
362 d->textLabel->setWordWrap(wordWrap);
363 QSizePolicy policy = sizePolicy();
364 policy.setHeightForWidth(wordWrap);
365 setSizePolicy(policy);
377 return d->closeButton->isVisible();
382 d->closeButton->setVisible(show);
388 QFrame::addAction(action);
394 QFrame::removeAction(action);
411 int wantedHeight = d->bestContentHeight();
412 d->content->setGeometry(0, -wantedHeight, width(), wantedHeight);
417 if (d->timeLine->state() == QTimeLine::NotRunning) {
418 d->timeLine->start();
433 d->content->move(0, -d->content->height());
436 d->timeLine->setDirection(QTimeLine::Backward);
437 if (d->timeLine->state() == QTimeLine::NotRunning) {
438 d->timeLine->start();
450 if (d->icon.isNull()) {
451 d->iconLabel->hide();
454 d->iconLabel->setPixmap(d->icon.pixmap(size));
455 d->iconLabel->show();
460 #include "kmessagewidget.moc"