mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-05 08:45:25 +08:00
qt 6.5.1 original
This commit is contained in:
37
examples/widgets/touch/knobs/CMakeLists.txt
Normal file
37
examples/widgets/touch/knobs/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(knobs LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/touch/knobs")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(knobs
|
||||
knob.cpp knob.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(knobs PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(knobs PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS knobs
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
BIN
examples/widgets/touch/knobs/doc/images/touch-knobs-example.png
Normal file
BIN
examples/widgets/touch/knobs/doc/images/touch-knobs-example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
14
examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc
Normal file
14
examples/widgets/touch/knobs/doc/src/touch-knobs.qdoc
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
||||
|
||||
/*!
|
||||
\example touch/knobs
|
||||
\title Touch Knobs Example
|
||||
\ingroup touchinputexamples
|
||||
\brief Shows how to create custom controls that accept touch input.
|
||||
|
||||
The Touch Knobs example shows how to create custom controls that
|
||||
accept touch input.
|
||||
|
||||
\image touch-knobs-example.png
|
||||
*/
|
51
examples/widgets/touch/knobs/knob.cpp
Normal file
51
examples/widgets/touch/knobs/knob.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "knob.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QTouchEvent>
|
||||
|
||||
Knob::Knob()
|
||||
: QGraphicsEllipseItem(-50, -50, 100, 100)
|
||||
{
|
||||
setAcceptTouchEvents(true);
|
||||
setBrush(Qt::lightGray);
|
||||
|
||||
QGraphicsEllipseItem *leftItem = new QGraphicsEllipseItem(0, 0, 20, 20, this);
|
||||
leftItem->setPos(-40, -10);
|
||||
leftItem->setBrush(Qt::darkGreen);
|
||||
|
||||
QGraphicsEllipseItem *rightItem = new QGraphicsEllipseItem(0, 0, 20, 20, this);
|
||||
rightItem->setPos(20, -10);
|
||||
rightItem->setBrush(Qt::darkRed);
|
||||
}
|
||||
|
||||
bool Knob::sceneEvent(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::TouchBegin:
|
||||
case QEvent::TouchUpdate:
|
||||
case QEvent::TouchEnd:
|
||||
{
|
||||
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
|
||||
|
||||
if (touchEvent->points().count() == 2) {
|
||||
const QEventPoint &touchPoint1 = touchEvent->points().first();
|
||||
const QEventPoint &touchPoint2 = touchEvent->points().last();
|
||||
|
||||
QLineF line1(touchPoint1.sceneLastPosition(), touchPoint2.sceneLastPosition());
|
||||
QLineF line2(touchPoint1.scenePosition(), touchPoint2.scenePosition());
|
||||
|
||||
setTransform(QTransform().rotate(line2.angleTo(line1)), true);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return QGraphicsItem::sceneEvent(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
17
examples/widgets/touch/knobs/knob.h
Normal file
17
examples/widgets/touch/knobs/knob.h
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef KNOB_H
|
||||
#define KNOB_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class Knob : public QGraphicsEllipseItem
|
||||
{
|
||||
public:
|
||||
Knob();
|
||||
|
||||
bool sceneEvent(QEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // KNOB_H
|
8
examples/widgets/touch/knobs/knobs.pro
Normal file
8
examples/widgets/touch/knobs/knobs.pro
Normal file
@ -0,0 +1,8 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = knob.h
|
||||
SOURCES = main.cpp knob.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/touch/knobs
|
||||
INSTALLS += target
|
27
examples/widgets/touch/knobs/main.cpp
Normal file
27
examples/widgets/touch/knobs/main.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "knob.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QGraphicsScene scene;
|
||||
QGraphicsView view(&scene);
|
||||
|
||||
Knob *knob1 = new Knob;
|
||||
knob1->setPos(-110, 0);
|
||||
Knob *knob2 = new Knob;
|
||||
|
||||
scene.addItem(knob1);
|
||||
scene.addItem(knob2);
|
||||
|
||||
view.showMaximized();
|
||||
view.fitInView(scene.sceneRect().adjusted(-20, -20, 20, 20), Qt::KeepAspectRatio);
|
||||
|
||||
return app.exec();
|
||||
}
|
Reference in New Issue
Block a user