#include <QApplication>
#include <QDesktopWidget>
#include <QtDebug>
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+#include <QSurfaceFormat>
+#endif
#include <stdio.h>
#include <stdlib.h>
if ( items.isEmpty() )
return;
- QList<QAction*> toRemove;
- for ( int i = 1; i < items.count(); i++ )
+ bool action = false;
+ for ( int i = 0; i < items.count(); i++ )
{
- if ( items[i]->isSeparator() && items[i - 1]->isSeparator() )
- toRemove.append( items[i] );
-
- if ( recursive && items[i]->menu() )
- simplifySeparators( items[i]->menu(), recursive );
+ QAction* a = items[i];
+ if ( a->isSeparator() ) {
+ a->setVisible(action);
+ action = false;
+ }
+ else if ( a->isVisible() ) {
+ action = true;
+ if ( recursive && a->menu() )
+ simplifySeparators( a->menu(), recursive );
+ }
}
- for ( QList<QAction*>::iterator it = toRemove.begin(); it != toRemove.end(); ++it )
- wid->removeAction( *it );
-
- items = wid->actions();
- if ( !items.isEmpty() && items[0]->isSeparator() )
- wid->removeAction( items[0] );
-
- items = wid->actions();
- if ( !items.isEmpty() && items[items.count() - 1]->isSeparator() )
- wid->removeAction( items[items.count() - 1] );
+ action = false;
+ for ( int i = items.count() - 1; i > 0; i-- ) {
+ QAction* a = items[i];
+ if ( a->isSeparator() ) {
+ a->setVisible(action);
+ action = false;
+ }
+ else if ( a->isVisible() )
+ action = true;
+ }
}
/*!
*/
bool Qtx::dos2unix( const QString& absName )
{
- FILE* src = ::fopen( absName.toLatin1(), "rb" );
+ FILE* src = ::fopen( absName.toUtf8(), "rb" );
if ( !src )
return false;
/* we'll use temporary file */
char temp[512] = { '\0' };
QString dir = Qtx::dir( absName );
- FILE* tgt = ::fopen( strcpy( temp, ::tempnam( dir.toLatin1(), "__x" ) ), "wb" );
+ FILE* tgt = ::fopen( strcpy( temp, ::tempnam( dir.toUtf8(), "__x" ) ), "wb" );
if ( !tgt )
return false;
break;
QString newStr;
- if ( ::getenv( envName.toLatin1() ) || mode == Always )
- newStr = QString( ::getenv( envName.toLatin1() ) );
+ if ( ::getenv( envName.toUtf8() ) || mode == Always )
+ newStr = QString( ::getenv( envName.toUtf8() ) );
if ( newStr.isNull() )
{
#endif // WIN32
+
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+/*!
+ \brief Set default QSurfaceFormat for an application.
+
+ This application property should be set before a creation of the QApplication.
+*/
+void Qtx::initDefaultSurfaceFormat()
+{
+ // Settings from Paraview:
+ // This piece of code was taken from QVTKOpenGLWidget::defaultFormat() method in
+ // order to avoid dependency of the SALOME_Session_Server on vtk libraries
+ QSurfaceFormat fmt;
+ fmt.setRenderableType(QSurfaceFormat::OpenGL);
+ fmt.setVersion(3, 2);
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+ fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ fmt.setRedBufferSize(1);
+ fmt.setGreenBufferSize(1);
+ fmt.setBlueBufferSize(1);
+ fmt.setDepthBufferSize(1);
+ fmt.setStencilBufferSize(0);
+ fmt.setAlphaBufferSize(1);
+ fmt.setStereo(false);
+ fmt.setSamples(0);
+
+ // Settings for OCCT viewer window:
+ fmt.setDepthBufferSize(16);
+ fmt.setStencilBufferSize(1);
+ // fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
+
+ QSurfaceFormat::setDefaultFormat(fmt);
+}
+#endif
+
/*!
\class Qtx::CmdLineArgs
\brief Get access to the command line arguments in the C-like manner.