From 0cd4fa50f143cc929b39862fd6ce52758c5580fa Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 27 Mar 2014 13:09:08 +0400 Subject: [PATCH] Transparent background on toolbars of ViewWindow --- src/XGUI/XGUI_MainWindow.cpp | 1 + src/XGUI/XGUI_ViewPort.cpp | 45 ++++++++++++++------- src/XGUI/XGUI_ViewPort.h | 2 +- src/XGUI/XGUI_ViewWindow.cpp | 70 +++++++++++++++++++-------------- src/XGUI/XGUI_ViewWindow.h | 42 +++++++++++++++++--- src/XGUI/XGUI_msg_en.ts | 4 ++ src/XGUI/pictures/wnd_grip.png | Bin 230 -> 220 bytes 7 files changed, 115 insertions(+), 49 deletions(-) diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 9f2f85b8c..cbf8aa475 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -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); diff --git a/src/XGUI/XGUI_ViewPort.cpp b/src/XGUI/XGUI_ViewPort.cpp index 1ec3731f6..73a5b1320 100644 --- a/src/XGUI/XGUI_ViewPort.cpp +++ b/src/XGUI/XGUI_ViewPort.cpp @@ -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(); diff --git a/src/XGUI/XGUI_ViewPort.h b/src/XGUI/XGUI_ViewPort.h index 1be2c4932..d3f6eddf1 100644 --- a/src/XGUI/XGUI_ViewPort.h +++ b/src/XGUI/XGUI_ViewPort.h @@ -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(); } diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index 5499ec8cc..cf6bcc6d1 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -11,11 +11,43 @@ #include #include #include +#include #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(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 +} + diff --git a/src/XGUI/XGUI_ViewWindow.h b/src/XGUI/XGUI_ViewWindow.h index 1f37dc3fe..b963f173a 100644 --- a/src/XGUI/XGUI_ViewWindow.h +++ b/src/XGUI/XGUI_ViewWindow.h @@ -3,14 +3,16 @@ #include #include +#include +#include #include #include -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 diff --git a/src/XGUI/XGUI_msg_en.ts b/src/XGUI/XGUI_msg_en.ts index 6f94461a3..a8ffce717 100644 --- a/src/XGUI/XGUI_msg_en.ts +++ b/src/XGUI/XGUI_msg_en.ts @@ -101,6 +101,10 @@ XGUI_MainWindow + + WINDOW_TITLE + New GEOM + OBJECT_BROWSER_TITLE Object Browser diff --git a/src/XGUI/pictures/wnd_grip.png b/src/XGUI/pictures/wnd_grip.png index 8b0d09242b1885ee566b7d950de097fd15639c59..032a29fda52649026e5b2ebcc97692132a30b247 100644 GIT binary patch delta 130 zcmV-|0Db@F0o(zQJPN@801m+cxRGn^kwz(PSV=@dR5(v#fB`NpE(TFi5g-