From: asl Date: Mon, 25 Jul 2005 04:22:01 +0000 (+0000) Subject: new preference: file selector X-Git-Tag: V3_0_1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=28b4e92038cdec491f0cc319a156af3bf55e0c3e;p=modules%2Fgui.git new preference: file selector and new flag in FontItem: Preview; if this flag is on, then user can use standard font dialog to select font --- diff --git a/src/Qtx/QtxListResourceEdit.cxx b/src/Qtx/QtxListResourceEdit.cxx index 597d945f2..4bd054886 100644 --- a/src/Qtx/QtxListResourceEdit.cxx +++ b/src/Qtx/QtxListResourceEdit.cxx @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include "QtxIntSpinBox.h" #include "QtxDblSpinBox.h" @@ -460,6 +462,9 @@ QtxResourceEdit::Item* QtxListResourceEdit::Group::createItem( const QString& ti case DirList: item = new DirListItem( title, resourceEdit(), this, this ); break; + case File: + item = new FileItem( title, resourceEdit(), this, this ); + break; } return item; @@ -935,14 +940,17 @@ QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* 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() @@ -1062,7 +1070,6 @@ void QtxListResourceEdit::FontItem::setProperty( const QString& name, const QVar setFamily( fam ); setSize( -1 ); //set default size - onActivateFamily( -1 ); } else if( name=="widget_flags" ) @@ -1079,6 +1086,8 @@ void QtxListResourceEdit::FontItem::setProperty( const QString& name, const QVar 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(); } @@ -1111,6 +1120,8 @@ void QtxListResourceEdit::FontItem::setFamily( const QString& f ) if ( idx >= 0 ) myFamilies->setCurrentItem( idx ); + + onActivateFamily( idx ); } QString QtxListResourceEdit::FontItem::family() const @@ -1213,6 +1224,27 @@ void QtxListResourceEdit::FontItem::onActivateFamily( int ) 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() ); + } +} + + @@ -1241,3 +1273,125 @@ void QtxListResourceEdit::DirListItem::retrieve() { 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; +} diff --git a/src/Qtx/QtxListResourceEdit.h b/src/Qtx/QtxListResourceEdit.h index 99ddfb75d..7a6d2b4a5 100644 --- a/src/Qtx/QtxListResourceEdit.h +++ b/src/Qtx/QtxListResourceEdit.h @@ -10,6 +10,7 @@ #include #include #include +#include class QLabel; class QListBox; @@ -49,9 +50,10 @@ public: 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 ); @@ -366,6 +368,7 @@ private: */ class QtxComboBox; +class QToolButton; class QtxListResourceEdit::FontItem : public PrefItem { @@ -380,8 +383,9 @@ public: Bold = 0x08, Italic = 0x10, Underline = 0x20, + Preview = 0x40, - All = Family | Size | UserSize | Bold | Italic | Underline + All = Family | Size | UserSize | Bold | Italic | Underline | Preview } WidgetFlags; @@ -397,6 +401,7 @@ public: private slots: void onActivateFamily( int ); + void onPreview(); private: void setFamily( const QString& ); @@ -412,6 +417,7 @@ private: bool myIsSystem; QtxComboBox *myFamilies, *mySizes; QCheckBox *myBold, *myItalic, *myUnderline; + QToolButton *myPreview; QMap myProperties; }; @@ -450,4 +456,56 @@ private: 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