Advance Wayland and KDE package bring-up

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-04-14 10:51:06 +01:00
parent 51f3c21121
commit cf12defd28
15214 changed files with 20594243 additions and 269 deletions
@@ -0,0 +1,66 @@
include(ECMMarkAsTest)
find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test)
macro(kwidgetsaddons_executable_tests)
foreach(_testname ${ARGN})
add_executable(${_testname} ${_testname}.cpp)
target_link_libraries(${_testname} Qt6::Test KF6::WidgetsAddons)
ecm_mark_as_test(${_testname})
endforeach(_testname)
endmacro()
kwidgetsaddons_executable_tests(
kanimatedbuttontest
kbusyindicatorwidgettest
kcharselecttest
kcollapsiblegroupboxtest
kdatecomboboxtestapp
kdatepicktest
kdatepickerpopuptest
kdatetimeedittestapp
kgradientselectortest
kledtest
kmessageboxtest
kmessageboxwidtest
kselectactiontest
kseparatortest
ksqueezedtextlabeltest
ktitlewidgettest
kfontchooserdialogtest
kfontrequestertest
kpassworddialogtest
keditlistwidgettest
kratingwidgettest
kactionselectortest
kcolorcombotest
kpixmapregionselectordialogtest
ktoolbarlabelactiontest
kpagedialogtest
kpagewidgettest
kassistantdialogtest
kmessagewidgettest
kmessagedialogtest
knewpassworddialogtest
knewpasswordwidget_test
kpixmapsequenceoverlaypaintertest
kmimetypechoosertest
ksplittercollapserbuttongui_test
ktooltipwidget_test
kpasswordlineedit_test
ktwofingertap_test
ktwofingerswipe_test
)
add_executable(kdatetabletest kdatetabletest.cpp ../src/kdatetable.cpp)
target_include_directories(kdatetabletest PRIVATE ../src)
target_link_libraries(kdatetabletest Qt6::Widgets)
ecm_mark_as_test(kdatetabletest)
add_executable(kcolumnresizertestapp)
set(kcolumnresizertestapp_UI_SRCS)
qt_wrap_ui(kcolumnresizertestapp_UI_SRCS kcolumnresizertestapp.ui)
target_sources(kcolumnresizertestapp PRIVATE ${kcolumnresizertestapp_UI_SRCS} kcolumnresizertestapp.cpp)
target_link_libraries(kcolumnresizertestapp KF6::WidgetsAddons Qt6::Widgets)
ecm_mark_as_test(kcolumnresizertestapp)
@@ -0,0 +1,23 @@
/*
SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <kactionselector.h>
#include <QApplication>
#include <QListWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
KActionSelector actionSelector(nullptr);
actionSelector.availableListWidget()->addItems(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C") << QStringLiteral("D")
<< QStringLiteral("E"));
actionSelector.selectedListWidget()->addItems(QStringList() << QStringLiteral("1") << QStringLiteral("2"));
actionSelector.show();
return app.exec();
}
@@ -0,0 +1,71 @@
/*
SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kanimatedbuttontest.h"
#include "kanimatedbutton.h"
#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
#include <qlayout.h>
AnimationGroup::AnimationGroup(const QString &path, int size, QWidget *parent)
: QGroupBox(parent)
{
QHBoxLayout *lay = new QHBoxLayout(this);
m_animButton = new KAnimatedButton(this);
lay->addWidget(m_animButton);
QPushButton *start = new QPushButton(QStringLiteral("Start"), this);
lay->addWidget(start);
QPushButton *stop = new QPushButton(QStringLiteral("Stop"), this);
lay->addWidget(stop);
setTitle(QStringLiteral("%1 (%2)").arg(path).arg(size));
m_animButton->setIconSize(QSize(size, size));
m_animButton->setAnimationPath(path);
connect(start, &QAbstractButton::clicked, m_animButton, &KAnimatedButton::start);
connect(stop, &QAbstractButton::clicked, m_animButton, &KAnimatedButton::stop);
}
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *lay = new QVBoxLayout(this);
QWidget *top = new QWidget(this);
lay->addWidget(top);
QHBoxLayout *lay2 = new QHBoxLayout(top);
m_path = new QLineEdit(top);
lay2->addWidget(m_path);
m_size = new QSpinBox(top);
lay2->addWidget(m_size);
m_size->setValue(22);
connect(m_path, &QLineEdit::returnPressed, this, &MainWindow::slotAddNew);
}
void MainWindow::slotAddNew()
{
AnimationGroup *group = new AnimationGroup(m_path->text(), m_size->value(), this);
layout()->addWidget(group);
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kanimatedbuttontest"));
QApplication app(argc, argv);
MainWindow *window = new MainWindow();
window->show();
return app.exec();
}
#include "moc_kanimatedbuttontest.cpp"
@@ -0,0 +1,42 @@
/*
SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KANIMATEDBUTTONTEST_H
#define KANIMATEDBUTTONTEST_H
#include <QGroupBox>
class QLineEdit;
class QSpinBox;
class KAnimatedButton;
class AnimationGroup : public QGroupBox
{
Q_OBJECT
public:
AnimationGroup(const QString &name, int size, QWidget *parent = nullptr);
private:
KAnimatedButton *m_animButton;
};
class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
private Q_SLOTS:
void slotAddNew();
private:
QLineEdit *m_path;
QSpinBox *m_size;
};
#endif
@@ -0,0 +1,34 @@
/*
kassistantdialogtest - a test program for the KAssistantDialog class
SPDX-FileCopyrightText: 1998 Thomas Tanghus <tanghus@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <kassistantdialog.h>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("test"));
QApplication a(argc, argv);
KAssistantDialog *dlg = new KAssistantDialog();
QObject::connect(dlg, &QDialog::finished, &a, &QCoreApplication::quit);
for (int i = 1; i < 11; i++) {
QWidget *p = new QWidget;
QString msg = QStringLiteral("This is page %1 out of 10").arg(i);
QLabel *label = new QLabel(msg, p);
QHBoxLayout *layout = new QHBoxLayout(p);
label->setAlignment(Qt::AlignCenter);
label->setFixedSize(300, 200);
layout->addWidget(label);
QString title = QStringLiteral("%1. page").arg(i);
dlg->addPage(p, title);
}
dlg->show();
return a.exec();
}
@@ -0,0 +1,41 @@
/*
SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "kbusyindicatorwidget.h"
#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget window;
window.setBaseSize(128, 128);
auto layout = new QVBoxLayout(&window);
auto busyWidget = new QWidget(&window);
auto busyLayout = new QHBoxLayout(busyWidget);
auto busyIndicator = new KBusyIndicatorWidget(&window);
auto busyLabel = new QLabel(QStringLiteral("Busy..."), &window);
busyLayout->addWidget(busyIndicator);
busyLayout->addWidget(busyLabel);
auto toggle = new QPushButton(QStringLiteral("Toggle Visible"), &window);
QObject::connect(toggle, &QPushButton::clicked, busyWidget, [=] {
busyWidget->setVisible(!busyWidget->isVisible());
});
layout->addWidget(toggle);
layout->addWidget(busyWidget);
layout->setAlignment(Qt::AlignTop);
window.show();
return app.exec();
}
@@ -0,0 +1,18 @@
#include <QApplication>
#include "kcharselect.h"
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kcharselecttest"));
QApplication app(argc, argv);
KCharSelect selector(nullptr, nullptr);
selector.setAllPlanesEnabled(true);
selector.resize(selector.sizeHint());
selector.show();
selector.setWindowTitle(QStringLiteral("KCharSelect Test"));
return app.exec();
}
@@ -0,0 +1,74 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
Based on test program by Dominik Haumann <dhaumann@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QApplication>
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>
#include "kdatepicker.h"
#include <kcollapsiblegroupbox.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget mainWindow;
QVBoxLayout mainWindowLayout(&mainWindow);
// add a layout with many items to make sure it doesn't shuffle them weirdly when animating
{
auto groupBox = new KCollapsibleGroupBox;
groupBox->setTitle(QStringLiteral("&Advanced Options"));
auto *innerLayout = new QVBoxLayout(groupBox);
for (int i = 0; i < 6; i++) {
auto checkBox = new QCheckBox(QStringLiteral("Some text"));
innerLayout->addWidget(checkBox);
}
auto checkBox = new QCheckBox(QStringLiteral("Some really long text that goes on and on and on for ever and ever"));
innerLayout->addWidget(checkBox);
auto label = new QLabel(groupBox);
label->setText(QStringLiteral("Some input field:"));
// Word-wrapping in labels triggers a bug in the layout positioning.
label->setWordWrap(true);
innerLayout->addWidget(label);
auto lineEdit = new QLineEdit(groupBox);
innerLayout->addWidget(lineEdit);
auto hiddenCheckBox = new QCheckBox(QStringLiteral("This will be always hidden"));
innerLayout->addWidget(hiddenCheckBox);
hiddenCheckBox->hide();
mainWindowLayout.addWidget(groupBox);
}
// another item which should expand to fill width
{
auto groupBox = new KCollapsibleGroupBox;
groupBox->setTitle(QStringLiteral("Pick a &date"));
auto innerLayout = new QVBoxLayout(groupBox);
auto datePicker = new KDatePicker();
innerLayout->addWidget(datePicker);
mainWindowLayout.addWidget(groupBox);
}
mainWindowLayout.addStretch();
mainWindow.resize(400, 300);
mainWindow.show();
return app.exec();
}
// kate: replace-tabs on;
@@ -0,0 +1,139 @@
/*
This file is part of the KDE Libraries
SPDX-FileCopyrightText: 2007 David Jarvie <djarvie@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kcolorcombotest.h"
#include <QApplication>
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <kcolorcombo.h>
KColorComboTest::KColorComboTest(QWidget *widget)
: QWidget(widget)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
QHBoxLayout *hboxLayout = new QHBoxLayout(this);
// Standard color list
QLabel *lbl = new QLabel(QStringLiteral("&Standard colors:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
mStandard = new KColorCombo(this);
mStandard->setObjectName(QStringLiteral("StandardColors"));
lbl->setBuddy(mStandard);
QLabel *lblPreset = new QLabel(QStringLiteral("Preset to green (0,255,0)"), this);
// add to box layout
hboxLayout->addWidget(lbl);
hboxLayout->addWidget(mStandard);
hboxLayout->addWidget(lblPreset);
vbox->addLayout(hboxLayout);
hboxLayout = new QHBoxLayout(this);
// Custom color list
lbl = new QLabel(QStringLiteral("&Reds, greens, blues:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
mCustom = new KColorCombo(this);
mCustom->setObjectName(QStringLiteral("CustomColors"));
lbl->setBuddy(mCustom);
lblPreset = new QLabel(QStringLiteral("Preset to green (0,192,0)"), this);
// add to box layout
hboxLayout->addWidget(lbl);
hboxLayout->addWidget(mCustom);
hboxLayout->addWidget(lblPreset);
vbox->addLayout(hboxLayout);
// Create an exit button
mExit = new QPushButton(QStringLiteral("E&xit"), this);
QObject::connect(mExit, &QAbstractButton::clicked, this, &KColorComboTest::quitApp);
vbox->addWidget(mExit);
// Populate the custom list
QList<QColor> standardList;
standardList << Qt::red << Qt::green << Qt::blue << Qt::cyan << Qt::magenta << Qt::yellow << Qt::darkRed << Qt::darkGreen << Qt::darkBlue << Qt::darkCyan
<< Qt::darkMagenta << Qt::darkYellow << Qt::white << Qt::lightGray << Qt::gray << Qt::darkGray << Qt::black;
QList<QColor> list;
list << QColor(255, 0, 0) << QColor(192, 0, 0) << QColor(128, 0, 0) << QColor(64, 0, 0) << QColor(0, 255, 0) << QColor(0, 192, 0) << QColor(0, 128, 0)
<< QColor(0, 64, 0) << QColor(0, 0, 255) << QColor(0, 0, 192) << QColor(0, 0, 128) << QColor(0, 0, 64);
mCustom->setColors(list);
if (mCustom->colors() != list) {
qCritical() << "Custom combo: setColors() != colors()";
}
mCustom->setColors(QList<QColor>());
if (mCustom->colors() != standardList) {
qCritical() << "Custom combo: setColors(empty) != standard colors";
}
mCustom->setColors(list);
if (mCustom->colors() != list) {
qCritical() << "Custom combo: setColors() != colors()";
}
if (mStandard->colors() != standardList) {
qCritical() << "Standard combo: colors()";
}
QColor col = QColor(1, 2, 3);
mStandard->setColor(col);
if (mStandard->color() != col) {
qCritical() << "Standard combo: set custom color -> " << mStandard->color().red() << "," << mStandard->color().green() << ","
<< mStandard->color().blue();
}
if (!mStandard->isCustomColor()) {
qCritical() << "Standard combo: custom color: isCustomColor() -> false";
}
mStandard->setColor(Qt::green);
if (mStandard->color() != Qt::green) {
qCritical() << "Standard combo: color() -> " << mStandard->color().red() << "," << mStandard->color().green() << "," << mStandard->color().blue();
}
if (mStandard->isCustomColor()) {
qCritical() << "Standard combo: standard color: isCustomColor() -> true";
}
col = QColor(1, 2, 3);
mCustom->setColor(col);
if (mCustom->color() != col) {
qCritical() << "Custom combo: set custom color -> " << mCustom->color().red() << "," << mCustom->color().green() << "," << mCustom->color().blue();
}
if (!mCustom->isCustomColor()) {
qCritical() << "Custom combo: custom color: isCustomColor() -> false";
}
col = QColor(0, 192, 0);
mCustom->setColor(col);
if (mCustom->color() != col) {
qCritical() << "Custom combo: color() -> " << mCustom->color().red() << "," << mCustom->color().green() << "," << mCustom->color().blue();
}
if (mCustom->isCustomColor()) {
qCritical() << "Custom combo: standard color: isCustomColor() -> true";
}
}
KColorComboTest::~KColorComboTest()
{
}
void KColorComboTest::quitApp()
{
qApp->closeAllWindows();
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
KColorComboTest *t = new KColorComboTest;
t->show();
return a.exec();
}
#include "moc_kcolorcombotest.cpp"
@@ -0,0 +1,26 @@
#ifndef _KCOLORCOMBOTEST_H
#define _KCOLORCOMBOTEST_H
#include <QWidget>
class QPushButton;
class KColorCombo;
class KColorComboTest : public QWidget
{
Q_OBJECT
public:
KColorComboTest(QWidget *parent = nullptr);
~KColorComboTest() override;
private Q_SLOTS:
void quitApp();
protected:
KColorCombo *mStandard;
KColorCombo *mCustom;
QPushButton *mExit;
};
#endif
@@ -0,0 +1,51 @@
/*
This file is part of the KDE frameworks
SPDX-FileCopyrightText: 2011-2014 Aurélien Gâteau <agateau@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <kcolumnresizertestapp.h>
#include <QApplication>
#include <kcolumnresizer.h>
#include <ui_kcolumnresizertestapp.h>
Window::Window()
{
m_ui = new Ui_ColumnResizerTestWidget;
m_ui->setupUi(this);
KColumnResizer *resizer = new KColumnResizer(this);
resizer->addWidgetsFromLayout(m_ui->gridGroupBox1->layout(), 0);
resizer->addWidgetsFromLayout(m_ui->formGroupBox1->layout(), 0);
resizer->addWidgetsFromLayout(m_ui->formGroupBox2->layout(), 0);
resizer->addWidgetsFromLayout(m_ui->gridGroupBox2->layout(), 0);
connect(m_ui->spinBox, &QSpinBox::valueChanged, this, &Window::updateAdjustableLabel);
updateAdjustableLabel();
}
Window::~Window()
{
delete m_ui;
}
void Window::updateAdjustableLabel()
{
QString txt;
txt.fill(QLatin1Char('#'), m_ui->spinBox->value());
m_ui->adjustableLabel->setText(QStringLiteral("Spin me %1:").arg(txt));
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
#include "moc_kcolumnresizertestapp.cpp"
@@ -0,0 +1,28 @@
/*
This file is part of the KDE frameworks
SPDX-FileCopyrightText: 2011-2014 Aurélien Gâteau <agateau@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef KCOLUMNRESIZERTESTAPP_H
#define KCOLUMNRESIZERTESTAPP_H
#include <QWidget>
class Ui_ColumnResizerTestWidget;
class Window : public QWidget
{
Q_OBJECT
public:
Window();
~Window() override;
public Q_SLOTS:
void updateAdjustableLabel();
private:
Ui_ColumnResizerTestWidget *m_ui;
};
#endif /* KCOLUMNRESIZERTESTAPP_H */
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ColumnResizerTestWidget</class>
<widget class="QWidget" name="Co&amp;lumnResizerDemoWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>580</height>
</rect>
</property>
<property name="windowTitle">
<string>ColumnResizer Test</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="gridGroupBox1">
<property name="title">
<string>GridLayout</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>A line edit:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="adjustableLabel">
<property name="text">
<string>Spin me:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>A check box</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="formGroupBox1">
<property name="title">
<string>FormLayout</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>One line:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_2"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>A much bigger text area:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="formGroupBox2">
<property name="title">
<string>FormLayout2</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="2" column="1">
<widget class="QTimeEdit" name="timeEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>Show seconds</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Details:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>Option &amp;1</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>Option &amp;2</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gridGroupBox2">
<property name="title">
<string>Crazy QGridLayout</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<widget class="QPushButton" name="pushButton_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,46 @@
/*
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kdatecombobox.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDate>
#include <QDebug>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("test"));
QApplication app{argc, argv};
QCommandLineParser parser;
parser.addHelpOption();
parser.addOption({QStringLiteral("min-date"), QStringLiteral("Minimum date in ISO 8601 format, e.g. 2020-02-02"), QStringLiteral("min-date")});
parser.addOption({QStringLiteral("max-date"), QStringLiteral("Maximum date in ISO 8601 format, e.g. 2121-12-12"), QStringLiteral("max-date")});
parser.process(app.arguments());
const auto minDate = QDate::fromString(parser.value(QStringLiteral("min-date")), Qt::ISODate);
const auto maxDate = QDate::fromString(parser.value(QStringLiteral("max-date")), Qt::ISODate);
KDateComboBox dateComboBox;
dateComboBox.setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords
| KDateComboBox::WarnOnInvalid);
dateComboBox.setMinimumDate(minDate);
dateComboBox.setMaximumDate(maxDate);
QObject::connect(&dateComboBox, &KDateComboBox::dateEntered, [](const QDate &d) {
qDebug() << "dateEntered" << d;
});
QObject::connect(&dateComboBox, &KDateComboBox::dateChanged, [](const QDate &d) {
qDebug() << "dateChanged" << d;
});
QObject::connect(&dateComboBox, &KDateComboBox::dateEdited, [](const QDate &d) {
qDebug() << "dateEdited" << d;
});
dateComboBox.resize(200, dateComboBox.sizeHint().height());
dateComboBox.show();
// dateComboBox.setEnabled(false);
return app.exec();
}
@@ -0,0 +1,26 @@
/*
SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <KDatePickerPopup>
#include <QApplication>
#include <QDebug>
#include <QToolButton>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QToolButton button;
button.setIcon(QIcon::fromTheme(QStringLiteral("view-calendar")));
KDatePickerPopup popup(KDatePickerPopup::DatePicker | KDatePickerPopup::Words | KDatePickerPopup::NoDate);
QObject::connect(&popup, &KDatePickerPopup::dateChanged, &app, [](QDate date) {
qInfo() << date;
});
button.setMenu(&popup);
button.show();
return app.exec();
}
@@ -0,0 +1,46 @@
/*
SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "kdatepicker.h"
#include <QApplication>
#include <QTimer>
class Manager : public QObject
{
Q_OBJECT
public:
Manager()
{
picker.show();
QTimer::singleShot(1000, this, &Manager::timeout1);
QTimer::singleShot(5000, this, &Manager::timeout2);
}
private Q_SLOTS:
void timeout1()
{
picker.setEnabled(false);
}
void timeout2()
{
picker.setEnabled(true);
}
private:
KDatePicker picker;
};
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("KDatePickertest"));
QApplication app(argc, argv);
Manager mgr;
return app.exec();
}
#include <kdatepicktest.moc>
@@ -0,0 +1,16 @@
#include <QApplication>
#include "kdatetable_p.h"
#include <QDate>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("test"));
QApplication app(argc, argv);
KDateTable widget;
widget.setCustomDatePainting(QDate::currentDate().addDays(-3), QColor("green"), KDateTable::CircleMode, QColor("yellow"));
widget.show();
return app.exec();
}
@@ -0,0 +1,24 @@
#include "kdatetimeedit.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("test"));
QApplication app(argc, argv);
KDateTimeEdit dateTimeEdit;
dateTimeEdit.setOptions(dateTimeEdit.options() | KDateTimeEdit::ShowCalendar | KDateTimeEdit::SelectCalendar | KDateTimeEdit::ShowTimeZone
| KDateTimeEdit::SelectTimeZone);
QObject::connect(&dateTimeEdit, &KDateTimeEdit::dateTimeEntered, [](const QDateTime &dt) {
qDebug() << "dateTimeEntered" << dt;
});
QObject::connect(&dateTimeEdit, &KDateTimeEdit::dateTimeChanged, [](const QDateTime &dt) {
qDebug() << "dateTimeChanged" << dt;
});
QObject::connect(&dateTimeEdit, &KDateTimeEdit::dateTimeEdited, [](const QDateTime &dt) {
qDebug() << "dateTimeEdited" << dt;
});
dateTimeEdit.show();
// dateTimeEdit.setEnabled(false);
return app.exec();
}
@@ -0,0 +1,54 @@
#include <QDialog>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <qapplication.h>
#include <QDebug>
#include <keditlistwidget.h>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
#if 0
KEditListWidget::CustomEditor editor(new KComboBox(true, 0));
KEditListWidget *box = new KEditListWidget(editor);
box->insertItem(QStringLiteral("Test"));
box->insertItem(QStringLiteral("for"));
box->insertItem(QStringLiteral("this"));
box->insertItem(QStringLiteral("KEditListWidget"));
box->insertItem(QStringLiteral("Widget"));
box->show();
#else
// code from kexi
QStringList list;
list << QStringLiteral("one") << QStringLiteral("two");
QDialog dialog;
dialog.setObjectName(QStringLiteral("stringlist_dialog"));
dialog.setModal(true);
dialog.setWindowTitle(QStringLiteral("Edit List of Items"));
KEditListWidget *edit = new KEditListWidget(&dialog);
edit->setObjectName(QStringLiteral("editlist"));
edit->insertStringList(list);
QDialogButtonBox *buttonBox = new QDialogButtonBox(&dialog);
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
auto *layout = new QVBoxLayout(&dialog);
layout->addWidget(edit);
layout->addWidget(buttonBox);
if (dialog.exec() == QDialog::Accepted) {
list = edit->items();
qDebug() << list;
}
#endif
return app.exec();
}
@@ -0,0 +1,40 @@
/*
SPDX-FileCopyrightText: 1996 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kfontchooserdialog.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("KFontChooserDialogTest"));
QApplication app(argc, argv);
QFont font;
// Use a font with an unusual styleName
font.fromString(QStringLiteral("Noto Sans,13,-1,5,87,1,0,0,0,0,Black Italic"));
qDebug() << "Default use case, all bells and whistles";
int nRet = KFontChooserDialog::getFont(font);
qDebug() << font.toString();
qDebug() << "Only show monospaced fonts, FixedOnly checkbox is _not_ shown";
nRet = KFontChooserDialog::getFont(font, KFontChooser::FixedFontsOnly);
qDebug() << font.toString();
KFontChooser::FontDiffFlags diffFlags;
qDebug() << "ShowDifferences mode";
nRet = KFontChooserDialog::getFontDiff(font, diffFlags);
qDebug() << font.toString();
qDebug() << "ShowDifferences mode and only showing monospaced fonts (the FixedOnly checkbox is _not_ shown)";
nRet = KFontChooserDialog::getFontDiff(font, diffFlags, KFontChooser::FixedFontsOnly);
qDebug() << font.toString();
return nRet;
}
@@ -0,0 +1,42 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2013 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include <QApplication>
#include <QVBoxLayout>
#include <kfontrequester.h>
class KFontRequesterTest : public QWidget
{
public:
KFontRequesterTest(QWidget *parent = nullptr)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
KFontRequester *test1 = new KFontRequester(this);
mainLayout->addWidget(test1);
KFontRequester *test2 = new KFontRequester(this);
test2->setSampleText(QStringLiteral("This is different sample text"));
test2->setTitle(QStringLiteral("A different title"));
test2->setFont(QFont(QStringLiteral("comic-sans"), 12, 1));
mainLayout->addWidget(test2);
}
};
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kfontrequestertest"));
QApplication app(argc, argv);
KFontRequesterTest *mainWidget = new KFontRequesterTest;
mainWidget->show();
return app.exec();
}
@@ -0,0 +1,45 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2022 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <KGradientSelector>
#include <QApplication>
#include <QCheckBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class KSelectorTestWidget : public QWidget
{
public:
KSelectorTestWidget(QWidget *parent = nullptr)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
auto label = new QLabel(QStringLiteral("Gradient box"));
mainLayout->addWidget(label);
auto selector = new KGradientSelector(Qt::Horizontal, this);
selector->setFixedSize(256, 26);
selector->setIndent(true);
selector->setArrowDirection(Qt::DownArrow);
selector->setRange(0, 255);
mainLayout->addWidget(selector);
}
};
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("ktitlewidgettest"));
QApplication app(argc, argv);
KSelectorTestWidget *mainWidget = new KSelectorTestWidget;
mainWidget->show();
return app.exec();
}
@@ -0,0 +1,149 @@
#include "kledtest.h"
#include "kled.h"
#include <qapplication.h>
KLedTest::KLedTest(QWidget *parent)
: QWidget(parent)
, LedWidth(16)
, LedHeight(10)
, Grid(3)
, ledcolor(0)
, ledlook(KLed::Flat)
, kled_round(true) // Switch HERE between rectangle and circular leds
{
if (kled_round) {
// KLed l(KLed::red, &qw); // create lamp
// KLed l(KLed::blue, &qw); // create lamp
l = new KLed(Qt::green, this); // create lamp
// KLed l(KLed::yellow, &qw); // create lamp
// KLed l(KLed::orange, &qw); // create lamp
l->resize(16, 30);
// l.setLook(KLed::flat);
l->setShape(KLed::Circular);
// l->setShape(KLed::Rectangular);
// l->setLook(KLed::Flat);
// l->setLook(KLed::Flat);
// l->setLook(KLed::Flat);
l->move(5, 5);
// ktmp tmpobj(l);
t_toggle.setSingleShot(false);
t_toggle.start(1000);
t_color.setSingleShot(false);
t_color.start(3500);
t_look.setSingleShot(false);
t_look.start(3500);
QObject::connect(&t_toggle, &QTimer::timeout, l, &KLed::toggle);
QObject::connect(&t_color, &QTimer::timeout, this, &KLedTest::nextColor);
QObject::connect(&t_look, &QTimer::timeout, this, &KLedTest::nextLook);
l->show();
resize(240, 140);
} else {
y = Grid;
index = 0;
for (int shape = 0; (int)shape < 2; shape = (KLed::Shape)(shape + 1)) {
x = Grid;
for (int look = 0; (int)look < 3; look = (KLed::Look)(look + 1)) {
for (state = KLed::Off; (int)state < 2; state = (KLed::State)(state + 1)) {
leds[index] = new KLed(Qt::yellow, state, (KLed::Look)(look + 1), (KLed::Shape)(shape + 1), this);
leds[index]->setGeometry(x, y, LedWidth, LedHeight);
++index;
x += Grid + LedWidth;
}
}
y += Grid + LedHeight;
}
setFixedSize(x + Grid, y + Grid);
connect(&timer, &QTimer::timeout, this, &KLedTest::timeout);
timer.start(500);
}
}
KLedTest::~KLedTest()
{
if (kled_round) {
delete l;
}
}
void KLedTest::nextColor()
{
ledcolor++;
ledcolor %= 4;
switch (ledcolor) {
default:
case 0:
l->setColor(Qt::green);
break;
case 1:
l->setColor(Qt::blue);
break;
case 2:
l->setColor(Qt::red);
break;
case 3:
l->setColor(Qt::yellow);
break;
}
}
void KLedTest::nextLook()
{
int tmp;
if (kled_round) {
tmp = (static_cast<int>(ledlook) + 1) % 3;
} else {
tmp = (static_cast<int>(ledlook) + 1) % 3;
}
ledlook = static_cast<KLed::Look>(tmp);
l->setLook(ledlook);
// qDebug("painting look %i", ledlook);
// l->repaint();
}
void KLedTest::timeout()
{
const int NoOfLeds = sizeof(leds) / sizeof(leds[0]);
int count;
// -----
for (count = 0; count < NoOfLeds; ++count) {
if (leds[count]->state() == KLed::Off) {
leds[count]->setState(KLed::On);
} else {
leds[count]->setState(KLed::Off);
}
}
}
/*#include <stdio.h>*/
int main(int argc, char **argv)
{
QApplication a(argc, argv);
KLedTest widget;
// -----
/*
if (argc>1) { // look out for round or circular led command
if (strncmp(argv[1],"-c",2)) {
// paint circular
printf("painting circular led\n");
widget.kled_round = true;
}
else if (strncmp(argv[1],"-r",2)) {
// paint rectangle
printf("painting rectangular led\n");
widget.kled_round = false;
}
}
*/
widget.show();
return a.exec(); // go
}
#include "moc_kledtest.cpp"
@@ -0,0 +1,45 @@
#ifndef kledtest_h
#define kledtest_h
#include <QTimer>
#include <QWidget>
#include <kled.h>
#include <stdlib.h>
class KLedTest : public QWidget
{
Q_OBJECT
protected:
QTimer timer;
KLed *leds[/*KLed::NoOfShapes*/ 2 * /*KLed::NoOfLooks*/ 3 * /*KLed::NoOfStates*/ 2];
const int LedWidth;
const int LedHeight;
const int Grid;
KLed::Shape shape;
KLed::Look look;
KLed::State state;
int x, y, index;
QTimer t_toggle, t_color, t_look;
// KLed *l; // create lamp
// KLed *l; // create lamp
KLed *l; // create lamp
// KLed *l; // create lamp
// KLed *l; // create lamp
int ledcolor;
KLed::Look ledlook;
public:
KLedTest(QWidget *parent = nullptr);
~KLedTest() override;
bool kled_round;
public Q_SLOTS:
void timeout();
void nextColor();
void nextLook();
};
#endif
@@ -0,0 +1,382 @@
#undef QT_NO_CAST_FROM_ASCII
#include "kmessagebox.h"
#include <QLabel>
#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
class ExampleWidget : public QLabel
{
public:
ExampleWidget(QWidget *parent = nullptr);
};
ExampleWidget::ExampleWidget(QWidget *parent)
: QLabel(parent)
{
// Make the top-level layout; a vertical box to contain all widgets
// and sub-layouts.
QSize sh;
setText(QStringLiteral("<p>Hello.</p>"));
sh = sizeHint();
qWarning("SizeHint = %d x %d", sh.width(), sh.height());
setText(QStringLiteral("Hello."));
sh = sizeHint();
qWarning("SizeHint = %d x %d", sh.width(), sh.height());
setText(QStringLiteral("<p>Hello<br>World</p>"));
sh = sizeHint();
qWarning("SizeHint = %d x %d", sh.width(), sh.height());
// setText("Hello\nWorld");
sh = sizeHint();
qWarning("SizeHint = %d x %d", sh.width(), sh.height());
setMinimumSize(sizeHint());
}
void showResult(int test, int i)
{
printf("Test %d. returned %d ", test, i);
switch (i) {
case KMessageBox::Ok:
printf("(%s)\n", "Ok");
break;
case KMessageBox::Cancel:
printf("(%s)\n", "Cancel");
break;
case KMessageBox::PrimaryAction:
printf("(%s)\n", "PrimaryAction");
break;
case KMessageBox::SecondaryAction:
printf("(%s)\n", "SecondaryAction");
break;
case KMessageBox::Continue:
printf("(%s)\n", "Continue");
break;
default:
printf("(%s)\n", "ERROR!");
exit(1);
}
}
bool testMessageBox(int test)
{
QStringList list;
list.append(QStringLiteral("Hello"));
list.append(QStringLiteral("World"));
int i;
switch (test) {
case 1: {
ExampleWidget *w = new ExampleWidget();
w->show();
i = KMessageBox::warningContinueCancel(w,
QString::fromLatin1("You are about to <Print>.\n"
"Are you sure?"),
QStringLiteral("Print"),
KGuiItem(QStringLiteral("&Print")),
KStandardGuiItem::cancel(),
QStringLiteral("dontask"));
i = KMessageBox::warningContinueCancel(nullptr,
QString::fromLatin1("You are about to <Print>.\n"
"Are you sure?"),
QStringLiteral("Print"),
KGuiItem(QStringLiteral("&Print")),
KStandardGuiItem::cancel(),
QStringLiteral("dontask"),
KMessageBox::AllowLink);
i = KMessageBox::questionTwoActions(
nullptr,
QStringLiteral("<p>Do you have a printer? thisisaverylongdkldhklghklghklashgkllasghkdlsghkldfghklsabla bla bbla bla. It "
"also has <a href=http://www.kde.org>this URL</a>.</p>"),
QStringLiteral("Bla"),
KGuiItem(QStringLiteral("Scan")),
KGuiItem(QStringLiteral("Select")),
QStringLiteral("bla"),
KMessageBox::AllowLink);
break;
}
case 2:
i = KMessageBox::questionTwoActions(nullptr,
QStringLiteral("Does your printer support color or only black and white?"),
QStringLiteral("Printer setup"),
KGuiItem(QStringLiteral("Print Color")),
KGuiItem(QLatin1String("Print Black & White")));
break;
case 3:
i = KMessageBox::warningTwoActions(nullptr,
QStringLiteral("Your printer has been added.\n"
"Do you want to update your configuration?"),
QStringLiteral("Printer Setup"),
KGuiItem(QStringLiteral("Update")),
KGuiItem(QStringLiteral("Skip")));
break;
case 4:
i = KMessageBox::warningContinueCancel(nullptr,
QString::fromLatin1("You are about to print.\n"
"Are you sure?"),
QStringLiteral("Print"),
KGuiItem(QStringLiteral("&Print")));
break;
case 5:
i = KMessageBox::warningContinueCancel(nullptr,
QString::fromLatin1("You are about to <Print>.\n"
"Are you sure?"),
QStringLiteral("Print"),
KGuiItem(QStringLiteral("&Print")),
KStandardGuiItem::cancel(),
QStringLiteral("dontask"));
i = KMessageBox::warningContinueCancel(nullptr,
QString::fromLatin1("You are about to <Print>.\n"
"Are you sure?"),
QStringLiteral("Print"),
KGuiItem(QStringLiteral("&Print")),
KStandardGuiItem::cancel(),
QStringLiteral("dontask"));
break;
case 6:
i = KMessageBox::warningTwoActionsCancel(nullptr,
QString::fromLatin1("Your document contains unsaved changes.\n"
"Do you want to save or discard your changes?\n"),
QStringLiteral("Close"),
KGuiItem(QStringLiteral("&Save")),
KGuiItem(QStringLiteral("&Discard")));
break;
case 7:
i = KMessageBox::Ok;
KMessageBox::error(nullptr, QStringLiteral("Oops, Your harddisk is unreadable."));
break;
case 8:
i = KMessageBox::Ok;
KMessageBox::detailedError(nullptr,
QStringLiteral("Oops, Your harddisk is unreadable."),
QStringLiteral("We don't know more yet."),
QStringLiteral("Uh ooh"));
break;
case 9:
i = KMessageBox::Ok;
KMessageBox::information(nullptr,
QString::fromLatin1("You can enable the menubar again "
"with the right mouse button menu."));
break;
case 10:
i = KMessageBox::Ok;
KMessageBox::information(nullptr,
QString::fromLatin1("You can enable the menubar again "
"with the right mouse button menu."),
QStringLiteral("Menubar Info"));
break;
case 11:
i = KMessageBox::Ok;
KMessageBox::information(nullptr,
QStringLiteral("You can enable the menubar again\nwith the right mouse button menu."),
QString(),
QStringLiteral("Enable_Menubar"));
break;
case 12:
i = KMessageBox::Ok;
KMessageBox::enableAllMessages();
break;
case 13:
i = KMessageBox::Ok;
KMessageBox::information(nullptr, QStringLiteral("Return of the annoying popup message."), QString(), QStringLiteral("Enable_Menubar"));
break;
case 14: {
QStringList strlist;
strlist << QStringLiteral("/dev/hda") << QStringLiteral("/etc/inittab") << QStringLiteral("/usr/somefile")
<< QString::fromLatin1(
"/some/really/"
"long/file/name/which/is/in/a/really/deep/directory/in/a/really/large/"
"hard/disk/of/your/system")
<< QStringLiteral("/and/another/one");
i = KMessageBox::questionTwoActionsList(nullptr,
QStringLiteral("Do you want to delete the following files?"),
strlist,
QStringLiteral("Delete Files"),
KGuiItem(QStringLiteral("Delete")),
KGuiItem(QStringLiteral("Move to Trash")));
} break;
case 15: {
QStringList strlist;
printf("Filling StringList...\n");
for (int j = 1; j <= 6000; j++) {
strlist.append(QStringLiteral("/tmp/tmp.%1").arg(j));
}
printf("Completed...\n");
i = KMessageBox::questionTwoActionsList(nullptr,
QStringLiteral("Do you want to delete the following files?"),
strlist,
QStringLiteral("Delete Files"),
KGuiItem(QStringLiteral("Delete")),
KGuiItem(QStringLiteral("Move to Trash")));
} break;
case 16:
i = KMessageBox::Ok;
KMessageBox::informationList(nullptr, QStringLiteral("The following words have been found:"), list);
break;
case 17:
i = KMessageBox::Ok;
KMessageBox::informationList(nullptr, QStringLiteral("The following words have been found:"), list, QStringLiteral("Search Words"));
break;
case 18:
i = KMessageBox::Ok;
KMessageBox::informationList(nullptr, QStringLiteral("The following words have been found:"), list, QString(), QStringLiteral("Search_Words"));
break;
default:
return false; // done
} // Switch
showResult(test, i);
return true;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName(QStringLiteral("kmessageboxtest"));
// Syntax: kmessageboxtest <test_number>
if (argc > 1) {
testMessageBox(QByteArray(argv[1]).toInt());
return 0;
}
// No argument specified, run all tests
int test = 1;
while (++test) {
if (!testMessageBox(test)) {
break;
}
}
return 0;
}
#if 0
//this is my sequence for testing messagebox layout:
KMessageBox::questionYesNoCancel(
0, "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", "long",
KStandardGuiItem::saveAs(), KGuiItem("dsdddddd"), KStandardGuiItem::cancel()
);
KMessageBox::questionYesNoCancel(
0, "ddddddddddddddddddddd ddddddddddddddddddddd dddddddddd dddddddddd ddddddddddddddddddd dddddddddddd ddddddddd", "long wrap",
KStandardGuiItem::saveAs(), KGuiItem("dsdddddd"), KStandardGuiItem::cancel()
);
KMessageBox::questionYesNoCancel(
0, "dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd", "height",
KStandardGuiItem::saveAs(), KGuiItem("dsdddddd"), KStandardGuiItem::cancel()
);
QStringList strlist;
strlist << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfgh\nghghgfhgf" << "f\ngfg\nhg\nhghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf" << "fgfghghghgfhgf";
KMessageBox::errorList(0,
"short\n",
strlist, "short");
KMessageBox::errorList(0,
"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
strlist, "short");
KMessageBox::errorList(0,
"ddddddddddddddddddddd ddddddddddddddddddddd dddddddddd dddddddddd ddddddddddddddddddd dddddddddddd ddddddddd",
strlist, "short");
KMessageBox::errorList(0,
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd",
strlist, "short");
KMessageBox::detailedError(0,
"sss",
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
);
KMessageBox::detailedError(0,
"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
);
KMessageBox::detailedError(0,
"ddddddddddddddddddddd ddddddddddddddddddddd dddddddddd dddddddddd ddddddddddddddddddd dddddddddddd ddddddddd",
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
);
KMessageBox::detailedError(0,
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd",
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
"dddddd\ndddddd\nddddddddd ddddd\ndddd\ndddddddddddd \ndddddddddd dddddddddd dd\nddddddddddd\ndd\ndddd dddd\ndddddddd ddd\ndd\ndddd"
);
#endif
@@ -0,0 +1,35 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2013 Aurélien Gâteau <agateau@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <iostream>
#include <kmessagebox.h>
#include <QApplication>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kmessageboxwidtest"));
QApplication app(argc, argv);
if (argc != 2) {
std::cerr << "Usage: " << qPrintable(QApplication::applicationName()) << " <window id>\n";
std::cerr << '\n';
std::cerr << "You can get a window id using a tool like `xwininfo`.\n";
return 1;
}
bool ok;
int winId = QByteArray(argv[1]).toInt(&ok, 0);
if (!ok) {
std::cerr << '"' << argv[1] << "\" is not a number\n";
return 1;
}
int ret = KMessageBox::warningContinueCancelWId(winId, QStringLiteral("Are you sure you want to continue?"), QStringLiteral("Dangerous stuff"));
std::cout << "Returned " << ret << '\n';
return ret;
}
@@ -0,0 +1,75 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2020 Ahmad Samir <a.samirh78@gmail.com>
SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "kmessagedialog.h"
#include <KGuiItem>
#include <KStandardGuiItem>
#include <QApplication>
#include <QDebug>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QPushButton>
#include <memory>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName(QStringLiteral("kmessagedialogtest"));
const auto types = {KMessageDialog::QuestionTwoActions,
KMessageDialog::QuestionTwoActionsCancel,
KMessageDialog::WarningTwoActions,
KMessageDialog::WarningTwoActionsCancel,
KMessageDialog::WarningContinueCancel,
KMessageDialog::Information,
KMessageDialog::Error};
for (auto type : types) {
auto dlg = std::unique_ptr<KMessageDialog>(new KMessageDialog(type, QStringLiteral("Message in a box."), nullptr));
dlg->setCaption(QString{});
dlg->setIcon(QIcon{});
if ((type != KMessageDialog::Information) && (type != KMessageDialog::Error)) {
dlg->setButtons(KGuiItem(QStringLiteral("Primary Action")), KGuiItem(QStringLiteral("Secondary Action")), KStandardGuiItem::cancel());
}
auto getResult = [&]() {
const auto result = static_cast<KMessageDialog::ButtonType>(dlg->exec());
switch (result) {
case KMessageDialog::Ok:
case KMessageDialog::PrimaryAction:
qDebug() << "Button OK/Primary clicked."
<< "Don't ask again status:" << (dlg->isDontAskAgainChecked() ? "Checked" : "Unchecked");
break;
case KMessageDialog::SecondaryAction:
qDebug() << "Button Secondary clicked"
<< "Don't ask again status:" << (dlg->isDontAskAgainChecked() ? "Checked" : "Unchecked");
break;
case KMessageDialog::Cancel:
qDebug() << "Button Cancel clicked";
break;
default:
break;
}
};
getResult();
dlg->setDontAskAgainText(QStringLiteral("Do not show this again"));
dlg->setDontAskAgainChecked(false);
getResult();
dlg->setListWidgetItems(QStringList{QStringLiteral("file1"), QStringLiteral("file2")});
getResult();
dlg->setDetails(QStringLiteral("Some more details."));
getResult();
}
return app.exec();
}
@@ -0,0 +1,114 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2012 Aurélien Gâteau <agateau@kde.org>
Based on test program by Dominik Haumann <dhaumann@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QAction>
#include <QApplication>
#include <QCheckBox>
#include <QFrame>
#include <QVBoxLayout>
#include <QWhatsThis>
#include <QWidget>
#include <kmessagewidget.h>
class Receiver : public QObject
{
Q_OBJECT
public:
Receiver(QObject *parent)
: QObject(parent)
{
}
~Receiver() override
{
}
public Q_SLOTS:
void showWhatsThis(const QString &text)
{
QWhatsThis::showText(QCursor::pos(), text);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *mainWindow = new QWidget();
QVBoxLayout *l = new QVBoxLayout(mainWindow);
KMessageWidget *mw = new KMessageWidget(mainWindow);
mw->setMessageType(KMessageWidget::Positive);
mw->setWordWrap(true);
mw->setText(QStringLiteral("Test KMessageWidget is properly sized when <a href=\"this is the contents\">word-wrap</a> is enabled by default."));
mw->setIcon(QIcon::fromTheme(QStringLiteral("kde")));
KMessageWidget *mw1 = new KMessageWidget(mainWindow);
mw1->setMessageType(KMessageWidget::Positive);
mw1->setWordWrap(true);
mw1->setText(QStringLiteral("Test KMessageWidget icon alignemnt<br />with pre-wrapped<br />content<br />like<br />this.<br />Please test with word wrap enabled and disabled."));
mw1->setIcon(QIcon::fromTheme(QStringLiteral("kde")));
KMessageWidget *mw2 = new KMessageWidget(mainWindow);
mw2->setWordWrap(true);
mw2->setText(QStringLiteral("A KMessageWidget with an icon and two additional buttons"));
mw2->setIcon(QIcon::fromTheme(QStringLiteral("kde")));
mw2->addAction(new QAction(QStringLiteral("Foo"), mw2));
mw2->addAction(new QAction(QStringLiteral("Bar"), mw2));
KMessageWidget *mw3 = new KMessageWidget(mainWindow);
mw3->setMessageType(KMessageWidget::Warning);
mw3->setWordWrap(true);
mw3->setText(QStringLiteral("A KMessageWidget of Warning type."));
KMessageWidget *mw4 = new KMessageWidget(mainWindow);
mw4->setMessageType(KMessageWidget::Error);
mw4->setWordWrap(true);
mw4->setText(QStringLiteral("A KMessageWidget of Error type."));
// A frame to materialize the end of the KMessageWidget
QFrame *frame = new QFrame(mainWindow);
frame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QCheckBox *wordWrapCb = new QCheckBox(QStringLiteral("wordWrap"), mainWindow);
wordWrapCb->setChecked(true);
QObject::connect(wordWrapCb, &QAbstractButton::toggled, mw, &KMessageWidget::setWordWrap);
QObject::connect(wordWrapCb, &QAbstractButton::toggled, mw1, &KMessageWidget::setWordWrap);
QObject::connect(wordWrapCb, &QAbstractButton::toggled, mw2, &KMessageWidget::setWordWrap);
QObject::connect(wordWrapCb, &QAbstractButton::toggled, mw3, &KMessageWidget::setWordWrap);
QObject::connect(wordWrapCb, &QAbstractButton::toggled, mw4, &KMessageWidget::setWordWrap);
QCheckBox *closeButtonCb = new QCheckBox(QStringLiteral("closeButton"), mainWindow);
closeButtonCb->setChecked(true);
QObject::connect(closeButtonCb, &QAbstractButton::toggled, mw, &KMessageWidget::setCloseButtonVisible);
QObject::connect(closeButtonCb, &QAbstractButton::toggled, mw1, &KMessageWidget::setCloseButtonVisible);
QObject::connect(closeButtonCb, &QAbstractButton::toggled, mw2, &KMessageWidget::setCloseButtonVisible);
QObject::connect(closeButtonCb, &QAbstractButton::toggled, mw3, &KMessageWidget::setCloseButtonVisible);
QObject::connect(closeButtonCb, &QAbstractButton::toggled, mw4, &KMessageWidget::setCloseButtonVisible);
l->addWidget(wordWrapCb);
l->addWidget(closeButtonCb);
l->addWidget(mw);
l->addWidget(mw1);
l->addWidget(mw2);
l->addWidget(mw3);
l->addWidget(mw4);
l->addWidget(frame);
mainWindow->resize(400, 300);
mainWindow->show();
mainWindow->setAttribute(Qt::WA_DeleteOnClose);
// demonstrate linkActivated
Receiver *info = new Receiver(mw);
QObject::connect(mw, &KMessageWidget::linkActivated, info, &Receiver::showWhatsThis);
return app.exec();
}
#include "kmessagewidgettest.moc"
// kate: replace-tabs on;
@@ -0,0 +1,33 @@
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <QApplication>
#include <QDebug>
#include <kmimetypechooser.h>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
const QString text = QStringLiteral("Select the MimeTypes you want for this file type.");
QStringList list({QStringLiteral("inode/directory"), QStringLiteral("text/plain")});
KMimeTypeChooserDialog dlg(QStringLiteral("Select Mime Types"),
text,
list,
QStringLiteral("text"),
QStringList(),
KMimeTypeChooser::Comments | KMimeTypeChooser::Patterns | KMimeTypeChooser::EditButton,
(QWidget *)nullptr);
if (dlg.exec() == QDialog::Accepted) {
qDebug() << dlg.chooser()->patterns();
qDebug() << dlg.chooser()->mimeTypes().join(QLatin1Char(';'));
}
return 0; // app.exec();
}
@@ -0,0 +1,27 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2007 Olivier Goffart <ogoffart at kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <iostream>
#include <knewpassworddialog.h>
#include <qapplication.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
KNewPasswordDialog dlg;
dlg.setPasswordStrengthWarningLevel(30);
dlg.setPrompt(QApplication::translate("main", "Enter a password for the test"));
if (dlg.exec()) {
std::cout << "Entered password: " << qPrintable(dlg.password()) << std::endl;
return 0;
} else {
std::cout << "No password" << std::endl;
return -1;
}
}
@@ -0,0 +1,88 @@
/*
SPDX-FileCopyrightText: 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "knewpasswordwidget_test.h"
#include <QApplication>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <KMessageBox>
#include <KNewPasswordWidget>
// Doxygen will generate code snippets from this file.
// We can't use i18n() here, but we want it to show up in the apidox.
#define i18n QStringLiteral
MyPasswordDialog::MyPasswordDialog(QWidget *parent)
: QDialog(parent)
{
m_passwordWidget = new KNewPasswordWidget(this);
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
m_passwordWidget->setMinimumPasswordLength(6);
auto layout = new QVBoxLayout(this);
layout->addWidget(m_passwordWidget);
layout->addWidget(new QCheckBox(QStringLiteral("A checkbox"), this));
layout->addWidget(m_buttonBox);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
//! [accept_custom_dialog]
void MyPasswordDialog::accept()
{
switch (m_passwordWidget->passwordStatus()) {
case KNewPasswordWidget::WeakPassword:
case KNewPasswordWidget::StrongPassword:
QDialog::accept();
break;
case KNewPasswordWidget::PasswordNotVerified:
KMessageBox::error(nullptr, i18n("The chosen password does not match the given verification password."));
break;
case KNewPasswordWidget::EmptyPasswordNotAllowed:
KMessageBox::error(nullptr, i18n("The chosen password cannot be empty."));
break;
case KNewPasswordWidget::PasswordTooShort:
KMessageBox::error(nullptr, i18n("The chosen password is too short."));
break;
}
}
//! [accept_custom_dialog]
//! [update_custom_dialog]
void MyPasswordDialog::slotPasswordStatusChanged()
{
// You may want to extend this switch with more cases,
// in order to warn the user about all the possible password issues.
switch (m_passwordWidget->passwordStatus()) {
case KNewPasswordWidget::WeakPassword:
case KNewPasswordWidget::StrongPassword:
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
break;
default:
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
break;
}
}
//! [update_custom_dialog]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyPasswordDialog dialog;
QObject::connect(&dialog, &QDialog::finished, &app, &QCoreApplication::quit);
dialog.show();
return app.exec();
}
#include "moc_knewpasswordwidget_test.cpp"
@@ -0,0 +1,33 @@
/*
SPDX-FileCopyrightText: 2016 Elvis Angelaccio <elvis.angelaccio@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KNEWPASSWORDWIDGET_TEST_H
#define KNEWPASSWORDWIDGET_TEST_H
#include <QDialog>
class QDialogButtonBox;
class KNewPasswordWidget;
class MyPasswordDialog : public QDialog
{
Q_OBJECT
public:
MyPasswordDialog(QWidget *parent = nullptr);
void accept() override;
private Q_SLOTS:
void slotPasswordStatusChanged();
private:
KNewPasswordWidget *m_passwordWidget;
QDialogButtonBox *m_buttonBox;
};
#endif
@@ -0,0 +1,56 @@
/*
This file is part of the KDE Libraries
SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kpagedialogtest.h"
#include <QApplication>
#include <QBoxLayout>
#include <QLabel>
KPageDialogTest::KPageDialogTest(QWidget *parent)
: KPageDialog(parent)
{
setFaceType(Tabbed);
QWidget *page = new QWidget(this);
QBoxLayout *layout = new QVBoxLayout(page);
QLabel *label = new QLabel(QStringLiteral("first page"));
layout->addWidget(label);
label = new QLabel(QStringLiteral("This is a very long text that is contained in a single string within a single label"));
layout->addWidget(label);
addPage(page, QStringLiteral("First"));
page = new QWidget(this);
layout = new QHBoxLayout(page);
label = new QLabel(QStringLiteral("second page"));
label->setMinimumSize(300, 200);
layout->addWidget(label);
addPage(page, QStringLiteral("Second"));
}
KPageDialogTest::~KPageDialogTest()
{
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("KPageDialogTest"));
QApplication app(argc, argv);
KPageDialogTest testDialog(nullptr);
testDialog.exec();
return 0;
}
#include "moc_kpagedialogtest.cpp"
@@ -0,0 +1,22 @@
/*
This file is part of the KDE Libraries
SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPAGEDIALOGTEST_H
#define KPAGEDIALOGTEST_H
#include "kpagedialog.h"
class KPageDialogTest : public KPageDialog
{
Q_OBJECT
public:
KPageDialogTest(QWidget *parent = nullptr);
~KPageDialogTest() override;
};
#endif
@@ -0,0 +1,206 @@
/*
This file is part of the KDE Libraries
SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kpagewidgettest.h"
#include <QApplication>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include "kpagewidgetmodel.h"
KPageWidgetTest::KPageWidgetTest(QWidget *parent)
: QWidget(parent)
{
QGridLayout *layout = new QGridLayout(this);
mWidget = new KPageWidget(this);
layout->addWidget(mWidget, 0, 0, 7, 1);
connect(mWidget, &KPageWidget::currentPageChanged, this, &KPageWidgetTest::currentPageChanged);
connect(mWidget, &KPageWidget::pageToggled, this, &KPageWidgetTest::pageToggled);
int rowCount = 0;
QPushButton *button = new QPushButton(QStringLiteral("Auto"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::setAutoFace);
rowCount++;
button = new QPushButton(QStringLiteral("Plain"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::setPlainFace);
rowCount++;
button = new QPushButton(QStringLiteral("List"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::setListFace);
rowCount++;
button = new QPushButton(QStringLiteral("Flat List"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::setFlatListFace);
rowCount++;
button = new QPushButton(QStringLiteral("Tree"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::setTreeFace);
rowCount++;
button = new QPushButton(QStringLiteral("Tabbed"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::setTabbedFace);
rowCount++;
button = new QPushButton(QStringLiteral("Add Page"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::addPage);
rowCount++;
button = new QPushButton(QStringLiteral("Add Sub Page"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::addSubPage);
rowCount++;
button = new QPushButton(QStringLiteral("Insert Page"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::insertPage);
rowCount++;
button = new QPushButton(QStringLiteral("Delete Page"), this);
layout->addWidget(button, rowCount, 1);
connect(button, &QAbstractButton::clicked, this, &KPageWidgetTest::deletePage);
rowCount++;
KPageWidgetItem *item = mWidget->addPage(new QPushButton(QStringLiteral("folder")), QStringLiteral("folder"));
item->setIcon(QIcon::fromTheme(QStringLiteral("folder")));
item = mWidget->addSubPage(item, new QPushButton(QStringLiteral("subfolder")), QStringLiteral("subfolder"));
item->setIcon(QIcon::fromTheme(QStringLiteral("folder")));
item = mWidget->addPage(new QLabel(QStringLiteral("second folder")), QStringLiteral("second folder"));
item->setIcon(QIcon::fromTheme(QStringLiteral("folder")));
}
KPageWidgetTest::~KPageWidgetTest()
{
}
void KPageWidgetTest::setAutoFace()
{
mWidget->setFaceType(KPageWidget::Auto);
}
void KPageWidgetTest::setPlainFace()
{
mWidget->setFaceType(KPageWidget::Plain);
}
void KPageWidgetTest::setListFace()
{
mWidget->setFaceType(KPageWidget::List);
}
void KPageWidgetTest::setTreeFace()
{
mWidget->setFaceType(KPageWidget::Tree);
}
void KPageWidgetTest::setTabbedFace()
{
mWidget->setFaceType(KPageWidget::Tabbed);
}
void KPageWidgetTest::setFlatListFace()
{
mWidget->setFaceType(KPageWidget::FlatList);
}
void KPageWidgetTest::addPage()
{
static int counter = 0;
const QString title = QStringLiteral("dynamic folder %1").arg(QString::number(counter));
KPageWidgetItem *item = mWidget->addPage(new QPushButton(title), title);
item->setIcon(QIcon::fromTheme(QStringLiteral("folder")));
item->setHeader(QStringLiteral("Header Test No. %1").arg(QString::number(counter)));
item->setCheckable(true);
counter++;
}
void KPageWidgetTest::addSubPage()
{
static int counter = 0;
KPageWidgetItem *item = mWidget->currentPage();
if (!item) {
return;
}
const QString title = QStringLiteral("subfolder %1").arg(QString::number(counter));
item = mWidget->addSubPage(item, new QLabel(title), title);
item->setIcon(QIcon::fromTheme(QStringLiteral("folder")));
counter++;
}
void KPageWidgetTest::insertPage()
{
static int counter = 0;
KPageWidgetItem *item = mWidget->currentPage();
if (!item) {
return;
}
const QString title = QStringLiteral("before folder %1").arg(QString::number(counter));
item = mWidget->insertPage(item, new QLabel(title), title);
item->setIcon(QIcon::fromTheme(QStringLiteral("folder")));
counter++;
}
void KPageWidgetTest::deletePage()
{
KPageWidgetItem *item = mWidget->currentPage();
if (item) {
mWidget->removePage(item);
}
}
void KPageWidgetTest::currentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before)
{
if (current) {
qDebug("Current item: %s", qPrintable(current->name()));
} else {
qDebug("No current item");
}
if (before) {
qDebug("Item before: %s", qPrintable(before->name()));
} else {
qDebug("No item before");
}
}
void KPageWidgetTest::pageToggled(KPageWidgetItem *item, bool checked)
{
qDebug("Item %s changed check state to: %s", qPrintable(item->name()), checked ? "checked" : "unchecked");
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("KPageWidgetTest"));
QApplication app(argc, argv);
KPageWidgetTest testWidget(nullptr);
testWidget.show();
return app.exec();
}
#include "moc_kpagewidgettest.cpp"
@@ -0,0 +1,43 @@
/*
This file is part of the KDE Libraries
SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPAGEWIDGETTEST_H
#define KPAGEWIDGETTEST_H
#include <QWidget>
#include "kpagewidget.h"
class KPageWidgetTest : public QWidget
{
Q_OBJECT
public:
KPageWidgetTest(QWidget *parent = nullptr);
~KPageWidgetTest() override;
private Q_SLOTS:
void setAutoFace();
void setPlainFace();
void setListFace();
void setTreeFace();
void setTabbedFace();
void setFlatListFace();
void addPage();
void addSubPage();
void insertPage();
void deletePage();
void currentPageChanged(KPageWidgetItem *, KPageWidgetItem *);
void pageToggled(KPageWidgetItem *, bool);
private:
KPageWidget *mWidget;
};
#endif
@@ -0,0 +1,75 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2007 Olivier Goffart <ogoffart at kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <QApplication>
#include <QMap>
#include <kpassworddialog.h>
#include <iostream>
// We can't depend on i18n in this test, but still -- show good practice (other than the line below) :-)
#define i18n QString::fromLatin1
int main(int argc, char *argv[])
{
QApplication::setApplicationName(QStringLiteral("KNewPasswordDialogTest"));
QApplication a(argc, argv);
// step 1 simple password
{
KPasswordDialog dlg(nullptr, KPasswordDialog::ShowKeepPassword);
dlg.setPrompt(
i18n("This is a long prompt line. It is important it to be long so we can test the dialog does not get broken because of multiline labels. Please "
"enter a password:"));
dlg.addCommentLine(i18n("This is a rather large left comment line"),
i18n("Right part of the comment line has to be long too so be test the layouting works really ok. Please visit http://www.kde.org"));
if (dlg.exec()) {
std::cout << "Entered password: " << qPrintable(dlg.password()) << std::endl;
} else {
std::cout << "No password" << std::endl;
return -1;
}
}
// step 2 readonly username
{
KPasswordDialog dlg(nullptr, KPasswordDialog::ShowUsernameLine | KPasswordDialog::UsernameReadOnly);
dlg.setPrompt(i18n("Enter a password for the test"));
dlg.setUsername(QStringLiteral("konqui"));
dlg.addCommentLine(i18n("Site"), i18n("http://www.kde.org"));
if (dlg.exec()) {
std::cout << "Entered password: " << qPrintable(dlg.password()) << std::endl;
} else {
std::cout << "No password" << std::endl;
return -1;
}
}
// step 3 with some username preset
{
KPasswordDialog dlg(nullptr, KPasswordDialog::ShowUsernameLine);
dlg.setPrompt(i18n("Enter a password for the test"));
QMap<QString, QString> logins;
logins.insert(QStringLiteral("konqui"), QStringLiteral("foo"));
logins.insert(QStringLiteral("watson"), QStringLiteral("bar"));
logins.insert(QStringLiteral("ogoffart"), QString());
dlg.setKnownLogins(logins);
if (dlg.exec()) {
std::cout << "Entered password: " << qPrintable(dlg.password()) << " for username " << qPrintable(dlg.username()) << std::endl;
} else {
std::cout << "No password" << std::endl;
return -1;
}
}
return 0;
}
@@ -0,0 +1,34 @@
/*
SPDX-FileCopyrightText: 2017 Montel Laurent <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include <QVBoxLayout>
#include <QWidget>
#include <QApplication>
#include <QCommandLineParser>
#include <KPasswordLineEdit>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.process(app);
QWidget *w = new QWidget;
QVBoxLayout *vbox = new QVBoxLayout(w);
KPasswordLineEdit *passwordLineEdit = new KPasswordLineEdit(w);
vbox->addWidget(passwordLineEdit);
vbox->addStretch();
w->resize(400, 400);
w->show();
return app.exec();
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

@@ -0,0 +1,29 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2004 Antonio Larrosa <larrosa@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kpixmapregionselectordialog.h"
#include <QApplication>
#include <QFile>
#include <QImage>
#include <QPixmap>
#include <iostream>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
if (argc <= 1) {
std::cerr << "Usage: kpixmapregionselectordialogtest <imageFile>" << std::endl;
return 1;
}
QPixmap pix(QFile::decodeName(argv[1]));
QImage image = KPixmapRegionSelectorDialog::getSelectedImage(pix, 100, 100);
image.save(QStringLiteral("output.png"), "PNG");
return 0;
}
@@ -0,0 +1,92 @@
#include "kpixmapsequenceoverlaypaintertest.h"
#include "kpixmapsequence.h"
#include "kpixmapsequenceoverlaypainter.h"
#include <QApplication>
#include <QComboBox>
#include <QEvent>
#include <QGridLayout>
#include <QSpinBox>
#include <QTest>
#include <QVariant>
Q_DECLARE_METATYPE(Qt::Alignment)
TestWidget::TestWidget()
: QWidget()
{
m_draggingLeft = false;
m_draggingRight = false;
m_draggingTop = false;
m_draggingBottom = false;
QGridLayout *layout = new QGridLayout(this);
m_widget = new QWidget(this);
m_alignment = new QComboBox(this);
m_offsetX = new QSpinBox(this);
m_offsetY = new QSpinBox(this);
layout->addWidget(m_widget, 0, 0, 1, 2);
layout->addWidget(m_alignment, 1, 0, 1, 2);
layout->addWidget(m_offsetX, 2, 0, 1, 1);
layout->addWidget(m_offsetY, 2, 1, 1, 1);
m_alignment->addItem(QStringLiteral("Center"), QVariant::fromValue(Qt::Alignment(Qt::AlignCenter)));
m_alignment->addItem(QStringLiteral("Top-left"), QVariant::fromValue(Qt::Alignment(Qt::AlignTop | Qt::AlignLeft)));
m_alignment->addItem(QStringLiteral("Top"), QVariant::fromValue(Qt::Alignment(Qt::AlignTop | Qt::AlignHCenter)));
m_alignment->addItem(QStringLiteral("Top-right"), QVariant::fromValue(Qt::Alignment(Qt::AlignTop | Qt::AlignRight)));
m_alignment->addItem(QStringLiteral("Right"), QVariant::fromValue(Qt::Alignment(Qt::AlignRight | Qt::AlignVCenter)));
m_alignment->addItem(QStringLiteral("Bottom-right"), QVariant::fromValue(Qt::Alignment(Qt::AlignRight | Qt::AlignBottom)));
m_alignment->addItem(QStringLiteral("Bottom"), QVariant::fromValue(Qt::Alignment(Qt::AlignHCenter | Qt::AlignBottom)));
m_alignment->addItem(QStringLiteral("Bottom-left"), QVariant::fromValue(Qt::Alignment(Qt::AlignLeft | Qt::AlignBottom)));
m_alignment->addItem(QStringLiteral("Left"), QVariant::fromValue(Qt::Alignment(Qt::AlignLeft | Qt::AlignVCenter)));
connect(m_alignment, &QComboBox::activated, this, &TestWidget::alignementChanged);
connect(m_offsetX, &QSpinBox::valueChanged, this, &TestWidget::offsetChanged);
connect(m_offsetY, &QSpinBox::valueChanged, this, &TestWidget::offsetChanged);
m_painter = new KPixmapSequenceOverlayPainter(KPixmapSequence(QFINDTESTDATA("kpixmap-animation.png"), 22), this);
m_painter->setWidget(m_widget);
m_painter->start();
}
TestWidget::~TestWidget()
{
}
void TestWidget::alignementChanged(int i)
{
m_painter->setAlignment(m_alignment->itemData(i).value<Qt::Alignment>());
}
void TestWidget::offsetChanged()
{
m_painter->setOffset(QPoint(m_offsetX->value(), m_offsetY->value()));
}
bool TestWidget::eventFilter(QObject *o, QEvent *e)
{
if (o == m_widget) {
if (e->type() == QEvent::Paint) {
} else if (e->type() == QEvent::MouseButtonPress) {
} else if (e->type() == QEvent::MouseButtonRelease) {
} else if (e->type() == QEvent::MouseMove) {
}
}
return QWidget::eventFilter(o, e);
}
/* --- MAIN -----------------------*/
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("test"));
TestWidget *window;
QApplication testapp(argc, argv);
window = new TestWidget();
window->show();
return testapp.exec();
}
#include "moc_kpixmapsequenceoverlaypaintertest.cpp"
@@ -0,0 +1,39 @@
#ifndef _K_PIXMAPSEQUENCE_OVERLAY_PAINTER_TEST_H_
#define _K_PIXMAPSEQUENCE_OVERLAY_PAINTER_TEST_H_
#include <QWidget>
class KPixmapSequenceOverlayPainter;
class QComboBox;
class QSpinBox;
class QEvent;
class TestWidget : public QWidget
{
Q_OBJECT
public:
TestWidget();
~TestWidget() override;
bool eventFilter(QObject *, QEvent *) override;
private Q_SLOTS:
void alignementChanged(int);
void offsetChanged();
private:
KPixmapSequenceOverlayPainter *m_painter;
QWidget *m_widget;
QComboBox *m_alignment;
QSpinBox *m_offsetX;
QSpinBox *m_offsetY;
bool m_draggingLeft;
bool m_draggingRight;
bool m_draggingTop;
bool m_draggingBottom;
};
#endif
@@ -0,0 +1,29 @@
/*
This file is part of the KDE Libraries
SPDX-FileCopyrightText: 2013 Kevin Ottens <ervin+bluesystems@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <QApplication>
#include <QVBoxLayout>
#include <kratingwidget.h>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget window;
auto *layout = new QVBoxLayout(&window);
KRatingWidget *enabled = new KRatingWidget(&window);
layout->addWidget(enabled);
KRatingWidget *disabled = new KRatingWidget(&window);
disabled->setEnabled(false);
layout->addWidget(disabled);
window.show();
return app.exec();
}
@@ -0,0 +1,104 @@
/*
SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
SPDX-FileCopyrightText: 2006 Simon Hausmann <hausmann@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "kselectactiontest.h"
#include <QApplication>
#include <QMenuBar>
#include <QToolBar>
#include <QDebug>
#include <kselectaction.h>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kselectactiontest"));
QApplication app(argc, argv);
QWidget parentWidget;
SelectActionTest *test = new SelectActionTest(&parentWidget);
test->show();
return app.exec();
}
SelectActionTest::SelectActionTest(QWidget *parent)
: QMainWindow(parent)
, m_comboSelect(new KSelectAction(QStringLiteral("Combo Selection"), this))
, m_buttonSelect(new KSelectAction(QStringLiteral("Button Selection"), this))
{
for (int i = 0; i < 7; ++i) {
QAction *action = m_comboSelect->addAction(QStringLiteral("Combo Action %1").arg(i));
connect(action, &QAction::triggered, this, &SelectActionTest::slotActionTriggered);
action = m_buttonSelect->addAction(QStringLiteral("Action %1").arg(i));
connect(action, &QAction::triggered, this, &SelectActionTest::slotActionTriggered);
}
m_comboSelect->setToolBarMode(KSelectAction::ComboBoxMode);
m_comboSelect->setWhatsThis(QStringLiteral("What's this?"));
connect(m_comboSelect, &KSelectAction::actionTriggered, this, &SelectActionTest::actionTriggered);
connect(m_comboSelect, &KSelectAction::indexTriggered, this, &SelectActionTest::indexTriggered);
connect(m_comboSelect, &KSelectAction::textTriggered, this, &SelectActionTest::textTriggered);
m_buttonSelect->setToolBarMode(KSelectAction::MenuMode);
m_buttonSelect->setWhatsThis(QStringLiteral("What's this?"));
connect(m_buttonSelect, &KSelectAction::actionTriggered, this, &SelectActionTest::actionTriggered);
connect(m_buttonSelect, &KSelectAction::indexTriggered, this, &SelectActionTest::indexTriggered);
connect(m_buttonSelect, &KSelectAction::textTriggered, this, &SelectActionTest::textTriggered);
menuBar()->addAction(m_comboSelect);
menuBar()->addAction(m_buttonSelect);
menuBar()->addAction(QStringLiteral("Add an action"), this, &SelectActionTest::addAction);
menuBar()->addAction(QStringLiteral("Remove an action"), this, &SelectActionTest::removeAction);
QToolBar *toolBar = addToolBar(QStringLiteral("Test"));
toolBar->addAction(m_comboSelect);
toolBar->addAction(m_buttonSelect);
}
void SelectActionTest::actionTriggered(QAction *action)
{
qDebug() << Q_FUNC_INFO << action;
}
void SelectActionTest::indexTriggered(int index)
{
qDebug() << Q_FUNC_INFO << index;
}
void SelectActionTest::textTriggered(const QString &text)
{
qDebug() << Q_FUNC_INFO << '"' << text << '"';
}
void SelectActionTest::addAction()
{
QAction *action = m_comboSelect->addAction(QStringLiteral("Combo Action %1").arg(m_comboSelect->actions().count()));
connect(action, &QAction::triggered, this, &SelectActionTest::slotActionTriggered);
action = m_buttonSelect->addAction(QStringLiteral("Action %1").arg(m_buttonSelect->actions().count()));
connect(action, &QAction::triggered, this, &SelectActionTest::slotActionTriggered);
}
void SelectActionTest::removeAction()
{
if (!m_comboSelect->actions().isEmpty()) {
m_comboSelect->removeAction(m_comboSelect->actions().last());
}
if (!m_buttonSelect->actions().isEmpty()) {
m_buttonSelect->removeAction(m_buttonSelect->actions().last());
}
}
void SelectActionTest::slotActionTriggered(bool state)
{
qDebug() << sender() << " state " << state;
}
#include "moc_kselectactiontest.cpp"
@@ -0,0 +1,36 @@
/*
SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KSELECTACTION_TEST_H
#define KSELECTACTION_TEST_H
#include <QMainWindow>
class KSelectAction;
class SelectActionTest : public QMainWindow
{
Q_OBJECT
public:
SelectActionTest(QWidget *parent = nullptr);
public Q_SLOTS:
void actionTriggered(QAction *action);
void indexTriggered(int index);
void textTriggered(const QString &text);
void slotActionTriggered(bool state);
void addAction();
void removeAction();
private:
KSelectAction *m_comboSelect;
KSelectAction *m_buttonSelect;
};
#endif
@@ -0,0 +1,30 @@
/*
SPDX-FileCopyrightText: 1997 Michael Roth <mroth@wirlweb.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QApplication>
#include <QBoxLayout>
#include <QWidget>
#include "kseparator.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget toplevel;
QBoxLayout *mainbox = new QBoxLayout(QBoxLayout::TopToBottom, &toplevel);
mainbox->setContentsMargins(10, 10, 10, 10);
KSeparator *sep1 = new KSeparator(Qt::Vertical, &toplevel);
mainbox->addWidget(sep1);
KSeparator *sep2 = new KSeparator(Qt::Horizontal, &toplevel);
mainbox->addWidget(sep2);
mainbox->activate();
toplevel.show();
return app.exec();
}
@@ -0,0 +1,71 @@
/*
SPDX-FileCopyrightText: 2014 Montel Laurent <montel@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "ksplittercollapserbuttongui_test.h"
#include "ksplittercollapserbutton.h"
#include <QSplitter>
#include <qapplication.h>
#include <QApplication>
#include <QCommandLineParser>
#include <QHBoxLayout>
#include <QTextEdit>
KSplitterCollapserButtonGui_test::KSplitterCollapserButtonGui_test(int indexOfWidgetAssociateToSplitterCollapser, Qt::Orientation orientation, QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *lay = new QHBoxLayout(this);
QSplitter *splitter = new QSplitter(orientation);
lay->addWidget(splitter);
QTextEdit *firstTextEdit = new QTextEdit;
splitter->addWidget(firstTextEdit);
QTextEdit *secondTextEdit = new QTextEdit;
splitter->addWidget(secondTextEdit);
if (indexOfWidgetAssociateToSplitterCollapser == 0) {
new KSplitterCollapserButton(firstTextEdit, splitter);
} else {
new KSplitterCollapserButton(secondTextEdit, splitter);
}
}
KSplitterCollapserButtonGui_test::~KSplitterCollapserButtonGui_test()
{
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.process(app);
KSplitterCollapserButtonGui_test *w = new KSplitterCollapserButtonGui_test(0, Qt::Horizontal);
w->resize(800, 600);
w->show();
KSplitterCollapserButtonGui_test *w2 = new KSplitterCollapserButtonGui_test(1, Qt::Horizontal);
w2->resize(800, 600);
w2->show();
KSplitterCollapserButtonGui_test *w3 = new KSplitterCollapserButtonGui_test(0, Qt::Vertical);
w3->resize(800, 600);
w3->show();
KSplitterCollapserButtonGui_test *w4 = new KSplitterCollapserButtonGui_test(1, Qt::Vertical);
w4->resize(800, 600);
w4->show();
app.exec();
delete w;
delete w2;
delete w3;
delete w4;
return 0;
}
#include "moc_ksplittercollapserbuttongui_test.cpp"
@@ -0,0 +1,20 @@
/*
SPDX-FileCopyrightText: 2014 Montel Laurent <montel@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef KSPLITTERCOLLAPSERBUTTONGUI_TEST_H
#define KSPLITTERCOLLAPSERBUTTONGUI_TEST_H
#include <QWidget>
class KSplitterCollapserButtonGui_test : public QWidget
{
Q_OBJECT
public:
explicit KSplitterCollapserButtonGui_test(int indexOfWidgetAssociateToSplitterCollapser, Qt::Orientation orientation, QWidget *parent = nullptr);
~KSplitterCollapserButtonGui_test() override;
};
#endif // KSPLITTERCOLLAPSERBUTTONGUI_TEST_H
@@ -0,0 +1,34 @@
#include "ksqueezedtextlabel.h"
#include <QApplication>
#include <QVBoxLayout>
#include <QWidget>
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("test"));
QApplication app(argc, argv);
QWidget *box = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(box);
KSqueezedTextLabel *l1 = new KSqueezedTextLabel(QStringLiteral("This is a rather long string"), box);
KSqueezedTextLabel *l2 = new KSqueezedTextLabel(QStringLiteral("This is another long string, selectable by mouse\nsdfsdfsfsf\nsdfsdfsdf\n"), box);
l2->setTextElideMode(Qt::ElideRight);
l2->setTextInteractionFlags(Qt::TextSelectableByMouse);
KSqueezedTextLabel *urlLabel = new KSqueezedTextLabel(QStringLiteral("http://www.example.com/this/url/is/selectable/by/mouse"), box);
urlLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
layout->addWidget(l1);
layout->addWidget(l2);
layout->addWidget(urlLabel);
layout->addWidget(new QLabel(QStringLiteral("This is a normal QLabel"), box));
QLabel *selectableLabel = new QLabel(QStringLiteral("This is a normal QLabel, selectable by mouse"), box);
selectableLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
layout->addWidget(selectableLabel);
box->show();
return app.exec();
}
@@ -0,0 +1,66 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer@kde.org>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include <QApplication>
#include <ktitlewidget.h>
#include <QCheckBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class KTitleWidgetTestWidget : public QWidget
{
public:
KTitleWidgetTestWidget(QWidget *parent = nullptr)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
KTitleWidget *titleWidget = new KTitleWidget(this);
titleWidget->setText(QStringLiteral("Title"));
titleWidget->setIconSize(QSize(22, 22));
titleWidget->setIcon(QIcon::fromTheme(QStringLiteral("kde")), KTitleWidget::ImageLeft);
mainLayout->addWidget(titleWidget);
KTitleWidget *errorTitle = new KTitleWidget(this);
errorTitle->setText(QStringLiteral("Title"));
errorTitle->setComment(QStringLiteral("Error Comment"), KTitleWidget::ErrorMessage);
mainLayout->addWidget(errorTitle);
KTitleWidget *checkboxTitleWidget = new KTitleWidget(this);
QWidget *checkBoxTitleMainWidget = new QWidget(this);
QVBoxLayout *titleLayout = new QVBoxLayout(checkBoxTitleMainWidget);
titleLayout->setContentsMargins(6, 6, 6, 6);
QCheckBox *checkBox = new QCheckBox(QStringLiteral("Text Checkbox"), checkBoxTitleMainWidget);
titleLayout->addWidget(checkBox);
checkboxTitleWidget->setWidget(checkBoxTitleMainWidget);
mainLayout->addWidget(checkboxTitleWidget);
QLabel *otherLabel = new QLabel(QStringLiteral("Some text..."), this);
mainLayout->addWidget(otherLabel);
mainLayout->addStretch();
}
};
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("ktitlewidgettest"));
QApplication app(argc, argv);
KTitleWidgetTestWidget *mainWidget = new KTitleWidgetTestWidget;
mainWidget->show();
return app.exec();
}
@@ -0,0 +1,77 @@
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2013 Benjamin Port <benjamin.port@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include <QApplication>
#include <QLineEdit>
#include <QMainWindow>
#include <QPushButton>
#include <QString>
#include <QToolBar>
#include <QVBoxLayout>
#include <ktoolbarlabelaction.h>
class MainWindow : public QMainWindow
{
Q_OBJECT
private Q_SLOTS:
void updateLabel1()
{
label1->setText(labelText->text());
}
public:
MainWindow()
{
QWidget *mainWidget = new QWidget(this);
setCentralWidget(mainWidget);
QVBoxLayout *layout = new QVBoxLayout(mainWidget);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
QToolBar *toolBar = addToolBar(QStringLiteral("Toolbar"));
labelText = new QLineEdit();
QPushButton *validateButton = new QPushButton(QStringLiteral("Update label"));
layout->addWidget(labelText);
layout->addWidget(validateButton);
connect(validateButton, &QAbstractButton::clicked, this, &MainWindow::updateLabel1);
QWidgetAction *lineEditAction2 = new QWidgetAction(toolBar);
QLineEdit *lineEdit2 = new QLineEdit;
lineEditAction2->setDefaultWidget(lineEdit2);
label1 = new KToolBarLabelAction(QStringLiteral("&Label 1"), toolBar);
label2 = new KToolBarLabelAction(lineEditAction2, QStringLiteral("&Second label"), toolBar);
QWidgetAction *lineEditAction = new QWidgetAction(toolBar);
QLineEdit *lineEdit = new QLineEdit;
lineEditAction->setDefaultWidget(lineEdit);
// set buddy for label1
label1->setBuddy(lineEditAction);
toolBar->addAction(label1);
toolBar->addAction(lineEditAction);
toolBar->addAction(label2);
toolBar->addAction(lineEditAction2);
}
QLineEdit *labelText;
KToolBarLabelAction *label1;
KToolBarLabelAction *label2;
};
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("Test KToolBarLabelAction"));
QApplication app(argc, argv);
MainWindow *window = new MainWindow;
window->show();
return app.exec();
}
#include "ktoolbarlabelactiontest.moc"
@@ -0,0 +1,63 @@
/*
SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "ktooltipwidget_test.h"
#include <QApplication>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
// Doxygen will generate code snippets from this file.
// We can't use i18n() here, but we want it to show up in the apidox.
#define i18n QStringLiteral
TestDialog::TestDialog(QWidget *parent)
: QDialog(parent)
{
m_view.setColumnCount(1);
m_view.setRootIsDecorated(false);
m_view.setMouseTracking(true);
auto item = new QTreeWidgetItem(&m_view);
item->setText(0, QStringLiteral("Hover me! (first item)"));
auto item2 = new QTreeWidgetItem(&m_view);
item2->setText(0, QStringLiteral("Hover me! (second item)"));
auto spinBox = new QSpinBox(this);
spinBox->setPrefix(QStringLiteral("Hide delay (ms): "));
spinBox->setMaximum(5000);
spinBox->setValue(500);
connect(spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), &m_tooltipWidget, &KToolTipWidget::setHideDelay);
auto layout = new QVBoxLayout(this);
layout->addWidget(spinBox);
layout->addWidget(&m_view);
//! [show_tooltip_widget]
connect(&m_view, &QAbstractItemView::entered, this, [this](const QModelIndex &index) {
auto rect = m_view.visualRect(index);
const auto pos = m_view.viewport()->mapToGlobal(rect.topLeft());
rect.moveTo(pos);
auto button = new QPushButton(i18n("Push me (row %1)").arg(index.row()), this);
m_tooltipWidget.showBelow(rect, button, m_view.nativeParentWidget()->windowHandle());
});
//! [show_tooltip_widget]
connect(&m_view, &QAbstractItemView::viewportEntered, &m_tooltipWidget, &KToolTipWidget::hideLater);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TestDialog dialog;
QObject::connect(&dialog, &QDialog::finished, &app, &QCoreApplication::quit);
dialog.show();
return app.exec();
}
#include "moc_ktooltipwidget_test.cpp"
@@ -0,0 +1,27 @@
/*
SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef KTOOLTIPWIDGET_TEST_H
#define KTOOLTIPWIDGET_TEST_H
#include <KToolTipWidget>
#include <QDialog>
#include <QTreeWidget>
class TestDialog : public QDialog
{
Q_OBJECT
public:
TestDialog(QWidget *parent = nullptr);
private:
KToolTipWidget m_tooltipWidget;
QTreeWidget m_view;
};
#endif
@@ -0,0 +1,158 @@
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "ktwofingerswipe_test.h"
#include <QApplication>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QLineEdit>
#include <QLabel>
#include <QDebug>
#include <QTouchEvent>
#include <QSpinBox>
#include <ktwofingerswipe.h>
MainWindow::MainWindow()
: QMainWindow()
{
mWidget = new QWidget(this);
setCentralWidget(mWidget);
QVBoxLayout *vLayout = new QVBoxLayout (mWidget);
QLabel *msgLabel = new QLabel(QStringLiteral("Make a two finger swipe gesture in this window."), mWidget);
msgLabel->setAlignment(Qt::AlignHCenter);
mGStarted = new QCheckBox(QStringLiteral("gesture started"), mWidget);
mGStarted->setEnabled(false);
mGUpdated = new QCheckBox(QStringLiteral("gesture updated"), mWidget);
mGUpdated->setEnabled(false);
mGCanceled = new QCheckBox(QStringLiteral("gesture canceled"), mWidget);
mGCanceled->setEnabled(false);
mGFinished = new QCheckBox(QStringLiteral("gesture finished"), mWidget);
mGFinished->setEnabled(false);
mGPos = new QLineEdit(mWidget);
mGPos->setReadOnly(true);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
QLabel *timeLabel = new QLabel(QStringLiteral("maximum duration:"), mWidget);
timeLabel->setSizePolicy(sizePolicy);
mGSwipeTime = new QSpinBox(mWidget);
mGSwipeTime->setMaximum(1000);
QLabel *distanceLabel = new QLabel(QStringLiteral("minimum distance:"), mWidget);
distanceLabel->setSizePolicy(sizePolicy);
mGSwipeDistance = new QSpinBox(mWidget);
mGSwipeDistance->setMaximum(1000);
vLayout->addWidget(msgLabel);
vLayout->addWidget(mGStarted);
vLayout->addWidget(mGUpdated);
vLayout->addWidget(mGCanceled);
vLayout->addWidget(mGFinished);
vLayout->addWidget(mGPos);
vLayout->addWidget(timeLabel);
vLayout->addWidget(mGSwipeTime);
vLayout->addWidget(distanceLabel);
vLayout->addWidget(mGSwipeDistance);
mTwoFingerRec = new KTwoFingerSwipeRecognizer();
mKTwoFingerSwipeGesture = QGestureRecognizer::registerRecognizer(mTwoFingerRec);
mGSwipeTime->setValue(mTwoFingerRec->maxSwipeTime());
mGSwipeDistance->setValue(mTwoFingerRec->minSswipeDistance());
mWidget->grabGesture(mKTwoFingerSwipeGesture);
mWidget->setAttribute(Qt::WA_AcceptTouchEvents);
mWidget->installEventFilter(this);
connect (mGSwipeTime, &QSpinBox::valueChanged, this, &MainWindow::slotSwipeTimeChanged);
connect (mGSwipeDistance, &QSpinBox::valueChanged, this, &MainWindow::slotSwipeDistanceChanged);
}
MainWindow::~MainWindow()
{
}
bool MainWindow::eventFilter(QObject *watched, QEvent *e)
{
if (e->type() == QEvent::TouchBegin) {
resetAll();
}
if (e->type() == QEvent::Gesture) {
QGestureEvent *gEvent = static_cast<QGestureEvent *>(e);
KTwoFingerSwipe *swipe = static_cast<KTwoFingerSwipe *>(gEvent->gesture(mKTwoFingerSwipeGesture));
if (swipe) {
// We need to map the local position, because the tap->pos() is the local position which on received the gesture.
// In this case it is local to the Widgets in the layout.
const QPoint lokalPos = mWidget->mapFromGlobal(swipe->scenePos().toPoint());
QString posStr = QStringLiteral("tap Position = ");
posStr += QString::number(lokalPos.x()) + QStringLiteral(",") + QString::number(lokalPos.y());
const Qt::GestureState state = swipe->state();
if (state == Qt::GestureFinished) {
posStr += QStringLiteral(" angle = ");
posStr += QString::number(swipe->swipeAngle());
mGPos->setText(posStr);
mGFinished->setCheckState(Qt::Checked);
} else if (state == Qt::GestureStarted) {
mGPos->setText(posStr);
mGStarted->setCheckState(Qt::Checked);
} else if (state == Qt::GestureUpdated) {
mGUpdated->setCheckState(Qt::Checked);
} else if (state == Qt::GestureCanceled) {
mGCanceled->setCheckState(Qt::Checked);
}
}
e->accept();
return true;
}
return QObject::eventFilter(watched, e);
}
void MainWindow::resetAll()
{
mGStarted->setCheckState(Qt::Unchecked);
mGUpdated->setCheckState(Qt::Unchecked);
mGCanceled->setCheckState(Qt::Unchecked);
mGFinished->setCheckState(Qt::Unchecked);
mGPos->setText(QString());
}
void MainWindow::slotSwipeTimeChanged(int value)
{
mTwoFingerRec->setMaxSwipeTime(value);
}
void MainWindow::slotSwipeDistanceChanged(int value)
{
mTwoFingerRec->setSwipeDistance(value);
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("ktwofingerswipe_test"));
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.setGeometry(500, 200, 500, 500);
mainWindow.show();
return app.exec();
}
#include "moc_ktwofingerswipe_test.cpp"
@@ -0,0 +1,45 @@
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef KTWOFINGERSWIPE_TEST_H
#define KTWOFINGERSWIPE_TEST_H
#include <QMainWindow>
class QCheckBox;
class QLineEdit;
class QSpinBox;
class KTwoFingerSwipeRecognizer;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow() override;
public Q_SLOTS:
void slotSwipeTimeChanged(int value);
void slotSwipeDistanceChanged(int value);
protected:
bool eventFilter(QObject *watched, QEvent *e) override;
private:
void resetAll();
QWidget *mWidget = nullptr;
KTwoFingerSwipeRecognizer *mTwoFingerRec = nullptr;
Qt::GestureType mKTwoFingerSwipeGesture;
QCheckBox *mGStarted = nullptr;
QCheckBox *mGUpdated = nullptr;
QCheckBox *mGCanceled = nullptr;
QCheckBox *mGFinished = nullptr;
QLineEdit *mGPos = nullptr;
QSpinBox *mGSwipeTime = nullptr;
QSpinBox *mGSwipeDistance = nullptr;
};
#endif
@@ -0,0 +1,143 @@
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "ktwofingertap_test.h"
#include <QApplication>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QLineEdit>
#include <QLabel>
#include <QDebug>
#include <QTouchEvent>
#include <QSpinBox>
#include <ktwofingertap.h>
MainWindow::MainWindow()
: QMainWindow()
{
mWidget = new QWidget(this);
setCentralWidget(mWidget);
QVBoxLayout *vLayout = new QVBoxLayout (mWidget);
QLabel *msgLabel = new QLabel(QStringLiteral("Make a two finger tap gesture in this window."), mWidget);
msgLabel->setAlignment(Qt::AlignHCenter);
mGStarted = new QCheckBox(QStringLiteral("gesture started"), mWidget);
mGStarted->setEnabled(false);
mGUpdated = new QCheckBox(QStringLiteral("gesture updated"), mWidget);
mGUpdated->setEnabled(false);
mGCanceled = new QCheckBox(QStringLiteral("gesture canceled"), mWidget);
mGCanceled->setEnabled(false);
mGFinished = new QCheckBox(QStringLiteral("gesture finished"), mWidget);
mGFinished->setEnabled(false);
mGPos = new QLineEdit(mWidget);
mGPos->setReadOnly(true);
QLabel *radiusLabel = new QLabel(QStringLiteral("current tapRadius:"), mWidget);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
radiusLabel->setSizePolicy(sizePolicy);
mGTapRadius = new QSpinBox(mWidget);
mGTapRadius->setMaximum(1000);
vLayout->addWidget(msgLabel);
vLayout->addWidget(mGStarted);
vLayout->addWidget(mGUpdated);
vLayout->addWidget(mGCanceled);
vLayout->addWidget(mGFinished);
vLayout->addWidget(mGPos);
vLayout->addWidget(radiusLabel);
vLayout->addWidget(mGTapRadius);
mTwoFingerRec = new KTwoFingerTapRecognizer();
kTwoFingerTapGesture = QGestureRecognizer::registerRecognizer(mTwoFingerRec);
mGTapRadius->setValue(mTwoFingerRec->tapRadius());
mWidget->grabGesture(kTwoFingerTapGesture);
mWidget->setAttribute(Qt::WA_AcceptTouchEvents);
mWidget->installEventFilter(this);
connect (mGTapRadius, &QSpinBox::valueChanged, this, &MainWindow::slotSwipeTimeChanged);
}
MainWindow::~MainWindow()
{
}
bool MainWindow::eventFilter(QObject *watched, QEvent *e)
{
if (e->type() == QEvent::TouchBegin) {
resetAll();
}
if (e->type() == QEvent::Gesture) {
QGestureEvent *gEvent = static_cast<QGestureEvent *>(e);
KTwoFingerTap *tap = static_cast<KTwoFingerTap *>(gEvent->gesture(kTwoFingerTapGesture));
if (tap) {
const Qt::GestureState state = tap->state();
if (state == Qt::GestureFinished) {
mGFinished->setCheckState(Qt::Checked);
} else if (state == Qt::GestureStarted) {
// We need to map the local position, because the tap->pos() is the local position which on received the gesture.
// In this case it is local to the Widgets in the layout.
const QPoint lokalPos = mWidget->mapFromGlobal(tap->scenePos().toPoint());
QString posStr = QStringLiteral("tap Position = ");
posStr += QString::number(lokalPos.x()) + QStringLiteral(",") + QString::number(lokalPos.y());
mGPos->setText(posStr);
mGStarted->setCheckState(Qt::Checked);
} else if (state == Qt::GestureUpdated) {
mGUpdated->setCheckState(Qt::Checked);
} else if (state == Qt::GestureCanceled) {
mGCanceled->setCheckState(Qt::Checked);
} else if (mGCanceled->isChecked() && mGFinished->isChecked()) {
qWarning()<<"ERROR: The gesture state is canceled and finished at the same time";
}
}
e->accept();
return true;
}
return QObject::eventFilter(watched, e);
}
void MainWindow::resetAll()
{
mGStarted->setCheckState(Qt::Unchecked);
mGUpdated->setCheckState(Qt::Unchecked);
mGCanceled->setCheckState(Qt::Unchecked);
mGFinished->setCheckState(Qt::Unchecked);
mGPos->setText(QString());
}
void MainWindow::slotSwipeTimeChanged(int value)
{
mTwoFingerRec->setTapRadius(value);
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("ktwofingertap_test"));
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.setGeometry(500, 200, 500, 500);
mainWindow.show();
return app.exec();
}
#include "moc_ktwofingertap_test.cpp"
@@ -0,0 +1,43 @@
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef KTWOFINGERTAP_TEST_H
#define KTWOFINGERTAP_TEST_H
#include <QMainWindow>
class QCheckBox;
class QLineEdit;
class QSpinBox;
class KTwoFingerTapRecognizer;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow() override;
public Q_SLOTS:
void slotSwipeTimeChanged(int value);
protected:
bool eventFilter(QObject *watched, QEvent *e) override;
private:
void resetAll();
QWidget *mWidget = nullptr;
KTwoFingerTapRecognizer *mTwoFingerRec = nullptr;
Qt::GestureType kTwoFingerTapGesture;
QCheckBox *mGStarted = nullptr;
QCheckBox *mGUpdated = nullptr;
QCheckBox *mGCanceled = nullptr;
QCheckBox *mGFinished = nullptr;
QLineEdit *mGPos = nullptr;
QSpinBox *mGTapRadius = nullptr;
};
#endif