From 4d7db7c4798085b6095bdbab62337f7d01974e2c Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 5 Apr 2022 10:41:36 +0200 Subject: [PATCH 1/2] 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 ) From 2a6d27d78d107791e3f5347c753cc64fcbc80fed Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 5 Apr 2022 11:38:23 +0200 Subject: [PATCH 2/2] wip --- examples/gallery/main.cpp | 22 ++++++---------- skins/material/QskMaterialSkin.cpp | 42 ++++++++++++++++++++++++++++++ skins/squiek/QskSquiekSkin.cpp | 15 ++++++----- src/controls/QskMenu.cpp | 5 ++++ 4 files changed, 63 insertions(+), 21 deletions(-) diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 3263ab5e..5a466641 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -57,22 +57,16 @@ namespace private: void openMenu() { - auto pos = geometry().bottomLeft(); + auto menu = new QskMenu( window()->contentItem() ); - 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.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; + menu->setOrigin( geometry().bottomLeft() ); + menu->open(); } }; diff --git a/skins/material/QskMaterialSkin.cpp b/skins/material/QskMaterialSkin.cpp index 979dee8f..03b170ba 100644 --- a/skins/material/QskMaterialSkin.cpp +++ b/skins/material/QskMaterialSkin.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -120,6 +121,7 @@ namespace void setupInputPanel(); void setupVirtualKeyboard(); void setupListView(); + void setupMenu(); void setupPageIndicator(); void setupPopup(); void setupProgressBar(); @@ -151,6 +153,7 @@ void Editor::setup() setupInputPanel(); setupVirtualKeyboard(); setupListView(); + setupMenu(); setupPageIndicator(); setupPopup(); setupProgressBar(); @@ -223,6 +226,45 @@ void Editor::setupPopup() setGradient( Q::Overlay, gradient ); } +void Editor::setupMenu() +{ + using A = QskAspect; + using Q = QskMenu; + + setBoxShape( Q::Panel, qskDpiScaled( 4 ) ); + setBoxBorderMetrics( Q::Panel, qskDpiScaled( 1 ) ); + setBoxBorderColors( Q::Panel, m_pal.darker125 ); + + setGradient( Q::Panel, m_pal.baseColor ); + + const bool isCascading = qskMaybeDesktopPlatform(); + setFlagHint( Q::Panel | A::Style, isCascading ); + +#if 0 + setPadding( Q::Separator, QMarginsF( 10, 0, 10, 0 ) ); +#endif + setMetric( Q::Separator | A::Size, qskDpiScaled( 1 ) ); + setBoxShape( Q::Separator, 0 ); + setBoxBorderMetrics( Q::Separator, 0 ); + setGradient( Q::Separator, m_pal.darker125 ); + + setPadding( Q::Cell, QskMargins( 2, 10, 2, 10 ) ); + setSpacing( Q::Cell, 5 ); + setGradient( Q::Cell, Qt::transparent ); + + setGradient( Q::Cursor, m_pal.accentColor ); + + setColor( Q::Text, m_pal.textColor ); + setColor( Q::Text | Q::Selected, m_pal.contrastColor ); + setFontRole( Q::Text, QskSkin::SmallFont ); + + setPosition( Q::Panel, 0 ); + setPosition( Q::Panel | QskPopup::Closed, 1 ); + + setAnimation( Q::Panel | A::Metric, 150 ); + setAnimation( Q::Cursor | A::Position | A::Metric, 75, QEasingCurve::OutCubic ); +} + void Editor::setupTextLabel() { using Q = QskTextLabel; diff --git a/skins/squiek/QskSquiekSkin.cpp b/skins/squiek/QskSquiekSkin.cpp index 3d250d91..fd45d94a 100644 --- a/skins/squiek/QskSquiekSkin.cpp +++ b/skins/squiek/QskSquiekSkin.cpp @@ -331,11 +331,11 @@ void Editor::setupMenu() using A = QskAspect; using Q = QskMenu; - const QColor c1( 78, 158, 38 ); - const QColor c2( 15, 103, 43 ); + setBoxShape( Q::Panel, qskDpiScaled( 4 ) ); + setBoxBorderMetrics( Q::Panel, qskDpiScaled( 1 ) ); + setBoxBorderColors( Q::Panel, m_pal.darker125 ); - setBoxShape( Q::Panel, 4 ); - setVGradient( Q::Panel, c1, c2 ); + setGradient( Q::Panel, m_pal.lighter110 ); const bool isCascading = qskMaybeDesktopPlatform(); setFlagHint( Q::Panel | A::Style, isCascading ); @@ -343,16 +343,17 @@ void Editor::setupMenu() #if 0 setPadding( Q::Separator, QMarginsF( 10, 0, 10, 0 ) ); #endif - setMetric( Q::Separator | A::Size, 2 ); + setMetric( Q::Separator | A::Size, qskDpiScaled( 2 ) ); setSeparator( Q::Separator | A::Horizontal ); setPadding( Q::Cell, QskMargins( 2, 10, 2, 10 ) ); setSpacing( Q::Cell, 5 ); setGradient( Q::Cell, Qt::transparent ); - setHGradient( Q::Cursor, c2, c2.lighter( 2 ) ); + setGradient( Q::Cursor, m_pal.highlighted ); - setColor( Q::Text, QColor( 255, 255, 255 ) ); + setColor( Q::Text, m_pal.contrastedText ); + setColor( Q::Text | Q::Selected, m_pal.highlightedText ); setFontRole( Q::Text, QskSkin::SmallFont ); setPosition( Q::Panel, 0 ); diff --git a/src/controls/QskMenu.cpp b/src/controls/QskMenu.cpp index a8034736..9c1389f9 100644 --- a/src/controls/QskMenu.cpp +++ b/src/controls/QskMenu.cpp @@ -37,6 +37,11 @@ namespace QString text; QskGraphic graphic; + +#if 0 + // TODO ... + bool isEnabled = true; +#endif }; }