]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Correcting toolbars background painting on windows (issue #32)
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 21 Apr 2014 13:07:59 +0000 (17:07 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 21 Apr 2014 13:07:59 +0000 (17:07 +0400)
src/XGUI/XGUI_ViewPort.cpp
src/XGUI/XGUI_ViewPort.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_ViewWindow.h

index 8efbfc0c820a953abefae0050556bc9daf0051ed..6ec2c0c65f51c35f6c852dd8e76721ca28ba4bb2 100644 (file)
@@ -303,6 +303,7 @@ void XGUI_ViewPort::resizeEvent(QResizeEvent* theEvent)
   if (!activeView().IsNull()) {
     activeView()->MustBeResized();
   }
+  emit resized();
 }
 
 //***********************************************
index cb8327d26f8bb162da3495b74d06ada727ea120d..fa4104508146186d34225fd27926d5dbb23209c7 100644 (file)
@@ -67,6 +67,7 @@ signals:
   void vpMapped();
   void vpTransformed();
   void vpUpdated();
+  void resized();
 
 protected:
   virtual void paintEvent(QPaintEvent*);
index 48e22dc19f407fb0c341ddc90ec4d7e512e96abb..3de5191cd951e9fc35574971871be1109586df8b 100644 (file)
@@ -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);
 }
 
index e528138a3bd3ea331919fb9541de5c5c9047037a..77b966d860a0901ba6eeac2250bab8db8f3c3c03 100644 (file)
@@ -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