QStringList aValuesList;
QList<QVariant> anIndicesList;
QIntList idList;
+ QIntList txtList;
// . Top-level "SALOME" preferences group <<start>>
int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
// pref->setItemProperty( "columns", 2, bgGroup );
aValuesList.clear();
anIndicesList.clear();
- QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList );
+ txtList.clear();
+ QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList, txtList );
foreach( int gid, idList ) anIndicesList << gid;
// .... -> 3D viewer background
int bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
LightApp_Preferences::Background, "OCCViewer", "background" );
pref->setItemProperty( "gradient_names", aValuesList, bgId );
pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
- pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
+ pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
+ pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
+ pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
pref->setItemProperty( "custom_enabled", false, bgId );
pref->setItemProperty( "image_formats", formats, bgId );
// .... -> XZ viewer background
LightApp_Preferences::Background, "OCCViewer", "xz_background" );
pref->setItemProperty( "gradient_names", aValuesList, bgId );
pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
- pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
+ pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
+ pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
+ pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
pref->setItemProperty( "custom_enabled", false, bgId );
pref->setItemProperty( "image_formats", formats, bgId );
// .... -> YZ viewer background
LightApp_Preferences::Background, "OCCViewer", "yz_background" );
pref->setItemProperty( "gradient_names", aValuesList, bgId );
pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
- pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
+ pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
+ pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
+ pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
pref->setItemProperty( "custom_enabled", false, bgId );
pref->setItemProperty( "image_formats", formats, bgId );
// .... -> XY viewer background
LightApp_Preferences::Background, "OCCViewer", "xy_background" );
pref->setItemProperty( "gradient_names", aValuesList, bgId );
pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
- pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
+ pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
+ pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
+ pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
pref->setItemProperty( "custom_enabled", false, bgId );
pref->setItemProperty( "image_formats", formats, bgId );
// ... "Background" group <<end>>
// .... -> background
aValuesList.clear();
anIndicesList.clear();
- formats = SVTK_Viewer::backgroundData( aValuesList, idList );
+ txtList.clear();
+ formats = SVTK_Viewer::backgroundData( aValuesList, idList, txtList );
foreach( int gid, idList ) anIndicesList << gid;
bgId = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
LightApp_Preferences::Background, "VTKViewer", "background" );
pref->setItemProperty( "gradient_names", aValuesList, bgId );
pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
- pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
+ pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
+ pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
+ pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
pref->setItemProperty( "custom_enabled", false, bgId );
pref->setItemProperty( "image_formats", formats, bgId );
// .... -> navigation mode
/*!Set desktop:*/
void LightApp_Application::setDesktop( SUIT_Desktop* desk )
{
- SUIT_Desktop* prev = desktop();
-
CAM_Application::setDesktop( desk );
if ( desk ) {
#include <Basics_OCCTVersion.hxx>
+// VSR: Uncomment below line to allow texture background support in OCC viewer
+// #define OCC_ENABLE_TEXTURED_BACKGROUND
+
/*!
Get data for supported background modes: gradient types, identifiers and supported image formats
*/
-QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList )
+QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
{
gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
Diagonal1Gradient << Diagonal2Gradient <<
Corner1Gradient << Corner2Gradient <<
Corner3Gradient << Corner4Gradient;
- return QString(); // temporarily, means support of all image formars!
+#if OCC_VERSION_LARGE > 0x06050200 // enabled since OCCT 6.5.3, since in previous version this functionality is buggy
+#ifdef OCC_ENABLE_TEXTURED_BACKGROUND
+ txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
+#endif
+#endif
+ return tr("BG_IMAGE_FILES");
}
/*!
// get supported gradient types
QStringList gradList;
- QIntList idList;
- QString formats = backgroundData( gradList, idList );
+ QIntList idList, txtList;
+ QString formats = backgroundData( gradList, idList, txtList );
// invoke dialog box
- Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box
- aView->background(), // initial background
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
+ aView, // parent for dialog box
+ txtList, // allowed texture modes
true, // enable solid color mode
- false, // disable texture mode
true, // enable gradient mode
false, // disable custom gradient mode
+ !txtList.isEmpty(), // enable/disable texture mode
gradList, // gradient names
idList, // gradient identifiers
formats ); // image formats
};
static QString Type() { return "OCCViewer"; }
- static QString backgroundData( QStringList&, QIntList& );
+ static QString backgroundData( QStringList&, QIntList&, QIntList& );
OCCViewer_Viewer( bool DisplayTrihedron = true);
virtual ~OCCViewer_Viewer();
oldView->View()->Deactivate();
view->SetBackgroundColor( oldView->BackgroundColor() );
}
-
+
if ( myDegenerated )
view->SetDegenerateModeOn();
else
if ( !myBackground.isValid() ) return;
// VSR: Important note on below code.
- // In OCCT (at least in version 6.5.2), things about the background drawing
+ // In OCCT (in version 6.5.2), things about the background drawing
// are not straightforward and not clearly understandable:
// - Horizontal gradient is drawn vertically (!), well ok, from top side to bottom one.
// - Vertical gradient is drawn horizontally (!), from right side to left one (!!!).
// (see V3d_View::SetBgGradientColors() function).
// - Also, it is impossible to draw texture image above the gradiented background (only above
// single-colored).
- // Well, all this is strange but we have to live with it.
+ // In OCCT 6.5.3 all above mentioned problems are fixed; so, above comment should be removed as soon
+ // as SALOME is migrated to OCCT 6.5.3. The same concerns #ifdef statements in the below code
switch ( myBackground.mode() ) {
- case Qtx::ImageBackground:
- {
- // VSR: Do not use this code until the bug is fixed - currently it is not possible to
- // clear the background texture image as soon as it is once set to the viewer.
- QString fileName;
- int textureMode = myBackground.texture( fileName );
- QFileInfo fi( fileName );
- if ( !fileName.isEmpty() && fi.exists() ) {
- // set texture image: file name and fill mode
- switch ( textureMode ) {
- case Qtx::CenterTexture:
- activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
- break;
- case Qtx::TileTexture:
- activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
- break;
- case Qtx::StretchTexture:
- activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
- break;
- default:
- break;
- }
- }
- break;
- }
case Qtx::ColorBackground:
{
QColor c = myBackground.color();
if ( c.isValid() ) {
// Unset texture should be done here
// ...
- // cancel gradient background (in OCC the only way is to set it to NONE type)
Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
+#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
+ activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
+ activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
+#else
+ // cancel gradient background (in OCC before v6.5.3 the only way to do this is to set it to NONE type passing arbitrary colors as parameters)
activeView()->SetBgGradientColors( qCol, qCol, Aspect_GFM_NONE );
+#endif
// then change background color
activeView()->SetBackgroundColor( qCol );
// update viewer
if ( !c2.isValid() ) c2 = c1;
Quantity_Color qCol1( c1.red()/255., c1.green()/255., c1.blue()/255., Quantity_TOC_RGB );
Quantity_Color qCol2( c2.red()/255., c2.green()/255., c2.blue()/255., Quantity_TOC_RGB );
+ activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
switch ( type ) {
case OCCViewer_Viewer::HorizontalGradient:
- // in OCCT, to draw horizontal gradient it's necessary to use Aspect_GFM_VER type
+#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
+#else
+ // in OCCT before v6.5.3, to draw horizontal gradient it's necessary to use Aspect_GFM_VER type
// and interchange the colors
activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_VER, Standard_True );
+#endif
break;
case OCCViewer_Viewer::VerticalGradient:
- // in OCCT, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type
+#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
+#else
+ // in OCCT before v6.5.3, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
+#endif
break;
case OCCViewer_Viewer::Diagonal1Gradient:
- // in OCCT, to draw 1st dialognal gradient it's necessary to use Aspect_GFM_DIAG2 type
+#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
+#else
+ // in OCCT before v6.5.3, to draw 1st dialognal gradient it's necessary to use Aspect_GFM_DIAG2 type
// and interchange the colors
activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_DIAG2, Standard_True );
+#endif
break;
case OCCViewer_Viewer::Diagonal2Gradient:
- // in OCCT, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type
+#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True );
+#else
+ // in OCCT before v6.5.3, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
+#endif
break;
case OCCViewer_Viewer::Corner1Gradient:
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
default:
break;
}
+#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
+ // VSR: In OCCT before v6.5.3 below code can't be used because of very ugly bug - it has been impossible to
+ // clear the background texture image as soon as it was once set to the viewer.
+ if ( myBackground.isTextureShown() ) {
+ QString fileName;
+ int textureMode = myBackground.texture( fileName );
+ QFileInfo fi( fileName );
+ if ( !fileName.isEmpty() && fi.exists() ) {
+ // set texture image: file name and fill mode
+ switch ( textureMode ) {
+ case Qtx::CenterTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
+ break;
+ case Qtx::TileTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
+ break;
+ case Qtx::StretchTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
+ break;
+ default:
+ break;
+ }
+ activeView()->Update();
+ }
+ }
+#endif
}
/*!
/*!
Inits 'rotation' transformation. [ protected ]
*/
-void OCCViewer_ViewPort3d::startRotation( int x, int y,
+void OCCViewer_ViewPort3d::startRotation( int x, int y,
int theRotationPointType,
const gp_Pnt& theSelectedPoint )
{
myDegenerated = activeView()->DegenerateModeIsOn();
activeView()->SetDegenerateModeOn();
if (myAnimate) activeView()->SetAnimationModeOn();
-
+
//double gx, gy, gz;
//double gx = activeView()->gx;
//activeView()->Gravity(gx,gy,gz);
-
+
switch ( theRotationPointType ) {
case OCCViewer_ViewWindow::GRAVITY:
activeView()->StartRotation( x, y, 0.45 );
break;
case OCCViewer_ViewWindow::SELECTED:
sx = x; sy = y;
-
+
double X,Y;
activeView()->Size(X,Y);
- rx = Standard_Real(activeView()->Convert(X));
- ry = Standard_Real(activeView()->Convert(Y));
-
- activeView()->Rotate( 0., 0., 0.,
- theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
+ rx = Standard_Real(activeView()->Convert(X));
+ ry = Standard_Real(activeView()->Convert(Y));
+
+ activeView()->Rotate( 0., 0., 0.,
+ theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
Standard_True );
-
+
Quantity_Ratio zRotationThreshold;
zRotation = Standard_False;
zRotationThreshold = 0.45;
/*!
Rotates the viewport. [ protected ]
*/
-void OCCViewer_ViewPort3d::rotate( int x, int y,
+void OCCViewer_ViewPort3d::rotate( int x, int y,
int theRotationPointType,
const gp_Pnt& theSelectedPoint )
{
case OCCViewer_ViewWindow::SELECTED:
double dx, dy, dz;
if( zRotation ) {
- dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) -
+ dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) -
atan2(sx-rx/2.,ry/2.-sy);
dx = dy = 0.;
}
dy = (sy - Standard_Real(y)) * M_PI/ry;
dz = 0.;
}
-
- activeView()->Rotate( dx, dy, dz,
+
+ activeView()->Rotate( dx, dy, dz,
theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
Standard_False );
break;
activeView()->Convert( x, y, X, Y, Z );
activeView()->Rotate( 0, 0, degrees * M_PI / 180., X, Y, Z );
emit vpTransformed( this );
-}
-
+}
+
/*!
Set axial scale to the view
*/
{
if ( activeView().IsNull() )
return;
-
+
activeView()->SetAxialScale( xScale, yScale, zScale );
emit vpTransformed( this );
}
return !myWindow.IsNull();
}
-void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view,
+void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view,
const Handle(Aspect_Window)& window)
{
if (!view.IsNull()) {
{
bool ok = false;
OCCViewer_ViewPort3d* vp3d = qobject_cast<OCCViewer_ViewPort3d*>( view );
- if ( vp3d ) {
+ if ( vp3d ) {
bool blocked = blockSignals( false );
Handle(V3d_View) aView3d = getView();
Handle(V3d_View) aRefView3d = vp3d->getView();
}
aView->Update();
}
- }
+ }
}
<source>OCC_IMAGE_FILES</source>
<translation>Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)</translation>
</message>
- <message>
- <source>OCC_BG_IMAGE_FILES</source>
- <translation>Images Files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
- </message>
<message>
<source>DSC_MAXIMIZE_VIEW</source>
<translation>Maximize view</translation>
<source>GT_FORTHCORNERGRADIENT</source>
<translation>Fourth corner gradient</translation>
</message>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
+ </message>
</context>
<context>
<name>OCCViewer_AxialScaleDlg</name>
<source>OCC_IMAGE_FILES</source>
<translation>Fichiers images (*.bmp *.png *.jpg *.jpeg *.eps *.ps)</translation>
</message>
- <message>
- <source>OCC_BG_IMAGE_FILES</source>
- <translation>Fichiers images (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
- </message>
<message>
<source>DSC_MAXIMIZE_VIEW</source>
<translation>Maximiser la vue</translation>
<source>GT_FORTHCORNERGRADIENT</source>
<translation>Gradient du quatrième coin</translation>
</message>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Fichiers images (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
+ </message>
</context>
<context>
<name>OCCViewer_AxialScaleDlg</name>
1. background type (enumerator, see Qtx::BackgroundMode)
2. texture image file name (string)
3. texture mode (enumerator, see Qtx::TextureMode)
- 4. first color (for simple gradient data) or solid color (for single-colored mode)
- 5. second color (for simple gradient data)
- 6. type of simple gradient (some integer identifier)
- 7. complex gradient data (for custom gradient mode)
+ 4. "show texture" flag (boolean)
+ 5. first color (for simple gradient data) or solid color (for single-colored mode)
+ 6. second color (for simple gradient data)
+ 7. type of simple gradient (some integer identifier)
+ 8. complex gradient data (for custom gradient mode)
Each sub-string consists of keyword/value couple, in form of "<keyword>=<value>".
Backward conversion can be done with stringToBackground() method.
const QString kwBgType = "bt";
const QString kwFileName = "fn";
const QString kwTextureMode = "tm";
+ const QString kwShowTexture = "ts";
const QString kwFirstColor = "c1";
const QString kwSecondColor = "c2";
const QString kwGrType = "gt";
Qtx::BackgroundMode bgMode = bgData.mode();
QString fileName;
Qtx::TextureMode textureMode = bgData.texture( fileName );
+ bool showTexture = bgData.isTextureShown();
QColor c1, c2;
int gradientType = bgData.gradient( c1, c2 );
const QGradient* gradient = bgData.gradient();
data << QString( "%1%2%3" ).arg( kwBgType ).arg( kwSep ).arg( (int)bgMode );
data << QString( "%1%2%3" ).arg( kwFileName ).arg( kwSep ).arg( fileName );
data << QString( "%1%2%3" ).arg( kwTextureMode ).arg( kwSep ).arg( (int)textureMode );
+ data << QString( "%1%2%3" ).arg( kwShowTexture ).arg( kwSep ).arg( showTexture ? "true" : "false" );
data << QString( "%1%2%3" ).arg( kwFirstColor ).arg( kwSep ).arg( Qtx::colorToString( c1 ) );
data << QString( "%1%2%3" ).arg( kwSecondColor ).arg( kwSep ).arg( Qtx::colorToString( c2 ) );
data << QString( "%1%2%3" ).arg( kwGrType ).arg( kwSep ).arg( gradientType );
The string should consist of several sub-strings separated by ';' symbol.
Each sub-string consists of keyword/value couple, in form of "<keyword>=<value>".
- The sub-strings can follow in arbitrary order, some keywords might be missed.
+ The sub-strings can follow in arbitrary order, some keywords can be missing.
The background data is described by the following values:
- background type (enumerator, see Qtx::BackgroundMode), keyword "bt"
- texture image file name (string), keyword "fn"
- texture mode (enumerator, see Qtx::TextureMode), keyword "tm"
+ - "show texture" flag (boolean), keyword "ts"
- first color (for simple gradient data) or solid color (for single-colored mode), keyword "c1"
- second color (for simple gradient data), keyword "c2"
- name of gradient type (string), keyword "gt"
const QString kwBgType = "bt";
const QString kwFileName = "fn";
const QString kwTextureMode = "tm";
+ const QString kwShowTexture = "ts";
const QString kwFirstColor = "c1";
const QString kwSecondColor = "c2";
const QString kwGrType = "gt";
QString bgMode = dmap.value( kwBgType, QString() );
QString fileName = dmap.value( kwFileName, QString() );
QString textureMode = dmap.value( kwTextureMode, QString() );
+ QString showTexture = dmap.value( kwShowTexture, QString() );
QString color1 = dmap.value( kwFirstColor, QString() );
QString color2 = dmap.value( kwSecondColor, QString() );
QString gradientType = dmap.value( kwGrType, QString() );
QString gradient = dmap.value( kwGrData, QString() );
- // try texture mode
- if ( !fileName.isEmpty() || !textureMode.isEmpty() ) {
+ // texture data
+ if ( !fileName.isEmpty() || !textureMode.isEmpty() || !showTexture.isEmpty() ) {
Qtx::TextureMode m = (Qtx::TextureMode)( stringToInt( textureMode, Qtx::CenterTexture,
Qtx::CenterTexture, Qtx::StretchTexture ) );
bgData.setTexture( fileName, m );
+ QStringList boolvars; boolvars << "true" << "yes" << "ok" << "1";
+ if ( boolvars.contains( showTexture.trimmed().toLower() ) )
+ bgData.setTextureShown( true );
}
QColor c1, c2;
// try color mode
bgData.setGradient( cg );
}
- // finally set backround mode
- Qtx::BackgroundMode m = (Qtx::BackgroundMode)( stringToInt( bgMode, Qtx::ColorBackground,
- Qtx::ImageBackground, Qtx::CustomGradientBackground ) );
+ // finally set background mode
+ Qtx::BackgroundMode m = (Qtx::BackgroundMode)( stringToInt( bgMode, Qtx::ColorBackground,
+ Qtx::NoBackground, Qtx::CustomGradientBackground ) );
bgData.setMode( m );
}
This class is used to store background data. Depending on the mode,
the background can be specified by:
- - image (by assigning the file name to be used as background texture), see setTexture()
+ - image (by assigning the file name to be used as background texture), see setTexture(), setTextureShown()
- single color (by assigning any color), see setColor()
- simple two-color gradient (with the gradient type id and two colors), see setGradient( int, const QColor&, const QColor& )
- complex gradient (by assigning arbitrary gradient data), see setGradient( const QGradient& )
+
The class stores all the data passed to it, so switching between different modes can be done
just by calling setMode() function.
+ \note Texture is used with combination of the background mode.
+
\note Two-color gradient is specified by two colors and integer identifier. The interpretation of
this identifier should be done in the calling code.
\code
Qtx::BackgroundData bg;
- bg.setTexture( "/data/images/background.png" ); // bg is switched to Qtx::ImageBackground mode
bg.setColor( QColor(100, 100, 100) ); // bg is switched to Qtx::ColorBackground mode
bg.setGradient( Qt::Horizontal, Qt::gray, Qt::white ); // bg is switched to Qtx::ColorBackground mode
QLinearGradient grad( 0,0,1,1 );
grad.setSpread( QGradient::PadSpread );
bg.setGradient( grad ); // bg is switched to Qtx::CustomGradientBackground mode
bg.setMode( Qtx::ColorBackground ); // bg is switched back to Qtx::ColorBackground mode
+ bg.setTexture( "/data/images/background.png" ); // specify texture (in the centered mode by default)
+ bg.setTextureShown( true ); // draw texture on the solid color background
\endcode
*/
Creates invalid background data.
*/
Qtx::BackgroundData::BackgroundData()
- : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false )
{
setMode( Qtx::NoBackground );
}
\param c color
*/
Qtx::BackgroundData::BackgroundData( const QColor& c )
- : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false )
{
setColor( c );
}
\note the interpretation of the gradient identifier should be done in the calling code
*/
Qtx::BackgroundData::BackgroundData( int type, const QColor& c1, const QColor& c2 )
- : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false )
{
setGradient( type, c1, c2 );
}
\param grad gradient data
*/
Qtx::BackgroundData::BackgroundData( const QGradient& grad )
- : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 )
+ : myTextureMode( Qtx::CenterTexture ), myGradientType( -1 ), myTextureShown( false )
{
setGradient( grad );
}
( myFileName == other.myFileName ) &&
( myColors == other.myColors ) &&
( myGradientType == other.myGradientType ) &&
- ( myGradient == other.myGradient );
+ ( myGradient == other.myGradient ) &&
+ ( myTextureShown == other.myTextureShown );
}
/*!
/*!
\brief Get file name used as a texture image
\return path to the texture image file
- \sa setTexture(), mode()
+ \sa setTexture(), setTextureShown()
*/
Qtx::TextureMode Qtx::BackgroundData::texture( QString& fileName ) const
{
}
/*!
- \brief Set file name to be used as a texture image and switch to the Qtx::ImageBackground mode
+ \brief Set file name to be used as a texture image.
+
+ \note To show texture image on the background it is necessary to call additionally
+ setTextureShown() method.
+
\param fileName path to the texture image file name
\param m texture mode (Qtx::CenterTexture by default)
- \sa texture(), mode()
+ \sa texture(), setTextureShown()
*/
void Qtx::BackgroundData::setTexture( const QString& fileName, const Qtx::TextureMode m )
{
myFileName = fileName;
myTextureMode = m;
- setMode( Qtx::ImageBackground );
+}
+
+/*!
+ \brief Check if "show texture" flag is switched on
+ \return \c true if "show texture" flag is set or \c false otherwise
+ \sa setTextureShown(), texture()
+*/
+bool Qtx::BackgroundData::isTextureShown() const
+{
+ return myTextureShown;
+}
+
+/*!
+ \brief Specify if texture should be shown on the background or no.
+ \param on \c true if texture should be shown or \c false otherwise
+ \sa isTextureShown(), texture()
+*/
+void Qtx::BackgroundData::setTextureShown( bool on )
+{
+ myTextureShown = on;
}
/*!
//! Background mode
typedef enum {
NoBackground, // no (invalid) background data
- ImageBackground, // image (texture)
ColorBackground, // single color
SimpleGradientBackground, // simple two-color gradient
CustomGradientBackground // custom (complex) gradient
TextureMode texture( QString& ) const;
void setTexture( const QString&, TextureMode = Qtx::CenterTexture );
+ bool isTextureShown() const;
+ void setTextureShown( bool );
QColor color() const;
void setColor( const QColor& );
void setGradient( const QGradient& );
private:
- BackgroundMode myMode;
- TextureMode myTextureMode;
- QString myFileName;
- QColorList myColors;
- int myGradientType;
- QGradient myGradient;
+ BackgroundMode myMode;
+ TextureMode myTextureMode;
+ QString myFileName;
+ QColorList myColors;
+ int myGradientType;
+ QGradient myGradient;
+ bool myTextureShown;
};
static QString toQString( const char*, const int = -1 );
#include "QtxBackgroundTool.h"
#include "QtxColorButton.h"
+#include <QCheckBox>
#include <QComboBox>
#include <QFileDialog>
#include <QHBoxLayout>
/*!
\brief Constructor.
+
+ Creates a background data widget with horizontal orientation.
+
\param parent parent widget
*/
QtxBackgroundTool::QtxBackgroundTool( QWidget* parent )
- : QWidget( parent ), myLastGradient( -1 )
+ : QWidget( parent ), myTextureAllowed( true ), myLastGradient( -1 )
{
init( Qt::Horizontal );
}
/*!
\brief Constructor.
+
+ Creates a background data widget with specified orientation.
+
\param o widget orientation
\param parent parent widget
*/
QtxBackgroundTool::QtxBackgroundTool( Qt::Orientation o, QWidget* parent )
- : QWidget( parent ), myLastGradient( -1 )
+ : QWidget( parent ), myTextureAllowed( true ), myLastGradient( -1 )
{
init( o );
}
{
// mode combo box
myModeCombo = new QComboBox( this );
- // sub-widgets container
- myContainer = new QStackedWidget( this );
+ // color / gradient sub-widgets container
+ myCContainer = new QStackedWidget( this );
+ // texture sub-widgets container
+ myTContainer = new QWidget( this );
QWidget* wrap;
QHBoxLayout* wrapLayout;
// add image controls
- wrap = new QWidget( this );
- wrapLayout = new QHBoxLayout( wrap );
+ wrapLayout = new QHBoxLayout( myTContainer );
wrapLayout->setMargin( 0 );
wrapLayout->setSpacing( 5 );
- myFileName = new QLineEdit( wrap );
- myBrowseBtn = new QPushButton( tr( "Browse..." ), wrap );
- myTextureMode = new QComboBox( wrap );
+ myTextureCheck = new QCheckBox( tr( "Image" ), myTContainer );
+ myFileName = new QLineEdit( myTContainer );
+ myFileName->setMinimumWidth(100);
+ myBrowseBtn = new QPushButton( tr( "Browse..." ), myTContainer );
+ myTextureMode = new QComboBox( myTContainer );
+ wrapLayout->addWidget( myTextureCheck );
wrapLayout->addWidget( myFileName );
wrapLayout->addWidget( myBrowseBtn );
wrapLayout->addWidget( myTextureMode );
- myContainer->addWidget( wrap ); // Image
+ wrapLayout->setStretchFactor(myFileName, 10);
// add color controls
wrap = new QWidget( this );
wrapLayout = new QHBoxLayout( wrap );
mySecondColor = new QtxColorButton( wrap );
wrapLayout->addWidget( myFirstColor );
wrapLayout->addWidget( mySecondColor );
- myContainer->addWidget( wrap ); // Color
+ wrapLayout->setStretchFactor(myFirstColor, 5);
+ wrapLayout->setStretchFactor(mySecondColor, 5);
+ myCContainer->addWidget( wrap ); // Color
// add gradient controls ... NOT IMPLEMENTED YET
wrap = new QWidget( this );
wrapLayout = new QHBoxLayout( wrap );
QLabel* foo = new QLabel( tr( "Not implemented yet" ), wrap );
foo->setAlignment( Qt::AlignCenter );
wrapLayout->addWidget( foo );
- myContainer->addWidget( wrap ); // Gradient
+ myCContainer->addWidget( wrap ); // Gradient
// initialize widget
myFirstColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
mySecondColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
- myTextureMode->addItem( tr( "Center" ), Qtx::CenterTexture );
- myTextureMode->addItem( tr( "Tile" ), Qtx::TileTexture );
- myTextureMode->addItem( tr( "Stretch" ), Qtx::StretchTexture );
connect( myModeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateState() ) );
+ connect( myTextureCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateState() ) );
connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( browse() ) );
- setModeAllowed( Qtx::ImageBackground );
setModeAllowed( Qtx::ColorBackground );
setModeAllowed( Qtx::SimpleGradientBackground );
setModeAllowed( Qtx::CustomGradientBackground );
+ setTextureModeAllowed( Qtx::CenterTexture );
+ setTextureModeAllowed( Qtx::TileTexture );
+ setTextureModeAllowed( Qtx::StretchTexture );
+ setTextureAllowed();
setImageFormats( QString() );
setOrientation( o );
}
// get currently selected mode
int id = myModeCombo->itemData( idx, TypeRole ).toInt();
// texture data
- if ( isModeAllowed( Qtx::ImageBackground ) ) {
+ if ( isTextureAllowed() && myTextureMode->currentIndex() != -1 ) {
bgData.setTexture( myFileName->text().trimmed(),
Qtx::TextureMode( myTextureMode->itemData( myTextureMode->currentIndex() ).toInt() ) );
+ bgData.setTextureShown( myTextureCheck->isChecked() );
}
// single-color data
if ( isModeAllowed( Qtx::ColorBackground ) ) {
int gtype = bgData.gradient( c1, c2 );
QString fileName;
int tmode = bgData.texture( fileName );
+ bool tshown = bgData.isTextureShown();
+
// texture data
myFileName->setText( fileName );
- myTextureMode->setCurrentIndex( tmode );
+ for ( int i = 0; i < myTextureMode->count(); i++ ) {
+ if ( myTextureMode->itemData( i ).toInt() == tmode ) {
+ myTextureMode->setCurrentIndex( i );
+ break;
+ }
+ }
+ myTextureCheck->setChecked( tshown );
+
// color / simple gradient data
myFirstColor->setColor( c1 );
mySecondColor->setColor( c2 );
+
// gradient data
// ... NOT IMPLEMENTED YET
- // set current index
+ // set current mode index
int idx = -1;
for ( int i = 0; i < myModeCombo->count() && idx == -1; i++ ) {
int im = myModeCombo->itemData( i, TypeRole ).toInt();
if ( it == gtype ) idx = i;
}
// for other modes we just check mode itself
- else if ( im == m ) idx = i;
+ else if ( im == m ) {
+ idx = i;
+ }
}
+ // if background data is invalid, we set-up widget to the first available type
+ if ( idx == -1 && myModeCombo->count() > 0 ) idx = 0;
myModeCombo->setCurrentIndex( idx );
}
*/
void QtxBackgroundTool::setGradients( const QStringList& gradList, const QIntList& idList )
{
- myGradients = gradList;
- myGradientsIds = idList;
- myLastGradient = -1;
- Qtx::BackgroundData d = data(); // store current state
+ Qtx::BackgroundData d = data(); // get current state
+ myGradients = gradList; // store new gradient data
+ myGradientsIds = idList; // ...
+ myLastGradient = -1; // ...
internalUpdate(); // re-initialize
setData( d ); // restore current state (if possible)
}
/*!
\brief Enable / disable specific background mode
\param mode background mode
- \param on enable / disable flag
+ \param on enable / disable flag (\c true by default)
\sa isModeAllowed()
*/
void QtxBackgroundTool::setModeAllowed( Qtx::BackgroundMode mode, bool on )
if ( mode == Qtx::CustomGradientBackground )
return; // NOT IMPLEMENTED YET //
- myTypesAllowed[ mode ] = on;
- Qtx::BackgroundData d = data(); // store current state
- internalUpdate(); // re-initialize
- setData( d ); // restore current state (if possible)
+ if ( isModeAllowed( mode ) != on ) {
+ Qtx::BackgroundData d = data(); // get current state
+ myTypesAllowed[ mode ] = on; // store new background mode state
+ internalUpdate(); // re-initialize
+ setData( d ); // restore current state (if possible)
+ }
+}
+
+/*!
+ \brief Check if specific texture mode is allowed
+ \param mode texture mode
+ \return \c true if specified texture mode is enabled or \c false otherwise
+ \sa setTextureModeAllowed(), setTextureAllowed()
+*/
+bool QtxBackgroundTool::isTextureModeAllowed( Qtx::TextureMode mode ) const
+{
+ return myTextureTypesAllowed.contains( mode ) ? myTextureTypesAllowed[ mode ] : false;
+}
+
+/*!
+ \brief Enable / disable specific texture mode
+ \param mode texture mode
+ \param on enable / disable flag (\c true by default)
+ \sa isTextureModeAllowed(), setTextureAllowed()
+*/
+void QtxBackgroundTool::setTextureModeAllowed( Qtx::TextureMode mode, bool on )
+{
+ if ( isTextureModeAllowed( mode ) != on ) {
+ Qtx::BackgroundData d = data(); // get current state
+ myTextureTypesAllowed[ mode ] = on; // store new texture mode
+ internalUpdate(); // re-initialize
+ setData( d ); // restore current state (if possible)
+ }
+}
+
+/*!
+ \brief Check if texture controls are allowed (shown)
+ \return \c true if texture controls are enabled or \c false otherwise
+ \sa setTextureAllowed(), setTextureModeAllowed()
+*/
+bool QtxBackgroundTool::isTextureAllowed() const
+{
+ return myTextureAllowed;
+}
+
+/*!
+ \brief Enable / disable texture controls
+ \param on enable / disable flag (\c true by default)
+ \sa isTextureAllowed(), setTextureModeAllowed()
+*/
+void QtxBackgroundTool::setTextureAllowed( bool on )
+{
+ if ( myTextureAllowed != on ) {
+ myTextureAllowed = on;
+ setOrientation( orientation() );
+ }
}
/*!
l->setMargin( 0 );
l->setSpacing( 5 );
l->addWidget( myModeCombo );
- l->addWidget( myContainer );
+ l->addWidget( myCContainer );
+ myTContainer->setVisible( isTextureAllowed() );
+ if ( isTextureAllowed() )
+ l->addWidget( myTContainer );
delete layout();
setLayout( l );
}
void QtxBackgroundTool::internalUpdate()
{
myModeCombo->clear();
- if ( isModeAllowed( Qtx::ImageBackground ) ) {
- myModeCombo->addItem( tr( "Image" ) );
- int idx = myModeCombo->count()-1;
- myModeCombo->setItemData( idx, (int)Qtx::ImageBackground, TypeRole );
- }
if ( isModeAllowed( Qtx::ColorBackground ) ) {
- if ( myModeCombo->count() > 0 )
- myModeCombo->insertSeparator( myModeCombo->count() );
myModeCombo->addItem( tr( "Single Color" ) );
- int idx = myModeCombo->count()-1;
- myModeCombo->setItemData( idx, (int)Qtx::ColorBackground, TypeRole );
+ myModeCombo->setItemData( 0, (int)Qtx::ColorBackground, TypeRole );
}
if ( isModeAllowed( Qtx::SimpleGradientBackground ) ) {
- if ( myGradients.count() > 0 && myModeCombo->count() > 0 )
- myModeCombo->insertSeparator( myModeCombo->count() );
+// if ( myGradients.count() > 0 && myModeCombo->count() > 0 )
+// myModeCombo->insertSeparator( myModeCombo->count() );
for ( int i = 0; i < myGradients.count(); i++ ) {
myModeCombo->addItem( myGradients[i] );
int idx = myModeCombo->count()-1;
}
}
if ( isModeAllowed( Qtx::CustomGradientBackground ) ) {
- if ( myModeCombo->count() > 0 )
- myModeCombo->insertSeparator( myModeCombo->count() );
+// if ( myModeCombo->count() > 0 )
+// myModeCombo->insertSeparator( myModeCombo->count() );
myModeCombo->addItem( tr( "Custom" ) );
int idx = myModeCombo->count()-1;
myModeCombo->setItemData( idx, (int)Qtx::CustomGradientBackground, TypeRole );
}
+
+ myTextureMode->clear();
+ if ( isTextureModeAllowed( Qtx::CenterTexture ) )
+ myTextureMode->addItem( tr( "Center" ), Qtx::CenterTexture );
+ if ( isTextureModeAllowed( Qtx::TileTexture ) )
+ myTextureMode->addItem( tr( "Tile" ), Qtx::TileTexture );
+ if ( isTextureModeAllowed( Qtx::StretchTexture ) )
+ myTextureMode->addItem( tr( "Stretch" ), Qtx::StretchTexture );
+
updateState();
}
if ( idx >= 0 ) {
id = myModeCombo->itemData( idx, TypeRole ).toInt();
switch( id ) {
- case Qtx::ImageBackground:
- myContainer->setCurrentIndex( Image );
- break;
case Qtx::ColorBackground:
+ myCContainer->setCurrentIndex( Color );
+ break;
case Qtx::SimpleGradientBackground:
- myContainer->setCurrentIndex( Color );
+ myCContainer->setCurrentIndex( Color );
myLastGradient = myModeCombo->itemData( idx, IdRole ).toInt();
break;
case Qtx::CustomGradientBackground:
- myContainer->setCurrentIndex( Gradient );
+ myCContainer->setCurrentIndex( Gradient );
break;
}
}
myModeCombo->setEnabled( idx >= 0 );
- myContainer->setEnabled( idx >= 0 );
+ myCContainer->setEnabled( idx >= 0 );
mySecondColor->setEnabled( id == Qtx::SimpleGradientBackground );
+ myTContainer->setEnabled( idx >= 0 );
+ myFileName->setEnabled( myTextureCheck->isChecked() );
+ myBrowseBtn->setEnabled( myTextureCheck->isChecked() );
+ myTextureMode->setEnabled( myTextureCheck->isChecked() );
}
/*!
: QtxDialog( parent, true, true, OK | Cancel )
{
init();
+ setData( bgData );
}
/*!
setDialogFlags( SetFocus );
// move "Cancel" button to the right
setButtonPosition( Right, Cancel );
+ // set OK button to be default (activated by Enter key)
+ qobject_cast<QPushButton*>( button( OK ) )->setDefault( true );
// main layout
QVBoxLayout* main = new QVBoxLayout( mainFrame() );
myTool->setModeAllowed( mode, on );
}
+/*!
+ \brief Enable / disable texture controls
+ \param on enable / disable flag
+ \sa setTextureModeAllowed()
+*/
+void QtxBackgroundDialog::setTextureAllowed( bool on )
+{
+ myTool->setTextureAllowed( on );
+}
+
+/*!
+ \brief Enable / disable specific texture mode
+ \param mode texture mode
+ \param on enable / disable flag (\c true by default)
+ \sa setTextureAllowed()
+*/
+void QtxBackgroundDialog::setTextureModeAllowed( Qtx::TextureMode mode, bool on )
+{
+ myTool->setTextureModeAllowed( mode, on );
+}
+
/*!
\brief Set allowed image formats
\param formats image formats
/*!
\brief This is a convenience static function that returns an background data selected by the user.
If the user presses Cancel, it returns an invalid background data.
+
+ By default:
+ - all background modes are enabled
+ - texture controls are shown
+ - all texture modes are enabled
+ - simple gradient types list is empty
+ - all image formats are supported
+
+ To customize the dialog box behavior, initialize it passing the corresponding options to the function.
+
+ \param bgData initial background data
+ \param parent parent widget
+ \param enableSolidColor "enable solid colored background mode" flag
+ \param enableGradient "enable simple gradient background mode" flag
+ \param enableCustom "enable custom gradient background mode" flag
+ \param enableTexture "show texture controls" flag
+ \param gradList list of simple gradients names
+ \param idList list of simple gradients identifiers
+ \param formats image formats
+ \return resulting background data chosen by the user or invalid data if users cancels operation
*/
-Qtx::BackgroundData QtxBackgroundDialog::getBackground( QWidget* parent,
- const Qtx::BackgroundData& bgData,
+Qtx::BackgroundData QtxBackgroundDialog::getBackground( const Qtx::BackgroundData& bgData,
+ QWidget* parent,
bool enableSolidColor,
+ bool enableGradient,
+ bool enableCustom,
bool enableTexture,
+ const QStringList& gradList,
+ const QIntList& idList,
+ const QString& formats )
+{
+ QtxBackgroundDialog dlg( parent );
+ dlg.setTextureAllowed( enableTexture );
+ dlg.setModeAllowed( Qtx::ColorBackground, enableSolidColor );
+ dlg.setModeAllowed( Qtx::SimpleGradientBackground, enableGradient );
+ dlg.setModeAllowed( Qtx::CustomGradientBackground, enableCustom );
+ dlg.setGradients( gradList, idList );
+ dlg.setImageFormats( formats );
+ dlg.setData( bgData );
+ Qtx::BackgroundData res;
+ int rc = dlg.exec();
+ if ( rc ) res = dlg.data();
+ return res;
+}
+
+/*!
+ \brief This is a convenience static function that returns an background data selected by the user.
+ If the user presses Cancel, it returns an invalid background data.
+
+ By default:
+ - all background modes are enabled
+ - texture controls are shown
+ - all texture modes are disabled
+ - simple gradient types list is empty
+ - all image formats are supported
+
+ To customize the dialog box behavior, initialize it passing the corresponding options to the function.
+
+ \param bgData initial background data
+ \param parent parent widget
+ \param tmList allowed texture modes
+ \param enableSolidColor "enable solid colored background mode" flag
+ \param enableGradient "enable simple gradient background mode" flag
+ \param enableCustom "enable custom gradient background mode" flag
+ \param enableTexture "show texture controls" flag
+ \param gradList list of simple gradients names
+ \param idList list of simple gradients identifiers
+ \param formats image formats
+ \return resulting background data chosen by the user or invalid data if users cancels operation
+*/
+Qtx::BackgroundData QtxBackgroundDialog::getBackground( const Qtx::BackgroundData& bgData,
+ QWidget* parent,
+ const QIntList& tmList,
+ bool enableSolidColor,
bool enableGradient,
bool enableCustom,
+ bool enableTexture,
const QStringList& gradList,
const QIntList& idList,
const QString& formats )
{
QtxBackgroundDialog dlg( parent );
- dlg.setModeAllowed( Qtx::ImageBackground, enableTexture );
+ dlg.setTextureAllowed( enableTexture );
+ for ( int i = Qtx::CenterTexture; i <= Qtx::StretchTexture; i++ )
+ dlg.setTextureModeAllowed( (Qtx::TextureMode)i, tmList.contains( i ) );
dlg.setModeAllowed( Qtx::ColorBackground, enableSolidColor );
dlg.setModeAllowed( Qtx::SimpleGradientBackground, enableGradient );
dlg.setModeAllowed( Qtx::CustomGradientBackground, enableCustom );
#include <QWidget>
#include <QMap>
+class QCheckBox;
class QComboBox;
class QStackedWidget;
class QLineEdit;
class QTX_EXPORT QtxBackgroundTool : public QWidget
{
- enum { Image, Color, Gradient };
+ enum { Color, Gradient };
enum { TypeRole = Qt::UserRole, IdRole };
Q_OBJECT
bool isModeAllowed( Qtx::BackgroundMode ) const;
void setModeAllowed( Qtx::BackgroundMode, bool = true );
+ bool isTextureModeAllowed( Qtx::TextureMode ) const;
+ void setTextureModeAllowed( Qtx::TextureMode, bool = true );
+
+ bool isTextureAllowed() const;
+ void setTextureAllowed( bool = true );
+
QString imageFormats() const;
void setImageFormats( const QString& );
private:
QComboBox* myModeCombo;
- QStackedWidget* myContainer;
+ QStackedWidget* myCContainer;
+ QWidget* myTContainer;
+ QCheckBox* myTextureCheck;
QLineEdit* myFileName;
QPushButton* myBrowseBtn;
QComboBox* myTextureMode;
QtxColorButton* mySecondColor;
QStringList myGradients;
QIntList myGradientsIds;
+ bool myTextureAllowed;
QMap<int, bool> myTypesAllowed;
+ QMap<int, bool> myTextureTypesAllowed;
QString myImageFormats;
int myLastGradient;
};
void setData( const Qtx::BackgroundData& );
Qtx::BackgroundData data() const;
- static Qtx::BackgroundData getBackground( QWidget* = 0,
- const Qtx::BackgroundData& = Qtx::BackgroundData(),
+ static Qtx::BackgroundData getBackground( const Qtx::BackgroundData& = Qtx::BackgroundData(),
+ QWidget* = 0,
bool = true, bool = true, bool = true, bool = true,
const QStringList& = QStringList(),
const QIntList& = QIntList(),
const QString& = QString() );
+ static Qtx::BackgroundData getBackground( const Qtx::BackgroundData&,
+ QWidget*,
+ const QIntList&,
+ bool = true, bool = true, bool = true, bool = true,
+ const QStringList& = QStringList(),
+ const QIntList& = QIntList(),
+ const QString& = QString() );
+
void setGradients( const QStringList&, const QIntList& = QIntList() );
void setModeAllowed( Qtx::BackgroundMode, bool = true );
+ void setTextureAllowed( bool = true );
+ void setTextureModeAllowed( Qtx::TextureMode, bool = true );
void setImageFormats( const QString& );
private:
- simple two-color gradient
- complex custom gradient (NOT IMPLEMENTED YET)
- Allows background modes can be specified using setModeAllowed() method.
+ Allowed background modes can be specified using setModeAllowed() method.
+ Texture modes can be enabled/disabled using setTextureModeAllowed() method.
+ Also, showing texture controls can be enabled/disabled by means of
+ setTextureAllowed() method.
Verical or horizontal orientation of the widget can be chosen via setOrientation()
method (default orientation is horizontal).
Simple gradient types can be specified using setGradients() method.
+
\sa Qtx::BackgroundData, QtxBackgroundTool
*/
myBgTool->setModeAllowed( mode, on );
}
+/*!
+ \brief Check if specific texture mode is allowed
+ \param mode texture mode
+ \return \c true if specified texture mode is enabled or \c false otherwise
+ \sa setTextureModeAllowed(), setTextureAllowed()
+*/
+bool QtxPagePrefBackgroundItem::isTextureModeAllowed( Qtx::TextureMode mode ) const
+{
+ return myBgTool->isTextureModeAllowed( mode );
+}
+
+/*!
+ \brief Enable / disable specific texture mode
+ \param mode texture mode
+ \param on enable / disable flag (\c true by default)
+ \sa isTextureModeAllowed(), setTextureAllowed()
+*/
+void QtxPagePrefBackgroundItem::setTextureModeAllowed( Qtx::TextureMode mode, bool on )
+{
+ myBgTool->setTextureModeAllowed( mode, on );
+}
+
+/*!
+ \brief Check if texture controls are allowed (shown)
+ \return \c true if texture controls are enabled or \c false otherwise
+ \sa setTextureAllowed(), setTextureModeAllowed()
+*/
+bool QtxPagePrefBackgroundItem::isTextureAllowed() const
+{
+ return myBgTool->isTextureAllowed();
+}
+
+/*!
+ \brief Enable / disable texture controls
+ \param on enable / disable flag (\c true by default)
+ \sa isTextureAllowed(), setTextureModeAllowed()
+*/
+void QtxPagePrefBackgroundItem::setTextureAllowed( bool on )
+{
+ myBgTool->setTextureAllowed( on );
+}
+
/*!
\brief Get allowed image formats
\return image formats
QVariant QtxPagePrefBackgroundItem::optionValue( const QString& name ) const
{
if ( name == "texture_enabled" )
- return isModeAllowed( Qtx::ImageBackground );
+ return isTextureAllowed();
else if ( name == "color_enabled" )
return isModeAllowed( Qtx::ColorBackground );
else if ( name == "gradient_enabled" )
return isModeAllowed( Qtx::SimpleGradientBackground );
else if ( name == "custom_enabled" )
return isModeAllowed( Qtx::CustomGradientBackground );
+ else if ( name == "texture_center_enabled" )
+ return isTextureModeAllowed( Qtx::CenterTexture );
+ else if ( name == "texture_tile_enabled" )
+ return isTextureModeAllowed( Qtx::TileTexture );
+ else if ( name == "texture_stretch_enabled" )
+ return isTextureModeAllowed( Qtx::StretchTexture );
else if ( name == "orientation" )
return orientation();
else if ( name == "image_formats" )
{
if ( name == "texture_enabled" ) {
if ( val.canConvert( QVariant::Bool ) )
- setModeAllowed( Qtx::ImageBackground, val.toBool() );
+ setTextureAllowed( val.toBool() );
}
else if ( name == "color_enabled" ) {
if ( val.canConvert( QVariant::Bool ) )
if ( val.canConvert( QVariant::Bool ) )
setModeAllowed( Qtx::CustomGradientBackground, val.toBool() );
}
+ else if ( name == "texture_center_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setTextureModeAllowed( Qtx::CenterTexture, val.toBool() );
+ }
+ else if ( name == "texture_tile_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setTextureModeAllowed( Qtx::TileTexture, val.toBool() );
+ }
+ else if ( name == "texture_stretch_enabled" ) {
+ if ( val.canConvert( QVariant::Bool ) )
+ setTextureModeAllowed( Qtx::StretchTexture, val.toBool() );
+ }
else if ( name == "orientation" ) {
if ( val.canConvert( QVariant::Int ) )
setOrientation( (Qt::Orientation)val.toInt() );
void setGradients( const QStringList&, const QIntList& = QIntList() );
bool isModeAllowed( Qtx::BackgroundMode ) const;
- void setModeAllowed( Qtx::BackgroundMode, bool = true );
+ void setModeAllowed( Qtx::BackgroundMode, bool );
+
+ bool isTextureModeAllowed( Qtx::TextureMode ) const;
+ void setTextureModeAllowed( Qtx::TextureMode, bool );
+
+ bool isTextureAllowed() const;
+ void setTextureAllowed( bool );
QString imageFormats() const;
void setImageFormats( const QString& );
#include "QtxActionToolMgr.h"
#include "QtxBackgroundTool.h"
+// VSR: Uncomment below line to allow texture background support in VTK viewer
+// #define VTK_ENABLE_TEXTURED_BACKGROUND
+
+
// in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
// SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
// SALOMEDS::StudyManager - no linkage with SalomeApp.
}
/*! Get data for supported background modes: gradient types, identifiers and supported image formats */
-QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList )
+QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
{
- gradList << tr( "GT_VERTICALGRADIENT" );
- idList << VerticalGradient;
- return QString(); // temporarily, means support of all image formats!
+ gradList << tr( "GT_VERTICALGRADIENT" ); // only vertical type of gradient is supported
+ idList << VerticalGradient; // only vertical type of gradient is supported
+#ifdef VTK_ENABLE_TEXTURED_BACKGROUND
+ txtList << Qtx::StretchTexture; // only stretch texture mode is supported
+#endif
+ return tr("BG_IMAGE_FILES");
}
//! Get background color of the viewer [obsolete]
// get supported gradient types
QStringList gradList;
- QIntList idList;
- QString formats = backgroundData( gradList, idList );
+ QIntList idList, txtList;
+ QString formats = backgroundData( gradList, idList, txtList );
// invoke dialog box
- Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box
- aView->background(), // initial background
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
+ aView, // parent for dialog box
+ txtList, // allowed texture modes
true, // enable solid color mode
- false, // disable texture mode
true, // enable gradient mode
false, // disable custom gradient mode
+ !txtList.isEmpty(), // enable texture mode
gradList, // gradient names
idList, // gradient identifiers
formats ); // image formats
//! Define string representation of the viewer type
static QString Type() { return "VTKViewer"; }
- static QString backgroundData( QStringList&, QIntList& );
+ static QString backgroundData( QStringList&, QIntList&, QIntList& );
SVTK_Viewer();
virtual ~SVTK_Viewer();
*/
void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
{
- bool ok = bgData.isValid();
-
- switch ( bgData.mode() ) {
- case Qtx::ImageBackground:
- {
+ bool ok = false;
+
+ if ( bgData.isValid() ) {
+ switch ( bgData.mode() ) {
+ case Qtx::ColorBackground:
+ {
+ QColor c = bgData.color();
+ if ( c.isValid() ) {
+ // show solid-colored background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ getRenderer()->SetBackground( c.red()/255.0,
+ c.green()/255.0,
+ c.blue()/255.0 ); // set background color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = bgData.gradient( c1, c2 );
+ // VSR: Currently, only vertical gradient is supported by VTK.
+ // In future, switch operator might be added here to process different supported gradient types.
+ if ( c1.isValid() && type == SVTK_Viewer::VerticalGradient ) {
+ if ( !c2.isValid() ) c2 = c1;
+ // show two-color gradient background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( true ); // switch to gradient mode
+ // VSR: In VTK, gradient is colored from bottom to top:
+ // - top color is set via SetBackground2()
+ // - bottom color is set via SetBackground()
+ // So, we reverse colors, to draw gradient from top to bottom instead.
+ getRenderer()->SetBackground( c2.red()/255.0,
+ c2.green()/255.0,
+ c2.blue()/255.0 ); // set first gradient color
+ getRenderer()->SetBackground2( c1.red()/255.0,
+ c1.green()/255.0,
+ c1.blue()/255.0 ); // set second gradient color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::CustomGradientBackground:
+ {
+ // NOT IMPLEMENTED YET
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ // .........
+ break;
+ }
+ default:
+ break;
+ }
+ if ( bgData.isTextureShown() ) {
QString fileName;
int textureMode = bgData.texture( fileName );
QFileInfo fi( fileName );
// create texture
aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
aReader->Update();
-
+
vtkTexture* aTexture = vtkTexture::New();
vtkImageMapToColors* aMap = 0;
vtkAlgorithmOutput* anOutput;
// special processing for BMP reader
vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
if ( aBMPReader ) {
- // Special processing for BMP file
- aBMPReader->SetAllow8BitBMP(1);
+ // Special processing for BMP file
+ aBMPReader->SetAllow8BitBMP(1);
- aMap = vtkImageMapToColors::New();
- aMap->SetInputConnection( aBMPReader->GetOutputPort() );
- aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
- aMap->SetOutputFormatToRGB();
+ aMap = vtkImageMapToColors::New();
+ aMap->SetInputConnection( aBMPReader->GetOutputPort() );
+ aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
+ aMap->SetOutputFormatToRGB();
- anOutput = aMap->GetOutputPort();
+ anOutput = aMap->GetOutputPort();
}
else {
- }
+ }
*/
anOutput = aReader->GetOutputPort( 0 );
aTexture->SetInputConnection( anOutput );
ok = true;
}
}
- break;
- }
- case Qtx::ColorBackground:
- {
- QColor c = bgData.color();
- if ( c.isValid() ) {
- // show solid-colored background
- getRenderer()->SetTexturedBackground( false ); // cancel texture mode
- getRenderer()->SetGradientBackground( false ); // cancel gradient mode
- getRenderer()->SetBackground( c.red()/255.0,
- c.green()/255.0,
- c.blue()/255.0 ); // set background color
- ok = true;
- }
- break;
- }
- case Qtx::SimpleGradientBackground:
- {
- QColor c1, c2;
- int type = bgData.gradient( c1, c2 );
- // VSR: Currently, only vertical gradient is supported by VTK.
- // In future, switch operator might be added here to process different supported gradient types.
- if ( c1.isValid() && type == SVTK_Viewer::VerticalGradient ) {
- if ( !c2.isValid() ) c2 = c1;
- // show two-color gradient background
- getRenderer()->SetTexturedBackground( false ); // cancel texture mode
- getRenderer()->SetGradientBackground( true ); // switch to gradient mode
- // VSR: In VTK, gradient is colored from bottom to top:
- // - top color is set via SetBackground2()
- // - bottom color is set via SetBackground()
- // So, we reverse colors, to draw gradient from top to bottom instead.
- getRenderer()->SetBackground( c2.red()/255.0,
- c2.green()/255.0,
- c2.blue()/255.0 ); // set first gradient color
- getRenderer()->SetBackground2( c1.red()/255.0,
- c1.green()/255.0,
- c1.blue()/255.0 ); // set second gradient color
- ok = true;
- }
- break;
- }
- case Qtx::CustomGradientBackground:
- {
- // NOT IMPLEMENTED YET
- getRenderer()->SetTexturedBackground( false ); // cancel texture mode
- getRenderer()->SetGradientBackground( false ); // cancel gradient mode
- // .........
- break;
}
- default:
- break;
}
if ( ok )
myBackground = bgData;
<source>GT_VERTICALGRADIENT</source>
<translation>Vertical gradient</translation>
</message>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>
+ </message>
</context>
</TS>
<source>GT_VERTICALGRADIENT</source>
<translation>Gradient vertical</translation>
</message>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Fichiers images (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>
+ </message>
</context>
</TS>
#include <QMouseEvent>
#include <QToolBar>
+// VSR: Uncomment below line to allow texture background support in VTK viewer
+// #define VTK_ENABLE_TEXTURED_BACKGROUND
+
bool _InitializeVtkWarningsCall()
{
char* isOn = getenv( "VTK_WARNINGS_IS_ON" );
}
/*! Get data for supported background modes: gradient types, identifiers and supported image formats */
-QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList )
+QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
{
- gradList << tr( "GT_VERTICALGRADIENT" );
- idList << VerticalGradient;
- return QString(); // temporarily, means support of all image formats!
+ gradList << tr( "GT_VERTICALGRADIENT" ); // only vertical type of gradient is supported
+ idList << VerticalGradient; // only vertical type of gradient is supported
+#ifdef VTK_ENABLE_TEXTURED_BACKGROUND
+ txtList << Qtx::StretchTexture; // only stretch texture mode is supported
+#endif
+ return tr("BG_IMAGE_FILES");
}
/*!Gets background color [obsolete]*/
// get supported gradient types
QStringList gradList;
- QIntList idList;
- QString formats = backgroundData( gradList, idList );
+ QIntList idList, txtList;
+ QString formats = backgroundData( gradList, idList, txtList );
// invoke dialog box
- Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box
- aView->background(), // initial background
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
+ aView, // parent for dialog box
+ txtList, // allowed texture modes
true, // enable solid color mode
- false, // disable texture mode
true, // enable gradient mode
false, // disable custom gradient mode
+ !txtList.isEmpty(), // enable texture mode
gradList, // gradient names
idList, // gradient identifiers
formats ); // image formats
/*!Initialize type of viewer.*/
static QString Type() { return "VTKViewer"; }
- static QString backgroundData( QStringList&, QIntList& );
+ static QString backgroundData( QStringList&, QIntList&, QIntList& );
VTKViewer_Viewer();
virtual ~VTKViewer_Viewer();
/*!Set background of the viewport*/
void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
{
- bool ok = bgData.isValid();
-
- switch ( bgData.mode() ) {
- case Qtx::ImageBackground:
- {
+ bool ok = false;
+
+ if ( bgData.isValid() ) {
+ switch ( bgData.mode() ) {
+ case Qtx::ColorBackground:
+ {
+ QColor c = bgData.color();
+ if ( c.isValid() ) {
+ // show solid-colored background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ getRenderer()->SetBackground( c.red()/255.0,
+ c.green()/255.0,
+ c.blue()/255.0 ); // set background color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = bgData.gradient( c1, c2 );
+ // VSR: Currently, only vertical gradient is supported by VTK.
+ // In future, switch operator might be added here to process different supported gradient types.
+ if ( c1.isValid() && type == VTKViewer_Viewer::VerticalGradient ) {
+ if ( !c2.isValid() ) c2 = c1;
+ // show two-color gradient background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( true ); // switch to gradient mode
+ // VSR: In VTK, gradient is colored from bottom to top:
+ // - top color is set via SetBackground2()
+ // - bottom color is set via SetBackground()
+ // So, we reverse colors, to draw gradient from top to bottom instead.
+ getRenderer()->SetBackground( c2.red()/255.0,
+ c2.green()/255.0,
+ c2.blue()/255.0 ); // set first gradient color
+ getRenderer()->SetBackground2( c1.red()/255.0,
+ c1.green()/255.0,
+ c1.blue()/255.0 ); // set second gradient color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::CustomGradientBackground:
+ {
+ // NOT IMPLEMENTED YET
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ // .........
+ break;
+ }
+ default:
+ break;
+ }
+ if ( bgData.isTextureShown() ) {
QString fileName;
int textureMode = bgData.texture( fileName );
QFileInfo fi( fileName );
ok = true;
}
}
- break;
- }
- case Qtx::ColorBackground:
- {
- QColor c = bgData.color();
- if ( c.isValid() ) {
- // show solid-colored background
- getRenderer()->SetTexturedBackground( false ); // cancel texture mode
- getRenderer()->SetGradientBackground( false ); // cancel gradient mode
- getRenderer()->SetBackground( c.red()/255.0,
- c.green()/255.0,
- c.blue()/255.0 ); // set background color
- ok = true;
- }
- break;
}
- case Qtx::SimpleGradientBackground:
- {
- QColor c1, c2;
- int type = bgData.gradient( c1, c2 );
- // VSR: Currently, only vertical gradient is supported by VTK.
- // In future, switch operator might be added here to process different supported gradient types.
- if ( c1.isValid() && type == VTKViewer_Viewer::VerticalGradient ) {
- if ( !c2.isValid() ) c2 = c1;
- // show two-color gradient background
- getRenderer()->SetTexturedBackground( false ); // cancel texture mode
- getRenderer()->SetGradientBackground( true ); // switch to gradient mode
- // VSR: In VTK, gradient is colored from bottom to top:
- // - top color is set via SetBackground2()
- // - bottom color is set via SetBackground()
- // So, we reverse colors, to draw gradient from top to bottom instead.
- getRenderer()->SetBackground( c2.red()/255.0,
- c2.green()/255.0,
- c2.blue()/255.0 ); // set first gradient color
- getRenderer()->SetBackground2( c1.red()/255.0,
- c1.green()/255.0,
- c1.blue()/255.0 ); // set second gradient color
- ok = true;
- }
- break;
- }
- case Qtx::CustomGradientBackground:
- {
- // NOT IMPLEMENTED YET
- getRenderer()->SetTexturedBackground( false ); // cancel texture mode
- getRenderer()->SetGradientBackground( false ); // cancel gradient mode
- // .........
- break;
- }
- default:
- break;
}
+
if ( ok )
myBackground = bgData;
}
<source>GT_VERTICALGRADIENT</source>
<translation>Vertical gradient</translation>
</message>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>
+ </message>
</context>
</TS>
<source>GT_VERTICALGRADIENT</source>
<translation>Gradient vertical</translation>
</message>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Fichiers images (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>
+ </message>
</context>
</TS>