From 75c916436a62b869e515510e53fe651948e600b5 Mon Sep 17 00:00:00 2001 From: stv Date: Wed, 4 Jul 2007 15:13:38 +0000 Subject: [PATCH] no message --- src/Qtx/QtxColorButton.cxx | 226 ++++ src/Qtx/QtxColorButton.h | 72 ++ src/Qtx/QtxComboBox.cxx | 10 + src/Qtx/QtxComboBox.h | 1 + src/Qtx/QtxDirListEditor.cxx | 571 --------- src/Qtx/QtxDirListEditor.h | 150 --- src/Qtx/QtxFontEdit.cxx | 199 ++++ src/Qtx/QtxFontEdit.h | 83 ++ src/Qtx/QtxListResourceEdit.cxx | 1749 --------------------------- src/Qtx/QtxListResourceEdit.h | 533 --------- src/Qtx/QtxPagePrefMgr.cxx | 1949 +++++++++++++++++++++++++++++++ src/Qtx/QtxPagePrefMgr.h | 621 ++++++++++ src/Qtx/QtxPathEdit.cxx | 168 +++ src/Qtx/QtxPathEdit.h | 68 ++ src/Qtx/QtxPathListEdit.cxx | 536 +++++++++ src/Qtx/QtxPathListEdit.h | 90 ++ src/Qtx/QtxPreferenceMgr.cxx | 896 ++++++++++++++ src/Qtx/QtxPreferenceMgr.h | 188 +++ src/Qtx/QtxResourceEdit.cxx | 748 ------------ src/Qtx/QtxResourceEdit.h | 197 ---- src/Qtx/QtxResourceMgr.cxx | 14 +- src/Qtx/QtxResourceMgr.h | 6 +- src/SUIT/SUIT_PreferenceMgr.cxx | 125 ++ src/SUIT/SUIT_PreferenceMgr.h | 52 + 24 files changed, 5299 insertions(+), 3953 deletions(-) create mode 100644 src/Qtx/QtxColorButton.cxx create mode 100644 src/Qtx/QtxColorButton.h delete mode 100644 src/Qtx/QtxDirListEditor.cxx delete mode 100644 src/Qtx/QtxDirListEditor.h create mode 100644 src/Qtx/QtxFontEdit.cxx create mode 100644 src/Qtx/QtxFontEdit.h delete mode 100644 src/Qtx/QtxListResourceEdit.cxx delete mode 100644 src/Qtx/QtxListResourceEdit.h create mode 100644 src/Qtx/QtxPagePrefMgr.cxx create mode 100644 src/Qtx/QtxPagePrefMgr.h create mode 100644 src/Qtx/QtxPathEdit.cxx create mode 100644 src/Qtx/QtxPathEdit.h create mode 100644 src/Qtx/QtxPathListEdit.cxx create mode 100644 src/Qtx/QtxPathListEdit.h create mode 100644 src/Qtx/QtxPreferenceMgr.cxx create mode 100644 src/Qtx/QtxPreferenceMgr.h delete mode 100644 src/Qtx/QtxResourceEdit.cxx delete mode 100644 src/Qtx/QtxResourceEdit.h create mode 100644 src/SUIT/SUIT_PreferenceMgr.cxx create mode 100644 src/SUIT/SUIT_PreferenceMgr.h diff --git a/src/Qtx/QtxColorButton.cxx b/src/Qtx/QtxColorButton.cxx new file mode 100644 index 000000000..24c4c5b5d --- /dev/null +++ b/src/Qtx/QtxColorButton.cxx @@ -0,0 +1,226 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxColorButton.cxx +// Author: Sergey TELKOV + +#include "QtxColorButton.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +QtxColorButton::QtxColorButton( QWidget* parent ) +: QToolButton( parent ) +{ + setCheckable( false ); + setPopupMode( MenuButtonPopup ); + + QMenu* pm = new QMenu( this ); + QGridLayout* grid = new QGridLayout( pm ); + grid->setMargin( 5 ); + grid->setSpacing( 0 ); + + QList cList = colorsList(); + int w = 8; + int h = cList.count() / w; + + for ( int y = 0; y < h; y++ ) + { + for ( int x = 0; x < w; x++ ) + { + QColor c = cList.at( x * h + y ).toRgb(); + QToolButton* btn = new QToolButton( pm ); + btn->setAutoRaise( true ); + btn->setCheckable( true ); + myColors.insert( btn, c ); + grid->addWidget( btn, y, x ); + + connect( btn, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); + + updateButton( btn ); + } + } + + QToolButton* other = new QToolButton( pm ); + other->setText( tr( "Other colors..." ) ); + other->setAutoRaise( true ); + other->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + grid->addWidget( other, grid->rowCount(), 0, 1, grid->columnCount() ); + connect( other, SIGNAL( clicked( bool ) ), this, SLOT( onDialogClicked( bool ) ) ); + + setMenu( pm ); + + connect( this, SIGNAL( clicked( bool ) ), this, SLOT( onClicked( bool ) ) ); +} + +QtxColorButton::~QtxColorButton() +{ +} + +QColor QtxColorButton::color() const +{ + return myColors.contains( this ) ? myColors[this] : QColor(); +} + +void QtxColorButton::setColor( const QColor& c ) +{ + myColors.insert( this, c ); + updateButton( this ); + updateState(); +} + +void QtxColorButton::onClicked( bool ) +{ + emit clicked( color() ); +} + +void QtxColorButton::onToggled( bool on ) +{ + const QToolButton* tb = ::qobject_cast( sender() ); + if ( !tb ) + return; + + QColor old = color(); + + if ( on && myColors.contains( tb ) ) + { + myColors.insert( this, myColors[tb] ); + updateButton( this ); + } + + if ( menu() ) + menu()->hide(); + + updateState(); + + if ( old != color() ) + emit changed( color() ); +} + +void QtxColorButton::onDialogClicked( bool ) +{ + QColor c = QColorDialog::getColor( color(), this ); + if ( !c.isValid() ) + return; + + QColor old = color(); + + setColor( c ); + + if ( old != color() ) + emit changed( color() ); +} + +void QtxColorButton::paintEvent( QPaintEvent* e ) +{ + QToolButton::paintEvent( e ); + + if ( !color().isValid() ) + return; + + QStyleOptionToolButton opt; + opt.initFrom( this ); + opt.text = text(); + opt.icon = icon(); + opt.features = QStyleOptionToolButton::Menu; + + QRect r = style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton ); + r.setTopLeft( r.topLeft() + QPoint( 2, 2 ) ); + r.setBottomRight( r.bottomRight() - QPoint( 2, 2 ) ); + + QPixmap pix( r.size() ); + drawColor( &pix, color() ); + + QPainter p( this ); + p.drawPixmap( r, pix ); + p.end(); +} + +void QtxColorButton::updateState() +{ + QColor c = color().toRgb(); + for ( ColorMap::iterator it = myColors.begin(); it != myColors.end(); ++it ) + { + QColor bc = it.value().toRgb(); + QToolButton* b = (QToolButton*)it.key(); + bool block = b->signalsBlocked(); + b->blockSignals( true ); + + if ( bc == c ) + b->setChecked( true ); + else + b->setChecked( false ); + b->blockSignals( block ); + } +} + +void QtxColorButton::updateButton( QToolButton* btn ) +{ + btn->setIcon( buttonIcon( myColors[btn] ) ); +} + +QPixmap QtxColorButton::buttonIcon( const QColor& c ) const +{ + static QMap pixMap; + + if ( pixMap.contains( c.rgb() ) ) + return pixMap[c.rgb()]; + + QPixmap pix( 16, 16 ); + + drawColor( &pix, c ); + + pix.setMask( pix.createHeuristicMask() ); + + pixMap.insert( c.rgb(), pix ); + + return pix; +} + +void QtxColorButton::drawColor( QPaintDevice* pd, const QColor& c, const int m ) const +{ + if ( !pd ) + return; + + QPainter p( pd ); + p.setPen( Qt::black ); + p.fillRect( m, m, pd->width() - 2 * m, pd->height() - 2 * m, QBrush( c ) ); + p.drawRect( m, m, pd->width() - 2 * m - 1, pd->height() - 2 * m - 1 ); + p.end(); +} + +QList QtxColorButton::colorsList() const +{ + QList lst; + + for ( int g = 0; g < 4; g++ ) + { + for ( int r = 0; r < 4; r++ ) + { + for ( int b = 0; b < 3; b++ ) + lst.append( QColor( qRgb( r * 255 / 3, g * 255 / 3, b * 255 / 2 ) ) ); + } + } + return lst; +} diff --git a/src/Qtx/QtxColorButton.h b/src/Qtx/QtxColorButton.h new file mode 100644 index 000000000..dcc72b489 --- /dev/null +++ b/src/Qtx/QtxColorButton.h @@ -0,0 +1,72 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxColorButton.h +// Author: Sergey TELKOV + +#ifndef QTXCOLORBUTTON_H +#define QTXCOLORBUTTON_H + +#include "Qtx.h" + +#include +#include +#include +#include + +class QPaintDevice; + +class QTX_EXPORT QtxColorButton : public QToolButton +{ + Q_OBJECT + +public: + QtxColorButton( QWidget* = 0 ); + virtual ~QtxColorButton(); + + QColor color() const; + void setColor( const QColor& ); + +signals: + void clicked( QColor ); + void changed( QColor ); + +private slots: + void onClicked( bool ); + void onToggled( bool ); + void onDialogClicked( bool ); + +protected: + virtual void paintEvent( QPaintEvent* ); + +private: + QList colorsList() const; + + void updateState(); + void updateButton( QToolButton* ); + QPixmap buttonIcon( const QColor& ) const; + void drawColor( QPaintDevice*, const QColor&, const int = 1 ) const; + +private: + typedef QMap ColorMap; + +private: + ColorMap myColors; +}; + +#endif diff --git a/src/Qtx/QtxComboBox.cxx b/src/Qtx/QtxComboBox.cxx index 96a1b8e0c..eaffefbdf 100755 --- a/src/Qtx/QtxComboBox.cxx +++ b/src/Qtx/QtxComboBox.cxx @@ -227,6 +227,16 @@ int QtxComboBox::index( const int ident ) const return idx; } +/*! + \brief Returns true if the item with index has ID. + \param idx item index +*/ +bool QtxComboBox::hasId( const int idx ) const +{ + QVariant v = itemData( idx, (Qt::ItemDataRole)IdRole ); + return v.canConvert( QVariant::Int ); +} + /*! \fn void QtxComboBox::activatedId( int id ) \brief Emitted when the item with identificator \a id is activated. diff --git a/src/Qtx/QtxComboBox.h b/src/Qtx/QtxComboBox.h index 9aae4eb72..c821ffaed 100755 --- a/src/Qtx/QtxComboBox.h +++ b/src/Qtx/QtxComboBox.h @@ -50,6 +50,7 @@ public: int id( const int ) const; int index( const int ) const; + bool hasId( const int ) const; void setId( const int, const int ); signals: diff --git a/src/Qtx/QtxDirListEditor.cxx b/src/Qtx/QtxDirListEditor.cxx deleted file mode 100644 index 770cc58a0..000000000 --- a/src/Qtx/QtxDirListEditor.cxx +++ /dev/null @@ -1,571 +0,0 @@ -// 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 -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -#include "QtxDirListEditor.h" - -#include -#include -#include -#include -#include -#include - -#define MARGIN_SIZE 11 -#define SPACING_SIZE 6 -#define SPACER_SIZE 5 - -static const char* delete_icon[] = { -"16 16 3 1", -"` c #810000", -" c none", -"# c #ffffff", -" ", -" ", -" ``# ``# ", -" ````# ``# ", -" ````# ``# ", -" ```# `# ", -" `````# ", -" ```# ", -" `````# ", -" ```# ``# ", -" ```# ``# ", -" ```# `# ", -" ```# `# ", -" `# `# ", -" ", -" " -}; - -static const char* insert_icon[] = { -"16 16 5 1", -"` c #000000", -". c #ffff00", -"# c #9d9da1", -" c none", -"b c #ffffff", -" ", -" ", -" # #b #. ", -" # #.#.` ` ` ", -" .#.b#### ` ", -" ### .. ", -" . # .# ` ", -" #` #. ", -" # ` ", -" ` ", -" ` ", -" ` ", -" ` ", -" ` ` ` ` ` ` ", -" ", -" " -}; - -static const char* movedown_icon[] = { -"16 16 2 1", -"` c #000000", -" c none", -" ", -" ", -" ``` ", -" ``` ", -" ``` ", -" ``` ", -" ``` ", -" ``` ", -" ``````````` ", -" ````````` ", -" ``````` ", -" ````` ", -" ``` ", -" ` ", -" ", -" " -}; - -static const char* moveup_icon[] = { -"16 16 2 1", -"` c #000000", -" c none", -" ", -" ", -" ` ", -" ``` ", -" ````` ", -" ``````` ", -" ````````` ", -" ``````````` ", -" ``` ", -" ``` ", -" ``` ", -" ``` ", -" ``` ", -" ``` ", -" ", -" " -}; - -/*! - Constructor -*/ -QtxDirListEditor::QtxDirListEditor( QWidget* parent ) -: QWidget( parent ) -{ - myEdited = false; - myLastSelected = 0; - myEdit = 0; - myBtn = 0; - - QGridLayout* topLayout = new QGridLayout(this); - topLayout->setMargin(0); - topLayout->setSpacing(0); - - setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - - myDirList = new QListBox(this); - myDirList->setSelectionMode(QListBox::Single); - myDirList->setHScrollBarMode(QListBox::AlwaysOff); - myDirList->horizontalScrollBar()->installEventFilter(this); - myDirList->verticalScrollBar()->installEventFilter(this); - myDirList->insertItem(tr("")); - myDirList->installEventFilter(this); - - QHBoxLayout* ctrlLayout = new QHBoxLayout; - ctrlLayout->setMargin(0); - ctrlLayout->setSpacing(0); - - // QLabel* lab = new QLabel(myDirList, tr("DIRECTORIES_LBL"), this); - - QToolButton* insertBtn = new QToolButton(this); - insertBtn->setIconSet(QPixmap( insert_icon )); - insertBtn->setAutoRaise(true); - - QToolButton* deleteBtn = new QToolButton(this); - deleteBtn->setIconSet(QPixmap( delete_icon )); - deleteBtn->setAutoRaise(true); - - QToolButton* upBtn = new QToolButton(this); - upBtn->setIconSet(QPixmap( moveup_icon )); - upBtn->setAutoRaise(true); - - QToolButton* downBtn = new QToolButton(this); - downBtn->setIconSet(QPixmap( movedown_icon )); - downBtn->setAutoRaise(true); - - // ctrlLayout->addWidget(lab); - ctrlLayout->addItem(new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum)); - ctrlLayout->addWidget(insertBtn); - ctrlLayout->addWidget(deleteBtn); - ctrlLayout->addWidget(upBtn); - ctrlLayout->addWidget(downBtn); - - QHBoxLayout* btnLayout = new QHBoxLayout; - btnLayout->setMargin(0); - btnLayout->setSpacing(6); - - topLayout->addLayout(ctrlLayout, 0, 0); - topLayout->addWidget(myDirList, 1, 0); - topLayout->addLayout(btnLayout, 2, 0); - - connect(myDirList, SIGNAL(mouseButtonClicked(int, QListBoxItem*, const QPoint&)), - this, SLOT(onMouseButtonClicked(int, QListBoxItem*, const QPoint&))); - connect(myDirList, SIGNAL(doubleClicked(QListBoxItem*)), - this, SLOT(onDblClicked(QListBoxItem*))); - - connect(insertBtn, SIGNAL(clicked()), this, SLOT(onInsert())); - connect(deleteBtn, SIGNAL(clicked()), this, SLOT(onDelete())); - connect(upBtn, SIGNAL(clicked()), this, SLOT(onUp())); - connect(downBtn, SIGNAL(clicked()), this, SLOT(onDown())); -} - -/*! - Destructor -*/ -QtxDirListEditor::~QtxDirListEditor() -{ -} - -/*! - Gets list of paths -*/ -void QtxDirListEditor::getPathList(QStringList& list) -{ - // Finish the path editing - if (myEdit) { - validate(true); - - myEdit->deleteLater(); - myBtn->deleteLater(); - myEdit = 0; - myBtn = 0; - myEdited = false; - myDirList->setFocus(); - } - - list.clear(); - for (unsigned i = 0; i < myDirList->count()-1; i++) - list.append(myDirList->text(i)); -} - -/*! - Sets list of paths -*/ -void QtxDirListEditor::setPathList(const QStringList& list) { - myDirList->clear(); - myDirList->insertItem(tr("")); - for (unsigned i = 0; i < list.count(); i++) - myDirList->insertItem(list[i], myDirList->count()-1); -} - -/*! - Validates entered path, returns true if OK -*/ -bool QtxDirListEditor::validate( const bool quietMode ) -{ - if ( myEdited ) - { - QString dirPath = QFileInfo( myEdit->text().stripWhiteSpace() ).filePath(); -/* -#ifndef WIN32 - if ( dirPath.startsWith( "~") ) { - dirPath = dirPath.remove(0,1); - QString user; - int slashPos = dirPath.find("/"); - if ( slashPos >= 0 ) { - user = dirPath.left(slashPos); - dirPath = dirPath.mid(slashPos); - } - else { - user = dirPath; - dirPath = ""; - } - if ( user.isEmpty() ) - user = getenv( "USER" ); - - struct passwd* user_data = getpwnam( user.latin1() ); - if ( user_data == NULL ) { - // unknown user or something another error - QMessageBox::critical(this, - tr("Error"), - tr("Unknown user %1").arg(user), - tr("Ok")); - myEdit->setFocus(); - return false; - } - dirPath = user_data->pw_dir + dirPath; - } -#endif -*/ - QDir dir(dirPath); - QListBoxItem* found = 0; - for (unsigned i = 0; i < myDirList->count()-1; i++) { - QDir aDir(myDirList->text(i)); - if ( aDir.canonicalPath().isNull() && myDirList->text(i) == dir.absPath() || - !aDir.canonicalPath().isNull() && aDir.exists() && aDir.canonicalPath() == dir.canonicalPath()) { - found = myDirList->item(i); - break; - } - } - if (dirPath.isEmpty()) { - if (found) { - // it should be last (empty) item in the list - nothing to do - return true; - } - else { - // delete directory from the list - removeDir(myLastSelected); - return true; - } - } - else { - if (found) { - if (found != myLastSelected) { - // it is forbidden to add directory more then once - if ( !quietMode ) - QMessageBox::critical(this, - tr("Error"), - tr("Directory already specified."), - tr("Ok")); - myEdit->setFocus(); - return false; - } - } - else { - if (!dir.exists()) { - if ( !quietMode && QMessageBox::information(this, - tr("Warning"), - tr("%1\n\nThe directory doesn't exist.\nAdd directory anyway?").arg(dir.absPath()), - tr("Yes"), tr("No"), QString::null, 1, 1) == 1) { - myEdit->setFocus(); - return false; - } - } - // append - appendDir(myLastSelected, dir.absPath()); - } - } - } - return true; -} - -/*! - Appends/changes directory -*/ -void QtxDirListEditor::appendDir(QListBoxItem* item, const QString& dir) { - int index = myDirList->index(item); - if (index >= 0 && index < (int)myDirList->count()) { - if (index == (int)myDirList->count()-1) { - // it is the last item (new), well, insert it before the last (empty) - myDirList->insertItem(dir, myDirList->count()-1); - } - else { - // change item - myDirList->changeItem(dir, index); - } - } -} - -/*! - Removes directory from list -*/ -void QtxDirListEditor::removeDir(QListBoxItem* item) { - // do not remove last item (empty) - int index = myDirList->index(item); - if (index >= 0 && index < (int)myDirList->count()-1) { - delete item; - myLastSelected = myDirList->item(index); - myDirList->setSelected(myLastSelected, true); - } -} - -/*! - Resize event -*/ -void QtxDirListEditor::resizeEvent(QResizeEvent* event) { - QWidget::resizeEvent(event); - if ( myEdited ) { - myEdit->resize(myDirList->viewport()->width()-myBtn->sizeHint().width(), myEdit->height()); - myBtn->move(myEdit->width(), myEdit->y()); - } -} - -/*! - Called when user clicks inside directories list box -*/ -void QtxDirListEditor::onMouseButtonClicked(int button, - QListBoxItem* item, - const QPoint& point) { - if (myEdited) { - if (!validate()) { - myDirList->setCurrentItem(myLastSelected); - myDirList->setSelected(myLastSelected, true); - return; - } - delete myEdit; - delete myBtn; - myEdit = 0; - myBtn = 0; - myEdited = false; - myDirList->setFocus(); - } - if (item) { - myDirList->setCurrentItem(item); - myDirList->setSelected(item, true); - myDirList->ensureCurrentVisible(); - qApp->processEvents(); - if (button == LeftButton && myLastSelected == item) { - QRect ir = myDirList->itemRect(myLastSelected); - - myEdit = new QLineEdit(myDirList->viewport()); - myBtn = new QToolButton(myDirList->viewport()); - myBtn->setText(" ... "); - connect(myBtn, SIGNAL(clicked()), this, SLOT(onBtnClicked())); - myEdit->setGeometry(0, - ir.top()-(myEdit->sizeHint().height()-ir.height())/2, - myDirList->viewport()->width()-myBtn->sizeHint().width(), - myEdit->sizeHint().height()); - myBtn->setGeometry (myEdit->width(), - ir.top()-(myEdit->sizeHint().height()-ir.height())/2, - myBtn->sizeHint().width(), - myEdit->sizeHint().height()); - connect(myEdit, SIGNAL(returnPressed()), this, SLOT(onEditFinished())); - myEdited = true; - myEdit->show(); - myBtn->show(); - if (myDirList->index(myLastSelected) != (int)myDirList->count()-1) - myEdit->setText(myLastSelected->text()); - myEdit->selectAll(); - myEdit->setCursorPosition(myEdit->text().length()); - myEdit->installEventFilter(this); - myEdit->setFocus(); - } - } - else { - myDirList->clearSelection(); - } - myLastSelected = item; -} - -/*! - Called when user double-clicks on any item -*/ -void QtxDirListEditor::onDblClicked(QListBoxItem* item) { - onMouseButtonClicked(LeftButton, item, QPoint(0,0)); -} - -/*! - <...> (Browse dir) button slot -*/ -void QtxDirListEditor::onBtnClicked() { - QString dir = myEdit->text().stripWhiteSpace().isEmpty() ? - QString::null : - myEdit->text().stripWhiteSpace(); - - dir = QFileDialog::getExistingDirectory(dir, this, 0, tr("Select directory"), true); - - if (!dir.isEmpty()) { - myEdit->setText(dir); - myEdit->selectAll(); - myEdit->setCursorPosition(myEdit->text().length()); - } -} - -/*! - Called when user finises editing of path by pressing -*/ -void QtxDirListEditor::onEditFinished() { - if (myEdit) { - if (!validate()) { - myDirList->setCurrentItem(myLastSelected); - myDirList->setSelected(myLastSelected, true); - return; - } - myEdit->deleteLater(); - myBtn->deleteLater(); - myEdit = 0; - myBtn = 0; - myEdited = false; - myDirList->setFocus(); - } -} - -/*! - Event filter -*/ -bool QtxDirListEditor::eventFilter(QObject* object, QEvent* event) { - if ( myEdited ) { - if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) { - if (object == myDirList->horizontalScrollBar() || object == myDirList->verticalScrollBar()) { - if (!validate()) { - myDirList->setCurrentItem(myLastSelected); - myDirList->setSelected(myLastSelected, true); - return true; - } - delete myEdit; - delete myBtn; - myEdit = 0; - myBtn = 0; - myEdited = false; - myDirList->setFocus(); - } - } - else if (event->type() == QEvent::KeyPress) { - QKeyEvent* ke = (QKeyEvent*)event; - if (ke->key() == Key_Tab) - return true; - if (object == myDirList) { - return true; - } - else if (object == myEdit) { - if ( ke->key() == Key_Up || ke->key() == Key_Down || ke->key() == Key_PageUp || ke->key() == Key_PageDown || - ( ke->key() == Key_Home || ke->key() == Key_End || ke->key() == Key_Prior || ke->key() == Key_Next ) && - (ke->state() & ControlButton) ) { - return true; - } - else if ( ke->key() == Key_Escape ) { - delete myEdit; - delete myBtn; - myEdit = 0; - myBtn = 0; - myEdited = false; - myDirList->setFocus(); - return true; - } - } - } - } - return QWidget::eventFilter(object, event); -} - -/*! - button slot -*/ -void QtxDirListEditor::onInsert() { - if (!myEdited) { - myLastSelected = 0; - onMouseButtonClicked(LeftButton, myDirList->item(myDirList->count()-1), QPoint(0,0)); - onMouseButtonClicked(LeftButton, myDirList->item(myDirList->count()-1), QPoint(0,0)); - } -} - -/*! - button slot -*/ -void QtxDirListEditor::onDelete() { - if (!myEdited && myDirList->currentItem() >=0) { - removeDir(myDirList->item(myDirList->currentItem())); - myDirList->setFocus(); - } -} - -/*! - button slot -*/ -void QtxDirListEditor::onUp() { - if (!myEdited && myLastSelected) { - int index = myDirList->currentItem(); - if (index > 0 && index < (int)myDirList->count()-1 && myDirList->isSelected(index)) { - QString t = myDirList->text(index-1); - myDirList->changeItem(myDirList->text(index), index-1); - myDirList->changeItem(t, index); - myDirList->setCurrentItem(index-1); - myLastSelected = myDirList->item(index-1); - myDirList->setSelected(myLastSelected, true); - myDirList->setFocus(); - } - } -} - -/*! - button slot -*/ -void QtxDirListEditor::onDown() { - if (!myEdited && myLastSelected) { - int index = myDirList->currentItem(); - if (index >= 0 && index < (int)myDirList->count()-2 && myDirList->isSelected(index)) { - QString t = myDirList->text(index+1); - myDirList->changeItem(myDirList->text(index), index+1); - myDirList->changeItem(t, index); - myDirList->setCurrentItem(index+1); - myLastSelected = myDirList->item(index+1); - myDirList->setSelected(myLastSelected, true); - myDirList->setFocus(); - } - } -} diff --git a/src/Qtx/QtxDirListEditor.h b/src/Qtx/QtxDirListEditor.h deleted file mode 100644 index 2edbfc7e6..000000000 --- a/src/Qtx/QtxDirListEditor.h +++ /dev/null @@ -1,150 +0,0 @@ -// 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 -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -#ifndef QTX_DIRLISTEDITOR_H -#define QTX_DIRLISTEDITOR_H - -#include "Qtx.h" - -#include -#include -#include -#include -#include - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -/*! - * \brief The GUI implementation of the directory list - */ -class QTX_EXPORT QtxDirListEditor : public QWidget -{ - - Q_OBJECT - -public: - - /*! - * \brief Constructor - * \param parent - the parent of the widget - */ - QtxDirListEditor(QWidget* parent); - - /*! - * \brief Destructor - */ - ~QtxDirListEditor(); - - /*! - * \brief Gets list of paths - * \param list - the returned reference to the list of paths - */ - void getPathList(QStringList& list); - - /*! - * \brief Sets list of paths - * \param list - the list of paths to set - */ - void setPathList(const QStringList& list); - - /*! - * \brief Event filter, redefined from QObject class - */ - bool eventFilter(QObject* object, QEvent* event); - -protected: - - /*! - * \brief Validates entered path - * \retval bool - returns status (true if OK) - */ - bool validate( const bool quietMode = false ); - - /*! - * \brief Appends/changes path - * \param item - the item in QListBox - * \param dir - the path - */ - void appendDir(QListBoxItem* item, const QString& dir); - - /*! - * \brief Removes directory from list - * \param item - the item in QListBox - */ - void removeDir(QListBoxItem* item); - - /*! - * \brief Resize event handler, reimplemented from QWidget - * \param event - the resize event - */ - void resizeEvent(QResizeEvent* event); - -protected slots: - - /*! - * \brief Called when user clicks inside directories list box - */ - void onMouseButtonClicked(int, QListBoxItem*, const QPoint&); - - /*! - * \brief Called when user double-clicks on any item - */ - void onDblClicked(QListBoxItem*); - - /*! - * \brief <...> (Browse dir) button slot - */ - void onBtnClicked(); - - /*! - * \brief Ccalled when user finises editing of path by pressing - */ - void onEditFinished(); - - /*! - * \brief button slot - */ - void onInsert(); - - /*! - * \brief button slot - */ - void onDelete(); - - /*! - * \brief button slot - */ - void onUp(); - - /*! - * \brief button slot - */ - void onDown(); - -private: - QListBox* myDirList; //!< directory list - QLineEdit* myEdit; //!< path edit box - QToolButton* myBtn; //!< browse pah button - bool myEdited; //!< edit mode flag - QListBoxItem* myLastSelected; //!< last selected row - -}; - -#endif diff --git a/src/Qtx/QtxFontEdit.cxx b/src/Qtx/QtxFontEdit.cxx new file mode 100644 index 000000000..eff70ac39 --- /dev/null +++ b/src/Qtx/QtxFontEdit.cxx @@ -0,0 +1,199 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxFontEdit.cxx +// Author: Sergey TELKOV + +#include "QtxFontEdit.h" + +#include "QtxComboBox.h" + +#include +#include +#include +#include +#include + +QtxFontEdit::QtxFontEdit( const int feat, QWidget* parent ) +: QFrame( parent ), +myFeatures( feat ) +{ + initialize(); +} + +QtxFontEdit::QtxFontEdit( QWidget* parent ) +: QFrame( parent ), +myFeatures( All ) +{ + initialize(); +} + +QtxFontEdit::~QtxFontEdit() +{ +} + +int QtxFontEdit::features() const +{ + return myFeatures; +} + +void QtxFontEdit::setFeatures( const int f ) +{ + if ( myFeatures == f ) + return; + + myFeatures = f; + updateState(); +} + +QFont QtxFontEdit::currentFont() const +{ + QFont fnt( fontFamily(), fontSize() ); + + int script = fontScripting(); + fnt.setBold( script & Bold ); + fnt.setItalic( script & Italic ); + fnt.setUnderline( script & Underline ); + + return fnt; +} + +void QtxFontEdit::setCurrentFont( const QFont& fnt ) +{ + setFontFamily( fnt.family() ); + setFontSize( fnt.pointSize() ); + setFontScripting( ( fnt.bold() ? Bold : 0 ) | + ( fnt.italic() ? Italic : 0 ) | + ( fnt.underline() ? Underline : 0 ) ); +} + +QString QtxFontEdit::fontFamily() const +{ + return myFamily->currentFont().family(); +} + +int QtxFontEdit::fontSize() const +{ + bool ok; + int pSize = mySize->currentText().toInt( &ok ); + return ok ? pSize : 0; +} + +int QtxFontEdit::fontScripting() const +{ + return ( myB->isChecked() ? Bold : 0 ) | + ( myI->isChecked() ? Italic : 0 ) | + ( myU->isChecked() ? Underline : 0 ); +} + +void QtxFontEdit::setFontFamily( const QString& fam ) +{ + myFamily->setCurrentFont( QFont( fam ) ); + onFontChanged( myFamily->currentFont() ); +} + +void QtxFontEdit::setFontSize( const int s ) +{ + if ( s <= 0 ) + return; + + int idx = mySize->findText( QString::number( s ) ); + if ( idx != -1 ) + mySize->setCurrentIndex( idx ); + else if ( mySize->isEditable() ) + mySize->setEditText( QString::number( s ) ); +} + +void QtxFontEdit::setFontScripting( const int script ) +{ + myB->setChecked( script & Bold ); + myI->setChecked( script & Italic ); + myU->setChecked( script & Underline ); +} + +void QtxFontEdit::updateState() +{ + int feat = features(); + + myFamily->setVisible( feat & Family ); + mySize->setVisible( feat & Size ); + myB->setVisible( feat & Bold ); + myI->setVisible( feat & Italic ); + myU->setVisible( feat & Underline ); + myPreview->setVisible( feat & Preview ); + + mySize->setEditable( feat & UserSize ); +} + +void QtxFontEdit::onFontChanged( const QFont& ) +{ + int s = fontSize(); + mySize->clear(); + + QList szList = QFontDatabase().pointSizes( fontFamily() ); + QStringList sizes; + for ( QList::const_iterator it = szList.begin(); it != szList.end(); ++it ) + sizes.append( QString::number( *it ) ); + mySize->addItems( sizes ); + + setFontSize( s ); +} + +void QtxFontEdit::onPreview( bool ) +{ + bool ok; + QFont fnt = QFontDialog::getFont( &ok, currentFont() ); + + if ( ok ) + setCurrentFont( fnt ); +} + +void QtxFontEdit::initialize() +{ + QHBoxLayout* base = new QHBoxLayout( this ); + base->setMargin( 0 ); + base->setSpacing( 5 ); + + base->addWidget( myFamily = new QFontComboBox( this ) ); + base->addWidget( mySize = new QtxComboBox( this ) ); + mySize->setInsertPolicy( QComboBox::NoInsert ); + mySize->setValidator( new QIntValidator( 1, 250, mySize ) ); + + base->addWidget( myB = new QToolButton( this ) ); + myB->setText( tr( "B" ) ); + myB->setCheckable( true ); + + base->addWidget( myI = new QToolButton( this ) ); + myI->setText( tr( "I" ) ); + myI->setCheckable( true ); + + base->addWidget( myU = new QToolButton( this ) ); + myU->setText( tr( "U" ) ); + myU->setCheckable( true ); + + base->addWidget( myPreview = new QToolButton( this ) ); + myPreview->setText( "..." ); + + myFamily->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); + + connect( myPreview, SIGNAL( clicked( bool ) ), this, SLOT( onPreview( bool ) ) ); + connect( myFamily, SIGNAL( currentFontChanged( const QFont& ) ), this, SLOT( onFontChanged( const QFont& ) ) ); + + updateState(); + onFontChanged( currentFont() ); +} diff --git a/src/Qtx/QtxFontEdit.h b/src/Qtx/QtxFontEdit.h new file mode 100644 index 000000000..b851ce9f1 --- /dev/null +++ b/src/Qtx/QtxFontEdit.h @@ -0,0 +1,83 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxFontEdit.h +// Author: Sergey TELKOV + +#ifndef QtxFontEdit_H +#define QtxFontEdit_H + +#include "Qtx.h" + +#include + +class QtxComboBox; +class QToolButton; +class QFontComboBox; + +class QTX_EXPORT QtxFontEdit : public QFrame +{ + Q_OBJECT + +public: + typedef enum { Family = 0x01, + Size = 0x02, + UserSize = 0x04, + Bold = 0x08, + Italic = 0x10, + Underline = 0x20, + Preview = 0x40, + Scripting = Bold | Italic | Underline, + All = Family | Size | UserSize | Scripting | Preview } Features; + +public: + QtxFontEdit( const int, QWidget* = 0 ); + QtxFontEdit( QWidget* = 0 ); + virtual ~QtxFontEdit(); + + QFont currentFont() const; + void setCurrentFont( const QFont& ); + + int fontSize() const; + QString fontFamily() const; + int fontScripting() const; + + void setFontSize( const int ); + void setFontFamily( const QString& ); + void setFontScripting( const int ); + + int features() const; + void setFeatures( const int ); + +private slots: + void onPreview( bool ); + void onFontChanged( const QFont& ); + +private: + void initialize(); + void updateState(); + +private: + QtxComboBox* mySize; + QFontComboBox* myFamily; + QToolButton* myPreview; + int myFeatures; + QToolButton *myB, *myI, *myU; +}; + +#endif diff --git a/src/Qtx/QtxListResourceEdit.cxx b/src/Qtx/QtxListResourceEdit.cxx deleted file mode 100644 index 2a7678df4..000000000 --- a/src/Qtx/QtxListResourceEdit.cxx +++ /dev/null @@ -1,1749 +0,0 @@ -// 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 -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxListResourceEdit.cxx -// Author: Sergey TELKOV - -#include "QtxListResourceEdit.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "QtxIntSpinBox.h" -#include "QtxDblSpinBox.h" -#include "QtxComboBox.h" -#include "QtxDirListEditor.h" - -/*! - Constructor -*/ -QtxListResourceEdit::QtxListResourceEdit( QtxResourceMgr* mgr, QWidget* parent ) -: QFrame( parent ), -QtxResourceEdit( mgr ) -{ - QVBoxLayout* main = new QVBoxLayout( this, 0, 5 ); - QGroupBox* base = new QGroupBox( 1, Qt::Vertical, "", this ); - base->setFrameStyle( QFrame::NoFrame ); - base->setInsideMargin( 0 ); - main->addWidget( base ); - - myList = new QListBox( base ); - myStack = new QWidgetStack( base ); - - myList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); - myStack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - - myList->setSelectionMode( QListBox::Single ); - - connect( myList, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); - - setFocusProxy( myList ); - - updateState(); -} - -/*! - Destructor -*/ -QtxListResourceEdit::~QtxListResourceEdit() -{ -} - -/*! - Sets value to widget - \param id - id of widget - \param prop - name of resource - \param val - value of resource -*/ -void QtxListResourceEdit::setItemProperty( const int id, const QString& prop, const QVariant& val ) -{ - Item* i = item( id ); - if ( !i ) - return; - - bool prev = i->isEmpty(); - - QtxResourceEdit::setItemProperty( id, prop, val ); - - bool next = i->isEmpty(); - - if ( prev != next ) - updateVisible(); -} - -/*! - SLOT: called if main list selection changed, raises resource group widgets -*/ -void QtxListResourceEdit::onSelectionChanged() -{ - QString title = myList->text( myList->index( myList->selectedItem() ) ); - if ( title.isEmpty() ) - return; - - Item* i = 0; - QPtrList lst; - childItems( lst ); - for ( QPtrListIterator it( lst ); it.current() && !i; ++it ) - { - if ( it.current()->title() == title ) - i = it.current(); - } - - if ( i ) - myStack->raiseWidget( i->id() ); -} - -/*! - Custom activity after item addition - \param i - added item -*/ -void QtxListResourceEdit::itemAdded( QtxResourceEdit::Item* i ) -{ - if ( !i ) - return; - - QPtrList items; - childItems( items ); - - if ( items.contains( i ) || items.contains( i->parentItem() ) ) - updateVisible(); -} - -/*! - Creates and \return category - \param title - category title -*/ -QtxResourceEdit::Item* QtxListResourceEdit::createItem( const QString& title, const int ) -{ - Item* i = item( title, -1 ); - if ( i ) - return i; - - Category* category = new Category( this, myStack ); - myStack->addWidget( category, category->id() ); - - updateVisible(); - - if ( !myList->selectedItem() ) - myList->setSelected( 0, true ); - - updateState(); - - return category; -} - -/*! - Emits signal about resource changing - \param map - map of changed resources -*/ -void QtxListResourceEdit::changedResources( const QMap& map ) -{ - QMap idMap; - for ( QMap::ConstIterator it = map.begin(); it != map.end(); ++it ) - { - idMap.insert( it.key()->id(), it.data() ); - - emit resourceChanged( it.key()->id() ); - - QString sec, param; - it.key()->resource( sec, param ); - emit resourceChanged( sec, param ); - } - - emit resourcesChanged( idMap ); -} - -/*! - Updates widgets with accordance with main list selection -*/ -void QtxListResourceEdit::updateState() -{ - if ( myList->selectedItem() && myStack->visibleWidget() ) - myStack->show(); - else - myStack->hide(); - - myList->setShown( myList->count() > 1 ); -} - -/*! - Updates visibility state -*/ -void QtxListResourceEdit::updateVisible() -{ - QPtrList items; - childItems( items ); - - QString name = myList->text( myList->index( myList->selectedItem() ) ); - - myList->clear(); - for ( QPtrListIterator it( items ); it.current(); ++it ) - { - if ( it.current()->isEmpty() ) - continue; - - myList->insertItem( it.current()->title() ); - } - - int idx = -1; - for ( int i = 0; i < (int)myList->count() && idx == -1; i++ ) - { - if ( myList->text( i ) == name ) - idx = i; - } - - myList->setSelected( QMAX( idx, 0 ), true ); - - updateState(); -} - -/*! - Constructor -*/ -QtxListResourceEdit::Category::Category( QtxListResourceEdit* edit, QWidget* parent ) -: QFrame( parent ), -Item( edit ) -{ - QVBoxLayout* main = new QVBoxLayout( this ); - QGroupBox* base = new QGroupBox( 1, Qt::Horizontal, "", this ); - base->setFrameStyle( QFrame::NoFrame ); - base->setInsideMargin( 0 ); - main->addWidget( base, 1 ); - - myTabs = new QTabWidget( base ); - myInfo = new QLabel( base ); - - myInfo->setAlignment( Qt::AlignCenter ); - myInfo->setFrameStyle( QFrame::WinPanel | QFrame::Raised ); - myInfo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - - updateState(); -} - -/*! - Destructor -*/ -QtxListResourceEdit::Category::~Category() -{ -} - -/*! - \return true if it is empty -*/ -bool QtxListResourceEdit::Category::isEmpty() const -{ - return Item::isEmpty() && myInfo->text().isEmpty(); -} - -/*! - \return category type -*/ -int QtxListResourceEdit::Category::type() const -{ - return -1; -} - -/*! - Default empty implementation of resources storing -*/ -void QtxListResourceEdit::Category::store() -{ -} - -/*! - Default empty implementation of resources retrieving -*/ -void QtxListResourceEdit::Category::retrieve() -{ -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::Category::property( const QString& prop ) const -{ - QVariant var; - if ( prop == QString( "information" ) || prop == QString( "info" ) ) - var = myInfo->text(); - return var; -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::Category::setProperty( const QString& name, const QVariant& var ) -{ - QVariant prop = var; - if ( !prop.cast( QVariant::String ) ) - return; - - if ( name == QString( "information" ) || name == QString( "info" ) ) - myInfo->setText( prop.toString() ); - - updateState(); -} - -/*! - Creates new tab - \param title - name of tab -*/ -QtxResourceEdit::Item* QtxListResourceEdit::Category::createItem( const QString& title, const int ) -{ - Item* i = item( title, id() ); - if ( i ) - return i; - - Tab* tab = new Tab( resourceEdit(), this, this ); - myTabs->addTab( tab, title ); - - updateState(); - - return tab; -} - -/*! - Updates category -*/ -void QtxListResourceEdit::Category::updateState() -{ - if ( myTabs->count() ) - myTabs->show(); - else - myTabs->hide(); - - if ( !myTabs->count() && !myInfo->text().isEmpty() ) - myInfo->show(); - else - myInfo->hide(); -} - - -/*! - Constructor -*/ -QtxListResourceEdit::Tab::Tab( QtxResourceEdit* edit, Item* pItem, QWidget* parent ) -: QFrame( parent ), -Item( edit, pItem ) -{ - QVBoxLayout* main = new QVBoxLayout( this ); - QVBox* vbox = new QVBox( this ); - vbox->setMargin( 5 ); - myMainFrame = vbox; - main->addWidget( myMainFrame ); - main->addStretch( 1 ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::Tab::~Tab() -{ -} - -/*! - \return tab type -*/ -int QtxListResourceEdit::Tab::type() const -{ - return -1; -} - -/*! - Default empty implementation of resources storing -*/ -void QtxListResourceEdit::Tab::store() -{ -} - -/*! - Default empty implementation of resources retrieving -*/ -void QtxListResourceEdit::Tab::retrieve() -{ -} - -/*! - Delayed initialization of a widget -*/ -void QtxListResourceEdit::Tab::polish() -{ - QFrame::polish(); - - adjustLabels(); -} - -/*! - Creates new group - \param title - name of group -*/ -QtxResourceEdit::Item* QtxListResourceEdit::Tab::createItem( const QString& title, const int ) -{ - Item* i = item( title, id() ); - if ( i ) - return i; - - Group* group = new Group( title, resourceEdit(), this, myMainFrame ); - - return group; -} - -/*! - Adjusts sizes of labels -*/ -void QtxListResourceEdit::Tab::adjustLabels() -{ - QObjectList* labels = queryList( "QLabel" ); - if ( labels ) - { - int w = 0; - for ( QObjectListIt it1( *labels ); it1.current(); ++it1 ) - { - if ( it1.current()->isWidgetType() ) - { - QWidget* wid = (QWidget*)it1.current(); - w = QMAX( w, wid->sizeHint().width() ); - } - } - for ( QObjectListIt it2( *labels ); it2.current(); ++it2 ) - { - if ( it2.current()->isWidgetType() ) - { - QWidget* wid = (QWidget*)it2.current(); - wid->setMinimumWidth( w ); - } - } - delete labels; - } -} - -/*! - Constructor -*/ -QtxListResourceEdit::Group::Group( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent ) -: QGroupBox( 2, Qt::Horizontal, title, parent ), -Item( edit, pItem ) -{ -} - -/*! - Destructor -*/ -QtxListResourceEdit::Group::~Group() -{ -} - -/*! - \return group type -*/ -int QtxListResourceEdit::Group::type() const -{ - return -1; -} - -/*! - Default empty implementation of resources storing -*/ -void QtxListResourceEdit::Group::store() -{ -} - -/*! - Default empty implementation of resources retrieving -*/ -void QtxListResourceEdit::Group::retrieve() -{ -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::Group::property( const QString& prop ) const -{ - QVariant var; - if ( prop == "columns" ) - var = QVariant( columns() ); - else if ( prop == "orientation" ) - var = QVariant( orientation() ); - else if ( prop == "frame" ) - var = QVariant( frameStyle() != QFrame::NoFrame ); - return var; -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::Group::setProperty( const QString& name, const QVariant& var ) -{ - QVariant prop = var; - if ( !prop.cast( QVariant::Int ) ) - return; - - if ( name == QString( "columns" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 ) - setColumns( prop.toInt() ); - else if ( name == QString( "orientation" ) && prop.cast( QVariant::Int ) ) - { - int o = prop.toInt(); - if ( o == Qt::Horizontal || o == Qt::Vertical ) - setOrientation( (Orientation)o ); - } - else if ( name == "frame" && prop.cast( QVariant::Bool ) ) - { - setInsideMargin( prop.toBool() ? 5 : 0 ); - QGroupBox::setTitle( prop.toBool() ? Item::title() : QString::null ); - setFrameStyle( prop.toBool() ? QFrame::Box | QFrame::Sunken : QFrame::NoFrame ); - } -} - -/*! - Sets title of group - \param title - new title of group -*/ -void QtxListResourceEdit::Group::setTitle( const QString& title ) -{ - Item::setTitle( title ); - QGroupBox::setTitle( title ); -} - -/*! - Creates new item - \param title - title of new item - \type - type of new item -*/ -QtxResourceEdit::Item* QtxListResourceEdit::Group::createItem( const QString& title, const int type ) -{ - Item* item = 0; - - switch ( type ) - { - case Color: - item = new ColorItem( title, resourceEdit(), this, this ); - break; - case Bool: - item = new StateItem( title, resourceEdit(), this, this ); - break; - case String: - item = new StringItem( title, resourceEdit(), this, this ); - break; - case Selector: - item = new SelectItem( title, resourceEdit(), this, this ); - break; - case DblSpin: - item = new DoubleSpinItem( title, resourceEdit(), this, this ); - break; - case IntSpin: - item = new IntegerSpinItem( title, resourceEdit(), this, this ); - break; - case Double: - item = new DoubleEditItem( title, resourceEdit(), this, this ); - break; - case Integer: - item = new IntegerEditItem( title, resourceEdit(), this, this ); - break; - case Space: - item = new Spacer( resourceEdit(), this, this ); - break; - case GroupBox: - item = new Group( title, resourceEdit(), this, this ); - break; - case Font: - item = new FontItem( title, resourceEdit(), this, this ); - break; - case DirList: - item = new DirListItem( title, resourceEdit(), this, this ); - break; - case File: - item = new FileItem( title, resourceEdit(), this, this ); - break; - } - - return item; -} - -/*! - Constructor -*/ -QtxListResourceEdit::PrefItem::PrefItem( const int type, QtxResourceEdit* edit, Item* pi, QWidget* parent ) -: QHBox( parent ), -Item( edit, pi ), -myType( type ) -{ - setSpacing( 5 ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::PrefItem::~PrefItem() -{ -} - -/*! - \return preference item type -*/ -int QtxListResourceEdit::PrefItem::type() const -{ - return myType; -} - -/*! - Doesn't create item, \return 0 by default -*/ -QtxResourceEdit::Item* QtxListResourceEdit::PrefItem::createItem( const QString&, const int ) -{ - return 0; -} - -/*! - Constructor -*/ -QtxListResourceEdit::Spacer::Spacer( QtxResourceEdit* edit, Item* pItem, QWidget* parent ) -: PrefItem( Space, edit, pItem, parent ) -{ - setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::Spacer::~Spacer() -{ -} - -/*! - Default empty implementation of resources storing -*/ -void QtxListResourceEdit::Spacer::store() -{ -} - -/*! - Default empty implementation of resources retrieving -*/ -void QtxListResourceEdit::Spacer::retrieve() -{ -} - -/*! - Constructor -*/ -QtxListResourceEdit::SelectItem::SelectItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( Selector, edit, pItem, parent ) -{ - new QLabel( title, this ); - myList = new QComboBox( false, this ); - myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::SelectItem::~SelectItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::SelectItem::store() -{ - int idx = myList->currentItem(); - if ( idx >= 0 ) - setInteger( myIndex.contains( idx ) ? myIndex[idx] : idx ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::SelectItem::retrieve() -{ - int id = getInteger( -1 ); - - for ( QMap::ConstIterator it = myIndex.begin(); it != myIndex.end(); ++it ) - { - if ( it.data() == id ) { - myList->setCurrentItem( it.key() ); - return; - } - } - if ( id >= 0 ) - myList->setCurrentItem( id ); -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::SelectItem::property( const QString& name ) const -{ - QVariant val; - if ( name == QString( "strings" ) ) - { - QStringList lst; - for ( int i = 0; i < (int)myList->count(); i++ ) - lst.append( myList->text( i ) ); - val = QVariant( lst ); - } - else if ( name == QString( "indexes" ) ) - { - QValueList lst; - for ( int i = 0; i < (int)myList->count(); i++ ) - lst.append( myIndex.contains( i ) ? myIndex[i] : 0 ); - val = QVariant( lst ); - } - return val; -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::SelectItem::setProperty( const QString& name, const QVariant& val ) -{ - if ( name == QString( "strings" ) ) - setStrings( val ); - else if ( name == QString( "indexes" ) ) - setIndexes( val ); -} - -/*! - Sets property "strings" - items for selection in combo box - \param var - must be string list: list of items -*/ -void QtxListResourceEdit::SelectItem::setStrings( const QVariant& var ) -{ - if ( var.type() != QVariant::StringList ) - return; - - setStrings( var.toStringList() ); -} - -/*! - Sets property "indexes" - corresponding indices of items in combo box - \param var - must be list of integer variants: list of indices -*/ -void QtxListResourceEdit::SelectItem::setIndexes( const QVariant& var ) -{ - if ( var.type() != QVariant::List ) - return; - - QValueList varList = var.toList(); - QValueList lst; - for ( QValueList::const_iterator it = varList.begin(); it != varList.end(); ++it ) - { - if ( (*it).canCast( QVariant::Int ) ) - lst.append( (*it).toInt() ); - } - setIndexes( lst ); -} - -/*! - Sets property "strings" - items for selection in combo box - \param lst - list of items -*/ -void QtxListResourceEdit::SelectItem::setStrings( const QStringList& lst ) -{ - myList->clear(); - myList->insertStringList( lst ); -} - -/*! - Sets property "indexes" - corresponding indices of items in combo box - \param var - list of indices -*/ -void QtxListResourceEdit::SelectItem::setIndexes( const QValueList& lst ) -{ - myIndex.clear(); - - int idx = 0; - for ( QValueList::const_iterator it = lst.begin(); it != lst.end(); ++it, idx++ ) - myIndex.insert( idx, *it ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::StateItem::StateItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( Bool, edit, pItem, parent ) -{ - myState = new QCheckBox( title, this ); - myState->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::StateItem::~StateItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::StateItem::store() -{ - setBoolean( myState->isChecked() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::StateItem::retrieve() -{ - myState->setChecked( getBoolean() ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::StringItem::StringItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( String, edit, pItem, parent ) -{ - new QLabel( title, this ); - myString = new QLineEdit( this ); - myString->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::StringItem::~StringItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::StringItem::store() -{ - setString( myString->text() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::StringItem::retrieve() -{ - myString->setText( getString() ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::IntegerEditItem::IntegerEditItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent ) -: PrefItem( Integer, edit, pItem, parent ) -{ - new QLabel( title, this ); - myInteger = new QLineEdit( this ); - myInteger->setValidator( new QIntValidator( myInteger ) ); - myInteger->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::IntegerEditItem::~IntegerEditItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::IntegerEditItem::store() -{ - setString( myInteger->text() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::IntegerEditItem::retrieve() -{ - myInteger->setText( getString() ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::IntegerSpinItem::IntegerSpinItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent ) -: PrefItem( IntSpin, edit, pItem, parent ) -{ - new QLabel( title, this ); - myInteger = new QtxIntSpinBox( this ); - myInteger->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::IntegerSpinItem::~IntegerSpinItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::IntegerSpinItem::store() -{ - setInteger( myInteger->value() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::IntegerSpinItem::retrieve() -{ - myInteger->setValue( getInteger() ); -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::IntegerSpinItem::property( const QString& name ) const -{ - QVariant var; - if ( name == QString( "minimum" ) || name == QString( "min" ) ) - var = QVariant( myInteger->minValue() ); - else if ( name == QString( "maximum" ) || name == QString( "max" ) ) - var = QVariant( myInteger->maxValue() ); - else if ( name == QString( "step" ) ) - var = QVariant( myInteger->lineStep() ); - else if ( name == QString( "special" ) ) - var = QVariant( myInteger->specialValueText() ); - else if ( name == QString( "prefix" ) ) - var = QVariant( myInteger->prefix() ); - else if ( name == QString( "suffix" ) ) - var = QVariant( myInteger->suffix() ); - return var; -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::IntegerSpinItem::setProperty( const QString& name, const QVariant& var ) -{ - QVariant prop = var; - - if ( ( name == QString( "minimum" ) || name == QString( "min" ) ) && prop.cast( QVariant::Int ) ) - myInteger->setMinValue( prop.toInt() ); - else if ( ( name == QString( "maximum" ) || name == QString( "max" ) ) && prop.cast( QVariant::Int ) ) - myInteger->setMaxValue( prop.toInt() ); - else if ( name == QString( "step" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 ) - myInteger->setLineStep( prop.toInt() ); - else if ( name == QString( "special" ) && prop.cast( QVariant::String ) ) - myInteger->setSpecialValueText( prop.toString() ); - else if ( name == QString( "prefix" ) && prop.cast( QVariant::String ) ) - myInteger->setPrefix( prop.toString() ); - else if ( name == QString( "suffix" ) && prop.cast( QVariant::String ) ) - myInteger->setSuffix( prop.toString() ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::DoubleEditItem::DoubleEditItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( Double, edit, pItem, parent ) -{ - new QLabel( title, this ); - myDouble = new QLineEdit( this ); - myDouble->setValidator( new QDoubleValidator( myDouble ) ); - myDouble->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::DoubleEditItem::~DoubleEditItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::DoubleEditItem::store() -{ - setString( myDouble->text() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::DoubleEditItem::retrieve() -{ - myDouble->setText( getString() ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::DoubleSpinItem::DoubleSpinItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( DblSpin, edit, pItem, parent ) -{ - new QLabel( title, this ); - myDouble = new QtxDblSpinBox( this ); - myDouble->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::DoubleSpinItem::~DoubleSpinItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::DoubleSpinItem::store() -{ - setDouble( myDouble->value() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::DoubleSpinItem::retrieve() -{ - myDouble->setValue( getDouble() ); -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::DoubleSpinItem::property( const QString& name ) const -{ - QVariant var; - if ( name == QString( "minimum" ) || name == QString( "min" ) ) - var = QVariant( myDouble->minValue() ); - else if ( name == QString( "maximum" ) || name == QString( "max" ) ) - var = QVariant( myDouble->maxValue() ); - else if ( name == QString( "precision" ) ) - var = QVariant( myDouble->precision() ); - else if ( name == QString( "step" ) ) - var = QVariant( myDouble->lineStep() ); - else if ( name == QString( "special" ) ) - var = QVariant( myDouble->specialValueText() ); - else if ( name == QString( "prefix" ) ) - var = QVariant( myDouble->prefix() ); - else if ( name == QString( "suffix" ) ) - var = QVariant( myDouble->suffix() ); - return var; -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::DoubleSpinItem::setProperty( const QString& name, const QVariant& var ) -{ - QVariant prop = var; - - if ( ( name == QString( "minimum" ) || name == QString( "min" ) ) && prop.cast( QVariant::Double ) ) - myDouble->setMinValue( prop.toDouble() ); - else if ( ( name == QString( "maximum" ) || name == QString( "max" ) ) && prop.cast( QVariant::Double ) ) - myDouble->setMaxValue( prop.toDouble() ); - else if ( name == QString( "step" ) && prop.cast( QVariant::Double ) && prop.toDouble() > 0 ) - myDouble->setLineStep( prop.toDouble() ); - else if ( name == QString( "precision" ) && prop.cast( QVariant::Int ) && prop.toInt() > 0 ) - myDouble->setPrecision( prop.toInt() ); - else if ( name == QString( "special" ) && prop.cast( QVariant::String ) ) - myDouble->setSpecialValueText( prop.toString() ); - else if ( name == QString( "prefix" ) && prop.cast( QVariant::String ) ) - myDouble->setPrefix( prop.toString() ); - else if ( name == QString( "suffix" ) && prop.cast( QVariant::String ) ) - myDouble->setSuffix( prop.toString() ); -} - -/*! - Constructor -*/ -QtxListResourceEdit::ColorItem::ColorItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( Color, edit, pItem, parent ) -{ - /*! - \class QtxListResourceEdit::ColorItem::ColorSelector - \brief Label, showing color and allowing to pick color with help of standard color dialog - */ - class ColorSelector : public QLabel - { - public: - ColorSelector( QWidget* parent = 0 ) : QLabel( parent ) - { - setFrameStyle( WinPanel | Raised ); - } - virtual ~ColorSelector() {} - virtual QSize minimumSizeHint() const - { - return QLabel::minimumSizeHint() + QSize( 0, 2 ); - } - - protected: - virtual void mousePressEvent( QMouseEvent* e ) - { - if ( e->button() == LeftButton ) - { - setFrameStyle( WinPanel | Sunken ); - QColor c = QColorDialog::getColor( paletteBackgroundColor(), this ); - if ( c.isValid() ) - setPaletteBackgroundColor( c ); - - setFrameStyle( WinPanel | Raised ); - } - } - }; - - new QLabel( title, this ); - myColor = new ColorSelector( this ); - myColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::ColorItem::~ColorItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::ColorItem::store() -{ - setColor( myColor->paletteBackgroundColor() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::ColorItem::retrieve() -{ - myColor->setPaletteBackgroundColor( getColor() ); -} - - -/*! - Constructor -*/ -QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( Font, edit, pItem, parent ) -{ - new QLabel( title, this ); - myFamilies = new QtxComboBox( false, this ); - mySizes = new QtxComboBox( true, this ); - mySizes->setInsertionPolicy( QComboBox::NoInsertion ); - myBold = new QCheckBox( tr( "Bold" ), this ); - myItalic = new QCheckBox( tr( "Italic" ), this ); - myUnderline = new QCheckBox( tr( "Shadow" ), this ); - myPreview = new QToolButton( this ); - myPreview->setText( "..." ); - - myFamilies->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); - mySizes->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); - - connect( myFamilies, SIGNAL( activated( int ) ), this, SLOT( onActivateFamily( int ) ) ); - connect( myPreview, SIGNAL( clicked() ), this, SLOT( onPreview() ) ); - - setProperty( "system", ( bool )true ); - setProperty( "widget_flags", ( int )All ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::FontItem::~FontItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::FontItem::store() -{ - QFont f( family(), size() ); - bool bold, italic, underline; - params( bold, italic, underline ); - f.setBold( bold ); - f.setItalic( italic ); - f.setUnderline( underline ); - Item::setFont( f ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::FontItem::retrieve() -{ - QFont f = getFont(); - setFamily( f.family() ); - setSize( f.pointSize() ); - setParams( f.bold(), f.italic(), f.underline() ); -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::FontItem::property( const QString& name ) const -{ - if( name=="system" ) - return myIsSystem; - - else if( name=="widget_flags" ) - return ( int )myFlags; - - if( myIsSystem ) - { - if( name=="families" ) - { - QFontDatabase fdb; - return fdb.families(); - } - - else if( name=="default_family" ) - { - QFontDatabase fdb; - QStringList fam = fdb.families(); - if( fam.count()>0 ) - return fam.first(); - else - return QString::null; - } - - else - { - QStringList parts = QStringList::split( ":", name ); - if( parts.count()==2 ) - { - if( parts[1]=="default_bold" || parts[1]=="default_italic" || parts[1]=="default_underline" ) - return false; - - else if( parts[1]=="sizes" ) - { - QFontDatabase fdb; - QValueList sizes = fdb.pointSizes( parts[0] ); - QValueList vsizes; - QValueList::const_iterator anIt = sizes.begin(), - aLast = sizes.end(); - for( ; anIt!=aLast; anIt++ ) - vsizes.append( *anIt ); - - return vsizes; - } - - else if( parts[1]=="default_size" ) - { - if( parts[0].isEmpty() ) - return 0; - - QFontDatabase fdb; - QValueList sizes = fdb.pointSizes( parts[0] ); - if( sizes.count()>0 ) - return sizes.first(); - else - return 0; - } - } - } - } - - else if( myProperties.contains( name ) ) - return myProperties[ name ]; - - return QVariant(); -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::FontItem::setProperty( const QString& name, const QVariant& value ) -{ - if( name=="system" ) - { - if( !value.canCast( QVariant::Bool ) ) - return; - - bool isSystem = value.toBool(); - if( myIsSystem==isSystem ) - return; - - myIsSystem = isSystem; - - QVariant families = property( "families" ); - QString fam = family(); - - myFamilies->clear(); - if( families.canCast( QVariant::StringList ) ) - { - QStringList list = families.toStringList(); - myFamilies->insertStringList( list ); - } - - setFamily( fam ); - setSize( -1 ); //set default size - } - - else if( name=="widget_flags" ) - { - if( !value.canCast( QVariant::Int ) ) - return; - - int wf = value.toInt(); - - myFlags = wf; - myFamilies ->setShown( wf & Family ); - mySizes ->setShown( wf & Size ); - mySizes->lineEdit()->setReadOnly( ( wf & UserSize )==0 ); - myBold ->setShown( wf & Bold ); - myItalic ->setShown( wf & Italic ); - myUnderline->setShown( wf & Underline ); - bool isSystem = property( "system" ).canCast( QVariant::Bool ) ? property( "system" ).toBool() : false; - myPreview->setShown( ( wf & Preview ) && isSystem ); - - internalUpdate(); - } - - else - myProperties[ name ] = value; -} - -/*! - Sets family of font - \param f - new family -*/ -void QtxListResourceEdit::FontItem::setFamily( const QString& f ) -{ - QString curtext; - if( myFamilies->isShown() ) - { - if( myFamilies->listBox()->findItem( f, Qt::ExactMatch ) ) - curtext = f; - } - else - { - QVariant deffam = property( "default_family" ); - if( deffam.canCast( QVariant::String ) ) - curtext = deffam.toString(); - } - - if ( curtext.isEmpty() ) - curtext = (QApplication::font()).family(); - - int idx = -1; - for ( int i = 0; i < (int)myFamilies->count() && idx < 0; i++ ) - { - if ( myFamilies->text( i ) == curtext ) - idx = i; - } - - if ( idx >= 0 ) - myFamilies->setCurrentItem( idx ); - - onActivateFamily( idx ); -} - -/*! - \return family of font -*/ -QString QtxListResourceEdit::FontItem::family() const -{ - return myFamilies->currentText(); -} - -/*! - Sets size of font - \param s - new size of font -*/ -void QtxListResourceEdit::FontItem::setSize( const int s ) -{ - int cursize = -1; - if( mySizes->isShown() && s>0 ) - { - if( ( myFlags & UserSize ) || mySizes->listBox()->findItem( QString( "%1" ).arg( s ), Qt::ExactMatch ) ) - cursize = s; - } - else - { - QVariant defsize = property( QString( "%1:default_size" ).arg( family() ) ); - if( defsize.canCast( QVariant::Int ) ) - cursize = defsize.toInt(); - } - - mySizes->setCurrentText( cursize>0 ? QString( "%1" ).arg( cursize ) : "" ); -} - -/*! - \return size of font -*/ -int QtxListResourceEdit::FontItem::size() const -{ - QString s = mySizes->currentText(); - bool ok; - int pSize = s.toInt( &ok ); - return ( ok ? pSize : 0 ); -} - -/*! - Sets font parameters - \param bold - is font bold - \param italic - is font italic - \param underline - is font underlined -*/ -void QtxListResourceEdit::FontItem::setParams( const bool bold, const bool italic, const bool underline ) -{ - bool curbold = false, curitalic = false, curunderline = false; - if( myBold->isShown() ) - curbold = bold; - else - { - QVariant def = property( QString( "%1:default_bold" ).arg( family() ) ); - if( def.canCast( QVariant::Bool ) ) - curbold = def.toBool(); - } - if( myItalic->isShown() ) - curitalic = italic; - else - { - QVariant def = property( QString( "%1:default_italic" ).arg( family() ) ); - if( def.canCast( QVariant::Bool ) ) - curitalic = def.toBool(); - } - if( myUnderline->isShown() ) - curunderline = underline; - else - { - QVariant def = property( QString( "%1:default_underline" ).arg( family() ) ); - if( def.canCast( QVariant::Bool ) ) - curunderline = def.toBool(); - } - myBold->setChecked( curbold ); - myItalic->setChecked( curitalic ); - myUnderline->setChecked( curunderline ); -} - -/*! - \return font parameters - \param bold - is font bold - \param italic - is font italic - \param underline - is font underlined -*/ -void QtxListResourceEdit::FontItem::params( bool& bold, bool& italic, bool& underline ) -{ - bold = myBold->isChecked(); - italic = myItalic->isChecked(); - underline = myUnderline->isChecked(); -} - -/*! - Updates internal selection of font properties -*/ -void QtxListResourceEdit::FontItem::internalUpdate() -{ - setFamily( family() ); - setSize( size() ); - bool b1, b2, b3; - params( b1, b2, b3 ); - setParams( b1, b2, b3 ); -} - -/*! - SLOT: called if family is activated, updates list of possible sizes -*/ -void QtxListResourceEdit::FontItem::onActivateFamily( int ) -{ - QVariant sizes = property( QString( "%1:sizes" ).arg( family() ) ); - - int s = size(); - mySizes->clear(); - if( sizes.canCast( QVariant::List ) ) - { - QValueList list = sizes.toList(); - QStringList sizeItems; - QValueList::const_iterator anIt = list.begin(), - aLast = list.end(); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).canCast( QVariant::Int ) && (*anIt).toInt()>0 ) - sizeItems.append( QString( "%1" ).arg( (*anIt).toInt() ) ); - mySizes->insertStringList( sizeItems ); - } - setSize( s ); -} - -/*! - SLOT: called if it is necessary to show font preview -*/ -void QtxListResourceEdit::FontItem::onPreview() -{ - QFont f( family(), size() ); - bool bold, italic, underline; - params( bold, italic, underline ); - f.setBold( bold ); - f.setItalic( italic ); - f.setUnderline( underline ); - - bool ok; - f = QFontDialog::getFont( &ok, f ); - - if( ok ) - { - setFamily( f.family() ); - setSize( f.pointSize() ); - setParams( f.bold(), f.italic(), f.underline() ); - } -} - - - -/*! - Constructor -*/ -QtxListResourceEdit::DirListItem::DirListItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent ) -: PrefItem( Font, edit, pItem, parent ) -{ - myDirListEditor = new QtxDirListEditor( this ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::DirListItem::~DirListItem() -{ -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::DirListItem::store() -{ - QStringList list; - myDirListEditor->getPathList(list); - setString( QString(list.join(";")) ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::DirListItem::retrieve() -{ - myDirListEditor->setPathList(QStringList::split(";", getString())); -} - - - -/*! - Constructor -*/ -QtxListResourceEdit::FileItem::FileItem( const QString& title, QtxResourceEdit* edit, - Item* pItem, QWidget* parent ) -: PrefItem( Font, edit, pItem, parent ), - myFlags( QFileInfo::ReadUser ), - myIsExisting( true ), - myIsReadOnly ( true ), - myFileDlg( 0 ) -{ - new QLabel( title, this ); - myFile = new QLineEdit( this ); - myFile->setValidator( new FileValidator( this, myFile ) ); - myFile->setReadOnly( myIsReadOnly ); - myOpenFile = new QToolButton( this ); - myOpenFile->setText( "..." ); - connect( myOpenFile, SIGNAL( clicked() ), this, SLOT( onOpenFile() ) ); -} - -/*! - Destructor -*/ -QtxListResourceEdit::FileItem::~FileItem() -{ - if( myFileDlg ) - delete myFileDlg; -} - -/*! - Stores value to resource manager -*/ -void QtxListResourceEdit::FileItem::store() -{ - setString( myFile->text() ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::FileItem::retrieve() -{ - myFile->setText( getString() ); -} - -/*! - \return value of property - \param prop - property name -*/ -QVariant QtxListResourceEdit::FileItem::property( const QString& name ) const -{ - if( name=="filter" ) - return myFilter; - else if( name=="existing" ) - return myIsExisting; - else if( name=="flags" ) - return myFlags; - else if( name=="readOnly") - return myIsReadOnly; - - return QVariant(); -} - -/*! - Sets property value - \param name - name of property - \param var - value of property -*/ -void QtxListResourceEdit::FileItem::setProperty( const QString& name, const QVariant& value ) -{ - if( name=="filter" ) - { - if( value.canCast( QVariant::String ) ) - { - myFilter.clear(); - myFilter.append( value.toString() ); - } - else if( value.canCast( QVariant::StringList ) ) - myFilter = value.toStringList(); - } - else if( name=="existing" && value.canCast( QVariant::Bool ) ) - myIsExisting = value.toBool(); - - else if( name=="flags" && value.canCast( QVariant::UInt ) ) - myFlags = value.toUInt(); - - else if( name=="readOnly" && value.canCast( QVariant::Bool) ) { - myIsReadOnly = value.toBool(); - myFile->setReadOnly( myIsReadOnly ); - } -} - -/*! - SLOT: called if user click "Open File" button, shows dialog -*/ -void QtxListResourceEdit::FileItem::onOpenFile() -{ - if( !myFileDlg ) - { - myFileDlg = new QFileDialog( "." ); - connect( myFileDlg, SIGNAL( fileHighlighted( const QString& ) ), this, SLOT( onFileSelected( const QString& ) ) ); - } - - myFileDlg->setCaption( title() ); - myFileDlg->setFilters( myFilter ); - myFileDlg->setMode( myIsExisting ? QFileDialog::ExistingFile : QFileDialog::AnyFile ); - - if( myFileDlg->exec()==QDialog::Accepted ) - { - QString selFile = QDir::convertSeparators( myFileDlg->selectedFile() ); - myFile->setText( selFile ); - } -} - -/*! - \return true if file satisfies permissions - \param f - file name -*/ -bool QtxListResourceEdit::FileItem::isFileCorrect( const QString& f ) const -{ - bool res = false; - QFileInfo info( f ); - if( !myIsExisting || info.exists() ) - res = info.isFile() && info.permission( myFlags ); - - return res; -} - -/*! - SLOT: called if user has selected file in file dialog, checks file permissions and passes it's name to widget - \param f - file name -*/ -void QtxListResourceEdit::FileItem::onFileSelected( const QString& f ) -{ - if( myFileDlg && !isFileCorrect( f ) ) - myFileDlg->setSelection( "" ); -} - - -/*! - Constructor -*/ -QtxListResourceEdit::FileItem::FileValidator::FileValidator( FileItem* item, QObject* parent ) -: QValidator( parent ), - myItem( item ) -{ -} - -/*! - Destructor -*/ -QtxListResourceEdit::FileItem::FileValidator::~FileValidator() -{ -} - -/*! - Check file permissions - \param f - file name -*/ -QValidator::State QtxListResourceEdit::FileItem::FileValidator::validate( QString& f, int& ) const -{ - if( myItem && myItem->isFileCorrect( f ) ) - return QValidator::Acceptable; - else - return QValidator::Intermediate; -} diff --git a/src/Qtx/QtxListResourceEdit.h b/src/Qtx/QtxListResourceEdit.h deleted file mode 100644 index ac009d7c8..000000000 --- a/src/Qtx/QtxListResourceEdit.h +++ /dev/null @@ -1,533 +0,0 @@ -// 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 -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxListResourceEdit.h -// Author: Sergey TELKOV - -#ifndef QTXLISTRESOURCEEDIT_H -#define QTXLISTRESOURCEEDIT_H - -#include "QtxResourceEdit.h" - -#include -//#include -#include -#include -#include -#include - -class QLabel; -class QListBox; -class QLineEdit; -class QCheckBox; -class QComboBox; -class QTabWidget; -class QWidgetStack; - -class QtxIntSpinBox; -class QtxDblSpinBox; - -class QtxDirListEditor; - -/*! - \class QtxListResourceEdit - GUI implementation of QtxResourceEdit - manager of resources -*/ - -class QTX_EXPORT QtxListResourceEdit : public QFrame, public QtxResourceEdit -{ - Q_OBJECT - -public: - class Tab; - class Group; - class Category; - class PrefItem; - - class Spacer; - class ColorItem; - class StateItem; - class SelectItem; - class StringItem; - class DoubleSpinItem; - class DoubleEditItem; - class IntegerSpinItem; - class IntegerEditItem; - class FontItem; - class FileItem; - class DirListItem; - - enum { Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, GroupBox, Font, DirList, File, User }; - -public: - QtxListResourceEdit( QtxResourceMgr*, QWidget* = 0 ); - virtual ~QtxListResourceEdit(); - - virtual void setItemProperty( const int, const QString&, const QVariant& ); - -signals: - void resourceChanged( int ); - void resourceChanged( QString&, QString& ); - void resourcesChanged( const QMap& ); - -private slots: - void onSelectionChanged(); - -protected: - virtual void itemAdded( Item* ); - virtual Item* createItem( const QString&, const int ); - virtual void changedResources( const QMap& ); - -private: - void updateState(); - void updateVisible(); - -private: - QListBox* myList; - QWidgetStack* myStack; -}; - -/*! - \class QtxListResourceEdit::Category - GUI implementation of 'Category' frame -*/ - -class QtxListResourceEdit::Category : public QFrame, public Item -{ -public: - Category( QtxListResourceEdit*, QWidget* = 0 ); - virtual ~Category(); - - virtual bool isEmpty() const; - - virtual int type() const; - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - -protected: - virtual Item* createItem( const QString&, const int ); - -private: - void updateState(); - -private: - QLabel* myInfo; - QTabWidget* myTabs; -}; - -/*! - \class QtxListResourceEdit::Tab - GUI implementation of resources tab. -*/ - -class QtxListResourceEdit::Tab : public QFrame, public Item -{ -public: - Tab( QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~Tab(); - - virtual int type() const; - virtual void store(); - virtual void retrieve(); - -public: - virtual void polish(); - -protected: - virtual Item* createItem( const QString&, const int ); - -private: - void adjustLabels(); - -private: - QWidget* myMainFrame; -}; - -/*! - \class QtxListResourceEdit::Group - GUI implementation of resources group. -*/ - -class QtxListResourceEdit::Group : public QGroupBox, public Item -{ -public: - Group( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~Group(); - - virtual int type() const; - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - - virtual void setTitle( const QString& ); - -protected: - virtual Item* createItem( const QString&, const int ); -}; - -/*! - \class QtxListResourceEdit::PrefItem - Base class for preferences items. -*/ - -class QtxListResourceEdit::PrefItem : public QWidget/*QHBox*/, public Item -{ -public: - PrefItem( const int, QtxResourceEdit*, Item* = 0, QWidget* = 0 ); - virtual ~PrefItem(); - - virtual int type() const; - -protected: - virtual Item* createItem( const QString&, const int ); - -private: - int myType; -}; - -/*! - \class QtxListResourceEdit::Spacer - GUI implementation of resources spacer. -*/ - -class QtxListResourceEdit::Spacer : public PrefItem -{ -public: - Spacer( QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~Spacer(); - - virtual void store(); - virtual void retrieve(); -}; - -/*! - \class QtxListResourceEdit::SelectItem - GUI implementation of resources selector item. -*/ - -class QtxListResourceEdit::SelectItem : public PrefItem -{ -public: - SelectItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~SelectItem(); - - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - -private: - void setStrings( const QVariant& ); - void setIndexes( const QVariant& ); - - void setStrings( const QStringList& ); - void setIndexes( const QList& ); - -private: - QComboBox* myList; - QMap myIndex; -}; - -/*! - \class QtxListResourceEdit::StateItem - GUI implementation of resources bool item. -*/ -class QtxListResourceEdit::StateItem : public PrefItem -{ -public: - StateItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~StateItem(); - - virtual void store(); - virtual void retrieve(); - -private: - QCheckBox* myState; -}; - -/*! - \class QtxListResourceEdit::StringItem - GUI implementation of resources string item. -*/ - -class QtxListResourceEdit::StringItem : public PrefItem -{ -public: - StringItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~StringItem(); - - virtual void store(); - virtual void retrieve(); - -private: - QLineEdit* myString; -}; - -/*! - \class QtxListResourceEdit::IntegerEditItem - GUI implementation of resources integer item. -*/ - -class QtxListResourceEdit::IntegerEditItem : public PrefItem -{ -public: - IntegerEditItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~IntegerEditItem(); - - virtual void store(); - virtual void retrieve(); - -private: - QLineEdit* myInteger; -}; - -/*! - \class QtxListResourceEdit::IntegerSpinItem - GUI implementation of resources integer item. -*/ - -class QtxListResourceEdit::IntegerSpinItem : public PrefItem -{ -public: - IntegerSpinItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~IntegerSpinItem(); - - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - -private: - QtxIntSpinBox* myInteger; -}; - -/*! - \class QtxListResourceEdit::DoubleEditItem - GUI implementation of resources double item. -*/ - -class QtxListResourceEdit::DoubleEditItem : public PrefItem -{ -public: - DoubleEditItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~DoubleEditItem(); - - virtual void store(); - virtual void retrieve(); - -private: - QLineEdit* myDouble; -}; - -/*! - \class QtxListResourceEdit::DoubleSpinItem - GUI implementation of resources double item. -*/ - -class QtxListResourceEdit::DoubleSpinItem : public PrefItem -{ -public: - DoubleSpinItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~DoubleSpinItem(); - - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - -private: - QtxDblSpinBox* myDouble; -}; - -/*! - \class QtxListResourceEdit::ColorItem - GUI implementation of resources color item. -*/ - -class QtxListResourceEdit::ColorItem : public PrefItem -{ -public: - ColorItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~ColorItem(); - - virtual void store(); - virtual void retrieve(); - -private: - QWidget* myColor; -}; - -class QtxComboBox; -class QToolButton; - -/*! - \class QtxListResourceEdit::FontItem - GUI implementation of resources font item. -*/ -class QtxListResourceEdit::FontItem : public PrefItem -{ - Q_OBJECT - -public: - typedef enum - { - Family = 0x01, - Size = 0x02, - UserSize = 0x04, - Bold = 0x08, - Italic = 0x10, - Underline = 0x20, - Preview = 0x40, - - All = Family | Size | UserSize | Bold | Italic | Underline | Preview - - } WidgetFlags; - -public: - FontItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~FontItem(); - - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - -private slots: - void onActivateFamily( int ); - void onPreview(); - -private: - void setFamily( const QString& ); - QString family() const; - void setSize( const int ); - int size() const; - void setParams( const bool, const bool, const bool ); - void params( bool&, bool&, bool& ); - void internalUpdate(); - -private: - int myFlags; - bool myIsSystem; - QtxComboBox *myFamilies, *mySizes; - QCheckBox *myBold, *myItalic, *myUnderline; - QToolButton *myPreview; - QMap myProperties; -}; - - -/*! - \class QtxListResourceEdit - \brief GUI implementation of resources directory list item. -*/ -class QtxListResourceEdit::DirListItem : public PrefItem -{ - Q_OBJECT - -public: - - /*! - * \brief Constructor - */ - DirListItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - /*! - * \brief Destructor - */ - virtual ~DirListItem(); - - /*! - * \brief Stores the data - */ - virtual void store(); - - /*! - * \brief Retrieves the data - */ - virtual void retrieve(); - -private: - QtxDirListEditor* myDirListEditor; //!< The widget wich implements in GUI the list of directories -}; - -class QtxComboBox; -class QToolButton; -class QFileDialog; - -/*! - \class QtxListResourceEdit::FontItem - GUI implementation of resources font item. -*/ - -class QtxListResourceEdit::FileItem : public PrefItem -{ - Q_OBJECT - -private: - /*! - \class QtxListResourceEdit::FileItem::FileValidator - custom file validator: checks files on some rights - */ - - class FileValidator : public QValidator - { - public: - FileValidator( FileItem*, QObject* ); - ~FileValidator(); - - virtual QValidator::State validate( QString&, int& ) const; - - private: - FileItem* myItem; - }; - -public: - FileItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); - virtual ~FileItem(); - - virtual void store(); - virtual void retrieve(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - - virtual bool isFileCorrect( const QString& ) const; - -private slots: - void onOpenFile(); - void onFileSelected( const QString& ); - -private: - uint myFlags; - bool myIsReadOnly; - QStringList myFilter; - bool myIsExisting; - QLineEdit* myFile; - QToolButton* myOpenFile; - QFileDialog* myFileDlg; -}; - - -#endif diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx new file mode 100644 index 000000000..897ef71f1 --- /dev/null +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -0,0 +1,1949 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxPagePrefMgr.cxx +// Author: Sergey TELKOV + +#include "QtxPagePrefMgr.h" + +#include "QtxGridBox.h" +#include "QtxFontEdit.h" +#include "QtxGroupBox.h" +#include "QtxComboBox.h" +#include "QtxIntSpinBox.h" +#include "QtxColorButton.h" +#include "QtxDoubleSpinBox.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + \class QtxPagePrefMgr + GUI implementation of QtxPreferenceMgr - manager of preferences +*/ + +QtxPagePrefMgr::QtxPagePrefMgr( QtxResourceMgr* resMgr, QWidget* parent ) +: QFrame( parent ), +QtxPreferenceMgr( resMgr ), +myInit( false ) +{ + myBox = new QtxGridBox( 1, Qt::Horizontal, this, 0 ); + QVBoxLayout* base = new QVBoxLayout( this ); + base->setMargin( 0 ); + base->setSpacing( 0 ); + base->addWidget( myBox ); +} + +QtxPagePrefMgr::~QtxPagePrefMgr() +{ +} + +QSize QtxPagePrefMgr::sizeHint() const +{ + initialize(); + + return QFrame::sizeHint(); +} + +QSize QtxPagePrefMgr::minimumSizeHint() const +{ + initialize(); + + return QFrame::minimumSizeHint(); +} + +void QtxPagePrefMgr::setVisible( bool on ) +{ + if ( on && !myInit ) + updateContents(); + + QFrame::setVisible( on ); +} + +void QtxPagePrefMgr::updateContents() +{ + QtxPreferenceMgr::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 ); + } + } +} + +void QtxPagePrefMgr::itemAdded( QtxPreferenceItem* ) +{ + triggerUpdate(); +} + +void QtxPagePrefMgr::itemRemoved( QtxPreferenceItem* ) +{ + triggerUpdate(); +} + +void QtxPagePrefMgr::itemChanged( QtxPreferenceItem* ) +{ + triggerUpdate(); +} + +QVariant QtxPagePrefMgr::optionValue( const QString& name ) const +{ + if ( name == "orientation" ) + return myBox->orientation() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal; + else + return QtxPreferenceMgr::optionValue( name ); +} + +void QtxPagePrefMgr::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "orientation" ) + { + if ( val.canConvert( QVariant::Int ) ) + myBox->setOrientation( val.toInt() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal ); + } + else + QtxPreferenceMgr::setOptionValue( name, val ); +} + +void QtxPagePrefMgr::initialize() const +{ + if ( myInit ) + return; + + QtxPagePrefMgr* that = (QtxPagePrefMgr*)this; + + that->updateContents(); + + QList lst = childItems( true ); + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) + (*it)->updateContents(); + + that->myInit = true; +} + +/*! + \class QtxPagePrefItem + Base class for implementation of the preference items +*/ + +QtxPagePrefItem::QtxPagePrefItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPreferenceItem( title, sect, param, parent ), +myWidget( 0 ) +{ +} + +QtxPagePrefItem::~QtxPagePrefItem() +{ + delete myWidget; +} + +int QtxPagePrefItem::rtti() const +{ + return QtxPagePrefItem::RTTI(); +} + +QWidget* QtxPagePrefItem::widget() const +{ + return myWidget; +} + +int QtxPagePrefItem::RTTI() +{ + return 1000; +} + +void QtxPagePrefItem::setWidget( QWidget* wid ) +{ + myWidget = wid; + sendItemChanges(); +} + +void QtxPagePrefItem::itemAdded( QtxPreferenceItem* ) +{ + contentChanged(); +} + +void QtxPagePrefItem::itemRemoved( QtxPreferenceItem* ) +{ + contentChanged(); +} + +void QtxPagePrefItem::itemChanged( QtxPreferenceItem* ) +{ + contentChanged(); +} + +void QtxPagePrefItem::store() +{ +} + +void QtxPagePrefItem::retrieve() +{ +} + +void QtxPagePrefItem::pageChildItems( QList& list, const bool rec ) const +{ + QList lst = childItems( rec ); + for ( QList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + { + if ( (*it)->rtti() == QtxPagePrefItem::RTTI() ) + list.append( (QtxPagePrefItem*)*it ); + } +} + +void QtxPagePrefItem::contentChanged() +{ + triggerUpdate(); +} + +/*! + \class QtxPageNamedPrefItem + Base class for implementation of the named preference items (items with text labels). +*/ +QtxPageNamedPrefItem::QtxPageNamedPrefItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPagePrefItem( title, parent, sect, param ), +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 ); + + setWidget( main ); + + myLabel->setVisible( !title.isEmpty() ); +} + +QtxPageNamedPrefItem::~QtxPageNamedPrefItem() +{ +} + +void QtxPageNamedPrefItem::setTitle( const QString& txt ) +{ + QtxPagePrefItem::setTitle( txt ); + + label()->setText( title() ); + if ( !title().isEmpty() ) + label()->setVisible( true ); +} + +QLabel* QtxPageNamedPrefItem::label() const +{ + return myLabel; +} + +QWidget* QtxPageNamedPrefItem::control() const +{ + return myControl; +} + +void QtxPageNamedPrefItem::setControl( QWidget* wid ) +{ + if ( myControl == wid ) + return; + + delete myControl; + myControl = wid; + + if ( myControl ) + widget()->layout()->addWidget( myControl ); +} + +/*! + \class QtxPagePrefListItem +*/ + +QtxPagePrefListItem::QtxPagePrefListItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPagePrefItem( title, parent, sect, param ), +myFix( false ) +{ + QSplitter* main = new QSplitter( Qt::Horizontal ); + main->setChildrenCollapsible( false ); + + main->addWidget( myList = new QListWidget( main ) ); + main->addWidget( myStack = new QStackedWidget( main ) ); + + myList->setSelectionMode( QListWidget::SingleSelection ); + + myStack->addWidget( myInfLabel = new QLabel( myStack ) ); + myInfLabel->setAlignment( Qt::AlignCenter ); + + connect( myList, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) ); + + setWidget( main ); +} + +QtxPagePrefListItem::~QtxPagePrefListItem() +{ +} + +QString QtxPagePrefListItem::emptyInfo() const +{ + return myInfText; +} + +void QtxPagePrefListItem::setEmptyInfo( const QString& inf ) +{ + if ( myInfText == inf ) + return; + + myInfText = inf; + + updateVisible(); +} + +bool QtxPagePrefListItem::isFixedSize() const +{ + return myFix; +} + +void QtxPagePrefListItem::setFixedSize( const bool on ) +{ + if ( myFix == on ) + return; + + myFix = on; + + updateGeom(); +} + +void QtxPagePrefListItem::updateContents() +{ + updateVisible(); +} + +QVariant QtxPagePrefListItem::optionValue( const QString& name ) const +{ + if ( name == "fixed_size" ) + return isFixedSize(); + else if ( name == "empty_info" || name == "info" ) + return emptyInfo(); + else + return QtxPagePrefItem::optionValue( name ); +} + +void QtxPagePrefListItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "fixed_size" ) + { + if ( val.canConvert( QVariant::Bool ) ) + setFixedSize( val.toBool() ); + } + else if ( name == "empty_info" || name == "info" ) + { + if ( val.canConvert( QVariant::String ) ) + setEmptyInfo( val.toString() ); + } + else + QtxPagePrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefListItem::onItemSelectionChanged() +{ + updateState(); +} + +void QtxPagePrefListItem::updateInfo() +{ + QString infoText; + QtxPagePrefItem* item = selectedItem(); + if ( item ) + { + infoText = emptyInfo(); + QRegExp rx( "%([%|N])" ); + + int idx = 0; + while ( ( idx = rx.indexIn( infoText ) ) != -1 ) + { + if ( rx.cap() == QString( "%%" ) ) + infoText.replace( idx, rx.matchedLength(), "%" ); + else if ( rx.cap() == QString( "%N" ) ) + infoText.replace( idx, rx.matchedLength(), item->title() ); + } + } + myInfLabel->setText( infoText ); +} + +void QtxPagePrefListItem::updateState() +{ + QtxPagePrefItem* item = selectedItem(); + QWidget* wid = item && !item->isEmpty() ? item->widget() : myInfLabel; + if ( wid ) + myStack->setCurrentWidget( wid ); + + updateInfo(); +} + +void QtxPagePrefListItem::updateVisible() +{ + QList items; + pageChildItems( items ); + + QMap map; + for ( int i = 0; i < (int)myStack->count(); i++ ) + map.insert( myStack->widget( i ), 0 ); + + int selId = selected(); + myList->clear(); + for ( QList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + if ( (*it)->isEmpty() && myInfText.isEmpty() ) + continue; + + myList->addItem( (*it)->title() ); + myList->item( myList->count() - 1 )->setIcon( (*it)->icon() ); + myList->item( myList->count() - 1 )->setData( Qt::UserRole, (*it)->id() ); + + QWidget* wid = (*it)->widget(); + if ( !map.contains( wid ) ) + myStack->addWidget( wid ); + + map.remove( wid ); + } + + map.remove( myInfLabel ); + + for ( QMap::const_iterator it = map.begin(); it != map.end(); ++it ) + myStack->removeWidget( it.key() ); + + setSelected( selId ); + if ( selected() == -1 && myList->count() ) + setSelected( myList->item( 0 )->data( Qt::UserRole ).toInt() ); + + myList->setVisible( myList->count() > 1 ); + + updateState(); + updateGeom(); +} + +void QtxPagePrefListItem::updateGeom() +{ + if ( myFix ) + myList->setFixedWidth( myList->minimumSizeHint().width() + 10 ); + else + { + myList->setMinimumWidth( 0 ); + myList->setMaximumWidth( 16777215 ); + + QSplitter* s = ::qobject_cast( widget() ); + if ( s ) + { + int w = myList->minimumSizeHint().width() + 30; + QList szList; + szList.append( w ); + szList.append( s->width() - w ); + s->setSizes( szList ); + } + } +} + +int QtxPagePrefListItem::selected() const +{ + QList selList = myList->selectedItems(); + if ( selList.isEmpty() ) + return -1; + + QVariant v = selList.first()->data( Qt::UserRole ); + return v.canConvert( QVariant::Int ) ? v.toInt() : -1; +} + +QtxPagePrefItem* QtxPagePrefListItem::selectedItem() const +{ + int selId = selected(); + + QList items; + pageChildItems( items ); + + QtxPagePrefItem* item = 0; + for ( QList::const_iterator it = items.begin(); it != items.end() && !item; ++it ) + { + if ( (*it)->id() == selId ) + item = *it; + } + return item; +} + +void QtxPagePrefListItem::setSelected( const int id ) +{ + int idx = -1; + for ( int i = 0; i < (int)myList->count() && idx < 0; i++ ) + { + QVariant v = myList->item( i )->data( Qt::UserRole ); + if ( v.canConvert( QVariant::Int ) && v.toInt() == id ) + idx = i; + } + + QItemSelection sel; + QItemSelectionModel* selModel = myList->selectionModel(); + + if ( idx >= 0 ) + sel.select( myList->model()->index( idx, 0 ), myList->model()->index( idx, 0 ) ); + + selModel->select( sel, QItemSelectionModel::ClearAndSelect ); +} + +/*! + \class QtxPagePrefTabsItem +*/ + +QtxPagePrefTabsItem::QtxPagePrefTabsItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPagePrefItem( title, parent, sect, param ) +{ + myTabs = new QTabWidget( 0 ); + setWidget( myTabs ); +} + +QtxPagePrefTabsItem::~QtxPagePrefTabsItem() +{ +} + +void QtxPagePrefTabsItem::updateContents() +{ + updateTabs(); +} + +int QtxPagePrefTabsItem::tabPosition() const +{ + return myTabs->tabPosition(); +} + +void QtxPagePrefTabsItem::setTabPosition( const int tp ) +{ + myTabs->setTabPosition( (QTabWidget::TabPosition)tp ); +} + +int QtxPagePrefTabsItem::tabShape() const +{ + return myTabs->tabShape(); +} + +void QtxPagePrefTabsItem::setTabShape( const int ts ) +{ + myTabs->setTabShape( (QTabWidget::TabShape)ts ); +} + +QSize QtxPagePrefTabsItem::tabIconSize() const +{ + return myTabs->iconSize(); +} + +void QtxPagePrefTabsItem::setTabIconSize( const QSize& sz ) +{ + myTabs->setIconSize( sz ); +} + +QVariant QtxPagePrefTabsItem::optionValue( const QString& name ) const +{ + if ( name == "position" ) + return tabPosition(); + else if ( name == "shape" ) + return tabShape(); + else if ( name == "icon_size" ) + return tabIconSize(); + else + return QtxPagePrefItem::optionValue( name ); +} + +void QtxPagePrefTabsItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "position" ) + { + if ( val.canConvert( QVariant::Int ) ) + setTabPosition( val.toInt() ); + } + else if ( name == "shape" ) + { + if ( val.canConvert( QVariant::Int ) ) + setTabShape( val.toInt() ); + } + else if ( name == "icon_size" ) + { + if ( val.canConvert( QVariant::Size ) ) + setTabIconSize( val.toSize() ); + } + else + QtxPagePrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefTabsItem::updateTabs() +{ + QList items; + pageChildItems( items ); + + QWidget* cur = myTabs->currentWidget(); + + int i = 0; + QMap map; + for ( QList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + QWidget* wid = (*it)->widget(); + if ( !wid ) + continue; + + if ( myTabs->widget( i ) != wid ) + { + if ( myTabs->indexOf( wid ) != -1 ) + myTabs->removeTab( myTabs->indexOf( wid ) ); + + myTabs->insertTab( i, wid, (*it)->title() ); + } + else + myTabs->setTabText( i, (*it)->title() ); + + myTabs->setTabIcon( i, (*it)->icon() ); + + i++; + map.insert( wid, 0 ); + } + + QList del; + for ( int idx = 0; idx < (int)myTabs->count(); idx++ ) + { + QWidget* w = myTabs->widget( idx ); + if ( !map.contains( w ) ) + del.append( w ); + } + + for ( QList::const_iterator itr = del.begin(); itr != del.end(); ++itr ) + myTabs->removeTab( myTabs->indexOf( *itr ) ); + + myTabs->setCurrentWidget( cur ); +} + +/*! + \class QtxPagePrefFrameItem +*/ + +QtxPagePrefFrameItem::QtxPagePrefFrameItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPagePrefItem( title, parent, sect, param ) +{ + myBox = new QtxGridBox( 1, Qt::Horizontal, 0, 5, 0 ); + setWidget( myBox ); +} + +QtxPagePrefFrameItem::~QtxPagePrefFrameItem() +{ +} + +void QtxPagePrefFrameItem::updateContents() +{ + updateFrame(); +} + +int QtxPagePrefFrameItem::margin() const +{ + return myBox->insideMargin(); +} + +void QtxPagePrefFrameItem::setMargin( const int m ) +{ + myBox->setInsideMargin( m ); +} + +int QtxPagePrefFrameItem::spacing() const +{ + return myBox->insideSpacing(); +} + +void QtxPagePrefFrameItem::setSpacing( const int s ) +{ + myBox->setInsideSpacing( s ); +} + +int QtxPagePrefFrameItem::columns() const +{ + return myBox->columns(); +} + +void QtxPagePrefFrameItem::setColumns( const int c ) +{ + myBox->setColumns( c ); +} + +Qt::Orientation QtxPagePrefFrameItem::orientation() const +{ + return myBox->orientation(); +} + +void QtxPagePrefFrameItem::setOrientation( const Qt::Orientation o ) +{ + myBox->setOrientation( o ); +} + +QVariant QtxPagePrefFrameItem::optionValue( const QString& name ) const +{ + if ( name == "margin" ) + return margin(); + else if ( name == "spacing" ) + return spacing(); + else if ( name == "columns" ) + return columns(); + else if ( name == "orientation" ) + return orientation(); + else + return QtxPagePrefItem::optionValue( name ); +} + +void QtxPagePrefFrameItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "margin" ) + { + if ( val.canConvert( QVariant::Int ) ) + setMargin( val.toInt() ); + } + else if ( name == "spacing" ) + { + if ( val.canConvert( QVariant::Int ) ) + setSpacing( val.toInt() ); + } + else if ( name == "columns" ) + { + if ( val.canConvert( QVariant::Int ) ) + setColumns( val.toInt() ); + } + else if ( name == "orientation" ) + { + if ( val.canConvert( QVariant::Int ) ) + setOrientation( (Qt::Orientation)val.toInt() ); + } + else + QtxPagePrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefFrameItem::updateFrame() +{ + QList items; + pageChildItems( items ); + + for ( QList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + QWidget* wid = (*it)->widget(); + if ( !wid ) + continue; + + if ( wid->parent() != myBox ) + wid->setParent( myBox ); + } +} + +/*! + \class QtxPagePrefGroupItem +*/ + +QtxPagePrefGroupItem::QtxPagePrefGroupItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPagePrefItem( title, parent, sect, param ) +{ + myGroup = new QtxGroupBox( title, 0 ); + myBox = new QtxGridBox( 1, Qt::Horizontal, myGroup, 5, 5 ); + myGroup->setWidget( myBox ); + + setWidget( myGroup ); +} + +QtxPagePrefGroupItem::QtxPagePrefGroupItem( const int cols, const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPagePrefItem( title, parent, sect, param ) +{ + myGroup = new QtxGroupBox( title, 0 ); + myBox = new QtxGridBox( cols, Qt::Horizontal, myGroup, 5, 5 ); + myGroup->setWidget( myBox ); + + setWidget( myGroup ); +} + +QtxPagePrefGroupItem::~QtxPagePrefGroupItem() +{ +} + +void QtxPagePrefGroupItem::setResource( const QString& sect, const QString& param ) +{ + QtxPagePrefItem::setResource( sect, param ); + updateState(); +} + +void QtxPagePrefGroupItem::updateContents() +{ + myGroup->setTitle( title() ); + + updateState(); + updateGroup(); +} + +int QtxPagePrefGroupItem::margin() const +{ + return myBox->insideMargin(); +} + +void QtxPagePrefGroupItem::setMargin( const int m ) +{ + myBox->setInsideMargin( m ); +} + +int QtxPagePrefGroupItem::spacing() const +{ + return myBox->insideSpacing(); +} + +void QtxPagePrefGroupItem::setSpacing( const int s ) +{ + myBox->setInsideSpacing( s ); +} + +int QtxPagePrefGroupItem::columns() const +{ + return myBox->columns(); +} + +void QtxPagePrefGroupItem::setColumns( const int c ) +{ + myBox->setColumns( c ); +} + +Qt::Orientation QtxPagePrefGroupItem::orientation() const +{ + return myBox->orientation(); +} + +void QtxPagePrefGroupItem::setOrientation( const Qt::Orientation o ) +{ + myBox->setOrientation( o ); +} + +bool QtxPagePrefGroupItem::isFlat() const +{ + return myGroup->isFlat(); +} + +void QtxPagePrefGroupItem::setFlat( const bool on ) +{ + myGroup->setFlat( on ); +} + +void QtxPagePrefGroupItem::store() +{ + if ( myGroup->isCheckable() ) + setBoolean( myGroup->isChecked() ); +} + +void QtxPagePrefGroupItem::retrieve() +{ + if ( myGroup->isCheckable() ) + myGroup->setChecked( getBoolean() ); +} + +QVariant QtxPagePrefGroupItem::optionValue( const QString& name ) const +{ + if ( name == "margin" ) + return margin(); + else if ( name == "spacing" ) + return spacing(); + else if ( name == "columns" ) + return columns(); + else if ( name == "orientation" ) + return orientation(); + else if ( name == "flat" ) + return isFlat(); + else + return QtxPagePrefItem::optionValue( name ); +} + +void QtxPagePrefGroupItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "margin" ) + { + if ( val.canConvert( QVariant::Int ) ) + setMargin( val.toInt() ); + } + else if ( name == "spacing" ) + { + if ( val.canConvert( QVariant::Int ) ) + setSpacing( val.toInt() ); + } + else if ( name == "columns" ) + { + if ( val.canConvert( QVariant::Int ) ) + setColumns( val.toInt() ); + } + else if ( name == "orientation" ) + { + if ( val.canConvert( QVariant::Int ) ) + setOrientation( (Qt::Orientation)val.toInt() ); + } + else if ( name == "flat" ) + { + if ( val.canConvert( QVariant::Bool ) ) + setFlat( val.toBool() ); + } + else + QtxPagePrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefGroupItem::updateState() +{ + QString section, param; + resource( section, param ); + myGroup->setCheckable( !title().isEmpty() && !section.isEmpty() && !param.isEmpty() ); +} + +void QtxPagePrefGroupItem::updateGroup() +{ + QList items; + pageChildItems( items ); + + for ( QList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + QWidget* wid = (*it)->widget(); + if ( !wid ) + continue; + + if ( wid->parent() != myBox ) + wid->setParent( myBox ); + } +} + +/*! + \class QtxPagePrefSpaceItem +*/ + +QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( QtxPreferenceItem* parent ) +: QtxPagePrefItem( QString(), parent ) +{ + initialize( 0, 0, 1, 1 ); +} + +QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( Qt::Orientation o, QtxPreferenceItem* parent ) +: QtxPagePrefItem( QString(), parent ) +{ + if ( o == Qt::Horizontal ) + initialize( 0, 0, 1, 0 ); + else + initialize( 0, 0, 0, 1 ); +} + +QtxPagePrefSpaceItem::QtxPagePrefSpaceItem( const int w, const int h, QtxPreferenceItem* parent ) +: QtxPagePrefItem( QString(), parent ) +{ + initialize( w, h, w > 0 ? 0 : 1, h > 0 ? 0 : 1 ); +} + +QtxPagePrefSpaceItem::~QtxPagePrefSpaceItem() +{ +} + +int QtxPagePrefSpaceItem::size( Qt::Orientation o ) const +{ + return o == Qt::Horizontal ? widget()->minimumWidth() : widget()->minimumHeight(); +} + +void QtxPagePrefSpaceItem::setSize( Qt::Orientation o, const int sz ) +{ + if ( o == Qt::Horizontal ) + widget()->setMinimumWidth( sz ); + else + widget()->setMinimumHeight( sz ); +} + +int QtxPagePrefSpaceItem::stretch( Qt::Orientation o ) const +{ + QSizePolicy sp = widget()->sizePolicy(); + return o == Qt::Horizontal ? sp.horizontalStretch() : sp.verticalStretch(); +} + +void QtxPagePrefSpaceItem::setStretch( Qt::Orientation o, const int sf ) +{ + QSizePolicy sp = widget()->sizePolicy(); + if ( o == Qt::Horizontal ) + { + sp.setHorizontalStretch( sf ); + sp.setHorizontalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); + } + else + { + sp.setVerticalStretch( sf ); + sp.setVerticalPolicy( sf > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); + } + + widget()->setSizePolicy( sp ); +} + +QVariant QtxPagePrefSpaceItem::optionValue( const QString& name ) const +{ + if ( name == "horizontal_size" || name == "hsize" ) + return size( Qt::Horizontal ); + else if ( name == "vertical_size" || name == "vsize" ) + return size( Qt::Vertical ); + else if ( name == "horizontal_stretch" || name == "hstretch" ) + return stretch( Qt::Horizontal ); + else if ( name == "vertical_stretch" || name == "vstretch" ) + return stretch( Qt::Vertical ); + else + return QtxPagePrefItem::optionValue( name ); +} + +void QtxPagePrefSpaceItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "horizontal_size" || name == "hsize" ) + { + if ( val.canConvert( QVariant::Int ) ) + setSize( Qt::Horizontal, val.toInt() ); + } + else if ( name == "vertical_size" || name == "vsize" ) + { + if ( val.canConvert( QVariant::Int ) ) + setSize( Qt::Vertical, val.toInt() ); + } + else if ( name == "horizontal_stretch" || name == "hstretch" ) + { + if ( val.canConvert( QVariant::Int ) ) + setStretch( Qt::Horizontal, val.toInt() ); + } + else if ( name == "vertical_stretch" || name == "vstretch" ) + { + if ( val.canConvert( QVariant::Int ) ) + setStretch( Qt::Vertical, val.toInt() ); + } + else + QtxPagePrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefSpaceItem::initialize( const int w, const int h, const int hs, const int vs ) +{ + QSizePolicy sp; + sp.setHorizontalPolicy( hs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); + sp.setVerticalPolicy( vs > 0 ? QSizePolicy::Expanding : QSizePolicy::Fixed ); + + sp.setHorizontalStretch( hs ); + sp.setVerticalStretch( vs ); + + QWidget* wid = new QWidget(); + wid->setSizePolicy( sp ); + + wid->setMinimumSize( w, h ); + + setWidget( wid ); +} + +/*! + \class QtxPagePrefCheckItem + GUI implementation of resources check item (bool). +*/ + +QtxPagePrefCheckItem::QtxPagePrefCheckItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) + +: QtxPagePrefItem( title, parent, sect, param ) +{ + myCheck = new QCheckBox( title ); + myCheck->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + setWidget( myCheck ); +} + +QtxPagePrefCheckItem::~QtxPagePrefCheckItem() +{ +} + +void QtxPagePrefCheckItem::setTitle( const QString& txt ) +{ + QtxPagePrefItem::setTitle( txt ); + + myCheck->setText( title() ); +} + +void QtxPagePrefCheckItem::store() +{ + setBoolean( myCheck->isChecked() ); +} + +void QtxPagePrefCheckItem::retrieve() +{ + myCheck->setChecked( getBoolean() ); +} + +/*! + \class QtxPagePrefEditItem + GUI implementation of resources line edit item (string, integer, double). +*/ + +QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ), +myType( String ) +{ + setControl( myEditor = new QLineEdit() ); + updateEditor(); +} + +QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ), +myType( type ) +{ + setControl( myEditor = new QLineEdit() ); + updateEditor(); +} + +QtxPagePrefEditItem::~QtxPagePrefEditItem() +{ +} + +int QtxPagePrefEditItem::inputType() const +{ + return myType; +} + +void QtxPagePrefEditItem::setInputType( const type ) +{ + if ( myType == type ) + return; + + myType = type; + updateEditor(); +} + +void QtxPagePrefEditItem::store() +{ + setString( myEditor->text() ); +} + +void QtxPagePrefEditItem::retrieve() +{ + QString txt = getString(); + if ( myEditor->validator() ) + { + int pos = 0; + if ( myEditor->validator()->validate( txt, pos ) == QValidator::Invalid ) + txt.clear(); + } + myEditor->setText( txt ); +} + +QVariant QtxPagePrefEditItem::optionValue( const QString& name ) const +{ + if ( name == "input_type" || name == "type" ) + return inputType(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "input_type" || name == "type" ) + { + if ( val.canConvert( QVariant::Int ) ) + setInputType( val.toInt() ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefEditItem::updateEditor() +{ + QValidator* val = 0; + switch ( inputType() ) + { + case Integer: + val = new QIntValidator( myEditor ); + break; + case Double: + val = new QDoubleValidator( myEditor ); + break; + default: + break; + } + + if ( !myEditor->text().isEmpty() && val ) + { + int pos = 0; + if ( val->validate( myEditor->text(), pos ) == QValidator::Invalid ) + myEditor->clear(); + } + + delete myEditor->validator(); + myEditor->setValidator( val ); +} + +/*! + \class QtxPagePrefSelectItem + GUI implementation of resources selector item (enum). +*/ +QtxPagePrefSelectItem::QtxPagePrefSelectItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ), +myType( NoInput ) +{ + setControl( mySelector = new QtxComboBox() ); + mySelector->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + mySelector->setDuplicatesEnabled( false ); + updateSelector(); +} + +QtxPagePrefSelectItem::QtxPagePrefSelectItem( const int type, const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ), +myType( type ) +{ + setControl( mySelector = new QtxComboBox() ); + mySelector->setDuplicatesEnabled( false ); + updateSelector(); +} + +QtxPagePrefSelectItem::~QtxPagePrefSelectItem() +{ +} + +int QtxPagePrefSelectItem::inputType() const +{ + return myType; +} + +void QtxPagePrefSelectItem::setInputType( const type ) +{ + if ( myType == type ) + return; + + myType = type; + updateSelector(); +} + +QStringList QtxPagePrefSelectItem::strings() const +{ + QStringList res; + for ( uint i = 0; i < mySelector->count(); i++ ) + res.append( mySelector->itemText( i ) ); + return res; +} + +QList QtxPagePrefSelectItem::numbers() const +{ + QList res; + for ( uint i = 0; i < mySelector->count(); i++ ) + { + if ( mySelector->hasId( i ) ) + res.append( mySelector->id( i ) ); + } + return res; +} + +void QtxPagePrefSelectItem::setStrings( const QStringList& lst ) +{ + mySelector->clear(); + mySelector->addItems( lst ); +} + +void QtxPagePrefSelectItem::setNumbers( const QList& ids ) +{ + uint i = 0; + for ( QList::const_iterator it = ids.begin(); it != ids.end() && i < mySelector->count(); ++it, i++ ) + mySelector->setId( i, *it ); +} + +void QtxPagePrefSelectItem::store() +{ + if ( mySelector->isCleared() ) + return; + + int idx = mySelector->currentIndex(); + + if ( mySelector->hasId( idx ) ) + setInteger( mySelector->id( idx ) ); + else if ( idx >= 0 ) + setString( mySelector->itemText( idx ) ); +} + +void QtxPagePrefSelectItem::retrieve() +{ + QString txt = getString(); + + int idx = -1; + + bool ok = false; + int num = txt.toInt( &ok ); + if ( ok ) + idx = mySelector->index( num ); + else + { + for ( uint i = 0; i < mySelector->count() && idx == -1; i++ ) + { + if ( mySelector->itemText( i ) == txt ) + idx = i; + } + } + + if ( idx != -1 ) + mySelector->setCurrentIndex( idx ); + else if ( mySelector->isEditable() ) + { + int pos = 0; + if ( mySelector->validator() && + mySelector->validator()->validate( txt, pos ) == QValidator::Invalid ) + mySelector->setCleared( true ); + else + { + mySelector->setCleared( false ); + mySelector->addItem( txt ); + mySelector->setCurrentIndex( mySelector->count() - 1 ); + } + } +} + +QVariant QtxPagePrefSelectItem::optionValue( const QString& name ) const +{ + if ( name == "input_type" || name == "type" ) + return inputType(); + else if ( name == "strings" || name == "labels" ) + return strings(); + else if ( name == "numbers" || name == "ids" || name == "indexes" ) + { + QList lst; + QList nums = numbers(); + for ( QList::const_iterator it = nums.begin(); it != nums.end(); ++it ) + lst.append( *it ); + return lst; + } + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +void QtxPagePrefSelectItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "input_type" || name == "type" ) + { + if ( val.canConvert( QVariant::Int ) ) + setInputType( val.toInt() ); + } + else if ( name == "strings" || name == "labels" ) + setStrings( val ); + else if ( name == "numbers" || name == "ids" || name == "indexes" ) + setNumbers( val ); + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefSelectItem::setStrings( const QVariant& var ) +{ + if ( var.type() != QVariant::StringList ) + return; + + setStrings( var.toStringList() ); +} + +void QtxPagePrefSelectItem::setNumbers( const QVariant& var ) +{ + if ( var.type() != QVariant::List ) + return; + + QList lst; + QList varList = var.toList(); + for ( QList::const_iterator it = varList.begin(); it != varList.end(); ++it ) + { + if ( (*it).canConvert( QVariant::Int ) ) + lst.append( (*it).toInt() ); + } + setNumbers( lst ); +} + +void QtxPagePrefSelectItem::updateSelector() +{ + QValidator* val = 0; + switch ( inputType() ) + { + case Integer: + val = new QIntValidator( mySelector ); + break; + case Double: + val = new QDoubleValidator( mySelector ); + break; + default: + break; + } + + mySelector->setEditable( inputType() != NoInput ); + + if ( mySelector->isEditable() && !mySelector->currentText().isEmpty() && val ) + { + int pos = 0; + if ( val->validate( mySelector->currentText(), pos ) == QValidator::Invalid ) + mySelector->clearEditText(); + } + + delete mySelector->validator(); + mySelector->setValidator( val ); +} + +/*! + \class QtxPagePrefSpinItem + GUI implementation of resources spin box item (integer, double). +*/ + +QtxPagePrefSpinItem::QtxPagePrefSpinItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ), +myType( Integer ) +{ + updateSpinBox(); +} + +QtxPagePrefSpinItem::QtxPagePrefSpinItem( const int type, const QString& title, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ), +myType( type ) +{ + updateSpinBox(); +} + +QtxPagePrefSpinItem::~QtxPagePrefSpinItem() +{ +} + +int QtxPagePrefSpinItem::inputType() const +{ + return myType; +} + +void QtxPagePrefSpinItem::setInputType( const type ) +{ + if ( myType == type ) + return; + + myType = type; + updateSpinBox(); +} + +QVariant QtxPagePrefSpinItem::step() const +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + return isb->singleStep(); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + return dsb->singleStep(); + else + return QVariant(); +} + +QVariant QtxPagePrefSpinItem::minimum() const +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + return isb->minimum(); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + return dsb->minimum(); + else + return QVariant(); +} + +QVariant QtxPagePrefSpinItem::maximum() const +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + return isb->maximum(); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + return dsb->maximum(); + else + return QVariant(); +} + +QString QtxPagePrefSpinItem::prefix() const +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + return isb->prefix(); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + return dsb->prefix(); + else + return QString(); +} + +QString QtxPagePrefSpinItem::suffix() const +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + return isb->suffix(); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + return dsb->suffix(); + else + return QString(); +} + +QString QtxPagePrefSpinItem::specialValueText() const +{ + QAbstractSpinBox* sb = ::qobject_cast( control() ); + if ( sb ) + return sb->specialValueText(); + else + return QString(); +} + +void QtxPagePrefSpinItem::setStep( const QVariant& step ) +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + { + if ( step.canConvert( QVariant::Int ) ) + isb->setSingleStep( step.toInt() ); + } + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + { + if ( step.canConvert( QVariant::Double ) ) + dsb->setSingleStep( step.toDouble() ); + } +} + +void QtxPagePrefSpinItem::setMinimum( const QVariant& min ) +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + { + if ( min.canConvert( QVariant::Int ) ) + isb->setMinimum( min.toInt() ); + } + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + { + if ( min.canConvert( QVariant::Double ) ) + dsb->setMinimum( min.toDouble() ); + } +} + +void QtxPagePrefSpinItem::setMaximum( const QVariant& max ) +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + { + if ( max.canConvert( QVariant::Int ) ) + isb->setMaximum( max.toInt() ); + } + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + { + if ( max.canConvert( QVariant::Double ) ) + dsb->setMaximum( max.toDouble() ); + } +} + +void QtxPagePrefSpinItem::setPrefix( const QString& txt ) +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + isb->setPrefix( txt ); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + dsb->setPrefix( txt ); +} + +void QtxPagePrefSpinItem::setSuffix( const QString& txt ) +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + isb->setSuffix( txt ); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + dsb->setSuffix( txt ); +} + +void QtxPagePrefSpinItem::setSpecialValueText( const QString& txt ) +{ + QAbstractSpinBox* sb = ::qobject_cast( control() ); + if ( sb ) + sb->setSpecialValueText( txt ); +} + +void QtxPagePrefSpinItem::store() +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + setInteger( isb->value() ); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + setDouble( dsb->value() ); +} + +void QtxPagePrefSpinItem::retrieve() +{ + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + isb->setValue( getInteger( isb->value() ) ); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + dsb->setValue( getDouble( dsb->value() ) ); +} + +QVariant QtxPagePrefSpinItem::optionValue( const QString& name ) const +{ + if ( name == "input_type" || name == "type" ) + return inputType(); + else if ( name == "minimum" || name == "min" ) + return minimum(); + else if ( name == "maximum" || name == "max" ) + return maximum(); + else if ( name == "step" ) + return step(); + else if ( name == "prefix" ) + return prefix(); + else if ( name == "suffix" ) + return suffix(); + else if ( name == "special" ) + return specialValueText(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +void QtxPagePrefSpinItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "input_type" || name == "type" ) + { + if ( val.canConvert( QVariant::Int ) ) + setInputType( val.toInt() ); + } + else if ( name == "minimum" || name == "min" ) + setMinimum( val ); + else if ( name == "maximum" || name == "max" ) + setMaximum( val ); + else if ( name == "step" ) + setStep( val ); + else if ( name == "prefix" ) + { + if ( val.canConvert( QVariant::String ) ) + setPrefix( val.toString() ); + } + else if ( name == "suffix" ) + { + if ( val.canConvert( QVariant::String ) ) + setSuffix( val.toString() ); + } + else if ( name == "special" ) + { + if ( val.canConvert( QVariant::String ) ) + setSpecialValueText( val.toString() ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + +void QtxPagePrefSpinItem::updateSpinBox() +{ + QVariant val; + QVariant stp = step(); + QVariant min = minimum(); + QVariant max = maximum(); + + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + val = isb->value(); + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + val = dsb->value(); + + switch ( inputType() ) + { + case Integer: + setControl( new QtxIntSpinBox() ); + break; + case Double: + setControl( new QtxDoubleSpinBox() ); + break; + default: + break; + } + + control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + + setStep( stp ); + setMinimum( min ); + setMaximum( max ); + + if ( QtxIntSpinBox* isb = ::qobject_cast( control() ) ) + { + if ( val.canConvert( QVariant::Int ) ) + isb->setValue( val.toInt() ); + } + else if ( QtxDoubleSpinBox* dsb = ::qobject_cast( control() ) ) + { + if ( val.canConvert( QVariant::Double ) ) + dsb->setValue( val.toDouble() ); + } +} + +/*! + \class QtxPagePrefTextItem + GUI implementation of resources text edit item (text - several strings). +*/ +QtxPagePrefTextItem::QtxPagePrefTextItem( QtxPreferenceItem* parent, const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( QString(), parent, sect, param ) +{ + myEditor = new QTextEdit(); + myEditor->setAcceptRichText( false ); + + setControl( myEditor ); +} + +QtxPagePrefTextItem::QtxPagePrefTextItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + myEditor = new QTextEdit(); + myEditor->setAcceptRichText( false ); + + setControl( myEditor ); +} + +QtxPagePrefTextItem::~QtxPagePrefTextItem() +{ +} + +void QtxPagePrefTextItem::store() +{ + setString( myEditor->toPlainText() ); +} + +void QtxPagePrefTextItem::retrieve() +{ + myEditor->setPlainText( getString() ); +} + +/*! + \class QtxPagePrefColorItem + GUI implementation of resources color item. +*/ +QtxPagePrefColorItem::QtxPagePrefColorItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myColor = new QtxColorButton() ); + myColor->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); +} + +QtxPagePrefColorItem::~QtxPagePrefColorItem() +{ +} + +void QtxPagePrefColorItem::store() +{ + setColor( myColor->color() ); +} + +void QtxPagePrefColorItem::retrieve() +{ + myColor->setColor( getColor() ); +} + +/*! + \class QtxPagePrefFontItem + GUI implementation of resources font item. +*/ +QtxPagePrefFontItem::QtxPagePrefFontItem( const int feat, const QString& title, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myFont = new QtxFontEdit( feat ) ); +} + +QtxPagePrefFontItem::QtxPagePrefFontItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myFont = new QtxFontEdit() ); +} + +QtxPagePrefFontItem::~QtxPagePrefFontItem() +{ +} + +int QtxPagePrefFontItem::features() const +{ + return myFont->features(); +} + +void QtxPagePrefFontItem::setFeatures( const int f ) +{ + myFont->setFeatures( f ); +} + +void QtxPagePrefFontItem::store() +{ + setFont( myFont->currentFont() ); +} + +void QtxPagePrefFontItem::retrieve() +{ + myFont->setCurrentFont( getFont() ); +} + +QVariant QtxPagePrefFontItem::optionValue( const QString& name ) const +{ + if ( name == "features" ) + return features(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "features" ) + { + if ( val.canConvert( QVariant::Int ) ) + setFeatures( val.toInt() ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + +/*! + \class QtxPagePrefPathItem + GUI implementation of resources path item. +*/ +QtxPagePrefPathItem::QtxPagePrefPathItem( const int mode, const QString& title, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myPath = new QtxPathEdit( mode ) ); +} + +QtxPagePrefPathItem::QtxPagePrefPathItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myPath = new QtxPathEdit() ); +} + +QtxPagePrefPathItem::~QtxPagePrefPathItem() +{ +} + +int QtxPagePrefPathItem::mode() const +{ + return myPath->mode(); +} + +void QtxPagePrefPathItem::setMode( const int mode ) +{ + myPath->setMode( mode ); +} + +QString QtxPagePrefPathItem::filter() const +{ + return myPath->filter(); +} + +void QtxPagePrefPathItem::setFilter( const QString& f ) +{ + myPath->setFilter( f ); +} + +void QtxPagePrefPathItem::store() +{ + setString( myPath->path() ); +} + +void QtxPagePrefPathItem::retrieve() +{ + myPath->setPath( getString() ); +} + +QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const +{ + if ( name == "mode" ) + return mode(); + else if ( name == "filter" ) + return filter(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "mode" ) + { + if ( val.canConvert( QVariant::Int ) ) + setMode( val.toInt() ); + } + else if ( name == "filter" ) + { + if ( val.canConvert( QVariant::String ) ) + setFilter( val.toString() ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + +/*! + \class QtxPagePrefPathsItem + \brief GUI implementation of resources directory list item. +*/ +QtxPagePrefPathsItem::QtxPagePrefPathsItem( QtxPreferenceItem* parent, const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( QString(), parent, sect, param ) +{ + setControl( myPaths = new QtxPathListEdit() ); +} + +QtxPagePrefPathsItem::QtxPagePrefPathsItem( const int mode, const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myPaths = new QtxPathListEdit( mode ) ); +} + +QtxPagePrefPathsItem::QtxPagePrefPathsItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( myPaths = new QtxPathListEdit() ); +} + +QtxPagePrefPathsItem::~QtxPagePrefPathsItem() +{ +} + +int QtxPagePrefPathsItem::mode() const +{ + return myPaths->mode(); +} + +void QtxPagePrefPathsItem::setMode( const int mode ) +{ + myPaths->setMode( mode ); +} + +void QtxPagePrefPathsItem::store() +{ + setString( myPaths->pathList().join( ";" ) ); +} + +void QtxPagePrefPathsItem::retrieve() +{ + myPaths->setPathList( getString().split( ";" ) ); +} + +QVariant QtxPagePrefPathsItem::optionValue( const QString& name ) const +{ + if ( name == "mode" ) + return mode(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +void QtxPagePrefPathsItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( name == "mode" ) + { + if ( val.canConvert( QVariant::Int ) ) + setMode( val.toInt() ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h new file mode 100644 index 000000000..aa8c0f95b --- /dev/null +++ b/src/Qtx/QtxPagePrefMgr.h @@ -0,0 +1,621 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxPagePrefMgr.h +// Author: Sergey TELKOV + +#ifndef QTXPAGEPREFMGR_H +#define QTXPAGEPREFMGR_H + +#include "QtxPreferenceMgr.h" + +#include "QtxPathEdit.h" +#include "QtxPathListEdit.h" + +#include +#include +#include + +class QtxGridBox; +class QtxFontEdit; +class QtxGroupBox; +class QtxComboBox; +class QtxColorButton; + +class QLineEdit; +class QTextEdit; +class QCheckBox; +class QTabWidget; +class QToolButton; +class QListWidget; +class QFileDialog; +class QStackedWidget; + +/*! + \class QtxPagePrefMgr + GUI implementation of QtxPreferenceMgr - manager of preferences +*/ + +class QTX_EXPORT QtxPagePrefMgr : public QFrame, public QtxPreferenceMgr +{ + Q_OBJECT + +public: + QtxPagePrefMgr( QtxResourceMgr*, QWidget* = 0 ); + virtual ~QtxPagePrefMgr(); + + virtual QSize sizeHint() const; + virtual QSize minimumSizeHint() const; + + virtual void updateContents(); + +signals: + void resourceChanged( int ); + void resourceChanged( QString&, QString& ); + void resourcesChanged( const QMap& ); + +public slots: + virtual void setVisible( bool ); + +protected: + virtual void itemAdded( QtxPreferenceItem* ); + virtual void itemRemoved( QtxPreferenceItem* ); + virtual void itemChanged( QtxPreferenceItem* ); + + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void initialize() const; + +private: + QtxGridBox* myBox; + bool myInit; +}; + +/*! + \class QtxPagePrefItem + Base class for implementation of the preference items +*/ +class QTX_EXPORT QtxPagePrefItem : public QtxPreferenceItem +{ +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* ); + + virtual void itemAdded( QtxPreferenceItem* ); + virtual void itemRemoved( QtxPreferenceItem* ); + virtual void itemChanged( QtxPreferenceItem* ); + + void pageChildItems( QList&, const bool = false ) const; + + virtual void store(); + virtual void retrieve(); + +private: + virtual void contentChanged(); + +private: + QPointer myWidget; +}; + +/*! + \class QtxPageNamedPrefItem + Base class for implementation of the named preference items (items with text labels). +*/ +class QTX_EXPORT QtxPageNamedPrefItem : public QtxPagePrefItem +{ +public: + QtxPageNamedPrefItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPageNamedPrefItem(); + + virtual void setTitle( const QString& ); + +protected: + QLabel* label() const; + QWidget* control() const; + + void setControl( QWidget* ); + +private: + QPointer myLabel; + QPointer myControl; +}; + +/*! + \class QtxPagePrefListItem + GUI implementation of listed container. +*/ +class QTX_EXPORT QtxPagePrefListItem : public QObject, public QtxPagePrefItem +{ + Q_OBJECT + +public: + QtxPagePrefListItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefListItem(); + + virtual void updateContents(); + + QString emptyInfo() const; + void setEmptyInfo( const QString& ); + + bool isFixedSize() const; + void setFixedSize( const bool ); + +private slots: + void onItemSelectionChanged(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateInfo(); + void updateGeom(); + void updateState(); + void updateVisible(); + + int selected() const; + QtxPagePrefItem* selectedItem() const; + void setSelected( const int ); + +private: + bool myFix; + QListWidget* myList; + QStackedWidget* myStack; + + QString myInfText; + QLabel* myInfLabel; +}; + +/*! + \class QtxPagePrefTabsItem + GUI implementation of tab widget container. +*/ +class QTX_EXPORT QtxPagePrefTabsItem : public QtxPagePrefItem +{ +public: + QtxPagePrefTabsItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefTabsItem(); + + virtual void updateContents(); + + int tabPosition() const; + void setTabPosition( const int ); + + int tabShape() const; + void setTabShape( const int ); + + QSize tabIconSize() const; + void setTabIconSize( const QSize& ); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateTabs(); + +private: + QTabWidget* myTabs; +}; + +/*! + \class QtxPagePrefFrameItem + GUI implementation of frame container. +*/ +class QTX_EXPORT QtxPagePrefFrameItem : public QtxPagePrefItem +{ +public: + QtxPagePrefFrameItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefFrameItem(); + + virtual void updateContents(); + + int margin() const; + void setMargin( const int ); + + int spacing() const; + void setSpacing( const int ); + + int columns() const; + void setColumns( const int ); + + Qt::Orientation orientation() const; + void setOrientation( const Qt::Orientation ); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateFrame(); + +private: + QtxGridBox* myBox; +}; + +/*! + \class QtxPagePrefGroupItem + GUI implementation of group container. +*/ +class QTX_EXPORT QtxPagePrefGroupItem : public QtxPagePrefItem +{ +public: + QtxPagePrefGroupItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefGroupItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefGroupItem(); + + virtual void updateContents(); + + int margin() const; + void setMargin( const int ); + + int spacing() const; + void setSpacing( const int ); + + int columns() const; + void setColumns( const int ); + + Qt::Orientation orientation() const; + void setOrientation( const Qt::Orientation ); + + bool isFlat() const; + void setFlat( const bool ); + + virtual void setResource( const QString&, const QString& ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateState(); + void updateGroup(); + +private: + QtxGridBox* myBox; + QtxGroupBox* myGroup; +}; + +/*! + \class QtxPagePrefSpaceItem +*/ +class QTX_EXPORT QtxPagePrefSpaceItem : public QtxPagePrefItem +{ +public: + QtxPagePrefSpaceItem( QtxPreferenceItem* = 0 ); + QtxPagePrefSpaceItem( Qt::Orientation, QtxPreferenceItem* = 0 ); + QtxPagePrefSpaceItem( const int, const int, QtxPreferenceItem* = 0 ); + virtual ~QtxPagePrefSpaceItem(); + + int size( Qt::Orientation ) const; + void setSize( Qt::Orientation, const int ); + + int stretch( Qt::Orientation ) const; + void setStretch( Qt::Orientation, const int ); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void initialize( const int, const int, const int, const int ); +}; + +/*! + \class QtxPagePrefCheckItem + GUI implementation of resources check item (bool). +*/ +class QTX_EXPORT QtxPagePrefCheckItem : public QtxPagePrefItem +{ +public: + QtxPagePrefCheckItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefCheckItem(); + + virtual void setTitle( const QString& ); + + virtual void store(); + virtual void retrieve(); + +private: + QCheckBox* myCheck; +}; + +/*! + \class QtxPagePrefEditItem + GUI implementation of resources line edit item (string, integer, double). +*/ +class QTX_EXPORT QtxPagePrefEditItem : public QtxPageNamedPrefItem +{ +public: + typedef enum { String, Integer, Double } InputType; + +public: + QtxPagePrefEditItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefEditItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefEditItem(); + + int inputType() const; + void setInputType( const type ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateEditor(); + +private: + int myType; + QLineEdit* myEditor; +}; + +/*! + \class QtxPagePrefSelectItem + GUI implementation of resources selector item (enum). +*/ + +class QTX_EXPORT QtxPagePrefSelectItem : public QtxPageNamedPrefItem +{ +public: + typedef enum { NoInput, String, Integer, Double } InputType; + +public: + QtxPagePrefSelectItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefSelectItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefSelectItem(); + + int inputType() const; + void setInputType( const type ); + + QStringList strings() const; + QList numbers() const; + + void setStrings( const QStringList& ); + void setNumbers( const QList& ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateSelector(); + void setStrings( const QVariant& ); + void setNumbers( const QVariant& ); + +private: + int myType; + QtxComboBox* mySelector; +}; + +/*! + \class QtxPagePrefSpinItem + GUI implementation of resources spin box item (integer, double). +*/ +class QTX_EXPORT QtxPagePrefSpinItem : public QtxPageNamedPrefItem +{ +public: + typedef enum { Integer, Double } InputType; + +public: + QtxPagePrefSpinItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefSpinItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefSpinItem(); + + QVariant step() const; + QVariant minimum() const; + QVariant maximum() const; + + QString prefix() const; + QString suffix() const; + QString specialValueText() const; + + void setStep( const QVariant& ); + void setMinimum( const QVariant& ); + void setMaximum( const QVariant& ); + + void setPrefix( const QString& ); + void setSuffix( const QString& ); + void setSpecialValueText( const QString& ); + + int inputType() const; + void setInputType( const type ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateSpinBox(); + +private: + int myType; +}; + +/*! + \class QtxPagePrefTextItem + GUI implementation of resources text edit item (text - several strings). +*/ +class QTX_EXPORT QtxPagePrefTextItem : public QtxPageNamedPrefItem +{ +public: + QtxPagePrefTextItem( QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefTextItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefTextItem(); + + virtual void store(); + virtual void retrieve(); + +private: + QTextEdit* myEditor; +}; + +/*! + \class QtxPagePrefColorItem + GUI implementation of resources color item. +*/ +class QTX_EXPORT QtxPagePrefColorItem : public QtxPageNamedPrefItem +{ +public: + QtxPagePrefColorItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefColorItem(); + + virtual void store(); + virtual void retrieve(); + +private: + QtxColorButton* myColor; +}; + +/*! + \class QtxPagePrefFontItem + GUI implementation of resources font item. +*/ +class QTX_EXPORT QtxPagePrefFontItem : public QObject, public QtxPageNamedPrefItem +{ + Q_OBJECT + +public: + QtxPagePrefFontItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefFontItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefFontItem(); + + int features() const; + void setFeatures( const int ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + QtxFontEdit* myFont; +}; + +/*! + \class QtxPagePrefPathItem + GUI implementation of resources path item. +*/ +class QTX_EXPORT QtxPagePrefPathItem : public QtxPageNamedPrefItem +{ +public: + typedef enum { OpenFile = QtxPathEdit::OpenFile, + SaveFile = QtxPathEdit::SaveFile, + Directory = QtxPathEdit::Directory } Mode; + +public: + QtxPagePrefPathItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefPathItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefPathItem(); + + int mode() const; + void setMode( const int ); + + QString filter() const; + void setFilter( const QString& ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + QtxPathEdit* myPath; +}; + +/*! + \class QtxPagePrefPathsItem + \brief GUI implementation of resources directory list item. +*/ +class QTX_EXPORT QtxPagePrefPathsItem : public QtxPageNamedPrefItem +{ +public: + typedef enum { File = QtxPathListEdit::File, + Directory = QtxPathListEdit::Directory } Mode; + +public: + QtxPagePrefPathsItem( QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefPathsItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + QtxPagePrefPathsItem( const int, const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefPathsItem(); + + int mode() const; + void setMode( const int ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + QtxPathListEdit* myPaths; +}; + +#endif diff --git a/src/Qtx/QtxPathEdit.cxx b/src/Qtx/QtxPathEdit.cxx new file mode 100644 index 000000000..aa31f4fe8 --- /dev/null +++ b/src/Qtx/QtxPathEdit.cxx @@ -0,0 +1,168 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxPathEdit.cxx +// Author: Sergey TELKOV + +#include "QtxPathEdit.h" + +#include +#include +#include +#include +#include +#include +#include + +QtxPathEdit::QtxPathEdit( const int mode, QWidget* parent ) +: QFrame( parent ), +myMode( mode ) +{ + initialize(); +} + +QtxPathEdit::QtxPathEdit( QWidget* parent ) +: QFrame( parent ), +myMode( OpenFile ) +{ + initialize(); +} + +QtxPathEdit::~QtxPathEdit() +{ +} + +int QtxPathEdit::mode() const +{ + return myMode; +} + +void QtxPathEdit::setMode( const int mode ) +{ + if ( myMode == mode ) + return; + + myMode = mode; + updateState(); +} + +QString QtxPathEdit::path() const +{ + return myPath->text(); +} + +void QtxPathEdit::setPath( const QString& txt ) +{ + myPath->setText( txt ); +} + +QString QtxPathEdit::filter() const +{ + return myFilter; +} + +void QtxPathEdit::setFilter( const QString& f ) +{ + if ( myFilter == f ) + return; + + myFilter = f; + updateState(); +} + +void QtxPathEdit::onBrowse( bool ) +{ + QString path; + QString initial = QFileInfo( myPath->text() ).path(); + switch ( mode() ) + { + case OpenFile: + path = QFileDialog::getOpenFileName( myPath, QString(), initial, filter() ); + break; + case SaveFile: + path = QFileDialog::getSaveFileName( myPath, QString(), initial, filter() ); + break; + case Directory: + path = QFileDialog::getExistingDirectory( myPath, QString(), initial ); + break; + } + + if ( !path.isEmpty() ) + myPath->setText( QDir::convertSeparators( path ) ); + + myPath->setFocus(); +} + +QLineEdit* QtxPathEdit::lineEdit() const +{ + return myPath; +} + +void QtxPathEdit::initialize() +{ + QHBoxLayout* base = new QHBoxLayout( this ); + base->setMargin( 0 ); + base->setSpacing( 5 ); + + base->addWidget( myPath = new QLineEdit( this ) ); + myPath->setValidator( new QRegExpValidator( QRegExp( "^([\\w/]{2}|[A-Z]:)[^:;\\*\\?]*[\\w\\\\/\\.]$" ), myPath ) ); + + QToolButton* browse = new QToolButton( this ); + browse->setText( "..." ); + base->addWidget( browse ); + + connect( browse, SIGNAL( clicked( bool ) ), this, SLOT( onBrowse( bool ) ) ); + + setFocusProxy( myPath ); + + updateState(); +} + +void QtxPathEdit::updateState() +{ + QStringList extList; + QStringList filterList = filter().split( ";;" ); + for ( QStringList::const_iterator it = filterList.begin(); it != filterList.end(); ++it ) + { + QRegExp rx( "[\\s\\w,;]*\\(?\\*\\.([\\w]+)\\)?[\\d\\s\\w]*" ); + int index = 0; + while ( ( index = rx.indexIn( *it, index ) ) != -1 ) + { + extList.append( QString( "*.%1" ).arg( rx.cap( 1 ) ) ); + index += rx.matchedLength(); + } + } + + QDir::Filters filters = 0; + switch ( mode() ) + { + case OpenFile: + case SaveFile: + filters = QDir::AllEntries | QDir::AllDirs | QDir::NoDotAndDotDot; + break; + case Directory: + filters = QDir::Drives | QDir::Dirs | QDir::NoDotAndDotDot; + break; + } + + QDirModel* dm = new QDirModel( extList, filters, QDir::Unsorted ); + QCompleter* cmp = new QCompleter( dm, myPath ); + dm->setParent( cmp ); + + myPath->setCompleter( cmp ); +} diff --git a/src/Qtx/QtxPathEdit.h b/src/Qtx/QtxPathEdit.h new file mode 100644 index 000000000..ff74539d1 --- /dev/null +++ b/src/Qtx/QtxPathEdit.h @@ -0,0 +1,68 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxPathEdit.h +// Author: Sergey TELKOV + +#ifndef QTXPATHEDIT_H +#define QTXPATHEDIT_H + +#include "Qtx.h" + +#include + +class QLineEdit; + +class QTX_EXPORT QtxPathEdit : public QFrame +{ + Q_OBJECT + +public: + typedef enum { OpenFile, SaveFile, Directory } Mode; + +public: + QtxPathEdit( const int, QWidget* = 0 ); + QtxPathEdit( QWidget* = 0 ); + virtual ~QtxPathEdit(); + + int mode() const; + void setMode( const int ); + + QString path() const; + void setPath( const QString& ); + + QString filter() const; + void setFilter( const QString& ); + +private slots: + void onBrowse( bool = false ); + +protected: + QLineEdit* lineEdit() const; + +private: + void initialize(); + void updateState(); + +private: + int myMode; + QLineEdit* myPath; + QString myFilter; +}; + +#endif diff --git a/src/Qtx/QtxPathListEdit.cxx b/src/Qtx/QtxPathListEdit.cxx new file mode 100644 index 000000000..5766eff74 --- /dev/null +++ b/src/Qtx/QtxPathListEdit.cxx @@ -0,0 +1,536 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "QtxPathListEdit.h" + +#include "QtxPathEdit.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char* delete_icon[] = { +"16 16 3 1", +"` c #810000", +" c none", +"# c #ffffff", +" ", +" ", +" ``# ``# ", +" ````# ``# ", +" ````# ``# ", +" ```# `# ", +" `````# ", +" ```# ", +" `````# ", +" ```# ``# ", +" ```# ``# ", +" ```# `# ", +" ```# `# ", +" `# `# ", +" ", +" " +}; + +static const char* insert_icon[] = { +"16 16 5 1", +"` c #000000", +". c #ffff00", +"# c #9d9da1", +" c none", +"b c #ffffff", +" ", +" ", +" # #b #. ", +" # #.#.` ` ` ", +" .#.b#### ` ", +" ### .. ", +" . # .# ` ", +" #` #. ", +" # ` ", +" ` ", +" ` ", +" ` ", +" ` ", +" ` ` ` ` ` ` ", +" ", +" " +}; + +static const char* movedown_icon[] = { +"16 16 2 1", +"` c #000000", +" c none", +" ", +" ", +" ``` ", +" ``` ", +" ``` ", +" ``` ", +" ``` ", +" ``` ", +" ``````````` ", +" ````````` ", +" ``````` ", +" ````` ", +" ``` ", +" ` ", +" ", +" " +}; + +static const char* moveup_icon[] = { +"16 16 2 1", +"` c #000000", +" c none", +" ", +" ", +" ` ", +" ``` ", +" ````` ", +" ``````` ", +" ````````` ", +" ``````````` ", +" ``` ", +" ``` ", +" ``` ", +" ``` ", +" ``` ", +" ``` ", +" ", +" " +}; + +/*! + \class QtxPathListEdit::Editor +*/ +class QtxPathListEdit::Editor : public QtxPathEdit +{ +public: + Editor( QWidget* parent = 0 ) : QtxPathEdit( parent ) + { + layout()->setSpacing( 0 ); + lineEdit()->setFrame( false ); + } + + virtual ~Editor() {} +}; + +/*! + \class QtxPathListEdit::Delegate +*/ +class QtxPathListEdit::Delegate : public QItemDelegate +{ +public: + Delegate( QtxPathListEdit*, QObject* = 0 ); + virtual ~Delegate(); + + virtual QWidget* createEditor( QWidget*, const QStyleOptionViewItem&, const QModelIndex& ) const; + virtual void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const; + virtual void setEditorData( QWidget*, const QModelIndex& ) const; + virtual void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const; + +protected: + virtual void drawFocus( QPainter*, const QStyleOptionViewItem&, const QRect& ) const; + +private: + QtxPathListEdit* myPathEdit; +}; + +QtxPathListEdit::Delegate::Delegate( QtxPathListEdit* pe, QObject* parent ) +: QItemDelegate( parent ), +myPathEdit( pe ) +{ +} + +QtxPathListEdit::Delegate::~Delegate() +{ +} + +QWidget* QtxPathListEdit::Delegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, + const QModelIndex& index ) const +{ + return myPathEdit->createEditor( parent ); +} + +void QtxPathListEdit::Delegate::setModelData( QWidget* editor, QAbstractItemModel* model, + const QModelIndex& index ) const +{ + myPathEdit->setModelData( editor, index ); +} + +void QtxPathListEdit::Delegate::setEditorData( QWidget* editor, const QModelIndex& index ) const +{ + myPathEdit->setEditorData( editor, index ); +} + +void QtxPathListEdit::Delegate::paint( QPainter* painter, const QStyleOptionViewItem& option, + const QModelIndex& index ) const +{ + QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; + if ( cg == QPalette::Normal && !( option.state & QStyle::State_Active ) ) + cg = QPalette::Inactive; + + if ( option.state & QStyle::State_Selected ) + { + painter->fillRect( option.rect, option.palette.brush( cg, QPalette::Highlight ) ); + painter->setPen( option.palette.color( cg, QPalette::HighlightedText ) ); + } + else + painter->setPen( option.palette.color( cg, QPalette::Text ) ); + + QItemDelegate::paint( painter, option, index ); +} + +void QtxPathListEdit::Delegate::drawFocus( QPainter* painter, const QStyleOptionViewItem& option, + const QRect& rect ) const +{ + QItemDelegate::drawFocus( painter, option, option.rect ); +} + +/*! + \class QtxPathListEdit +*/ +QtxPathListEdit::QtxPathListEdit( const int mode, QWidget* parent ) +: QFrame( parent ), +myCompleter( 0 ), +myMode( mode ) +{ + initialize(); +} + +QtxPathListEdit::QtxPathListEdit( QWidget* parent ) +: QFrame( parent ), +myCompleter( 0 ), +myMode( File ) +{ + initialize(); +} + +/*! + Destructor +*/ +QtxPathListEdit::~QtxPathListEdit() +{ +} + +int QtxPathListEdit::mode() const +{ + return myMode; +} + +void QtxPathListEdit::setMode( const int m ) +{ + if ( myMode == m ) + return; + + myMode = m; + delete myCompleter; + myCompleter = 0; +} + +QStringList QtxPathListEdit::pathList() const +{ + return myModel->stringList(); +} + +void QtxPathListEdit::setPathList( const QStringList& lst ) +{ + myModel->setStringList( lst ); +} + +int QtxPathListEdit::count() const +{ + return myModel->rowCount(); +} + +bool QtxPathListEdit::contains( const QString& path ) const +{ + return myModel->stringList().contains( path ); +} + +void QtxPathListEdit::clear() +{ + myModel->removeRows( 0, myModel->rowCount() ); +} + +void QtxPathListEdit::remove( const int idx ) +{ + if ( 0 <= idx && idx < myModel->rowCount() ) + myModel->removeRow( idx ); +} + +void QtxPathListEdit::remove( const QString& path ) +{ + QModelIndexList indexes = myModel->match( myModel->index( 0, 0 ), Qt::DisplayRole, path, + myModel->rowCount(), Qt::MatchExactly | Qt::MatchCaseSensitive ); + while ( !indexes.isEmpty() ) + { + myModel->removeRow( indexes.last().row() ); + indexes.removeLast(); + } +} + +void QtxPathListEdit::insert( const QString& path, const int idx ) +{ + int index = idx < 0 ? myModel->rowCount() : qMin( idx, myModel->rowCount() ); + if ( myModel->insertRow( index ) ) + myModel->setData( myModel->index( index, 0 ), path, Qt::EditRole ); +} + +/*! + Validates entered path, returns true if OK +*/ +/* +bool QtxPathListEdit::validate( const bool quietMode ) +{ + if ( myEdited ) + { + QString dirPath = QFileInfo( myEdit->text().stripWhiteSpace() ).filePath(); + QDir dir(dirPath); + QListBoxItem* found = 0; + for (unsigned i = 0; i < myList->count()-1; i++) { + QDir aDir(myList->text(i)); + if ( aDir.canonicalPath().isNull() && myList->text(i) == dir.absPath() || + !aDir.canonicalPath().isNull() && aDir.exists() && aDir.canonicalPath() == dir.canonicalPath()) { + found = myList->item(i); + break; + } + } + if (dirPath.isEmpty()) { + if (found) { + // it should be last (empty) item in the list - nothing to do + return true; + } + else { + // delete directory from the list + removeDir(myLastSelected); + return true; + } + } + else { + if (found) { + if (found != myLastSelected) { + // it is forbidden to add directory more then once + if ( !quietMode ) + QMessageBox::critical(this, + tr("Error"), + tr("Directory already specified."), + tr("Ok")); + myEdit->setFocus(); + return false; + } + } + else { + if (!dir.exists()) { + if ( !quietMode && QMessageBox::information(this, + tr("Warning"), + tr("%1\n\nThe directory doesn't exist.\nAdd directory anyway?").arg(dir.absPath()), + tr("Yes"), tr("No"), QString::null, 1, 1) == 1) { + myEdit->setFocus(); + return false; + } + } + // append + appendDir(myLastSelected, dir.absPath()); + } + } + } + return true; +} +*/ +/*! + Event filter +*/ +bool QtxPathListEdit::eventFilter( QObject* o, QEvent* e ) +{ + if ( e->type() == QEvent::KeyPress ) + { + QKeyEvent* ke = (QKeyEvent*)e; + if ( ke->key() == Qt::Key_Delete ) + onDelete(); + else if ( ke->key() == Qt::Key_Insert ) + onInsert(); + else if ( ke->key() == Qt::Key_Up && ke->modifiers() == Qt::CTRL ) + { + onUp(); + return true; + } + else if ( ke->key() == Qt::Key_Down && ke->modifiers() == Qt::CTRL ) + { + onDown(); + return true; + } + } + + return QFrame::eventFilter( o, e ); +} + +/*! + button slot +*/ + +void QtxPathListEdit::onInsert( bool ) +{ + myModel->insertRows( myModel->rowCount(), 1 ); + QModelIndex idx = myModel->index( myModel->rowCount() - 1, 0 ); + myList->setCurrentIndex( idx ); + myList->edit( idx ); +} + +/*! + button slot +*/ +void QtxPathListEdit::onDelete( bool ) +{ + QModelIndex idx = myList->currentIndex(); + if ( !idx.isValid() ) + return; + + myModel->removeRow( idx.row() ); +} + +/*! + button slot +*/ +void QtxPathListEdit::onUp( bool ) +{ + QModelIndex idx = myList->currentIndex(); + if ( !idx.isValid() || idx.row() < 1 ) + return; + + QModelIndex toIdx = myModel->index( idx.row() - 1, 0 ); + + QVariant val = myModel->data( toIdx, Qt::DisplayRole ); + myModel->setData( toIdx, myModel->data( idx, Qt::DisplayRole ), Qt::DisplayRole ); + myModel->setData( idx, val, Qt::DisplayRole ); + + myList->setCurrentIndex( toIdx ); +} + +/*! + button slot +*/ +void QtxPathListEdit::onDown( bool ) +{ + QModelIndex idx = myList->currentIndex(); + if ( !idx.isValid() || idx.row() >= myModel->rowCount() - 1 ) + return; + + QModelIndex toIdx = myModel->index( idx.row() + 1, 0 ); + + QVariant val = myModel->data( toIdx, Qt::DisplayRole ); + myModel->setData( toIdx, myModel->data( idx, Qt::DisplayRole ), Qt::DisplayRole ); + myModel->setData( idx, val, Qt::DisplayRole ); + + myList->setCurrentIndex( toIdx ); +} + +void QtxPathListEdit::initialize() +{ + QVBoxLayout* base = new QVBoxLayout( this ); + base->setMargin( 0 ); + base->setSpacing( 5 ); + + QWidget* cBox = new QWidget( this ); + base->addWidget( cBox ); + + QHBoxLayout* cLayout = new QHBoxLayout( cBox ); + cLayout->setMargin( 0 ); + cLayout->setSpacing( 0 ); + + cLayout->addStretch( 1 ); + + QToolButton* insertBtn = new QToolButton( cBox ); + insertBtn->setIcon( QPixmap( insert_icon ) ); + cLayout->addWidget( insertBtn ); + + QToolButton* deleteBtn = new QToolButton( cBox ); + deleteBtn->setIcon( QPixmap( delete_icon ) ); + cLayout->addWidget( deleteBtn ); + + QToolButton* upBtn = new QToolButton( cBox ); + upBtn->setIcon( QPixmap( moveup_icon ) ); + cLayout->addWidget( upBtn ); + + QToolButton* downBtn = new QToolButton( cBox ); + downBtn->setIcon( QPixmap( movedown_icon ) ); + cLayout->addWidget( downBtn ); + + + myList = new QListView( this ); + myList->setAlternatingRowColors( true ); + myList->setItemDelegate( new Delegate( this, myList ) ); + myList->setModel( myModel = new QStringListModel( myList ) ); + myList->setSelectionMode( QListView::SingleSelection ); + myList->setSelectionBehavior( QListView::SelectRows ); + myList->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + myList->installEventFilter( this ); + + base->addWidget( myList ); + + connect( insertBtn, SIGNAL( clicked( bool ) ), this, SLOT( onInsert( bool ) ) ); + connect( deleteBtn, SIGNAL( clicked( bool ) ), this, SLOT( onDelete( bool ) ) ); + connect( upBtn, SIGNAL( clicked( bool ) ), this, SLOT( onUp( bool ) ) ); + connect( downBtn, SIGNAL( clicked( bool ) ), this, SLOT( onDown( bool ) ) ); +} + +QWidget* QtxPathListEdit::createEditor( QWidget* parent ) +{ + QtxPathEdit* edit = new Editor( parent ); + switch ( mode() ) + { + case File: + edit->setMode( QtxPathEdit::OpenFile ); + break; + case Directory: + edit->setMode( QtxPathEdit::Directory ); + break; + } + + return edit; +} + +void QtxPathListEdit::setModelData( QWidget* editor, const QModelIndex& index ) +{ + QtxPathEdit* edit = ::qobject_cast( editor ); + if ( !edit ) + return; + + myModel->setData( index, edit->path(), Qt::EditRole ); +} + +void QtxPathListEdit::setEditorData( QWidget* editor, const QModelIndex& index ) +{ + QtxPathEdit* edit = ::qobject_cast( editor ); + if ( !edit ) + return; + + QVariant v = myModel->data( index, Qt::EditRole ); + edit->setPath( v.toString() ); +} diff --git a/src/Qtx/QtxPathListEdit.h b/src/Qtx/QtxPathListEdit.h new file mode 100644 index 000000000..2cb7f81af --- /dev/null +++ b/src/Qtx/QtxPathListEdit.h @@ -0,0 +1,90 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef QTX_PATHLISTEDIT_H +#define QTX_PATHLISTEDIT_H + +#include "Qtx.h" + +#include +#include + +class QLineEdit; +class QListView; +class QCompleter; +class QModelIndex; +class QToolButton; +class QStringListModel; + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +class QTX_EXPORT QtxPathListEdit : public QFrame +{ + Q_OBJECT + + class Editor; + class Delegate; + +public: + typedef enum { File, Directory } PathMode; + +public: + QtxPathListEdit( const int, QWidget* = 0 ); + QtxPathListEdit( QWidget* = 0 ); + virtual ~QtxPathListEdit(); + + int mode() const; + void setMode( const int ); + + QStringList pathList() const; + void setPathList( const QStringList& ); + + int count() const; + bool contains( const QString& ) const; + + void clear(); + void remove( const int ); + void remove( const QString& ); + void insert( const QString&, const int = -1 ); + + bool eventFilter( QObject*, QEvent* ); + +protected slots: + void onUp( bool = false ); + void onDown( bool = false ); + void onInsert( bool = false ); + void onDelete( bool = false ); + +private: + void initialize(); + QWidget* createEditor( QWidget* ); + void setModelData( QWidget*, const QModelIndex& ); + void setEditorData( QWidget*, const QModelIndex& ); + +private: + int myMode; + QListView* myList; + QStringListModel* myModel; + QCompleter* myCompleter; + + friend class QtxPathListEdit::Delegate; +}; + +#endif diff --git a/src/Qtx/QtxPreferenceMgr.cxx b/src/Qtx/QtxPreferenceMgr.cxx new file mode 100644 index 000000000..7a73095f3 --- /dev/null +++ b/src/Qtx/QtxPreferenceMgr.cxx @@ -0,0 +1,896 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxPreferenceMgr.cxx +// Author: Sergey TELKOV + +#include "QtxPreferenceMgr.h" + +#include "QtxResourceMgr.h" + +#include +#include + +/*! + \class QtxPreferenceItem::Updater + Class for incapsulation of one preference item +*/ + +class QtxPreferenceItem::Updater : public QObject +{ +public: + Updater(); + ~Updater(); + + static Updater* instance(); + + void updateItem( QtxPreferenceItem* ); + void removeItem( QtxPreferenceItem* ); + +protected: + virtual void customEvent( QEvent* ); + +private: + QList myItems; + static Updater* _Updater; +}; + +QtxPreferenceItem::Updater* QtxPreferenceItem::Updater::_Updater = 0; + +QtxPreferenceItem::Updater::Updater() +{ +} + +QtxPreferenceItem::Updater::~Updater() +{ +} + +QtxPreferenceItem::Updater* QtxPreferenceItem::Updater::instance() +{ + if ( !_Updater ) + _Updater = new Updater(); + return _Updater; +} + +void QtxPreferenceItem::Updater::updateItem( QtxPreferenceItem* item ) +{ + if ( !item || myItems.contains( item ) ) + return; + + myItems.append( item ); + QApplication::postEvent( this, new QEvent( QEvent::User ) ); +} + +void QtxPreferenceItem::Updater::removeItem( QtxPreferenceItem* item ) +{ + myItems.removeAll( item ); +} + +void QtxPreferenceItem::Updater::customEvent( QEvent* e ) +{ + QList lst = myItems; + for ( QList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + (*it)->updateContents(); +} + +/*! + \class QtxPreferenceItem + Class for incapsulation of one preference item +*/ + + +/*! + Constructor +*/ +QtxPreferenceItem::QtxPreferenceItem( QtxPreferenceItem* parent ) +: myParent( 0 ) +{ + myId = generateId(); + + if ( parent ) + parent->insertItem( this ); +} + +QtxPreferenceItem::QtxPreferenceItem( const QString& title, QtxPreferenceItem* parent ) +: myParent( 0 ), +myTitle( title ) +{ + myId = generateId(); + + if ( parent ) + parent->insertItem( this ); +} + +QtxPreferenceItem::QtxPreferenceItem( const QString& title, const QString& sect, + const QString& param, QtxPreferenceItem* parent ) +: myParent( 0 ), +myTitle( title ), +mySection( sect ), +myParameter( param ) +{ + myId = generateId(); + + if ( parent ) + parent->insertItem( this ); +} + +/*! + Destructor +*/ +QtxPreferenceItem::~QtxPreferenceItem() +{ + ItemList list = myChildren; + myChildren.clear(); + qDeleteAll( list ); + + if ( myParent ) + myParent->removeItem( this ); + + Updater::instance()->removeItem( this ); +} + +/*! + \return id of item +*/ +int QtxPreferenceItem::id() const +{ + return myId; +} + +int QtxPreferenceItem::rtti() const +{ + return QtxPreferenceItem::RTTI(); +} + +int QtxPreferenceItem::RTTI() +{ + return 1; +} + +/*! + \return root item +*/ +QtxPreferenceItem* QtxPreferenceItem::rootItem() const +{ + QtxPreferenceItem* item = (QtxPreferenceItem*)this; + while ( item->parentItem() ) + item = item->parentItem(); + return item; +} + +/*! + \return parent item +*/ +QtxPreferenceItem* QtxPreferenceItem::parentItem() const +{ + return myParent; +} + +/*! + Appends child and (if necessary) removes item from old parent + \param item - item to be added +*/ +void QtxPreferenceItem::insertItem( QtxPreferenceItem* item ) +{ + if ( !item || myChildren.contains( item ) ) + return; + + if ( item->parentItem() && item->parentItem() != this ) + item->parentItem()->removeItem( item ); + + item->myParent = this; + myChildren.append( item ); + + itemAdded( item ); +} + +/*! + Removes child + \param item - item to be removed +*/ +void QtxPreferenceItem::removeItem( QtxPreferenceItem* item ) +{ + if ( !item || !myChildren.contains( item ) ) + return; + + item->myParent = 0; + myChildren.removeAll( item ); + + itemRemoved( item ); +} + +/*! + Fills list with children items + \param lst - list to be filled with +*/ +QList QtxPreferenceItem::childItems( const bool rec ) const +{ + QList lst = myChildren; + if ( rec ) + { + for ( ItemList::const_iterator it = myChildren.begin(); it != myChildren.end(); ++it ) + lst += (*it)->childItems( rec ); + } + + return lst; +} + +int QtxPreferenceItem::depth() const +{ + return parentItem() ? parentItem()->depth() + 1 : 0; +} + +int QtxPreferenceItem::count() const +{ + return myChildren.count(); +} + +/*! + \return true if there is no children of this item +*/ +bool QtxPreferenceItem::isEmpty() const +{ + return myChildren.isEmpty(); +} + +/*! + \return icon of item +*/ +QIcon QtxPreferenceItem::icon() const +{ + return myIcon; +} + +/*! + \return title of item +*/ +QString QtxPreferenceItem::title() const +{ + return myTitle; +} + +/*! + \return assigned resource placement + \param sec - to return section + \param param - to return param name +*/ +void QtxPreferenceItem::resource( QString& sec, QString& param ) const +{ + sec = mySection; + param = myParameter; +} + +/*! + Sets item icon + \param ico - new item icon +*/ +void QtxPreferenceItem::setIcon( const QIcon& ico ) +{ + if ( myIcon.serialNumber() == ico.serialNumber() ) + return; + + myIcon = ico; + sendItemChanges(); +} + +/*! + Sets item title + \param title - new item title +*/ +void QtxPreferenceItem::setTitle( const QString& title ) +{ + if ( myTitle == title ) + return; + + myTitle = title; + sendItemChanges(); +} + +/*! + Assigns new resource to item + \param sec - section + \param sec - param name +*/ +void QtxPreferenceItem::setResource( const QString& sec, const QString& param ) +{ + mySection = sec; + myParameter = param; +} + +/*! + Updates item (default implementation is empty) +*/ +void QtxPreferenceItem::updateContents() +{ + Updater::instance()->removeItem( this ); +} + +/*! + \return property value +*/ +QVariant QtxPreferenceItem::option( const QString& name ) const +{ + return optionValue( name.toLower() ); +} + +/*! + Sets property value +*/ +void QtxPreferenceItem::setOption( const QString& name, const QVariant& val ) +{ + QVariant old = optionValue( name.toLower() ); + setOptionValue( name.toLower(), val ); + if ( old != optionValue( name.toLower() ) ) + sendItemChanges(); +} + +/*! + \return value of assigned resource +*/ +QString QtxPreferenceItem::resourceValue() const +{ + return getString(); +} + +/*! + Sets value of assigned resource + \param val - new value +*/ +void QtxPreferenceItem::setResourceValue( const QString& val ) +{ + setString( val ); +} + +/*! + \return corresponding resource manager +*/ +QtxResourceMgr* QtxPreferenceItem::resourceMgr() const +{ + QtxPreferenceMgr* mgr = preferenceMgr(); + return mgr ? mgr->resourceMgr() : 0; +} + +/*! + \return corresponding resource edit +*/ +QtxPreferenceMgr* QtxPreferenceItem::preferenceMgr() const +{ + return parentItem() ? parentItem()->preferenceMgr() : 0; +} + +/*! + \return other item + \param id - other item id +*/ +QtxPreferenceItem* QtxPreferenceItem::findItem( const int id, const bool rec ) const +{ + QtxPreferenceItem* item = 0; + for ( ItemList::const_iterator it = myChildren.begin(); it != myChildren.end() && item; ++it ) + { + QtxPreferenceItem* i = *it; + if ( i->id() == id ) + item = i; + else if ( rec ) + item = i->findItem( id, rec ); + } + return item; +} + +/*! + \return other item + \param title - other item title +*/ +QtxPreferenceItem* QtxPreferenceItem::findItem( const QString& title, const bool rec ) const +{ + QtxPreferenceItem* item = 0; + for ( ItemList::const_iterator it = myChildren.begin(); it != myChildren.end() && item; ++it ) + { + QtxPreferenceItem* i = *it; + if ( i->title() == title ) + item = i; + else if ( rec ) + item = i->findItem( title, rec ); + } + return item; +} + +/*! + \return other item + \param title - other item title + \param id - parent item id +*/ +QtxPreferenceItem* QtxPreferenceItem::findItem( const QString& title, const int id, const bool rec ) const +{ + QtxPreferenceItem* item = 0; + for ( ItemList::const_iterator it = myChildren.begin(); it != myChildren.end() && item; ++it ) + { + QtxPreferenceItem* i = *it; + if ( i->title() == title && i->id() == id ) + item = i; + else if ( rec ) + item = i->findItem( title, id, rec ); + } + return item; +} + + +/*! + \return integer value of resource corresponding to item + \param val - default value (it is returned if there is no such resource) +*/ +int QtxPreferenceItem::getInteger( const int val ) const +{ + QtxResourceMgr* resMgr = resourceMgr(); + return resMgr ? resMgr->integerValue( mySection, myParameter, val ) : val; +} + +/*! + \return double value of resource corresponding to item + \param val - default value (it is returned if there is no such resource) +*/ +double QtxPreferenceItem::getDouble( const double val ) const +{ + QtxResourceMgr* resMgr = resourceMgr(); + return resMgr ? resMgr->doubleValue( mySection, myParameter, val ) : val; +} + +/*! + \return boolean value of resource corresponding to item + \param val - default value (it is returned if there is no such resource) +*/ +bool QtxPreferenceItem::getBoolean( const bool val ) const +{ + QtxResourceMgr* resMgr = resourceMgr(); + return resMgr ? resMgr->booleanValue( mySection, myParameter, val ) : val; +} + +/*! + \return string value of resource corresponding to item + \param val - default value (it is returned if there is no such resource) +*/ +QString QtxPreferenceItem::getString( const QString& val ) const +{ + QtxResourceMgr* resMgr = resourceMgr(); + return resMgr ? resMgr->stringValue( mySection, myParameter, val ) : val; +} + +/*! + \return color value of resource corresponding to item + \param val - default value (it is returned if there is no such resource) +*/ +QColor QtxPreferenceItem::getColor( const QColor& val ) const +{ + QtxResourceMgr* resMgr = resourceMgr(); + return resMgr ? resMgr->colorValue( mySection, myParameter, val ) : val; +} + +/*! + \return font value of resource corresponding to item + \param val - default value (it is returned if there is no such resource) +*/ +QFont QtxPreferenceItem::getFont( const QFont& val ) const +{ + QtxResourceMgr* resMgr = resourceMgr(); + return resMgr ? resMgr->fontValue( mySection, myParameter, val ) : val; +} + +/*! + Sets value of resource + \param val - value +*/ +void QtxPreferenceItem::setInteger( const int val ) +{ + QtxResourceMgr* resMgr = resourceMgr(); + if ( resMgr ) + resMgr->setValue( mySection, myParameter, val ); +} + +/*! + Sets value of resource + \param val - value +*/ +void QtxPreferenceItem::setDouble( const double val ) +{ + QtxResourceMgr* resMgr = resourceMgr(); + if ( resMgr ) + resMgr->setValue( mySection, myParameter, val ); +} + +/*! + Sets value of resource + \param val - value +*/ +void QtxPreferenceItem::setBoolean( const bool val ) +{ + QtxResourceMgr* resMgr = resourceMgr(); + if ( resMgr ) + resMgr->setValue( mySection, myParameter, val ); +} + +/*! + Sets value of resource + \param val - value +*/ +void QtxPreferenceItem::setString( const QString& val ) +{ + QtxResourceMgr* resMgr = resourceMgr(); + if ( resMgr ) + resMgr->setValue( mySection, myParameter, val ); +} + +/*! + Sets value of resource + \param val - value +*/ +void QtxPreferenceItem::setColor( const QColor& val ) +{ + QtxResourceMgr* resMgr = resourceMgr(); + if ( resMgr ) + resMgr->setValue( mySection, myParameter, val ); +} + +/*! + Sets value of resource + \param val - value +*/ +void QtxPreferenceItem::setFont( const QFont& val ) +{ + QtxResourceMgr* resMgr = resourceMgr(); + if ( resMgr ) + resMgr->setValue( mySection, myParameter, val ); +} + +void QtxPreferenceItem::itemAdded( QtxPreferenceItem* ) +{ +} + +void QtxPreferenceItem::itemRemoved( QtxPreferenceItem* ) +{ +} + +void QtxPreferenceItem::itemChanged( QtxPreferenceItem* ) +{ +} + +void QtxPreferenceItem::triggerUpdate() +{ + Updater::instance()->updateItem( this ); +} + +QVariant QtxPreferenceItem::optionValue( const QString& ) const +{ + return QVariant(); +} + +void QtxPreferenceItem::setOptionValue( const QString&, const QVariant& ) +{ +} + +void QtxPreferenceItem::sendItemChanges() +{ + if ( parentItem() ) + parentItem()->itemChanged( this ); +} + +/*! + \return free item id +*/ +int QtxPreferenceItem::generateId() +{ + static int _id = 0; + return _id++; +} + + + +/*! + \class QtxPreferenceMgr + Class for managing preferences items +*/ + + + +/*! + Constructor +*/ +QtxPreferenceMgr::QtxPreferenceMgr( QtxResourceMgr* mgr ) +: QtxPreferenceItem( 0 ), +myResMgr( mgr ) +{ +} + +/*! + Destructor +*/ +QtxPreferenceMgr::~QtxPreferenceMgr() +{ +} + +/*! + \return assigned resource manager +*/ +QtxResourceMgr* QtxPreferenceMgr::resourceMgr() const +{ + return myResMgr; +} + +QtxPreferenceMgr* QtxPreferenceMgr::preferenceMgr() const +{ + return (QtxPreferenceMgr*)this; +} + +/*! + Adds new item + \param label - label of widget to edit preference + \param pId - parent item id + \param type - type of item + \param section - section of resource assigned with item + \param param - name of resource assigned with 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(); +} +*/ + +/*! + \return value of item property + \param id - item id + \propName - propertyName +*/ +QVariant QtxPreferenceMgr::option( const int id, const QString& propName ) const +{ + QVariant propValue; + QtxPreferenceItem* i = findItem( id, true ); + if ( i ) + propValue = i->option( propName ); + return propValue; +} +/*! + Sets value of item property + \param id - item id + \propName - propertyName + \propValue - new value of property +*/ +void QtxPreferenceMgr::setOption( const int id, const QString& propName, const QVariant& propValue ) +{ + QtxPreferenceItem* i = findItem( id, true ); + if ( i ) + i->setOption( propName, propValue ); +} + +/*! + Stores all values to resource manager +*/ +void QtxPreferenceMgr::store() +{ + ResourceMap before; + resourceValues( before ); + + QList items = childItems( true ); + for ( QList::iterator it = items.begin(); it != items.end(); ++it ) + (*it)->store(); + + ResourceMap after; + resourceValues( after ); + + ResourceMap changed; + differentValues( before, after, changed ); + + changedResources( changed ); +} + +/*! + Retrieve all values from resource manager +*/ +void QtxPreferenceMgr::retrieve() +{ + QList items = childItems( true ); + for ( QList::iterator it = items.begin(); it != items.end(); ++it ) + (*it)->retrieve(); +} + +/*! + Stores all values to backup container +*/ +void QtxPreferenceMgr::toBackup() +{ + myBackup.clear(); + resourceValues( myBackup ); +} + +/*! + Retrieve all values from backup container +*/ +void QtxPreferenceMgr::fromBackup() +{ + ResourceMap before; + resourceValues( before ); + + setResourceValues( myBackup ); + + ResourceMap after; + resourceValues( after ); + + ResourceMap changed; + differentValues( before, after, changed ); + + changedResources( changed ); +} + +/*! + Updates resource edit (default implementation is empty) +*/ +void QtxPreferenceMgr::update() +{ +} + +/*! + Creates item + \return new item + \param label - text of label for new item + \param type - type of new item + \param pId - parent id + +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; +} +*/ + +/*! + \return all resources values from widgets + \param map - map to be filled by resources values +*/ +void QtxPreferenceMgr::resourceValues( QMap& map ) const +{ + QString sect, name; + QtxResourceMgr* resMgr = resourceMgr(); + QList items = childItems( true ); + for ( QList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + QtxPreferenceItem* item = *it; + item->resource( sect, name ); + if ( resMgr->hasValue( sect, name ) ) + map.insert( item->id(), item->resourceValue() ); + } +} + +/*! + \return all resources values from widgets + \param map - map to be filled by resources values +*/ +void QtxPreferenceMgr::resourceValues( ResourceMap& map ) const +{ + QString sect, name; + QtxResourceMgr* resMgr = resourceMgr(); + QList items = childItems( true ); + for ( QList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + QtxPreferenceItem* item = *it; + item->resource( sect, name ); + if ( resMgr->hasValue( sect, name ) ) + map.insert( item, item->resourceValue() ); + } +} + +/*! + Sets to widgets all resources values from map + \param map - map with resources values +*/ +void QtxPreferenceMgr::setResourceValues( QMap& map ) const +{ + for ( QMap::const_iterator it = map.begin(); it != map.end(); ++it ) + { + QtxPreferenceItem* i = findItem( it.key(), true ); + if ( i ) + i->setResourceValue( it.value() ); + } +} + +/*! + Sets to widgets all resources values from map + \param map - map with resources values +*/ +void QtxPreferenceMgr::setResourceValues( ResourceMap& map ) const +{ + for ( ResourceMap::const_iterator it = map.begin(); it != map.end(); ++it ) + it.key()->setResourceValue( it.value() ); +} + +/*! + Compares two map of resources values and finds different ones + \param map1 - first map + \param map2 - second map + \param resMap - map to be filled with different values + \param fromFirst - if it is true, then resMap will be filled with values from first map, otherwise - from second +*/ +void QtxPreferenceMgr::differentValues( const QMap& map1, const QMap& map2, + QMap& resMap, const bool fromFirst ) const +{ + resMap.clear(); + const QMap& later = fromFirst ? map1 : map2; + const QMap& early = fromFirst ? map2 : map1; + + for ( QMap::const_iterator it = later.begin(); it != later.end(); ++it ) + { + if ( !early.contains( it.key() ) || early[it.key()] != it.value() ) + resMap.insert( it.key(), it.value() ); + } +} + +/*! + Compares two map of resources values and finds different ones + \param map1 - first map + \param map2 - second map + \param resMap - map to be filled with different values + \param fromFirst - if it is true, then resMap will be filled with values from first map, otherwise - from second +*/ +void QtxPreferenceMgr::differentValues( const ResourceMap& map1, const ResourceMap& map2, + ResourceMap& resMap, const bool fromFirst ) const +{ + resMap.clear(); + const ResourceMap& later = fromFirst ? map1 : map2; + const ResourceMap& early = fromFirst ? map2 : map1; + + for ( ResourceMap::const_iterator it = later.begin(); it != later.end(); ++it ) + { + if ( !early.contains( it.key() ) || early[it.key()] != it.value() ) + resMap.insert( it.key(), it.value() ); + } +} + +/*! + Makes some activity on resource changing (called from store() method) + \sa store() +*/ +void QtxPreferenceMgr::changedResources( const ResourceMap& ) +{ +} diff --git a/src/Qtx/QtxPreferenceMgr.h b/src/Qtx/QtxPreferenceMgr.h new file mode 100644 index 000000000..1c5010702 --- /dev/null +++ b/src/Qtx/QtxPreferenceMgr.h @@ -0,0 +1,188 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxPreferenceMgr.h +// Author: Sergey TELKOV + +#ifndef QTXPREFERENCEMGR_H +#define QTXPREFERENCEMGR_H + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include "Qtx.h" + +#include +#include +#include +#include + +class QtxResourceMgr; +class QtxPreferenceMgr; + +/*! + \class QtxPreferenceItem + Class for incapsulation of one preference item +*/ +class QTX_EXPORT QtxPreferenceItem +{ + class Updater; + +public: + QtxPreferenceItem( QtxPreferenceItem* = 0 ); + QtxPreferenceItem( const QString&, QtxPreferenceItem* ); + QtxPreferenceItem( const QString&, const QString&, const QString&, QtxPreferenceItem* ); + virtual ~QtxPreferenceItem(); + + int id() const; + virtual int rtti() const; + + QtxPreferenceItem* rootItem() const; + QtxPreferenceItem* parentItem() const; + QList childItems( const bool = false ) const; + + int depth() const; + int count() const; + virtual bool isEmpty() const; + + void insertItem( QtxPreferenceItem* ); + void removeItem( QtxPreferenceItem* ); + + QIcon icon() const; + QString title() const; + void resource( QString&, QString& ) const; + + virtual void setIcon( const QIcon& ); + virtual void setTitle( const QString& ); + virtual void setResource( const QString&, const QString& ); + + virtual void updateContents(); + + QVariant option( const QString& ) const; + void setOption( const QString&, const QVariant& ); + + virtual void store() = 0; + virtual void retrieve() = 0; + + QString resourceValue() const; + void setResourceValue( const QString& ); + + QtxPreferenceItem* findItem( const int, const bool = false ) const; + QtxPreferenceItem* findItem( const QString&, const bool = false ) const; + QtxPreferenceItem* findItem( const QString&, const int, const bool = false ) const; + + virtual QtxResourceMgr* resourceMgr() const; + virtual QtxPreferenceMgr* preferenceMgr() const; + + static int RTTI(); + +protected: + int getInteger( const int = 0 ) const; + double getDouble( const double = 0.0 ) const; + 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; + + void setInteger( const int ); + void setDouble( const double ); + void setBoolean( const bool ); + void setColor( const QColor& ); + void setFont( const QFont& ); + void setString( const QString& ); + + virtual void itemAdded( QtxPreferenceItem* ); + virtual void itemRemoved( QtxPreferenceItem* ); + virtual void itemChanged( QtxPreferenceItem* ); + + void sendItemChanges(); + + virtual void triggerUpdate(); + + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +protected: + typedef QList ItemList; + +private: + static int generateId(); + +private: + int myId; + QtxPreferenceItem* myParent; + ItemList myChildren; + + QIcon myIcon; + QString myTitle; + QString mySection; + QString myParameter; +}; + + +/*! + \class QtxPreferenceMgr + Class for managing preferences items +*/ +class QTX_EXPORT QtxPreferenceMgr : public QtxPreferenceItem +{ +public: + QtxPreferenceMgr( QtxResourceMgr* ); + virtual ~QtxPreferenceMgr(); + + virtual QtxResourceMgr* resourceMgr() const; + virtual QtxPreferenceMgr* preferenceMgr() const; + + QVariant option( const int, const QString& ) const; + void setOption( const int, const QString&, const QVariant& ); + + virtual void store(); + virtual void retrieve(); + + virtual void update(); + + virtual void toBackup(); + virtual void fromBackup(); + +protected: + typedef QMap ResourceMap; + + void resourceValues( QMap& ) const; + void resourceValues( ResourceMap& ) const; + + 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&, + ResourceMap&, const bool fromFirst = false ) const; + + virtual void changedResources( const ResourceMap& ); + +private: + QtxResourceMgr* myResMgr; + ResourceMap myBackup; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/Qtx/QtxResourceEdit.cxx b/src/Qtx/QtxResourceEdit.cxx deleted file mode 100644 index e96a57e04..000000000 --- a/src/Qtx/QtxResourceEdit.cxx +++ /dev/null @@ -1,748 +0,0 @@ -// 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 -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxResourceEdit.cxx -// Author: Sergey TELKOV - -#include "QtxResourceEdit.h" - -#include "QtxResourceMgr.h" - - -/*! - Constructor -*/ -QtxResourceEdit::QtxResourceEdit( QtxResourceMgr* mgr ) -: myResMgr( mgr ) -{ -} - -/*! - Destructor -*/ -QtxResourceEdit::~QtxResourceEdit() -{ - ItemMap items; - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it ) - items.insert( it.key(), it.data() ); - - for ( ItemMap::ConstIterator itr = items.begin(); itr != items.end(); ++itr ) - if ( myItems.contains( itr.key() ) ) - delete itr.data(); -} - -/*! - \return assigned resource manager -*/ -QtxResourceMgr* QtxResourceEdit::resourceMgr() const -{ - return myResMgr; -} - -/*! - Adds new item - \param label - label of widget to edit preference - \param pId - parent item id - \param type - type of item - \param section - section of resource assigned with item - \param param - name of resource assigned with item -*/ -int QtxResourceEdit::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(); -} - -/*! - \return value of item property - \param id - item id - \propName - propertyName -*/ -QVariant QtxResourceEdit::itemProperty( const int id, const QString& propName ) const -{ - QVariant propValue; - Item* i = item( id ); - if ( i ) - propValue = i->property( propName ); - return propValue; -} - -/*! - Sets value of item property - \param id - item id - \propName - propertyName - \propValue - new value of property -*/ -void QtxResourceEdit::setItemProperty( const int id, const QString& propName, const QVariant& propValue ) -{ - Item* i = item( id ); - if ( i ) - i->setProperty( propName, propValue ); -} - -/*! - \return resource assigned with item - \param id - item id - \param section - to return section of resource - \param param - to return name of resource -*/ -void QtxResourceEdit::resource( const int id, QString& sec, QString& param ) const -{ - Item* i = item( id ); - if ( i ) - i->resource( sec, param ); -} - -/*! - Stores all values to resource manager -*/ -void QtxResourceEdit::store() -{ - QMap before; - resourceValues( before ); - - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it ) - it.data()->store(); - - QMap after; - resourceValues( after ); - - QMap changed; - differentValues( before, after, changed ); - - changedResources( changed ); -} - -/*! - Retrieve all values from resource manager -*/ -void QtxResourceEdit::retrieve() -{ - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it ) - it.data()->retrieve(); -} - -/*! - Stores all values to backup container -*/ -void QtxResourceEdit::toBackup() -{ - myBackup.clear(); - resourceValues( myBackup ); -} - -/*! - Retrieve all values from backup container -*/ -void QtxResourceEdit::fromBackup() -{ - QMap before; - resourceValues( before ); - - setResourceValues( myBackup ); - - QMap after; - resourceValues( after ); - - QMap changed; - differentValues( before, after, changed ); - - changedResources( changed ); -} - -/*! - Updates resource edit (default implementation is empty) -*/ -void QtxResourceEdit::update() -{ -} - -/*! - \return item by it's id - \param id - item id -*/ -QtxResourceEdit::Item* QtxResourceEdit::item( const int id ) const -{ - Item* i = 0; - if ( myItems.contains( id ) ) - i = myItems[id]; - return i; -} - -/*! - \return item by it's title (finds first item) - \param title - item title -*/ -QtxResourceEdit::Item* QtxResourceEdit::item( const QString& title ) const -{ - Item* i = 0; - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end() && !i; ++it ) - { - if ( it.data()->title() == title ) - i = it.data(); - } - return i; -} - -/*! - \return item by it's title and parent id - \param title - item title - \param pId - parent id -*/ -QtxResourceEdit::Item* QtxResourceEdit::item( const QString& title, const int pId ) const -{ - Item* i = 0; - Item* pItem = item( pId ); - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end() && !i; ++it ) - { - if ( it.data()->parentItem() == pItem && it.data()->title() == title ) - i = it.data(); - } - return i; -} - -/*! - Creates item - \return new item - \param label - text of label for new item - \param type - type of new item - \param pId - parent id -*/ -QtxResourceEdit::Item* QtxResourceEdit::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; -} - -/*! - Removes item - \param item - item to be removed -*/ -void QtxResourceEdit::removeItem( Item* item ) -{ - if ( !item ) - return; - - myChildren.remove( item ); - myItems.remove( item->id() ); - - itemRemoved( item ); -} - -/*! - \return children items of resource edit - \param lst - list of items to be filled with children -*/ -void QtxResourceEdit::childItems( QPtrList& lst ) const -{ - lst.clear(); - for ( QPtrListIterator it( myChildren ); it.current(); ++it ) - lst.append( it.current() ); -} - -/*! - \return all resources values from widgets - \param map - map to be filled by resources values -*/ -void QtxResourceEdit::resourceValues( QMap& map ) const -{ - QString sect, name; - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it ) - { - it.data()->resource( sect, name ); - if( myResMgr->hasValue( sect, name ) ) - map.insert( it.key(), it.data()->resourceValue() ); - } -} - -/*! - \return all resources values from widgets - \param map - map to be filled by resources values -*/ -void QtxResourceEdit::resourceValues( QMap& map ) const -{ - QString sect, name; - for ( ItemMap::ConstIterator it = myItems.begin(); it != myItems.end(); ++it ) - { - it.data()->resource( sect, name ); - if( myResMgr->hasValue( sect, name ) ) - map.insert( it.data(), it.data()->resourceValue() ); - } -} - -/*! - Sets to widgets all resources values from map - \param map - map with resources values -*/ -void QtxResourceEdit::setResourceValues( QMap& map ) const -{ - for ( QMap::ConstIterator it = map.begin(); it != map.end(); ++it ) - { - Item* i = item( it.key() ); - if ( i ) - i->setResourceValue( it.data() ); - } -} - -/*! - Sets to widgets all resources values from map - \param map - map with resources values -*/ -void QtxResourceEdit::setResourceValues( QMap& map ) const -{ - for ( QMap::ConstIterator it = map.begin(); it != map.end(); ++it ) - it.key()->setResourceValue( it.data() ); -} - -/*! - Compares two map of resources values and finds different ones - \param map1 - first map - \param map2 - second map - \param resMap - map to be filled with different values - \param fromFirst - if it is true, then resMap will be filled with values from first map, otherwise - from second -*/ -void QtxResourceEdit::differentValues( const QMap& map1, const QMap& map2, - QMap& resMap, const bool fromFirst ) const -{ - resMap.clear(); - const QMap& later = fromFirst ? map1 : map2; - const QMap& early = fromFirst ? map2 : map1; - - for ( QMap::ConstIterator it = later.begin(); it != later.end(); ++it ) - { - if ( !early.contains( it.key() ) || early[it.key()] != it.data() ) - resMap.insert( it.key(), it.data() ); - } -} - -/*! - Compares two map of resources values and finds different ones - \param map1 - first map - \param map2 - second map - \param resMap - map to be filled with different values - \param fromFirst - if it is true, then resMap will be filled with values from first map, otherwise - from second -*/ -void QtxResourceEdit::differentValues( const QMap& map1, const QMap& map2, - QMap& resMap, const bool fromFirst ) const -{ - resMap.clear(); - const QMap& later = fromFirst ? map1 : map2; - const QMap& early = fromFirst ? map2 : map1; - - for ( QMap::ConstIterator it = later.begin(); it != later.end(); ++it ) - { - if ( !early.contains( it.key() ) || early[it.key()] != it.data() ) - resMap.insert( it.key(), it.data() ); - } -} - -/*! - Makes some activity on resource changing (called from store() method) - \sa store() -*/ -void QtxResourceEdit::changedResources( const QMap& ) -{ -} - -/*! - Some activity on item addition (default implementation is empty) -*/ -void QtxResourceEdit::itemAdded( Item* ) -{ -} - -/*! - Some activity on item removing (default implementation is empty) -*/ -void QtxResourceEdit::itemRemoved( Item* ) -{ -} - -/*! - Constructor -*/ -QtxResourceEdit::Item::Item( QtxResourceEdit* edit, Item* parent ) -: myEdit( edit ), -myParent( 0 ) -{ - myId = generateId(); - - if ( parent ) - parent->insertChild( this ); -} - -/*! - Destructor -*/ -QtxResourceEdit::Item::~Item() -{ - if ( resourceEdit() ) - resourceEdit()->removeItem( this ); -} - -/*! - \return id of item -*/ -int QtxResourceEdit::Item::id() const -{ - return myId; -} - -/*! - \return parent item -*/ -QtxResourceEdit::Item* QtxResourceEdit::Item::parentItem() const -{ - return myParent; -} - -/*! - Appends child and (if necessary) removes item from old parent - \param item - item to be added -*/ -void QtxResourceEdit::Item::insertChild( Item* item ) -{ - if ( !item || myChildren.contains( item ) ) - return; - - if ( item->parentItem() && item->parentItem() != this ) - item->parentItem()->removeChild( item ); - - item->myParent = this; - myChildren.append( item ); -} - -/*! - Removes child - \param item - item to be removed -*/ -void QtxResourceEdit::Item::removeChild( Item* item ) -{ - if ( !item || !myChildren.contains( item ) ) - return; - - myChildren.remove( item ); - item->myParent = 0; -} - -/*! - Fills list with children items - \param lst - list to be filled with -*/ -void QtxResourceEdit::Item::childItems( QPtrList& lst ) const -{ - for ( ItemListIterator it( myChildren ); it.current(); ++it ) - lst.append( it.current() ); -} - -/*! - \return true if there is no children of this item -*/ -bool QtxResourceEdit::Item::isEmpty() const -{ - return myChildren.isEmpty(); -} - -/*! - \return title of item -*/ -QString QtxResourceEdit::Item::title() const -{ - return myTitle; -} - -/*! - \return assigned resource placement - \param sec - to return section - \param param - to return param name -*/ -void QtxResourceEdit::Item::resource( QString& sec, QString& param ) const -{ - sec = myResSection; - param = myResParameter; -} - -/*! - Sets item title - \param title - new item title -*/ -void QtxResourceEdit::Item::setTitle( const QString& title ) -{ - myTitle = title; -} - -/*! - Assigns new resource to item - \param sec - section - \param sec - param name -*/ -void QtxResourceEdit::Item::setResource( const QString& sec, const QString& param ) -{ - myResSection = sec; - myResParameter = param; -} - -/*! - Updates item (default implementation is empty) -*/ -void QtxResourceEdit::Item::update() -{ -} - -/*! - \return property value -*/ -QVariant QtxResourceEdit::Item::property( const QString& ) const -{ - return QVariant(); -} - -/*! - Sets property value -*/ -void QtxResourceEdit::Item::setProperty( const QString&, const QVariant& ) -{ -} - -/*! - \return value of assigned resource -*/ -QString QtxResourceEdit::Item::resourceValue() const -{ - return getString(); -} - -/*! - Sets value of assigned resource - \param val - new value -*/ -void QtxResourceEdit::Item::setResourceValue( const QString& val ) -{ - setString( val ); -} - -/*! - \return corresponding resource manager -*/ -QtxResourceMgr* QtxResourceEdit::Item::resourceMgr() const -{ - QtxResourceMgr* resMgr = 0; - if ( resourceEdit() ) - resMgr = resourceEdit()->resourceMgr(); - return resMgr; -} - -/*! - \return corresponding resource edit -*/ -QtxResourceEdit* QtxResourceEdit::Item::resourceEdit() const -{ - return myEdit; -} - -/*! - \return integer value of resource corresponding to item - \param val - default value (it is returned if there is no such resource) -*/ -int QtxResourceEdit::Item::getInteger( const int val ) const -{ - QtxResourceMgr* resMgr = resourceMgr(); - return resMgr ? resMgr->integerValue( myResSection, myResParameter, val ) : val; -} - -/*! - \return double value of resource corresponding to item - \param val - default value (it is returned if there is no such resource) -*/ -double QtxResourceEdit::Item::getDouble( const double val ) const -{ - QtxResourceMgr* resMgr = resourceMgr(); - return resMgr ? resMgr->doubleValue( myResSection, myResParameter, val ) : val; -} - -/*! - \return boolean value of resource corresponding to item - \param val - default value (it is returned if there is no such resource) -*/ -bool QtxResourceEdit::Item::getBoolean( const bool val ) const -{ - QtxResourceMgr* resMgr = resourceMgr(); - return resMgr ? resMgr->booleanValue( myResSection, myResParameter, val ) : val; -} - -/*! - \return string value of resource corresponding to item - \param val - default value (it is returned if there is no such resource) -*/ -QString QtxResourceEdit::Item::getString( const QString& val ) const -{ - QtxResourceMgr* resMgr = resourceMgr(); - return resMgr ? resMgr->stringValue( myResSection, myResParameter, val ) : val; -} - -/*! - \return color value of resource corresponding to item - \param val - default value (it is returned if there is no such resource) -*/ -QColor QtxResourceEdit::Item::getColor( const QColor& val ) const -{ - QtxResourceMgr* resMgr = resourceMgr(); - return resMgr ? resMgr->colorValue( myResSection, myResParameter, val ) : val; -} - -/*! - \return font value of resource corresponding to item - \param val - default value (it is returned if there is no such resource) -*/ -QFont QtxResourceEdit::Item::getFont( const QFont& val ) const -{ - QtxResourceMgr* resMgr = resourceMgr(); - return resMgr ? resMgr->fontValue( myResSection, myResParameter, val ) : val; -} - -/*! - Sets value of resource - \param val - value -*/ -void QtxResourceEdit::Item::setInteger( const int val ) -{ - QtxResourceMgr* resMgr = resourceMgr(); - if ( resMgr ) - resMgr->setValue( myResSection, myResParameter, val ); -} - -/*! - Sets value of resource - \param val - value -*/ -void QtxResourceEdit::Item::setDouble( const double val ) -{ - QtxResourceMgr* resMgr = resourceMgr(); - if ( resMgr ) - resMgr->setValue( myResSection, myResParameter, val ); -} - -/*! - Sets value of resource - \param val - value -*/ -void QtxResourceEdit::Item::setBoolean( const bool val ) -{ - QtxResourceMgr* resMgr = resourceMgr(); - if ( resMgr ) - resMgr->setValue( myResSection, myResParameter, val ); -} - -/*! - Sets value of resource - \param val - value -*/ -void QtxResourceEdit::Item::setString( const QString& val ) -{ - QtxResourceMgr* resMgr = resourceMgr(); - if ( resMgr ) - resMgr->setValue( myResSection, myResParameter, val ); -} - -/*! - Sets value of resource - \param val - value -*/ -void QtxResourceEdit::Item::setColor( const QColor& val ) -{ - QtxResourceMgr* resMgr = resourceMgr(); - if ( resMgr ) - resMgr->setValue( myResSection, myResParameter, val ); -} - -/*! - Sets value of resource - \param val - value -*/ -void QtxResourceEdit::Item::setFont( const QFont& val ) -{ - QtxResourceMgr* resMgr = resourceMgr(); - if ( resMgr ) - resMgr->setValue( myResSection, myResParameter, val ); -} - -/*! - \return other item - \param id - other item id -*/ -QtxResourceEdit::Item* QtxResourceEdit::Item::item( const int id ) const -{ - return resourceEdit() ? resourceEdit()->item( id ) : 0; -} - -/*! - \return other item - \param title - other item title -*/ -QtxResourceEdit::Item* QtxResourceEdit::Item::item( const QString& title ) const -{ - return resourceEdit() ? resourceEdit()->item( title ) : 0; -} - -/*! - \return other item - \param title - other item title - \param id - parent item id -*/ -QtxResourceEdit::Item* QtxResourceEdit::Item::item( const QString& title, const int id ) const -{ - return resourceEdit() ? resourceEdit()->item( title, id ) : 0; -} - -/*! - \return free item id -*/ -int QtxResourceEdit::Item::generateId() -{ - static int _id = 0; - return _id++; -} diff --git a/src/Qtx/QtxResourceEdit.h b/src/Qtx/QtxResourceEdit.h deleted file mode 100644 index 14b920591..000000000 --- a/src/Qtx/QtxResourceEdit.h +++ /dev/null @@ -1,197 +0,0 @@ -// 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 -// 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 -// 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 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxResourceEdit.h -// Author: Sergey TELKOV - -#ifndef QTXRESOURCEEDIT_H -#define QTXRESOURCEEDIT_H - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -#include "Qtx.h" - -class QString; -class QtxResourceMgr; - -#include -#include -#include - -/*! - \class QtxResourceEdit - Class for managing preferences items -*/ -class QTX_EXPORT QtxResourceEdit -{ -public: - class Item; - -public: - QtxResourceEdit( QtxResourceMgr* ); - virtual ~QtxResourceEdit(); - - QtxResourceMgr* resourceMgr() const; - - virtual int addItem( const QString& label, const int pId = -1, const int = -1, - const QString& section = QString::null, - const QString& param = QString::null ); - - QVariant itemProperty( const int, const QString& ) const; - virtual void setItemProperty( const int, const QString&, const QVariant& ); - - void resource( const int, QString&, QString& ) const; - - virtual void store(); - virtual void retrieve(); - - virtual void update(); - - virtual void toBackup(); - virtual void fromBackup(); - -protected: - Item* item( const int ) const; - Item* item( const QString& ) const; - Item* item( const QString&, const int ) const; - - virtual Item* createItem( const QString&, const int ) = 0; - - void resourceValues( QMap& ) const; - void resourceValues( QMap& ) const; - - void setResourceValues( QMap& ) const; - void setResourceValues( QMap& ) const; - - void differentValues( const QMap&, const QMap&, - QMap&, const bool fromFirst = false ) const; - void differentValues( const QMap&, const QMap&, - QMap&, const bool fromFirst = false ) const; - - virtual void changedResources( const QMap& ); - - virtual void itemAdded( Item* ); - virtual void itemRemoved( Item* ); - - void childItems( QList& ) const; - -private: - void removeItem( Item* ); - Item* createItem( const QString&, const int, const int ); - -private: - typedef QMap ItemMap; - -private: - ItemMap myItems; - QtxResourceMgr* myResMgr; - QMap myBackup; - QList myChildren; - - friend class QtxResourceEdit::Item; -}; - -/*! - \class QtxResourceEditor::Item - Class for incapsulation of one preference item -*/ - -class QTX_EXPORT QtxResourceEdit::Item -{ -public: - Item( QtxResourceEdit*, Item* = 0 ); - virtual ~Item(); - - int id() const; - virtual int type() const = 0; - - Item* parentItem() const; - void childItems( QList& ) const; - - virtual bool isEmpty() const; - - QString title() const; - void resource( QString&, QString& ) const; - - virtual void setTitle( const QString& ); - virtual void setResource( const QString&, const QString& ); - - virtual void update(); - - virtual QVariant property( const QString& ) const; - virtual void setProperty( const QString&, const QVariant& ); - - virtual void store() = 0; - virtual void retrieve() = 0; - - virtual Item* createItem( const QString&, const int ) = 0; - - QString resourceValue() const; - void setResourceValue( const QString& ); - - virtual void insertChild( Item* ); - virtual void removeChild( Item* ); - -protected: - QtxResourceMgr* resourceMgr() const; - QtxResourceEdit* resourceEdit() const; - - int getInteger( const int = 0 ) const; - double getDouble( const double = 0.0 ) const; - 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; - - void setInteger( const int ); - void setDouble( const double ); - void setBoolean( const bool ); - void setColor( const QColor& ); - void setFont( const QFont& ); - void setString( const QString& ); - - Item* item( const int ) const; - Item* item( const QString& ) const; - Item* item( const QString&, const int ) const; - -protected: - typedef QList ItemList; - typedef QListIterator ItemListIterator; - -private: - static int generateId(); - -private: - int myId; - Item* myParent; - ItemList myChildren; - - QString myTitle; - QString myResSection; - QString myResParameter; - - QtxResourceEdit* myEdit; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 51411bfa4..70a27527a 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1117,6 +1117,7 @@ bool QtxResourceMgr::Format::save( Resources* res ) QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTemplate ) : myAppName( appName ), myCheckExist( true ), + myDefaultPix( 0 ), myIsPixmapCached( true ), myIsIgnoreUserValues( false ) { @@ -1155,6 +1156,8 @@ QtxResourceMgr::~QtxResourceMgr() myResources.clear(); for ( FormatList::iterator formIt = myFormats.begin(); formIt != myFormats.end(); ++formIt ) delete *formIt; + + delete myDefaultPix; } /*! @@ -2130,7 +2133,10 @@ QString QtxResourceMgr::langSection() const */ QPixmap QtxResourceMgr::defaultPixmap() const { - return myDefaultPix; + QPixmap res; + if ( myDefaultPix && !myDefaultPix->isNull() ) + res = *myDefaultPix; + return res; } /*! @@ -2143,7 +2149,11 @@ QPixmap QtxResourceMgr::defaultPixmap() const */ void QtxResourceMgr::setDefaultPixmap( const QPixmap& pix ) { - myDefaultPix = pix; + delete myDefaultPix; + if ( pix.isNull() ) + myDefaultPix = 0; + else + myDefaultPix = new QPixmap( pix ); } /*! diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 304e25fdc..6508fc95a 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -30,11 +30,11 @@ #include #include -#include -#include #include #include #include +#include +#include class QTranslator; @@ -169,7 +169,7 @@ private: ResList myResources; //!< resources list bool myCheckExist; //!< "check existance" flag TransListMap myTranslator; //!< map of loaded translators - QPixmap myDefaultPix; //!< default icon + QPixmap* myDefaultPix; //!< default icon bool myIsPixmapCached; //!< "cached pixmaps" flag bool myIsIgnoreUserValues; //!< "ignore user values" flag diff --git a/src/SUIT/SUIT_PreferenceMgr.cxx b/src/SUIT/SUIT_PreferenceMgr.cxx new file mode 100644 index 000000000..1db3fc6a8 --- /dev/null +++ b/src/SUIT/SUIT_PreferenceMgr.cxx @@ -0,0 +1,125 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: SUIT_PreferenceMgr.cxx +// Author: Sergey TELKOV + +#include "SUIT_PreferenceMgr.h" + +SUIT_PreferenceMgr::SUIT_PreferenceMgr( QtxResourceMgr* resMgr, QWidget* parent ) +: QtxPagePrefMgr( resMgr, parent ) +{ +} + +SUIT_PreferenceMgr::~SUIT_PreferenceMgr() +{ +} + +QVariant SUIT_PreferenceMgr::itemProperty( const int id, const QString& prop ) const +{ + QtxPreferenceItem* item = findItem( id, true ); + return item ? item->option( prop ) : QVariant(); +} + +void SUIT_PreferenceMgr::setItemProperty( const int id, const QString& prop, const QVariant& val ) +{ + QtxPreferenceItem* item = findItem( id, true ); + if ( item ) + item->setOption( prop, val ); +} + +int SUIT_PreferenceMgr::addItem( const QString& title, const int pId, + const SUIT_PreferenceMgr::PrefItemType type, + const QString& sect, const QString& param ) +{ + QtxPreferenceItem* item = findItem( title, true ); + if ( item ) + return item->id(); + + QtxPreferenceItem* parent = 0; + if ( pId == -1 ) + { + QList lst = childItems(); + for ( QList::const_iterator it = lst.begin(); it != lst.end() && !parent; ++it ) + parent = *it; + } + else + parent = findItem( pId ); + + if ( !parent ) + parent = new QtxPagePrefListItem( QString(), this ); + + switch( type ) + { + case Auto: + switch ( parent->depth() ) + { + case 1: + item = new QtxPagePrefTabsItem( title, parent, sect, param ); + break; + case 2: + item = new QtxPagePrefFrameItem( title, parent, sect, param ); + break; + case 3: + item = new QtxPagePrefGroupItem( title, parent, sect, param ); + break; + } + break; + case Space: + item = new QtxPagePrefSpaceItem( parent ); + break; + case Bool: + item = new QtxPagePrefCheckItem( title, parent, sect, param ); + break; + case Color: + item = new QtxPagePrefColorItem( title, parent, sect, param ); + break; + case String: + item = new QtxPagePrefEditItem( QtxPagePrefEditItem::String, title, parent, sect, param ); + break; + case Selector: + item = new QtxPagePrefSelectItem( title, parent, sect, param ); + break; + case DblSpin: + item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Double, title, parent, sect, param ); + break; + case IntSpin: + item = new QtxPagePrefSpinItem( QtxPagePrefSpinItem::Integer, title, parent, sect, param ); + break; + case Double: + item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Double, title, parent, sect, param ); + break; + case Integer: + item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Integer, title, parent, sect, param ); + break; + case GroupBox: + item = new QtxPagePrefGroupItem( title, parent, sect, param ); + break; + case Font: + item = new QtxPagePrefFontItem( title, parent, sect, param ); + break; + case File: + item = new QtxPagePrefPathItem( QtxPagePrefPathItem::OpenFile, title, parent, sect, param ); + break; + case DirList: + item = new QtxPagePrefPathsItem( QtxPagePrefPathsItem::Directory, title, parent, sect, param ); + break; + } + + return item ? item->id() : -1; +} diff --git a/src/SUIT/SUIT_PreferenceMgr.h b/src/SUIT/SUIT_PreferenceMgr.h new file mode 100644 index 000000000..6a95da776 --- /dev/null +++ b/src/SUIT/SUIT_PreferenceMgr.h @@ -0,0 +1,52 @@ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: SUIT_PreferenceMgr.h +// Author: Sergey TELKOV + +#ifndef SUIT_PREFERENCEMGR_H +#define SUIT_PREFERENCEMGR_H + +// This class is obsoleted. +// It was created for backward compatibility with ResourceEdit from Salome version 3.x.x + +#include "SUIT.h" + +#include "QtxPagePrefMgr.h" + +class SUIT_EXPORT SUIT_PreferenceMgr : public QtxPagePrefMgr +{ + Q_OBJECT + +public: + typedef enum { Auto, Space, Bool, Color, String, Selector, + DblSpin, IntSpin, Double, Integer, + GroupBox, Font, DirList, File } PrefItemType; + +public: + SUIT_PreferenceMgr( QtxResourceMgr*, QWidget* = 0 ); + virtual ~SUIT_PreferenceMgr(); + + QVariant itemProperty( const int, const QString& ) const; + void setItemProperty( const int, const QString&, const QVariant& ); + + int addItem( const QString&, const int pId = -1, const PrefItemType = Auto, + const QString& = QString(), const QString& = QString() ); +}; + +#endif -- 2.39.2