Skip to content

Commit

Permalink
add tap gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
Szybet committed Oct 14, 2023
1 parent 6bdbfdf commit 2a0dc61
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cardView/buttons/fourOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void fourOptions::on_showButton_clicked()
emit show();
}

#define BUTTON_DELAY 650
#define BUTTON_DELAY 750

void fourOptions::showButtons() {
QTimer::singleShot(BUTTON_DELAY, this, [this]() {
Expand Down
65 changes: 65 additions & 0 deletions cardView/buttons/fourOptionsNFlashy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "fourOptionsNFlashy.h"
#include "global.h"
#include "ui_fourOptionsNFlashy.h"

#include <QTimer>
#include <QDebug>

fourOptionsNFlashy::fourOptionsNFlashy(QWidget *parent) :
QWidget(parent),
ui(new Ui::fourOptionsNFlashy)
{
ui->setupUi(this);
if(ereader) {
ui->againButton->setStyleSheet(ereaderVars::buttonNoFlashStylesheet);
ui->hardButton->setStyleSheet(ereaderVars::buttonNoFlashStylesheet);
ui->goodButton->setStyleSheet(ereaderVars::buttonNoFlashStylesheet);
ui->easyButton->setStyleSheet(ereaderVars::buttonNoFlashStylesheet);
this->setFixedHeight(125);
}
}

fourOptionsNFlashy::~fourOptionsNFlashy()
{
delete ui;
}

void fourOptionsNFlashy::on_againButton_clicked()
{
if(enabledButtons == true) {
emit again();
enabledButtons = false;
}
}

void fourOptionsNFlashy::on_hardButton_clicked()
{
if(enabledButtons == true) {
emit hard();
enabledButtons = false;
}
}

void fourOptionsNFlashy::on_goodButton_clicked()
{
if(enabledButtons == true) {
emit good();
enabledButtons = false;
}
}

void fourOptionsNFlashy::on_easyButton_clicked()
{
if(enabledButtons == true) {
emit easy();
enabledButtons = false;
}
}

void fourOptionsNFlashy::enableButtons() {
qDebug() << "Enabled buttons for fourOptionsNFlashy";
// Delay for skipping any button that would accour of taps inside this widget
QTimer::singleShot(100, this, [this]() {
enabledButtons = true;
});
}
41 changes: 41 additions & 0 deletions cardView/buttons/fourOptionsNFlashy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef fourOptionsNFlashy_H
#define fourOptionsNFlashy_H

#include <QWidget>

namespace Ui {
class fourOptionsNFlashy;
}

class fourOptionsNFlashy : public QWidget
{
Q_OBJECT

public:
explicit fourOptionsNFlashy(QWidget *parent = nullptr);
~fourOptionsNFlashy();
bool enabledButtons = false;

public slots:
void enableButtons();

signals:
void again();
void hard();
void good();
void easy();

private slots:
void on_hardButton_clicked();

void on_againButton_clicked();

void on_goodButton_clicked();

void on_easyButton_clicked();

private:
Ui::fourOptionsNFlashy *ui;
};

#endif // fourOptionsNFlashy_H
94 changes: 94 additions & 0 deletions cardView/buttons/fourOptionsNFlashy.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>fourOptionsNFlashy</class>
<widget class="QWidget" name="fourOptionsNFlashy">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>42</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="againButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Again</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="hardButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Hard</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="goodButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Good</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="easyButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Easy</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
32 changes: 32 additions & 0 deletions cardView/deckPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ void DeckPlay::start(sessionStr newSession)
elapsedTimer = new QElapsedTimer;
elapsedTimer->start();

// Load this before loading modes
QSettings settingsGlobal(directories::globalSettings.fileName(), QSettings::IniFormat);
enabledTapGesture = settingsGlobal.value("tapGesture").toBool();
settingsGlobal.deleteLater();

saveSessionData();

if(currectSession.core.mode == CompletlyRandomised) {
Expand Down Expand Up @@ -236,6 +241,9 @@ void DeckPlay::setText(QTextBrowser* area, QString text) {
if(area == ui->textBackCard) {
previousBackText = text;
} else if(area == ui->textFrontCard) {
QTimer::singleShot(500, this, [this]() {
enabledTapGestureTmp = true;
});
previousFrontText = text;
}

Expand Down Expand Up @@ -338,6 +346,7 @@ void DeckPlay::exitIt() {
delete gestureTimer;
this->ungrabGesture(Qt::PinchGesture);
this->ungrabGesture(Qt::TapAndHoldGesture);
this->ungrabGesture(Qt::TapGesture);

qDebug() << "Count of connections:" << realSqlDatabases.count();
// Is there a cleaner way?
Expand Down Expand Up @@ -456,6 +465,8 @@ void DeckPlay::zoomUpdate() {
void DeckPlay::manageGestures() {
grabGesture(Qt::TapAndHoldGesture);
grabGesture(Qt::PinchGesture);
grabGesture(Qt::TapGesture);
QTapAndHoldGesture::setTimeout(1500);
gestureTimer = new QElapsedTimer();
gestureTimer->start();
}
Expand Down Expand Up @@ -496,6 +507,27 @@ bool DeckPlay::event(QEvent *event)
gestureTimer->restart();
refreshCard(true);
}
} else if(QGesture* gesture = gEvent->gesture(Qt::TapGesture)) {
Q_UNUSED(gesture);
if(enabledTapGesture == true) {
qDebug() << "Tap gesture detected";
int elapsed = gestureTimer->elapsed();
if(gestureTimer->isValid() == true && elapsed > 850) {
// doesnt work with qpoint, idk it gives relative point to the widget?...
//if(QTapGesture* tap = static_cast<QTapGesture *>(gesture)) {
//QPoint point = tap->position().toPoint();
//qDebug() << "Tap point:" << point << "Card geometry:" << ui->gridManageCard->geometry();
//if(ui->gridManageCard->geometry().contains(point, false) == false) {
if(enabledTapGestureTmp == true) {
enabledTapGestureTmp = false;
qDebug() << "Tap gesture actually registered";
gestureTimer->restart();
emit tapGesture();
}
//}
//}
}
}
}
return true; // Not sure
}
Expand Down
3 changes: 3 additions & 0 deletions cardView/deckPlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class DeckPlay : public QMainWindow
void zoomIn();
void zoomOut();
void zoomUpdate();
bool enabledTapGesture = false;
bool enabledTapGestureTmp = false; // to ignore tap gestures when they are not needed

protected:
bool event(QEvent *event) override;
Expand All @@ -62,6 +64,7 @@ public slots:
signals:
void saveData();
void changeStatusBarTextSignal(QString text);
void tapGesture();

private slots:
void on_horizontalScrollBar_valueChanged(int value);
Expand Down
2 changes: 1 addition & 1 deletion cardView/modes/boxes/askforboxesoptions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>307</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
37 changes: 25 additions & 12 deletions cardView/modes/boxes/boxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ui_deckPlay.h"
#include "cardView/functions/helperFunctions.h"
#include "cardView/modes/boxes/askforboxesoptions.h"
#include "cardView/buttons/fourOptionsNFlashy.h"

#include <QObject>
#include <QDebug>
Expand All @@ -21,15 +22,24 @@ void boxes::setup(DeckPlay* parentArg, Ui::DeckPlay* parentUiArg) {
frontText = parentUi->textFrontCard;
backText = parentUi->textBackCard;

buttons = new fourOptions(parent);

connect(buttons, &fourOptions::again, this, &boxes::againClicked);
connect(buttons, &fourOptions::hard, this, &boxes::hardClicked);
connect(buttons, &fourOptions::good, this, &boxes::goodClicked);
connect(buttons, &fourOptions::easy, this, &boxes::easyClicked);
connect(buttons, &fourOptions::show, this, &boxes::showBack);

parentUi->gridManageCard->addWidget(buttons);
if(parent->enabledTapGesture == false) {
fourOptions* buttons = new fourOptions(parent);
connect(buttons, &fourOptions::again, this, &boxes::againClicked);
connect(buttons, &fourOptions::hard, this, &boxes::hardClicked);
connect(buttons, &fourOptions::good, this, &boxes::goodClicked);
connect(buttons, &fourOptions::easy, this, &boxes::easyClicked);
connect(buttons, &fourOptions::show, this, &boxes::showBack);
parentUi->gridManageCard->addWidget(buttons);
} else {
fourOptionsNFlashy* buttons = new fourOptionsNFlashy(parent);
connect(buttons, &fourOptionsNFlashy::again, this, &boxes::againClicked);
connect(buttons, &fourOptionsNFlashy::hard, this, &boxes::hardClicked);
connect(buttons, &fourOptionsNFlashy::good, this, &boxes::goodClicked);
connect(buttons, &fourOptionsNFlashy::easy, this, &boxes::easyClicked);
connect(parent, &DeckPlay::tapGesture, this, &boxes::showBack);
connect(parent, &DeckPlay::tapGesture, buttons, &fourOptionsNFlashy::enableButtons); // enable buttons with tap
parentUi->gridManageCard->addWidget(buttons);
}

if(parent->saveSession->value("boxMode/box").isNull() == true && parent->saveSession->value("boxMode/box").isValid() == false) {
qDebug() << "There is no saved config for box mode, asking things";
Expand Down Expand Up @@ -165,9 +175,12 @@ void boxes::easyClicked() {

void boxes::showBack() {
qDebug() << "Clicked show button";
parentUi->lineMiddleText->setVisible(true);
backText->show();
parent->setText(backText, backCard);
// simple checker ;)
if(parentUi->lineMiddleText->isVisible() == false) {
parentUi->lineMiddleText->setVisible(true);
backText->show();
parent->setText(backText, backCard);
}
}

void boxes::moveCard(int moveValue) {
Expand Down
1 change: 0 additions & 1 deletion cardView/modes/boxes/boxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class boxes : public QObject
QString frontCard;
QString backCard;
box theBox;
fourOptions* buttons;
uint currentCardIndex;
void moveCard(int moveValue);
QList<int> boxesCardCount;
Expand Down
8 changes: 8 additions & 0 deletions components/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ void Settings::requestMenuPage() {
QFont font = variant.value<QFont>();
ui->labelFontName->setText(font.family() + ", " + QString::number(font.pointSize()));
currentFont = font;

bool tapGesture = settingsGlobal->value("tapGesture").toBool();
ui->tapGestoreCheckBox->setChecked(tapGesture);
}

void Settings::requestSyncPage() {
Expand Down Expand Up @@ -440,3 +443,8 @@ void Settings::on_gesturesButton_clicked()
qInfo() << "- Pinch in and out to zoom in and out.<br>- Press and hold for screen refresh.";
}

void Settings::on_tapGestoreCheckBox_stateChanged(int arg1)
{
qDebug() << "tapGestoreCheckBox:" << arg1;
settingsGlobal->setValue("tapGesture", arg1);
}
2 changes: 2 additions & 0 deletions components/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private slots:

void on_gesturesButton_clicked();

void on_tapGestoreCheckBox_stateChanged(int arg1);

private:
Ui::Settings *ui;
enum Direction{
Expand Down
Loading

0 comments on commit 2a0dc61

Please sign in to comment.