From: stv Date: Wed, 14 Feb 2007 16:55:01 +0000 (+0000) Subject: no message X-Git-Tag: For_HDF~45 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b7da5e874e2a3c21c0126e427494bc84d3616cb7;p=modules%2Fgui.git no message --- diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 6e2a31648..a5ffacf22 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -21,24 +21,65 @@ #include "Qtx.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include +QString Qtx::toQString( const char* str, const int len ) +{ + return toQString( (unsigned char*)str, len ); +} + +QString Qtx::toQString( const short* str, const int len ) +{ + return toQString( (unsigned short*)str, len ); +} + +QString Qtx::toQString( const unsigned char* str, const int len ) +{ + QString res; + int l = len; + const unsigned char* s = str; + while ( len < 0 || res.length() < len ) + { + if ( *s == '\0' ) + break; + + res.append( QChar( *s ) ); + s++; + } + return res; +} + +QString Qtx::toQString( const unsigned short* str, const int len ) +{ + QString res; + int l = len; + const unsigned short* s = str; + while ( len < 0 || res.length() < len ) + { + if ( *s == '\0' ) + break; + + res.append( QChar( *s ) ); + s++; + } + return res; +} + /*! Name: setTabOrder [static public] Desc: Set tab order for specified list of widgets. Last parameter should be null pointer. @@ -72,9 +113,9 @@ void Qtx::setTabOrder( const QWidgetList& widgets ) return; QWidget* prev = 0; - for ( QWidgetListIt it( widgets ); it.current(); ++it ) + for ( QWidgetList::const_iterator it = widgets.begin(); it!= widgets.end(); ++it ) { - QWidget* next = it.current(); + QWidget* next = *it; if ( prev && next ) QWidget::setTabOrder( prev, next ); prev = next; @@ -158,8 +199,8 @@ void Qtx::alignWidget( QWidget* src, const QWidget* ref, const int alignFlags ) if ( desk && y + srcHei + border > desk->height() ) y = desk->height() - srcHei - border; - x = QMAX( x, 0 ); - y = QMAX( y, 0 ); + x = qMax( x, 0 ); + y = qMax( y, 0 ); src->move( x, y ); } @@ -168,66 +209,76 @@ void Qtx::alignWidget( QWidget* src, const QWidget* ref, const int alignFlags ) Name: simplifySeparators [static public] Desc: Checks toolbar for unnecessary separators and removes them */ +/* void Qtx::simplifySeparators( QToolBar* toolbar ) { if ( !toolbar ) return; - const QObjectList* objList = toolbar->children(); - if ( !objList ) - return; + const QObjectList& objList = toolbar->children(); QObjectList delList; bool isPrevSep = true; - for ( QObjectListIt it( *objList ); it.current(); ++it ) + QObject* lastVis = 0; // last visible + for ( QObjectList::const_iterator it = objList.begin(); it != objList.end(); ++it ) { - bool isSep = it.current()->isA( "QToolBarSeparator" ); + QObject* obj = *it; + if ( !obj || !obj->isWidgetType() ) + continue; + bool isSep = obj->inherits( "QToolBarSeparator" ); + if ( !isSep && !((QWidget*)obj)->isVisibleTo( toolbar ) ) + continue; if ( isPrevSep && isSep ) - delList.append( it.current() ); - isPrevSep = isSep; + delList.append( obj ); + else + { + isPrevSep = isSep; + lastVis = obj; + } } + // remove last visible separator + if ( lastVis && lastVis->inherits( "QToolBarSeparator" ) ) + delList.append( lastVis ); - for ( QObjectListIt itr( delList ); itr.current(); ++itr ) - delete itr.current(); - - if ( toolbar->children() && !toolbar->children()->isEmpty() && - toolbar->children()->getFirst()->isA( "QToolBarSeparator" ) ) - delete toolbar->children()->getFirst(); - - if ( toolbar->children() && !toolbar->children()->isEmpty() && - toolbar->children()->getLast()->isA( "QToolBarSeparator" ) ) - delete toolbar->children()->getLast(); + for ( QObjectList::iterator itr = delList.begin(); itr != delList.end(); ++itr ) + delete *itr; } +*/ /*! Name: simplifySeparators [static public] Desc: Checks popup menu recursively for unnecessary separators and removes them */ -void Qtx::simplifySeparators( QPopupMenu* popup, const bool recursive ) +void Qtx::simplifySeparators( QWidget* wid, const bool recursive ) { - if ( !popup || !popup->count() ) + if ( !wid ) + return; + + QList items = wid->actions(); + if ( items.isEmpty() ) return; - QIntList idRemove; - for ( uint i = 1; i < popup->count(); i++ ) + QList toRemove; + for ( uint i = 1; i < items.count(); i++ ) { - if ( popup->findItem( popup->idAt( i ) )->isSeparator() && - popup->findItem( popup->idAt( i - 1 ) )->isSeparator() ) - idRemove.append( popup->idAt( i ) ); + if ( items[i]->isSeparator() && items[i - 1]->isSeparator() ) + toRemove.append( items[i] ); - if ( recursive ) - simplifySeparators( popup->findItem( popup->idAt( i ) )->popup() ); + if ( recursive && items[i]->menu() ) + simplifySeparators( items[i]->menu(), recursive ); } - for ( QIntList::const_iterator it = idRemove.begin(); it != idRemove.end(); ++it ) - popup->removeItem( *it ); + for ( QList::iterator it = toRemove.begin(); it != toRemove.end(); ++it ) + wid->removeAction( *it ); - if ( popup->count() > 0 && popup->findItem( popup->idAt( 0 ) )->isSeparator() ) - popup->removeItem( popup->idAt( 0 ) ); + items = wid->actions(); + if ( !items.isEmpty() && items[0]->isSeparator() ) + wid->removeAction( items[0] ); - if ( popup->count() > 0 && popup->findItem( popup->idAt( popup->count() - 1 ) )->isSeparator() ) - popup->removeItem( popup->idAt( popup->count() - 1 ) ); + items = wid->actions(); + if ( !items.isEmpty() && items[items.count() - 1]->isSeparator() ) + wid->removeAction( items[items.count() - 1] ); } /*! @@ -255,7 +306,8 @@ bool Qtx::isParent( QObject* child, QObject* parent ) */ QString Qtx::dir( const QString& path, const bool abs ) { - QString dirPath = QFileInfo( path ).dirPath( abs ); + QDir aDir = QFileInfo( path ).dir(); + QString dirPath = abs ? aDir.absolutePath() : aDir.path(); if ( dirPath == QString( "." ) ) dirPath = QString::null; return dirPath; @@ -277,9 +329,9 @@ QString Qtx::file( const QString& path, bool withExt ) Name: extension [static public] Desc: Returns the file extension only or null string. */ -QString Qtx::extension( const QString& path ) +QString Qtx::extension( const QString& path, const bool full ) { - return QFileInfo( path ).extension(false); // after the last dot + return full ? QFileInfo( path ).completeSuffix() : QFileInfo( path ).suffix(); } /*! @@ -304,7 +356,7 @@ QString Qtx::library( const QString& str ) QString libExt( "so" ); #endif - if ( ext.lower() != QString( "so" ) && ext.lower() != QString( "dll" ) ) + if ( ext.toLower() != QString( "so" ) && ext.toLower() != QString( "dll" ) ) { if ( !name.isEmpty() && !ext.isEmpty() ) name += QString( "." ); @@ -345,24 +397,7 @@ QString Qtx::tmpDir() */ bool Qtx::mkDir( const QString& dirPath ) { - QString path = QDir::convertSeparators( dirPath ); - -#ifdef WIN32 - while ( !path.isEmpty() && path.at( path.length() - 1 ) == QDir::separator() ) - path.remove( path.length() - 1, 1 ); - - if ( path.at( path.length() - 1 ) == ':' ) - return QFileInfo( path ).exists(); -#endif - - QFileInfo fInfo( path ); - if ( fInfo.exists() ) - return fInfo.isDir(); - - if ( !mkDir( fInfo.dirPath() ) ) - return false; - - return QDir( fInfo.dirPath() ).mkdir( fInfo.fileName() ); + return QDir().mkpath( dirPath ); } /*! @@ -382,15 +417,13 @@ bool Qtx::rmDir( const QString& thePath ) else if ( fi.isDir() ) { QDir aDir( thePath ); - const QFileInfoList* anEntries = aDir.entryInfoList(); - if ( anEntries ) + QFileInfoList anEntries = aDir.entryInfoList(); + for ( QFileInfoList::iterator it = anEntries.begin(); it != anEntries.end(); ++it ) { - for ( QPtrListIterator it( *anEntries ); it.current(); ++it ) - { - if ( it.current()->fileName() == "." || it.current()->fileName() == ".." ) + QFileInfo inf = *it; + if ( inf.fileName() == "." || inf.fileName() == ".." ) continue; - stat = stat && rmDir( it.current()->absFilePath() ); - } + stat = stat && rmDir( inf.absoluteFilePath() ); } stat = stat && aDir.rmdir( thePath ); } @@ -416,14 +449,14 @@ QString Qtx::addSlash( const QString& path ) */ bool Qtx::dos2unix( const QString& absName ) { - FILE* src = ::fopen( absName, "rb" ); + FILE* src = ::fopen( absName.toLatin1(), "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, "__x" ) ), "wb" ); + FILE* tgt = ::fopen( strcpy( temp, ::tempnam( dir.toLatin1(), "__x" ) ), "wb" ); if ( !tgt ) return false; @@ -502,11 +535,11 @@ int Qtx::rgbSet( const int r, const int g, const int b ) Name: rgbSet [static public] Desc: Unpack the specified integer RGB set into the color. */ -void Qtx::rgbSet( const int rgb, QColor& c ) +QColor Qtx::rgbSet( const int rgb ) { int r, g, b; rgbSet( rgb, r, g, b ); - c = QColor( r, g, b ); + return QColor( r, g, b ); } /*! @@ -545,14 +578,14 @@ QColor Qtx::scaleColor( const int index, const int min, const int max ) } } - return QColor( hue, 255, 255, QColor::Hsv ); + return QColor::fromHsv( hue, 255, 255 ); } /*! Name: scaleColors [static public] Desc: Returns the 'num' number of colors from blue to red. */ -void Qtx::scaleColors( const int num, QValueList& lst ) +void Qtx::scaleColors( const int num, QList& lst ) { lst.clear(); for ( int i = 0; i < num; i++ ) @@ -595,7 +628,7 @@ QImage Qtx::grayscale( const QImage& img ) QPixmap Qtx::grayscale( const QPixmap& pix ) { QPixmap res; - res.convertFromImage( grayscale( pix.convertToImage() ) ); + res.fromImage( grayscale( pix.toImage() ) ); return res; } @@ -605,10 +638,27 @@ QPixmap Qtx::grayscale( const QPixmap& pix ) */ QImage Qtx::transparentImage( const int w, const int h, const int d ) { - QImage img; - if ( img.create( w, h, d < 0 ? QPixmap::defaultDepth() : d ) ) + QImage::Format fmt; + switch ( d ) + { + case 1: + fmt = QImage::Format_Mono; + break; + case 8: + fmt = QImage::Format_Indexed8; + break; + case 16: + case 24: + case 32: + default: + fmt = QImage::Format_ARGB32; + break; + } + + QImage img( w, h, fmt ); + if ( !img.isNull() ) { - img.setAlphaBuffer( true ); +// img.setAlphaBuffer( true ); for ( int i = 0; i < img.height(); i++ ) for ( int j = 0; j < img.width(); j++ ) img.setPixel( j, i, qRgba( 0, 0, 0, 0 ) ); @@ -625,7 +675,7 @@ QPixmap Qtx::transparentPixmap( const int w, const int h, const int d ) QPixmap pix; QImage img = transparentImage( w, h, d ); if ( !img.isNull() ) - pix.convertFromImage( img ); + pix.fromImage( img ); return pix; } @@ -640,25 +690,25 @@ QPixmap Qtx::composite( const QPixmap& pix, const int x, const int y, const QPix if ( pix.isNull() ) return dest; - int width = QMAX( pix.width() + x, dest.width() ); - int height = QMAX( pix.height() + y, dest.height() ); + int width = qMax( pix.width() + x, dest.width() ); + int height = qMax( pix.height() + y, dest.height() ); QPixmap res( width, height ); QImage img = transparentImage( width, height, 32 ); QPainter p; p.begin( &res ); - p.fillRect( 0, 0, width, height, QBrush( white ) ); + p.fillRect( 0, 0, width, height, QBrush( Qt::white ) ); if ( !dest.isNull() ) { p.drawPixmap( 0, 0, dest ); - QImage temp = dest.convertToImage(); + QImage temp = dest.toImage(); for ( int i = 0; i < temp.width() && i < img.width(); i++ ) { for ( int j = 0; j < temp.height() && j < img.height(); j++ ) { - if ( temp.hasAlphaBuffer() ) + if ( temp.hasAlphaChannel() ) img.setPixel( i, j, temp.pixel( i, j ) ); else { @@ -670,7 +720,7 @@ QPixmap Qtx::composite( const QPixmap& pix, const int x, const int y, const QPix } p.drawPixmap( x, y, pix ); - QImage temp = pix.convertToImage(); + QImage temp = pix.toImage(); for ( int c = x; c < temp.width() + x && c < img.width(); c++ ) { for ( int r = y; r < temp.height() + y && r < img.height(); r++ ) @@ -694,7 +744,7 @@ QPixmap Qtx::composite( const QPixmap& pix, const int x, const int y, const QPix } QBitmap bmp( width, height ); - bmp.convertFromImage( img, Qt::ColorMode_Mask | Qt::ThresholdDither ); + bmp.fromImage( img, Qt::ColorMode_Mask | Qt::ThresholdDither ); res.setMask( bmp ); return res; diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index 0d5cb3a40..066847e9a 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -42,81 +42,79 @@ #define true 1 #endif -#ifndef INCLUDE_MENUITEM_DEF -#define INCLUDE_MENUITEM_DEF -#endif +#define QT_VER 4 -#include +#include -#ifndef QT_VERSION -#define QT_VER 0 -#else -#if QT_VERSION >= 0x30000 -#define QT_VER 3 -#else -#if QT_VERSION >= 300 -#define QT_VER 3 -#else -#if QT_VERSION >= 200 -#define QT_VER 2 -#else -#if QT_VERSION >= 100 -#define QT_VER 1 -#endif -#endif -#endif -#endif -#endif - -#include -#include +#include +#include +#include +class QMenu; class QObject; class QString; class QWidget; class QToolBar; -class QGroupBox; -class QPopupMenu; -class QWidgetList; -template class QValueList; - -#if QT_VER < 3 -#define QPtrList QList -#define QPtrListIterator QListIterator -#endif +template class QList; -typedef QValueList QIntList; -typedef QValueList QShortList; -typedef QValueList QDoubleList; +typedef QList QIntList; +typedef QList QShortList; +typedef QList QDoubleList; /*! \class Qtx \brief Set of auxiliary static methods */ + +#ifndef QT_MOC_RUN +class QTX_EXPORT Qtx +#else class QTX_EXPORT Qtx : public Qt +#endif { public: enum AlignmentFlags { - AlignOutLeft = AlignVCenter << 2, + AlignLeft = Qt::AlignLeft, + AlignLeading = Qt::AlignLeading, + AlignRight = Qt::AlignRight, + AlignTrailing = Qt::AlignTrailing, + AlignHCenter = Qt::AlignHCenter, + AlignJustify = Qt::AlignJustify, + AlignAbsolute = Qt::AlignAbsolute, + AlignHorizontal_Mask = Qt::AlignHorizontal_Mask, + + AlignTop = Qt::AlignTop, + AlignBottom = Qt::AlignBottom, + AlignVCenter = Qt::AlignVCenter, + AlignVertical_Mask = Qt::AlignVertical_Mask, + + AlignCenter = Qt::AlignCenter, + + AlignOutLeft = Qt::AlignVCenter << 2, AlignOutRight = AlignOutLeft << 2, AlignOutTop = AlignOutRight << 2, AlignOutBottom = AlignOutTop << 2 }; + static QString toQString( const char*, const int = -1 ); + static QString toQString( const short*, const int = -1 ); + static QString toQString( const unsigned char*, const int = -1 ); + static QString toQString( const unsigned short*, const int = -1 ); + static void setTabOrder( QWidget*, ... ); static void setTabOrder( const QWidgetList& ); static void alignWidget( QWidget*, const QWidget*, const int ); - static void simplifySeparators( QToolBar* ); - static void simplifySeparators( QPopupMenu*, const bool = true ); +// static void simplifySeparators( QToolBar* ); + static void simplifySeparators( QWidget*, const bool = true ); static bool isParent( QObject*, QObject* ); - static QString extension( const QString& ); static QString dir( const QString&, const bool = true ); static QString file( const QString&, const bool = true ); + static QString extension( const QString&, const bool = false ); static QString library( const QString& ); @@ -129,11 +127,11 @@ public: static int rgbSet( const QColor& ); static int rgbSet( const int, const int, const int ); - static void rgbSet( const int, QColor& ); + static QColor rgbSet( const int ); static void rgbSet( const int, int&, int&, int& ); static QColor scaleColor( const int, const int, const int ); - static void scaleColors( const int, QValueList& ); + static void scaleColors( const int, QList& ); static QImage grayscale( const QImage& ); static QPixmap grayscale( const QPixmap& ); diff --git a/src/Qtx/QtxAction.cxx b/src/Qtx/QtxAction.cxx index dbae4819f..23bd566af 100755 --- a/src/Qtx/QtxAction.cxx +++ b/src/Qtx/QtxAction.cxx @@ -21,8 +21,8 @@ #include "QtxAction.h" -#include -#include +#include +#include /*! Name: QtxAction [public] @@ -31,8 +31,9 @@ */ QtxAction::QtxAction( QObject* parent, const char* name, bool toggle ) - : QAction( parent, name, toggle ) +: QAction( parent ) { + setCheckable( toggle ); } /*! @@ -44,11 +45,14 @@ QtxAction::QtxAction( QObject* parent, const char* name, bool toggle ) be a command action. */ -QtxAction::QtxAction( const QString& text, const QIconSet& icon, +QtxAction::QtxAction( const QString& text, const QIcon& icon, const QString& menuText, int accel, QObject* parent, const char* name, bool toggle ) - : QAction( text, icon, menuText, accel, parent, name, toggle ) +: QAction( icon, menuText, parent ) { + setToolTip( text ); + setShortcut( accel ); + setCheckable( toggle ); } /*! @@ -61,8 +65,11 @@ QtxAction::QtxAction( const QString& text, const QIconSet& icon, QtxAction::QtxAction( const QString& text, const QString& menuText, int accel, QObject* parent, const char* name, bool toggle ) - : QAction( text, menuText, accel, parent, name, toggle ) +: QAction( menuText, parent ) { + setToolTip( text ); + setShortcut( accel ); + setCheckable( toggle ); } /*! @@ -82,27 +89,11 @@ QtxAction::~QtxAction() bool QtxAction::addTo( QWidget* w ) { - if ( w->inherits( "QMenuBar" ) ) { - // --- Add action to the QMenuBar --- - // n.b. currently for the actions inserted to the menu bar - // the following properties are not supported: - // * tooltips - // * what's this info - // * toggle mode - QMenuBar* mb = (QMenuBar*)w; - if ( myMenuIds.find( w ) != myMenuIds.end() ) - return false; // already added - if ( name() == "qt_separator_action" ) // separator - myMenuIds[ w ] = mb->insertSeparator(); - else if ( iconSet().isNull() ) // has no icon - myMenuIds[ w ] = mb->insertItem( menuText(), this, SIGNAL( activated() ), accel() ); - else // has icon - myMenuIds[ w ] = mb->insertItem( iconSet(), menuText(), this, SIGNAL( activated() ), accel() ); - mb->setItemEnabled( myMenuIds[ w ], isEnabled() ); - mb->setItemVisible( myMenuIds[ w ], isVisible() ); - return true; - } - return QAction::addTo( w ); + if ( !w ) + return false; + + w->addAction( this ); + return true; } /*! @@ -114,97 +105,15 @@ bool QtxAction::addTo( QWidget* w ) bool QtxAction::addTo( QWidget* w, const int index ) { - if ( !addTo( w ) ) + if ( !w ) return false; - if ( w->inherits( "QPopupMenu" ) ) { - // --- Add action to the QPopupMenu --- - QPopupMenu* popup = (QPopupMenu*)w; - if ( index >= 0 && index < (int)popup->count() - 1 ) { - int id = popup->idAt( popup->count() - 1 ); - if ( id != -1 ) { - QMenuItem* item = popup->findItem( id ); - if ( item && item->isSeparator() ) { - popup->removeItem( id ); - popup->insertSeparator( index ); - } - else { - QPopupMenu* p = item ? item->popup() : 0; - int accel = popup->accel( id ); - bool isOn = popup->isItemEnabled( id ); - bool isVisible = popup->isItemVisible( id ); - bool isChecked = popup->isItemChecked( id ); - QString text = popup->text( id ); - QIconSet icon; - if ( popup->iconSet( id ) ) - icon = *popup->iconSet( id ); - popup->removeItem( id ); - int pos; - if ( icon.isNull() ) - if ( p ) - pos = popup->indexOf( popup->insertItem( text, p, id, index ) ); - else - pos = popup->indexOf( popup->insertItem( text, id, index ) ); - else - if ( p ) - pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) ); - else - pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) ); - popup->setId( pos, id ); - popup->setAccel( accel, id ); - popup->setItemEnabled( id, isOn ); - popup->setItemVisible( id, isVisible ); - popup->setItemChecked( id, isChecked ); - if ( !whatsThis().isEmpty() ) - popup->setWhatsThis( id, whatsThis() ); - if ( !p ) - popup->connectItem( id, this, SLOT( internalActivation() ) ); - } - } - } - } - else if ( w->inherits( "QMenuBar" ) ) { - // --- Add action to the QMenuBar --- - QMenuBar* mb = (QMenuBar*)w; - if ( index >= 0 && index < (int)mb->count() - 1 ) { - int id = mb->idAt( mb->count() - 1 ); - if ( id != -1 ) { - QMenuItem* item = mb->findItem( id ); - if ( item && item->isSeparator() ) { - mb->removeItem( id ); - mb->insertSeparator( index ); - } - else { - QPopupMenu* p = item ? item->popup() : 0; - int accel = mb->accel( id ); - bool isOn = mb->isItemEnabled( id ); - bool isVisible = mb->isItemVisible( id ); - QString text = mb->text( id ); - QIconSet icon; - if ( mb->iconSet( id ) ) - icon = *mb->iconSet( id ); - mb->removeItem( id ); - int pos; - if ( icon.isNull() ) - if ( p ) - pos = mb->indexOf( mb->insertItem( text, p, id, index ) ); - else - pos = mb->indexOf( mb->insertItem( text, id, index ) ); - else - if ( p ) - pos = mb->indexOf( mb->insertItem( icon, text, p, id, index ) ); - else - pos = mb->indexOf( mb->insertItem( icon, text, p, id, index ) ); - mb->setId( pos, id ); - mb->setAccel( accel, id ); - mb->setItemEnabled( id, isOn ); - mb->setItemVisible( id, isVisible ); - if ( !p ) - mb->connectItem( id, this, SIGNAL( activated() ) ); - } - } - } - } + QAction* b = 0; + if ( 0 <= index && index < w->actions().count() ) + b = w->actions().at( index ); + + w->insertAction( b, this ); + return true; } @@ -216,16 +125,11 @@ bool QtxAction::addTo( QWidget* w, const int index ) bool QtxAction::removeFrom( QWidget* w ) { - // check if widget is QMenuBar - if ( w->inherits( "QMenuBar" ) ) { - QMenuBar* mb = (QMenuBar*)w; - if ( myMenuIds.find( w ) == myMenuIds.end() ) - return false; // not yet added - mb->removeItem( myMenuIds[ w ] ); - myMenuIds.remove( w ); - return true; - } - return QAction::removeFrom( w ); + if ( !w ) + return false; + + w->removeAction( this ); + return true; } /*! @@ -233,8 +137,9 @@ bool QtxAction::removeFrom( QWidget* w ) Desc: Set or unset the sub popup menu for item with specified id in the given popup. */ -void QtxAction::setPopup( QWidget* w, const int id, QPopupMenu* subPopup ) const +void QtxAction::setPopup( QWidget* w, const int id, QMenu* subPopup ) const { +/* if ( !w ) return; @@ -271,25 +176,27 @@ void QtxAction::setPopup( QWidget* w, const int id, QPopupMenu* subPopup ) const pmd->removeItem( id ); // add new item - if ( w->inherits( "QPopupMenu" ) ) { + if ( w->inherits( "QPopupMenu" ) ) + { // --- QPopupMenu --- QPopupMenu* popup = (QPopupMenu*)w; if ( icon.isNull() ) pos = popup->indexOf( subPopup ? popup->insertItem( text, subPopup, id, pos ) : - popup->insertItem( text, id, pos ) ); + popup->insertItem( text, id, pos ) ); else pos = popup->indexOf( subPopup ? popup->insertItem( icon, text, subPopup, id, pos ) : - popup->insertItem( icon, text, id, pos ) ); + popup->insertItem( icon, text, id, pos ) ); } - else { + else + { // --- QMenuBar --- QMenuBar* mb = (QMenuBar*)w; if ( icon.isNull() ) pos = mb->indexOf( subPopup ? mb->insertItem( text, subPopup, id, pos ) : - mb->insertItem( text, id, pos ) ); + mb->insertItem( text, id, pos ) ); else pos = mb->indexOf( subPopup ? mb->insertItem( icon, text, subPopup, id, pos ) : - mb->insertItem( icon, text, id, pos ) ); + mb->insertItem( icon, text, id, pos ) ); } // restore properties @@ -300,5 +207,5 @@ void QtxAction::setPopup( QWidget* w, const int id, QPopupMenu* subPopup ) const // delete old popup delete oldPopup; +*/ } - diff --git a/src/Qtx/QtxAction.h b/src/Qtx/QtxAction.h index af0473f3f..33932ec70 100755 --- a/src/Qtx/QtxAction.h +++ b/src/Qtx/QtxAction.h @@ -24,13 +24,16 @@ #include "Qtx.h" -#include -#include +#include +#include +#include #ifdef WIN32 #pragma warning ( disable:4251 ) #endif +class QMenu; + class QTX_EXPORT QtxAction : public QAction { Q_OBJECT @@ -38,15 +41,16 @@ class QTX_EXPORT QtxAction : public QAction public: QtxAction( QObject* = 0, const char* = 0, bool = false ); QtxAction( const QString&, const QString&, int, QObject*, const char* = 0, bool = false ); - QtxAction( const QString&, const QIconSet&, const QString&, int, QObject*, const char* = 0, bool = false ); + QtxAction( const QString&, const QIcon&, const QString&, int, QObject*, const char* = 0, bool = false ); virtual ~QtxAction(); virtual bool addTo( QWidget* ); virtual bool addTo( QWidget*, const int ); + virtual bool removeFrom( QWidget* ); protected: - void setPopup( QWidget*, const int, QPopupMenu* ) const; + void setPopup( QWidget*, const int, QMenu* ) const; private: QMap myMenuIds; diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index 94f7050a0..869dd0026 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -23,15 +23,15 @@ #include "QtxAction.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include + +#include // VSR: Uncomment this #define in order to allow dynamic menus support // (emit signals when popup menu is pre-activated) @@ -43,15 +43,17 @@ Level: Internal */ namespace { - QValueList prepareIds( const QWidget* w ) +/* + QList prepareIds( const QWidget* w ) { - QValueList l; + QList l; const QMenuData* md = 0; if ( w->inherits( "QMenuBar" ) ) md = ::qt_cast( w ); else if ( w->inherits( "QPopupMenu" ) ) md = ::qt_cast( w ); - if ( md ) { + if ( md ) + { for ( uint i = 0; i < md->count(); i++ ) l.append( md->idAt( i ) ); } @@ -95,6 +97,7 @@ namespace { printf( "%d: %d: %s\n", i, md->idAt( i ), md->text( md->idAt( i ) ).latin1() ); printf( "<<< end dump menu (%s) <<<\n", before ? "before" : "after" ); } +*/ }; /*! @@ -108,20 +111,11 @@ public: MenuAction( const QString&, const QString&, QObject*, const int = -1, const bool = false ); virtual ~MenuAction(); - virtual bool addTo( QWidget* ); - - virtual bool removeFrom( QWidget* ); - - QPopupMenu* popup() const; - private: - int myId; - QPopupMenu* myPopup; - bool myEmptyEnabled; - QMap myIds; + int myId; + bool myEmptyEnabled; }; - /*! Constructor for menu action \param text - description text @@ -130,31 +124,30 @@ private: \param id - integer identificator of action \param allowEmpty - if it is true, it makes possible to add this action with empty popup to menu */ - -QtxActionMenuMgr::MenuAction::MenuAction( const QString& text, - const QString& menuText, - QObject* parent, - const int id, - const bool allowEmpty ) +/* +QtxActionMenuMgr::MenuAction::MenuAction( const QString& text, const QString& menuText, + QObject* parent, const int id, const bool allowEmpty ) : QtxAction( text, menuText, 0, parent ), - myId( id ), - myPopup( 0 ), - myEmptyEnabled( allowEmpty ) +myId( id ), +myPopup( 0 ), +myEmptyEnabled( allowEmpty ) { - myPopup = new QPopupMenu(); + myPopup = new QMenu(); } - +*/ /*! Destructor: deletes internal popup */ +/* QtxActionMenuMgr::MenuAction::~MenuAction() { delete myPopup; } - +*/ /*! Adds action to widget, for example, to popup menu or menu bar */ +/* bool QtxActionMenuMgr::MenuAction::addTo( QWidget* w ) { if ( !w ) @@ -169,40 +162,47 @@ bool QtxActionMenuMgr::MenuAction::addTo( QWidget* w ) if ( !myPopup ) return false; // bad own popup menu - if ( !myEmptyEnabled && !myPopup->count() ) + if ( !myEmptyEnabled && !myPopup->actions().count() ) return false; // not allowed empty menu - if ( w->inherits( "QPopupMenu" ) ) { + if ( w->inherits( "QPopupMenu" ) ) + { QValueList l = prepareIds( w ); int idx; - if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) { + if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) + { QPopupMenu* pm = (QPopupMenu*)w; myIds[ w ] = pm->idAt( idx ); if ( myId != -1 ) - pm->setId( idx, myId ); + pm->setId( idx, myId ); setPopup( pm, myId != -1 ? myId : myIds[ w ], myPopup ); } } - else if ( w->inherits( "QMenuBar" ) ) { + else if ( w->inherits( "QMenuBar" ) ) + { QValueList l = prepareIds( w ); int idx; - if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) { + if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) + { QMenuBar* mb = (QMenuBar*)w; myIds[ w ] = mb->idAt( idx ); if ( myId != -1 ) - mb->setId( idx, myId ); + mb->setId( idx, myId ); setPopup( mb, myId != -1 ? myId : myIds[ w ], myPopup ); } + } else return false; return true; } +*/ /*! Removes action from widget, for example, from popup menu or menu bar */ +/* bool QtxActionMenuMgr::MenuAction::removeFrom( QWidget* w ) { if ( !w ) @@ -214,35 +214,43 @@ bool QtxActionMenuMgr::MenuAction::removeFrom( QWidget* w ) if ( myIds.find( w ) == myIds.end() ) return false; // not yet added - if ( w->inherits( "QPopupMenu" ) ) { - if ( myId != -1 ) { + if ( w->inherits( "QPopupMenu" ) ) + { + if ( myId != -1 ) + { QPopupMenu* pm = (QPopupMenu*)w; int idx = pm->indexOf( myId ); - if ( idx != -1 ) pm->setId( idx, myIds[ w ] ); + if ( idx != -1 ) + pm->setId( idx, myIds[ w ] ); } myIds.remove( w ); return QtxAction::removeFrom( w );; } else if ( w->inherits( "QMenuBar" ) ) { - if ( myId != -1 ) { + if ( myId != -1 ) + { QMenuBar* mb = (QMenuBar*)w; int idx = mb->indexOf( myId ); - if ( idx != -1 ) mb->setId( idx, myIds[ w ] ); + if ( idx != -1 ) + mb->setId( idx, myIds[ w ] ); } myIds.remove( w ); return QtxAction::removeFrom( w ); } return false; } +*/ /*! \return internal popup of action */ -QPopupMenu* QtxActionMenuMgr::MenuAction::popup() const +/* +QMenu* QtxActionMenuMgr::MenuAction::popup() const { return myPopup; } +*/ /*! Class: QtxActionMenuMgr @@ -250,7 +258,7 @@ QPopupMenu* QtxActionMenuMgr::MenuAction::popup() const */ QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p ) : QtxActionMgr( p ), - myMenu( p ? p->menuBar() : 0 ) +myMenu( p ? p->menuBar() : 0 ) { myRoot.id = -1; myRoot.group = -1; @@ -269,7 +277,7 @@ QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p ) */ QtxActionMenuMgr::QtxActionMenuMgr( QWidget* mw, QObject* p ) : QtxActionMgr( p ), - myMenu( mw ) +myMenu( mw ) { myRoot.id = -1; myRoot.group = -1; @@ -283,18 +291,18 @@ QtxActionMenuMgr::QtxActionMenuMgr( QWidget* mw, QObject* p ) */ QtxActionMenuMgr::~QtxActionMenuMgr() { - for ( NodeListIterator it( myRoot.children ); it.current() && myMenu; ++it ) + for ( NodeList::iterator it = myRoot.children.begin(); it != myRoot.children.end() && myMenu; ++it ) { - QAction* a = itemAction( it.current()->id ); + QAction* a = itemAction( (*it)->id ); if ( !a ) - a = menuAction( it.current()->id ); + a = menuAction( (*it)->id ); - if ( a ) - a->removeFrom( myMenu ); +// if ( a ) +// a->removeFrom( myMenu ); } for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr ) - delete itr.data(); + delete itr.value(); } /*! @@ -331,7 +339,7 @@ void QtxActionMenuMgr::setVisible( const int actId, const int place, const bool */ int QtxActionMenuMgr::insert( const int id, const QString& menus, const int group, const int idx ) { - return insert( id, QStringList::split( "|", menus ), group, idx ); + return insert( id, menus.split( "|", QString::SkipEmptyParts ), group, idx ); } /*! @@ -344,7 +352,7 @@ int QtxActionMenuMgr::insert( const int id, const QString& menus, const int grou */ int QtxActionMenuMgr::insert( QAction* a, const QString& menus, const int group, const int idx ) { - return insert( a, QStringList::split( "|", menus ), group, idx ); + return insert( a, menus.split( "|", QString::SkipEmptyParts ), group, idx ); } /*! @@ -404,7 +412,8 @@ int QtxActionMenuMgr::insert( const int id, const int pId, const int group, cons pNode->children.append( node ); - updateMenu( pNode, false ); + triggerUpdate( pNode->id, false ); + return node->id; } @@ -440,11 +449,11 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro MenuNode* eNode = id == -1 ? 0 : find( id ); int fid = -1; - for ( NodeListIterator it( pNode->children ); it.current() && fid == -1; ++it ) + for ( NodeList::iterator it = pNode->children.begin(); it != pNode->children.end() && fid == -1; ++it ) { - if ( myMenus.contains( it.current()->id ) && - clearTitle( myMenus[it.current()->id]->menuText() ) == clearTitle( title ) ) - fid = it.current()->id; + if ( myMenus.contains( (*it)->id ) && + clearTitle( myMenus[(*it)->id]->text() ) == clearTitle( title ) ) + fid = (*it)->id; } if ( fid != -1 ) @@ -452,9 +461,10 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro int gid = (id == -1 || eNode ) ? generateId() : id; - MenuAction* ma = new MenuAction( clearTitle( title ), title, this, gid, allowEmpty ); + QAction* ma = new QAction( title, this ); + ma->setMenu( new QMenu( myMenu ) ); #ifdef ENABLE_DYNAMIC_MENU - connect( ma->popup(), SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) ); + connect( ma->menu(), SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) ); #endif MenuNode* node = new MenuNode( pNode ); @@ -464,7 +474,7 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro pNode->children.append( node ); - updateMenu( pNode, false ); + triggerUpdate( pNode->id, false ); return node->id; } @@ -481,7 +491,7 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro */ int QtxActionMenuMgr::insert( const QString& title, const QString& menus, const int group, const int id, const int idx, const bool allowEmpty ) { - return insert( title, QStringList::split( "|", menus ), group, id, idx, allowEmpty ); + return insert( title, menus.split( "|", QString::SkipEmptyParts ), group, id, idx, allowEmpty ); } /*! @@ -599,16 +609,16 @@ void QtxActionMenuMgr::remove( const int id, const int pId, const int group ) return; NodeList delNodes; - for ( NodeListIterator it( pNode->children ); it.current(); ++it ) + for ( NodeList::iterator it = pNode->children.begin(); it != pNode->children.end(); ++it ) { - if ( it.current()->id == id && ( it.current()->group == group || group == -1 ) ) - delNodes.append( it.current() ); + if ( (*it)->id == id && ( (*it)->group == group || group == -1 ) ) + delNodes.append( *it ); } - for ( NodeListIterator itr( delNodes ); itr.current(); ++itr ) - pNode->children.remove( itr.current() ); + for ( NodeList::iterator itr = delNodes.begin(); itr != delNodes.end(); ++itr ) + pNode->children.removeAll( *itr ); - updateMenu( pNode, false ); + triggerUpdate( pNode->id, false ); } /*! @@ -652,18 +662,24 @@ void QtxActionMenuMgr::setShown( const int id, const bool on ) NodeList aNodes; find( id, aNodes ); - QMap updMap; - for ( NodeListIterator it( aNodes ); it.current(); ++it ) + for ( NodeList::iterator it = aNodes.begin(); it != aNodes.end(); ++it ) { - if ( it.current()->visible != on ) + if ( (*it)->visible != on ) { - it.current()->visible = on; - updMap.insert( it.current()->parent, 0 ); + (*it)->visible = on; + triggerUpdate( (*it)->parent ? (*it)->parent->id : myRoot.id, false ); } } +} - for ( QMap::ConstIterator itr = updMap.begin(); itr != updMap.end(); ++itr ) - updateMenu( itr.key(), false ); +/*! + Changes the specified menu title +*/ +void QtxActionMenuMgr::change( const int id, const QString& title ) +{ + QAction* a = menuAction( id ); + if ( a ) + a->setText( title ); } /*! @@ -684,20 +700,21 @@ void QtxActionMenuMgr::onHighlighted( int id ) int pid = 0, realId; if ( myMenu && snd == myMenu ) pid = -1; - else { - for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr ) { - if ( itr.data()->popup() && itr.data()->popup() == snd ) - pid = itr.key(); + else + { + for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr ) + { + if ( itr.value()->menu() && itr.value()->menu() == snd ) + pid = itr.key(); } } - if ( pid ) { + if ( pid ) + { realId = findId( id, pid ); - if ( realId != -1 ) { - bool updatesEnabled = isUpdatesEnabled(); - setUpdatesEnabled( false ); + if ( realId != -1 ) + { emit menuHighlighted( pid, realId ); - setUpdatesEnabled( updatesEnabled ); - updateMenu( find( realId ) ); + triggerUpdate( realId ); } } } @@ -741,12 +758,12 @@ QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int id, MenuNode* star { MenuNode* node = 0; MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot; - for ( NodeListIterator it( start->children ); it.current() && !node; ++it ) + for ( NodeList::iterator it = start->children.begin(); it != start->children.end() && !node; ++it ) { - if ( it.current()->id == id ) - node = it.current(); + if ( (*it)->id == id ) + node = *it; else if ( rec ) - node = find( id, it.current(), rec ); + node = find( id, *it, rec ); } return node; } @@ -761,12 +778,13 @@ QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int id, MenuNode* star bool QtxActionMenuMgr::find( const int id, NodeList& lst, MenuNode* startNode ) const { MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot; - for ( NodeListIterator it( start->children ); it.current(); ++it ) + for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it ) { - if ( it.current()->id == id ) - lst.prepend( it.current() ); + MenuNode* node = *it; + if ( node->id == id ) + lst.prepend( node ); - find( id, lst, it.current() ); + find( id, lst, node ); } return !lst.isEmpty(); } @@ -793,15 +811,15 @@ QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, const bool QtxActionMenuMgr::find( const QString& title, NodeList& lst, MenuNode* startNode ) const { MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot; - for ( NodeListIterator it( start->children ); it.current(); ++it ) + for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it ) { - QAction* a = itemAction( it.current()->id ); + QAction* a = itemAction( (*it)->id ); if ( !a ) - a = menuAction( it.current()->id ); - if ( a && clearTitle( a->menuText() ) == clearTitle( title ) ) - lst.prepend( it.current() ); + a = menuAction( (*it)->id ); + if ( a && clearTitle( a->text() ) == clearTitle( title ) ) + lst.prepend( *it ); - find( title, lst, it.current() ); + find( title, lst, *it ); } return !lst.isEmpty(); } @@ -817,15 +835,15 @@ QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, MenuNo { MenuNode* node = 0; MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot; - for ( NodeListIterator it( start->children ); it.current() && !node; ++it ) + for ( NodeList::iterator it = start->children.begin(); it != start->children.end() && !node; ++it ) { - QAction* a = itemAction( it.current()->id ); + QAction* a = itemAction( (*it)->id ); if ( !a ) - a = menuAction( it.current()->id ); - if ( a && clearTitle( a->menuText() ) == clearTitle( title ) ) - node = it.current(); + a = menuAction( (*it)->id ); + if ( a && clearTitle( a->text() ) == clearTitle( title ) ) + node = *it; if ( !node && rec ) - node = find( title, it.current(), rec ); + node = find( title, *it, rec ); } return node; } @@ -839,9 +857,12 @@ QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, MenuNo int QtxActionMenuMgr::findId( const int id, const int pid ) const { MenuNode* start = pid != -1 ? find( pid ) : (MenuNode*)&myRoot; - if ( start ) { - for ( NodeListIterator it( start->children ); it.current(); ++it ) { - if ( it.current()->id == id ) return id; + if ( start ) + { + for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it ) + { + if ( (*it)->id == id ) + return id; } } return -1; @@ -855,12 +876,12 @@ int QtxActionMenuMgr::findId( const int id, const int pid ) const void QtxActionMenuMgr::removeMenu( const int id, MenuNode* startNode ) { MenuNode* start = startNode ? startNode : &myRoot; - for ( NodeListIterator it( start->children ); it.current(); ++it ) + for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it ) { - if ( it.current()->id == id ) - start->children.remove( it.current() ); + if ( (*it)->id == id ) + start->children.removeAll( *it ); else - removeMenu( id, it.current() ); + removeMenu( id, *it ); } } @@ -877,9 +898,9 @@ QAction* QtxActionMenuMgr::itemAction( const int id ) const \return menu action by id \param id - id of action */ -QtxActionMenuMgr::MenuAction* QtxActionMenuMgr::menuAction( const int id ) const +QAction* QtxActionMenuMgr::menuAction( const int id ) const { - MenuAction* a = 0; + QAction* a = 0; if ( myMenus.contains( id ) ) a = myMenus[id]; @@ -907,36 +928,32 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo bool filled = checkWidget( mw ); - for ( NodeListIterator it1( node->children ); it1.current(); ++it1 ) + for ( NodeList::iterator it1 = node->children.begin(); it1 != node->children.end(); ++it1 ) { - QAction* a = itemAction( it1.current()->id ); + QAction* a = itemAction( (*it1)->id ); if ( !a ) - a = menuAction( it1.current()->id ); + a = menuAction( (*it1)->id ); - if ( a ) - a->removeFrom( mw ); + mw->removeAction( a ); +// if ( a ) +// a->removeFrom( mw ); } - /* VSR: commented to allow direct creating of menus by calling insertItem() methods - if ( mw->inherits( "QMenuBar" ) ) - ((QMenuBar*)mw)->clear(); - else if ( mw->inherits( "QPopupMenu" ) ) - ((QPopupMenu*)mw)->clear(); - */ + QMap idMap; - for ( NodeListIterator it2( node->children ); it2.current(); ++it2 ) + for ( NodeList::iterator it2 = node->children.begin(); it2 != node->children.end(); ++it2 ) { - NodeList& lst = idMap[it2.current()->group]; - int idx = it2.current()->idx; + NodeList& lst = idMap[(*it2)->group]; + int idx = (*it2)->idx; if ( idx < 0 || idx >= (int)lst.count() ) - lst.append( it2.current() ); + lst.append( *it2 ); else - lst.insert( idx, it2.current() ); + lst.insert( idx, *it2 ); } QIntList groups = idMap.keys(); - qHeapSort( groups ); + qSort( groups ); - groups.remove( -1 ); + groups.removeAll( -1 ); groups.append( -1 ); for ( QIntList::const_iterator gIt = groups.begin(); gIt != groups.end(); ++gIt ) @@ -945,20 +962,23 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo continue; const NodeList& lst = idMap[*gIt]; - for ( NodeListIterator iter( lst ); iter.current(); ++iter ) + for ( NodeList::const_iterator iter = lst.begin(); iter != lst.end(); ++iter ) { - MenuNode* par = iter.current()->parent; - if ( !isVisible( iter.current()->id, par ? par->id : -1 ) ) - continue; + MenuNode* node = *iter; if ( rec ) - updateMenu( iter.current(), rec, false ); + updateMenu( node, rec, false ); + + MenuNode* par = node->parent; + if ( !isVisible( node->id, par ? par->id : -1 ) ) + continue; - QAction* a = itemAction( iter.current()->id ); + QAction* a = itemAction( node->id ); if ( !a ) - a = menuAction( iter.current()->id ); - if ( a ) - a->addTo( mw ); + a = menuAction( node->id ); + + if ( !a->menu() || !a->menu()->isEmpty() ) + mw->addAction( a ); } } @@ -973,8 +993,11 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo */ void QtxActionMenuMgr::internalUpdate() { - if ( isUpdatesEnabled() ) - updateMenu(); + if ( !isUpdatesEnabled() ) + return; + + updateMenu(); + myUpdateIds.clear(); } /*! @@ -986,13 +1009,7 @@ bool QtxActionMenuMgr::checkWidget( QWidget* wid ) const if ( !wid ) return false; - QMenuData* md = 0; - if ( wid->inherits( "QPopupMenu" ) ) - md = (QPopupMenu*)wid; - else if ( wid->inherits( "QMenuBar" ) ) - md = (QMenuBar*)wid; - - return md ? md->count() : false; + return !wid->actions().isEmpty(); } /*! @@ -1007,7 +1024,7 @@ QWidget* QtxActionMenuMgr::menuWidget( MenuNode* node) const if ( !myMenus.contains( node->id ) || !myMenus[node->id] ) return 0; - return myMenus[node->id]->popup(); + return myMenus[node->id]->menu(); } /*! @@ -1016,8 +1033,7 @@ QWidget* QtxActionMenuMgr::menuWidget( MenuNode* node) const */ void QtxActionMenuMgr::simplifySeparators( QWidget* wid ) { - if ( wid && wid->inherits( "QPopupMenu" ) ) - Qtx::simplifySeparators( (QPopupMenu*)wid, false ); + Qtx::simplifySeparators( wid, false ); } /*! @@ -1050,8 +1066,8 @@ int QtxActionMenuMgr::createMenu( const QStringList& lst, const int pId ) QStringList sl( lst ); - QString title = sl.last().stripWhiteSpace(); - sl.remove( sl.fromLast() ); + QString title = sl.last().trimmed(); + sl.removeLast(); int parentId = sl.isEmpty() ? pId : createMenu( sl, pId ); @@ -1090,16 +1106,48 @@ bool QtxActionMenuMgr::containsMenu( const int id, const int pid ) const return (bool)find( id, pid, false ); } +/*! + \Sets trigger for delayed update +*/ +void QtxActionMenuMgr::triggerUpdate( const int id, const bool rec ) +{ + bool isRec = rec; + if ( myUpdateIds.contains( id ) ) + isRec = isRec || myUpdateIds[ id ]; + myUpdateIds.insert( id, isRec ); + + QtxActionMgr::triggerUpdate(); +} + +/*! + \Sets trigger for delayed update +*/ +void QtxActionMenuMgr::updateContent() +{ + // Warning: For correct updating it is necessary to update the most enclosed submenu firstly + // because not updated empty submenu will be skipped. Now the submenu are iterated in + // ascending order their identifiers. For a submenu with automatically generated identifiers + // will work correctly as the uppermost submenu have the biggest number (identifiers generated + // reduction from -1). Generally when any submenu will have positive identifiers are obviously + // appropriated can to work not truly. In this case it is required to improve the given method + // and to add preliminary sorting a submenu on depth of an enclosure. + for ( QMap::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it ) + { + MenuNode* node = it.key() == -1 ? &myRoot : find( it.key() ); + if ( node ) + updateMenu( node, it.value() ); + } + myUpdateIds.clear(); +} /*! Constructor \param r - menu reader \param mgr - menu manager */ -QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r, - QtxActionMenuMgr* mgr ) +QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r, QtxActionMenuMgr* mgr ) : QtxActionMgr::Creator( r ), - myMgr( mgr ) +myMgr( mgr ) { } @@ -1141,10 +1189,11 @@ int QtxActionMenuMgr::MenuCreator::append( const QString& tag, const bool subMen res = myMgr->insert( separator(), pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) ); else { - QPixmap pix; QIconSet set; + QIcon set; + QPixmap pix; QString name = strValue( attr, icon ); if( !name.isEmpty() && loadPixmap( name, pix ) ) - set = QIconSet( pix ); + set = QIcon( pix ); QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, strValue( attr, label ), @@ -1152,8 +1201,8 @@ int QtxActionMenuMgr::MenuCreator::append( const QString& tag, const bool subMen myMgr ); newAct->setToolTip( strValue( attr, tooltip ) ); QString toggleact = strValue( attr, toggle ); - newAct->setToggleAction( !toggleact.isEmpty() ); - newAct->setOn( toggleact.lower()=="true" ); + newAct->setCheckable( !toggleact.isEmpty() ); + newAct->setChecked( toggleact.toLower() == "true" ); connect( newAct ); int aid = myMgr->registerAction( newAct, actId ); diff --git a/src/Qtx/QtxActionMenuMgr.h b/src/Qtx/QtxActionMenuMgr.h index bdbe139a4..80d00c43c 100644 --- a/src/Qtx/QtxActionMenuMgr.h +++ b/src/Qtx/QtxActionMenuMgr.h @@ -25,8 +25,8 @@ #include "Qtx.h" #include "QtxActionMgr.h" -#include -#include +#include +#include class QPopupMenu; class QMainWindow; @@ -53,8 +53,7 @@ class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr class MenuNode; - typedef QPtrList NodeList; - typedef QPtrListIterator NodeListIterator; + typedef QList NodeList; /*! \class MenuNode @@ -64,8 +63,13 @@ class QTX_EXPORT QtxActionMenuMgr : public QtxActionMgr class MenuNode { public: - MenuNode() : parent( 0 ), visible( true ) { children.setAutoDelete( true ); }; - MenuNode( MenuNode* p ) : parent( p ), visible( true ) { children.setAutoDelete( true ); }; + MenuNode() : parent( 0 ), visible( true ) {}; + MenuNode( MenuNode* p ) : parent( p ), visible( true ) {}; + ~MenuNode() + { + for ( NodeList::iterator it = children.begin(); it != children.end(); ++it ) + delete *it; + } int id; int idx; @@ -118,6 +122,8 @@ public: bool isShown( const int ) const; void setShown( const int, const bool ); + virtual void change( const int, const QString& ); + virtual bool load( const QString&, QtxActionMgr::Reader& ); bool containsMenu( const QString&, const int ) const; @@ -144,10 +150,11 @@ protected: void removeMenu( const int, MenuNode* ); QAction* itemAction( const int ) const; - MenuAction* menuAction( const int ) const; + QAction* menuAction( const int ) const; void updateMenu( MenuNode* = 0, const bool = true, const bool = true ); virtual void internalUpdate(); + virtual void updateContent(); private: bool checkWidget( QWidget* ) const; @@ -156,13 +163,16 @@ private: QString clearTitle( const QString& ) const; int createMenu( const QStringList&, const int ); + void triggerUpdate( const int, const bool rec = true ); + private: - typedef QMap MenuMap; + typedef QMap MenuMap; private: MenuNode myRoot; QWidget* myMenu; MenuMap myMenus; + QMap myUpdateIds; }; /*! diff --git a/src/Qtx/QtxActionMgr.cxx b/src/Qtx/QtxActionMgr.cxx index b157b835e..bd6a6bd5e 100644 --- a/src/Qtx/QtxActionMgr.cxx +++ b/src/Qtx/QtxActionMgr.cxx @@ -23,20 +23,23 @@ #include "QtxActionMgr.h" #include "QtxAction.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include -static QAction* qtx_separator_action = 0; +#include +#include +#include +#include + +#include + +typedef QList< QPointer > qtx_actionlist; +static qtx_actionlist qtx_separator_actions; void qtxSeparatorActionCleanup() { - delete qtx_separator_action; - qtx_separator_action = 0; + for ( qtx_actionlist::iterator it = qtx_separator_actions.begin(); it != qtx_separator_actions.end(); ++it ) + delete *it; } /*! @@ -49,13 +52,6 @@ class QtxActionMgr::SeparatorAction : public QtxAction public: SeparatorAction( QObject* = 0 ); virtual ~SeparatorAction(); - - virtual bool addTo( QWidget* ); - virtual bool removeFrom( QWidget* ); - -private: - QMap myMenus; - QMap myTools; }; /*! @@ -64,6 +60,7 @@ private: QtxActionMgr::SeparatorAction::SeparatorAction( QObject* parent ) : QtxAction( parent ) { + setSeparator( true ); } /*! @@ -73,82 +70,6 @@ QtxActionMgr::SeparatorAction::~SeparatorAction() { } -/*! - Adds action to widget - \param wid - widget -*/ -bool QtxActionMgr::SeparatorAction::addTo( QWidget* wid ) -{ - if ( !wid ) - return false; - - bool res = true; - if ( wid->inherits( "QPopupMenu" ) ) - { - QPopupMenu* popup = (QPopupMenu*)wid; - myMenus[popup].append( popup->insertSeparator() ); - } - else if ( wid->inherits( "QToolBar" ) ) - { - QToolBar* tb = (QToolBar*)wid; - tb->addSeparator(); - myTools[tb].append( (QWidget*)tb->children()->getLast() ); - } - else - res = false; - - return res; -} - -/*! - Removes action from widget - \param wid - widget -*/ -bool QtxActionMgr::SeparatorAction::removeFrom( QWidget* wid ) -{ - if ( !wid ) - return false; - - bool res = true; - if ( wid->inherits( "QPopupMenu" ) ) - { - QPopupMenu* popup = (QPopupMenu*)wid; - if ( myMenus.contains( popup ) ) - { - const QIntList& list = myMenus[popup]; - for ( QIntList::const_iterator it = list.begin(); it != list.end(); ++it ) - popup->removeItem( *it ); - - myMenus.remove( popup ); - } - } - else if ( wid->inherits( "QToolBar" ) ) - { - QToolBar* tb = (QToolBar*)wid; - if ( myTools.contains( tb ) ) - { - QMap childMap; - if ( tb->children() ) - { - for ( QObjectListIt it( *tb->children() ); it.current(); ++it ) - childMap.insert( it.current(), 0 ); - } - const QWidgetList& list = myTools[tb]; - for ( QWidgetListIt it( list ); it.current(); ++it ) - { - if ( childMap.contains( it.current() ) ) - delete it.current(); - } - - myTools.remove( tb ); - } - } - else - res = false; - - return res; -} - /*! Class: QtxActionMgr Level: Public @@ -159,7 +80,8 @@ bool QtxActionMgr::SeparatorAction::removeFrom( QWidget* wid ) */ QtxActionMgr::QtxActionMgr( QObject* parent ) : QObject( parent ), -myUpdate( true ) +myUpdate( true ), +myUpdTimer( 0 ) { } @@ -234,7 +156,7 @@ int QtxActionMgr::actionId( const QAction* a ) const int theId = -1; for ( ActionMap::ConstIterator it = myActions.begin(); it != myActions.end() && theId == -1; ++it ) { - if ( it.data() == a ) + if ( it.value() == a ) theId = it.key(); } @@ -312,8 +234,12 @@ void QtxActionMgr::setVisible( const int, const int, const bool ) */ void QtxActionMgr::update() { - if ( isUpdatesEnabled() ) - internalUpdate(); + if ( !isUpdatesEnabled() ) + return; + + internalUpdate(); + if ( myUpdTimer ) + myUpdTimer->stop(); } /*! @@ -367,12 +293,48 @@ QAction* QtxActionMgr::separator( const bool individual ) if ( individual ) return new SeparatorAction(); - if ( !qtx_separator_action ) - { - qtx_separator_action = new SeparatorAction(); + if ( qtx_separator_actions.isEmpty() ) qAddPostRoutine( qtxSeparatorActionCleanup ); + + SeparatorAction* a = new SeparatorAction(); + qtx_separator_actions.append( a ); + + return a; +} + +/*! + \initialise timer for delayed update +*/ +void QtxActionMgr::triggerUpdate() +{ + if ( !isUpdatesEnabled() ) + return; + + if ( !myUpdTimer ) + { + myUpdTimer = new QTimer( this ); + myUpdTimer->setSingleShot( true ); + connect( myUpdTimer, SIGNAL( timeout() ), this, SLOT( onUpdateContent() ) ); } - return qtx_separator_action; + myUpdTimer->stop(); + // add timer event to event list + myUpdTimer->start( 0 ); +} + +/*! + \perform delayed update + \default implementation is empty +*/ +void QtxActionMgr::updateContent() +{} + +/*! + \perform delayed update + \default implementation is empty +*/ +void QtxActionMgr::onUpdateContent() +{ + updateContent(); } /*! @@ -427,7 +389,8 @@ void QtxActionMgr::Reader::setOption( const QString& name, const QString& value /*! - Constructor + Class: QtxActionMgr::XMLReader + Level: Public */ QtxActionMgr::XMLReader::XMLReader( const QString& root, const QString& item, @@ -467,7 +430,7 @@ bool QtxActionMgr::XMLReader::read( const QString& fname, Creator& cr ) const #ifndef QT_NO_DOM QFile file( fname ); - if ( !file.open( IO_ReadOnly ) ) + if ( !file.open( QFile::ReadOnly ) ) return res; QDomDocument doc; @@ -513,7 +476,7 @@ void QtxActionMgr::XMLReader::read( const QDomNode& parent_node, if( parent_node.isNull() ) return; - QStringList items = QStringList::split( "|", option( QString( "menu_item" ) ) ); + QStringList items = option( "menu_item" ).split( "|", QString::SkipEmptyParts ); const QDomNodeList& children = parent_node.childNodes(); for( int i=0, n=children.count(); ioption( "icons_dir", "." ) ); + QStringList dirlist = reader()->option( "icons_dir", "." ).split( ";", QString::SkipEmptyParts ); QStringList::const_iterator anIt = dirlist.begin(), aLast = dirlist.end(); bool res = false; diff --git a/src/Qtx/QtxActionMgr.h b/src/Qtx/QtxActionMgr.h index e0ba1d0e6..a2fee6b7f 100644 --- a/src/Qtx/QtxActionMgr.h +++ b/src/Qtx/QtxActionMgr.h @@ -24,14 +24,14 @@ #include "Qtx.h" -#include -#include -#include +#include +#include +#include +class QTimer; class QAction; class QDomNode; - #ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -87,13 +87,21 @@ protected: virtual void internalUpdate(); int generateId() const; + //! initialise timer for delayed update + void triggerUpdate(); + virtual void updateContent(); + +private slots: + void onUpdateContent(); + private: - typedef QGuardedPtr ActionPtr; + typedef QPointer ActionPtr; typedef QMap ActionMap; private: bool myUpdate; ActionMap myActions; + QTimer* myUpdTimer; }; diff --git a/src/Qtx/QtxActionToolMgr.cxx b/src/Qtx/QtxActionToolMgr.cxx index 9ce569613..ed0455cc3 100644 --- a/src/Qtx/QtxActionToolMgr.cxx +++ b/src/Qtx/QtxActionToolMgr.cxx @@ -24,8 +24,7 @@ #include "QtxAction.h" #include "QtxToolBar.h" -#include -#include +#include /*! Constructor @@ -64,7 +63,7 @@ int QtxActionToolMgr::createToolBar( const QString& name, const int tid ) int tbId = -1; for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && tbId == -1; ++it ) { - if ( it.data().toolBar->label().lower() == name.lower() ) + if ( it.value().toolBar->windowTitle().toLower() == name.toLower() ) tbId = it.key(); } @@ -81,7 +80,8 @@ int QtxActionToolMgr::createToolBar( const QString& name, const int tid ) if ( !tb ) { tb = new QtxToolBar( true, mainWindow() ); - tb->setLabel( name ); + mainWindow()->addToolBar( tb ); + tb->setWindowTitle( name ); } tInfo.toolBar = tb; @@ -100,18 +100,14 @@ QToolBar* QtxActionToolMgr::find( const QString& label, QMainWindow* mw ) const if ( !mw ) return 0; - QString pattern = label.lower(); + QString pattern = label.toLower(); QToolBar* res = 0; - QPtrList lst = mw->dockWindows(); - for ( QPtrListIterator it( lst ); it.current() && !res; ++it ) + QList toolbars = qFindChildren( mw ); + for ( QList::iterator it = toolbars.begin(); it != toolbars.end() && !res; ++it ) { - if ( !it.current()->inherits( "QToolBar" ) ) - continue; - - QToolBar* cur = (QToolBar*)it.current(); - if ( cur->label().lower() == pattern ) - res = cur; + if ( (*it)->windowTitle().toLower() == pattern ) + res = *it; } return res; } @@ -148,17 +144,17 @@ int QtxActionToolMgr::insert( const int id, const int tid, const int idx ) { if ( !contains( id ) || !hasToolBar( tid ) ) return -1; - +/* if ( containsAction( id, tid ) ) remove( id, tid ); - +*/ ToolNode node; node.id = id; NodeList& list = myToolBars[tid].nodes; - int index = idx < 0 ? list.count() : QMIN( idx, (int)list.count() ); - list.insert( list.at( index ), node ); - updateToolBar( tid ); + int index = idx < 0 ? list.count() : qMin( idx, (int)list.count() ); + list.insert( index, node ); + triggerUpdate( tid ); return id; } @@ -296,7 +292,7 @@ void QtxActionToolMgr::remove( const int id, const int tid ) myToolBars[tid].nodes = newList; - updateToolBar( tid ); + triggerUpdate( tid ); } /*! @@ -357,8 +353,9 @@ bool QtxActionToolMgr::containsAction( const int id, const int tid ) const { for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it ) { - if ( tid == -1 || it.key() == tid ) { - const NodeList& list = it.data().nodes; + if ( tid == -1 || it.key() == tid ) + { + const NodeList& list = it.value().nodes; for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit ) if ( (*nit).id == id ) return true; @@ -384,7 +381,7 @@ int QtxActionToolMgr::find( const QString& tname ) const int id = -1; for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it ) { - if ( it.data().toolBar->label() == tname ) + if ( it.value().toolBar->windowTitle() == tname ) id = it.key(); } return id; @@ -399,7 +396,7 @@ int QtxActionToolMgr::find( QToolBar* t ) const int id = -1; for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it ) { - if ( it.data().toolBar == t ) + if ( it.value().toolBar == t ) id = it.key(); } return id; @@ -423,8 +420,9 @@ void QtxActionToolMgr::updateToolBar( const int tId ) for ( NodeList::const_iterator it = list.begin(); it != list.end(); ++it ) { QAction* a = action( (*it).id ); - if ( a ) - a->removeFrom( tb ); + tb->removeAction( a ); +// if ( a ) +// a->removeFrom( tb ); } tb->clear(); @@ -435,8 +433,9 @@ void QtxActionToolMgr::updateToolBar( const int tId ) continue; QAction* a = action( (*itr).id ); - if ( a ) - a->addTo( tb ); + tb->addAction( a ); +// if ( a ) +// a->addTo( tb ); } simplifySeparators( tb ); @@ -447,8 +446,13 @@ void QtxActionToolMgr::updateToolBar( const int tId ) */ void QtxActionToolMgr::internalUpdate() { + if ( !isUpdatesEnabled() ) + return; + for ( ToolBarMap::ConstIterator it1 = myToolBars.begin(); it1 != myToolBars.end(); ++it1 ) updateToolBar( it1.key() ); + + myUpdateIds.clear(); } /*! @@ -456,8 +460,7 @@ void QtxActionToolMgr::internalUpdate() */ void QtxActionToolMgr::simplifySeparators( QToolBar* t ) { - if ( t ) - Qtx::simplifySeparators( t ); + Qtx::simplifySeparators( t ); } /*! @@ -495,10 +498,10 @@ void QtxActionToolMgr::setShown( const int id, const bool on ) */ bool QtxActionToolMgr::isShown( const int id ) const { - QPtrList nodes; + QList nodes; for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it ) { - const NodeList& nl = it.data().nodes; + const NodeList& nl = it.value().nodes; for ( NodeList::const_iterator itr = nl.begin(); itr != nl.end(); ++itr ) { const ToolNode& node = *itr; @@ -511,8 +514,8 @@ bool QtxActionToolMgr::isShown( const int id ) const return false; bool vis = true; - for ( QPtrListIterator itr( nodes ); itr.current() && vis; ++itr ) - vis = itr.current()->visible; + for ( QList::iterator itr = nodes.begin(); itr != nodes.end() && vis; ++itr ) + vis = (*itr)->visible; return vis; } @@ -562,7 +565,7 @@ void QtxActionToolMgr::setVisible( const int id, const int tId, const bool on ) } if ( changed ) - updateToolBar( tId ); + triggerUpdate( tId ); } /*! @@ -576,9 +579,31 @@ bool QtxActionToolMgr::load( const QString& fname, QtxActionMgr::Reader& r ) return r.read( fname, cr ); } +/*! + \Perform delayed update +*/ +void QtxActionToolMgr::updateContent() +{ + if ( !isUpdatesEnabled() ) + return; + + for ( QMap::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it ) + updateToolBar( it.key() ); + myUpdateIds.clear(); +} /*! - Constructor + \ Sets trigger to update +*/ +void QtxActionToolMgr::triggerUpdate( const int id ) +{ + myUpdateIds.insert( id, 0 ); + QtxActionMgr::triggerUpdate(); +} + +/*! + Class: QtxActionToolMgr::ToolCreator + Level: Public */ QtxActionToolMgr::ToolCreator::ToolCreator( QtxActionMgr::Reader* r, QtxActionToolMgr* mgr ) @@ -624,18 +649,17 @@ int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool subMen res = myMgr->insert( separator(), tId, intValue( attr, pos, -1 ) ); else { - QPixmap pix; QIconSet set; + QIcon set; + QPixmap pix; QString name = strValue( attr, icon ); if( !name.isEmpty() && loadPixmap( name, pix ) ) - set = QIconSet( pix ); + set = QIcon( pix ); - QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, - strValue( attr, label ), - QKeySequence( strValue( attr, accel ) ), - myMgr ); + QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, strValue( attr, label ), + QKeySequence( strValue( attr, accel ) ), myMgr ); QString toggleact = strValue( attr, toggle ); - newAct->setToggleAction( !toggleact.isEmpty() ); - newAct->setOn( toggleact.lower()=="true" ); + newAct->setCheckable( !toggleact.isEmpty() ); + newAct->setChecked( toggleact.toLower() == "true" ); connect( newAct ); int aid = myMgr->registerAction( newAct, actId ); @@ -644,5 +668,3 @@ int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool subMen return res; } - - diff --git a/src/Qtx/QtxActionToolMgr.h b/src/Qtx/QtxActionToolMgr.h index 9300ec22a..b8b39227d 100644 --- a/src/Qtx/QtxActionToolMgr.h +++ b/src/Qtx/QtxActionToolMgr.h @@ -24,7 +24,10 @@ #include "Qtx.h" -#include +#include +#include + +#include #include "QtxActionMgr.h" @@ -60,7 +63,7 @@ class QTX_EXPORT QtxActionToolMgr : public QtxActionMgr bool visible; }; - typedef QValueList NodeList; + typedef QList NodeList; protected: class ToolCreator; @@ -122,8 +125,11 @@ protected: virtual void internalUpdate(); void updateToolBar( const int ); + virtual void updateContent(); + private: void simplifySeparators( QToolBar* ); + void triggerUpdate( const int ); private: typedef struct { NodeList nodes; QToolBar* toolBar; } ToolBarInfo; @@ -132,6 +138,7 @@ private: private: ToolBarMap myToolBars; QMainWindow* myMainWindow; + QMap myUpdateIds; }; /*! diff --git a/src/Qtx/QtxColorScale.cxx b/src/Qtx/QtxColorScale.cxx index 30c919361..2a62d888e 100755 --- a/src/Qtx/QtxColorScale.cxx +++ b/src/Qtx/QtxColorScale.cxx @@ -21,30 +21,27 @@ #include "QtxColorScale.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include + +#include +#include +#include +#include +#include #include /*! Constructor */ -QtxColorScale::QtxColorScale( QWidget* parent, const char* name, WFlags f ) -: QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ), -myDock( 0 ), +QtxColorScale::QtxColorScale( QWidget* parent, Qt::WindowFlags f ) +: QFrame( parent, f ), myMin( 0.0 ), myMax( 1.0 ), myTitle( "" ), myInterval( 10 ), -myStyleSheet( 0 ), myFormat( "%.4g" ), myColorMode( Auto ), myLabelMode( Auto ), @@ -53,20 +50,18 @@ myTitlePos( Center ), myDumpMode( NoDump ), myFlags( AtBorder | WrapTitle ) { - setCaption( tr ( "Color scale" ) ); + setWindowTitle( tr ( "Color scale" ) ); } /*! Constructor */ -QtxColorScale::QtxColorScale( const int num, QWidget* parent, const char* name, WFlags f ) -: QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ), -myDock( 0 ), +QtxColorScale::QtxColorScale( const int num, QWidget* parent, Qt::WindowFlags f ) +: QFrame( parent, f ), myMin( 0.0 ), myMax( 1.0 ), myTitle( "" ), myInterval( num ), -myStyleSheet( 0 ), myFormat( "%.4g" ), myColorMode( Auto ), myLabelMode( Auto ), @@ -75,35 +70,9 @@ myTitlePos( Center ), myDumpMode( NoDump ), myFlags( AtBorder | WrapTitle ) { - setCaption( tr ( "Color scale" ) ); + setWindowTitle( tr ( "Color scale" ) ); } -#if QT_VER == 3 - -/*! - Constructor -*/ -QtxColorScale::QtxColorScale( Dock* dock, const char* name, WFlags f ) -: QFrame( dock, name, f | WResizeNoErase | WRepaintNoErase ), -myMin( 0.0 ), -myMax( 1.0 ), -myTitle( "" ), -myDock( dock ), -myInterval( 10 ), -myStyleSheet( 0 ), -myFormat( "%.4g" ), -myColorMode( Auto ), -myLabelMode( Auto ), -myLabelPos( Right ), -myTitlePos( Center ), -myDumpMode( NoDump ), -myFlags( AtBorder | WrapTitle ) -{ - setCaption( tr ( "Color scale" ) ); -} - -#endif - /*! Destructor */ @@ -191,7 +160,7 @@ QString QtxColorScale::label( const int idx ) const { QString res; if ( idx >= 0 && idx < (int)myLabels.count() ) - res = *myLabels.at( idx ); + res = myLabels[idx]; return res; } @@ -202,7 +171,7 @@ QColor QtxColorScale::color( const int idx ) const { QColor res; if ( idx >= 0 && idx < (int)myColors.count() ) - res = *myColors.at( idx ); + res = myColors[idx]; return res; } @@ -217,7 +186,7 @@ void QtxColorScale::labels( QStringList& list ) const /*! \return the user color. */ -void QtxColorScale::colors( QValueList& list ) const +void QtxColorScale::colors( QList& list ) const { list = myColors; } @@ -323,7 +292,7 @@ void QtxColorScale::setLabel( const QString& txt, const int idx ) uint i = idx < 0 ? myLabels.count() : idx; if ( i < myLabels.count() ) { - changed = *myLabels.at( i ) != txt; + changed = myLabels[i] != txt; myLabels[i] = txt; } else @@ -348,7 +317,7 @@ void QtxColorScale::setColor( const QColor& clr, const int idx ) uint i = idx < 0 ? myColors.count() : idx; if ( i < myColors.count() ) { - changed = *myColors.at( i ) != clr; + changed = myColors[i] != clr; myColors[i] = clr; } else @@ -377,7 +346,7 @@ void QtxColorScale::setLabels( const QStringList& list ) /*! Replace the all user colors with specified list. */ -void QtxColorScale::setColors( const QValueList& list ) +void QtxColorScale::setColors( const QList& list ) { if ( list.isEmpty() ) return; @@ -509,13 +478,13 @@ QSize QtxColorScale::calculateSize( const bool min, const int flags, const bool QString fmt = that->myFormat; for ( int idx = 0; idx < num; idx++ ) - textWidth = QMAX( textWidth, fontMetrics().width( getLabel( idx ) ) ); + textWidth = qMax( textWidth, fontMetrics().width( getLabel( idx ) ) ); if ( !min ) that->myFormat = that->myFormat.replace( QRegExp( "g" ), "f" ); for ( int index = 0; index < num; index++ ) - textWidth = QMAX( textWidth, fontMetrics().width( getLabel( index ) ) ); + textWidth = qMax( textWidth, fontMetrics().width( getLabel( index ) ) ); that->myFormat = fmt; } @@ -537,28 +506,28 @@ QSize QtxColorScale::calculateSize( const bool min, const int flags, const bool { scaleWidth = colorWidth + textWidth + ( textWidth ? 3 : 2 ) * spacer; if ( min ) - scaleHeight = QMAX( 2 * num, 3 * textHeight ); + scaleHeight = qMax( 2 * num, 3 * textHeight ); else scaleHeight = (int)( 1.5 * ( num + 1 ) * textHeight ); } if ( title ) { - QSimpleRichText* srt = simpleRichText( flags ); + QTextDocument* srt = textDocument( flags ); if ( srt ) { - QPainter p( this ); + QPainter p( (QtxColorScale*)this ); if ( scaleWidth ) - srt->setWidth( &p, scaleWidth ); + srt->setTextWidth( scaleWidth ); - titleHeight = srt->height() + spacer; - titleWidth = srt->widthUsed() + 10; + titleHeight = srt->size().height() + spacer; + titleWidth = srt->size().width() + 10; - delete srt; } + delete srt; } - int W = QMAX( titleWidth, scaleWidth ) + width() - contentsRect().width(); + int W = qMax( titleWidth, scaleWidth ) + width() - contentsRect().width(); int H = scaleHeight + titleHeight + height() - contentsRect().height(); return QSize( W, H ); @@ -581,12 +550,7 @@ QPixmap QtxColorScale::dump() const labelPosition() != None; bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) && titlePosition() != None; - -#if QT_VER < 3 - QColor bgc = backgroundColor(); -#else - QColor bgc = paletteBackgroundColor(); -#endif + QColor bgc = palette().color( backgroundRole() ); QPainter p; p.begin( &aPix ); p.fillRect( 0, 0, aPix.width(), aPix.height(), bgc ); @@ -603,11 +567,7 @@ QPixmap QtxColorScale::dump() const */ QPixmap QtxColorScale::dump( const int w, const int h ) const { -#if QT_VER < 3 - return dump( backgroundColor(), w, h ); -#else - return dump( paletteBackgroundColor(), w, h ); -#endif + return dump( palette().color( backgroundRole() ), w, h ); } /*! @@ -655,11 +615,6 @@ QPixmap QtxColorScale::dump( const QColor& bg, const int w, const int h ) const */ void QtxColorScale::show() { -#if QT_VER == 3 - if ( myDock ) - myDock->activate(); - else -#endif QFrame::show(); } @@ -668,11 +623,6 @@ void QtxColorScale::show() */ void QtxColorScale::hide() { -#if QT_VER == 3 - if ( myDock ) - myDock->deactivate(); - else -#endif QFrame::hide(); } @@ -681,7 +631,7 @@ void QtxColorScale::hide() */ void QtxColorScale::drawContents( QPainter* p ) { - if ( !isUpdatesEnabled() ) + if ( !updatesEnabled() ) return; QRect aDrawRect = contentsRect(); @@ -701,11 +651,7 @@ void QtxColorScale::drawScale( QPainter* p, const bool transp, const int X, cons QPixmap cache( W, H ); QPainter cp( &cache ); -#if QT_VER < 3 - drawScale( &cp, backgroundColor(), transp, 0, 0, W, H, title, label, scale ); -#else - drawScale( &cp, paletteBackgroundColor(), transp, 0, 0, W, H, title, label, scale ); -#endif + drawScale( &cp, palette().color( backgroundRole() ), transp, 0, 0, W, H, title, label, scale ); cp.end(); p->drawPixmap( X, Y, cache ); @@ -737,29 +683,29 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, if ( qGray( bg.rgb() ) < 128 ) p->setPen( QColor( 255, 255, 255 ) ); else - p->setPen( QColor( 0, 0, 0 ) ); + p->setPen( QColor( 0, 0, 0 ) ); // Draw title if ( drawTitle ) { - QSimpleRichText* srt = simpleRichText( myFlags ); + QTextDocument* srt = textDocument( myFlags ); if ( srt ) { - srt->setWidth( p, W - 10 ); - titleHeight = srt->height() + spacer; - titleWidth = srt->widthUsed(); - QColorGroup cg = colorGroup(); - cg.setColor( QColorGroup::Text, p->pen().color() ); - srt->draw( p, X + 5, Y, QRect( 0, 0, srt->width(), srt->height() ), cg ); - - delete srt; + srt->setTextWidth( W - 10 ); + titleHeight = srt->size().height() + spacer; + titleWidth = srt->size().width(); + p->save(); + p->translate( X + 5, Y ); + srt->drawContents( p ); + p->restore(); } + delete srt; } bool reverse = testFlags( Reverse ); - QValueList colors; - QValueList labels; + QList colors; + QList labels; for ( int idx = 0; idx < num; idx++ ) { if ( reverse ) @@ -781,29 +727,29 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, else labels.prepend( getLabel( num ) ); if ( drawLabel ) - textWidth = QMAX( textWidth, p->fontMetrics().width( labels.last() ) ); + textWidth = qMax( textWidth, p->fontMetrics().width( labels.last() ) ); } if ( drawLabel ) { const QFontMetrics& fm = p->fontMetrics(); for ( QStringList::ConstIterator it = labels.begin(); it != labels.end(); ++it ) - textWidth = QMAX( textWidth, fm.width( *it) ); + textWidth = qMax( textWidth, fm.width( *it) ); } int lab = labels.count(); - double spc = ( H - ( ( QMIN( lab, 2 ) + QABS( lab - num - 1 ) ) * textHeight ) - titleHeight ); - double val = spc != 0 ? 1.0 * ( lab - QMIN( lab, 2 ) ) * textHeight / spc : 0; + double spc = ( H - ( ( qMin( lab, 2 ) + qAbs( lab - num - 1 ) ) * textHeight ) - titleHeight ); + double val = spc != 0 ? 1.0 * ( lab - qMin( lab, 2 ) ) * textHeight / spc : 0; double iPart; double fPart = modf( val, &iPart ); int filter = (int)iPart + ( fPart != 0 ? 1 : 0 ); - filter = QMAX( filter, 1 ); + filter = qMax( filter, 1 ); - double step = 1.0 * ( H - ( lab - num + QABS( lab - num - 1 ) ) * textHeight - titleHeight ) / num; + double step = 1.0 * ( H - ( lab - num + qAbs( lab - num - 1 ) ) * textHeight - titleHeight ) / num; int ascent = p->fontMetrics().ascent(); - int colorWidth = QMAX( 5, QMIN( 20, W - textWidth - 3 * spacer ) ); + int colorWidth = qMax( 5, qMin( 20, W - textWidth - 3 * spacer ) ); if ( labPos == Center || !drawLabel ) colorWidth = W - 2 * spacer; @@ -816,8 +762,8 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, break; } - double offset = 1.0 * textHeight / 2 * ( lab - num + QABS( lab - num - 1 ) ) + titleHeight; - QValueList::Iterator cit = colors.begin(); + double offset = 1.0 * textHeight / 2 * ( lab - num + qAbs( lab - num - 1 ) ) + titleHeight; + QList::Iterator cit = colors.begin(); uint ci = 0; for ( ci = 0; cit != colors.end() && drawColors; ++cit, ci++ ) { @@ -830,8 +776,8 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, p->drawRect( int( x - 1 ), int( Y + offset - 1 ), int( colorWidth + 2 ), int( ci * step + 2 ) ); // Draw labels - offset = 1.0 * QABS( lab - num - 1 ) * ( step - textHeight ) / 2 + - 1.0 * QABS( lab - num - 1 ) * textHeight / 2; + offset = 1.0 * qAbs( lab - num - 1 ) * ( step - textHeight ) / 2 + + 1.0 * qAbs( lab - num - 1 ) * textHeight / 2; offset += titleHeight; if ( drawLabel && !labels.isEmpty() ) { @@ -854,12 +800,12 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, int pos2 = lab - 1 - i2; if ( filter && !( pos1 % filter ) ) { - p->drawText( x, (int)( Y + i1 * step + ascent + offset ), *labels.at( i1 ) ); + p->drawText( x, (int)( Y + i1 * step + ascent + offset ), labels[i1] ); last1 = i1; } if ( filter && !( pos2 % filter ) ) { - p->drawText( x, (int)( Y + i2 * step + ascent + offset ), *labels.at( i2 ) ); + p->drawText( x, (int)( Y + i2 * step + ascent + offset ), labels[i2] ); last2 = i2; } i1++; @@ -870,13 +816,13 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, while ( pos <= i2 && i0 == -1 ) { if ( filter && !( pos % filter ) && - QABS( pos - last1 ) >= filter && QABS( pos - last2 ) >= filter ) + qAbs( pos - last1 ) >= filter && qAbs( pos - last2 ) >= filter ) i0 = pos; pos++; } if ( i0 != -1 ) - p->drawText( x, (int)( Y + i0 * step + ascent + offset ), *labels.at( i0 ) ); + p->drawText( x, (int)( Y + i0 * step + ascent + offset ), labels[i0] ); } } @@ -893,11 +839,11 @@ QString QtxColorScale::getFormat() const if ( !myPrecise.isEmpty() ) return myPrecise; - if ( aFormat.find( QRegExp( "^(%[0-9]*.?[0-9]*[fegFEG])$" ) ) != 0 ) + if ( !aFormat.contains( QRegExp( "^(%[0-9]*.?[0-9]*[fegFEG])$" ) ) ) return aFormat; - int pos1 = aFormat.find( '.' ); - int pos2 = aFormat.find( QRegExp( "[fegFEG]") ); + int pos1 = aFormat.indexOf( '.' ); + int pos2 = aFormat.indexOf( QRegExp( "[fegFEG]") ); QString aLocFormat; int precision = 1; @@ -927,7 +873,7 @@ QString QtxColorScale::getFormat() const for ( int idx = 0; idx < intervalsNumber() && !isHasTwinz; idx++ ) { double val = getNumber( idx ); - QString tmpname = QString().sprintf( aTmpFormat, val ); + QString tmpname = QString().sprintf( aTmpFormat.toLatin1(), val ); isHasTwinz = map.contains( tmpname ); map.insert( tmpname, 1 ); } @@ -950,7 +896,7 @@ double QtxColorScale::getNumber( const int idx ) const { double val = 0; if ( intervalsNumber() > 0 ) - val = minimum() + idx * ( QABS( maximum() - minimum() ) / intervalsNumber() ); + val = minimum() + idx * ( qAbs( maximum() - minimum() ) / intervalsNumber() ); return val; } @@ -965,7 +911,7 @@ QString QtxColorScale::getLabel( const int idx ) const else { double val = getNumber( idx ); - res = QString().sprintf( getFormat(), testFlags( Integer ) ? (int)val : val ); + res = QString().sprintf( getFormat().toLatin1(), testFlags( Integer ) ? (int)val : val ); } return res; } @@ -997,9 +943,9 @@ void QtxColorScale::updateScale() not defined (empty string) then return null pointer. Object should be deleted by caller function. */ -QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const +QTextDocument* QtxColorScale::textDocument( const int flags ) const { - QSimpleRichText* srt = 0; + QTextDocument* doc = 0; QString aTitle; switch ( titlePosition() ) @@ -1020,6 +966,7 @@ QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const if ( !aTitle.isEmpty() && !title().isEmpty() ) { + /* if ( !myStyleSheet ) { QtxColorScale* that = (QtxColorScale*)this; @@ -1033,163 +980,10 @@ QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const item->setWhiteSpaceMode( flags & WrapTitle ? QStyleSheetItem::WhiteSpaceNormal : QStyleSheetItem::WhiteSpaceNoWrap ); } - - aTitle = aTitle.arg( title() ); - srt = new QSimpleRichText( aTitle, font(), QString::null, myStyleSheet ); - } - - return srt; -} - -#if QT_VER == 3 - -/*! - \class QtxColorScale::Dock - Dockable window contains the color scale. -*/ - -/*! - Constructor -*/ -QtxColorScale::Dock::Dock( Place p, QWidget* parent, const char* name, WFlags f ) -: QDockWindow( p, parent, name, f ), -myBlockShow( false ), -myBlockResize( false ) -{ - myScale = new QtxColorScale( this ); - - setWidget( myScale ); - - setCloseMode( Always ); - setMovingEnabled( true ); - setResizeEnabled( true ); - setHorizontalStretchable( false ); - - setCaption( tr ( "Color scale" ) ); -} - -/*! - Destructor. -*/ -QtxColorScale::Dock::~Dock() -{ -} - -/*! - \return color scale widget. -*/ -QtxColorScale* QtxColorScale::Dock::colorScale() const -{ - return myScale; -} - -/*! - Set the dockable window is visible for main window. -*/ -void QtxColorScale::Dock::activate() -{ - if ( myBlockShow ) - return; - - QMainWindow* mw = 0; - QWidget* p = parentWidget(); - while ( !mw && p ) - { - if ( p->inherits( "QMainWindow" ) ) - mw = (QMainWindow*)p; - p = p->parentWidget(); - } - if ( mw ) - mw->setAppropriate( this, true ); -} - -/*! - Set the dockable window is hidden for main window. */ -void QtxColorScale::Dock::deactivate() -{ - if ( myBlockShow ) - return; - - QMainWindow* mw = 0; - QWidget* p = parentWidget(); - while ( !mw && p ) - { - if ( p->inherits( "QMainWindow" ) ) - mw = (QMainWindow*)p; - p = p->parentWidget(); + aTitle = aTitle.arg( title() ); + doc = new QTextDocument( aTitle ); } - if ( mw ) - mw->setAppropriate( this, false ); -} -/*! - \return true if the dockable window is visible. -*/ -bool QtxColorScale::Dock::isActive() const -{ - QMainWindow* mw = 0; - QWidget* p = parentWidget(); - while ( !mw && p ) - { - if ( p->inherits( "QMainWindow" ) ) - mw = (QMainWindow*)p; - p = p->parentWidget(); - } - if ( mw ) - return mw->appropriate( (QDockWindow*)this ); - else - return false; + return doc; } - -/*! - Redefined show -*/ -void QtxColorScale::Dock::show() -{ - bool f = myBlockShow; - myBlockShow = true; - QDockWindow::show(); - myBlockShow = f; -} - -/*! - Redefined hide -*/ -void QtxColorScale::Dock::hide() -{ - bool f = myBlockShow; - myBlockShow = false; - QDockWindow::hide(); - myBlockShow = f; -} - -/*! - Make extent width as maximum value of widget width. -*/ -void QtxColorScale::Dock::resize( int w, int h ) -{ - QDockWindow::resize( w, h ); - - if ( myBlockResize ) - return; - - if ( orientation() == Qt::Vertical ) - setFixedExtentWidth( QMAX( fixedExtent().width(), w ) ); - else if ( orientation() == Qt::Horizontal ) - setFixedExtentHeight( QMAX( fixedExtent().height(), h ) ); -} - -/*! - Set orientation - \param o - new orientation -*/ -void QtxColorScale::Dock::setOrientation( Orientation o ) -{ - bool b = myBlockResize; - myBlockResize = true; - QDockWindow::setOrientation( o ); - myBlockResize = b; -} - -#endif diff --git a/src/Qtx/QtxColorScale.h b/src/Qtx/QtxColorScale.h index bae5e9d63..364ac1e2e 100755 --- a/src/Qtx/QtxColorScale.h +++ b/src/Qtx/QtxColorScale.h @@ -24,15 +24,10 @@ #include "Qtx.h" -#include -#include +#include +#include -#if QT_VER == 3 -#include -#endif - -class QStyleSheet; -class QSimpleRichText; +class QTextDocument; #ifdef WIN32 #pragma warning( disable:4251 ) @@ -44,141 +39,105 @@ class QSimpleRichText; */ class QTX_EXPORT QtxColorScale : public QFrame { - Q_OBJECT + Q_OBJECT public: - typedef enum { Auto, User } Mode; - typedef enum { None, Left, Right, Center } Position; - typedef enum { NoDump, TitleDump, ScaleDump, FullDump } DumpMode; - typedef enum { AtBorder = 0x001, Reverse = 0x002, Integer = 0x004, - WrapTitle = 0x008, PreciseFormat = 0x010, Transparent = 0x020 } Flags; - -#if QT_VER == 3 - class Dock : public QDockWindow - { - public: - Dock( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 ); - virtual ~Dock(); - - QtxColorScale* colorScale() const; - - void activate(); - void deactivate(); - - bool isActive() const; - - virtual void show(); - virtual void hide(); - - virtual void resize( int, int ); - virtual void setOrientation( Orientation ); - - private: - QtxColorScale* myScale; - bool myBlockShow; - bool myBlockResize; - }; - -private: - QtxColorScale( Dock*, const char* = 0, WFlags = 0 ); -#endif + typedef enum { Auto, User } Mode; + typedef enum { None, Left, Right, Center } Position; + typedef enum { NoDump, TitleDump, ScaleDump, FullDump } DumpMode; + typedef enum { AtBorder = 0x001, Reverse = 0x002, Integer = 0x004, + WrapTitle = 0x008, PreciseFormat = 0x010, Transparent = 0x020 } Flags; public: - QtxColorScale( QWidget* = 0, const char* = 0, WFlags = 0 ); - QtxColorScale( const int, QWidget* = 0, const char* = 0, WFlags = 0 ); - virtual ~QtxColorScale(); - - double minimum() const; - double maximum() const; - void range( double&, double& ) const; - int dumpMode() const; - int labelMode() const; - int colorMode() const; - int intervalsNumber() const; - - QString title() const; - QString format() const; - QString label( const int ) const; - QColor color( const int ) const; - void labels( QStringList& ) const; - void colors( QValueList& ) const; - - int labelPosition() const; - int titlePosition() const; - - void setMinimum( const double ); - void setMaximum( const double ); - void setRange( const double, const double ); - void setDumpMode( const int ); - void setColorMode( const int ); - void setLabelMode( const int ); - void setIntervalsNumber( const int ); - - void setTitle( const QString& ); - void setFormat( const QString& ); - void setLabel( const QString&, const int = -1 ); - void setColor( const QColor&, const int = -1 ); - void setLabels( const QStringList& ); - void setColors( const QValueList& ); - - void setLabelPosition( const int ); - void setTitlePosition( const int ); - - void setFlags( const int ); - bool testFlags( const int ) const; - void clearFlags( const int ); - - QPixmap dump() const; - QPixmap dump( const int = -1, const int = -1 ) const; - QPixmap dump( const QColor&, const int = -1, const int = -1 ) const; - - virtual QSize minimumSizeHint() const; - virtual QSize sizeHint() const; - - virtual void show(); - virtual void hide(); + QtxColorScale( QWidget* = 0, Qt::WindowFlags = 0 ); + QtxColorScale( const int, QWidget* = 0, Qt::WindowFlags = 0 ); + virtual ~QtxColorScale(); + + double minimum() const; + double maximum() const; + void range( double&, double& ) const; + int dumpMode() const; + int labelMode() const; + int colorMode() const; + int intervalsNumber() const; + + QString title() const; + QString format() const; + QString label( const int ) const; + QColor color( const int ) const; + void labels( QStringList& ) const; + void colors( QList& ) const; + + int labelPosition() const; + int titlePosition() const; + + void setMinimum( const double ); + void setMaximum( const double ); + void setRange( const double, const double ); + void setDumpMode( const int ); + void setColorMode( const int ); + void setLabelMode( const int ); + void setIntervalsNumber( const int ); + + void setTitle( const QString& ); + void setFormat( const QString& ); + void setLabel( const QString&, const int = -1 ); + void setColor( const QColor&, const int = -1 ); + void setLabels( const QStringList& ); + void setColors( const QList& ); + + void setLabelPosition( const int ); + void setTitlePosition( const int ); + + void setFlags( const int ); + bool testFlags( const int ) const; + void clearFlags( const int ); + + QPixmap dump() const; + QPixmap dump( const int = -1, const int = -1 ) const; + QPixmap dump( const QColor&, const int = -1, const int = -1 ) const; + + virtual QSize minimumSizeHint() const; + virtual QSize sizeHint() const; + + virtual void show(); + virtual void hide(); protected: - virtual void drawContents( QPainter* ); + virtual void drawContents( QPainter* ); private: - void updateScale(); - QString getFormat() const; - QString getLabel( const int ) const; - QColor getColor( const int ) const; - double getNumber( const int ) const; - QSimpleRichText* simpleRichText( const int ) const; - void drawScale( QPainter*, const bool, const int, const int, - const int, const int, const bool, const bool, const bool ) const; - void drawScale( QPainter*, const QColor&, const bool, - const int, const int, const int, const int, - const bool, const bool, const bool ) const; - QSize calculateSize( const bool, const int, - const bool, const bool, const bool ) const; - -#if QT_VER == 3 - friend class QtxColorScale::Dock; -#endif + void updateScale(); + QString getFormat() const; + QString getLabel( const int ) const; + QColor getColor( const int ) const; + double getNumber( const int ) const; + QTextDocument* textDocument( const int ) const; + void drawScale( QPainter*, const bool, const int, const int, + const int, const int, const bool, const bool, const bool ) const; + void drawScale( QPainter*, const QColor&, const bool, + const int, const int, const int, const int, + const bool, const bool, const bool ) const; + QSize calculateSize( const bool, const int, + const bool, const bool, const bool ) const; private: - double myMin; - double myMax; - QString myTitle; - QString myFormat; - QString myPrecise; - int myInterval; - int myDumpMode; - int myColorMode; - int myLabelMode; - - QValueList myColors; - QValueList myLabels; - - Dock* myDock; - int myFlags; - int myLabelPos; - int myTitlePos; - QStyleSheet* myStyleSheet; + double myMin; + double myMax; + QString myTitle; + QString myFormat; + QString myPrecise; + int myInterval; + int myDumpMode; + int myColorMode; + int myLabelMode; + + QList myColors; + QList myLabels; + + int myFlags; + int myLabelPos; + int myTitlePos; }; #ifdef WIN32 diff --git a/src/Qtx/QtxComboBox.cxx b/src/Qtx/QtxComboBox.cxx index a2c95f251..b7ba7292a 100755 --- a/src/Qtx/QtxComboBox.cxx +++ b/src/Qtx/QtxComboBox.cxx @@ -21,26 +21,15 @@ #include "QtxComboBox.h" -#include -#include -#include +#include +#include +#include /*! Constructor */ -QtxComboBox::QtxComboBox( QWidget* parent, const char* name ) -: QComboBox( parent, name ), -myCleared( false ) -{ - connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) ); -} - -/*! - Constructor -*/ -QtxComboBox::QtxComboBox( bool rw, QWidget* parent, const char* name ) -: QComboBox( rw, parent, name ), +QtxComboBox::QtxComboBox( QWidget* parent ) +: QComboBox( parent ), myCleared( false ) { connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); @@ -59,7 +48,7 @@ QtxComboBox::~QtxComboBox() */ bool QtxComboBox::isCleared() const { - return myCleared; + return myCleared; } /*! @@ -68,56 +57,33 @@ bool QtxComboBox::isCleared() const */ void QtxComboBox::setCleared( const bool isClear ) { - if ( myCleared == isClear ) - return; + if ( myCleared == isClear ) + return; - myCleared = isClear; + myCleared = isClear; - if ( editable() ) - { - if ( myCleared ) - lineEdit()->setText( "" ); - else - lineEdit()->setText( text( currentItem() ) ); - } + if ( isEditable() ) + { + if ( myCleared ) + lineEdit()->setText( "" ); + else + lineEdit()->setText( itemText( currentIndex() ) ); + } - update(); + update(); } /*! Sets currently selected item \param idx - index of item */ -void QtxComboBox::setCurrentItem( int idx ) +void QtxComboBox::setCurrentIndex( int idx ) { - if ( idx < 0 || idx >= count() ) - return; + if ( idx < 0 || idx >= count() ) + return; - myCleared = false; - QComboBox::setCurrentItem( idx ); -} - -/*! - Sets current text - \param txt - new current text -*/ -void QtxComboBox::setCurrentText( const QString& txt ) -{ - myCleared = false; -#if QT_VER < 3 - int i = -1; - for ( int j = 0; j < count() && i == -1; j++ ) - if ( text( j ) == txt ) - i = j; - if ( i >= 0 && i < count() ) - setCurrentItem( i ); - else if ( editable() ) - lineEdit()->setText( txt ); - else - changeItem( txt, currentItem() ); -#else - QComboBox::setCurrentText( txt ); -#endif + myCleared = false; + QComboBox::setCurrentIndex( idx ); } /*! @@ -125,7 +91,7 @@ void QtxComboBox::setCurrentText( const QString& txt ) */ int QtxComboBox::currentId() const { - return id( currentItem() ); + return id( currentIndex() ); } /*! @@ -133,7 +99,7 @@ int QtxComboBox::currentId() const */ void QtxComboBox::setCurrentId( int num ) { - setCurrentItem( index( num ) ); + setCurrentIndex( index( num ) ); } /*! @@ -141,10 +107,10 @@ void QtxComboBox::setCurrentId( int num ) */ void QtxComboBox::paintEvent( QPaintEvent* e ) { - if ( !count() || !myCleared || editable() ) - QComboBox::paintEvent( e ); - else - paintClear( e ); + if ( !count() || !myCleared || isEditable() ) + QComboBox::paintEvent( e ); + else + paintClear( e ); } /*! @@ -153,10 +119,7 @@ void QtxComboBox::paintEvent( QPaintEvent* e ) */ void QtxComboBox::onActivated( int idx ) { - resetClear(); - - if ( myIndexId.contains( idx ) ) - emit activatedId( myIndexId[idx] ); + resetClear(); } /*! @@ -183,25 +146,22 @@ void QtxComboBox::resetClear() */ void QtxComboBox::paintClear( QPaintEvent* e ) { - int curIndex = currentItem(); - QString curText = text( curIndex ); - - QPixmap curPix; - if ( pixmap( curIndex ) ) - curPix = *pixmap( curIndex ); + int curIndex = currentIndex(); + QString curText = itemText( curIndex ); + QIcon curIcon = itemIcon( curIndex ); - bool upd = isUpdatesEnabled(); - setUpdatesEnabled( false ); + bool upd = updatesEnabled(); + setUpdatesEnabled( false ); - changeItem( "", curIndex ); - QComboBox::paintEvent( e ); + setItemIcon( curIndex, QIcon() ); + setItemText( curIndex, QString::null ); + + QComboBox::paintEvent( e ); - if ( curPix.isNull() ) - changeItem( curText, curIndex ); - else - changeItem( curPix, curText, curIndex ); + setItemText( curIndex, curText ); + setItemIcon( curIndex, curIcon ); - setUpdatesEnabled( upd ); + setUpdatesEnabled( upd ); } /*! @@ -209,10 +169,10 @@ void QtxComboBox::paintClear( QPaintEvent* e ) */ int QtxComboBox::id( const int idx ) const { - int id = -1; - if ( myIndexId.contains( idx ) ) - id = myIndexId[idx]; - return id; + int id = -1; + if ( myIndexId.contains( idx ) ) + id = myIndexId[idx]; + return id; } /*! @@ -220,10 +180,11 @@ int QtxComboBox::id( const int idx ) const */ int QtxComboBox::index( const int id ) const { - int idx = -1; - for ( IndexIdMap::ConstIterator it = myIndexId.begin(); - it != myIndexId.end() && idx == -1; ++it ) - if ( it.data() == id ) - idx = it.key(); - return idx; + int idx = -1; + for ( IndexIdMap::ConstIterator it = myIndexId.begin(); it != myIndexId.end() && idx == -1; ++it ) + { + if ( it.value() == id ) + idx = it.key(); + } + return idx; } diff --git a/src/Qtx/QtxComboBox.h b/src/Qtx/QtxComboBox.h index 82c8989e0..79f40d924 100755 --- a/src/Qtx/QtxComboBox.h +++ b/src/Qtx/QtxComboBox.h @@ -24,8 +24,8 @@ #include "Qtx.h" -#include -#include +#include +#include #ifdef WIN32 #pragma warning( disable:4251 ) @@ -33,45 +33,43 @@ class QTX_EXPORT QtxComboBox : public QComboBox { - Q_OBJECT + Q_OBJECT - typedef QMap IndexIdMap; + typedef QMap IndexIdMap; public: - QtxComboBox( QWidget* = 0, const char* = 0 ); - QtxComboBox( bool, QWidget* = 0, const char* = 0 ); - virtual ~QtxComboBox(); + QtxComboBox( QWidget* = 0 ); + virtual ~QtxComboBox(); - bool isCleared() const; - void setCleared( const bool ); + bool isCleared() const; + void setCleared( const bool ); - virtual void setCurrentItem( int ); - virtual void setCurrentText( const QString& ); + virtual void setCurrentIndex( int ); - int currentId() const; - void setCurrentId( int ); + int currentId() const; + void setCurrentId( int ); -signals: - void activatedId( int ); - void highlightedId( int ); +Q_SIGNALS: + void activatedId( int ); + void highlightedId( int ); -private slots: - void onActivated( int ); - void onActivated( const QString& ); +private Q_SLOTS: + void onActivated( int ); + void onActivated( const QString& ); protected: - virtual void paintEvent( QPaintEvent* ); + virtual void paintEvent( QPaintEvent* ); private: - int id( const int ) const; - int index( const int ) const; + int id( const int ) const; + int index( const int ) const; - void resetClear(); - void paintClear( QPaintEvent* ); + void resetClear(); + void paintClear( QPaintEvent* ); private: - bool myCleared; - IndexIdMap myIndexId; + bool myCleared; + IndexIdMap myIndexId; }; #ifdef WIN32 diff --git a/src/Qtx/QtxDockWidget.cxx b/src/Qtx/QtxDockWidget.cxx new file mode 100644 index 000000000..90b3d40c9 --- /dev/null +++ b/src/Qtx/QtxDockWidget.cxx @@ -0,0 +1,325 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxDockWidget.cxx +// Author: Sergey TELKOV + +#include "QtxDockWidget.h" + +#include +#include +#include + +/*! + \class QtxDockWidget::Watcher [Internal] + Internal object with event filter. +*/ +class QtxDockWidget::Watcher : public QObject +{ +public: + Watcher( QtxDockWidget* ); + + void shown( QtxDockWidget* ); + void hided( QtxDockWidget* ); + + virtual bool eventFilter( QObject*, QEvent* ); + +protected: + virtual void customEvent( QEvent* ); + +private: + void installFilters(); + + void showContainer(); + void hideContainer(); + + void updateIcon(); + void updateCaption(); + void updateVisibility(); + +private: + QtxDockWidget* myCont; + bool myState; + bool myEmpty; + bool myVisible; +}; + +/*! + Constructor +*/ +QtxDockWidget::Watcher::Watcher( QtxDockWidget* cont ) +: QObject( cont ), myCont( cont ), +myState( true ), +myEmpty( true ) +{ + myCont->installEventFilter( this ); + myVisible = myCont->isVisibleTo( myCont->parentWidget() ); + + installFilters(); +} + +/*! + Custom event filter +*/ +bool QtxDockWidget::Watcher::eventFilter( QObject* o, QEvent* e ) +{ + if ( o == myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || + e->type() == QEvent::Hide || e->type() == QEvent::HideToParent || + e->type() == QEvent::ChildAdded ) ) + QApplication::postEvent( this, new QEvent( QEvent::User ) ); + + if ( o != myCont && e->type() == QEvent::WindowIconChange ) + updateIcon(); + + if ( o != myCont && e->type() == QEvent::WindowTitleChange ) + updateCaption(); + + if ( ( o != myCont && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || + ( o == myCont && ( e->type() == QEvent::ChildRemoved ) ) || + ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) ) + updateVisibility(); + + return false; +} + +/*! + Sets internal status to shown +*/ +void QtxDockWidget::Watcher::shown( QtxDockWidget* dw ) +{ + if ( dw != myCont ) + return; + + myVisible = true; +} + +/*! + Sets internal status to hidden +*/ +void QtxDockWidget::Watcher::hided( QtxDockWidget* dw ) +{ + if ( dw != myCont ) + return; + + myVisible = false; +} + +/*! + Shows corresponding dock window +*/ +void QtxDockWidget::Watcher::showContainer() +{ + if ( !myCont ) + return; + + QtxDockWidget* cont = myCont; + myCont = 0; + cont->show(); + myCont = cont; +} + +/*! + Hides corresponding dock window +*/ +void QtxDockWidget::Watcher::hideContainer() +{ + if ( !myCont ) + return; + + QtxDockWidget* cont = myCont; + myCont = 0; + cont->hide(); + myCont = cont; +} + +/*! + Event filter of custom events +*/ +void QtxDockWidget::Watcher::customEvent( QEvent* e ) +{ + installFilters(); + + updateIcon(); + updateCaption(); + updateVisibility(); +} + +/*! + Installs this object as event filter to all widgets inside corresponding main window +*/ +void QtxDockWidget::Watcher::installFilters() +{ + if ( !myCont ) + return; + + QLayout* l = myCont->layout(); + if ( !l ) + return; + + for ( uint i = 0; i < l->count(); i++ ) + { + if ( l->itemAt( i ) && l->itemAt( i )->widget() ) + l->itemAt( i )->widget()->installEventFilter( this ); + } +} + +/*! + Updates visibility of all widgets inside corresponding main window +*/ +void QtxDockWidget::Watcher::updateVisibility() +{ + if ( !myCont ) + return; + + QLayout* l = myCont->layout(); + if ( !l ) + return; + + bool vis = false; + for ( uint i = 0; i < l->count() && !vis; i++ ) + vis = l->itemAt( i ) && l->itemAt( i )->widget() && l->itemAt( i )->widget()->isVisibleTo( myCont ); + + if ( myEmpty == vis ) + { + myEmpty = !vis; + if ( !myEmpty ) + myCont->toggleViewAction()->setVisible( myState ); + else + { + myState = myCont->toggleViewAction()->isVisible(); + myCont->toggleViewAction()->setVisible( false ); + } + } + + vis = !myEmpty && myVisible; + if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) ) + vis ? showContainer() : hideContainer(); +} + +/*! + Updates icon of corresponding main window +*/ +void QtxDockWidget::Watcher::updateIcon() +{ + if ( !myCont || !myCont->widget() ) + return; + + myCont->setWindowIcon( myCont->widget()->windowIcon() ); +} + +/*! + Updates caption of corresponding main window +*/ +void QtxDockWidget::Watcher::updateCaption() +{ + if ( myCont && myCont->widget() && !myCont->widget()->windowTitle().isNull() ) + myCont->setWindowTitle( myCont->widget()->windowTitle() ); +} + +/*! + Constructor +*/ +QtxDockWidget::QtxDockWidget( const QString& title, QWidget* parent, Qt::WindowFlags f ) +: QDockWidget( title, parent, f ), +myWatcher( 0 ) +{ +} + +/*! + Constructor +*/ +QtxDockWidget::QtxDockWidget( const bool watch, QWidget* parent, Qt::WindowFlags f ) +: QDockWidget( parent, f ), +myWatcher( 0 ) +{ + if ( watch ) + myWatcher = new Watcher( this ); +} + +/*! + Constructor +*/ +QtxDockWidget::QtxDockWidget( QWidget* parent, Qt::WindowFlags f ) +: QDockWidget( parent, f ), +myWatcher( 0 ) +{ +} + +/*! + Destructor +*/ +QtxDockWidget::~QtxDockWidget() +{ +} + +/*! + \return the recommended size for the widget +*/ +QSize QtxDockWidget::sizeHint() const +{ + QSize sz = QDockWidget::sizeHint(); +/* + if ( place() == InDock && isStretchable() && area() ) + { + if ( orientation() == Horizontal ) + sz.setWidth( area()->width() ); + else + sz.setHeight( area()->height() ); + } +*/ + return sz; +} + +/*! + \return the recommended minimum size for the widget +*/ +QSize QtxDockWidget::minimumSizeHint() const +{ + QSize sz = QDockWidget::minimumSizeHint(); +/* + if ( orientation() == Horizontal ) + sz = QSize( 0, QDockWidget::minimumSizeHint().height() ); + else + sz = QSize( QDockWidget::minimumSizeHint().width(), 0 ); + + if ( place() == InDock && isStretchable() && area() ) + { + if ( orientation() == Horizontal ) + sz.setWidth( area()->width() ); + else + sz.setHeight( area()->height() ); + } +*/ + return sz; +} + +/*! + Shows/hides the window +*/ +void QtxDockWidget::setVisible( bool on ) +{ + if ( myWatcher ) + { + if ( on ) + myWatcher->shown( this ); + else + myWatcher->hided( this ); + } + + QDockWidget::setVisible( on ); +} diff --git a/src/Qtx/QtxDockWidget.h b/src/Qtx/QtxDockWidget.h new file mode 100644 index 000000000..5ec766a07 --- /dev/null +++ b/src/Qtx/QtxDockWidget.h @@ -0,0 +1,46 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxDockWidget.h +// Author: Sergey TELKOV + +#include "Qtx.h" + +#include + +class QTX_EXPORT QtxDockWidget : public QDockWidget +{ + Q_OBJECT + + class Watcher; + +public: + QtxDockWidget( const QString&, QWidget* = 0, Qt::WindowFlags = 0 ); + QtxDockWidget( const bool, QWidget* = 0, Qt::WindowFlags = 0 ); + QtxDockWidget( QWidget*, Qt::WindowFlags = 0 ); + virtual ~QtxDockWidget(); + + virtual QSize sizeHint() const; + virtual QSize minimumSizeHint() const; + +public slots: + virtual void setVisible( bool ); + +private: + Watcher* myWatcher; +}; diff --git a/src/Qtx/QtxDockWindow.cxx b/src/Qtx/QtxDockWindow.cxx deleted file mode 100644 index da6f5cc55..000000000 --- a/src/Qtx/QtxDockWindow.cxx +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxDockWindow.cxx -// Author: Sergey TELKOV - -#include "QtxDockWindow.h" - -#include -#include -#include -#include -#include - -/*! - \class QtxDockWindow::Watcher [Internal] - Internal object with event filter. -*/ -class QtxDockWindow::Watcher : public QObject -{ -public: - Watcher( QtxDockWindow* ); - - void shown( QtxDockWindow* ); - void hided( QtxDockWindow* ); - - virtual bool eventFilter( QObject*, QEvent* ); - -protected: - virtual void customEvent( QCustomEvent* ); - -private: - void installFilters(); - - void showContainer(); - void hideContainer(); - - void updateIcon(); - void updateCaption(); - void updateVisibility(); - -private: - QtxDockWindow* myCont; - bool myState; - bool myEmpty; - bool myVisible; -}; - -/*! - Constructor -*/ -QtxDockWindow::Watcher::Watcher( QtxDockWindow* cont ) -: QObject( cont ), myCont( cont ), -myState( true ), -myEmpty( true ) -{ - if ( myCont->mainWindow() ) - myState = myCont->mainWindow()->appropriate( myCont ); - - myCont->installEventFilter( this ); - myVisible = myCont->isVisibleTo( myCont->parentWidget() ); - - installFilters(); -} - -/*! - Custom event filter -*/ -bool QtxDockWindow::Watcher::eventFilter( QObject* o, QEvent* e ) -{ - if ( o == myCont && - ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || - e->type() == QEvent::Hide || e->type() == QEvent::HideToParent || - e->type() == QEvent::ChildInserted ) ) - QApplication::postEvent( this, new QCustomEvent( QEvent::User ) ); - - if ( o != myCont && e->type() == QEvent::IconChange ) - updateIcon(); - - if ( o != myCont && e->type() == QEvent::CaptionChange ) - updateCaption(); - - if ( ( o != myCont && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || - ( o == myCont && ( e->type() == QEvent::ChildRemoved ) ) || - ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) ) - updateVisibility(); - - return false; -} - -/*! - Sets internal status to shown -*/ -void QtxDockWindow::Watcher::shown( QtxDockWindow* dw ) -{ - if ( dw != myCont ) - return; - - myVisible = true; -} - -/*! - Sets internal status to hidden -*/ -void QtxDockWindow::Watcher::hided( QtxDockWindow* dw ) -{ - if ( dw != myCont ) - return; - - myVisible = false; -} - -/*! - Shows corresponding dock window -*/ -void QtxDockWindow::Watcher::showContainer() -{ - if ( !myCont ) - return; - - QtxDockWindow* cont = myCont; - myCont = 0; - cont->show(); - myCont = cont; -} - -/*! - Hides corresponding dock window -*/ -void QtxDockWindow::Watcher::hideContainer() -{ - if ( !myCont ) - return; - - QtxDockWindow* cont = myCont; - myCont = 0; - cont->hide(); - myCont = cont; -} - -/*! - Event filter of custom events -*/ -void QtxDockWindow::Watcher::customEvent( QCustomEvent* e ) -{ - installFilters(); - - updateIcon(); - updateCaption(); - updateVisibility(); -} - -/*! - Installs this object as event filter to all widgets inside corresponding main window -*/ -void QtxDockWindow::Watcher::installFilters() -{ - if ( !myCont ) - return; - - QBoxLayout* bl = myCont->boxLayout(); - if ( !bl ) - return; - - for ( QLayoutIterator it = bl->iterator(); it.current(); ++it ) - { - if ( it.current()->widget() ) - it.current()->widget()->installEventFilter( this ); - } -} - -/*! - Updates visibility of all widgets inside corresponding main window -*/ -void QtxDockWindow::Watcher::updateVisibility() -{ - if ( !myCont ) - return; - - QBoxLayout* bl = myCont->boxLayout(); - if ( !bl ) - return; - - bool vis = false; - for ( QLayoutIterator it = bl->iterator(); it.current() && !vis; ++it ) - vis = it.current()->widget() && it.current()->widget()->isVisibleTo( myCont ); - - QMainWindow* mw = myCont->mainWindow(); - if ( mw && myEmpty == vis ) - { - myEmpty = !vis; - if ( !myEmpty ) - mw->setAppropriate( myCont, myState ); - else - { - myState = mw->appropriate( myCont ); - mw->setAppropriate( myCont, false ); - } - } - - vis = !myEmpty && myVisible; - if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) ) - vis ? showContainer() : hideContainer(); -} - -/*! - Updates icon of corresponding main window -*/ -void QtxDockWindow::Watcher::updateIcon() -{ - if ( !myCont || !myCont->widget() ) - return; - - const QPixmap* ico = myCont->widget()->icon(); - myCont->setIcon( ico ? *ico : QPixmap() ); -} - -/*! - Updates caption of corresponding main window -*/ -void QtxDockWindow::Watcher::updateCaption() -{ - if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() ) - myCont->setCaption( myCont->widget()->caption() ); -} - -/*! - Constructor -*/ -QtxDockWindow::QtxDockWindow( Place p, QWidget* parent, const char* name, WFlags f ) -: QDockWindow( p, parent, name, f ), -myWatcher( 0 ), -myStretch( false ) -{ -} - -/*! - Constructor -*/ -QtxDockWindow::QtxDockWindow( const bool watch, QWidget* parent, const char* name, WFlags f ) -: QDockWindow( InDock, parent, name, f ), -myWatcher( 0 ), -myStretch( false ) -{ - if ( watch ) - myWatcher = new Watcher( this ); -} - -/*! - Constructor -*/ -QtxDockWindow::QtxDockWindow( QWidget* parent, const char* name, WFlags f ) -: QDockWindow( InDock, parent, name, f ), -myWatcher( 0 ), -myStretch( false ) -{ -} - -/*! - Destructor -*/ -QtxDockWindow::~QtxDockWindow() -{ -} - -/*! - Sets the dock window's main widget - \param wid - new main widget -*/ -void QtxDockWindow::setWidget( QWidget* wid ) -{ - if ( wid ) - { - if ( wid->parentWidget() != this ) - wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) ); - if ( myWatcher ) - { - setCaption( wid->caption() ); - if ( wid->icon() ) - setIcon( *wid->icon() ); - } - } - - QDockWindow::setWidget( wid ); -} - -/*! - \return true if the dock window is stretchable -*/ -bool QtxDockWindow::isStretchable() const -{ - return myStretch; -} - -/*! - Sets the dock window "stretchable" state - \param on - new state -*/ -void QtxDockWindow::setStretchable( const bool on ) -{ - if ( myStretch == on ) - return; - - myStretch = on; - - boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 ); - - if ( myStretch != isHorizontalStretchable() || - myStretch != isVerticalStretchable() ) - { - if ( orientation() == Horizontal ) - setHorizontalStretchable( myStretch ); - else - setVerticalStretchable( myStretch ); - } -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxDockWindow::sizeHint() const -{ - QSize sz = QDockWindow::sizeHint(); - - if ( place() == InDock && isStretchable() && area() ) - { - if ( orientation() == Horizontal ) - sz.setWidth( area()->width() ); - else - sz.setHeight( area()->height() ); - } - - return sz; -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxDockWindow::minimumSizeHint() const -{ - QSize sz = QDockWindow::minimumSizeHint(); - - if ( orientation() == Horizontal ) - sz = QSize( 0, QDockWindow::minimumSizeHint().height() ); - else - sz = QSize( QDockWindow::minimumSizeHint().width(), 0 ); - - if ( place() == InDock && isStretchable() && area() ) - { - if ( orientation() == Horizontal ) - sz.setWidth( area()->width() ); - else - sz.setHeight( area()->height() ); - } - - return sz; -} - -/*! - \return corresponding main window -*/ -QMainWindow* QtxDockWindow::mainWindow() const -{ - QMainWindow* mw = 0; - - QWidget* wid = parentWidget(); - while ( !mw && wid ) - { - if ( wid->inherits( "QMainWindow" ) ) - mw = (QMainWindow*)wid; - wid = wid->parentWidget(); - } - - return mw; -} - -/*! - Shows window -*/ -void QtxDockWindow::show() -{ - if ( myWatcher ) - myWatcher->shown( this ); - - QDockWindow::show(); -} - -/*! - Hides window -*/ -void QtxDockWindow::hide() -{ - if ( myWatcher ) - myWatcher->hided( this ); - - QDockWindow::hide(); -} diff --git a/src/Qtx/QtxDockWindow.h b/src/Qtx/QtxDockWindow.h deleted file mode 100644 index 6aa0190e3..000000000 --- a/src/Qtx/QtxDockWindow.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxDockWindow.h -// Author: Sergey TELKOV - -#include "Qtx.h" - -#include - -class QTX_EXPORT QtxDockWindow : public QDockWindow -{ - Q_OBJECT - - class Watcher; - -public: - QtxDockWindow( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 ); - QtxDockWindow( const bool, QWidget*, const char* = 0, WFlags = 0 ); - QtxDockWindow( QWidget*, const char* = 0, WFlags = 0 ); - virtual ~QtxDockWindow(); - - virtual void setWidget( QWidget* ); - - bool isStretchable() const; - virtual void setStretchable( const bool ); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; - - QMainWindow* mainWindow() const; - -public slots: - virtual void show(); - virtual void hide(); - -private: - Watcher* myWatcher; - bool myStretch; -};