From a0cac2fefa1d7b5eaaa159608b8198058e192f95 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 6 Jan 2020 12:43:33 +0100 Subject: [PATCH] #5288 Fix update issues --- .../RicSnapshotViewToFileFeature.cpp | 28 +++++----- .../ProjectDataModel/RimMultiPlotWindow.cpp | 2 +- .../UserInterface/RiuMultiPlotPage.cpp | 13 +++-- .../UserInterface/RiuMultiPlotPage.h | 3 +- .../UserInterface/RiuMultiPlotWindow.cpp | 6 +- .../UserInterface/RiuMultiPlotWindow.h | 1 - .../UserInterface/RiuQwtPlotWidget.cpp | 55 ++++++++++++++++--- .../UserInterface/RiuQwtPlotWidget.h | 4 +- .../UserInterface/RiuWellLogPlot.cpp | 5 +- 9 files changed, 81 insertions(+), 36 deletions(-) diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp index 744993047a..e7e50e359b 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp @@ -84,22 +84,22 @@ void RicSnapshotViewToFileFeature::savePlotPDFReportAs( const QString& fileName, QFile pdfFile( fileName ); if ( pdfFile.open( QIODevice::WriteOnly ) ) { - int resolution = RiaGuiApplication::applicationResolution(); - int pageWidth = plot->pageLayout().fullRectPixels( resolution ).width(); - int widgetWidth = plot->viewWidget()->width(); - int deltaWidth = widgetWidth - pageWidth; + int resolution = RiaGuiApplication::applicationResolution(); + /* int pageWidth = plot->pageLayout().fullRectPixels( resolution ).width(); + int widgetWidth = plot->viewWidget()->width(); + int deltaWidth = widgetWidth - pageWidth; - while ( std::abs( deltaWidth ) > 1 ) - { - int newResolution = resolution + deltaWidth / std::abs( deltaWidth ); - pageWidth = plot->pageLayout().fullRectPixels( resolution ).width(); - int newDeltaWidth = widgetWidth - pageWidth; - if ( std::abs( newDeltaWidth ) > std::abs( deltaWidth ) ) break; - - resolution = newResolution; - deltaWidth = newDeltaWidth; - } + while ( std::abs( deltaWidth ) > 1 ) + { + int newResolution = resolution + deltaWidth / std::abs( deltaWidth ); + pageWidth = plot->pageLayout().fullRectPixels( resolution ).width(); + int newDeltaWidth = widgetWidth - pageWidth; + if ( std::abs( newDeltaWidth ) > std::abs( deltaWidth ) ) break; + resolution = newResolution; + deltaWidth = newDeltaWidth; + } + */ QPdfWriter pdfPrinter( fileName ); pdfPrinter.setPageLayout( plot->pageLayout() ); pdfPrinter.setCreator( QCoreApplication::applicationName() ); diff --git a/ApplicationCode/ProjectDataModel/RimMultiPlotWindow.cpp b/ApplicationCode/ProjectDataModel/RimMultiPlotWindow.cpp index fc3ba0d33d..2a648fe3d7 100644 --- a/ApplicationCode/ProjectDataModel/RimMultiPlotWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimMultiPlotWindow.cpp @@ -178,13 +178,13 @@ void RimMultiPlotWindow::insertPlot( RimPlot* plot, size_t index ) if ( plot ) { m_plots.insert( index, plot ); - plot->setShowWindow( true ); if ( m_viewer ) { plot->createPlotWidget(); m_viewer->insertPlot( plot->viewer(), index ); } + plot->setShowWindow( true ); plot->setLegendsVisible( false ); onPlotAdditionOrRemoval(); diff --git a/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp b/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp index da7eaca425..6f96946151 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp +++ b/ApplicationCode/UserInterface/RiuMultiPlotPage.cpp @@ -76,13 +76,14 @@ RiuMultiPlotPage::RiuMultiPlotPage( RimMultiPlotWindow* plotDefinition, QWidget* m_plotTitle = createTitleLabel(); m_layout->addWidget( m_plotTitle ); + m_plotTitle->setVisible( m_plotDefinition->isMultiPlotTitleVisible() ); m_plotLayout = new QHBoxLayout; m_layout->addLayout( m_plotLayout ); m_plotWidgetFrame = new QFrame; - m_plotWidgetFrame->setVisible( true ); m_plotLayout->addWidget( m_plotWidgetFrame, 1 ); + m_plotWidgetFrame->setVisible( true ); m_gridLayout = new QGridLayout( m_plotWidgetFrame ); m_gridLayout->setContentsMargins( 0, 0, 0, 0 ); @@ -308,14 +309,17 @@ void RiuMultiPlotPage::scheduleReplotOfAllPlots() //-------------------------------------------------------------------------------------------------- void RiuMultiPlotPage::renderTo( QPaintDevice* paintDevice ) { + int resolution = paintDevice->logicalDpiX(); + double scaling = resolution / static_cast( RiaGuiApplication::applicationResolution() ); + QPainter painter( paintDevice ); - renderTo( &painter ); + renderTo( &painter, scaling ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuMultiPlotPage::renderTo( QPainter* painter ) +void RiuMultiPlotPage::renderTo( QPainter* painter, double scalingFactor ) { setSelectionsVisible( false ); m_plotTitle->render( painter ); @@ -345,7 +349,7 @@ void RiuMultiPlotPage::renderTo( QPainter* painter ) QPoint plotWidgetFrameTopLeft = m_plotWidgetFrame->frameGeometry().topLeft(); plotWidgetGeometry.moveTo( plotWidgetTopLeft + plotWidgetFrameTopLeft - marginOffset ); - plotWidget->renderTo( painter, plotWidgetGeometry ); + plotWidget->renderTo( painter, plotWidgetGeometry, scalingFactor ); } setSelectionsVisible( true ); @@ -378,7 +382,6 @@ void RiuMultiPlotPage::contextMenuEvent( QContextMenuEvent* event ) QLabel* RiuMultiPlotPage::createTitleLabel() const { QLabel* plotTitle = new QLabel( "PLOT TITLE HERE", nullptr ); - plotTitle->setVisible( m_plotDefinition->isMultiPlotTitleVisible() ); plotTitle->setAlignment( Qt::AlignHCenter ); plotTitle->setWordWrap( true ); plotTitle->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); diff --git a/ApplicationCode/UserInterface/RiuMultiPlotPage.h b/ApplicationCode/UserInterface/RiuMultiPlotPage.h index 127310eb82..ab1c1aac91 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotPage.h +++ b/ApplicationCode/UserInterface/RiuMultiPlotPage.h @@ -15,7 +15,6 @@ // for more details. // ///////////////////////////////////////////////////////////////////////////////// - #pragma once #include "RiuMultiPlotInterface.h" @@ -80,7 +79,7 @@ public: void updateVerticalScrollBar( double visibleMin, double visibleMax, double totalMin, double totalMax ) override {} void renderTo( QPaintDevice* paintDevice ) override; - void renderTo( QPainter* painter ); + void renderTo( QPainter* painter, double scalingFactor ); QSize sizeHint() const override; QSize minimumSizeHint() const override; diff --git a/ApplicationCode/UserInterface/RiuMultiPlotWindow.cpp b/ApplicationCode/UserInterface/RiuMultiPlotWindow.cpp index 1fa329c120..d887c2f1fe 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMultiPlotWindow.cpp @@ -15,7 +15,6 @@ // for more details. // ///////////////////////////////////////////////////////////////////////////////// - #include "RiuMultiPlotWindow.h" #include "RiaGuiApplication.h" @@ -292,6 +291,9 @@ void RiuMultiPlotWindow::renderTo( QPaintDevice* paintDevice ) { setSelectionsVisible( false ); + int resolution = paintDevice->logicalDpiX(); + double scaling = resolution / static_cast( RiaGuiApplication::applicationResolution() ); + bool firstPage = true; QPainter painter( paintDevice ); for ( RiuMultiPlotPage* page : m_pages ) @@ -304,7 +306,7 @@ void RiuMultiPlotWindow::renderTo( QPaintDevice* paintDevice ) pagedDevice->newPage(); } } - page->renderTo( &painter ); + page->renderTo( &painter, scaling ); firstPage = false; } diff --git a/ApplicationCode/UserInterface/RiuMultiPlotWindow.h b/ApplicationCode/UserInterface/RiuMultiPlotWindow.h index b534fa66ac..d058b97210 100644 --- a/ApplicationCode/UserInterface/RiuMultiPlotWindow.h +++ b/ApplicationCode/UserInterface/RiuMultiPlotWindow.h @@ -15,7 +15,6 @@ // for more details. // ///////////////////////////////////////////////////////////////////////////////// - #pragma once #include "RiuInterfaceToViewWindow.h" diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp index 6440fd6254..31d316c227 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp @@ -19,9 +19,9 @@ #include "RiuQwtPlotWidget.h" -#include "RiaApplication.h" #include "RiaColorTools.h" #include "RiaFontCache.h" +#include "RiaGuiApplication.h" #include "RiaPlotWindowRedrawScheduler.h" #include "RimPlot.h" @@ -609,10 +609,21 @@ void RiuQwtPlotWidget::endZoomOperations() {} //-------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect ) +void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect, double scaling ) { static_cast( this->canvas() )->setPaintAttribute( QwtPlotCanvas::BackingStore, false ); + + QPoint plotTopLeftInWindowCoords = targetRect.topLeft(); + + QRectF canvasRect = this->plotLayout()->canvasRect(); + QPoint canvasTopLeftInPlotCoords( canvasRect.topLeft().x() * scaling, canvasRect.topLeft().y() * scaling ); + QPoint canvasBottomRightInPlotCoords( canvasRect.bottomRight().x() * scaling, canvasRect.bottomRight().y() * scaling ); + + QPoint canvasTopLeftInWindowCoords = canvasTopLeftInPlotCoords + plotTopLeftInWindowCoords; + QPoint canvasBottomRightInWindowCoords = canvasBottomRightInPlotCoords + plotTopLeftInWindowCoords; + QwtPlotRenderer renderer( this ); + renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true ); renderer.render( this, painter, targetRect ); static_cast( this->canvas() )->setPaintAttribute( QwtPlotCanvas::BackingStore, true ); @@ -621,11 +632,8 @@ void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect ) if ( overlayFrame->isVisible() ) { QPoint overlayTopLeftInCanvasCoords = overlayFrame->frameGeometry().topLeft(); - QPoint canvasTopLeftInPlotCoords = this->canvas()->frameGeometry().topLeft(); - QPoint plotTopLeftInWindowCoords = targetRect.topLeft(); - QPoint overlayTopLeftInWindowCoords = plotTopLeftInWindowCoords + canvasTopLeftInPlotCoords + - overlayTopLeftInCanvasCoords; + QPoint overlayTopLeftInWindowCoords = overlayTopLeftInCanvasCoords + canvasTopLeftInWindowCoords; { QRect overlayRect = overlayFrame->frameGeometry(); QSize desiredSize = overlayRect.size(); @@ -633,6 +641,14 @@ void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect ) QSize actualSize = desiredSize.expandedTo( minimumSize ); overlayRect.moveTo( overlayTopLeftInWindowCoords ); overlayRect.setSize( actualSize ); + /* QPoint overlayBottomRightInWindowCoords = overlayRect.bottomRight(); + overlayBottomRightInWindowCoords.setX( + std::min( overlayBottomRightInWindowCoords.x(), + canvasBottomRightInPlotCoords.x() - (int)scaling * m_overlayMargins ) ); + overlayBottomRightInWindowCoords.setY( + std::min( overlayBottomRightInWindowCoords.y(), + canvasBottomRightInPlotCoords.y() - (int)scaling * m_overlayMargins ) ); + overlayRect.setBottomRight( overlayBottomRightInWindowCoords ); */ overlayFrame->renderTo( painter, overlayRect ); } } @@ -644,8 +660,10 @@ void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect ) //-------------------------------------------------------------------------------------------------- void RiuQwtPlotWidget::renderTo( QPaintDevice* paintDevice, const QRect& targetRect ) { + int resolution = paintDevice->logicalDpiX(); + double scaling = resolution / static_cast( RiaGuiApplication::applicationResolution() ); QPainter painter( paintDevice ); - renderTo( &painter, targetRect ); + renderTo( &painter, targetRect, scaling ); } //-------------------------------------------------------------------------------------------------- @@ -766,6 +784,29 @@ void RiuQwtPlotWidget::updateOverlayFrameLayout() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuQwtPlotWidget::scaleFonts( double scalingFactor ) +{ + for ( int axisId = static_cast( QwtPlot::yLeft ); axisId < static_cast( axisCnt ); ++axisId ) + { + QFont axisFont = this->axisFont( axisId ); + axisFont.setPointSize( axisFont.pointSize() * scalingFactor ); + this->setAxisFont( axisId, axisFont ); + + // Axis title font + QwtText axisTitle = this->axisTitle( axisId ); + QFont axisTitleFont = axisTitle.font(); + axisTitleFont.setPointSize( axisTitleFont.pointSize() * scalingFactor ); + axisTitle.setFont( axisTitleFont ); + this->setAxisTitle( axisId, axisTitle ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RiuQwtPlotWidget::selectPlotOwner( bool toggleItemInSelection ) { if ( toggleItemInSelection ) diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h index 791030f790..480c59deae 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h @@ -105,7 +105,7 @@ public: void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget ); void updateLayout() override; - void renderTo( QPainter* painter, const QRect& targetRect ); + void renderTo( QPainter* painter, const QRect& targetRect, double scaling ); void renderTo( QPaintDevice* painter, const QRect& targetRect ); int overlayMargins() const; @@ -139,6 +139,8 @@ private: void updateOverlayFrameLayout(); + void scaleFonts( double scalingFactor ); + private: caf::PdmPointer m_plotDefinition; QPoint m_clickPosition; diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp index 95c5ee557c..5380d3cb75 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp @@ -59,7 +59,6 @@ void RiuWellLogPlot::updateVerticalScrollBar( double minVisible, double maxVisib m_trackScrollBar->setRange( (int)minAvailable, (int)( ( maxAvailable - visibleRange ) ) ); m_trackScrollBar->setPageStep( (int)visibleRange ); m_trackScrollBar->setValue( (int)minVisible ); - m_trackScrollBar->setVisible( true ); } m_trackScrollBar->blockSignals( false ); } @@ -108,9 +107,8 @@ void RiuWellLogPlot::reinsertScrollbar() int rowCount = this->m_gridLayout->rowCount(); int colCount = this->m_gridLayout->columnCount(); - m_trackScrollBar->setVisible( !plotWidgets.empty() ); - m_gridLayout->addLayout( m_trackScrollBarLayout, 2, colCount, rowCount * 2 - 1, 1 ); + m_trackScrollBar->setVisible( !plotWidgets.empty() ); m_gridLayout->setColumnStretch( colCount, 0 ); } @@ -141,6 +139,7 @@ void RiuWellLogPlot::slotSetMinDepth( int value ) //-------------------------------------------------------------------------------------------------- void RiuWellLogPlot::performUpdate() { + m_trackScrollBar->setVisible( false ); reinsertPlotWidgets(); reinsertScrollbar(); int axisShift = alignCanvasTops();