From 4d7db7c4798085b6095bdbab62337f7d01974e2c Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 5 Apr 2022 10:41:36 +0200 Subject: [PATCH] wip --- examples/gallery/main.cpp | 38 +++++++++++++++++++++++++++++++ examples/qvgviewer/MainWindow.cpp | 30 ------------------------ examples/qvgviewer/main.cpp | 8 ------- examples/qvgviewer/qvgviewer.pro | 1 - src/controls/QskMenu.cpp | 5 ++++ 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 7123fe62..3263ab5e 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,39 @@ namespace } }; + class MenuButton : public QskPushButton + { + public: + MenuButton( const QString& text, QQuickItem* parent = nullptr ) + : QskPushButton( text, parent ) + { + setFlat( true ); // until we have the section bit in QskAspect + + connect( this, &QskPushButton::pressed, this, &MenuButton::openMenu ); + } + + private: + void openMenu() + { + auto pos = geometry().bottomLeft(); + + QskMenu menu( window()->contentItem() ); + menu.setPopupFlag( QskPopup::DeleteOnClose, false ); + + menu.addOption( "image://shapes/Rectangle/White", "Print" ); + menu.addOption( "image://shapes/Diamond/Yellow", "Save As" ); + menu.addOption( "image://shapes/Ellipse/Red", "Setup" ); + menu.addSeparator(); + menu.addOption( "image://shapes/Hexagon/PapayaWhip", "Help" ); + + menu.setOrigin( pos ); + + const int result = menu.exec(); + if ( result >= 0 ) + qDebug() << "Selected:" << result; + } + }; + /* Once QskApplicationView and friends are implemented we can replace Header/ApplicationWindow with it. TODO ... @@ -70,6 +104,10 @@ namespace [] { Skinny::changeSkin( 500 ); } ); } + { + new MenuButton( "Menu", this ); + } + addStretch( 10 ); { diff --git a/examples/qvgviewer/MainWindow.cpp b/examples/qvgviewer/MainWindow.cpp index e78a1a79..bc379584 100644 --- a/examples/qvgviewer/MainWindow.cpp +++ b/examples/qvgviewer/MainWindow.cpp @@ -20,11 +20,6 @@ #include #include -#ifdef CONTEXT_MENU - #include - #include -#endif - #include #include @@ -46,10 +41,6 @@ class GraphicLabel : public QskGraphicLabel setBoxShapeHint( Panel, 8 ); setAlignment( Qt::AlignCenter ); setDarknessMode( false ); - -#ifdef CONTEXT_MENU - setAcceptedMouseButtons( Qt::LeftButton ); -#endif } void setDarknessMode( bool on ) @@ -80,27 +71,6 @@ class GraphicLabel : public QskGraphicLabel startTransition( QskGraphicLabel::Graphic | QskAspect::GraphicRole, duration, oldRole, graphicRole() ); } - -#ifdef CONTEXT_MENU - protected: - void mousePressEvent( QMouseEvent* event ) override - { - QskMenu menu( this ); - menu.setPopupFlag( QskPopup::DeleteOnClose, false ); - - menu.addOption( "image://shapes/Rectangle/White", "Print" ); - menu.addOption( "image://shapes/Diamond/Yellow", "Save As" ); - menu.addOption( "image://shapes/Ellipse/Red", "Setup" ); - menu.addSeparator(); - menu.addOption( "image://shapes/Hexagon/PapayaWhip", "Help" ); - - menu.setOrigin( qskMousePosition( event ) ); - - const int result = menu.exec(); - if ( result >= 0 ) - qDebug() << "Selected:" << result; - } -#endif }; MainWindow::MainWindow() diff --git a/examples/qvgviewer/main.cpp b/examples/qvgviewer/main.cpp index 31d62caa..458709e1 100644 --- a/examples/qvgviewer/main.cpp +++ b/examples/qvgviewer/main.cpp @@ -7,10 +7,6 @@ #include -#ifdef CONTEXT_MENU - #include -#endif - #include #include @@ -22,10 +18,6 @@ int main( int argc, char* argv[] ) QskObjectCounter counter( true ); #endif -#ifdef CONTEXT_MENU - Qsk::addGraphicProvider( "shapes", new SkinnyShapeProvider() ); -#endif - QGuiApplication app( argc, argv ); SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts ); diff --git a/examples/qvgviewer/qvgviewer.pro b/examples/qvgviewer/qvgviewer.pro index ece321d1..d2c05ec5 100644 --- a/examples/qvgviewer/qvgviewer.pro +++ b/examples/qvgviewer/qvgviewer.pro @@ -1,5 +1,4 @@ CONFIG += qskexample -DEFINES += CONTEXT_MENU HEADERS += \ MainWindow.h diff --git a/src/controls/QskMenu.cpp b/src/controls/QskMenu.cpp index 0cff4321..a8034736 100644 --- a/src/controls/QskMenu.cpp +++ b/src/controls/QskMenu.cpp @@ -75,6 +75,9 @@ QskMenu::~QskMenu() { } +#if 1 + +// has no effect as we do not offer submenus yet. TODO ... bool QskMenu::isCascading() const { return flagHint( QskMenu::Panel | QskAspect::Style ); @@ -92,6 +95,8 @@ void QskMenu::resetCascading() Q_EMIT cascadingChanged( isCascading() ); } +#endif + void QskMenu::setOrigin( const QPointF& origin ) { if ( origin != m_data->origin )