31 #include <QGridLayout>
32 #include <QHBoxLayout>
37 #include <QToolButton>
42 class KMessageWidgetPrivate
56 QList<QToolButton*> buttons;
57 QPixmap contentSnapShot;
60 void updateSnapShot();
62 void slotTimeLineChanged(qreal);
63 void slotTimeLineFinished();
65 int bestContentHeight()
const;
72 q->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
74 timeLine =
new QTimeLine(500, q);
75 QObject::connect(timeLine, SIGNAL(valueChanged(qreal)), q, SLOT(slotTimeLineChanged(qreal)));
76 QObject::connect(timeLine, SIGNAL(finished()), q, SLOT(slotTimeLineFinished()));
79 content->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
83 iconLabel =
new QLabel(content);
84 iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
86 textLabel =
new QLabel(content);
87 textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
88 textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
93 closeButton->setAutoRaise(
true);
94 closeButton->setDefaultAction(closeAction);
99 void KMessageWidgetPrivate::createLayout()
101 delete content->layout();
103 content->resize(q->size());
108 Q_FOREACH(
QAction* action, q->actions()) {
110 button->setDefaultAction(action);
111 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
112 buttons.append(button);
118 closeButton->setAutoRaise(buttons.isEmpty());
121 QGridLayout* layout =
new QGridLayout(content);
123 layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
124 layout->addWidget(textLabel, 0, 1);
126 QHBoxLayout* buttonLayout =
new QHBoxLayout;
127 buttonLayout->addStretch();
133 buttonLayout->addWidget(button);
135 buttonLayout->addWidget(closeButton);
136 layout->addItem(buttonLayout, 1, 0, 1, 2);
138 QHBoxLayout* layout =
new QHBoxLayout(content);
139 layout->addWidget(iconLabel);
140 layout->addWidget(textLabel);
143 layout->addWidget(button);
146 layout->addWidget(closeButton);
149 if (q->isVisible()) {
150 q->setFixedHeight(content->sizeHint().height());
155 void KMessageWidgetPrivate::updateLayout()
157 if (content->layout()) {
162 void KMessageWidgetPrivate::updateSnapShot()
164 contentSnapShot = QPixmap(content->size());
165 contentSnapShot.fill(Qt::transparent);
166 content->render(&contentSnapShot,
QPoint(), QRegion(), QWidget::DrawChildren);
169 void KMessageWidgetPrivate::slotTimeLineChanged(qreal value)
171 q->setFixedHeight(qMin(value * 2, qreal(1.0)) * content->height());
175 void KMessageWidgetPrivate::slotTimeLineFinished()
186 int KMessageWidgetPrivate::bestContentHeight()
const
188 int height = content->heightForWidth(q->width());
190 height = content->sizeHint().height();
201 , d(new KMessageWidgetPrivate)
208 , d(new KMessageWidgetPrivate)
221 return d->textLabel->text();
226 d->textLabel->setText(text);
232 return d->messageType;
244 d->messageType = type;
246 QColor bg0, bg1, bg2, border, fg;
249 icon =
KIcon(
"dialog-ok");
253 icon =
KIcon(
"dialog-information");
256 bg1 = palette().highlight().color();
257 fg = palette().highlightedText().color();
260 icon =
KIcon(
"dialog-warning");
264 icon =
KIcon(
"dialog-error");
270 bg0 = bg1.lighter(110);
271 bg2 = bg1.darker(110);
274 d->content->setStyleSheet(
276 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
280 "border-radius: 5px;"
281 "border: 1px solid %4;"
283 ".QLabel { color: %5; }"
294 d->iconLabel->setPixmap(icon.pixmap(size));
300 return d->content->sizeHint();
306 return d->content->minimumSizeHint();
311 if (event->type() == QEvent::Polish && !d->content->layout()) {
320 int contentHeight = d->bestContentHeight();
322 if (d->timeLine->state() == QTimeLine::NotRunning) {
323 d->content->resize(width(), contentHeight);
324 }
else if (event->size().width() !=
event->oldSize().width()) {
325 d->content->resize(width(), contentHeight);
333 return d->content->heightForWidth(width);
339 if (d->timeLine->state() == QTimeLine::Running) {
340 QPainter painter(
this);
341 painter.setOpacity(d->timeLine->currentValue() * d->timeLine->currentValue());
342 painter.drawPixmap(0, 0, d->contentSnapShot);
361 d->textLabel->setWordWrap(wordWrap);
362 QSizePolicy policy = sizePolicy();
363 policy.setHeightForWidth(wordWrap);
364 setSizePolicy(policy);
376 return d->closeButton->isVisible();
381 d->closeButton->setVisible(show);
410 int wantedHeight = d->bestContentHeight();
411 d->content->setGeometry(0, -wantedHeight, width(), wantedHeight);
416 if (d->timeLine->state() == QTimeLine::NotRunning) {
417 d->timeLine->start();
432 d->content->move(0, -d->content->height());
435 d->timeLine->setDirection(QTimeLine::Backward);
436 if (d->timeLine->state() == QTimeLine::NotRunning) {
437 d->timeLine->start();
441 #include "kmessagewidget.moc"