Skip to content

Commit

Permalink
Scale monitor images on resizing monitor settings dialog (#1054)
Browse files Browse the repository at this point in the history
* Scale monitor images on resizing monitor settings dialog

Also, the images are made a little larger by default.

Closes #1053

* Cleaned up `monitor.svg`

`monitor.svg` contained Gaussian blur, which is not well supported by `QSvgRenderer` and can cause extra CPU usage (→ lxqt/libqtxdg#291 (comment)).
  • Loading branch information
tsujan authored Sep 21, 2024
1 parent 7725fe3 commit 581d382
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 213 deletions.
237 changes: 33 additions & 204 deletions lxqt-config-monitor/icons/monitor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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

0 comments on commit 581d382

Please sign in to comment.