From a30a9344f01040efcf82070bd97c776d70c6c6a1 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 7 May 2007 14:27:40 +0000 Subject: [PATCH] Porting to Qt4 --- src/Qtx/Qtx.cxx | 686 +++++++++++++++++++++++++++++------------------- src/Qtx/Qtx.h | 95 +++---- src/Qtx/Qtx.pro | 97 +++++++ 3 files changed, 552 insertions(+), 326 deletions(-) create mode 100644 src/Qtx/Qtx.pro diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 6e2a31648..e4149bf6d 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -1,17 +1,17 @@ // 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 +// 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 +// +// 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 +// 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 @@ -21,60 +21,125 @@ #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 /*! - Name: setTabOrder [static public] - Desc: Set tab order for specified list of widgets. Last parameter should be null pointer. -*/ + \brief Convert character array (ASCII string) to the QString. + \param str character array + \param len array length, if < 0, the array should be zero-terminated + \return QString object + */ +QString Qtx::toQString( const char* str, const int len ) +{ + return toQString( (unsigned char*)str, len ); +} + +/*! + \brief Convert integer array (UNICODE string) to the QString. + \param str integer array + \param len array length, if < 0, the array should be zero-terminated + \return QString object + */ +QString Qtx::toQString( const short* str, const int len ) +{ + return toQString( (unsigned short*)str, len ); +} + +/*! + \brief Convert character array (ASCII string) to the QString. + \param str character array + \param len array length, if < 0, the array should be zero-terminated + \return QString object + */ +QString Qtx::toQString( const unsigned char* str, const int len ) +{ + QString res; + const unsigned char* s = str; + while ( len < 0 || res.length() < len ) + { + if ( *s == '\0' ) + break; + + res.append( QChar( *s ) ); + s++; + } + return res; +} + +/*! + \brief Convert integer array (UNICODE string) to the QString. + \param str integer array + \param len array length, if < 0, the array should be zero-terminated + \return QString object + */ +QString Qtx::toQString( const unsigned short* str, const int len ) +{ + QString res; + const unsigned short* s = str; + while ( len < 0 || res.length() < len ) + { + if ( *s == '\0' ) + break; + res.append( QChar( *s ) ); + s++; + } + return res; +} + +/*! + \brief Set tab order for specified list of widgets. + + The function has arbitrary number of parameters, each should be + hovewer of QWidget* type. Last parameter should be null pointer. + + \param first first widget in the sequence +*/ void Qtx::setTabOrder( QWidget* first, ... ) { va_list wids; - va_start( wids, first ); + va_start( wids, first ); - QWidgetList widList; + QWidgetList widList; - QWidget* cur = first; - while ( cur ) - { - widList.append( cur ); - cur = va_arg( wids, QWidget* ); + QWidget* cur = first; + while ( cur ) + { + widList.append( cur ); + cur = va_arg( wids, QWidget* ); } - setTabOrder( widList ); + setTabOrder( widList ); } /*! - Name: setTabOrder [static public] - Desc: Set tab order for specified list of widgets. + \brief Set tab order for specified list of widgets. + \param widgets list of widgets */ - void Qtx::setTabOrder( const QWidgetList& widgets ) { if ( widgets.count() < 2 ) 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; @@ -82,157 +147,175 @@ void Qtx::setTabOrder( const QWidgetList& widgets ) } /*! - Name: alignWidget [static public] - Desc: Align widget 'src' relative to widget 'ref' acording to alignment flags. - Alignment flags: - Qtx::AlignLeft - Align left side of 'src' to left side of 'ref'. - Qtx::AlignRight - Align right side of 'src' to right side of 'ref'. - Qtx::AlignTop - Align top side of 'src' to top side of 'ref'. - Qtx::AlignBottom - Align bottom side of 'src' to bottom side of 'ref'. - Qtx::AlignHCenter - Align 'src' to center of 'ref' in horizontal dimension. - Qtx::AlignVCenter - Align 'src' to center of 'ref' in vertical dimension. - Qtx::AlignCenter - Align 'src' to center of 'ref' in both dimensions. - Qtx::AlignOutLeft - Align right side of 'src' to left side of 'ref'. - Qtx::AlignOutRight - Align left side of 'src' to right side of 'ref'. - Qtx::AlignOutTop - Align bottom side of 'src' to top side of 'ref'. - Qtx::AlignOutBottom - Align top side of 'src' to bottom side of 'ref'. + \brief Align widget \a src relative to widget \a ref acording to alignment flags. + + Alignment flags: + - Qtx::AlignLeft : align left side of \a src to the left side of \a ref + - Qtx::AlignRight : align right side of \a src to the right side of \a ref + - Qtx::AlignTop : align top side of \a src to the top side of \a ref + - Qtx::AlignBottom : align bottom side of \a src to the bottom side of \a ref + - Qtx::AlignHCenter : align \a src to the center of \a ref in horizontal dimension + - Qtx::AlignVCenter : align \a src to the center of \a ref in vertical dimension + - Qtx::AlignCenter : align \a src to the center of \a ref in both dimensions + - Qtx::AlignOutLeft : align right side of \a src to the left side of \a ref + - Qtx::AlignOutRight : align left side of \a src to the right side of \a ref + - Qtx::AlignOutTop : align bottom side of \a src to the top side of \a ref + - Qtx::AlignOutBottom : align top side of \a src to the bottom side of \a ref + + \param src source widget (being aligned) + \param ref reference widget (source widget being to) + \param alignFlags alignment flags */ - void Qtx::alignWidget( QWidget* src, const QWidget* ref, const int alignFlags ) { - if ( !src || !ref || !alignFlags ) - return; - - QPoint srcOri = src->pos(); - QPoint refOri = ref->pos(); - if ( src->parentWidget() && !src->isTopLevel() ) - srcOri = src->parentWidget()->mapToGlobal( srcOri ); - if ( ref->parentWidget() && !ref->isTopLevel() ) - refOri = ref->parentWidget()->mapToGlobal( refOri ); - - int x = srcOri.x(), y = srcOri.y(); - int refWidth = ref->frameGeometry().width(), refHei = ref->frameGeometry().height(); - int srcWidth = src->frameGeometry().width(), srcHei = src->frameGeometry().height(); - - if ( srcWidth <= 0 ) - srcWidth = src->sizeHint().width(); + if ( !src || !ref || !alignFlags ) + return; + + QPoint srcOri = src->pos(); + QPoint refOri = ref->pos(); + if ( src->parentWidget() && !src->isTopLevel() ) + srcOri = src->parentWidget()->mapToGlobal( srcOri ); + if ( ref->parentWidget() && !ref->isTopLevel() ) + refOri = ref->parentWidget()->mapToGlobal( refOri ); + + int x = srcOri.x(), y = srcOri.y(); + int refWidth = ref->frameGeometry().width(), refHei = ref->frameGeometry().height(); + int srcWidth = src->frameGeometry().width(), srcHei = src->frameGeometry().height(); + + if ( srcWidth <= 0 ) + srcWidth = src->sizeHint().width(); if ( srcHei <= 0 ) srcHei = src->sizeHint().height(); - int border = 0; + int border = 0; if ( ref->isTopLevel() && ref->isMaximized() && src->isTopLevel() && !src->isMaximized() ) border = ( src->frameGeometry().width() - src->width() ) / 2; - if ( alignFlags & Qtx::AlignLeft ) - x = refOri.x() + border; - if ( alignFlags & Qtx::AlignOutLeft ) - x = refOri.x() - srcWidth - border; - if ( alignFlags & Qtx::AlignRight ) - x = refOri.x() + refWidth - srcWidth - border; - if ( alignFlags & Qtx::AlignOutRight ) - x = refOri.x() + refWidth + border; - if ( alignFlags & Qtx::AlignTop ) - y = refOri.y() + border; - if ( alignFlags & Qtx::AlignOutTop ) - y = refOri.y() - srcHei - border; - if ( alignFlags & Qtx::AlignBottom ) - y = refOri.y() + refHei - srcHei - border; - if ( alignFlags & Qtx::AlignOutBottom ) - y = refOri.y() + refHei + border; - if ( alignFlags & Qtx::AlignHCenter ) - x = refOri.x() + ( refWidth - srcWidth ) / 2; - if ( alignFlags & Qtx::AlignVCenter ) - y = refOri.y() + ( refHei - srcHei ) / 2; - - if ( src->parentWidget() && !src->isTopLevel() ) - { - QPoint pos = src->parentWidget()->mapFromGlobal( QPoint( x, y ) ); - x = pos.x(); - y = pos.y(); - } - - QWidget* desk = QApplication::desktop(); - if ( desk && x + srcWidth + border > desk->width() ) - x = desk->width() - srcWidth - border; - if ( desk && y + srcHei + border > desk->height() ) - y = desk->height() - srcHei - border; - - x = QMAX( x, 0 ); - y = QMAX( y, 0 ); - - src->move( x, y ); + if ( alignFlags & Qtx::AlignLeft ) + x = refOri.x() + border; + if ( alignFlags & Qtx::AlignOutLeft ) + x = refOri.x() - srcWidth - border; + if ( alignFlags & Qtx::AlignRight ) + x = refOri.x() + refWidth - srcWidth - border; + if ( alignFlags & Qtx::AlignOutRight ) + x = refOri.x() + refWidth + border; + if ( alignFlags & Qtx::AlignTop ) + y = refOri.y() + border; + if ( alignFlags & Qtx::AlignOutTop ) + y = refOri.y() - srcHei - border; + if ( alignFlags & Qtx::AlignBottom ) + y = refOri.y() + refHei - srcHei - border; + if ( alignFlags & Qtx::AlignOutBottom ) + y = refOri.y() + refHei + border; + if ( alignFlags & Qtx::AlignHCenter ) + x = refOri.x() + ( refWidth - srcWidth ) / 2; + if ( alignFlags & Qtx::AlignVCenter ) + y = refOri.y() + ( refHei - srcHei ) / 2; + + if ( src->parentWidget() && !src->isTopLevel() ) + { + QPoint pos = src->parentWidget()->mapFromGlobal( QPoint( x, y ) ); + x = pos.x(); + y = pos.y(); + } + + QWidget* desk = QApplication::desktop(); + if ( desk && x + srcWidth + border > desk->width() ) + x = desk->width() - srcWidth - border; + if ( desk && y + srcHei + border > desk->height() ) + y = desk->height() - srcHei - border; + + x = qMax( x, 0 ); + y = qMax( y, 0 ); + + src->move( x, y ); } -/*! - Name: simplifySeparators [static public] - Desc: Checks toolbar for unnecessary separators and removes them -*/ +/* VSR: obsolete 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 + \brief Remove (recursively) unnecessary separators from the menu or toolbar. + \param wid widget, should be of QMenu* or QToolBar* class */ -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 ( int 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] ); } /*! - Name: isParent [static public] - Desc: Returns 'true' if specified 'parent' is parent object of given 'child'. + \brief Return \c true if specified \a parent is a parent object + of given \a child (in terms of QObject). + + This function works recursively. It means that \a true is also + returned if \a parent is a grand-father, grand-grand-father, etc + of \a child. If the same object is given as both \a parent and + \a child, \c true is also returned. + + \param child child object + \param parent parent object + \return \c true if the \a parent is a parent of \a child */ bool Qtx::isParent( QObject* child, QObject* parent ) { @@ -250,42 +333,68 @@ bool Qtx::isParent( QObject* child, QObject* parent ) } /*! - Name: dir [static public] - Desc: Returns dir name or null string. + \brief Return directory part of the file path. + + If the file path does not include directory part (the file is in the + current directory), null string is returned. + + \param path file path + \param abs if true (default) \a path parameter is treated as absolute file path + \return directory part of the file path */ 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; + dirPath = QString(); return dirPath; } /*! - Name: file [static public] - Desc: Returns file with or without extension. + \brief Return file name part of the file path. + + \param path file path + \param withExt if true (default) complete file name (with all + extension except the last) is returned, otherwise only base name + is returned + \return file name part of the file path */ QString Qtx::file( const QString& path, bool withExt ) { + QString fPath = path; + while ( !fPath.isEmpty() && ( fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/' ) ) + fPath.remove( fPath.length() - 1, 1 ); + if ( withExt ) - return QFileInfo( path ).fileName(); + return QFileInfo( fPath ).fileName(); else - return QFileInfo( path ).baseName(); + return QFileInfo( fPath ).baseName(); } /*! - Name: extension [static public] - Desc: Returns the file extension only or null string. + \brief Return extension part of the file path. + + \param path file path + \param full if true complete extension (all extensions, dot separated) + is returned, otherwise (default) only last extension is returned + \return extension part of the file path */ -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(); } /*! - Name: library [static public] - Desc: Generate library file name. - Append required prefix (lib) and suffix (.dll/.so) to the library file name. + \brief Convert the given parameter to the platform-specific library name. + + The function appends platform-specific prefix (lib) and suffix (.dll/.so) + to the library file name. + For example, if \a str = "mylib", "libmylib.so" is returned for Linux and + mylib.dll for Windows. + + \param str short library name + \return full library name */ QString Qtx::library( const QString& str ) { @@ -304,7 +413,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( "." ); @@ -319,113 +428,99 @@ QString Qtx::library( const QString& str ) } /*! - Name: tmpDir [static public] - Desc: Returns path to temporary directory. + \brief Get the temporary directory name. + \return temporary directory (platform specific) */ QString Qtx::tmpDir() { - char* tmpdir = ::getenv( "TEMP" ); - if ( !tmpdir ) - tmpdir = ::getenv ( "TMP" ); - if ( !tmpdir ) - { + char* tmpdir = ::getenv( "TEMP" ); + if ( !tmpdir ) + tmpdir = ::getenv ( "TMP" ); + if ( !tmpdir ) + { #ifdef WIN32 - tmpdir = "C:\\"; + tmpdir = "C:\\"; #else - tmpdir = "/tmp"; + tmpdir = "/tmp"; #endif - } - return QString( tmpdir ); + } + return QString( tmpdir ); } /*! - Name: mkDir [static public] - Desc: Creates directory with intermediate perent directories. - Returns true in successfull case. + \brief Create directory recursively including all intermediate sub directories. + \return \c true if the directory is successfully created and \c false otherwise */ 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 ); } /*! - Name: rmDir [static public] - Desc: Removes directory with its subdirectories and files. - Returns true in successfull case. + \brief Remove directory recursively including all subdirectories and files. + \return \c true if the directory is successfully removed and \c false otherwise */ bool Qtx::rmDir( const QString& thePath ) { - QFileInfo fi( thePath ); - if ( !fi.exists() ) - return true; - - bool stat = true; - if ( fi.isFile() ) - stat = QFile::remove( thePath ); - else if ( fi.isDir() ) - { - QDir aDir( thePath ); - const QFileInfoList* anEntries = aDir.entryInfoList(); - if ( anEntries ) - { - for ( QPtrListIterator it( *anEntries ); it.current(); ++it ) - { - if ( it.current()->fileName() == "." || it.current()->fileName() == ".." ) - continue; - stat = stat && rmDir( it.current()->absFilePath() ); - } - } - stat = stat && aDir.rmdir( thePath ); - } - return stat; + QFileInfo fi( thePath ); + if ( !fi.exists() ) + return true; + + bool stat = true; + if ( fi.isFile() ) + stat = QFile::remove( thePath ); + else if ( fi.isDir() ) + { + QDir aDir( thePath ); + QFileInfoList anEntries = aDir.entryInfoList(); + for ( QFileInfoList::iterator it = anEntries.begin(); it != anEntries.end(); ++it ) + { + QFileInfo inf = *it; + if ( inf.fileName() == "." || inf.fileName() == ".." ) + continue; + stat = stat && rmDir( inf.absoluteFilePath() ); + } + stat = stat && aDir.rmdir( thePath ); + } + return stat; } /*! - Name: addSlash [static public] - Desc: Adds a slash to the end of 'path' if it is not already there. + \brief Add a slash (platform-specific) to the end of \a path + if it is not already there. + \param path directory path + \return modified path (with slash added to the end) */ QString Qtx::addSlash( const QString& path ) { - QString res = path; + QString res = path; if ( !res.isEmpty() && res.at( res.length() - 1 ) != QChar( '/' ) && - res.at( res.length() - 1 ) != QChar( '\\' ) ) + res.at( res.length() - 1 ) != QChar( '\\' ) ) res += QDir::separator(); return res; } /*! - Name: dos2unix [static public] - Desc: Convert text file. Replace symbols "LF/CR" by symbol "LF". + \brief Convert text file from DOS format to UNIX. + + The function replaces "LF/CR" symbols sequence by "LF" symbol. + + \param absName file name + \return \c true if the file is converted successfully and \c false in + case of any error */ bool Qtx::dos2unix( const QString& absName ) { - FILE* src = ::fopen( absName, "rb" ); + FILE* src = ::fopen( absName.toLatin1(), "rb" ); if ( !src ) - return false; + 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; + return false; /* temp -> result of conversion */ const char CR = 0x0d; @@ -471,7 +566,7 @@ bool Qtx::dos2unix( const QString& absName ) break; /* converted ok */ } ::fclose( src ); - ::fclose( tgt ); + ::fclose( tgt ); /* rename temp -> src */ if ( !QFile::remove( absName ) ) @@ -481,8 +576,9 @@ bool Qtx::dos2unix( const QString& absName ) } /*! - Name: rgbSet [static public] - Desc: Pack the specified color into one integer RGB set. + \brief Pack the specified color into integer RGB set. + \param c unpacked color + \return packed color */ int Qtx::rgbSet( const QColor& c ) { @@ -490,8 +586,11 @@ int Qtx::rgbSet( const QColor& c ) } /*! - Name: rgbSet [static public] - Desc: Pack the specified color components into one integer RGB set. + \brief Pack the specified RGB color components into integer RGB set. + \param r red component + \param g green component + \param b blue component + \return packed color */ int Qtx::rgbSet( const int r, const int g, const int b ) { @@ -499,19 +598,23 @@ 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. + \brief Unpack the specified integer RGB set to the color. + \param rgb packed color + \return unpacked color (QColor) */ -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 ); } /*! - Name: rgbSet [static public] - Desc: Unpack the specified integer RGB set into the color components. + \brief Unpack the specified integer RGB set to the three RGB components. + \param rgb packed color + \param r returned unpacked red component + \param g returned unpacked green component + \param b returned unpacked blue component */ void Qtx::rgbSet( const int rgb, int& r, int& g, int& b ) { @@ -521,8 +624,11 @@ void Qtx::rgbSet( const int rgb, int& r, int& g, int& b ) } /*! - Name: scaleColor [static public] - Desc: Returns the color specified by the index between min (blue) and max (red). + \brief Return the color specified by the index between min (blue) and max (red). + \param index color index + \param min required minimum hue value + \param max required maximum hue value + \return resulting color */ QColor Qtx::scaleColor( const int index, const int min, const int max ) { @@ -530,7 +636,7 @@ QColor Qtx::scaleColor( const int index, const int min, const int max ) int hue = HUE[0]; - if ( min != max ) + if ( min != max ) { double aPosition = 9.0 * ( index - min ) / ( max - min ); if ( aPosition > 0.0 ) @@ -545,14 +651,15 @@ 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. + \brief Generate required number of colors aligned from blue to red. + \param num required number of colors + \param lst returned set of colors */ -void Qtx::scaleColors( const int num, QValueList& lst ) +void Qtx::scaleColors( const int num, QColorList& lst ) { lst.clear(); for ( int i = 0; i < num; i++ ) @@ -560,8 +667,9 @@ void Qtx::scaleColors( const int num, QValueList& lst ) } /*! - Name: grayscale [static public] - Desc: Convert color image to grayscale image. + \brief Convert given image to the grayscale format. + \param img initial image + \return converted to the grayscale image */ QImage Qtx::grayscale( const QImage& img ) { @@ -589,26 +697,47 @@ QImage Qtx::grayscale( const QImage& img ) } /*! - Name: grayscale [static public] - Desc: Convert color pixmap to grayscale pixmap. + \brief Convert given pixmap to the grayscale format. + \param pix initial pixmap + \return converted to the grayscale pixmap */ QPixmap Qtx::grayscale( const QPixmap& pix ) { QPixmap res; - res.convertFromImage( grayscale( pix.convertToImage() ) ); + res.fromImage( grayscale( pix.toImage() ) ); return res; } /*! - Name: transparentImage [static public] - Desc: Create transparent image with specified width \aw, height \ah and color depth \ad. + \brief Create transparent image. + \param w required image width + \param h required image height + \param d required image depth + \return generated image */ 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 ) ); @@ -617,48 +746,59 @@ QImage Qtx::transparentImage( const int w, const int h, const int d ) } /*! - Name: transparentPixmap [static public] - Desc: Create transparent pixmap with specified width \aw, height \ah and color depth \ad. +/*! + \brief Create transparent pixmap. + \param w required image width + \param h required pixmap height + \param d required pixmap depth + \return generated pixmap */ 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; } /*! - Name: composite [static public] - Desc: Create composite pixmap. Pixmap 'pix' draws over pixmap 'dest' with coordinates - specified relative upper left corner of 'dest'. If 'dest' not given then new empty - pixmap with appropriate size created. + \brief Create composite pixmap. + + Pixmap \a pix is drawn over pixmap \a dest with coordinates + specified relatively to the upper left corner of \a dest. + If \a dest is not given, the new empty pixmap with appropriate size created instead. + + \param pix source pixmap + \param x horizontal shift + \param y vertical shift + \param dest background pixmap + \return resulting pixmap */ QPixmap Qtx::composite( const QPixmap& pix, const int x, const int y, const QPixmap& dest ) { 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 +810,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 +834,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..23ac9ea85 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -42,81 +42,70 @@ #define true 1 #endif -#ifndef INCLUDE_MENUITEM_DEF -#define INCLUDE_MENUITEM_DEF -#endif - -#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 +#include +#include class QObject; -class QString; class QWidget; -class QToolBar; -class QGroupBox; -class QPopupMenu; -class QWidgetList; +//class QToolBar; -template class QValueList; - -#if QT_VER < 3 -#define QPtrList QList -#define QPtrListIterator QListIterator -#endif - -typedef QValueList QIntList; -typedef QValueList QShortList; -typedef QValueList QDoubleList; +typedef QList QIntList; +typedef QList QShortList; +typedef QList QDoubleList; +typedef QList QColorList; /*! \class Qtx \brief Set of auxiliary static methods */ -class QTX_EXPORT Qtx : public Qt + +class QTX_EXPORT Qtx { public: enum AlignmentFlags { - AlignOutLeft = AlignVCenter << 2, - AlignOutRight = AlignOutLeft << 2, - AlignOutTop = AlignOutRight << 2, - AlignOutBottom = AlignOutTop << 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 +118,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, QColorList& ); static QImage grayscale( const QImage& ); static QPixmap grayscale( const QPixmap& ); diff --git a/src/Qtx/Qtx.pro b/src/Qtx/Qtx.pro new file mode 100644 index 000000000..fe5e44661 --- /dev/null +++ b/src/Qtx/Qtx.pro @@ -0,0 +1,97 @@ +TEMPLATE = lib +TARGET = qtx +DESTDIR = ../../lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../obj/$$TARGET + +QT += xml +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += QTX_EXPORTS + +HEADERS = Qtx.h +HEADERS += QtxAction.h +HEADERS += QtxActionMenuMgr.h +HEADERS += QtxActionMgr.h +HEADERS += QtxActionToolMgr.h +HEADERS += QtxColorScale.h +HEADERS += QtxComboBox.h +HEADERS += QtxDialog.h +HEADERS += QtxDockAction.h +HEADERS += QtxDockWidget.h +HEADERS += QtxMainWindow.h +HEADERS += QtxResourceMgr.h +HEADERS += QtxToolBar.h +HEADERS += QtxWorkstack.h +#HEADERS += QtxDblSpinBox.h +#HEADERS += QtxDblValidator.h +#HEADERS += QtxDirListEditor.h +#HEADERS += QtxGroupBox.h +#HEADERS += QtxIntSpinBox.h +#HEADERS += QtxListAction.h +#HEADERS += QtxListBox.h +#HEADERS += QtxListOfOperations.h +#HEADERS += QtxListResourceEdit.h +#HEADERS += QtxListView.h +#HEADERS += QtxLogoMgr.h +#HEADERS += QtxMRUAction.h +#HEADERS += QtxMenuButton.h +#HEADERS += QtxOperations.h +#HEADERS += QtxParser.h +#HEADERS += QtxPathDialog.h +#HEADERS += QtxPopupMenu.h +#HEADERS += QtxPopupMgr.h +#HEADERS += QtxResourceEdit.h +#HEADERS += QtxSplash.h +#HEADERS += QtxStdOperations.h +#HEADERS += QtxTable.h +#HEADERS += QtxToolTip.h +#HEADERS += QtxWorkspaceAction.h +#HEADERS += QtxWorkstackAction.h + +SOURCES = Qtx.cxx +SOURCES += QtxAction.cxx +SOURCES += QtxActionMenuMgr.cxx +SOURCES += QtxActionMgr.cxx +SOURCES += QtxActionToolMgr.cxx +SOURCES += QtxColorScale.cxx +SOURCES += QtxComboBox.cxx +SOURCES += QtxDialog.cxx +SOURCES += QtxDockAction.cxx +SOURCES += QtxDockWidget.cxx +SOURCES += QtxMainWindow.cxx +SOURCES += QtxResourceMgr.cxx +SOURCES += QtxToolBar.cxx +SOURCES += QtxWorkstack.cxx +#SOURCES += QtxDblSpinBox.cxx +#SOURCES += QtxDblValidator.cxx +#SOURCES += QtxDirListEditor.cxx +#SOURCES += QtxGroupBox.cxx +#SOURCES += QtxIntSpinBox.cxx +#SOURCES += QtxListAction.cxx +#SOURCES += QtxListBox.cxx +#SOURCES += QtxListOfOperations.cxx +#SOURCES += QtxListResourceEdit.cxx +#SOURCES += QtxListView.cxx +#SOURCES += QtxLogoMgr.cxx +#SOURCES += QtxMRUAction.cxx +#SOURCES += QtxMenuButton.cxx +#SOURCES += QtxOperations.cxx +#SOURCES += QtxParser.cxx +#SOURCES += QtxPathDialog.cxx +#SOURCES += QtxPopupMenu.cxx +#SOURCES += QtxPopupMgr.cxx +#SOURCES += QtxResourceEdit.cxx +#SOURCES += QtxSplash.cxx +#SOURCES += QtxStdOperations.cxx +#SOURCES += QtxTable.cxx +#SOURCES += QtxToolTip.cxx +#SOURCES += QtxWorkspaceAction.cxx +#SOURCES += QtxWorkstackAction.cxx + +includes.files = $$HEADERS +includes.path = ../../include + +INSTALLS += includes -- 2.39.2