1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxListResourceEdit.cxx
20 // Author: Sergey TELKOV
22 #include "QtxListResourceEdit.h"
29 #include <qcombobox.h>
30 #include <qlineedit.h>
31 #include <qcheckbox.h>
32 #include <qtabwidget.h>
33 #include <qvalidator.h>
34 #include <qobjectlist.h>
35 #include <qcolordialog.h>
36 #include <qwidgetstack.h>
37 #include <qtoolbutton.h>
38 #include <qfontdialog.h>
39 #include <qfontdatabase.h>
40 #include <qfileinfo.h>
41 #include <qfiledialog.h>
42 #include <qapplication.h>
44 #include "QtxIntSpinBox.h"
45 #include "QtxDblSpinBox.h"
46 #include "QtxComboBox.h"
47 #include "QtxDirListEditor.h"
52 QtxListResourceEdit::QtxListResourceEdit( QtxResourceMgr* mgr, QWidget* parent )
54 QtxResourceEdit( mgr )
56 QVBoxLayout* main = new QVBoxLayout( this, 0, 5 );
57 QGroupBox* base = new QGroupBox( 1, Qt::Vertical, "", this );
58 base->setFrameStyle( QFrame::NoFrame );
59 base->setInsideMargin( 0 );
60 main->addWidget( base );
62 myList = new QListBox( base );
63 myStack = new QWidgetStack( base );
65 myList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
66 myStack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
68 myList->setSelectionMode( QListBox::Single );
70 connect( myList, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
72 setFocusProxy( myList );
80 QtxListResourceEdit::~QtxListResourceEdit()
86 \param id - id of widget
87 \param prop - name of resource
88 \param val - value of resource
90 void QtxListResourceEdit::setItemProperty( const int id, const QString& prop, const QVariant& val )
96 bool prev = i->isEmpty();
98 QtxResourceEdit::setItemProperty( id, prop, val );
100 bool next = i->isEmpty();
107 SLOT: called if main list selection changed, raises resource group widgets
109 void QtxListResourceEdit::onSelectionChanged()
111 QString title = myList->text( myList->index( myList->selectedItem() ) );
112 if ( title.isEmpty() )
118 for ( QPtrListIterator<Item> it( lst ); it.current() && !i; ++it )
120 if ( it.current()->title() == title )
125 myStack->raiseWidget( i->id() );
129 Custom activity after item addition
130 \param i - added item
132 void QtxListResourceEdit::itemAdded( QtxResourceEdit::Item* i )
137 QPtrList<Item> items;
140 if ( items.contains( i ) || items.contains( i->parentItem() ) )
145 Creates and \return category
146 \param title - category title
148 QtxResourceEdit::Item* QtxListResourceEdit::createItem( const QString& title, const int )
150 Item* i = item( title, -1 );
154 Category* category = new Category( this, myStack );
155 myStack->addWidget( category, category->id() );
159 if ( !myList->selectedItem() )
160 myList->setSelected( 0, true );
168 Emits signal about resource changing
169 \param map - map of changed resources
171 void QtxListResourceEdit::changedResources( const QMap<Item*, QString>& map )
173 QMap<int, QString> idMap;
174 for ( QMap<Item*, QString>::ConstIterator it = map.begin(); it != map.end(); ++it )
176 idMap.insert( it.key()->id(), it.data() );
178 emit resourceChanged( it.key()->id() );
181 it.key()->resource( sec, param );
182 emit resourceChanged( sec, param );
185 emit resourcesChanged( idMap );
189 Updates widgets with accordance with main list selection
191 void QtxListResourceEdit::updateState()
193 if ( myList->selectedItem() && myStack->visibleWidget() )
198 myList->setShown( myList->count() > 1 );
202 Updates visibility state
204 void QtxListResourceEdit::updateVisible()
206 QPtrList<Item> items;
209 QString name = myList->text( myList->index( myList->selectedItem() ) );
212 for ( QPtrListIterator<Item> it( items ); it.current(); ++it )
214 if ( it.current()->isEmpty() )
217 myList->insertItem( it.current()->title() );
221 for ( int i = 0; i < (int)myList->count() && idx == -1; i++ )
223 if ( myList->text( i ) == name )
227 myList->setSelected( QMAX( idx, 0 ), true );
235 QtxListResourceEdit::Category::Category( QtxListResourceEdit* edit, QWidget* parent )
239 QVBoxLayout* main = new QVBoxLayout( this );
240 QGroupBox* base = new QGroupBox( 1, Qt::Horizontal, "", this );
241 base->setFrameStyle( QFrame::NoFrame );
242 base->setInsideMargin( 0 );
243 main->addWidget( base, 1 );
245 myTabs = new QTabWidget( base );
246 myInfo = new QLabel( base );
248 myInfo->setAlignment( Qt::AlignCenter );
249 myInfo->setFrameStyle( QFrame::WinPanel | QFrame::Raised );
250 myInfo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
258 QtxListResourceEdit::Category::~Category()
263 \return true if it is empty
265 bool QtxListResourceEdit::Category::isEmpty() const
267 return Item::isEmpty() && myInfo->text().isEmpty();
271 \return category type
273 int QtxListResourceEdit::Category::type() const
279 Default empty implementation of resources storing
281 void QtxListResourceEdit::Category::store()
286 Default empty implementation of resources retrieving
288 void QtxListResourceEdit::Category::retrieve()
293 \return value of property
294 \param prop - property name
296 QVariant QtxListResourceEdit::Category::property( const QString& prop ) const
299 if ( prop == QString( "information" ) || prop == QString( "info" ) )
300 var = myInfo->text();
306 \param name - name of property
307 \param var - value of property
309 void QtxListResourceEdit::Category::setProperty( const QString& name, const QVariant& var )
312 if ( !prop.cast( QVariant::String ) )
315 if ( name == QString( "information" ) || name == QString( "info" ) )
316 myInfo->setText( prop.toString() );
323 \param title - name of tab
325 QtxResourceEdit::Item* QtxListResourceEdit::Category::createItem( const QString& title, const int )
327 Item* i = item( title, id() );
331 Tab* tab = new Tab( resourceEdit(), this, this );
332 myTabs->addTab( tab, title );
342 void QtxListResourceEdit::Category::updateState()
344 if ( myTabs->count() )
349 if ( !myTabs->count() && !myInfo->text().isEmpty() )
359 QtxListResourceEdit::Tab::Tab( QtxResourceEdit* edit, Item* pItem, QWidget* parent )
363 QVBoxLayout* main = new QVBoxLayout( this );
364 QVBox* vbox = new QVBox( this );
365 vbox->setMargin( 5 );
367 main->addWidget( myMainFrame );
368 main->addStretch( 1 );
374 QtxListResourceEdit::Tab::~Tab()
381 int QtxListResourceEdit::Tab::type() const
387 Default empty implementation of resources storing
389 void QtxListResourceEdit::Tab::store()
394 Default empty implementation of resources retrieving
396 void QtxListResourceEdit::Tab::retrieve()
401 Delayed initialization of a widget
403 void QtxListResourceEdit::Tab::polish()
412 \param title - name of group
414 QtxResourceEdit::Item* QtxListResourceEdit::Tab::createItem( const QString& title, const int )
416 Item* i = item( title, id() );
420 Group* group = new Group( title, resourceEdit(), this, myMainFrame );
426 Adjusts sizes of labels
428 void QtxListResourceEdit::Tab::adjustLabels()
430 QObjectList* labels = queryList( "QLabel" );
434 for ( QObjectListIt it1( *labels ); it1.current(); ++it1 )
436 if ( it1.current()->isWidgetType() )
438 QWidget* wid = (QWidget*)it1.current();
439 w = QMAX( w, wid->sizeHint().width() );
442 for ( QObjectListIt it2( *labels ); it2.current(); ++it2 )
444 if ( it2.current()->isWidgetType() )
446 QWidget* wid = (QWidget*)it2.current();
447 wid->setMinimumWidth( w );
457 QtxListResourceEdit::Group::Group( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
458 : QGroupBox( 2, Qt::Horizontal, title, parent ),
466 QtxListResourceEdit::Group::~Group()
473 int QtxListResourceEdit::Group::type() const
479 Default empty implementation of resources storing
481 void QtxListResourceEdit::Group::store()
486 Default empty implementation of resources retrieving
488 void QtxListResourceEdit::Group::retrieve()
493 \return value of property
494 \param prop - property name
496 QVariant QtxListResourceEdit::Group::property( const QString& prop ) const
499 if ( prop == "columns" )
500 var = QVariant( columns() );
501 else if ( prop == "orientation" )
502 var = QVariant( orientation() );
503 else if ( prop == "frame" )
504 var = QVariant( frameStyle() != QFrame::NoFrame );
510 \param name - name of property
511 \param var - value of property
513 void QtxListResourceEdit::Group::setProperty( const QString& name, const QVariant& var )
516 if ( !prop.cast( QVariant::Int ) )
519 if ( name == QString( "columns" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 )
520 setColumns( prop.toInt() );
521 else if ( name == QString( "orientation" ) && prop.cast( QVariant::Int ) )
523 int o = prop.toInt();
524 if ( o == Qt::Horizontal || o == Qt::Vertical )
525 setOrientation( (Orientation)o );
527 else if ( name == "frame" && prop.cast( QVariant::Bool ) )
529 setInsideMargin( prop.toBool() ? 5 : 0 );
530 QGroupBox::setTitle( prop.toBool() ? Item::title() : QString::null );
531 setFrameStyle( prop.toBool() ? QFrame::Box | QFrame::Sunken : QFrame::NoFrame );
537 \param title - new title of group
539 void QtxListResourceEdit::Group::setTitle( const QString& title )
541 Item::setTitle( title );
542 QGroupBox::setTitle( title );
547 \param title - title of new item
548 \type - type of new item
550 QtxResourceEdit::Item* QtxListResourceEdit::Group::createItem( const QString& title, const int type )
557 item = new ColorItem( title, resourceEdit(), this, this );
560 item = new StateItem( title, resourceEdit(), this, this );
563 item = new StringItem( title, resourceEdit(), this, this );
566 item = new SelectItem( title, resourceEdit(), this, this );
569 item = new DoubleSpinItem( title, resourceEdit(), this, this );
572 item = new IntegerSpinItem( title, resourceEdit(), this, this );
575 item = new DoubleEditItem( title, resourceEdit(), this, this );
578 item = new IntegerEditItem( title, resourceEdit(), this, this );
581 item = new Spacer( resourceEdit(), this, this );
584 item = new Group( title, resourceEdit(), this, this );
587 item = new FontItem( title, resourceEdit(), this, this );
590 item = new DirListItem( title, resourceEdit(), this, this );
593 item = new FileItem( title, resourceEdit(), this, this );
603 QtxListResourceEdit::PrefItem::PrefItem( const int type, QtxResourceEdit* edit, Item* pi, QWidget* parent )
614 QtxListResourceEdit::PrefItem::~PrefItem()
619 \return preference item type
621 int QtxListResourceEdit::PrefItem::type() const
627 Doesn't create item, \return 0 by default
629 QtxResourceEdit::Item* QtxListResourceEdit::PrefItem::createItem( const QString&, const int )
637 QtxListResourceEdit::Spacer::Spacer( QtxResourceEdit* edit, Item* pItem, QWidget* parent )
638 : PrefItem( Space, edit, pItem, parent )
640 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
646 QtxListResourceEdit::Spacer::~Spacer()
651 Default empty implementation of resources storing
653 void QtxListResourceEdit::Spacer::store()
658 Default empty implementation of resources retrieving
660 void QtxListResourceEdit::Spacer::retrieve()
667 QtxListResourceEdit::SelectItem::SelectItem( const QString& title, QtxResourceEdit* edit,
668 Item* pItem, QWidget* parent )
669 : PrefItem( Selector, edit, pItem, parent )
671 new QLabel( title, this );
672 myList = new QComboBox( false, this );
673 myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
679 QtxListResourceEdit::SelectItem::~SelectItem()
684 Stores value to resource manager
686 void QtxListResourceEdit::SelectItem::store()
688 int idx = myList->currentItem();
689 if ( myIndex.contains( idx ) )
690 setInteger( myIndex[idx] );
694 Retrieve value to resource manager
696 void QtxListResourceEdit::SelectItem::retrieve()
698 int id = getInteger( -1 );
701 for ( QMap<int, int>::ConstIterator it = myIndex.begin(); it != myIndex.end() && idx == -1; ++it )
703 if ( it.data() == id )
707 myList->setCurrentItem( idx );
711 \return value of property
712 \param prop - property name
714 QVariant QtxListResourceEdit::SelectItem::property( const QString& name ) const
717 if ( name == QString( "strings" ) )
720 for ( int i = 0; i < (int)myList->count(); i++ )
721 lst.append( myList->text( i ) );
722 val = QVariant( lst );
724 else if ( name == QString( "indexes" ) )
726 QValueList<QVariant> lst;
727 for ( int i = 0; i < (int)myList->count(); i++ )
728 lst.append( myIndex.contains( i ) ? myIndex[i] : 0 );
729 val = QVariant( lst );
736 \param name - name of property
737 \param var - value of property
739 void QtxListResourceEdit::SelectItem::setProperty( const QString& name, const QVariant& val )
741 if ( name == QString( "strings" ) )
743 else if ( name == QString( "indexes" ) )
748 Sets property "strings" - items for selection in combo box
749 \param var - must be string list: list of items
751 void QtxListResourceEdit::SelectItem::setStrings( const QVariant& var )
753 if ( var.type() != QVariant::StringList )
756 setStrings( var.toStringList() );
760 Sets property "indexes" - corresponding indices of items in combo box
761 \param var - must be list of integer variants: list of indices
763 void QtxListResourceEdit::SelectItem::setIndexes( const QVariant& var )
765 if ( var.type() != QVariant::List )
768 QValueList<QVariant> varList = var.toList();
770 for ( QValueList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
772 if ( (*it).canCast( QVariant::Int ) )
773 lst.append( (*it).toInt() );
779 Sets property "strings" - items for selection in combo box
780 \param lst - list of items
782 void QtxListResourceEdit::SelectItem::setStrings( const QStringList& lst )
785 myList->insertStringList( lst );
789 Sets property "indexes" - corresponding indices of items in combo box
790 \param var - list of indices
792 void QtxListResourceEdit::SelectItem::setIndexes( const QValueList<int>& lst )
797 for ( QValueList<int>::const_iterator it = lst.begin(); it != lst.end(); ++it, idx++ )
798 myIndex.insert( idx, *it );
804 QtxListResourceEdit::StateItem::StateItem( const QString& title, QtxResourceEdit* edit,
805 Item* pItem, QWidget* parent )
806 : PrefItem( Bool, edit, pItem, parent )
808 myState = new QCheckBox( title, this );
809 myState->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
815 QtxListResourceEdit::StateItem::~StateItem()
820 Stores value to resource manager
822 void QtxListResourceEdit::StateItem::store()
824 setBoolean( myState->isChecked() );
828 Retrieve value to resource manager
830 void QtxListResourceEdit::StateItem::retrieve()
832 myState->setChecked( getBoolean() );
838 QtxListResourceEdit::StringItem::StringItem( const QString& title, QtxResourceEdit* edit,
839 Item* pItem, QWidget* parent )
840 : PrefItem( String, edit, pItem, parent )
842 new QLabel( title, this );
843 myString = new QLineEdit( this );
844 myString->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
850 QtxListResourceEdit::StringItem::~StringItem()
855 Stores value to resource manager
857 void QtxListResourceEdit::StringItem::store()
859 setString( myString->text() );
863 Retrieve value to resource manager
865 void QtxListResourceEdit::StringItem::retrieve()
867 myString->setText( getString() );
873 QtxListResourceEdit::IntegerEditItem::IntegerEditItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
874 : PrefItem( Integer, edit, pItem, parent )
876 new QLabel( title, this );
877 myInteger = new QLineEdit( this );
878 myInteger->setValidator( new QIntValidator( myInteger ) );
879 myInteger->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
885 QtxListResourceEdit::IntegerEditItem::~IntegerEditItem()
890 Stores value to resource manager
892 void QtxListResourceEdit::IntegerEditItem::store()
894 setString( myInteger->text() );
898 Retrieve value to resource manager
900 void QtxListResourceEdit::IntegerEditItem::retrieve()
902 myInteger->setText( getString() );
908 QtxListResourceEdit::IntegerSpinItem::IntegerSpinItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
909 : PrefItem( IntSpin, edit, pItem, parent )
911 new QLabel( title, this );
912 myInteger = new QtxIntSpinBox( this );
913 myInteger->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
919 QtxListResourceEdit::IntegerSpinItem::~IntegerSpinItem()
924 Stores value to resource manager
926 void QtxListResourceEdit::IntegerSpinItem::store()
928 setInteger( myInteger->value() );
932 Retrieve value to resource manager
934 void QtxListResourceEdit::IntegerSpinItem::retrieve()
936 myInteger->setValue( getInteger() );
940 \return value of property
941 \param prop - property name
943 QVariant QtxListResourceEdit::IntegerSpinItem::property( const QString& name ) const
946 if ( name == QString( "minimum" ) || name == QString( "min" ) )
947 var = QVariant( myInteger->minValue() );
948 else if ( name == QString( "maximum" ) || name == QString( "max" ) )
949 var = QVariant( myInteger->maxValue() );
950 else if ( name == QString( "step" ) )
951 var = QVariant( myInteger->lineStep() );
952 else if ( name == QString( "special" ) )
953 var = QVariant( myInteger->specialValueText() );
954 else if ( name == QString( "prefix" ) )
955 var = QVariant( myInteger->prefix() );
956 else if ( name == QString( "suffix" ) )
957 var = QVariant( myInteger->suffix() );
963 \param name - name of property
964 \param var - value of property
966 void QtxListResourceEdit::IntegerSpinItem::setProperty( const QString& name, const QVariant& var )
970 if ( ( name == QString( "minimum" ) || name == QString( "min" ) ) && prop.cast( QVariant::Int ) )
971 myInteger->setMinValue( prop.toInt() );
972 else if ( ( name == QString( "maximum" ) || name == QString( "max" ) ) && prop.cast( QVariant::Int ) )
973 myInteger->setMaxValue( prop.toInt() );
974 else if ( name == QString( "step" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 )
975 myInteger->setLineStep( prop.toInt() );
976 else if ( name == QString( "special" ) && prop.cast( QVariant::String ) )
977 myInteger->setSpecialValueText( prop.toString() );
978 else if ( name == QString( "prefix" ) && prop.cast( QVariant::String ) )
979 myInteger->setPrefix( prop.toString() );
980 else if ( name == QString( "suffix" ) && prop.cast( QVariant::String ) )
981 myInteger->setSuffix( prop.toString() );
987 QtxListResourceEdit::DoubleEditItem::DoubleEditItem( const QString& title, QtxResourceEdit* edit,
988 Item* pItem, QWidget* parent )
989 : PrefItem( Double, edit, pItem, parent )
991 new QLabel( title, this );
992 myDouble = new QLineEdit( this );
993 myDouble->setValidator( new QDoubleValidator( myDouble ) );
994 myDouble->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1000 QtxListResourceEdit::DoubleEditItem::~DoubleEditItem()
1005 Stores value to resource manager
1007 void QtxListResourceEdit::DoubleEditItem::store()
1009 setString( myDouble->text() );
1013 Retrieve value to resource manager
1015 void QtxListResourceEdit::DoubleEditItem::retrieve()
1017 myDouble->setText( getString() );
1023 QtxListResourceEdit::DoubleSpinItem::DoubleSpinItem( const QString& title, QtxResourceEdit* edit,
1024 Item* pItem, QWidget* parent )
1025 : PrefItem( DblSpin, edit, pItem, parent )
1027 new QLabel( title, this );
1028 myDouble = new QtxDblSpinBox( this );
1029 myDouble->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1035 QtxListResourceEdit::DoubleSpinItem::~DoubleSpinItem()
1040 Stores value to resource manager
1042 void QtxListResourceEdit::DoubleSpinItem::store()
1044 setDouble( myDouble->value() );
1048 Retrieve value to resource manager
1050 void QtxListResourceEdit::DoubleSpinItem::retrieve()
1052 myDouble->setValue( getDouble() );
1056 \return value of property
1057 \param prop - property name
1059 QVariant QtxListResourceEdit::DoubleSpinItem::property( const QString& name ) const
1062 if ( name == QString( "minimum" ) || name == QString( "min" ) )
1063 var = QVariant( myDouble->minValue() );
1064 else if ( name == QString( "maximum" ) || name == QString( "max" ) )
1065 var = QVariant( myDouble->maxValue() );
1066 else if ( name == QString( "precision" ) )
1067 var = QVariant( myDouble->precision() );
1068 else if ( name == QString( "step" ) )
1069 var = QVariant( myDouble->lineStep() );
1070 else if ( name == QString( "special" ) )
1071 var = QVariant( myDouble->specialValueText() );
1072 else if ( name == QString( "prefix" ) )
1073 var = QVariant( myDouble->prefix() );
1074 else if ( name == QString( "suffix" ) )
1075 var = QVariant( myDouble->suffix() );
1081 \param name - name of property
1082 \param var - value of property
1084 void QtxListResourceEdit::DoubleSpinItem::setProperty( const QString& name, const QVariant& var )
1086 QVariant prop = var;
1088 if ( ( name == QString( "minimum" ) || name == QString( "min" ) ) && prop.cast( QVariant::Double ) )
1089 myDouble->setMinValue( prop.toDouble() );
1090 else if ( ( name == QString( "maximum" ) || name == QString( "max" ) ) && prop.cast( QVariant::Double ) )
1091 myDouble->setMaxValue( prop.toDouble() );
1092 else if ( name == QString( "step" ) && prop.cast( QVariant::Double ) && prop.toDouble() > 0 )
1093 myDouble->setLineStep( prop.toDouble() );
1094 else if ( name == QString( "precision" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 )
1095 myDouble->setPrecision( prop.toInt() );
1096 else if ( name == QString( "special" ) && prop.cast( QVariant::String ) )
1097 myDouble->setSpecialValueText( prop.toString() );
1098 else if ( name == QString( "prefix" ) && prop.cast( QVariant::String ) )
1099 myDouble->setPrefix( prop.toString() );
1100 else if ( name == QString( "suffix" ) && prop.cast( QVariant::String ) )
1101 myDouble->setSuffix( prop.toString() );
1107 QtxListResourceEdit::ColorItem::ColorItem( const QString& title, QtxResourceEdit* edit,
1108 Item* pItem, QWidget* parent )
1109 : PrefItem( Color, edit, pItem, parent )
1112 \class QtxListResourceEdit::ColorItem::ColorSelector
1113 \brief Label, showing color and allowing to pick color with help of standard color dialog
1115 class ColorSelector : public QLabel
1118 ColorSelector( QWidget* parent = 0 ) : QLabel( parent )
1120 setFrameStyle( WinPanel | Raised );
1122 virtual ~ColorSelector() {}
1123 virtual QSize minimumSizeHint() const
1125 return QLabel::minimumSizeHint() + QSize( 0, 2 );
1129 virtual void mousePressEvent( QMouseEvent* e )
1131 if ( e->button() == LeftButton )
1133 setFrameStyle( WinPanel | Sunken );
1134 QColor c = QColorDialog::getColor( paletteBackgroundColor(), this );
1136 setPaletteBackgroundColor( c );
1138 setFrameStyle( WinPanel | Raised );
1143 new QLabel( title, this );
1144 myColor = new ColorSelector( this );
1145 myColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1151 QtxListResourceEdit::ColorItem::~ColorItem()
1156 Stores value to resource manager
1158 void QtxListResourceEdit::ColorItem::store()
1160 setColor( myColor->paletteBackgroundColor() );
1164 Retrieve value to resource manager
1166 void QtxListResourceEdit::ColorItem::retrieve()
1168 myColor->setPaletteBackgroundColor( getColor() );
1175 QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* edit,
1176 Item* pItem, QWidget* parent )
1177 : PrefItem( Font, edit, pItem, parent )
1179 new QLabel( title, this );
1180 myFamilies = new QtxComboBox( false, this );
1181 mySizes = new QtxComboBox( true, this );
1182 mySizes->setInsertionPolicy( QComboBox::NoInsertion );
1183 myBold = new QCheckBox( tr( "Bold" ), this );
1184 myItalic = new QCheckBox( tr( "Italic" ), this );
1185 myUnderline = new QCheckBox( tr( "Underline" ), this );
1186 myPreview = new QToolButton( this );
1187 myPreview->setText( "..." );
1189 myFamilies->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
1190 mySizes->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
1192 connect( myFamilies, SIGNAL( activated( int ) ), this, SLOT( onActivateFamily( int ) ) );
1193 connect( myPreview, SIGNAL( clicked() ), this, SLOT( onPreview() ) );
1195 setProperty( "system", ( bool )true );
1196 setProperty( "widget_flags", ( int )All );
1202 QtxListResourceEdit::FontItem::~FontItem()
1207 Stores value to resource manager
1209 void QtxListResourceEdit::FontItem::store()
1211 QFont f( family(), size() );
1212 bool bold, italic, underline;
1213 params( bold, italic, underline );
1215 f.setItalic( italic );
1216 f.setUnderline( underline );
1221 Retrieve value to resource manager
1223 void QtxListResourceEdit::FontItem::retrieve()
1225 QFont f = getFont();
1226 setFamily( f.family() );
1227 setSize( f.pointSize() );
1228 setParams( f.bold(), f.italic(), f.underline() );
1232 \return value of property
1233 \param prop - property name
1235 QVariant QtxListResourceEdit::FontItem::property( const QString& name ) const
1237 if( name=="system" )
1240 else if( name=="widget_flags" )
1241 return ( int )myFlags;
1245 if( name=="families" )
1248 return fdb.families();
1251 else if( name=="default_family" )
1254 QStringList fam = fdb.families();
1258 return QString::null;
1263 QStringList parts = QStringList::split( ":", name );
1264 if( parts.count()==2 )
1266 if( parts[1]=="default_bold" || parts[1]=="default_italic" || parts[1]=="default_underline" )
1269 else if( parts[1]=="sizes" )
1272 QValueList<int> sizes = fdb.pointSizes( parts[0] );
1273 QValueList<QVariant> vsizes;
1274 QValueList<int>::const_iterator anIt = sizes.begin(),
1275 aLast = sizes.end();
1276 for( ; anIt!=aLast; anIt++ )
1277 vsizes.append( *anIt );
1282 else if( parts[1]=="default_size" )
1284 if( parts[0].isEmpty() )
1288 QValueList<int> sizes = fdb.pointSizes( parts[0] );
1289 if( sizes.count()>0 )
1290 return sizes.first();
1298 else if( myProperties.contains( name ) )
1299 return myProperties[ name ];
1306 \param name - name of property
1307 \param var - value of property
1309 void QtxListResourceEdit::FontItem::setProperty( const QString& name, const QVariant& value )
1311 if( name=="system" )
1313 if( !value.canCast( QVariant::Bool ) )
1316 bool isSystem = value.toBool();
1317 if( myIsSystem==isSystem )
1320 myIsSystem = isSystem;
1322 QVariant families = property( "families" );
1323 QString fam = family();
1325 myFamilies->clear();
1326 if( families.canCast( QVariant::StringList ) )
1328 QStringList list = families.toStringList();
1329 myFamilies->insertStringList( list );
1333 setSize( -1 ); //set default size
1336 else if( name=="widget_flags" )
1338 if( !value.canCast( QVariant::Int ) )
1341 int wf = value.toInt();
1344 myFamilies ->setShown( wf & Family );
1345 mySizes ->setShown( wf & Size );
1346 mySizes->lineEdit()->setReadOnly( ( wf & UserSize )==0 );
1347 myBold ->setShown( wf & Bold );
1348 myItalic ->setShown( wf & Italic );
1349 myUnderline->setShown( wf & Underline );
1350 bool isSystem = property( "system" ).canCast( QVariant::Bool ) ? property( "system" ).toBool() : false;
1351 myPreview->setShown( ( wf & Preview ) && isSystem );
1357 myProperties[ name ] = value;
1362 \param f - new family
1364 void QtxListResourceEdit::FontItem::setFamily( const QString& f )
1367 if( myFamilies->isShown() )
1369 if( myFamilies->listBox()->findItem( f, Qt::ExactMatch ) )
1374 QVariant deffam = property( "default_family" );
1375 if( deffam.canCast( QVariant::String ) )
1376 curtext = deffam.toString();
1379 if ( curtext.isEmpty() )
1380 curtext = (QApplication::font()).family();
1383 for ( int i = 0; i < (int)myFamilies->count() && idx < 0; i++ )
1385 if ( myFamilies->text( i ) == curtext )
1390 myFamilies->setCurrentItem( idx );
1392 onActivateFamily( idx );
1396 \return family of font
1398 QString QtxListResourceEdit::FontItem::family() const
1400 return myFamilies->currentText();
1405 \param s - new size of font
1407 void QtxListResourceEdit::FontItem::setSize( const int s )
1410 if( mySizes->isShown() && s>0 )
1412 if( ( myFlags & UserSize ) || mySizes->listBox()->findItem( QString( "%1" ).arg( s ), Qt::ExactMatch ) )
1417 QVariant defsize = property( QString( "%1:default_size" ).arg( family() ) );
1418 if( defsize.canCast( QVariant::Int ) )
1419 cursize = defsize.toInt();
1422 mySizes->setCurrentText( cursize>0 ? QString( "%1" ).arg( cursize ) : "" );
1426 \return size of font
1428 int QtxListResourceEdit::FontItem::size() const
1430 QString s = mySizes->currentText();
1432 int pSize = s.toInt( &ok );
1433 return ( ok ? pSize : 0 );
1437 Sets font parameters
1438 \param bold - is font bold
1439 \param italic - is font italic
1440 \param underline - is font underlined
1442 void QtxListResourceEdit::FontItem::setParams( const bool bold, const bool italic, const bool underline )
1444 bool curbold = false, curitalic = false, curunderline = false;
1445 if( myBold->isShown() )
1449 QVariant def = property( QString( "%1:default_bold" ).arg( family() ) );
1450 if( def.canCast( QVariant::Bool ) )
1451 curbold = def.toBool();
1453 if( myItalic->isShown() )
1457 QVariant def = property( QString( "%1:default_italic" ).arg( family() ) );
1458 if( def.canCast( QVariant::Bool ) )
1459 curitalic = def.toBool();
1461 if( myUnderline->isShown() )
1462 curunderline = underline;
1465 QVariant def = property( QString( "%1:default_underline" ).arg( family() ) );
1466 if( def.canCast( QVariant::Bool ) )
1467 curunderline = def.toBool();
1469 myBold->setChecked( curbold );
1470 myItalic->setChecked( curitalic );
1471 myUnderline->setChecked( curunderline );
1475 \return font parameters
1476 \param bold - is font bold
1477 \param italic - is font italic
1478 \param underline - is font underlined
1480 void QtxListResourceEdit::FontItem::params( bool& bold, bool& italic, bool& underline )
1482 bold = myBold->isChecked();
1483 italic = myItalic->isChecked();
1484 underline = myUnderline->isChecked();
1488 Updates internal selection of font properties
1490 void QtxListResourceEdit::FontItem::internalUpdate()
1492 setFamily( family() );
1495 params( b1, b2, b3 );
1496 setParams( b1, b2, b3 );
1500 SLOT: called if family is activated, updates list of possible sizes
1502 void QtxListResourceEdit::FontItem::onActivateFamily( int )
1504 QVariant sizes = property( QString( "%1:sizes" ).arg( family() ) );
1508 if( sizes.canCast( QVariant::List ) )
1510 QValueList<QVariant> list = sizes.toList();
1511 QStringList sizeItems;
1512 QValueList<QVariant>::const_iterator anIt = list.begin(),
1514 for( ; anIt!=aLast; anIt++ )
1515 if( (*anIt).canCast( QVariant::Int ) && (*anIt).toInt()>0 )
1516 sizeItems.append( QString( "%1" ).arg( (*anIt).toInt() ) );
1517 mySizes->insertStringList( sizeItems );
1523 SLOT: called if it is necessary to show font preview
1525 void QtxListResourceEdit::FontItem::onPreview()
1527 QFont f( family(), size() );
1528 bool bold, italic, underline;
1529 params( bold, italic, underline );
1531 f.setItalic( italic );
1532 f.setUnderline( underline );
1535 f = QFontDialog::getFont( &ok, f );
1539 setFamily( f.family() );
1540 setSize( f.pointSize() );
1541 setParams( f.bold(), f.italic(), f.underline() );
1550 QtxListResourceEdit::DirListItem::DirListItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent )
1551 : PrefItem( Font, edit, pItem, parent )
1553 myDirListEditor = new QtxDirListEditor( this );
1559 QtxListResourceEdit::DirListItem::~DirListItem()
1564 Stores value to resource manager
1566 void QtxListResourceEdit::DirListItem::store()
1569 myDirListEditor->getPathList(list);
1570 setString( QString(list.join(";")) );
1574 Retrieve value to resource manager
1576 void QtxListResourceEdit::DirListItem::retrieve()
1578 myDirListEditor->setPathList(QStringList::split(";", getString()));
1586 QtxListResourceEdit::FileItem::FileItem( const QString& title, QtxResourceEdit* edit,
1587 Item* pItem, QWidget* parent )
1588 : PrefItem( Font, edit, pItem, parent ),
1589 myFlags( QFileInfo::ReadUser ),
1590 myIsExisting( true ),
1591 myIsReadOnly ( true ),
1594 new QLabel( title, this );
1595 myFile = new QLineEdit( this );
1596 myFile->setValidator( new FileValidator( this, myFile ) );
1597 myFile->setReadOnly( myIsReadOnly );
1598 myOpenFile = new QToolButton( this );
1599 myOpenFile->setText( "..." );
1600 connect( myOpenFile, SIGNAL( clicked() ), this, SLOT( onOpenFile() ) );
1606 QtxListResourceEdit::FileItem::~FileItem()
1613 Stores value to resource manager
1615 void QtxListResourceEdit::FileItem::store()
1617 setString( myFile->text() );
1621 Retrieve value to resource manager
1623 void QtxListResourceEdit::FileItem::retrieve()
1625 myFile->setText( getString() );
1629 \return value of property
1630 \param prop - property name
1632 QVariant QtxListResourceEdit::FileItem::property( const QString& name ) const
1634 if( name=="filter" )
1636 else if( name=="existing" )
1637 return myIsExisting;
1638 else if( name=="flags" )
1640 else if( name=="readOnly")
1641 return myIsReadOnly;
1648 \param name - name of property
1649 \param var - value of property
1651 void QtxListResourceEdit::FileItem::setProperty( const QString& name, const QVariant& value )
1653 if( name=="filter" )
1655 if( value.canCast( QVariant::String ) )
1658 myFilter.append( value.toString() );
1660 else if( value.canCast( QVariant::StringList ) )
1661 myFilter = value.toStringList();
1663 else if( name=="existing" && value.canCast( QVariant::Bool ) )
1664 myIsExisting = value.toBool();
1666 else if( name=="flags" && value.canCast( QVariant::UInt ) )
1667 myFlags = value.toUInt();
1669 else if( name=="readOnly" && value.canCast( QVariant::Bool) ) {
1670 myIsReadOnly = value.toBool();
1671 myFile->setReadOnly( myIsReadOnly );
1676 SLOT: called if user click "Open File" button, shows dialog
1678 void QtxListResourceEdit::FileItem::onOpenFile()
1682 myFileDlg = new QFileDialog( "." );
1683 connect( myFileDlg, SIGNAL( fileHighlighted( const QString& ) ), this, SLOT( onFileSelected( const QString& ) ) );
1686 myFileDlg->setCaption( title() );
1687 myFileDlg->setFilters( myFilter );
1688 myFileDlg->setMode( myIsExisting ? QFileDialog::ExistingFile : QFileDialog::AnyFile );
1690 if( myFileDlg->exec()==QDialog::Accepted )
1692 myFile->setText( myFileDlg->selectedFile() );
1697 \return true if file satisfies permissions
1698 \param f - file name
1700 bool QtxListResourceEdit::FileItem::isFileCorrect( const QString& f ) const
1703 QFileInfo info( f );
1704 if( !myIsExisting || info.exists() )
1705 res = info.isFile() && info.permission( myFlags );
1711 SLOT: called if user has selected file in file dialog, checks file permissions and passes it's name to widget
1712 \param f - file name
1714 void QtxListResourceEdit::FileItem::onFileSelected( const QString& f )
1716 if( myFileDlg && !isFileCorrect( f ) )
1717 myFileDlg->setSelection( "" );
1724 QtxListResourceEdit::FileItem::FileValidator::FileValidator( FileItem* item, QObject* parent )
1725 : QValidator( parent ),
1733 QtxListResourceEdit::FileItem::FileValidator::~FileValidator()
1738 Check file permissions
1739 \param f - file name
1741 QValidator::State QtxListResourceEdit::FileItem::FileValidator::validate( QString& f, int& ) const
1743 if( myItem && myItem->isFileCorrect( f ) )
1744 return QValidator::Acceptable;
1746 return QValidator::Intermediate;