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,25 @@
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
remove_definitions(-DQT_NO_CAST_TO_ASCII)
include(ECMMarkAsTest)
find_package(Qt6Test ${REQUIRED_QT_VERSION} CONFIG QUIET)
if(NOT Qt6Test_FOUND)
message(STATUS "Qt6Test not found, manual tests will not be built.")
return()
endif()
macro(kcompletion_executable_tests)
foreach(_testname ${ARGN})
add_executable(${_testname} ${_testname}.cpp ${_testname}.h)
target_link_libraries(${_testname} Qt6::Test Qt6::Widgets KF6::Completion KF6::ConfigCore)
ecm_mark_as_test(${_testname})
endforeach(_testname)
endmacro()
kcompletion_executable_tests(
kcomboboxtest
kcompletionuitest
klineedittest
)
@@ -0,0 +1,242 @@
#include "kcomboboxtest.h"
#include <assert.h>
#include <KConfig>
#include <KConfigGroup>
#include <QApplication>
#include <QBoxLayout>
#include <QDebug>
#include <QLabel>
#include <QLayout>
#include <QPixmap>
#include <QPushButton>
#include <QTimer>
#include <khistorycombobox.h>
KComboBoxTest::KComboBoxTest(QWidget *widget)
: QWidget(widget)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
// Qt combobox
QHBoxLayout *hbox = new QHBoxLayout();
QLabel *lbl = new QLabel(QStringLiteral("&QCombobox:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
hbox->addWidget(lbl);
m_qc = new QComboBox(this);
m_qc->setObjectName(QStringLiteral("QtReadOnlyCombo"));
lbl->setBuddy(m_qc);
connectComboSignals(m_qc);
hbox->addWidget(m_qc);
vbox->addLayout(hbox);
// Read-only combobox
hbox = new QHBoxLayout();
lbl = new QLabel(QStringLiteral("&Read-Only Combo:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
hbox->addWidget(lbl);
m_ro = new KComboBox(this);
m_ro->setObjectName(QStringLiteral("ReadOnlyCombo"));
lbl->setBuddy(m_ro);
m_ro->setCompletionMode(KCompletion::CompletionAuto);
connectComboSignals(m_ro);
hbox->addWidget(m_ro);
vbox->addLayout(hbox);
// Read-write combobox
hbox = new QHBoxLayout();
lbl = new QLabel(QStringLiteral("&Editable Combo:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
hbox->addWidget(lbl);
m_rw = new KComboBox(true, this);
m_rw->setObjectName(QStringLiteral("ReadWriteCombo"));
lbl->setBuddy(m_rw);
m_rw->setDuplicatesEnabled(true);
m_rw->setInsertPolicy(QComboBox::NoInsert);
m_rw->setTrapReturnKey(true);
connectComboSignals(m_rw);
hbox->addWidget(m_rw);
vbox->addLayout(hbox);
// History combobox...
hbox = new QHBoxLayout();
lbl = new QLabel(QStringLiteral("&History Combo:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
hbox->addWidget(lbl);
m_hc = new KHistoryComboBox(this);
m_hc->setObjectName(QStringLiteral("HistoryCombo"));
lbl->setBuddy(m_hc);
m_hc->setDuplicatesEnabled(true);
m_hc->setInsertPolicy(QComboBox::NoInsert);
connectComboSignals(m_hc);
m_hc->setTrapReturnKey(true);
hbox->addWidget(m_hc);
vbox->addLayout(hbox);
// Read-write combobox that is a replica of code in konqueror...
hbox = new QHBoxLayout();
lbl = new QLabel(QStringLiteral("&Konq's Combo:"), this);
lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
hbox->addWidget(lbl);
m_konqc = new KComboBox(true, this);
m_konqc->setObjectName(QStringLiteral("KonqyCombo"));
lbl->setBuddy(m_konqc);
m_konqc->setMaxCount(10);
connectComboSignals(m_konqc);
hbox->addWidget(m_konqc);
vbox->addLayout(hbox);
// Create an exit button
hbox = new QHBoxLayout();
m_btnExit = new QPushButton(QStringLiteral("E&xit"), this);
QObject::connect(m_btnExit, &QAbstractButton::clicked, this, &KComboBoxTest::quitApp);
hbox->addWidget(m_btnExit);
// Create a disable button...
m_btnEnable = new QPushButton(QStringLiteral("Disa&ble"), this);
QObject::connect(m_btnEnable, &QAbstractButton::clicked, this, &KComboBoxTest::slotDisable);
hbox->addWidget(m_btnEnable);
vbox->addLayout(hbox);
// Populate the select-only list box
QStringList list;
list << QStringLiteral("Stone") << QStringLiteral("Tree") << QStringLiteral("Peables") << QStringLiteral("Ocean") << QStringLiteral("Sand")
<< QStringLiteral("Chips") << QStringLiteral("Computer") << QStringLiteral("Mankind");
list.sort();
// Setup the qcombobox
m_qc->addItems(list);
// Setup read-only combo
m_ro->addItems(list);
m_ro->completionObject()->setItems(list);
// Setup read-write combo
m_rw->addItems(list);
m_rw->completionObject()->setItems(list);
// Setup history combo
m_hc->addItems(list);
m_hc->completionObject()->setItems(list + QStringList() << QStringLiteral("One") << QStringLiteral("Two") << QStringLiteral("Three"));
// Setup konq's combobox
KConfig historyConfig(QStringLiteral("konq_history"), KConfig::SimpleConfig);
KConfigGroup cg(&historyConfig, QStringLiteral("Location Bar"));
KCompletion *s_pCompletion = new KCompletion;
s_pCompletion->setOrder(KCompletion::Weighted);
s_pCompletion->setItems(cg.readEntry("ComboContents", QStringList()));
s_pCompletion->setCompletionMode(KCompletion::CompletionPopup);
m_konqc->setCompletionObject(s_pCompletion);
QPixmap pix(16, 16);
pix.fill(Qt::blue);
m_konqc->addItem(pix, QStringLiteral("http://www.kde.org"));
m_konqc->setCurrentIndex(m_konqc->count() - 1);
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &KComboBoxTest::slotTimeout);
}
KComboBoxTest::~KComboBoxTest()
{
delete m_timer;
m_timer = nullptr;
}
void KComboBoxTest::connectComboSignals(QComboBox *combo)
{
QObject::connect(combo, qOverload<int>(&QComboBox::activated), this, &KComboBoxTest::slotActivated);
QObject::connect(combo, &QComboBox::textActivated, this, &KComboBoxTest::slotTextActivated);
QObject::connect(combo, qOverload<int>(&QComboBox::currentIndexChanged), this, &KComboBoxTest::slotCurrentIndexChanged);
QObject::connect(combo, qOverload<int>(&QComboBox::currentIndexChanged), this, [this, combo](const int index) {
slotCurrentTextChanged(combo->itemText(index));
});
QObject::connect(combo, &QComboBox::textActivated, this, qOverload<const QString &>(&KComboBoxTest::slotReturnPressed));
}
void KComboBoxTest::slotDisable()
{
if (m_timer->isActive()) {
return;
}
m_btnEnable->setEnabled(!m_btnEnable->isEnabled());
m_timer->setSingleShot(true);
m_timer->start(5000);
}
void KComboBoxTest::slotTimeout()
{
bool enabled = m_ro->isEnabled();
if (enabled) {
m_btnEnable->setText(QStringLiteral("Ena&ble"));
} else {
m_btnEnable->setText(QStringLiteral("Disa&ble"));
}
m_qc->setEnabled(!enabled);
m_ro->setEnabled(!enabled);
m_rw->setEnabled(!enabled);
m_hc->setEnabled(!enabled);
m_konqc->setEnabled(!enabled);
m_btnEnable->setEnabled(!m_btnEnable->isEnabled());
}
void KComboBoxTest::slotCurrentIndexChanged(int index)
{
qDebug() << qPrintable(sender()->objectName()) << ", index:" << index;
}
void KComboBoxTest::slotCurrentTextChanged(const QString &item)
{
qDebug() << qPrintable(sender()->objectName()) << ", item:" << item;
}
void KComboBoxTest::slotActivated(int index)
{
qDebug() << "Activated Combo:" << qPrintable(sender()->objectName()) << ", index:" << index;
}
void KComboBoxTest::slotTextActivated(const QString &item)
{
qDebug() << "Activated Combo:" << qPrintable(sender()->objectName()) << ", item:" << item;
}
void KComboBoxTest::slotReturnPressed(const QString &item)
{
qDebug() << "Return Pressed:" << qPrintable(sender()->objectName()) << ", value =" << item;
}
void KComboBoxTest::quitApp()
{
qApp->closeAllWindows();
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kcomboboxtest"));
QApplication a(argc, argv);
KComboBoxTest *t = new KComboBoxTest;
t->show();
return a.exec();
}
#include "moc_kcomboboxtest.cpp"
@@ -0,0 +1,48 @@
#ifndef _KCOMBOBOXTEST_H
#define _KCOMBOBOXTEST_H
#include <kcompletion_export.h>
#include <QWidget>
class QTimer;
class QComboBox;
class QPushButton;
class KComboBox;
class KComboBoxTest : public QWidget
{
Q_OBJECT
public:
KComboBoxTest(QWidget *parent = nullptr);
~KComboBoxTest() override;
private Q_SLOTS:
void quitApp();
void slotTimeout();
void slotDisable();
void slotReturnPressed(const QString &);
void slotActivated(int);
void slotTextActivated(const QString &);
void slotCurrentIndexChanged(int);
void slotCurrentTextChanged(const QString &);
private:
void connectComboSignals(QComboBox *combo);
QComboBox *m_qc;
KComboBox *m_ro;
KComboBox *m_rw;
KComboBox *m_hc;
KComboBox *m_konqc;
QPushButton *m_btnExit;
QPushButton *m_btnEnable;
QTimer *m_timer;
};
#endif
@@ -0,0 +1,197 @@
#include "kcompletionuitest.h"
#include <QApplication>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
#include <QListWidget>
#include <QPushButton>
#include <khistorycombobox.h>
#include <klineedit.h>
Form1::Form1(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
resize(559, 465);
setWindowTitle(QStringLiteral("Form1"));
Form1Layout = new QVBoxLayout(this);
GroupBox1 = new QGroupBox(this);
GroupBox1->setLayout(new QVBoxLayout());
GroupBox1->setTitle(QStringLiteral("Completion Test"));
GroupBox1->layout()->setSpacing(0);
GroupBox1->layout()->setContentsMargins(0, 0, 0, 0);
GroupBox1Layout = new QVBoxLayout;
GroupBox1Layout->setAlignment(Qt::AlignTop);
GroupBox1->layout()->addItem(GroupBox1Layout);
GroupBox1Layout->setParent(GroupBox1->layout());
Layout9 = new QVBoxLayout;
Layout9->setSpacing(6);
Layout9->setContentsMargins(0, 0, 0, 0);
Layout1 = new QHBoxLayout;
Layout1->setSpacing(6);
Layout1->setContentsMargins(0, 0, 0, 0);
TextLabel1 = new QLabel(GroupBox1);
TextLabel1->setObjectName(QStringLiteral("TextLabel1"));
TextLabel1->setText(QStringLiteral("Completion"));
Layout1->addWidget(TextLabel1);
edit = new KLineEdit(GroupBox1);
edit->setObjectName(QStringLiteral("edit"));
Layout1->addWidget(edit);
Layout9->addLayout(Layout1);
edit->completionObject()->setItems(defaultItems());
edit->completionObject()->setIgnoreCase(true);
edit->setFocus();
edit->setToolTip(QStringLiteral("right-click to change completion mode"));
Layout2 = new QHBoxLayout;
Layout2->setSpacing(6);
Layout2->setContentsMargins(0, 0, 0, 0);
combo = new KHistoryComboBox(GroupBox1);
combo->setObjectName(QStringLiteral("history combo"));
combo->setCompletionObject(edit->completionObject());
// combo->setMaxCount( 5 );
combo->setHistoryItems(defaultItems(), true);
connect(combo, &QComboBox::textActivated, combo, &KHistoryComboBox::addToHistory);
combo->setToolTip(QStringLiteral("KHistoryComboBox"));
Layout2->addWidget(combo);
LineEdit1 = new KLineEdit(GroupBox1);
LineEdit1->setObjectName(QStringLiteral("LineEdit1"));
Layout2->addWidget(LineEdit1);
PushButton1 = new QPushButton(GroupBox1);
PushButton1->setObjectName(QStringLiteral("PushButton1"));
PushButton1->setText(QStringLiteral("Add"));
connect(PushButton1, &QAbstractButton::clicked, this, &Form1::slotAdd);
Layout2->addWidget(PushButton1);
Layout9->addLayout(Layout2);
Layout3 = new QHBoxLayout;
Layout3->setSpacing(6);
Layout3->setContentsMargins(0, 0, 0, 0);
QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
Layout3->addItem(spacer);
PushButton1_4 = new QPushButton(GroupBox1);
PushButton1_4->setObjectName(QStringLiteral("PushButton1_4"));
PushButton1_4->setText(QStringLiteral("Remove"));
connect(PushButton1_4, &QAbstractButton::clicked, this, &Form1::slotRemove);
Layout3->addWidget(PushButton1_4);
Layout9->addLayout(Layout3);
Layout8 = new QHBoxLayout;
Layout8->setSpacing(6);
Layout8->setContentsMargins(0, 0, 0, 0);
ListBox1 = new QListWidget(GroupBox1);
Layout8->addWidget(ListBox1);
connect(ListBox1, &QListWidget::currentRowChanged, this, &Form1::slotHighlighted);
ListBox1->setToolTip(QStringLiteral("Contains the contents of the completion object.\n:x is the weighting, i.e. how often an item has been inserted"));
Layout7 = new QVBoxLayout;
Layout7->setSpacing(6);
Layout7->setContentsMargins(0, 0, 0, 0);
PushButton1_3 = new QPushButton(GroupBox1);
PushButton1_3->setObjectName(QStringLiteral("PushButton1_3"));
PushButton1_3->setText(QStringLiteral("Completion items"));
connect(PushButton1_3, &QAbstractButton::clicked, this, &Form1::slotList);
Layout7->addWidget(PushButton1_3);
PushButton1_2 = new QPushButton(GroupBox1);
PushButton1_2->setObjectName(QStringLiteral("PushButton1_2"));
PushButton1_2->setText(QStringLiteral("Clear"));
connect(PushButton1_2, &QAbstractButton::clicked, edit->completionObject(), &KCompletion::clear);
Layout7->addWidget(PushButton1_2);
Layout8->addLayout(Layout7);
Layout9->addLayout(Layout8);
GroupBox1Layout->addLayout(Layout9);
Form1Layout->addWidget(GroupBox1);
slotList();
}
/*
* Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
// no need to delete child widgets, Qt does it all for us
}
void Form1::slotAdd()
{
qDebug("** adding: %s", LineEdit1->text().toLatin1().constData());
edit->completionObject()->addItem(LineEdit1->text());
QStringList matches = edit->completionObject()->allMatches(QStringLiteral("S"));
QStringList::ConstIterator it = matches.constBegin();
for (; it != matches.constEnd(); ++it) {
qDebug("-- %s", (*it).toLatin1().constData());
}
}
void Form1::slotRemove()
{
edit->completionObject()->removeItem(LineEdit1->text());
}
void Form1::slotList()
{
ListBox1->clear();
QStringList items = edit->completionObject()->items();
ListBox1->addItems(items);
}
void Form1::slotHighlighted(int row)
{
if (row == -1) {
return;
}
QListWidgetItem *i = ListBox1->item(row);
Q_ASSERT(i != nullptr);
QString text = i->text();
// remove any "weighting"
int index = text.lastIndexOf(QLatin1Char(':'));
if (index > 0) {
LineEdit1->setText(text.left(index));
} else {
LineEdit1->setText(text);
}
}
QStringList Form1::defaultItems() const
{
// clang-format off
QStringList items;
items << QStringLiteral("Super") << QStringLiteral("Sushi") << QStringLiteral("Samson") << QStringLiteral("Sucks") << QStringLiteral("Sumo") << QStringLiteral("Schumi");
items << QStringLiteral("Slashdot") << QStringLiteral("sUpEr") << QStringLiteral("SUshi") << QStringLiteral("sUshi") << QStringLiteral("sUShi");
items << QStringLiteral("sushI") << QStringLiteral("SushI");
// clang-format on
return items;
}
int main(int argc, char **argv)
{
QApplication::setApplicationName(QStringLiteral("kcompletiontest"));
QApplication app(argc, argv);
Form1 *form = new Form1();
form->show();
return app.exec();
}
#include "moc_kcompletionuitest.cpp"
@@ -0,0 +1,55 @@
#ifndef KCOMPLETIONUITEST_H
#define KCOMPLETIONUITEST_H
#include <QStringList>
#include <QWidget>
class QVBoxLayout;
class QHBoxLayout;
class QGroupBox;
class QLabel;
class QListWidget;
class QPushButton;
class KHistoryComboBox;
class KLineEdit;
class Form1 : public QWidget
{
Q_OBJECT
public:
Form1(QWidget *parent = nullptr);
~Form1() override;
QGroupBox *GroupBox1;
QLabel *TextLabel1;
KLineEdit *LineEdit1;
QPushButton *PushButton1;
QPushButton *PushButton1_4;
QListWidget *ListBox1;
QPushButton *PushButton1_3;
QPushButton *PushButton1_2;
KLineEdit *edit;
KHistoryComboBox *combo;
protected Q_SLOTS:
void slotList();
void slotAdd();
void slotRemove();
void slotHighlighted(int);
protected:
QStringList defaultItems() const;
QVBoxLayout *Form1Layout;
QVBoxLayout *GroupBox1Layout;
QVBoxLayout *Layout9;
QHBoxLayout *Layout1;
QHBoxLayout *Layout2;
QHBoxLayout *Layout3;
QHBoxLayout *Layout8;
QVBoxLayout *Layout7;
};
#endif // KCOMPLETIONUITEST_H
@@ -0,0 +1,186 @@
#include "klineedittest.h"
#include <QApplication>
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QTimer>
#include <klineedit.h>
KLineEditTest::KLineEditTest(QWidget *widget)
: QWidget(widget)
{
QVBoxLayout *layout = new QVBoxLayout(this);
QStringList list;
list << QStringLiteral("Tree") << QStringLiteral("Suuupa") << QStringLiteral("Stroustrup") << QStringLiteral("Stone") << QStringLiteral("Slick")
<< QStringLiteral("Slashdot") << QStringLiteral("Send") << QStringLiteral("Peables") << QStringLiteral("Mankind") << QStringLiteral("Ocean")
<< QStringLiteral("Chips") << QStringLiteral("Computer") << QStringLiteral("Sandworm") << QStringLiteral("Sandstorm") << QStringLiteral("Chops");
list.sort();
m_lineedit = new KLineEdit(this);
m_lineedit->setObjectName(QStringLiteral("klineedittest"));
m_lineedit->completionObject()->setItems(list);
m_lineedit->setSqueezedTextEnabled(true);
m_lineedit->setClearButtonEnabled(true);
connect(m_lineedit, &QLineEdit::returnPressed, this, &KLineEditTest::slotReturnPressed);
connect(m_lineedit, &KLineEdit::returnKeyPressed, this, &KLineEditTest::slotReturnKeyPressed);
QHBoxLayout *restrictedHBox = new QHBoxLayout;
m_restrictedLine = new KLineEdit(this);
QRegularExpression regex(QStringLiteral("[aeiouyé]*"));
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regex, m_restrictedLine);
m_restrictedLine->setValidator(validator);
// connect(m_restrictedLine, SIGNAL(invalidChar(int)), this, SLOT(slotInvalidChar(int)));
connect(m_restrictedLine, &QLineEdit::returnPressed, this, &KLineEditTest::slotReturnPressed);
connect(m_restrictedLine, &KLineEdit::returnKeyPressed, this, &KLineEditTest::slotReturnKeyPressed);
restrictedHBox->addWidget(new QLabel(QStringLiteral("Vowels only:"), this));
restrictedHBox->addWidget(m_restrictedLine);
m_invalidCharLabel = new QLabel(this);
restrictedHBox->addWidget(m_invalidCharLabel);
// horizontal button layout
m_btnExit = new QPushButton(QStringLiteral("E&xit"), this);
connect(m_btnExit, &QAbstractButton::clicked, this, &KLineEditTest::quitApp);
m_btnReadOnly = new QPushButton(QStringLiteral("&Read Only"), this);
m_btnReadOnly->setCheckable(true);
connect(m_btnReadOnly, &QAbstractButton::toggled, this, &KLineEditTest::slotReadOnly);
m_btnPassword = new QPushButton(QStringLiteral("&Password"), this);
m_btnPassword->setCheckable(true);
connect(m_btnPassword, &QAbstractButton::toggled, this, &KLineEditTest::slotPassword);
m_btnEnable = new QPushButton(QStringLiteral("Dis&able"), this);
m_btnEnable->setCheckable(true);
connect(m_btnEnable, &QAbstractButton::toggled, this, &KLineEditTest::slotEnable);
m_btnHide = new QPushButton(QStringLiteral("Hi&de"), this);
connect(m_btnHide, &QAbstractButton::clicked, this, &KLineEditTest::slotHide);
m_btnPlaceholderText = new QPushButton(QStringLiteral("Place Holder Text"), this);
m_btnPlaceholderText->setCheckable(true);
connect(m_btnPlaceholderText, &QAbstractButton::toggled, this, &KLineEditTest::slotPlaceholderText);
QPushButton *btnStyle = new QPushButton(QStringLiteral("Stylesheet"), this);
connect(btnStyle, &QAbstractButton::clicked, this, &KLineEditTest::slotSetStyleSheet);
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addWidget(m_btnExit);
buttonLayout->addWidget(m_btnReadOnly);
buttonLayout->addWidget(m_btnPassword);
buttonLayout->addWidget(m_btnEnable);
buttonLayout->addWidget(m_btnHide);
buttonLayout->addWidget(m_btnPlaceholderText);
buttonLayout->addWidget(btnStyle);
layout->addWidget(m_lineedit);
layout->addLayout(restrictedHBox);
layout->addLayout(buttonLayout);
setWindowTitle(QStringLiteral("KLineEdit Unit Test"));
}
KLineEditTest::~KLineEditTest()
{
}
void KLineEditTest::quitApp()
{
qApp->closeAllWindows();
}
void KLineEditTest::slotSetStyleSheet()
{
m_lineedit->setStyleSheet(QStringLiteral("QLineEdit{ background-color:#baf9ce }"));
}
void KLineEditTest::show()
{
if (m_lineedit->isHidden()) {
m_lineedit->show();
}
m_btnHide->setEnabled(true);
QWidget::show();
}
void KLineEditTest::slotReturnPressed()
{
qDebug() << "Return pressed";
}
void KLineEditTest::slotReturnKeyPressed(const QString &text)
{
qDebug() << "Return pressed: " << text;
}
void KLineEditTest::resultOutput(const QString &text)
{
qDebug() << "KlineEditTest Debug: " << text;
}
void KLineEditTest::slotReadOnly(bool ro)
{
m_lineedit->setReadOnly(ro);
QString text = (ro) ? "&Read Write" : "&Read Only";
m_btnReadOnly->setText(text);
}
void KLineEditTest::slotPassword(bool pw)
{
m_lineedit->setEchoMode(pw ? QLineEdit::Password : QLineEdit::Normal);
QString text = (pw) ? "&Normal Text" : "&Password";
m_btnPassword->setText(text);
}
void KLineEditTest::slotEnable(bool enable)
{
m_lineedit->setEnabled(!enable);
QString text = (enable) ? "En&able" : "Dis&able";
m_btnEnable->setText(text);
}
void KLineEditTest::slotPlaceholderText(bool click)
{
if (click) {
m_lineedit->setText(QLatin1String("")); // Clear before to add message
m_lineedit->setPlaceholderText(QStringLiteral("Click in this lineedit"));
}
}
void KLineEditTest::slotHide()
{
m_lineedit->hide();
m_btnHide->setEnabled(false);
m_lineedit->setText(
"My dog ate the homework, whaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaa! I want my mommy!");
QTimer::singleShot(1000, this, &KLineEditTest::show);
}
void KLineEditTest::slotInvalidChar(int key)
{
m_invalidCharLabel->setText(QStringLiteral("Invalid char: %1").arg(key));
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
KLineEditTest *t = new KLineEditTest();
// t->lineEdit()->setTrapReturnKey( true );
// t->lineEdit()->completionBox()->setTabHandling( false );
t->lineEdit()->setSqueezedTextEnabled(true);
t->lineEdit()->setText(
"This is a really really really really really really "
"really really long line because I am a talkative fool!"
"I mean ... REALLY talkative. If you don't believe me, ask my cousin.");
t->show();
return a.exec();
}
#include "moc_klineedittest.cpp"
@@ -0,0 +1,54 @@
#ifndef _KLINEEDITTEST_H
#define _KLINEEDITTEST_H
#include <QWidget>
class QLabel;
class QLineEdit;
class QString;
class QPushButton;
class KLineEdit;
class KLineEditTest : public QWidget
{
Q_OBJECT
public:
KLineEditTest(QWidget *parent = nullptr);
~KLineEditTest() override;
KLineEdit *lineEdit() const
{
return m_lineedit;
}
public Q_SLOTS:
virtual void show();
private Q_SLOTS:
void quitApp();
void slotHide();
void slotEnable(bool);
void slotReadOnly(bool);
void slotPassword(bool);
void slotReturnPressed();
void resultOutput(const QString &);
void slotReturnKeyPressed(const QString &);
void slotPlaceholderText(bool click);
void slotInvalidChar(int);
void slotSetStyleSheet();
protected:
KLineEdit *m_lineedit;
KLineEdit *m_restrictedLine;
QLabel *m_invalidCharLabel;
QPushButton *m_btnExit;
QPushButton *m_btnReadOnly;
QPushButton *m_btnPassword;
QPushButton *m_btnEnable;
QPushButton *m_btnHide;
QPushButton *m_btnPlaceholderText;
QPushButton *m_btnClickMessage;
};
#endif