Refactor attachment handling system with enhanced UI (#12085)

* Renamed NewEntryAttachmentsDialog to EditEntryAttachmentsDialog for clarity.
* Introduced EditEntryAttachmentsDialog class to manage editing of existing attachments.
* Added functionality to preview attachments while editing them.
* Enhanced EntryAttachmentsModel with rowByKey method for better key management.
* Add image attachment support with zoom functionality.
* Add html and markdown detection.
* Improve button layout on the attachment section when editing an entry
This commit is contained in:
Kuznetsov Oleg 2025-06-19 20:27:23 +03:00 committed by GitHub
parent c4b4be48a5
commit f2a4cc7e66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 3254 additions and 388 deletions

View file

@ -0,0 +1,76 @@
#include "TestImageAttachmentsView.h"
#include <attachments/ImageAttachmentsView.h>
#include <QBuffer>
#include <QPixmap>
#include <QSignalSpy>
#include <QTest>
#include <QWheelEvent>
void TestImageAttachmentsView::initTestCase()
{
m_view.reset(new ImageAttachmentsView());
// Generate the black rectange.
QImage image(1000, 1000, QImage::Format_RGB32);
image.fill(Qt::black);
auto scene = new QGraphicsScene();
scene->addPixmap(QPixmap::fromImage(image));
m_view->setScene(scene);
m_view->show();
QCoreApplication::processEvents();
}
void TestImageAttachmentsView::testEmitWheelEvent()
{
QSignalSpy ctrlWheelEvent{m_view.data(), &ImageAttachmentsView::ctrlWheelEvent};
QPoint center = m_view->rect().center();
m_view->setFocus();
QWheelEvent event(center, // local pos
m_view->mapToGlobal(center), // global pos
QPoint(0, 0),
QPoint(0, 120),
Qt::NoButton,
Qt::ControlModifier,
Qt::ScrollBegin,
false);
QCoreApplication::sendEvent(m_view->viewport(), &event);
QCOMPARE(ctrlWheelEvent.count(), 1);
}
void TestImageAttachmentsView::testEnableFit()
{
m_view->enableAutoFitInView();
QVERIFY(m_view->isAutoFitInViewActivated());
const auto oldTransform = m_view->transform();
m_view->resize(m_view->size() + QSize(100, 100));
QCoreApplication::processEvents();
QVERIFY(m_view->transform() != oldTransform);
}
void TestImageAttachmentsView::testDisableFit()
{
m_view->disableAutoFitInView();
QVERIFY(!m_view->isAutoFitInViewActivated());
const auto expectedTransform = m_view->transform();
m_view->resize(m_view->size() + QSize(100, 100));
QCoreApplication::processEvents();
QCOMPARE(m_view->transform(), expectedTransform);
}