]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Transparent background on toolbars of ViewWindow
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 27 Mar 2014 09:09:08 +0000 (13:09 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 27 Mar 2014 09:09:08 +0000 (13:09 +0400)
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_ViewPort.cpp
src/XGUI/XGUI_ViewPort.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_ViewWindow.h
src/XGUI/XGUI_msg_en.ts
src/XGUI/pictures/wnd_grip.png

index 9f2f85b8c988383ee088b3e77538213ce19335f2..cbf8aa4751646024b2945633c942fd18307e17d8 100644 (file)
@@ -23,6 +23,7 @@
 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) :
     QMainWindow(parent), myObjectBrowser(0)
 {
+    setWindowTitle(tr("WINDOW_TITLE"));
     myMenuBar = new XGUI_MainMenu(this);
 
     QDockWidget* aDoc = new QDockWidget(this);
index 1ec3731f6b5ee039dfcf2892ac40a2a842ff6686..73a5b13209db3c3049a63d8dcda178d4e67fa2de 100644 (file)
@@ -365,17 +365,22 @@ void XGUI_ViewPort::resizeEvent( QResizeEvent* )
 }
 
 //***********************************************
-QImage XGUI_ViewPort::dumpView()
+QImage XGUI_ViewPort::dumpView(QRect theRect, bool toUpdate)
 {
     Handle(V3d_View) view = getView();
     if ( view.IsNull() )
         return QImage();
   
-    int aWidth = width();
-    int aHeight = height();
+    int aWidth;
+    int aHeight; 
+    if (theRect.isNull()) {
+        aWidth = width();
+        aHeight = height();
+    } else {
+        aWidth = theRect.width();
+        aHeight = theRect.height();
+    }
     //QApplication::syncX();
-    view->Redraw(); // In order to reactivate GL context
-    //view->Update();
 
     OpenGLUtils_FrameBuffer aFrameBuffer;
     if( aFrameBuffer.init( aWidth, aHeight ) )
@@ -387,13 +392,20 @@ QImage XGUI_ViewPort::dumpView()
         aFrameBuffer.bind();
 
         // draw scene
-        view->Redraw();
-
+        if (toUpdate) {
+            if (theRect.isNull())
+                view->Redraw();
+            else
+                view->Redraw(theRect.x(), theRect.y(), theRect.width(), theRect.height());
+        }
         aFrameBuffer.unbind();
         glPopAttrib();
 
         aFrameBuffer.bind();
-        glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
+        if (theRect.isNull())
+            glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
+        else 
+            glReadPixels( theRect.x(), theRect.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
         aFrameBuffer.unbind();
 
         anImage = anImage.rgbSwapped();
@@ -401,14 +413,19 @@ QImage XGUI_ViewPort::dumpView()
         return anImage;
     }
     // if frame buffers are unsupported, use old functionality
-    //view->Redraw();
-
     unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
 
-    QPoint p = mapFromParent(geometry().topLeft());
-
-    glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
-                data);
+    QPoint p;
+    if (theRect.isNull()) {
+        if (toUpdate)
+            view->Redraw();
+        p = mapFromParent(geometry().topLeft());
+    } else {
+        if (toUpdate)
+            view->Redraw(theRect.x(), theRect.y(), theRect.width(), theRect.height());
+        p = theRect.topLeft();
+    }
+    glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);
 
     QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
     anImage = anImage.mirrored();
index 1be2c4932937c452992ae5cfb362ebc6ccdb74c9..d3f6eddf1d3c123cbda1fd4ceb598000ed24c4a0 100644 (file)
@@ -19,7 +19,7 @@ public:
 
     virtual QPaintEngine* paintEngine() const { return 0; }
 
-    QImage dumpView();
+    QImage dumpView(QRect theRect = QRect(), bool toUpdate = true);
 
     Handle(V3d_View) getView() const { return activeView(); }
 
index 5499ec8cc4cd2c15c7adecbaf567a77df45511a2..cf6bcc6d16be08e646840b10012325acfac18f72 100644 (file)
 #include <QMdiArea>
 #include <QMdiSubWindow>
 #include <QPainter>
+#include <QTime>
 
 #define BORDER_SIZE 2
 
 
+//**************************************************************************
+void ViewerToolbar::paintEvent( QPaintEvent* theEvent)
+{
+    QTime aTime;
+    aTime.start();
+    QRect aRect = rect();
+    QRect aVPRect = myVPort->rect();
+    QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
+    QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
+
+    QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
+    QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
+    QString aMsg = QString("### Painted in %1").arg(aTime.elapsed());
+    qDebug(qPrintable(aMsg));
+}
+
+//**************************************************************************
+void ViewerLabel::paintEvent( QPaintEvent* theEvent)
+{
+    QRect aRect = rect();
+    QRect aVPRect = myVPort->rect();
+    QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
+    QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
+
+    QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
+    QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
+    QLabel::paintEvent(theEvent);
+}
 
+//**************************************************************************
+//**************************************************************************
+//**************************************************************************
 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, 
                                  V3d_TypeOfView theType):
 QFrame(),
@@ -39,7 +71,6 @@ QFrame(),
     myPicture = new QLabel();
     myPicture->setFrameStyle(QFrame::Sunken);
     myPicture->setFrameShape(QFrame::Panel);
-    //aLay->addWidget(myPicture);
     myPicture->setMouseTracking(true);
     myPicture->installEventFilter(this);
     myPicture->hide();
@@ -59,24 +90,21 @@ QFrame(),
     aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate";
     aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view";
 
-    myGripWgt = new QLabel(this);
+    myGripWgt = new ViewerLabel(this, myViewPort);
     myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
     myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
     myGripWgt->setMouseTracking(true);
     myGripWgt->installEventFilter(this);
