qt 6.5.1 original
15
tests/manual/cocoa/appicon/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## appicon Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(appicon
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
3
tests/manual/cocoa/appicon/README
Normal file
@ -0,0 +1,3 @@
|
||||
Test for checking that the dock icon is changed when
|
||||
QGuiApplication::setWindowIcon() is called. Clicking the
|
||||
buttong should change the entry in the dock to a red icon.
|
4
tests/manual/cocoa/appicon/appicon.pro
Normal file
@ -0,0 +1,4 @@
|
||||
QT += widgets
|
||||
TEMPLATE = app
|
||||
TARGET = appicon
|
||||
SOURCES += main.cpp
|
38
tests/manual/cocoa/appicon/main.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class TopWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TopWidget(QWidget *parent = nullptr) : QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
QPushButton *button = new QPushButton("Change app icon");
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(changeIcon()));
|
||||
layout->addWidget(button);
|
||||
setLayout(layout);
|
||||
}
|
||||
public slots:
|
||||
void changeIcon()
|
||||
{
|
||||
QPixmap pix(32, 32);
|
||||
pix.fill(Qt::red);
|
||||
QIcon i(pix);
|
||||
qApp->setWindowIcon(i);
|
||||
}
|
||||
};
|
||||
|
||||
#include "main.moc"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
TopWidget w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
19
tests/manual/cocoa/menurama/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## Menurama Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(Menurama
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
mainwindow.cpp mainwindow.h mainwindow.ui
|
||||
menuramaapplication.cpp menuramaapplication.h
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
ENABLE_AUTOGEN_TOOLS
|
||||
uic
|
||||
)
|
51
tests/manual/cocoa/menurama/main.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "menuramaapplication.h"
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QtWidgets/QMenu>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
MenuramaApplication a(argc, argv);
|
||||
a.setQuitOnLastWindowClosed(false);
|
||||
|
||||
auto *dockMenu = new QMenu();
|
||||
dockMenu->setAsDockMenu();
|
||||
dockMenu->addAction(QLatin1String("New Window"), [=] {
|
||||
auto *w = new MainWindow;
|
||||
w->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
w->show();
|
||||
});
|
||||
auto *disabledAction = dockMenu->addAction(QLatin1String("Disabled Item"), [=] {
|
||||
qDebug() << "Should not happen!";
|
||||
Q_UNREACHABLE();
|
||||
});
|
||||
disabledAction->setEnabled(false);
|
||||
dockMenu->addAction(QLatin1String("Last Item Before Separator"), [=] {
|
||||
qDebug() << "Last Item triggered";
|
||||
});
|
||||
auto *hiddenAction = dockMenu->addAction(QLatin1String("Invisible Item (FIXME rdar:39615815)"), [=] {
|
||||
qDebug() << "Should not happen!";
|
||||
Q_UNREACHABLE();
|
||||
});
|
||||
hiddenAction->setVisible(false);
|
||||
dockMenu->addSeparator();
|
||||
auto *toolsMenu = dockMenu->addMenu(QLatin1String("Menurama Tools"));
|
||||
toolsMenu->addAction(QLatin1String("Hammer"), [=] {
|
||||
qDebug() << "Bang! Bang!";
|
||||
});
|
||||
toolsMenu->addAction(QLatin1String("Wrench"), [=] {
|
||||
qDebug() << "Clang! Clang!";
|
||||
});
|
||||
toolsMenu->addAction(QLatin1String("Screwdriver"), [=] {
|
||||
qDebug() << "Squeak! Squeak!";
|
||||
});
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
73
tests/manual/cocoa/menurama/mainwindow.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "menuramaapplication.h"
|
||||
#include <QDebug>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
auto *a = ui->menuStuff->addAction("Enabled Submenu (QTBUG-63172)");
|
||||
auto *qtbug63172_Menu = new QMenu;
|
||||
qtbug63172_Menu->addAction("We're Good!");
|
||||
a->setMenu(qtbug63172_Menu);
|
||||
|
||||
startTimer(1000);
|
||||
|
||||
connect(ui->menuAfter_aboutToShow, &QMenu::aboutToShow, [=] {
|
||||
menuApp->populateMenu(ui->menuAfter_aboutToShow, true /*clear*/);
|
||||
});
|
||||
|
||||
connect(ui->menuDynamic_Stuff, &QMenu::aboutToShow, [=] {
|
||||
menuApp->addDynMenu(QLatin1String("Menu Added After aboutToShow()"), ui->menuDynamic_Stuff);
|
||||
|
||||
const QLatin1String itemTitle = QLatin1String("Disabled Item Added After aboutToShow()");
|
||||
if (QAction *a = menuApp->findAction(itemTitle, ui->menuDynamic_Stuff))
|
||||
ui->menuDynamic_Stuff->removeAction(a);
|
||||
QAction *a = ui->menuDynamic_Stuff->addAction(itemTitle);
|
||||
a->setEnabled(false);
|
||||
});
|
||||
|
||||
connect(ui->pushButton, &QPushButton::clicked, [=] {
|
||||
menuApp->populateMenu(ui->menuOn_Click, true /*clear*/);
|
||||
});
|
||||
|
||||
connect(ui->addManyButton, &QPushButton::clicked, [=] {
|
||||
QMenu *menu = new QMenu(QLatin1String("Many More ") +
|
||||
QString::number(ui->menuBar->actions().count()));
|
||||
ui->menuBar->insertMenu(ui->menuDynamic_Stuff->menuAction(), menu);
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
auto *action = menu->addAction(QLatin1String("Item ") + QString::number(i));
|
||||
if (i & 0x1)
|
||||
action->setEnabled(false);
|
||||
if (i & 0x2)
|
||||
action->setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::timerEvent(QTimerEvent *)
|
||||
{
|
||||
menuApp->populateMenu(ui->menuPopulated_by_Timer, true /*clear*/);
|
||||
menuApp->addDynMenu(QLatin1String("Added by Timer"), ui->menuDynamic_Stuff);
|
||||
}
|
||||
|
||||
void MainWindow::enableStuffMenu(bool enable)
|
||||
{
|
||||
ui->menuStuff->setEnabled(enable);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionQuit_triggered()
|
||||
{
|
||||
menuApp->exit();
|
||||
}
|
34
tests/manual/cocoa/menurama/mainwindow.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *) override;
|
||||
|
||||
public slots:
|
||||
void enableStuffMenu(bool enable);
|
||||
|
||||
private slots:
|
||||
void on_actionQuit_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
328
tests/manual/cocoa/menurama/mainwindow.ui
Normal file
@ -0,0 +1,328 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>486</width>
|
||||
<height>376</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>The "Help" menu should NOT be visible.
|
||||
|
||||
Click on "Dynamic Stuff" then move left and right to other menus. Disabled items should remain that way.</string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Enable "Stuff" Menu</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Populate Dynamic Submenu</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QPushButton" name="addManyButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add Many Items</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Adding hundreds of items should not block the UI for noticeable periods of time. Odd numbered items should be disabled, those with 2nd LSB on should be hidden.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Check out the dock menu. You can close this window to verify that its actions will trigger in the absence of any window. And you can add more windows from there too.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>486</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuStuff">
|
||||
<property name="title">
|
||||
<string>Stuff</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuSubmenu">
|
||||
<property name="title">
|
||||
<string>Submenu</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuMore_Submenu_2">
|
||||
<property name="title">
|
||||
<string>More Submenu</string>
|
||||
</property>
|
||||
<addaction name="actionMOARH"/>
|
||||
</widget>
|
||||
<addaction name="actionWith_More_Stuff"/>
|
||||
<addaction name="menuMore_Submenu_2"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuDisabled_Submenu">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Disabled Submenu</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuMore_Submenu">
|
||||
<property name="title">
|
||||
<string>More Submenu</string>
|
||||
</property>
|
||||
<addaction name="actionShould_be_Disabled_Too"/>
|
||||
</widget>
|
||||
<addaction name="actionShould_be_Disabled"/>
|
||||
<addaction name="menuMore_Submenu"/>
|
||||
</widget>
|
||||
<addaction name="actionItem"/>
|
||||
<addaction name="menuSubmenu"/>
|
||||
<addaction name="actionDisabled_Item"/>
|
||||
<addaction name="menuDisabled_Submenu"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuDisabled_Stuff">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Disabled Stuff</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuSubmenu_2">
|
||||
<property name="title">
|
||||
<string>Disabled Submenu</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuSubsubmenu">
|
||||
<property name="title">
|
||||
<string>Disabled Subsubmenu</string>
|
||||
</property>
|
||||
<addaction name="actionWith_its_own_Stuff"/>
|
||||
</widget>
|
||||
<addaction name="actionMore_Disabled_Stuff"/>
|
||||
<addaction name="menuSubsubmenu"/>
|
||||
</widget>
|
||||
<addaction name="actionItem_2"/>
|
||||
<addaction name="menuSubmenu_2"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuShould_NOT_Be_Visible">
|
||||
<property name="title">
|
||||
<string>Should NOT Be Visible</string>
|
||||
</property>
|
||||
<addaction name="actionAbout"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp">
|
||||
<property name="title">
|
||||
<string>Help</string>
|
||||
</property>
|
||||
<addaction name="actionAbout_Qt"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuDynamic_Stuff">
|
||||
<property name="title">
|
||||
<string>Dynamic Stuff</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuAfter_aboutToShow">
|
||||
<property name="title">
|
||||
<string>Populated After aboutToShow()</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuOn_Click">
|
||||
<property name="title">
|
||||
<string>Click Button to Populate</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuPopulated_by_Timer">
|
||||
<property name="title">
|
||||
<string>Populated by Timer</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menuOn_Click"/>
|
||||
<addaction name="menuAfter_aboutToShow"/>
|
||||
<addaction name="menuPopulated_by_Timer"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionNew"/>
|
||||
<addaction name="actionNo_Empty_Spaces_Below"/>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuStuff"/>
|
||||
<addaction name="menuDisabled_Stuff"/>
|
||||
<addaction name="menuShould_NOT_Be_Visible"/>
|
||||
<addaction name="menuDynamic_Stuff"/>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionWith_More_Stuff">
|
||||
<property name="text">
|
||||
<string>With More Stuff</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDisabled_Item">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Disabled Item</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionItem">
|
||||
<property name="text">
|
||||
<string>Item</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShould_be_Disabled">
|
||||
<property name="text">
|
||||
<string>Should be Disabled</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShould_be_Disabled_Too">
|
||||
<property name="text">
|
||||
<string>Should be Disabled Too</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionMOARH">
|
||||
<property name="text">
|
||||
<string>MOAR!!</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionItem_2">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Disabled Item</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionMore_Disabled_Stuff">
|
||||
<property name="text">
|
||||
<string>More Disabled Stuff</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionWith_its_own_Stuff">
|
||||
<property name="text">
|
||||
<string>With its own Disabled Stuff</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout_Qt">
|
||||
<property name="text">
|
||||
<string>About Qt</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionQuit">
|
||||
<property name="text">
|
||||
<string>Exit</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNew">
|
||||
<property name="text">
|
||||
<string>New...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNo_Empty_Spaces_Below">
|
||||
<property name="text">
|
||||
<string>No Empty Spaces Below</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>checkBox</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>enableStuffMenu(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>62</x>
|
||||
<y>94</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>72</x>
|
||||
<y>73</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>enableStuffMenu(bool)</slot>
|
||||
</slots>
|
||||
</ui>
|
20
tests/manual/cocoa/menurama/menurama.pro
Normal file
@ -0,0 +1,20 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2016-08-10T14:21:46
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui widgets
|
||||
|
||||
TARGET = Menurama
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
menuramaapplication.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
menuramaapplication.h
|
||||
|
||||
FORMS += mainwindow.ui
|
50
tests/manual/cocoa/menurama/menuramaapplication.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "menuramaapplication.h"
|
||||
|
||||
MenuramaApplication::MenuramaApplication(int &argc, char **argv)
|
||||
: QApplication (argc, argv)
|
||||
{
|
||||
#if 0
|
||||
QMenuBar *mb = new QMenuBar();
|
||||
QMenu *menu = mb->addMenu("App Dynamic");
|
||||
QMenu *dynMenu = menu->addMenu("After aboutToShow()");
|
||||
connect(dynMenu, &QMenu::aboutToShow, [=] {
|
||||
qDebug() << "aboutToShow(), populating" << dynMenu;
|
||||
menuApp->populateMenu(dynMenu, true /*clear*/);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void MenuramaApplication::populateMenu(QMenu *menu, bool clear)
|
||||
{
|
||||
if (clear)
|
||||
menu->clear();
|
||||
|
||||
static const char *sym[] = { "Foo", "Bar", "Baz", "Huux" };
|
||||
static int id = 0;
|
||||
for (unsigned i = 0; i < sizeof(sym) / sizeof(sym[0]); i++)
|
||||
menu->addAction(QStringLiteral("%1 — %2 %3 ")
|
||||
.arg(menu->title()).arg(sym[i]).arg(id));
|
||||
++id;
|
||||
}
|
||||
|
||||
void MenuramaApplication::addDynMenu(QLatin1String title, QMenu *parentMenu)
|
||||
{
|
||||
if (QAction *a = findAction(title, parentMenu))
|
||||
parentMenu->removeAction(a);
|
||||
|
||||
QMenu *subMenu = new QMenu(title, parentMenu);
|
||||
populateMenu(subMenu, false /*clear*/);
|
||||
parentMenu->addMenu(subMenu);
|
||||
}
|
||||
|
||||
QAction *MenuramaApplication::findAction(QLatin1String title, QMenu *parentMenu)
|
||||
{
|
||||
foreach (QAction *a, parentMenu->actions())
|
||||
if (a->text() == title)
|
||||
return a;
|
||||
|
||||
return nullptr;
|
||||
}
|
22
tests/manual/cocoa/menurama/menuramaapplication.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef MENURAMAAPPLICATION_H
|
||||
#define MENURAMAAPPLICATION_H
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#define menuApp (static_cast<MenuramaApplication *>(QCoreApplication::instance()))
|
||||
|
||||
class MenuramaApplication : public QApplication
|
||||
{
|
||||
public:
|
||||
MenuramaApplication(int &argc, char **argv);
|
||||
void addDynMenu(QLatin1String title, QMenu *parentMenu);
|
||||
QAction *findAction(QLatin1String title, QMenu *parentMenu);
|
||||
|
||||
public slots:
|
||||
void populateMenu(QMenu *menu, bool clear);
|
||||
};
|
||||
|
||||
#endif // MENURAMAAPPLICATION_H
|
14
tests/manual/cocoa/menus/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## menus Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(menus
|
||||
SOURCES
|
||||
main.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
223
tests/manual/cocoa/menus/main.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
// Copyright (C) 2012 KDAB
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QApplication>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
class Responder : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Responder(QObject *pr) :
|
||||
QObject(pr), visibleMenu(0), visibleSubMenu(0), enabledMenu(0), enabledSubMenu(0), visibleAction(0), enabledAction(0)
|
||||
{
|
||||
}
|
||||
void setVisibleObjects(QMenu *vm, QMenu *vsm, QAction *va)
|
||||
{
|
||||
visibleMenu = vm;
|
||||
visibleSubMenu = vsm;
|
||||
visibleAction = va;
|
||||
}
|
||||
void setEnabledObjects(QMenu *em, QMenu *esm, QAction *ea)
|
||||
{
|
||||
enabledMenu = em;
|
||||
enabledSubMenu = esm;
|
||||
enabledAction = ea;
|
||||
}
|
||||
public slots:
|
||||
void toggleVisiblity()
|
||||
{
|
||||
visibleMenu->menuAction()->setVisible(!visibleMenu->menuAction()->isVisible());
|
||||
visibleSubMenu->menuAction()->setVisible(!visibleSubMenu->menuAction()->isVisible());
|
||||
visibleAction->setVisible(!visibleAction->isVisible());
|
||||
}
|
||||
void toggleEnabled()
|
||||
{
|
||||
enabledMenu->menuAction()->setEnabled(!enabledMenu->menuAction()->isEnabled());
|
||||
enabledSubMenu->menuAction()->setEnabled(!enabledSubMenu->menuAction()->isEnabled());
|
||||
enabledAction->setEnabled(!enabledAction->isEnabled());
|
||||
}
|
||||
void toggleChecked(bool b)
|
||||
{
|
||||
QAction *a = qobject_cast<QAction *>(sender());
|
||||
}
|
||||
|
||||
void showModalDialog()
|
||||
{
|
||||
QMessageBox::information(NULL, "Something", "Something happened. Modally.");
|
||||
}
|
||||
|
||||
void doPreferences()
|
||||
{
|
||||
qDebug() << "show preferences";
|
||||
}
|
||||
|
||||
void aboutToShowSubmenu()
|
||||
{
|
||||
QMenu* m = (QMenu*) sender();
|
||||
qDebug() << "will show" << m;
|
||||
|
||||
m->clear();
|
||||
|
||||
for (int i=0; i<10; ++i) {
|
||||
m->addAction(QString("Recent File %1").arg(i + 1));
|
||||
}
|
||||
}
|
||||
private:
|
||||
QMenu *visibleMenu, *visibleSubMenu, *enabledMenu, *enabledSubMenu;
|
||||
QAction *visibleAction, *enabledAction;
|
||||
};
|
||||
|
||||
void createWindow1()
|
||||
{
|
||||
|
||||
QMainWindow *window = new QMainWindow;
|
||||
QMenu *menu = new QMenu("TestMenu", window);
|
||||
|
||||
window->menuBar()->addMenu(menu);
|
||||
|
||||
Responder *r = new Responder(window);
|
||||
|
||||
QAction *a = menu->addAction("TestMenuItem1");
|
||||
a->setShortcut( Qt::Key_A | Qt::SHIFT | Qt::CTRL );
|
||||
QObject::connect(a, SIGNAL(triggered()),
|
||||
r, SLOT(showModalDialog()));
|
||||
|
||||
|
||||
menu->addAction("T&estMenuItem2");
|
||||
a = menu->addAction("Preferences");
|
||||
a->setMenuRole(QAction::PreferencesRole);
|
||||
QObject::connect(a, SIGNAL(triggered()),
|
||||
r, SLOT(doPreferences()));
|
||||
|
||||
a = menu->addAction("TestMenuItem4");
|
||||
a->setShortcut( Qt::Key_W | Qt::CTRL);
|
||||
|
||||
QMenu *menu2 = new QMenu("SecondMenu", window);
|
||||
window->menuBar()->addMenu(menu2);
|
||||
|
||||
menu2->addAction("Yellow");
|
||||
a = menu2->addAction("Mau&ve");
|
||||
|
||||
QFont f;
|
||||
f.setPointSize(9);
|
||||
a->setFont(f);
|
||||
|
||||
menu2->addAction("Taupe");
|
||||
|
||||
QMenu *submenu1 = new QMenu("Submenu", window);
|
||||
submenu1->addAction("Sub Item 1");
|
||||
submenu1->addAction("Sub Item 2");
|
||||
submenu1->addAction("Sub Item 3");
|
||||
menu2->addMenu(submenu1);
|
||||
|
||||
QMenu *submenu2 = new QMenu("Deeper", window);
|
||||
submenu2->addAction("Sub Sub Item 1");
|
||||
submenu2->addAction("Sub Sub Item 2");
|
||||
submenu2->addAction("Sub Sub Item 3");
|
||||
submenu1->addMenu(submenu2);
|
||||
|
||||
QMenu *menu3 = new QMenu("A Third Menu", window);
|
||||
|
||||
menu3->addAction("Eins");
|
||||
|
||||
QMenu *submenu3 = new QMenu("Dynamic", window);
|
||||
QObject::connect(submenu3, SIGNAL(aboutToShow()), r, SLOT(aboutToShowSubmenu()));
|
||||
menu3->addMenu(submenu3);
|
||||
|
||||
a = menu3->addAction("Zwei");
|
||||
a->setShortcut( Qt::Key_3 | Qt::ALT);
|
||||
a = menu3->addAction("About Drei...");
|
||||
a->setMenuRole(QAction::AboutRole);
|
||||
|
||||
window->menuBar()->addMenu(menu3);
|
||||
|
||||
QAction *checkableAction = new QAction("Thing Enabled", window);
|
||||
checkableAction->setCheckable(true);
|
||||
checkableAction->setChecked(true);
|
||||
QObject::connect(checkableAction, SIGNAL(triggered(bool)),
|
||||
r, SLOT(toggleChecked(bool)));
|
||||
|
||||
menu2->addAction(checkableAction);
|
||||
|
||||
QMenu *menu4 = new QMenu("Toggle menu", window);
|
||||
QAction *toggleVisiblity = new QAction("Toggle visibility", window);
|
||||
QAction *toggleEnabled = new QAction("Toggle enabled", window);
|
||||
QObject::connect(toggleVisiblity, SIGNAL(triggered()), r, SLOT(toggleVisiblity()));
|
||||
QObject::connect(toggleEnabled, SIGNAL(triggered()), r, SLOT(toggleEnabled()));
|
||||
menu4->addAction(toggleVisiblity);
|
||||
menu4->addAction(toggleEnabled);
|
||||
window->menuBar()->addMenu(menu4);
|
||||
|
||||
QMenu *menu5 = new QMenu("Visible Menu", window);
|
||||
menu5->addAction("Dummy action");
|
||||
window->menuBar()->addMenu(menu5);
|
||||
QMenu *menu6 = new QMenu("Menu with visible action and submenu", window);
|
||||
QAction *visibleAction = new QAction("Visible action", window);
|
||||
menu6->addAction(visibleAction);
|
||||
QMenu *subMenu6 = new QMenu("Submenu");
|
||||
subMenu6->addAction("Dummy action");
|
||||
menu6->addMenu(subMenu6);
|
||||
window->menuBar()->addMenu(menu6);
|
||||
|
||||
QMenu *menu7 = new QMenu("Enabled Menu", window);
|
||||
menu7->addAction("Dummy action");
|
||||
window->menuBar()->addMenu(menu7);
|
||||
QMenu *menu8 = new QMenu("Menu with enabled action and submenu", window);
|
||||
QAction *enabledAction = new QAction("Enabled action", window);
|
||||
menu8->addAction(enabledAction);
|
||||
QMenu *subMenu8 = new QMenu("Submenu");
|
||||
subMenu8->addAction("Dummy action");
|
||||
menu8->addMenu(subMenu8);
|
||||
window->menuBar()->addMenu(menu8);
|
||||
|
||||
r->setVisibleObjects(menu5, subMenu6, visibleAction);
|
||||
r->setEnabledObjects(menu7, subMenu8, enabledAction);
|
||||
window->show();
|
||||
|
||||
}
|
||||
|
||||
void createWindow2()
|
||||
{
|
||||
QMainWindow *window = new QMainWindow;
|
||||
QMenu *menu = new QMenu("Nuts", window);
|
||||
|
||||
window->menuBar()->addMenu(menu);
|
||||
|
||||
menu->addAction("Peanuts");
|
||||
menu->addAction("Walnuts");
|
||||
|
||||
QMenu *menu2 = new QMenu("Colours", window);
|
||||
window->menuBar()->addMenu(menu2);
|
||||
|
||||
menu2->addAction("Pink");
|
||||
menu2->addAction("Yellow");
|
||||
menu2->addAction("Grape");
|
||||
|
||||
QMenu *menu3 = new QMenu("Edit", window);
|
||||
menu3->addAction("Cut");
|
||||
menu3->addAction("Copy boring way");
|
||||
menu3->addAction("Copy awesomely");
|
||||
menu3->addAction("Paste");
|
||||
|
||||
window->menuBar()->addMenu(menu3);
|
||||
window->show();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QApplication app(argc, argv);
|
||||
|
||||
app.setApplicationName("Banana");
|
||||
|
||||
createWindow1();
|
||||
createWindow2();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "main.moc"
|
5
tests/manual/cocoa/menus/menus.pro
Normal file
@ -0,0 +1,5 @@
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += main.cpp
|
||||
QT += gui widgets
|
||||
CONFIG -=app_bundle
|
15
tests/manual/cocoa/nativewidgets/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## nativewigets Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(nativewigets
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
109
tests/manual/cocoa/nativewidgets/main.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtWidgets>
|
||||
|
||||
class ColorWidget : public QWidget
|
||||
{
|
||||
QColor color;
|
||||
int s;
|
||||
int v;
|
||||
|
||||
void changeColor()
|
||||
{
|
||||
color.setHsv(QRandomGenerator::global()->bounded(50) + 200, s, s);
|
||||
}
|
||||
|
||||
public:
|
||||
ColorWidget()
|
||||
{
|
||||
s = 150;
|
||||
v = 150;
|
||||
changeColor();
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
void mousePressEvent(QMouseEvent *)
|
||||
{
|
||||
changeColor();
|
||||
update();
|
||||
}
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *)
|
||||
{
|
||||
changeColor();
|
||||
update();
|
||||
}
|
||||
|
||||
void enterEvent(QEnterEvent *)
|
||||
{
|
||||
s = 200;
|
||||
v = 200;
|
||||
changeColor();
|
||||
update();
|
||||
}
|
||||
|
||||
void leaveEvent(QEvent *)
|
||||
{
|
||||
s = 75;
|
||||
v = 75;
|
||||
changeColor();
|
||||
update();
|
||||
}
|
||||
|
||||
void paintEvent(QPaintEvent *){
|
||||
QPainter p(this);
|
||||
p.fillRect(QRect(QPoint(0, 0), size()), QBrush(color));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
ColorWidget window;
|
||||
|
||||
QWidget *w1 = new ColorWidget;
|
||||
QWidget *w2 = new ColorWidget;
|
||||
QWidget *w3 = new ColorWidget;
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
layout->addWidget(w1);
|
||||
layout->addWidget(w2);
|
||||
layout->addWidget(w3);
|
||||
|
||||
QWidget *w3_1 = new ColorWidget;
|
||||
QWidget *w3_2 = new ColorWidget;
|
||||
QWidget *w3_3 = new ColorWidget;
|
||||
|
||||
QVBoxLayout *layout3 = new QVBoxLayout;
|
||||
layout3->setMargin(0);
|
||||
layout3->addWidget(w3_1);
|
||||
layout3->addWidget(w3_2);
|
||||
layout3->addWidget(w3_3);
|
||||
w3->setLayout(layout3);
|
||||
|
||||
window.setLayout(layout);
|
||||
|
||||
bool native = 1;
|
||||
|
||||
if (native) {
|
||||
w1->winId();
|
||||
w2->winId();
|
||||
w3->winId();
|
||||
|
||||
w3_1->winId();
|
||||
w3_2->winId();
|
||||
w3_3->winId();
|
||||
}
|
||||
|
||||
window.resize(640, 480);
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
||||
|
6
tests/manual/cocoa/nativewidgets/nativewigets.pro
Normal file
@ -0,0 +1,6 @@
|
||||
TEMPLATE = app
|
||||
|
||||
HEADERS +=
|
||||
SOURCES += main.cpp
|
||||
|
||||
QT += core widgets
|
14
tests/manual/cocoa/popups/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## popups Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(popups
|
||||
SOURCES
|
||||
main.cpp
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
122
tests/manual/cocoa/popups/main.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
class Window : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Window();
|
||||
|
||||
public slots:
|
||||
void triggered(QAction*);
|
||||
void clean();
|
||||
void showPoppWindow();
|
||||
|
||||
private:
|
||||
QLabel *explanation;
|
||||
QToolButton *toolButton;
|
||||
QMenu *menu;
|
||||
QLineEdit *echo;
|
||||
QComboBox *comboBox;
|
||||
QPushButton *pushButton;
|
||||
};
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
QGroupBox* group = new QGroupBox(tr("test the popup"));
|
||||
|
||||
explanation = new QLabel(
|
||||
"This test is used to verify that popup windows will be closed "
|
||||
"as expected. This includes when clicking outside the popup or moving the "
|
||||
"parent window. Tested popups include context menus, combo box popups, tooltips "
|
||||
"and QWindow with Qt::Popup set."
|
||||
);
|
||||
explanation->setWordWrap(true);
|
||||
explanation->setToolTip("I'm a tool tip!");
|
||||
|
||||
menu = new QMenu(group);
|
||||
menu->addAction(tr("line one"));
|
||||
menu->addAction(tr("line two"));
|
||||
menu->addAction(tr("line three"));
|
||||
menu->addAction(tr("line four"));
|
||||
menu->addAction(tr("line five"));
|
||||
|
||||
QMenu *subMenu1 = new QMenu();
|
||||
subMenu1->addAction("1");
|
||||
subMenu1->addAction("2");
|
||||
subMenu1->addAction("3");
|
||||
menu->addMenu(subMenu1);
|
||||
|
||||
QMenu *subMenu2 = new QMenu();
|
||||
subMenu2->addAction("2 1");
|
||||
subMenu2->addAction("2 2");
|
||||
subMenu2->addAction("2 3");
|
||||
menu->addMenu(subMenu2);
|
||||
|
||||
toolButton = new QToolButton(group);
|
||||
toolButton->setMenu(menu);
|
||||
toolButton->setPopupMode( QToolButton::MenuButtonPopup );
|
||||
toolButton->setText("select me");
|
||||
|
||||
echo = new QLineEdit(group);
|
||||
echo->setPlaceholderText("not triggered");
|
||||
|
||||
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*)));
|
||||
connect(menu, SIGNAL(aboutToShow()), this, SLOT(clean()));
|
||||
|
||||
comboBox = new QComboBox();
|
||||
comboBox->addItem("Item 1");
|
||||
comboBox->addItem("Item 2");
|
||||
comboBox->addItem("Item 3");
|
||||
|
||||
pushButton = new QPushButton("Show popup window");
|
||||
connect(pushButton, SIGNAL(clicked()), this, SLOT(showPoppWindow()));
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
layout->addWidget(explanation);
|
||||
layout->addWidget(toolButton);
|
||||
layout->addWidget(echo);
|
||||
layout->addWidget(comboBox);
|
||||
layout->addWidget(pushButton);
|
||||
|
||||
group ->setLayout(layout);
|
||||
setLayout(layout);
|
||||
setWindowTitle(tr("Popup Window Testing"));
|
||||
}
|
||||
|
||||
void Window::clean()
|
||||
{
|
||||
echo->setText("");
|
||||
}
|
||||
|
||||
void Window::showPoppWindow()
|
||||
{
|
||||
QWindow *window = new QWindow();
|
||||
window->setTransientParent(this->windowHandle());
|
||||
window->setPosition(this->pos());
|
||||
window->setWidth(100);
|
||||
window->setHeight(100);
|
||||
window->setFlags(Qt::Window | Qt::Popup);
|
||||
window->show();
|
||||
}
|
||||
|
||||
void Window::triggered(QAction* act)
|
||||
{
|
||||
if (!act)
|
||||
return;
|
||||
echo->setText(act->text());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
Window window;
|
||||
window.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "main.moc"
|
4
tests/manual/cocoa/popups/popups.pro
Normal file
@ -0,0 +1,4 @@
|
||||
QT += widgets
|
||||
|
||||
SOURCES = main.cpp
|
||||
CONFIG -= app_bundle
|
35
tests/manual/cocoa/qsystemtrayicon/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## qsystemtrayicon Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(qsystemtrayicon
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
INCLUDE_DIRECTORIES
|
||||
.
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(icons_resource_files
|
||||
"macsystray16x16.png"
|
||||
"macsystray18x18.png"
|
||||
"macsystray25x15.png"
|
||||
"macsystray32x32.png"
|
||||
"macsystray36x36.png"
|
||||
"macsystray50x30.png"
|
||||
"macsystray64x64.png"
|
||||
)
|
||||
|
||||
qt_internal_add_resource(qsystemtrayicon "icons"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${icons_resource_files}
|
||||
)
|
11
tests/manual/cocoa/qsystemtrayicon/icons.qrc
Normal file
@ -0,0 +1,11 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>macsystray18x18.png</file>
|
||||
<file>macsystray36x36.png</file>
|
||||
<file>macsystray25x15.png</file>
|
||||
<file>macsystray50x30.png</file>
|
||||
<file>macsystray16x16.png</file>
|
||||
<file>macsystray32x32.png</file>
|
||||
<file>macsystray64x64.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray16x16.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray18x18.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray25x15.png
Normal file
After Width: | Height: | Size: 109 B |
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray32x32.png
Normal file
After Width: | Height: | Size: 117 B |
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray36x36.png
Normal file
After Width: | Height: | Size: 151 B |
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray50x30.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
tests/manual/cocoa/qsystemtrayicon/macsystray64x64.png
Normal file
After Width: | Height: | Size: 204 B |
50
tests/manual/cocoa/qsystemtrayicon/main.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
#include <QtWidgets>
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QWidget window;
|
||||
window.show();
|
||||
|
||||
QSystemTrayIcon systrayIcon(&window);
|
||||
|
||||
|
||||
enum Iconset { Square, // square icons, reccomended size (18 device-independent pixels or less)
|
||||
Rectangular, // rectangular icons, good size
|
||||
PowerOfTwo, // standard pow-2 icons, not optimized for the OS X menu bar
|
||||
Small, // Not enough pixels
|
||||
UnreasonablyLarge // please do something reasonable with my unreasonably large pixmap
|
||||
};
|
||||
|
||||
// Select icon set and load images
|
||||
Iconset iconset = Square;
|
||||
QIcon icon;
|
||||
switch (iconset) {
|
||||
case Square:
|
||||
icon.addFile(":/macsystray36x36.png");
|
||||
icon.addFile(":/macsystray18x18.png");
|
||||
break;
|
||||
case Rectangular:
|
||||
icon.addFile(":/macsystray50x30.png");
|
||||
icon.addFile(":/macsystray25x15.png");
|
||||
break;
|
||||
case PowerOfTwo:
|
||||
icon.addFile(":/macsystray16x16.png");
|
||||
icon.addFile(":/macsystray32x32.png");
|
||||
icon.addFile(":/macsystray64x64.png");
|
||||
break;
|
||||
case Small:
|
||||
icon.addFile(":/macsystray16x16.png");
|
||||
case UnreasonablyLarge:
|
||||
icon.addFile(":/macsystray64x64.png");
|
||||
break;
|
||||
}
|
||||
|
||||
systrayIcon.setIcon(icon);
|
||||
systrayIcon.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
7
tests/manual/cocoa/qsystemtrayicon/qsystemtrayicon.pro
Normal file
@ -0,0 +1,7 @@
|
||||
TEMPLATE = app
|
||||
TARGET = qsystemtrayicon
|
||||
INCLUDEPATH += .
|
||||
QT += widgets
|
||||
|
||||
SOURCES += main.cpp
|
||||
RESOURCES += icons.qrc
|
18
tests/manual/cocoa/qt_on_cocoa/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## qt_on_cocoa Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(qt_on_cocoa
|
||||
GUI
|
||||
SOURCES
|
||||
main.mm
|
||||
rasterwindow.cpp rasterwindow.h
|
||||
LIBRARIES
|
||||
${FWAppKit}
|
||||
Qt::Gui
|
||||
Qt::Quick
|
||||
Qt::Widgets
|
||||
)
|
105
tests/manual/cocoa/qt_on_cocoa/main.mm
Normal file
@ -0,0 +1,105 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "rasterwindow.h"
|
||||
|
||||
#include <QtGui>
|
||||
#include <QtWidgets/QtWidgets>
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
|
||||
@interface ContentView : NSView
|
||||
@end
|
||||
|
||||
@implementation ContentView
|
||||
- (void)drawRect:(NSRect)dirtyRect {
|
||||
[[NSColor whiteColor] setFill];
|
||||
NSRectFill(dirtyRect);
|
||||
}
|
||||
|
||||
- (void)cursorUpdate:(NSEvent *)theEvent
|
||||
{
|
||||
Q_UNUSED(theEvent);
|
||||
[[NSCursor pointingHandCursor] set];
|
||||
}
|
||||
@end
|
||||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
||||
@end
|
||||
|
||||
@implementation AppDelegate {
|
||||
QGuiApplication *m_app;
|
||||
QWindow *m_window;
|
||||
}
|
||||
|
||||
- (instancetype)initWithArgc:(int)argc argv:(const char **)argv
|
||||
{
|
||||
if ((self = [self init])) {
|
||||
m_app = new QGuiApplication(argc, const_cast<char **>(argv));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)applicationWillFinishLaunching:(NSNotification *)notification
|
||||
{
|
||||
Q_UNUSED(notification);
|
||||
|
||||
// Create the NSWindow
|
||||
NSRect frame = NSMakeRect(500, 500, 500, 500);
|
||||
NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
|
||||
NSString *title = @"This the NSWindow window";
|
||||
[window setTitle:title];
|
||||
[window setBackgroundColor:[NSColor blueColor]];
|
||||
|
||||
NSView *contentView = [[[ContentView alloc] initWithFrame:frame] autorelease];
|
||||
[contentView addTrackingArea:[[NSTrackingArea alloc] initWithRect:[contentView frame]
|
||||
options:NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | NSTrackingCursorUpdate
|
||||
owner:contentView userInfo:nil]];
|
||||
|
||||
// Create the QWindow, add its NSView to the content view
|
||||
m_window = new RasterWindow;
|
||||
m_window->setObjectName("RasterWindow");
|
||||
m_window->setCursor(Qt::CrossCursor);
|
||||
m_window->setGeometry(QRect(0, 0, 300, 300));
|
||||
|
||||
QWindow *childWindow = new RasterWindow;
|
||||
childWindow->setObjectName("RasterWindowChild");
|
||||
childWindow->setParent(m_window);
|
||||
childWindow->setCursor(Qt::BusyCursor);
|
||||
childWindow->setGeometry(50, 50, 100, 100);
|
||||
|
||||
NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 80, 25)];
|
||||
[reinterpret_cast<NSView *>(childWindow->winId()) addSubview:textField];
|
||||
|
||||
[contentView addSubview:reinterpret_cast<NSView *>(m_window->winId())];
|
||||
|
||||
window.contentView = contentView;
|
||||
|
||||
// Show the NSWindow delayed, so that we can verify that Qt picks up the right
|
||||
// notifications to expose the window when it does become visible.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[window makeKeyAndOrderFront:NSApp];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)notification
|
||||
{
|
||||
Q_UNUSED(notification);
|
||||
delete m_window;
|
||||
delete m_app;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
// Create NSApplicaiton with delgate
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv];
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
10
tests/manual/cocoa/qt_on_cocoa/qt_on_cocoa.pro
Normal file
@ -0,0 +1,10 @@
|
||||
TEMPLATE = app
|
||||
|
||||
OBJECTIVE_SOURCES += main.mm
|
||||
HEADERS += rasterwindow.h
|
||||
SOURCES += rasterwindow.cpp
|
||||
LIBS += -framework AppKit
|
||||
|
||||
QT += gui widgets quick
|
||||
|
||||
QT += quick
|
152
tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "rasterwindow.h"
|
||||
|
||||
//#include <private/qguiapplication_p.h>
|
||||
|
||||
#include <QBackingStore>
|
||||
#include <QPainter>
|
||||
#include <QtWidgets>
|
||||
|
||||
static int colorIndexId = 0;
|
||||
|
||||
QColor colorTable[] =
|
||||
{
|
||||
QColor("#f09f8f"),
|
||||
QColor("#a2bff2"),
|
||||
QColor("#c0ef8f")
|
||||
};
|
||||
|
||||
RasterWindow::RasterWindow(QRasterWindow *parent)
|
||||
: QRasterWindow(parent)
|
||||
, m_backgroundColorIndex(colorIndexId++)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
void RasterWindow::initialize()
|
||||
{
|
||||
create();
|
||||
m_backingStore = new QBackingStore(this);
|
||||
|
||||
m_image = QImage(geometry().size(), QImage::Format_RGB32);
|
||||
m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba());
|
||||
|
||||
m_lastPos = QPoint(-1, -1);
|
||||
}
|
||||
|
||||
void RasterWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_lastPos = event->pos();
|
||||
unsetCursor();
|
||||
}
|
||||
|
||||
void RasterWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_lastPos != QPoint(-1, -1)) {
|
||||
QPainter p(&m_image);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.drawLine(m_lastPos, event->pos());
|
||||
m_lastPos = event->pos();
|
||||
}
|
||||
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void RasterWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_lastPos != QPoint(-1, -1)) {
|
||||
QPainter p(&m_image);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.drawLine(m_lastPos, event->pos());
|
||||
m_lastPos = QPoint(-1, -1);
|
||||
}
|
||||
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void RasterWindow::exposeEvent(QExposeEvent *)
|
||||
{
|
||||
render();
|
||||
}
|
||||
|
||||
void RasterWindow::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
QImage old = m_image;
|
||||
|
||||
//qDebug() << "RasterWindow::resizeEvent" << width << height;
|
||||
|
||||
int width = qMax(geometry().width(), old.width());
|
||||
int height = qMax(geometry().height(), old.height());
|
||||
|
||||
if (width > old.width() || height > old.height()) {
|
||||
m_image = QImage(width, height, QImage::Format_RGB32);
|
||||
m_image.fill(colorTable[(m_backgroundColorIndex) % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba());
|
||||
|
||||
QPainter p(&m_image);
|
||||
p.drawImage(0, 0, old);
|
||||
}
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
void RasterWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Backspace:
|
||||
m_text.chop(1);
|
||||
break;
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
m_text.append('\n');
|
||||
break;
|
||||
default:
|
||||
m_text.append(event->text());
|
||||
break;
|
||||
}
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void RasterWindow::scheduleRender()
|
||||
{
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
bool RasterWindow::event(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::UpdateRequest)
|
||||
render();
|
||||
|
||||
return QWindow::event(e);
|
||||
}
|
||||
|
||||
void RasterWindow::render()
|
||||
{
|
||||
if (!isExposed()) {
|
||||
qDebug() << "Skipping render, not exposed";
|
||||
return;
|
||||
}
|
||||
|
||||
QRect rect(QPoint(), geometry().size());
|
||||
|
||||
m_backingStore->resize(rect.size());
|
||||
|
||||
m_backingStore->beginPaint(rect);
|
||||
|
||||
QPaintDevice *device = m_backingStore->paintDevice();
|
||||
|
||||
QPainter p(device);
|
||||
p.drawImage(0, 0, m_image);
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(32);
|
||||
|
||||
p.setFont(font);
|
||||
p.drawText(rect, 0, m_text);
|
||||
|
||||
m_backingStore->endPaint();
|
||||
m_backingStore->flush(rect);
|
||||
}
|
||||
|
||||
|
34
tests/manual/cocoa/qt_on_cocoa/rasterwindow.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QRasterWindow>
|
||||
#include <QImage>
|
||||
|
||||
class RasterWindow : public QRasterWindow
|
||||
{
|
||||
public:
|
||||
RasterWindow(QRasterWindow *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
|
||||
void keyPressEvent(QKeyEvent *);
|
||||
|
||||
void exposeEvent(QExposeEvent *);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
bool event(QEvent *);
|
||||
|
||||
private:
|
||||
void render();
|
||||
void scheduleRender();
|
||||
void initialize();
|
||||
|
||||
QString m_text;
|
||||
QImage m_image;
|
||||
QPoint m_lastPos;
|
||||
int m_backgroundColorIndex;
|
||||
QBackingStore *m_backingStore;
|
||||
};
|
1432
tests/manual/cocoa/textinput/Debug.keylayout
Normal file
14
tests/manual/cocoa/textinput/README
Normal file
@ -0,0 +1,14 @@
|
||||
# Debug keyboard layout
|
||||
|
||||
The keyboard layout in this directory can be enabled by
|
||||
copying it to "~/Library/Keyboard Layouts/" and adding it
|
||||
it as an input source in the macOS keyboard preferences.
|
||||
|
||||
The layout was created in Ukulele and tries to cover many
|
||||
corner cases of keyboard input related to e.g. modifier
|
||||
and dead key states.
|
||||
|
||||
# Useful tools
|
||||
|
||||
- https://software.sil.org/ukelele/
|
||||
- https://manytricks.com/keycodes/
|
18
tests/manual/cocoa/wheelevent/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## wheelevent Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(wheelevent
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
window.cpp window.h
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Widgets
|
||||
)
|
21
tests/manual/cocoa/wheelevent/main.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
Window window;
|
||||
window.show();
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
||||
|
6
tests/manual/cocoa/wheelevent/wheelevent.pro
Normal file
@ -0,0 +1,6 @@
|
||||
TEMPLATE = app
|
||||
|
||||
HEADERS += window.h
|
||||
SOURCES += window.cpp main.cpp
|
||||
|
||||
QT += core core-private gui gui-private widgets
|
217
tests/manual/cocoa/wheelevent/window.cpp
Normal file
@ -0,0 +1,217 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "window.h"
|
||||
|
||||
#include <private/qguiapplication_p.h>
|
||||
|
||||
#include <QBackingStore>
|
||||
#include <QPainter>
|
||||
#include <QtWidgets>
|
||||
|
||||
static int colorIndexId = 0;
|
||||
|
||||
QColor colorTable[] =
|
||||
{
|
||||
QColor("#f09f8f"),
|
||||
QColor("#a2bff2"),
|
||||
QColor("#c0ef8f")
|
||||
};
|
||||
|
||||
Window::Window(QScreen *screen)
|
||||
: QWindow(screen)
|
||||
, m_backgroundColorIndex(colorIndexId++)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
Window::Window(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_backgroundColorIndex(colorIndexId++)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
void Window::initialize()
|
||||
{
|
||||
if (parent())
|
||||
setGeometry(QRect(160, 120, 320, 240));
|
||||
else {
|
||||
setGeometry(QRect(10, 10, 640, 480));
|
||||
|
||||
setSizeIncrement(QSize(10, 10));
|
||||
setBaseSize(QSize(640, 480));
|
||||
setMinimumSize(QSize(240, 160));
|
||||
}
|
||||
|
||||
create();
|
||||
m_backingStore = new QBackingStore(this);
|
||||
|
||||
m_image = QImage(geometry().size(), QImage::Format_RGB32);
|
||||
m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba());
|
||||
|
||||
m_lastPos = QPoint(-1, -1);
|
||||
m_renderTimer = 0;
|
||||
}
|
||||
|
||||
void Window::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_lastPos = event->pos();
|
||||
}
|
||||
|
||||
void Window::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_lastPos != QPoint(-1, -1)) {
|
||||
QPainter p(&m_image);
|
||||
|
||||
QPen pen;
|
||||
pen.setCosmetic(true);
|
||||
pen.setWidth(1);
|
||||
p.setPen(pen);
|
||||
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.drawLine(m_lastPos, event->pos());
|
||||
m_lastPos = event->pos();
|
||||
}
|
||||
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void Window::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
qDebug() << "wheelEvent delta" << event->delta() << "orientation" << event->orientation();
|
||||
qDebug() << "wheelEvent pixelDelta" << event->pixelDelta();
|
||||
qDebug() << "wheelEvent angleDelta" << event->angleDelta();
|
||||
|
||||
const bool useQt4API = false;
|
||||
|
||||
if (useQt4API) {
|
||||
if (event->orientation() == Qt::Horizontal)
|
||||
scrollOffset.setX(scrollOffset.x() + event->delta());
|
||||
else
|
||||
scrollOffset.setY(scrollOffset.y() + event->delta());
|
||||
scheduleRender();
|
||||
} else {
|
||||
if (!event->pixelDelta().isNull()) {
|
||||
scrollOffset += event->pixelDelta();
|
||||
scheduleRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (m_lastPos != QPoint(-1, -1)) {
|
||||
QPainter p(&m_image);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
p.drawLine(m_lastPos, event->pos());
|
||||
m_lastPos = QPoint(-1, -1);
|
||||
}
|
||||
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void Window::exposeEvent(QExposeEvent *)
|
||||
{
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void Window::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
QImage old = m_image;
|
||||
|
||||
qDebug() << "Window::resizeEvent" << geometry();
|
||||
|
||||
int width = qMax(geometry().width() * devicePixelRatio(), qreal(old.width()));
|
||||
int height = qMax(geometry().height() * devicePixelRatio(), qreal(old.height()));
|
||||
|
||||
qDebug() << "Window::resizeEvent" << width << height;
|
||||
|
||||
if (width > old.width() || height > old.height()) {
|
||||
m_image = QImage(width, height, QImage::Format_RGB32);
|
||||
m_image.setDevicePixelRatio(devicePixelRatio());
|
||||
m_image.fill(colorTable[(m_backgroundColorIndex) % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba());
|
||||
|
||||
QPainter p(&m_image);
|
||||
p.drawImage(0, 0, old);
|
||||
}
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
void Window::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Backspace:
|
||||
m_text.chop(1);
|
||||
break;
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
m_text.append('\n');
|
||||
break;
|
||||
default:
|
||||
m_text.append(event->text());
|
||||
break;
|
||||
}
|
||||
scheduleRender();
|
||||
}
|
||||
|
||||
void Window::scheduleRender()
|
||||
{
|
||||
if (!m_renderTimer)
|
||||
m_renderTimer = startTimer(1);
|
||||
}
|
||||
|
||||
void Window::timerEvent(QTimerEvent *)
|
||||
{
|
||||
render();
|
||||
killTimer(m_renderTimer);
|
||||
m_renderTimer = 0;
|
||||
}
|
||||
|
||||
void Window::render()
|
||||
{
|
||||
QRect rect(QPoint(), geometry().size());
|
||||
|
||||
m_backingStore->resize(rect.size());
|
||||
|
||||
m_backingStore->beginPaint(rect);
|
||||
|
||||
QPaintDevice *device = m_backingStore->paintDevice();
|
||||
|
||||
QPainter p(device);
|
||||
p.drawImage(0, 0, m_image);
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(32);
|
||||
|
||||
p.setFont(font);
|
||||
p.drawText(rect, 0, m_text);
|
||||
|
||||
// draw grid:
|
||||
int gridSpace = 80;
|
||||
|
||||
QPen pen;
|
||||
pen.setCosmetic(true);
|
||||
pen.setWidth(1);
|
||||
p.setPen(pen);
|
||||
|
||||
|
||||
for (int y = 0; y < geometry().height() + gridSpace; y+= gridSpace) {
|
||||
int offset = scrollOffset.y() % gridSpace;
|
||||
//int color = ((y + offset) %255);// + scrollOffset.y()) % 255);
|
||||
p.drawLine(0, y + offset, geometry().width(), y + offset);
|
||||
//p.setBrush(QColor(color,0, 0));
|
||||
//p.fillRect(0, y + offset, geometry().width(), gridSpace,QColor(color,0, 0));
|
||||
}
|
||||
|
||||
|
||||
for (int x = 0; x < geometry().width() + gridSpace; x+= gridSpace) {
|
||||
p.drawLine(x + scrollOffset.x() % gridSpace, 0, x + scrollOffset.x() % gridSpace, geometry().height());
|
||||
}
|
||||
|
||||
m_backingStore->endPaint();
|
||||
m_backingStore->flush(rect);
|
||||
}
|
||||
|
||||
|
38
tests/manual/cocoa/wheelevent/window.h
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QWindow>
|
||||
#include <QImage>
|
||||
|
||||
class Window : public QWindow
|
||||
{
|
||||
public:
|
||||
Window(QWindow *parent = nullptr);
|
||||
Window(QScreen *screen);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
|
||||
void keyPressEvent(QKeyEvent *);
|
||||
|
||||
void exposeEvent(QExposeEvent *);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
void timerEvent(QTimerEvent *);
|
||||
|
||||
private:
|
||||
void render();
|
||||
void scheduleRender();
|
||||
void initialize();
|
||||
|
||||
QString m_text;
|
||||
QImage m_image;
|
||||
QPoint m_lastPos;
|
||||
int m_backgroundColorIndex;
|
||||
QBackingStore *m_backingStore;
|
||||
int m_renderTimer;
|
||||
QPoint scrollOffset;
|
||||
};
|