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:
@@ -0,0 +1,29 @@
|
||||
|
||||
include(ECMMarkAsTest)
|
||||
|
||||
find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test)
|
||||
|
||||
macro(xmlgui_executable_tests)
|
||||
foreach(_testname ${ARGN})
|
||||
add_executable(${_testname} ${_testname}.cpp)
|
||||
target_link_libraries(${_testname} Qt6::Test KF6::CoreAddons KF6::WidgetsAddons KF6::I18n KF6::XmlGui)
|
||||
ecm_mark_as_test(${_testname})
|
||||
endforeach(_testname)
|
||||
endmacro()
|
||||
|
||||
xmlgui_executable_tests(
|
||||
kbugreporttest
|
||||
kmainwindowrestoretest
|
||||
kmainwindowtest
|
||||
krulertest
|
||||
ktoolbartest
|
||||
kxmlguitest
|
||||
kxmlguiwindowtest
|
||||
kwindowtest
|
||||
)
|
||||
|
||||
# KTextWidgets dependency is only needed for this test
|
||||
find_package(KF6TextWidgets QUIET)
|
||||
if(TARGET KF6::TextWidgets)
|
||||
add_subdirectory(krichtexteditor)
|
||||
endif()
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
This file is part of the KDE libraries
|
||||
SPDX-FileCopyrightText: 2005 Joseph Wenninger <jowenn@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KLocalizedString>
|
||||
#include <QApplication>
|
||||
#include <kbugreport.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setQuitOnLastWindowClosed(false);
|
||||
|
||||
// First a bug report to bugs.kde.org
|
||||
KAboutData about(QStringLiteral("kbugreporttest"), i18n("kbugreporttest"), QStringLiteral("version"));
|
||||
KBugReport rep(about);
|
||||
rep.exec();
|
||||
|
||||
// Then a bug report by email.
|
||||
// Change the email address to check if it worked :)
|
||||
KAboutData about1(QStringLiteral("kbugreporttest"),
|
||||
i18n("kbugreporttest"),
|
||||
QStringLiteral("version"),
|
||||
i18n("description"),
|
||||
KAboutLicense::Unknown,
|
||||
i18n("copyright"),
|
||||
i18n("bug report tool"),
|
||||
QString(),
|
||||
QStringLiteral("null@bugs.kde.org"));
|
||||
KBugReport rep1(about1);
|
||||
rep1.exec();
|
||||
|
||||
// Then a web bug report.
|
||||
KAboutData about2(QStringLiteral("kbugreporttest"),
|
||||
i18n("kbugreporttest"),
|
||||
QStringLiteral("version"),
|
||||
i18n("description"),
|
||||
KAboutLicense::Unknown,
|
||||
i18n("copyright"),
|
||||
i18n("bug report tool"),
|
||||
QString(),
|
||||
QStringLiteral("https://bugs.kde.org"));
|
||||
KBugReport rep2(about2);
|
||||
rep2.exec();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#include "kmainwindowrestoretest.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
|
||||
// clang-format off
|
||||
#define MAKE_WINDOW( kind, title ) do { \
|
||||
MainWin##kind * m = new MainWin##kind; \
|
||||
m->setCaption( title ); \
|
||||
m->setCentralWidget( new QLabel( title, m ) ); \
|
||||
m->show(); \
|
||||
} while ( false )
|
||||
// clang-format on
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("kmainwindowrestoretest"));
|
||||
QApplication app(argc, argv);
|
||||
|
||||
if (qApp->isSessionRestored()) {
|
||||
kRestoreMainWindows<MainWin1, MainWin2, MainWin3>();
|
||||
kRestoreMainWindows<MainWin4, MainWin5>();
|
||||
kRestoreMainWindows<MainWin6>(); // should be equivalent to RESTORE()
|
||||
} else {
|
||||
MAKE_WINDOW(1, QStringLiteral("First 1"));
|
||||
MAKE_WINDOW(1, QStringLiteral("Second 1"));
|
||||
MAKE_WINDOW(2, QStringLiteral("Only 2"));
|
||||
MAKE_WINDOW(3, QStringLiteral("First 3"));
|
||||
MAKE_WINDOW(4, QStringLiteral("First 4"));
|
||||
MAKE_WINDOW(4, QStringLiteral("Second 4"));
|
||||
MAKE_WINDOW(3, QStringLiteral("Second 3"));
|
||||
MAKE_WINDOW(4, QStringLiteral("Third 4"));
|
||||
MAKE_WINDOW(5, QStringLiteral("First 5"));
|
||||
MAKE_WINDOW(5, QStringLiteral("Second 5"));
|
||||
MAKE_WINDOW(1, QStringLiteral("Only 6"));
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "moc_kmainwindowrestoretest.cpp"
|
||||
@@ -0,0 +1,84 @@
|
||||
#ifndef _KDEUI_TESTS_KMAINWINDOWRESTORETEST_H_
|
||||
#define _KDEUI_TESTS_KMAINWINDOWRESTORETEST_H_
|
||||
|
||||
#include <kmainwindow.h>
|
||||
|
||||
class MainWin1 : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWin1()
|
||||
: KMainWindow()
|
||||
{
|
||||
}
|
||||
~MainWin1() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class MainWin2 : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWin2()
|
||||
: KMainWindow()
|
||||
{
|
||||
}
|
||||
~MainWin2() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class MainWin3 : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWin3()
|
||||
: KMainWindow()
|
||||
{
|
||||
}
|
||||
~MainWin3() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class MainWin4 : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWin4()
|
||||
: KMainWindow()
|
||||
{
|
||||
}
|
||||
~MainWin4() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class MainWin5 : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWin5()
|
||||
: KMainWindow()
|
||||
{
|
||||
}
|
||||
~MainWin5() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class MainWin6 : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWin6()
|
||||
: KMainWindow()
|
||||
{
|
||||
}
|
||||
~MainWin6() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _KDEUI_TESTS_KMAINWINDOWRESTORETEST_H_
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2002 Simon Hausmann <hausmann@kde.org>
|
||||
SPDX-FileCopyrightText: 2005-2006 David Faure <faure@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "kmainwindowtest.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QTimer>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
QTimer::singleShot(2 * 1000, this, &MainWindow::showMessage);
|
||||
|
||||
setCentralWidget(new QLabel(QStringLiteral("foo"), this));
|
||||
|
||||
menuBar()->addAction(QStringLiteral("hi"));
|
||||
}
|
||||
|
||||
void MainWindow::showMessage()
|
||||
{
|
||||
statusBar()->show();
|
||||
statusBar()->showMessage(QStringLiteral("test"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("kmainwindowtest"));
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow *mw = new MainWindow; // deletes itself when closed
|
||||
mw->show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "moc_kmainwindowtest.cpp"
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2002 Simon Hausmann <hausmann@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef KMAINWINDOWTEST_H
|
||||
#define KMAINWINDOWTEST_H
|
||||
|
||||
#include <kmainwindow.h>
|
||||
|
||||
class MainWindow : public KMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
private Q_SLOTS:
|
||||
void showMessage();
|
||||
};
|
||||
|
||||
#endif // KMAINWINDOWTEST_H
|
||||
@@ -0,0 +1,17 @@
|
||||
add_executable(krichtexteditor)
|
||||
|
||||
target_sources(krichtexteditor PRIVATE
|
||||
main.cpp
|
||||
krichtexteditor.cpp
|
||||
)
|
||||
|
||||
target_include_directories(krichtexteditor PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
${CMAKE_CURRENT_BINARY_DIR}/..
|
||||
)
|
||||
ecm_mark_as_test(krichtexteditor)
|
||||
target_link_libraries(krichtexteditor Qt6::Test KF6::ConfigWidgets KF6::TextWidgets KF6::XmlGui)
|
||||
|
||||
#install(TARGETS krichtexteditor DESTINATION ${KDE_INSTALL_BINDIR})
|
||||
#install(FILES krichtexteditorui.rc DESTINATION ${KDE_INSTALL_KXMLGUIDIR}/krichtexteditor)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
KDE Rich Text Editor
|
||||
SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#include "krichtexteditor.h"
|
||||
|
||||
#include <KStandardActions>
|
||||
#include <kactioncollection.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QSaveFile>
|
||||
#include <QStatusBar>
|
||||
#include <QTest>
|
||||
#include <QTextStream>
|
||||
|
||||
KRichTextEditor::KRichTextEditor()
|
||||
: KXmlGuiWindow()
|
||||
{
|
||||
setupActions();
|
||||
|
||||
textArea = new KRichTextWidget(this);
|
||||
setCentralWidget(textArea);
|
||||
|
||||
actionCollection()->addActions(textArea->createActions());
|
||||
|
||||
setupGUI(KXmlGuiWindow::Default, QFINDTESTDATA("krichtexteditorui.rc"));
|
||||
|
||||
itemLabel = new QLabel;
|
||||
statusBar()->addWidget(itemLabel);
|
||||
|
||||
connect(textArea, &KRichTextWidget::cursorPositionChanged, this, &KRichTextEditor::cursorPositionChanged);
|
||||
}
|
||||
|
||||
KRichTextEditor::~KRichTextEditor()
|
||||
{
|
||||
}
|
||||
|
||||
void KRichTextEditor::setupActions()
|
||||
{
|
||||
KStandardActions::quit(qApp, &QCoreApplication::quit, actionCollection());
|
||||
|
||||
KStandardActions::open(this, &KRichTextEditor::openFile, actionCollection());
|
||||
|
||||
KStandardActions::save(this, &KRichTextEditor::saveFile, actionCollection());
|
||||
|
||||
KStandardActions::saveAs(this, qOverload<>(&KRichTextEditor::saveFileAs), actionCollection());
|
||||
|
||||
KStandardActions::openNew(this, &KRichTextEditor::newFile, actionCollection());
|
||||
}
|
||||
|
||||
void KRichTextEditor::cursorPositionChanged()
|
||||
{
|
||||
// Show link target in status bar
|
||||
if (textArea->textCursor().charFormat().isAnchor()) {
|
||||
QString text = textArea->currentLinkText();
|
||||
QString url = textArea->currentLinkUrl();
|
||||
itemLabel->setText(text + QStringLiteral(" -> ") + url);
|
||||
} else {
|
||||
itemLabel->setText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextEditor::newFile()
|
||||
{
|
||||
// maybeSave
|
||||
fileName.clear();
|
||||
textArea->clear();
|
||||
}
|
||||
|
||||
void KRichTextEditor::saveFileAs(const QString &outputFileName)
|
||||
{
|
||||
QSaveFile file(outputFileName);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray outputByteArray;
|
||||
outputByteArray.append(textArea->toHtml().toUtf8());
|
||||
file.write(outputByteArray);
|
||||
if (!file.commit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fileName = outputFileName;
|
||||
}
|
||||
|
||||
void KRichTextEditor::saveFileAs()
|
||||
{
|
||||
saveFileAs(QFileDialog::getSaveFileName());
|
||||
}
|
||||
|
||||
void KRichTextEditor::saveFile()
|
||||
{
|
||||
if (!fileName.isEmpty()) {
|
||||
saveFileAs(fileName);
|
||||
} else {
|
||||
saveFileAs();
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextEditor::openFile()
|
||||
{
|
||||
QString fileNameFromDialog = QFileDialog::getOpenFileName();
|
||||
if (fileNameFromDialog.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(fileNameFromDialog);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
textArea->setTextOrHtml(QTextStream(&file).readAll());
|
||||
fileName = fileNameFromDialog;
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_krichtexteditor.cpp"
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
KDE Rich Text Editor
|
||||
SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#ifndef KRICHTEXTEDITOR_H
|
||||
#define KRICHTEXTEDITOR_H
|
||||
|
||||
#include <KRichTextWidget>
|
||||
|
||||
#include <kxmlguiwindow.h>
|
||||
|
||||
//@cond PRIVATE
|
||||
|
||||
class QLabel;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Test window for testing KRichTextWidget
|
||||
*/
|
||||
class KRichTextEditor : public KXmlGuiWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KRichTextEditor();
|
||||
~KRichTextEditor() override;
|
||||
|
||||
void setupActions();
|
||||
|
||||
private Q_SLOTS:
|
||||
void newFile();
|
||||
void openFile();
|
||||
void saveFile();
|
||||
void saveFileAs();
|
||||
void saveFileAs(const QString &outputFileName);
|
||||
void cursorPositionChanged();
|
||||
|
||||
private:
|
||||
KRichTextWidget *textArea;
|
||||
QString fileName;
|
||||
QLabel *itemLabel;
|
||||
};
|
||||
|
||||
//@endcond
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
|
||||
<gui name="krichtexteditor" version="14">
|
||||
|
||||
<MenuBar>
|
||||
<Menu noMerge="1" name="format"><text>F&ormat</text>
|
||||
<Action name="format_text_bold"/>
|
||||
<Action name="format_text_italic"/>
|
||||
<Action name="format_text_underline"/>
|
||||
<Action name="format_text_strikeout"/>
|
||||
<Action name="format_text_foreground_color"/>
|
||||
<Action name="format_text_background_color"/>
|
||||
<Action name="format_text_superscript"/>
|
||||
<Action name="format_text_subscript"/>
|
||||
<Separator/>
|
||||
<Action name="format_heading_level"/>
|
||||
<Separator/>
|
||||
<Menu name="alignment"><text>&Alignment</text>
|
||||
<Action name="format_align_left"/>
|
||||
<Action name="format_align_center"/>
|
||||
<Action name="format_align_right"/>
|
||||
<Action name="format_align_justify"/>
|
||||
</Menu>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_list_style"/>
|
||||
<Action name="format_list_indent_more"/>
|
||||
<Action name="format_list_indent_less"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="insert_horizontal_rule"/>
|
||||
<Action name="manage_link"/>
|
||||
<Action name="format_painter"/>
|
||||
</Menu>
|
||||
</MenuBar>
|
||||
|
||||
<ToolBar name="textToolBar" iconText="icononly"><text>Text Toolbar</text>
|
||||
<Action name="format_text_bold"/>
|
||||
<Action name="format_text_italic"/>
|
||||
<Action name="format_text_underline"/>
|
||||
<Action name="format_text_strikeout"/>
|
||||
<Action name="format_text_foreground_color"/>
|
||||
<Action name="format_text_background_color"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_font_family"/>
|
||||
<Action name="format_font_size"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_text_superscript"/>
|
||||
<Action name="format_text_subscript"/>
|
||||
</ToolBar>
|
||||
<ToolBar name="formatToolBar" iconText="icononly"><text>Format Toolbar</text>
|
||||
<Action name="format_heading_level"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_align_left"/>
|
||||
<Action name="format_align_center"/>
|
||||
<Action name="format_align_right"/>
|
||||
<Action name="format_align_justify"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_list_style"/>
|
||||
<Action name="format_list_indent_more"/>
|
||||
<Action name="format_list_indent_less"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="insert_horizontal_rule"/>
|
||||
<Action name="manage_link"/>
|
||||
<Action name="format_painter"/>
|
||||
<Action name="action_to_plain_text"/>
|
||||
</ToolBar>
|
||||
|
||||
</gui>
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
KDE Rich Text Editor
|
||||
SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#include "krichtexteditor.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("krichtexteditor"));
|
||||
QApplication app(argc, argv);
|
||||
KRichTextEditor *mw = new KRichTextEditor();
|
||||
mw->show();
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
#include "krulertest.h"
|
||||
|
||||
#include <KRuler>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QButtonGroup>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QGroupBox>
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QSpinBox>
|
||||
|
||||
/*
|
||||
void
|
||||
MyCheckBox::mouseReleaseEvent(QMouseEvent *e )
|
||||
{
|
||||
QButton::mouseReleaseEvent(e);
|
||||
if ();
|
||||
}
|
||||
*/
|
||||
|
||||
MouseWidget::MouseWidget(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MouseWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
mouseButtonDown = true;
|
||||
Q_EMIT newXPos(qRound(e->position().x()));
|
||||
Q_EMIT newYPos(qRound(e->position().y()));
|
||||
}
|
||||
|
||||
void MouseWidget::mouseReleaseEvent(QMouseEvent *)
|
||||
{
|
||||
mouseButtonDown = false;
|
||||
}
|
||||
|
||||
void MouseWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (mouseButtonDown) {
|
||||
Q_EMIT newXPos(qRound(e->position().x()));
|
||||
Q_EMIT newYPos(qRound(e->position().y()));
|
||||
}
|
||||
}
|
||||
|
||||
void MouseWidget::resizeEvent(QResizeEvent *r)
|
||||
{
|
||||
Q_EMIT newWidth(r->size().width());
|
||||
Q_EMIT newHeight(r->size().height());
|
||||
}
|
||||
|
||||
KRulerTest::KRulerTest()
|
||||
: QWidget(nullptr)
|
||||
{
|
||||
QVBoxLayout *topLayout = new QVBoxLayout(this);
|
||||
mainframe = new QFrame(this);
|
||||
topLayout->addWidget(mainframe);
|
||||
|
||||
layout = new QGridLayout(mainframe);
|
||||
|
||||
miniwidget = new QFrame(mainframe);
|
||||
miniwidget->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
|
||||
bigwidget = new MouseWidget(mainframe);
|
||||
bigwidget->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
|
||||
|
||||
// QRect bwrect = bigwidget->frameRect();
|
||||
// qDebug("big rect: top%i left%i bottom%i right%i",
|
||||
// bwrect.top(), bwrect.left(), bwrect.bottom(), bwrect.right());
|
||||
hruler = new KRuler(Qt::Horizontal, mainframe);
|
||||
// hruler->setRange( bwrect.left(), bwrect.right() );
|
||||
hruler->setRange(0, 1000);
|
||||
// hruler->setOffset( bwrect.left() - bigwidget->frameRect().left() );
|
||||
hruler->setOffset(0);
|
||||
|
||||
vruler = new KRuler(Qt::Vertical, mainframe);
|
||||
vruler->setOffset(0);
|
||||
vruler->setRange(0, 1000);
|
||||
|
||||
connect(bigwidget, &MouseWidget::newXPos, hruler, &KRuler::slotNewValue);
|
||||
connect(bigwidget, &MouseWidget::newYPos, vruler, &KRuler::slotNewValue);
|
||||
connect(bigwidget, &MouseWidget::newWidth, this, &KRulerTest::slotNewWidth);
|
||||
connect(bigwidget, &MouseWidget::newHeight, this, &KRulerTest::slotNewHeight);
|
||||
|
||||
layout->addWidget(miniwidget, 0, 0);
|
||||
layout->addWidget(hruler, 0, 1);
|
||||
layout->addWidget(vruler, 1, 0);
|
||||
layout->addWidget(bigwidget, 1, 1);
|
||||
|
||||
mouse_message = new QLabel(QStringLiteral("Press and hold mouse button\nfor pointer movement"), bigwidget);
|
||||
mouse_message->adjustSize();
|
||||
mouse_message->move(4, 4);
|
||||
|
||||
showMarks = new QGroupBox(QStringLiteral("Show which marks ?"), bigwidget);
|
||||
showMarks->setFixedSize(140, 160);
|
||||
showMarks->move(330, 4);
|
||||
showTM = new QCheckBox(QStringLiteral("show tiny marks"), showMarks);
|
||||
showTM->adjustSize();
|
||||
showTM->move(5, 15);
|
||||
showTM->setChecked(true);
|
||||
connect(showTM, &QCheckBox::toggled, this, &KRulerTest::slotSetTinyMarks);
|
||||
showLM = new QCheckBox(QStringLiteral("show little marks"), showMarks);
|
||||
showLM->adjustSize();
|
||||
showLM->move(5, 35);
|
||||
showLM->setChecked(true);
|
||||
connect(showLM, &QCheckBox::toggled, this, &KRulerTest::slotSetLittleMarks);
|
||||
showMM = new QCheckBox(QStringLiteral("show medium marks"), showMarks);
|
||||
showMM->adjustSize();
|
||||
showMM->move(5, 55);
|
||||
showMM->setChecked(true);
|
||||
connect(showMM, &QCheckBox::toggled, this, &KRulerTest::slotSetMediumMarks);
|
||||
showBM = new QCheckBox(QStringLiteral("show big marks"), showMarks);
|
||||
showBM->adjustSize();
|
||||
showBM->move(5, 75);
|
||||
showBM->setChecked(true);
|
||||
connect(showBM, &QCheckBox::toggled, this, &KRulerTest::slotSetBigMarks);
|
||||
showEM = new QCheckBox(QStringLiteral("show end marks"), showMarks);
|
||||
showEM->adjustSize();
|
||||
showEM->move(5, 95);
|
||||
showEM->setChecked(true);
|
||||
connect(showEM, &QCheckBox::toggled, this, &KRulerTest::slotSetEndMarks);
|
||||
showPT = new QCheckBox(QStringLiteral("show ruler pointer"), showMarks);
|
||||
showPT->adjustSize();
|
||||
showPT->move(5, 115);
|
||||
showPT->setChecked(true);
|
||||
connect(showPT, &QCheckBox::toggled, this, &KRulerTest::slotSetRulerPointer);
|
||||
fixLen = new QCheckBox(QStringLiteral("fix ruler length"), showMarks);
|
||||
fixLen->adjustSize();
|
||||
fixLen->move(5, 135);
|
||||
fixLen->setChecked(true);
|
||||
connect(fixLen, &QCheckBox::toggled, this, &KRulerTest::slotFixRulerLength);
|
||||
connect(fixLen, &QCheckBox::toggled, this, &KRulerTest::slotCheckLength);
|
||||
|
||||
lineEdit = new QGroupBox(QStringLiteral("Value of begin/end"), bigwidget);
|
||||
lineEdit->setFixedSize(140, 80);
|
||||
lineEdit->move(330, 4 + 160);
|
||||
beginMark = new QSpinBox(lineEdit);
|
||||
beginMark->setValue(0);
|
||||
beginMark->setRange(-1000, 1000);
|
||||
beginMark->move(5, 15);
|
||||
beginMark->setFixedSize(beginMark->sizeHint());
|
||||
connect(beginMark, qOverload<int>(&QSpinBox::valueChanged), hruler, &KRuler::slotNewOffset);
|
||||
connect(beginMark, qOverload<int>(&QSpinBox::valueChanged), vruler, &KRuler::slotNewOffset);
|
||||
endMark = new QSpinBox(lineEdit);
|
||||
endMark->setValue(0);
|
||||
endMark->setRange(-1000, 1000);
|
||||
endMark->move(5, 35);
|
||||
endMark->setFixedSize(endMark->sizeHint());
|
||||
connect(endMark, qOverload<int>(&QSpinBox::valueChanged), hruler, &KRuler::slotEndOffset);
|
||||
connect(endMark, qOverload<int>(&QSpinBox::valueChanged), vruler, &KRuler::slotEndOffset);
|
||||
lengthInput = new QSpinBox(lineEdit);
|
||||
lengthInput->setValue(0);
|
||||
lengthInput->setRange(-1000, 1000);
|
||||
lengthInput->move(5, 55);
|
||||
lengthInput->setFixedSize(lengthInput->sizeHint());
|
||||
connect(lengthInput, qOverload<int>(&QSpinBox::valueChanged), hruler, &KRuler::slotEndOffset);
|
||||
connect(lengthInput, qOverload<int>(&QSpinBox::valueChanged), vruler, &KRuler::slotEndOffset);
|
||||
|
||||
vertrot = new QGroupBox(QStringLiteral("Value of rotate translate for Vert."), bigwidget);
|
||||
vertrot->setFixedSize(140, 80);
|
||||
vertrot->move(330, 4 + 160 + 80 + 4);
|
||||
transX = new QDoubleSpinBox(vertrot);
|
||||
transX->setValue(0.0);
|
||||
transX->setRange(-1000, 1000);
|
||||
transX->setSingleStep(1);
|
||||
transX->move(5, 15);
|
||||
transX->setFixedSize(transX->sizeHint());
|
||||
// transX->setLabel("transx", AlignLeft);
|
||||
connect(transX, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &KRulerTest::slotSetXTrans);
|
||||
transY = new QDoubleSpinBox(vertrot);
|
||||
transY->setValue(-12.0);
|
||||
transY->setRange(-1000, 1000);
|
||||
transY->setSingleStep(1);
|
||||
transY->move(5, 35);
|
||||
transY->setFixedSize(transY->sizeHint());
|
||||
// transY->setLabel("transy", AlignLeft);
|
||||
connect(transY, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &KRulerTest::slotSetYTrans);
|
||||
rotV = new QDoubleSpinBox(vertrot);
|
||||
rotV->setValue(90.0);
|
||||
rotV->setRange(-1000, 1000);
|
||||
rotV->setSingleStep(1);
|
||||
rotV->move(5, 55);
|
||||
rotV->setFixedSize(rotV->sizeHint());
|
||||
// rotV->setLabel("rot", AlignLeft);
|
||||
connect(rotV, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &KRulerTest::slotSetRotate);
|
||||
|
||||
metricstyle = new QGroupBox(QStringLiteral("metric styles"), bigwidget);
|
||||
|
||||
QButtonGroup *metricstyleButtons = new QButtonGroup(bigwidget);
|
||||
|
||||
metricstyle->setFixedSize(100, 120);
|
||||
metricstyle->move(330 - 110, 4);
|
||||
pixelmetric = new QRadioButton(QStringLiteral("pixel"), metricstyle);
|
||||
pixelmetric->adjustSize();
|
||||
pixelmetric->move(5, 15);
|
||||
metricstyleButtons->addButton(pixelmetric, (int)KRuler::Pixel);
|
||||
inchmetric = new QRadioButton(QStringLiteral("inch"), metricstyle);
|
||||
inchmetric->adjustSize();
|
||||
inchmetric->move(5, 35);
|
||||
metricstyleButtons->addButton(inchmetric, (int)KRuler::Inch);
|
||||
mmmetric = new QRadioButton(QStringLiteral("millimeter"), metricstyle);
|
||||
mmmetric->adjustSize();
|
||||
mmmetric->move(5, 55);
|
||||
metricstyleButtons->addButton(mmmetric, (int)KRuler::Millimetres);
|
||||
cmmetric = new QRadioButton(QStringLiteral("centimeter"), metricstyle);
|
||||
cmmetric->adjustSize();
|
||||
cmmetric->move(5, 75);
|
||||
metricstyleButtons->addButton(cmmetric, (int)KRuler::Centimetres);
|
||||
mmetric = new QRadioButton(QStringLiteral("meter"), metricstyle);
|
||||
mmetric->adjustSize();
|
||||
mmetric->move(5, 95);
|
||||
metricstyleButtons->addButton(mmetric, (int)KRuler::Metres);
|
||||
connect(metricstyleButtons, &QButtonGroup::buttonClicked, this, [this, metricstyleButtons](QAbstractButton *button) {
|
||||
slotSetMStyle(metricstyleButtons->id(button));
|
||||
});
|
||||
|
||||
slotUpdateShowMarks();
|
||||
}
|
||||
|
||||
KRulerTest::~KRulerTest()
|
||||
{
|
||||
delete layout;
|
||||
delete hruler;
|
||||
delete vruler;
|
||||
delete miniwidget;
|
||||
delete bigwidget;
|
||||
delete mainframe;
|
||||
}
|
||||
|
||||
void KRulerTest::slotNewWidth(int width)
|
||||
{
|
||||
hruler->setMaximum(width);
|
||||
}
|
||||
|
||||
void KRulerTest::slotNewHeight(int height)
|
||||
{
|
||||
vruler->setMaximum(height);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetTinyMarks(bool set)
|
||||
{
|
||||
hruler->setShowTinyMarks(set);
|
||||
vruler->setShowTinyMarks(set);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetLittleMarks(bool set)
|
||||
{
|
||||
hruler->setShowLittleMarks(set);
|
||||
vruler->setShowLittleMarks(set);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetMediumMarks(bool set)
|
||||
{
|
||||
hruler->setShowMediumMarks(set);
|
||||
vruler->setShowMediumMarks(set);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetBigMarks(bool set)
|
||||
{
|
||||
hruler->setShowBigMarks(set);
|
||||
vruler->setShowBigMarks(set);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetEndMarks(bool set)
|
||||
{
|
||||
hruler->setShowEndMarks(set);
|
||||
vruler->setShowEndMarks(set);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetRulerPointer(bool set)
|
||||
{
|
||||
hruler->setShowPointer(set);
|
||||
vruler->setShowPointer(set);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetRulerLength(int len)
|
||||
{
|
||||
hruler->setLength(len);
|
||||
vruler->setLength(len);
|
||||
}
|
||||
|
||||
void KRulerTest::slotFixRulerLength(bool fix)
|
||||
{
|
||||
hruler->setLengthFixed(fix);
|
||||
vruler->setLengthFixed(fix);
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetMStyle(int style)
|
||||
{
|
||||
hruler->setRulerMetricStyle((KRuler::MetricStyle)style);
|
||||
vruler->setRulerMetricStyle((KRuler::MetricStyle)style);
|
||||
slotUpdateShowMarks();
|
||||
}
|
||||
|
||||
void KRulerTest::slotUpdateShowMarks()
|
||||
{
|
||||
showTM->setChecked(hruler->showTinyMarks());
|
||||
showLM->setChecked(hruler->showLittleMarks());
|
||||
showMM->setChecked(hruler->showMediumMarks());
|
||||
showBM->setChecked(hruler->showBigMarks());
|
||||
showEM->setChecked(hruler->showEndMarks());
|
||||
}
|
||||
|
||||
void KRulerTest::slotCheckLength(bool fixlen)
|
||||
{
|
||||
Q_UNUSED(fixlen);
|
||||
beginMark->setValue(hruler->offset());
|
||||
endMark->setValue(hruler->endOffset());
|
||||
lengthInput->setValue(hruler->length());
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetRotate(double d)
|
||||
{
|
||||
Q_UNUSED(d);
|
||||
#ifdef KRULER_ROTATE_TEST
|
||||
vruler->rotate = d;
|
||||
vruler->update();
|
||||
// debug("rotate %.1f", d);
|
||||
#endif
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetXTrans(double d)
|
||||
{
|
||||
Q_UNUSED(d);
|
||||
#ifdef KRULER_ROTATE_TEST
|
||||
vruler->xtrans = d;
|
||||
vruler->update();
|
||||
// debug("trans x %.1f", d);
|
||||
#endif
|
||||
}
|
||||
|
||||
void KRulerTest::slotSetYTrans(double d)
|
||||
{
|
||||
Q_UNUSED(d);
|
||||
#ifdef KRULER_ROTATE_TEST
|
||||
vruler->ytrans = d;
|
||||
vruler->update();
|
||||
// debug("trans y %.1f", d);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --- MAIN -----------------------*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("test"));
|
||||
QApplication *testapp;
|
||||
KRulerTest *window;
|
||||
|
||||
testapp = new QApplication(argc, argv);
|
||||
testapp->setFont(QFont(QStringLiteral("Helvetica"), 12));
|
||||
|
||||
window = new KRulerTest();
|
||||
window->setWindowTitle(QStringLiteral("KRulerTest"));
|
||||
window->resize(800, 600);
|
||||
window->show();
|
||||
return testapp->exec();
|
||||
}
|
||||
|
||||
#include "moc_krulertest.cpp"
|
||||
@@ -0,0 +1,83 @@
|
||||
/* -*- c++ -*- */
|
||||
|
||||
#ifndef krulertest_h
|
||||
#define krulertest_h
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QFrame>
|
||||
#include <QRadioButton>
|
||||
|
||||
class KRuler;
|
||||
class QWidget;
|
||||
class QGridLayout;
|
||||
class QGroupBox;
|
||||
class QLabel;
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
|
||||
class MouseWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MouseWidget(QWidget *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void newXPos(int);
|
||||
void newYPos(int);
|
||||
void newWidth(int);
|
||||
void newHeight(int);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *) override;
|
||||
void mouseReleaseEvent(QMouseEvent *) override;
|
||||
void mouseMoveEvent(QMouseEvent *) override;
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
|
||||
private:
|
||||
bool mouseButtonDown;
|
||||
};
|
||||
|
||||
class KRulerTest : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KRulerTest();
|
||||
~KRulerTest() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotNewWidth(int);
|
||||
void slotNewHeight(int);
|
||||
|
||||
void slotSetTinyMarks(bool);
|
||||
void slotSetLittleMarks(bool);
|
||||
void slotSetMediumMarks(bool);
|
||||
void slotSetBigMarks(bool);
|
||||
void slotSetEndMarks(bool);
|
||||
void slotSetRulerPointer(bool);
|
||||
|
||||
void slotSetRulerLength(int);
|
||||
void slotFixRulerLength(bool);
|
||||
void slotSetMStyle(int);
|
||||
void slotUpdateShowMarks();
|
||||
void slotCheckLength(bool);
|
||||
|
||||
void slotSetRotate(double);
|
||||
void slotSetXTrans(double);
|
||||
void slotSetYTrans(double);
|
||||
|
||||
private:
|
||||
KRuler *hruler, *vruler;
|
||||
QGridLayout *layout;
|
||||
QFrame *mainframe = nullptr;
|
||||
MouseWidget *bigwidget = nullptr;
|
||||
QFrame *miniwidget = nullptr;
|
||||
|
||||
QLabel *mouse_message;
|
||||
QGroupBox *showMarks, *lineEdit, *vertrot;
|
||||
QCheckBox *showTM, *showLM, *showMM, *showBM, *showEM, *showPT, *fixLen;
|
||||
QSpinBox *beginMark, *endMark, *lengthInput;
|
||||
QDoubleSpinBox *transX, *transY, *rotV;
|
||||
QGroupBox *metricstyle;
|
||||
QRadioButton *pixelmetric, *inchmetric, *mmmetric, *cmmetric, *mmetric;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <ktoolbar.h>
|
||||
|
||||
// This is a test for "Automatically hide extra toolbar separators"
|
||||
// If several separators are next to each other, only one should show up.
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("kactiontest"));
|
||||
QApplication app(argc, argv);
|
||||
|
||||
KActionCollection coll(static_cast<QObject *>(nullptr));
|
||||
|
||||
QAction *action1 = coll.addAction(QStringLiteral("test1"));
|
||||
action1->setText(QStringLiteral("test1"));
|
||||
QAction *action2 = coll.addAction(QStringLiteral("test2"));
|
||||
action2->setText(QStringLiteral("test2"));
|
||||
QAction *action3 = coll.addAction(QStringLiteral("test3"));
|
||||
action3->setText(QStringLiteral("test3"));
|
||||
QAction *action4 = coll.addAction(QStringLiteral("test4"));
|
||||
action4->setText(QStringLiteral("test4"));
|
||||
QAction *action5 = coll.addAction(QStringLiteral("test5"));
|
||||
action5->setText(QStringLiteral("test5"));
|
||||
QAction *action6 = coll.addAction(QStringLiteral("test6"));
|
||||
action6->setText(QStringLiteral("test6"));
|
||||
QAction *action7 = coll.addAction(QStringLiteral("test7"));
|
||||
action7->setText(QStringLiteral("test7"));
|
||||
|
||||
QMainWindow *mw = new QMainWindow();
|
||||
KToolBar *tb = new KToolBar(mw);
|
||||
mw->addToolBar(tb);
|
||||
|
||||
action2->setSeparator(true);
|
||||
action3->setSeparator(true);
|
||||
action7->setSeparator(true);
|
||||
|
||||
coll.addAssociatedWidget(tb);
|
||||
|
||||
mw->show();
|
||||
|
||||
app.exec();
|
||||
|
||||
mw->show();
|
||||
|
||||
action2->setVisible(false);
|
||||
|
||||
app.exec();
|
||||
|
||||
mw->show();
|
||||
|
||||
action1->setVisible(false);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
#include "kwindowtest.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QTest>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <KActionMenu>
|
||||
#include <KToggleAction>
|
||||
#include <QAction>
|
||||
#include <QActionGroup>
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include <kactioncollection.h>
|
||||
#include <khelpmenu.h>
|
||||
#include <kxmlguifactory.h>
|
||||
|
||||
TestWindow::TestWindow(QWidget *parent)
|
||||
: KXmlGuiWindow(parent)
|
||||
{
|
||||
ena = false;
|
||||
exitB = true; // exit button is shown
|
||||
lineL = true; // LineEdit is enabled
|
||||
greenF = false; // Frame not inserted
|
||||
timer = nullptr;
|
||||
|
||||
setCaption(QStringLiteral("test window"));
|
||||
|
||||
// The xmlgui file defines the layout of the menus and toolbars.
|
||||
// We only need to create actions with the right name here.
|
||||
|
||||
// First four buttons
|
||||
fileNewAction = new QAction(QIcon::fromTheme(QStringLiteral("document-new")), QStringLiteral("Create.. (toggles upper button)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("filenew"), fileNewAction);
|
||||
fileNewAction->setCheckable(true);
|
||||
connect(fileNewAction, &QAction::triggered, this, &TestWindow::slotNew);
|
||||
|
||||
QAction *fileOpenAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open")), QStringLiteral("Open"), this);
|
||||
actionCollection()->addAction(QStringLiteral("fileopen"), fileOpenAction);
|
||||
connect(fileOpenAction, &QAction::triggered, this, &TestWindow::slotOpen);
|
||||
|
||||
KActionMenu *fileFloppyAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("filefloppy")), QStringLiteral("Save (beep or delayed popup)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("filefloppy"), fileFloppyAction);
|
||||
connect(fileFloppyAction, &QAction::triggered, this, &TestWindow::slotSave);
|
||||
|
||||
QAction *filePrintAction = new QAction(QIcon::fromTheme(QStringLiteral("document-print")), QStringLiteral("Print (enables/disables open)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("fileprint"), filePrintAction);
|
||||
filePrintAction->setToolTip(QStringLiteral("This tooltip does not work for menu items"));
|
||||
filePrintAction->setWhatsThis(QStringLiteral("This is the longer explanation of the action"));
|
||||
filePrintAction->setStatusTip(QStringLiteral("This action is supposed to print, but in fact enables/disables open"));
|
||||
connect(filePrintAction, &QAction::triggered, this, &TestWindow::slotPrint);
|
||||
|
||||
// And a combobox
|
||||
// arguments: text (or strList), ID, writable, signal, object, slot, enabled,
|
||||
// tooltiptext, size
|
||||
testComboBox = new QComboBox(toolBar());
|
||||
// K3WidgetAction* comboAction = new K3WidgetAction(testComboBox, QString(), 0, 0, 0, actionCollection(), "combobox");
|
||||
// connect(testComboBox, SIGNAL(activated(QString)), this, SLOT(slotList(QString)));
|
||||
|
||||
// Then one line editor
|
||||
// arguments: text, id, signal, object (this), slot, enabled, tooltiptext, size
|
||||
testLineEdit = new QLineEdit(toolBar());
|
||||
testLineEdit->setText(QStringLiteral("ftp://ftp.kde.org/pub/kde"));
|
||||
// K3WidgetAction* lineEditAction = new K3WidgetAction(testLineEdit, QString(), 0, 0, 0, actionCollection(), "location");
|
||||
// connect(testLineEdit, SIGNAL(returnPressed()), this, SLOT(slotReturn()));
|
||||
|
||||
// Now add another button and align it right
|
||||
exitAction = new QAction(QIcon::fromTheme(QStringLiteral("application-exit")), QStringLiteral("Exit"), this);
|
||||
actionCollection()->addAction(QStringLiteral("exit"), exitAction);
|
||||
connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||
|
||||
// Another toolbar
|
||||
|
||||
QAction *fileNewAction2 = new QAction(QIcon::fromTheme(QStringLiteral("document-new")), QStringLiteral("Create new file2 (Toggle)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("filenew2"), fileNewAction2);
|
||||
connect(fileNewAction2, &QAction::toggled, this, &TestWindow::slotToggle);
|
||||
fileNewAction2->setToolTip(QStringLiteral("Tooltip"));
|
||||
fileNewAction2->setStatusTip(QStringLiteral("Statustip"));
|
||||
fileNewAction2->setWhatsThis(QStringLiteral("WhatsThis"));
|
||||
|
||||
QAction *fileOpenAction2 = new QAction(QIcon::fromTheme(QStringLiteral("document-open")), QStringLiteral("Open (starts progress in sb)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("fileopen2"), fileOpenAction2);
|
||||
connect(fileOpenAction2, &QAction::triggered, this, &TestWindow::slotOpen);
|
||||
fileOpenAction2->setToolTip(QStringLiteral("This action starts a progressbar inside the statusbar"));
|
||||
|
||||
QAction *fileFloppyAction2 = new QAction(QIcon::fromTheme(QStringLiteral("filefloppy")), QStringLiteral("Save file2 (autorepeat)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("filefloppy2"), fileFloppyAction2);
|
||||
connect(fileFloppyAction2, &QAction::triggered, this, &TestWindow::slotSave);
|
||||
|
||||
itemsMenu = new QMenu;
|
||||
itemsMenu->addAction(QStringLiteral("delete/insert exit button"), this, &TestWindow::slotExit);
|
||||
itemsMenu->addAction(QStringLiteral("enable/disable lineedit"), this, &TestWindow::slotLined);
|
||||
itemsMenu->addAction(QStringLiteral("Toggle fileNew"), this, &TestWindow::slotNew);
|
||||
itemsMenu->addAction(QStringLiteral("Combo: clear"), this, &TestWindow::slotClearCombo);
|
||||
itemsMenu->addAction(QStringLiteral("Combo: insert list"), this, &TestWindow::slotInsertListInCombo);
|
||||
itemsMenu->addAction(QStringLiteral("Combo: make item 3 current"), this, &TestWindow::slotMakeItem3Current);
|
||||
itemsMenu->addAction(QStringLiteral("Important msg in statusbar"), this, &TestWindow::slotImportant);
|
||||
|
||||
QAction *filePrintAction2 = new QAction(QIcon::fromTheme(QStringLiteral("document-print")), QStringLiteral("Print (pops menu)"), this);
|
||||
actionCollection()->addAction(QStringLiteral("fileprint2"), filePrintAction2);
|
||||
filePrintAction2->setMenu(itemsMenu);
|
||||
|
||||
// *** RADIO BUTTONS
|
||||
QActionGroup *radioGroup = new QActionGroup(this);
|
||||
radioGroup->setExclusive(true);
|
||||
|
||||
KToggleAction *radioButton1 = new KToggleAction(QIcon::fromTheme(QStringLiteral("document-new")), QStringLiteral("Radiobutton1"), this);
|
||||
actionCollection()->addAction(QStringLiteral("radioButton1"), radioButton1);
|
||||
radioButton1->setActionGroup(radioGroup);
|
||||
|
||||
KToggleAction *radioButton2 = new KToggleAction(QIcon::fromTheme(QStringLiteral("document-open")), QStringLiteral("Radiobutton2"), this);
|
||||
actionCollection()->addAction(QStringLiteral("radioButton2"), radioButton2);
|
||||
radioButton2->setActionGroup(radioGroup);
|
||||
|
||||
KToggleAction *radioButton3 = new KToggleAction(QIcon::fromTheme(QStringLiteral("filefloppy")), QStringLiteral("Radiobutton3"), this);
|
||||
actionCollection()->addAction(QStringLiteral("radioButton3"), radioButton3);
|
||||
radioButton3->setActionGroup(radioGroup);
|
||||
|
||||
KToggleAction *radioButton4 = new KToggleAction(QIcon::fromTheme(QStringLiteral("document-print")), QStringLiteral("Radiobutton4"), this);
|
||||
actionCollection()->addAction(QStringLiteral("radioButton4"), radioButton4);
|
||||
radioButton4->setActionGroup(radioGroup);
|
||||
|
||||
connect(radioGroup, &QActionGroup::triggered, this, &TestWindow::slotToggled);
|
||||
|
||||
/**************************************************/
|
||||
/*Now, we setup statusbar; order is not important. */
|
||||
/**************************************************/
|
||||
statusBar = new QStatusBar(this);
|
||||
// statusBar->insertItem("Hi there! ", 0);
|
||||
// statusBar->insertItem("Look for tooltips to see functions", 1);
|
||||
setStatusBar(statusBar);
|
||||
|
||||
// DigitalClock *clk = new DigitalClock (statusBar);
|
||||
// clk->setFrameStyle(QFrame::NoFrame);
|
||||
// statusBar->insertWidget(clk, 70, 2);
|
||||
|
||||
// Set main widget. In this example it is Qt's multiline text editor.
|
||||
widget = new QTextEdit(this);
|
||||
setCentralWidget(widget);
|
||||
|
||||
// Setup is now complete
|
||||
|
||||
setAutoSaveSettings();
|
||||
|
||||
// This is not strictly related to toolbars, menubars or KMainWindow.
|
||||
// Setup popup for completions
|
||||
completions = new QMenu;
|
||||
|
||||
completions->addAction(QStringLiteral("/"));
|
||||
completions->addAction(QStringLiteral("/usr/"));
|
||||
completions->addAction(QStringLiteral("/lib/"));
|
||||
completions->addAction(QStringLiteral("/var/"));
|
||||
completions->addAction(QStringLiteral("/bin/"));
|
||||
completions->addAction(QStringLiteral("/kde/"));
|
||||
completions->addAction(QStringLiteral("/home/"));
|
||||
completions->addAction(QStringLiteral("/vmlinuz :-)"));
|
||||
|
||||
connect(completions, &QMenu::triggered, this, &TestWindow::slotCompletionsMenu);
|
||||
pr = nullptr;
|
||||
|
||||
// KXMLGUIClient looks in the "data" resource for the .rc files
|
||||
// This line is for test programs only!
|
||||
qputenv("XDG_DATA_HOME", QFile::encodeName(QFileInfo(QFINDTESTDATA("kwindowtest.rc")).absolutePath()));
|
||||
setupGUI(QSize(400, 500), Default, QStringLiteral("kwindowtest.rc"));
|
||||
|
||||
tb = toolBar();
|
||||
tb1 = toolBar(QStringLiteral("AnotherToolBar"));
|
||||
}
|
||||
/***********************************/
|
||||
/* Now slots for toolbar actions */
|
||||
/***********************************/
|
||||
void TestWindow::slotToggled(QAction *)
|
||||
{
|
||||
statusBar->showMessage(QStringLiteral("Button toggled"), 1500);
|
||||
}
|
||||
|
||||
void TestWindow::slotInsertClock()
|
||||
{
|
||||
// DigitalClock *clock = new DigitalClock(tb1);
|
||||
// clock->setFrameStyle(QFrame::NoFrame);
|
||||
// tb1->insertWidget(8, 70, clock);
|
||||
}
|
||||
|
||||
void TestWindow::slotNew()
|
||||
{
|
||||
// tb1->actions()[0]->toggle();
|
||||
// toolBar()->removeAction( fileNewAction );
|
||||
}
|
||||
void TestWindow::slotOpen()
|
||||
{
|
||||
if (pr == nullptr) {
|
||||
pr = new QProgressBar(statusBar);
|
||||
pr->show();
|
||||
}
|
||||
// statusBar->message(pr);
|
||||
if (!timer) {
|
||||
timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, &TestWindow::slotGoGoGoo);
|
||||
}
|
||||
timer->start(100);
|
||||
}
|
||||
|
||||
void TestWindow::slotGoGoGoo()
|
||||
{
|
||||
pr->setValue(pr->value() + 1);
|
||||
if (pr->value() == 100) {
|
||||
timer->stop();
|
||||
statusBar->clearMessage();
|
||||
delete pr;
|
||||
pr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TestWindow::slotSave()
|
||||
{
|
||||
qApp->beep();
|
||||
statusBar->showMessage(QStringLiteral("Saving properties…"));
|
||||
}
|
||||
|
||||
void TestWindow::slotPrint()
|
||||
{
|
||||
statusBar->showMessage(QStringLiteral("Print file pressed"));
|
||||
ena = !ena;
|
||||
qobject_cast<QAction *>(sender())->setEnabled(ena);
|
||||
}
|
||||
void TestWindow::slotReturn()
|
||||
{
|
||||
QString s = QStringLiteral("You entered ");
|
||||
s = s + testLineEdit->text();
|
||||
statusBar->showMessage(s);
|
||||
}
|
||||
void TestWindow::slotList(const QString &str)
|
||||
{
|
||||
QString s = QStringLiteral("You chose ");
|
||||
s = s + str;
|
||||
statusBar->showMessage(s);
|
||||
}
|
||||
|
||||
void TestWindow::slotCompletion()
|
||||
{
|
||||
// Now do a completion
|
||||
// Call your completing function and set that text in lineedit
|
||||
// QString s = tb->getLinedText(/* ID */ 4)
|
||||
// QString completed = complete (s);
|
||||
// tb->setLinedText(/* ID */ 4, completed.data())
|
||||
|
||||
// for now this:
|
||||
|
||||
completions->popup(QCursor::pos()); // This popup should understunf keys up and down
|
||||
|
||||
/* This is just an example. QLineEdit automatically sets cursor at end of string
|
||||
when ctrl-d or ctrl-s is pressed. KToolBar will also put cursor at end of text in LineEdit
|
||||
after inserting text with setLinedText (...).
|
||||
*/
|
||||
}
|
||||
|
||||
void TestWindow::slotListCompletion()
|
||||
{
|
||||
/*
|
||||
Combo is not behaving good and it is ugly. I will see how it behaves in Qt-1.3,
|
||||
and then decide should I make a new combobox.
|
||||
*/
|
||||
QString s(testComboBox->currentText()); // get text in combo
|
||||
s += QStringLiteral("(completing)");
|
||||
// tb->getCombo(4)->changeItem(s.data()); // setTextIncombo
|
||||
}
|
||||
|
||||
void TestWindow::slotCompletionsMenu(QAction *action)
|
||||
{
|
||||
// Now set text in lined
|
||||
QString s = action->text();
|
||||
testLineEdit->setText(s); // Cursor is automatically at the end of string after this
|
||||
}
|
||||
|
||||
TestWindow::~TestWindow()
|
||||
{
|
||||
qDebug() << "kwindowtest finished";
|
||||
}
|
||||
|
||||
void TestWindow::beFixed()
|
||||
{
|
||||
widget->setFixedSize(400, 200);
|
||||
}
|
||||
|
||||
void TestWindow::beYFixed()
|
||||
{
|
||||
widget->setMinimumSize(400, 200);
|
||||
widget->setMaximumSize(9999, 200);
|
||||
}
|
||||
|
||||
void TestWindow::slotImportant()
|
||||
{
|
||||
statusBar->showMessage(QStringLiteral("This important message will go away in 15 seconds"), 15000);
|
||||
}
|
||||
|
||||
void TestWindow::slotExit()
|
||||
{
|
||||
if (exitB == true) {
|
||||
tb->removeAction(exitAction);
|
||||
exitB = false;
|
||||
} else {
|
||||
if (tb->actions().count() >= 7) {
|
||||
tb->insertAction(tb->actions().at(6), exitAction);
|
||||
} else {
|
||||
tb->addAction(exitAction);
|
||||
}
|
||||
exitB = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TestWindow::slotLined()
|
||||
{
|
||||
lineL = !lineL;
|
||||
testLineEdit->setEnabled(lineL); // enable/disable lined
|
||||
}
|
||||
|
||||
void TestWindow::slotToggle(bool on)
|
||||
{
|
||||
if (on == true) {
|
||||
statusBar->showMessage(QStringLiteral("Toggle is on"));
|
||||
} else {
|
||||
statusBar->showMessage(QStringLiteral("Toggle is off"));
|
||||
}
|
||||
}
|
||||
|
||||
void TestWindow::slotFrame()
|
||||
{
|
||||
#if 0
|
||||
if (greenF == false) {
|
||||
tb1->insertFrame(10, 100);
|
||||
tb1->alignItemRight(10); // this is pointless 'cause tb1 is not fullwidth
|
||||
|
||||
QFrame *myFrame = tb1->getFrame(10); // get frame pointer
|
||||
|
||||
if (myFrame == 0) {
|
||||
warning("bad frame ID");
|
||||
return;
|
||||
}
|
||||
|
||||
//paint it green
|
||||
// Or do whatever you want with it, just don't change its height (height = hardcoded = 24)
|
||||
// And don't move it
|
||||
// If you want to have something right from your toolbar you can reduce its
|
||||
// max_width with setMaxWidth()
|
||||
myFrame->setBackgroundColor(QColor("green"));
|
||||
|
||||
greenF = true;
|
||||
} else {
|
||||
tb1->removeItem(10);
|
||||
greenF = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TestWindow::slotMessage(int, bool boo)
|
||||
{
|
||||
if (boo) {
|
||||
statusBar->showMessage(QStringLiteral("This button does this and that"), 1500);
|
||||
} else {
|
||||
statusBar->clearMessage();
|
||||
}
|
||||
}
|
||||
// Now few Combo slots, for Torben
|
||||
|
||||
void TestWindow::slotClearCombo()
|
||||
{
|
||||
testComboBox->clear();
|
||||
}
|
||||
|
||||
void TestWindow::slotInsertListInCombo()
|
||||
{
|
||||
QStringList list;
|
||||
list.append(QStringLiteral("ListOne"));
|
||||
list.append(QStringLiteral("ListTwo"));
|
||||
list.append(QStringLiteral("ListThree"));
|
||||
list.append(QStringLiteral("ListFour"));
|
||||
list.append(QStringLiteral("ListFive"));
|
||||
list.append(QStringLiteral("ListSix"));
|
||||
list.append(QStringLiteral("ListSeven"));
|
||||
list.append(QStringLiteral("ListEight"));
|
||||
list.append(QStringLiteral("ListNine"));
|
||||
list.append(QStringLiteral("ListTen"));
|
||||
list.append(QStringLiteral("ListEleven"));
|
||||
list.append(QStringLiteral("ListAndSoOn"));
|
||||
testComboBox->addItems(list);
|
||||
}
|
||||
|
||||
void TestWindow::slotMakeItem3Current()
|
||||
{
|
||||
testComboBox->setCurrentIndex(3);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("kwindowtest"));
|
||||
|
||||
QApplication myApp(argc, argv);
|
||||
TestWindow *test = new TestWindow;
|
||||
|
||||
myApp.setQuitOnLastWindowClosed(false); // don't quit after the messagebox!
|
||||
|
||||
#if 0
|
||||
int i = QMessageBox::information(0, "Select", "Select type of mainwidget",
|
||||
"Fixed", "Y-fixed", "Resizable");
|
||||
if (i == 0) {
|
||||
test->beFixed();
|
||||
} else if (i == 1) {
|
||||
test->beYFixed();
|
||||
}
|
||||
#endif
|
||||
|
||||
test->show();
|
||||
myApp.setQuitOnLastWindowClosed(true);
|
||||
int ret = myApp.exec();
|
||||
|
||||
// delete test;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include "moc_kwindowtest.cpp"
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef KWINDOWTEST_H
|
||||
#define KWINDOWTEST_H
|
||||
|
||||
#include <QMenuBar>
|
||||
#include <QProgressBar>
|
||||
#include <QStatusBar>
|
||||
#include <QTimer>
|
||||
#include <ktoolbar.h>
|
||||
#include <kxmlguiwindow.h>
|
||||
|
||||
class QTextEdit;
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
|
||||
class TestWindow : public KXmlGuiWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestWindow(QWidget *parent = nullptr);
|
||||
~TestWindow() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void beFixed();
|
||||
void beYFixed();
|
||||
|
||||
void slotNew();
|
||||
void slotPrint();
|
||||
void slotReturn();
|
||||
void slotSave();
|
||||
void slotList(const QString &str);
|
||||
void slotOpen();
|
||||
void slotCompletion();
|
||||
void slotCompletionsMenu(QAction *action);
|
||||
void slotInsertClock();
|
||||
void slotLined();
|
||||
void slotImportant();
|
||||
void slotExit();
|
||||
void slotFrame();
|
||||
void slotListCompletion();
|
||||
void slotMessage(int, bool);
|
||||
void slotToggle(bool);
|
||||
void slotClearCombo();
|
||||
void slotGoGoGoo();
|
||||
void slotInsertListInCombo();
|
||||
void slotMakeItem3Current();
|
||||
void slotToggled(QAction *action);
|
||||
|
||||
protected:
|
||||
QMenu *itemsMenu;
|
||||
QMenu *completions;
|
||||
QStatusBar *statusBar;
|
||||
KToolBar *tb;
|
||||
KToolBar *tb1;
|
||||
class QLineEdit *testLineEdit;
|
||||
class QComboBox *testComboBox;
|
||||
QAction *fileNewAction;
|
||||
QAction *exitAction;
|
||||
bool lineL;
|
||||
bool exitB;
|
||||
bool greenF;
|
||||
bool ena;
|
||||
QTextEdit *widget;
|
||||
QTimer *timer;
|
||||
QProgressBar *pr;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
|
||||
<gui name="windowtest" version="1">
|
||||
|
||||
<MenuBar>
|
||||
<Menu name="file" noMerge="1">
|
||||
<text>&File</text>
|
||||
<Action name="filenew" />
|
||||
<Action name="fileopen" />
|
||||
<Action name="filefloppy" />
|
||||
<Action name="fileprint" />
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="exit"/>
|
||||
</Menu>
|
||||
<Menu name="file2">
|
||||
<text>F&ile2</text>
|
||||
<Action name="filenew2" />
|
||||
<Action name="fileopen2" />
|
||||
<Separator />
|
||||
<Action name="filefloppy2" />
|
||||
<Action name="fileprint2" />
|
||||
<Separator />
|
||||
<Action name="radioButton1" />
|
||||
<Action name="radioButton2" />
|
||||
<Action name="radioButton3" />
|
||||
<Action name="radioButton4" />
|
||||
</Menu>
|
||||
<Menu name="settings">
|
||||
<text>&Settings</text>
|
||||
<Merge name="StandardToolBarMenuHandler" append="show_merge"/>
|
||||
</Menu>
|
||||
</MenuBar>
|
||||
|
||||
|
||||
|
||||
<ToolBar name="mainToolBar"><text>Toolbar 1</text>
|
||||
<Action name="filenew" />
|
||||
<Action name="fileopen" />
|
||||
<Action name="filefloppy" />
|
||||
<Action name="fileprint" />
|
||||
<Action name="combobox" />
|
||||
<Action name="location" />
|
||||
<Action name="exit" />
|
||||
</ToolBar>
|
||||
|
||||
|
||||
<ToolBar name="AnotherToolbar"><text>Toolbar 2</text>
|
||||
<Action name="filenew2" />
|
||||
<Action name="fileopen2" />
|
||||
<Separator />
|
||||
<Action name="filefloppy2" />
|
||||
<Action name="fileprint2" />
|
||||
<Separator />
|
||||
<Action name="radioButton1" />
|
||||
<Action name="radioButton2" />
|
||||
<Action name="radioButton3" />
|
||||
<Action name="radioButton4" />
|
||||
</ToolBar>
|
||||
|
||||
</gui>
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2001 Simon Hausmann <hausmann@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "kxmlguitest.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QLineEdit>
|
||||
#include <QTest>
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <kmainwindow.h>
|
||||
#include <kxmlguibuilder.h>
|
||||
#include <kxmlguifactory.h>
|
||||
|
||||
void Client::slotSec()
|
||||
{
|
||||
qDebug() << "Client::slotSec()";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("test"));
|
||||
QApplication app(argc, argv);
|
||||
QAction *a;
|
||||
|
||||
KMainWindow *mainwindow = new KMainWindow;
|
||||
|
||||
QLineEdit *line = new QLineEdit(mainwindow);
|
||||
mainwindow->setCentralWidget(line);
|
||||
|
||||
mainwindow->show();
|
||||
|
||||
KXMLGUIBuilder *builder = new KXMLGUIBuilder(mainwindow);
|
||||
|
||||
KXMLGUIFactory *factory = new KXMLGUIFactory(builder);
|
||||
|
||||
Client *shell = new Client;
|
||||
shell->setComponentName(QStringLiteral("konqueror"), QStringLiteral("Konqueror"));
|
||||
|
||||
a = new QAction(QIcon::fromTheme(QStringLiteral("view-split-left-right")), QStringLiteral("Split"), shell);
|
||||
shell->actionCollection()->addAction(QStringLiteral("splitviewh"), a);
|
||||
|
||||
shell->setXMLFile(QFINDTESTDATA("kxmlguitest_shell.rc"));
|
||||
|
||||
factory->addClient(shell);
|
||||
|
||||
Client *part = new Client;
|
||||
|
||||
a = new QAction(QIcon::fromTheme(QStringLiteral("zoom-out")), QStringLiteral("decfont"), part);
|
||||
part->actionCollection()->addAction(QStringLiteral("decFontSizes"), a);
|
||||
a = new QAction(QIcon::fromTheme(QStringLiteral("security-low")), QStringLiteral("sec"), part);
|
||||
part->actionCollection()->addAction(QStringLiteral("security"), a);
|
||||
KActionCollection::setDefaultShortcuts(a, QList<QKeySequence>() << QKeySequence{Qt::ALT | Qt::Key_1});
|
||||
a->connect(a, &QAction::triggered, part, &Client::slotSec);
|
||||
|
||||
part->setXMLFile(QFINDTESTDATA("kxmlguitest_part.rc"));
|
||||
|
||||
factory->addClient(part);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
factory->removeClient(part);
|
||||
factory->addClient(part);
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "moc_kxmlguitest.cpp"
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef KXMLGUITEST_H
|
||||
#define KXMLGUITEST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <kxmlguiclient.h>
|
||||
|
||||
class Client : public QObject, public KXMLGUIClient
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Client()
|
||||
{
|
||||
}
|
||||
|
||||
using KXMLGUIClient::setComponentName;
|
||||
using KXMLGUIClient::setXMLFile;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotSec();
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
|
||||
<gui name="khtmlpart" version="7">
|
||||
<ToolBar name="mainToolBar"><text>Main Toolbar</text>
|
||||
<Action name="decFontSizes" />
|
||||
<Separator />
|
||||
<Action name="security" />
|
||||
</ToolBar>
|
||||
</gui>
|
||||
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
|
||||
<gui version="31" name="Konqueror" >
|
||||
<ToolBar newline="true" name="mainToolBar">
|
||||
<text>Main Toolbar</text>
|
||||
<Merge/>
|
||||
<Action name="splitviewh" />
|
||||
</ToolBar>
|
||||
</gui>
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
This file is part of the KDE libraries
|
||||
SPDX-FileCopyrightText: 2008 Rafael Fernández López <ereslibre@kde.org>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-only
|
||||
*/
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QTest>
|
||||
#include <QTextEdit>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KMessageBox>
|
||||
#include <kactioncollection.h>
|
||||
#include <kxmlguiwindow.h>
|
||||
|
||||
// BUG: if this symbol is defined the problem consists on:
|
||||
// - main window is created.
|
||||
// - settings are saved (and applied), but in this case no toolbars exist yet, so they don't
|
||||
// apply to any toolbar.
|
||||
// - after 1 second the GUI is created.
|
||||
//
|
||||
// How to reproduce ?
|
||||
// - Move one toolbar to other place (bottom, left, right, or deattach it).
|
||||
// - Close the test (so settings are saved).
|
||||
// - Reopen the test. The toolbar you moved is not keeping the place you specified.
|
||||
#define REPRODUCE_TOOLBAR_BUG
|
||||
|
||||
class MainWindow : public KXmlGuiWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotTest();
|
||||
void slotCreate();
|
||||
|
||||
private:
|
||||
void setupActions();
|
||||
};
|
||||
|
||||
void MainWindow::slotTest()
|
||||
{
|
||||
KMessageBox::information(nullptr, QStringLiteral("Test"), QStringLiteral("Test"));
|
||||
}
|
||||
|
||||
void MainWindow::slotCreate()
|
||||
{
|
||||
setupGUI(ToolBar | Keys);
|
||||
createGUI(xmlFile());
|
||||
|
||||
if (autoSaveConfigGroup().isValid()) {
|
||||
applyMainWindowSettings(autoSaveConfigGroup());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setupActions()
|
||||
{
|
||||
QAction *testAction = new QAction(this);
|
||||
testAction->setText(QStringLiteral("Test"));
|
||||
testAction->setIcon(QIcon::fromTheme(QStringLiteral("kde")));
|
||||
actionCollection()->addAction(QStringLiteral("test"), testAction);
|
||||
connect(testAction, &QAction::triggered, this, &MainWindow::slotTest);
|
||||
|
||||
KStandardActions::quit(qApp, &QCoreApplication::quit, actionCollection());
|
||||
|
||||
setAutoSaveSettings();
|
||||
|
||||
// BUG: if the GUI is created after an amount of time (so settings have been saved), then toolbars
|
||||
// are shown misplaced. KMainWindow uses a 500 ms timer to save window settings.
|
||||
#ifdef REPRODUCE_TOOLBAR_BUG
|
||||
QTimer::singleShot(1000, this, &MainWindow::slotCreate); // more than 500 ms so the main window has saved settings.
|
||||
// We can think of this case on natural applications when they
|
||||
// load plugins and change parts. It can take 1 second perfectly.
|
||||
#else
|
||||
QTimer::singleShot(0, this, &MainWindow::slotCreate);
|
||||
#endif
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: KXmlGuiWindow(parent)
|
||||
{
|
||||
setXMLFile(QFINDTESTDATA("kxmlguiwindowtestui.rc"), true);
|
||||
// Because we use a full path in setXMLFile, we need to call setLocalXMLFile too.
|
||||
// In your apps, just pass a relative filename to setXMLFile instead.
|
||||
setLocalXMLFile(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kxmlguiwindowtest/kxmlguiwindowtestui.rc"));
|
||||
|
||||
setCentralWidget(new QTextEdit(this));
|
||||
setupActions();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow *mainWindow = new MainWindow;
|
||||
mainWindow->show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "kxmlguiwindowtest.moc"
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE gui SYSTEM 'kpartgui.dtd'>
|
||||
<gui name="kxmlguiwindowtest" version="1">
|
||||
<ToolBar name="mainToolBar">
|
||||
<text>Main Toolbar</text>
|
||||
<Action name="test"/>
|
||||
</ToolBar>
|
||||
<ToolBar name="otherToolBar">
|
||||
<text>Other Toolbar</text>
|
||||
<Action name="file_quit"/>
|
||||
</ToolBar>
|
||||
<MenuBar>
|
||||
<Menu name="file">
|
||||
<Action name="test"/>
|
||||
<Action name="file_quit"/>
|
||||
</Menu>
|
||||
</MenuBar>
|
||||
<ActionProperties scheme="Default">
|
||||
<Action name="help_report_bug" priority="128"/>
|
||||
</ActionProperties>
|
||||
</gui>
|
||||
Reference in New Issue
Block a user