From e33df864468a8be443d99cf78a21fda62da2da34 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 19 Sep 2008 05:18:30 +0000 Subject: [PATCH] Merge from BR_QT4_Dev --- src/Qtx/QtxMRUAction.cxx | 194 ++++++++++++-- src/Qtx/QtxMRUAction.h | 21 ++ src/Qtx/QtxPagePrefMgr.cxx | 481 +++++++++++++++++++++++++++++------ src/Qtx/QtxPagePrefMgr.h | 46 +++- src/Qtx/QtxPreferenceMgr.cxx | 104 ++------ src/Qtx/QtxPreferenceMgr.h | 26 +- 6 files changed, 665 insertions(+), 207 deletions(-) diff --git a/src/Qtx/QtxMRUAction.cxx b/src/Qtx/QtxMRUAction.cxx index 6f1b81844..5ee95779f 100755 --- a/src/Qtx/QtxMRUAction.cxx +++ b/src/Qtx/QtxMRUAction.cxx @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -36,12 +36,19 @@ \param parent parent object */ QtxMRUAction::QtxMRUAction( QObject* parent ) -: QtxAction( "Most Recently Used", "Most Recently Used", 0, parent ), +: QtxAction( tr( "Most Recently Used" ), tr( "Most Recently Used" ), 0, parent ), myVisCount( 5 ), + myHistoryCount( -1 ), + myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { + myClear = new QAction( tr( "Clear" ), this ); + myClear->setVisible( false ); + setMenu( new QMenu( 0 ) ); + connect( menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); + connect( myClear, SIGNAL( triggered( bool ) ), this, SLOT( onCleared( bool ) ) ); } /*! @@ -53,10 +60,16 @@ QtxMRUAction::QtxMRUAction( QObject* parent ) QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObject* parent ) : QtxAction( text, menuText, 0, parent ), myVisCount( 5 ), + myHistoryCount( -1 ), + myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { + myClear = new QAction( tr( "Clear" ), this ); + myClear->setVisible( false ); + setMenu( new QMenu( 0 ) ); connect( menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); + connect( myClear, SIGNAL( triggered( bool ) ), this, SLOT( onCleared( bool ) ) ); } /*! @@ -69,11 +82,17 @@ QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObjec QtxMRUAction::QtxMRUAction( const QString& text, const QIcon& icon, const QString& menuText, QObject* parent ) : QtxAction( text, icon, menuText, 0, parent ), -myVisCount( 5 ), -myInsertMode( MoveFirst ) + myVisCount( 5 ), + myHistoryCount( -1 ), + myLinkType( LinkAuto ), + myInsertMode( MoveFirst ) { + myClear = new QAction( tr( "Clear" ), this ); + myClear->setVisible( false ); + setMenu( new QMenu( 0 ) ); connect( menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); + connect( myClear, SIGNAL( triggered( bool ) ), this, SLOT( onCleared( bool ) ) ); } /*! @@ -102,6 +121,24 @@ void QtxMRUAction::setInsertMode( const int mode ) myInsertMode = mode; } +/*! + \brief Get the type of link menu name. + \return link type (QtxMRUAction::LinkType) +*/ +int QtxMRUAction::linkType() const +{ + return myLinkType; +} + +/*! + \brief Set the type of link menu name. + \param link type (QtxMRUAction::LinkType) +*/ +void QtxMRUAction::setLinkType( const int type ) +{ + myLinkType = type; +} + /*! \brief Get number of MRU items. \return number of MRU items @@ -132,7 +169,7 @@ int QtxMRUAction::visibleCount() const /*! \brief Set number of visible MRU items. - + This method sets the maximum number of MRU items to be displayed in the popup menu (5 by default). @@ -148,6 +185,48 @@ void QtxMRUAction::setVisibleCount( int num ) myVisCount = num; } +/*! + \brief Return visible status of the menu item which clear all MRU items. +*/ +bool QtxMRUAction::isClearPossible() const +{ + return myClear->isVisible(); +} + +/*! + \brief Set visible the menu item which clear all MRU items. +*/ +void QtxMRUAction::setClearPossible( const bool on ) +{ + myClear->setVisible( on ); +} + +/*! + \brief Get number of totally stored MRU items. + \return number of MRU items stored in the preferences + \sa setHistoryCount(), saveLinks(), loadLinks() +*/ +int QtxMRUAction::historyCount() const +{ + return myHistoryCount; +} + +/*! + \brief Set number of totally stored MRU items. + + This option allows setting number of MRU items to be stored + in the preferences file. + + If \a num < 0, then number of stored MRU items is not limited. + + \return number of MRU items stored in the preferences + \sa historyCount(), saveLinks(), loadLinks() +*/ +void QtxMRUAction::setHistoryCount( const int num ) +{ + myHistoryCount = num; +} + /*! \brief Insert MRU item. @@ -202,6 +281,14 @@ void QtxMRUAction::remove( const QString& link ) myLinks.removeAll( link ); } +/*! + \brief Remove all MRU items. +*/ +void QtxMRUAction::clear() +{ + myLinks.clear(); +} + /*! \brief Get MRU item \param idx MRU item index @@ -261,7 +348,7 @@ void QtxMRUAction::loadLinks( QtxResourceMgr* resMgr, const QString& section, co if ( !(*it).startsWith( itemPrefix ) ) continue; - QString link = resMgr->stringValue( section, *it, QString::null ); + QString link = resMgr->stringValue( section, *it, QString() ); if ( link.isEmpty() || map.contains( link ) ) continue; @@ -281,8 +368,16 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co if ( !resMgr || section.isEmpty() ) return; - if ( clear ) - resMgr->remove( section ); + QString itemPrefix( "item_" ); + + if ( clear ) { + QStringList items = resMgr->parameters( section ); + for ( QStringList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + if ( (*it).startsWith( itemPrefix ) ) + resMgr->remove( section, *it ); + } + } QStringList lst; QMap map; @@ -292,14 +387,13 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co map.insert( *itr, 0 ); } - QString itemPrefix( "item_" ); QStringList items = resMgr->parameters( section ); for ( QStringList::const_iterator it = items.begin(); it != items.end(); ++it ) { if ( !(*it).startsWith( itemPrefix ) ) continue; - QString link = resMgr->stringValue( section, *it, QString::null ); + QString link = resMgr->stringValue( section, *it, QString() ); if ( !link.isEmpty() && !map.contains( link ) ) { lst.append( link ); @@ -310,13 +404,15 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co } int counter = 0; - for ( QStringList::const_iterator iter = lst.begin(); iter != lst.end(); ++iter, counter++ ) + for ( QStringList::const_iterator iter = lst.begin(); + iter != lst.end() && ( myHistoryCount < 0 || counter < myHistoryCount ); + ++iter, counter++ ) resMgr->setValue( section, itemPrefix + QString().sprintf( "%03d", counter ), *iter ); } /*! \brief Prepare MRU items popup menu. - + This method is called when the parent menu is shown. Enables or disables sub menu item according to the number of MRU items. */ @@ -336,11 +432,16 @@ void QtxMRUAction::onActivated() if ( !a ) return; - QString link = a->text(); + QString link = a->data().toString(); if ( !link.isEmpty() && myLinks.contains( link ) ) emit activated( link ); } +void QtxMRUAction::onCleared( bool ) +{ + clear(); +} + /*! \brief Update MRU items popup menu. */ @@ -352,9 +453,58 @@ void QtxMRUAction::updateMenu() pm->clear(); + QStringList links; + QMap map; int count = visibleCount() < 0 ? myLinks.count() : visibleCount(); - for ( QStringList::const_iterator it = myLinks.begin(); it != myLinks.end() && count > 0; ++it, count-- ) - pm->addAction( *it, this, SLOT( onActivated() ) ); + int i = insertMode() == AddLast || insertMode() == MoveLast ? qMax( 0, myLinks.count()-count ) : 0; + for ( ; i < myLinks.count() && count > 0; ++i, count-- ) + { + links.append( myLinks[i] ); + if ( linkType() == LinkAuto ) + { + QString shortName = Qtx::file( myLinks[i] ); + if ( map.contains( shortName ) ) + map[shortName]++; + else + map.insert( shortName, 0 ); + } + } + + i = 1; + for ( QStringList::const_iterator it = links.begin(); it != links.end(); ++it, i++ ) + { + QString linkName; + switch( linkType() ) + { + case LinkAuto: + linkName = Qtx::file( *it ); + if ( map.contains( linkName ) && map[linkName] ) + linkName = *it; + break; + case LinkShort: + linkName = Qtx::file( *it ); + break; + case LinkFull: + default: + linkName = *it; + break; + } + + if ( links.count() < 10 ) + linkName = QString( "&%1 %2" ).arg( i ).arg( linkName ); + + pm->addAction( linkName, this, SLOT( onActivated() ) )->setData( *it ); + } + + if ( pm->isEmpty() ) + pm->addAction( tr( "" ) )->setEnabled( false ); + + if ( isClearPossible() ) + { + pm->addSeparator(); + pm->addAction( myClear ); + myClear->setEnabled( !pm->isEmpty() ); + } } /*! diff --git a/src/Qtx/QtxMRUAction.h b/src/Qtx/QtxMRUAction.h index f8a5dd9b0..f07f4fc46 100755 --- a/src/Qtx/QtxMRUAction.h +++ b/src/Qtx/QtxMRUAction.h @@ -44,6 +44,11 @@ public: AddLast //!< if specified item doesn't exist, add it to the end } InsertionMode; + typedef enum { LinkAuto, //!< put the full path of link into the menu if link file names of severals link are same + LinkShort, //!< put the only file name of link into the menu + LinkFull //!< put the full path of link into the menu + } LinkType; + public: QtxMRUAction( QObject* = 0 ); QtxMRUAction( const QString&, const QString&, QObject* = 0 ); @@ -53,12 +58,21 @@ public: int insertMode() const; void setInsertMode( const int ); + int linkType() const; + void setLinkType( const int ); + int count() const; bool isEmpty() const; int visibleCount() const; void setVisibleCount( const int ); + bool isClearPossible() const; + void setClearPossible( const bool ); + + int historyCount() const; + void setHistoryCount( const int ); + void remove( const int ); void remove( const QString& ); void insert( const QString& ); @@ -70,19 +84,26 @@ public: virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true ); virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const; +public slots: + void clear(); + signals: void activated( const QString& ); private slots: void onActivated(); void onAboutToShow(); + void onCleared( bool ); private: void updateMenu(); private: QStringList myLinks; //!< most recent used items + QAction* myClear; //!< clear item int myVisCount; //!< number of visible MRU items + int myHistoryCount; //!< number of stored MRU items + int myLinkType; //!< type of link names in menu int myInsertMode; //!< items insertion policy }; diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 5697e4415..27701557e 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -58,7 +59,7 @@ QtxPagePrefMgr::QtxPagePrefMgr( QtxResourceMgr* resMgr, QWidget* parent ) { myBox = new QtxGridBox( 1, Qt::Horizontal, this, 0 ); QVBoxLayout* base = new QVBoxLayout( this ); - base->setMargin( 0 ); + base->setMargin( 5 ); base->setSpacing( 0 ); base->addWidget( myBox ); } @@ -76,8 +77,6 @@ QtxPagePrefMgr::~QtxPagePrefMgr() */ QSize QtxPagePrefMgr::sizeHint() const { - initialize(); - return QFrame::sizeHint(); } @@ -87,20 +86,20 @@ QSize QtxPagePrefMgr::sizeHint() const */ QSize QtxPagePrefMgr::minimumSizeHint() const { - initialize(); - return QFrame::minimumSizeHint(); } /*! \brief Customize show/hide widget operation. - \param on if \c true the widget is being shown, otherswise + \param on if \c true the widget is being shown, otherswise it is being hidden */ void QtxPagePrefMgr::setVisible( bool on ) { - if ( on && !myInit ) - updateContents(); + if ( on ) + initialize(); + + QApplication::instance()->processEvents(); QFrame::setVisible( on ); } @@ -115,12 +114,9 @@ void QtxPagePrefMgr::updateContents() QList lst = childItems(); for ( QList::const_iterator it = lst.begin(); it != lst.end(); ++it ) { - if ( (*it)->rtti() == QtxPagePrefItem::RTTI() ) - { - QtxPagePrefItem* item = (QtxPagePrefItem*)(*it); - if ( item->widget() && item->widget()->parent() != myBox ) - item->widget()->setParent( myBox ); - } + QtxPagePrefItem* item = dynamic_cast( *it ); + if ( item && item->widget() && item->widget()->parent() != myBox ) + item->widget()->setParent( myBox ); } setWindowIcon( icon() ); @@ -195,18 +191,25 @@ void QtxPagePrefMgr::setOptionValue( const QString& name, const QVariant& val ) */ void QtxPagePrefMgr::initialize() const { - if ( myInit ) - return; + // if ( myInit ) + // return; QtxPagePrefMgr* that = (QtxPagePrefMgr*)this; - - that->updateContents(); + that->initialize( that ); + + // that->myInit = true; +} + +void QtxPagePrefMgr::initialize( QtxPreferenceItem* item ) +{ + if ( !item ) + return; - QList lst = childItems( true ); + QList lst = item->childItems( false ); for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) - (*it)->updateContents(); + initialize( *it ); - that->myInit = true; + updateContents(); } /*! @@ -215,6 +218,41 @@ void QtxPagePrefMgr::initialize() const preference items. */ +class QtxPagePrefItem::Listener : public QObject +{ +public: + Listener( QtxPagePrefItem* ); + virtual ~Listener(); + + virtual bool eventFilter( QObject*, QEvent* ); + +private: + QtxPagePrefItem* myItem; +}; + +QtxPagePrefItem::Listener::Listener( QtxPagePrefItem* item ) +: QObject( 0 ), + myItem( item ) +{ +} + +QtxPagePrefItem::Listener::~Listener() +{ +} + +bool QtxPagePrefItem::Listener::eventFilter( QObject* o, QEvent* e ) +{ + if ( !myItem || myItem->widget() != o ) + return false; + + if ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) + myItem->widgetShown(); + if ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) + myItem->widgetHided(); + + return false; +} + /*! \brief Constructor. \param title preference item title @@ -225,7 +263,8 @@ void QtxPagePrefMgr::initialize() const QtxPagePrefItem::QtxPagePrefItem( const QString& title, QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPreferenceItem( title, sect, param, parent ), - myWidget( 0 ) + myWidget( 0 ), + myListener( 0 ) { } @@ -235,15 +274,7 @@ QtxPagePrefItem::QtxPagePrefItem( const QString& title, QtxPreferenceItem* paren QtxPagePrefItem::~QtxPagePrefItem() { delete myWidget; -} - -/*! - \brief Get unique item type identifier. - \return item type ID -*/ -int QtxPagePrefItem::rtti() const -{ - return QtxPagePrefItem::RTTI(); + delete myListener; } /*! @@ -256,15 +287,6 @@ QWidget* QtxPagePrefItem::widget() const return myWidget; } -/*! - \brief Specify unique item class identifier. - \return item class ID -*/ -int QtxPagePrefItem::RTTI() -{ - return 1000; -} - /*! \brief Set preference item editor widget. \param wid editor widget @@ -272,7 +294,18 @@ int QtxPagePrefItem::RTTI() */ void QtxPagePrefItem::setWidget( QWidget* wid ) { + if ( myWidget && myListener ) + myWidget->removeEventFilter( myListener ); + myWidget = wid; + + if ( myWidget ) + { + if ( !myListener ) + myListener = new Listener( this ); + myWidget->installEventFilter( myListener ); + } + sendItemChanges(); } @@ -311,7 +344,7 @@ void QtxPagePrefItem::itemChanged( QtxPreferenceItem* /*item*/ ) /*! \brief Store preference item to the resource manager. - + This method should be reimplemented in the subclasses. Base implementation does nothing. @@ -323,7 +356,7 @@ void QtxPagePrefItem::store() /*! \brief Retrieve preference item from the resource manager. - + This method should be reimplemented in the subclasses. Base implementation does nothing. @@ -333,6 +366,29 @@ void QtxPagePrefItem::retrieve() { } +/*! + \brief Invoked when preference item widget is shown. +*/ +void QtxPagePrefItem::widgetShown() +{ +} + +/*! + \brief Invoked when preference item widget is hided. +*/ +void QtxPagePrefItem::widgetHided() +{ +} + +void QtxPagePrefItem::ensureVisible( QtxPreferenceItem* i ) +{ + QtxPreferenceItem::ensureVisible(); + + QtxPagePrefItem* item = dynamic_cast( i ); + if ( item && item->widget() ) + item->widget()->setVisible( true ); +} + /*! \brief Find all child items of the QtxPagePrefItem type. \param list used to return list of child items @@ -343,14 +399,15 @@ void QtxPagePrefItem::pageChildItems( QList& list, const bool QList lst = childItems( rec ); for ( QList::const_iterator it = lst.begin(); it != lst.end(); ++it ) { - if ( (*it)->rtti() == QtxPagePrefItem::RTTI() ) - list.append( (QtxPagePrefItem*)*it ); + QtxPagePrefItem* item = dynamic_cast( *it ); + if ( item ) + list.append( item ); } } /*! \brief Called when contents is changed (item is added, removed or modified). - + Triggers the item update. */ void QtxPagePrefItem::contentChanged() @@ -377,12 +434,19 @@ QtxPageNamedPrefItem::QtxPageNamedPrefItem( const QString& title, QtxPreferenceI myControl( 0 ) { QWidget* main = new QWidget(); - QHBoxLayout* base = new QHBoxLayout( main ); - base->setMargin( 0 ); - base->setSpacing( 5 ); - myLabel = new QLabel( title, main ); - base->addWidget( myLabel ); + // QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast(parent); + // if ( !aGroup ) + // { + QHBoxLayout* base = new QHBoxLayout( main ); + base->setMargin( 0 ); + base->setSpacing( 5 ); + + myLabel = new QLabel( title, main ); + base->addWidget( myLabel ); + // } + // else + // myLabel = new QLabel( title, aGroup->gridBox() ); setWidget( main ); @@ -442,7 +506,43 @@ void QtxPageNamedPrefItem::setControl( QWidget* wid ) myControl = wid; if ( myControl ) - widget()->layout()->addWidget( myControl ); + { + // QtxPagePrefGroupItem* aGroup = 0;//dynamic_cast(parentItem()); + // if ( !aGroup ) + widget()->layout()->addWidget( myControl ); + // else myControl->setParent( aGroup->gridBox() ); + } +} + +void QtxPageNamedPrefItem::adjustLabels( QtxPagePrefItem* parent ) +{ + if ( !parent ) + return; + + QList childList = parent->childItems(); + + QList namedItems; + for ( QList::iterator it = childList.begin(); it != childList.end(); ++it ) + { + QtxPageNamedPrefItem* item = dynamic_cast( *it ); + if ( item ) + namedItems.append( item ); + } + + int sz = 0; + for ( QList::iterator it1 = namedItems.begin(); it1 != namedItems.end(); ++it1 ) + { + QtxPageNamedPrefItem* item = *it1; + if ( item->label() ) + sz = qMax( sz, item->label()->sizeHint().width() ); + } + + for ( QList::iterator it2 = namedItems.begin(); it2 != namedItems.end(); ++it2 ) + { + QtxPageNamedPrefItem* item = *it2; + if ( item->label() ) + item->label()->setMinimumWidth( sz ); + } } /*! @@ -540,6 +640,7 @@ void QtxPagePrefListItem::setFixedSize( const bool on ) */ void QtxPagePrefListItem::updateContents() { + QtxPagePrefItem::updateContents(); updateVisible(); } @@ -581,6 +682,22 @@ void QtxPagePrefListItem::setOptionValue( const QString& name, const QVariant& v QtxPagePrefItem::setOptionValue( name, val ); } +void QtxPagePrefListItem::widgetShown() +{ + updateState(); +} + +void QtxPagePrefListItem::ensureVisible( QtxPreferenceItem* i ) +{ + if ( !i ) + return; + + QtxPreferenceItem::ensureVisible( i ); + + setSelected( i->id() ); + updateState(); +} + /*! \brief Called when the selection in the list box is changed. */ @@ -756,8 +873,16 @@ void QtxPagePrefListItem::setSelected( const int id ) /*! \class QtxPagePrefToolBoxItem + \brief GUI implementation of the tool box container preference item. */ +/*! + \brief Constructor. + \param title preference item title + \param parent parent preference item + \param sect resource file section associated with the preference item + \param param resource file parameter associated with the preference item +*/ QtxPagePrefToolBoxItem::QtxPagePrefToolBoxItem( const QString& title, QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPagePrefItem( title, parent, sect, param ) @@ -765,15 +890,25 @@ QtxPagePrefToolBoxItem::QtxPagePrefToolBoxItem( const QString& title, QtxPrefere setWidget( myToolBox = new QToolBox( 0 ) ); } +/*! + \brief Destructor. +*/ QtxPagePrefToolBoxItem::~QtxPagePrefToolBoxItem() { } +/*! + \brief Update widget contents. +*/ void QtxPagePrefToolBoxItem::updateContents() { + QtxPagePrefItem::updateContents(); updateToolBox(); } +/*! + \brief Update tool box widget. +*/ void QtxPagePrefToolBoxItem::updateToolBox() { QList items; @@ -820,6 +955,18 @@ void QtxPagePrefToolBoxItem::updateToolBox() myToolBox->setCurrentWidget( cur ); } +void QtxPagePrefToolBoxItem::ensureVisible( QtxPreferenceItem* i ) +{ + if ( !i ) + return; + + QtxPreferenceItem::ensureVisible( i ); + + QtxPagePrefItem* item = dynamic_cast( i ); + if ( item && item->widget() ) + myToolBox->setCurrentWidget( item->widget() ); +} + /*! \class QtxPagePrefTabsItem \brief GUI implementation of the tab widget container. @@ -851,6 +998,7 @@ QtxPagePrefTabsItem::~QtxPagePrefTabsItem() */ void QtxPagePrefTabsItem::updateContents() { + QtxPagePrefItem::updateContents(); updateTabs(); } @@ -959,6 +1107,18 @@ void QtxPagePrefTabsItem::setOptionValue( const QString& name, const QVariant& v QtxPagePrefItem::setOptionValue( name, val ); } +void QtxPagePrefTabsItem::ensureVisible( QtxPreferenceItem* i ) +{ + if ( !i ) + return; + + QtxPreferenceItem::ensureVisible( i ); + + QtxPagePrefItem* item = dynamic_cast( i ); + if ( item && item->widget() ) + myTabs->setCurrentWidget( item->widget() ); +} + /*! \brief Update tabs. */ @@ -1047,7 +1207,11 @@ QtxPagePrefFrameItem::~QtxPagePrefFrameItem() */ void QtxPagePrefFrameItem::updateContents() { + QtxPagePrefItem::updateContents(); + updateFrame(); + + QtxPageNamedPrefItem::adjustLabels( this ); } /*! @@ -1130,6 +1294,11 @@ void QtxPagePrefFrameItem::setOrientation( const Qt::Orientation o ) myBox->setOrientation( o ); } +/*! + \brief Check if the frame widget stretching is enabled. + \return \c true if the widget is stretchable + \sa setStretch() +*/ bool QtxPagePrefFrameItem::stretch() const { QSpacerItem* s = 0; @@ -1137,9 +1306,14 @@ bool QtxPagePrefFrameItem::stretch() const for ( int i = 0; l && i < l->count() && !s; i++ ) s = l->itemAt( i )->spacerItem(); - return s ? ( s->expandingDirections() & Qt::Vertical ) != 0 : false; + return s ? (bool)( s->expandingDirections() & Qt::Vertical ) : false; } +/*! + \brief Enable/disable frame widget stretching. + \param on new stretchable state + \sa stretch() +*/ void QtxPagePrefFrameItem::setStretch( const bool on ) { QSpacerItem* s = 0; @@ -1210,6 +1384,13 @@ void QtxPagePrefFrameItem::setOptionValue( const QString& name, const QVariant& QtxPagePrefItem::setOptionValue( name, val ); } +void QtxPagePrefFrameItem::widgetShown() +{ + QtxPagePrefItem::widgetShown(); + + QtxPageNamedPrefItem::adjustLabels( this ); +} + /*! \brief Update frame widget. */ @@ -1250,6 +1431,8 @@ QtxPagePrefGroupItem::QtxPagePrefGroupItem( const QString& title, QtxPreferenceI myGroup->setWidget( myBox ); setWidget( myGroup ); + + updateState(); } /*! @@ -1269,6 +1452,8 @@ QtxPagePrefGroupItem::QtxPagePrefGroupItem( const int cols, const QString& title myGroup->setWidget( myBox ); setWidget( myGroup ); + + updateState(); } /*! @@ -1295,10 +1480,14 @@ void QtxPagePrefGroupItem::setResource( const QString& sect, const QString& para */ void QtxPagePrefGroupItem::updateContents() { + QtxPagePrefItem::updateContents(); + myGroup->setTitle( title() ); updateState(); updateGroup(); + + QtxPageNamedPrefItem::adjustLabels( this ); } /*! @@ -1409,6 +1598,14 @@ void QtxPagePrefGroupItem::store() setBoolean( myGroup->isChecked() ); } +/*! + \brief Return widget contained grid layout of this group. +*/ +QtxGridBox* QtxPagePrefGroupItem::gridBox() const +{ + return myBox; +} + /*! \brief Retrieve preference item from the resource manager. \sa store() @@ -1478,6 +1675,13 @@ void QtxPagePrefGroupItem::setOptionValue( const QString& name, const QVariant& QtxPagePrefItem::setOptionValue( name, val ); } +void QtxPagePrefGroupItem::widgetShown() +{ + QtxPagePrefItem::widgetShown(); + + QtxPageNamedPrefItem::adjustLabels( this ); +} + /*! \brief Update widget state. */ @@ -1516,7 +1720,7 @@ void QtxPagePrefGroupItem::updateGroup() /*! \brief Constructor. - Creates spacer item with zero width and height and expanding + Creates spacer item with zero width and height and expanding on both directions (by height and width). \param parent parent preference item @@ -1530,7 +1734,7 @@ QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( QtxPreferenceItem* parent ) /*! \brief Constructor. - Creates spacer item with zero width and height and expanding + Creates spacer item with zero width and height and expanding according to the specified orientation. \param o spacer orientation @@ -1625,7 +1829,7 @@ void QtxPagePrefSpaceItem::setStretch( Qt::Orientation o, const int sf ) sp.setVerticalStretch( sf ); sp.setVerticalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); } - + widget()->setSizePolicy( sp ); } @@ -1693,7 +1897,7 @@ void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, c QSizePolicy sp; sp.setHorizontalPolicy( hs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); sp.setVerticalPolicy( vs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); - + sp.setHorizontalStretch( hs ); sp.setVerticalStretch( vs ); @@ -1701,7 +1905,7 @@ void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, c wid->setSizePolicy( sp ); wid->setMinimumSize( w, h ); - + setWidget( wid ); } @@ -1744,7 +1948,7 @@ void QtxPagePrefCheckItem::setTitle( const QString& txt ) myCheck->setText( title() ); } - + /*! \brief Store preference item to the resource manager. \sa retrieve() @@ -1801,7 +2005,7 @@ QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceIte \param param resource file parameter associated with the preference item */ QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title, - QtxPreferenceItem* parent, const QString& sect, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ), myType( type ) @@ -1929,7 +2133,7 @@ void QtxPagePrefEditItem::updateEditor() /*! \class QtxPagePrefSelectItem - \brief GUI implementation of the resources selector item + \brief GUI implementation of the resources selector item (string, integer or double values list). All items in the list (represented as combo box) should be specified @@ -1939,7 +2143,7 @@ void QtxPagePrefEditItem::updateEditor() /*! \brief Constructor. - + Creates preference item with combo box widget which is not editable (direct value entering is disabled). @@ -1961,7 +2165,7 @@ QtxPagePrefSelectItem::QtxPagePrefSelectItem( const QString& title, QtxPreferenc /*! \brief Constructor. - + Creates preference item with combo box widget which is editable according to the specified input type (integer, double or string values). @@ -2020,7 +2224,7 @@ void QtxPagePrefSelectItem::setInputType( const int type ) QStringList QtxPagePrefSelectItem::strings() const { QStringList res; - for ( int i = 0; i < mySelector->count(); i++ ) + for ( uint i = 0; i < mySelector->count(); i++ ) res.append( mySelector->itemText( i ) ); return res; } @@ -2033,7 +2237,7 @@ QStringList QtxPagePrefSelectItem::strings() const QList QtxPagePrefSelectItem::numbers() const { QList res; - for ( int i = 0; i < mySelector->count(); i++ ) + for ( uint i = 0; i < mySelector->count(); i++ ) { if ( mySelector->hasId( i ) ) res.append( mySelector->id( i ) ); @@ -2059,7 +2263,7 @@ void QtxPagePrefSelectItem::setStrings( const QStringList& lst ) */ void QtxPagePrefSelectItem::setNumbers( const QList& ids ) { - int i = 0; + uint i = 0; for ( QList::const_iterator it = ids.begin(); it != ids.end() && i < mySelector->count(); ++it, i++ ) mySelector->setId( i, *it ); } @@ -2097,7 +2301,7 @@ void QtxPagePrefSelectItem::retrieve() idx = mySelector->index( num ); else { - for ( int i = 0; i < mySelector->count() && idx == -1; i++ ) + for ( uint i = 0; i < mySelector->count() && idx == -1; i++ ) { if ( mySelector->itemText( i ) == txt ) idx = i; @@ -2268,7 +2472,7 @@ QtxPagePrefSpinItem::QtxPagePrefSpinItem( const QString& title, QtxPreferenceIte \param param resource file parameter associated with the preference item */ QtxPagePrefSpinItem::QtxPagePrefSpinItem( const int type, const QString& title, - QtxPreferenceItem* parent, const QString& sect, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ), myType( type ) @@ -2383,7 +2587,7 @@ QString QtxPagePrefSpinItem::suffix() const } /*! - \brief Get spin box preference item special value text (which is shown + \brief Get spin box preference item special value text (which is shown when the spin box reaches minimum value). \return spin box special value text \sa setSpecialValueText() @@ -2481,7 +2685,7 @@ void QtxPagePrefSpinItem::setSuffix( const QString& txt ) } /*! - \brief Set spin box preference item special value text (which is shown + \brief Set spin box preference item special value text (which is shown when the spin box reaches minimum value). \param txt new spin box special value text \sa specialValueText() @@ -2638,7 +2842,7 @@ void QtxPagePrefSpinItem::updateSpinBox() \param sect resource file section associated with the preference item \param param resource file parameter associated with the preference item */ -QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect, +QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( QString(), parent, sect, param ) { @@ -2706,7 +2910,10 @@ QtxPagePrefColorItem::QtxPagePrefColorItem( const QString& title, QtxPreferenceI const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ) { - setControl( myColor = new QtxColorButton() ); + // QtxPagePrefGroupItem* aGroup 0; //= dynamic_cast( parent ); + + // setControl( myColor = new QtxColorButton( aGroup ? aGroup->gridBox() : 0 ) ); + setControl( myColor = new QtxColorButton( 0 ) ); myColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); } @@ -2749,7 +2956,7 @@ void QtxPagePrefColorItem::retrieve() \param param resource file parameter associated with the preference item */ QtxPagePrefFontItem::QtxPagePrefFontItem( const int feat, const QString& title, - QtxPreferenceItem* parent, const QString& sect, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ) { @@ -2984,8 +3191,8 @@ void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& v } /*! - \class QtxPagePrefPathListItem - \brief GUI implementation of resources directory list item. + \class QtxPagePrefPathListItem + \brief GUI implementation of the resources files/directories list item. */ /*! @@ -3111,10 +3318,20 @@ void QtxPagePrefPathListItem::setOptionValue( const QString& name, const QVarian \brief GUI implementation of resources date/time item. */ +/*! + \brief Constructor. + + Creates an item to enter date and time. + + \param title preference item title + \param parent parent preference item + \param sect resource file section associated with the preference item + \param param resource file parameter associated with the preference item +*/ QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const QString& title, QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ), -myType( DateTime ) + myType( DateTime ) { setControl( myDateTime = new QDateTimeEdit() ); myDateTime->setCalendarPopup( true ); @@ -3122,10 +3339,22 @@ myType( DateTime ) updateDateTime(); } +/*! + \brief Constructor. + + Creates preference item for editing of the date and/or time value: + the type is specified by parameter \a type. + + \param type preference item input type (QtxPagePrefDateTimeItem::InputType) + \param title preference item title + \param parent parent preference item + \param sect resource file section associated with the preference item + \param param resource file parameter associated with the preference item +*/ QtxPagePrefDateTimeItem::QtxPagePrefDateTimeItem( const int type, const QString& title, QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ), -myType( type ) + myType( type ) { setControl( myDateTime = new QDateTimeEdit() ); myDateTime->setCalendarPopup( true ); @@ -3133,15 +3362,28 @@ myType( type ) updateDateTime(); } +/*! + \brief Destructor. +*/ QtxPagePrefDateTimeItem::~QtxPagePrefDateTimeItem() { } +/*! + \brief Get date/time box preference item input type. + \return preference item input type (QtxPagePrefDateTimeItem::InputType) + \sa setInputType() +*/ int QtxPagePrefDateTimeItem::inputType() const { return myType; } +/*! + \brief Set date/time box preference item input type. + \param type new preference item input type (QtxPagePrefDateTimeItem::InputType) + \sa inputType() +*/ void QtxPagePrefDateTimeItem::setInputType( const int type ) { if ( myType == type ) @@ -3151,36 +3393,69 @@ void QtxPagePrefDateTimeItem::setInputType( const int type ) updateDateTime(); } +/*! + \brief Check if the popup calendar menu is enabled. + \return \c true if calendar popup menu is enabled +*/ bool QtxPagePrefDateTimeItem::calendar() const { return myDateTime->calendarPopup(); } +/*! + \brief Enable/disable popup calendar menu. + \param on new flag state +*/ void QtxPagePrefDateTimeItem::setCalendar( const bool on ) { myDateTime->setCalendarPopup( on ); } +/*! + \brief Get maximum date value. + \return maximum date value + \sa setMaximumDate(), minimumDate(), maximumTime(), minimumTime() +*/ QDate QtxPagePrefDateTimeItem::maximumDate() const { return myDateTime->maximumDate(); } +/*! + \brief Get maximum time value. + \return maximum time value + \sa setMaximumTime(), minimumTime(), maximumDate(), minimumDate() +*/ QTime QtxPagePrefDateTimeItem::maximumTime() const { return myDateTime->maximumTime(); } +/*! + \brief Get minimum date value. + \return minimum date value + \sa setMinimumDate(), maximumDate(), maximumTime(), minimumTime() +*/ QDate QtxPagePrefDateTimeItem::minimumDate() const { return myDateTime->minimumDate(); } +/*! + \brief Get minimum time value. + \return maximum time value + \sa setMinimumTime(), maximumTime(), maximumDate(), minimumDate() +*/ QTime QtxPagePrefDateTimeItem::minimumTime() const { return myDateTime->minimumTime(); } +/*! + \brief Set maximum date value. + \param d new maximum date value + \sa maximumDate(), minimumDate(), maximumTime(), minimumTime() +*/ void QtxPagePrefDateTimeItem::setMaximumDate( const QDate& d ) { if ( d.isValid() ) @@ -3189,6 +3464,11 @@ void QtxPagePrefDateTimeItem::setMaximumDate( const QDate& d ) myDateTime->clearMaximumDate(); } +/*! + \brief Set maximum time value. + \param t new maximum time value + \sa maximumTime(), minimumTime(), maximumDate(), minimumDate() +*/ void QtxPagePrefDateTimeItem::setMaximumTime( const QTime& t ) { if ( t.isValid() ) @@ -3197,6 +3477,11 @@ void QtxPagePrefDateTimeItem::setMaximumTime( const QTime& t ) myDateTime->clearMaximumTime(); } +/*! + \brief Set minimum date value. + \param d new minimum date value + \sa minimumDate(), maximumDate(), maximumTime(), minimumTime() +*/ void QtxPagePrefDateTimeItem::setMinimumDate( const QDate& d ) { if ( d.isValid() ) @@ -3205,6 +3490,11 @@ void QtxPagePrefDateTimeItem::setMinimumDate( const QDate& d ) myDateTime->clearMinimumDate(); } +/*! + \brief Set minimum time value. + \param t new minimum time value + \sa minimumTime(), maximumTime(), maximumDate(), minimumDate() +*/ void QtxPagePrefDateTimeItem::setMinimumTime( const QTime& t ) { if ( t.isValid() ) @@ -3213,6 +3503,10 @@ void QtxPagePrefDateTimeItem::setMinimumTime( const QTime& t ) myDateTime->clearMinimumTime(); } +/*! + \brief Store preference item to the resource manager. + \sa retrieve() +*/ void QtxPagePrefDateTimeItem::store() { QString str; @@ -3232,6 +3526,10 @@ void QtxPagePrefDateTimeItem::store() setString( str ); } +/*! + \brief Retrieve preference item from the resource manager. + \sa store() +*/ void QtxPagePrefDateTimeItem::retrieve() { QString str = getString(); @@ -3249,6 +3547,12 @@ void QtxPagePrefDateTimeItem::retrieve() } } +/*! + \brief Get preference item option value. + \param name option name + \return property value or null QVariant if option is not set + \sa setOptionValue() +*/ QVariant QtxPagePrefDateTimeItem::optionValue( const QString& name ) const { if ( name == "input_type" || name == "type" ) @@ -3265,6 +3569,12 @@ QVariant QtxPagePrefDateTimeItem::optionValue( const QString& name ) const return QtxPageNamedPrefItem::optionValue( name ); } +/*! + \brief Set preference item option value. + \param name option name + \param val new property value + \sa optionValue() +*/ void QtxPagePrefDateTimeItem::setOptionValue( const QString& name, const QVariant& val ) { if ( name == "input_type" || name == "type" ) @@ -3296,6 +3606,9 @@ void QtxPagePrefDateTimeItem::setOptionValue( const QString& name, const QVarian QtxPageNamedPrefItem::setOptionValue( name, val ); } +/*! + \brief Update date/time widget. +*/ void QtxPagePrefDateTimeItem::updateDateTime() { QString dispFmt; diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index 67ceee71e..11ca33aa3 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -79,6 +79,7 @@ protected: private: void initialize() const; + void initialize( QtxPreferenceItem* ); private: QtxGridBox* myBox; @@ -87,17 +88,15 @@ private: class QTX_EXPORT QtxPagePrefItem : public QtxPreferenceItem { + class Listener; + public: QtxPagePrefItem( const QString&, QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); virtual ~QtxPagePrefItem(); - virtual int rtti() const; - QWidget* widget() const; - static int RTTI(); - protected: void setWidget( QWidget* ); @@ -110,11 +109,17 @@ protected: virtual void store(); virtual void retrieve(); + virtual void widgetShown(); + virtual void widgetHided(); + + virtual void ensureVisible( QtxPreferenceItem* ); + private: virtual void contentChanged(); private: QPointer myWidget; + Listener* myListener; }; class QTX_EXPORT QtxPageNamedPrefItem : public QtxPagePrefItem @@ -126,6 +131,8 @@ public: virtual void setTitle( const QString& ); + static void adjustLabels( QtxPagePrefItem* ); + protected: QLabel* label() const; QWidget* control() const; @@ -160,6 +167,9 @@ private slots: protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); + virtual void ensureVisible( QtxPreferenceItem* ); + + virtual void widgetShown(); private: void updateInfo(); @@ -189,6 +199,9 @@ public: virtual void updateContents(); +protected: + virtual void ensureVisible( QtxPreferenceItem* ); + private: void updateToolBox(); @@ -217,6 +230,7 @@ public: protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); + virtual void ensureVisible( QtxPreferenceItem* ); private: void updateTabs(); @@ -253,6 +267,8 @@ protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); + virtual void widgetShown(); + private: void updateFrame(); @@ -291,10 +307,14 @@ public: virtual void store(); virtual void retrieve(); + QtxGridBox* gridBox() const; + protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); + virtual void widgetShown(); + private: void updateState(); void updateGroup(); @@ -531,7 +551,7 @@ public: protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); - + private: QtxPathEdit* myPath; }; diff --git a/src/Qtx/QtxPreferenceMgr.cxx b/src/Qtx/QtxPreferenceMgr.cxx index 1b12db5e6..26ebbf2a3 100644 --- a/src/Qtx/QtxPreferenceMgr.cxx +++ b/src/Qtx/QtxPreferenceMgr.cxx @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -121,7 +121,7 @@ void QtxPreferenceItem::Updater::customEvent( QEvent* /*e*/ ) \class QtxPreferenceItem \brief Base class for implementing of all the preference items. - To implement any specific preference item, cubclass from the + To implement any specific preference item, cubclass from the QtxPreferenceItem and redefine store() and retrieve() methods. */ @@ -554,6 +554,11 @@ QtxPreferenceItem* QtxPreferenceItem::findItem( const QString& title, const int return item; } +void QtxPreferenceItem::ensureVisible() +{ + if ( parentItem() ) + parentItem()->ensureVisible( this ); +} /*! \brief Get integer resources value corresponding to the item. @@ -705,7 +710,7 @@ void QtxPreferenceItem::setFont( const QFont& val ) /*! \brief Callback function which is called when the child preference item is added. - + This function can be reimplemented in the subclasses to customize child item addition operation. Base implementation does nothing. @@ -719,7 +724,7 @@ void QtxPreferenceItem::itemAdded( QtxPreferenceItem* /*item*/ ) /*! \brief Callback function which is called when the child preference item is removed. - + This function can be reimplemented in the subclasses to customize child item removal operation. Base implementation does nothing. @@ -733,15 +738,20 @@ void QtxPreferenceItem::itemRemoved( QtxPreferenceItem* /*item*/ ) /*! \brief Callback function which is called when the child preference item is modified. - + This function can be reimplemented in the subclasses to customize child item modifying operation. Base implementation does nothing. \param item child item being modified \sa itemAdded(), itemRemoved() */ -void QtxPreferenceItem::itemChanged( QtxPreferenceItem* /*item*/ ) +void QtxPreferenceItem::itemChanged( QtxPreferenceItem* ) +{ +} + +void QtxPreferenceItem::ensureVisible( QtxPreferenceItem* ) { + ensureVisible(); } /*! @@ -757,7 +767,7 @@ void QtxPreferenceItem::triggerUpdate() This function can be reimplemented in the subclasses. Base implementation does nothing. - + \param name option name \return property value or null QVariant if option is not set \sa setOptionValue() @@ -775,7 +785,7 @@ QVariant QtxPreferenceItem::optionValue( const QString& name ) const This function can be reimplemented in the subclasses. Base implementation does nothing. - + \param name option name \param val new property value \sa optionValue() @@ -848,39 +858,6 @@ QtxPreferenceMgr* QtxPreferenceMgr::preferenceMgr() const return (QtxPreferenceMgr*)this; } -/* - \brief Add new preference item. - \param label label of widget to edit preference item - \param pId parent preference item id - \param type preference item type - \param section resource file section associated to the preference item - \param param resource file parameter associated to the preference item -*/ -/* -int QtxPreferenceMgr::addItem( const QString& label, const int pId, const int type, - const QString& section, const QString& param ) -{ - Item* i = createItem( label, type, pId ); - if ( !i ) - return -1; - - if ( !myItems.contains( i->id() ) ) - { - myItems.insert( i->id(), i ); - - i->setTitle( label ); - i->setResource( section, param ); - - if ( !i->parentItem() && !myChildren.contains( i ) ) - myChildren.append( i ); - - itemAdded( i ); - } - - return i->id(); -} -*/ - /*! \brief Get preference item option value. \param id preference item ID @@ -976,40 +953,13 @@ void QtxPreferenceMgr::fromBackup() /*! \brief Update preferences manager. - + Base implementation does nothing. */ void QtxPreferenceMgr::update() { } -/* - \brief Create preference item. - \param label preference item title - \param type preference item type - \param pId parent preference item ID - \return new item -*/ -/* -QtxPreferenceItem* QtxPreferenceMgr::createItem( const QString& label, const int type, const int pId ) -{ - Item* i = 0; - if ( pId < 0 ) - i = createItem( label, type ); - else - { - Item* pItem = item( pId ); - if ( pItem ) - { - i = pItem->createItem( label, type ); - pItem->insertChild( i ); - } - } - - return i; -} -*/ - /*! \brief Get all resources items values. \param map used as container filled with the resources values (:) @@ -1124,7 +1074,7 @@ void QtxPreferenceMgr::differentValues( const ResourceMap& map1, const ResourceM This method is called from store() and fromBackup() methods. Base implementation does nothing. - + \sa store(), fromBackup() */ void QtxPreferenceMgr::changedResources( const ResourceMap& ) diff --git a/src/Qtx/QtxPreferenceMgr.h b/src/Qtx/QtxPreferenceMgr.h index 0e193db34..1b99d84ad 100644 --- a/src/Qtx/QtxPreferenceMgr.h +++ b/src/Qtx/QtxPreferenceMgr.h @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -89,6 +89,8 @@ public: virtual QtxResourceMgr* resourceMgr() const; virtual QtxPreferenceMgr* preferenceMgr() const; + void ensureVisible(); + static int RTTI(); protected: @@ -97,19 +99,21 @@ protected: bool getBoolean( const bool = false ) const; QColor getColor( const QColor& = QColor() ) const; QFont getFont( const QFont& = QFont() ) const; - QString getString( const QString& = QString::null ) const; + QString getString( const QString& = QString() ) const; void setInteger( const int ); void setDouble( const double ); void setBoolean( const bool ); void setColor( const QColor& ); - void setFont( const QFont& ); + void setFont( const QFont& ); void setString( const QString& ); virtual void itemAdded( QtxPreferenceItem* ); virtual void itemRemoved( QtxPreferenceItem* ); virtual void itemChanged( QtxPreferenceItem* ); + virtual void ensureVisible( QtxPreferenceItem* ); + void sendItemChanges(); virtual void triggerUpdate(); @@ -163,7 +167,7 @@ protected: void setResourceValues( QMap& ) const; void setResourceValues( ResourceMap& ) const; - + void differentValues( const QMap&, const QMap&, QMap&, const bool fromFirst = false ) const; void differentValues( const ResourceMap&, const ResourceMap&, -- 2.39.2