and geometry store/retrieve.
*/
QtxMainWindow::QtxMainWindow( QWidget* parent, Qt::WindowFlags f )
-: QMainWindow( parent ),
+: QMainWindow( parent, f ),
myMode( -1 ),
myMenuBar( 0 ),
myStatusBar( 0 )
}
}
+QString QtxMainWindow::saveGeometry() const
+{
+ QRect frame = frameGeometry();
+ QRect screen = QApplication::desktop()->availableGeometry( this );
+
+ QString x;
+ if ( frame.left() == screen.left() )
+ x = QString( "+0" );
+ else if ( frame.right() == screen.right() )
+ x = QString( "-0" );
+ else
+ x = QString( "+%1" ).arg( frame.left() );
+
+ QString y;
+ if ( frame.top() == screen.top() )
+ y = QString( "+0" );
+ else if ( frame.bottom() == screen.bottom() )
+ y = QString( "-0" );
+ else
+ y = QString( "+%1" ).arg( frame.top() );
+
+ QString geom = QString( "%1x%2%3%4" ).arg( frame.width() ).arg( frame.height() ).arg( x ).arg( y );
+
+ QString state;
+ switch ( windowState() )
+ {
+ case Qt::WindowMaximized:
+ state = QString( "max" );
+ break;
+ case Qt::WindowMinimized:
+ state = QString( "min" );
+ break;
+ case Qt::WindowFullScreen:
+ state = QString( "full" );
+ break;
+ }
+
+ if ( !state.isEmpty() )
+ geom += QString( ":" ) + state;
+
+ return geom;
+}
+
+#include <stdio.h>
+
+void QtxMainWindow::loadGeometry( const QString& str )
+{
+ QString geom = str;
+ // geom.remove( '\t' );
+ // geom.remove( ' ' );
+
+ QRect rect = geometry();
+ QRect screen = QApplication::desktop()->availableGeometry( this );
+
+ QByteArray ba = geom.toLatin1();
+ const char* s = (const char*)ba;
+ printf( "Geometry string: %s\n", s );
+
+ QRegExp szRx( "(\\d+%?)\\s*x\\s*(\\d+%?)" );
+ if ( szRx.indexIn( geom ) != -1 )
+ {
+ int w = -1;
+ bool wp = false;
+ int ws = geometryValue( szRx.cap( 1 ).trimmed(), w, wp );
+ bool wOk = ws != 0;
+ if ( wOk && wp )
+ w = screen.width() * qMax( qMin( w, 100 ), 0 ) / 100;
+ wOk = wOk && w;
+
+ int h = -1;
+ bool hp = false;
+ int hs = geometryValue( szRx.cap( 2 ).trimmed(), h, hp );
+ bool hOk = hs != 0;
+ if ( hOk && hp )
+ h = screen.height() * qMax( qMin( h, 100 ), 0 ) / 100;
+ hOk = hOk && h;
+
+ if ( wOk && hOk )
+ rect.setSize( QSize( w, h ) );
+ }
+
+ QRegExp posRx( "([+|-]\\d+\%?)\\s*([+|-]\\d+\%?)" );
+ if ( posRx.indexIn( geom ) != -1 )
+ {
+ int x = -1;
+ bool xp = false;
+ int xs = geometryValue( posRx.cap( 1 ).trimmed(), x, xp );
+ bool xOk = xs != 0;
+ if ( xOk )
+ {
+ if ( xp )
+ x = screen.width() * qMax( qMin( x, 100 ), 0 ) / 100;
+ x = ( xs > 0 ? x : screen.right() - x - rect.width() ) + frameGeometry().x() - geometry().x();
+ }
+
+ int y = -1;
+ bool yp = false;
+ int ys = geometryValue( posRx.cap( 2 ).trimmed(), y, yp );
+ bool yOk = ys != 0;
+ if ( yOk )
+ {
+ if ( yp )
+ y = screen.height() * qMax( qMin( y, 100 ), 0 ) / 100;
+ y = ( ys > 0 ? y : screen.bottom() - y - rect.height() ) + frameGeometry().y() - geometry().y();
+ }
+
+ if ( xOk && yOk )
+ rect.moveTo( x, y );
+ }
+
+ Qt::WindowState state = Qt::WindowNoState;
+
+ QRegExp stRx( ":(\\w+)" );
+ if ( stRx.indexIn( geom ) != -1 )
+ {
+ QString stStr = stRx.cap( 1 ).trimmed().toLower();
+ if ( stStr.startsWith( QString( "max" ) ) )
+ state = Qt::WindowMaximized;
+ else if ( stStr.startsWith( QString( "min" ) ) )
+ state = Qt::WindowMinimized;
+ else if ( stStr.startsWith( QString( "full" ) ) )
+ state = Qt::WindowFullScreen;
+ }
+
+ setGeometry( rect );
+ if ( state != Qt::WindowNoState )
+ setWindowState( state );
+}
+
+int QtxMainWindow::geometryValue( const QString& str, int& num, bool& percent ) const
+{
+ num = -1;
+ int res = 1;
+ QString numStr = str;
+ if ( numStr.startsWith( "+" ) || numStr.startsWith( "-" ) )
+ {
+ res = numStr.startsWith( "+" ) ? 1 : -1;
+ numStr = numStr.mid( 1 );
+ }
+
+ percent = numStr.endsWith( "%" );
+ if ( percent )
+ numStr = numStr.mid( 0, numStr.length() - 1 );
+
+ bool ok = false;
+ num = numStr.toInt( &ok );
+ if ( !ok )
+ res = 0;
+
+ return res;
+}
+
/*!
Retrieve the geometry information from the specified resource manager section.
\param resMgr - instance of ersource manager
QString sec = section.trimmed();
if ( !resMgr || sec.isEmpty() )
return;
-
+ /*
int winState = -1;
if ( !resMgr->value( sec, "state", winState ) )
{
move( win_x, win_y );
myMode = -1;
+ */
/*
if ( vis )
QApplication::postEvent( this, new QEvent( QEvent::User, (void*)winState ) );
\param wh - left point
\param WH - right point
*/
+/*
int QtxMainWindow::relativeCoordinate( const int type, const int WH, const int wh ) const
{
int res = 0;
}
return res;
}
+*/
/*!
Store the geometry information into the specified resource manager section.
QString sec = section.trimmed();
if ( !resMgr || sec.isEmpty() )
return;
-
+ /*
resMgr->setValue( sec, "pos_x", pos().x() );
resMgr->setValue( sec, "pos_y", pos().y() );
resMgr->setValue( sec, "width", width() );
winState = WS_Maximized;
resMgr->setValue( sec, "state", winState );
+ */
}
/*!
\return flag of window state by it's name
\param str - name of flag
*/
+/*
int QtxMainWindow::windowState( const QString& str ) const
{
static QMap<QString, int> winStateMap;
res = winStateMap[stateStr];
return res;
}
+*/
/*!
\return flag of position by it's name
\param str - name of position
*/
+/*
int QtxMainWindow::windowPosition( const QString& str ) const
{
static QMap<QString, int> winPosMap;
res = winPosMap[posStr];
return res;
}
+*/
bool isDockableStatusBar() const;
void setDockableStatusBar( const bool );
+ QString saveGeometry() const;
+ void loadGeometry( const QString& );
+
void loadGeometry( QtxResourceMgr*, const QString& );
void saveGeometry( QtxResourceMgr*, const QString& ) const;
void onDestroyed( QObject* );
private:
- int windowState( const QString& ) const;
- int windowPosition( const QString& ) const;
- int relativeCoordinate( const int, const int, const int ) const;
+ int geometryValue( const QString&, int&, bool& ) const;
+// int windowState( const QString& ) const;
+// int windowPosition( const QString& ) const;
+// int relativeCoordinate( const int, const int, const int ) const;
private:
int myMode;
class QtxResourceMgr::Resources
{
public:
- Resources( const QtxResourceMgr*, const QString& );
+ Resources( QtxResourceMgr*, const QString& );
virtual ~Resources();
QString file() const;
friend class QtxResourceMgr::Format;
};
-QtxResourceMgr::Resources::Resources( const QtxResourceMgr* mgr, const QString& fileName )
-: myFileName( fileName ),
- myMgr( const_cast<QtxResourceMgr*>( mgr ) )
+QtxResourceMgr::Resources::Resources( QtxResourceMgr* mgr, const QString& fileName )
+: myMgr( mgr ),
+ myFileName( fileName )
{
}
if ( len )
{
buf = new char[len];
- if ( !file.open( QIODevice::ReadOnly ) || len != (uint)file.read( buf, len ) )
+ if ( !file.open( QIODevice::ReadOnly ) || len != (int)file.read( buf, len ) )
{
delete buf;
buf = 0;
QString varName = QString::null;
len = 0;
- QByteArray ba = str.toLatin1();
- const char* s = (const char*)ba;
-
QRegExp rx( "(^\\$\\{|[^\\$]\\$\\{)([a-zA-Z]+[a-zA-Z0-9_]*)(\\})|(^\\$\\(|[^\\$]\\$\\()([a-zA-Z]+[a-zA-Z0-9_]*)(\\))|(^\\$|[^\\$]\\$)([a-zA-Z]+[a-zA-Z0-9_]*)|(^%|[^%]%)([a-zA-Z]+[a-zA-Z0-9_]*)(%[^%]|%$)" );
int pos = rx.indexIn( str, start );
end++;
len = end - start;
}
-/*
- start = pos;
- len = rx.matchedLength();
- QStringList caps = rx.capturedTexts();
- for ( uint i = 1; i <= caps.count() && varName.isEmpty(); i++ )
- varName = caps[i];
-*/
}
return varName;
}
QtxResourceMgr* that = (QtxResourceMgr*)this;
if ( !userFileName( appName() ).isEmpty() )
- that->myResources.append( new Resources( this, userFileName( appName() ) ) );
+ that->myResources.append( new Resources( that, userFileName( appName() ) ) );
for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it )
{
QString path = Qtx::addSlash( *it ) + globalFileName( appName() );
- that->myResources.append( new Resources( this, path ) );
+ that->myResources.append( new Resources( that, path ) );
}
if ( autoLoad )
return false;
bool res = true;
- QStringList vals = val.split( "," );
+ QStringList vals = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts );
QIntList nums;
for ( QStringList::const_iterator it = vals.begin(); it != vals.end() && res; ++it )
- nums.append( (*it).toInt( &res ) );
+ {
+ int num = 0;
+ if ( (*it).startsWith( "#" ) )
+ num = (*it).mid( 1 ).toInt( &res, 16 );
+ else
+ num = (*it).toInt( &res, 10 );
+ if ( res )
+ nums.append( num );
+ }
- if ( res && nums.count() >= 3 )
+ res = res && nums.count() >= 3;
+ if ( res )
cVal.setRgb( nums[0], nums[1], nums[2] );
- else
+
+ if ( !res )
{
int pack = val.toInt( &res );
if ( res )
cVal = Qtx::rgbSet( pack );
}
+ if ( !res )
+ {
+ cVal = QColor( val );
+ res = cVal.isValid();
+ }
+
return res;
}
return true;
}
+/*!
+ \brief Get the resource value as byte array. Returns 'true' if it successfull otherwise
+ returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param baVal - Reference on the variable which should contains the resource output.
+*/
+bool QtxResourceMgr::value( const QString& sect, const QString& name, QByteArray& baVal ) const
+{
+ QString val;
+ if ( !value( sect, name, val, true ) )
+ return false;
+
+ baVal.clear();
+ QStringList lst = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts );
+ for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
+ {
+ int base = 10;
+ QString str = *it;
+ if ( str.startsWith( "#" ) )
+ {
+ base = 16;
+ str = str.mid( 1 );
+ }
+ bool ok = false;
+ int num = str.toInt( &ok, base );
+ if ( !ok || num < 0 || num > 255 )
+ continue;
+
+ baVal.append( (char)num );
+ }
+ return !baVal.isEmpty();
+}
+
/*!
\brief Get the resource value as string (native format). Returns 'true' if it
successfull otherwise returns 'false'.
return val;
}
+/*!
+ \brief Returns the byte array resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
+QByteArray QtxResourceMgr::byteArrayValue( const QString& sect, const QString& name, const QByteArray& def ) const
+{
+ QByteArray val;
+ if ( !value( sect, name, val ) )
+ val = def;
+ return val;
+}
+
/*!
\brief Checks existance of the specified resource.
\param sect - Resource section name which contains resource.
if ( checkExisting() && value( sect, name, res ) && res == val )
return;
- setResource( sect, name, QString( "%1, %2, %3" ).arg( val.red() ).arg( val.green() ).arg( val.blue() ) );
+ setResource( sect, name, val.isValid() ? val.name() : QString() );
}
/*!
setResource( sect, name, val );
}
+/*!
+ \brief Sets the string resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QByteArray& val )
+{
+ QByteArray res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
+
+ char buf[8];
+ QStringList lst;
+ for ( int i = 0; i < val.size(); i++ )
+ {
+ ::sprintf( buf, "#%02X", val.at( i ) );
+ lst.append( QString( buf ) );
+ }
+
+ setResource( sect, name, lst.join( " " ) );
+}
+
/*!
\brief Remove the all specified resource section.
\param sect - Resource section name.
{
QStringList translators = option( "translators" ).split( "|", QString::SkipEmptyParts );
QStringList newTranslators = trs.split( "|", QString::SkipEmptyParts );
- for ( uint i = 0; i < newTranslators.count(); i++ )
+ for ( int i = 0; i < (int)newTranslators.count(); i++ )
{
if ( translators.indexOf( newTranslators[i] ) < 0 )
translators += newTranslators[i];
#include <QtCore/qmap.h>
#include <QtCore/qlist.h>
+#include <QtCore/qbytearray.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qtranslator.h>
-#include <QtGui/qcolor.h>
#include <QtGui/qfont.h>
+#include <QtGui/qcolor.h>
#include <QtGui/qpixmap.h>
class QPixmap;
bool value( const QString&, const QString&, bool& ) const;
bool value( const QString&, const QString&, QColor& ) const;
bool value( const QString&, const QString&, QFont& ) const;
+ bool value( const QString&, const QString&, QByteArray& ) const;
bool value( const QString&, const QString&, QString&, const bool = true ) const;
int integerValue( const QString&, const QString&, const int = 0 ) const;
QFont fontValue( const QString&, const QString&, const QFont& = QFont() ) const;
QColor colorValue( const QString&, const QString&, const QColor& = QColor() ) const;
QString stringValue( const QString&, const QString&, const QString& = QString::null ) const;
+ QByteArray byteArrayValue( const QString&, const QString&, const QByteArray& = QByteArray() ) const;
bool hasSection( const QString& ) const;
bool hasValue( const QString&, const QString& ) const;
void setValue( const QString&, const QString&, const QFont& );
void setValue( const QString&, const QString&, const QColor& );
void setValue( const QString&, const QString&, const QString& );
+ void setValue( const QString&, const QString&, const QByteArray& );
void remove( const QString& );
void remove( const QString&, const QString& );