\param title toolbar title
\param tid requested toolbar ID
+ \param mw parent main window; if it is null, the tool manager's main window is used
\return id of created/found toolbar
*/
-int QtxActionToolMgr::createToolBar( const QString& title, const int tid )
+int QtxActionToolMgr::createToolBar( const QString& title, const int tid, QMainWindow* mw )
{
static int _toolBarId = -1;
int tbId = -1;
for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && tbId == -1; ++it )
{
- if ( it.value().toolBar->windowTitle().toLower() == title.toLower() )
+ if( it.value().toolBar->windowTitle().toLower() == title.toLower() &&
+ ( !mw || it.value().toolBar->parent()==mw ) )
tbId = it.key();
}
if ( tbId != -1 )
return tbId;
- QToolBar* tb = find( title, mainWindow() );
+ QMainWindow* tbw = mw ? mw : mainWindow();
+ QToolBar* tb = find( title, tbw );
tbId = tid < 0 ? --_toolBarId : tid;
if ( !tb )
{
- tb = new QtxToolBar( true, mainWindow() );
- mainWindow()->addToolBar( tb );
+ tb = new QtxToolBar( true, tbw );
+ //mainWindow()->addToolBar( tb );
tb->setWindowTitle( title );
tb->setObjectName( title );
- }
+ tb->setToolTip( title );
+ }
tInfo.toolBar = tb;
connect( tInfo.toolBar, SIGNAL( destroyed() ), this, SLOT( onToolBarDestroyed() ) );
}
simplifySeparators( tb );
+
+ // fix of 19921 -->
+ if ( !tb->isVisible() )
+ tb->adjustSize();
+ // fix of 19921 <--
}
/*!
QMainWindow* mainWindow() const;
- int createToolBar( const QString&, int = -1 );
+ int createToolBar( const QString&, int = -1, QMainWindow* = 0 );
void removeToolBar( const QString& );
void removeToolBar( const int );
virtual bool load( const QString&, QtxActionMgr::Reader& );
+ int find( QToolBar* ) const;
+
protected slots:
void onToolBarDestroyed();
protected:
- int find( QToolBar* ) const;
int find( const QString& ) const;
QToolBar* find( const QString&, QMainWindow* ) const;
myMin = min;
myMax = max;
- myPrecise = QString::null;
+ myPrecise = QString();
if ( colorMode() == Auto || labelMode() == Auto )
updateScale();
return;
myFormat = format;
- myPrecise = QString::null;
+ myPrecise = QString();
if ( colorMode() == Auto )
updateScale();
}
return;
myInterval = num;
- myPrecise = QString::null;
+ myPrecise = QString();
updateScale();
}
QFrame::hide();
}
+/*!
+ \brief Paint widget
+ \param e paint event
+*/
+void QtxColorScale::paintEvent( QPaintEvent* e )
+{
+ QPainter p( this );
+ drawFrame( &p );
+ drawContents( &p );
+}
+
/*!
\brief Draw color scale (reimplemented from QFrame).
\param p painter
} DumpMode;
//! Color scale flags (bitwise).
typedef enum {
- AtBorder = 0x001,
- Reverse = 0x002,
- Integer = 0x004,
- WrapTitle = 0x008,
- PreciseFormat = 0x010,
- Transparent = 0x020
+ AtBorder = 0x001, //!< diplay values at colors boundaries
+ Reverse = 0x002, //!< display color scale in reverse order
+ Integer = 0x004, //!< round numbers to integer values
+ WrapTitle = 0x008, //!< wrap title to several lines
+ PreciseFormat = 0x010, //!< autodetect decimal point precision for color scale values
+ Transparent = 0x020 //!< transparent background (not implemented yet!)
} Flags;
public:
virtual void hide();
protected:
+ virtual void paintEvent( QPaintEvent* );
virtual void drawContents( QPainter* );
private:
#include "QtxComboBox.h"
+#include <QStandardItemModel>
#include <QLineEdit>
+#include <QEvent>
+#include <QApplication>
+
+/*!
+ \class QtxComboBox::Model
+ \brief Internal view model, used to process 'cleared' state of the combo box.
+ \internal
+*/
+class QtxComboBox::Model : public QStandardItemModel
+{
+public:
+ Model( QObject* parent = 0 );
+ ~Model();
+ void setCleared( const bool );
+
+ QVariant data( const QModelIndex&, int = Qt::DisplayRole ) const;
+
+private:
+ bool myCleared;
+};
+
+/*!
+ \brief Constructor
+ \internal
+ \param parent parent object
+*/
+QtxComboBox::Model::Model( QObject* parent )
+ : QStandardItemModel( 0, 1, parent ),
+ myCleared( false )
+{
+}
+
+/*!
+ \brief Destructor
+ \internal
+*/
+QtxComboBox::Model::~Model()
+{
+}
+
+/*!
+ \brief Set 'cleared' state
+ \param isClear new 'cleared' state
+ \internal
+*/
+void QtxComboBox::Model::setCleared( const bool isClear )
+{
+ if ( myCleared == isClear )
+ return;
+
+ myCleared = isClear;
+}
+
+/*!
+ \brief Get model data.
+ \param index model index
+ \param role data role
+ \return data of role \a role for the \a index
+ \internal
+*/
+QVariant QtxComboBox::Model::data( const QModelIndex& index, int role ) const
+{
+ return ( myCleared && ( role == Qt::DisplayRole || role == Qt::DecorationRole ) ) ?
+ QVariant() : QStandardItemModel::data( index, role );
+}
+
+/*!
+ \class QtxComboBox::ClearEvent
+ \brief Custom event, used to process 'cleared' state of the combo box
+ in the editable mode.
+ \internal
+*/
+
+#define CLEAR_EVENT QEvent::Type( QEvent::User + 123 )
+
+class QtxComboBox::ClearEvent : public QEvent
+{
+public:
+ ClearEvent();
+};
+
+/*!
+ \brief Constructor
+ \internal
+*/
+QtxComboBox::ClearEvent::ClearEvent() : QEvent( CLEAR_EVENT )
+{
+}
/*!
\class QtxComboBox
: QComboBox( parent ),
myCleared( false )
{
- connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
- connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
+ connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
+ connect( this, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onCurrentChanged( int ) ) );
+ setModel( new Model( this ) );
}
/*!
return;
myCleared = isClear;
-
- if ( isEditable() )
- {
- if ( myCleared )
- lineEdit()->setText( "" );
- else
- lineEdit()->setText( itemText( currentIndex() ) );
- }
-
- update();
-}
-
-/*!
- \brief Set current item.
- Does nothing if the item index is out of range.
+ if ( lineEdit() )
+ lineEdit()->setText( myCleared ? QString( "" ) : itemText( currentIndex() ) );
- \param idx item index
-*/
-void QtxComboBox::setCurrentIndex( int idx )
-{
- if ( idx < 0 || idx >= count() )
- return;
-
- myCleared = false;
- QComboBox::setCurrentIndex( idx );
+ update();
}
/*!
*/
void QtxComboBox::paintEvent( QPaintEvent* e )
{
- if ( !count() || !myCleared || isEditable() )
- QComboBox::paintEvent( e );
- else
- paintClear( e );
+ Model* m = dynamic_cast<Model*>( model() );
+ if ( m )
+ m->setCleared( myCleared );
+ QComboBox::paintEvent( e );
+ if ( m )
+ m->setCleared( false );
+}
+
+/*!
+ \brief Customize child addition/removal event
+ \param e child event
+*/
+void QtxComboBox::childEvent( QChildEvent* e )
+{
+ if ( ( e->added() || e->polished() ) && qobject_cast<QLineEdit*>( e->child() ) )
+ QApplication::postEvent( this, new ClearEvent() );
+}
+
+/*!
+ \brief Process custom events
+ \param e custom event
+*/
+void QtxComboBox::customEvent( QEvent* e )
+{
+ if ( e->type() == CLEAR_EVENT && lineEdit() && myCleared )
+ lineEdit()->setText( "" );
}
/*!
void QtxComboBox::onActivated( int idx )
{
resetClear();
-
emit activatedId( id( idx ) );
}
/*!
- \brief Called when any item is activated by the user.
- \param txt activated item text (not used)
+ \brief Called when current item is chaned (by the user or programmatically).
+ \param idx item being set current
*/
-void QtxComboBox::onActivated( const QString& /*txt*/ )
+void QtxComboBox::onCurrentChanged( int idx )
{
- resetClear();
+ if ( idx != -1 )
+ resetClear();
}
/*!
update();
}
-/*!
- \brief Draw combobox in the "cleared" state.
- \param e paint event
-*/
-void QtxComboBox::paintClear( QPaintEvent* e )
-{
- int curIndex = currentIndex();
- QString curText = itemText( curIndex );
- QIcon curIcon = itemIcon( curIndex );
-
- bool upd = updatesEnabled();
- setUpdatesEnabled( false );
-
- setItemIcon( curIndex, QIcon() );
- setItemText( curIndex, QString::null );
-
- QComboBox::paintEvent( e );
-
- setItemText( curIndex, curText );
- setItemIcon( curIndex, curIcon );
-
- setUpdatesEnabled( upd );
-}
-
/*!
\brief Get item ID by the index.
\param idx item index
\brief Emitted when the item with identificator \a id is activated.
\param id item ID
*/
-
-/*!
- \fn void QtxComboBox::highlightedId( int id )
- \brief Emitted when the item with identificator \a id is highlighted.
- \param id item ID
-*/
{
Q_OBJECT
+ class Model;
+ class ClearEvent;
+
public:
QtxComboBox( QWidget* = 0 );
virtual ~QtxComboBox();
bool isCleared() const;
void setCleared( const bool );
- virtual void setCurrentIndex( int );
-
int currentId() const;
void setCurrentId( int );
signals:
void activatedId( int );
- void highlightedId( int );
private slots:
void onActivated( int );
- void onActivated( const QString& );
+ void onCurrentChanged( int );
protected:
virtual void paintEvent( QPaintEvent* );
+ virtual void childEvent( QChildEvent* );
+ virtual void customEvent( QEvent* );
private:
void resetClear();
- void paintClear( QPaintEvent* );
private:
enum { IdRole = Qt::UserRole + 10 };
: QSpinBox( parent ),
myCleared( false )
{
+ setCorrectionMode( QSpinBox::CorrectToNearestValue );
connect( lineEdit(), SIGNAL( textChanged( const QString& ) ),
this, SLOT( onTextChanged( const QString& ) ) );
}
setMinimum( min );
setMaximum( max );
setSingleStep( step );
+ setCorrectionMode( QSpinBox::CorrectToNearestValue );
connect( lineEdit(), SIGNAL( textChanged( const QString& ) ),
this, SLOT( onTextChanged( const QString& ) ) );
\param parent parent object
*/
QtxListAction::QtxListAction( QObject* parent )
-: QWidgetAction( parent ),
+: QtxAction( parent ),
myFrame( 0 )
{
initialize();
*/
QtxListAction::QtxListAction( const QIcon& icon, const QString& menuText,
int accel, QObject* parent )
-: QWidgetAction( parent ),
+: QtxAction( menuText, icon, menuText, accel, parent ),
myFrame( 0 )
{
- setIcon( icon );
- setText( menuText );
- setShortcut( accel );
-
initialize();
}
\param parent parent object
*/
QtxListAction::QtxListAction( const QString& menuText, int accel, QObject* parent )
-: QWidgetAction( parent ),
+: QtxAction( menuText, menuText, accel, parent ),
myFrame( 0 )
{
- setText( menuText );
- setShortcut( accel );
-
initialize();
}
*/
QtxListAction::QtxListAction( const QString& text, const QString& menuText,
int accel, QObject* parent )
-: QWidgetAction( parent ),
+: QtxAction( text, menuText, accel, parent ),
myFrame( 0 )
{
- setText( menuText );
- setShortcut( accel );
- setToolTip( text );
- setStatusTip( text );
-
initialize();
}
*/
QtxListAction::QtxListAction( const QString& text, const QIcon& icon,
const QString& menuText, int accel, QObject* parent )
-: QWidgetAction( parent ),
+: QtxAction( text, icon, menuText, accel, parent ),
myFrame( 0 )
{
- setIcon( icon );
- setText( menuText );
- setShortcut( accel );
- setToolTip( text );
- setStatusTip( text );
-
initialize();
}
#define QTXLISTACTION_H
#include "Qtx.h"
-
+#include "QtxAction.h"
#include <QStringList>
-#include <QWidgetAction>
#ifdef WIN32
#pragma warning( disable:4251 )
#endif
-class QTX_EXPORT QtxListAction : public QWidgetAction
+class QTX_EXPORT QtxListAction : public QtxAction
{
Q_OBJECT
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 geom = QString( "%1x%2%3%4" ).arg( width() ).arg( height() ).arg( x ).arg( y );
QString state;
switch ( windowState() )
state = Qt::WindowFullScreen;
}
- setGeometry( rect );
+ resize( rect.size() );
+ move( rect.topLeft() );
+
if ( state != Qt::WindowNoState )
setWindowState( state );
}
QStringList prepareFilters( const QString& ) const;
bool hasVisibleChildren( QWidget* ) const;
QStringList filterWildCards( const QString& ) const;
- QString autoExtension( const QString&, const QString& = QString::null ) const;
+ QString autoExtension( const QString&, const QString& = QString() ) const;
protected:
enum { OpenFile, SaveFile, OpenDir, SaveDir, NewDir };
{
case QVariant::Int:
return v1.toInt() < v2.toInt();
- break;
case QVariant::Double:
return v1.toDouble() < v2.toDouble();
- break;
case QVariant::String:
return v1.toString() < v2.toString();
- break;
case QVariant::StringList:
case QVariant::List:
{
return (*anIt1)<(*anIt2);
}
return anIt1 == aLast1 && anIt2 != aLast2;
- break;
}
default:
return v1.toString() < v2.toString();
- break;
}
}
- else
- return t1 < t2;
+ return t1 < t2;
}
/*!
// Author: Alexander SOLOVYOV, Sergey TELKOV
#include "QtxResourceMgr.h"
+#include "QtxTranslator.h"
#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QTextStream>
-#include <QTranslator>
#include <QApplication>
#ifndef QT_NO_DOM
#include <QDomDocument>
*/
QTranslator* QtxResourceMgr::Resources::loadTranslator( const QString& sect, const QString& prefix, const QString& name ) const
{
- QTranslator* trans = new QTranslator( 0 );
+ QTranslator* trans = new QtxTranslator( 0 );
QString fname = fileName( sect, prefix, name );
-#ifdef EMULATE_GLOBAL_CONTEXT
- char* buf = 0;
- QFile file( fname );
- int len = file.size();
- if ( len )
- {
- buf = new char[len];
- if ( !file.open( QIODevice::ReadOnly ) || len != (int)file.read( buf, len ) )
- {
- delete buf;
- buf = 0;
- }
- file.close();
- }
- if ( buf )
- {
- char* pattern = "@default";
- size_t pl = strlen( pattern );
- for ( size_t i = 0; i < len - pl; i++ )
- {
- char* cur = buf + i;
- if ( !strncmp( cur, pattern, pl ) )
- {
- *cur = '\0';
- i += pl - 1;
- }
- }
-
- if ( !trans->load( (uchar*)buf, len ) )
- {
- delete buf;
- buf = 0;
- }
- }
-
- if ( !buf )
-#else
if ( !trans->load( Qtx::file( fname, false ), Qtx::dir( fname ) ) )
-#endif
{
delete trans;
trans = 0;
data.append( iter.key() + " = " + iter.value() );
data.append( "" );
- for ( QStringList::const_iterator itr = data.begin(); itr != data.end(); ++itr )
+ for ( QStringList::ConstIterator itr = data.begin(); itr != data.end(); ++itr )
ts << *itr << endl;
}
QTextStream ts( &file );
QStringList docStr = doc.toString().split( "\n" );
- for ( QStringList::const_iterator itr = docStr.begin(); itr != docStr.end(); ++itr )
+ for ( QStringList::ConstIterator itr = docStr.begin(); itr != docStr.end(); ++itr )
ts << *itr << endl;
file.close();
QtxResourceMgr::~QtxResourceMgr()
{
QStringList prefList = myTranslator.keys();
- for ( QStringList::const_iterator it = prefList.begin(); it != prefList.end(); ++it )
+ for ( QStringList::ConstIterator it = prefList.begin(); it != prefList.end(); ++it )
removeTranslators( *it );
- for ( ResList::iterator resIt = myResources.begin(); resIt != myResources.end(); ++resIt )
- delete *resIt;
- myResources.clear();
- for ( FormatList::iterator formIt = myFormats.begin(); formIt != myFormats.end(); ++formIt )
- delete *formIt;
+
+ qDeleteAll( myResources );
+ qDeleteAll( myFormats );
delete myDefaultPix;
}
Prepare the resources containers and load resources (if \a autoLoad is \c true).
- \param autoLoad if \c true then all resources are loaded
+ \param autoLoad if \c true (default) then all resources are loaded
+ \param loadUser if \c true (default) then user settings are also loaded
*/
-void QtxResourceMgr::initialize( const bool autoLoad ) const
+void QtxResourceMgr::initialize( const bool autoLoad, const bool loadUser ) const
{
if ( !myResources.isEmpty() )
return;
QtxResourceMgr* that = (QtxResourceMgr*)this;
- if ( !userFileName( appName() ).isEmpty() )
+ if ( loadUser && !userFileName( appName() ).isEmpty() )
that->myResources.append( new Resources( that, userFileName( appName() ) ) );
- for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it )
+ for ( QStringList::ConstIterator it = myDirList.begin(); it != myDirList.end(); ++it )
{
QString path = Qtx::addSlash( *it ) + globalFileName( appName() );
that->myResources.append( new Resources( that, path ) );
*/
void QtxResourceMgr::clear()
{
- for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it )
+ for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it )
(*it)->clear();
}
baVal.clear();
QStringList lst = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts );
- for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
+ for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it )
{
int base = 10;
QString str = *it;
bool ok = false;
- ResList::const_iterator it = myResources.begin();
+ ResList::ConstIterator it = myResources.begin();
if ( ignoreUserValues() )
++it;
initialize();
bool ok = false;
- for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && !ok; ++it )
+ for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && !ok; ++it )
ok = (*it)->hasValue( sect, name );
return ok;
initialize();
bool ok = false;
- for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && !ok; ++it )
+ for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && !ok; ++it )
ok = (*it)->hasSection( sect );
return ok;
{
initialize();
- for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it )
+ for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it )
(*it)->removeSection( sect );
}
{
initialize();
- for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it )
+ for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it )
(*it)->removeValue( sect, name );
}
if ( myResources.isEmpty() )
return;
- ResList::iterator resIt = myResources.begin();
+ ResList::Iterator resIt = myResources.begin();
if ( myResources.count() > myDirList.count() && resIt != myResources.end() )
{
(*resIt)->setFile( userFileName( appName() ) );
++resIt;
}
- for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end() && resIt != myResources.end(); ++it, ++resIt )
+ for ( QStringList::ConstIterator it = myDirList.begin(); it != myDirList.end() && resIt != myResources.end(); ++it, ++resIt )
(*resIt)->setFile( Qtx::addSlash( *it ) + globalFileName( appName() ) );
}
QtxResourceMgr::Format* QtxResourceMgr::format( const QString& fmt ) const
{
Format* form = 0;
- for ( FormatList::const_iterator it = myFormats.begin(); it != myFormats.end() && !form; ++it )
+ for ( FormatList::ConstIterator it = myFormats.begin(); it != myFormats.end() && !form; ++it )
{
if ( (*it)->format() == fmt )
form = *it;
return false;
bool res = true;
- for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it )
+ for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it )
res = fmt->load( *it ) && res;
return res;
initialize();
QMap<QString, int> map;
- for ( ResList::const_iterator it = myResources.begin(); it != myResources.end(); ++it )
+ for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end(); ++it )
{
QStringList lst = (*it)->sections();
- for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
+ for ( QStringList::ConstIterator itr = lst.begin(); itr != lst.end(); ++itr )
map.insert( *itr, 0 );
}
typedef IMap<QString, int> PMap;
#endif
PMap pmap;
- ResList lst;
- for ( ResList::const_iterator itr = myResources.begin(); itr != myResources.end(); ++itr )
- lst.prepend( *itr );
- for ( ResList::const_iterator it = lst.begin(); it != lst.end(); ++it )
+ ResList::ConstIterator it = myResources.end();
+ while ( it != myResources.begin() )
{
+ --it;
QStringList lst = (*it)->parameters( sec );
- for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
+ for ( QStringList::ConstIterator itr = lst.begin(); itr != lst.end(); ++itr )
pmap.insert( *itr, 0, false );
}
QString QtxResourceMgr::path( const QString& sect, const QString& prefix, const QString& name ) const
{
QString res;
- for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && res.isEmpty(); ++it )
+ for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && res.isEmpty(); ++it )
res = (*it)->path( sect, prefix, name );
return res;
}
initialize();
QPixmap pix;
- for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && pix.isNull(); ++it )
+ for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && pix.isNull(); ++it )
pix = (*it)->loadPixmap( resSection(), prefix, name );
if ( pix.isNull() )
pix = defPix;
*/
void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l )
{
- initialize();
+ loadLanguage( true, pref, l );
+}
+
+/*!
+ \brief Load translation files according to the specified language.
+
+ Names of the translation files are calculated according to the pattern specified
+ by the "translators" option (this option is read from the section "language" of resources files).
+ By default, "%P_msg_%L.qm" pattern is used.
+ Keywords \%A, \%P, \%L in the pattern are substituted by the application name, prefix and language name
+ correspondingly.
+ For example, for prefix "SUIT" and language "en", all translation files "SUIT_msg_en.qm" are searched and
+ loaded.
+
+ If prefix is empty or null string, all translation files specified in the "resources" section of resources
+ files are loaded (actually, the section is retrieved from resSection() method).
+ If language is not specified, it is retrieved from the langSection() method, and if the latest is also empty,
+ by default "en" (English) language is used.
+ By default, settings from the user preferences file are also loaded (if user resource file is valid,
+ see userFileName()). To avoid loading user settings, pass \c false as first parameter.
+
+ \param loadUser if \c true then user settings are also loaded
+ \param pref parameter which defines translation context (for example, package name)
+ \param l language name
+
+ \sa resSection(), langSection(), loadTranslators()
+*/
+void QtxResourceMgr::loadLanguage( const bool loadUser, const QString& pref, const QString& l )
+{
+ initialize( true, loadUser );
QMap<QChar, QString> substMap;
substMap.insert( 'A', appName() );
else
prefixList = parameters( resSection() );
- for ( QStringList::const_iterator iter = prefixList.begin(); iter != prefixList.end(); ++iter )
+ for ( QStringList::ConstIterator iter = prefixList.begin(); iter != prefixList.end(); ++iter )
{
QString prefix = *iter;
substMap.insert( 'P', prefix );
QStringList trs;
- for ( QStringList::const_iterator it = trList.begin(); it != trList.end(); ++it )
+ for ( QStringList::ConstIterator it = trList.begin(); it != trList.end(); ++it )
trs.append( substMacro( *it, substMap ).trimmed() );
loadTranslators( prefix, trs );
initialize();
ResList lst;
- for ( ResList::iterator iter = myResources.begin(); iter != myResources.end(); ++iter )
+ for ( ResList::Iterator iter = myResources.begin(); iter != myResources.end(); ++iter )
lst.prepend( *iter );
QTranslator* trans = 0;
- for ( ResList::iterator it = lst.begin(); it != lst.end(); ++it )
+ for ( ResList::Iterator it = lst.begin(); it != lst.end(); ++it )
{
- for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr )
+ for ( QStringList::ConstIterator itr = translators.begin(); itr != translators.end(); ++itr )
{
trans = (*it)->loadTranslator( resSection(), prefix, *itr );
if ( trans )
initialize();
QTranslator* trans = 0;
- ResList::iterator it = myResources.end();
- for ( ; it != myResources.begin(); --it )
+
+ ResList::ConstIterator it = myResources.end();
+ while ( it != myResources.begin() )
{
+ --it;
trans = (*it)->loadTranslator( resSection(), prefix, name );
if ( trans )
{
if ( !myTranslator.contains( prefix ) )
return;
- for ( TransList::iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
+ for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
{
QApplication::instance()->removeTranslator( *it );
delete *it;
if ( !myTranslator.contains( prefix ) )
return;
- for ( TransList::iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
+ for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
{
QApplication::instance()->removeTranslator( *it );
QApplication::instance()->installTranslator( *it );
void QtxResourceMgr::refresh()
{
QStringList sl = sections();
- for ( QStringList::const_iterator it = sl.begin(); it != sl.end(); ++it )
+ for ( QStringList::ConstIterator it = sl.begin(); it != sl.end(); ++it )
{
QStringList pl = parameters( *it );
- for ( QStringList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr )
+ for ( QStringList::ConstIterator itr = pl.begin(); itr != pl.end(); ++itr )
setResource( *it, *itr, stringValue( *it, *itr ) );
}
}
void QtxResourceMgr::setDirList( const QStringList& dl )
{
myDirList = dl;
- for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it )
+ for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it )
delete *it;
myResources.clear();
QPixmap loadPixmap( const QString&, const QString&, const bool ) const;
QPixmap loadPixmap( const QString&, const QString&, const QPixmap& ) const;
void loadLanguage( const QString& = QString(), const QString& = QString() );
+ void loadLanguage( const bool, const QString& = QString(), const QString& = QString() );
void raiseTranslators( const QString& );
void removeTranslators( const QString& );
virtual QString globalFileName( const QString& ) const;
private:
- void initialize( const bool = true ) const;
+ void initialize( const bool = true, const bool = true ) const;
QString substMacro( const QString&, const QMap<QChar, QString>& ) const;
private:
/*!
\class QtxSplash
- \brief The QtxSplash widget provides a splash screen that can be shown during application startup..
-
- A splash screen is a widget that is usually displayed when an application is being started.
- Splash screens are often used for applications that have long start up times to provide
- the user with feedback that the application is loading.
-
- Only one instance of the QtxSplash widget can be created. To access to the splash screen widget,
- use static method QtxSplash::splash(), which creates and instance of the QtxSplash widget if
- necessary and returns pointer to it. You should not destroy yhis instance - it is done automatically
- after application main window is shown. Just use methods finish() to make splash screen wait untill
- main window is shown.
-
- The splash screen appears in the center of the screen. The most common usage is to show a splash
- screen before the main widget is displayed on the screen.
+ \brief The QtxSplash widget provides a splash screen that can be shown
+ during application startup.
+
+ A splash screen is a widget that is usually displayed when an application
+ is being started.
+ Splash screens are often used for applications that have long start up times
+ to provide the user with feedback that the application is loading.
+
+ Only one instance of the QtxSplash widget can be created. To access the splash
+ screen widget, use static method QtxSplash::splash(), which creates an
+ instance of the QtxSplash widget (if it is not yet creaed) and returns a
+ pointer to it.
+ You should not destroy this instance - it is done automatically after
+ application main window is shown. Just use methods finish() to make splash
+ screen wait untill main window is shown.
+
+ The splash screen appears in the center of the screen.
+ The most common usage is to show a splash screen before the main widget
+ is displayed on the screen.
For example,
\code
int main(int argc, char *argv[])
}
\endcode
- The user can hide the splash screen by clicking on it with the mouse. Since the splash screen is
- typically displayed before the event loop has started running, it is necessary to periodically call
+ The user can hide the splash screen by clicking on it with the mouse.
+ Since the splash screen is typically displayed before the event loop
+ has started running, it is necessary to periodically call
QApplication::processEvents() to receive the mouse clicks.
- This feature can be switched off by using method setHideOnClick() with \c false parameter.
+ To activate the possibility of hiding the splash screen on the mouse
+ click, use setHideOnClick() method passing \c true as parameter.
+ By default, this feature is switched off.
- It is sometimes useful to update the splash screen with messages and/or progress information,
- for example, announcing connections established or modules loaded as the application starts up.
- QtxSplash class provides the functionality to show status messages and(or) progress bar.
+ It is sometimes useful to update the splash screen with any status messages
+ and/or progress information, for example, announcing connections established
+ or modules loaded as the application starts up.
+ QtxSplash class provides the functionality to show status messages
+ and(or) progress bar.
\code
QPixmap pixmap(":/splash.png");
QtxSplash* splash = QtxSplash::splash(pixmap);
- splash->setProgress(0, 5);
+ splash->setProgress(0, 5); // progress from 0 to 5
splash->show();
app.processEvents();
// doing first step
splash->setMessage("Step 1");
- splash->ress(1);
+ splash->setProgress(1); // progress is 20%
qApp->processEvents();
// ... perform some actions
// doing second step
splash->setMessage("Step 2");
- splash->setProgress(2);
+ splash->setProgress(2); // progress is 40%
qApp->processEvents();
// ... perform some actions
... et cetera
\endcode
- There is a static function QtxSplash::setStatus() which allows to put next status message
- and progress with one call. It can substitue two calls: setMessage() and setProgress().
-
- QtxSplash class provides alos a lot of functions to set-up its behavior. Set progress
- bar width with setProgressWidth() method, its position and direction with setProgressFlags().
- It can be single-colored or gradient-colored. Use setProgressColors() method for this.
- You can even set your own gradient scale with QLinearGradient and use it for the progress
- bar coloring: setProgressGradient().
-
- To change the progress bar and status message transparency, use setOpacity() function.
- The methods setTextAlignment(), setTextColor() and setTextColors() can be used to change
- the attributes of the status message.
-
- The displayed message text includes constant info and status message. The constant info
- is set by setConstantInfo() method and status message is set by setMessage().
-
- Sometimes it is useful to splay an error message above the splash screen window.
- For example, it can be necessary if an error occurs when loading the application.
- Method setError() can be used to show the error message and set the error code which
- can be then retrieved with the error() function.
+ There is a static function QtxSplash::setStatus() which allows to put the
+ next status message and current progress with one call.
+ It can substitue two calls: setMessage() and setProgress().
+
+ QtxSplash class provides also a lot of functions to customize its behavior.
+ Set progress bar width with setProgressWidth() method, its position and
+ direction with setProgressFlags().
+ It can be single-colored or gradient-colored. Use setProgressColors() methods
+ for this. You can even set your own gradient scale with QLinearGradient,
+ QRadialGradient or QConicalGradient and use it for the progress
+ bar coloring. In addition, it is possible to enable/disable displaying
+ of the progress percentage with setPercentageVisible() method.
+
+ Displaying of the progress bar and status messages can be switched on/off with
+ setProgressVisible() and setMessageVisible() methods.
+
+ To change the progress bar and status message transparency, use
+ setOpacity() function. The methods setTextAlignment() and setTextColors()
+ can be used to change the attributes of the status messages.
+
+ The displayed message text can include constant info and status message.
+ The constant info is set by setConstantInfo() method and status message
+ is set by setMessage().
+
+ Sometimes it is useful to display an error message above the splash screen
+ window. For example, it can be necessary if an error occurs when loading
+ the application. Method setError() can be used to show the error message
+ and set the error code which can be then retrieved with the error() function.
+
+ There is one more helpful feature. The QtxSplash class can read all the
+ settings from the resource file with help of resource manager
+ (QtxResourceMgr class). Refer to the method readSettings() for more details.
*/
//! The only one instance of splash screen
/*!
\brief Constructor.
- \brief Construct a splash screen that will display the \a pixmap.
+
+ Construct a splash screen that will display the \a pixmap.
+
\param pixmap splash screen pixmap
+ \sa setPixmap(), pixmap()
*/
QtxSplash::QtxSplash( const QPixmap& pixmap )
: QWidget( 0, Qt::SplashScreen | Qt::WindowStaysOnTopHint ),
myHideOnClick( false ),
myProgress( 0 ),
myTotal( 0 ),
- myStartColor( Qt::red ),
- myGradientType( Vertical ),
myProgressWidth( 10 ),
myProgressFlags( BottomSide | LeftToRight ),
myMargin( 5 ),
myOpacity( 1.0 ),
myError( 0 ),
- myGradientUsed( false )
+ myShowPercent( true ),
+ myShowProgress( true ),
+ myShowMessage( true )
{
setAttribute( Qt::WA_DeleteOnClose, true );
setPixmap( pixmap );
\param px splash screen pixmap
\return splash screen widget
+ \sa setPixmap(), pixmap()
*/
QtxSplash* QtxSplash::splash( const QPixmap& px )
{
return myHideOnClick;
}
+/*!
+ \brief Enable/disable displaying of the progress bar.
+ \param on if \c true, progress bar will be enabled
+ \sa progressVisible(), setMessageVisible()
+*/
+void QtxSplash::setProgressVisible( const bool on )
+{
+ myShowProgress = on;
+ repaint();
+}
+
+/*!
+ \brief Check if the progress bar is displayed.
+ \return \c true if progress bar is enabled
+ \sa setProgressVisible()
+*/
+bool QtxSplash::progressVisible() const
+{
+ return myShowProgress;
+}
+
+/*!
+ \brief Enable/disable displaying of the status message.
+ \param on if \c true, status message will be enabled
+ \sa messageVisible(), setProgressVisible()
+*/
+void QtxSplash::setMessageVisible( const bool on )
+{
+ myShowMessage = on;
+ repaint();
+}
+
+/*!
+ \brief Check if the status message is displayed.
+ \return \c true if status message is enabled
+ \sa setMessageVisible()
+*/
+bool QtxSplash::messageVisible() const
+{
+ return myShowMessage;
+}
+
+/*!
+ \brief Enable/disable displaying progress percentage.
+ \param enable if \c true, percentage will be displayed
+ \sa percentageVisible()
+*/
+void QtxSplash::setPercentageVisible( const bool enable )
+{
+ myShowPercent = enable;
+ repaint();
+}
+
+/*!
+ \brief Check if the progress percentage is displayed.
+ \return \c true if percentage displaying is enabled
+ \sa setPercentageVisible()
+*/
+bool QtxSplash::percentageVisible() const
+{
+ return myShowPercent;
+}
+
/*!
\brief Set total progress steps to \a total.
\param total total number of progress steps
}
/*!
- \brief Set margin (a border width).
+ \brief Set splash window margin (a border width).
+
+ Note, that margin is used only for drawing the progress bar and status
+ messages.
+
\param margin new margin width
\sa margin()
*/
}
/*!
- \brief Get margin (a border width).
+ \brief Get splash window margin (a border width).
\return current margin width
\sa setMargin()
*/
\brief Set progress bar position and direction.
By default, progress bar is displayed at the bottom side and
- shows progress from left to right.
+ shows progress from left to right but this behaviour can be changed.
\param flags ORed progress bar flags (QtxSplash::ProgressBarFlags)
\sa progressFlags()
/*!
\brief Set progress bar colors.
- If the colors differ the gradient color bar is drawn.
+ If the colors differ the two-colored gradient bar is drawn.
If the \a endColor is not valid, \a startColor is used instead
- (no gradient coloring).
+ (i.e. simple, one-colored progress bar is drawn).
- The parameter \a gradientType defines the type of gradient
+ The parameter \a orientation defines the type of gradient
to be drawn - horizontal or vertical. Default is vertical.
- Note, that methods setProgressGradient() and setProgressColors() are
- alternative. Only the latest used is taken into account.
-
\param startColor start gradient color (or mono-color)
\param endColor end gradient color
- \param gradientType gradient type (QtxSplash::GradientType)
- \sa progressColors(), setProgressGradient()
+ \param orientation gradient type (Qt::Orientation)
+ \sa progressColors()
*/
-void QtxSplash::setProgressColors( const QColor& startColor,
- const QColor& endColor,
- const GradientType gradientType )
+void QtxSplash::setProgressColors( const QColor& startColor,
+ const QColor& endColor,
+ const Qt::Orientation orientation )
{
- if ( startColor.isValid() )
- myStartColor = startColor;
- myEndColor = endColor;
- myGradientType = gradientType;
- myGradientUsed = false;
- repaint();
-}
+ if ( !startColor.isValid() )
+ return;
-/*!
- \brief Get progress colors and gradient type.
- \param startColor start gradient color (or mono-color)
- \param endColor end gradient color
- \return gradient type (QtxSplash::GradientType)
- \sa setProgressColors()
-*/
-QtxSplash::GradientType QtxSplash::progressColors( QColor& startColor,
- QColor& endColor ) const
-{
- startColor = myStartColor;
- endColor = myEndColor;
- return myGradientType;
+ QLinearGradient l;
+ if ( orientation == Qt::Vertical ) {
+ l.setStart( 0., 0. );
+ l.setFinalStop( 0., 1. );
+ }
+ else {
+ l.setStart( 0., 0. );
+ l.setFinalStop( 1., 0. );
+ }
+ l.setColorAt( 0., startColor );
+ l.setColorAt( 1., endColor.isValid() ? endColor : startColor );
+
+ setProgressColors( l );
}
/*!
- \brief Set custom progress bar colors.
+ \brief Set progress bar colors.
- The gradient start and final stops are scaled to the actual progress
- bar size. For example:
+ Use this method to display multi-colored gradient progress bar.
+ You have to use QLinearGradient, QRadialGradient or QConicalGradient
+ classes to define the gradient.
+
+ Note, that progress bar coordinates can be defined in absolute or
+ relative mode.
+ In absolute mode the actual coordinates of the gradient key points
+ (like start and final point for linear gradient, center and focal point
+ for radial gradient, etc) are calculated from the top-left progress bar's corner.
+ In relative mode you have to use values from 0 to 1 (including) to define
+ the key points positions.
+
+ For example:
\code
QLinearGradient lg(0.5, 0, 1, 1);
lg.setColorAt(0.2, Qt::blue);
splash->setProgressGradient(lg);
\endcode
The above code creates linear gradient, which sets start stop to the
- center of the progress bar; the final stop is always in the end of
- the progress bar. The color scale (blue to red) is changed by the
- progress bar diagonal.
-
- Note, that methods setProgressGradient() and setProgressColors() are
- alternative. Only the latest used is taken into account.
+ center of the progress bar; the final stop is assigned to its right-bottom corner.
+ The color scale (blue to red) is changed by the progress bar diagonal.
\param gradient color gradient to be used for progress bar coloring
- \sa progressGradient(), setProgressColors()
+ \sa progressColors()
*/
-void QtxSplash::setProgressGradient( const QLinearGradient& gradient )
+void QtxSplash::setProgressColors( const QGradient& gradient )
{
myGradient = gradient;
- myGradientUsed = true;
repaint();
}
/*!
\brief Get custom progress bar colors.
\return color gradient used for progress bar coloring
- \sa setProgressGradient()
+ \sa setProgressColors()
*/
-QLinearGradient QtxSplash::progressGradient() const
+const QGradient* QtxSplash::progressColors() const
{
- return myGradient;
+ return &myGradient;
}
/*!
}
/*!
- \brief Set message text color.
+ \brief Set message text colors.
- Default message color is white.
-
- \param color message text color
- \sa setTextColors()
-*/
-void QtxSplash::setTextColor( const QColor& color )
-{
- if ( myColor.isValid() )
- myColor = color;
- myShadowColor = QColor();
- repaint();
-}
+ If \a shadow parameter is invalid color, the simple one-colored
+ text is drawn. Otherwise, second parameter is used to draw the text
+ shadow.
-/*!
- \brief Get message text color.
- \return color message text color
- \sa setTextColor()
-*/
-QColor QtxSplash::textColor() const
-{
- return myColor;
-}
-
-/*!
- \brief Set message text color and text shadow color.
\param color message text color
\param shadow message text shadow color
- \sa textColors(), textColor(), setTextColor()
+ \sa textColors()
*/
void QtxSplash::setTextColors( const QColor& color, const QColor& shadow )
{
- if ( myColor.isValid() )
- myColor = color;
+ if ( !myColor.isValid() )
+ return;
+
+ myColor = color;
myShadowColor = shadow;
+
repaint();
}
/*!
- \brief Get message text color and text shadow color.
+ \brief Get message text colors.
\param color message text color
\param shadow message text shadow color
- \sa setTextColors(), textColor(), setTextColor()
+ \sa setTextColors()
*/
void QtxSplash::textColors( QColor& color, QColor& shadow ) const
{
message is set by setMessage().
\param info constant info text
- \sa constantInfo(), message(), setMessage()
+ \sa constantInfo(), message(), setMessage(), option(), setOption()
*/
void QtxSplash::setConstantInfo( const QString& info )
{
which is replaced at the time of the displaying.
The following options are supported:
- - %A - could be used as application name
- - %V - could be used as application version
- - %L - could be used as application license information
- - %C - could be used as application copyright information
+ - \c \%A - could be used as application name
+ - \c \%V - could be used as application version
+ - \c \%L - could be used as application license information
+ - \c \%C - could be used as application copyright information
+ For example,
+ \code
+ splash->setContantInfo("%A [%V]\n%C");
+ splash->setOption("%A", "MyApplication" );
+ splash->setOption("%V", "Version 1.0" );
+ splash->setOption("%C", "Copyright (C) MyCompany 2008" );
+ \endcode
+
\param name option name
\param option value
- \sa option()
+ \sa option(), setConstantInfo(), constantInfo()
*/
void QtxSplash::setOption( const QString& name, const QString& value )
{
\brief Get constant information option value.
\param name option name
\return option value or empty string if option is not set
- \sa setOption()
+ \sa setOption(), setConstantInfo(), constantInfo()
*/
QString QtxSplash::option( const QString& name ) const
{
/*!
\brief Get error code.
- This function returns error code, set previoiusly with
- error(const QString&, const QString&, const int) method.
+ This function returns error code, set previously with
+ setError() method.
If no error code has been set, 0 is returned.
\return last error code
/*!
\brief Read splash settings from the resources manager.
+
+ This method can be used to setup the splash screen look-n-feel.
+ By default, "splash" section of the resources file is used, but you can
+ use any other section.
+ All the splash screen parameters can be defined via resources file:
+ - \c "image" : splash screen image, see setPixmap()
+ - \c "margin" : splash window margin, see setMargin()
+ - \c "show_progress" : show progress bar flag, see setProgressVisible()
+ - \c "show_message" : show status messages flag, see setMessageVisible()
+ - \c "show_percents" : show progress percentage flag, see setPercentageVisible()
+ - \c "progress_width" : progress bar width(), see setProgressWidth()
+ - \c "progress_flags" : progress bar position and direction, see setProgressFlags()
+ - \c "constant_info" : status messages constant info, see setConstantInfo()
+ - \c "text_colors" : status messages color(s), see setTextColors()
+ - \c "progress_colors" : progress bar color(s), see setProgressColors()
+ - \c "opacity" : progress bar and status messages opacity, see setOpacity()
+ - \c "font" : status messages font
+ - \c "alignment" : status messages alignment flags, see setTextAlignment()
+ - \c "hide_on_click" : hide-on-click flag, see setHideOnClick()
+
\param resMgr resources manager
- \param section resources file section name (if empty, the default name is used).
+ \param section resources file section name (if empty, the default "splash"
+ section is used).
*/
void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section )
{
- QString resSection = section.isEmpty() ? "splash" : section;
+ QString resSection = section.isEmpty() ? QString( "splash" ) : section;
// pixmap
QString pxname;
}
#endif
+ // enable progress bar
+ bool bShowProgress;
+ if ( resMgr->value( resSection, "show_progress", bShowProgress ) ) {
+ setProgressVisible( bShowProgress );
+ }
+
+ // enable status message
+ bool bShowMessage;
+ if ( resMgr->value( resSection, "show_message", bShowMessage ) ) {
+ setMessageVisible( bShowMessage );
+ }
+
// margin
int m;
if ( resMgr->value( resSection, "margin", m ) ) {
}
setTextAlignment( fl );
}
-
// progress color(s)
QString pc;
- QLinearGradient grad;
- if ( resMgr->value( resSection, "progress_gradient", grad ) ) {
- // gradient-colored progress bar
- setProgressGradient( grad );
+ QLinearGradient lgrad;
+ QRadialGradient rgrad;
+ QConicalGradient cgrad;
+ if ( resMgr->value( resSection, "progress_color", lgrad ) ||
+ resMgr->value( resSection, "progress_colors", lgrad ) ) {
+ // linear gradient-colored progress bar
+ setProgressColors( lgrad );
+ }
+ else if ( resMgr->value( resSection, "progress_color", rgrad ) ||
+ resMgr->value( resSection, "progress_colors", rgrad ) ) {
+ // radial gradient-colored progress bar
+ setProgressColors( rgrad );
+ }
+ else if ( resMgr->value( resSection, "progress_color", cgrad ) ||
+ resMgr->value( resSection, "progress_colors", cgrad ) ) {
+ // conical gradient-colored progress bar
+ setProgressColors( cgrad );
}
else if ( resMgr->value( resSection, "progress_color", pc ) ||
resMgr->value( resSection, "progress_colors", pc ) ) {
// one/two-colored progress bar
QStringList colors = pc.split( "|", QString::SkipEmptyParts );
QColor c1, c2;
- QtxSplash::GradientType gradType = QtxSplash::Vertical;
+ Qt::Orientation o = Qt::Vertical;
if ( colors.count() > 0 ) c1 = QColor( colors[0] );
if ( colors.count() > 1 ) c2 = QColor( colors[1] );
int gt;
bool bOk;
gt = colors[2].toInt( &bOk );
if ( bOk ) {
- if ( gt >= QtxSplash::Horizontal && gt <= QtxSplash::Vertical )
- gradType = (QtxSplash::GradientType)gt;
+ if ( gt == 0 )
+ o = Qt::Horizontal;
}
else {
- if ( colors[2].toLower() == "horizontal" )
- gradType = QtxSplash::Horizontal;
- else if ( colors[2].toLower() == "vertical" )
- gradType = QtxSplash::Vertical;
+ if ( colors[2].toLower().startsWith( "h" ) )
+ o = Qt::Horizontal;
}
}
- setProgressColors( c1, c2, gradType );
+ setProgressColors( c1, c2, o );
+ }
+ // show percents
+ bool bPercent;
+ if ( resMgr->value( resSection, "show_percents", bPercent ) ) {
+ setPercentageVisible( bPercent );
}
// text color(s)
/*!
\brief Remove the message being displayed on the splash screen.
- \sa message()
+
+ This is equivalent to setMessage("");
+
+ \sa message(), setMessage()
*/
void QtxSplash::clear()
{
/*!
\brief Draw the contents of the splash screen.
- \param painter painter
+ \param p painter
*/
void QtxSplash::drawContents( QPainter* p )
{
// draw progress bar
- if ( myTotal > 0 ) {
+ if ( myTotal > 0 && progressVisible() ) {
p->save();
drawProgressBar( p );
p->restore();
}
// draw status message
- if ( !fullMessage().isEmpty() ) {
+ if ( !fullMessage().isEmpty() && messageVisible() ) {
p->save();
drawMessage( p );
p->restore();
}
}
+/*!
+ \brief Check if the gradient is defined in the relative coordinates [static].
+ \internal
+ \return \c true if gradient is defined in the relative coordinates
+*/
+static bool checkGradient( const QGradient* g )
+{
+#define BOUNDED( a, min, max ) ( a >= min && a <= max )
+ if ( g->type() == QGradient::LinearGradient ) {
+ const QLinearGradient* lg = static_cast<const QLinearGradient*>( g );
+ return BOUNDED( lg->start().x(), 0.0, 1.0 ) &&
+ BOUNDED( lg->start().y(), 0.0, 1.0 ) &&
+ BOUNDED( lg->finalStop().x(), 0.0, 1.0 ) &&
+ BOUNDED( lg->finalStop().y(), 0.0, 1.0 );
+ }
+ if ( g->type() == QGradient::RadialGradient ) {
+ const QRadialGradient* rg = static_cast<const QRadialGradient*>( g );
+ return BOUNDED( rg->center().x(), 0.0, 1.0 ) &&
+ BOUNDED( rg->center().y(), 0.0, 1.0 ) &&
+ BOUNDED( rg->focalPoint().x(), 0.0, 1.0 ) &&
+ BOUNDED( rg->focalPoint().y(), 0.0, 1.0 ); // && BOUNDED( rg->radius(), 0.0, 1.0 );
+ }
+ if ( g->type() == QGradient::ConicalGradient ) {
+ const QConicalGradient* cg = static_cast<const QConicalGradient*>( g );
+ return BOUNDED( cg->center().x(), 0.0, 1.0 ) &&
+ BOUNDED( cg->center().y(), 0.0, 1.0 );
+ }
+ return false;
+}
+
/*!
\brief Draw progress bar.
\param p painter
+ \sa drawMessage()
*/
void QtxSplash::drawProgressBar( QPainter* p )
{
if ( myProgressFlags & RightToLeft)
cr.translate( 0, r.height() - cr.height() );
}
- int x1, x2, y1, y2;
- if ( myGradientType == Horizontal ) {
- x1 = r.left(); x2 = r.right(); y1 = y2 = 0;
- }
- else {
- x1 = x2 = 0; y1 = r.top(); y2 = r.bottom();
- }
- QLinearGradient lg;
- if ( myGradientUsed ) {
- QPointF start = myGradient.start();
- QPointF final = myGradient.finalStop();
- qreal xd = final.x() - start.x();
- qreal yd = final.y() - start.y();
- lg.setStart( xd != 0 ? r.left() + r.width() * start.x() / xd : 0,
- yd != 0 ? r.top() + r.height() * start.y() / yd : 0 );
- lg.setFinalStop( xd != 0 ? r.right() : 0, yd != 0 ? r.bottom() : 0 );
- lg.setStops( myGradient.stops() );
- lg.setSpread( myGradient.spread() );
- }
- else {
- lg.setStart( x1, y1 );
- lg.setFinalStop( x2, y2 );
- lg.setColorAt( 0, myStartColor );
- lg.setColorAt( 1, myEndColor.isValid() ? myEndColor : myStartColor );
+ QBrush b;
+ switch ( progressColors()->type() ) {
+ case QGradient::LinearGradient:
+ {
+ QLinearGradient lg;
+ const QLinearGradient* other = static_cast<const QLinearGradient*>( progressColors() );
+ if ( checkGradient( other ) ) {
+ // gradient is defined in relative coordinates [0.0 - 1.0]
+ lg.setStart( r.left() + r.width() * other->start().x(),
+ r.top() + r.height() * other->start().y() );
+ lg.setFinalStop( r.left() + r.width() * other->finalStop().x(),
+ r.top() + r.height() * other->finalStop().y() );
+ }
+ else {
+ // gradient is defined in absolute coordinates
+ // according to its dimensions
+ lg.setStart( r.topLeft() + other->start() );
+ lg.setFinalStop( r.topLeft() + other->finalStop() );
+ }
+
+ lg.setStops( other->stops() );
+ lg.setSpread( other->spread() );
+
+ b = QBrush( lg );
+
+ break;
+ } // case QGradient::LinearGradient
+ case QGradient::RadialGradient:
+ {
+ QRadialGradient rg;
+ const QRadialGradient* other = static_cast<const QRadialGradient*>( progressColors() );
+ if ( checkGradient( other ) ) {
+ // gradient is defined in relative coordinates [0.0 - 1.0]
+ rg.setCenter( r.left() + r.width() * other->center().x(),
+ r.top() + r.height() * other->center().y() );
+ rg.setFocalPoint( r.left() + r.width() * other->focalPoint().x(),
+ r.top() + r.height() * other->focalPoint().y() );
+ }
+ else {
+ // gradient is defined in absolute coordinates
+ // according to its dimensions
+ rg.setCenter( r.topLeft() + other->center() );
+ rg.setFocalPoint( r.topLeft() + other->focalPoint() );
+ }
+
+ // only width is taken into account for the radius in relative mode
+ rg.setRadius( other->radius() > 1.0 ? other->radius() : r.width() * other->radius() );
+
+ rg.setStops( other->stops() );
+ rg.setSpread( other->spread() );
+
+ b = QBrush( rg );
+
+ break;
+ } // case QGradient::RadialGradient
+ case QGradient::ConicalGradient:
+ {
+ QConicalGradient cg;
+ const QConicalGradient* other = static_cast<const QConicalGradient*>( progressColors() );
+ if ( checkGradient( other ) ) {
+ // gradient is defined in relative coordinates [0.0 - 1.0]
+ cg.setCenter( r.left() + r.width() * other->center().x(),
+ r.top() + r.height() * other->center().y() );
+ }
+ else {
+ // gradient is defined in absolute coordinates
+ // according to its dimensions
+ cg.setCenter( r.topLeft() + other->center() );
+ }
+
+ cg.setAngle( other->angle() );
+ cg.setStops( other->stops() );
+ cg.setSpread( other->spread() );
+
+ b = QBrush( cg );
+
+ break;
+ } // case QGradient::RadialGradient
+ default:
+ b = QBrush( Qt::red ); // default is simple red-colored progress bar
+ break;
}
+
p->setOpacity( myOpacity );
- p->setClipRect( cr );
- p->fillRect( r, lg );
- p->setClipping( false );
// draw progress bar outline rectangle
p->setPen( palette().color( QPalette::Dark ) );
p->setPen( palette().color( QPalette::Light ) );
p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
p->drawLine( r.right(), r.top(), r.right(), r.bottom() );
+
+ r.setCoords( r.left()+1, r.top()+1, r.right()-1, r.bottom()-1 );
+ p->setClipRect( cr );
+ p->fillRect( r, b );
+ p->setClipping( false );
+
+ if ( myShowPercent ) {
+ int percent = ( int )( ( myProgress > 0 ? myProgress : 0 ) * 100 / myTotal );
+ QFont f = font();
+ f.setPixelSize( r.height() - 4 );
+ p->setFont( f );
+ // draw shadow status text
+ if ( myShadowColor.isValid() ) {
+ QRect rs = r;
+ rs.moveTopLeft( rs.topLeft() + QPoint( 1,1 ) );
+ p->setPen( myShadowColor );
+ p->drawText( rs, Qt::AlignCenter, QString( "%1%" ).arg( percent ) );
+ }
+ p->setPen( myColor );
+ p->drawText( r, Qt::AlignCenter, QString( "%1%" ).arg( percent ) );
+ }
}
/*!
\brief Draw status message.
\param p painter
+ \sa drawProgressBar()
*/
void QtxSplash::drawMessage( QPainter* p )
{
// get rect, margin, progress bar width
QRect r = rect();
int m = margin();
- int pw = progressWidth();
+ int pw = progressVisible() ? progressWidth() : 0;
// calculate drawing rect
QFontMetrics f( font() );
/*!
\brief Draw the splash screen window contents.
+ \internal
*/
void QtxSplash::drawContents()
{
/*!
\brief Sets error code.
\param code error code
+ \internal
*/
void QtxSplash::setError( const int code )
{
\brief Get full message which includes constant info and status message.
\return get fill message text
\sa constantInfo(), setConstantInfo(), message(), setMessage()
+ \internal
*/
QString QtxSplash::fullMessage() const
{
#include <QWidget>
#include <QPixmap>
-#include <QLinearGradient>
+#include <QGradient>
#include <QMap>
#ifdef WIN32
QtxSplash( const QPixmap& );
public:
- //! Gradient type
- typedef enum {
- Horizontal, //!< horizontal
- Vertical //!< vertical
- } GradientType;
-
//! Progress bar position and direction
typedef enum {
LeftSide = 0x0001, //!< progress bar is displayed at the left side
void setHideOnClick( const bool );
bool hideOnClick() const;
-
+
+ void setProgressVisible( const bool );
+ bool progressVisible() const;
+
+ void setMessageVisible( const bool );
+ bool messageVisible() const;
+
+ void setPercentageVisible( const bool );
+ bool percentageVisible() const;
+
void setTotalSteps( const int );
int totalSteps() const;
void setProgressWidth( const int );
int progressWidth() const;
-
+
void setProgressFlags( const int );
int progressFlags() const;
void setProgressColors( const QColor&,
const QColor& = QColor(),
- const GradientType = Vertical );
- GradientType progressColors( QColor&, QColor& ) const;
-
- void setProgressGradient( const QLinearGradient& );
- QLinearGradient progressGradient() const;
+ const Qt::Orientation = Qt::Vertical );
+ void setProgressColors( const QGradient& );
+ const QGradient* progressColors() const;
void setOpacity( const double );
double opacity() const;
void setTextAlignment( const int );
int textAlignment() const;
- void setTextColor( const QColor& );
- QColor textColor() const;
void setTextColors( const QColor&, const QColor& = QColor() );
void textColors( QColor&, QColor& ) const;
bool myHideOnClick; //!< 'hide on click' flag
int myProgress; //!< current progress
int myTotal; //!< total progress steps
- QColor myStartColor; //!< progress bar gradient starting color
- QColor myEndColor; //!< progress bar gradient ending color
- GradientType myGradientType; //!< progress bar gradient direction
- QLinearGradient myGradient; //!< progress bar custom gradient
+ QGradient myGradient; //!< progress bar custom gradient
int myProgressWidth; //!< progress bar width
int myProgressFlags; //!< progress bar flags (QtxSplash::ProgressBarFlags)
int myMargin; //!< margin (for progress bar and status message)
double myOpacity; //!< progress bar / status message opacity
int myError; //!< error code
- bool myGradientUsed; //!< 'use custom gradient color scale' flag
OptMap myOptions; //!< constant info options
+ bool myShowProgress; //!< 'show progress bar' flag
+ bool myShowMessage; //!< 'show status message' flag
+ bool myShowPercent; //!< 'show percentage' flag
};
#endif
virtual bool eventFilter( QObject*, QEvent* );
+ bool isEmpty() const;
+ bool isVisible() const;
+
protected:
virtual void customEvent( QEvent* );
void updateVisibility();
+ void setEmpty( const bool );
+ void setVisible( const bool );
+
private:
QtxToolBar* myCont;
bool myState;
bool myEmpty;
- bool myVisible;
};
/*!
myState( true ),
myEmpty( false )
{
+ setVisible( myCont->isVisibleTo( myCont->parentWidget() ) );
+
myCont->installEventFilter( this );
- myVisible = myCont->isVisibleTo( myCont->parentWidget() );
installFilters();
}
if ( tb != myCont )
return;
- myVisible = true;
+ setVisible( true );
}
/*!
if ( tb != myCont )
return;
- myVisible = false;
+ setVisible( false );
+}
+
+bool QtxToolBar::Watcher::isEmpty() const
+{
+ return myEmpty;
+}
+
+bool QtxToolBar::Watcher::isVisible() const
+{
+ bool vis = false;
+ if ( myCont && myCont->toggleViewAction() )
+ vis = myCont->toggleViewAction()->isChecked();
+ return vis;
+}
+
+void QtxToolBar::Watcher::setEmpty( const bool on )
+{
+ myEmpty = on;
+}
+
+void QtxToolBar::Watcher::setVisible( const bool on )
+{
+ if ( !myCont || !myCont->toggleViewAction() )
+ return;
+
+ bool block = myCont->toggleViewAction()->signalsBlocked();
+ myCont->toggleViewAction()->blockSignals( true );
+ myCont->toggleViewAction()->setChecked( on );
+ myCont->toggleViewAction()->blockSignals( block );
}
/*!
if ( !myCont )
return;
+ bool vis = isVisible();
+
QtxToolBar* cont = myCont;
myCont = 0;
cont->show();
myCont = cont;
+
+ setVisible( vis );
}
/*!
if ( !myCont )
return;
+ bool vis = isVisible();
+
QtxToolBar* cont = myCont;
myCont = 0;
cont->hide();
myCont = cont;
+
+ setVisible( vis );
}
/*!
return;
bool vis = false;
-
QList<QAction*> actList = myCont->actions();
-
for ( QList<QAction*>::const_iterator it = actList.begin(); it != actList.end() && !vis; ++it )
{
if ( (*it)->isSeparator() )
}
QMainWindow* mw = myCont->mainWindow();
- if ( mw && myEmpty == vis )
+ bool empty = isEmpty();
+ if ( mw && empty == vis )
{
- myEmpty = !vis;
- if ( !myEmpty )
+ empty = !vis;
+ setEmpty( empty );
+ if ( !empty )
myCont->toggleViewAction()->setVisible( myState );
else
{
}
}
- vis = !myEmpty && myVisible;
+ vis = !empty && isVisible();
if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) )
vis ? showContainer() : hideContainer();
}
bool sortMenuEnabled() const;
void addMenuAction( QAction* );
-
protected:
void contextMenuEvent( QContextMenuEvent* );
private:
typedef QMap<int, QAction*> ActionsMap;
- bool myEnableSortMenu;
+ bool myEnableSortMenu;
ActionsMap myActions;
};
h->addMenuAction( action );
}
+/*!
+ \brief Resizes the given column in order to enclose its contents.
+ The size will be changed only if it is smaller than the size of
+ contents.
+ \param column number of column
+*/
+void QtxTreeView::resizeColumnToEncloseContents( int column )
+{
+ if (column < 0 || column >= header()->count())
+ return;
+
+ int contentsSizeHint = sizeHintForColumn(column);
+ int headerSizeHint = header()->isHidden() ? 0 : header()->sectionSizeHint(column);
+ int sizeHint = qMax(contentsSizeHint, headerSizeHint);
+
+ int currentSize = columnWidth( column );
+ if (currentSize < sizeHint)
+ setColumnWidth( column, sizeHint );
+}
+
/*
\brief Called when the header section is clicked.
\param column header column index
emit drawedRow( index );
}
+/*!
+ \brief Called when rows are about to be removed.
+ \param parent model index
+ \param start first row to remove
+ \param end last row to remove
+*/
+void QtxTreeView::rowsAboutToBeRemoved( const QModelIndex& parent, int start, int end )
+{
+ setCurrentIndex( QModelIndex() );
+ QTreeView::rowsAboutToBeRemoved( parent, start, end );
+}
+
/*!
\brief Expand/collapse the specified item (recursively).
\param index model index
void addHeaderMenuAction( QAction* );
+ void resizeColumnToEncloseContents( int );
+
protected slots:
void onHeaderClicked( int );
+ void rowsAboutToBeRemoved( const QModelIndex&, int, int );
void selectionChanged( const QItemSelection&, const QItemSelection& );
protected:
#include "QtxAction.h"
-#include <QRegExp>
#include <QMenu>
-#include <QFocusEvent>
-#include <QMouseEvent>
#include <QStyle>
+#include <QRegExp>
#include <QLayout>
+#include <QPainter>
#include <QSplitter>
+#include <QFocusEvent>
+#include <QMouseEvent>
#include <QRubberBand>
#include <QApplication>
+#include <QStyleOption>
#include <QInputDialog>
#include <QStackedWidget>
#include <QAbstractButton>
-#include <QPainter>
-#include <QStyleOption>
-
-#define DARK_COLOR_LIGHT 250
/*!
\class QtxWorkstackArea::WidgetEvent
connect( myActionsMap[Close], SIGNAL( triggered( bool ) ), this, SLOT( onCloseWindow() ) );
connect( myActionsMap[Rename], SIGNAL( triggered( bool ) ), this, SLOT( onRename() ) );
+ // Action shortcut will work when action added in any widget.
+ for ( QMap<int, QAction*>::iterator it = myActionsMap.begin(); it != myActionsMap.end(); ++it )
+ {
+ addAction( it.value() );
+ it.value()->setShortcutContext( Qt::ApplicationShortcut );
+ }
+
QVBoxLayout* base = new QVBoxLayout( this );
base->setMargin( 0 );
}
/*!
- \brief Get all child widgets in all workareas.
- \return list of widgets in all workareas
+ \brief Get list of all widgets in all areas or in specified area which given
+ widget belongs to
+ \param wid widget specifying area if it is equal to null when widgets of all
+ areas are retuned
+ \return list of widgets
*/
-QWidgetList QtxWorkstack::windowList() const
+QWidgetList QtxWorkstack::windowList( QWidget* wid ) const
{
QList<QtxWorkstackArea*> lst;
- areas( mySplit, lst, true );
+ if ( !wid )
+ {
+ areas( mySplit, lst, true );
+ }
+ else
+ {
+ QtxWorkstackArea* area = wgArea( wid );
+ if ( area )
+ lst.append( area );
+ }
QWidgetList widList;
for ( QList<QtxWorkstackArea*>::iterator it = lst.begin(); it != lst.end(); ++it )
if ( !split )
return;
- const QObjectList& objs = split->children();
+ /*const QObjectList& objs = */split->children(); // VSR: is it needed ???
QString sizesStr;
QList<int> sizes = split->sizes();
\brief Emitted when the workstack's child widget \w is activated.
\param w widget being activated
*/
+
+/*!
+ \brief Gets area containing given widget
+ \param wid widget
+ \return pointer to QtxWorkstackArea* object
+*/
+QtxWorkstackArea* QtxWorkstack::wgArea( QWidget* wid ) const
+{
+ QtxWorkstackArea* resArea = 0;
+
+ QList<QtxWorkstackArea*> areaList;
+ areas( mySplit, areaList, true );
+
+ QList<QtxWorkstackArea*>::ConstIterator it;
+ for ( it = areaList.begin(); it != areaList.end() && !resArea; ++it )
+ {
+ if ( (*it)->contains( wid ) )
+ resArea = *it;
+ }
+
+ return resArea;
+}
+
+/*!
+ \brief Moves the first widget to the same area which the second widget belongs to
+ \param wid widget to be moved
+ \param wid_to widget specified the destination area
+ \param before specifies whether the first widget has to be moved before or after
+ the second widget
+ \return TRUE if operation is completed successfully, FALSE otherwise
+*/
+bool QtxWorkstack::move( QWidget* wid, QWidget* wid_to, const bool before )
+{
+ if ( wid && wid_to )
+ {
+ QtxWorkstackArea* area_src = wgArea( wid );
+ QtxWorkstackArea* area_to = wgArea( wid_to );
+ if ( area_src && area_to )
+ {
+ // find index of the second widget
+ QWidgetList wgList = area_to->widgetList();
+ QWidgetList::ConstIterator it;
+ int idx = 0;
+ for ( it = wgList.begin(); it != wgList.begin(); ++it, idx++ )
+ {
+ if ( *it == wid_to )
+ break;
+ }
+
+ if ( idx < wgList.count() ) // paranoidal check
+ {
+ if ( !before )
+ idx++;
+ area_src->removeWidget( wid, true );
+ area_to->insertWidget( wid, idx );
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+/*!
+ \brief Group all windows in one area
+ \return TRUE if operation is completed successfully, FALSE otherwise
+*/
+void QtxWorkstack::stack()
+{
+ QWidgetList wgList = windowList();
+ if ( !wgList.count() )
+ return; // nothing to do
+
+ QtxWorkstackArea* area_to = 0;
+ QWidgetList::ConstIterator it;
+ for ( it = wgList.begin(); it != wgList.end(); ++it )
+ {
+ QtxWorkstackArea* area_src = 0;
+ if ( !area_to )
+ {
+ area_to = wgArea( *it );
+ area_src = area_to;
+ }
+ else
+ area_src = wgArea( *it );
+
+ if ( area_src != area_to )
+ {
+ area_src->removeWidget( *it, true );
+ area_to->insertWidget( *it, -1 );
+ }
+ }
+}
QtxWorkstack( QWidget* = 0 );
virtual ~QtxWorkstack();
- QWidgetList windowList() const;
+ QWidgetList windowList( QWidget* = 0 ) const;
QWidgetList splitWindowList() const;
QWidget* activeWindow() const;
int menuActions() const;
void split( const int );
+ bool move( QWidget* wid, QWidget* wid_to, const bool before );
+ void stack();
QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 );
void insertWidget( QWidget*, QWidget*, QWidget* );
QtxWorkstackArea* areaAt( const QPoint& ) const;
+ QtxWorkstackArea* wgArea( QWidget* ) const;
QtxWorkstackArea* targetArea();
QtxWorkstackArea* activeArea() const;