}
//***********************************************
-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 ) )
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();
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();
#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(),
myPicture = new QLabel();
myPicture->setFrameStyle(QFrame::Sunken);
myPicture->setFrameShape(QFrame::Panel);
- //aLay->addWidget(myPicture);
myPicture->setMouseTracking(true);
myPicture->installEventFilter(this);
myPicture->hide();
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);
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());
}
//****************************************************************
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();
myPicture->move(parentWidget()->x(), parentWidget()->y());
myPicture->show();
} else {
- //myViewPort->show();
myPicture->hide();
if (isMaximized()) {
myMinimizeBtn->setIcon(MinimizeIco);
//****************************************************************
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);
}
//****************************************************************
}
}
return QFrame::eventFilter(theObj, theEvent);
-}
\ No newline at end of file
+}
+
#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
{
XGUI_Viewer* myViewer;
QLabel* myPicture;
- QLabel* myGripWgt;
+ ViewerLabel* myGripWgt;
XGUI_ViewPort* myViewPort;
- QToolBar* myViewBar;
- QToolBar* myWindowBar;
+ ViewerToolbar* myViewBar;
+ ViewerToolbar* myWindowBar;
QAction* myMinimizeBtn;
QAction* myMaximizeBtn;
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