graphic android patches: buttons moved to popup-menu on tap-and-hold gesture

This commit is contained in:
2021-09-17 21:19:37 +03:00
parent 1cb6880c55
commit b6c08b076e
3 changed files with 62 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
project(qad)
set(qad_MAJOR 2)
set(qad_MINOR 5)
set(qad_MINOR 6)
set(qad_REVISION 0)
set(qad_SUFFIX )
set(qad_COMPANY SHS)

View File

@@ -14,7 +14,9 @@
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
# include <QRandomGenerator>
#endif
#ifndef Q_OS_ANDROID
#ifdef Q_OS_ANDROID
# define NO_BUTTONS
#else
# ifndef FORCE_NO_GL
# define HAS_GL
# endif
@@ -25,6 +27,7 @@
# endif
#endif
const char _button_prop_name_[] = "_button_";
const double rad2deg_qpie = 45. / atan(1.);
__GraphicRegistrator__ __graphic_registrator__;
@@ -72,6 +75,32 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
ui->setupUi(this);
ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend));
ui->scrollLegend->hide();
#ifdef NO_BUTTONS
ui->widgetLeft->hide();
ui->widgetRight->hide();
QList<QToolButton*> btnlist = {
ui->graphic_buttonAutofit,
ui->graphic_checkGrid,
ui->graphic_checkGuides,
ui->graphic_buttonFullscreen,
ui->graphic_checkBorderInputs,
ui->graphic_checkLegend,
ui->graphic_checkPause,
ui->graphic_buttonConfigure,
ui->graphic_buttonSave,
ui->graphic_buttonExport,
ui->graphic_buttonClear,
ui->graphic_buttonClose};
buttons_menu = new QMenu(this);
for (auto * b: btnlist) {
auto * a = new QAction(this);
connect(a, SIGNAL(triggered()), b, SLOT(click()));
connect(a, SIGNAL(triggered(bool)), b, SLOT(setChecked(bool)));
a->setCheckable(b->isCheckable());
a->setProperty(_button_prop_name_, (quintptr)b);
buttons_menu->addAction(a);
}
#endif
QActionGroup * agroup = new QActionGroup(this);
agroup->addAction(ui->graphic_actionGuidesFree );
agroup->addAction(ui->graphic_actionGuidesTraceX);
@@ -156,6 +185,9 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
Graphic::~Graphic() {
#ifdef NO_BUTTONS
delete buttons_menu;
#endif
delete conf;
if (buffer != 0) delete buffer;
}
@@ -274,7 +306,7 @@ void Graphic::procGesture(QGesture * g) {
case Qt::TapAndHoldGesture: {
QTapAndHoldGesture * pg = (QTapAndHoldGesture*)g;
if (pg->state() == Qt::GestureStarted)
QMetaObject::invokeMethod(this, "enterFullscreen", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "showMenu", Qt::QueuedConnection);
} break;
default:
break;
@@ -727,6 +759,9 @@ void Graphic::setButtonsPosition(Graphic::Alignment a) {
align = a;
ui->widgetLeft->hide();
ui->widgetRight->hide();
#ifdef NO_BUTTONS
return;
#endif
switch (a) {
case Graphic::Left:
ui->widgetLeft->setLayout(ui->layoutButtons);
@@ -1880,6 +1915,7 @@ void Graphic::enterFullscreen() {
dlg.exec();
dlg.layout()->removeWidget(canvas);
leaveFullscreen();
return;
#else
ui->layoutCanvas->removeWidget(canvas);
canvas->setParent(0);
@@ -1905,6 +1941,26 @@ void Graphic::leaveFullscreen() {
}
void Graphic::showMenu() {
#ifdef NO_BUTTONS
for (auto * a: buttons_menu->actions()) {
QToolButton * b = (QToolButton *)(a->property(_button_prop_name_).toULongLong());
if (!b) {
a->setVisible(false);
continue;
}
a->blockSignals(true);
a->setVisible(!b->isHidden());
a->setText(b->toolTip());
a->setIcon(b->icon());
a->setChecked(b->isChecked());
a->blockSignals(false);
}
buttons_menu->popup(QCursor::pos());
#endif
}
QString Graphic::caption() const {
return ui->labelCaption->text();
}

View File

@@ -31,6 +31,7 @@
#include <QElapsedTimer>
#include <QTranslator>
#include <QGestureEvent>
#include <QMenu>
#include <qmath.h>
#include <float.h>
#include "graphic_conf.h"
@@ -402,6 +403,7 @@ protected:
GraphicConf * conf;
EvalSpinBox line_x_min, line_x_max, line_y_min, line_y_max;
QElapsedTimer tm;
QMenu * buttons_menu = nullptr;
#ifdef Q_OS_ANDROID
QElapsedTimer tm_fscr;
#endif
@@ -448,6 +450,7 @@ protected slots:
void actionGuidesTriggered(QAction * a);
void enterFullscreen();
void leaveFullscreen();
void showMenu();
signals:
void beforeGraphicPaintEvent(QPainter * );