From 22ab5a1af17c4bf55fa2b1d5ba4cb2c5ef87ebaa Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 21 Apr 2014 17:07:59 +0400 Subject: [PATCH] Correcting toolbars background painting on windows (issue #32) --- src/XGUI/XGUI_ViewPort.cpp | 1 + src/XGUI/XGUI_ViewPort.h | 1 + src/XGUI/XGUI_ViewWindow.cpp | 37 +++++++++++++++++++++++++++--------- src/XGUI/XGUI_ViewWindow.h | 28 +++++++++++---------------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/XGUI/XGUI_ViewPort.cpp b/src/XGUI/XGUI_ViewPort.cpp index 8efbfc0c8..6ec2c0c65 100644 --- a/src/XGUI/XGUI_ViewPort.cpp +++ b/src/XGUI/XGUI_ViewPort.cpp @@ -303,6 +303,7 @@ void XGUI_ViewPort::resizeEvent(QResizeEvent* theEvent) if (!activeView().IsNull()) { activeView()->MustBeResized(); } + emit resized(); } //*********************************************** diff --git a/src/XGUI/XGUI_ViewPort.h b/src/XGUI/XGUI_ViewPort.h index cb8327d26..fa4104508 100644 --- a/src/XGUI/XGUI_ViewPort.h +++ b/src/XGUI/XGUI_ViewPort.h @@ -67,6 +67,7 @@ signals: void vpMapped(); void vpTransformed(); void vpUpdated(); + void resized(); protected: virtual void paintEvent(QPaintEvent*); diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index 48e22dc19..3de5191cd 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -79,7 +79,16 @@ const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c "................................", "................................" }; -static int aAA = 0; +ViewerToolbar::ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) + : QToolBar(theParent), myVPort(thePort), myResize(false) +{ + setBackgroundRole(QPalette::NoRole); + setAttribute(Qt::WA_NoSystemBackground); + //setAttribute(Qt::WA_PaintOnScreen); + setAutoFillBackground(false); + connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized())); +} + void ViewerToolbar::paintEvent(QPaintEvent* theEvent) { // Paint background @@ -91,7 +100,10 @@ void ViewerToolbar::paintEvent(QPaintEvent* theEvent) QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height())); - aPainter.drawImage(aRect, myVPort->dumpView(aImgRect, false)); + QImage aImg = myVPort->dumpView(aImgRect, myResize); + if (!aImg.isNull()) + aPainter.drawImage(aRect, aImg); + myResize = false; // Paint foreground QStyle *style = this->style(); @@ -104,7 +116,17 @@ void ViewerToolbar::paintEvent(QPaintEvent* theEvent) } //************************************************************************** -void ViewerLabel::repaintBackground() +ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort) + : QLabel(theParent), myVPort(thePort), myResize(false) +{ + setBackgroundRole(QPalette::NoRole); + setAttribute(Qt::WA_NoSystemBackground); + //setAttribute(Qt::WA_PaintOnScreen); + setAutoFillBackground(false); + connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized())); +} + +void ViewerLabel::paintEvent(QPaintEvent* theEvent) { QRect aRect = rect(); QRect aVPRect = myVPort->rect(); @@ -113,12 +135,9 @@ void ViewerLabel::repaintBackground() QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height())); - QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false)); -} - -void ViewerLabel::paintEvent(QPaintEvent* theEvent) -{ - repaintBackground(); + QImage aImg = myVPort->dumpView(aImgRect, myResize); + if (!aImg.isNull()) + QPainter(this).drawImage(aRect, aImg); QLabel::paintEvent(theEvent); } diff --git a/src/XGUI/XGUI_ViewWindow.h b/src/XGUI/XGUI_ViewWindow.h index e528138a3..77b966d86 100644 --- a/src/XGUI/XGUI_ViewWindow.h +++ b/src/XGUI/XGUI_ViewWindow.h @@ -299,20 +299,19 @@ class ViewerToolbar: public QToolBar { Q_OBJECT public: - ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) - : QToolBar(theParent), myVPort(thePort) - { - setBackgroundRole(QPalette::NoRole); - setAttribute(Qt::WA_NoSystemBackground); - //setAttribute(Qt::WA_PaintOnScreen); - setAutoFillBackground(false); - } + ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort); + +protected slots: + void onViewPortResized() { myResize = true; } protected: virtual void paintEvent(QPaintEvent* theEvent); + + private: XGUI_ViewPort* myVPort; + bool myResize; }; //****************************************************** @@ -325,22 +324,17 @@ class ViewerLabel: public QLabel { Q_OBJECT public: - ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort) - : QLabel(theParent), myVPort(thePort) - { - setBackgroundRole(QPalette::NoRole); - setAttribute(Qt::WA_NoSystemBackground); - //setAttribute(Qt::WA_PaintOnScreen); - setAutoFillBackground(false); - } + ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort); - void repaintBackground(); +protected slots: + void onViewPortResized() { myResize = true; } protected: virtual void paintEvent(QPaintEvent* theEvent); private: XGUI_ViewPort* myVPort; + bool myResize; }; #endif -- 2.39.2