Commit d299d6eb authored by René J.V. Bertin's avatar René J.V. Bertin
Browse files

add KMessage preview to the demo

Adds a preview of the 4 different KMessageWidget types to the frame
page, plus the magic required for detecting and reacting to colour
theme changes.

Differential Revision: https://phabricator.kde.org/D13881
parent 8ac3cd24
......@@ -29,13 +29,19 @@
#include <QButtonGroup>
#include <KComboBox>
#include <KMessageWidget>
#include <kwidgetsaddons_version.h>
namespace Oxygen
{
//_____________________________________________________________
FrameDemoWidget::FrameDemoWidget( QWidget* parent ):
DemoWidget( parent )
DemoWidget( parent ),
posMsg(nullptr),
infoMsg(nullptr),
warnMsg(nullptr),
errMsg(nullptr)
{
ui.setupUi( this );
......@@ -51,6 +57,60 @@ namespace Oxygen
connect( ui.directionComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateLayoutDirection(int)) );
connect( ui.flatGroupBoxCheckBox, SIGNAL(toggled(bool)), SLOT(toggleFlatGroupBox(bool)) );
addMessages();
#if KWIDGETSADDONS_VERSION < QT_VERSION_CHECK(5, 48, 0)
qApp->installEventFilter(this);
#endif
}
void FrameDemoWidget::addMessages()
{
delete posMsg;
delete infoMsg;
delete warnMsg;
delete errMsg;
posMsg = new KMessageWidget(QStringLiteral("A positive message"), ui.msgFrame);
posMsg->setMessageType(KMessageWidget::Positive);
posMsg->setWordWrap(true);
posMsg->setIcon(QIcon::fromTheme("dialog-positive"));
ui.verticalLayout_5->addWidget(posMsg);
infoMsg = new KMessageWidget(QStringLiteral("An information message"), ui.msgFrame);
infoMsg->setMessageType(KMessageWidget::Information);
infoMsg->setWordWrap(true);
infoMsg->setIcon(QIcon::fromTheme("dialog-information"));
ui.verticalLayout_5->addWidget(infoMsg);
warnMsg = new KMessageWidget(QStringLiteral("A warning message"), ui.msgFrame);
warnMsg->setMessageType(KMessageWidget::Warning);
warnMsg->setWordWrap(true);
warnMsg->setIcon(QIcon::fromTheme("dialog-warning"));
ui.verticalLayout_5->addWidget(warnMsg);
errMsg = new KMessageWidget(QStringLiteral("An error message"), ui.msgFrame);
errMsg->setMessageType(KMessageWidget::Error);
errMsg->setWordWrap(true);
errMsg->setIcon(QIcon::fromTheme("dialog-error"));
ui.verticalLayout_5->addWidget(errMsg);
ui.verticalLayout_5->addStretch();
}
bool FrameDemoWidget::eventFilter( QObject *obj, QEvent *event )
{
#if KWIDGETSADDONS_VERSION < QT_VERSION_CHECK(5, 48, 0)
if (event->type() == QEvent::DynamicPropertyChange && obj == qApp) {
QDynamicPropertyChangeEvent *e = dynamic_cast<QDynamicPropertyChangeEvent*>(event);
if (e->propertyName() == QByteArrayLiteral("KDE_COLOR_SCHEME_PATH")) {
addMessages();
}
}
#else
Q_UNUSED(obj);
Q_UNUSED(event);
#endif
return false;
}
//_____________________________________________________________
......
......@@ -34,6 +34,8 @@
#include "oxygendemowidget.h"
#include "ui_oxygenframedemowidget.h"
class KMessageWidget;
namespace Oxygen
{
class FrameDemoWidget: public DemoWidget
......@@ -46,6 +48,10 @@ namespace Oxygen
//* constructor
explicit FrameDemoWidget( QWidget* = 0 );
void addMessages();
bool eventFilter( QObject *obj, QEvent *event );
public Q_SLOTS:
//* benchmarking
......@@ -73,6 +79,7 @@ namespace Oxygen
private:
Ui_FrameDemoWidget ui;
KMessageWidget *posMsg, *infoMsg, *warnMsg, *errMsg;
};
......
......@@ -101,7 +101,7 @@
<item>
<widget class="QRadioButton" name="raisedFrameRadioButton">
<property name="text">
<string>Raised</string>
<string>&amp;Raised</string>
</property>
<property name="checked">
<bool>true</bool>
......@@ -114,7 +114,7 @@
<bool>true</bool>
</property>
<property name="text">
<string comment="Flat frame. No frame is actually drawn.">Flat</string>
<string comment="Flat frame. No frame is actually drawn.">&amp;Flat</string>
</property>
</widget>
</item>
......@@ -185,6 +185,19 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="msgLayout" stretch="1">
<item>
<widget class="QFrame" name="msgFrame">
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment