#include <qtoolbutton.h>
#include <qfontdialog.h>
#include <qfontdatabase.h>
+#include <qfileinfo.h>
+#include <qfiledialog.h>
#include "QtxIntSpinBox.h"
#include "QtxDblSpinBox.h"
case DirList:
item = new DirListItem( title, resourceEdit(), this, this );
break;
+ case File:
+ item = new FileItem( title, resourceEdit(), this, this );
+ break;
}
return item;
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( "widget_flags", ( int )All );
setProperty( "system", ( bool )true );
+ setProperty( "widget_flags", ( int )All );
}
QtxListResourceEdit::FontItem::~FontItem()
setFamily( fam );
setSize( -1 ); //set default size
- onActivateFamily( -1 );
}
else if( name=="widget_flags" )
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();
}
if ( idx >= 0 )
myFamilies->setCurrentItem( idx );
+
+ onActivateFamily( idx );
}
QString QtxListResourceEdit::FontItem::family() const
setSize( s );
}
+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;
+ f = QFontDialog::getFont( &ok, f );
+
+ if( ok )
+ {
+ setFamily( f.family() );
+ setSize( f.pointSize() );
+ setParams( f.bold(), f.italic(), f.underline() );
+ }
+}
+
+
{
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->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;
+}
#include <qhbox.h>
#include <qframe.h>
#include <qgroupbox.h>
+#include <qvalidator.h>
class QLabel;
class QListBox;
class IntegerSpinItem;
class IntegerEditItem;
class FontItem;
+ class FileItem;
class DirListItem;
- enum { Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, GroupBox, Font, DirList, User };
+ enum { Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, GroupBox, Font, DirList, File, User };
public:
QtxListResourceEdit( QtxResourceMgr*, QWidget* = 0 );
*/
class QtxComboBox;
+class QToolButton;
class QtxListResourceEdit::FontItem : public PrefItem
{
Bold = 0x08,
Italic = 0x10,
Underline = 0x20,
+ Preview = 0x40,
- All = Family | Size | UserSize | Bold | Italic | Underline
+ All = Family | Size | UserSize | Bold | Italic | Underline | Preview
} WidgetFlags;
private slots:
void onActivateFamily( int );
+ void onPreview();
private:
void setFamily( const QString& );
bool myIsSystem;
QtxComboBox *myFamilies, *mySizes;
QCheckBox *myBold, *myItalic, *myUnderline;
+ QToolButton *myPreview;
QMap<QString, QVariant> myProperties;
};
QtxDirListEditor* myDirListEditor; //!< The widget wich implements in GUI the list of directories
};
+/*
+ Class: QtxListResourceEdit::FontItem
+ Descr: GUI implementation of resources font item.
+*/
+
+class QtxComboBox;
+class QToolButton;
+class QFileDialog;
+
+class QtxListResourceEdit::FileItem : public PrefItem
+{
+ Q_OBJECT
+
+private:
+ class FileValidator : public QValidator
+ {
+ public:
+ FileValidator( FileItem*, QObject* );
+ ~FileValidator();
+
+ virtual QValidator::State validate( QString&, int& ) const;
+
+ private:
+ FileItem* myItem;
+ };
+
+public:
+ FileItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 );
+ virtual ~FileItem();
+
+ virtual void store();
+ virtual void retrieve();
+
+ virtual QVariant property( const QString& ) const;
+ virtual void setProperty( const QString&, const QVariant& );
+
+ virtual bool isFileCorrect( const QString& ) const;
+
+private slots:
+ void onOpenFile();
+ void onFileSelected( const QString& );
+
+private:
+ uint myFlags;
+ QStringList myFilter;
+ bool myIsExisting;
+ QLineEdit* myFile;
+ QToolButton* myOpenFile;
+ QFileDialog* myFileDlg;
+};
+
+
#endif