22#include <QtCore/QTimer>
23#include <QtGui/QMouseEvent>
24#include <QtGui/QFrame>
25#include <QtGui/QLabel>
26#include <QtGui/QLayout>
27#include <QtGui/QTextDocument>
32class KTitleWidget::Private
42 QString textStyleSheet()
const
44 return QString(
"QLabel { font-weight: bold; color: %1}").arg(q->palette().color(QPalette::WindowText).name());
47 QString commentStyleSheet()
const
50 switch (messageType) {
58 styleSheet = QString(
"QLabel { color: palette(%1); background: palette(%2); }").arg(q->palette().color(QPalette::HighlightedText).name()).arg(q->palette().color(QPalette::Highlight).name());
68 QGridLayout *headerLayout;
82 void _k_timeoutFinished()
92 return QLatin1String(
"dialog-information");
95 return QLatin1String(
"dialog-error");
98 return QLatin1String(
"dialog-warning");
112 titleFrame->setAutoFillBackground(
true);
113 titleFrame->setFrameShape(QFrame::StyledPanel);
114 titleFrame->setFrameShadow(QFrame::Plain);
115 titleFrame->setBackgroundRole(QPalette::Base);
118 d->headerLayout =
new QGridLayout(titleFrame);
119 d->headerLayout->setColumnStretch(0, 1);
120 d->headerLayout->setMargin(6);
122 d->textLabel =
new QLabel(titleFrame);
123 d->textLabel->setVisible(
false);
124 d->textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
126 d->imageLabel =
new QLabel(titleFrame);
127 d->imageLabel->setVisible(
false);
129 d->headerLayout->addWidget(d->textLabel, 0, 0);
130 d->headerLayout->addWidget(d->imageLabel, 0, 1, 1, 2);
132 d->commentLabel =
new QLabel(titleFrame);
133 d->commentLabel->setVisible(
false);
134 d->commentLabel->setOpenExternalLinks(
true);
135 d->commentLabel->setWordWrap(
true);
136 d->commentLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
137 d->headerLayout->addWidget(d->commentLabel, 1, 0);
141 QVBoxLayout *mainLayout =
new QVBoxLayout(
this);
142 mainLayout->addWidget(titleFrame);
143 mainLayout->setMargin(0);
144 setLayout(mainLayout);
155 if (d->autoHideTimeout > 0 &&
156 event->type() == QEvent::MouseButtonPress) {
157 QMouseEvent *mouseEvent =
static_cast<QMouseEvent*
>(event);
158 if (mouseEvent && mouseEvent->button() == Qt::LeftButton) {
164 return QWidget::eventFilter(
object, event);
169 d->headerLayout->addWidget(widget, 2, 0, 1, 2);
174 return d->textLabel->text();
179 return d->commentLabel->text();
184 return d->imageLabel->pixmap();
189 d->textLabel->setBuddy(buddy);
194 QWidget::changeEvent(e);
195 if (e->type() == QEvent::PaletteChange) {
196 d->textLabel->setStyleSheet(d->textStyleSheet());
197 d->commentLabel->setStyleSheet(d->commentStyleSheet());
203 d->textLabel->setVisible(!text.isNull());
205 if (!Qt::mightBeRichText(text)) {
206 d->textLabel->setStyleSheet(d->textStyleSheet());
209 d->textLabel->setText(text);
210 d->textLabel->setAlignment(alignment);
222 d->commentLabel->setVisible(!comment.isNull());
225 d->messageType = type;
226 d->commentLabel->setStyleSheet(d->commentStyleSheet());
227 d->commentLabel->setText(comment);
233 d->imageLabel->setVisible(!pixmap.isNull());
235 d->headerLayout->removeWidget(d->textLabel);
236 d->headerLayout->removeWidget(d->commentLabel);
237 d->headerLayout->removeWidget(d->imageLabel);
241 d->headerLayout->addWidget(d->imageLabel, 0, 0, 2, 1);
242 d->headerLayout->addWidget(d->textLabel, 0, 1);
243 d->headerLayout->addWidget(d->commentLabel, 1, 1);
244 d->headerLayout->setColumnStretch(0, 0);
245 d->headerLayout->setColumnStretch(1, 1);
247 d->headerLayout->addWidget(d->textLabel, 0, 0);
248 d->headerLayout->addWidget(d->commentLabel, 1, 0);
249 d->headerLayout->addWidget(d->imageLabel, 0, 1, 2, 1);
250 d->headerLayout->setColumnStretch(1, 0);
251 d->headerLayout->setColumnStretch(0, 1);
254 d->imageLabel->setPixmap(pixmap);
275 return d->autoHideTimeout;
280 d->autoHideTimeout = msecs;
283 installEventFilter(
this);
285 removeEventFilter(
this);
292 if (d->autoHideTimeout > 0) {
293 QTimer::singleShot(d->autoHideTimeout,
this, SLOT(_k_timeoutFinished()));
297#include "ktitlewidget.moc"
@ Dialog
Icons for use in dialog titles, page lists, etc.
A wrapper around QIcon that provides KDE icon features.
int IconSize(KIconLoader::Group group)