mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: drop unused KTitleWidget features
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
b9ccbf8b72
commit
ddd6e8a034
2 changed files with 45 additions and 205 deletions
|
@ -22,20 +22,17 @@
|
|||
#include "kiconloader.h"
|
||||
#include "kpixmapwidget.h"
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtGui/QFrame>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QLayout>
|
||||
#include <QtGui/QTextDocument>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
|
||||
class KTitleWidget::Private
|
||||
{
|
||||
public:
|
||||
Private(KTitleWidget* parent)
|
||||
: q(parent),
|
||||
autoHideTimeout(0),
|
||||
messageType(InfoMessage)
|
||||
Private()
|
||||
: titleLayout(nullptr),
|
||||
pixmapWidget(nullptr),
|
||||
textLabel(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -46,74 +43,14 @@ public:
|
|||
textLabel->setFont(f);
|
||||
}
|
||||
|
||||
void updateCommentWidget() const
|
||||
{
|
||||
// FIXME: need the usability color styles to implement different
|
||||
// yet palette appropriate colours for the different use cases!
|
||||
// also .. should an icon be included here, perhaps using the pixmapWidget?
|
||||
switch (messageType) {
|
||||
case InfoMessage:
|
||||
case WarningMessage:
|
||||
case ErrorMessage: {
|
||||
QPalette p = commentLabel->palette();
|
||||
const QColor c = q->palette().color(QPalette::HighlightedText);
|
||||
p.setColor(QPalette::Foreground, c);
|
||||
p.setColor(QPalette::Background, c);
|
||||
commentLabel->setPalette(p);
|
||||
break;
|
||||
}
|
||||
case PlainMessage:
|
||||
default: {
|
||||
QPalette p = commentLabel->palette();
|
||||
QColor c = q->palette().color(QPalette::Foreground);
|
||||
p.setColor(QPalette::Foreground, c);
|
||||
c = q->palette().color(QPalette::Background);
|
||||
p.setColor(QPalette::Background, c);
|
||||
commentLabel->setPalette(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KTitleWidget* q;
|
||||
QGridLayout *headerLayout;
|
||||
QHBoxLayout *titleLayout;
|
||||
KPixmapWidget *pixmapWidget;
|
||||
QLabel *textLabel;
|
||||
QLabel *commentLabel;
|
||||
int autoHideTimeout;
|
||||
MessageType messageType;
|
||||
|
||||
/**
|
||||
* @brief Get the icon name from the icon type
|
||||
* @param type icon type from the enum
|
||||
* @return named icon as QString
|
||||
*/
|
||||
QString iconTypeToIconName(KTitleWidget::MessageType type);
|
||||
|
||||
void _k_timeoutFinished()
|
||||
{
|
||||
q->setVisible(false);
|
||||
}
|
||||
};
|
||||
|
||||
QString KTitleWidget::Private::iconTypeToIconName(KTitleWidget::MessageType type)
|
||||
{
|
||||
switch (type) {
|
||||
case KTitleWidget::InfoMessage:
|
||||
return QLatin1String("dialog-information");
|
||||
case KTitleWidget::ErrorMessage:
|
||||
return QLatin1String("dialog-error");
|
||||
case KTitleWidget::WarningMessage:
|
||||
return QLatin1String("dialog-warning");
|
||||
case KTitleWidget::PlainMessage:
|
||||
break;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
KTitleWidget::KTitleWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
d(new Private(this))
|
||||
d(new Private())
|
||||
{
|
||||
QFrame *titleFrame = new QFrame(this);
|
||||
titleFrame->setAutoFillBackground(true);
|
||||
|
@ -122,9 +59,8 @@ KTitleWidget::KTitleWidget(QWidget *parent)
|
|||
titleFrame->setBackgroundRole(QPalette::Base);
|
||||
|
||||
// default image / text part start
|
||||
d->headerLayout = new QGridLayout(titleFrame);
|
||||
d->headerLayout->setColumnStretch(0, 1);
|
||||
d->headerLayout->setMargin(6);
|
||||
d->titleLayout = new QHBoxLayout(titleFrame);
|
||||
d->titleLayout->setMargin(6);
|
||||
|
||||
d->textLabel = new QLabel(titleFrame);
|
||||
d->textLabel->setVisible(false);
|
||||
|
@ -133,16 +69,9 @@ KTitleWidget::KTitleWidget(QWidget *parent)
|
|||
d->pixmapWidget = new KPixmapWidget(titleFrame);
|
||||
d->pixmapWidget->setVisible(false);
|
||||
|
||||
d->headerLayout->addWidget(d->textLabel, 0, 0);
|
||||
d->headerLayout->addWidget(d->pixmapWidget, 0, 1, 1, 2);
|
||||
|
||||
d->commentLabel = new QLabel(titleFrame);
|
||||
d->commentLabel->setVisible(false);
|
||||
d->commentLabel->setOpenExternalLinks(true);
|
||||
d->commentLabel->setWordWrap(true);
|
||||
d->commentLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||
d->headerLayout->addWidget(d->commentLabel, 1, 0);
|
||||
|
||||
d->titleLayout->addWidget(d->textLabel);
|
||||
d->titleLayout->addWidget(d->pixmapWidget);
|
||||
d->titleLayout->setStretchFactor(d->textLabel, 1);
|
||||
// default image / text part end
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
|
@ -156,36 +85,11 @@ KTitleWidget::~KTitleWidget()
|
|||
delete d;
|
||||
}
|
||||
|
||||
bool KTitleWidget::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
// Hide message label on click
|
||||
if (d->autoHideTimeout > 0 &&
|
||||
event->type() == QEvent::MouseButtonPress) {
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
if (mouseEvent && mouseEvent->button() == Qt::LeftButton) {
|
||||
setVisible(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(object, event);
|
||||
}
|
||||
|
||||
void KTitleWidget::setWidget(QWidget *widget)
|
||||
{
|
||||
d->headerLayout->addWidget(widget, 2, 0, 1, 2);
|
||||
}
|
||||
|
||||
QString KTitleWidget::text() const
|
||||
{
|
||||
return d->textLabel->text();
|
||||
}
|
||||
|
||||
QString KTitleWidget::comment() const
|
||||
{
|
||||
return d->commentLabel->text();
|
||||
}
|
||||
|
||||
QPixmap KTitleWidget::pixmap() const
|
||||
{
|
||||
return d->pixmapWidget->pixmap();
|
||||
|
@ -199,9 +103,8 @@ void KTitleWidget::setBuddy(QWidget *buddy)
|
|||
void KTitleWidget::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
if (e->type() == QEvent::PaletteChange || e->type() == QEvent::FontChange) {
|
||||
if (e->type() == QEvent::FontChange) {
|
||||
d->updateTextWidget();
|
||||
d->updateCommentWidget();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,80 +127,54 @@ void KTitleWidget::setText(const QString &text, MessageType type)
|
|||
setText(text);
|
||||
}
|
||||
|
||||
void KTitleWidget::setComment(const QString &comment, MessageType type)
|
||||
{
|
||||
d->commentLabel->setVisible(!comment.isNull());
|
||||
|
||||
//TODO: should we override the current icon with the corresponding MessageType icon?
|
||||
d->messageType = type;
|
||||
d->updateCommentWidget();
|
||||
d->commentLabel->setText(comment);
|
||||
show();
|
||||
}
|
||||
|
||||
void KTitleWidget::setPixmap(const QPixmap &pixmap, ImageAlignment alignment)
|
||||
{
|
||||
d->pixmapWidget->setVisible(!pixmap.isNull());
|
||||
|
||||
d->headerLayout->removeWidget(d->textLabel);
|
||||
d->headerLayout->removeWidget(d->commentLabel);
|
||||
d->headerLayout->removeWidget(d->pixmapWidget);
|
||||
d->titleLayout->removeWidget(d->textLabel);
|
||||
d->titleLayout->removeWidget(d->pixmapWidget);
|
||||
|
||||
if (alignment == ImageLeft) {
|
||||
// swap the text and image labels around
|
||||
d->headerLayout->addWidget(d->pixmapWidget, 0, 0, 2, 1);
|
||||
d->headerLayout->addWidget(d->textLabel, 0, 1);
|
||||
d->headerLayout->addWidget(d->commentLabel, 1, 1);
|
||||
d->headerLayout->setColumnStretch(0, 0);
|
||||
d->headerLayout->setColumnStretch(1, 1);
|
||||
d->titleLayout->addWidget(d->pixmapWidget);
|
||||
d->titleLayout->addWidget(d->textLabel);
|
||||
d->titleLayout->setStretchFactor(d->textLabel, 1);
|
||||
d->titleLayout->setStretchFactor(d->pixmapWidget, 0);
|
||||
} else {
|
||||
d->headerLayout->addWidget(d->textLabel, 0, 0);
|
||||
d->headerLayout->addWidget(d->commentLabel, 1, 0);
|
||||
d->headerLayout->addWidget(d->pixmapWidget, 0, 1, 2, 1);
|
||||
d->headerLayout->setColumnStretch(1, 0);
|
||||
d->headerLayout->setColumnStretch(0, 1);
|
||||
d->titleLayout->addWidget(d->textLabel);
|
||||
d->titleLayout->addWidget(d->pixmapWidget);
|
||||
d->titleLayout->setStretchFactor(d->textLabel, 1);
|
||||
d->titleLayout->setStretchFactor(d->pixmapWidget, 0);
|
||||
}
|
||||
|
||||
d->pixmapWidget->setPixmap(pixmap);
|
||||
}
|
||||
|
||||
|
||||
void KTitleWidget::setPixmap(const QString &icon, ImageAlignment alignment)
|
||||
{
|
||||
setPixmap(KIcon(icon), alignment);
|
||||
}
|
||||
|
||||
void KTitleWidget::setPixmap(const QIcon& icon, ImageAlignment alignment)
|
||||
void KTitleWidget::setPixmap(const QIcon &icon, ImageAlignment alignment)
|
||||
{
|
||||
setPixmap(icon.pixmap(IconSize(KIconLoader::Dialog)), alignment);
|
||||
}
|
||||
|
||||
void KTitleWidget::setPixmap(MessageType type, ImageAlignment alignment)
|
||||
{
|
||||
setPixmap(KIcon(d->iconTypeToIconName(type)), alignment);
|
||||
}
|
||||
|
||||
int KTitleWidget::autoHideTimeout() const
|
||||
{
|
||||
return d->autoHideTimeout;
|
||||
}
|
||||
|
||||
void KTitleWidget::setAutoHideTimeout(int msecs)
|
||||
{
|
||||
d->autoHideTimeout = msecs;
|
||||
|
||||
if (msecs > 0) {
|
||||
installEventFilter(this);
|
||||
} else {
|
||||
removeEventFilter(this);
|
||||
}
|
||||
}
|
||||
|
||||
void KTitleWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (d->autoHideTimeout > 0) {
|
||||
QTimer::singleShot(d->autoHideTimeout, this, SLOT(_k_timeoutFinished()));
|
||||
switch (type) {
|
||||
case KTitleWidget::InfoMessage:
|
||||
setPixmap(QLatin1String("dialog-information"), alignment);
|
||||
break;
|
||||
case KTitleWidget::ErrorMessage:
|
||||
setPixmap(QLatin1String("dialog-error"), alignment);
|
||||
break;
|
||||
case KTitleWidget::WarningMessage:
|
||||
setPixmap(QLatin1String("dialog-warning"), alignment);
|
||||
break;
|
||||
case KTitleWidget::PlainMessage:
|
||||
setPixmap(KIcon(), alignment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,7 @@ class KDEUI_EXPORT KTitleWidget : public QWidget
|
|||
Q_OBJECT
|
||||
Q_ENUMS(ImageAlignment)
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
|
||||
Q_PROPERTY(int autoHideTimeout READ autoHideTimeout WRITE setAutoHideTimeout)
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -80,13 +78,13 @@ public:
|
|||
};
|
||||
|
||||
/**
|
||||
* Comment message types
|
||||
* Message types
|
||||
*/
|
||||
enum MessageType {
|
||||
PlainMessage, /**< Normal comment */
|
||||
InfoMessage, /**< Information the user should be alerted to */
|
||||
PlainMessage, /**< Normal message */
|
||||
InfoMessage, /**< Information the user should be alerted to */
|
||||
WarningMessage, /**< A warning the user should be alerted to */
|
||||
ErrorMessage /**< An error message */
|
||||
ErrorMessage /**< An error message */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -96,23 +94,12 @@ public:
|
|||
|
||||
virtual ~KTitleWidget();
|
||||
|
||||
/**
|
||||
* @param widget Widget displayed on the title widget.
|
||||
*/
|
||||
void setWidget(QWidget *widget);
|
||||
|
||||
/**
|
||||
* @return the text displayed in the title
|
||||
* @see setText()
|
||||
*/
|
||||
QString text() const;
|
||||
|
||||
/**
|
||||
* @return the text displayed in the comment below the title, if any
|
||||
* @see setComment()
|
||||
*/
|
||||
QString comment() const;
|
||||
|
||||
/**
|
||||
* @return the pixmap displayed in the title
|
||||
* @see setPixmap()
|
||||
|
@ -128,12 +115,6 @@ public:
|
|||
*/
|
||||
void setBuddy(QWidget *buddy);
|
||||
|
||||
/**
|
||||
* Get the current timeout value in milliseconds
|
||||
* @return timeout value in msecs
|
||||
*/
|
||||
int autoHideTimeout() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* @param text Text displayed on the label. It can either be plain text or rich text. If it
|
||||
|
@ -150,14 +131,6 @@ public Q_SLOTS:
|
|||
*/
|
||||
void setText(const QString &text, MessageType type);
|
||||
|
||||
/**
|
||||
* @param comment Text displayed beneath the main title as a comment.
|
||||
* It can either be plain text or rich text.
|
||||
* @param type The sort of message it is. @see MessageType
|
||||
* @see comment()
|
||||
*/
|
||||
void setComment(const QString &comment, MessageType type = PlainMessage);
|
||||
|
||||
/**
|
||||
* @param pixmap Pixmap displayed in the header. The pixmap is by default right, but
|
||||
* @param alignment can be used to display it also left.
|
||||
|
@ -177,7 +150,7 @@ public Q_SLOTS:
|
|||
* @param alignment can be used to display it also left.
|
||||
* @see pixmap()
|
||||
*/
|
||||
void setPixmap(const QIcon& icon, ImageAlignment alignment = ImageRight);
|
||||
void setPixmap(const QIcon &icon, ImageAlignment alignment = ImageRight);
|
||||
|
||||
/**
|
||||
* @param pixmap the icon to display in the header. The pixmap is by default right, but
|
||||
|
@ -186,24 +159,14 @@ public Q_SLOTS:
|
|||
*/
|
||||
void setPixmap(MessageType type, ImageAlignment alignment = ImageRight);
|
||||
|
||||
/**
|
||||
* Set the autohide timeout of the label
|
||||
* Set value to 0 to disable autohide, which is the default.
|
||||
* @param msecs timeout value in milliseconds
|
||||
*/
|
||||
void setAutoHideTimeout(int msecs);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
void showEvent(QShowEvent *event);
|
||||
bool eventFilter(QObject *object, QEvent *event);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private* const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void _k_timeoutFinished())
|
||||
Q_DISABLE_COPY(KTitleWidget)
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // KTITLEWIDGET_H
|
||||
|
|
Loading…
Add table
Reference in a new issue