Skip to content

Commit

Permalink
Current version of Psi+ is 1.5.1707
Browse files Browse the repository at this point in the history
It is based on:
* psi: eb361036
* plugins: 526dd7d
* psimedia: 9fd3307
* resources: 2ef1865
  • Loading branch information
tehnick committed Mar 20, 2024
1 parent 1d905a3 commit 03a3b84
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 217 deletions.
43 changes: 36 additions & 7 deletions 3rdparty/qite/libqite/qite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ under the License.
#include <QTextEdit>
#include <QTextObjectInterface>

// #define DEBUG_QITE

//----------------------------------//
// InteractiveTextElementController //
//----------------------------------//
Expand All @@ -37,7 +39,15 @@ InteractiveTextElementController::InteractiveTextElementController(InteractiveTe
objectType = itc->registerController(this);
}

InteractiveTextElementController::~InteractiveTextElementController() { itc->unregisterController(this); }
InteractiveTextElementController::~InteractiveTextElementController()
{
if (itc) {
itc->unregisterController(this);
}
#ifdef DEBUG_QITE
qDebug("InteractiveTextElementController destroyed");
#endif
}

void InteractiveTextElementController::drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc,
int posInDocument, const QTextFormat &format)
Expand Down Expand Up @@ -78,6 +88,13 @@ InteractiveText::InteractiveText(QTextEdit *textEdit, int baseObjectType) :
connect(textEdit, &QTextEdit::textChanged, this, &InteractiveText::trackVisibility, Qt::QueuedConnection);
}

InteractiveText::~InteractiveText()
{
#ifdef DEBUG_QITE
qDebug("InteractiveText destroyed");
#endif
}

