#include <QPainter>
#include <QTimer>
#include <QFileDialog>
+#include <QStyleOptionToolBar>
#include <TopoDS_Shape.hxx>
#include <BRep_Tool.hxx>
"................................", "................................",
"................................", "................................" };
-//**************************************************************************
-void ViewerToolbar::repaintBackground()
+
+ViewerToolbar::ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
+ : QToolBar(theParent), myVPort(thePort), myResize(false)
{
+ connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
+}
+
+void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
+{
+ //QToolBar::paintEvent(theEvent);
+ // Paint background
+ QPainter aPainter(this);
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(),
+ QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
aRect.width(), aRect.height()));
- QPainter(this).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();
+ QStyleOptionToolBar aOpt;
+ initStyleOption(&aOpt);
+
+ aOpt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &aOpt, this);
+ if (aOpt.rect.isValid())
+ style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
}
-void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
+//**************************************************************************
+ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
+ : QLabel(theParent), myVPort(thePort), myResize(false)
{
- repaintBackground();
- QToolBar::paintEvent(theEvent);
+ connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
}
-//**************************************************************************
-void ViewerLabel::repaintBackground()
+void ViewerLabel::paintEvent(QPaintEvent* theEvent)
{
QRect aRect = rect();
QRect aVPRect = myVPort->rect();
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);
}
myCurrPointType(XGUI::GRAVITY),
myPrevPointType(XGUI::GRAVITY),
myRotationPointSelection(false),
- myClosable(true)
+ myClosable(true),
+ myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
+ myDrawRect(false), myEnableDrawMode(true), myCursorIsHand(false), myEventStarted(false),
+ myIsActive(false),
+ myLastState(WindowNormalState), myOperation(NOTHING)
{
mySelectedPoint = gp_Pnt(0., 0., 0.);
setFrameStyle(QFrame::Raised);
aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
myViewPort->installEventFilter(this);
+ myViewPort->setCursor(Qt::ArrowCursor);
aLay->addWidget(myViewPort);
myPicture = new QLabel(this);
aLay->addWidget(myPicture);
myPicture->hide();
+ QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
+ aVPLay->setMargin(0);
+ aVPLay->setSpacing(0);
+ aVPLay->setContentsMargins(0,0,0,0);
+
+ QHBoxLayout* aToolLay = new QHBoxLayout();
+ aToolLay->setMargin(0);
+ aToolLay->setSpacing(0);
+ aToolLay->setContentsMargins(0,0,0,0);
+ aVPLay->addLayout(aToolLay);
+ aVPLay->addStretch();
+
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->setCursor(Qt::OpenHandCursor);
+ aToolLay->addWidget(myGripWgt);
// Create Viewer management buttons
myViewBar = new ViewerToolbar(this, myViewPort);
+ myViewBar->setCursor(Qt::PointingHandCursor);
+ aToolLay->addWidget(myViewBar);
+ aToolLay->addStretch();
QAction* aBtn;
// Create Window management buttons
myWindowBar = new ViewerToolbar(this, myViewPort);
+ myWindowBar->setCursor(Qt::PointingHandCursor);
+ aToolLay->addWidget(myWindowBar);
myMinimizeBtn = new QAction(myWindowBar);
myMinimizeBtn->setIcon(MinimizeIco);
myWindowBar->addAction(aBtn);
connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
- myViewBar->hide();
- myWindowBar->hide();
- myGripWgt->hide();
-
//Support copy of background on updating of viewer
connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
{
}
+
//****************************************************************
-void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
+void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
{
- QSize aSize = theEvent->size();
- QSize aWndBarSize = myWindowBar->sizeHint();
- QSize myViewBarSize = myViewBar->sizeHint();
-
- 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 + 2, aViewBarWidth, myViewBarSize.height());
+ QFrame::showEvent(theEvent);
+ myWindowBar->setFixedSize(myWindowBar->sizeHint());
}
//****************************************************************
if (theEvent->type() == QEvent::WindowStateChange) {
if (isMinimized()) {
- myViewBar->hide();
- myGripWgt->hide();
- myWindowBar->hide();
- myViewPort->hide();
- myPicture->show();
+ if (myPicture->isHidden()) {
+ myViewBar->hide();
+ myGripWgt->hide();
+ myWindowBar->hide();
+ myViewPort->hide();
+ myPicture->show();
+ }
} else {
- myPicture->hide();
- myViewPort->show();
+ if (myPicture->isVisible()) {
+ myPicture->hide();
+ myViewPort->show();
+ }
if (isMaximized()) {
myMinimizeBtn->setIcon(MinimizeIco);
myMaximizeBtn->setIcon(RestoreIco);
}
+ myViewBar->setVisible(myIsActive);
+ myWindowBar->setVisible(myIsActive);
+ myGripWgt->setVisible(myIsActive && (!isMaximized()));
}
} else
QWidget::changeEvent(theEvent);
}
+
//****************************************************************
-void XGUI_ViewWindow::onClose()
+void XGUI_ViewWindow::windowActivated()
{
- if (parentWidget()) {
- emit tryClosing(this);
- if (closable()) {
- emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
- parentWidget()->close();
+ if (!(isMinimized() || parentWidget()->isMinimized())) {
+ myIsActive = true;
+ if (isMaximized() || parentWidget()->isMaximized()) {
+ myMaximizeBtn->setIcon(RestoreIco);
+ } else {
+ myMaximizeBtn->setIcon(MaximizeIco);
}
- }
+ myViewBar->show();
+ myWindowBar->show();
+ myGripWgt->setVisible(!(isMaximized() || isMinimized() ||
+ parentWidget()->isMaximized() || parentWidget()->isMinimized()));
+ } else
+ myIsActive = false;
}
//****************************************************************
-void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
+void XGUI_ViewWindow::windowDeactivated()
{
- if (!isMinimized()) {
- myViewBar->show();
- myWindowBar->show();
- if (!isMaximized())
- myGripWgt->show();
+ myIsActive = false;
+ if (!(isMinimized() || parentWidget()->isMinimized())) {
+ if (isMaximized() || parentWidget()->isMaximized()) {
+ myMaximizeBtn->setIcon(RestoreIco);
+ } else {
+ myMaximizeBtn->setIcon(MaximizeIco);
+ }
+ myViewBar->hide();
+ myWindowBar->hide();
+ myGripWgt->hide();
}
}
+
//****************************************************************
-void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
+void XGUI_ViewWindow::onClose()
{
- myViewBar->hide();
- myGripWgt->hide();
- myWindowBar->hide();
+ if (parentWidget()) {
+ emit tryClosing(this);
+ if (closable()) {
+ emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
+ parentWidget()->close();
+ }
+ }
}
//****************************************************************
int aW = width();
int aH = height();
double aR = aW / 100.;
- int aNewH = int(aH / aR);
- myPicture->setPixmap(aPMap.scaled(100, aNewH));
+ int aNewH = int(aH / aR);
+ myPicture->setPixmap(aPMap.scaled(100, aNewH));
- myLastState = isMaximized() ? MaximizedState : NormalState;
+ myLastState = (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
showMinimized();
- parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(),
- 100, aNewH);
+ parentWidget()->showMinimized();
+ parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
+ parentWidget()->lower();
+ windowDeactivated();
+ myViewer->onWindowMinimized((QMdiSubWindow*)parentWidget());
}
//****************************************************************
void XGUI_ViewWindow::onMaximize()
{
- if (isMaximized()) {
+ if (isMaximized() || parentWidget()->isMaximized()) {
myMaximizeBtn->setIcon(MaximizeIco);
myGripWgt->show();
showNormal();
+ parentWidget()->showNormal();
} else {
myMaximizeBtn->setIcon(RestoreIco);
myGripWgt->hide();
showMaximized();
+ parentWidget()->showMaximized();
}
+ parentWidget()->activateWindow();
myMinimizeBtn->setIcon(MinimizeIco);
+
+ // In order to avoid frosen background in toolbars when it shown as a second view
+ QTimer::singleShot(50, parentWidget(), SLOT(setFocus()));
}
//****************************************************************
case QEvent::MouseButtonDblClick:
if (theObj == myPicture) {
myMoving = false;
- if (myLastState == MaximizedState)
+ if (myLastState == MaximizedState) {
showMaximized();
- else
+ } else {
showNormal();
+ }
+ myViewer->onWindowActivated((QMdiSubWindow*)parentWidget());
+
+ // In order to avoid frosen background in toolbars when it shown as a second view
+ QTimer::singleShot(20, parentWidget(), SLOT(setFocus()));
+
return true;
}
}
if (processViewPort(theEvent)) {
return true;
}
+ if (theEvent->type() == QEvent::KeyRelease) {
+ emit keyReleased(this, (QKeyEvent*) theEvent);
+ return true;
+ }
}
return QFrame::eventFilter(theObj, theEvent);
}
QMdiSubWindow* vw = myViewer->createView();
XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
aNewWnd->viewPort()->syncronizeWith(myViewPort);
+
emit viewCloned( vw );
+
+ // In order to avoid frosen background in toolbars when it shown as a second view
+ QTimer::singleShot(20, vw, SLOT(setFocus()));
}
void XGUI_ViewWindow::dumpView()
Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
if (aFmt == "PS")
- a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
+ a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
else if (aFmt == "EPS")
- a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
+ a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
else
aPicture.save( aFileName, aFmt.toLatin1() );
QApplication::restoreOverrideCursor();
myGripWgt->update();
myViewBar->update();
myWindowBar->update();
- //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
}
-/*void XGUI_ViewWindow::repaintToolBar()
-{
- QApplication::sync();
- myGripWgt->repaint();
- myViewBar->repaint();
- myWindowBar->repaint();
-}*/