#include <qwidgetstack.h>
#include <qtoolbutton.h>
#include <qfontdialog.h>
+#include <qfontdatabase.h>
+#include <qfileinfo.h>
+#include <qfiledialog.h>
#include "QtxIntSpinBox.h"
#include "QtxDblSpinBox.h"
-
+#include "QtxComboBox.h"
#include "QtxDirListEditor.h"
/*
case DirList:
item = new DirListItem( title, resourceEdit(), this, this );
break;
+ case File:
+ item = new FileItem( title, resourceEdit(), this, this );
+ break;
}
return item;
Class: QtxListResourceEdit::FontItem
Descr: GUI implementation of resources font item.
*/
-QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
+QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* edit,
+ Item* pItem, QWidget* parent )
: PrefItem( Font, edit, pItem, parent )
{
new QLabel( title, this );
- myFontPrs = new QLabel( "", this );
- myFontPrs->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
- myFontPrs->setAutoResize( true );
- myFontPrs->setAlignment( Qt::AlignLeft );
-
- QToolButton* selFont = new QToolButton( this );
- selFont->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
- selFont->setText( "..." );
- connect( selFont, SIGNAL( clicked() ), this, SLOT( onSelectFont() ) );
+ myFamilies = new QtxComboBox( false, this );
+ mySizes = new QtxComboBox( true, this );
+ mySizes->setInsertionPolicy( QComboBox::NoInsertion );
+ myBold = new QCheckBox( tr( "Bold" ), this );
+ myItalic = new QCheckBox( tr( "Italic" ), this );
+ myUnderline = new QCheckBox( tr( "Underline" ), this );
+ myPreview = new QToolButton( this );
+ myPreview->setText( "..." );
+
+ myFamilies->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
+ mySizes->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
+
+ connect( myFamilies, SIGNAL( activated( int ) ), this, SLOT( onActivateFamily( int ) ) );
+ connect( myPreview, SIGNAL( clicked() ), this, SLOT( onPreview() ) );
+
+ setProperty( "system", ( bool )true );
+ setProperty( "widget_flags", ( int )All );
}
QtxListResourceEdit::FontItem::~FontItem()
void QtxListResourceEdit::FontItem::store()
{
- Item::setFont( myFont );
+ QFont f( family(), size() );
+ bool bold, italic, underline;
+ params( bold, italic, underline );
+ f.setBold( bold );
+ f.setItalic( italic );
+ f.setUnderline( underline );
+ Item::setFont( f );
}
void QtxListResourceEdit::FontItem::retrieve()
{
- myFont = getFont();
- buildFontPrs();
+ QFont f = getFont();
+ setFamily( f.family() );
+ setSize( f.pointSize() );
+ setParams( f.bold(), f.italic(), f.underline() );
+}
+
+QVariant QtxListResourceEdit::FontItem::property( const QString& name ) const
+{
+ if( name=="system" )
+ return myIsSystem;
+
+ else if( name=="widget_flags" )
+ return ( int )myFlags;
+
+ if( myIsSystem )
+ {
+ if( name=="families" )
+ {
+ QFontDatabase fdb;
+ return fdb.families();
+ }
+
+ else if( name=="default_family" )
+ {
+ QFontDatabase fdb;
+ QStringList fam = fdb.families();
+ if( fam.count()>0 )
+ return fam.first();
+ else
+ return QString::null;
+ }
+
+ else
+ {
+ QStringList parts = QStringList::split( ":", name );
+ if( parts.count()==2 )
+ {
+ if( parts[1]=="default_bold" || parts[1]=="default_italic" || parts[1]=="default_underline" )
+ return false;
+
+ else if( parts[1]=="sizes" )
+ {
+ QFontDatabase fdb;
+ QValueList<int> sizes = fdb.pointSizes( parts[0] );
+ QValueList<QVariant> vsizes;
+ QValueList<int>::const_iterator anIt = sizes.begin(),
+ aLast = sizes.end();
+ for( ; anIt!=aLast; anIt++ )
+ vsizes.append( *anIt );
+
+ return vsizes;
+ }
+
+ else if( parts[1]=="default_size" )
+ {
+ if( parts[0].isEmpty() )
+ return 0;
+
+ QFontDatabase fdb;
+ QValueList<int> sizes = fdb.pointSizes( parts[0] );
+ if( sizes.count()>0 )
+ return sizes.first();
+ else
+ return 0;
+ }
+ }
+ }
+ }
+
+ else if( myProperties.contains( name ) )
+ return myProperties[ name ];
+
+ return QVariant();
}
-void QtxListResourceEdit::FontItem::buildFontPrs()
+void QtxListResourceEdit::FontItem::setProperty( const QString& name, const QVariant& value )
{
- QStringList fval;
- fval.append( myFont.family() );
- if( myFont.bold() )
- fval.append( "Bold" );
- if( myFont.italic() )
- fval.append( "Italic" );
- fval.append( QString( "%1" ).arg( myFont.pointSize() ) );
+ if( name=="system" )
+ {
+ if( !value.canCast( QVariant::Bool ) )
+ return;
+
+ bool isSystem = value.toBool();
+ if( myIsSystem==isSystem )
+ return;
+
+ myIsSystem = isSystem;
+
+ QVariant families = property( "families" );
+ QString fam = family();
+
+ myFamilies->clear();
+ if( families.canCast( QVariant::StringList ) )
+ {
+ QStringList list = families.toStringList();
+ myFamilies->insertStringList( list );
+ }
+
+ setFamily( fam );
+ setSize( -1 ); //set default size
+ }
+
+ else if( name=="widget_flags" )
+ {
+ if( !value.canCast( QVariant::Int ) )
+ return;
+
+ int wf = value.toInt();
+
+ myFlags = wf;
+ myFamilies ->setShown( wf & Family );
+ mySizes ->setShown( wf & Size );
+ mySizes->lineEdit()->setReadOnly( ( wf & UserSize )==0 );
+ myBold ->setShown( wf & Bold );
+ myItalic ->setShown( wf & Italic );
+ myUnderline->setShown( wf & Underline );
+ bool isSystem = property( "system" ).canCast( QVariant::Bool ) ? property( "system" ).toBool() : false;
+ myPreview->setShown( ( wf & Preview ) && isSystem );
+
+ internalUpdate();
+ }
- myFontPrs->setText( fval.join( ", " ) );
+ else
+ myProperties[ name ] = value;
+}
+
+void QtxListResourceEdit::FontItem::setFamily( const QString& f )
+{
+ QString curtext;
+ if( myFamilies->isShown() )
+ {
+ if( myFamilies->listBox()->findItem( f, Qt::ExactMatch ) )
+ curtext = f;
+ }
+ else
+ {
+ QVariant deffam = property( "default_family" );
+ if( deffam.canCast( QVariant::String ) )
+ curtext = deffam.toString();
+ }
+
+ int idx = -1;
+ for ( int i = 0; i < (int)myFamilies->count() && idx < 0; i++ )
+ {
+ if ( myFamilies->text( i ) == curtext )
+ idx = i;
+ }
+
+ if ( idx >= 0 )
+ myFamilies->setCurrentItem( idx );
+
+ onActivateFamily( idx );
+}
+
+QString QtxListResourceEdit::FontItem::family() const
+{
+ return myFamilies->currentText();
+}
+
+void QtxListResourceEdit::FontItem::setSize( const int s )
+{
+ int cursize = -1;
+ if( mySizes->isShown() && s>0 )
+ {
+ if( ( myFlags & UserSize ) || mySizes->listBox()->findItem( QString( "%1" ).arg( s ), Qt::ExactMatch ) )
+ cursize = s;
+ }
+ else
+ {
+ QVariant defsize = property( QString( "%1:default_size" ).arg( family() ) );
+ if( defsize.canCast( QVariant::Int ) )
+ cursize = defsize.toInt();
+ }
+
+ mySizes->setCurrentText( cursize>0 ? QString( "%1" ).arg( cursize ) : "" );
+}
+
+int QtxListResourceEdit::FontItem::size() const
+{
+ QString s = mySizes->currentText();
+ bool ok;
+ int pSize = s.toInt( &ok );
+ return ( ok ? pSize : 0 );
+}
+
+void QtxListResourceEdit::FontItem::setParams( const bool bold, const bool italic, const bool underline )
+{
+ bool curbold = false, curitalic = false, curunderline = false;
+ if( myBold->isShown() )
+ curbold = bold;
+ else
+ {
+ QVariant def = property( QString( "%1:default_bold" ).arg( family() ) );
+ if( def.canCast( QVariant::Bool ) )
+ curbold = def.toBool();
+ }
+ if( myItalic->isShown() )
+ curitalic = italic;
+ else
+ {
+ QVariant def = property( QString( "%1:default_italic" ).arg( family() ) );
+ if( def.canCast( QVariant::Bool ) )
+ curitalic = def.toBool();
+ }
+ if( myUnderline->isShown() )
+ curunderline = underline;
+ else
+ {
+ QVariant def = property( QString( "%1:default_underline" ).arg( family() ) );
+ if( def.canCast( QVariant::Bool ) )
+ curunderline = def.toBool();
+ }
+ myBold->setChecked( curbold );
+ myItalic->setChecked( curitalic );
+ myUnderline->setChecked( curunderline );
+}
+
+void QtxListResourceEdit::FontItem::params( bool& bold, bool& italic, bool& underline )
+{
+ bold = myBold->isChecked();
+ italic = myItalic->isChecked();
+ underline = myUnderline->isChecked();
+}
+
+void QtxListResourceEdit::FontItem::internalUpdate()
+{
+ //update internal selection of font properties
+ setFamily( family() );
+ setSize( size() );
+ bool b1, b2, b3;
+ params( b1, b2, b3 );
+ setParams( b1, b2, b3 );
+}
+
+void QtxListResourceEdit::FontItem::onActivateFamily( int )
+{
+ QVariant sizes = property( QString( "%1:sizes" ).arg( family() ) );
+
+ int s = size();
+ mySizes->clear();
+ if( sizes.canCast( QVariant::List ) )
+ {
+ QValueList<QVariant> list = sizes.toList();
+ QStringList sizeItems;
+ QValueList<QVariant>::const_iterator anIt = list.begin(),
+ aLast = list.end();
+ for( ; anIt!=aLast; anIt++ )
+ if( (*anIt).canCast( QVariant::Int ) && (*anIt).toInt()>0 )
+ sizeItems.append( QString( "%1" ).arg( (*anIt).toInt() ) );
+ mySizes->insertStringList( sizeItems );
+ }
+ setSize( s );
}
-void QtxListResourceEdit::FontItem::onSelectFont()
+void QtxListResourceEdit::FontItem::onPreview()
{
+ QFont f( family(), size() );
+ bool bold, italic, underline;
+ params( bold, italic, underline );
+ f.setBold( bold );
+ f.setItalic( italic );
+ f.setUnderline( underline );
+
bool ok;
- QFont newFont = QFontDialog::getFont( &ok, myFont, this );
+ f = QFontDialog::getFont( &ok, f );
+
if( ok )
{
- myFont = newFont;
- buildFontPrs();
+ setFamily( f.family() );
+ setSize( f.pointSize() );
+ setParams( f.bold(), f.italic(), f.underline() );
}
}
+
+
+
+
+/*
+ Class: QtxListResourceEdit::DirListItem
+ Descr:
+*/
QtxListResourceEdit::DirListItem::DirListItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
: PrefItem( Font, edit, pItem, parent )
{
{
myDirListEditor->setPathList(QStringList::split(";", getString()));
}
+
+
+
+/*
+ Class: QtxListResourceEdit::FileItem
+ Descr: GUI implementation of resources file item.
+*/
+QtxListResourceEdit::FileItem::FileItem( const QString& title, QtxResourceEdit* edit,
+ Item* pItem, QWidget* parent )
+: PrefItem( Font, edit, pItem, parent ),
+ myFlags( QFileInfo::ReadUser ),
+ myIsExisting( true ),
+ myFileDlg( 0 )
+{
+ new QLabel( title, this );
+ myFile = new QLineEdit( this );
+ myFile->setValidator( new FileValidator( this, myFile ) );
+ myFile->setReadOnly( true );
+ myOpenFile = new QToolButton( this );
+ myOpenFile->setText( "..." );
+ connect( myOpenFile, SIGNAL( clicked() ), this, SLOT( onOpenFile() ) );
+}
+
+QtxListResourceEdit::FileItem::~FileItem()
+{
+ if( myFileDlg )
+ delete myFileDlg;
+}
+
+void QtxListResourceEdit::FileItem::store()
+{
+ setString( myFile->text() );
+}
+
+void QtxListResourceEdit::FileItem::retrieve()
+{
+ myFile->setText( getString() );
+}
+
+QVariant QtxListResourceEdit::FileItem::property( const QString& name ) const
+{
+ if( name=="filter" )
+ return myFilter;
+ else if( name=="existing" )
+ return myIsExisting;
+ else if( name=="flags" )
+ return myFlags;
+
+ return QVariant();
+}
+
+void QtxListResourceEdit::FileItem::setProperty( const QString& name, const QVariant& value )
+{
+ if( name=="filter" )
+ {
+ if( value.canCast( QVariant::String ) )
+ {
+ myFilter.clear();
+ myFilter.append( value.toString() );
+ }
+ else if( value.canCast( QVariant::StringList ) )
+ myFilter = value.toStringList();
+ }
+ else if( name=="existing" && value.canCast( QVariant::Bool ) )
+ myIsExisting = value.toBool();
+
+ else if( name=="flags" && value.canCast( QVariant::UInt ) )
+ myFlags = value.toUInt();
+}
+
+void QtxListResourceEdit::FileItem::onOpenFile()
+{
+ if( !myFileDlg )
+ {
+ myFileDlg = new QFileDialog( "." );
+ connect( myFileDlg, SIGNAL( fileHighlighted( const QString& ) ), this, SLOT( onFileSelected( const QString& ) ) );
+ }
+
+ myFileDlg->setCaption( title() );
+ myFileDlg->setFilters( myFilter );
+ myFileDlg->setMode( myIsExisting ? QFileDialog::ExistingFile : QFileDialog::AnyFile );
+
+ if( myFileDlg->exec()==QDialog::Accepted )
+ {
+ myFile->setText( myFileDlg->selectedFile() );
+ }
+}
+
+bool QtxListResourceEdit::FileItem::isFileCorrect( const QString& f ) const
+{
+ bool res = false;
+ QFileInfo info( f );
+ if( !myIsExisting || info.exists() )
+ res = info.isFile() && info.permission( myFlags );
+
+ return res;
+}
+
+void QtxListResourceEdit::FileItem::onFileSelected( const QString& f )
+{
+ if( myFileDlg && !isFileCorrect( f ) )
+ myFileDlg->setSelection( "" );
+}
+
+
+
+QtxListResourceEdit::FileItem::FileValidator::FileValidator( FileItem* item, QObject* parent )
+: QValidator( parent ),
+ myItem( item )
+{
+}
+
+QtxListResourceEdit::FileItem::FileValidator::~FileValidator()
+{
+}
+
+QValidator::State QtxListResourceEdit::FileItem::FileValidator::validate( QString& f, int& ) const
+{
+ if( myItem && myItem->isFileCorrect( f ) )
+ return QValidator::Acceptable;
+ else
+ return QValidator::Intermediate;
+}