mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 02:46:52 -05:00
[CardInfoPicture] Defer enlargedPixmap creation until needed (#6426)
* [CardInfoPicture] Defer enlargedPixmap creation until needed Took 4 minutes Took 1 minute * Disregard const_cast Took 2 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
cd44392866
commit
41aca8467a
|
|
@ -39,10 +39,6 @@ CardInfoPictureWidget::CardInfoPictureWidget(QWidget *parent, const bool _hoverT
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
enlargedPixmapWidget = new CardInfoPictureEnlargedWidget(this->window());
|
|
||||||
enlargedPixmapWidget->hide();
|
|
||||||
connect(this, &QObject::destroyed, enlargedPixmapWidget, &CardInfoPictureEnlargedWidget::deleteLater);
|
|
||||||
|
|
||||||
hoverTimer = new QTimer(this);
|
hoverTimer = new QTimer(this);
|
||||||
hoverTimer->setSingleShot(true);
|
hoverTimer->setSingleShot(true);
|
||||||
connect(hoverTimer, &QTimer::timeout, this, &CardInfoPictureWidget::showEnlargedPixmap);
|
connect(hoverTimer, &QTimer::timeout, this, &CardInfoPictureWidget::showEnlargedPixmap);
|
||||||
|
|
@ -277,7 +273,7 @@ void CardInfoPictureWidget::leaveEvent(QEvent *event)
|
||||||
|
|
||||||
if (hoverToZoomEnabled) {
|
if (hoverToZoomEnabled) {
|
||||||
hoverTimer->stop();
|
hoverTimer->stop();
|
||||||
enlargedPixmapWidget->hide();
|
destroyEnlargedPixmapWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raiseOnEnter) {
|
if (raiseOnEnter) {
|
||||||
|
|
@ -294,7 +290,7 @@ void CardInfoPictureWidget::moveEvent(QMoveEvent *event)
|
||||||
QWidget::moveEvent(event);
|
QWidget::moveEvent(event);
|
||||||
|
|
||||||
hoverTimer->stop();
|
hoverTimer->stop();
|
||||||
enlargedPixmapWidget->hide();
|
destroyEnlargedPixmapWidget();
|
||||||
|
|
||||||
if (animation->state() == QAbstractAnimation::Running) {
|
if (animation->state() == QAbstractAnimation::Running) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -310,7 +306,7 @@ void CardInfoPictureWidget::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::mouseMoveEvent(event);
|
QWidget::mouseMoveEvent(event);
|
||||||
|
|
||||||
if (hoverToZoomEnabled && enlargedPixmapWidget->isVisible()) {
|
if (hoverToZoomEnabled && enlargedPixmapWidget && enlargedPixmapWidget->isVisible()) {
|
||||||
const QPoint cursorPos = QCursor::pos();
|
const QPoint cursorPos = QCursor::pos();
|
||||||
const QRect screenGeometry = QGuiApplication::screenAt(cursorPos)->geometry();
|
const QRect screenGeometry = QGuiApplication::screenAt(cursorPos)->geometry();
|
||||||
const QSize widgetSize = enlargedPixmapWidget->size();
|
const QSize widgetSize = enlargedPixmapWidget->size();
|
||||||
|
|
@ -344,7 +340,7 @@ void CardInfoPictureWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
|
||||||
void CardInfoPictureWidget::hideEvent(QHideEvent *event)
|
void CardInfoPictureWidget::hideEvent(QHideEvent *event)
|
||||||
{
|
{
|
||||||
enlargedPixmapWidget->hide();
|
destroyEnlargedPixmapWidget();
|
||||||
QWidget::hideEvent(event);
|
QWidget::hideEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,12 +440,19 @@ QMenu *CardInfoPictureWidget::createAddToOpenDeckMenu()
|
||||||
* If card information is available, the enlarged pixmap is loaded, positioned near the cursor,
|
* If card information is available, the enlarged pixmap is loaded, positioned near the cursor,
|
||||||
* and displayed.
|
* and displayed.
|
||||||
*/
|
*/
|
||||||
void CardInfoPictureWidget::showEnlargedPixmap() const
|
void CardInfoPictureWidget::showEnlargedPixmap()
|
||||||
{
|
{
|
||||||
if (!exactCard) {
|
if (!exactCard) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lazy creation of the enlarged widget
|
||||||
|
if (!enlargedPixmapWidget) {
|
||||||
|
enlargedPixmapWidget = new CardInfoPictureEnlargedWidget(const_cast<CardInfoPictureWidget *>(this)->window());
|
||||||
|
enlargedPixmapWidget->hide();
|
||||||
|
connect(this, &QObject::destroyed, enlargedPixmapWidget, &CardInfoPictureEnlargedWidget::deleteLater);
|
||||||
|
}
|
||||||
|
|
||||||
const QSize enlargedSize(static_cast<int>(size().width() * 2), static_cast<int>(size().width() * aspectRatio * 2));
|
const QSize enlargedSize(static_cast<int>(size().width() * 2), static_cast<int>(size().width() * aspectRatio * 2));
|
||||||
enlargedPixmapWidget->setCardPixmap(exactCard, enlargedSize);
|
enlargedPixmapWidget->setCardPixmap(exactCard, enlargedSize);
|
||||||
|
|
||||||
|
|
@ -460,7 +463,6 @@ void CardInfoPictureWidget::showEnlargedPixmap() const
|
||||||
int newX = cursorPos.x() + enlargedPixmapOffset;
|
int newX = cursorPos.x() + enlargedPixmapOffset;
|
||||||
int newY = cursorPos.y() + enlargedPixmapOffset;
|
int newY = cursorPos.y() + enlargedPixmapOffset;
|
||||||
|
|
||||||
// Adjust if out of bounds
|
|
||||||
if (newX + widgetSize.width() > screenGeometry.right()) {
|
if (newX + widgetSize.width() > screenGeometry.right()) {
|
||||||
newX = cursorPos.x() - widgetSize.width() - enlargedPixmapOffset;
|
newX = cursorPos.x() - widgetSize.width() - enlargedPixmapOffset;
|
||||||
}
|
}
|
||||||
|
|
@ -472,3 +474,11 @@ void CardInfoPictureWidget::showEnlargedPixmap() const
|
||||||
|
|
||||||
enlargedPixmapWidget->show();
|
enlargedPixmapWidget->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardInfoPictureWidget::destroyEnlargedPixmapWidget()
|
||||||
|
{
|
||||||
|
if (enlargedPixmapWidget) {
|
||||||
|
enlargedPixmapWidget->deleteLater();
|
||||||
|
enlargedPixmapWidget = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,8 @@ protected:
|
||||||
{
|
{
|
||||||
return resizedPixmap;
|
return resizedPixmap;
|
||||||
}
|
}
|
||||||
void showEnlargedPixmap() const;
|
void showEnlargedPixmap();
|
||||||
|
void destroyEnlargedPixmapWidget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExactCard exactCard;
|
ExactCard exactCard;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user