From: san Date: Fri, 23 Sep 2011 08:46:16 +0000 (+0000) Subject: New preference item for GUI style selection was added. X-Git-Tag: BR_HDF_dev_for_QT_QWT~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=131131543bbe4203e3d9dd3d0826757dbdb2bb26;p=modules%2Fgui.git New preference item for GUI style selection was added. --- diff --git a/src/Qtx/QtxComboBox.cxx b/src/Qtx/QtxComboBox.cxx index 831cb18c5..35ec55c26 100755 --- a/src/Qtx/QtxComboBox.cxx +++ b/src/Qtx/QtxComboBox.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 @@ -72,7 +72,7 @@ void QtxComboBox::Model::setCleared( const bool isClear ) { if ( myCleared == isClear ) return; - + myCleared = isClear; } @@ -116,7 +116,7 @@ QtxComboBox::ClearEvent::ClearEvent() : QEvent( CLEAR_EVENT ) \class QtxComboBox \brief Enhanced version of Qt combo box class. - In addition to the QComboBox class, QtxComboBox supports + In addition to the QComboBox class, QtxComboBox supports adding/removing the items with the associated unique identifiers. It also provides a way to set "cleared" state to the combo box - when no item is selected. @@ -161,7 +161,7 @@ void QtxComboBox::setCleared( const bool isClear ) { if ( myCleared == isClear ) return; - + myCleared = isClear; if ( lineEdit() ) @@ -259,7 +259,7 @@ void QtxComboBox::resetClear() { if ( !myCleared ) return; - + myCleared = false; update(); } @@ -309,3 +309,13 @@ bool QtxComboBox::hasId( const int idx ) const \brief Emitted when the item with identificator \a id is activated. \param id item ID */ + +bool QtxComboBox::event( QEvent* e ) +{ + if ( e->type() == QEvent::StyleChange ) { + setEditable( !isEditable() ); + setEditable( !isEditable() ); + } + + return QComboBox::event( e ); +} diff --git a/src/Qtx/QtxComboBox.h b/src/Qtx/QtxComboBox.h index f1b4f91ec..6fa081b96 100755 --- a/src/Qtx/QtxComboBox.h +++ b/src/Qtx/QtxComboBox.h @@ -54,6 +54,8 @@ public: bool hasId( const int ) const; void setId( const int, const int ); + virtual bool event( QEvent* ); + signals: void activatedId( int ); diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 27e8a9776..cc8c5cefd 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -29,18 +29,20 @@ #include "QtxColorButton.h" #include "QtxDoubleSpinBox.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /*! \class QtxPagePrefMgr @@ -2330,7 +2332,7 @@ void QtxPagePrefSelectItem::setInputType( const int type ) QStringList QtxPagePrefSelectItem::strings() const { QStringList res; - for ( uint i = 0; i < mySelector->count(); i++ ) + for ( int i = 0; i < mySelector->count(); i++ ) res.append( mySelector->itemText( i ) ); return res; } @@ -2343,7 +2345,7 @@ QStringList QtxPagePrefSelectItem::strings() const QList QtxPagePrefSelectItem::numbers() const { QList res; - for ( uint i = 0; i < mySelector->count(); i++ ) + for ( int i = 0; i < mySelector->count(); i++ ) { if ( mySelector->hasId( i ) ) res.append( mySelector->id( i ) ); @@ -2359,7 +2361,7 @@ QList QtxPagePrefSelectItem::numbers() const QList QtxPagePrefSelectItem::icons() const { QList res; - for ( uint i = 0; i < mySelector->count(); i++ ) + for ( int i = 0; i < mySelector->count(); i++ ) res.append( mySelector->itemIcon( i ) ); return res; } @@ -2382,7 +2384,7 @@ void QtxPagePrefSelectItem::setStrings( const QStringList& lst ) */ void QtxPagePrefSelectItem::setNumbers( const QList& ids ) { - uint i = 0; + int i = 0; for ( QList::const_iterator it = ids.begin(); it != ids.end() && i < mySelector->count(); ++it, i++ ) mySelector->setId( i, *it ); } @@ -2394,7 +2396,7 @@ void QtxPagePrefSelectItem::setNumbers( const QList& ids ) */ void QtxPagePrefSelectItem::setIcons( const QList& icons ) { - uint i = 0; + int i = 0; for ( QList::const_iterator it = icons.begin(); it != icons.end() && i < mySelector->count(); ++it, i++ ) mySelector->setItemIcon( i, *it ); } @@ -2432,7 +2434,7 @@ void QtxPagePrefSelectItem::retrieve() idx = mySelector->index( num ); else { - for ( uint i = 0; i < mySelector->count() && idx == -1; i++ ) + for ( int i = 0; i < mySelector->count() && idx == -1; i++ ) { if ( mySelector->itemText( i ) == txt ) idx = i; @@ -3758,3 +3760,71 @@ void QtxPagePrefDateTimeItem::updateDateTime() myDateTime->setDisplayFormat( dispFmt ); } + +/*! + \class QtxPagePrefStyleItem + \brief GUI implementation of the GUI style selector item + + All items in the list (represented as combo box) defined by Qt style system +*/ + +/*! + \brief Constructor. + + Creates preference item with combo box widget which is not editable. + + \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 +*/ +QtxPagePrefStyleItem::QtxPagePrefStyleItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myStyle = new QtxComboBox() ); + + myStyle->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + myStyle->addItems( QStyleFactory::keys() ); +} + +/*! + \brief Destructor. +*/ +QtxPagePrefStyleItem::~QtxPagePrefStyleItem() +{ +} + +/*! + \brief Store preference item to the resource manager. + \sa retrieve() +*/ +void QtxPagePrefStyleItem::store() +{ + /* + if ( myStyle->isCleared() ) + return; + */ + setString( myStyle->itemText( myStyle->currentIndex() ) ); +} + +/*! + \brief Retrieve preference item from the resource manager. + \sa store() +*/ +void QtxPagePrefStyleItem::retrieve() +{ + QString txt = getString(); + + int idx = -1; + for ( int i = 0; i < myStyle->count() && idx == -1; i++ ) { + if ( myStyle->itemText( i ) == txt ) + idx = i; + } + + if ( idx != -1 ) + myStyle->setCurrentIndex( idx ); + /* else + myStyle->setCleared( true ); + */ +} diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index 2cb95bcb1..922cc94f5 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -38,6 +38,7 @@ class QtxComboBox; class QtxColorButton; class QToolBox; +class QComboBox; class QLineEdit; class QTextEdit; class QCheckBox; @@ -652,4 +653,19 @@ private: QDateTimeEdit* myDateTime; }; +class QTX_EXPORT QtxPagePrefStyleItem : public QtxPageNamedPrefItem +{ +public: + QtxPagePrefStyleItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefStyleItem(); + + virtual void store(); + virtual void retrieve(); + +private: + // QtxComboBox* myStyle; + QComboBox* myStyle; +}; + #endif