Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale monitor images on resizing monitor settings dialog #1054

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions lxqt-config-monitor/monitorpicture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <QRectF>
#include <KScreen/Mode>
#include <QScrollBar>
#include <QResizeEvent>
#include <QTransform>

#include "configure.h"

Expand Down Expand Up @@ -97,13 +99,34 @@ void MonitorPictureDialog::setScene(QList<MonitorWidget *> monitors)
void MonitorPictureDialog::showEvent(QShowEvent * event)
{
QWidget::showEvent(event);
if( ! firstShownOk ) {
// Update scale and set scrollbar position.
// Real widget size is not set, until widget is shown.
if (!firstShownOk) {
firstShownOk = true;
int minWidgetLength = qMin(ui.graphicsView->size().width(), ui.graphicsView->size().width()) / 1.5;
qDebug() << "minWidgetLength" << minWidgetLength << "maxMonitorSize" << maxMonitorSize << "scale" << minWidgetLength / (float) maxMonitorSize;
ui.graphicsView->scale(minWidgetLength / (float) maxMonitorSize, minWidgetLength / (float) maxMonitorSize);
qreal minWidgetLength = static_cast<qreal>(qMax(ui.graphicsView->size().width(), ui.graphicsView->size().height())) / 1.2;
if (maxMonitorSize > 0)
updateScale(minWidgetLength / maxMonitorSize);
}
}

void MonitorPictureDialog::resizeEvent(QResizeEvent *event)
{
QDialog::resizeEvent(event);
if (firstShownOk && maxMonitorSize > 0)
{
qreal scale = ui.graphicsView->transform().m11();
if (scale > 0)
{
qreal minWidgetLength = static_cast<qreal>(qMax(ui.graphicsView->size().width(), ui.graphicsView->size().height())) / 1.2;
updateScale((minWidgetLength / maxMonitorSize) / scale);
}
}
}

void MonitorPictureDialog::updateScale(qreal scale)
{
// Update scale and set scrollbar position.
if (scale > 0)
{
ui.graphicsView->scale(scale, scale);
updateScene();
ui.graphicsView->verticalScrollBar()->setValue(0);
ui.graphicsView->horizontalScrollBar()->setValue(0);
Expand Down
9 changes: 6 additions & 3 deletions lxqt-config-monitor/monitorpicture.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ class MonitorPictureDialog : public QDialog

protected:
void showEvent(QShowEvent * event) override;
void resizeEvent(QResizeEvent *event) override;

private:
void updateScale(qreal scale);

Ui::MonitorPictureDialog ui;
QList<MonitorPicture*> pictures;
bool updatingOk;
Expand All @@ -70,7 +73,7 @@ class MonitorPicture : public QGraphicsRectItem

private:
QGraphicsTextItem *textItem;
QGraphicsSvgItem *svgItem;
QGraphicsSvgItem *svgItem;
MonitorPictureDialog *monitorPictureDialog;


Expand All @@ -85,11 +88,11 @@ class MonitorPictureProxy: public QObject
public:
MonitorPictureProxy(QObject *parent, MonitorPicture *monitorPicture);
MonitorPicture *monitorPicture;

public slots:
void updateSize();
void updatePosition();

};


Expand Down