Skip to content

Commit

Permalink
add graphics layer option for better eink rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Szybet committed Oct 16, 2023
1 parent 2a0dc61 commit 13ec8f6
Show file tree
Hide file tree
Showing 19 changed files with 594 additions and 302 deletions.
3 changes: 3 additions & 0 deletions all/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ bool warningsEnabled = true;
bool pc = false;
bool ereader = false;

bool grender = true;
qGraphicsViewEvents* graphic = NULL;

QString deckAddedFileName = "creationTime";

namespace directories {
Expand Down
5 changes: 5 additions & 0 deletions all/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
#include "devicedescriptor.h"
#endif

#include "components/other/reImplementations/qGraphicsViewEvents.h"

extern bool debugEnabled;
extern bool warningsEnabled;

// Those variables check if it's running on this device
extern bool pc;
extern bool ereader;

extern bool grender; // graphics render
extern qGraphicsViewEvents* graphic;

namespace directories {
extern QDir config;
extern QDir deckStorage;
Expand Down
57 changes: 39 additions & 18 deletions cardView/deckPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#endif

DeckPlay::DeckPlay(QWidget *parent) :
QMainWindow(parent),
QWidget(parent),
ui(new Ui::DeckPlay)
{
ui->setupUi(this);
Expand Down Expand Up @@ -258,6 +258,9 @@ void DeckPlay::setText(QTextBrowser* area, QString text) {
text = adjustImgSize(finalWidth, text);
}

// Making this avoids showing for half a second the first word of the qtextedit
area->setUpdatesEnabled(false);

area->setHtml(text);

// Very important
Expand Down Expand Up @@ -287,17 +290,17 @@ void DeckPlay::setText(QTextBrowser* area, QString text) {
WaveForm currentWaveFormConverted = static_cast<WaveForm>(currentWaveForm);
if(currentWaveFormConverted == WaveForm_A2) {
qDebug() << "Check if ghost fix is needed";
if(text.count() > 50) {
if(text.count() > 50 == true || text.contains("<img") == true || area->horizontalScrollBar()->isVisible() == true || area->verticalScrollBar()->isVisible() == true) {
QTimer::singleShot(500, this, [this, area, text]() {
if(area->horizontalScrollBar()->isVisible() || area->verticalScrollBar()->isVisible()) {
qDebug() << "Requesting special refresh for ghosting";
QApplication::processEvents();
refreshCard(true);
}
qDebug() << "Requesting special refresh for ghosting";
QApplication::processEvents();
refreshCard(true);
});
}
}
#endif

area->setUpdatesEnabled(true);
}

void DeckPlay::saveSessionData() {
Expand Down Expand Up @@ -410,14 +413,26 @@ void DeckPlay::refreshCard(bool force) {
if(refreshCardRate > 0 || force == true) {
if(refreshCardCount >= refreshCardRate || force == true) {
refreshCardCount = 1;
refreshRect(ui->gridCard->contentsRect());
refreshRect(ui->gridManageCard->contentsRect());

QApplication::processEvents();
this->repaint();
this->repaint();
this->repaint();
QApplication::processEvents();
if(grender == false) {
refreshRect(ui->gridCard->contentsRect());
refreshRect(ui->gridManageCard->contentsRect());

QApplication::processEvents();
this->repaint();
this->repaint();
this->repaint();
QApplication::processEvents();
} else {
#ifdef EREADER
KoboPlatformFunctions::setFullScreenRefreshMode(WaveForm_GC16);
#endif
qDebug() << "Using graphic repaint";
QApplication::processEvents();
graphic->repaint();
graphic->repaint();
graphic->repaint();
QApplication::processEvents();
}

currentWaveForm = loadWaveFormSetting();
} else {
Expand Down Expand Up @@ -463,18 +478,19 @@ void DeckPlay::zoomUpdate() {

// https://doc.qt.io/qt-6/qtwidgets-gestures-imagegestures-example.html
void DeckPlay::manageGestures() {
this->setAttribute(Qt::WA_AcceptTouchEvents);
grabGesture(Qt::TapAndHoldGesture);
grabGesture(Qt::PinchGesture);
grabGesture(Qt::TapGesture);
QTapAndHoldGesture::setTimeout(1500);
QTapAndHoldGesture::setTimeout(2250);
gestureTimer = new QElapsedTimer();
gestureTimer->start();
}

bool DeckPlay::event(QEvent *event)
{
//qDebug() << "Captured event:" << event;
if (event->type() == QEvent::Gesture) {
if (event->type() == QEvent::Gesture || event->type() == QEvent::GestureOverride) {
QGestureEvent* gEvent = static_cast<QGestureEvent*>(event);
//qDebug() << "Captured gesture:" << gEvent;
if (QGesture* gesture = gEvent->gesture(Qt::PinchGesture)) {
Expand Down Expand Up @@ -529,7 +545,12 @@ bool DeckPlay::event(QEvent *event)
}
}
}
return true; // Not sure
return true; // needed to track further gesture
}
return QWidget::event(event);
}

void DeckPlay::eventSlot(QEvent* eventItem) {
//qDebug() << "Received event for graphics render";
this->event(eventItem);
}
6 changes: 3 additions & 3 deletions cardView/deckPlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "mainMenu/sessions/sessionStruct.h"

#include <QTextBrowser>
#include <QMainWindow>
#include <QDir>
#include <QSqlDatabase>
#include <QSettings>
Expand All @@ -23,7 +22,7 @@ namespace Ui {
class DeckPlay;
}

class DeckPlay : public QMainWindow
class DeckPlay : public QWidget
{
Q_OBJECT

Expand Down Expand Up @@ -54,12 +53,13 @@ class DeckPlay : public QMainWindow
bool enabledTapGestureTmp = false; // to ignore tap gestures when they are not needed

protected:
bool event(QEvent *event) override;
bool event(QEvent* event) override;

public slots:
void showStats();
// When options dialog is closed
void reloadSettings();
void eventSlot(QEvent* eventItem);

signals:
void saveData();
Expand Down

0 comments on commit 13ec8f6

Please sign in to comment.