int InteractiveText::registerController(InteractiveTextElementController *elementController)
{
auto objectType = _objectType++;
Expand All @@ -89,7 +106,8 @@ int InteractiveText::registerController(InteractiveTextElementController *elemen

void InteractiveText::unregisterController(InteractiveTextElementController *elementController)
{
textEdit()->document()->documentLayout()->unregisterHandler(elementController->objectType, elementController);
if (_textEdit)
_textEdit->document()->documentLayout()->unregisterHandler(elementController->objectType, elementController);
_controllers.remove(elementController->objectType);
}

Expand Down Expand Up @@ -137,18 +155,28 @@ bool InteractiveText::eventFilter(QObject *obj, QEvent *event)
return false;
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define MoveMoveEvent QEvent::HoverMove
bool ourEvent = (obj == _textEdit
&& (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove
|| event->type() == QEvent::HoverLeave))
|| (obj == _textEdit->viewport() && event->type() == QEvent::MouseButtonPress);
#else
#define MoveMoveEvent QEvent::MouseMove
bool ourEvent = (obj == _textEdit && (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave))
|| (obj == _textEdit->viewport()
&& (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseMove));
#endif

if (!ourEvent) {
return false;
}
// qDebug() << "event obj=" << (obj == _textEdit ? "textedit" : "viewport") << "type=" << event->type();

bool ret = false;
bool leaveHandled = false;
QPoint pos; // relative to visible part.
if (event->type() == QEvent::MouseButtonPress) {
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseMove) {
pos = static_cast<QMouseEvent *>(event)->pos();
} else {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -158,7 +186,7 @@ bool InteractiveText::eventFilter(QObject *obj, QEvent *event)
#endif
}

if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove
if (event->type() == QEvent::HoverEnter || event->type() == MoveMoveEvent
|| event->type() == QEvent::MouseButtonPress) {
QPoint viewportOffset(_textEdit->horizontalScrollBar()->value(), _textEdit->verticalScrollBar()->value());
int docLPos = _textEdit->document()->documentLayout()->hitTest(pos + viewportOffset, Qt::ExactHit);
Expand Down Expand Up @@ -280,9 +308,10 @@ void InteractiveText::trackVisibility()
QRect viewPort(QPoint(0, 0), _textEdit->viewport()->size());

while (it.hasNext()) {
auto id = it.next();
auto cursor = findElement(
id); // FIXME this call is not optimal. but internally it uses qtextdocument, so it won't slowdoan that much
auto id = it.next();

// FIXME this call is not optimal. but internally it uses qtextdocument, so it won't slowdoan that much
auto cursor = findElement(id);
if (!cursor.isNull()) {
auto cr = elementRect(cursor);
cr.translate(-viewportOffset);
Expand Down
12 changes: 7 additions & 5 deletions 3rdparty/qite/libqite/qite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ under the License.
#define QITE_H

#include <QObject>
#include <QPointer>
#include <QTextEdit>
#include <QTextObjectInterface>

class QTextEdit;
class InteractiveText;

#ifndef QITE_FIRST_USER_PROPERTY
Expand Down Expand Up @@ -77,8 +78,8 @@ class InteractiveTextElementController : public QObject, public QTextObjectInter

protected:
friend class InteractiveText;
InteractiveText *itc;
int objectType;
QPointer<InteractiveText> itc;
int objectType;

virtual bool mouseEvent(const Event &event, const QRect &rect, QTextCursor &selected);
virtual void hideEvent(QTextCursor &selected);
Expand All @@ -88,7 +89,8 @@ class InteractiveText : public QObject {
Q_OBJECT
public:
InteractiveText(QTextEdit *_textEdit, int baseObjectType = QTextFormat::UserObject);
inline QTextEdit *textEdit() const { return _textEdit; }
~InteractiveText();
inline QTextEdit *textEdit() const { return _textEdit.data(); }

int registerController(InteractiveTextElementController *elementController);
void unregisterController(InteractiveTextElementController *elementController);
Expand All @@ -107,7 +109,7 @@ private slots:
void trackVisibility();

private:
QTextEdit *_textEdit = nullptr;
QPointer<QTextEdit> _textEdit;
int _baseObjectType;
int _objectType;
quint32 _uniqueElementId = 0; // just a sequence number
Expand Down
25 changes: 20 additions & 5 deletions 3rdparty/qite/libqite/qiteaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ under the License.

#include "qiteaudio.h"

#include <QAudioOutput>
#include <QEvent>
#include <QHoverEvent>
#include <QMediaMetaData>
Expand All @@ -31,6 +32,8 @@ under the License.
#include <QVector2D>
#include <QtGlobal>

#define QITE_DEBUG

class AudioMessageFormat : public InteractiveTextFormat {
public:
enum Property {
Expand Down Expand Up @@ -124,6 +127,10 @@ QSizeF ITEAudioController::intrinsicSize(QTextDocument *doc, int posInDocument,
Q_UNUSED(posInDocument)
const QTextCharFormat charFormat = format.toCharFormat();
auto psize = QFontMetrics(charFormat.font()).height();
#ifdef QITE_DEBUG
// qDebug("Audio controller size is computed from font \"%s\" with size %d", qPrintable(charFormat.font().family()),
// charFormat.font().pointSize());
#endif
if (lastFontSize != psize) {
lastFontSize = psize;
updateGeomtry();
Expand Down Expand Up @@ -347,7 +354,7 @@ QTextCharFormat ITEAudioController::makeFormat(const QUrl &audioSrc, ITEMediaOpe
{
AudioMessageFormat fmt(objectType, itc->nextId(), audioSrc, mediaOpener);
fmt.setFontPointSize(itc->textEdit()->currentFont().pointSize());
return std::move(fmt);
return fmt;
}

void ITEAudioController::insert(const QUrl &audioSrc, ITEMediaOpener *mediaOpener)
Expand Down Expand Up @@ -396,6 +403,9 @@ bool ITEAudioController::mouseEvent(const Event &event, const QRect &rect, QText
if (state & AudioMessageFormat::Playing) {
if (!player) {
player = new QMediaPlayer(this);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
player->setAudioOutput(new QAudioOutput(player));
#endif
player->setProperty("playerId", playerId);
player->setProperty("cursorPos", selected.anchor());
activePlayers.insert(playerId, player);
Expand Down Expand Up @@ -518,17 +528,22 @@ bool ITEAudioController::mouseEvent(const Event &event, const QRect &rect, QText
cursor.setCharFormat(format);
});

connect(player, SIGNAL(stateChanged(ITEAudioController::PlaybackState)), this,
SLOT(playerStateChanged(ITEAudioController::PlaybackState)));
QObject::connect(player, &QMediaPlayer::mediaStatusChanged,
[=]() { qDebug() << "Media status changed:" << player->mediaStatus(); });
QObject::connect(player, &QMediaPlayer::mediaStatusChanged, [=]() {
#ifdef QITE_DEBUG
qDebug() << "Media status changed:" << player->mediaStatus();
#endif
});
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(player, &QMediaPlayer::stateChanged, this, &ITEAudioController::playerStateChanged);
QObject::connect(player,
static_cast<void (QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
[=](QMediaPlayer::Error error) { qDebug() << "Error occurred:" << error; });
#else
QObject::connect(player, &QMediaPlayer::playbackStateChanged, this,
&ITEAudioController::playerStateChanged);
QObject::connect(player, &QMediaPlayer::errorOccurred, this,
[=](QMediaPlayer::Error error, const QString &errorString) {
Q_UNUSED(error);
qDebug() << "Error occurred:" << errorString;
});
#endif
Expand Down
Loading

0 comments on commit 03a3b84

Please sign in to comment.