-    myGripWgt->setAutoFillBackground(true);
 
-    myViewBar = new QToolBar(this);
-    myViewBar->setAutoFillBackground(true);
+    myViewBar = new ViewerToolbar(this, myViewPort);
 
     QAction* aBtn;
     for (int i = 0; i < aTitles.length(); i++) {
         aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar);
         myViewBar->addAction(aBtn);
     }
-    
-    myWindowBar = new QToolBar(this);
-    myWindowBar->setAutoFillBackground(true);
+
+    myWindowBar = new ViewerToolbar(this, myViewPort);
 
     myMinimizeBtn = new QAction(myWindowBar);
     myMinimizeBtn->setIcon(MinimizeIco);
@@ -110,11 +138,11 @@ void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
     QSize aWndBarSize = myWindowBar->sizeHint();
     QSize myViewBarSize = myViewBar->sizeHint();
 
-    myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, BORDER_SIZE);
+    myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, BORDER_SIZE + 2);
     int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
     if (aViewBarWidth > myViewBarSize.width())
         aViewBarWidth = myViewBarSize.width();
-    myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE, aViewBarWidth, myViewBarSize.height());
+    myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
 }
 
 //****************************************************************
@@ -123,14 +151,6 @@ void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
 
     if (theEvent->type() == QEvent::WindowStateChange) {
         if (isMinimized()) {
-            //parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, 80);
-            //myViewPort->hide();
-            //myViewBar->hide();
-            //myGripWgt->hide();
-            //myWindowBar->hide();
-            //myMinimizeBtn->setIcon(RestoreIco);
-            //myMaximizeBtn->setIcon(MaximizeIco);
-
             if (!myPicture->parentWidget()) {
                 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
                 QMdiArea* aMDIArea = aParent->mdiArea();
@@ -139,7 +159,6 @@ void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
             myPicture->move(parentWidget()->x(), parentWidget()->y());
             myPicture->show();
         } else {
-            //myViewPort->show();
             myPicture->hide();
             if (isMaximized()) {
                 myMinimizeBtn->setIcon(MinimizeIco);
@@ -180,22 +199,14 @@ void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
 //****************************************************************
 void XGUI_ViewWindow::onMinimize()
 {
-    //QPixmap aPMap = myViewPort->grab();
     QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
     int aW = width();
     int aH = height();
     double aR = aW / 100.;
     myPicture->setPixmap(aPMap.scaled(100,  int(aH / aR)));
-
+    
     myLastState = isMaximized()? MaximizedState : NormalState;
-    //if (isMinimized()) {
-        //myMinimizeBtn->setIcon(MinimizeIco);
-        //showNormal();
-    //} else {
-        //myMinimizeBtn->setIcon(RestoreIco);
     showMinimized();
-    //}
-    //myMaximizeBtn->setIcon(MaximizeIco);
 }
 
 //****************************************************************
@@ -267,4 +278,5 @@ bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
         }
     }
     return QFrame::eventFilter(theObj, theEvent);
-}
\ No newline at end of file
+}
+
index 1f37dc3febdf4615818fbe924160a7b25415a4ee..b963f173af5b836f3e730c040d4c9e7eba6a3ac0 100644 (file)
@@ -3,14 +3,16 @@
 
 #include <QFrame>
 #include <QIcon>
+#include <QToolBar>
+#include <QLabel>
 
 #include <V3d_View.hxx>
 #include <V3d_Viewer.hxx>
 
-class QLabel;
-class QToolBar;
 class XGUI_ViewPort;
 class XGUI_Viewer;
+class ViewerToolbar;
+class ViewerLabel;
 
 class XGUI_ViewWindow : public QFrame
 {
@@ -43,10 +45,10 @@ private:
     XGUI_Viewer* myViewer;
 
     QLabel* myPicture;
-    QLabel* myGripWgt;
+    ViewerLabel* myGripWgt;
     XGUI_ViewPort* myViewPort;
-    QToolBar* myViewBar;
-    QToolBar* myWindowBar;
+    ViewerToolbar* myViewBar;
+    ViewerToolbar* myWindowBar;
     QAction* myMinimizeBtn;
     QAction* myMaximizeBtn;
 
@@ -59,6 +61,36 @@ private:
     QPoint myMousePnt;
 
     WindowState myLastState;
+
+    //QGraphicsScene* myScene;
+};
+
+class ViewerToolbar : public QToolBar
+{
+    Q_OBJECT
+public:
+    ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort) :
+    QToolBar(theParent), myVPort(thePort) {}
+
+protected:
+    virtual void paintEvent( QPaintEvent* theEvent);
+
+private:
+    XGUI_ViewPort* myVPort;
+};
+
+class ViewerLabel : public QLabel
+{
+    Q_OBJECT
+public:
+    ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort) :
+    QLabel(theParent), myVPort(thePort) {}
+
+protected:
+    virtual void paintEvent( QPaintEvent* theEvent);
+
+private:
+    XGUI_ViewPort* myVPort;
 };
 
 #endif
\ No newline at end of file
index 6f94461a36ee71480205de8ded07ed7f979ce545..a8ffce717a95819060d73da03a448b2162b5e534 100644 (file)
 </context>
 <context>
     <name>XGUI_MainWindow</name>
+    <message>
+        <source>WINDOW_TITLE</source>
+        <translation>New GEOM</translation>
+    </message>
     <message>
         <source>OBJECT_BROWSER_TITLE</source>
         <translation>Object Browser</translation>
index 8b0d09242b1885ee566b7d950de097fd15639c59..032a29fda52649026e5b2ebcc97692132a30b247 100644 (file)
Binary files a/src/XGUI/pictures/wnd_grip.png and b/src/XGUI/pictures/wnd_grip.png differ