File indexing completed on 2024-04-28 15:29:14
0001 #include "kpassivepopuptest.h" 0002 #include <QApplication> 0003 #include <QPushButton> 0004 #include <kpassivepopup.h> 0005 0006 #include <kwindowsystem.h> 0007 0008 QPushButton *pb; 0009 QPushButton *pb2; 0010 QPushButton *pb3; 0011 QPushButton *pb4; 0012 QPushButton *pb5; 0013 QPushButton *pb6; 0014 QPushButton *pb7; 0015 QSystemTrayIcon *icon; 0016 0017 void Test::showIt() 0018 { 0019 KPassivePopup::message(QStringLiteral("Hello World"), pb); 0020 } 0021 0022 void Test::showIt2() 0023 { 0024 KPassivePopup::message(QStringLiteral("The caption is..."), QStringLiteral("Hello World"), pb2); 0025 } 0026 0027 void Test::showIt3() 0028 { 0029 KPassivePopup *pop = new KPassivePopup(); 0030 pop->setView(QStringLiteral("Caption"), QStringLiteral("test")); 0031 pop->show(); 0032 } 0033 0034 void Test::showIt4() 0035 { 0036 KPassivePopup::message(KPassivePopup::Boxed, QStringLiteral("The caption is..."), QStringLiteral("Hello World"), pb4); 0037 } 0038 0039 void Test::showIt5() 0040 { 0041 KPassivePopup::message(KPassivePopup::Balloon, QStringLiteral("The caption is..."), QStringLiteral("Hello World"), pb5); 0042 } 0043 0044 void Test::showIt6() 0045 { 0046 KPassivePopup::message(KPassivePopup::Boxed, QStringLiteral("The caption is..."), QStringLiteral("Hello World"), pb6); 0047 } 0048 0049 void Test::showIt7() 0050 { 0051 int iconDimension = QApplication::fontMetrics().height(); 0052 KPassivePopup::message(QStringLiteral("The caption is..."), 0053 QStringLiteral("Hello World"), 0054 QIcon::fromTheme(QStringLiteral("dialog-ok")).pixmap(iconDimension, iconDimension), 0055 pb2); 0056 } 0057 0058 void Test::showItIcon(QSystemTrayIcon::ActivationReason reason) 0059 { 0060 if (reason == QSystemTrayIcon::Trigger) { 0061 KPassivePopup::message(QStringLiteral("QSystemTrayIcon test"), QStringLiteral("Hello World"), icon); 0062 } 0063 } 0064 0065 int main(int argc, char **argv) 0066 { 0067 QApplication::setApplicationName(QStringLiteral("test")); 0068 QApplication app(argc, argv); 0069 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 0070 0071 Test *t = new Test(); 0072 0073 pb = new QPushButton(); 0074 pb->setText(QStringLiteral("By taskbar entry (no caption, default style)")); 0075 pb->connect(pb, &QAbstractButton::clicked, t, &Test::showIt); 0076 pb->show(); 0077 0078 pb2 = new QPushButton(); 0079 pb2->setText(QStringLiteral("By taskbar entry (with caption, default style)")); 0080 pb2->connect(pb2, &QAbstractButton::clicked, t, &Test::showIt2); 0081 pb2->show(); 0082 0083 pb3 = new QPushButton(); 0084 pb3->setText(QStringLiteral("Without WinID")); 0085 pb3->connect(pb3, &QAbstractButton::clicked, t, &Test::showIt3); 0086 pb3->show(); 0087 0088 pb4 = new QPushButton(); 0089 pb4->setText(QStringLiteral("By taskbar entry (with caption, boxed)")); 0090 pb4->connect(pb4, &QAbstractButton::clicked, t, &Test::showIt4); 0091 pb4->show(); 0092 0093 pb5 = new QPushButton(); 0094 pb5->setText(QStringLiteral("By taskbar entry (with caption, balloon)")); 0095 pb5->connect(pb5, &QAbstractButton::clicked, t, &Test::showIt5); 0096 pb5->show(); 0097 0098 // this test depends on X11 0099 pb6 = new QPushButton(); 0100 pb6->setText(QStringLiteral("By window (with caption, balloon)")); 0101 pb6->connect(pb6, &QAbstractButton::clicked, t, &Test::showIt6); 0102 pb6->show(); 0103 KWindowSystem::setState(pb6->effectiveWinId(), NET::SkipTaskbar); 0104 0105 pb7 = new QPushButton(); 0106 pb7->setText(QStringLiteral("By taskbar entry (with caption and icon, default style)")); 0107 pb7->connect(pb7, &QAbstractButton::clicked, t, &Test::showIt7); 0108 pb7->show(); 0109 0110 icon = new QSystemTrayIcon(); 0111 // TODO icon->setIcon(icon->loadIcon("xorg")); 0112 icon->connect(icon, &QSystemTrayIcon::activated, t, &Test::showItIcon); 0113 icon->show(); 0114 0115 return app.exec(); 0116 } 0117 0118 #include "moc_kpassivepopuptest.cpp"