From d02140ab92bb35d03a80741086292363a5837eeb Mon Sep 17 00:00:00 2001 From: stv Date: Wed, 14 Feb 2007 17:38:58 +0000 Subject: [PATCH] no message --- src/Qtx/Makefile.in | 165 --- src/Qtx/Qtx.pro | 20 + src/Qtx/QtxDblSpinBox.cxx | 603 --------- src/Qtx/QtxDblSpinBox.h | 113 -- src/Qtx/QtxDblValidator.cxx | 62 - src/Qtx/QtxDblValidator.h | 41 - src/Qtx/QtxDialog.cxx | 1454 --------------------- src/Qtx/QtxDialog.h | 190 --- src/Qtx/QtxDirListEditor.cxx | 571 --------- src/Qtx/QtxDirListEditor.h | 149 --- src/Qtx/QtxDockAction.cxx | 1304 ------------------- src/Qtx/QtxDockAction.h | 164 --- src/Qtx/QtxGroupBox.cxx | 407 ------ src/Qtx/QtxGroupBox.h | 80 -- src/Qtx/QtxIntSpinBox.cxx | 173 --- src/Qtx/QtxIntSpinBox.h | 60 - src/Qtx/QtxListAction.cxx | 1124 ----------------- src/Qtx/QtxListAction.h | 196 --- src/Qtx/QtxListBox.cxx | 471 ------- src/Qtx/QtxListBox.h | 108 -- src/Qtx/QtxListOfOperations.cxx | 278 ---- src/Qtx/QtxListOfOperations.h | 82 -- src/Qtx/QtxListResourceEdit.cxx | 1748 -------------------------- src/Qtx/QtxListResourceEdit.h | 532 -------- src/Qtx/QtxListView.cxx | 422 ------- src/Qtx/QtxListView.h | 101 -- src/Qtx/QtxLogoMgr.cxx | 200 --- src/Qtx/QtxLogoMgr.h | 67 - src/Qtx/QtxMRUAction.cxx | 662 ---------- src/Qtx/QtxMRUAction.h | 115 -- src/Qtx/QtxMainWindow.cxx | 78 +- src/Qtx/QtxMainWindow.h | 10 +- src/Qtx/QtxMenuButton.cxx | 429 ------- src/Qtx/QtxMenuButton.h | 88 -- src/Qtx/QtxOperations.cxx | 43 - src/Qtx/QtxOperations.h | 61 - src/Qtx/QtxParser.cxx | 850 ------------- src/Qtx/QtxParser.h | 159 --- src/Qtx/QtxPathDialog.cxx | 606 --------- src/Qtx/QtxPathDialog.h | 111 -- src/Qtx/QtxPopupMenu.cxx | 328 ----- src/Qtx/QtxPopupMenu.h | 74 -- src/Qtx/QtxPopupMgr.cxx | 759 ----------- src/Qtx/QtxPopupMgr.h | 132 -- src/Qtx/QtxResourceEdit.cxx | 748 ----------- src/Qtx/QtxResourceEdit.h | 197 --- src/Qtx/QtxResourceMgr.cxx | 361 ++++-- src/Qtx/QtxResourceMgr.h | 121 +- src/Qtx/QtxSplash.cxx | 507 -------- src/Qtx/QtxSplash.h | 114 -- src/Qtx/QtxStdOperations.cxx | 833 ------------ src/Qtx/QtxStdOperations.h | 144 --- src/Qtx/QtxTable.cxx | 398 ------ src/Qtx/QtxTable.h | 88 -- src/Qtx/QtxToolBar.cxx | 203 +-- src/Qtx/QtxToolBar.h | 20 +- src/Qtx/QtxToolTip.cxx | 265 ---- src/Qtx/QtxToolTip.h | 78 -- src/Qtx/QtxWorkspaceAction.cxx | 530 -------- src/Qtx/QtxWorkspaceAction.h | 106 -- src/Qtx/QtxWorkstack.cxx | 1040 ++++++++------- src/Qtx/QtxWorkstack.h | 72 +- src/Qtx/QtxWorkstackAction.cxx | 407 ------ src/Qtx/QtxWorkstackAction.h | 97 -- src/SUIT/Makefile.in | 126 -- src/SUIT/SUIT.h | 6 +- src/SUIT/SUIT_Accel.cxx | 37 +- src/SUIT/SUIT_Accel.h | 10 +- src/SUIT/SUIT_ActionOperation.cxx | 12 +- src/SUIT/SUIT_ActionOperation.h | 21 +- src/SUIT/SUIT_Application.cxx | 44 +- src/SUIT/SUIT_Application.h | 8 +- src/SUIT/SUIT_Convertor.h | 43 - src/SUIT/SUIT_DataObject.cxx | 60 +- src/SUIT/SUIT_DataObject.h | 13 +- src/SUIT/SUIT_DataObjectIterator.cxx | 16 +- src/SUIT/SUIT_DataObjectKey.cxx | 4 +- src/SUIT/SUIT_DataOwner.cxx | 70 +- src/SUIT/SUIT_DataOwner.h | 18 +- src/SUIT/SUIT_Desktop.cxx | 72 +- src/SUIT/SUIT_Desktop.h | 22 +- src/SUIT/SUIT_ExceptionHandler.cxx | 4 +- src/SUIT/SUIT_FileDlg.cxx | 306 ++--- src/SUIT/SUIT_FileDlg.h | 12 +- src/SUIT/SUIT_FileValidator.cxx | 27 +- src/SUIT/SUIT_FileValidator.h | 6 +- src/SUIT/SUIT_MessageBox.cxx | 34 +- src/SUIT/SUIT_MessageBox.h | 4 +- src/SUIT/SUIT_Operation.h | 9 +- src/SUIT/SUIT_OverrideCursor.cxx | 2 +- src/SUIT/SUIT_OverrideCursor.h | 9 +- src/SUIT/SUIT_ParserSettings.cxx | 341 ----- src/SUIT/SUIT_ParserSettings.h | 56 - src/SUIT/SUIT_PopupClient.cxx | 2 +- src/SUIT/SUIT_PopupClient.h | 6 +- src/SUIT/SUIT_ResourceMgr.cxx | 12 +- src/SUIT/SUIT_SelectionMgr.cxx | 91 +- src/SUIT/SUIT_SelectionMgr.h | 31 +- src/SUIT/SUIT_Selector.cxx | 2 +- src/SUIT/SUIT_Selector.h | 6 +- src/SUIT/SUIT_Session.cxx | 112 +- src/SUIT/SUIT_Session.h | 22 +- src/SUIT/SUIT_Study.cxx | 34 +- src/SUIT/SUIT_Study.h | 10 +- src/SUIT/SUIT_ToolButton.cxx | 97 +- src/SUIT/SUIT_ToolButton.h | 21 +- src/SUIT/SUIT_Tools.cxx | 8 +- src/SUIT/SUIT_Tools.h | 7 +- src/SUIT/SUIT_ViewManager.cxx | 55 +- src/SUIT/SUIT_ViewManager.h | 14 +- src/SUIT/SUIT_ViewModel.cxx | 17 +- src/SUIT/SUIT_ViewModel.h | 17 +- src/SUIT/SUIT_ViewWindow.cxx | 54 +- src/SUIT/SUIT_ViewWindow.h | 12 +- src/SUIT/utilities.h | 122 -- 115 files changed, 1668 insertions(+), 22195 deletions(-) delete mode 100755 src/Qtx/Makefile.in create mode 100644 src/Qtx/Qtx.pro delete mode 100755 src/Qtx/QtxDblSpinBox.cxx delete mode 100755 src/Qtx/QtxDblSpinBox.h delete mode 100644 src/Qtx/QtxDblValidator.cxx delete mode 100644 src/Qtx/QtxDblValidator.h delete mode 100755 src/Qtx/QtxDialog.cxx delete mode 100755 src/Qtx/QtxDialog.h delete mode 100644 src/Qtx/QtxDirListEditor.cxx delete mode 100644 src/Qtx/QtxDirListEditor.h delete mode 100755 src/Qtx/QtxDockAction.cxx delete mode 100755 src/Qtx/QtxDockAction.h delete mode 100644 src/Qtx/QtxGroupBox.cxx delete mode 100644 src/Qtx/QtxGroupBox.h delete mode 100755 src/Qtx/QtxIntSpinBox.cxx delete mode 100755 src/Qtx/QtxIntSpinBox.h delete mode 100755 src/Qtx/QtxListAction.cxx delete mode 100755 src/Qtx/QtxListAction.h delete mode 100755 src/Qtx/QtxListBox.cxx delete mode 100755 src/Qtx/QtxListBox.h delete mode 100644 src/Qtx/QtxListOfOperations.cxx delete mode 100644 src/Qtx/QtxListOfOperations.h delete mode 100644 src/Qtx/QtxListResourceEdit.cxx delete mode 100644 src/Qtx/QtxListResourceEdit.h delete mode 100755 src/Qtx/QtxListView.cxx delete mode 100755 src/Qtx/QtxListView.h delete mode 100644 src/Qtx/QtxLogoMgr.cxx delete mode 100644 src/Qtx/QtxLogoMgr.h delete mode 100755 src/Qtx/QtxMRUAction.cxx delete mode 100755 src/Qtx/QtxMRUAction.h delete mode 100755 src/Qtx/QtxMenuButton.cxx delete mode 100755 src/Qtx/QtxMenuButton.h delete mode 100644 src/Qtx/QtxOperations.cxx delete mode 100644 src/Qtx/QtxOperations.h delete mode 100644 src/Qtx/QtxParser.cxx delete mode 100644 src/Qtx/QtxParser.h delete mode 100755 src/Qtx/QtxPathDialog.cxx delete mode 100755 src/Qtx/QtxPathDialog.h delete mode 100644 src/Qtx/QtxPopupMenu.cxx delete mode 100644 src/Qtx/QtxPopupMenu.h delete mode 100644 src/Qtx/QtxPopupMgr.cxx delete mode 100644 src/Qtx/QtxPopupMgr.h delete mode 100644 src/Qtx/QtxResourceEdit.cxx delete mode 100644 src/Qtx/QtxResourceEdit.h delete mode 100644 src/Qtx/QtxSplash.cxx delete mode 100644 src/Qtx/QtxSplash.h delete mode 100644 src/Qtx/QtxStdOperations.cxx delete mode 100644 src/Qtx/QtxStdOperations.h delete mode 100644 src/Qtx/QtxTable.cxx delete mode 100644 src/Qtx/QtxTable.h delete mode 100755 src/Qtx/QtxToolTip.cxx delete mode 100755 src/Qtx/QtxToolTip.h delete mode 100644 src/Qtx/QtxWorkspaceAction.cxx delete mode 100644 src/Qtx/QtxWorkspaceAction.h delete mode 100644 src/Qtx/QtxWorkstackAction.cxx delete mode 100644 src/Qtx/QtxWorkstackAction.h delete mode 100755 src/SUIT/Makefile.in delete mode 100755 src/SUIT/SUIT_Convertor.h delete mode 100755 src/SUIT/SUIT_ParserSettings.cxx delete mode 100755 src/SUIT/SUIT_ParserSettings.h delete mode 100755 src/SUIT/utilities.h diff --git a/src/Qtx/Makefile.in b/src/Qtx/Makefile.in deleted file mode 100755 index ea5bccbc6..000000000 --- a/src/Qtx/Makefile.in +++ /dev/null @@ -1,165 +0,0 @@ -# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, 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 : Makefile.in -# Author : Vladimir Klyachin (OCN) -# Module : suit -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ - -VPATH=.:@srcdir@:@srcdir@/resources - -@COMMENCE@ - -# header files - -EXPORT_HEADERS= Qtx.h \ - QtxAction.h \ - QtxColorScale.h \ - QtxComboBox.h \ - QtxDblSpinBox.h \ - QtxDialog.h \ - QtxDockAction.h \ - QtxDockWindow.h \ - QtxGroupBox.h \ - QtxIntSpinBox.h \ - QtxListAction.h \ - QtxListBox.h \ - QtxListOfOperations.h \ - QtxLogoMgr.h \ - QtxMenuButton.h \ - QtxMRUAction.h \ - QtxOperations.h \ - QtxPathDialog.h \ - QtxPopupMgr.h \ - QtxResourceMgr.h \ - QtxStdOperations.h \ - QtxTable.h \ - QtxToolBar.h \ - QtxToolTip.h \ - QtxParser.h \ - QtxPopupMenu.h \ - QtxActionMgr.h \ - QtxActionMenuMgr.h \ - QtxActionToolMgr.h \ - QtxMainWindow.h \ - QtxWorkspaceAction.h \ - QtxWorkstackAction.h \ - QtxListResourceEdit.h \ - QtxWorkstack.h \ - QtxResourceEdit.h \ - QtxListView.h \ - QtxDirListEditor.h \ - QtxDblValidator.h \ - QtxSplash.h - -# .po files to transform in .qm - -PO_FILES = \ - -# Libraries targets - -LIB = libqtx.la - -LIB_SRC= \ - Qtx.cxx \ - QtxAction.cxx \ - QtxColorScale.cxx \ - QtxComboBox.cxx \ - QtxDblSpinBox.cxx \ - QtxDialog.cxx \ - QtxDockAction.cxx \ - QtxDockWindow.cxx \ - QtxGroupBox.cxx \ - QtxIntSpinBox.cxx \ - QtxListAction.cxx \ - QtxListBox.cxx \ - QtxListOfOperations.cxx \ - QtxLogoMgr.cxx \ - QtxMenuButton.cxx \ - QtxMRUAction.cxx \ - QtxPathDialog.cxx \ - QtxPopupMgr.cxx \ - QtxResourceMgr.cxx \ - QtxStdOperations.cxx \ - QtxTable.cxx \ - QtxToolBar.cxx \ - QtxToolTip.cxx \ - QtxOperations.cxx \ - QtxParser.cxx \ - QtxPopupMenu.cxx \ - QtxActionMgr.cxx \ - QtxActionMenuMgr.cxx \ - QtxActionToolMgr.cxx \ - QtxMainWindow.cxx \ - QtxWorkspaceAction.cxx \ - QtxWorkstackAction.cxx \ - QtxListResourceEdit.cxx \ - QtxResourceEdit.cxx \ - QtxWorkstack.cxx \ - QtxListView.cxx \ - QtxDirListEditor.cxx \ - QtxDblValidator.cxx \ - QtxSplash.cxx - -LIB_MOC = \ - QtxAction.h \ - QtxColorScale.h \ - QtxComboBox.h \ - QtxDblSpinBox.h \ - QtxDialog.h \ - QtxDockAction.h \ - QtxDockWindow.h \ - QtxGroupBox.h \ - QtxIntSpinBox.h \ - QtxListAction.h \ - QtxListBox.h \ - QtxLogoMgr.h \ - QtxMenuButton.h \ - QtxMRUAction.h \ - QtxPathDialog.h \ - QtxPopupMgr.h \ - QtxPopupMenu.h \ - QtxTable.h \ - QtxToolBar.h \ - QtxToolTip.h \ - QtxActionMgr.h \ - QtxActionMenuMgr.h \ - QtxActionToolMgr.h \ - QtxMainWindow.h \ - QtxWorkspaceAction.h \ - QtxWorkstackAction.h \ - QtxWorkstack.h \ - QtxListView.h \ - QtxListResourceEdit.h \ - QtxDirListEditor.h \ - QtxDblValidator.h \ - QtxSplash.h - -RESOURCES_FILES = \ - -CPPFLAGS+=$(QT_INCLUDES) - -LDFLAGS+=$(QT_MT_LIBS) - -@CONCLUDE@ - - diff --git a/src/Qtx/Qtx.pro b/src/Qtx/Qtx.pro new file mode 100644 index 000000000..b174dfd5b --- /dev/null +++ b/src/Qtx/Qtx.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +DESTDIR = ../../lib +MOC_DIR = ../../moc +OBJECTS_DIR = ../../obj/$$TARGET + +QT += xml +CONFIG -= debug release debug_and_release +CONFIG += qt thread debug dll shared + +win32:DEFINES += WIN32 +DEFINES += QTX_EXPORTS + +HEADERS = *.h + +SOURCES = *.cxx + +includes.files = $$HEADERS +includes.path = ../../include + +INSTALLS += includes diff --git a/src/Qtx/QtxDblSpinBox.cxx b/src/Qtx/QtxDblSpinBox.cxx deleted file mode 100755 index 59f9f6192..000000000 --- a/src/Qtx/QtxDblSpinBox.cxx +++ /dev/null @@ -1,603 +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: QtxDblSpinBox.cxx -// Author: Sergey TELKOV - -#include "QtxDblSpinBox.h" - -#include -#include -#include - -#include - -/*! - \class QtxDblSpinBox::Validator [internal] - Validator for QtxDblSpinBox (getted from Trolltech Qt - SpinBoxValidator) -*/ -class QtxDblSpinBox::Validator : public QDoubleValidator -{ -public: - Validator( QtxDblSpinBox* sb, const char* name ) - : QDoubleValidator( sb, name ), spinBox( sb ) {} - - virtual State validate( QString& str, int& pos ) const; - -private: - QtxDblSpinBox* spinBox; -}; - - -/*! - Checks string and \return QValidator::State -*/ -QValidator::State QtxDblSpinBox::Validator::validate( QString& str, int& pos ) const -{ - QString pref = spinBox->prefix(); - QString suff = spinBox->suffix(); - uint overhead = pref.length() + suff.length(); - State state = Invalid; - - if ( overhead == 0 ) - state = QDoubleValidator::validate( str, pos ); - else - { - if ( str.length() >= overhead && str.startsWith( pref ) && - str.right( suff.length() ) == suff ) - { - QString core = str.mid( pref.length(), str.length() - overhead ); - int corePos = pos - pref.length(); - state = QDoubleValidator::validate( core, corePos ); - pos = corePos + pref.length(); - str.replace( pref.length(), str.length() - overhead, core ); - } - else - { - state = QDoubleValidator::validate( str, pos ); - if ( state == Invalid ) - { - QString special = spinBox->specialValueText().stripWhiteSpace(); - QString candidate = str.stripWhiteSpace(); - if ( special.startsWith( candidate ) ) - { - if ( candidate.length() == special.length() ) - state = Acceptable; - else - state = Intermediate; - } - } - } - } - return state; -} - -/*! - Constructor -*/ -QtxDblSpinBox::QtxDblSpinBox( QWidget* parent, const char* name ) -: QSpinBox( parent, name ), -myCleared( false ), -myBlocked( false ), -myPrecision( 0 ) -{ - myMin = -DBL_MAX; - myMax = DBL_MAX; - myStep = QRangeControl::lineStep(); - myValue = 0; - setValidator( new Validator( this, "double_spinbox_validator" ) ); - rangeChange(); - updateDisplay(); - - connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); -} - -/*! - Constructor -*/ -QtxDblSpinBox::QtxDblSpinBox( double min, double max, double step, QWidget* parent, const char* name ) -: QSpinBox( parent, name ), -myMin( min ), -myMax( max ), -myStep( step ), -myCleared( false ), -myBlocked( false ), -myPrecision( 0 ) -{ - myValue = myMin; - setValidator( new Validator( this, "double_spinbox_validator" ) ); - rangeChange(); - updateDisplay(); - - connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); -} - -/*! - Destructor -*/ -QtxDblSpinBox::~QtxDblSpinBox() -{ -} - -/*! - \return min value of spin box -*/ -double QtxDblSpinBox::minValue() const -{ - return myMin; -} - -/*! - \return max value of spin box -*/ -double QtxDblSpinBox::maxValue() const -{ - return myMax; -} - -/*! - Changes min value of spin box - \param min - new min value -*/ -void QtxDblSpinBox::setMinValue( int min ) -{ - setMinValue( (double)min ); -} - -/*! - Changes min value of spin box - \param min - new min value -*/ -void QtxDblSpinBox::setMinValue( double min ) -{ - if ( myMin != min ) - { - myMin = min; - rangeChange(); - } -} - -/*! - Changes max value of spin box - \param max - new max value -*/ -void QtxDblSpinBox::setMaxValue( int max ) -{ - setMaxValue( (double)max ); -} - -/*! - Changes max value of spin box - \param max - new max value -*/ -void QtxDblSpinBox::setMaxValue( double max ) -{ - if ( myMax != max ) - { - myMax = max; - rangeChange(); - } -} - -/*! - Changes min and max value of spin box - \param min - new min value - \param max - new max value -*/ -void QtxDblSpinBox::setRange( int min, int max ) -{ - setRange( (double)min, (double)max ); -} - -/*! - Changes min and max value of spin box - \param min - new min value - \param max - new max value -*/ -void QtxDblSpinBox::setRange( double min, double max ) -{ - if ( myMin != min || myMax != max ) - { - myMin = min; - myMax = max; - rangeChange(); - } -} - -/*! - \return step of spin box -*/ -double QtxDblSpinBox::lineStep() const -{ - return myStep; -} - -/*! - Changes step of spin box - \param step - new step -*/ -void QtxDblSpinBox::setLineStep( int step ) -{ - setLineStep( (double)step ); -} - -/*! - Changes step of spin box - \param step - new step -*/ -void QtxDblSpinBox::setLineStep( double step ) -{ - myStep = step; -} - -/*! - \return value of spin box -*/ -double QtxDblSpinBox::value() const -{ - QSpinBox::value(); - - return myValue; -} - -/*! - Changes value of spin box - \param val - new value of spin box -*/ -void QtxDblSpinBox::setValue( int val ) -{ - setValue( (double)val ); -} - -/*! - Changes value of spin box - \param val - new value of spin box -*/ -void QtxDblSpinBox::setValue( double val ) -{ - myCleared = false; - double prevVal = myValue; - myValue = bound( val ); - if ( prevVal != myValue ) - valueChange(); -} - -/*! - Adds step to value -*/ -void QtxDblSpinBox::stepUp() -{ - interpretText(); - if ( wrapping() && myValue + myStep > myMax ) - setValue( myMin ); - else - setValue( myValue + myStep ); -} - -/*! - Subtracks step from value -*/ -void QtxDblSpinBox::stepDown() -{ - interpretText(); - if ( wrapping() && myValue - myStep < myMin ) - setValue( myMax ); - else - setValue( myValue - myStep ); -} - -/*! - \return number of digit after comma -*/ -int QtxDblSpinBox::precision() const -{ - return myPrecision; -} - -/*! - Changes number of digit after comma - \param prec - new digit number -*/ -void QtxDblSpinBox::setPrecision( const int prec ) -{ - int newPrec = QMAX( prec, 0 ); - int oldPrec = QMAX( myPrecision, 0 ); - myPrecision = prec; - if ( newPrec != oldPrec ) - updateDisplay(); -} - -/*! - \return true if spin box is cleared -*/ -bool QtxDblSpinBox::isCleared() const -{ - return myCleared; -} - -/*! - Changes cleared status of spin box - \param on - new status -*/ -void QtxDblSpinBox::setCleared( const bool on ) -{ - if ( myCleared == on ) - return; - - myCleared = on; - updateDisplay(); -} - -/*! - Selects all content of spin box editor -*/ -void QtxDblSpinBox::selectAll() -{ -#if QT_VER >= 3 - QSpinBox::selectAll(); -#else - editor()->selectAll(); -#endif -} - -/*! - Custom event filter, updates text of spin box editor -*/ -bool QtxDblSpinBox::eventFilter( QObject* o, QEvent* e ) -{ - if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() ) - { - bool state = QSpinBox::eventFilter( o, e ); - if ( e->type() == QEvent::FocusOut && o == editor() ) - updateDisplay(); - return state; - } - - if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide ) - return false; - - if ( e->type() == QEvent::KeyPress && - ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) ) - { - QApplication::sendEvent( this, e ); - return true; - } - - return QSpinBox::eventFilter( o, e ); -} - -/*! - Updates text of editor -*/ -void QtxDblSpinBox::updateDisplay() -{ - if ( myBlocked ) - return; - - bool upd = editor()->isUpdatesEnabled(); - editor()->setUpdatesEnabled( false ); - - bool isBlock = myBlocked; - myBlocked = true; - - QString txt = currentValueText(); - - if ( myValue >= myMax ) - QSpinBox::setValue( QSpinBox::maxValue() ); - else if ( myValue <= myMin ) - QSpinBox::setValue( QSpinBox::minValue() ); - else - QSpinBox::setValue( ( QSpinBox::minValue() + QSpinBox::maxValue() ) / 2 ); - - QSpinBox::updateDisplay(); - - editor()->setUpdatesEnabled( upd ); - - editor()->setText( myCleared ? QString::null : txt ); - if ( !myCleared && editor()->hasFocus() ) - { - if ( editor()->text() == specialValueText() ) - editor()->selectAll(); - else - editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() ); - } - else - editor()->setCursorPosition( 0 ); - - myBlocked = isBlock; -} - -/*! - Sets double value by text in editor -*/ -void QtxDblSpinBox::interpretText() -{ - myCleared = false; - - bool ok = true; - bool done = false; - double newVal = 0; - if ( !specialValueText().isEmpty() ) - { - QString s = QString( text() ).stripWhiteSpace(); - QString t = QString( specialValueText() ).stripWhiteSpace(); - if ( s == t ) - { - newVal = minValue(); - done = true; - } - } - if ( !done ) - newVal = mapTextToDoubleValue( &ok ); - if ( ok ) - setValue( newVal ); - updateDisplay(); -} - -/*! - Emits signal "valueChanged" -*/ -void QtxDblSpinBox::valueChange() -{ - updateDisplay(); - emit valueChanged( myValue ); - emit valueChanged( currentValueText() ); -} - -/*! - Attune parameters on range changing -*/ -void QtxDblSpinBox::rangeChange() -{ - double min = QMIN( myMin, myMax ); - double max = QMAX( myMin, myMax ); - myMin = min; - myMax = max; - QDoubleValidator* v = ::qt_cast( validator() ); - if ( v ) - v->setRange( myMin, myMax ); - - if ( myMin == myMax ) - QSpinBox::setRange( 0, 0 ); - else - QSpinBox::setRange( 0, 2 ); - - setValue( myValue ); - updateDisplay(); -} - -/*! - \return text of editor -*/ -QString QtxDblSpinBox::currentValueText() -{ - QString s; - if ( (myValue == minValue()) && !specialValueText().isEmpty() ) - s = specialValueText(); - else - { - s = prefix(); - s.append( mapValueToText( myValue ) ); - s.append( suffix() ); - } - return s; -} - -/*! - Converts number to string - \param v - number to be converted -*/ -QString QtxDblSpinBox::mapValueToText( double v ) -{ - QString s; - s.setNum( v, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) ); - return removeTrailingZeroes( s ); -} - -/*! - Converts value to string -*/ -QString QtxDblSpinBox::mapValueToText( int ) -{ - QString s; - s.setNum( myValue, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) ); - return removeTrailingZeroes( s ); -} - -/*! - Converts current text of editor to double -*/ -double QtxDblSpinBox::mapTextToDoubleValue( bool* ok ) -{ - QString s = text(); - double newVal = s.toDouble( ok ); - if ( !(*ok) && !( !prefix() && !suffix() ) ) - { - s = cleanText(); - newVal = s.toDouble( ok ); - } - return newVal; -} - -/*! - \return value corrected in accordance with borders - \param val - value to be corrected -*/ -double QtxDblSpinBox::bound( double val ) -{ - double newVal = val; - if ( newVal > myMax ) - newVal = myMax; - if ( newVal < myMin ) - newVal = myMin; - return newVal; -} - -/*! - Custom handler for leave event -*/ -void QtxDblSpinBox::leaveEvent( QEvent* e ) -{ - if ( !myCleared ) - QSpinBox::leaveEvent( e ); -} - -/*! - Custom handler for wheel event -*/ -void QtxDblSpinBox::wheelEvent( QWheelEvent* e ) -{ - if ( !isEnabled() ) - return; - - QSpinBox::wheelEvent( e ); - updateDisplay(); -} - -/*! - SLOT: called if text is changed -*/ -void QtxDblSpinBox::onTextChanged( const QString& str ) -{ - if ( !myBlocked ) - myCleared = false; -} - -/*! - \return string without excess zeros in start and in end -*/ -QString QtxDblSpinBox::removeTrailingZeroes( const QString& src ) const -{ - QString delim( "." ); - - int idx = src.findRev( delim ); - if ( idx == -1 ) - return src; - - QString iPart = src.left( idx ); - QString fPart = src.mid( idx + 1 ); - - while ( !fPart.isEmpty() && fPart.at( fPart.length() - 1 ) == '0' ) - fPart.remove( fPart.length() - 1, 1 ); - - QString res = iPart; - if ( !fPart.isEmpty() ) - res += delim + fPart; - - return res; -} diff --git a/src/Qtx/QtxDblSpinBox.h b/src/Qtx/QtxDblSpinBox.h deleted file mode 100755 index b715fb3a2..000000000 --- a/src/Qtx/QtxDblSpinBox.h +++ /dev/null @@ -1,113 +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: QtxDblSpinBox.h -// Author: Sergey TELKOV - -#ifndef QTXDBLSPINBOX_H -#define QTXDBLSPINBOX_H - -#include "Qtx.h" - -#include - -/*! - \class QtxDblSpinBox - Spin box for real numbers. -*/ -class QTX_EXPORT QtxDblSpinBox : public QSpinBox -{ - Q_OBJECT - - class Validator; - -public: - typedef enum QSpinBox::ButtonSymbols ButtonSymbols; - -public: - QtxDblSpinBox( QWidget* = 0, const char* = 0 ); - QtxDblSpinBox( double, double, double = 1, QWidget* = 0, const char* = 0 ); - virtual ~QtxDblSpinBox(); - - double minValue() const; - double maxValue() const; - void setMinValue( int ); - void setMaxValue( int ); - void setMinValue( double ); - void setMaxValue( double ); - void setRange( int, int ); - virtual void setRange( double, double ); - - double lineStep() const; - void setLineStep( int ); - virtual void setLineStep( double ); - - double value() const; - - int precision() const; - virtual void setPrecision( const int ); - - bool isCleared() const; - virtual void setCleared( const bool ); - - virtual bool eventFilter( QObject*, QEvent* ); - -signals: - void valueChanged( double ); - void valueChanged( const QString& ); - -public slots: - virtual void stepUp(); - virtual void stepDown(); - virtual void selectAll(); - virtual void setValue( int ); - virtual void setValue( double ); - -protected slots: - virtual void onTextChanged( const QString& ); - -protected: - virtual void updateDisplay(); - virtual void interpretText(); - - virtual void valueChange(); - virtual void rangeChange(); - - QString currentValueText(); - virtual QString mapValueToText( int ); - virtual QString mapValueToText( double ); - virtual double mapTextToDoubleValue( bool* ); - - virtual void leaveEvent( QEvent* ); - virtual void wheelEvent( QWheelEvent* ); - - double bound( double ); - - QString removeTrailingZeroes( const QString& ) const; - -private: - double myMin; - double myMax; - double myStep; - double myValue; - bool myCleared; - bool myBlocked; - int myPrecision; -}; - -#endif diff --git a/src/Qtx/QtxDblValidator.cxx b/src/Qtx/QtxDblValidator.cxx deleted file mode 100644 index b7dd3e9d0..000000000 --- a/src/Qtx/QtxDblValidator.cxx +++ /dev/null @@ -1,62 +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: QtxDblValidator.cxx -// Author: Alexandre SOLOVYOV - -#include "QtxDblValidator.h" - -/*! - Constructor - \param bot - minimal possible value - \param top - maximal possible value - \param dec - number of digits - \param o - parent object - \param name - name of validator -*/ -QtxDblValidator::QtxDblValidator( const double bot, const double top, const int dec, - QObject* o, const char* name ) -: QDoubleValidator( bot, top, dec, o, name ) -{ -} - -/*! - Destructor -*/ -QtxDblValidator::~QtxDblValidator() -{ -} - -/*! - Corrects string: if it represent double value less then bottom, it becomes equal to bottom, - if it is more then top, it becomes equal to top, if it isn't number is becomes '0' -*/ -void QtxDblValidator::fixup( QString& str ) const -{ - bool ok = false; - double d = str.toDouble( &ok ); - if( ok ) - { - if( dtop() ) - str = QString::number( top() ); - } - else - str = "0"; -} diff --git a/src/Qtx/QtxDblValidator.h b/src/Qtx/QtxDblValidator.h deleted file mode 100644 index a5b389fd1..000000000 --- a/src/Qtx/QtxDblValidator.h +++ /dev/null @@ -1,41 +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: QtxDblValidator.h -// Author: Alexandre SOLOVYOV - -#ifndef QTX_DOUBLE_VALIDATOR -#define QTX_DOUBLE_VALIDATOR - -#include "Qtx.h" - -#include - -class QTX_EXPORT QtxDblValidator : public QDoubleValidator -{ - Q_OBJECT - -public: - QtxDblValidator( const double, const double, const int, - QObject*, const char* = 0 ); - ~QtxDblValidator(); - - virtual void fixup( QString& ) const; -}; - -#endif diff --git a/src/Qtx/QtxDialog.cxx b/src/Qtx/QtxDialog.cxx deleted file mode 100755 index c52cb85fe..000000000 --- a/src/Qtx/QtxDialog.cxx +++ /dev/null @@ -1,1454 +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: QtxDialog.cxx -// Author: Sergey TELKOV - -#include "QtxDialog.h" - -#include "QtxGroupBox.h" - -#include -#include -#include -#include -#include - -/*! - Class: QtxDialog::Area - Level: Internal -*/ -class QtxDialog::Area : public QFrame -{ -public: - Area( Orientation, QtxDialog*, QWidget* = 0 ); - virtual ~Area(); - - bool isBorderEnabled() const; - void setBorderEnabled( const bool ); - - void setBorderWidget( QLabel* ); - - void insertButton( QButton* ); - void removeButton( QButton* ); - bool contains( QButton* ) const; - - int policy() const; - void setPolicy( const int ); - - void layoutButtons(); - - const QPtrList& buttons() const; - -private: - void updateBorder(); - -private: - QtxDialog* myDlg; - QLabel* myLine; - bool myBorder; - int myPolicy; - QPtrList myButtons; - Orientation myOrientation; -}; - -/*! - Contructor -*/ -QtxDialog::Area::Area( Orientation o, QtxDialog* dlg, QWidget* parent ) -: QFrame( parent ), -myDlg( dlg ), -myLine( 0 ), -myBorder( false ), -myPolicy( Position ), -myOrientation( o ) -{ - if ( myOrientation == Qt::Horizontal ) - setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); - else - setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); - - hide(); -} - -/*! - Destructor -*/ -QtxDialog::Area::~Area() -{ -} - -/*! - Inserts button to area - \param b - button -*/ -void QtxDialog::Area::insertButton( QButton* b ) -{ - if ( !b || myButtons.findRef( b ) != -1 ) - return; - - QWidget* parent = b->parentWidget(); - if ( parent != this ) - b->reparent( this, 0, QPoint( 0, 0 ), b->isVisibleTo( parent ) ); - - myButtons.append( b ); - - if ( myDlg ) - myDlg->adjustButtons(); - layoutButtons(); - - show(); - - updateBorder(); -} - -/*! - Removes button from area - \param b - button -*/ -void QtxDialog::Area::removeButton( QButton* b ) -{ - if ( !b ) - return; - - myButtons.removeRef( b ); - - if ( myButtons.isEmpty() ) - hide(); - - updateBorder(); - - if ( myDlg ) - myDlg->adjustButtons(); - - layoutButtons(); -} - -/*! - \return true if area contains button - \param b - button -*/ -bool QtxDialog::Area::contains( QButton* b ) const -{ - return myButtons.containsRef( b ); -} - -/*! - \return policy of button layouting. -*/ -int QtxDialog::Area::policy() const -{ - return myPolicy; -} - -/*! - Changes policy of button layouting. - \param p - new policy -*/ -void QtxDialog::Area::setPolicy( const int p ) -{ - if ( myPolicy == p ) - return; - - myPolicy = p; - layoutButtons(); -} - -/*! - \return true if border enabled -*/ -bool QtxDialog::Area::isBorderEnabled() const -{ - return myLine && myBorder; -} - -/*! - Enables/disable separator between main frame and button frame - \param on - new state -*/ -void QtxDialog::Area::setBorderEnabled( const bool on ) -{ - if ( !myLine || myBorder == on ) - return; - - myBorder = on; - updateBorder(); -} - -/*! - Sets label as separator between main frame and button frame - \param line - new separator -*/ -void QtxDialog::Area::setBorderWidget( QLabel* line ) -{ - if ( myLine == line ) - return; - - delete myLine; - myLine = line; - updateBorder(); -} - -/*! - \return const reference to list of buttons -*/ -const QPtrList& QtxDialog::Area::buttons() const -{ - return myButtons; -} - -/*! - Updates visibility of border -*/ -void QtxDialog::Area::updateBorder() -{ - if ( !myLine ) - return; - - bool isVis = isVisibleTo( parentWidget() ); -#if QT_VER >= 3 - if ( isVis ) -#else - if ( isVis && myBorder ) -#endif - myLine->show(); - else - myLine->hide(); - - myLine->setLineWidth( myBorder ? 1 : 0 ); -} - -/*! - Installs buttons into layout -*/ -void QtxDialog::Area::layoutButtons() -{ - int aPolicy = policy(); - - QMap buttonId; - for ( QPtrListIterator it1( myButtons ); it1.current(); ++it1 ) - buttonId.insert( it1.current(), 0 ); - - QPtrList src; - for ( ButtonMap::Iterator mit = myDlg->myButton.begin(); - mit != myDlg->myButton.end(); ++mit ) - { - if ( buttonId.contains( mit.data() ) ) - { - buttonId[mit.data()] = mit.key(); - if ( mit.key() >= 0 ) - src.append( mit.data() ); - } - } - - for ( QPtrListIterator it2( myButtons ); it2.current(); ++it2 ) - if ( buttonId[it2.current()] < 0 ) - src.append( it2.current() ); - - QPtrList left, right, center, other; - for ( QPtrListIterator it( src ); it.current(); ++it ) - { - if ( !it.current()->isVisibleTo( this ) ) - continue; - - int aPosition = myDlg->buttonPosition( it.current() ); - if ( aPosition == -1 ) - continue; - - if ( aPolicy != QtxDialog::Position ) - other.append( it.current() ); - else if ( aPosition == QtxDialog::Left ) - left.append( it.current() ); - else if ( aPosition == QtxDialog::Right ) - right.append( it.current() ); - else if ( aPosition == QtxDialog::Center ) - center.append( it.current() ); - } - - delete layout(); - - QBoxLayout* buttonLayout = 0; - if ( myOrientation == Qt::Vertical ) - buttonLayout = new QVBoxLayout( this, 0, 5 ); - else - buttonLayout = new QHBoxLayout( this, 0, 5 ); - - if ( !buttonLayout ) - return; - - if ( aPolicy == QtxDialog::Position ) - { - for ( QPtrListIterator lit( left ); lit.current(); ++lit ) - buttonLayout->addWidget( lit.current() ); - buttonLayout->addStretch( 1 ); - for ( QPtrListIterator cit( center ); cit.current(); ++cit ) - buttonLayout->addWidget( cit.current() ); - buttonLayout->addStretch( 1 ); - for ( QPtrListIterator rit( right ); rit.current(); ++rit ) - buttonLayout->addWidget( rit.current() ); - } - else - { - for ( QPtrListIterator oit( other ); oit.current(); ++oit ) - { - buttonLayout->addWidget( oit.current() ); - if ( aPolicy == QtxDialog::Uniform && !oit.atLast() ) - buttonLayout->addStretch( 1 ); - } - } - - QWidgetList wids; - if ( layout() ) - { - for ( QLayoutIterator it = layout()->iterator(); it.current(); ++it ) - { - if ( !it.current()->widget() ) - continue; - - if ( QApplication::reverseLayout() ) - wids.prepend( it.current()->widget() ); - else - wids.append( it.current()->widget() ); - } - } - Qtx::setTabOrder( wids ); -} - - -/*! - \class QtxDialog::Border - - Special label used as separator between main frame and button frame -*/ -class QtxDialog::Border : public QLabel -{ -public: - Border( QWidget* = 0 ); - virtual ~Border(); - - virtual void setLineWidth( int ); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; -}; - -/*! - Constructor -*/ -QtxDialog::Border::Border( QWidget* parent ) -: QLabel( parent ) -{ - setAlignment( Qt::AlignCenter ); -} - -/*! - Destructor -*/ -QtxDialog::Border::~Border() -{ -} - -/*! - Set line width of separator - \param lw - new line width -*/ -void QtxDialog::Border::setLineWidth( int lw ) -{ - bool isOn = lineWidth() > 0; - - QLabel::setLineWidth( lw ); - - if ( isOn != ( lineWidth() > 0 ) ) - updateGeometry(); -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxDialog::Border::sizeHint() const -{ - QSize sz( 5, 5 ); - -#if QT_VER >= 3 - if ( lineWidth() > 0 ) - { - if ( frameShape() == VLine ) - sz += QSize( 5 + lineWidth(), 0 ); - else if ( frameShape() == HLine ) - sz += QSize( 0, 5 + lineWidth() ); - } -#endif - - return sz; -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxDialog::Border::minimumSizeHint() const -{ - return sizeHint(); -} - -/*! - Constructor - Construct a dialog with specified parent and name. - \param modal define modal status of dialog (default non modal dialog created). - \param allowResize - if it is true then dialog can be resize by user (default non resizable dialog created). - \param Button flags specified control buttons for dialog (default buttons is OK, Cancel and Help). - \param Widget flags used as in any widget. -*/ -QtxDialog::QtxDialog( QWidget* parent, const char* name, - bool modal, bool allowResize, const int f, WFlags wf ) -: QDialog( parent, name, modal, - wf | WStyle_Customize | WStyle_Title | WStyle_SysMenu | -#ifdef WIN32 - ( allowResize ? WStyle_NormalBorder : WStyle_NoBorderEx ) | -#else - WStyle_NormalBorder | -#endif - ( allowResize ? WStyle_Maximize : 0 ) ), -mySender( 0 ), -myAlignment( 0 ), -myInited( false ), -myDialogFlags( Accept | SetFocus ) -{ - QVBoxLayout* base = new QVBoxLayout( this, 5, 0 ); - QtxGroupBox* main = new QtxGroupBox( 1, Qt::Horizontal, "", this ); - main->setFrameStyle( QFrame::NoFrame ); - main->setInsideMargin( 0 ); - main->setInsideSpacing( 0 ); - base->addWidget( main ); - - Area* topArea = new Area( Qt::Horizontal, this, main ); - QLabel* topLine = new Border( main ); - QtxGroupBox* midGroup = new QtxGroupBox( 1, Qt::Vertical, "", main ); - QLabel* botLine = new Border( main ); - Area* botArea = new Area( Qt::Horizontal, this, main ); - - midGroup->setFrameStyle( QFrame::NoFrame ); - midGroup->setInsideMargin( 0 ); - midGroup->setInsideSpacing( 0 ); - - Area* leftArea = new Area( Qt::Vertical, this, midGroup ); - QLabel* leftLine = new Border( midGroup ); - myMainFrame = new QFrame( midGroup ); - QLabel* rightLine = new Border( midGroup ); - Area* rightArea = new Area( Qt::Vertical, this, midGroup ); - - myMainFrame->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, - QSizePolicy::Expanding ) ); - - topLine->setFrameStyle( QFrame::Sunken | QFrame::HLine ); - botLine->setFrameStyle( QFrame::Sunken | QFrame::HLine ); - leftLine->setFrameStyle( QFrame::Sunken | QFrame::VLine ); - rightLine->setFrameStyle( QFrame::Sunken | QFrame::VLine ); - topArea->setBorderWidget( topLine ); - botArea->setBorderWidget( botLine ); - leftArea->setBorderWidget( leftLine ); - rightArea->setBorderWidget( rightLine ); - - myArea.insert( TopArea, topArea ); - myArea.insert( BottomArea, botArea ); - myArea.insert( LeftArea, leftArea ); - myArea.insert( RightArea, rightArea ); - - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++ itr ) - itr.data()->setBorderEnabled( false ); - - myButton.insert( OK, new QPushButton( tr( "&OK" ), this ) ); - myButton.insert( Cancel, new QPushButton( tr( "&Cancel" ), this ) ); - myButton.insert( Close, new QPushButton( tr( "C&lose" ), this ) ); - myButton.insert( Help, new QPushButton( tr( "&Help" ), this ) ); - myButton.insert( Apply, new QPushButton( tr( "&Apply" ), this ) ); - myButton.insert( Yes, new QPushButton( tr( "&Yes" ), this ) ); - myButton.insert( No, new QPushButton( tr( "&No" ), this ) ); - - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - { - ((QPushButton*)it.data())->setAutoDefault( false ); -#if QT_VER >= 3 - connect( it.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); -#endif - } - - setButtonPosition( Left, OK | Cancel | Apply ); - setButtonPosition( Center, Yes | No | Close ); - setButtonPosition( Right, Help ); - setButtonPlace( BottomArea, All ); - - connect( myButton[Apply], SIGNAL( clicked() ), this, SIGNAL( dlgApply() ) ); - connect( myButton[Help], SIGNAL( clicked() ), this, SIGNAL( dlgHelp() ) ); - - connect( myButton[OK], SIGNAL( clicked() ), this, SLOT( onAccept() ) ); - connect( myButton[Cancel], SIGNAL( clicked() ), this, SLOT( onReject() ) ); - connect( myButton[Yes], SIGNAL( clicked() ), this, SLOT( onAccept() ) ); - connect( myButton[No], SIGNAL( clicked() ), this, SLOT( onReject() ) ); - connect( myButton[Close], SIGNAL( clicked() ), this, SLOT( onReject() ) ); - - QPixmap icon; - if ( qApp && qApp->mainWidget() && qApp->mainWidget()->icon() ) - setIcon( *qApp->mainWidget()->icon() ); - - myButtonFlags = f; - -#ifndef WIN32 - if ( !allowResize ) - setMaximumSize( minimumSize() ); -#endif - - update(); -} - -/*! - Name: ~QtxDialog [public] - Desc: Destructor -*/ - -QtxDialog::~QtxDialog() -{ -} - -/*! - Name: setButtonFlags [public] - Desc: Allow to set specified control button(s) into dialog. -*/ - -void QtxDialog::setButtonFlags( const int f ) -{ - int old = myButtonFlags; - myButtonFlags = myButtonFlags | f; - if ( old != myButtonFlags ) - update(); -} - -/*! - Name: clearButtonFlags [public] - Desc: Allow to unset specified control button(s) from dialog. -*/ - -void QtxDialog::clearButtonFlags( const int f ) -{ - int old = myButtonFlags; - myButtonFlags = myButtonFlags & ~f; - if ( old != myButtonFlags ) - update(); -} - -/*! - Name: testButtonFlags [public] - Desc: Return true if specified control button is used in dialog. -*/ - -bool QtxDialog::testButtonFlags( const int f ) const -{ - return ( myButtonFlags & f ) == f; -} - -/*! - Name: setDialogFlags [public] - Desc: Allow to set the dialog flags. - - Following flags can be used: - Accept - Allow to control dialog accepting. See also acceptData(). - Reject - Allow to control dialog rejecting. See also rejectData(). - AlignOnce - Allow to align dialog only when it first time shown. - SetFocus - Allow to set focus on dialog when it shown. User can use - setFocusProxy() and specify own initial focus widget. -*/ - -void QtxDialog::setDialogFlags( const int f ) -{ - myDialogFlags = myDialogFlags | f; -} - -/*! - Name: clearDialogFlags [public] - Desc: Allow to clear the dialog flags. See also setDialogFlags(). -*/ - -void QtxDialog::clearDialogFlags( const int f ) -{ - myDialogFlags = myDialogFlags & ~f; -} - -/*! - Name: testDialogFlags [public] - Desc: Returns true if specified dialog flag is setted (see setDialogFlags()). -*/ - -bool QtxDialog::testDialogFlags( const int f ) const -{ - return ( myDialogFlags & f ) == f; -} - -/*! - Name: mainFrame [public] - Desc: Returns main frame of dialog. Main frame should contains all - elements of dialog except control buttons. -*/ - -QFrame* QtxDialog::mainFrame() const -{ - return myMainFrame; -} - -/*! - Name: buttonPosition [public] - Desc: Returns position of specified button. -*/ - -int QtxDialog::buttonPosition( const int id ) const -{ - int pos = -1; - if ( myPosition.contains( id ) ) - pos = myPosition[id]; - return pos; -} - -/*! - Name: setButtonPosition [public] - Desc: Sets the position for specified button(s). Following positions - may be used: Left, Right, Center, Top, Bottom. -*/ - -void QtxDialog::setButtonPosition( const int pos, const int id ) -{ - ButtonMap map = buttons( id ); - - QMap changed; - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - { - if ( myPosition[it.key()] == pos ) - continue; - - myPosition[it.key()] = pos; - if ( button( it.key() ) ) - changed.insert( button( it.key() )->parent(), 0 ); - } - - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) - if ( changed.contains( itr.data() ) ) - itr.data()->layoutButtons(); -} - -/*! - Name: setPlacePosition [public] - Desc: Sets button position for all buttons in given place. -*/ - -void QtxDialog::setPlacePosition( const int pos, const int area ) -{ - if ( !myArea.contains( area ) ) - return; - - Area* anArea = myArea[area]; - - bool changed = false; - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - { - if ( !anArea->contains( it.data() ) ) - continue; - - changed = changed && myPosition[it.key()] != pos; - - myPosition[it.key()] = pos; - } - - if ( changed ) - anArea->layoutButtons(); -} - -/*! - Name: placePolicy [public] - Desc: Returns policy of button layouting for specified place. - - Following place may be used: - TopArea - Horizontal area in the top side of dialog. - BottomArea - Horizontal area in the bottom side of dialog. - LeftArea - Vertical area in the left side of dialog. - RightArea - Vertical area in the right side of dialog. - - Following policy may be used: - Position - Buttons placed according their position. - Expand - Buttons fills all available space. - Uniform - Buttons uniformly placed in area. -*/ - -int QtxDialog::placePolicy( const int area ) const -{ - int res = -1; - if ( myArea.contains( area ) ) - res = myArea[area]->policy(); - return res; -} - -/*! - Name: setPlacePolicy [public] - Desc: Sets the policy of button layouting for specified place. - See also placePolicy(). -*/ - -void QtxDialog::setPlacePolicy( const int policy, const int area ) -{ - if ( area < 0 ) - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) - itr.data()->setPolicy( policy ); - else if ( myArea.contains( area ) ) - myArea[area]->setPolicy( policy ); -} - -/*! - Name: setButtonPlace [public] - Desc: Move given button(s) into specified place. -*/ - -void QtxDialog::setButtonPlace( const int area, const int ids ) -{ - if ( !myArea.contains( area ) ) - return; - - Area* anArea = myArea[area]; - - ButtonMap map = buttons( ids ); - - QMap areaMap; - for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt ) - areaMap.insert( aIt.data(), 0 ); - - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - { - Area* old = (Area*)it.data()->parent(); - if ( old == anArea ) - continue; - - if ( areaMap.contains( old ) ) - old->removeButton( it.data() ); - anArea->insertButton( it.data() ); - } -} - -/*! - Name: isBorderEnabled [public] - Desc: Returns true if border is shown for specified button area. -*/ - -bool QtxDialog::isBorderEnabled( const int area ) const -{ - bool res = false; - if ( myArea.contains( area ) ) - res = myArea[area]->isBorderEnabled(); - return res; -} - -/*! - Name: setBorderEnabled [public] - Desc: Show/hide border for specified button area. Border are - line which separate main frame and control buttons. -*/ - -void QtxDialog::setBorderEnabled( const bool on, const int area ) -{ - if ( !myArea.contains( area ) ) - return; - - if ( myArea[area]->isBorderEnabled() == on ) - return; - - myArea[area]->setBorderEnabled( on ); - - if ( isVisible() ) - { - QApplication::sendPostedEvents(); - adjustSize(); - } -} - -/*! - Name: isButtonEnabled [public] - Desc: Returns true if all specified button(s) is enabled. -*/ - -bool QtxDialog::isButtonEnabled( const int f ) const -{ - ButtonMap map = buttons( f ); - bool result = !map.isEmpty(); - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - result = result && it.data()->isEnabled(); - return result; -} - -/*! - Name: setButtonEnabled [public] - Desc: Enable/disable specified button(s). -*/ - -void QtxDialog::setButtonEnabled( const bool on, const int ids ) -{ - ButtonMap map = buttons( ids ); - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - it.data()->setEnabled( on ); -} - -/*! - Name: hasButtonFocus [public] - Desc: Retruns true if specified button has keyboard focus. -*/ - -bool QtxDialog::hasButtonFocus( const int id ) const -{ - bool res = false; - QButton* pb = button( id ); - if ( pb ) - res = pb->hasFocus(); - return res; -} - -/*! - Name: setButtonFocus [public] - Desc: Sets the keyboard focus on specified button. -*/ - -void QtxDialog::setButtonFocus( const int id ) -{ - QButton* pb = button( id ); - if ( pb ) - pb->setFocus(); -} - -/*! - Name: buttonText [public] - Desc: Return text of specified button. -*/ - -QString QtxDialog::buttonText( const int id ) -{ - QString retval; - QButton* but = button( id ); - if ( but ) - retval = but->text(); - return retval; -} - -/*! - Name: setButtonText [public] - Desc: Sets text to specified button. -*/ - -void QtxDialog::setButtonText( const int id, const QString& text ) -{ - QButton* but = button( id ); - if ( but && but->text() != text ) - { - but->setText( text ); - adjustButtons(); - } -} - -/*! - Name: setAlignment [public] - Desc: Sets alignment policy. Returns the previous alignment. - Use the function before the first show of the dialog. - If dialog flag AlignOnce is setted then align will performed - only one time otherwise dialog will be aligned every time - when it shown. Dialog will be aligned relative to it parent. - - Following align flags may be used: - Qtx::AlignAuto - Align to center of desktop (default). - Qtx::AlignLeft - Align left side of dialog to left side of parent. - Qtx::AlignRight - Align right side of dialog to right side of parent. - Qtx::AlignTop - Align top side of dialog to top side of parent. - Qtx::AlignBottom - Align bottom side of dialog to bottom side of parent. - Qtx::AlignHCenter - Align dialog to center of parent in horizontal dimension. - Qtx::AlignVCenter - Align dialog to center of parent in vertical dimension. - Qtx::AlignCenter - Align dialog to center of parent in both dimensions. - Qtx::AlignOutLeft - Align right side of dialog to left side of parent. - Qtx::AlignOutRight - Align left side of dialog to right side of parent. - Qtx::AlignOutTop - Align bottom side of dialog to top side of parent. - Qtx::AlignOutBottom - Align top side of dialog to bottom side of parent. -*/ - -uint QtxDialog::setAlignment( uint align ) -{ - uint oldAlign = myAlignment; - myAlignment = align; - return oldAlign; -} - -/*! - Name: update [virtual public slot] - Desc: Updates dialog, show selected buttons and hide unselected. -*/ - -void QtxDialog::update() -{ - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - if ( it.key() >= 0 ) - testButtonFlags( it.key() ) ? it.data()->show() : it.data()->hide(); - - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) - itr.data()->layoutButtons(); - - adjustButtons(); - - QDialog::update(); -} - -/*! - Name: show [virtual public] - Desc: Show dialog, set keyboard focus on dialog. -*/ - -void QtxDialog::show() -{ - QDialog::show(); - - if ( testDialogFlags( SetFocus ) ) - setFocus(); - - myInited = true; -} - -/*! - Name: hide [virtual public] - Desc: Hides dialog, processed all posted events. -*/ - -void QtxDialog::hide() -{ - QDialog::hide(); - qApp->processEvents(); -} - -/*! - Name: userButton [public] - Desc: Return user dialog button using specified identificator. -*/ - -QButton* QtxDialog::userButton( const int id ) const -{ - QButton* b = 0; - if ( id < -1 && myButton.contains( id ) ) - b = myButton[id]; - return b; -} - -/*! - Name: userButtonIds [public] - Desc: Return list of user dialog button identificators. -*/ - -QValueList QtxDialog::userButtonIds() const -{ - QValueList retlist; - for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it ) - if ( it.key() < 0 ) - retlist.append( it.key() ); - return retlist; -} - -/*! - Name: insertButton [public] - Desc: Add new user dialog button. Function return identificator of - newly added button in successfull case otherwise -1 will be returned. -*/ - -int QtxDialog::insertButton( const QString& text, const int area ) -{ - if ( !myArea.contains( area ) ) - return -1; - - int id = -2; - while ( myButton.contains( id ) ) - id--; - - Area* anArea = myArea[area]; - QButton* b = createButton( this ); - if ( b ) - { - b->setText( text ); - myButton.insert( id, b ); - myPosition.insert( id, Left ); - - connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) ); -#if QT_VER >= 3 - connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); -#endif - - anArea->insertButton( b ); - update(); - } - else - id = -1; - - return id; -} - -/*! - Name: removeButton [public] - Desc: Remove user dialog button with specified identificator. If - identificator equal -1 then method will remove all user dialog buttons. -*/ - -void QtxDialog::removeButton( const int id ) -{ - if ( id >= 0 ) - return; - - ButtonMap map; - if ( id == -1 ) - { - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - { - if ( it.key() < 0 ) - map.insert( it.key(), it.data() ); - } - } - else if ( myButton.contains( id ) ) - map.insert( id, myButton[id] ); - - for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr ) - { - for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it ) - it.data()->removeButton( itr.data() ); - - myButton.remove( itr.key() ); - myPosition.remove( itr.key() ); - - delete itr.data(); - } - update(); -} - -/*! - Name: setUnits [static public] - Desc: Sets specified measure units in given label. Measure units close - in braces. If measure units not exist then they will be added. - For example: - 1. Label contains text 'Radius'. - setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm)' - setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm)' - 2. Label "aLabel" contains text 'Radius ():'. - setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm):' - setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm):' -*/ - -void QtxDialog::setUnits( QLabel* aLabel, const QString& aUnits ) -{ - QString label = aLabel->text(); - int begin; - int end = label.findRev( ')' ); - - QString startLabel = label; - QString finalLabel; - - if ( end != -1 ) - { - begin = label.left( end ).findRev( '(' ); - if ( begin != -1 ) - { - startLabel = label.mid( 0, begin ); - finalLabel = label.mid( end + 1 ); - } - } - else - { - startLabel = startLabel.stripWhiteSpace(); - if ( startLabel.at( startLabel.length() - 1 ) == ':' ) - { - finalLabel = startLabel.mid( startLabel.length() - 1 ); - startLabel = startLabel.mid( 0, startLabel.length() - 1 ); - } - } - if ( aUnits.length() ) - label = startLabel.stripWhiteSpace() + - " (" + aUnits + ") " + finalLabel.stripWhiteSpace(); - else - label = startLabel.stripWhiteSpace() + - " " + finalLabel.stripWhiteSpace(); - aLabel->setText( label ); -} - -/*! - Name: acceptData [virtual protected] - Desc: If returns true dialog will be accepted and closed. This method - called if dialog flag Accept is setted. -*/ - -bool QtxDialog::acceptData() const -{ - return true; -} - -/*! - Name: rejectData [virtual protected] - Desc: If returns true dialog will be rejected and closed. This method - called if dialog flag Reject is setted. -*/ - -bool QtxDialog::rejectData() const -{ - return true; -} - -/*! - Name: createButton [virtual protected] - Desc: Create new user button. Invoked from method "insertButton". -*/ - -QButton* QtxDialog::createButton( QWidget* parent ) -{ - QPushButton* pb = new QPushButton( parent ); - pb->setAutoDefault( false ); - return pb; -} - -/*! - Name: button [protected] - Desc: Return pointer on control button specified by identifier. - If identifier is wrong then null pointer will returned. -*/ - -QButton* QtxDialog::button( const int f ) const -{ - QButton* retval = 0; - if ( myButton.contains( f ) ) - retval = myButton[f]; - return retval; -} - -/*! - Name: buttons [protected] - Desc: Return map with control dialog buttons accordance to given button flags. -*/ - -QtxDialog::ButtonMap QtxDialog::buttons( const int f ) const -{ - ButtonMap retmap; - if ( f < -1 ) - { - if ( myButton.contains( f ) ) - retmap.insert( f, myButton[f] ); - } - else - { - for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it ) - if ( f == -1 || ( it.key() >= 0 && f & it.key() ) ) - retmap.insert( it.key(), it.data() ); - } - - return retmap; -} - -/*! - Name: buttonId [protected] - Desc: Return identifier of specified button. -*/ - -int QtxDialog::buttonId( const QButton* b ) const -{ - int id = -1; - for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it ) - if ( it.data() == b ) - id = it.key(); - return id; -} - -/*! - Name: buttonPosition - Desc: Returns position of specified button. [protected] -*/ - -int QtxDialog::buttonPosition( QButton* b ) const -{ - return buttonPosition( buttonId( b ) ); -} - -/*! - Name: showEvent [virtual protected] - Desc: Aligns this dialog according the parent widget and alignment - policy before the show. -*/ - -void QtxDialog::showEvent( QShowEvent* e ) -{ - if ( !testDialogFlags( AlignOnce ) || !myInited ) - Qtx::alignWidget( this, parentWidget(), myAlignment ); - QDialog::showEvent( e ); -} - -/*! - Name: hideEvent [virtual protected] - Desc: Process all existing events when dialog is closed. -*/ - -void QtxDialog::hideEvent( QHideEvent* e ) -{ - qApp->processEvents(); - QDialog::hideEvent( e ); -} - -/*! - Name: childEvent [virtual protected] - Desc: Setting up layout when size grip is added. -*/ - -void QtxDialog::childEvent( QChildEvent* e ) -{ - QDialog::childEvent( e ); - if ( layout() && e->inserted() && e->child()->inherits( "QSizeGrip" ) ) - { - layout()->setMargin( 12 ); -#if QT_VER >= 3 - connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) ); -#endif - } -} - -/*! - Name: keyPressEvent [virtual protected] - Desc: Calls reject() if key Escape is pressed. - Calls accept() if key "Ctrl+Enter" is pressed. - Process key "F1" and emit signal dlgHelp(). - Transfer key "Ctrl+(Shift+)Tab" press event to Tab Widget. -*/ - -void QtxDialog::keyPressEvent( QKeyEvent* e ) -{ - QDialog::keyPressEvent( e ); - if ( e->isAccepted() ) - return; - - if ( ( e->state() == 0 ) && ( e->key() == Key_Escape ) ) - reject(); - - if ( ( e->state() == ControlButton ) && ( e->key() == Key_Return ) ) - { - if ( testButtonFlags( OK ) || testButtonFlags( Yes ) ) - accept(); - else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) ) - emit dlgApply(); - e->accept(); - } - - if ( e->key() == Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) ) - { - e->accept(); - emit dlgHelp(); - } - - if ( ( e->key() == Key_Tab ) && ( e->state() & ControlButton ) ) - { - QObject* tab = child( 0, "QTabWidget" ); - if ( tab ) - tab->event( e ); - } -} - -/*! - Name: closeEvent [virtual protected] - Desc: Reject the dialog. -*/ - -void QtxDialog::closeEvent( QCloseEvent* ) -{ - reject(); -} - -/*! - Name: accept [virtual protected slot] - Desc: Invoke function acceptData() if it needed and if acceptData() return - false does nothing. Otherwise hides the dialog and sets the result code - to Accepted. Emit signal according to the pressed control button. -*/ - -void QtxDialog::accept() -{ - if ( !mySender ) - { - if ( testButtonFlags( OK ) ) - mySender = button( OK ); - else if ( testButtonFlags( Yes ) ) - mySender = button( Yes ); - else - mySender = button( Close ); - } - - if ( !mySender || !mySender->isWidgetType() || - !((QWidget*)mySender)->isEnabled() ) - return; - - if ( testDialogFlags( Accept ) && !acceptData() ) - return; - - QDialog::accept(); - - emitSignal(); -} - -/*! - Name: reject [virtual protected slot] - Desc: Invoke function rejectData() if it needed and if rejectData() return - false does nothing. Otherwise hides the dialog and sets the result code - to Rejected. Emit signal according to the pressed control button. (If - dialog was closed by key Escape or by close event emit signal dlgCancel(), - or dlgClose(), or dlgNo(). -*/ - -void QtxDialog::reject() -{ - if ( testDialogFlags( Reject ) && !rejectData() ) - return; - - if ( !mySender ) - { - if ( testButtonFlags( Cancel ) ) - mySender = button( Cancel ); - else if ( testButtonFlags( No ) ) - mySender = button( No ); - else - mySender = button( Close ); - } - - if ( !mySender || !mySender->isWidgetType() || - !((QWidget*)mySender)->isEnabled() ) - return; - - QDialog::reject(); - - emitSignal(); -} - -/*! - Name: reject [private] - Desc: Emit signal appropriate to control button. -*/ - -void QtxDialog::emitSignal() -{ - qApp->processEvents(); - QApplication::syncX(); - - int id = buttonId( (QButton*)mySender ); - mySender = 0; - - switch ( id ) - { - case OK: - emit dlgOk(); - break; - case Cancel: - emit dlgCancel(); - break; - case Close: - emit dlgClose(); - break; - case Yes: - emit dlgYes(); - break; - case No: - emit dlgNo(); - break; - } -} - -/*! - Name: onAccept [private slot] - Desc: Process signals "clicked()" from control buttons "OK", "Yes". Invoke accept(). -*/ - -void QtxDialog::onAccept() -{ - const QObject* obj = sender(); - mySender = obj; - accept(); -} - -/*! - Name: onReject [private slot] - Desc: Process signals "clicked()" from control buttons "Cancel", "No", "Close". - Invoke reject(). -*/ - -void QtxDialog::onReject() -{ - const QObject* obj = sender(); - mySender = obj; - reject(); -} - -/*! - Name: onButton [private slot] - Desc: Receive signal "clicked()" from user buttons and emit signal - "dlgButton( int )" with identificator of clicked user button. -*/ - -void QtxDialog::onButton() -{ - int id = buttonId( (QButton*)sender() ); - if ( id != -1 ) - emit dlgButton( id ); -} - -/*! - Name: onDestroyed [private slot] - Desc: Remove user button if it was destroyed. -*/ - -void QtxDialog::onDestroyed( QObject* obj ) -{ - QButton* b = (QButton*)obj; - int id = buttonId( b ); - if ( id == -1 ) - return; - - myButton.remove( id ); - myPosition.remove( id ); - for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it ) - it.data()->removeButton( b ); -} - -/*! - Name: onSizeGripDestroyed [private slot] - Desc: Setting up layout when size grip is destroyed. -*/ - -void QtxDialog::onSizeGripDestroyed() -{ - if ( layout() ) - layout()->setMargin( 5 ); -} - -/*! - Name: adjustButtons [private] - Desc: Setting the equal with for all buttons. -*/ - -void QtxDialog::adjustButtons() -{ - int minWidth = 0; - for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt ) - for ( QPtrListIterator bIt( aIt.data()->buttons() ); bIt.current(); ++bIt ) - if ( bIt.current()->isVisibleTo( this ) ) - minWidth = QMAX( minWidth, bIt.current()->sizeHint().width() ); - - for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr ) - for ( QPtrListIterator bItr( aItr.data()->buttons() ); bItr.current(); ++bItr ) - if ( bItr.current()->isVisibleTo( this ) ) - bItr.current()->setMinimumWidth( minWidth ); -} diff --git a/src/Qtx/QtxDialog.h b/src/Qtx/QtxDialog.h deleted file mode 100755 index dbf4fbd9d..000000000 --- a/src/Qtx/QtxDialog.h +++ /dev/null @@ -1,190 +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: QtxDialog.hxx -// Author: Sergey TELKOV - -#ifndef QTXDIALOG_H -#define QTXDIALOG_H - -#include "Qtx.h" - -#include -#include -#include - -class QFrame; -class QLabel; -class QButton; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxDialog : public QDialog -{ - Q_OBJECT - - class Area; - class Border; - -public: - typedef enum { Position, Expand, Uniform } PlacePolicy; - typedef enum { TopArea, BottomArea, LeftArea, RightArea } ButtonArea; - typedef enum { Left, Right, Center, Top = Left, Bottom = Right } ButtonPosition; - - typedef enum { None = 0x00000000, - OK = 0x00000001, - Apply = 0x00000002, - Cancel = 0x00000004, - Yes = 0x00000008, - No = 0x00000010, - Close = 0x00000020, - Help = 0x00000040, - OKCancel = OK | Cancel, - YesNo = Yes | No, - Standard = OK | Cancel | Help, - All = Standard | YesNo | Apply | Close } ButtonFlags; - - typedef enum { Accept = 0x000001, - Reject = 0x000002, - AlignOnce = 0x000004, - SetFocus = 0x000008 } DialogFlags; - -public: - QtxDialog( QWidget* = 0, const char* = 0, bool = false, - bool = false, const int = Standard, WFlags = 0 ); - virtual ~QtxDialog(); - - void setDialogFlags( const int ); - void clearDialogFlags( const int ); - bool testDialogFlags( const int ) const; - - void setButtonFlags( const int ); - void clearButtonFlags( const int ); - bool testButtonFlags( const int ) const; - - int buttonPosition( const int ) const; - void setButtonPosition( const int, const int = -1 ); - void setPlacePosition( const int, const int ); - - int placePolicy( const int ) const; - void setPlacePolicy( const int, const int ); - void setButtonPlace( const int, const int ); - - QString buttonText( const int ); - void setButtonText( const int, const QString& text ); - - void setButtonFocus( const int ); - bool hasButtonFocus( const int ) const; - - bool isButtonEnabled( const int ) const; - void setButtonEnabled( const bool, const int ); - - bool isBorderEnabled( const int ) const; - void setBorderEnabled( const bool, const int ); - - void removeButton( const int ); - int insertButton( const QString&, const int = BottomArea ); - - QValueList userButtonIds() const; - QButton* userButton( const int ) const; - - virtual void show(); - virtual void hide(); - - uint setAlignment( uint align ); - static void setUnits( QLabel*, const QString& ); - -signals: - void dlgButton( int ); - void dlgParamChanged(); - - void dlgHelp(); - void dlgApply(); - - void dlgOk(); - void dlgNo(); - void dlgYes(); - void dlgClose(); - void dlgCancel(); - -public slots: - void update(); - -protected slots: - virtual void accept(); - virtual void reject(); - -private slots: - void onAccept(); - void onReject(); - void onButton(); - void onSizeGripDestroyed(); - void onDestroyed( QObject* ); - -protected: - typedef QMap ButtonMap; - -protected: - QFrame* mainFrame() const; - - virtual bool acceptData() const; - virtual bool rejectData() const; - - virtual QButton* createButton( QWidget* ); - - QButton* button( const int ) const; - ButtonMap buttons( const int = All ) const; - int buttonId( const QButton* ) const; - int buttonPosition( QButton* ) const; - - virtual void showEvent( QShowEvent* ); - virtual void hideEvent( QHideEvent* ); - virtual void closeEvent( QCloseEvent* ); - virtual void childEvent( QChildEvent* ); - virtual void keyPressEvent( QKeyEvent* ); - -private: - void adjustButtons(); - void emitSignal(); - -private: - typedef QMap AreaMap; - typedef QMap PositionMap; - - friend class Area; - -private: - AreaMap myArea; - ButtonMap myButton; - PositionMap myPosition; - - bool myInited; - const QObject* mySender; - uint myAlignment; - QFrame* myMainFrame; - int myButtonFlags; - int myDialogFlags; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxDirListEditor.cxx b/src/Qtx/QtxDirListEditor.cxx deleted file mode 100644 index cd4bb9fcf..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 WNT - 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 38d62dead..000000000 --- a/src/Qtx/QtxDirListEditor.h +++ /dev/null @@ -1,149 +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/QtxDockAction.cxx b/src/Qtx/QtxDockAction.cxx deleted file mode 100755 index 1b25e280a..000000000 --- a/src/Qtx/QtxDockAction.cxx +++ /dev/null @@ -1,1304 +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: QtxDockAction.cxx -// Author: Sergey TELKOV - -#include "QtxDockAction.h" - -#include "QtxResourceMgr.h" - -#include -#include -#include -#include -#include -#include -#include - -/*! - Name: QtxDockAction [public] - Desc: Constructs an Dock action with given main window and name. -*/ - -QtxDockAction::QtxDockAction( QMainWindow* mw, const char* name ) -: QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw, name ), -myMain( mw ), -myAutoAdd( true ), -mySeparate( true ), -myAutoPlace( false ) -{ - initialize( mw ); -} - -/*! - Name: QtxDockAction [public] - Desc: This constructor creates an action with the following properties: the - description text, the menu text and. It is a child of given main window - and named specified name. -*/ - -QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw, const char* name ) -: QtxAction( text, menuText, 0, mw, name ), -myMain( mw ), -myAutoAdd( true ), -mySeparate( true ), -myAutoPlace( false ) -{ - initialize( mw ); -} - -/*! - Name: QtxDockAction [public] - Desc: This constructor creates an action with the following properties: the - description text, the menu text, the icon or iconset icon and keyboard - accelerator. It is a child of given main window and named specified name. -*/ - -QtxDockAction::QtxDockAction( const QString& text, const QIconSet& icon, const QString& menuText, QMainWindow* mw, const char* name ) -: QtxAction( text, icon, menuText, 0, mw, name ), -myMain( mw ), -myAutoAdd( true ), -mySeparate( true ), -myAutoPlace( false ) -{ - initialize( mw ); -} - -/*! - Name: ~QtxDockAction [public] - Desc: Removes all added popup items. -*/ - -QtxDockAction::~QtxDockAction() -{ - for ( MenuMap::ConstIterator mIt = myMenu.begin(); mIt != myMenu.end(); ++mIt ) - removeFrom( mIt.key() ); - - for ( InfoMap::ConstIterator iIt = myInfo.begin(); iIt != myInfo.end(); ++iIt ) - delete iIt.data().a; -} - -/*! - Name: mainWindow [public] - Desc: Returns the main window which contains managed dock windows. -*/ - -QMainWindow* QtxDockAction::mainWindow() const -{ - return myMain; -} - -/*! - Name: isAutoAdd [public] - Desc: Returns the auto add property. If this property is setted then all newly - appeared dock windows will be automatically added. -*/ - -bool QtxDockAction::isAutoAdd() const -{ - return myAutoAdd; -} - -/*! - Name: setAutoAdd [public] - Desc: Sets the auto add property. If this property is setted then all newly - appeared dock windows will be automatically added. -*/ - -void QtxDockAction::setAutoAdd( const bool on ) -{ - myAutoAdd = on; -} - -/*! - Name: isAutoPlace [public] - Desc: Returns the auto place property. If this property is setted then all newly - added dock windows will be automatically placed according stored place information. -*/ - -bool QtxDockAction::isAutoPlace() const -{ - return myAutoPlace; -} - -/*! - Name: setAutoPlace [public] - Desc: Sets the auto place property. If this property is setted then all newly - added dock windows will be automatically placed according stored place - information. -*/ - -void QtxDockAction::setAutoPlace( const bool on ) -{ - myAutoPlace = on; -} - -/*! - Name: isSeparate [public] - Desc: Returns the 'separate' property. -*/ - -bool QtxDockAction::isSeparate() const -{ - return mySeparate; -} - -/*! - Name: setSeparate [public] - Desc: Sets the 'separate' property. If this property is 'true' then toolbars and - dock windows menu items will be placed in different popup menus otherwise - their will be placed in one common popup menu. This property will be - affected in next method 'addTo'. -*/ - -void QtxDockAction::setSeparate( const bool on ) -{ - if ( mySeparate == on ) - return; - - mySeparate = on; - updateMenus(); -} - -/*! - Name: addTo [public] - Desc: Add the dock windows sub menu item to the end of specified popup. -*/ - -bool QtxDockAction::addTo( QWidget* wid ) -{ - return addTo( wid, -1 ); -} - -/*! - Name: addTo [public] - Desc: Add the dock windows sub menu item to specified popup at the given index. -*/ - -bool QtxDockAction::addTo( QWidget* wid, const int idx ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - checkPopup( pm ); - - if ( myMenu.contains( pm ) ) - return false; - - MenuInfo mInfo; - mInfo.dock = new QPopupMenu( pm ); - mInfo.tool = isSeparate() ? new QPopupMenu( pm ) : 0; - - QString dock, tool; - splitMenuText( dock, tool ); - - myMenu.insert( pm, mInfo ); - - int index = idx; - - if ( mInfo.dock ) - iconSet().isNull() ? pm->insertItem ( dock, mInfo.dock, -1, index ) : - pm->insertItem ( iconSet(), dock, mInfo.dock, -1, index ); - - if ( index >= 0 ) - index++; - - if ( mInfo.tool ) - iconSet().isNull() ? pm->insertItem ( tool, mInfo.tool, -1, index ) : - pm->insertItem ( iconSet(), tool, mInfo.tool, -1, index ); - - connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - return true; -} - -/*! - Name: removeFrom [public] - Desc: Removes dock window sub menu from specified popup. -*/ - -bool QtxDockAction::removeFrom( QWidget* wid ) -{ - QPopupMenu* pm = (QPopupMenu*)wid; - - if ( myMenu.contains( pm ) ) - { - pm->removeItem( findId( pm, myMenu[pm].dock ) ); - pm->removeItem( findId( pm, myMenu[pm].tool ) ); - - delete myMenu[pm].dock; - delete myMenu[pm].tool; - myMenu.remove( pm ); - - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - } - - return QtxAction::removeFrom( wid ); -} - -/*! - Sets menu text of action - \param txt - new menu text -*/ -void QtxDockAction::setMenuText( const QString& txt ) -{ - if ( menuText() == txt ) - return; - - QtxAction::setMenuText( txt ); - updateMenus(); -} - -/*! - Name: addDockWindow [public] - Desc: Add dock window to internal data structures. Action will be include all added - dock windows in to menu and manage their place configuration. -*/ - -bool QtxDockAction::addDockWindow( QDockWindow* dw ) -{ - if ( !dw || !mainWindow() ) - return false; - - if ( myInfo.contains( dw ) ) - return false; - - myInfo.insert( dw, DockInfo() ); - - DockInfo& inf = myInfo[dw]; - inf.name = windowName( dw ); - QAction* a = inf.a = new QAction( mainWindow(), 0, true ); - - autoLoadPlaceInfo( dw ); - - bool block = a->signalsBlocked(); - a->blockSignals( true ); - a->setOn( dw->isVisibleTo( mainWindow() ) ); - a->blockSignals( block ); - - updateInfo( dw ); - savePlaceInfo( dw ); - - dw->installEventFilter( this ); - - connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); - connect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) ); - connect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) ); - - return true; -} - -/*! - Name: removeDockWindow [public] - Desc: Remove dock window from internal data structures. Action will not manage this window. -*/ - -bool QtxDockAction::removeDockWindow( QDockWindow* dw ) -{ - if ( !myInfo.contains( dw ) ) - return false; - - myGeom.remove( myInfo[dw].name ); - - delete myInfo[dw].a; - myInfo.remove( dw ); - - dw->removeEventFilter( this ); - - disconnect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) ); - disconnect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) ); - - return true; -} - -/*! - Name: eventFilter [public] - Desc: Event filter process caption and icon changing of managed dock windows - and try to add newly appeared dock windows. -*/ - -bool QtxDockAction::eventFilter( QObject* o, QEvent* e ) -{ - if ( o->inherits( "QDockWindow" ) && ( e->type() == QEvent::CaptionChange || - e->type() == QEvent::IconChange ) ) - updateInfo( (QDockWindow*)o ); - - if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildRemoved ) - { - QChildEvent* ce = (QChildEvent*)e; - if ( ce->child() && ce->child()->inherits( "QDockWindow" ) ) - savePlaceInfo( (QDockWindow*)ce->child() ); - } - - if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildInserted ) - { - QChildEvent* ce = (QChildEvent*)e; - if ( ce->child() && ce->child()->inherits( "QDockWindow" ) ) - QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, ce->child() ) ); - } - - return false; -} - -/*! - Name: restoreGeometry [public] - Desc: Retrieve the dock window geometry. If dock window specified as 0 - then all windows geometry will be restored. -*/ - -void QtxDockAction::restoreGeometry( QDockWindow* dw ) const -{ - if ( !dw ) - loadPlaceInfo(); - else - loadPlaceInfo( dw ); -} - -/*! - Name: storeGeometry [public] - Desc: Store the dock window geometry. If dock window specified as 0 - then all windows geometry will be stored. -*/ - -void QtxDockAction::storeGeometry( QDockWindow* dw ) -{ - QPtrList dwList; - - if ( dw ) - dwList.append( dw ); - else - dockWindows( dwList ); - - for ( QPtrListIterator it( dwList ); it.current(); ++it ) - savePlaceInfo( it.current() ); -} - -/*! - Name: loadGeometry [public] - Desc: Retrieve the dock windows geometry information from the specified resource manager section. -*/ - -void QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear ) -{ - QString sec = section.stripWhiteSpace(); - if ( !resMgr || sec.isEmpty() ) - return; - - myNames = QStringList::split( "|", resMgr->stringValue( sec, "windows_list", QString::null ) ); - - QMap map; - QStringList params = resMgr->parameters( sec ); - for ( QStringList::const_iterator it = params.begin(); it != params.end(); ++it ) - { - QString p = QStringList::split( ".", *it, true ).first().stripWhiteSpace(); - if ( !p.isEmpty() ) - map.insert( p, 0 ); - } - - for ( QMap::ConstIterator itr = map.begin(); itr != map.end(); ++itr ) - { - GeomInfo inf; - if ( !clear && myGeom.contains( itr.key() ) ) - inf = myGeom[itr.key()]; - else - { - inf.vis = true; inf.newLine = false; inf.place = DockTop; - inf.index = 0; inf.offset = 0; - inf.x = 0; inf.y = 0; inf.w = 0; inf.h = 0; - inf.fixW = -1; inf.fixH = -1; - } - if ( loadGeometry( resMgr, sec, itr.key(), inf ) ) - myGeom.insert( itr.key(), inf ); - } -} - -/*! - Name: saveGeometry [public] - Desc: Store the dock windows geometry information into the specified resource manager section. -*/ - -void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const -{ - QString sec = section.stripWhiteSpace(); - if ( !resMgr || sec.isEmpty() ) - return; - - QtxDockAction* that = (QtxDockAction*)this; - that->storeGeometry(); - - that->myNames.clear(); - collectNames( Minimized, that->myNames ); - for ( int i = DockTornOff; i < Minimized; i++ ) - collectNames( i, that->myNames ); - - if ( clear ) - resMgr->remove( sec ); - - resMgr->setValue( sec, "windows_list", myNames.join( "|" ) ); - - for ( GeomMap::ConstIterator it = myGeom.begin(); it != myGeom.end(); ++it ) - saveGeometry( resMgr, sec, it.key(), it.data() ); -} - -/*! - Name: onAboutToShow [private slots] - Desc: Prepare sub popup with dock windows list when parent popup is shown. -*/ - -void QtxDockAction::onAboutToShow() -{ - const QObject* obj = sender(); - if ( obj && obj->inherits( "QPopupMenu" ) ) - { - QPopupMenu* pm = (QPopupMenu*)obj; - fillPopup( pm ); - pm->setItemEnabled( findId( pm, myMenu[pm].dock ), isEnabled() && myMenu[pm].dock && myMenu[pm].dock->count() ); - pm->setItemEnabled( findId( pm, myMenu[pm].tool ), isEnabled() && myMenu[pm].tool && myMenu[pm].tool->count() ); - } -} - -/*! - Name: onToggled [private slots] - Desc: Show or hide dock window when user toggled window item in popup. -*/ - -void QtxDockAction::onToggled( bool on ) -{ - QDockWindow* dw = dockWindow( (QAction*)sender() ); - if ( dw ) - on ? dw->show() : dw->hide(); -} - -/*! - Name: onPopupDestroyed [private slots] - Desc: Remove destroyed popup from data structures. -*/ - -void QtxDockAction::onPopupDestroyed( QObject* obj ) -{ - myMenu.remove( (QPopupMenu*)obj ); -} - -/*! - Name: onWindowDestroyed [private slots] - Desc: Remove information about destroyed dock window. -*/ - -void QtxDockAction::onWindowDestroyed( QObject* obj ) -{ - QDockWindow* dw = (QDockWindow*)obj; - if ( !myInfo.contains( dw ) ) - return; - - delete myInfo[dw].a; - myInfo.remove( dw ); -} - -/*! - Name: onVisibilityChanged [private slots] - Desc: Toggle corresponded action when visibility state of dock window changed. -*/ - -void QtxDockAction::onVisibilityChanged( bool on ) -{ - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QDockWindow" ) ) - return; - - QDockWindow* dw = (QDockWindow*)obj; - - QAction* a = action( dw ); - if ( a && a->isOn() != on ) - { - bool block = a->signalsBlocked(); - a->blockSignals( true ); - a->setOn( on ); - a->blockSignals( block ); - } - - savePlaceInfo( dw ); -} - -/*! - Name: onDockWindowPositionChanged [private slots] - Desc: Update dock window place information -*/ - -void QtxDockAction::onDockWindowPositionChanged( QDockWindow* dw ) -{ - savePlaceInfo( dw ); -} - -/*! - Name: event [protected] - Desc: Check consistency the popup content and internal datas. - Synchronize internal data structures with popup content. -*/ - -bool QtxDockAction::event( QEvent* e ) -{ - if ( e->type() == (int)AutoAdd ) - { - QCustomEvent* ce = (QCustomEvent*)e; - QDockWindow* dw = (QDockWindow*)ce->data(); - if ( !myInfo.contains( dw ) ) - { - autoAddDockWindow( dw ); - autoLoadPlaceInfo( dw ); - } - } - - return QtxAction::event( e ); -} - -/*! - Name: checkPopup [private] - Desc: Check consistency the popup content and internal datas. - Synchronize internal data structures with popup content. -*/ - -void QtxDockAction::checkPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return; - - int id = findId( pm, myMenu[pm].dock ); - if ( id == -1 ) - { - delete myMenu[pm].dock; - myMenu[pm].dock = 0; - } - id = findId( pm, myMenu[pm].tool ); - if ( id == -1 ) - { - delete myMenu[pm].tool; - myMenu[pm].tool = 0; - } - - if ( !myMenu[pm].dock ) - { - delete myMenu[pm].tool; - myMenu.remove( pm ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); - } -} - -/*! - Name: fillPopup [private] - Desc: Clear the popup and the add to it required actions. -*/ - -void QtxDockAction::fillPopup( QPopupMenu* pm ) const -{ - if ( !pm || !mainWindow() ) - return; - - if ( !myMenu.contains( pm ) ) - return; - - QPopupMenu* dockMenu = myMenu[pm].dock; - QPopupMenu* toolMenu = myMenu[pm].tool; - - for ( InfoMap::ConstIterator mit = myInfo.begin(); mit != myInfo.end(); ++mit ) - { - mit.data().a->removeFrom( dockMenu ); - mit.data().a->removeFrom( toolMenu ); - } - - if ( dockMenu ) - dockMenu->clear(); - - if ( toolMenu ) - toolMenu->clear(); - - QPtrList dockList; - dockWindows( dockList, mainWindow() ); - - if ( dockList.isEmpty() ) - return; - - QPtrList toolBars, windows; - for ( QPtrListIterator it( dockList ); it.current(); ++it ) - { - if ( !myInfo.contains( it.current() ) ) - { - QtxDockAction* that = (QtxDockAction*)this; - that->autoAddDockWindow( it.current() ); - } - - if ( !mainWindow()->appropriate( it.current() ) || - it.current()->caption().isEmpty() || !action( it.current() ) ) - continue; - - if ( isToolBar( it.current() ) ) - toolBars.append( action( it.current() ) ); - else - windows.append( action( it.current() ) ); - } - - for ( QPtrListIterator wit( windows ); wit.current(); ++wit ) - wit.current()->addTo( dockMenu ); - - dockMenu->insertSeparator(); - - for ( QPtrListIterator tit( toolBars ); tit.current(); ++tit ) - tit.current()->addTo( toolMenu ? toolMenu : dockMenu ); - - Qtx::simplifySeparators( dockMenu ); - Qtx::simplifySeparators( toolMenu ); -} - -/*! - Name: isToolBar [private] - Desc: Returns 'true' if dock window is a toolbar. -*/ - -bool QtxDockAction::isToolBar( QDockWindow* dw ) const -{ - return dw && dw->inherits( "QToolBar" ); -} - -/*! - Name: findId [private] - Desc: Returns identificator of popup item which contains sub popup 'pm' in the popup 'cont'. -*/ - -int QtxDockAction::findId( QPopupMenu* cont, QPopupMenu* pm ) const -{ - if ( !cont || !pm ) - return -1; - - int id = -1; - - for ( int i = 0; i < (int)cont->count() && id == -1; i++ ) - { - QMenuData* md = 0; - QMenuItem* item = cont->findItem( cont->idAt( i ), &md ); - if ( item && md == cont && item->popup() == pm ) - id = item->id(); - } - return id; -} - -/*! - Name: dockWindows [private] - Desc: Returns all dock windows of the main window. -*/ - -void QtxDockAction::dockWindows( QPtrList& lst, QMainWindow* main ) const -{ - lst.clear(); - - QMainWindow* mw = main ? main : mainWindow(); - if ( !mw ) - return; - - QObjectList* objs = mw->queryList( "QDockWindow" ); - if ( objs ) - { - for ( QObjectListIt it( *objs ); it.current(); ++it ) - { - QDockWindow* dockWin = ::qt_cast( it.current() ); - if ( dockWin && dockMainWindow( mw, dockWin ) ) - lst.append( dockWin ); - } - } - delete objs; -} - -/*! - \return true if main window is parent of object - \param mw - main window - \param win - object -*/ -bool QtxDockAction::dockMainWindow( QMainWindow* mw, QObject* win ) const -{ - if ( !mw || !win ) - return false; - - while ( win ) - { - if ( win->parent() && win->parent() == mw ) - return true; - - if ( ::qt_cast( win->parent() ) ) - return false; - - win = win->parent(); - } - - return false; -} - -/*! - Name: updateInfo [private] - Desc: Updates icon and caption info of dock window in the corresponded action. -*/ - -void QtxDockAction::updateInfo( QDockWindow* dw ) -{ - QAction* a = action( dw ); - if ( !a ) - return; - - a->setText( dw->caption() ); - a->setMenuText( dw->caption() ); - - if ( isToolBar( dw ) ) - a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) ); - else - a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) ); - - const QPixmap* icon = dw->icon(); - if ( icon ) - a->setIconSet( *icon ); -} - -/*! - Name: savePlaceInfo [private] - Desc: Store the place and geometry information from specified dock window. -*/ - -void QtxDockAction::savePlaceInfo( QDockWindow* dw ) -{ - if ( !myInfo.contains( dw ) ) - return; - - if ( !myGeom.contains( myInfo[dw].name ) ) - myGeom.insert( myInfo[dw].name, GeomInfo() ); - - GeomInfo& inf = myGeom[myInfo[dw].name]; - - Dock dock; - inf.vis = dw->isVisibleTo( mainWindow() ); - mainWindow()->getLocation( dw, dock, inf.index, inf.newLine, inf.offset ); - - inf.place = dock; - inf.x = dw->x(); - inf.y = dw->y(); - inf.w = dw->width(); - inf.h = dw->height(); - inf.fixW = dw->fixedExtent().width(); - inf.fixH = dw->fixedExtent().height(); -} - -/*! - Name: loadPlaceInfo [private] - Desc: Retrieve the stored place and geometry information to specified dock window. -*/ - -void QtxDockAction::loadPlaceInfo( QDockWindow* dw ) const -{ - if ( !myInfo.contains( dw ) ) - return; - - QMainWindow* mw = mainWindow(); - if ( !mw ) - return; - - QObject* p = dw->parent(); - if ( !( !p || p == mw || ( p->parent() && p->parent() == mw ) ) ) - return; - - QString winName = myInfo[dw].name; - if ( winName.isEmpty() || !myGeom.contains( winName ) ) - return; - - GeomInfo inf = myGeom[myInfo[dw].name]; - - mainWindow()->moveDockWindow( dw, (Qt::Dock)inf.place, inf.newLine, inf.index, inf.offset ); - dw->setGeometry( inf.x, inf.y, inf.w, inf.h ); - - dw->setFixedExtentWidth( inf.fixW ); - dw->setFixedExtentHeight( inf.fixH ); - - QtxDockAction* that = (QtxDockAction*)this; - that->myGeom.insert( myInfo[dw].name, inf ); -} - -/*! - Name: loadPlaceInfo [private] - Desc: Retrieve the stored place and geometry information to all dock windows. -*/ - -void QtxDockAction::loadPlaceInfo() const -{ - QMainWindow* mw = mainWindow(); - if ( !mw ) - return; - - typedef QPtrList DockWinList; - - DockWinList lst; - dockWindows( lst, mw ); - - QMap nameMap; - for ( QPtrListIterator itr( lst ); itr.current(); ++itr ) - { - QObject* p = itr.current()->parent(); - if ( !( !p || p == mw || ( p->parent() && p->parent() == mw ) ) ) - continue; - - QString name; - if ( myInfo.contains( itr.current() ) ) - name = myInfo[itr.current()].name; - - if ( !myGeom.contains( name ) ) - continue; - - nameMap.insert( name, itr.current() ); - } - - DockWinList winList; - for ( QStringList::const_iterator iter = myNames.begin(); iter != myNames.end(); ++iter ) - { - if ( nameMap.contains( *iter ) ) - winList.append( nameMap[*iter] ); - nameMap.remove( *iter ); - } - - for ( QMap::ConstIterator mIt = nameMap.begin(); mIt != nameMap.end(); ++mIt ) - winList.append( mIt.data() ); - - QMap winMap; - QMap geomMap; - - for ( QPtrListIterator it( winList ); it.current(); ++it ) - { - QString name; - if ( myInfo.contains( it.current() ) ) - name = myInfo[it.current()].name; - - if ( !myGeom.contains( name ) ) - continue; - - //! collect pointer of info to have fresh info data after processEvents(); - GeomInfo* inf = (GeomInfo*)&( myGeom[name] ); - geomMap.insert( it.current(), inf ); - if ( !winMap.contains( inf->place ) ) - winMap.insert( inf->place, DockWinList() ); - winMap[inf->place].append( it.current() ); - } - - loadPlaceArea( DockMinimized, mw, 0, - winMap.contains( DockMinimized ) ? winMap[DockMinimized] : DockWinList(), geomMap ); - for ( int i = DockTornOff; i < DockMinimized; i++ ) - { - loadPlaceArea( i, mw, dockArea( i ), winMap.contains( i ) ? winMap[i] : DockWinList(), geomMap ); - } -} - -/*! - Name: loadPlaceArea [private] - Desc: Set the place and geometry information to all dock windows in the area. -*/ - -void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area, - const QPtrList& dockList, - const QMap& geomMap ) const -{ - for ( QPtrListIterator it( dockList ); it.current(); ++it ) - { - if ( !geomMap.contains( it.current() ) ) - continue; - - GeomInfo* inf = geomMap[it.current()]; - mw->moveDockWindow( it.current(), (Qt::Dock)place, inf->newLine, inf->index, inf->offset ); - } - - if ( !area ) - return; - - qApp->processEvents(); - - for ( QPtrListIterator itr( dockList ); itr.current(); ++itr ) - { - QDockWindow* dw = itr.current(); - if ( !geomMap.contains( dw ) ) - continue; - - GeomInfo* inf = geomMap[dw]; - if ( place != DockTornOff ) - { - dw->setNewLine( inf->newLine ); - dw->setOffset( inf->offset ); - dw->setFixedExtentWidth( inf->fixW ); - dw->setFixedExtentHeight( inf->fixH ); - } - dw->setGeometry( inf->x, inf->y, inf->w, inf->h ); - - QAction* a = action( dw ); - if ( a ) - { - bool block = a->signalsBlocked(); - a->blockSignals( true ); - a->setOn( inf->vis ); - a->blockSignals( block ); - } - - if ( mainWindow() && mainWindow()->appropriate( dw ) ) - inf->vis ? dw->show() : dw->hide(); - } - - QWidget* wid = area; - if ( wid->layout() ) - { - wid->layout()->invalidate(); - wid->layout()->activate(); - } -} - -/*! - Name: action [private] - Desc: Returns action for the given dock window. -*/ - -QAction* QtxDockAction::action( QDockWindow* dw ) const -{ - QAction* a = 0; - if ( myInfo.contains( dw ) ) - a = myInfo[dw].a; - return a; -} - -/*! - Name: dockWindow [private] - Desc: Returns dock window for the given action. -*/ - -QDockWindow* QtxDockAction::dockWindow( const QAction* a ) const -{ - QDockWindow* dw = 0; - for ( InfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !dw; ++it ) - { - if ( it.data().a == a ) - dw = it.key(); - } - return dw; -} - -/*! - Name: initialize [private] - Desc: Initialisation of the object. Sets the event filters and add existing dock windows. -*/ - -void QtxDockAction::initialize( QMainWindow* mw ) -{ - if ( !mw ) - return; - - QPtrList lst; - dockWindows( lst, mw ); - - for ( QPtrListIterator it( lst ); it.current(); ++it ) - QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, it.current() ) ); - - if ( mw->topDock() ) - mw->topDock()->installEventFilter( this ); - if ( mw->leftDock() ) - mw->leftDock()->installEventFilter( this ); - if ( mw->rightDock() ) - mw->rightDock()->installEventFilter( this ); - if ( mw->bottomDock() ) - mw->bottomDock()->installEventFilter( this ); - - connect( mw, SIGNAL( dockWindowPositionChanged( QDockWindow* ) ), - this, SLOT( onDockWindowPositionChanged( QDockWindow* ) ) ); -} - -/*! - Name: windowName [private] - Desc: Generate the dock window name. -*/ - -QString QtxDockAction::windowName( QDockWindow* dw ) const -{ - QString name; - - if ( dw ) - { - name = dw->name( "" ); - if ( name.isEmpty() ) - name = dw->caption(); - } - - return name; -} - -/*! - Name: autoAddDockWindow [private] - Desc: Add the dock window if auto add property is setted. -*/ - -bool QtxDockAction::autoAddDockWindow( QDockWindow* dw ) -{ - if ( !isAutoAdd() ) - return false; - - return addDockWindow( dw ); -} - -/*! - Name: autoLoadPlaceInfo [private] - Desc: Retieve the dock window place geometry if auto place property is setted. -*/ - -void QtxDockAction::autoLoadPlaceInfo( QDockWindow* dw ) -{ - if ( isAutoPlace() ) - loadPlaceInfo( dw ); -} - -/*! - Name: splitMenuText [private] - Desc: -*/ - -void QtxDockAction::splitMenuText( QString& dock, QString& tool ) const -{ - dock = tool = menuText(); - if ( !isSeparate() ) - return; - - QStringList lst = splitText( menuText(), "|" ); - if ( lst.count() < 2 ) - lst = splitText( menuText(), "and" ); - - dock = lst.first(); - tool = lst.last(); -} - -/*! - Name: splitText [private] - Desc: -*/ - -QStringList QtxDockAction::splitText( const QString& str, const QString& sep ) const -{ - QStringList res; - - int idx = str.lower().find( sep.lower() ); - if ( idx != -1 ) - { - res.append( str.mid( 0, idx ).stripWhiteSpace() ); - res.append( str.mid( idx + sep.length() ).stripWhiteSpace() ); - } - - return res; -} - -/*! - Name: dockPlace [private] - Desc: -*/ - -int QtxDockAction::dockPlace( const QString& dockName ) const -{ - static QMap dockNameMap; - if ( dockNameMap.isEmpty() ) - { - dockNameMap["top"] = DockTop; - dockNameMap["bottom"] = DockBottom; - dockNameMap["left"] = DockLeft; - dockNameMap["right"] = DockRight; - dockNameMap["tornoff"] = DockTornOff; - dockNameMap["torn_off"] = DockTornOff; - dockNameMap["outside"] = DockTornOff; - dockNameMap["undock"] = DockTornOff; - dockNameMap["minimized"] = DockMinimized; - dockNameMap["unmanaged"] = DockUnmanaged; - } - - int res = -1; - if ( dockNameMap.contains( dockName.lower() ) ) - res = dockNameMap[dockName.lower()]; - return res; -} - -/*! - Name: dockArea [private] - Desc: -*/ - -QDockArea* QtxDockAction::dockArea( const int place ) const -{ - if ( !mainWindow() ) - return 0; - - QDockArea* area = 0; - switch ( place ) - { - case DockTop: - area = mainWindow()->topDock(); - break; - case DockBottom: - area = mainWindow()->bottomDock(); - break; - case DockLeft: - area = mainWindow()->leftDock(); - break; - case DockRight: - area = mainWindow()->rightDock(); - break; - } - return area; -} - -/*! - Name: loadGeometry [private] - Desc: -*/ - -bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec, - const QString& name, GeomInfo& inf ) const -{ - if ( !resMgr || sec.isEmpty() || name.isEmpty() ) - return false; - - QString tmpl = QString( "%1.%2" ).arg( name ); - - inf.vis = resMgr->booleanValue( sec, tmpl.arg( "visible" ), inf.vis ); - inf.newLine = resMgr->booleanValue( sec, tmpl.arg( "new_line" ), inf.newLine ); - - inf.index = resMgr->integerValue( sec, tmpl.arg( "index" ), inf.index ); - inf.offset = resMgr->integerValue( sec, tmpl.arg( "offset" ), inf.offset ); - - inf.x = resMgr->integerValue( sec, tmpl.arg( "x" ), inf.x ); - inf.y = resMgr->integerValue( sec, tmpl.arg( "y" ), inf.y ); - inf.w = resMgr->integerValue( sec, tmpl.arg( "width" ), inf.w ); - inf.h = resMgr->integerValue( sec, tmpl.arg( "height" ), inf.h ); - - inf.fixW = resMgr->integerValue( sec, tmpl.arg( "fixed_width" ), inf.fixW ); - inf.fixH = resMgr->integerValue( sec, tmpl.arg( "fixed_height" ), inf.fixH ); - - int place = -1; - if ( !resMgr->value( sec, tmpl.arg( "place" ), place ) ) - { - QString placeStr; - if ( resMgr->value( sec, tmpl.arg( "place" ), placeStr ) ) - place = dockPlace( placeStr ); - } - - if ( place >= DockUnmanaged && place <= DockMinimized ) - inf.place = place; - - return true; -} - -/*! - Name: saveGeometry [private] - Desc: -*/ - -bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec, - const QString& name, const GeomInfo& inf ) const -{ - if ( !resMgr || sec.isEmpty() || name.isEmpty() ) - return false; - - QString tmpl = QString( "%1.%2" ).arg( name ); - - resMgr->setValue( sec, tmpl.arg( "visible" ), inf.vis ); - resMgr->setValue( sec, tmpl.arg( "new_line" ), inf.newLine ); - resMgr->setValue( sec, tmpl.arg( "index" ), inf.index ); - resMgr->setValue( sec, tmpl.arg( "offset" ), inf.offset ); - resMgr->setValue( sec, tmpl.arg( "x" ), inf.x ); - resMgr->setValue( sec, tmpl.arg( "y" ), inf.y ); - resMgr->setValue( sec, tmpl.arg( "width" ), inf.w ); - resMgr->setValue( sec, tmpl.arg( "height" ), inf.h ); - resMgr->setValue( sec, tmpl.arg( "fixed_width" ), inf.fixW ); - resMgr->setValue( sec, tmpl.arg( "fixed_height" ), inf.fixH ); - resMgr->setValue( sec, tmpl.arg( "place" ), inf.place ); - - return true; -} - -/*! - Name: collectNames [private] - Desc: -*/ - -void QtxDockAction::collectNames( const int place, QStringList& lst ) const -{ - QPtrList winList; - QDockArea* area = dockArea( place ); - if ( area ) - winList = area->dockWindowList(); - else - winList = mainWindow()->dockWindows( (Qt::Dock)place ); - - for ( QPtrListIterator it( winList ); it.current(); ++it ) - { - QString name; - if ( myInfo.contains( it.current() ) ) - name = myInfo[it.current()].name; - if ( name.isEmpty() ) - name = windowName( it.current() ); - if ( name.isEmpty() ) - continue; - - lst.append( name ); - } -} - -/*! - Updates menu of action -*/ -void QtxDockAction::updateMenus() -{ - for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it ) - { - QPopupMenu* pm = it.key(); - MenuInfo& inf = it.data(); - - int toolId = findId( pm, inf.tool ); - int dockId = findId( pm, inf.dock ); - - int index = pm->indexOf( dockId ); - - if ( isSeparate() && !inf.tool ) - inf.tool = new QPopupMenu( pm ); - - pm->removeItem( dockId ); - pm->removeItem( toolId ); - - if ( !isSeparate() && inf.tool ) - { - delete inf.tool; - inf.tool = 0; - } - - QString dock, tool; - splitMenuText( dock, tool ); - - if ( inf.dock ) - iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) : - pm->insertItem ( iconSet(), dock, inf.dock, -1, index ); - - if ( index >= 0 ) - index++; - - if ( inf.tool ) - iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) : - pm->insertItem ( iconSet(), tool, inf.tool, -1, index ); - } -} diff --git a/src/Qtx/QtxDockAction.h b/src/Qtx/QtxDockAction.h deleted file mode 100755 index a18d102fb..000000000 --- a/src/Qtx/QtxDockAction.h +++ /dev/null @@ -1,164 +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: QtxDockAction.h -// Author: Sergey TELKOV - -#ifndef QTX_DOCKACTION_H -#define QTX_DOCKACTION_H - -#include "QtxAction.h" - -#include -#include -#include - -class QAction; -class QDockArea; -class QDockWindow; -class QMainWindow; -class QtxResourceMgr; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxDockAction : public QtxAction -{ - Q_OBJECT - - Q_PROPERTY( bool autoAdd READ isAutoAdd WRITE setAutoAdd ) - Q_PROPERTY( bool autoPlace READ isAutoPlace WRITE setAutoPlace ) - Q_PROPERTY( bool separate READ isSeparate WRITE setSeparate ) - -public: - QtxDockAction( QMainWindow*, const char* = 0 ); - QtxDockAction( const QString&, const QString&, QMainWindow*, const char* = 0 ); - QtxDockAction( const QString&, const QIconSet&, const QString&, QMainWindow*, const char* = 0 ); - virtual ~QtxDockAction(); - - QMainWindow* mainWindow() const; - - bool isAutoAdd() const; - void setAutoAdd( const bool ); - - bool isAutoPlace() const; - void setAutoPlace( const bool ); - - bool isSeparate() const; - void setSeparate( const bool ); - - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); - virtual bool removeFrom( QWidget* ); - virtual void setMenuText( const QString& ); - - bool addDockWindow( QDockWindow* ); - bool removeDockWindow( QDockWindow* ); - - virtual bool eventFilter( QObject*, QEvent* ); - - virtual void storeGeometry( QDockWindow* = 0 ); - virtual void restoreGeometry( QDockWindow* = 0 ) const; - - virtual void loadGeometry( QtxResourceMgr*, const QString&, const bool = true ); - virtual void saveGeometry( QtxResourceMgr*, const QString&, const bool = true ) const; - -private slots: - void onAboutToShow(); - void onToggled( bool ); - void onVisibilityChanged( bool ); - void onPopupDestroyed( QObject* ); - void onWindowDestroyed( QObject* ); - void onDockWindowPositionChanged( QDockWindow* ); - -protected: - virtual bool event( QEvent* ); - -private: - QAction* action( QDockWindow* ) const; - QDockWindow* dockWindow( const QAction* ) const; - - void checkPopup( QPopupMenu* ); - void fillPopup( QPopupMenu* ) const; - int findId( QPopupMenu*, QPopupMenu* ) const; - - void initialize( QMainWindow* ); - void updateInfo( QDockWindow* ); - bool isToolBar( QDockWindow* ) const; - void dockWindows( QPtrList&, QMainWindow* = 0 ) const; - - QString windowName( QDockWindow* ) const; - void savePlaceInfo( QDockWindow* ); - void loadPlaceInfo( QDockWindow* ) const; - void loadPlaceInfo() const; - - bool autoAddDockWindow( QDockWindow* ); - void autoLoadPlaceInfo( QDockWindow* ); - - void splitMenuText( QString&, QString& ) const; - QStringList splitText( const QString&, const QString& ) const; - - QDockArea* dockArea( const int ) const; - int dockPlace( const QString& ) const; - - void collectNames( const int, QStringList& ) const; - - void updateMenus(); - - bool dockMainWindow( QMainWindow*, QObject* ) const; - -private: - enum { AutoAdd = QEvent::User, LoadArea }; - - typedef struct { bool vis, newLine; - int place, index, offset; - int x, y, w, h, fixW, fixH; } GeomInfo; - typedef struct { QString name; QAction* a; } DockInfo; - typedef struct { QPopupMenu *dock, *tool; } MenuInfo; - - typedef QMap InfoMap; - typedef QMap GeomMap; - typedef QMap MenuMap; - -private: - bool loadGeometry( QtxResourceMgr*, const QString&, - const QString&, GeomInfo& ) const; - bool saveGeometry( QtxResourceMgr*, const QString&, - const QString&, const GeomInfo& ) const; - void loadPlaceArea( const int, QMainWindow*, QDockArea*, - const QPtrList&, - const QMap& ) const; - -private: - InfoMap myInfo; - MenuMap myMenu; - GeomMap myGeom; - QMainWindow* myMain; - QStringList myNames; - - bool myAutoAdd; - bool mySeparate; - bool myAutoPlace; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxGroupBox.cxx b/src/Qtx/QtxGroupBox.cxx deleted file mode 100644 index 6975f779e..000000000 --- a/src/Qtx/QtxGroupBox.cxx +++ /dev/null @@ -1,407 +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: QtxGroupBox.cxx -// Author: Sergey TELKOV - -#include "QtxGroupBox.h" - -#include -#include -#include -#include -#include - -/*! - Constructor -*/ -QtxGroupBox::QtxGroupBox( QWidget* parent, const char* name ) -: QGroupBox( parent, name ), -myContainer( 0 ) -{ -} - -/*! - Constructor -*/ -QtxGroupBox::QtxGroupBox( const QString& title, QWidget* parent, const char* name ) -: QGroupBox( title, parent, name ), -myContainer( 0 ) -{ - initialize(); -} - -/*! - Constructor -*/ -QtxGroupBox::QtxGroupBox( int strips, Orientation o, QWidget* parent, const char* name ) -: QGroupBox( strips, o, parent, name ), -myContainer( 0 ) -{ - initialize(); -} - -/*! - Constructor -*/ -QtxGroupBox::QtxGroupBox( int strips, Orientation o, const QString& title, - QWidget* parent, const char* name ) -: QGroupBox( strips, o, title, parent, name ), -myContainer( 0 ) -{ - initialize(); -} - -/*! - Destructor -*/ -QtxGroupBox::~QtxGroupBox() -{ - delete myContainer; -} - -/*! - Creates horizontal box as container -*/ -void QtxGroupBox::initialize() -{ - myContainer = new QHBox( this, 0, WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool ); - - updateTitle(); -} - -#if QT_VER < 3 - -/*! - \return the width of the empty space between the items in the group and the frame of the group -*/ -int QtxGroupBox::insideMargin() const -{ - int m = 0; - if ( layout() ) - m = layout()->margin(); - return m; -} - -/*! - \return the width of the empty space between each of the items in the group -*/ -int QtxGroupBox::insideSpacing() const -{ - int s = 0; - if ( layout() ) - s = layout()->spacing(); - return s; -} - -/*! - Sets the width of the empty space between the items in the group and the frame of the group -*/ -void QtxGroupBox::setInsideMargin( int m ) -{ - if ( layout() ) - layout()->setMargin( m ); -} - -/*! - Sets the width of the empty space between each of the items in the group -*/ -void QtxGroupBox::setInsideSpacing( int s ) -{ - if ( layout() ) - layout()->setSpacing( s ); -} - -#endif - -/*! - Inserts title widget - \param wid - new title widget -*/ -void QtxGroupBox::insertTitleWidget( QWidget* wid ) -{ - if ( !myContainer ) - return; - - wid->reparent( myContainer, QPoint( 0, 0 ), true ); - wid->installEventFilter( this ); - - updateTitle(); -} - -/*! - Removes title widget - \param wid - title widget -*/ -void QtxGroupBox::removeTitleWidget( QWidget* wid ) -{ - if ( !myContainer || wid->parentWidget() != myContainer ) - return; - - wid->reparent( 0, QPoint( 0, 0 ), false ); - wid->removeEventFilter( this ); - - updateTitle(); -} - -/*! - Calculates margin -*/ -void QtxGroupBox::adjustInsideMargin() -{ - QApplication::sendPostedEvents( myContainer, QEvent::ChildInserted ); - - myContainer->resize( myContainer->minimumSizeHint() ); - - setInsideMargin( myContainer->height() ); -} - -/*! - Sets the alignment of the group box title -*/ -void QtxGroupBox::setAlignment( int align ) -{ - QGroupBox::setAlignment( align ); - - updateTitle(); -} - -/*! - Sets title of groop box -*/ -void QtxGroupBox::setTitle( const QString& title ) -{ - QGroupBox::setTitle( title ); - - updateTitle(); -} - -/*! - Changes the layout of the group box - \param strips - number of column/rows - \param o - orientation -*/ -void QtxGroupBox::setColumnLayout( int strips, Orientation o ) -{ - if ( myContainer ) - myContainer->reparent( 0, QPoint( 0, 0 ), false ); - - QGroupBox::setColumnLayout( strips, o ); - - if ( myContainer ) - myContainer->reparent( this, QPoint( 0, 0 ), false ); - - updateTitle(); -} - -/*! - Shows group box -*/ -void QtxGroupBox::show() -{ - QGroupBox::show(); - - updateTitle(); -} - -/*! - Updates group box -*/ -void QtxGroupBox::update() -{ - QGroupBox::update(); - - updateTitle(); -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxGroupBox::sizeHint() const -{ - QSize sz = QGroupBox::sizeHint(); - - int sw = titleSize().width(); - - if ( myContainer ) - { - if ( alignment() == AlignCenter ) - sw += 2 * ( myContainer->width() + 5 ); - else - sw += 1 * ( myContainer->width() + 5 ); - } - - sw += frameRect().left(); - - return QSize( QMAX( sz.width(), sw ), sz.height() ); -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxGroupBox::minimumSizeHint() const -{ - QSize sz = QGroupBox::minimumSizeHint(); - - int sw = titleSize().width() + myContainer ? myContainer->width() + 5 : 0; - - if ( myContainer ) - { - if ( alignment() == AlignCenter ) - sw += 2 * ( myContainer->width() + 5 ); - else - sw += 1 * ( myContainer->width() + 5 ); - } - - sw += frameRect().left(); - - return QSize( QMAX( sz.width(), sw ), sz.height() ); -} - -/*! - Custom event filter -*/ -bool QtxGroupBox::eventFilter( QObject* obj, QEvent* e ) -{ - QEvent::Type type = e->type(); - if ( myContainer && obj->parent() == myContainer && - ( type == QEvent::Show || type == QEvent::ShowToParent || - type == QEvent::Hide || type == QEvent::HideToParent ) ) - QApplication::postEvent( this, new QCustomEvent( QEvent::User ) ); - - return QGroupBox::eventFilter( obj, e ); -} - -/*! - Custom resize event filter -*/ -void QtxGroupBox::resizeEvent( QResizeEvent* e ) -{ - QGroupBox::resizeEvent( e ); - - updateTitle(); -} - -/*! - Custom child event filter -*/ -void QtxGroupBox::childEvent( QChildEvent* e ) -{ - if ( e->type() == QEvent::ChildInserted && e->child() == myContainer ) - return; - - QGroupBox::childEvent( e ); -} - -/*! - Event filter of custom items -*/ -void QtxGroupBox::customEvent( QCustomEvent* ) -{ - updateTitle(); -} - -/*! - On frame changed -*/ -void QtxGroupBox::frameChanged() -{ - updateTitle(); -} - -/*! - \return size of title -*/ -QSize QtxGroupBox::titleSize() const -{ - QSize sz( 0, 0 ); - - if ( layout() ) - { - QSpacerItem* si = 0; - for ( QLayoutIterator it = layout()->iterator(); it.current() && !si; ++it ) - si = it.current()->spacerItem(); - if ( si ) - sz = si->sizeHint(); - } - - int w = sz.width(); - int h = sz.height() + insideMargin(); - - return QSize( w, h ); -} - -/*! - Updates title -*/ -void QtxGroupBox::updateTitle() -{ - if ( !myContainer ) - return; - - int align = alignment(); - if ( align == AlignAuto ) - align = QApplication::reverseLayout() ? AlignRight : AlignLeft; - - if ( title().isEmpty() ) - align = AlignRight; - - QSize ts = titleSize(); - - int m = 5; - - int w = frameRect().width() - ts.width(); - if ( align == AlignCenter ) - w = w / 2; - - w -= m; - - QApplication::sendPostedEvents( myContainer, QEvent::ChildInserted ); - myContainer->resize( myContainer->minimumSizeHint() ); - - bool vis = false; - const QObjectList* list = myContainer->children(); - if ( list ) - { - for ( QObjectListIt it( *list ); it.current() && !vis; ++it ) - vis = it.current()->isWidgetType() && - ((QWidget*)it.current())->isVisibleTo( myContainer ); - } - - if ( myContainer->height() > ts.height() || myContainer->width() > w || !vis ) - myContainer->hide(); - else - { - int x = 0; - if ( align == AlignRight ) - x = frameRect().left() + m; - else - x = frameRect().right() - myContainer->width() - m; - - int y = frameRect().top() - ( myContainer->height() - frameWidth() ) / 2; - - QPoint pos( x, QMAX( 0, y ) ); - pos = mapToGlobal( pos ); - if ( myContainer->parentWidget() ) - pos = myContainer->parentWidget()->mapFromGlobal( pos ); - myContainer->move( pos ); - myContainer->show(); - } - - updateGeometry(); -} diff --git a/src/Qtx/QtxGroupBox.h b/src/Qtx/QtxGroupBox.h deleted file mode 100644 index 04f9bb2e6..000000000 --- a/src/Qtx/QtxGroupBox.h +++ /dev/null @@ -1,80 +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: QtxGroupBox.h -// Author: Sergey TELKOV - -#ifndef QTXGROUPBOX_H -#define QTXGROUPBOX_H - -#include "Qtx.h" - -#include -#include - -class QTX_EXPORT QtxGroupBox : public QGroupBox -{ - Q_OBJECT - -public: - QtxGroupBox( QWidget* = 0, const char* = 0 ); - QtxGroupBox( const QString&, QWidget* = 0, const char* = 0 ); - QtxGroupBox( int, Orientation, QWidget* = 0, const char* = 0 ); - QtxGroupBox( int, Orientation, const QString&, QWidget* = 0, const char* = 0 ); - virtual ~QtxGroupBox(); - -#if QT_VER < 3 - int insideMargin() const; - int insideSpacing() const; - void setInsideMargin( int ); - void setInsideSpacing( int ); -#endif - - virtual void setAlignment( int ); - virtual void setTitle( const QString& ); - virtual void setColumnLayout( int, Orientation ); - - virtual void insertTitleWidget( QWidget* ); - virtual void removeTitleWidget( QWidget* ); - - virtual void show(); - virtual void update(); - - void adjustInsideMargin(); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; - - virtual bool eventFilter( QObject*, QEvent* ); - -protected: - virtual void frameChanged(); - virtual void childEvent( QChildEvent* ); - virtual void resizeEvent( QResizeEvent* ); - virtual void customEvent( QCustomEvent* ); - -private: - void initialize(); - void updateTitle(); - QSize titleSize() const; - -private: - QWidget* myContainer; -}; - -#endif diff --git a/src/Qtx/QtxIntSpinBox.cxx b/src/Qtx/QtxIntSpinBox.cxx deleted file mode 100755 index e002377e6..000000000 --- a/src/Qtx/QtxIntSpinBox.cxx +++ /dev/null @@ -1,173 +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: QtxIntSpinBox.cxx -// Author: Sergey TELKOV - -#include "QtxIntSpinBox.h" - -#include -#include - -/*! - Constructor -*/ -QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name ) -: QSpinBox( parent, name ), -myCleared( false ), -myBlocked( false ) -{ - connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); -} - -/*! - Constructor -*/ -QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name ) -: QSpinBox( min, max, step, parent, name ), -myCleared( false ), -myBlocked( false ) -{ - connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); -} - -/*! - Destructor -*/ -QtxIntSpinBox::~QtxIntSpinBox() -{ -} - -/*! - \return true if spin box is cleared -*/ -bool QtxIntSpinBox::isCleared() const -{ - return myCleared; -} - -/*! - Changes cleared status of spin box - \param on - new status -*/ -void QtxIntSpinBox::setCleared( const bool on ) -{ - if ( myCleared == on ) - return; - - myCleared = on; - updateDisplay(); -} - -/*! - Changes value of spin box - \param val - new value of spin box -*/ -void QtxIntSpinBox::setValue( int value ) -{ - myCleared = false; - - QSpinBox::setValue( value ); -} - -/*! - Custom event filter -*/ -bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* e ) -{ - if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() ) - return QSpinBox::eventFilter( o, e ); - - if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide ) - return false; - - if ( e->type() == QEvent::KeyPress && - ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) ) - { - QApplication::sendEvent( this, e ); - return true; - } - - return QSpinBox::eventFilter( o, e ); -} - -/*! - Sets integer value by text in editor -*/ -void QtxIntSpinBox::interpretText() -{ - myCleared = false; - - QSpinBox::interpretText(); -} - -/*! - Updates text of editor -*/ -void QtxIntSpinBox::updateDisplay() -{ - if ( myBlocked ) - return; - - bool block = myBlocked; - myBlocked = true; - - QSpinBox::updateDisplay(); - - if ( myCleared ) - editor()->clear(); - else if ( editor()->hasFocus() ) - { - if ( editor()->text() == specialValueText() ) - editor()->selectAll(); - else - editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() ); - } - - myBlocked = block; -} - -/*! - Custom handler for leave event -*/ -void QtxIntSpinBox::leaveEvent( QEvent* e ) -{ - if ( !myCleared ) - QSpinBox::leaveEvent( e ); -} - -/*! - Custom handler for wheel event -*/ -void QtxIntSpinBox::wheelEvent( QWheelEvent* e ) -{ - if ( !isEnabled() ) - return; - - QSpinBox::wheelEvent( e ); - updateDisplay(); -} - -/*! - SLOT: called if text is changed -*/ -void QtxIntSpinBox::onTextChanged( const QString& ) -{ - if ( !myBlocked ) - myCleared = false; -} diff --git a/src/Qtx/QtxIntSpinBox.h b/src/Qtx/QtxIntSpinBox.h deleted file mode 100755 index 7f083d519..000000000 --- a/src/Qtx/QtxIntSpinBox.h +++ /dev/null @@ -1,60 +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: QtxIntSpinBox.h -// Author: Sergey TELKOV - -#ifndef QTXINTSPINBOX_H -#define QTXINTSPINBOX_H - -#include "Qtx.h" - -#include - -class QTX_EXPORT QtxIntSpinBox : public QSpinBox -{ - Q_OBJECT - -public: - QtxIntSpinBox( QWidget* = 0, const char* = 0 ); - QtxIntSpinBox( int, int, int = 1, QWidget* = 0, const char* = 0 ); - virtual ~QtxIntSpinBox(); - - bool isCleared() const; - virtual void setCleared( const bool ); - - virtual bool eventFilter( QObject*, QEvent* ); - -public slots: - virtual void setValue( int ); - -protected slots: - virtual void onTextChanged( const QString& ); - -protected: - virtual void interpretText(); - virtual void updateDisplay(); - virtual void leaveEvent( QEvent* ); - virtual void wheelEvent( QWheelEvent* ); - -private: - bool myCleared; - bool myBlocked; -}; - -#endif diff --git a/src/Qtx/QtxListAction.cxx b/src/Qtx/QtxListAction.cxx deleted file mode 100755 index 52f093039..000000000 --- a/src/Qtx/QtxListAction.cxx +++ /dev/null @@ -1,1124 +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: QtxListAction.cxx -// Author: Sergey TELKOV (Based on code by Eugene AKSENOV) - -#include "QtxListAction.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char* list_arrow_icon[] = { -"10 6 2 1", -"# c #000000", -" c none", -" ", -" ####### ", -" ##### ", -" ### ", -" # ", -" " -}; - -/*! - \class QtxListAction::ToolButton - Custom tool button -*/ -class QtxListAction::ToolButton : public QToolButton -{ -public: - ToolButton( QtxListAction*, QWidget* = 0, const char* = 0 ); - virtual ~ToolButton(); - - virtual QSize sizeHint() const; - -private: - QtxListAction* myAction; -}; - -/*! - Constructor -*/ -QtxListAction::ToolButton::ToolButton( QtxListAction* a, QWidget* parent, const char* name ) -: QToolButton( parent, name ), -myAction( a ) -{ - setIconSet( QPixmap( list_arrow_icon ) ); -} - -/*! - Destructor -*/ -QtxListAction::ToolButton::~ToolButton() -{ - if ( myAction ) - myAction->controlDeleted( this ); -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxListAction::ToolButton::sizeHint() const -{ - QSize sz = iconSet().pixmap().size(); - return QSize( sz.width() + 2, sz.height() + 2 ); -} - -/*! - Constructs an list action with given parent and name. If toggle is true the - action will be a toggle action, otherwise it will be a command action. -*/ -QtxListAction::QtxListAction( QObject* parent, const char* name, bool toggle ) -: QtxAction( parent, name, toggle ), -myFrame( 0 ), -myMode( Item ), -myRaise( false ) -{ - initialize(); -} - -/*! - This constructor creates an action with the following properties: the - description text, the icon or iconset icon, the menu text and keyboard - accelerator. It is a child of given parent and named specified name. - If toggle is true the action will be a toggle action, otherwise it will - be a command action. -*/ - -QtxListAction::QtxListAction( const QString& text, const QIconSet& icon, - const QString& menuText, int accel, - QObject* parent, const char* name, bool toggle ) -: QtxAction( text, icon, menuText, accel, parent, name, toggle ), -myFrame( 0 ), -myMode( Item ), -myRaise( false ) -{ - initialize(); -} - -/*! - This constructor creates an action with the following properties: the - description text, the menu text and keyboard accelerator. It is a child - of given parent and named specified name. If toggle is true the action - will be a toggle action, otherwise it will be a command action. -*/ - -QtxListAction::QtxListAction( const QString& text, const QString& menuText, - int accel, QObject* parent, const char* name, bool toggle ) -: QtxAction( text, menuText, accel, parent, name, toggle ), -myFrame( 0 ), -myMode( Item ), -myRaise( false ) -{ - initialize(); -} - -/*! - Destructor. -*/ - -QtxListAction::~QtxListAction() -{ - if ( myFrame ) { - myFrame->myAction = 0; - delete myFrame; - myFrame = 0; - } -} - -/*! - Name: popupMode [public] - Desc: Returns popup mode. If popup mode "Item" (default) then action will - be added into popup menu as menu item. If popup mode "SubMenu" then - action will be added into popup menu as sub menu with list of items. -*/ - -int QtxListAction::popupMode() const -{ - return myMode; -} - -/*! - Name: setPopupMode [public] - Desc: Set the popup mode. Popup mode define way in this action will be - added into popup menu. This function should be used before addTo. -*/ - -void QtxListAction::setPopupMode( const int mode ) -{ - myMode = mode; -} - -/*! - \return list of names -*/ -QStringList QtxListAction::names() const -{ - QStringList lst; - if ( myFrame ) - lst = myFrame->names(); - return lst; -} - -/*! - Name: addNames [public] - Desc: Fills the list of actions. Removes the old contents from - the list if 'clear' is true. -*/ - -void QtxListAction::addNames( const QStringList& names, bool clear ) -{ - if ( !myFrame ) - return; - - if ( clear ) - myFrame->clear(); - - myFrame->addNames( names ); - - QStringList lst = myFrame->names(); - for ( PopupsMap::Iterator pit = myPopups.begin(); pit != myPopups.end(); ++pit ) - { - int i = 1; - QPopupMenu* pm = (QPopupMenu*)pit.key(); - for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) - pit.data().popup->insertItem( *it, i++ ); - pm->setItemEnabled( pit.data().id, isEnabled() && pit.data().popup->count() ); - } - - for ( ButtonsMap::Iterator bit = myButtons.begin(); bit != myButtons.end(); ++bit ) - { - bit.data().drop->setEnabled( isEnabled() && !lst.isEmpty() ); - bit.data().main->setEnabled( isEnabled() && !lst.isEmpty() ); - } -} - -/*! - Name: addTo [virtual public] - Desc: Adds this control to 'popup' or 'toolbar'. -*/ - -bool QtxListAction::addTo( QWidget* w ) -{ - if ( myButtons.contains( w ) || myPopups.contains( w ) ) - return false; - - if ( !w->inherits( "QPopupMenu" ) || popupMode() != SubMenu ) - if ( !QtxAction::addTo( w ) ) - return false; - -#if QT_VER < 3 - if ( w->children() ) - addedTo( (QWidget*)w->children()->getLast(), w ); -#endif - - if ( w->inherits( "QToolBar" ) ) - { - Buttons& entry = myButtons[w]; - QHBox* dropWrap = new QHBox( w ); - entry.drop = new ToolButton( this, dropWrap, "qt_dockwidget_internal" ); - - entry.drop->setTextLabel( text() ); - entry.drop->setToggleButton( true ); - entry.drop->setAutoRaise( entry.main->autoRaise() ); - - entry.main->setEnabled( isEnabled() && !myFrame->names().isEmpty() ); - entry.drop->setEnabled( isEnabled() && !myFrame->names().isEmpty() ); - - entry.main->installEventFilter( this ); - entry.drop->installEventFilter( this ); - - QToolTip::add( entry.drop, toolTip(), myTipGroup, statusTip() ); - - connect( entry.drop, SIGNAL( toggled( bool ) ), this, SLOT( onExpand( bool ) ) ); - } - else if ( w->inherits( "QPopupMenu" ) && popupMode() == SubMenu ) - { - Popups entry; - QPopupMenu* pm = (QPopupMenu*)w; - - entry.popup = new QPopupMenu( pm ); - entry.id = pm->insertItem( text(), entry.popup ); - - int i = 1; - QStringList lst = myFrame->names(); - for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) - { - int id = entry.popup->insertItem( *it ); - entry.popup->setItemParameter( id, i++ ); - } - pm->setItemEnabled( entry.id, isEnabled() && entry.popup->count() ); - myPopups.insert( w, entry ); - - connect( entry.popup, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - } - -#if QT_VER >= 3 - connect( w, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); -#endif - - return true; -} - -/*! - Name: addTo [virtual public] - Desc: Adds this control to 'popup' or 'toolbar'. Allow to specify index - for adding into 'popup'. -*/ - -bool QtxListAction::addTo( QWidget* w, const int idx ) -{ - return QtxAction::addTo( w, idx ); -} - -/*! - Name: removeFrom [virtual public] - Desc: Removes this control from 'popup' or 'toolbar'. -*/ - -bool QtxListAction::removeFrom( QWidget* w ) -{ - if ( !QtxAction::removeFrom( w ) ) - return false; - - if ( w->inherits( "QToolBar" ) ) - { - if ( myFrame ) - myFrame->hide(); - - if ( myButtons.contains( w ) ) - { - Buttons& entry = myButtons[w]; - - if ( entry.drop->parent() && entry.drop->parent()->parent() == w ) - delete entry.drop->parent(); - else - delete entry.drop; - } - myButtons.remove( w ); - } - else if ( w->inherits( "QPopupMenu" ) ) - myPopups.remove( w ); - -#if QT_VER >= 3 - disconnect( w, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); -#endif - - return true; -} - -/*! - Name: setEnabled [virtual public slot] - Desc: Enables/disables this control. -*/ - -void QtxListAction::setEnabled( bool enable ) -{ - QtxAction::setEnabled( enable ); - - bool isOn = enable && !myFrame->names().isEmpty(); - - for ( ButtonsMap::Iterator bit = myButtons.begin(); bit != myButtons.end(); ++bit ) - { - bit.data().drop->setEnabled( isOn ); - bit.data().main->setEnabled( isOn ); - } - - for ( PopupsMap::Iterator pit = myPopups.begin(); pit != myPopups.end(); ++pit ) - { - QPopupMenu* cont = (QPopupMenu*)pit.key(); - cont->setItemEnabled( pit.data().id, isOn ); - } -} - -/*! - Name: setMaxLines [public] - Desc: Sets max number of lines that list frame shows - without vertical scroll bar. Default value is 5. -*/ - -void QtxListAction::setMaxLines( int nlines ) -{ - myFrame->setMaxLines( nlines ); -} - -/*! - Name: setMaxLineChars [public] - Desc: Sets max number of characters in a line which list frame shows - without truncation. Default value is 12 (the widest char size is used). -*/ - -void QtxListAction::setMaxLineChars( int nchars ) -{ - myFrame->setMaxLineChars( nchars ); -} - -/*! - Name: setComment [public] - Desc: Sets the format Qt string for comments displayed under the list - of actions for one action and for several actions. - Ex. "Undo %1 actions" format string will work as "Undo 3 actions" - when 3 actions are selected. The default format string is "%1". -*/ - -void QtxListAction::setComment( const QString& c, const QString& sc ) -{ - if ( !myFrame ) - return; - - myFrame->setSingleComment( sc.isEmpty() ? c : sc ); - myFrame->setMultipleComment( c ); -} - -/*! - Name: eventFilter [virtual public] - Desc: Reimplemented to paint the tool buttons in 2D/3D. -*/ - -bool QtxListAction::eventFilter( QObject* o, QEvent* e ) -{ - if ( !myRaise && ( e->type() == QEvent::Enter || e->type() == QEvent::Leave ) ) - { - QWidget* obj = 0; - QWidget* wid = widget( (QWidget*)o ); - if ( o == mainButton( wid ) ) - obj = dropButton( wid ); - else if ( o == dropButton( wid ) ) - obj = mainButton( wid ); - - if ( obj ) - { - myRaise = true; - QApplication::sendEvent( obj, e ); - obj->repaint(); - myRaise = false; - } - } - return QObject::eventFilter( o, e ); -} - -/*! - Name: addedTo [protected] - Desc: Reimplemented for internal reasons. -*/ - -void QtxListAction::addedTo( QWidget* actionWidget, QWidget* container ) -{ -#if QT_VER >= 3 - QtxAction::addedTo( actionWidget, container ); -#endif - - if ( !container->inherits( "QToolBar" ) ) - return; - - Buttons entry; - entry.main = (QToolButton*)actionWidget; - - myButtons.insert( container, entry ); -} - -/*! - Name: initialize [private] - Desc: Initialization of object QtxListAction. -*/ - -void QtxListAction::initialize() -{ - myTipGroup = new QToolTipGroup( this ); - - myFrame = new QtxListFrame( this, qApp->mainWidget() ); - myFrame->setMaxLines( 5 ); - myFrame->setMaxLineChars( 7 ); - - myFrame->hide(); - - connect( myFrame, SIGNAL( hided() ), this, SLOT( onHided() ) ); - connect( this, SIGNAL( activated() ), this, SLOT( onSingle() ) ); - connect( myFrame, SIGNAL( selected( int ) ), this, SLOT( onMultiple( int ) ) ); - - connect( myTipGroup, SIGNAL( removeTip() ), this, SLOT( clearStatusText() ) ); - connect( myTipGroup, SIGNAL( showTip( const QString& ) ), this, SLOT( showStatusText( const QString& ) ) ); -} - -/*! - Name: onSingle [private slot] - Desc: Called when a single action is selected. -*/ - -void QtxListAction::onSingle() -{ - emit activated( 1 ); -} - -/*! - Name: onMultiple [private slot] - Desc: Called when multiple actions are selected. -*/ - -void QtxListAction::onMultiple( int numActions ) -{ - if ( myFrame ) - myFrame->hide(); - - if ( numActions > 0 ) - emit activated( numActions ); -} - -/*! - Name: onExpand [private slot] - Desc: Activates the list of actions. -*/ - -void QtxListAction::onExpand( bool on ) -{ - const QObject* obj = sender(); - if ( on ) - { - QWidget* wid = widget( (QToolButton*)obj ); - QToolButton* main = mainButton( wid ); - myFrame->setOwner( main ); - if ( main ) - myFrame->show(); - } - else - myFrame->hide(); -} - -/*! - SLOT: called when frame is hidden -*/ -void QtxListAction::onHided() -{ - for ( ButtonsMap::Iterator bit = myButtons.begin(); bit != myButtons.end(); ++bit ) - { - bool block = bit.data().drop->signalsBlocked(); - bit.data().drop->blockSignals( true ); - bit.data().drop->setOn( false ); - bit.data().drop->blockSignals( block ); - } -} - -/*! - Name: onActivated [private slot] - Desc: Called when a sub menu item is activated. -*/ - -void QtxListAction::onActivated( int id ) -{ - QPopupMenu* pm = (QPopupMenu*)sender(); - int num = pm->itemParameter( id ); - if ( num > 0 ) - emit activated( num ); -} - -/*! - Name: onDestroyed [private slot] - Desc: Called when a container widget is destroyed. -*/ - -void QtxListAction::onDestroyed( QObject* obj ) -{ - if ( !obj->isWidgetType() ) - return; - - myPopups.remove( (QWidget*)obj ); - myButtons.remove( (QWidget*)obj ); -} - -/*! - Name: widget [private] - Desc: Returns container widget for specified control. -*/ - -QWidget* QtxListAction::widget( QWidget* obj ) const -{ - QWidget* wid = 0; - for ( PopupsMap::ConstIterator pit = myPopups.begin(); pit != myPopups.end() && !wid; ++pit ) - if ( pit.data().popup == obj ) - wid = pit.key(); - - for ( ButtonsMap::ConstIterator bit = myButtons.begin(); bit != myButtons.end() && !wid; ++bit ) - if ( bit.data().main == obj || bit.data().drop == obj ) - wid = bit.key(); - - return wid; -} - -/*! - Name: listPopup [private] - Desc: Returns sub popup menu widget for specified container. -*/ - -QPopupMenu* QtxListAction::listPopup( QWidget* wid ) const -{ - QPopupMenu* p = 0; - if ( myPopups.contains( wid ) ) - p = myPopups[wid].popup; - return p; -} - -/*! - Name: mainButton [private] - Desc: Returns main tool button for specified container. -*/ - -QToolButton* QtxListAction::mainButton( QWidget* wid ) const -{ - QToolButton* mb = 0; - if ( myButtons.contains( wid ) ) - mb = myButtons[wid].main; - return mb; -} - -/*! - Name: dropButton [private] - Desc: Returns drop tool button for specified container. -*/ - -QToolButton* QtxListAction::dropButton( QWidget* wid ) const -{ - QToolButton* db = 0; - if ( myButtons.contains( wid ) ) - db = myButtons[wid].drop; - return db; -} - -/*! - Name: controlDeleted [private] - Desc: Called when action child controls deleted. -*/ - -void QtxListAction::controlDeleted( QWidget* wid ) -{ - QWidget* w = 0; - for ( ButtonsMap::Iterator it = myButtons.begin(); it != myButtons.end() && !w; ++it ) - { - if ( it.data().main == wid || it.data().drop == wid ) - w = it.key(); - } - - if ( w ) - { - if ( myFrame ) - myFrame->hide(); - - myButtons.remove( w ); - } -} - -/*! - \class QtxListFrame - Frame for the list of actions -*/ -class QtxListFrame::ScrollEvent : public QCustomEvent -{ -public: - enum { Scroll = User + 1 }; - - ScrollEvent( bool down ) : QCustomEvent( Scroll ), myDown( down ) {}; - virtual ~ScrollEvent() {}; - - bool isDown() const { return myDown; }; - -private: - bool myDown; -}; - -/*! - Class: QtxListAction - Level: Public -*/ - -/*! - Constructor -*/ -QtxListFrame::QtxListFrame( QtxListAction* a, QWidget* parent, WFlags f ) -: QFrame( parent, 0, WStyle_Customize | WStyle_NoBorderEx | WType_Popup | WStyle_Tool | WStyle_StaysOnTop ), -myList( 0 ), -myOwner( 0 ), -myAction( a ), -myComment( 0 ), -myMaxLines( 5 ), -myMaxLineChars( 10 ), -myScrollVal( 0 ), -myScrollBlock( false ) -{ - QVBoxLayout* theLayout = new QVBoxLayout( this, 3 ); - theLayout->setResizeMode( QLayout::FreeResize ); - - myList = new QListBox( this ); - myList->setSelectionMode( QListBox::Multi ); - myList->setHScrollBarMode( QScrollView::AlwaysOff ); - myList->setFocusPolicy( NoFocus ); - - QPalette p = myList->palette(); - p.setColor( QPalette::Inactive, QColorGroup::Highlight, - p.color( QPalette::Active, QColorGroup::Highlight ) ); - p.setColor( QPalette::Inactive, QColorGroup::HighlightedText, - p.color( QPalette::Active, QColorGroup::HighlightedText ) ); - myList->setPalette( p ); - - /* We'll have the vertical scroll bar only and - truncate the names which are too wide */ - connect( myList, SIGNAL( contentsMoving( int, int ) ), this, SLOT( onScroll( int, int ) ) ); - - myComment = new QLabel( this ); - myComment->setFrameStyle( Panel | Sunken ); - myComment->setAlignment( AlignCenter ); - myMultipleComment = "%1"; - - theLayout->addWidget( myList ); - theLayout->addWidget( myComment ); - - setFrameStyle( Panel | Raised ); -} - -/*! - Destructor -*/ -QtxListFrame::~QtxListFrame() -{ - if ( myAction ) - myAction->myFrame = 0; -} - -/*! - Clears list of names [ public ] -*/ - -void QtxListFrame::clear() -{ - myNames.clear(); - setNames( myNames ); -} - -/*! - Adds a names to the list. Truncates the name to fit to the frame width. - Use QtxListAction::setMaxLineChar( int ) to set the width in characters. [ public ] -*/ - -void QtxListFrame::addNames( const QStringList& names ) -{ - for ( QStringList::ConstIterator it = names.begin(); it != names.end(); ++it ) - myNames.append( *it ); - setNames( myNames ); -} - -/*! - Sets a names to the list. Truncates the name to fit to the frame width. - Use QtxListAction::setMaxLineChar( int ) to set the width in characters. [ public ] -*/ - -void QtxListFrame::setNames( const QStringList& names ) -{ - if ( !myList ) - return; - - myList->clear(); - - for ( QStringList::ConstIterator it = names.begin(); it != names.end(); ++it ) - { - QString s = *it; - QFontMetrics fm = myList->fontMetrics(); - int maxW = myMaxLineChars * fm.maxWidth(); - int w = fm.width( s ); - if ( w > maxW ) - { - QString extra( "..." ); - int len = s.length(); - int extraLen = fm.width( extra ) + 1; - while ( true ) - { - w = fm.width( s, --len ); - if ( w + extraLen < maxW ) - { - s = s.left( len ); - break; - } - } - s += extra; - } - myList->insertItem( s ); - } -} - -/*! - \return list of names -*/ -const QStringList QtxListFrame::names() const -{ - return myNames; -} - -/*! - Sets max number of lines shown without activation of vertical scroll bar. [ public ] -*/ - -void QtxListFrame::setMaxLines( int maxLines ) -{ - myMaxLines = maxLines; -} - -/*! - Sets max number of chars in line ( the rest will be truncated ). [ public ] -*/ - -void QtxListFrame::setMaxLineChars( int maxChars ) -{ - if ( myMaxLineChars == maxChars ) - return; - - myMaxLineChars = maxChars; - setNames( myNames ); -} - -/*! - Sets the format of single comment. [ public ] -*/ - -void QtxListFrame::setSingleComment( const QString& comment ) -{ - mySingleComment = comment; - setNames( myNames ); - updateComment(); -} - -/*! - Sets the format of multiple comment. [ public ] -*/ - -void QtxListFrame::setMultipleComment( const QString& comment ) -{ - myMultipleComment = comment; - setNames( myNames ); - updateComment(); -} - -/*! - Updates comment display. [ public ] -*/ - -void QtxListFrame::updateComment() -{ - QString com; - int selNum = selected(); - if ( selNum > 1 ) - com = myMultipleComment; - else if ( selNum > 0 && !mySingleComment.isEmpty() ) - com = mySingleComment; - - if ( !com.isEmpty() ) - com = com.arg( selNum ); - - myComment->setText( com ); -} - -/*! - Sets owner - \param wo - new owner -*/ -void QtxListFrame::setOwner( QWidget* wo ) -{ - myOwner = wo; - if ( myOwner ) - { - QPoint lpos; - if ( myOwner->parentWidget() && myOwner->parentWidget()->inherits( "QToolBar" ) && - ((QToolBar*)myOwner->parentWidget())->orientation() == Qt::Vertical ) - lpos = QPoint( myOwner->x() + myOwner->width() + 2, myOwner->y() ); - else - lpos = QPoint( myOwner->x(), myOwner->y() + myOwner->height() + 2 ); - QPoint gpos = myOwner->parentWidget() ? myOwner->parentWidget()->mapToGlobal( lpos ) - : myOwner->mapToGlobal( lpos ); - if ( parentWidget() ) - move( parentWidget()->mapFromGlobal( gpos ) ); - else - move( gpos ); - } -} - -/*! - Validates the action. [ private slot ] -*/ - -void QtxListFrame::accept() -{ - emit selected( selected() ); -} - -/*! - Cancels the action. [ private slot ] -*/ - -void QtxListFrame::reject() -{ - emit selected( 0 ); -} - -/*! - Initializes / shows the frame. [ virtual public slot ] -*/ - -void QtxListFrame::show() -{ - int cnt = (int)myList->count(); - if ( cnt ) - { - myScrollVal = 0; - myList->setTopItem( 0 ); - myList->clearSelection(); - myList->setMinimumSize( 0, ( QMIN( cnt + 1, myMaxLines ) ) * myList->itemHeight() + 1 ); - setSelected( 1 ); - - int linstep = myList->itemHeight(); - myList->verticalScrollBar()->setLineStep( linstep ); - myList->verticalScrollBar()->setPageStep( myMaxLines * linstep ); - - QFontMetrics fm = myList->fontMetrics(); - layout()->invalidate(); - int maxHeight = layout()->minimumSize().height() + layout()->margin(); - int maxWidth = myMaxLineChars * fm.maxWidth(); - for ( uint i = 0; i <= myList->count(); i++ ) - maxWidth = QMAX( maxWidth, fm.width( myList->text( i ) ) ); - - resize( width(), maxHeight ); - - myList->updateGeometry(); - - QApplication::sendPostedEvents(); - - myList->resizeContents( myList->contentsWidth(), - myList->itemHeight() * cnt ); - if ( myList->contentsHeight() > myList->visibleHeight() ) - maxWidth += myList->verticalScrollBar()->width(); - - QString single = mySingleComment.arg( cnt ); - QString multi = myMultipleComment.arg( cnt ); - int comWidth = QMAX( myComment->fontMetrics().width( single ), myComment->fontMetrics().width( multi ) ); - if ( myComment->frameWidth() ) - comWidth += myComment->fontMetrics().width( "x" ); - - maxWidth = QMAX( maxWidth, comWidth ); - - resize( maxWidth, maxHeight ); - updateComment(); - - qApp->installEventFilter( this ); - - QFrame::show(); - } -} - -/*! - Cleanup. [ virtual public slot ] -*/ - -void QtxListFrame::hide() -{ - qApp->removeEventFilter( this ); - QFrame::hide(); - emit hided(); -} - -/*! - Processes KeyUp/KeyDown, PageUp/PageDown, CR and Esc keys. - Returns 'true' if event is eaten, 'false' otherwise. [ private ] -*/ - -bool QtxListFrame::handleKeyEvent( QObject* , QKeyEvent* e ) -{ - if ( e->type() == QEvent::KeyRelease ) - return true; - - int selNum = selected(); - switch( e->key() ) - { - case Key_Up: - setSelected( QMAX( 1, selNum - 1 ) ); - break; - case Key_Down: - setSelected( QMAX( 1, selNum + 1 ) ); - break; - case Key_PageUp: - setSelected( QMAX( 1, selNum - myMaxLines ) ); - break; - case Key_PageDown: - setSelected( selNum += myMaxLines ); - break; - case Key_Home: - setSelected( 1 ); - break; - case Key_End: - setSelected( myList->count() ); - break; - case Key_Return: - accept(); - break; - case Key_Escape: - reject(); - break; - } - return true; -} - -/*! - Selects items on move, validates on button release. If object 'o' is not our name list, - we close the frame. Returns 'true' if event is eaten, 'false' otherwise. [ private ] -*/ - -bool QtxListFrame::handleMouseEvent( QObject* o, QMouseEvent* e ) -{ - switch( e->type() ) - { - case QEvent::MouseButtonPress: - { - if ( o != myList->viewport() && !isPopup() ) - reject(); - return true; - } - case QEvent::MouseMove: - { - if ( o == myList->viewport() ) - { - QListBoxItem* lbi = myList->itemAt( e->pos() ); - if ( lbi ) - setSelected( myList->index( lbi ) + 1 ); - } - break; - } - case QEvent::MouseButtonRelease: - { - if ( o == myList->viewport() ) - accept(); - else - reject(); - break; - } - default: - break; - } - return true; -} - -/*! - Custom event filter -*/ -bool QtxListFrame::event( QEvent* e ) -{ - if ( e->type() != (int)ScrollEvent::Scroll ) - return QFrame::event( e ); - - ScrollEvent* se = (ScrollEvent*)e; - if ( se->isDown() ) - setSelected( myList->topItem() + myList->numItemsVisible() ); - else - setSelected( myList->topItem() + 1 ); - - return true; -} - -/*! - Watches mouse events on the viewport of the list. [ virtual public ] -*/ - -bool QtxListFrame::eventFilter( QObject* o, QEvent* e ) -{ - bool isKeyEvent = ( e->type() == QEvent::KeyPress || - e->type() == QEvent::KeyRelease ); - bool isMouseEvent = ( e->type() == QEvent::MouseMove || - e->type() == QEvent::MouseButtonPress || - e->type() == QEvent::MouseButtonRelease || - e->type() == QEvent::MouseButtonDblClick ); - - if ( isKeyEvent ) - { - if ( handleKeyEvent( o, ( QKeyEvent* )e ) ) - return true; - } - else if ( isMouseEvent && o != myList->verticalScrollBar() ) - { - if ( handleMouseEvent( o, ( QMouseEvent*)e ) ) - return true; - } - - if ( o != this && ( e->type() == QEvent::Resize || e->type() == QEvent::Move ) ) - setOwner( myOwner ); - - return QFrame::eventFilter( o, e ); -} - -/*! - Selects operations while scrolling the list. [ private slot ] -*/ - -void QtxListFrame::onScroll( int x, int y ) -{ - int dx = y - myScrollVal; - if ( !myScrollBlock ) - QApplication::postEvent( this, new ScrollEvent( dx > 0 ) ); - myScrollVal = y; -} - -/*! - Selects the actions [ 0 - lastSel ]. [ public ] -*/ - -void QtxListFrame::setSelected( const int lastSel ) -{ - int last = QMIN( lastSel, (int)myList->count() ); - - for ( int i = 0; i < (int)myList->count(); i++ ) - myList->setSelected( i, i < last ); - - int item = last - 1; - - myScrollBlock = true; - - if ( item < myList->topItem() ) - myList->setTopItem( item ); - - if ( item >= myList->topItem() + myList->numItemsVisible() ) - myList->setTopItem( item - myList->numItemsVisible() + 1 ); - - myScrollBlock = false; - - myList->clearFocus(); - - updateComment(); -} - -/*! - return number of selected items -*/ -int QtxListFrame::selected() const -{ - uint sel = 0; - while ( sel < myList->count() && myList->isSelected( sel ) ) - sel++; - return sel; -} diff --git a/src/Qtx/QtxListAction.h b/src/Qtx/QtxListAction.h deleted file mode 100755 index 8ad60be5b..000000000 --- a/src/Qtx/QtxListAction.h +++ /dev/null @@ -1,196 +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: QtxListAction.hxx -// Author: Sergey TELKOV (Based on code by Eugene AKSENOV) - -#ifndef QTXLISTACTION_H -#define QTXLISTACTION_H - -#include "QtxAction.h" - -#include -#include -#include - -class QLabel; -class QListBox; -class QPopupMenu; -class QToolButton; -class QToolTipGroup; - -class QtxListFrame; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxListAction : public QtxAction -{ - Q_OBJECT - - Q_PROPERTY( QStringList names READ names WRITE addNames ) - - class ToolButton; - -public: - enum { Item, SubMenu } PopupMode; - -public: - QtxListAction( QObject* = 0, const char* = 0, bool = false ); - QtxListAction( const QString&, const QIconSet&, const QString&, int, QObject*, const char* = 0, bool = false ); - QtxListAction( const QString&, const QString&, int, QObject*, const char* = 0, bool = false ); - virtual ~QtxListAction(); - -public: - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); - - virtual bool removeFrom( QWidget* ); - virtual bool eventFilter( QObject*, QEvent* ); - - int popupMode() const; - void setPopupMode( const int ); - - QStringList names() const; - void addNames( const QStringList&, bool = true ); - void setComment( const QString&, const QString& = QString::null ); - - void setMaxLines( int ); - void setMaxLineChars( int ); - -signals: - void activated( int ); - -public slots: - virtual void setEnabled( bool ); - -private slots: - void onHided(); - void onSingle(); - void onExpand( bool ); - void onMultiple( int ); - void onActivated( int ); - void onDestroyed( QObject* ); - -protected: - virtual void addedTo( QWidget*, QWidget* ); - -private: - void initialize(); - QWidget* widget( QWidget* ) const; - QPopupMenu* listPopup( QWidget* ) const; - QToolButton* mainButton( QWidget* ) const; - QToolButton* dropButton( QWidget* ) const; - - void controlDeleted( QWidget* ); - -private: - typedef struct { int id; QPopupMenu* popup; } Popups; - typedef struct { QToolButton* main; QToolButton* drop; } Buttons; - typedef QMap PopupsMap; - typedef QMap ButtonsMap; - -private: - int myMode; - QtxListFrame* myFrame; - bool myRaise; - PopupsMap myPopups; - ButtonsMap myButtons; - QToolTipGroup* myTipGroup; - - friend class ToolButton; - friend class QtxListFrame; -}; - -/*! - \class QtxListFrame -*/ -class QtxListFrame : public QFrame -{ - Q_OBJECT - - class ScrollEvent; - -public: - QtxListFrame( QtxListAction*, QWidget* parent, WFlags f = 0 ); - virtual ~QtxListFrame(); - - void clear(); - const QStringList names() const; - void addNames( const QStringList& ); - - void setSingleComment( const QString& ); - void setMultipleComment( const QString& ); - - int selected() const; - void setSelected( const int ); - - void setMaxLines( int ); - void setMaxLineChars( int ); - - virtual bool event( QEvent* ); - virtual bool eventFilter( QObject*, QEvent* ); - - void setOwner( QWidget* ); - - void updateComment(); - -signals: - void hided(); - void selected( int ); - -public slots: - virtual void show(); - virtual void hide(); - -private slots: - void reject(); - void accept(); - - void onScroll( int, int ); - -private: - void setNames( const QStringList& ); - bool handleKeyEvent( QObject*, QKeyEvent* ); - bool handleMouseEvent( QObject*, QMouseEvent* ); - - friend class QtxListAction; - -private: - QListBox* myList; - QStringList myNames; - QWidget* myOwner; - QtxListAction* myAction; - QLabel* myComment; - - QString mySingleComment; - QString myMultipleComment; - - int myMaxLines; - int myMaxLineChars; - - int myScrollVal; - bool myScrollBlock; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxListBox.cxx b/src/Qtx/QtxListBox.cxx deleted file mode 100755 index b4bdef35f..000000000 --- a/src/Qtx/QtxListBox.cxx +++ /dev/null @@ -1,471 +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: QtxListBox.cxx -// Author: Sergey TELKOV - -#include "QtxListBox.h" - -#include -#include - -/*! - Constructor -*/ -QtxListBox::QtxListBox( QWidget* parent, const char* name, WFlags f ) -: QListBox( parent, name, f ), -myEditor( 0 ), -myEditIndex( -1 ), -myEditState( false ), -myEditDefault( true ), -myModifEnabled( true ) -{ - connect( this, SIGNAL( contentsMoving( int, int ) ), - this, SLOT( onContentsMoving( int, int ) ) ); -} - -/*! - Destructor -*/ -QtxListBox::~QtxListBox() -{ -} - -/*! - \return true if editing is enabled -*/ -bool QtxListBox::isEditEnabled() const -{ - return myEditState; -} - -/*! - Enables/disables editing - \param on - new state -*/ -void QtxListBox::setEditEnabled( bool on ) -{ - if ( isEditEnabled() == on ) - return; - - myEditState = on; - - if ( !isEditEnabled() ) - endEdition( defaultEditAction() ); -} - -/*! - \return default edit action - \sa setDefaultEditAction() -*/ -bool QtxListBox::defaultEditAction() const -{ - return myEditDefault; -} - -/*! - Changes default edit action. - Pressing of ENTER button always accepts new value of edited item. - But other ways, such as focus out or edition of other item accepts - new value of edited item only if "default edit action" is true - \param def - new value -*/ -void QtxListBox::setDefaultEditAction( bool def ) -{ - myEditDefault = def; -} - -/*! - \return modification enabled state - \sa setModificationEnabled() -*/ -bool QtxListBox::isModificationEnabled() const -{ - return myModifEnabled; -} - -/*! - Changes "modification enabled" state - If it is true, then pressing of CTRL + { Up, Down, Home, End } allows move items in list - \param on - new state -*/ -void QtxListBox::setModificationEnabled( bool on ) -{ - myModifEnabled = on; -} - -/*! - \return current edited item -*/ -QListBoxItem* QtxListBox::editedItem() const -{ - return item( editedIndex() ); -} - -/*! - \return current edited index -*/ -int QtxListBox::editedIndex() const -{ - return myEditIndex; -} - -/*! - Starts edition of item - \param idx - index of item -*/ -void QtxListBox::startEdition( const int idx ) -{ - if ( idx < 0 || editedIndex() == idx || !isEditEnabled() ) - return; - - QLineEdit* ed = editor(); - if ( !ed ) - return; - - endEdition( defaultEditAction() ); - - myEditIndex = idx; - - ensureItemVisible( myEditIndex ); - - ed->setText( text( myEditIndex ) ); - updateEditor(); - ed->show(); - - ed->setFocus(); -} - -/*! - Starts edition of item - \param item - item to be edited -*/ -void QtxListBox::startEdition( const QListBoxItem* item ) -{ - startEdition( index( item ) ); -} - -/*! - Finishes edition of item - \param action - if it is true, then new values must be accepted -*/ -void QtxListBox::endEdition( const bool action ) -{ - int idx = editedIndex(); - QLineEdit* ed = editor(); - - if ( idx < 0 || !ed ) - return; - - myEditIndex = -1; - - ed->hide(); - - if ( action ) - { - int cur = currentItem(); - - if ( pixmap( idx ) ) - changeItem( *pixmap( idx ), ed->text(), idx ); - else - changeItem( ed->text(), idx ); - - setCurrentItem( cur ); - - emit itemEdited( idx ); - emit itemEdited( item( idx ) ); - } -} - -/*! - Ensures that the item is visible. - \param idx - index of item -*/ -void QtxListBox::ensureItemVisible( const int idx ) -{ - if ( idx < 0 ) - return; - - if ( itemVisible( idx ) ) - return; - - setTopItem( idx ); -} - -/*! - Ensures that the item is visible. - \param item - item to be made visible -*/ -void QtxListBox::ensureItemVisible( const QListBoxItem* item ) -{ - ensureItemVisible( index( item ) ); -} - -/*! - \return validator of item editor -*/ -const QValidator* QtxListBox::validator() const -{ - const QValidator* v = 0; - if ( editor() ) - v = editor()->validator(); - return v; -} - -/*! - Removes validator of item editor -*/ -void QtxListBox::clearValidator() -{ - if ( editor() ) - editor()->clearValidator(); -} - -/*! - Changes validator of item editor - \param v - new validator -*/ -void QtxListBox::setValidator( const QValidator* v ) -{ - if ( editor() ) - editor()->setValidator( v ); -} - -/*! - Moves item to top - \param idx - index of item -*/ -void QtxListBox::moveItemToTop( const int idx ) -{ - moveItem( idx, -idx ); -} - -/*! - Moves item to bottom - \param idx - index of item -*/ -void QtxListBox::moveItemToBottom( const int idx ) -{ - moveItem( idx, count() - idx ); -} - -/*! - Moves item - \param idx - index of item - \param step - changing of position -*/ -void QtxListBox::moveItem( const int idx, const int step ) -{ - QListBoxItem* i = item( idx ); - if ( !i || step == 0 ) - return; - - QListBoxItem* cur = item( currentItem() ); - - takeItem( i ); - insertItem( i, QMAX( 0, idx + step ) ); - - setCurrentItem( index( cur ) ); - - int pos = index( i ); - if ( myEditIndex == idx ) - myEditIndex = pos; - - updateEditor(); - - if ( idx != pos ) - emit itemMoved( idx, pos ); -} - -/*! - Inserts empty item - \param i - position of item (if it is less than 0, then current position is used) -*/ -void QtxListBox::createItem( const int i ) -{ - if ( !isEditEnabled() ) - return; - - int idx = i < 0 ? currentItem() : i; - idx = idx < 0 ? count() : idx; - idx = QMIN( (int)count(), idx ); - - insertItem( "", idx ); - setCurrentItem( idx ); - startEdition( idx ); -} - -/*! - Removes item - \param i - position of item (if it is less than 0, then current position is used) -*/ -void QtxListBox::deleteItem( const int i ) -{ - if ( !isEditEnabled() ) - return; - - int idx = i < 0 ? currentItem() : i; - if ( idx < 0 ) - return; - - if ( editedIndex() == idx ) - endEdition( defaultEditAction() ); - - removeItem( idx ); - updateEditor(); -} - -/*! - Scrolls the content so that the point is in the top-left corner. - \param x, y - point co-ordinates -*/ -void QtxListBox::setContentsPos( int x, int y ) -{ - QListBox::setContentsPos( x, y ); - - updateEditor(); -} - -/*! - Custom event filter, performs finish of edition on focus out, escape/return/enter pressing -*/ -bool QtxListBox::eventFilter( QObject* o, QEvent* e ) -{ - if ( editor() == o ) - { - if ( e->type() == QEvent::FocusOut ) - endEdition( defaultEditAction() ); - - if ( e->type() == QEvent::KeyPress ) - { - QKeyEvent* ke = (QKeyEvent*)e; - if ( ke->key() == Key_Escape ) - endEdition( false ); - else if ( ke->key() == Key_Enter || ke->key() == Key_Return ) - endEdition( true ); - } - } - - return QListBox::eventFilter( o, e ); -} - -/*! - Custom key press event handler - Allows to move items by CTRL + { Up, Down, Home, End } -*/ -void QtxListBox::keyPressEvent( QKeyEvent* e ) -{ - if ( e->key() == Key_Up && e->state() & ControlButton && isModificationEnabled() ) - moveItem( currentItem(), -1 ); - else if ( e->key() == Key_Down && e->state() & ControlButton && isModificationEnabled() ) - moveItem( currentItem(), 1 ); - else if ( e->key() == Key_Home && e->state() & ControlButton && isModificationEnabled() ) - moveItemToTop( currentItem() ); - else if ( e->key() == Key_End && e->state() & ControlButton && isModificationEnabled() ) - moveItemToBottom( currentItem() ); - else if ( e->key() == Key_Insert && e->state() & ControlButton ) - createItem( currentItem() ); - else if ( e->key() == Key_Delete && e->state() & ControlButton ) - deleteItem( currentItem() ); - else - QListBox::keyPressEvent( e ); -} - -/*! - Custom resize event handler -*/ -void QtxListBox::viewportResizeEvent( QResizeEvent* e ) -{ - QListBox::viewportResizeEvent( e ); - - updateEditor(); -} - -/*! - Custom mouse double click event handler -*/ -void QtxListBox::mouseDoubleClickEvent( QMouseEvent* e ) -{ - if ( isEditEnabled() ) - startEdition( itemAt( e->pos() ) ); - else - QListBox::mouseDoubleClickEvent( e ); -} - -/*! - Updates editor on contents moving -*/ -void QtxListBox::onContentsMoving( int, int ) -{ - updateEditor(); -} - -/*! - \return item editor -*/ -QLineEdit* QtxListBox::editor() const -{ - if ( !myEditor ) - { - QtxListBox* that = (QtxListBox*)this; - that->createEditor(); - } - return myEditor; -} - -/*! - Creates item editor -*/ -void QtxListBox::createEditor() -{ - if ( myEditor ) - return; - - myEditor = new QLineEdit( viewport() ); - - myEditor->setLineWidth( 1 ); - myEditor->setMidLineWidth( 0 ); - myEditor->setFrameStyle( QFrame::Box | QFrame::Plain ); - myEditor->installEventFilter( this ); - - myEditor->hide(); - - addChild( myEditor ); -} - -/*! - Updates item editor -*/ -void QtxListBox::updateEditor() -{ - if ( !editedItem() || !editor() ) - return; - - QRect r = itemRect( editedItem() ); - if ( !r.isValid() ) - return; - - int m = editor()->lineWidth(); - r.addCoords( m, 0, 0, 0 ); - - const QPixmap* pix = pixmap( editedIndex() ); - if ( pix ) - r.addCoords( pix->width() + 2, 0, 0, 0 ); - - editor()->setGeometry( r ); -} diff --git a/src/Qtx/QtxListBox.h b/src/Qtx/QtxListBox.h deleted file mode 100755 index 180d2cafb..000000000 --- a/src/Qtx/QtxListBox.h +++ /dev/null @@ -1,108 +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: QtxListBox.h -// Author: Sergey TELKOV - -#ifndef QTXLISTBOX_H -#define QTXLISTBOX_H - -#include "Qtx.h" - -#include - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QLineEdit; -class QValidator; - -class QTX_EXPORT QtxListBox : public QListBox -{ - Q_OBJECT - -public: - QtxListBox( QWidget* = 0, const char* = 0, WFlags = 0 ); - virtual ~QtxListBox(); - - bool isEditEnabled() const; - bool defaultEditAction() const; - bool isModificationEnabled() const; - - QListBoxItem* editedItem() const; - int editedIndex() const; - - void startEdition( const int ); - void startEdition( const QListBoxItem* ); - void endEdition( const bool ); - - void ensureItemVisible( const int ); - void ensureItemVisible( const QListBoxItem* ); - - virtual bool eventFilter( QObject*, QEvent* ); - - const QValidator* validator() const; - - void moveItemToTop( const int ); - void moveItemToBottom( const int ); - void moveItem( const int, const int ); - - void createItem( const int = -1 ); - void deleteItem( const int = -1 ); - -signals: - void itemEdited( int ); - void itemEdited( QListBoxItem* ); - void itemMoved( int, int ); - -public slots: - virtual void setEditEnabled( bool ); - virtual void setDefaultEditAction( bool ); - virtual void setModificationEnabled( bool ); - - virtual void clearValidator(); - virtual void setValidator( const QValidator* ); - virtual void setContentsPos( int, int ); - -private slots: - void onContentsMoving( int, int ); - -protected: - virtual void keyPressEvent( QKeyEvent* ); - virtual void viewportResizeEvent( QResizeEvent* ); - virtual void mouseDoubleClickEvent( QMouseEvent* ); - -private: - QLineEdit* editor() const; - void createEditor(); - void updateEditor(); - -private: - QLineEdit* myEditor; - int myEditIndex; - bool myEditState; - bool myEditDefault; - bool myModifEnabled; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxListOfOperations.cxx b/src/Qtx/QtxListOfOperations.cxx deleted file mode 100644 index a6c2e6810..000000000 --- a/src/Qtx/QtxListOfOperations.cxx +++ /dev/null @@ -1,278 +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 "QtxListOfOperations.h" -#include - -/*! - Constructor -*/ -QtxListOfOperations::QtxListOfOperations() -{ -} - -/*! - Destructor -*/ -QtxListOfOperations::~QtxListOfOperations() -{ -} - -/*! - \return fills list with brackets symbols - \param list - list to be filled - \param open - if it is true, it is necessary to fill with open brackets otherwise with close -*/ -void QtxListOfOperations::bracketsList( QStringList& list, bool open ) const -{ - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - QStringList custom; - for( ; anIt!=aLast; anIt++ ) - { - custom.clear(); - (*anIt).myOperations->bracketsList( custom, open ); - QStringList::const_iterator aSIt = custom.begin(), - aSLast = custom.end(); - for( ; aSIt!=aSLast; aSIt++ ) - if( list.contains( *aSIt )==0 ) - list.append( *aSIt ); - } -} - -/*! - Fills list with operation names -*/ -void QtxListOfOperations::opersList( QStringList& list ) const -{ - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - QStringList custom; - for( ; anIt!=aLast; anIt++ ) - { - custom.clear(); - (*anIt).myOperations->opersList( custom ); - QStringList::const_iterator aSIt = custom.begin(), - aSLast = custom.end(); - for( ; aSIt!=aSLast; aSIt++ ) - if( list.contains( *aSIt )==0 ) - list.append( *aSIt ); - } -} - -/*! - Create some value by it's string representation -*/ -bool QtxListOfOperations::createValue( const QString& str, QtxValue& val ) const -{ - bool ok; - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - for( ; anIt!=aLast; anIt++ ) - { - ok = (*anIt).myOperations->createValue( str, val ); - if( ok ) - break; - } - return ok; -} - -/*! - \return priority of operation -*/ -int QtxListOfOperations::prior( const QString& op, bool isBin ) const -{ - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - int prior = 0; - for( ; anIt!=aLast; anIt++ ) - { - prior = (*anIt).myOperations->prior( op, isBin ); - if( prior>0 ) - { - prior+=(*anIt).myAddPrior; - break; - } - } - return prior>0 ? prior : 0; -} - -/*! - \return whether values with passed types are valid for arguments of operation - \param op - name of operation - \param t1 - type of first argument - \param t2 - type of second argument -*/ -QtxParser::Error QtxListOfOperations::isValid( const QString& op, - const QVariant::Type t1, - const QVariant::Type t2 ) const -{ - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - QtxParser::Error err = QtxParser::OK; - for( ; anIt!=aLast; anIt++ ) - { - err = (*anIt).myOperations->isValid( op, t1, t2 ); - if( err==QtxParser::OK ) - break; - } - return err; -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxListOfOperations::calculate( const QString& op, - QtxValue& v1, - QtxValue& v2 ) const -{ - const char* deb = op.latin1(); - - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - QtxValue nv1, nv2; - for( ; anIt!=aLast; anIt++ ) - { - nv1 = v1; - nv2 = v2; - if( (*anIt).myOperations->isValid( op, v1.type(), v2.type() ) == QtxParser::OK ) - { - QtxParser::Error err = (*anIt).myOperations->calculate( op, nv1, nv2 ); - if( err==QtxParser::OK || err==QtxParser::InvalidResult ) - { - QString oop = (*anIt).myName; - const char* ooo = oop.latin1(); - v1 = nv1; v2 = nv2; - return err; - } - } - } - return QtxParser::InvalidOperation; -} - -/*! - Clears list of operations -*/ -void QtxListOfOperations::clear() -{ - mySets.clear(); -} - -/*! - \return true if list contains operations - \param name - name of operation -*/ -bool QtxListOfOperations::has( const QString& name ) const -{ - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).myName == name ) - return true; - return false; -} - -/*! - Appends operations to list - \param name - name of operations - \param oper - operations - \param prior - additional prior -*/ -void QtxListOfOperations::append( const QString& name, QtxOperations* oper, - int prior ) -{ - insert( name, oper, prior ); -} - -/*! - Prepends operations to list - \param name - name of operations - \param oper - operations - \param prior - additional prior -*/ -void QtxListOfOperations::prepend( const QString& name, QtxOperations* oper, - int prior ) -{ - insert( name, oper, prior, 0 ); -} - -/*! - Inserts operations to list - \param name - name of operations - \param oper - operations - \param prior - additional prior - \param pos - insert position -*/ -void QtxListOfOperations::insert( const QString& name, QtxOperations* oper, - int prior, int pos ) -{ - if( has( name ) || oper==NULL || prior<0 ) - return; - - OperationSet op; - op.myName = name; - op.myOperations = oper; - op.myAddPrior = prior; - if( pos<0 ) - mySets.append( op ); - else - mySets.insert( mySets.at( pos ), op ); -} - -/*! - Removes operations from list - \param name - name of operations -*/ -void QtxListOfOperations::remove( const QString& name ) -{ - OperationSets::iterator anIt = mySets.begin(), - aLast = mySets.end(); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).myName == name ) - { - mySets.erase( anIt ); - break; - } -} - -/*! - \return count of operations in list -*/ -int QtxListOfOperations::count() const -{ - return mySets.count(); -} - -/*! - \return operations by name - \name - name of operations -*/ -QtxOperations* QtxListOfOperations::operations( const QString& name ) const -{ - OperationSetsIterator anIt = mySets.begin(), - aLast = mySets.end(); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).myName == name ) - return (*anIt).myOperations; - return NULL; -} diff --git a/src/Qtx/QtxListOfOperations.h b/src/Qtx/QtxListOfOperations.h deleted file mode 100644 index def9dd8c4..000000000 --- a/src/Qtx/QtxListOfOperations.h +++ /dev/null @@ -1,82 +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: QtxListOfOperations.h -// Author: Alexander SOLOVYOV - -#ifndef __QTX_LIST_OF_OPERATIONS_HEADER__ -#define __QTX_LIST_OF_OPERATIONS_HEADER__ - -#include "Qtx.h" -#include "QtxOperations.h" - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - - -/*! - Class: QtxListOfOperations - - This class provides special variant of QtxOperations. It contains list of QtxOperations* with - fixed order. When it is necessary to calculate operation or get it's priority, this operation is - being found starting from first item. It makes possible to create unions of operations. Every QtxOperations* - has priority, which is added to priority of operation, so that it makes possible to increase priority of - whole group of operations -*/ -class QTX_EXPORT QtxListOfOperations : public QtxOperations -{ -public: - QtxListOfOperations(); - virtual ~QtxListOfOperations(); - - virtual void opersList( QStringList& ) const; - virtual void bracketsList( QStringList&, bool open ) const; - - virtual bool createValue( const QString&, QtxValue& ) const; - virtual int prior ( const QString&, bool isBin ) const; - virtual QtxParser::Error isValid( const QString&, - const QVariant::Type, - const QVariant::Type ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; - - void clear (); - bool has ( const QString& ) const; - void append ( const QString&, QtxOperations*, int prior ); - void prepend( const QString&, QtxOperations*, int prior ); - void insert ( const QString&, QtxOperations*, int prior, int pos = -1 ); - void remove ( const QString& ); - int count () const; - QtxOperations* operations( const QString& ) const; - -private: - typedef struct - { - QString myName; - QtxOperations* myOperations; - int myAddPrior; - - } OperationSet; - - typedef QValueList< OperationSet > OperationSets; - typedef OperationSets::const_iterator OperationSetsIterator; - - OperationSets mySets; -}; - -#endif diff --git a/src/Qtx/QtxListResourceEdit.cxx b/src/Qtx/QtxListResourceEdit.cxx deleted file mode 100644 index a075dc153..000000000 --- a/src/Qtx/QtxListResourceEdit.cxx +++ /dev/null @@ -1,1748 +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 ( myIndex.contains( idx ) ) - setInteger( myIndex[idx] ); -} - -/*! - Retrieve value to resource manager -*/ -void QtxListResourceEdit::SelectItem::retrieve() -{ - int id = getInteger( -1 ); - - int idx = -1; - for ( QMap::ConstIterator it = myIndex.begin(); it != myIndex.end() && idx == -1; ++it ) - { - if ( it.data() == id ) - idx = it.key(); - } - - myList->setCurrentItem( idx ); -} - -/*! - \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 fc538004a..000000000 --- a/src/Qtx/QtxListResourceEdit.h +++ /dev/null @@ -1,532 +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 - -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 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 QValueList& ); - -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/QtxListView.cxx b/src/Qtx/QtxListView.cxx deleted file mode 100755 index 92af7e34c..000000000 --- a/src/Qtx/QtxListView.cxx +++ /dev/null @@ -1,422 +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 "QtxListView.h" - -#include -#include -#include - -static const char* list_xpm[] = { -"16 16 6 1", -". c None", -"a c #E3E9EB", -"b c #798391", -"c c #EBEBEB", -"d c #ABB4BE", -"e c #030E1F", -"................", -"................", -"................", -"...aaaaaaaaaa...", -"..abbbbbbbbbbe..", -"..abecbecbecbe..", -"..abbbbbbbbbbe..", -"..abecbecbecbe..", -"..abecaaaaaaaa..", -"..abeccdbbbbbb..", -"..abecccdbbbbe..", -"..abbbbe.dbbe...", -"...eeeee..de....", -"................", -"................", -"................" }; - -/*! - Constructor -*/ -QtxListView::QtxListView( const int state, QWidget* parent, const char* name, WFlags f ) -: QListView( parent, name, f ), -myButton( 0 ), -myHeaderState( state ) -{ - initialize(); -} - -/*! - Constructor -*/ -QtxListView::QtxListView( QWidget* parent, const char* name, WFlags f ) -: QListView( parent, name, f ), -myButton( 0 ), -myHeaderState( HeaderAuto ) -{ - initialize(); -} - -/*! - Initialization -*/ -void QtxListView::initialize() -{ - if ( myHeaderState == HeaderButton ) - { - QPixmap p( list_xpm ); - - QPushButton* but = new QPushButton( this ); - but->setDefault( false ); - but->setFlat( true ); - but->setIconSet( p ); - but->setBackgroundPixmap( p ); - if ( p.mask() ) - but->setMask( *p.mask() ); - myButton = but; - - connect( myButton, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - } - else - { - header()->installEventFilter( this ); - } - - myPopup = new QPopupMenu( this ); - connect( myPopup, SIGNAL( activated( int ) ), this, SLOT( onShowHide( int ) ) ); - connect( header(), SIGNAL( sizeChange( int, int, int ) ), this, SLOT( onHeaderResized() ) ); -} - -/*! - Destructor -*/ -QtxListView::~QtxListView() -{ -} - -/*! - Add new column - \param label - column title - \param width - column width -*/ -int QtxListView::addColumn( const QString& label, int width ) -{ - int res = QListView::addColumn( label, width ); - for ( int i = myAppropriate.count(); i <= res; i++ ) - myAppropriate.append( 1 ); - onHeaderResized(); - return res; -} - -/*! - Add new column - \param iconset - column icon - \param label - column title - \param width - column width -*/ -int QtxListView::addColumn( const QIconSet& iconset, const QString& label, int width ) -{ - int res = QListView::addColumn( iconset, label, width ); - for ( int i = myAppropriate.count(); i <= res; i++ ) - myAppropriate.append( 1 ); - onHeaderResized(); - return res; -} - -/*! - Removes column - \param index - column index -*/ -void QtxListView::removeColumn( int index ) -{ - QListView::removeColumn( index ); - if ( index >= 0 && index < (int)myAppropriate.count() ) - myAppropriate.remove( myAppropriate.at( index ) ); - onHeaderResized(); -} - -/*! - \return true if column is situated in popup for show/hide columns -*/ -bool QtxListView::appropriate( const int index ) const -{ - return index >= 0 && index < (int)myAppropriate.count() && myAppropriate[index]; -} - -/*! - Sets appropriate state: whether column is situated in popup for show/hide columns - \param index - column index - \param on - new state -*/ -void QtxListView::setAppropriate( const int index, const bool on ) -{ - if ( index < 0 || index >= (int)myAppropriate.count() ) - return; - - myAppropriate[index] = on ? 1 : 0; -} - -/*! - Resizes list view and header -*/ -void QtxListView::resize( int w, int h ) -{ - QListView::resize( w, h ); - onHeaderResized(); -} - -/*! - Shows list view -*/ -void QtxListView::show() -{ - QListView::show(); - onHeaderResized(); -} - -/*! - Update on resize contents -*/ -void QtxListView::resizeContents( int w, int h ) -{ -/* - if ( myButton && myButton->isVisibleTo( myButton->parentWidget() ) ) - { - if ( header()->orientation() == Qt::Horizontal ) - w += myButton->width(); - else - h += myButton->width(); - } -*/ - QListView::resizeContents( w, h ); - - onHeaderResized(); -} - -/*! - Shows column - \param ind - column index -*/ -void QtxListView::show( int ind ) -{ - setShown( ind, true ); -} - -/*! - Hides column - \param ind - column index -*/ -void QtxListView::hide( int ind ) -{ - setShown( ind, false ); -} - -/*! - \return true if column is shown - \param ind - column index -*/ -bool QtxListView::isShown( int ind ) const -{ - if ( ind>=0 && indcount() ) - return columnWidth( ind ) > 0 || header()->isResizeEnabled( ind ); - else - return false; -} - -/*! - Shows/hides column - \param ind - column index - \param sh - new is shown state -*/ -void QtxListView::setShown( int ind, bool sh ) -{ - if( ind<0 || ind>=header()->count() || isShown( ind )==sh ) - return; - - ColumnData& data = myColumns[ind]; - if ( sh ) - { - int w = data.width; - bool resizeable = data.resizeable; - myColumns.remove( ind ); - - setColumnWidth( ind, w ); - header()->setResizeEnabled( resizeable, ind ); - } - else - { - int w = columnWidth( ind ); - bool r = header()->isResizeEnabled( ind ); - setColumnWidth( ind, 0 ); - header()->setResizeEnabled( false, ind ); - data.width = w; - data.resizeable = r; - } - updateContents(); -} - -/*! - Changes column width - \param c - column index - \param w - new width -*/ -void QtxListView::setColumnWidth( int c, int w ) -{ - if ( myColumns.contains( c ) ) - myColumns[c].width = w; - - QListView::setColumnWidth( c, !myColumns.contains( c ) ? w : 0 ); -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxListView::sizeHint() const -{ - QSize sz = QListView::sizeHint(); - - if ( myButton && myButton->isVisibleTo( myButton->parentWidget() ) ) - sz.setWidth( sz.width() + 2 + myButton->width() ); - - return sz; -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxListView::minimumSizeHint() const -{ - QSize sz = QListView::minimumSizeHint(); - - if ( myButton && myButton->isVisibleTo( myButton->parentWidget() ) ) - sz.setWidth( sz.width() + 2 + myButton->width() ); - - return sz; -} - -/*! - SLOT: called if header is resized -*/ -void QtxListView::onHeaderResized() -{ - if ( myHeaderState == HeaderAuto ) - { - int c = 0; - for ( int i = 0; i < columns(); i++ ) - { - if ( !header()->label( i ).isEmpty() || - ( header()->iconSet( i ) && !header()->iconSet( i )->isNull() ) ) - c++; - } - - if ( c > 1 ) - header()->show(); - else - header()->hide(); - } - - if ( !myButton || !header()->isVisibleTo( this ) ) - return; - - int lw = lineWidth(); - int h = header()->size().height() - 1; - myButton->setFixedSize( h, h ); - - int x = header()->headerWidth() - header()->offset() + 2; - if ( x < header()->width() - h ) - x = header()->width() - h; - - if ( myHeaderState == HeaderButton ) - { - if ( header()->orientation() == Qt::Horizontal ) - myButton->move( lw+x, lw ); - else - myButton->move( lw, lw+x ); - } -} - -/*! - Shows popup filled with column names to show/hide column - \param x, y - position of popup -*/ -void QtxListView::showPopup( const int x, const int y ) -{ - myPopup->clear(); - for ( int i = 0; i < columns(); i++ ) - { - if ( appropriate( i ) ) - { - int id = myPopup->insertItem( header()->label( i ), i ); - myPopup->setItemChecked( id, isShown( i ) ); - } - } - - if( myPopup->count() ) - myPopup->exec( mapToGlobal( QPoint( x, y ) ) ); -} - -/*! - SLOT: shows popup on button ".." click -*/ -void QtxListView::onButtonClicked() -{ - if ( myHeaderState != HeaderButton ) - return; - - int x = myButton->x(), - y = myButton->y() + myButton->height(); - - showPopup( x, y ); -} - -/*! - SLOT: called on popup action is activated, toggles shown state of column - \param id - column index -*/ -void QtxListView::onShowHide( int id ) -{ - //if ( myHeaderState != HeaderButton ) - // return; - - setShown( id, !isShown( id ) ); -} - -/*! - Receives all resize events sent to the viewport -*/ -void QtxListView::viewportResizeEvent( QResizeEvent* e ) -{ - QListView::viewportResizeEvent( e ); - onHeaderResized(); -} - -/*! - Custom event filter, shows popup on right button click -*/ -bool QtxListView::eventFilter( QObject* o, QEvent* e ) -{ - if( o==header() && e->type()==QEvent::MouseButtonPress ) - { - QMouseEvent* me = ( QMouseEvent* )e; - if( me->button()==Qt::RightButton ) - { - showPopup( me->x()+2, me->y()+2 ); - return true; - } - } - - return QListView::eventFilter( o, e ); -} diff --git a/src/Qtx/QtxListView.h b/src/Qtx/QtxListView.h deleted file mode 100755 index 76aa63a05..000000000 --- a/src/Qtx/QtxListView.h +++ /dev/null @@ -1,101 +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 QTXLISTVIEW_H -#define QTXLISTVIEW_H - -#include "Qtx.h" - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -#include -#include - -class QButton; -class QPopupMenu; - -class QTX_EXPORT QtxListView : public QListView -{ - Q_OBJECT - -public: - enum { HeaderAuto, HeaderButton, NoHeaderButton }; - -public: - QtxListView( QWidget* = 0, const char* = 0, WFlags = 0 ); - QtxListView( const int, QWidget* = 0, const char* = 0, WFlags = 0 ); - virtual ~QtxListView(); - - virtual int addColumn( const QString&, int = -1 ); - virtual int addColumn( const QIconSet&, const QString&, int width = -1 ); - - virtual void removeColumn( int ); - - virtual void resize( int, int ); - - void show( int ); - void hide( int ); - - bool isShown( int ) const; - void setShown( int, bool ); - - bool appropriate( const int ) const; - virtual void setAppropriate( const int, const bool ); - - virtual void setColumnWidth( int, int ); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; - -public slots: - virtual void show(); - virtual void resizeContents( int, int ); - -protected slots: - void onHeaderResized(); - void onButtonClicked(); - void onShowHide( int ); - -protected: - virtual void viewportResizeEvent( QResizeEvent* ); - virtual bool eventFilter( QObject*, QEvent* ); - virtual void showPopup( const int x, const int y ); - -private: - typedef struct { int width; bool resizeable; } ColumnData; - typedef QMap ColumnsMap; - -private: - void initialize(); - -private: - QPopupMenu* myPopup; - QButton* myButton; - ColumnsMap myColumns; - QIntList myAppropriate; - int myHeaderState; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxLogoMgr.cxx b/src/Qtx/QtxLogoMgr.cxx deleted file mode 100644 index 2103eccae..000000000 --- a/src/Qtx/QtxLogoMgr.cxx +++ /dev/null @@ -1,200 +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 "QtxLogoMgr.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -/*! - Constructor -*/ -QtxLogoMgr::QtxLogoMgr( QMenuBar* mb ) -: QObject( mb ), -myMenus( mb ), -myId( 0 ) -{ -} - -/*! - Destructor -*/ -QtxLogoMgr::~QtxLogoMgr() -{ -} - -/*! - Returns the menubar. -*/ -QMenuBar* QtxLogoMgr::menuBar() const -{ - return myMenus; -} - -/*! - Returns the count of the existed logos. -*/ -int QtxLogoMgr::count() const -{ - return myLogos.count(); -} - -/*! - Insert new logo to the menu bar area -*/ -void QtxLogoMgr::insert( const QString& id, const QPixmap& pix, const int index ) -{ - if ( pix.isNull() ) - return; - - LogoInfo* inf = 0; - - int idx = find( id ); - if ( idx < 0 ) - { - idx = index < (int)myLogos.count() ? index : -1; - if ( idx < 0 ) - inf = &( *myLogos.append( LogoInfo() ) ); - else - inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) ); - } - else - inf = &( *myLogos.at( idx ) ); - - - inf->id = id; - inf->pix = pix; - - generate(); -} - -/*! - Removes a logo -*/ -void QtxLogoMgr::remove( const QString& id ) -{ - int idx = find( id ); - if ( idx < 0 ) - return; - - myLogos.remove( myLogos.at( idx ) ); - - generate(); -} - -/*! - Removes all logos -*/ -void QtxLogoMgr::clear() -{ - myLogos.clear(); - generate(); -} - -/*! - Inserts logo to menu bar -*/ -void QtxLogoMgr::generate() -{ - if ( !menuBar() ) - return; - - if ( myId ) - menuBar()->removeItem( myId ); - - myId = 0; - - if ( myLogos.isEmpty() ) - return; - - class LogoBox : public QHBox - { - public: - LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {}; - - void addSpacing( int spacing ) - { - QApplication::sendPostedEvents( this, QEvent::ChildInserted ); - ((QHBoxLayout*)layout())->addSpacing( spacing ); - } - - protected: - void drawContents( QPainter* p ) - { - if ( parentWidget()->inherits( "QMenuBar" ) ) - style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() ); - else - QHBox::drawContents( p ); - } - }; - - LogoBox* cnt = new LogoBox( menuBar() ); - cnt->setSpacing( 3 ); - - for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it ) - { - QPixmap pix = (*it).pix; - if ( !pix.mask() ) - { - QImage img = pix.convertToImage(); - QBitmap bm; - if ( img.hasAlphaBuffer() ) - bm = img.createAlphaMask(); - else - bm = img.createHeuristicMask(); - pix.setMask( bm ); - } - - QLabel* logoLab = new QLabel( cnt ); - logoLab->setPixmap( (*it).pix ); - logoLab->setScaledContents( false ); - logoLab->setAlignment( QLabel::AlignCenter ); - - if ( pix.mask() ) - logoLab->setMask( *pix.mask() ); - } - - QApplication::sendPostedEvents( cnt, QEvent::ChildInserted ); - cnt->addSpacing( 2 ); - - myId = menuBar()->insertItem( cnt ); - - QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint ); - QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) ); -} - -/*! - \return index of found logo - \param id - logo id -*/ -int QtxLogoMgr::find( const QString& id ) const -{ - int idx = -1; - for ( uint i = 0; i < myLogos.count() && idx < 0; i++ ) - { - if ( (*myLogos.at( i ) ).id == id ) - idx = i; - } - return idx; -} diff --git a/src/Qtx/QtxLogoMgr.h b/src/Qtx/QtxLogoMgr.h deleted file mode 100644 index 7e0615c82..000000000 --- a/src/Qtx/QtxLogoMgr.h +++ /dev/null @@ -1,67 +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_LOGOMGR_H -#define QTX_LOGOMGR_H - -#include "Qtx.h" - -class QMenuBar; - -#include -#include - -#ifdef WIN32 -#pragma warning( disable : 4251 ) -#endif - -class QTX_EXPORT QtxLogoMgr : public QObject -{ - Q_OBJECT - -public: - QtxLogoMgr( QMenuBar* ); - virtual ~QtxLogoMgr(); - - int count() const; - - void insert( const QString&, const QPixmap&, const int = -1 ); - void remove( const QString& ); - void clear(); - - QMenuBar* menuBar() const; - -private: - void generate(); - int find( const QString& ) const; - -private: - typedef struct { QString id; QPixmap pix; } LogoInfo; - typedef QValueList LogoList; - -private: - int myId; - QMenuBar* myMenus; - LogoList myLogos; -}; - -#ifdef WIN32 -#pragma warning( default : 4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxMRUAction.cxx b/src/Qtx/QtxMRUAction.cxx deleted file mode 100755 index eea0be25a..000000000 --- a/src/Qtx/QtxMRUAction.cxx +++ /dev/null @@ -1,662 +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: QtxMRUAction.cxx -// Author: Sergey TELKOV - -#include "QtxMRUAction.h" - -#include "QtxResourceMgr.h" - -#include - -/*! - Name: QtxMRUAction [public] - Desc: Constructs an MRU action with given parent and name. -*/ - -QtxMRUAction::QtxMRUAction( QObject* parent, const char* name ) -: QtxAction( "Most Recently Used", "Most Recently Used", 0, parent, name ), -myVisCount( 5 ), -myPopupMode( SubMenu ), -myInsertMode( MoveFirst ) -{ -} - -/*! - Name: QtxMRUAction [public] - Desc: This constructor creates an action with the following properties: the - description text, the menu text and. It is a child of given parent and - named specified name. -*/ - -QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObject* parent, const char* name ) -: QtxAction( text, menuText, 0, parent, name ), -myVisCount( 5 ), -myPopupMode( SubMenu ), -myInsertMode( MoveFirst ) -{ -} - -/*! - Name: QtxMRUAction [public] - Desc: This constructor creates an action with the following properties: the - description text, the menu text, the icon or iconset icon and keyboard - accelerator. It is a child of given parent and named specified name. -*/ - -QtxMRUAction::QtxMRUAction( const QString& text, const QIconSet& icon, const QString& menuText, QObject* parent, const char* name ) -: QtxAction( text, icon, menuText, 0, parent, name ), -myVisCount( 5 ), -myPopupMode( SubMenu ), -myInsertMode( MoveFirst ) -{ -} - -/*! - Name: ~QtxMRUAction [public] - Desc: This destructor removes all added popup items. -*/ - -QtxMRUAction::~QtxMRUAction() -{ - for ( ItemsMap::ConstIterator iIt = myItems.begin(); iIt != myItems.end(); ++iIt ) - removeFrom( iIt.key() ); - - for ( MenusMap::ConstIterator mIt = myMenus.begin(); mIt != myMenus.end(); ++mIt ) - removeFrom( mIt.key() ); -} - -/*! - Name: insertMode [public] - Desc: Returns the insert mode. -*/ - -int QtxMRUAction::insertMode() const -{ - return myInsertMode; -} - -/*! - Name: setInsertMode [public] - Desc: Returns the insert mode. Can be following values: - MoveFirst - place the specified link to the first position in any case - MoveLast - place the specified link to the last position in any case - AddFirst - if inserted link doesn't exist then add to the first position - AddLast - if inserted link doesn't exist then add to the lase position -*/ - -void QtxMRUAction::setInsertMode( const int mode ) -{ - myInsertMode = mode; -} - -/*! - Name: popupMode [public] - Desc: Returns the popup mode. -*/ - -int QtxMRUAction::popupMode() const -{ - return myPopupMode; -} - -/*! - Name: setPopupMode [public] - Desc: Set the popup mode. If this mode is 'Items' then method "addTo" creates the - items in the specified popup menu. If mode is 'SubMenu' then items will be - create in sub popup menu which will be placed in specified popup. -*/ - -void QtxMRUAction::setPopupMode( const int mode ) -{ - myPopupMode = mode; -} - -/*! - Name: count [public] - Desc: Returns the number of links. -*/ - -int QtxMRUAction::count() const -{ - return myLinks.count(); -} - -/*! - Name: isEmpty [public] - Desc: Returns 'true' if there is no links. -*/ - -bool QtxMRUAction::isEmpty() const -{ - return myLinks.isEmpty(); -} - -/*! - Name: visibleCount [public] - Desc: Returns the number of first links which will be added to popup menu. - If 'visibleCount' less than 1 then all links will be used. -*/ - -int QtxMRUAction::visibleCount() const -{ - return myVisCount; -} - -/*! - Name: setVisibleCount [public] - Desc: Sets the number of links which will be used in popup menu. -*/ - -void QtxMRUAction::setVisibleCount( int num ) -{ - if ( myVisCount == num ) - return; - - myVisCount = num; - - updateState(); -} - -/*! - Name: insert [public] - Desc: Insert the link according to the insert mode. -*/ - -void QtxMRUAction::insert( const QString& link ) -{ - if ( myLinks.contains( link ) && ( insertMode() == AddFirst || insertMode() == AddLast ) ) - return; - - myLinks.remove( link ); - - switch ( insertMode() ) - { - case AddFirst: - case MoveFirst: - myLinks.prepend( link ); - break; - case AddLast: - case MoveLast: - myLinks.append( link ); - break; - } - - updateState(); -} - -/*! - Name: remove [public] - Desc: Removes link with specified index. -*/ - -void QtxMRUAction::remove( const int idx ) -{ - if ( idx < 0 || idx >= (int)myLinks.count() ) - return; - - myLinks.remove( myLinks.at( idx ) ); - - updateState(); -} - -/*! - Name: remove [public] - Desc: Removes specified link. -*/ - -void QtxMRUAction::remove( const QString& link ) -{ - if ( myLinks.remove( link ) ) - updateState(); -} - -/*! - Name: item [public] - Desc: Returns the link with specified index. -*/ - -QString QtxMRUAction::item( const int idx ) const -{ - QString res; - if ( idx >= 0 && idx < (int)myLinks.count() ) - res = myLinks[idx]; - return res; -} - -/*! - Name: find [public] - Desc: Find specified link. If link exists then returns index otherwise -1 returned. -*/ - -int QtxMRUAction::find( const QString& link ) const -{ - return myLinks.findIndex( link ); -} - -/*! - Name: contains [public] - Desc: Returns 'true' if given link exist. -*/ - -bool QtxMRUAction::contains( const QString& link ) const -{ - return myLinks.contains( link ); -} - -/*! - Name: addTo [public] - Desc: Add the MRU links to the end of specified popup according to the popup mode. -*/ - -bool QtxMRUAction::addTo( QWidget* wid ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - checkPopup( pm ); - - int mode = popupMode(); - - if ( ( mode == Items && myItems.contains( pm ) ) || - ( mode == SubMenu && myMenus.contains( pm ) ) ) - return false; - - bool exist = myItems.contains( pm ) || myMenus.contains( pm ); - - if ( mode == SubMenu && !QtxAction::addTo( wid ) ) - return false; - - if ( mode == Items ) - { - myItems.insert( pm, Item() ); - myItems[pm].pId = myItems[pm].nId -1; - connect( pm, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - } - else if ( mode == SubMenu ) - { - myMenus.insert( pm, new QPopupMenu( pm ) ); - setPopup( pm, pm->idAt( pm->count() - 1 ), myMenus[pm] ); - connect( myMenus[pm], SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - } - - if ( !exist ) - { - connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); - } - - return insertLinks( pm, mode ); -} - -/*! - Name: addTo [public] - Desc: Add the MRU links to the specified popup at given index according to the popup mode. -*/ - -bool QtxMRUAction::addTo( QWidget* wid, const int idx ) -{ - if ( !QtxAction::addTo( wid, idx ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - - removeLinks( pm, popupMode() ); - insertLinks( pm, popupMode(), idx ); - - return true; -} - -/*! - Name: removeFrom [public] - Desc: Removes all MRU links from specified popup. -*/ - -bool QtxMRUAction::removeFrom( QWidget* wid ) -{ - QtxAction::removeFrom( wid ); - - QPopupMenu* pm = (QPopupMenu*)wid; - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - if ( myItems.contains( pm ) ) - { - removeLinks( pm, Items ); - myItems.remove( pm ); - disconnect( pm, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - } - if ( myMenus.contains( pm ) ) - { - removeLinks( pm, SubMenu ); - delete myMenus[pm]; - myMenus.remove( pm ); - } - - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); - - return true; -} - -/*! - Name: loadLinks [public] - Desc: Load the MRU links from specified resource manager section. - If parameter 'clear' is 'true' then link list will be cleared first. -*/ - -void QtxMRUAction::loadLinks( QtxResourceMgr* resMgr, const QString& section, const bool clear ) -{ - if ( !resMgr || section.isEmpty() ) - return; - - if ( clear ) - myLinks.clear(); - - QString itemPrefix( "item_" ); - - QMap map; - for ( QStringList::const_iterator itr = myLinks.begin(); itr != myLinks.end(); ++ itr ) - map.insert( *itr, 0 ); - - QStringList items = resMgr->parameters( section ); - for ( QStringList::const_iterator it = items.begin(); it != items.end(); ++it ) - { - if ( !(*it).startsWith( itemPrefix ) ) - continue; - - QString link = resMgr->stringValue( section, *it, QString::null ); - if ( link.isEmpty() || map.contains( link ) ) - continue; - - myLinks.append( link ); - map.insert( link, 0 ); - } - - updateState(); -} - -/*! - Name: saveLinks [public] - Desc: Save the MRU links into specified resource manager section. - If parameter 'clear' is 'true' then section will be cleared first. -*/ - -void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const -{ - if ( !resMgr || section.isEmpty() ) - return; - - if ( clear ) - resMgr->remove( section ); - - QStringList lst; - QMap map; - for ( QStringList::const_iterator itr = myLinks.begin(); itr != myLinks.end(); ++itr ) - map.insert( *lst.append( *itr ), 0 ); - - QString itemPrefix( "item_" ); - QStringList items = resMgr->parameters( section ); - for ( QStringList::const_iterator it = items.begin(); it != items.end(); ++it ) - { - if ( !(*it).startsWith( itemPrefix ) ) - continue; - - QString link = resMgr->stringValue( section, *it, QString::null ); - if ( !link.isEmpty() && !map.contains( link ) ) - map.insert( *lst.append( link ), 0 ); - - resMgr->remove( section, *it ); - } - - int counter = 0; - for ( QStringList::const_iterator iter = lst.begin(); iter != lst.end(); ++iter, counter++ ) - resMgr->setValue( section, itemPrefix + QString().sprintf( "%03d", counter ), *iter ); -} - -/*! - Name: setEnabled [public slot] - Desc: Enable or disable all popup items with MRU links. -*/ - -void QtxMRUAction::setEnabled( bool on ) -{ - QtxAction::setEnabled( on ); - - for ( ItemsMap::ConstIterator iter = myItems.begin(); iter != myItems.end(); ++iter ) - for ( QIntList::const_iterator it = iter.data().idList.begin(); it != iter.data().idList.end(); ++it ) - iter.key()->setItemEnabled( *it, on ); -} - -/*! - Name: onAboutToShow [private slots] - Desc: Enable or disable sub menu item according to number of MRU links - in sub popup when parent popup is shown. -*/ - -void QtxMRUAction::onAboutToShow() -{ - const QObject* obj = sender(); - if ( obj && obj->inherits( "QPopupMenu" ) ) - { - QPopupMenu* pm = (QPopupMenu*)obj; - if ( myMenus.contains( pm ) ) - pm->setItemEnabled( findId( pm, myMenus[pm]), isEnabled() && myMenus[pm] && myMenus[pm]->count() ); - } -} - -/*! - Name: onActivated [private slot] - Desc: Process popup item activation and emit signal activated with selected MRU link. -*/ - -void QtxMRUAction::onActivated( int id ) -{ - const QObject* obj = sender(); - if ( !obj->inherits( "QPopupMenu" ) ) - return; - - QPopupMenu* pm = (QPopupMenu*)obj; - - QString link; - if ( ( myItems.contains( pm ) && myItems[pm].idList.contains( id ) ) || - ( myMenus.contains( (QPopupMenu*)pm->parent() ) && myMenus[(QPopupMenu*)pm->parent()] == pm ) ) - link = pm->text( id ); - - if ( !link.isEmpty() ) - emit activated( link ); -} - -/*! - Name: onDestroyed [private slot] - Desc: Removes deleted popup menu from internal data structures. -*/ - -void QtxMRUAction::onDestroyed( QObject* obj ) -{ - if ( !obj ) - return; - - myItems.remove( (QPopupMenu*)obj ); - myMenus.remove( (QPopupMenu*)obj ); -} - -/*! - Name: updateState [private] - Desc: Updates the state of all popup menus which contains MRU link items. -*/ - -void QtxMRUAction::updateState() -{ - for ( ItemsMap::ConstIterator iIt = myItems.begin(); iIt != myItems.end(); ++iIt ) - updatePopup( iIt.key(), Items ); - - for ( MenusMap::ConstIterator mIt = myMenus.begin(); mIt != myMenus.end(); ++mIt ) - updatePopup( mIt.key(), SubMenu ); -} - -/*! - Name: checkPopup [private] - Desc: Check consistency the popup content and internal datas. - Synchronize internal data structures with popup content. -*/ - -void QtxMRUAction::checkPopup( QPopupMenu* pm ) -{ - if ( myItems.contains( pm ) ) - { - bool found = true; - for ( QIntList::const_iterator it = myItems[pm].idList.begin(); it != myItems[pm].idList.end() && found; ++it ) - found = pm->indexOf( *it ) != -1; - if ( !found ) - { - removeLinks( pm, Items ); - myItems.remove( pm ); - disconnect( pm, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - } - } - if ( myMenus.contains( pm ) ) - { - int id = findId( pm, myMenus[pm] ); - if ( id == -1 ) - { - delete myMenus[pm]; - myMenus.remove( pm ); - } - } - - if ( !myItems.contains( pm ) && !myMenus.contains( pm ) ) - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); -} - -/*! - Name: updatePopup [private] - Desc: Updates the MRU link items state in the specified popup menu. -*/ - -void QtxMRUAction::updatePopup( QPopupMenu* pm, const int mode ) -{ - if ( !pm ) - return; - - int idx = -1; - if ( mode == Items && myItems.contains( pm ) ) - { - if ( !myItems[pm].idList.isEmpty() ) - idx = pm->indexOf( myItems[pm].idList.first() ); - else - { - int pIdx = pm->indexOf( myItems[pm].pId ); - int nIdx = pm->indexOf( myItems[pm].nId ); - if ( pIdx != -1 ) - idx = pIdx + 1; - else if ( nIdx != -1 ) - idx = nIdx - 1; - } - } - - removeLinks( pm, mode ); - insertLinks( pm, mode, idx ); -} - -/*! - Name: removeLinks [private] - Desc: Removes MRU link items from specified popup. -*/ - -bool QtxMRUAction::removeLinks( QPopupMenu* pm, const int mode ) -{ - if ( !pm ) - return false; - - if ( mode == SubMenu && myMenus.contains( pm ) ) - myMenus[pm]->clear(); - else if ( mode == Items && myItems.contains( pm ) ) - { - for ( QIntList::const_iterator it = myItems[pm].idList.begin(); it != myItems[pm].idList.end(); ++it ) - pm->removeItem( *it ); - myItems[pm].idList.clear(); - } - - return true; -} - -/*! - Name: insertLinks [private] - Desc: Inserts MRU link items to the specified popup. -*/ - -bool QtxMRUAction::insertLinks( QPopupMenu* pm, const int mode, const int idx ) -{ - if ( !pm ) - return false; - - int count = visibleCount() < 0 ? myLinks.count() : visibleCount(); - bool isOn = isEnabled(); - if ( mode == SubMenu && myMenus.contains( pm ) ) - { - for ( QStringList::const_iterator it = myLinks.begin(); it != myLinks.end() && count > 0; ++it, count-- ) - { - int id = myMenus[pm]->insertItem( *it, -1 ); - myMenus[pm]->setItemEnabled( id, isOn ); - } - } - else if ( mode == Items ) - { - QIntList ids; - int index = idx; - for ( QStringList::const_iterator it = myLinks.begin(); it != myLinks.end() && count > 0; ++it, count-- ) - { - ids.append( pm->insertItem( *it, -1, index ) ); - pm->setItemEnabled( ids.last(), isOn ); - if ( index >= 0 ) - index++; - } - myItems[pm].idList = ids; - if ( !myItems[pm].idList.isEmpty() ) - { - myItems[pm].pId = pm->idAt( pm->indexOf( myItems[pm].idList.first() ) - 1 ); - myItems[pm].nId = pm->idAt( pm->indexOf( myItems[pm].idList.first() ) + 1 ); - } - } - return true; -} - -/*! - Name: findId [private] - Desc: Returns identificator of popup item which contains sub popup 'pm' in the popup 'cont'. -*/ - -int QtxMRUAction::findId( QPopupMenu* cont, QPopupMenu* pm ) const -{ - if ( !cont || !pm ) - return -1; - - int id = -1; - - for ( int i = 0; i < (int)cont->count() && id == -1; i++ ) - { - QMenuData* md = 0; - QMenuItem* item = cont->findItem( cont->idAt( i ), &md ); - if ( item && md == cont && item->popup() == pm ) - id = item->id(); - } - return id; -} diff --git a/src/Qtx/QtxMRUAction.h b/src/Qtx/QtxMRUAction.h deleted file mode 100755 index 6325860f8..000000000 --- a/src/Qtx/QtxMRUAction.h +++ /dev/null @@ -1,115 +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: QtxMRUAction.h -// Author: Sergey TELKOV - -#ifndef QTXMRUACTION_H -#define QTXMRUACTION_H - -#include "QtxAction.h" - -#include -#include - -class QPopupMenu; -class QtxResourceMgr; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxMRUAction : public QtxAction -{ - Q_OBJECT - - Q_PROPERTY( int visibleCount READ visibleCount WRITE setVisibleCount ) - -public: - enum { Items, SubMenu }; - enum { MoveFirst, MoveLast, AddFirst, AddLast }; - -public: - QtxMRUAction( QObject* = 0, const char* = 0 ); - QtxMRUAction( const QString&, const QString&, QObject*, const char* = 0 ); - QtxMRUAction( const QString&, const QIconSet&, const QString&, QObject*, const char* = 0 ); - virtual ~QtxMRUAction(); - - int insertMode() const; - void setInsertMode( const int ); - - int popupMode() const; - void setPopupMode( const int ); - - int count() const; - bool isEmpty() const; - - int visibleCount() const; - void setVisibleCount( const int ); - - void remove( const int ); - void remove( const QString& ); - void insert( const QString& ); - - QString item( const int ) const; - int find( const QString& ) const; - bool contains( const QString& ) const; - - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); - - virtual bool removeFrom( QWidget* ); - - virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true ); - virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const; - -signals: - void activated( QString ); - -public slots: - virtual void setEnabled( bool ); - -private slots: - void onAboutToShow(); - void onActivated( int ); - void onDestroyed( QObject* ); - -private: - void updateState(); - void checkPopup( QPopupMenu* ); - void updatePopup( QPopupMenu*, const int ); - bool removeLinks( QPopupMenu*, const int ); - bool insertLinks( QPopupMenu*, const int, const int = -1 ); - - int findId( QPopupMenu*, QPopupMenu* ) const; - -private: - typedef struct { int pId, nId; QIntList idList; } Item; - typedef QMap ItemsMap; - typedef QMap MenusMap; - -private: - QStringList myLinks; - ItemsMap myItems; - MenusMap myMenus; - int myVisCount; - int myPopupMode; - int myInsertMode; -}; - -#endif diff --git a/src/Qtx/QtxMainWindow.cxx b/src/Qtx/QtxMainWindow.cxx index 99f602bbb..9d3ce3092 100644 --- a/src/Qtx/QtxMainWindow.cxx +++ b/src/Qtx/QtxMainWindow.cxx @@ -24,10 +24,11 @@ #include "QtxToolBar.h" #include "QtxResourceMgr.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include /*! Class: QtxMainWindow::Filter [Internal] @@ -82,8 +83,8 @@ bool QtxMainWindow::Filter::eventFilter( QObject* o, QEvent* e ) Descr: Main window with support of dockable menubar/status bar and geometry store/retrieve. */ -QtxMainWindow::QtxMainWindow( QWidget* parent, const char* name, WFlags f ) -: QMainWindow( parent, name, f ), +QtxMainWindow::QtxMainWindow( QWidget* parent, Qt::WindowFlags f ) +: QMainWindow( parent ), myMode( -1 ), myMenuBar( NULL ), myStatusBar( NULL ) @@ -122,26 +123,22 @@ void QtxMainWindow::setDockableMenuBar( const bool on ) if ( on && !myMenuBar ) { - mb->setCaption( tr( "Menu bar" ) ); - QtxToolBar* dockMb = new QtxToolBar( true, this, "menu bar container" ); + mb->setWindowTitle( tr( "Menu bar" ) ); + QtxToolBar* dockMb = new QtxToolBar( true, this ); + dockMb->setObjectName( "menu_bar_container" ); myMenuBar = dockMb; new Filter( mb, this, myMenuBar ); - dockMb->setWidget( mb ); - dockMb->setNewLine( true ); - dockMb->setStretchable( true ); - dockMb->setResizeEnabled( false ); + dockMb->addWidget( mb ); + dockMb->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea ); + addToolBar( Qt::TopToolBarArea, dockMb ); - moveDockWindow( dockMb, DockTop ); - setDockEnabled( dockMb, Left, false ); - setDockEnabled( dockMb, Right, false ); - - setAppropriate( dockMb, false ); +// setAppropriate( dockMb, false ); connect( dockMb, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); } else if ( !on && myMenuBar ) { - mb->reparent( this, QPoint( 0, 0 ), mb->isVisibleTo( mb->parentWidget() ) ); + mb->setParent( this ); disconnect( myMenuBar, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); delete myMenuBar; myMenuBar = 0; @@ -175,29 +172,25 @@ void QtxMainWindow::setDockableStatusBar( const bool on ) if ( on && !myStatusBar ) { - sb->setCaption( tr( "Status bar" ) ); - QtxToolBar* dockSb = new QtxToolBar( true, this, "status bar container" ); + sb->setWindowTitle( tr( "Status bar" ) ); + QtxToolBar* dockSb = new QtxToolBar( true, this ); + dockSb->setObjectName( "status_bar_container" ); myStatusBar = dockSb; new Filter( sb, this, myStatusBar ); - dockSb->setWidget( sb ); - dockSb->setNewLine( true ); - dockSb->setStretchable( true ); - dockSb->setResizeEnabled( false ); sb->setMinimumWidth( 250 ); - sb->setSizeGripEnabled( false ); - moveDockWindow( dockSb, DockBottom ); - setDockEnabled( dockSb, Left, false ); - setDockEnabled( dockSb, Right, false ); + dockSb->addWidget( sb ); + dockSb->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea ); + addToolBar( Qt::BottomToolBarArea, dockSb ); - setAppropriate( dockSb, false ); +// setAppropriate( dockSb, false ); connect( dockSb, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); } else if ( !on && myStatusBar ) { - sb->reparent( this, QPoint( 0, 0 ), sb->isVisibleTo( sb->parentWidget() ) ); + sb->setParent( this ); disconnect( myStatusBar, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); delete myStatusBar; myStatusBar = 0; @@ -217,7 +210,7 @@ void QtxMainWindow::setDockableStatusBar( const bool on ) */ void QtxMainWindow::loadGeometry( QtxResourceMgr* resMgr, const QString& section ) { - QString sec = section.stripWhiteSpace(); + QString sec = section.trimmed(); if ( !resMgr || sec.isEmpty() ) return; @@ -255,11 +248,12 @@ void QtxMainWindow::loadGeometry( QtxResourceMgr* resMgr, const QString& section move( win_x, win_y ); myMode = -1; - +/* if ( vis ) - QApplication::postEvent( this, new QCustomEvent( QEvent::User, (void*)winState ) ); + QApplication::postEvent( this, new QEvent( QEvent::User, (void*)winState ) ); else myMode = winState; +*/ } /*! @@ -267,9 +261,10 @@ void QtxMainWindow::loadGeometry( QtxResourceMgr* resMgr, const QString& section */ void QtxMainWindow::show() { +/* if ( myMode != -1 ) QApplication::postEvent( this, new QCustomEvent( QEvent::User, (void*)myMode ) ); - +*/ myMode = -1; QMainWindow::show(); @@ -278,11 +273,12 @@ void QtxMainWindow::show() /*! Handler of custom events */ -void QtxMainWindow::customEvent( QCustomEvent* e ) +void QtxMainWindow::customEvent( QEvent* e ) { QMainWindow::customEvent( e ); - size_t mode = size_t(e->data()); + int mode = WS_Normal; +// int mode = (int)e->data(); switch ( mode ) { case WS_Normal: @@ -328,7 +324,7 @@ int QtxMainWindow::relativeCoordinate( const int type, const int WH, const int w */ void QtxMainWindow::saveGeometry( QtxResourceMgr* resMgr, const QString& section ) const { - QString sec = section.stripWhiteSpace(); + QString sec = section.trimmed(); if ( !resMgr || sec.isEmpty() ) return; @@ -362,7 +358,7 @@ bool QtxMainWindow::eventFilter( QObject* o, QEvent* e ) */ void QtxMainWindow::setAppropriate( QDockWindow* dw, bool a ) { - QMainWindow::setAppropriate( dw, myStatusBar != dw && myMenuBar != dw && a ); +// QMainWindow::setAppropriate( dw, myStatusBar != dw && myMenuBar != dw && a ); } /*! @@ -370,7 +366,7 @@ void QtxMainWindow::setAppropriate( QDockWindow* dw, bool a ) */ void QtxMainWindow::setUpLayout() { - QMainWindow::setUpLayout(); +// QMainWindow::setUpLayout(); if ( myMenuBar && layout() ) layout()->setMenuBar( 0 ); @@ -423,7 +419,7 @@ int QtxMainWindow::windowState( const QString& str ) const } int res = -1; - QString stateStr = str.stripWhiteSpace().lower(); + QString stateStr = str.trimmed().toLower(); if ( winStateMap.contains( stateStr ) ) res = winStateMap[stateStr]; return res; @@ -446,7 +442,7 @@ int QtxMainWindow::windowPosition( const QString& str ) const } int res = WP_Absolute; - QString posStr = str.stripWhiteSpace().lower(); + QString posStr = str.trimmed().toLower(); if ( winPosMap.contains( posStr ) ) res = winPosMap[posStr]; return res; diff --git a/src/Qtx/QtxMainWindow.h b/src/Qtx/QtxMainWindow.h index ee779aefd..795f1fc4d 100644 --- a/src/Qtx/QtxMainWindow.h +++ b/src/Qtx/QtxMainWindow.h @@ -24,7 +24,7 @@ #include "Qtx.h" -#include +#include class QDockWindow; class QtxResourceMgr; @@ -39,7 +39,7 @@ class QTX_EXPORT QtxMainWindow : public QMainWindow enum { WP_Absolute, WP_Center, WP_Left, WP_Right, WP_Top = WP_Left, WP_Bottom = WP_Right }; public: - QtxMainWindow( QWidget* = 0, const char* = 0, WFlags = WType_TopLevel ); + QtxMainWindow( QWidget* = 0, Qt::WindowFlags = 0 ); virtual ~QtxMainWindow(); bool isDockableMenuBar() const; @@ -59,7 +59,7 @@ public slots: protected: virtual void setUpLayout(); - virtual void customEvent( QCustomEvent* ); + virtual void customEvent( QEvent* ); private slots: void onDestroyed( QObject* ); @@ -71,8 +71,8 @@ private: private: int myMode; - QDockWindow* myMenuBar; - QDockWindow* myStatusBar; + QToolBar* myMenuBar; + QToolBar* myStatusBar; }; #endif diff --git a/src/Qtx/QtxMenuButton.cxx b/src/Qtx/QtxMenuButton.cxx deleted file mode 100755 index dc8abdde7..000000000 --- a/src/Qtx/QtxMenuButton.cxx +++ /dev/null @@ -1,429 +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: QtxMenuButton.cxx -// Author: Sergey TELKOV - -#include "QtxMenuButton.h" - -#include -#include -#include -#include -#include - -class QtxMenuButton::PopupMenu : public QPopupMenu -{ -public: - PopupMenu( QtxMenuButton* mb ) : QPopupMenu( mb ), myMenuButton( mb ) {}; - virtual ~PopupMenu() {}; - - virtual void setMinimumSize( int, int ); - -private: - QtxMenuButton* myMenuButton; -}; - -/*! - Sets the widget's minimum size - \param w - width - \param h - height -*/ -void QtxMenuButton::PopupMenu::setMinimumSize( int w, int h ) -{ - if ( myMenuButton->isAlignWidth() && - ( myMenuButton->position() == Top || myMenuButton->position() == Bottom ) ) - w = QMAX( w, myMenuButton->width() ); - - QPopupMenu::setMinimumSize( w, h ); -} - - -/*! - Constructor - \param pos - position - \param parent - parent widget - \param name - name -*/ -QtxMenuButton::QtxMenuButton( int pos, QWidget* parent, const char* name ) -: QPushButton( parent, name ), -myPos( pos ) -{ - initialize(); -} - -/*! - Constructor - \param text - button text - \param parent - parent widget - \param name - name -*/ -QtxMenuButton::QtxMenuButton( const QString& text, QWidget* parent, const char* name ) -: QPushButton( parent, name ), -myPos( Bottom ) -{ - setText( text ); - initialize(); -} - -/*! - Constructor - \param pos - position - \param text - button text - \param parent - parent widget - \param name - name -*/ -QtxMenuButton::QtxMenuButton( int pos, const QString& text, QWidget* parent, const char* name ) -: QPushButton( parent, name ), -myPos( pos ) -{ - setText( text ); - initialize(); -} - -/*! - Constructor - \param parent - parent widget - \param name - name -*/ -QtxMenuButton::QtxMenuButton( QWidget* parent, const char* name ) -: QPushButton( parent, name ), -myPos( Bottom ) -{ - initialize(); -} - -/*! - Destructor -*/ -QtxMenuButton::~QtxMenuButton() -{ -} - -/*! - Initialization -*/ -void QtxMenuButton::initialize() -{ - myArrow = true; - myAlign = true; - - setAutoDefault( false ); - myPopup = new PopupMenu( this ); - myPopup->hide(); - - connect( myPopup, SIGNAL( activated( int ) ), this, SIGNAL( activated( int ) ) ); - connect( this, SIGNAL( clicked() ), this, SLOT( onShowPopup() ) ); -} - -/*! - \return position -*/ -int QtxMenuButton::position() const -{ - return myPos; -} - -/*! - \return true if align is enabled -*/ -bool QtxMenuButton::isAlignWidth() const -{ - return myAlign; -} - -/*! - \return true if arrow is shown -*/ -bool QtxMenuButton::isArrowEnabled() const -{ - return myArrow; -} - -/*! - Changes position - \param pos - new position -*/ -void QtxMenuButton::setPosition( const int pos ) -{ - if ( myPos == pos ) - return; - - myPos = pos; - if ( myPopup->isVisible() ) - onShowPopup(); -} - -/*! - Changes align state - \param on - new align state -*/ -void QtxMenuButton::setAlignWidth( const bool on ) -{ - if ( myAlign == on ) - return; - - myAlign = on; - updateGeometry(); -} - -/*! - Enables/disable arrow - \param on - new enabled state -*/ -void QtxMenuButton::setArrowEnabled( const bool on ) -{ - if ( myArrow == on ) - return; - - myArrow = on; - repaint(); -} - -/*! - Clears popup -*/ -void QtxMenuButton::clear() -{ - if ( myPopup ) - myPopup->clear(); - onShowPopup(); - updateGeometry(); -} - -/*! - Removes item from popup - \param id - item id -*/ -void QtxMenuButton::removeItem( int id ) -{ - if ( myPopup ) - myPopup->removeItem( id ); - updateGeometry(); -} - -/*! - Inserts separator into popup - \param id - position -*/ -int QtxMenuButton::insertSeparator( int id ) -{ - int res = -1; - if ( myPopup ) - res = myPopup->insertSeparator( id ); - return res; -} - -/*! - Inserts item into popup - \param t - menu text - \param id - item id - \param index - position -*/ -int QtxMenuButton::insertItem( const QString& t, int id, int index ) -{ - int resId = -1; - if ( myPopup ) - resId = myPopup->insertItem( t, id, index ); - - if ( resId != -1 ) - updateGeometry(); - - return resId; -} - -/*! - Inserts item into popup - \param is - icons - \param t - menu text - \param id - item id - \param index - position -*/ -int QtxMenuButton::insertItem( const QIconSet& is, const QString& t, int id, int index ) -{ - int resId = -1; - if ( myPopup ) - resId = myPopup->insertItem( is, t, id, index ); - - if ( resId != -1 ) - updateGeometry(); - - return resId; -} - -/*! - SLOT: calls when button is clicked, shows popup -*/ -void QtxMenuButton::onShowPopup() -{ - if ( !myPopup || !myPopup->count() ) - { - myPopup->hide(); - return; - } - - QPoint p = mapToGlobal( QPoint( 0, 0 ) ); - int x = p.x(); - int y = p.y() + 1; - int margin = 0; - int xoffset = 0; - int yoffset = 0; - switch ( position() ) - { - case Left: - xoffset = -1 * ( myPopup->sizeHint().width() + margin ); - break; - case Right: - xoffset = width() + margin; - break; - case Top: - yoffset = -1 * ( myPopup->sizeHint().height() + margin ); - break; - case Bottom: - default: - yoffset = height() + margin; - break; - } - int dw = QApplication::desktop()->width(); - int dh = QApplication::desktop()->height(); - x = QMIN( QMAX( x + xoffset, 0 ), dw ); - y = QMIN( QMAX( y + yoffset, 0 ), dh ); - - myPopup->exec( QPoint( x, y ) ); -} - -/*! - Custom event handler -*/ -bool QtxMenuButton::event( QEvent* e ) -{ - if ( e->type() == QEvent::MouseButtonPress || - e->type() == QEvent::MouseButtonDblClick || - e->type() == QEvent::MouseButtonRelease ) - { - onShowPopup(); - return false; - } - - return QPushButton::event( e ); -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxMenuButton::sizeHint() const -{ - QSize sz = QPushButton::sizeHint(); - if ( ( position() == Top || position() == Bottom ) && myPopup && myAlign ) - sz = QSize( QMAX( sz.width(), myPopup->sizeHint().width() ), sz.height() ); - - return sz; -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxMenuButton::minimumSizeHint() const -{ - QSize sz = QPushButton::minimumSizeHint(); - if ( ( position() == Top || position() == Bottom ) && myPopup && myAlign ) - sz = QSize( QMAX( sz.width(), myPopup->sizeHint().width() ), sz.height() ); - - return sz; -} - -/*! - Custom resize event handler -*/ -void QtxMenuButton::resizeEvent( QResizeEvent* re ) -{ - if ( re ) - QPushButton::resizeEvent( re ); - - if ( ( position() == Top || position() == Bottom ) && myPopup && myAlign ) - myPopup->setMinimumWidth( re ? re->size().width() : width() ); -} - -/*! - \return corresponding popup -*/ -QPopupMenu* QtxMenuButton::popup() const -{ - return myPopup; -} - -/*! - Draws label -*/ -void QtxMenuButton::drawButtonLabel( QPainter* p ) -{ - QPushButton::drawButtonLabel( p ); -/* - QStyle::SFlags flags = QStyle::Style_Default; - if ( isEnabled() ) - flags |= QStyle::Style_Enabled; - if ( hasFocus() ) - flags |= QStyle::Style_HasFocus; -*/ -#if QT_VER < 3 - QRect r = rect(); -#else - QRect r = style().subRect( QStyle::SR_PushButtonContents, this ); -#endif - - if ( myArrow && myPopup && myPopup->count() ) - { - int w = 7; - int h = 7; - int margin = 5; - - QRect ar( 0, 0, w, h ); - if ( position() == Left || position() == Top ) - r.moveBy( ar.width() + 2 * margin, 0 ); - else - ar.moveBy( r.width() - ar.width() - 2 * margin, 0 ); - - r.setWidth( r.width() - ar.width() - 2 * margin ); - - ar.moveBy( margin, ( height() - h ) / 2 ); - - QPointArray arrow( 3 ); - switch ( position() ) - { - case Left: - arrow.putPoints( 0, 3, ar.left(), ar.top() + ar.height() / 2, ar.right(), ar.top(), ar.right(), ar.bottom() ); - break; - case Right: - arrow.putPoints( 0, 3, ar.left(), ar.top(), ar.left(), ar.bottom(), ar.right(), ar.top() + ar.height() / 2 ); - break; - case Top: - arrow.putPoints( 0, 3, ar.left(), ar.bottom(), ar.right(), ar.bottom(), ar.left() + ar.width() / 2, ar.top() ); - break; - case Bottom: - default: - arrow.putPoints( 0, 3, ar.left(), ar.top(), ar.right(), ar.top(), ar.left() + ar.width() / 2, ar.bottom() ); - break; - } - - p->setPen( colorGroup().text() ); - p->setBrush( colorGroup().text() ); - p->drawPolygon( arrow, true ); - } - -// style().drawControl( QStyle::CE_PushButtonLabel, p, this, r, colorGroup(), flags ); -} diff --git a/src/Qtx/QtxMenuButton.h b/src/Qtx/QtxMenuButton.h deleted file mode 100755 index b0f674196..000000000 --- a/src/Qtx/QtxMenuButton.h +++ /dev/null @@ -1,88 +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: QtxMenuButton.h -// Author: Sergey TELKOV - -#ifndef QTXMENUBUTTON_H -#define QTXMENUBUTTON_H - -#include "Qtx.h" - -#include - -class QIconSet; -class QPopupMenu; - -class QTX_EXPORT QtxMenuButton : public QPushButton -{ - Q_OBJECT - - class PopupMenu; - -public: - enum { Left, Right, Top, Bottom }; - -public: - QtxMenuButton( int, QWidget* = 0, const char* = 0 ); - QtxMenuButton( const QString&, QWidget* = 0, const char* = 0 ); - QtxMenuButton( int, const QString&, QWidget* = 0, const char* = 0 ); - QtxMenuButton( QWidget* = 0, const char* = 0 ); - virtual ~QtxMenuButton(); - - int position() const; - void setPosition( const int ); - - bool isAlignWidth() const; - void setAlignWidth( const bool ); - - bool isArrowEnabled() const; - void setArrowEnabled( const bool ); - - void clear(); - void removeItem( int ); - int insertSeparator( int = -1 ); - int insertItem( const QString&, int = -1, int = -1 ); - int insertItem( const QIconSet&, const QString&, int = -1, int = -1 ); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; - -signals: - void activated( int ); - -private slots: - void onShowPopup(); - -protected: - QPopupMenu* popup() const; - virtual bool event( QEvent* ); - virtual void resizeEvent( QResizeEvent* ); - virtual void drawButtonLabel( QPainter* ); - -private: - void initialize(); - -private: - int myPos; - bool myArrow; - bool myAlign; - QPopupMenu* myPopup; -}; - -#endif diff --git a/src/Qtx/QtxOperations.cxx b/src/Qtx/QtxOperations.cxx deleted file mode 100644 index ccf150007..000000000 --- a/src/Qtx/QtxOperations.cxx +++ /dev/null @@ -1,43 +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 "QtxOperations.h" - -/*! - Default constructor -*/ -QtxOperations::QtxOperations() -{ -} - -/*! - Destructor -*/ -QtxOperations::~QtxOperations() -{ -} - -/*! - Creates QtxValue by it's string representation -*/ -bool QtxOperations::createValue( const QString& str, QtxValue& v ) const -{ - v = str; - return false; -} diff --git a/src/Qtx/QtxOperations.h b/src/Qtx/QtxOperations.h deleted file mode 100644 index 642a3bf31..000000000 --- a/src/Qtx/QtxOperations.h +++ /dev/null @@ -1,61 +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: QtxOperations.h -// Author: Alexander SOLOVYOV - -#ifndef __QTX_OPERATIONS_HEADER__ -#define __QTX_OPERATIONS_HEADER__ - -#include "Qtx.h" -#include "QtxParser.h" - -class QTX_EXPORT QtxOperations -{ -public: - QtxOperations(); - virtual ~QtxOperations(); - - virtual void opersList( QStringList& ) const = 0; - //list of possible operations - - virtual void bracketsList( QStringList&, bool open ) const = 0; - //list of open/close brackets - - virtual bool createValue( const QString&, QtxValue& ) const; - //by default, the String value will be set, it corresponds to parameter - //base method returns false (always parameter) - //successor's method returns true if it has created custom value - //or call base if it hasn't - - virtual int prior( const QString&, bool isBin ) const = 0; - //returns prioritet of operation; - //if operation is impossible, it must return 0 or less - - virtual QtxParser::Error isValid( const QString&, - const QVariant::Type, - const QVariant::Type ) const = 0; - //return OK if this parameter types is valid for operation - //return OperandsNotMatch or InvalidOperation otherwise - - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const = 0; - //process binary operation with values - //for unary operation the second QtxValue will be passed as invalid -}; - -#endif diff --git a/src/Qtx/QtxParser.cxx b/src/Qtx/QtxParser.cxx deleted file mode 100644 index b4b32bb29..000000000 --- a/src/Qtx/QtxParser.cxx +++ /dev/null @@ -1,850 +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 "QtxParser.h" -#include "QtxOperations.h" - -/*! - Constructor -*/ -QtxParser::QtxParser( QtxOperations* operations, const QString& expr ) -: myOperations( operations ) -{ - if( myOperations ) - { - setLastError( OK ); - setExpr( expr ); - } - else - setLastError( OperationsNull ); -} - -/*! - Destructor -*/ -QtxParser::~QtxParser() -{ -} - -/*! - Search elements of list as substrings starting on 'offset' - \returns the least position of substrings inside string - \param list - list of substrings - \param str - string where search - \param offset - starting index for search - \param matchLen - the length of appropriate substring - \param listind - list index of appropriate substring -*/ -int QtxParser::search( const QStringList& list, const QString& str, int offset, - int& matchLen, int& listind ) -{ - QStringList::const_iterator anIt = list.begin(), aLast = list.end(); - int min = -1; - for( int ind = 0; anIt!=aLast; anIt++, ind++ ) - { - //const char* where = str.latin1(), *what = (*anIt).latin1(); - int pos = str.find( *anIt, offset ); - if( pos>=0 && ( min < 0 || min > pos || - ( min==pos && matchLen< (int)(*anIt).length() ) ) ) - { - min = pos; - listind = ind; - matchLen = (*anIt).length(); - } - } - if( min<0 ) - matchLen = 0; - return min; -} - -/*! - \return substring - \param str - string - \param pos - start position of substring - \param len - length of substring -*/ -QString QtxParser::note( const QString& str, int pos, int len ) -{ - return str.mid( pos, len ).stripWhiteSpace(); -} - -/*! - First step of parsing: finding tokens, determining its types and creating of unsorted pseudo-postfix (with brackets) - \param expr - string expression - \param post - postfix to be created -*/ -bool QtxParser::prepare( const QString& expr, Postfix& post ) -{ - int pos = 0, len = expr.length(); - QValueStack< int > aBracketStack; - QStringList anOpers, anOpenBr, aCloseBr; - if( myOperations ) - { - myOperations->bracketsList( anOpenBr, true ); - myOperations->bracketsList( aCloseBr, false ); - myOperations->opersList( anOpers ); - } - else - { - setLastError( OperationsNull ); - return false; - } - - while( pos < len && lastError()==OK ) - { - PostfixItem item; - while( expr[ pos ].isSpace() && pos=len ) - break; - - int mBrLen = 0, mLen = 0, br_ind = -1, op_ind = -1; - int oPos = search( anOpenBr, expr, pos, mBrLen, br_ind ), - cPos = oPos==pos ? -1 : search( aCloseBr, expr, pos, mBrLen, br_ind ), - opPos = search( anOpers, expr, pos, mLen, op_ind ); - - if( expr[ pos ]=="'" ) - { - int vpos = pos+1; - while ( vpos< (int)expr.length() && expr[ vpos ]!="'" ) - vpos++; - - mLen = vpos-pos+1; - - int res = myOperations->createValue( note( expr, pos, mLen ), item.myValue ); - item.myType = res ? Value : Param; - post.append( item ); - pos = vpos+1; - continue; - } - - if( oPos==pos ) - { - aBracketStack.push( br_ind ); - item.myValue = note( expr, pos, mBrLen ); - item.myType = Open; - post.append( item ); - } - - else if( cPos==pos ) - { - if( aBracketStack.count()==0 ) - { - setLastError( ExcessClose ); - break; - } - if( br_ind!=aBracketStack.top() ) - { - setLastError( BracketsNotMatch ); - break; - } - else - { - aBracketStack.pop(); - item.myValue = note( expr, pos, mBrLen ); - item.myType = Close; - post.append( item ); - } - } - else - mBrLen = 0; - - if( opPos==pos ) - { - mBrLen = 0; - item.myValue = note( expr, pos, mLen ); - item.myType = Binary; - //the type is set by default; - //the method setOperationTypes will set correct types - - if( oPos==pos ) - post.insert( post.at( post.count()-1 ), item ); - else - post.append( item ); - } - else - { - mLen = 0; - if( oPos!=pos && cPos!=pos ) - { - int i; - for( i=pos+1; i<(int)expr.length(); i++ ) - if( expr[ i ].isSpace() ) - break; - - int vpos = i; - if( oPos>=0 && oPos=0 && cPos=0 && opPoscreateValue( note( expr, pos, mLen ), item.myValue ); - item.myType = res ? Value : Param; - post.append( item ); - } - } - - pos+=mBrLen+mLen; - } - - //Bracket checking - PostfixIterator anIt = post.begin(), - aLast = post.end(); - int brValue = 0; - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).myType==Open ) - brValue++; - else if( (*anIt).myType==Close ) - if( brValue>0 ) - brValue--; - else - { - setLastError( ExcessClose ); - break; - } - if( brValue>0 ) - setLastError( CloseExpected ); - - return lastError()==OK; -} - -/*! - Second step of parsing: determining types of operations - \param post - unsorted postfix -*/ -bool QtxParser::setOperationTypes( Postfix& post ) -{ - Postfix::iterator aStart = post.begin(), - aLast = post.end(), - anIt = aStart, aPrev, aNext; - QStringList anOpen, aClose; - if( myOperations ) - { - myOperations->bracketsList( anOpen, true ); - myOperations->bracketsList( aClose, false ); - } - else - return false; - - for( ; anIt!=aLast; anIt++ ) - { - aPrev = anIt; aPrev--; - aNext = anIt; aNext++; - if( (*anIt).myType != Binary ) - continue; - - if( ( anIt==aStart || (*aPrev).myType == Open || - (*aPrev).myType == Pre || - (*aPrev).myType == Binary ) - && - aNext!=aLast && ( (*aNext).myType == Value || - (*aNext).myType == Param || - (*aNext).myType == Open || - (*aNext).myType == Binary ) ) - (*anIt).myType = Pre; - - else if( anIt!=aStart && ( (*aPrev).myType == Close || - (*aPrev).myType == Param || - (*aPrev).myType == Value || - (*aPrev).myType == Pre || - (*aPrev).myType == Post || - (*aPrev).myType == Binary ) - && - ( aNext==aLast || (*aNext).myType == Close ) ) - (*anIt).myType = Post; - - if( anOpen.contains( ( *anIt ).myValue.toString() )>0 ) - (*anIt).myType = Pre; - else if( aClose.contains( ( *anIt ).myValue.toString() )>0 ) - (*anIt).myType = Post; - } - - return lastError()==OK; -} - -/*! - \return how many global brackets there is (for example '((2+3))' has 2 global brackets) - \param post - postfix to be checked - \param f - start index to search - \param l - last index to search -*/ -int QtxParser::globalBrackets( const QtxParser::Postfix& post, int f, int l ) -{ - int i, - start_br = 0, - fin_br = 0, - br = 0, - br_num = 0, - min_br_num = (l-f+1)*5; - - for( i=f; i<=l; i++ ) - if( post[ i ].myType==QtxParser::Open ) - start_br++; - else - break; - for( i=l; i>=f; i-- ) - if( post[ i ].myType==QtxParser::Close ) - fin_br++; - else - break; - - br = start_br=0 ) - res.append( post[ f ] ); - if( l<=f ) - return true; - - if( myOperations ) - { - int min = -1; - QIntList argmin; - QValueList< PostfixItemType > min_types; - - //Find operation with minimal priority - //PostfixIterator anIt = post.at( f ), - // aLast = post.at( l+1 ); - for( int i=0, j=f; j<=l; i++, j++ ) - { - const PostfixItem& item = post[ j ]; - PostfixItemType tt = item.myType; - if( tt==Binary || tt==Pre || tt==Post ) - { - int cur_pr = myOperations->prior( item.myValue.toString(), tt==Binary ); - if( cur_pr>0 ) - { - if( min<0 || min>=cur_pr ) - { - if( min==cur_pr ) - { - argmin.append( f+i ); - min_types.append( tt ); - } - else - { - min = cur_pr; - argmin.clear(); argmin.append( f+i ); - min_types.clear(); min_types.append( tt ); - } - } - } - else - { - setLastError( InvalidOperation ); - break; - } - } - else if( tt==Open ) - { - QString opBr = item.myValue.toString(); - int ind = anOpen.findIndex( opBr ), brValue = 0; - while( j<=l ) - { - const PostfixItem& anItem = post[ j ]; - if( anItem.myType==Open ) - brValue++; - - if( anItem.myType==Close ) - { - brValue--; - QString clBr = anItem.myValue.toString(); - if( aClose.findIndex( clBr )==ind && brValue==0 ) - break; - } - i++; j++; - } - if( brValue>0 ) - { - setLastError( CloseExpected ); - break; - } - } - } - - if( lastError()==OK ) - if( min>=0 ) - { - QValueList< Postfix > parts; - QIntList::const_iterator anIt = argmin.begin(), - aLast = argmin.end(); - Postfix one; - bool ok = sort( post, one, anOpen, aClose, f, *anIt - 1 ); - parts.append( one ); - one.clear(); - for( ; anIt!=aLast && ok; anIt++ ) - { - QIntList::const_iterator aNext = anIt; aNext++; - ok = sort( post, one, anOpen, aClose, *anIt + 1, aNext==aLast ? l : *aNext - 1 ); - parts.append( one ); - one.clear(); - } - if( !ok ) - return false; - - QValueList< Postfix >::const_iterator aPIt = parts.begin(); - QValueList< PostfixItemType >::const_iterator aTIt = min_types.begin(); - QValueStack< PostfixItem > aStack; - res += (*aPIt); aPIt++; - anIt = argmin.begin(); - for( ; anIt!=aLast; anIt++, aPIt++, aTIt++ ) - { - if( *aTIt==Pre ) - if( anOpen.contains( post[ *anIt ].myValue.toString() )==0 ) - { - res+=(*aPIt); - aStack.push( post[ *anIt ] ); - } - else - { - res.append( post[ *anIt ] ); - res+=(*aPIt); - } - else - { - res+=(*aPIt); - while( !aStack.isEmpty() ) - { - res.append( aStack.top() ); - aStack.pop(); - } - res.append( post[ *anIt ] ); - } - } - while( !aStack.isEmpty() ) - { - res.append( aStack.top() ); - aStack.pop(); - } - } - else - { //there are no operations - PostfixIterator anIt = post.at( f ), - aLast = post.at( l+1 ); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).myType==Value || (*anIt).myType==Param ) - res.append( *anIt ); - } - } - else - setLastError( OperationsNull ); - - return lastError()==OK; -} - -/*! - Build posfix by expression - \param expr - string expression -*/ -bool QtxParser::parse( const QString& expr ) -{ - myPost.clear(); - - Postfix p; - QStringList opens, closes; - - if( myOperations ) - { - setLastError( OK ); - myOperations->bracketsList( opens, true ); - myOperations->bracketsList( closes, false ); - } - else - { - setLastError( OperationsNull ); - return false; - } - - //return prepare( expr, myPost ) && setOperationTypes( myPost ); - return prepare( expr, p ) && setOperationTypes( p ) && - sort( p, myPost, opens, closes ); -} - -/*! - Calculate operation - \param op - operation name - \param v1 - first argument (it is not valid for unary prefix operations and it is used to store result) - \param v2 - second argument (it is not valid for unary postfix operations) -*/ -bool QtxParser::calculate( const QString& op, QtxValue& v1, QtxValue& v2 ) -{ - Error err = myOperations->isValid( op, v1.type(), v2.type() ); - if( err==OK ) - setLastError( myOperations->calculate( op, v1, v2 ) ); - else - setLastError( err ); - - return lastError()==OK; -} - -/*! - Calculates expression without postfix rebuilding - \return QtxValue as result (it is invalid if there were errors during calculation) -*/ -QtxValue QtxParser::calculate() -{ - setLastError( OK ); - - QStringList anOpen, aClose; - if( myOperations ) - { - myOperations->bracketsList( anOpen, true ); - myOperations->bracketsList( aClose, false ); - } - else - { - setLastError( OperationsNull ); - return QtxValue(); - } - - QtxValueStack aStack; - PostfixIterator anIt = myPost.begin(), - aLast = myPost.end(); - for( ; anIt!=aLast && lastError()==OK; anIt++ ) - { - QString nn = (*anIt).myValue.toString(); - if( (*anIt).myType==Param ) - { - if( has( nn ) ) - { - QVariant& v = myParameters[ nn ]; - if( v.isValid() ) - aStack.push( v ); - else - setLastError( InvalidToken ); - } - else - setLastError( InvalidToken ); - } - - else if( (*anIt).myType==Value ) - aStack.push( (*anIt).myValue ); - - else if( (*anIt).myType==Pre || (*anIt).myType==Post ) - { - if( anOpen.contains( nn )>0 ) - { - QtxValue inv; - if( calculate( nn, inv, inv ) ) - aStack.push( QtxValue() ); - } - else if( aClose.contains( nn )>0 ) - { - QValueList< QtxValue > set; - while( true ) - { - if( aStack.count()==0 ) - { - setLastError( StackUnderflow ); - break; - } - if( aStack.top().isValid() ) - { - set.append( aStack.top() ); - aStack.pop(); - } - else - { - aStack.pop(); - break; - } - } - - QtxValue qSet = set, inv; - if( calculate( nn, qSet, inv ) ) - aStack.push( set ); - } - else if( aStack.count()>=1 ) - { - QtxValue inv; - QtxValue* v1 = &aStack.top(), *v2 = &inv; //"post-" case - if( (*anIt).myType==Pre ) - { - v2 = &aStack.top(); v1 = &inv; - } - - calculate( nn, *v1, *v2 ); - } - else - setLastError( StackUnderflow ); - } - - else if( (*anIt).myType==Binary ) - { - if( aStack.count()>=2 ) - { - QVariant v2 = aStack.top(); aStack.pop(); - calculate( nn, aStack.top(), v2 ); - } - else - setLastError( StackUnderflow ); - } - } - - QtxValue res; - if( lastError()==OK ) - { - int count = aStack.count(); - if( count==0 ) - setLastError( StackUnderflow ); - else if( count==1 ) - res = aStack.top(); - else - setLastError( ExcessData ); - } - return res; -} - -/*! - Change expression, rebuild postfix and calculate it - \return QtxValue as result (it is invalid if there were errors during calculation) -*/ -QtxValue QtxParser::calculate( const QString& expr ) -{ - setExpr( expr ); - return calculate(); -} - -/*! - Change expression and rebuild postfix -*/ -bool QtxParser::setExpr( const QString& expr ) -{ - return parse( expr ); -} - -/*! - \return true, if parser contain parameter - \param name - name of parameter -*/ -bool QtxParser::has( const QString& name ) const -{ - return myParameters.contains( name.stripWhiteSpace() ); -} - -/*! - Sets parameter value - \param name - name of parameter - \param value - value of parameter -*/ -void QtxParser::set( const QString& name, const QtxValue& value ) -{ - myParameters[ name.stripWhiteSpace() ] = value; -} - -/*! - Removes parameter - \param name - name of parameter -*/ -bool QtxParser::remove( const QString& name ) -{ - QString sname = name.stripWhiteSpace(); - bool res = has( sname ); - if( res ) - myParameters.remove( sname ); - return res; -} - -/*! - \return value of parameter (result is invalid if there is no such parameter) - \param name - name of parameter -*/ -QtxValue QtxParser::value( const QString& name ) const -{ - QString sname = name.stripWhiteSpace(); - if( has( sname ) ) - return myParameters[ sname ].toString(); - else - return QtxValue(); -} - -/*! - Searches first parameter with assigned invalid QtxValue - \return true if it is found - \param name - variable to return name of parameter -*/ -bool QtxParser::firstInvalid( QString& name ) const -{ - QMap< QString, QtxValue >::const_iterator anIt = myParameters.begin(), - aLast = myParameters.end(); - for( ; anIt!=aLast; anIt++ ) - if( !anIt.data().isValid() ) - { - name = anIt.key(); - return true; - } - return false; -} - -/*! - Removes all parameters with assigned invalid QtxValues -*/ -void QtxParser::removeInvalids() -{ - QStringList toDelete; - QMap< QString, QtxValue >::const_iterator anIt = myParameters.begin(), - aLast = myParameters.end(); - for( ; anIt!=aLast; anIt++ ) - if( !anIt.data().isValid() ) - toDelete.append( anIt.key() ); - - QStringList::const_iterator aLIt = toDelete.begin(), - aLLast = toDelete.end(); - for( ; aLIt!=aLLast; aLIt++ ) - myParameters.remove( *aLIt ); -} - -/*! - \return last error occured during parsing -*/ -QtxParser::Error QtxParser::lastError() const -{ - return myLastError; -} - -/*! - Sets last error occured during parsing (for internal using only) -*/ -void QtxParser::setLastError( QtxParser::Error err ) -{ - myLastError = err; -} - -/*! - \return string dump of internal parser postfix -*/ -QString QtxParser::dump() const -{ - return dump( myPost ); -} - -/*! - \return string dump of postfix - \param post - postfix to be dumped -*/ -QString QtxParser::dump( const Postfix& post ) const -{ - QString res; - - if( myOperations ) - { - PostfixIterator anIt = post.begin(), - aLast = post.end(); - for( ; anIt!=aLast; anIt++ ) - { - if( (*anIt).myType == Value && - ( ( *anIt ).myValue.type()==QVariant::String || - ( *anIt ).myValue.type()==QVariant::CString ) ) - res += "'" + ( *anIt ).myValue.toString() + "'"; - else - res += ( *anIt ).myValue.toString(); - if( (*anIt).myType == Pre ) - res += "(pre)"; - else if( (*anIt).myType == Post ) - res += "(post)"; - else if( (*anIt).myType == Binary ) - res += "(bin)"; - - res += "_"; - } - } - return res; -} - -/*! - Fills list with names of parameters - \param list - list to be filled -*/ -void QtxParser::paramsList( QStringList& list ) -{ - PostfixIterator anIt = myPost.begin(), - aLast = myPost.end(); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt).myType==Param ) - { - QString name = (*anIt).myValue.toString(); - if( list.contains( name )==0 ) - list.append( name ); - } -} - -/*! - Removes all parameters -*/ -void QtxParser::clear() -{ - myParameters.clear(); -} - -/*! - \return string representation for list of QtxValues - \param list - list to be converted -*/ -QString QtxParser::toString( const QValueList< QtxValue >& list ) -{ - QValueList< QtxValue >::const_iterator anIt = list.begin(), - aLast = list.end(); - QString res = "set : [ "; - for( ; anIt!=aLast; anIt++ ) - res+=(*anIt).toString()+" "; - res+="]"; - return res; -} diff --git a/src/Qtx/QtxParser.h b/src/Qtx/QtxParser.h deleted file mode 100644 index 0a0b05a16..000000000 --- a/src/Qtx/QtxParser.h +++ /dev/null @@ -1,159 +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: QtxParser.h -// Author: Alexander SOLOVYOV - -#ifndef __QTX_PARSER_HEADER__ -#define __QTX_PARSER_HEADER__ - -#include "Qtx.h" -#include -#include - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - - -class QtxOperations; - -/*! \var QtxValue - \brief Alias for QVariant -*/ -typedef QVariant QtxValue; - - -/*! - \class QtxParser - - This class allows to calculate values of expressions using different set of operations. - It is provided some of standard set of operations (arithmetics, logic, strings, etc - in QtxStdOperations.h). - This parser allows to use parameters with help of methods has(), set(), remove(), value(). It uses - postfix representation of expressions and uses class QtxOperations in order to make certain operation - Every instance of parser contains only one postfix, so that if expression has been changed, then postfix - must be rebuilt. In order to increase performance of frequent calculation for many of expressions it is - recommended to use different instances of parser for expressions - -*/ -class QTX_EXPORT QtxParser -{ -public: - /*! - \enum Error - \brief Errors during parsing - */ - typedef enum - { - OK, /*! \var All right */ - OperandsNotMatch, /*! \var Types of arguments are invalid for this operation */ - InvalidResult, /*! \var Operation cannot find result (for example, division by zero) */ - InvalidOperation, /*! \var Name of operation is unknown */ - OperationsNull, /*! \var Internal operations pointer of parser is null */ - InvalidToken, /*! \var It isn't operation, parameter of value */ - CloseExpected, /*! \var Close bracket is expected */ - ExcessClose, /*! \var The one of close bracket is excess */ - BracketsNotMatch, /*! \var Last open and this close bracket are different, for example [) */ - StackUnderflow, /*! \var There is no arguments in stack for operation */ - ExcessData /*! \var The parsing is finished, but there is more then one value in stack */ - - } Error; - -public: - QtxParser( QtxOperations*, const QString& = QString::null ); - virtual ~QtxParser(); - - QtxValue calculate(); - QtxValue calculate( const QString& ); - bool setExpr( const QString& ); - - virtual void clear(); - virtual bool has ( const QString& name ) const; - virtual void set ( const QString& name, const QtxValue& value ); - virtual bool remove( const QString& name ); - virtual QtxValue value ( const QString& name ) const; - - bool firstInvalid( QString& ) const; - void removeInvalids(); - QString dump() const; - Error lastError() const; - void paramsList( QStringList& ); - - static QString toString( const QValueList< QtxValue >& ); - -protected: - /*! - \enum PostfixItemType - \brief Types of postfix representation elements - */ - typedef enum - { - Value, /*! \var Value (number, string, etc.)*/ - Param, /*! \var Parameter */ - Open, /*! \var Open bracket */ - Close, /*! \var Close bracket */ - Pre, /*! \var Unary prefix operation */ - Post, /*! \var Unary postfix operation */ - Binary /*! \var Binary operation */ - - } PostfixItemType; - - /*! \var postfix representation element */ - typedef struct - { - QtxValue myValue; - PostfixItemType myType; - - } PostfixItem; - - /*! \var postfix representation */ - typedef QValueList< PostfixItem > Postfix; - - /*! \var postfix representation iterator */ - typedef Postfix::const_iterator PostfixIterator; - -protected: - QString dump( const Postfix& ) const; - virtual bool prepare( const QString&, Postfix& ); - virtual bool setOperationTypes( Postfix& ); - virtual bool sort( const Postfix&, Postfix&, - const QStringList&, const QStringList&, - int f=-1, int l=-1 ); - - virtual bool parse( const QString& ); - virtual void setLastError( const Error ); - - bool calculate( const QString&, QtxValue&, QtxValue& ); - - static int search ( const QStringList&, const QString&, int offset, - int& matchLen, int& listind ); - static QString note ( const QString& str, int pos, int len ); - static int globalBrackets( const Postfix&, int, int ); - -private: - /*! \var stack of QtxValues */ - typedef QValueStack < QtxValue > QtxValueStack; - -private: - QtxOperations* myOperations; - QMap< QString, QtxValue > myParameters; - Error myLastError; - Postfix myPost; -}; - -#endif diff --git a/src/Qtx/QtxPathDialog.cxx b/src/Qtx/QtxPathDialog.cxx deleted file mode 100755 index fd098e7ef..000000000 --- a/src/Qtx/QtxPathDialog.cxx +++ /dev/null @@ -1,606 +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: QtxPathDialog.cxx -// Author: Sergey TELKOV - -#include "QtxPathDialog.h" - -#include "QtxGroupBox.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char* open_icon[] = { -"16 16 5 1", -" c none", -". c #ffff00", -"# c #848200", -"a c #ffffff", -"b c #000000", -" ", -" bbb ", -" b b b", -" bb", -" bbb bbb", -" ba.abbbbbbb ", -" b.a.a.a.a.b ", -" ba.a.a.a.ab ", -" b.a.abbbbbbbbbb", -" ba.ab#########b", -" b.ab#########b ", -" bab#########b ", -" bb#########b ", -" bbbbbbbbbbb ", -" ", -" " -}; - -/*! - Constructor. -*/ -QtxPathDialog::QtxPathDialog( const bool import, QWidget* parent, const bool modal, const bool resize, const int buttons, WFlags f ) -: QtxDialog( parent, 0, modal, resize, buttons, f ), -myDefault( -1 ), -myEntriesFrame( 0 ), -myOptionsFrame( 0 ) -{ - initialize(); - - setCaption( tr( import ? "Open file" : "Save file" ) ); - - setDefaultEntry( createFileEntry( tr( "File name" ), import ? OpenFile : SaveFile ) ); - QLineEdit* le = fileEntry( defaultEntry() ); - if ( le ) - le->setMinimumWidth( 200 ); - - validate(); - - setFocusProxy( le ); -} - -/*! - Constructor. -*/ -QtxPathDialog::QtxPathDialog( QWidget* parent, const bool modal, const bool resize, const int buttons, WFlags f ) -: QtxDialog( parent, 0, modal, resize, buttons, f ), -myDefault( -1 ), -myEntriesFrame( 0 ), -myOptionsFrame( 0 ) -{ - initialize(); -} - -/*! - Destructor. -*/ -QtxPathDialog::~QtxPathDialog() -{ -} - -/*! - \return file name -*/ -QString QtxPathDialog::fileName() const -{ - return fileName( defaultEntry() ); -} - -/*! - Sets file name - \param txt - new file name - \param autoExtension - auto extension determination by file -*/ -void QtxPathDialog::setFileName( const QString& txt, const bool autoExtension ) -{ - setFileName( defaultEntry(), txt, autoExtension ); -} - -/*! - \return filter -*/ -QString QtxPathDialog::filter() const -{ - return myFilter; -} - -/*! - Changes filter (filter is a list of masks, separated by ';;') - \param fltr - new filter -*/ -void QtxPathDialog::setFilter( const QString& fltr ) -{ - myFilter = fltr; -} - -/*! - Shows path dialog -*/ -void QtxPathDialog::show() -{ - if ( hasVisibleChildren( myEntriesFrame ) ) - myEntriesFrame->show(); - else - myEntriesFrame->hide(); - - if ( hasVisibleChildren( myOptionsFrame ) ) - myOptionsFrame->show(); - else - myOptionsFrame->hide(); - - QtxDialog::show(); -} - -/*! - SLOT: called if user click button to show standard file dialog -*/ -void QtxPathDialog::onBrowse() -{ - const QObject* obj = sender(); - - int id = -1; - - for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && id == -1; ++it ) - if ( it.data().btn == obj ) - id = it.key(); - - if ( id == -1 ) - return; - - FileEntry& entry = myEntries[id]; - - bool isDir = entry.mode != OpenFile && entry.mode != SaveFile; - - if ( !entry.dlg ) - { - entry.dlg = new QFileDialog( QDir::current().path(), QString::null, this, 0, true ); - entry.dlg->setCaption( caption() ); - switch ( entry.mode ) - { - case NewDir: - case OpenDir: - case SaveDir: - isDir = true; - entry.dlg->setMode( QFileDialog::DirectoryOnly ); - break; - case SaveFile: - entry.dlg->setMode( QFileDialog::AnyFile ); - break; - case OpenFile: - default: - entry.dlg->setMode( QFileDialog::ExistingFile ); - break; - } - } - - if ( !isDir ) - entry.dlg->setFilters( prepareFilters() ); - entry.dlg->setSelection( fileName( id ) ); - - if ( entry.dlg->exec() != Accepted ) - return; - - QString fName = entry.dlg->selectedFile(); - - if ( fName.isEmpty() ) - return; - - if ( QFileInfo( fName ).extension().isEmpty() && !isDir ) - fName = autoExtension( fName, entry.dlg->selectedFilter() ); - - fName = QDir::convertSeparators( fName ); - QString prev = QDir::convertSeparators( fileName( id ) ); - if ( isDir ) - { - while ( prev.length() && prev.at( prev.length() - 1 ) == QDir::separator() ) - prev.remove( prev.length() - 1, 1 ); - while ( fName.length() && fName.at( fName.length() - 1 ) == QDir::separator() ) - fName.remove( fName.length() - 1, 1 ); - } - - if ( prev == fName ) - return; - - setFileName( id, fName ); - fileNameChanged( id, fName ); - - if ( id == defaultEntry() ) - emit fileNameChanged( fName ); -} - -/*! - SLOT: called if user presses RETURN in line edit -*/ -void QtxPathDialog::onReturnPressed() -{ - const QObject* obj = sender(); - - int id = -1; - for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && id == -1; ++it ) - if ( it.data().edit == obj ) - id = it.key(); - - if ( id == -1 ) - return; - - fileNameChanged( id, fileName( id ) ); - - if ( id == defaultEntry() ) - emit fileNameChanged( fileName() ); -} - -/*! - SLOT: called if text in line edit is changed -*/ -void QtxPathDialog::onTextChanged( const QString& ) -{ - validate(); -} - -/*! - Checks validity of text and according to it enables/disables OK, Yes buttons -*/ -void QtxPathDialog::validate() -{ - setButtonEnabled( isValid(), OK | Yes ); -} - -/*! - \return true if selected file is valid -*/ -bool QtxPathDialog::isValid() -{ - bool ok = true; - for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && ok; ++it ) - if ( it.data().edit->isEnabled() ) - ok = !it.data().edit->text().stripWhiteSpace().isEmpty(); - - return ok; -} - -/*! - \return true entered data is accepted -*/ -bool QtxPathDialog::acceptData() const -{ - bool ok = true; - - QWidget* parent = (QWidget*)this; - - FileEntryMap::ConstIterator it; - for ( it = myEntries.begin(); it != myEntries.end() && ok; ++it ) - { - const FileEntry& entry = it.data(); - QFileInfo fileInfo( entry.edit->text() ); - if ( entry.edit->text().isEmpty() ) - { - QMessageBox::critical( parent, caption(), tr( "File name not specified" ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - else switch ( entry.mode ) - { - case OpenFile: - if ( !fileInfo.exists() ) - { - QMessageBox::critical( parent, caption(), tr( "File \"%1\" does not exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - break; - case SaveFile: - if ( fileInfo.exists() ) - ok = QMessageBox::warning( parent, caption(), tr( "File \"%1\" already exist. Do you want to overwrite it?" ).arg( fileInfo.filePath() ), - QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; - break; - case OpenDir: - if ( !fileInfo.exists() || !fileInfo.isDir() ) - { - QMessageBox::critical( parent, caption(), tr( "Directory \"%1\" does not exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - break; - case SaveDir: - if ( fileInfo.exists() && !fileInfo.isDir() ) - { - QMessageBox::critical( parent, caption(), tr( "Directory \"%1\" can't be created because file with the same name exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - break; - case NewDir: - if ( fileInfo.exists() ) - { - if ( !fileInfo.isDir() ) - { - QMessageBox::critical( parent, caption(), tr( "Directory \"%1\" can't be created because file with the same name exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - else if ( QDir( fileInfo.filePath() ).count() > 2 ) - ok = QMessageBox::warning( parent, caption(), tr( "Directory \"%1\" not empty. Do you want to remove all files in this directory?" ).arg( fileInfo.filePath() ), - QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; - } - break; - default: - break; - } - - if ( !ok ) - entry.edit->setFocus(); - } - - return ok; -} - -/*! - Some custom activity on file name changing (must be redefined, default implementation is empty -*/ -void QtxPathDialog::fileNameChanged( int, QString ) -{ -} - -/*! - \return frame with options -*/ -QFrame* QtxPathDialog::optionsFrame() -{ - return myOptionsFrame; -} - -/*! - \return file name - \param id - id of file entry -*/ -QString QtxPathDialog::fileName( const int id ) const -{ - QString res; - if ( myEntries.contains( id ) ) - res = myEntries[id].edit->text(); - - return res; -} - -/*! - Change file name of file entry - \param id - id of file entry - \param txt - new file name - \param autoExt - assign extension automatically -*/ -void QtxPathDialog::setFileName( const int id, const QString& txt, const bool autoExt ) -{ - int mode; - QLineEdit* le = fileEntry( id, mode ); - - if ( le ) - { - if ( autoExt && ( mode == OpenFile || mode == SaveFile ) ) - le->setText( autoExtension( txt ) ); - else - le->setText( txt ); - } -} - -/*! - \return line edit of file entry - \param id - id of file entry -*/ -QLineEdit* QtxPathDialog::fileEntry( const int id ) const -{ - QLineEdit* le = 0; - if ( myEntries.contains( id ) ) - le = myEntries[id].edit; - - return le; -} - -/*! - \return line edit and mode of file entry - \param id - id of file entry - \param theMode - for return mode of file entry -*/ -QLineEdit* QtxPathDialog::fileEntry( const int theId, int& theMode ) const -{ - QLineEdit* le = 0; - if ( myEntries.contains( theId ) ) - { - le = myEntries[theId].edit; - theMode = myEntries[theId].mode; - } - - return le; -} - -/*! - Creates file entry - \return id of just created file entry - \param lab - title of entry - \param mode - mode of entry - \param id - proposed id (if it is -1, then id will be chosen automatically) -*/ -int QtxPathDialog::createFileEntry( const QString& lab, const int mode, const int id ) -{ - int num = id; - if ( num == -1 ) - { - num--; - while ( myEntries.contains( num ) ) - num--; - } - - FileEntry entry; - entry.dlg = 0; - entry.mode = mode; - - new QLabel( lab, myEntriesFrame ); - entry.edit = new QLineEdit( myEntriesFrame ); - entry.btn = new QPushButton( myEntriesFrame ); - entry.btn->setAutoDefault( false ); - entry.btn->setPixmap( QPixmap( open_icon ) ); - - connect( entry.btn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); - connect( entry.edit, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ); - connect( entry.edit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); - - myEntries.insert( num, entry ); - - return num; -} - -/*! - \return id of default entry -*/ -int QtxPathDialog::defaultEntry() const -{ - return myDefault; -} - -/*! - Change default entry id - \param id - new default entry id -*/ -void QtxPathDialog::setDefaultEntry( const int id ) -{ - myDefault = id; -} - -/*! - Initialize dialog layout -*/ -void QtxPathDialog::initialize() -{ - setCaption( tr( "File dialog" ) ); - - QVBoxLayout* main = new QVBoxLayout( mainFrame() ); - QtxGroupBox* mainGroup = new QtxGroupBox( 1, Qt::Horizontal, "", mainFrame() ); - mainGroup->setFrameStyle( QFrame::NoFrame ); - mainGroup->setInsideMargin( 0 ); - main->addWidget( mainGroup ); - - myEntriesFrame = new QGroupBox( 3, Qt::Horizontal, "", mainGroup ); - myOptionsFrame = new QFrame( mainGroup ); -} - -/*! - \return list of filters -*/ -QStringList QtxPathDialog::prepareFilters() const -{ - QStringList res; - if ( !myFilter.isEmpty() ) - { - res = QStringList::split( ";;", myFilter ); - bool allFilter = false; - for ( QStringList::ConstIterator it = res.begin(); it != res.end() && !allFilter; ++it ) - { - QStringList wildCards = filterWildCards( *it ); - allFilter = wildCards.findIndex( "*.*" ) != -1; - } - - if ( !allFilter ) - res.append( tr( "All files (*.*)" ) ); - } - - return res; -} - -/*! - \return list of filters with filtered wild cards -*/ -QStringList QtxPathDialog::filterWildCards( const QString& theFilter ) const -{ - QStringList res; - - int b = theFilter.findRev( "(" ); - int e = theFilter.findRev( ")" ); - if ( b != -1 && e != -1 ) - { - QString content = theFilter.mid( b + 1, e - b - 1 ).stripWhiteSpace(); - QStringList lst = QStringList::split( " ", content ); - for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) - if ( (*it).find( "." ) != -1 ) - res.append( (*it).stripWhiteSpace() ); - } - return res; -} - -/*! - \return file name with assigned extension - \param theFileName - source file name - \param theFilter - list of filters -*/ -QString QtxPathDialog::autoExtension( const QString& theFileName, const QString& theFilter ) const -{ - QString fName = theFileName; - - if ( fName.isEmpty() ) - return fName; - - QString filter = theFilter; - if ( filter.isEmpty() ) - { - QStringList filters = prepareFilters(); - if ( !filters.isEmpty() ) - filter = filters.first(); - } - - QStringList wildCards = filterWildCards( filter ); - if ( !wildCards.isEmpty() ) - { - QString ext = wildCards.first(); - if ( ext.find( "." ) != -1 ) - ext = ext.mid( ext.find( "." ) + 1 ); - - if ( !ext.isEmpty() && !ext.contains( "*" ) ) - fName = QDir::convertSeparators( fName ) + QString( "." ) + ext; - } - - return fName; -} - -/*! - \return true if widget has visible children - \param wid - widget -*/ -bool QtxPathDialog::hasVisibleChildren( QWidget* wid ) const -{ - bool res = false; - if ( wid ) - { - const QObjectList* aChildren = wid->children(); - if ( aChildren ) - { - for ( QObjectListIt it( *aChildren ); it.current() && !res; ++it ) - { - if ( it.current()->isWidgetType() ) - res = ((QWidget*)it.current())->isVisibleTo( wid ); - } - } - } - return res; -} diff --git a/src/Qtx/QtxPathDialog.h b/src/Qtx/QtxPathDialog.h deleted file mode 100755 index a4db3a7fd..000000000 --- a/src/Qtx/QtxPathDialog.h +++ /dev/null @@ -1,111 +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: QtxPathDialog.h -// Author: Sergey TELKOV - -#ifndef QTXPATHDIALOG_H -#define QTXPATHDIALOG_H - -#include "QtxDialog.h" - -#include - -class QFrame; -class QLineEdit; -class QPushButton; -class QFileDialog; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxPathDialog : public QtxDialog -{ - Q_OBJECT - -protected: - QtxPathDialog( QWidget* = 0, const bool = true, const bool = false, const int = Standard, WFlags = 0 ); - -public: - QtxPathDialog( const bool, QWidget* = 0, const bool = true, const bool = false, const int = Standard, WFlags = 0 ); - virtual ~QtxPathDialog(); - - QString fileName() const; - void setFileName( const QString&, const bool = false ); - - QString filter() const; - void setFilter( const QString& ); - - virtual void show(); - -signals: - void fileNameChanged( QString ); - -protected slots: - void validate(); - -private slots: - void onBrowse(); - void onReturnPressed(); - void onTextChanged( const QString& ); - -protected: - virtual bool isValid(); - virtual bool acceptData() const; - virtual void fileNameChanged( int, QString ); - - QFrame* optionsFrame(); - QString fileName( const int ) const; - void setFileName( const int, const QString&, const bool = false ); - - QLineEdit* fileEntry( const int ) const; - QLineEdit* fileEntry( const int, int& ) const; - int createFileEntry( const QString&, const int, const int = -1 ); - - int defaultEntry() const; - void setDefaultEntry( const int ); - -private: - void initialize(); - QStringList prepareFilters() const; - bool hasVisibleChildren( QWidget* ) const; - QStringList filterWildCards( const QString& ) const; - QString autoExtension( const QString&, const QString& = QString::null ) const; - -protected: - enum { OpenFile, SaveFile, OpenDir, SaveDir, NewDir }; - -private: - typedef struct { int mode; QLineEdit* edit; - QPushButton* btn; QFileDialog* dlg; } FileEntry; - typedef QMap FileEntryMap; - -private: - QString myFilter; - FileEntryMap myEntries; - int myDefault; - QFrame* myEntriesFrame; - QFrame* myOptionsFrame; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxPopupMenu.cxx b/src/Qtx/QtxPopupMenu.cxx deleted file mode 100644 index 8a1a4e458..000000000 --- a/src/Qtx/QtxPopupMenu.cxx +++ /dev/null @@ -1,328 +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 "QtxPopupMenu.h" - -#include - -/*! - Class: QtxPopupMenu::TitleMenuItem [Internal] - Descr: Custom menu item for popup title. -*/ - -class QtxPopupMenu::TitleMenuItem : public QCustomMenuItem -{ -public: - TitleMenuItem( const QString&, const QIconSet&, const int ); - virtual ~TitleMenuItem(); - - virtual bool fullSpan() const; - virtual bool isSeparator() const; - virtual void setFont( const QFont& ); - - virtual void paint( QPainter*, const QColorGroup&, bool, bool, int, int, int, int ); - virtual QSize sizeHint(); - -private: - QString myText; - QIconSet myIcon; - QFont myFont; - int myAlign; -}; - -/*! - Constructor -*/ -QtxPopupMenu::TitleMenuItem::TitleMenuItem( const QString& txt, const QIconSet& ico, const int align ) -: QCustomMenuItem(), -myText( txt ), -myIcon( ico ), -myAlign( align ) -{ -} - -/*! - Destructor -*/ -QtxPopupMenu::TitleMenuItem::~TitleMenuItem() -{ -} - -/*! - \return TRUE if this item wants to span the entire popup menu width -*/ -bool QtxPopupMenu::TitleMenuItem::fullSpan() const -{ - return true; -} - -/*! - \return TRUE if this item is just a separator -*/ -bool QtxPopupMenu::TitleMenuItem::isSeparator() const -{ - return false; -} - -/*! - Changes font of item - \param font - new font -*/ -void QtxPopupMenu::TitleMenuItem::setFont( const QFont& font ) -{ - myFont = font; - myFont.setBold( true ); -} - -/*! - Draws item -*/ -void QtxPopupMenu::TitleMenuItem::paint( QPainter* p, const QColorGroup& cg, - bool act, bool enabled, int x, int y, int w, int h ) -{ - QFont f = p->font(); - p->setFont( myFont ); - - p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark ) ); - - p->setPen( cg.shadow() ); - p->drawRect( x, y, w, h ); - - int m = 3; - int s = 3; - int iw = p->fontMetrics().width( myText ) + ( myIcon.isNull() ? 0 : myIcon.pixmap().width() + s ); - int ih = QMAX( ( myIcon.isNull() ? 0 : myIcon.pixmap().height() ), p->fontMetrics().height() ); - - int ix = x; - int iy = y + m; - - if ( myAlign & AlignLeft ) - ix = x; - else if ( myAlign & AlignRight ) - ix = x + ( w - iw ); - else if ( myAlign & AlignHCenter ) - ix = x + ( w - iw ) / 2; - - if ( myAlign & AlignTop ) - iy = y; - else if ( myAlign & AlignBottom ) - iy = y + ( h - ih - m ); - else if ( myAlign & AlignVCenter ) - iy = y + ( h - ih ) / 2; - - if ( !myIcon.isNull() ) - { - p->drawPixmap( ix, iy + ( ih - myIcon.pixmap().height() ) / 2, myIcon.pixmap() ); - ix += myIcon.pixmap().width() + s; - } - - p->setPen( cg.brightText() ); - p->drawText( ix, iy + ( ih - p->fontMetrics().height() ) / 2 + - p->fontMetrics().ascent(), myText, 0, -1 ); - - p->setFont( f ); -} - -/*! - \return the recommended size for item -*/ -QSize QtxPopupMenu::TitleMenuItem::sizeHint() -{ - QFontMetrics fM( myFont ); - - int m = 3; - int s = 3; - int w = fM.width( myText ) + ( myIcon.isNull() ? 0 : myIcon.pixmap().width() + s ); - int h = QMAX( ( myIcon.isNull() ? 0 : myIcon.pixmap().height() ), fM.height() ) + 2 * m; - - return QSize( w, h ); -} - -/*! - Constructor -*/ -QtxPopupMenu::QtxPopupMenu( QWidget* parent, const char* name ) -: QPopupMenu( parent, name ), -myId( -1 ), -myPolicy( TitleAuto ), -myAlign( AlignCenter ) -{ -} - -/*! - Destructor -*/ -QtxPopupMenu::~QtxPopupMenu() -{ -} - -/*! - \return popup menu title -*/ -QString QtxPopupMenu::titleText() const -{ - return myText; -} - -/*! - \return popup menu icon -*/ -QIconSet QtxPopupMenu::titleIcon() const -{ - return myIcon; -} - -/*! - \return popup menu title policy -*/ -int QtxPopupMenu::titlePolicy() const -{ - return myPolicy; -} - -/*! - \return popup menu title alignment -*/ -int QtxPopupMenu::titleAlignment() const -{ - return myAlign; -} - -/*! - Changes title text - \param txt - new text -*/ -void QtxPopupMenu::setTitleText( const QString& txt ) -{ - if ( myText == txt ) - return; - - myText = txt; - - updateTitle(); -} - -/*! - Changes title icon - \param icon - new icon -*/ -void QtxPopupMenu::setTitleIcon( const QIconSet& ico ) -{ - myIcon = ico; - - updateTitle(); -} - -/*! - Changes title policy - \param p - new policy -*/ -void QtxPopupMenu::setTitlePolicy( const int p ) -{ - if ( myPolicy == p ) - return; - - myPolicy = p; - - updateTitle(); -} - -/*! - Changes title alignment - \param a - new alignment -*/ -void QtxPopupMenu::setTitleAlignment( const int a ) -{ - if ( myAlign == a ) - return; - - myAlign = a; - - updateTitle(); -} - -/*! - Shows menu -*/ -void QtxPopupMenu::show() -{ - insertTitle(); - - QPopupMenu::show(); -} - -/*! - Hides menu -*/ -void QtxPopupMenu::hide() -{ - QPopupMenu::hide(); - - removeTitle(); -} - -/*! - Creates title item - \param txt - item text - \param icon - item icon - \param align - item alignment -*/ -QtxPopupMenu::TitleMenuItem* QtxPopupMenu::createTitleItem( const QString& txt, const QIconSet& ico, - const int align ) const -{ - return new TitleMenuItem( txt, ico, align ); -} - -/*! - Inserts title item to popup menu -*/ -void QtxPopupMenu::insertTitle() -{ - if ( myId != -1 || titlePolicy() == TitleOff || - ( titlePolicy() == TitleAuto && titleText().stripWhiteSpace().isEmpty() ) ) - return; - - TitleMenuItem* item = createTitleItem( titleText(), titleIcon(), titleAlignment() ); - - myId = insertItem( item, -1, 0 ); - setItemEnabled( myId, false ); -} - -/*! - Removes title item from popup menu -*/ -void QtxPopupMenu::removeTitle() -{ - if ( myId == -1 ) - return; - - removeItem( myId ); - myId = -1; -} - -/*! - Updates title item -*/ -void QtxPopupMenu::updateTitle() -{ - if ( myId != -1 ) - { - removeTitle(); - insertTitle(); - } -} diff --git a/src/Qtx/QtxPopupMenu.h b/src/Qtx/QtxPopupMenu.h deleted file mode 100644 index 01dd27041..000000000 --- a/src/Qtx/QtxPopupMenu.h +++ /dev/null @@ -1,74 +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 QTXPOPUPMENU_H -#define QTXPOPUPMENU_H - -#include "Qtx.h" - -#include -#include -#include - -class QTX_EXPORT QtxPopupMenu : public QPopupMenu -{ - Q_OBJECT - -protected: - class TitleMenuItem; - -public: - enum { TitleAuto, TitleOn, TitleOff }; - -public: - QtxPopupMenu( QWidget* = 0, const char* = 0 ); - virtual ~QtxPopupMenu(); - - QString titleText() const; - QIconSet titleIcon() const; - - int titlePolicy() const; - int titleAlignment() const; - - virtual void setTitleText( const QString& ); - virtual void setTitleIcon( const QIconSet& ); - - virtual void setTitlePolicy( const int ); - virtual void setTitleAlignment( const int ); - -public slots: - virtual void show(); - virtual void hide(); - -protected: - virtual TitleMenuItem* createTitleItem( const QString&, const QIconSet&, const int ) const; - -private: - void updateTitle(); - void insertTitle(); - void removeTitle(); - -private: - int myId; - QString myText; - QIconSet myIcon; - int myAlign; - int myPolicy; -}; - -#endif diff --git a/src/Qtx/QtxPopupMgr.cxx b/src/Qtx/QtxPopupMgr.cxx deleted file mode 100644 index 5f0df3de8..000000000 --- a/src/Qtx/QtxPopupMgr.cxx +++ /dev/null @@ -1,759 +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 "QtxPopupMgr.h" -#include "QtxListOfOperations.h" -#include "QtxStdOperations.h" -#include "QtxAction.h" - -#include -#include - - -/*! - \return value of global parameter (depending on whole selection, but not dependending on one object of selection) - \param str - name of parameter - - By default, it returns count of selected objects ("selcount") and list of parameters ("$") -*/ -QtxValue QtxPopupMgr::Selection::globalParam( const QString& str ) const -{ - if( str==selCountParam() ) - return count(); - - else if( str[0]==equality() ) - { - QtxSets::ValueSet set; - QString par = str.mid( 1 ); - - for( int i=0, n=count(); i CacheMap; - - QtxPopupMgr::Selection* mySel; - CacheMap myParamCache; -}; - -/*! - Constructor - \param sel - base selection used for parameter calculation -*/ -QtxCacheSelection::QtxCacheSelection( QtxPopupMgr::Selection* sel ) -: mySel( sel ) -{ -} - -/*! - Destructor -*/ -QtxCacheSelection::~QtxCacheSelection() -{ -} - -/*! - \return count of selected objects -*/ -int QtxCacheSelection::count() const -{ - return mySel ? mySel->count() : 0; -} - -/*! - Calculates and caches parameters. - Already calculated parameters are returned without calculation - \return parameter value - \param i - index of selected object - \param name - name of parameter -*/ -QtxValue QtxCacheSelection::param( const int i, const QString& name ) const -{ - QString param_name = name + "#####" + QString::number( i ); - if( myParamCache.contains( param_name ) ) - return myParamCache[ param_name ]; - else - { - QtxValue v; - if( mySel ) - v = mySel->param( i, name ); - if( v.isValid() ) - ( ( CacheMap& )myParamCache ).insert( param_name, v ); - return v; - } -} - -/*! - Calculates and caches global parameters. - Already calculated parameters are returned without calculation - \return parameter value - \param name - name of parameter -*/ -QtxValue QtxCacheSelection::globalParam( const QString& name ) const -{ - if( myParamCache.contains( name ) ) - return myParamCache[ name ]; - else - { - QtxValue v; - if( mySel ) - v = mySel->globalParam( name ); - if( v.isValid() ) - ( ( CacheMap& )myParamCache ).insert( name, v ); - return v; - } -} - - - - -/*! - Constructor - \param mgr - popup manager -*/ -QtxPopupMgr::Operations::Operations( QtxPopupMgr* mgr ) -: QtxStrings(), - myPopupMgr( mgr ) -{ - QStringList aList; - aList.append( "every" ); - aList.append( "any" ); - aList.append( "onlyone" ); - addOperations( aList ); - - myParser = new QtxParser( mgr->myOperations ); -} - -/*! - Destructor - Deletes internal parser -*/ -QtxPopupMgr::Operations::~Operations() -{ - delete myParser; -} - -/*! - \return priority of popup operation 'op'. - \param isBin indicate whether the operation is binary -*/ -int QtxPopupMgr::Operations::prior( const QString& op, bool isBin ) const -{ - if( !isBin && ( op=="every" || op=="any" || op=="onlyone" ) ) - return 1; - else - return QtxStrings::prior( op, isBin ); - -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxPopupMgr::Operations::calculate - ( const QString& op, QtxValue& v1, QtxValue& v2 ) const -{ - int ind = -1; - if( op=="every" ) - ind = 0; - else if( op=="any" ) - ind = 1; - else if( op=="onlyone" ) - ind = 2; - - if( ind>=0 && ind<=2 ) - { - QString val_name = op + "(" + v2.toString() + ")"; - QtxParser::Error err = QtxParser::OK; - - if( !myValues.contains( val_name ) ) - { - myParser->setExpr( v2.toString() ); - QStringList params, specific; - myParser->paramsList( params ); - - myParser->clear(); - myPopupMgr->setParams( myParser, specific ); - - QtxPopupMgr::Selection* sel = myPopupMgr->myCurrentSelection; - - int global_result = 0; - if( sel ) - for( int i=0, n=sel->count(); iparam( i, *anIt ); - if( v.isValid() ) - myParser->set( *anIt, v ); - else - return QtxParser::InvalidToken; - } - - QtxValue res = myParser->calculate(); - err = myParser->lastError(); - if( err==QtxParser::OK ) - if( res.type()==QVariant::Bool ) - { - if( res.toBool() ) - global_result++; - if( ind==2 && global_result>1 ) - break; - } - else - return QtxParser::InvalidResult; - else - return err; - } - - QtxValue& vv = ( QtxValue& )myValues[ val_name ]; - vv = ( ind==0 && global_result==sel->count() ) || - ( ind==1 ) || - ( ind==2 && global_result==1 ); - } - - v2 = myValues[ val_name ]; - - return err; - } - else - return QtxStrings::calculate( op, v1, v2 ); -} - -/*! - Clears internal map of values -*/ -void QtxPopupMgr::Operations::clear() -{ - myValues.clear(); -} - - - - - - - - -/*! - Constructor -*/ -QtxPopupMgr::QtxPopupMgr( QPopupMenu* popup, QObject* parent ) -: QtxActionMenuMgr( popup, parent ), - myCurrentSelection( 0 ) -{ - createOperations(); -} - -/*! - Destructor -*/ -QtxPopupMgr::~QtxPopupMgr() -{ -} - -/*! - Creates popup operations instance -*/ -void QtxPopupMgr::createOperations() -{ - myOperations = new QtxListOfOperations; - myOperations->prepend( "logic", new QtxLogic(), 0 ); - myOperations->prepend( "arithm", new QtxArithmetics(), 50 ); - myOperations->append( "strings", new QtxStrings(), 100 ); - myOperations->append( "sets", new QtxSets(), 150 ); - myOperations->append( "custom", new Operations( this ), 200 ); -} - -/*! - Additional version of registerAction - \param act - action to be registered - \param visible - rule for visibility state - \param toggle - rule for toggle on state - \param id - proposed id (if it is less than 0, then id will be generated automatically) -*/ -int QtxPopupMgr::registerAction( QAction* act, - const QString& visible, - const QString& toggle, - const int id ) -{ - int _id = QtxActionMenuMgr::registerAction( act, id ); - setRule( _id, visible, true ); - setRule( _id, toggle, false ); - return _id; -} - -/*! - Removes action from internal map - \param id - action id -*/ -void QtxPopupMgr::unRegisterAction( const int id ) -{ - QAction* act = action( id ); - - myVisibility.remove( act ); - myToggle.remove( act ); - - remove( id ); - //QtxActionMenuMgr::unRegisterAction( id ); -} - -/*! - \return true if manager has rule for action - \param act - action - \param visibility - if it is true, then rule for "visibility" is checked, otherwise - for "toggle" -*/ -bool QtxPopupMgr::hasRule( QAction* act, bool visibility ) const -{ - return map( visibility ).contains( act ); -} - -/*! - \return true if manager has rule for action - \param id - action id - \param visibility - if it is true, then rule for "visibility" is checked, otherwise - for "toggle" -*/ -bool QtxPopupMgr::hasRule( const int id, bool visibility ) const -{ - return hasRule( action( id ), visibility ); -} - -/*! - Sets new rule for action - \param act - action - \param rule - string expression of rule - \param visibility - if it is true, then rule for "visibility" will be set, otherwise - for "toggle" -*/ -void QtxPopupMgr::setRule( QAction* act, const QString& rule, bool visibility ) -{ - if( !act || rule.isEmpty() ) - return; - - if( !hasRule( act, visibility ) ) - { - QtxParser* p = new QtxParser( myOperations, rule ); - if( p->lastError()==QtxParser::OK ) - map( visibility ).insert( act, p ); - else - delete p; - } - else - { - QtxParser* p = map( visibility )[ act ]; - p->setExpr( rule ); - if( p->lastError()!=QtxParser::OK ) - p->setExpr( QString() ); - } -} - -/*! - Sets new rule for action - \param id - action id - \param rule - string expression of rule - \param visibility - if it is true, then rule for "visibility" will be set, otherwise - for "toggle" -*/ -void QtxPopupMgr::setRule( const int id, const QString& rule, bool visibility ) -{ - setRule( action( id ), rule, visibility ); -} - -/*! - \return true if parser has finished work without errors - \param p - parser -*/ -bool result( QtxParser* p ) -{ - bool res = false; - if( p ) - { - QtxValue vv = p->calculate(); - res = p->lastError()==QtxParser::OK && - ( ( vv.type()==QVariant::Int && vv.toInt()!=0 ) || - ( vv.type()==QVariant::Bool && vv.toBool() ) ); - } - return res; -} - -/*! - Fills parser parameters with help of Selection::globalParam() method - \param p - parser - \param specific - list will be filled with names of parameters depending on selection objects (not global) -*/ -void QtxPopupMgr::setParams( QtxParser* p, QStringList& specific ) const -{ - if( !p || !myCurrentSelection ) - return; - - QStringList params; - - p->paramsList( params ); - QStringList::const_iterator anIt = params.begin(), - aLast = params.end(); - for( ; anIt!=aLast; anIt++ ) - { - QtxValue v = myCurrentSelection->globalParam( *anIt ); - if( v.isValid() ) - p->set( *anIt, v ); - else - specific.append( *anIt ); - } -} - -/*! - \return true if 'v1'<'v2' - This function can work with many types of values -*/ -bool operator<( const QtxValue& v1, const QtxValue& v2 ) -{ - QVariant::Type t1 = v1.type(), t2 = v2.type(); - if( t1==t2 ) - { - switch( t1 ) - { - case QVariant::Int: - return v1.toInt() < v2.toInt(); - - case QVariant::Double: - return v1.toDouble() < v2.toDouble(); - - case QVariant::CString: - case QVariant::String: - return v1.toString() < v2.toString(); - - case QVariant::StringList: - case QVariant::List: - { - const QValueList& aList1 = v1.toList(), aList2 = v2.toList(); - QValueList::const_iterator - anIt1 = aList1.begin(), aLast1 = aList1.end(), - anIt2 = aList2.begin(), aLast2 = aList2.end(); - for( ; anIt1!=aLast1 && anIt2!=aLast2; anIt1++, anIt2++ ) - if( (*anIt1)!=(*anIt2) ) - return (*anIt1)<(*anIt2); - - return anIt1==aLast1 && anIt2!=aLast2; - } - - default: - return v1.toString()menuText(); - - bool res = false; - if( !act ) - return res; - - if( hasRule( act, visibility ) ) - { - QtxParser* p = map( visibility )[ act ]; - QStringList specific; - p->clear(); - ( ( Operations* )myOperations->operations( "custom" ) )->clear(); - - setParams( p, specific ); - - QMap,int> aCorteges; - QValueList c; - - if( specific.count()>0 ) - if( myCurrentSelection ) - { - res = false; - - for( int i=0, n=myCurrentSelection->count(); iparam( i, *anIt1 ) ); - aCorteges.insert( c, 0 ); - } - - //qDebug( QString( "%1 corteges" ).arg( aCorteges.count() ) ); - QMap,int>::const_iterator anIt = aCorteges.begin(), aLast = aCorteges.end(); - for( ; anIt!=aLast; anIt++ ) - { - QStringList::const_iterator anIt1 = specific.begin(), aLast1 = specific.end(); - const QValueList& aCortege = anIt.key(); - QValueList::const_iterator anIt2 = aCortege.begin(); - for( ; anIt1!=aLast1; anIt1++, anIt2++ ) - p->set( *anIt1, *anIt2 ); - res = res || result( p ); - } - - /* - for( int i=0, n=myCurrentSelection->count(); iset( *anIt1, myCurrentSelection->param( i, *anIt1 ) ); - res = res || result( p ); - }*/ - } - else - res = false; - else - res = result( p ); - } - - return res; -} - -/*! - \return true if item corresponding to action is visible - \param actId - action id - \param place - index of place -*/ -bool QtxPopupMgr::isVisible( const int actId, const int place ) const -{ - bool res = QtxActionMenuMgr::isVisible( actId, place ); - QAction* act = action( actId ); - if( hasRule( act, true ) ) - res = res && isSatisfied( act, true ); - return res; -} - -/*! - Updates popup according to selection - \param p - popup menu - \param sel - selection -*/ -void QtxPopupMgr::updatePopup( QPopupMenu* p, Selection* sel ) -{ - QTime t1 = QTime::currentTime(); - - if( !p || !sel ) - return; - - myCurrentSelection = new QtxCacheSelection( sel ); - RulesMap::iterator anIt = myToggle.begin(), - aLast = myToggle.end(); - for( ; anIt!=aLast; anIt++ ) - if( anIt.key()->isToggleAction() && hasRule( anIt.key(), false ) ) - anIt.key()->setOn( isSatisfied( anIt.key(), false ) ); - - setWidget( ( QWidget* )p ); - updateMenu(); - QTime t2 = QTime::currentTime(); - qDebug( QString( "update popup time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) ); - qDebug( QString( "number of objects = %1" ).arg( myCurrentSelection->count() ) ); - - delete myCurrentSelection; -} - -/*! - \return reference to map of rules - \param visibility - type of map: visibility of toggle -*/ -QtxPopupMgr::RulesMap& QtxPopupMgr::map( bool visibility ) const -{ - return ( RulesMap& )( visibility ? myVisibility : myToggle ); -} - -/*! - Loads actions description from file - \param fname - name of file - \param r - reader of file - \return true on success -*/ -bool QtxPopupMgr::load( const QString& fname, QtxActionMgr::Reader& r ) -{ - PopupCreator cr( &r, this ); - return r.read( fname, cr ); -} - - - - -/*! - Constructor - \param r - menu reader - \param mgr - menu manager -*/ -QtxPopupMgr::PopupCreator::PopupCreator( QtxActionMgr::Reader* r, - QtxPopupMgr* mgr ) -: QtxActionMgr::Creator( r ), - myMgr( mgr ) -{ -} - -/*! - Destructor -*/QtxPopupMgr::PopupCreator::~PopupCreator() -{ -} - - -/*! - Appends new menu items - \param tag - tag of item - \param subMenu - it has submenu - \param attr - list of attributes - \param pId - id of action corresponding to parent item -*/ -int QtxPopupMgr::PopupCreator::append( const QString& tag, const bool subMenu, - const ItemAttributes& attr, const int pId ) -{ - if( !myMgr || !reader() ) - return -1; - - QString label = reader()->option( "label", "label" ), - id = reader()->option( "id", "id" ), - pos = reader()->option( "pos", "pos" ), - group = reader()->option( "group", "group" ), - tooltip = reader()->option( "tooltip", "tooltip" ), - sep = reader()->option( "separator", "separator" ), - accel = reader()->option( "accel", "accel" ), - icon = reader()->option( "icon", "icon" ), - toggle = reader()->option( "toggle", "toggle" ); - - int res = -1, actId = intValue( attr, id, -1 );; - if( subMenu ) - res = myMgr->insert( strValue( attr, label ), pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) ); - else if( tag==sep ) - res = myMgr->insert( separator(), pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) ); - else //if( !myMgr->contains( actId ) ) - { - QPixmap pix; QIconSet set; - QString name = strValue( attr, icon ); - if( !name.isEmpty() ) - { - if( loadPixmap( name, pix ) ) - set = QIconSet( pix ); - } - - QString actLabel = strValue( attr, label ); - QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, actLabel, - QKeySequence( strValue( attr, accel ) ), - myMgr ); - newAct->setToolTip( strValue( attr, tooltip ) ); - QString toggleact = strValue( attr, toggle ); - bool isToggle = !toggleact.isEmpty(); - newAct->setToggleAction( isToggle ); - newAct->setOn( toggleact.lower()=="true" ); - - connect( newAct ); - int aid = myMgr->registerAction( newAct, visibleRule( attr ), - isToggle ? toggleRule( attr ) : QString::null, - actId ); - res = myMgr->insert( aid, pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) ); - } - - return res; -} - -/*! - \return visibility rule by attributes - Default implementation is empty -*/ -QString QtxPopupMgr::PopupCreator::visibleRule( const ItemAttributes& ) const -{ - return QString::null; -} - -/*! - \return toggle rule by attributes - Default implementation is empty -*/ -QString QtxPopupMgr::PopupCreator::toggleRule( const ItemAttributes& ) const -{ - return QString::null; -} diff --git a/src/Qtx/QtxPopupMgr.h b/src/Qtx/QtxPopupMgr.h deleted file mode 100644 index 7bc260b3b..000000000 --- a/src/Qtx/QtxPopupMgr.h +++ /dev/null @@ -1,132 +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_POPUP_MGR_HEADER__ -#define __QTX_POPUP_MGR_HEADER__ - -#include "Qtx.h" -#include "QtxActionMenuMgr.h" -#include "QtxParser.h" -#include "QtxStdOperations.h" - -#include - -class QtxListOfOperations; - -class QTX_EXPORT QtxPopupMgr : public QtxActionMenuMgr -{ - Q_OBJECT - -public: - class QTX_EXPORT Selection - { - public: - virtual int count() const = 0; - virtual QtxValue param( const int, const QString& ) const = 0; - virtual QtxValue globalParam( const QString& ) const; - - virtual QChar equality() const; - virtual QString selCountParam() const; - - static QChar defEquality(); - static QString defSelCountParam(); - }; - -protected: - class Operations : public QtxStrings - { - public: - Operations( QtxPopupMgr* ); - virtual ~Operations(); - - virtual int prior( const QString&, bool isBin ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; - - void clear(); - - private: - QtxPopupMgr* myPopupMgr; - QtxParser* myParser; - QMap< QString, QtxValue > myValues; - }; - - friend class Operations; - -protected: - class PopupCreator; - -public: - QtxPopupMgr( QPopupMenu*, QObject* = 0 ); - virtual ~QtxPopupMgr(); - - virtual int registerAction( QAction*, - const QString& visible, - const QString& toggle = QString::null, - const int = -1 ); - virtual void unRegisterAction( const int ); - - virtual bool isVisible( const int actId, const int place ) const; - - bool hasRule( QAction*, bool visibility ) const; - bool hasRule( const int, bool visibility ) const; - void setRule( QAction*, const QString&, bool visibility ); - void setRule( const int, const QString&, bool visibility ); - void updatePopup( QPopupMenu*, Selection* ); - - //return name of parameter corresponding to selected objects count - //it will be set automatically - - virtual bool load( const QString&, QtxActionMgr::Reader& ); - -protected: - typedef QMap< QAction*, QtxParser* > RulesMap; - -protected: - virtual bool isSatisfied( QAction*, bool visibility ) const; - void setParams( QtxParser*, QStringList& ) const; - RulesMap& map( bool visibility ) const; - - void createOperations(); - -private: - RulesMap myVisibility, myToggle; - Selection* myCurrentSelection; - QtxListOfOperations* myOperations; -}; - - - -class QtxPopupMgr::PopupCreator : public QtxActionMgr::Creator -{ -public: - PopupCreator( QtxActionMgr::Reader*, QtxPopupMgr* ); - virtual ~PopupCreator(); - - virtual int append( const QString&, const bool, - const ItemAttributes&, const int ); - - virtual QString visibleRule( const ItemAttributes& ) const; - virtual QString toggleRule( const ItemAttributes& ) const; - -private: - QtxPopupMgr* myMgr; -}; - - -#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 fc816fe3b..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( QPtrList& ) const; - -private: - void removeItem( Item* ); - Item* createItem( const QString&, const int, const int ); - -private: - typedef QMap ItemMap; - -private: - ItemMap myItems; - QtxResourceMgr* myResMgr; - QMap myBackup; - QPtrList 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( QPtrList& ) 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(); - - 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 QPtrList ItemList; - typedef QPtrListIterator 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 02b3a1c65..98c534e04 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -18,17 +18,21 @@ // #include "QtxResourceMgr.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#include +#include #ifndef QT_NO_DOM -#include +#include #endif +#define EMULATE_GLOBAL_CONTEXT + #include /*! @@ -36,6 +40,58 @@ Level: Internal */ +class QtxResourceMgr::Resources +{ +public: + Resources( const QtxResourceMgr*, const QString& ); + virtual ~Resources(); + + QString file() const; + void setFile( const QString& ); + + QString value( const QString&, const QString&, const bool ) const; + void setValue( const QString&, const QString&, const QString& ); + + bool hasSection( const QString& ) const; + bool hasValue( const QString&, const QString& ) const; + + void removeSection( const QString& ); + void removeValue( const QString&, const QString& ); + + QPixmap loadPixmap( const QString&, const QString&, const QString& ) const; + QTranslator* loadTranslator( const QString&, const QString&, const QString& ) const; + + QString environmentVariable( const QString&, int&, int& ) const; + QString makeSubstitution( const QString&, const QString&, const QString& ) const; + + void clear(); + + QStringList sections() const; + QStringList parameters( const QString& ) const; + + QString path( const QString&, const QString&, const QString& ) const; + +protected: + QtxResourceMgr* resMgr() const; + +private: + Section section( const QString& ); + const Section section( const QString& ) const; + + QString fileName( const QString&, const QString&, const QString& ) const; + +private: + typedef QMap SectionMap; + +private: + QtxResourceMgr* myMgr; + SectionMap mySections; + QString myFileName; + QMap myPixmapCache; + + friend class QtxResourceMgr::Format; +}; + QtxResourceMgr::Resources::Resources( const QtxResourceMgr* mgr, const QString& fileName ) : myFileName( fileName ), myMgr( const_cast( mgr ) ) @@ -99,8 +155,10 @@ QString QtxResourceMgr::Resources::value( const QString& sect, const QString& na */ void QtxResourceMgr::Resources::setValue( const QString& sect, const QString& name, const QString& val ) { - Section& s = section( sect ); - s.insert( name, val ); + if ( !mySections.contains( sect ) ) + mySections.insert( sect, Section() ); + + mySections[sect].insert( name, val ); } /*! @@ -138,13 +196,12 @@ void QtxResourceMgr::Resources::removeSection( const QString& sect ) */ void QtxResourceMgr::Resources::removeValue( const QString& sect, const QString& name ) { - if ( !hasSection( sect ) ) + if ( !mySections.contains( sect ) ) return; - Section& s = section( sect ); - s.remove( name ); + mySections[sect].remove( name ); - if ( s.isEmpty() ) + if ( mySections[sect].isEmpty() ) mySections.remove( sect ); } @@ -205,7 +262,7 @@ QtxResourceMgr* QtxResourceMgr::Resources::resMgr() const /*! \return instance of section by it's name. Section will be created if it doesn't exist */ -QtxResourceMgr::Section& QtxResourceMgr::Resources::section( const QString& sn ) +QtxResourceMgr::Section QtxResourceMgr::Resources::section( const QString& sn ) { if ( !mySections.contains( sn ) ) mySections.insert( sn, Section() ); @@ -216,7 +273,7 @@ QtxResourceMgr::Section& QtxResourceMgr::Resources::section( const QString& sn ) /*! \return instance of section by it's name. Section will be created if it doesn't exist */ -const QtxResourceMgr::Section& QtxResourceMgr::Resources::section( const QString& sn ) const +const QtxResourceMgr::Section QtxResourceMgr::Resources::section( const QString& sn ) const { return mySections[sn]; } @@ -236,7 +293,7 @@ QString QtxResourceMgr::Resources::fileName( const QString& sect, const QString& if ( !path.isEmpty() ) { if ( QFileInfo( path ).isRelative() ) - path = Qtx::addSlash( QFileInfo( myFileName ).dirPath( true ) ) + path; + path = Qtx::addSlash( Qtx::dir( myFileName, true ) ) + path; path = Qtx::addSlash( path ) + name; } @@ -245,7 +302,7 @@ QString QtxResourceMgr::Resources::fileName( const QString& sect, const QString& { QString fname = QDir::convertSeparators( path ); QFileInfo inf( fname ); - fname = inf.absFilePath(); + fname = inf.absoluteFilePath(); return fname; } return QString(); @@ -282,7 +339,46 @@ QPixmap QtxResourceMgr::Resources::loadPixmap( const QString& sect, const QStrin QTranslator* QtxResourceMgr::Resources::loadTranslator( const QString& sect, const QString& prefix, const QString& name ) const { QTranslator* trans = new QTranslator( 0 ); - if ( !trans->load( fileName( sect, prefix, name ) ) ) + QString fname = fileName( sect, prefix, name ); +#ifdef EMULATE_GLOBAL_CONTEXT + char* buf = 0; + QFile file( fname ); + int len = file.size(); + if ( len ) + { + buf = new char[len]; + if ( !file.open( QIODevice::ReadOnly ) || len != (uint)file.read( buf, len ) ) + { + delete buf; + buf = 0; + } + file.close(); + } + if ( buf ) + { + char* pattern = "@default"; + size_t pl = strlen( pattern ); + for ( size_t i = 0; i < len - pl; i++ ) + { + char* cur = buf + i; + if ( !strncmp( cur, pattern, pl ) ) + { + *cur = '\0'; + i += pl - 1; + } + } + + if ( !trans->load( (uchar*)buf, len ) ) + { + delete buf; + buf = 0; + } + } + + if ( !buf ) +#else + if ( !trans->load( Qtx::file( fname, false ), Qtx::dir( fname ) ) ) +#endif { delete trans; trans = 0; @@ -304,14 +400,14 @@ QString QtxResourceMgr::Resources::environmentVariable( const QString& str, int& QRegExp rx( "\\$\\{([a-zA-Z]+[a-zA-Z0-9_]*)\\}|\\$\\(([a-zA-Z]+[a-zA-Z0-9_]*)\\)|\\$([a-zA-Z]+[a-zA-Z0-9_]*)|\\%([a-zA-Z]+[a-zA-Z0-9_]*)\\%" ); - int pos = rx.search( str, start ); + int pos = rx.indexIn( str, start ); if ( pos != -1 ) { start = pos; len = rx.matchedLength(); QStringList caps = rx.capturedTexts(); for ( uint i = 1; i <= caps.count() && varName.isEmpty(); i++ ) - varName = *caps.at( i ); + varName = caps[i]; } return varName; } @@ -339,9 +435,9 @@ QString QtxResourceMgr::Resources::makeSubstitution( const QString& str, const Q if ( envName.isNull() ) break; - QString newStr = QString::null; - if ( ::getenv( envName ) ) - newStr = QString( ::getenv( envName ) ); + QString newStr; + if ( ::getenv( envName.toLatin1() ) ) + newStr = QString( ::getenv( envName.toLatin1() ) ); if ( newStr.isNull() ) { @@ -399,7 +495,7 @@ QtxResourceMgr::IniFormat::~IniFormat() bool QtxResourceMgr::IniFormat::load( const QString& fname, QMap& secMap ) { QFile file( fname ); - if ( !file.open( IO_ReadOnly ) ) + if ( !file.open( QFile::ReadOnly ) ) return false; QTextStream ts( &file ); @@ -425,7 +521,7 @@ bool QtxResourceMgr::IniFormat::load( const QString& fname, QMap& secMap ) { QFile file( fname ); - if ( !file.open( IO_WriteOnly ) ) + if ( !file.open( QFile::WriteOnly ) ) return false; + QTextStream ts( &file ); + bool res = true; for ( QMap::ConstIterator it = secMap.begin(); it != secMap.end() && res; ++it ) { - QString data = QString( "[%1]\n" ).arg( it.key() ); - for ( Section::ConstIterator iter = it.data().begin(); iter != it.data().end(); ++iter ) - data += iter.key() + " = " + iter.data() + "\n"; - data += "\n"; + QStringList data( QString( "[%1]" ).arg( it.key() ) ); + for ( Section::ConstIterator iter = it.value().begin(); iter != it.value().end(); ++iter ) + data.append( iter.key() + " = " + iter.value() ); + data.append( "" ); - res = file.writeBlock( data.latin1(), data.length() ) == (int)data.length(); + for ( QStringList::const_iterator itr = data.begin(); itr != data.end(); ++itr ) + ts << *itr << endl; } file.close(); @@ -539,7 +637,7 @@ bool QtxResourceMgr::XmlFormat::load( const QString& fname, QMapmySections = sections; else - qDebug( "QtxResourceMgr: Could not load resource file \"%s\"", res->myFileName.latin1() ); + qDebug( "QtxResourceMgr: Could not load resource file \"%s\"", (const char*)res->myFileName.toLatin1() ); return status; } @@ -856,14 +957,14 @@ QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTem envVar = envVar.arg( appName ); QString dirs; - if ( ::getenv( envVar ) ) - dirs = ::getenv( envVar ); + if ( ::getenv( envVar.toLatin1() ) ) + dirs = ::getenv( envVar.toLatin1() ); #ifdef WIN32 QString dirsep = ";"; // for Windows: ";" is used as directories separator #else QString dirsep = "[:|;]"; // for Linux: both ":" and ";" can be used #endif - setDirList( QStringList::split( QRegExp(dirsep), dirs ) ); + setDirList( dirs.split( QRegExp( dirsep ), QString::SkipEmptyParts ) ); installFormat( new XmlFormat() ); installFormat( new IniFormat() ); @@ -879,11 +980,11 @@ QtxResourceMgr::~QtxResourceMgr() QStringList prefList = myTranslator.keys(); for ( QStringList::const_iterator it = prefList.begin(); it != prefList.end(); ++it ) removeTranslators( *it ); - for ( ResListIterator resIt( myResources ); resIt.current(); ++resIt ) - delete resIt.current(); + for ( ResList::iterator resIt = myResources.begin(); resIt != myResources.end(); ++resIt ) + delete *resIt; myResources.clear(); - for ( FormatListIterator formIt( myFormats ); formIt.current(); ++formIt ) - delete formIt.current(); + for ( FormatList::iterator formIt = myFormats.begin(); formIt != myFormats.end(); ++formIt ) + delete *formIt; } /*! @@ -967,8 +1068,8 @@ void QtxResourceMgr::setIsPixmapCached( const bool on ) */ void QtxResourceMgr::clear() { - for ( ResListIterator it( myResources ); it.current(); ++it ) - it.current()->clear(); + for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + (*it)->clear(); } /*! @@ -1046,7 +1147,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, bool& bVal boolMap["false"] = boolMap["no"] = boolMap["off"] = false; } - val = val.lower(); + val = val.toLower(); bool res = boolMap.contains( val ); if ( res ) bVal = boolMap[val]; @@ -1074,7 +1175,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QColor& cV return false; bool res = true; - QStringList vals = QStringList::split( ",", val, true ); + QStringList vals = val.split( "," ); QIntList nums; for ( QStringList::const_iterator it = vals.begin(); it != vals.end() && res; ++it ) @@ -1086,7 +1187,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QColor& cV { int pack = val.toInt( &res ); if ( res ) - Qtx::rgbSet( pack, cVal ); + cVal = Qtx::rgbSet( pack ); } return res; @@ -1105,7 +1206,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QFont& fVa if ( !value( sect, name, val, true ) ) return false; - QStringList fontDescr = QStringList::split( ",", val ); + QStringList fontDescr = val.split( ",", QString::SkipEmptyParts ); if ( fontDescr.count() < 2 ) return false; @@ -1118,7 +1219,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QFont& fVa for ( int i = 1; i < (int)fontDescr.count(); i++ ) { - QString curval = fontDescr[i].stripWhiteSpace().lower(); + QString curval = fontDescr[i].trimmed().toLower(); if ( curval == QString( "bold" ) ) fVal.setBold( true ); else if ( curval == QString( "italic" ) ) @@ -1153,15 +1254,15 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& v bool ok = false; - ResListIterator it( myResources ); + ResList::const_iterator it = myResources.begin(); if ( ignoreUserValues() ) ++it; - for ( ; it.current() && !ok; ++it ) + for ( ; it != myResources.end() && !ok; ++it ) { - ok = it.current()->hasValue( sect, name ); + ok = (*it)->hasValue( sect, name ); if ( ok ) - val = it.current()->value( sect, name, subst ); + val = (*it)->value( sect, name, subst ); } return ok; @@ -1267,8 +1368,8 @@ bool QtxResourceMgr::hasValue( const QString& sect, const QString& name ) const initialize(); bool ok = false; - for ( ResListIterator it( myResources ); it.current() && !ok; ++it ) - ok = it.current()->hasValue( sect, name ); + for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) + ok = (*it)->hasValue( sect, name ); return ok; } @@ -1282,8 +1383,8 @@ bool QtxResourceMgr::hasSection( const QString& sect ) const initialize(); bool ok = false; - for ( ResListIterator it( myResources ); it.current() && !ok; ++it ) - ok = it.current()->hasSection( sect ); + for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) + ok = (*it)->hasSection( sect ); return ok; } @@ -1396,8 +1497,8 @@ void QtxResourceMgr::remove( const QString& sect ) { initialize(); - for ( ResListIterator it( myResources ); it.current(); ++it ) - it.current()->removeSection( sect ); + for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + (*it)->removeSection( sect ); } /*! @@ -1409,8 +1510,8 @@ void QtxResourceMgr::remove( const QString& sect, const QString& name ) { initialize(); - for ( ResListIterator it( myResources ); it.current(); ++it ) - it.current()->removeValue( sect, name ); + for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + (*it)->removeValue( sect, name ); } /*! @@ -1420,7 +1521,7 @@ QString QtxResourceMgr::currentFormat() const { QString fmt; if ( !myFormats.isEmpty() ) - fmt = myFormats.getFirst()->format(); + fmt = myFormats[0]->format(); return fmt; } @@ -1434,20 +1535,21 @@ void QtxResourceMgr::setCurrentFormat( const QString& fmt ) if ( !form ) return; - myFormats.remove( form ); + myFormats.removeAll( form ); myFormats.prepend( form ); if ( myResources.isEmpty() ) return; - ResListIterator resIt( myResources ); - if ( myResources.count() > myDirList.count() && resIt.current() ) { - resIt.current()->setFile( userFileName( appName() ) ); + ResList::iterator resIt = myResources.begin(); + if ( myResources.count() > myDirList.count() && resIt != myResources.end() ) + { + (*resIt)->setFile( userFileName( appName() ) ); ++resIt; } - for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end() && resIt.current(); ++it, ++resIt ) - resIt.current()->setFile( Qtx::addSlash( *it ) + globalFileName( appName() ) ); + for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end() && resIt != myResources.end(); ++it, ++resIt ) + (*resIt)->setFile( Qtx::addSlash( *it ) + globalFileName( appName() ) ); } /*! @@ -1457,10 +1559,10 @@ void QtxResourceMgr::setCurrentFormat( const QString& fmt ) QtxResourceMgr::Format* QtxResourceMgr::format( const QString& fmt ) const { Format* form = 0; - for ( FormatListIterator it( myFormats ); it.current() && !form; ++it ) + for ( FormatList::const_iterator it = myFormats.begin(); it != myFormats.end() && !form; ++it ) { - if ( it.current()->format() == fmt ) - form = it.current(); + if ( (*it)->format() == fmt ) + form = *it; } return form; @@ -1482,7 +1584,7 @@ void QtxResourceMgr::installFormat( QtxResourceMgr::Format* form ) */ void QtxResourceMgr::removeFormat( QtxResourceMgr::Format* form ) { - myFormats.remove( form ); + myFormats.removeAll( form ); } /*! @@ -1528,8 +1630,8 @@ bool QtxResourceMgr::load() return false; bool res = true; - for ( ResListIterator it( myResources ); it.current(); ++it ) - res = fmt->load( it.current() ) && res; + for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + res = fmt->load( *it ) && res; return res; } @@ -1543,8 +1645,8 @@ bool QtxResourceMgr::import( const QString& fname ) if ( !fmt ) return false; - Resources* r = myResources.getFirst(); - if( !r ) + Resources* r = myResources[0]; + if ( !r ) return false; QString old = r->file(); @@ -1568,7 +1670,7 @@ bool QtxResourceMgr::save() if ( myResources.isEmpty() ) return true; - return fmt->save( myResources.getFirst() ); + return fmt->save( myResources[0] ); } /*! @@ -1579,9 +1681,9 @@ QStringList QtxResourceMgr::sections() const initialize(); QMap map; - for ( ResListIterator it( myResources ); it.current(); ++it ) + for ( ResList::const_iterator it = myResources.begin(); it != myResources.end(); ++it ) { - QStringList lst = it.current()->sections(); + QStringList lst = (*it)->sections(); for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) map.insert( *itr, 0 ); } @@ -1607,10 +1709,13 @@ QStringList QtxResourceMgr::parameters( const QString& sec ) const typedef IMap PMap; #endif PMap pmap; - ResListIterator it( myResources ); - it.toLast(); - for ( ; it.current(); --it ) { - QStringList lst = it.current()->parameters( sec ); + ResList lst; + for ( ResList::const_iterator itr = myResources.begin(); itr != myResources.end(); ++itr ) + lst.prepend( *itr ); + + for ( ResList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + { + QStringList lst = (*it)->parameters( sec ); for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) pmap.insert( *itr, 0, false ); } @@ -1632,8 +1737,8 @@ QStringList QtxResourceMgr::parameters( const QString& sec ) const QString QtxResourceMgr::path( const QString& sect, const QString& prefix, const QString& name ) const { QString res; - for ( ResListIterator it( myResources ); it.current() && res.isEmpty(); ++it ) - res = it.current()->path( sect, prefix, name ); + for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && res.isEmpty(); ++it ) + res = (*it)->path( sect, prefix, name ); return res; } @@ -1713,8 +1818,8 @@ QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, initialize(); QPixmap pix; - for ( ResListIterator it( myResources ); it.current() && pix.isNull(); ++it ) - pix = it.current()->loadPixmap( resSection(), prefix, name ); + for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && pix.isNull(); ++it ) + pix = (*it)->loadPixmap( resSection(), prefix, name ); if ( pix.isNull() ) pix = defPix; return pix; @@ -1750,7 +1855,7 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) if ( lang.isEmpty() ) { lang = QString( "en" ); - qWarning( QString( "Language not specified. Assumed: %1" ).arg( lang ) ); + qWarning( "Language not specified. Assumed: %s", (const char*)lang.toLatin1() ); } substMap.insert( 'L', lang ); @@ -1758,19 +1863,21 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) QString trs; if ( value( langSection(), "translators", trs, false ) && !trs.isEmpty() ) { - QStringList translators = QStringList::split( "|", option( "translators" ) ); - QStringList newTranslators = QStringList::split( "|", trs ); + QStringList translators = option( "translators" ).split( "|", QString::SkipEmptyParts ); + QStringList newTranslators = trs.split( "|", QString::SkipEmptyParts ); for ( uint i = 0; i < newTranslators.count(); i++ ) - if ( translators.find( newTranslators[i] ) == translators.end() ) + { + if ( translators.indexOf( newTranslators[i] ) < 0 ) translators += newTranslators[i]; + } setOption( "translators", translators.join( "|" ) ); } - QStringList trList = QStringList::split( "|", option( "translators" ) ); + QStringList trList = option( "translators" ).split( "|", QString::SkipEmptyParts ); if ( trList.isEmpty() ) { trList.append( "%P_msg_%L.qm" ); - qWarning( QString( "Translators not defined. Assumed: %1" ).arg( trList.first() ) ); + qWarning( "Translators not defined. Assumed: %s", (const char*)trList[0].toLatin1() ); } QStringList prefixList; @@ -1786,7 +1893,7 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) QStringList trs; for ( QStringList::const_iterator it = trList.begin(); it != trList.end(); ++it ) - trs.append( substMacro( *it, substMap ).stripWhiteSpace() ); + trs.append( substMacro( *it, substMap ).trimmed() ); loadTranslators( prefix, trs ); } @@ -1802,19 +1909,22 @@ void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList& { initialize(); + ResList lst; + for ( ResList::iterator iter = myResources.begin(); iter != myResources.end(); ++iter ) + lst.prepend( *iter ); + QTranslator* trans = 0; - ResListIterator it( myResources ); - it.toLast(); - for ( ; it.current(); --it ) + + for ( ResList::iterator it = lst.begin(); it != lst.end(); ++it ) { for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr ) { - trans = it.current()->loadTranslator( resSection(), prefix, *itr ); + trans = (*it)->loadTranslator( resSection(), prefix, *itr ); if ( trans ) { if ( !myTranslator[prefix].contains( trans ) ) myTranslator[prefix].append( trans ); - qApp->installTranslator( trans ); + QApplication::instance()->installTranslator( trans ); } } } @@ -1831,16 +1941,15 @@ void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name initialize(); QTranslator* trans = 0; - ResListIterator it( myResources ); - it.toLast(); - for ( ; it.current(); --it ) + ResList::iterator it = myResources.end(); + for ( ; it != myResources.begin(); --it ) { - trans = it.current()->loadTranslator( resSection(), prefix, name ); + trans = (*it)->loadTranslator( resSection(), prefix, name ); if ( trans ) { if ( !myTranslator[prefix].contains( trans ) ) myTranslator[prefix].append( trans ); - qApp->installTranslator( trans ); + QApplication::instance()->installTranslator( trans ); } } } @@ -1855,10 +1964,10 @@ void QtxResourceMgr::removeTranslators( const QString& prefix ) if ( !myTranslator.contains( prefix ) ) return; - for ( TransListIterator it( myTranslator[prefix] ); it.current(); ++it ) + for ( TransList::iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it ) { - qApp->removeTranslator( it.current() ); - delete it.current(); + QApplication::instance()->removeTranslator( *it ); + delete *it; } myTranslator.remove( prefix ); @@ -1874,10 +1983,10 @@ void QtxResourceMgr::raiseTranslators( const QString& prefix ) if ( !myTranslator.contains( prefix ) ) return; - for ( TransListIterator it( myTranslator[prefix] ); it.current(); ++it ) + for ( TransList::iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it ) { - qApp->removeTranslator( it.current() ); - qApp->installTranslator( it.current() ); + QApplication::instance()->removeTranslator( *it ); + QApplication::instance()->installTranslator( *it ); } } @@ -1901,8 +2010,8 @@ void QtxResourceMgr::refresh() void QtxResourceMgr::setDirList( const QStringList& dl ) { myDirList = dl; - for ( ResListIterator it( myResources ); it.current(); ++it ) - delete it.current(); + for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + delete *it; myResources.clear(); } @@ -1930,7 +2039,7 @@ void QtxResourceMgr::setResource( const QString& sect, const QString& name, cons QString QtxResourceMgr::userFileName( const QString& appName, const bool /*for_load*/ ) const { QString fileName; - QString pathName = QDir::homeDirPath(); + QString pathName = QDir::homePath(); #ifdef WIN32 fileName = QString( "%1.%2" ).arg( appName ).arg( currentFormat() ); @@ -1965,7 +2074,7 @@ QString QtxResourceMgr::substMacro( const QString& src, const QMap= 0 ) + while ( ( idx = rx.indexIn( trg, idx ) ) >= 0 ) { QChar spec = trg.at( idx + 1 ); QString subst; diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index ff72dd3c2..1c9780f32 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -21,13 +21,14 @@ #include "Qtx.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +#include +#include +#include class QPixmap; @@ -153,15 +154,11 @@ private: QString substMacro( const QString&, const QMap& ) const; private: - typedef QPtrList ResList; - typedef QPtrList FormatList; - typedef QMap OptionsMap; - typedef QPtrListIterator ResListIterator; - typedef QPtrListIterator FormatListIterator; - - typedef QPtrList TransList; - typedef QMap TransListMap; - typedef QPtrListIterator TransListIterator; + typedef QList ResList; + typedef QList TransList; + typedef QList FormatList; + typedef QMap OptionsMap; + typedef QMap TransListMap; private: QString myAppName; @@ -207,62 +204,6 @@ private: QMap myOpt; }; -/*! - Class: QtxResourceMgr::Resources -*/ - -class QtxResourceMgr::Resources -{ -public: - Resources( const QtxResourceMgr*, const QString& ); - virtual ~Resources(); - - QString file() const; - void setFile( const QString& ); - - QString value( const QString&, const QString&, const bool ) const; - void setValue( const QString&, const QString&, const QString& ); - - bool hasSection( const QString& ) const; - bool hasValue( const QString&, const QString& ) const; - - void removeSection( const QString& ); - void removeValue( const QString&, const QString& ); - - QPixmap loadPixmap( const QString&, const QString&, const QString& ) const; - QTranslator* loadTranslator( const QString&, const QString&, const QString& ) const; - - QString environmentVariable( const QString&, int&, int& ) const; - QString makeSubstitution( const QString&, const QString&, const QString& ) const; - - void clear(); - - QStringList sections() const; - QStringList parameters( const QString& ) const; - - QString path( const QString&, const QString&, const QString& ) const; - -protected: - QtxResourceMgr* resMgr() const; - -private: - Section& section( const QString& ); - const Section& section( const QString& ) const; - - QString fileName( const QString&, const QString&, const QString& ) const; - -private: - typedef QMap SectionMap; - -private: - SectionMap mySections; - QString myFileName; - QMap myPixmapCache; - QtxResourceMgr* myMgr; - - friend class QtxResourceMgr::Format; -}; - /*! Class: QtxResourceMgr::IMapIterator */ @@ -280,10 +221,10 @@ public: operator bool() const { return myIndex >= 0; } const Key& key() const { return myMap->key( myIndex ); } - Value& data() { return myMap->value( myIndex ); } - const Value& data() const { return myMap->value( myIndex ); } + Value& value() { return myMap->value( myIndex ); } + const Value& value() const { return myMap->value( myIndex ); } - Value& operator*() { return data(); } + Value& operator*() { return value(); } IMapIterator& operator++() { myIndex++; init(); return *this; } IMapIterator operator++( int ) { IMapIterator i = *this; myIndex++; init(); return i; } @@ -320,10 +261,10 @@ public: operator bool() const { return myIndex >= 0; } const Key& key() const { return myMap->key( myIndex ); } - const Value& data() const { return myMap->value( myIndex ); } - - const Value& operator*() const { return data(); } + const Value value() const { return myMap->value( myIndex ); } + const Value operator*() const { return value(); } + IMapConstIterator& operator++() { myIndex++; init(); return *this; } IMapConstIterator operator++( int ) { IMapConstIterator i = *this; myIndex++; init(); return i; } IMapConstIterator& operator--() { myIndex--; init(); return *this; } @@ -362,9 +303,9 @@ public: void clear() { myKeys.clear(); myData.clear(); } - QValueList keys() const { return myKeys; } - QValueList values() const { QValueList l; for ( int i = 0; i < count(); i++ ) l.append( value( i ) ); return l; } - bool contains ( const Key& key ) const { return myData.contains( key ); } + QList keys() const { return myKeys; } + QList values() const { QList l; for ( int i = 0; i < count(); i++ ) l.append( value( i ) ); return l; } + bool contains ( const Key& key ) const { return myData.contains( key ); } Iterator begin() { return Iterator( this ); } Iterator end() { return Iterator( this, count() ); } @@ -376,7 +317,7 @@ public: if ( myData.find( key ) == myData.end() || overwrite ) { if ( myData.find( key ) != myData.end() && overwrite ) - myKeys.remove( myKeys.find( key ) ); + myKeys.removeAt( myKeys.indexOf( key ) ); myKeys.append( key ); myData[key] = value; } @@ -391,7 +332,7 @@ public: return Iterator( this, index( key ) ); } - int index( const Key& key ) const { return myKeys.findIndex( key ); } + int index( const Key& key ) const { return myKeys.indexOf( key ); } Iterator at( const int index ) { return Iterator( this, index ); } ConstIterator at( const int index ) const { return ConstIterator( this, index ); } @@ -402,25 +343,25 @@ public: return myKeys[index]; } - Value& value( const int index ) + Value value( const int index ) { if ( index < 0 || index >= (int)myKeys.count() ) return dummyValue; return myData[ myKeys[index] ]; } - Value& operator[]( const Key& key ) + Value operator[]( const Key& key ) { if ( myData.find( key ) == myData.end() ) insert( key, Value() ); return myData[ key ]; } - const Value& operator[]( const Key& key ) const + const Value operator[]( const Key& key ) const { if ( myData.find( key ) == myData.end() ) return dummyValue; - return myData[ key ]; + return myData[key]; } void erase( Iterator it ) { remove( it ); } @@ -432,13 +373,13 @@ public: { if ( index >= 0 && index < (int)myKeys.count() ) { - myData.remove( myKeys[ index ] ); - myKeys.remove( myKeys.at( index ) ); + myData.remove( myKeys[index] ); + myKeys.removeAt( index ); } } private: - QValueList myKeys; + QList myKeys; QMap myData; Key dummyKey; Value dummyValue; diff --git a/src/Qtx/QtxSplash.cxx b/src/Qtx/QtxSplash.cxx deleted file mode 100644 index d3244efc9..000000000 --- a/src/Qtx/QtxSplash.cxx +++ /dev/null @@ -1,507 +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: QtxSplash.cxx -// Author: Vadim SANDLER - -#include "QtxSplash.h" - -#include -#include -#include -#include - -const int _PROGRESS_EVENT = QEvent::User + 10; -const int _PROGRESS_WIDTH = 10; - -/*! - Class ProgressEvent [ internal ]. -*/ -class ProgressEvent: public QCustomEvent -{ -public: - ProgressEvent( const QString& msg, const int progress = 0 ) - : QCustomEvent( id() ), - myMessage( msg ), - myProgress( progress ) - {} - QString message() const { return myMessage; } - int progress() const { return myProgress; } - static int id() { return _PROGRESS_EVENT; } - -private: - QString myMessage; - int myProgress; -}; - -// Only one instance of splash screen is allowed -QtxSplash* QtxSplash::mySplash = 0; - -/*! - Construct a splash screen that will display the \a pixmap. -*/ -QtxSplash::QtxSplash( const QPixmap& pixmap ) - : QWidget( 0, 0, WStyle_Customize | WStyle_StaysOnTop | WX11BypassWM | WStyle_NoBorder ) -{ - myAlignment = AlignBottom | AlignRight; - myColor = white; - myHideOnClick = false; - myProgress = 0; - myTotal = 0; - myGradientType = Vertical; - myError = 0; - myStartColor = red; - - setPixmap( pixmap ); -} - -/*! - Destructor. -*/ -QtxSplash::~QtxSplash() -{ - mySplash = 0; -} - -/*! - Returns an only instance of splash screen. - If \a px is valid sets this pixmap to the splash screen. -*/ -QtxSplash* QtxSplash::splash( const QPixmap& px ) -{ - if ( !mySplash ) - mySplash = new QtxSplash( px ); - else if ( !px.isNull() ) - mySplash->setPixmap( px ); - return mySplash; -} - -/*! - Sends the status message and (optionally) progress to the splash screen. - Can be used, for example, from the progress thread. -*/ -void QtxSplash::setStatus( const QString& msg, - const int progress ) -{ - if ( mySplash ) { - QApplication::postEvent( mySplash, new ProgressEvent( msg, progress ) ); - qApp->processEvents(); - } -} - -/*! - Sets error status and shows error message box to the user. -*/ -void QtxSplash::error( const QString& error, const QString& title, const int code ) -{ - printf("QtxSplash::error: %s\n",error.latin1()); - if ( mySplash ) { - mySplash->setError( code ); - QMessageBox::critical( mySplash, - title.isEmpty() ? tr( "Error" ) : title, - error, - tr( "&OK" ) ); - } -} - -/*! - Sets the pixmap that will be used as the splash screen's image to - \a pixmap. -*/ -void QtxSplash::setPixmap( const QPixmap& pixmap ) -{ - myPixmap = pixmap; - QRect r( 0, 0, myPixmap.size().width(), myPixmap.size().height() ); - resize( myPixmap.size() ); - move( QApplication::desktop()->screenGeometry().center() - r.center() ); - repaint(); -} - -/*! - Returns the pixmap that is used in the splash screen. -*/ -QPixmap QtxSplash::pixmap() const -{ - return myPixmap; -} - -/*! - Sets/clear the 'hide on mouse click' flag. - Default is FALSE. - When this flag is set, user can hide the splash screen window - by clicking on it with mouse. - But for this to work it is necessary to call periodically - QApplication::processEvents() in order to allow event loop to process - events because usually main application loop is not yet started - at that moment. -*/ -void QtxSplash::setHideOnClick( const bool on ) -{ - myHideOnClick = on; -} - -/*! - Returns the 'hide on mouse click' flag. -*/ -bool QtxSplash::hideOnClick() const -{ - return myHideOnClick; -} - -/*! - Sets total progress steps to \a total. -*/ -void QtxSplash::setTotalSteps( const int total ) -{ - myTotal = total; - repaint(); -} - -/*! - Return total progress steps number. - \sa setTotalSteps(), setProgress() -*/ -int QtxSplash::totalSteps() const -{ - return myTotal; -} - -/*! - Sets progress to \a progress. -*/ -void QtxSplash::setProgress( const int progress ) -{ - myProgress = progress; - repaint(); -} - -/*! - Return current progress. - \sa setProgress(), setTotalSteps() -*/ -int QtxSplash::progress() const -{ - return myProgress; -} - -/*! - Sets progress to \a progress and total progress steps to \a total. -*/ -void QtxSplash::setProgress( const int progress, const int total ) -{ - myTotal = total; - myProgress = progress; - repaint(); -} - -/*! - Sets progress bar colors to \a startColor and \a endColor. - If the colors differ the gradient color bar is drawed. - If the \a endColor is not valid, \a startColor is used instead. - \a gradientType sets the type of gradient to be used for progress - bar - horizontal or vertical. Default is vertical. -*/ -void QtxSplash::setProgressColors( const QColor& startColor, - const QColor& endColor, - const int gradientType ) -{ - myStartColor = startColor; - myEndColor = endColor; - myGradientType = gradientType; - repaint(); -} - -/*! - Return progress colors and gradient type (horizontal or vertical). - \sa setProgressColors() -*/ -int QtxSplash::progressColors( QColor& startColor, QColor& endColor ) -{ - startColor = myStartColor; - endColor = myEndColor; - return myGradientType; -} - -/*! - Sets message text alignment flags to \a alignment. - Default is AlignBottom | AlignRight. -*/ -void QtxSplash::setTextAlignment( const int alignment ) -{ - myAlignment = alignment; - repaint(); -} - -/*! - Return message text alignment flags. - \sa setTextAlignment() -*/ -int QtxSplash::textAlignment() const -{ - return myAlignment; -} - -/*! - Sets message text color to \a color. - Default is white. - \sa setTextColors() -*/ -void QtxSplash::setTextColor( const QColor& color ) -{ - myColor = color; - myShadowColor = QColor(); - repaint(); -} - -/*! - Return message text color. - \sa setTextColor() -*/ -QColor QtxSplash::textColor() const -{ - return myColor; -} - -/*! - Sets message text color to \a color and text shadow color to \a shadow. - \sa setTextColor() -*/ -void QtxSplash::setTextColors( const QColor& color, const QColor& shadow ) -{ - myColor = color; - myShadowColor = shadow; - repaint(); -} - -/*! - Return message text color and text shadow color. - \sa setTextColors() -*/ -void QtxSplash::textColors( QColor& color, QColor& shadow ) const -{ - color = myColor; - shadow = myShadowColor; -} - -/*! - Returns current status message. -*/ -QString QtxSplash::message() const -{ - return myMessage; -} - -/*! - Return error code. If no errors were occured returns 0. - Error code can be set by error( QString&, QString, int ). -*/ -int QtxSplash::error() const -{ - return myError; -} - -/*! - Makes the splash screen wait until the widget \a mainWin is displayed - before calling close() on itself. -*/ -void QtxSplash::finish( QWidget* mainWin ) -{ - if ( mainWin ) { -#if defined(Q_WS_X11) - extern void qt_wait_for_window_manager( QWidget* w ); - qt_wait_for_window_manager( mainWin ); -#endif - } - close(); -} - -/*! - Repaint the splash screen. -*/ -void QtxSplash::repaint() -{ - drawContents(); - QWidget::repaint(); - QApplication::flush(); -} - -/*! - Draws the \a message text onto the splash screen with color \a - color and aligns the text according to the flags in \a alignment. -*/ -void QtxSplash::message( const QString& msg, - int alignment, - const QColor& color ) -{ - myMessage = msg; - myAlignment = alignment; - myColor = color; - repaint(); -} - -/*! - This is an overloaded member function, provided for convenience. - It behaves essentially like the above function. - Draws the \a message text onto the splash screen with default color - and aligns the text according to the default alignment flags. -*/ -void QtxSplash::message( const QString& msg ) -{ - myMessage = msg; - repaint(); -} - -/*! - Removes the message being displayed on the splash screen. - \sa message() -*/ -void QtxSplash::clear() -{ - myMessage = QString::null; - repaint(); -} - -/*! - Draw the contents of the splash screen using painter \a painter. -*/ -void QtxSplash::drawContents( QPainter* painter ) -{ - QRect r = rect(); - if ( myTotal > 0 ) { - // draw progress bar outline rectangle - painter->setPen( palette().active().dark() ); - painter->drawLine( r.x()+5, - r.height()-5-_PROGRESS_WIDTH, - r.width()-5, - r.height()-5-_PROGRESS_WIDTH ); - painter->drawLine( r.x()+5, - r.height()-5-_PROGRESS_WIDTH, - r.x()+5, - r.height()-5 ); - painter->setPen( palette().active().light() ); - painter->drawLine( r.x()+5, - r.height()-5, - r.width()-5, - r.height()-5 ); - painter->drawLine( r.width()-5, - r.height()-5-_PROGRESS_WIDTH, - r.width()-5, - r.height()-5 ); - // draw progress bar - if ( myGradientType == Horizontal ) { - int tng = r.width() - r.x() - 11; - int ng = (int) ( 1.0 * tng * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); - int h1, h2, s1, s2, v1, v2; - myStartColor.hsv( &h1, &s1, &v1 ); - myEndColor.isValid() ? myEndColor.hsv( &h2, &s2, &v2 ) : - myStartColor.hsv( &h2, &s2, &v2 ); - for ( int i = 0; i < ng; i++ ) { - painter->setPen( QColor( h1 + ((h2-h1)*i)/(tng-1), - s1 + ((s2-s1)*i)/(tng-1), - v1 + ((v2-v1)*i)/(tng-1), - QColor::Hsv ) ); - painter->drawLine( r.x()+6+i, - r.height()-5-_PROGRESS_WIDTH+1, - r.x()+6+i, - r.height()-6 ); - } - } - else { - int ng = (int) ( 1.0 * (r.width() - r.x() - 11) * ( myProgress > 0 ? myProgress : 0 ) / myTotal ); - int h1, h2, s1, s2, v1, v2; - myStartColor.hsv( &h1, &s1, &v1 ); - myEndColor.isValid() ? myEndColor.hsv( &h2, &s2, &v2 ) : - myStartColor.hsv( &h2, &s2, &v2 ); - for ( int i = 0; i < _PROGRESS_WIDTH-1; i++ ) { - painter->setPen( QColor( h1 + ((h2-h1)*i)/(_PROGRESS_WIDTH-2), - s1 + ((s2-s1)*i)/(_PROGRESS_WIDTH-2), - v1 + ((v2-v1)*i)/(_PROGRESS_WIDTH-2), - QColor::Hsv ) ); - painter->drawLine( r.x()+6, - r.height()-5-_PROGRESS_WIDTH+1+i, - r.x()+6+ng-1, - r.height()-5-_PROGRESS_WIDTH+1+i ); - } - } - } - // draw status - if ( !myMessage.isEmpty() ) { - QFontMetrics f( font() ); - int spacing = f.lineSpacing(); - int shift = myTotal > 0 ? _PROGRESS_WIDTH : _PROGRESS_WIDTH; // : 0 - int i = myMessage.length() - 1; - while( i >= 0 && myMessage[ i-- ] == '\n' ) - shift += spacing; - QRect r1( r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10 - shift ); - QRect r2 = r1; - if ( myAlignment & Qt::AlignLeft ) r2.setLeft ( r2.left() + 1 ); - if ( myAlignment & Qt::AlignTop ) r2.setTop ( r2.top() + 1 ); - if ( myAlignment & Qt::AlignRight ) r2.setRight ( r2.right() + 1 ); - if ( myAlignment & Qt::AlignBottom ) r2.setBottom( r2.bottom() + 1 ); - if ( myShadowColor.isValid() ) { - painter->setPen( myShadowColor ); - painter->drawText( r2, myAlignment, myMessage ); - } - painter->setPen( myColor ); - painter->drawText( r1, myAlignment, myMessage ); - } -} - -/*! - Mouse press event. - Hides splash screen if the 'hide on mouse click' flag is set. - \sa setHideOnClick() -*/ -void QtxSplash::mousePressEvent( QMouseEvent* ) -{ - if ( myHideOnClick ) - hide(); -} - -/*! - Processes custom event sent by setStatus() method. - \sa setStatus(). -*/ -void QtxSplash::customEvent( QCustomEvent* ce ) -{ - if ( ce->type() == ProgressEvent::id() ) { - ProgressEvent* pe = (ProgressEvent*)ce; - pe->message().isEmpty() ? clear() : message( pe->message() ); - setProgress( pe->progress() ); - qApp->processEvents(); - } -} - -/*! - Draws the splash screen window [ internal ]. -*/ -void QtxSplash::drawContents() -{ - QPixmap textPix = myPixmap; - QPainter painter( &textPix, this ); - drawContents( &painter ); - setErasePixmap( textPix ); -} - -/*! - Sets error code [ internal ]. -*/ -void QtxSplash::setError( const int code ) -{ - myError = code; -} diff --git a/src/Qtx/QtxSplash.h b/src/Qtx/QtxSplash.h deleted file mode 100644 index b6ade167c..000000000 --- a/src/Qtx/QtxSplash.h +++ /dev/null @@ -1,114 +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: QtxSplash.h -// Author: Vadim SANDLER - -#ifndef QTXSPLASH_H -#define QTXSPLASH_H - -#include "Qtx.h" - -#include -#include - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxSplash : public QWidget -{ - Q_OBJECT - -private: - QtxSplash( const QPixmap& = QPixmap() ); - -public: - enum { Horizontal, Vertical }; - - virtual ~QtxSplash(); - - static QtxSplash* splash( const QPixmap& = QPixmap() ); - static void setStatus( const QString&, const int = 0 ); - static void error( const QString&, const QString& = QString::null, const int = -1 ); - - void setPixmap( const QPixmap& ); - QPixmap pixmap() const; - - void setHideOnClick( const bool ); - bool hideOnClick() const; - - void setTotalSteps( const int ); - int totalSteps() const; - void setProgress( const int ); - int progress() const; - void setProgress( const int, const int ); - void setProgressColors( const QColor&, - const QColor& = QColor(), - const int = Vertical ); - int progressColors( QColor&, QColor& ); - - void setTextAlignment( const int ); - int textAlignment() const; - - void setTextColor( const QColor& ); - QColor textColor() const; - void setTextColors( const QColor&, const QColor& = QColor() ); - void textColors( QColor&, QColor& ) const; - - QString message() const; - - int error() const; - - void finish( QWidget* ); - void repaint(); - -public slots: - void message( const QString&, - const int, - const QColor& = white ); - void message( const QString& ); - void clear(); - -protected: - virtual void mousePressEvent( QMouseEvent* ); - virtual void customEvent( QCustomEvent* ); - virtual void drawContents( QPainter* ); - -private: - void drawContents(); - void setError( const int ); - -private: - static QtxSplash* mySplash; - - QPixmap myPixmap; - QString myMessage; - int myAlignment; - QColor myColor; - QColor myShadowColor; - bool myHideOnClick; - int myProgress; - int myTotal; - QColor myStartColor; - QColor myEndColor; - int myGradientType; - int myError; -}; - -#endif diff --git a/src/Qtx/QtxStdOperations.cxx b/src/Qtx/QtxStdOperations.cxx deleted file mode 100644 index 8e0a33e01..000000000 --- a/src/Qtx/QtxStdOperations.cxx +++ /dev/null @@ -1,833 +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 "QtxStdOperations.h" - -#include -#include - -/*! - Default constructor -*/ -QtxStdOperations::QtxStdOperations() -{ -} - -/*! - Destructor -*/ -QtxStdOperations::~QtxStdOperations() -{ -} - -/*! - Fills list of brackets treated as open (when 'open' is 'true') or close ('open' is 'false') -*/ -void QtxStdOperations::bracketsList( QStringList& list, bool open ) const -{ - if( open ) - list.append( "(" ); - else - list.append( ")" ); -} - -/*! - Fills list with operation names by copying of internal list of operations -*/ -void QtxStdOperations::opersList( QStringList& list ) const -{ - list += myOpers; -} - -/*! - Add operation names from list to internal list of operations -*/ -void QtxStdOperations::addOperations( const QStringList& list ) -{ - QStringList::const_iterator anIt = list.begin(), - aLast = list.end(); - for( ; anIt!=aLast; anIt++ ) - if( myOpers.contains( *anIt )==0 ) - myOpers.append( *anIt ); -} - -/*! - Append operation names from 'list' to internal list of operations -*/ -void QtxStdOperations::addTypes( const ListOfTypes& list ) -{ - ListOfTypes::const_iterator anIt = list.begin(), - aLast = list.end(); - for( ; anIt!=aLast; anIt++ ) - if( myTypes.contains( *anIt )==0 ) - myTypes.append( *anIt ); -} - -/*! - \return whether values with passed types are valid for arguments of operation - \param op - name of operation - \param t1 - type of first argument - \param t2 - type of second argument -*/ -QtxParser::Error QtxStdOperations::isValid( const QString& op, - const QVariant::Type t1, - const QVariant::Type t2 ) const -{ - if( ( t1==QVariant::Invalid || myTypes.contains( t1 ) ) && - ( t2==QVariant::Invalid || myTypes.contains( t2 ) ) && - ( t1!=QVariant::Invalid || t2!=QVariant::Invalid ) ) - if( prior( op, t1!=QVariant::Invalid && t2!=QVariant::Invalid ) > 0 ) - return QtxParser::OK; - else - return QtxParser::InvalidOperation; - else - return QtxParser::OperandsNotMatch; -} - - - - - - - - -/*! - Default constructor -*/ -QtxArithmetics::QtxArithmetics() -: QtxStdOperations() -{ - QStringList aList; - aList.append( "+" ); - aList.append( "-" ); - aList.append( "*" ); - aList.append( "/" ); - aList.append( "=" ); - aList.append( "<" ); - aList.append( ">" ); - aList.append( "<=" ); - aList.append( ">=" ); - aList.append( "<>" ); - aList.append( "!=" ); // same as "<>" - for C++ addicts - addOperations( aList ); - - ListOfTypes aTypes; - aTypes.append( QVariant::Int ); - aTypes.append( QVariant::UInt ); - aTypes.append( QVariant::Double ); - addTypes( aTypes ); -} - -/*! - Destructor -*/ -QtxArithmetics::~QtxArithmetics() -{ -} - -/*! - Creates numbers by it's string representation [redefined virtual] -*/ -bool QtxArithmetics::createValue( const QString& str, QtxValue& v ) const -{ - bool ok = false; - v = str.toInt( &ok ); - - if( !ok ) - { - v = str.toDouble( &ok ); - if( !ok ) - ok = QtxStdOperations::createValue( str, v ); - } - return ok; -} - -/*! - \return priority of arithmetic operation 'op'. - \param isBin indicate whether the operation is binary -*/ -int QtxArithmetics::prior( const QString& op, bool isBin ) const -{ - if( isBin ) - if( op=="<" || op==">" || op=="=" || - op=="<=" || op==">=" || op=="<>" || op=="!=" ) - return 1; - else if( op=="+" || op=="-" ) - return 2; - else if( op=="*" || op=="/" ) - return 3; - else - return 0; - else if( op=="+" || op=="-" ) - return 5; - else - return 0; -} - -void set( QVariant& v1, bool v2 ) -{ - v1 = QVariant( v2, 0 ); -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxArithmetics::calculate( const QString& op, - QtxValue& v1, QtxValue& v2 ) const -{ - QtxParser::Error err = QtxParser::OK; - - if( v1.isValid() && v2.isValid() ) - // binary operations - if( ( v1.type()==QVariant::Int || v1.type()==QVariant::UInt ) && - ( v2.type()==QVariant::Int || v2.type()==QVariant::UInt ) ) - { - int _v1 = v1.toInt(), - _v2 = v2.toInt(); - - if( op=="+" ) - v1 = _v1 + _v2; - else if( op=="-" ) - v1 = _v1 - _v2; - else if( op=="*" ) - v1 = _v1 * _v2; - else if( op=="/" ) - if( _v2!=0 ) - if( _v1%_v2==0 ) - v1 = _v1 / _v2; - else - v1 = double( _v1 ) / double( _v2 ); - else - err = QtxParser::InvalidResult; - else if( op=="<" ) - set( v1, _v1<_v2 ); - else if( op==">" ) - set( v1, _v1>_v2 ); - else if( op=="=" ) - set( v1, _v1==_v2 ); - else if( op=="<=" ) - set( v1, _v1<=_v2 ); - else if( op==">=" ) - set( v1, _v1>=_v2 ); - else if( op=="<>" || op=="!=" ) - set( v1, _v1!=_v2 ); - } - else if( ( v1.type()==QVariant::Int || v1.type()==QVariant::Double ) && - ( v2.type()==QVariant::Int || v2.type()==QVariant::Double ) ) - { - double _v1 = v1.toDouble(), - _v2 = v2.toDouble(); - - if( op=="+" ) - v1 = _v1 + _v2; - else if( op=="-" ) - v1 = _v1 - _v2; - else if( op=="*" ) - v1 = _v1 * _v2; - else if( op=="/" ) - if( _v2!=0 ) - v1 = _v1 / _v2; - else - err = QtxParser::InvalidResult; - else if( op=="<" ) - set( v1, _v1<_v2 ); - else if( op==">" ) - set( v1, _v1>_v2 ); - else if( op=="=" ) - set( v1, _v1==_v2 ); - else if( op=="<=" ) - set( v1, _v1<=_v2 ); - else if( op==">=" ) - set( v1, _v1>=_v2 ); - else if( op=="<>" || op=="!=" ) - set( v1, _v1!=_v2 ); - } - else - // prefix operations - if( op=="-" ) - if( v2.type()==QVariant::Int ) - v2 = -v2.toInt(); - else if( v2.type()==QVariant::Double ) - v2 = -v2.toDouble(); - - return err; -} - - - - - - - - - - - -/*! - Default constructor -*/ -QtxLogic::QtxLogic() -: QtxStdOperations() -{ - QStringList aList; - aList.append( "and" ); - aList.append( "&&" ); - aList.append( "or" ); - aList.append( "||" ); - aList.append( "xor" ); - aList.append( "not" ); - aList.append( "!" ); - aList.append( "imp" ); - aList.append( "=" ); - addOperations( aList ); - - ListOfTypes aTypes; - aTypes.append( QVariant::Bool ); - aTypes.append( QVariant::Int ); - aTypes.append( QVariant::UInt ); - addTypes( aTypes ); -} - -/*! - Destructor -*/ -QtxLogic::~QtxLogic() -{ -} - -/*! - Creates value 'true' or 'false' it's string representation [redefined virtual] -*/ -bool QtxLogic::createValue( const QString& str, QtxValue& v ) const -{ - bool ok = true; - if( str.lower()=="true" ) - v = QtxValue( true, 0 ); - else if( str.lower()=="false" ) - v = QtxValue( false, 0 ); - else - ok = QtxStdOperations::createValue( str, v ); - - return ok; -} - -/*! - \return priority of arithmetic operation 'op'. - \param isBin indicate whether the operation is binary -*/ -int QtxLogic::prior( const QString& op, bool isBin ) const -{ - if( isBin ) - if( op=="and" || op=="or" || op=="xor" || - op=="&&" || op=="||" || - op=="imp" ) - return 1; - else if( op=="=" ) - return 2; - else - return 0; - else if( op=="not" || op=="!" ) - return 5; - else - return 0; -} - -bool boolean_value( const QtxValue& v ) -{ - if( v.type()==QVariant::Bool ) - return v.toBool(); - else if( v.type()==QVariant::Int ) - return v.toInt()!=0; - else if( v.type()==QVariant::UInt ) - return v.toUInt()!=0; - else - return false; -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxLogic::calculate( const QString& op, - QtxValue& v1, QtxValue& v2 ) const -{ - QtxParser::Error err = QtxParser::OK; - bool val1 = boolean_value( v1 ), - val2 = boolean_value( v2 ); - if( v1.isValid() && v2.isValid() ) - { - if( op=="and" || op=="&&" ) - set( v1, val1 && val2 ); - else if( op=="or" || op=="||" ) - set( v1, val1 || val2 ); - else if( op=="xor" ) - set( v1, ( !val1 && val2 ) || ( val1 && !val2 ) ); - else if( op=="imp" ) - set( v1, !val1 || val2 ); - else if( op=="=" ) - set( v1, val1==val2 ); - } - else - if( op=="not" || op=="!" ) - set( v2, !val2 ); - - return err; -} - - - - - - -/*! - Default constructor -*/ -QtxFunctions::QtxFunctions() -: QtxStdOperations() -{ - QStringList aList; - aList.append( "sqrt" ); - aList.append( "abs" ); - aList.append( "sin" ); - aList.append( "cos" ); - aList.append( "rad2grad" ); - aList.append( "grad2rad" ); - addOperations( aList ); - - ListOfTypes aTypes; - aTypes.append( QVariant::Int ); - aTypes.append( QVariant::Double ); - addTypes( aTypes ); -} - -/*! - Destructor -*/ -QtxFunctions::~QtxFunctions() -{ -} - -/*! - Creates numbers by it's string representation [redefined virtual] -*/ -bool QtxFunctions::createValue( const QString& str, QtxValue& v ) const -{ - bool ok = false; - v = str.toInt( &ok ); - - if( !ok ) - { - v = str.toDouble( &ok ); - if( !ok ) - ok = QtxStdOperations::createValue( str, v ); - } - return ok; -} - -/*! - \return priority of arithmetic operation 'op'. - \param isBin indicate whether the operation is binary -*/ -int QtxFunctions::prior( const QString& op, bool isBin ) const -{ - if( isBin ) - return 0; - else if( op=="sqrt" || op=="abs" || op=="sin" || op=="cos" || - op=="rad2grad" || op=="grad2rad" ) - return 1; - else - return 0; -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxFunctions::calculate( const QString& op, - QtxValue& v1, QtxValue& v2 ) const -{ - QtxParser::Error err = QtxParser::OK; - double val = v2.toDouble(); - if( op=="sqrt" ) - if( val>=0 ) - v2 = sqrt( val ); - else - err = QtxParser::InvalidResult; - else if( op=="abs" ) - if( v2.type()==QVariant::Int ) - v2 = abs( v2.toInt() ); - else - v2 = fabs( v2.toDouble() ); - else if( op=="sin" ) - v2 = sin( val ); - else if( op=="cos" ) - v2 = cos( val ); - else if( op=="grad2rad" ) - v2 = val * 3.14159256 / 180.0; - else if( op=="rad2grad" ) - v2 = val * 180.0 / 3.14159256; - - return err; -} - - - - - - - - -/*! - Default constructor -*/ -QtxStrings::QtxStrings() -: QtxStdOperations() -{ - QStringList aList; - aList.append( "+" ); - aList.append( "=" ); - aList.append( "<" ); - aList.append( ">" ); - aList.append( "<=" ); - aList.append( ">=" ); - aList.append( "<>" ); - aList.append( "!=" ); // same as "<>" - for C++ addicts - aList.append( "length" ); - aList.append( "lower" ); - aList.append( "upper" ); - addOperations( aList ); - - ListOfTypes aTypes; - aTypes.append( QVariant::Int ); - aTypes.append( QVariant::Double ); - aTypes.append( QVariant::String ); - aTypes.append( QVariant::CString ); - addTypes( aTypes ); -} - - -/*! - Destructor -*/ -QtxStrings::~QtxStrings() -{ -} - -/*! - Creates string QtxValue by it's Qt string representation [redefined virtual] -*/ -bool QtxStrings::createValue( const QString& str, QtxValue& v ) const -{ - QChar st = str[0], - fin = str[ ( int )( str.length()-1 ) ]; - if( st=="'" && fin=="'" ) - { - v = str.mid( 1, str.length()-2 ); - return true; - } - else - return QtxStdOperations::createValue( str, v ); -} - -/*! - \return priority of arithmetic operation 'op'. - \param isBin indicate whether the operation is binary -*/ -int QtxStrings::prior( const QString& op, bool isBin ) const -{ - if( isBin ) - if( op=="+" ) - return 2; - else if( op=="=" || op=="<" || op==">" || - op=="<=" || op==">=" || op=="<>" || op=="!=" ) - return 1; - else - return 0; - else - if( op=="length" || op=="lower" || op=="upper" ) - return 5; - else - return 0; -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxStrings::calculate( const QString& op, - QtxValue& v1, QtxValue& v2 ) const -{ - QtxParser::Error err = QtxParser::OK; - if( v1.isValid() && v2.isValid() ) - { - QString _v1 = v1.toString(), - _v2 = v2.toString(); - if( op=="+" ) - v1 = _v1 + _v2; - else if( op=="=" ) - set( v1, _v1==_v2 ); - else if( op=="<" ) - set( v1, _v1<_v2 ); - else if( op==">" ) - set( v1, _v1>_v2 ); - else if( op=="<>" || op=="!=" ) - set( v1, _v1!=_v2 ); - else if( op=="<=" ) - set( v1, _v1<_v2 || _v1==_v2 ); - else if( op==">=" ) - set( v1, _v1>_v2 || _v1==_v2 ); - } - else if( !v1.isValid() && v2.isValid() ) - { - QString val = v2.toString(); - if( op=="length" ) - v2 = ( int )val.length(); - else if( op=="lower" ) - v2 = val.lower(); - else if( op=="upper" ) - v2 = val.upper(); - } - - return err; -} - - - - - - -/*! - Default constructor -*/ -QtxSets::QtxSets() -{ - QStringList aList; - aList.append( "{" ); - aList.append( "}" ); - aList.append( "=" ); - aList.append( "<>" ); - aList.append( "!=" ); // same as "<>" - for C++ addicts - aList.append( "+" ); - aList.append( "-" ); - aList.append( "*" ); - aList.append( "in" ); - aList.append( "count" ); - addOperations( aList ); - - ListOfTypes aTypes; - aTypes.append( QVariant::List ); - addTypes( aTypes ); -} - -/*! - Destructor -*/ -QtxSets::~QtxSets() -{ -} - -/*! - Fills list of brackets treated as open (when 'open' is 'true') or close ('open' is 'false') -*/ -void QtxSets::bracketsList( QStringList& list, bool open ) const -{ - if( open ) - list.append( "{" ); - else - list.append( "}" ); - QtxStdOperations::bracketsList( list, open ); -} - -/*! - Creates set of QtxValues by their string representation [redefined virtual] -*/ -bool QtxSets::createValue( const QString& str, QtxValue& val ) const -{ - return QtxStdOperations::createValue( str, val ); -} - -/*! - \return priority of arithmetic operation 'op'. - \param isBin indicate whether the operation is binary -*/ -int QtxSets::prior( const QString& op, bool isBin ) const -{ - if( isBin ) - if( op=="=" || op=="<>" || op=="!=" ) - return 1; - else if( op=="+" || op=="-" || op=="*" ) - return 2; - else if( op=="in" ) - return 3; - else - return 0; - - else - if( op=="{" || op=="}" ) - return 5; - else if( op=="count" ) - return 4; - else - return 0; -} - -/*! - \return whether values with passed types are valid for arguments of operation - \param op - name of operation - \param t1 - type of first argument - \param t2 - type of second argument -*/ -QtxParser::Error QtxSets::isValid( const QString& op, - const QVariant::Type t1, - const QVariant::Type t2 ) const -{ - if( op=="{" ) - return QtxParser::OK; - else if( op=="in" ) - if( t1!=QVariant::Invalid && t2==QVariant::List ) - return QtxParser::OK; - else - return QtxParser::OperandsNotMatch; - else - return QtxStdOperations::isValid( op, t1, t2 ); -} - -/*! - Adds new value 'v' to set 'set' [static] -*/ -void QtxSets::add( ValueSet& set, const QtxValue& v ) -{ - if( v.isValid() && set.contains( v )==0 ) - set.append( v ); -} - -/*! - Adds values from set 's2' to set 's1' -*/ -void QtxSets::add( ValueSet& s1, const ValueSet& s2 ) -{ - ValueSet::const_iterator anIt = s2.begin(), - aLast = s2.end(); - for( ; anIt!=aLast; anIt++ ) - add( s1, *anIt ); -} - -/*! - Removes value 'v' from set 'set' -*/ -void QtxSets::remove( ValueSet& set, const QtxValue& v ) -{ - set.remove( v ); -} - -/*! - Removes values of set 's2' from set 's1' -*/ -void QtxSets::remove( ValueSet& s1, const ValueSet& s2 ) -{ - ValueSet::const_iterator anIt = s2.begin(), - aLast = s2.end(); - for( ; anIt!=aLast; anIt++ ) - s1.remove( *anIt ); -} - -/*! - Calculates result of operation - \return one of error states - \param op - name of operation - \param v1 - first operation argument (must be used also to store result) - \param v2 - second operation argument -*/ -QtxParser::Error QtxSets::calculate( const QString& op, QtxValue& v1, QtxValue& v2 ) const -{ - QtxParser::Error err = QtxParser::OK; - - if( op!="{" ) - if( op=="}" ) - { - ValueSet aNewList; - add( aNewList, v1.toList() ); - v1 = aNewList; - } - - else if( op=="=" || op=="<>" || op=="!=" || op=="+" || op=="-" || op=="*" ) - { - ValueSet aNewList; - add( aNewList, v1.toList() ); - - if( op=="=" || op=="<>" || op=="!=" || op=="-" ) - { - remove( aNewList, v2.toList() ); - - if( op=="=" ) - set( v1, aNewList.isEmpty() && v1.toList().count()==v2.toList().count() ); - else if( op=="<>" || op=="!=" ) - set( v1, !aNewList.isEmpty() || v1.toList().count()!=v2.toList().count() ); - else - v1 = aNewList; - } - else if( op=="+" ) - { - add( aNewList, v2.toList() ); - v1 = aNewList; - } - else if( op=="*" ) - { - ValueSet toDelete; - add( toDelete, aNewList ); - remove( toDelete, v2.toList() ); - remove( aNewList, toDelete ); - v1 = aNewList; - } - } - else if( op=="count" ) - v2 = ( int )v2.toList().count(); - else if( op=="in" ) - { - if( v1.type()==QVariant::List ) - { - bool res = true; - ValueSet::const_iterator anIt = v1.toList().begin(), - aLast = v1.toList().end(); - for( ; anIt!=aLast && res; anIt++ ) - res = v2.toList().contains( *anIt )>0; - - set( v1, res ); - } - else - { - const QValueList< QVariant >& list = v2.toList(); - v1 = ( bool )( list.find( v1 )!=list.end() ); - } - } - - return err; -} diff --git a/src/Qtx/QtxStdOperations.h b/src/Qtx/QtxStdOperations.h deleted file mode 100644 index 3631d7b95..000000000 --- a/src/Qtx/QtxStdOperations.h +++ /dev/null @@ -1,144 +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: QtxStdOperations.h -// Author: Alexander SOLOVYOV - -#ifndef __QTX_STD_OPERATIONS_HEADER__ -#define __QTX_STD_OPERATIONS_HEADER__ - -#include "Qtx.h" -#include "QtxOperations.h" - -/*! - \class QtxStdOperations - Provides simplified interface for standard operations. - Conatins list of operation names, priority and possible types -*/ -class QTX_EXPORT QtxStdOperations : public QtxOperations -{ -public: - QtxStdOperations(); - virtual ~QtxStdOperations(); - - virtual void opersList( QStringList& ) const; - virtual void bracketsList( QStringList&, bool open ) const; - - virtual QtxParser::Error isValid( const QString&, - const QVariant::Type, - const QVariant::Type ) const; -protected: - typedef QValueList< QVariant::Type > ListOfTypes; - - void addOperations( const QStringList& ); - void addTypes( const ListOfTypes& ); - -private: - QStringList myOpers; - ListOfTypes myTypes; -}; - -/*! - \class QtxArithmetics - Provides set of arithmetic operations for parser -*/ -class QTX_EXPORT QtxArithmetics : public QtxStdOperations -{ -public: - QtxArithmetics(); - virtual ~QtxArithmetics(); - - virtual bool createValue( const QString&, QtxValue& ) const; - virtual int prior( const QString&, bool isBin ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; -}; - -/*! - \class QtxLogic - Provides set of logic operations for parser -*/ -class QTX_EXPORT QtxLogic : public QtxStdOperations -{ -public: - QtxLogic(); - virtual ~QtxLogic(); - - virtual bool createValue( const QString&, QtxValue& ) const; - virtual int prior( const QString&, bool isBin ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; -}; - -/*! - \class QtxFunctions - Provides set of more complex operations for parser (sqrt, sin, cos, etc) -*/ -class QTX_EXPORT QtxFunctions : public QtxStdOperations -{ -public: - QtxFunctions(); - virtual ~QtxFunctions(); - - virtual bool createValue( const QString&, QtxValue& ) const; - virtual int prior( const QString&, bool isBin ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; -}; - -/*! - \class QtxStrings - Provides set of string operations for parser -*/ -class QTX_EXPORT QtxStrings : public QtxStdOperations -{ -public: - QtxStrings(); - virtual ~QtxStrings(); - - virtual bool createValue( const QString&, QtxValue& ) const; - virtual int prior( const QString&, bool isBin ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; -}; - -/*! - \class QtxSets - Provides set of operations with sets for parser -*/ -class QTX_EXPORT QtxSets : public QtxStdOperations -{ -public: - typedef QValueList< QtxValue > ValueSet; - -public: - QtxSets(); - virtual ~QtxSets(); - - virtual void bracketsList( QStringList&, bool open ) const; - virtual bool createValue( const QString&, QtxValue& ) const; - virtual int prior( const QString&, bool isBin ) const; - virtual QtxParser::Error isValid( const QString&, - const QVariant::Type, - const QVariant::Type ) const; - virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; - - static void add( ValueSet&, const QtxValue& ); - static void add( ValueSet&, const ValueSet& ); - static void remove( ValueSet&, const QtxValue& ); - static void remove( ValueSet&, const ValueSet& ); -}; - - -#endif diff --git a/src/Qtx/QtxTable.cxx b/src/Qtx/QtxTable.cxx deleted file mode 100644 index 1f7c0be55..000000000 --- a/src/Qtx/QtxTable.cxx +++ /dev/null @@ -1,398 +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: QtxTable.cxx -// Author: Sergey TELKOV - -#include "QtxTable.h" - -#ifndef QT_NO_TABLE - -#include - -/*! - Constructor -*/ -QtxTable::QtxTable( QWidget* parent, const char* name ) -: QTable( parent, name ), -myHeaderEditor( 0 ), -myEditedHeader( 0 ), -myEditedSection( -1 ) -{ - connect( verticalHeader(), SIGNAL( sizeChange( int, int, int ) ), - this, SLOT( onHeaderSizeChange( int, int, int ) ) ); - connect( horizontalHeader(), SIGNAL( sizeChange( int, int, int ) ), - this, SLOT( onHeaderSizeChange( int, int, int ) ) ); - connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); - connect( horizontalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); -} - -/*! - Constructor -*/ -QtxTable::QtxTable( int numRows, int numCols, QWidget* parent, const char* name ) -: QTable( numRows, numCols, parent, name ), -myHeaderEditor( 0 ), -myEditedHeader( 0 ), -myEditedSection( -1 ) -{ - connect( verticalHeader(), SIGNAL( sizeChange( int, int, int ) ), - this, SLOT( onHeaderSizeChange( int, int, int ) ) ); - connect( horizontalHeader(), SIGNAL( sizeChange( int, int, int ) ), - this, SLOT( onHeaderSizeChange( int, int, int ) ) ); - connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); - connect( horizontalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( onScrollBarMoved( int ) ) ); -} - -/*! - Destructor -*/ -QtxTable::~QtxTable() -{ -} - -/*! - \return true if header is editable - \param o - header orientation -*/ -bool QtxTable::headerEditable( Orientation o ) const -{ - return myHeaderEditable.contains( o ) ? myHeaderEditable[o] : false; -} - -/*! - Changes editable state of header - \param o - header orientation - \param on - new state -*/ -void QtxTable::setHeaderEditable( Orientation o, const bool on ) -{ - if ( headerEditable( o ) == on ) - return; - - myHeaderEditable.insert( o, on ); - - QHeader* hdr = header( o ); - - if ( !on && myEditedHeader == hdr ) - endHeaderEdit( false ); - - if ( on ) - hdr->installEventFilter( this ); - else - hdr->removeEventFilter( this ); -} - -/*! - Starts edition of header - \param o - header orientation - \param sec - column/row -*/ -bool QtxTable::editHeader( Orientation o, const int sec ) -{ - return beginHeaderEdit( o, sec ); -} - -/*! - Finishes edition of header - \param accept - whether new value must be accepted -*/ -void QtxTable::endEditHeader( const bool accept ) -{ - endHeaderEdit( accept ); -} - -/*! - Finishes edition and hides table -*/ -void QtxTable::hide() -{ - endHeaderEdit(); - - QTable::hide(); -} - -/*! - Custom event filter - Starts edition of header by double click - Finishes edition by escape/return/enter pressing -*/ -bool QtxTable::eventFilter( QObject* o, QEvent* e ) -{ - if ( e->type() == QEvent::MouseButtonDblClick ) - { - QMouseEvent* me = (QMouseEvent*)e; - if ( o == horizontalHeader() ) - { - beginHeaderEdit( Horizontal, me->pos() ); - return true; - } - else if ( o == verticalHeader() ) - { - beginHeaderEdit( Vertical, me->pos() ); - return true; - } - } - - if ( o == myHeaderEditor && e->type() == QEvent::KeyPress && isHeaderEditing() ) - { - QKeyEvent* ke = (QKeyEvent*)e; - if ( ke->key() == Key_Escape ) - { - endHeaderEdit( false ); - return true; - } - - if ( ke->key() == Key_Return || ke->key() == Key_Enter ) - { - endHeaderEdit( true ); - return true; - } - - return false; - } - - if ( o == myHeaderEditor && e->type() == QEvent::FocusOut && - isHeaderEditing() && ((QFocusEvent*)e)->reason() != QFocusEvent::Popup ) - { - endHeaderEdit(); - return true; - } - - if ( e->type() == QEvent::Wheel && isHeaderEditing() ) - return true; - - return QTable::eventFilter( o, e ); -} - -/*! - SLOT: called on scroll -*/ -void QtxTable::onScrollBarMoved( int ) -{ - updateHeaderEditor(); -} - -/*! - SLOT: called on header size changing -*/ -void QtxTable::onHeaderSizeChange( int, int, int ) -{ - if ( sender() == myEditedHeader ) - updateHeaderEditor(); -} - -/*! - Custom resize event handler -*/ -void QtxTable::resizeEvent( QResizeEvent* e ) -{ - QTable::resizeEvent( e ); - - updateHeaderEditor(); -} - -/*! - Starts edition of header - \param o - header orientation - \param sec - column/row -*/ -bool QtxTable::beginHeaderEdit( Orientation o, const int section ) -{ - if ( !headerEditable( o ) || !header( o ) || !header( o )->isVisibleTo( this ) ) - return false; - - endHeaderEdit(); - - QHeader* hdr = header( o ); - - QRect r = headerSectionRect( hdr, section ); - if ( !r.isValid() ) - return false; - - if ( o == Horizontal ) - r.setLeft( QMAX( r.left(), leftMargin() ) ); - else - r.setTop( QMAX( r.top(), topMargin() ) ); - - myHeaderEditor = createHeaderEditor( hdr, section ); - if ( !myHeaderEditor ) - return false; - - myEditedHeader = hdr; - myEditedSection = section; - - myHeaderEditor->reparent( this, QPoint( 0, 0 ), false ); - - updateHeaderEditor(); - - myHeaderEditor->show(); - - myHeaderEditor->setActiveWindow(); - myHeaderEditor->setFocus(); - - myHeaderEditor->installEventFilter( this ); - - return true; -} - -/*! - Finishes edition of header - \param accept - whether new value must be accepted -*/ -void QtxTable::endHeaderEdit( const bool accept ) -{ - if ( !isHeaderEditing() ) - return; - - QString oldTxt = myEditedHeader ? myEditedHeader->label( myEditedSection ) : QString::null; - - if ( accept && myEditedHeader ) - setHeaderContentFromEditor( myEditedHeader, myEditedSection, myHeaderEditor ); - - QString newTxt = myEditedHeader ? myEditedHeader->label( myEditedSection ) : QString::null; - - int sec = myEditedSection; - QHeader* hdr = myEditedHeader; - - myEditedHeader = 0; - myEditedSection = -1; - - myHeaderEditor->hide(); - myHeaderEditor->deleteLater(); - myHeaderEditor = 0; - - if ( oldTxt != newTxt ) - { - emit headerEdited( hdr, sec ); - emit headerEdited( hdr == horizontalHeader() ? Horizontal : Vertical, sec ); - } -} - -/*! - \return true if header is being edited -*/ -bool QtxTable::isHeaderEditing() const -{ - return myHeaderEditor && myEditedHeader && myEditedSection != -1; -} - -/*! - Creates and \return header editor - \param hdr - header - \param sec - column/row - \param init - init editor with value -*/ -QWidget* QtxTable::createHeaderEditor( QHeader* hdr, const int sec, const bool init ) -{ - QLineEdit* ed = new QLineEdit( 0 ); - - if ( init && hdr ) - ed->setText( hdr->label( sec ) ); - - return ed; -} - -/*! - Initialize editor with value - \param hdr - header - \param sec - column/row - \param editor - editor -*/ -void QtxTable::setHeaderContentFromEditor( QHeader* hdr, const int sec, QWidget* editor ) -{ - if ( !hdr || !editor ) - return; - - if ( editor->inherits( "QLineEdit" ) ) - hdr->setLabel( sec, ((QLineEdit*)editor)->text() ); -} - -/*! - \return header - \param o - orientation -*/ -QHeader* QtxTable::header( Orientation o ) const -{ - return o == Horizontal ? horizontalHeader() : verticalHeader(); -} - -/*! - Starts edition of header - \param o - header orientation - \param p - point -*/ -void QtxTable::beginHeaderEdit( Orientation o, const QPoint& p ) -{ - QHeader* hdr = header( o ); - if ( !hdr ) - return; - - int pos = o == Horizontal ? p.x() : p.y(); - int sec = hdr->sectionAt( hdr->offset() + pos ); - - beginHeaderEdit( o, sec ); -} - -/*! - \return rectangle of header section - \param hdr - header - \param sec - column/row -*/ -QRect QtxTable::headerSectionRect( QHeader* hdr, const int sec ) const -{ - QRect r( -1, -1, -1, -1 ); - - if ( !hdr ) - return r; - - r = hdr->sectionRect( sec ); - if ( r.isValid() ) - r = QRect( mapFromGlobal( hdr->mapToGlobal( r.topLeft() ) ), r.size() ); - - return r; -} - -/*! - Updates header editor -*/ -void QtxTable::updateHeaderEditor() -{ - if ( !myHeaderEditor || !myEditedHeader || myEditedSection < 0 ) - return; - - QRect r = headerSectionRect( myEditedHeader, myEditedSection ); - if ( !r.isValid() ) - return; - - if ( myEditedHeader == horizontalHeader() ) - { - r.setLeft( QMAX( r.left(), leftMargin() ) ); - r.setRight( QMIN( r.right(), width() - rightMargin() - 2 ) ); - } - else - { - r.setTop( QMAX( r.top(), topMargin() ) ); - r.setBottom( QMIN( r.bottom(), height() - bottomMargin() - 2 ) ); - } - - myHeaderEditor->resize( r.size() ); - myHeaderEditor->move( r.topLeft() ); -} - -#endif diff --git a/src/Qtx/QtxTable.h b/src/Qtx/QtxTable.h deleted file mode 100644 index b7175d08e..000000000 --- a/src/Qtx/QtxTable.h +++ /dev/null @@ -1,88 +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: QtxTable.h -// Author: Sergey TELKOV - -#ifndef QTX_TABLE_H -#define QTX_TABLE_H - -#include "Qtx.h" - -#include - -#ifndef QT_NO_TABLE - -class QHeader; - -class QTX_EXPORT QtxTable : public QTable -{ - Q_OBJECT - - class HeaderEditor; - -public: - QtxTable( QWidget* = 0, const char* = 0 ); - QtxTable( int, int, QWidget* = 0, const char* = 0 ); - virtual ~QtxTable(); - - bool headerEditable( Orientation ) const; - - bool editHeader( Orientation, const int ); - void endEditHeader( const bool = true ); - - virtual bool eventFilter( QObject*, QEvent* ); - -signals: - void headerEdited( QHeader*, int ); - void headerEdited( Orientation, int ); - -public slots: - virtual void hide(); - virtual void setHeaderEditable( Orientation, bool ); - -private slots: - void onScrollBarMoved( int ); - void onHeaderSizeChange( int, int, int ); - -protected: - virtual void resizeEvent( QResizeEvent* ); - - virtual bool beginHeaderEdit( Orientation, const int ); - virtual void endHeaderEdit( const bool = true ); - bool isHeaderEditing() const; - virtual QWidget* createHeaderEditor( QHeader*, const int, const bool = true ); - virtual void setHeaderContentFromEditor( QHeader*, const int, QWidget* ); - - QHeader* header( Orientation o ) const; - -private: - void updateHeaderEditor(); - void beginHeaderEdit( Orientation, const QPoint& ); - QRect headerSectionRect( QHeader*, const int ) const; - -private: - QWidget* myHeaderEditor; - QHeader* myEditedHeader; - int myEditedSection; - QMap myHeaderEditable; -}; - -#endif - -#endif diff --git a/src/Qtx/QtxToolBar.cxx b/src/Qtx/QtxToolBar.cxx index cf585db64..f436f68a7 100644 --- a/src/Qtx/QtxToolBar.cxx +++ b/src/Qtx/QtxToolBar.cxx @@ -21,12 +21,11 @@ #include "QtxToolBar.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /*! Class: QtxToolBar::Watcher [Internal] @@ -44,7 +43,7 @@ public: virtual bool eventFilter( QObject*, QEvent* ); protected: - virtual void customEvent( QCustomEvent* ); + virtual void customEvent( QEvent* ); private: enum { Install = QEvent::User, Update }; @@ -55,8 +54,6 @@ private: void showContainer(); void hideContainer(); - void updateIcon(); - void updateCaption(); void updateVisibility(); private: @@ -73,11 +70,12 @@ QtxToolBar::Watcher::Watcher( QtxToolBar* cont ) : QObject( cont ), myCont( cont ), myState( true ), -myEmpty( true ) +myEmpty( false ) { +/* if ( myCont->mainWindow() ) myState = myCont->mainWindow()->appropriate( myCont ); - +*/ myCont->installEventFilter( this ); myVisible = myCont->isVisibleTo( myCont->parentWidget() ); @@ -89,14 +87,8 @@ myEmpty( true ) */ bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e ) { - if ( o == myCont && e->type() == QEvent::ChildInserted ) - QApplication::postEvent( this, new QCustomEvent( Install ) ); - - if ( o != myCont && e->type() == QEvent::IconChange ) - updateIcon(); - - if ( o != myCont && e->type() == QEvent::CaptionChange ) - updateCaption(); + if ( o == myCont && e->type() == QEvent::ChildAdded ) + QApplication::postEvent( this, new QEvent( (QEvent::Type)Install ) ); bool updVis = ( o != myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || @@ -108,7 +100,7 @@ bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e ) myCont = 0; QApplication::sendPostedEvents( this, Update ); myCont = cont; - QApplication::postEvent( this, new QCustomEvent( Update ) ); + QApplication::postEvent( this, new QEvent( (QEvent::Type)Update ) ); } return false; @@ -167,14 +159,12 @@ void QtxToolBar::Watcher::hideContainer() /*! Event handler of custom events */ -void QtxToolBar::Watcher::customEvent( QCustomEvent* e ) +void QtxToolBar::Watcher::customEvent( QEvent* e ) { switch ( e->type() ) { case Install: installFilters(); - updateIcon(); - updateCaption(); case Update: updateVisibility(); } @@ -188,15 +178,11 @@ void QtxToolBar::Watcher::installFilters() if ( !myCont ) return; - const QObjectList* objList = myCont->children(); - if ( !objList ) - return; - - for ( QObjectListIt it( *objList ); it.current(); ++it ) + const QObjectList& objList = myCont->children(); + for ( QObjectList::const_iterator it = objList.begin(); it != objList.end(); ++it ) { - if ( it.current()->isWidgetType() && - qstrcmp( "qt_dockwidget_internal", it.current()->name() ) ) - it.current()->installEventFilter( this ); + if ( (*it)->isWidgetType() && qstrcmp( "qt_dockwidget_internal", (*it)->objectName().toLatin1() ) ) + (*it)->installEventFilter( this ); } } @@ -210,18 +196,18 @@ void QtxToolBar::Watcher::updateVisibility() bool vis = false; - const QObjectList* objList = myCont->children(); - if ( objList ) + const QObjectList& objList = myCont->children(); + for ( QObjectList::const_iterator it = objList.begin(); it != objList.end() && !vis; ++it ) { - for ( QObjectListIt it( *objList ); it.current() && !vis; ++it ) - { - if ( !it.current()->isWidgetType() || - !qstrcmp( "qt_dockwidget_internal", it.current()->name() ) ) - continue; + QObject* obj = *it; + if ( !obj->isWidgetType() || !qstrcmp( "qt_dockwidget_internal", obj->objectName().toLatin1() ) ) + continue; - QWidget* wid = (QWidget*)it.current(); - vis = wid->isVisibleTo( wid->parentWidget() ); - } + if ( obj->inherits( "QToolBarHandle" ) || obj->inherits( "QToolBarExtension" ) ) + continue; + + QWidget* wid = (QWidget*)*it; + vis = wid->isVisibleTo( wid->parentWidget() ); } QMainWindow* mw = myCont->mainWindow(); @@ -229,11 +215,11 @@ void QtxToolBar::Watcher::updateVisibility() { myEmpty = !vis; if ( !myEmpty ) - mw->setAppropriate( myCont, myState ); + myCont->toggleViewAction()->setVisible( myState ); else { - myState = mw->appropriate( myCont ); - mw->setAppropriate( myCont, false ); + myState = myCont->toggleViewAction()->isVisible(); + myCont->toggleViewAction()->setVisible( false ); } } @@ -242,33 +228,11 @@ void QtxToolBar::Watcher::updateVisibility() vis ? showContainer() : hideContainer(); } -/*! - Updates icon -*/ -void QtxToolBar::Watcher::updateIcon() -{ - if ( !myCont || !myCont->widget() ) - return; - - const QPixmap* ico = myCont->widget()->icon(); - myCont->setIcon( ico ? *ico : QPixmap() ); -} - -/*! - Updates caption -*/ -void QtxToolBar::Watcher::updateCaption() -{ - if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() ) - myCont->setCaption( myCont->widget()->caption() ); -} - /*! Constructor */ -QtxToolBar::QtxToolBar( const bool watch, const QString& label, QMainWindow* main, - QWidget* parent, bool newLine, const char* name, WFlags f ) -: QToolBar( label, main, parent, newLine, name, f ), +QtxToolBar::QtxToolBar( const bool watch, const QString& label, QWidget* parent ) +: QToolBar( label, parent ), myWatcher( 0 ), myStretch( false ) { @@ -279,9 +243,8 @@ myStretch( false ) /*! Constructor */ -QtxToolBar::QtxToolBar( const QString& label, QMainWindow* main, - QWidget* parent, bool newLine, const char* name, WFlags f ) -: QToolBar( label, main, parent, newLine, name, f ), +QtxToolBar::QtxToolBar( const QString& label, QWidget* parent ) +: QToolBar( label, parent ), myWatcher( 0 ), myStretch( false ) { @@ -290,8 +253,8 @@ myStretch( false ) /*! Constructor */ -QtxToolBar::QtxToolBar( const bool watch, QMainWindow* main, const char* name ) -: QToolBar( main, name ), +QtxToolBar::QtxToolBar( const bool watch, QWidget* parent ) +: QToolBar( parent ), myWatcher( 0 ), myStretch( false ) { @@ -302,8 +265,8 @@ myStretch( false ) /*! Constructor */ -QtxToolBar::QtxToolBar( QMainWindow* main, const char* name ) -: QToolBar( main, name ), +QtxToolBar::QtxToolBar( QWidget* parent ) +: QToolBar( parent ), myWatcher( 0 ), myStretch( false ) { @@ -316,68 +279,13 @@ QtxToolBar::~QtxToolBar() { } -/*! - Change the toolbar's main widget - \param wid - new main widget -*/ -void QtxToolBar::setWidget( QWidget* wid ) -{ - if ( wid ) - wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) ); - - QToolBar::setWidget( wid ); - - if ( !boxLayout() ) - return; - - for ( QLayoutIterator it = boxLayout()->iterator(); it.current(); ++it ) - { - if ( it.current()->widget() == wid ) - { - it.deleteCurrent(); - break; - } - } -} - -/*! - \return true if toolbar is stretchable -*/ -bool QtxToolBar::isStretchable() const -{ - return myStretch; -} - -/*! - Sets stretchable state of toolbar - \param on - new state -*/ -void QtxToolBar::setStretchable( const bool on ) -{ - if ( myStretch == on ) - return; - - myStretch = on; - - boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 ); - - if ( myStretch != isHorizontalStretchable() || - myStretch != isVerticalStretchable() ) - { - if ( orientation() == Horizontal ) - setHorizontalStretchable( myStretch ); - else - setVerticalStretchable( myStretch ); - } -} - /*! \return the recommended size for the widget */ QSize QtxToolBar::sizeHint() const { QSize sz = QToolBar::sizeHint(); - +/* if ( place() == InDock && isStretchable() && area() ) { if ( orientation() == Horizontal ) @@ -385,7 +293,7 @@ QSize QtxToolBar::sizeHint() const else sz.setHeight( area()->height() ); } - +*/ return sz; } @@ -395,7 +303,7 @@ QSize QtxToolBar::sizeHint() const QSize QtxToolBar::minimumSizeHint() const { QSize sz = QToolBar::minimumSizeHint(); - +/* if ( place() == InDock && isStretchable() && area() ) { if ( orientation() == Horizontal ) @@ -403,28 +311,37 @@ QSize QtxToolBar::minimumSizeHint() const else sz.setHeight( area()->height() ); } - +*/ return sz; } /*! Shows toolbar */ -void QtxToolBar::show() +void QtxToolBar::setVisible( bool visible ) { if ( myWatcher ) - myWatcher->shown( this ); + { + if ( visible ) + myWatcher->shown( this ); + else + myWatcher->hided( this ); + } - QToolBar::show(); + QToolBar::setVisible( visible ); } /*! - Hides toolbar + Returns the main window */ -void QtxToolBar::hide() +QMainWindow* QtxToolBar::mainWindow() const { - if ( myWatcher ) - myWatcher->hided( this ); - - QToolBar::hide(); + QMainWindow* mw = 0; + QWidget* wid = parentWidget(); + while ( !mw && wid ) + { + mw = ::qobject_cast( wid ); + wid = wid->parentWidget(); + } + return mw; } diff --git a/src/Qtx/QtxToolBar.h b/src/Qtx/QtxToolBar.h index 57512f40d..e1757edf3 100644 --- a/src/Qtx/QtxToolBar.h +++ b/src/Qtx/QtxToolBar.h @@ -21,7 +21,7 @@ #include "Qtx.h" -#include +#include class QTX_EXPORT QtxToolBar : public QToolBar { @@ -30,23 +30,19 @@ class QTX_EXPORT QtxToolBar : public QToolBar class Watcher; public: - QtxToolBar( const bool, const QString&, QMainWindow*, QWidget*, bool = false, const char* = 0, WFlags = 0 ); - QtxToolBar( const QString&, QMainWindow*, QWidget*, bool = false, const char* = 0, WFlags = 0 ); - QtxToolBar( const bool, QMainWindow* = 0, const char* = 0 ); - QtxToolBar( QMainWindow* = 0, const char* = 0 ); + QtxToolBar( const bool, const QString&, QWidget* ); + QtxToolBar( const QString&, QWidget* ); + QtxToolBar( const bool, QWidget* = 0 ); + QtxToolBar( QWidget* = 0 ); virtual ~QtxToolBar(); - virtual void setWidget( QWidget* ); - - bool isStretchable() const; - virtual void setStretchable( const bool ); - virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; + QMainWindow* mainWindow() const; + public slots: - virtual void show(); - virtual void hide(); + virtual void setVisible( bool ); private: Watcher* myWatcher; diff --git a/src/Qtx/QtxToolTip.cxx b/src/Qtx/QtxToolTip.cxx deleted file mode 100755 index 530afca6d..000000000 --- a/src/Qtx/QtxToolTip.cxx +++ /dev/null @@ -1,265 +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: QtxToolTip.cxx -// Author: Sergey TELKOV - -#include "QtxToolTip.h" - -#include -#include -#include -#include -#include - -#define TOOLTIP_SHOW_DELAY 0500 -#define TOOLTIP_HIDE_DELAY 7000 - -/*! - Constructor -*/ -QtxToolTip::QtxToolTip( QWidget* parent ) -: QLabel( parent, "", WStyle_Customize | WStyle_NoBorder | WX11BypassWM | WStyle_Tool | WStyle_StaysOnTop | WType_TopLevel ) -{ - setIndent( 3 ); - setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - setBackgroundColor( QColor( 255, 255, 231 ) ); - - myWidgetRegion = QRect( -1, -1, -1, -1 ); - - setFrameShape( QFrame::Panel ); - setFrameShadow( QFrame::Plain ); - - parent->setMouseTracking( true ); - parent->installEventFilter( this ); - installEventFilter( this ); - - mySleepTimer = new QTimer( this ); - myWakeUpTimer = new QTimer( this ); - connect( mySleepTimer, SIGNAL( timeout() ), this, SLOT( onSleepTimeOut() ) ); - connect( myWakeUpTimer, SIGNAL( timeout() ), this, SLOT( onWakeUpTimeOut() ) ); - - myWakeUpDelayTime = 700; - myShowDelayTime = 5000; -} - -/*! - Destructor -*/ -QtxToolTip::~QtxToolTip() -{ -} - -/*! - Custom event filter -*/ -bool QtxToolTip::eventFilter( QObject* o, QEvent* e ) -{ - if ( ( e->type() == QEvent::Destroy ) || ( e->type() == QEvent::Close ) || ( e->type() == QEvent::Hide ) ) - { - hideTip(); - } - if ( e->type() == QEvent::Leave ) - { - if ( isVisible() && ( o == this ) ) - hideTip(); - myWakeUpTimer->stop(); - } - if ( e->type() == QEvent::MouseMove ) - { - QMouseEvent* me = (QMouseEvent*)e; - QPoint thePos = parentWidget()->mapFromGlobal( me->globalPos() ); - if ( myWakeUpTimer->isActive() ) - { - myWakeUpTimer->stop(); - myWakeUpTimer->start( myWakeUpDelayTime, true ); - } - if ( isVisible() ) - { - if ( !myWidgetRegion.contains( thePos ) ) - { - hideTip(); - myWidgetRegion = QRect( -1, -1, -1, -1 ); - } - } - else - { - if ( !myWidgetRegion.isValid() || myWidgetRegion.contains( thePos ) ) - myWakeUpTimer->start( myWakeUpDelayTime, true ); - } - } - if ( e->type() == QEvent::KeyPress ) - { - hideTip(); - } - if ( o == parent() && ( e->type() == QEvent::MouseButtonPress || - e->type() == QEvent::MouseButtonRelease ) ) - { - hideTip(); - } - return false; -} - -/*! - Shows tool tip - \param aPos - position - \param text - tooltip text - \param aWidgetRegion - rectangle -*/ -void QtxToolTip::showTip( const QPoint& aPos, const QString& text, const QRect& aWidgetRegion ) -{ - QFontMetrics theFM = fontMetrics(); - int theHeight = theFM.height(); - int theWidth = theFM.width( text ) + 2; - showTip( QRect( QPoint( aPos.x(), aPos.y() + 10 ), QSize( theWidth, theHeight ) ), text, aWidgetRegion ); -} - -/*! - Shows tool tip - \param aRegion - tooltip region - \param text - tooltip text - \param aWidgetRegion - widget rectangle -*/ -void QtxToolTip::showTip( const QRect& aRegion, const QString& text, const QRect& aWidgetRegion ) -{ - setText( text ); - myWidgetRegion = aWidgetRegion; - setGeometry( aRegion ); - if ( myShowDelayTime != 0 ) - mySleepTimer->start( myShowDelayTime, true ); - show(); -} - -/*! - Hides tooltip -*/ -void QtxToolTip::hideTip() -{ - hide(); - myWidgetRegion = QRect( -1, -1, -1, -1 ); - mySleepTimer->stop(); -} - -/*! - It is called when there is a possibility that a tool tip should be shown and - must decide whether there is a tool tip for the point p in the widget that this QToolTip object relates to - \param pos - position -*/ -void QtxToolTip::maybeTip( const QPoint& pos ) -{ - QString text; - QRect textRegion, theRegion( -1, -1, -1, -1 ); - QFont theFnt = font(); - - emit maybeTip( pos, text, theFnt, textRegion, theRegion ); - - if ( theRegion.isValid() ) - { - setFont( theFnt ); - int margin = lineWidth() + indent(); - QRect dspRegion( QPoint( textRegion.x() - margin, textRegion.y() ), - QSize( textRegion.width() + 2 * margin, textRegion.height() ) ); - QRect tipRegion( parentWidget()->mapToGlobal( dspRegion.topLeft() ), dspRegion.size() ); - if ( tipRegion.left() < 0 ) - tipRegion.moveBy( -1 * tipRegion.left(), 0 ); - showTip( tipRegion, text, theRegion ); - } -} - -/*! - SLOT: called when sleep time is out -*/ -void QtxToolTip::onSleepTimeOut() -{ - mySleepTimer->stop(); - hideTip(); -} - -/*! - SLOT: called when wake time is out -*/ -void QtxToolTip::onWakeUpTimeOut() -{ - myWakeUpTimer->stop(); - QPoint pos = QCursor::pos(); - if ( parentWidget() ) - pos = parentWidget()->mapFromGlobal( pos ); - maybeTip( pos ); -} - -/*! - Custom mouse press event handler -*/ -void QtxToolTip::mousePressEvent( QMouseEvent* e ) -{ - hideTip(); - QWidget* reciever = parentWidget(); - QMouseEvent* me = new QMouseEvent( QEvent::MouseButtonPress, - reciever->mapFromGlobal( e->globalPos() ), - e->button(), e->state() ); - QApplication::sendEvent( reciever, me ); -} - -/*! - Custom mouse double click event handler -*/ -void QtxToolTip::mouseDoubleClickEvent( QMouseEvent* e ) -{ - hideTip(); - QWidget* reciever = parentWidget(); - QMouseEvent* me = new QMouseEvent( QEvent::MouseButtonDblClick, - reciever->mapFromGlobal( e->globalPos() ), - e->button(), e->state() ); - QApplication::sendEvent( reciever, me ); -} - -/*! - Sets wake delay time - \param theTime -*/ -void QtxToolTip::setWakeUpDelayTime( int theTime ) -{ - if( !(theTime < 0) ) - myWakeUpDelayTime = theTime; -} - -/*! - Sets show delay time - \param theTime -*/ -void QtxToolTip::setShowDelayTime( int theTime ) -{ - if( !(theTime < 0) ) - myShowDelayTime = theTime; -} - -/*! - \return timer measuring time of sleeping -*/ -QTimer* QtxToolTip::sleepTimer() const -{ - return mySleepTimer; -} - -/*! - \return timer measuring time of waking up -*/ -QTimer* QtxToolTip::wakeUpTimer() const -{ - return myWakeUpTimer; -} diff --git a/src/Qtx/QtxToolTip.h b/src/Qtx/QtxToolTip.h deleted file mode 100755 index c8b9d704b..000000000 --- a/src/Qtx/QtxToolTip.h +++ /dev/null @@ -1,78 +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: QtxToolTip.h -// Author: Sergey TELKOV - -#ifndef QTXTOOLTIP_H -#define QTXTOOLTIP_H - -#include "Qtx.h" - -#include - -class QTimer; - -class QTX_EXPORT QtxToolTip : public QLabel -{ - Q_OBJECT - -public: - QtxToolTip( QWidget* = 0 ); - virtual ~QtxToolTip(); - - void hideTip(); - - virtual void showTip( const QPoint& aPos, - const QString& text, const QRect& aWidgetRegion ); - virtual void showTip( const QRect& aRegion, - const QString& text, const QRect& aWidgetRegion ); - - virtual bool eventFilter( QObject* o, QEvent* e ); - - void setWakeUpDelayTime( int ); - void setShowDelayTime( int ); - - int wakeUpDelayTime() const { return myWakeUpDelayTime; } - int showDelayTime() const { return myShowDelayTime; } - -signals: - void maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ); - -protected slots: - void onSleepTimeOut(); - void onWakeUpTimeOut(); - -protected: - virtual void maybeTip( const QPoint& ); - virtual void mousePressEvent( QMouseEvent* ); - virtual void mouseDoubleClickEvent( QMouseEvent* ); - - QTimer* sleepTimer() const; - QTimer* wakeUpTimer() const; - -private: - QTimer* myWakeUpTimer; - QTimer* mySleepTimer; - QRect myWidgetRegion; - - int myShowDelayTime; - int myWakeUpDelayTime; -}; - -#endif diff --git a/src/Qtx/QtxWorkspaceAction.cxx b/src/Qtx/QtxWorkspaceAction.cxx deleted file mode 100644 index f06c5c2a4..000000000 --- a/src/Qtx/QtxWorkspaceAction.cxx +++ /dev/null @@ -1,530 +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: QtxWorkspaceAction.cxx -// Author: Sergey TELKOV - -#include "QtxWorkspaceAction.h" - -#include -#include -#include - -/*! - Constructor -*/ -QtxWorkspaceAction::QtxWorkspaceAction( QWorkspace* ws, QObject* parent, const char* name ) -: QtxAction( tr( "Controls windows into workspace" ), tr( "Workspace management" ), 0, parent, name ), -myFlags( Standard ), -myWorkspace( ws ) -{ - myItem.insert( Cascade, new QtxAction( tr( "Arranges the windows as overlapping tiles" ), - tr( "Cascade" ), 0, this, 0, false ) ); - myItem.insert( Tile, new QtxAction( tr( "Arranges the windows as nonoverlapping tiles" ), - tr( "Tile" ), 0, this, 0, false ) ); - myItem.insert( HTile, new QtxAction( tr( "Arranges the windows as nonoverlapping horizontal tiles" ), - tr( "Tile horizontally" ), 0, this, 0, false ) ); - myItem.insert( VTile, new QtxAction( tr( "Arranges the windows as nonoverlapping vertical tiles" ), - tr( "Tile vertically" ), 0, this, 0, false ) ); - - connect( myItem[Tile], SIGNAL( activated() ), this, SLOT( tile() ) ); - connect( myItem[Cascade], SIGNAL( activated() ), this, SLOT( cascade() ) ); - connect( myItem[HTile], SIGNAL( activated() ), this, SLOT( tileVertical() ) ); - connect( myItem[VTile], SIGNAL( activated() ), this, SLOT( tileHorizontal() ) ); -} - -/*! - Destructor -*/ -QtxWorkspaceAction::~QtxWorkspaceAction() -{ -} - -/*! - \return corresponding workspace -*/ -QWorkspace* QtxWorkspaceAction::workspace() const -{ - return myWorkspace; -} - -/*! - \return set of action flags -*/ -int QtxWorkspaceAction::items() const -{ - return myFlags; -} - -/*! - Sets action flags - \param flags - new set of flags -*/ -void QtxWorkspaceAction::setItems( const int flags ) -{ - if ( !flags || flags == myFlags || !( flags & Operations ) ) - return; - - myFlags = flags; -} - -/*! - \return true if action contains all flags - \param flags - new set of flags -*/ -bool QtxWorkspaceAction::hasItems( const int flags ) const -{ - return ( myFlags & flags ) == flags; -} - -/*! - \return accelerator of item - \param id - item id -*/ -int QtxWorkspaceAction::accel( const int id ) const -{ - int a = 0; - if ( myItem.contains( id ) ) - a = myItem[id]->accel(); - return a; -} - -/*! - \return icons of item - \param id - item id -*/ -QIconSet QtxWorkspaceAction::iconSet( const int id ) const -{ - QIconSet ico; - if ( myItem.contains( id ) ) - ico = myItem[id]->iconSet(); - return ico; -} - -/*! - \return menu text of item - \param id - item id -*/ -QString QtxWorkspaceAction::menuText( const int id ) const -{ - QString txt; - if ( myItem.contains( id ) ) - txt = myItem[id]->menuText(); - return txt; -} - -/*! - \return status tip of item - \param id - item id -*/ -QString QtxWorkspaceAction::statusTip( const int id ) const -{ - QString txt; - if ( myItem.contains( id ) ) - txt = myItem[id]->statusTip(); - return txt; -} - -/*! - Changes accelerator of item - \param id - item id - \param a - new accelerator -*/ -void QtxWorkspaceAction::setAccel( const int id, const int a ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setAccel( a ); -} - -/*! - Changes icons of item - \param id - item id - \param ico - new icons -*/ -void QtxWorkspaceAction::setIconSet( const int id, const QIconSet& ico ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setIconSet( ico ); -} - -/*! - Changes menu text of item - \param id - item id - \param txt - new menu text -*/ -void QtxWorkspaceAction::setMenuText( const int id, const QString& txt ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setMenuText( txt ); -} - -/*! - Changes status tip of item - \param id - item id - \param txt - new status tip -*/ -void QtxWorkspaceAction::setStatusTip( const int id, const QString& txt ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setStatusTip( txt ); -} - -/*! - Adds action to widget - \param wid - widget -*/ -bool QtxWorkspaceAction::addTo( QWidget* wid ) -{ - return addTo( wid, -1 ); -} - -/*! - Adds action to widget - \param wid - widget - \param idx - position -*/ -bool QtxWorkspaceAction::addTo( QWidget* wid, const int idx ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - checkPopup( pm ); - - if ( myMenu.contains( pm ) ) - return false; - - myMenu.insert( pm, QIntList() ); - fillPopup( pm, idx ); - - connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - return true; -} - -/*! - Removes action from widget - \param wid - widget -*/ -bool QtxWorkspaceAction::removeFrom( QWidget* wid ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - if ( !myMenu.contains( pm ) ) - return false; - - clearPopup( pm ); - - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - myMenu.remove( pm ); - - return true; -} - -/*! - Performs action - \param type - action type -*/ -void QtxWorkspaceAction::perform( const int type ) -{ - switch ( type ) - { - case Cascade: - cascade(); - break; - case Tile: - tile(); - break; - case VTile: - tileVertical(); - break; - case HTile: - tileHorizontal(); - break; - } -} - -/*! - Performs tile action -*/ -void QtxWorkspaceAction::tile() -{ - QWorkspace* ws = workspace(); - if ( !ws ) - return; - - ws->tile(); -} - -/*! - Performs cascade action -*/ -void QtxWorkspaceAction::cascade() -{ - QWorkspace* ws = workspace(); - if ( !ws ) - return; - - ws->cascade(); - - int w = ws->width(); - int h = ws->height(); - - QWidgetList winList = ws->windowList(); - for ( QWidgetListIt it( winList ); it.current(); ++it ) - it.current()->resize( int( w * 0.8 ), int( h * 0.8 ) ); -} - -/*! - Performs tile vertical action -*/ -void QtxWorkspaceAction::tileVertical() -{ - QWorkspace* wrkSpace = workspace(); - if ( !wrkSpace ) - return; - - QWidgetList winList = wrkSpace->windowList(); - if ( winList.isEmpty() ) - return; - - int count = 0; - for ( QWidgetListIt itr( winList ); itr.current(); ++itr ) - if ( !itr.current()->testWState( WState_Minimized ) ) - count++; - - if ( !count ) - return; - - int y = 0; - - int heightForEach = wrkSpace->height() / count; - for ( QWidgetListIt it( winList ); it.current(); ++it ) - { - QWidget* win = it.current(); - if ( win->testWState( WState_Minimized ) ) - continue; - - if ( win->testWState( WState_Maximized ) ) - { - win->hide(); - win->showNormal(); - } - int prefH = win->minimumHeight() + win->parentWidget()->baseSize().height(); - int actualH = QMAX( heightForEach, prefH ); - - win->parentWidget()->setGeometry( 0, y, wrkSpace->width(), actualH ); - y += actualH; - } -} - -/*! - Performs tile horizontal action -*/ -void QtxWorkspaceAction::tileHorizontal() -{ - QWorkspace* wrkSpace = workspace(); - if ( !wrkSpace ) - return; - - QWidgetList winList = wrkSpace->windowList(); - if ( winList.isEmpty() ) - return; - - int count = 0; - for ( QWidgetListIt itr( winList ); itr.current(); ++itr ) - if ( !itr.current()->testWState( WState_Minimized ) ) - count++; - - if ( !count ) - return; - - int x = 0; - int widthForEach = wrkSpace->width() / count; - for ( QWidgetListIt it( winList ); it.current(); ++it ) - { - QWidget* win = it.current(); - if ( win->testWState( WState_Minimized ) ) - continue; - - if ( win->testWState( WState_Maximized ) ) - { - win->hide(); - win->showNormal(); - } - int prefW = win->minimumWidth(); - int actualW = QMAX( widthForEach, prefW ); - - win->parentWidget()->setGeometry( x, 0, actualW, wrkSpace->height() ); - x += actualW; - } -} - -/*! - SLOT: called just before the popup menu is displayed, updates popup -*/ -void QtxWorkspaceAction::onAboutToShow() -{ - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QPopupMenu" ) ) - return; - - updatePopup( (QPopupMenu*)obj ); -} - -/*! - SLOT: called when popup menu is destroyed, removes it from menu -*/ -void QtxWorkspaceAction::onPopupDestroyed( QObject* obj ) -{ - myMenu.remove( (QPopupMenu*)obj ); -} - -/*! - Updates popup - \param pm - popup menu -*/ -void QtxWorkspaceAction::checkPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return; - - QIntList updList; - for ( QIntList::const_iterator it = myMenu[pm].begin(); it != myMenu[pm].end(); ++it ) - { - if ( pm->indexOf( *it ) != -1 ) - updList.append( *it ); - } - - myMenu.remove( pm ); - - if ( !updList.isEmpty() ) - myMenu.insert( pm, updList ); - else - { - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - } -} - -/*! - Clears and refills popup and updates state of actions - \param pm - popup menu -*/ -void QtxWorkspaceAction::updatePopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return; - - fillPopup( pm, clearPopup( pm ) ); - - bool count = workspace() ? workspace()->windowList().count() : 0; - myItem[Cascade]->setEnabled( count ); - myItem[Tile]->setEnabled( count ); - myItem[HTile]->setEnabled( count ); - myItem[VTile]->setEnabled( count ); -} - -/*! - Clears popup - \param pm - popup menu -*/ -int QtxWorkspaceAction::clearPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return -1; - - int idx = -1; - const QIntList& lst = myMenu[pm]; - for ( QIntList::const_iterator it = lst.begin(); it != lst.end() && idx == -1; ++it ) - idx = pm->indexOf( *it ); - - for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit ) - mit.data()->removeFrom( pm ); - - for ( QIntList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) - pm->removeItem( *itr ); - - return idx; -} - -/*! - Fills popup with items - \param pm - popup menu - \param idx - position -*/ -void QtxWorkspaceAction::fillPopup( QPopupMenu* pm, const int idx ) -{ - if ( !pm ) - return; - - int index = idx < 0 ? pm->count() : QMIN( (int)pm->count(), idx ); - - myMenu.insert( pm, QIntList() ); - QIntList& lst = myMenu[pm]; - - for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit ) - { - if ( !hasItems( mit.key() ) ) - continue; - - mit.data()->addTo( pm, index ); - lst.append( pm->idAt( index++ ) ); - } - - QWorkspace* ws = workspace(); - if ( !ws || !hasItems( Windows ) ) - return; - - QWidgetList wList = ws->windowList(); - if ( wList.isEmpty() ) - return; - - lst.append( pm->insertSeparator( index++ ) ); - - int param = 0; - pm->setCheckable( true ); - for ( QWidgetListIt it( wList ); it.current(); ++it ) - { - int id = pm->insertItem( it.current()->caption(), this, SLOT( onItemActivated( int ) ), 0, -1, index++ ); - pm->setItemParameter( id, param++ ); - pm->setItemChecked( id, it.current() == ws->activeWindow() ); - lst.append( id ); - } -} - -/*! - SLOT: called when popup item corresponding to window is activated, activates window -*/ -void QtxWorkspaceAction::onItemActivated( int idx ) -{ - QWorkspace* ws = workspace(); - if ( !ws ) - return; - - QWidgetList wList = ws->windowList(); - if ( idx < 0 || idx >= (int)wList.count() ) - return; - - wList.at( idx )->setFocus(); -} diff --git a/src/Qtx/QtxWorkspaceAction.h b/src/Qtx/QtxWorkspaceAction.h deleted file mode 100644 index 2dfee9cdb..000000000 --- a/src/Qtx/QtxWorkspaceAction.h +++ /dev/null @@ -1,106 +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: QtxWorkspaceAction.h -// Author: Sergey TELKOV - -#ifndef QTXWORKSPACEACTION_H -#define QTXWORKSPACEACTION_H - -#include "QtxAction.h" - -class QWorkspace; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxWorkspaceAction : public QtxAction -{ - Q_OBJECT - -public: - enum { Cascade = 0x0001, - Tile = 0x0002, - VTile = 0x0004, - HTile = 0x0008, - Windows = 0x0010, - Standard = Cascade | Tile | Windows, - Operations = Cascade | Tile | VTile | HTile, - All = Standard | HTile | VTile }; - -public: - QtxWorkspaceAction( QWorkspace*, QObject* = 0, const char* = 0 ); - virtual ~QtxWorkspaceAction(); - - QWorkspace* workspace() const; - - int items() const; - void setItems( const int ); - bool hasItems( const int ) const; - - int accel( const int ) const; - QIconSet iconSet( const int ) const; - QString menuText( const int ) const; - QString statusTip( const int ) const; - - void setAccel( const int, const int ); - void setIconSet( const int, const QIconSet& ); - void setMenuText( const int, const QString& ); - void setStatusTip( const int, const QString& ); - - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); - virtual bool removeFrom( QWidget* ); - - void perform( const int ); - -public slots: - void tile(); - void cascade(); - void tileVertical(); - void tileHorizontal(); - -private slots: - void onAboutToShow(); - void onItemActivated( int ); - void onPopupDestroyed( QObject* ); - -private: - void checkPopup( QPopupMenu* ); - void updatePopup( QPopupMenu* ); - - int clearPopup( QPopupMenu* ); - void fillPopup( QPopupMenu*, const int ); - -private: - typedef QMap MenuMap; - typedef QMap ItemMap; - -private: - MenuMap myMenu; - ItemMap myItem; - int myFlags; - QWorkspace* myWorkspace; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 3cf22f413..263f2e699 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -21,24 +21,26 @@ #include "QtxWorkstack.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DARK_COLOR_LIGHT 250 +#include "QtxAction.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DARK_COLOR_LIGHT 250 /*! Constructor @@ -50,17 +52,19 @@ myArea( 0 ), myWorkWin( 0 ), myWorkArea( 0 ) { - myActionsMap.insert( SplitVertical, new QAction( tr( "Split vertically" ), 0, this ) ); - myActionsMap.insert( SplitHorizontal, new QAction( tr( "Split horizontally" ), 0, this ) ); - myActionsMap.insert( Close, new QAction( tr( "Close" ), 0, this ) ); - myActionsMap.insert( Rename, new QAction( tr( "Rename" ), 0, this ) ); + myActionsMap.insert( SplitVertical, new QtxAction( QString(), tr( "Split vertically" ), 0, this ) ); + myActionsMap.insert( SplitHorizontal, new QtxAction( QString(), tr( "Split horizontally" ), 0, this ) ); + myActionsMap.insert( Close, new QtxAction( QString(), tr( "Close" ), 0, this ) ); + myActionsMap.insert( Rename, new QtxAction( QString(), tr( "Rename" ), 0, this ) ); - connect( myActionsMap[SplitVertical], SIGNAL( activated() ), this, SLOT( splitVertical() ) ); - connect( myActionsMap[SplitHorizontal], SIGNAL( activated() ), this, SLOT( splitHorizontal() ) ); - connect( myActionsMap[Close], SIGNAL( activated() ), this, SLOT( onCloseWindow() ) ); - connect( myActionsMap[Rename], SIGNAL( activated() ), this, SLOT( onRename() ) ); + connect( myActionsMap[SplitVertical], SIGNAL( triggered( bool ) ), this, SLOT( splitVertical() ) ); + connect( myActionsMap[SplitHorizontal], SIGNAL( triggered( bool ) ), this, SLOT( splitHorizontal() ) ); + connect( myActionsMap[Close], SIGNAL( triggered( bool ) ), this, SLOT( onCloseWindow() ) ); + connect( myActionsMap[Rename], SIGNAL( triggered( bool ) ), this, SLOT( onRename() ) ); QVBoxLayout* base = new QVBoxLayout( this ); + base->setMargin( 0 ); + mySplit = new QSplitter( this ); mySplit->setChildrenCollapsible( false ); base->addWidget( mySplit ); @@ -78,15 +82,15 @@ QtxWorkstack::~QtxWorkstack() */ QWidgetList QtxWorkstack::windowList() const { - QPtrList lst; + QList lst; areas( mySplit, lst, true ); QWidgetList widList; - for ( QPtrListIterator it( lst ); it.current(); ++it ) + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) { - QWidgetList wids = it.current()->widgetList(); - for ( QWidgetListIt itr( wids ); itr.current(); ++itr ) - widList.append( itr.current() ); + QWidgetList wids = (*it)->widgetList(); + for ( QWidgetList::iterator itr = wids.begin(); itr != wids.end(); ++itr ) + widList.append( *itr ); } return widList; @@ -128,10 +132,10 @@ void QtxWorkstack::split( const int o ) return; QSplitter* s = splitter( area ); - QPtrList areaList; + QList areaList; areas( s, areaList ); - QPtrList splitList; + QList splitList; splitters( s, splitList ); QSplitter* trg = 0; @@ -144,10 +148,10 @@ void QtxWorkstack::split( const int o ) if ( !trg ) return; - trg->setOrientation( (Orientation)o ); + trg->setOrientation( (Qt::Orientation)o ); QtxWorkstackArea* newArea = createArea( 0 ); - insertWidget( newArea, trg, area ); + trg->insertWidget( trg->indexOf( area ) + 1, newArea ); area->removeWidget( curWid ); newArea->insertWidget( curWid ); @@ -164,31 +168,34 @@ void QtxWorkstack::split( const int o ) \param o - orientation of splitting (Qt::Horizontal or Qt::Vertical) \param type - type of splitting, see SplitType enumeration */ -void QtxWorkstack::Split (QWidget* wid, const Qt::Orientation o, const SplitType type) +void QtxWorkstack::Split( QWidget* wid, const Qt::Orientation o, const SplitType type ) { if (!wid) return; // find area of the given widget QtxWorkstackArea* area = NULL; - QPtrList allAreas; + QList allAreas; areas(mySplit, allAreas, true); - QPtrListIterator it (allAreas); - for (; it.current() && !area; ++it) { - if (it.current()->contains(wid)) - area = it.current(); + + for ( QList::iterator it = allAreas.begin(); it != allAreas.end() && !area; ++it ) + { + if ( (*it)->contains( wid ) ) + area = *it; } - if (!area) return; + + if ( !area ) + return; QWidgetList wids = area->widgetList(); - if (wids.count() < 2) + if ( wids.count() < 2 ) return; - QSplitter* s = splitter(area); - QPtrList areaList; - areas(s, areaList); + QSplitter* s = splitter( area ); + QList areaList; + areas( s, areaList ); - QPtrList splitList; + QList splitList; splitters(s, splitList); QSplitter* trg = 0; @@ -203,64 +210,40 @@ void QtxWorkstack::Split (QWidget* wid, const Qt::Orientation o, const SplitType QtxWorkstackArea* newArea = createArea(0); insertWidget(newArea, trg, area); - switch (type) { + switch ( type ) + { case SPLIT_STAY: + for ( QWidgetList::iterator itr = wids.begin(); itr != wids.end(); ++itr ) { - QWidgetListIt itr (wids); - for (; itr.current(); ++itr) + QWidget* wid_i = *itr; + if ( wid_i != wid ) { - QWidget* wid_i = itr.current(); - if (wid_i != wid) { - area->removeWidget(wid_i); - newArea->insertWidget(wid_i); - } + area->removeWidget( wid_i ); + newArea->insertWidget( wid_i ); } } break; case SPLIT_AT: { - QWidgetListIt itr (wids); - for (; itr.current() && itr.current() != wid; ++itr) { + QWidgetList::iterator itr = wids.begin(); + for ( ; itr != wids.end() && *itr != wid; ++itr ) + { } - for (; itr.current(); ++itr) { - area->removeWidget(itr.current()); - newArea->insertWidget(itr.current()); + for ( ; itr != wids.end(); ++itr ) + { + area->removeWidget( *itr ); + newArea->insertWidget( *itr ); } } break; case SPLIT_MOVE: - area->removeWidget(wid); - newArea->insertWidget(wid); + area->removeWidget( wid ); + newArea->insertWidget( wid ); break; } - distributeSpace(trg); -} - -/*! - \brief Put given widget on top of its workarea - \param wid - widget, belonging to this workstack -*/ -/* -void QtxWorkstack::OnTop (QWidget* wid) -{ - if ( !wid ) - return; - - // find area of the given widget - QtxWorkstackArea* area = 0; - QPtrList allAreas; - areas( mySplit, allAreas, true ); - for ( QPtrListIterator it( allAreas ); it.current() && !area; ++it ) - { - if ( it.current()->contains( wid ) ) - area = it.current(); - } - - if ( area ) - area->setActiveWidget( wid ); + distributeSpace( trg ); } -*/ /*! \brief Move widget(s) from source workarea into target workarea @@ -275,64 +258,73 @@ void QtxWorkstack::OnTop (QWidget* wid) will be moved together with \a wid2, source workarea will be deleted. If \a wid1 and \a wid2 belongs to one workarea, simple reordering will take place. */ -void QtxWorkstack::Attract ( QWidget* wid1, QWidget* wid2, const bool all ) +void QtxWorkstack::Attract( QWidget* wid1, QWidget* wid2, const bool all ) { if ( !wid1 || !wid2 ) return; // find area of the widgets - QtxWorkstackArea *area1 = NULL, *area2 = NULL; - QPtrList allAreas; - areas(mySplit, allAreas, true); - QPtrListIterator it (allAreas); - for (; it.current() && !(area1 && area2); ++it) { - if (it.current()->contains(wid1)) - area1 = it.current(); - if (it.current()->contains(wid2)) - area2 = it.current(); + QtxWorkstackArea *area1 = 0, *area2 = 0; + QList allAreas; + areas( mySplit, allAreas, true ); + for ( QList::iterator it = allAreas.begin(); it != allAreas.end() && !( area1 && area2 ); ++it ) + { + if ( (*it)->contains( wid1 ) ) + area1 = *it; + + if ( (*it)->contains( wid2 ) ) + area2 = *it; } - if (!area1 || !area2) return; + + if ( !area1 || !area2 ) + return; QWidget* curWid = area1->activeWidget(); - if (!curWid) return; + if ( !curWid ) + return; - if (area1 == area2) { - if (all) { + if ( area1 == area2 ) + { + if ( all ) + { // Set wid1 at first position, wid2 at second - area1->insertWidget(wid1); - area1->insertWidget(wid2, 1); - } else { + area1->insertWidget( wid1 ); + area1->insertWidget( wid2, 1 ); + } + else + { // Set wid2 right after wid1 - area1->removeWidget(wid2); + area1->removeWidget( wid2 ); int wid1_ind = 0; QWidgetList wids1 = area1->widgetList(); - QWidgetListIt itr1 (wids1); - for (; itr1.current() && itr1.current() != wid1; ++itr1, ++wid1_ind); - area1->insertWidget(wid2, wid1_ind + 1); + for ( QWidgetList::iterator itr1 = wids1.begin(); itr1 != wids1.end() && *itr1 != wid1; ++itr1, ++wid1_ind ); + area1->insertWidget( wid2, wid1_ind + 1 ); } - } else { + } + else + { int wid1_ind = 0; QWidgetList wids1 = area1->widgetList(); - QWidgetListIt itr1 (wids1); - for (; itr1.current() && itr1.current() != wid1; ++itr1, ++wid1_ind); - - if (all) { + for ( QWidgetList::iterator itr1 = wids1.begin(); itr1 != wids1.end() && *itr1 != wid1; ++itr1, ++wid1_ind ); + if ( all ) + { // Set wid2 right after wid1, other widgets from area2 right after wid2 QWidgetList wids2 = area2->widgetList(); - QWidgetListIt itr2 (wids2); - for (int ind = wid1_ind + 1; itr2.current(); ++itr2, ++ind) + QWidgetList::iterator itr2 = wids2.begin(); + for ( int ind = wid1_ind + 1; itr2 != wids2.end(); ++itr2, ++ind ) { - area2->removeWidget(itr2.current()); - if (itr2.current() == wid2) { - area1->insertWidget(itr2.current(), wid1_ind + 1); - } else { - area1->insertWidget(itr2.current(), ind); - } + area2->removeWidget( *itr2 ); + if ( *itr2 == wid2 ) + area1->insertWidget( *itr2, wid1_ind + 1 ); + else + area1->insertWidget( *itr2, ind ); } - } else { + } + else + { // Set wid2 right after wid1 - area2->removeWidget(wid2); - area1->insertWidget(wid2, wid1_ind + 1); + area2->removeWidget( wid2 ); + area1->insertWidget( wid2, wid1_ind + 1 ); } } @@ -375,14 +367,12 @@ void QtxWorkstack::SetRelativePositionInSplitter( QWidget* wid, const double pos // find area of the given widget QtxWorkstackArea* area = NULL; - QPtrList allAreas; - areas(mySplit, allAreas, true); - for ( QPtrListIterator it( allAreas ); - it.current() && !area; - ++it ) + QList allAreas; + areas( mySplit, allAreas, true ); + for ( QList::iterator it = allAreas.begin(); it != allAreas.end() && !area; ++it ) { - if (it.current()->contains(wid)) - area = it.current(); + if ( (*it)->contains( wid ) ) + area = *it; } if ( !area ) @@ -395,24 +385,24 @@ void QtxWorkstack::SetRelativePositionInSplitter( QWidget* wid, const double pos // find index of the area in its splitter int item_ind = -1; bool isFound = false; - const QObjectList* was = split->children(); - for (QObjectListIt ito (*was); ito.current() && !isFound; ++ito, ++item_ind) + const QObjectList& was = split->children(); + for ( QObjectList::const_iterator ito = was.begin(); ito != was.end() && !isFound; ++ito, ++item_ind ) { - if (ito.current() == area) + if ( *ito == area ) isFound = true; } - if (!isFound || item_ind == 0) + + if ( !isFound || item_ind == 0 ) return; QIntList szList = split->sizes(); - int splitter_size = (split->orientation() == Horizontal ? - split->width() : split->height()); + int splitter_size = ( split->orientation() == Qt::Horizontal ? split->width() : split->height()); int nb = szList.count(); - int new_prev = int(splitter_size * position / item_ind); - int new_next = int(splitter_size * (1.0 - position) / (nb - item_ind)); - setSizes (szList, item_ind, new_prev, new_next, new_next); - split->setSizes(szList); + int new_prev = int( splitter_size * position / item_ind ); + int new_next = int( splitter_size * ( 1.0 - position ) / ( nb - item_ind ) ); + setSizes( szList, item_ind, new_prev, new_next, new_next ); + split->setSizes( szList ); } /*! @@ -432,7 +422,7 @@ void QtxWorkstack::SetRelativePosition( QWidget* wid, const Qt::Orientation o, if ( !wid ) return; - int splitter_size = o == Horizontal ? mySplit->width() : mySplit->height(); + int splitter_size = o == Qt::Horizontal ? mySplit->width() : mySplit->height(); int need_pos = int( position * splitter_size ); int splitter_pos = 0; @@ -452,7 +442,7 @@ void QtxWorkstack::setAccel( const int id, const int accel ) if ( !myActionsMap.contains( id ) ) return; - myActionsMap[id]->setAccel( accel ); + myActionsMap[id]->setShortcut( accel ); } /*! @@ -464,7 +454,7 @@ int QtxWorkstack::accel( const int id ) const { int res = 0; if ( myActionsMap.contains( id ) ) - res = myActionsMap[id]->accel(); + res = myActionsMap[id]->shortcut(); return res; } @@ -554,41 +544,44 @@ int QtxWorkstack::setPosition( QWidget* wid, QSplitter* split, const Qt::Orienta int cur_ind = 0, item_ind = 0; bool isBottom = false, isFound = false; QSplitter* sub_split = NULL; - const QObjectList* objs = split->children(); - if ( objs ) + const QObjectList& objs = split->children(); + for ( QObjectList::const_iterator it = objs.begin(); it != objs.end() && !isFound; ++it ) { - for (QObjectListIt it (*objs); it.current() && !isFound; ++it) + QtxWorkstackArea* area = ::qobject_cast( *it ); + if ( area ) + { + if ( area->contains( wid ) ) + { + item_ind = cur_ind; + isBottom = true; + isFound = true; + } + cur_ind++; + } + else if ( (*it)->inherits( "QSplitter" ) ) { - if (it.current()->inherits( "QtxWorkstackArea")) { - if (((QtxWorkstackArea*)it.current())->contains(wid)) { + QList areaList; + areas( (QSplitter*)(*it), areaList, true ); + for ( QList::iterator ita = areaList.begin(); ita != areaList.end() && !isFound; ++ita ) + { + if ( (*ita)->contains( wid ) ) + { item_ind = cur_ind; - isBottom = true; isFound = true; + sub_split = (QSplitter*)*it; } - cur_ind++; - } else if (it.current()->inherits("QSplitter")) { - QPtrList areaList; - areas((QSplitter*)it.current(), areaList, true); - for (QPtrListIterator ita (areaList); - ita.current() && !isFound; - ++ita) - { - if (ita.current()->contains(wid)) { - item_ind = cur_ind; - isFound = true; - sub_split = (QSplitter*)it.current(); - } - } - cur_ind++; } + cur_ind++; } } - if (!isFound) - return (need_pos - splitter_pos); - if (split->orientation() == o) { + if ( !isFound ) + return ( need_pos - splitter_pos ); + + if ( split->orientation() == o ) + { // Find coordinates of near and far sides of the appropriate item relatively current splitter - int splitter_size = (o == Horizontal ? split->width() : split->height()); + int splitter_size = ( o == Qt::Horizontal ? split->width() : split->height() ); QIntList szList = split->sizes(); int nb = szList.count(); int item_rel_pos = 0; // position of near side of item relatively this splitter @@ -734,7 +727,7 @@ void QtxWorkstack::distributeSpace( QSplitter* split ) const return; QIntList szList = split->sizes(); - int size = ( split->orientation() == Horizontal ? + int size = ( split->orientation() == Qt::Horizontal ? split->width() : split->height() ) / szList.count(); for ( QIntList::iterator it = szList.begin(); it != szList.end(); ++it ) *it = size; @@ -766,10 +759,10 @@ void QtxWorkstack::onRename() return; bool ok = false; - QString newName = QInputDialog::getText( tr( "Rename" ), tr( "Enter new name:" ), QLineEdit::Normal, - myWorkWin->caption(), &ok, topLevelWidget() ); + QString newName = QInputDialog::getText( topLevelWidget(), tr( "Rename" ), tr( "Enter new name:" ), + QLineEdit::Normal, myWorkWin->windowTitle(), &ok ); if ( ok && !newName.isEmpty() ) - myWorkWin->setCaption( newName ); + myWorkWin->setWindowTitle( newName ); } /*! @@ -785,7 +778,7 @@ QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area ) if ( !pSplit ) return 0; - bool upd = pSplit->isUpdatesEnabled(); + bool upd = pSplit->updatesEnabled(); pSplit->setUpdatesEnabled( false ); QIntList szList = pSplit->sizes(); @@ -794,8 +787,9 @@ QSplitter* QtxWorkstack::wrapSplitter( QtxWorkstackArea* area ) #if defined QT_VERSION && QT_VERSION >= 0x30200 wrap->setChildrenCollapsible( false ); #endif - insertWidget( wrap, pSplit, area ); - area->reparent( wrap, QPoint( 0, 0 ), true ); + pSplit->insertWidget( pSplit->indexOf( area ) + 1, wrap ); + wrap->setVisible( true ); + wrap->addWidget( area ); pSplit->setSizes( szList ); @@ -816,31 +810,32 @@ void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after ) return; QWidgetList moveList; - const QObjectList* lst = pWid->children(); - if ( lst ) + const QObjectList& lst = pWid->children(); + bool found = false; + for ( QObjectList::const_iterator it = lst.begin(); it != lst.end(); ++it ) { - bool found = false; - for ( QObjectListIt it( *lst ); it.current(); ++it ) - { - if ( found && ( it.current()->inherits( "QSplitter" ) || - it.current()->inherits( "QtxWorkstackArea" ) ) ) - moveList.append( (QWidget*)it.current() ); - if ( it.current() == after ) - found = true; - } + if ( found && ( (*it)->inherits( "QSplitter" ) || + (*it)->inherits( "QtxWorkstackArea" ) ) ) + moveList.append( (QWidget*)(*it) ); + if ( *it == after ) + found = true; } QMap map; - for ( QWidgetListIt it( moveList ); it.current(); ++it ) + for ( QWidgetList::iterator it = moveList.begin(); it != moveList.end(); ++it ) { - map.insert( it.current(), it.current()->isVisibleTo( it.current()->parentWidget() ) ); - it.current()->reparent( 0, QPoint( 0, 0 ), false ); + map.insert( *it, (*it)->isVisibleTo( (*it)->parentWidget() ) ); + (*it)->setParent( 0 ); + (*it)->hide(); } - wid->reparent( pWid, QPoint( 0, 0 ), true ); + wid->setParent( pWid ); - for ( QWidgetListIt itr( moveList ); itr.current(); ++itr ) - itr.current()->reparent( pWid, QPoint( 0, 0 ), map.contains( itr.current() ) ? map[itr.current()] : false ); + for ( QWidgetList::iterator itr = moveList.begin(); itr != moveList.end(); ++itr ) + { + (*itr)->setParent( pWid ); + (*itr)->setShown( map.contains( *itr ) ? map[*itr] : false ); + } } /*! @@ -872,7 +867,7 @@ void QtxWorkstack::onDestroyed( QObject* obj ) cur->setFocus(); } - QApplication::postEvent( this, new QCustomEvent( QEvent::User ) ); + QApplication::postEvent( this, new QEvent( QEvent::User ) ); } /*! @@ -895,10 +890,10 @@ void QtxWorkstack::onDeactivated( QtxWorkstackArea* area ) if ( myArea != area ) return; - QPtrList lst; + QList lst; areas( mySplit, lst, true ); - int idx = lst.find( area ); + int idx = lst.indexOf( area ); if ( idx == -1 ) return; @@ -909,7 +904,7 @@ void QtxWorkstack::onDeactivated( QtxWorkstackArea* area ) if ( newArea && newArea->activeWidget() ) newArea->activeWidget()->setFocus(); - QApplication::postEvent( this, new QCustomEvent( QEvent::User ) ); + QApplication::postEvent( this, new QEvent( QEvent::User ) ); } /*! @@ -919,7 +914,7 @@ void QtxWorkstack::onDeactivated( QtxWorkstackArea* area ) */ void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) { - QtxWorkstackArea* anArea = ::qt_cast( (QObject*)sender() ); + QtxWorkstackArea* anArea = ::qobject_cast( (QObject*)sender() ); if ( !anArea ) anArea = activeArea(); @@ -933,24 +928,24 @@ void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) myWorkWin = w; myWorkArea = anArea; - QPopupMenu* pm = new QPopupMenu(); + QMenu* pm = new QMenu(); if ( lst.count() > 1 ) { - myActionsMap[SplitVertical]->addTo( pm ); - myActionsMap[SplitHorizontal]->addTo( pm ); - pm->insertSeparator(); + pm->addAction( myActionsMap[SplitVertical] ); + pm->addAction( myActionsMap[SplitHorizontal] ); + pm->addSeparator(); } if ( w ) { - myActionsMap[Close]->addTo( pm ); - myActionsMap[Rename]->addTo( pm ); + pm->addAction( myActionsMap[Close] ); + pm->addAction( myActionsMap[Rename] ); } Qtx::simplifySeparators( pm ); - if ( pm->count() ) + if ( !pm->actions().isEmpty() ) pm->exec( p ); delete pm; @@ -959,27 +954,18 @@ void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) myWorkArea = 0; } -/*! - Custom child event handler, inserts widget to active or current area -*/ -void QtxWorkstack::childEvent( QChildEvent* e ) +QWidget* QtxWorkstack::addWindow( QWidget* w, Qt::WindowFlags f ) { - if ( e->inserted() && e->child()->isWidgetType() ) - { - QWidget* w = (QWidget*)e->child(); - if ( w && w != mySplit ) - { - targetArea()->insertWidget( w ); - return; - } - } - QWidget::childEvent( e ); + if ( !w ) + return 0; + + return targetArea()->insertWidget( w, -1, f ); } /*! Handler of custom events */ -void QtxWorkstack::customEvent( QCustomEvent* e ) +void QtxWorkstack::customEvent( QEvent* e ) { updateState(); } @@ -1008,21 +994,18 @@ QSplitter* QtxWorkstack::splitter( QtxWorkstackArea* area ) const \param splitList - list to be filled with \param rec - recursive search of children */ -void QtxWorkstack::splitters( QSplitter* split, QPtrList& splitList, const bool rec ) const +void QtxWorkstack::splitters( QSplitter* split, QList& splitList, const bool rec ) const { if ( !split ) return; - const QObjectList* objs = split->children(); - if ( objs ) + const QObjectList& objs = split->children(); + for ( QObjectList::const_iterator it = objs.begin(); it != objs.end(); ++it ) { - for ( QObjectListIt it( *objs ); it.current(); ++it ) - { - if ( rec ) - splitters( (QSplitter*)it.current(), splitList, rec ); - if ( it.current()->inherits( "QSplitter" ) ) - splitList.append( (QSplitter*)it.current() ); - } + if ( rec ) + splitters( (QSplitter*)*it, splitList, rec ); + if ( (*it)->inherits( "QSplitter" ) ) + splitList.append( (QSplitter*)*it ); } } @@ -1032,21 +1015,18 @@ void QtxWorkstack::splitters( QSplitter* split, QPtrList& splitList, \param areaList - list to be filled with \param rec - recursive search of children */ -void QtxWorkstack::areas( QSplitter* split, QPtrList& areaList, const bool rec ) const +void QtxWorkstack::areas( QSplitter* split, QList& areaList, const bool rec ) const { if ( !split ) return; - const QObjectList* objs = split->children(); - if ( objs ) + const QObjectList& objs = split->children(); + for ( QObjectList::const_iterator it = objs.begin(); it != objs.end(); ++it ) { - for ( QObjectListIt it( *objs ); it.current(); ++it ) - { - if ( it.current()->inherits( "QtxWorkstackArea" ) ) - areaList.append( (QtxWorkstackArea*)it.current() ); - else if ( rec && it.current()->inherits( "QSplitter" ) ) - areas( (QSplitter*)it.current(), areaList, rec ); - } + if ( (*it)->inherits( "QtxWorkstackArea" ) ) + areaList.append( (QtxWorkstackArea*)*it ); + else if ( rec && (*it)->inherits( "QSplitter" ) ) + areas( (QSplitter*)*it, areaList, rec ); } } @@ -1068,7 +1048,7 @@ QtxWorkstackArea* QtxWorkstack::targetArea() area = currentArea(); if ( !area ) { - QPtrList lst; + QList lst; areas( mySplit, lst ); if ( !lst.isEmpty() ) area = lst.first(); @@ -1146,9 +1126,9 @@ void QtxWorkstack::setActiveArea( QtxWorkstackArea* area ) */ QtxWorkstackArea* QtxWorkstack::neighbourArea( QtxWorkstackArea* area ) const { - QPtrList lst; + QList lst; areas( mySplit, lst, true ); - int pos = lst.find( area ); + int pos = lst.indexOf( area ); if ( pos < 0 ) return 0; @@ -1174,11 +1154,11 @@ QtxWorkstackArea* QtxWorkstack::neighbourArea( QtxWorkstackArea* area ) const QtxWorkstackArea* QtxWorkstack::areaAt( const QPoint& p ) const { QtxWorkstackArea* area = 0; - QPtrList lst; + QList lst; areas( mySplit, lst, true ); - for ( QPtrListIterator it( lst ); it.current() && !area; ++it ) + for ( QList::iterator it = lst.begin(); it != lst.end() && !area; ++it ) { - QtxWorkstackArea* cur = it.current(); + QtxWorkstackArea* cur = *it; QRect r = cur->geometry(); if ( cur->parentWidget() ) r = QRect( cur->parentWidget()->mapToGlobal( r.topLeft() ), r.size() ); @@ -1201,25 +1181,25 @@ void QtxWorkstack::updateState() */ void QtxWorkstack::updateState( QSplitter* split ) { - QPtrList recList; + QList recList; splitters( split, recList, false ); - for ( QPtrListIterator itr( recList ); itr.current(); ++itr ) - updateState( itr.current() ); + for ( QList::iterator itr = recList.begin(); itr != recList.end(); ++itr ) + updateState( *itr ); - QPtrList splitList; + QList splitList; splitters( split, splitList, false ); - QPtrList areaList; + QList areaList; areas( split, areaList, false ); bool vis = false; - for ( QPtrListIterator it( areaList ); it.current(); ++it ) + for ( QList::iterator it = areaList.begin(); it != areaList.end(); ++it ) { - if ( it.current()->isEmpty() ) - it.current()->hide(); + if ( (*it)->isEmpty() ) + (*it)->hide(); else { - it.current()->show(); + (*it)->show(); vis = true; } } @@ -1227,8 +1207,8 @@ void QtxWorkstack::updateState( QSplitter* split ) if ( split == mySplit ) return; - for ( QPtrListIterator iter( splitList ); iter.current() && !vis; ++iter ) - vis = iter.current()->isVisibleTo( iter.current()->parentWidget() ); + for ( QList::iterator iter = splitList.begin(); iter != splitList.end() && !vis; ++iter ) + vis = (*iter)->isVisibleTo( (*iter)->parentWidget() ); if ( areaList.isEmpty() && splitList.isEmpty() ) delete split; @@ -1248,48 +1228,40 @@ void QtxWorkstack::splitterInfo( QSplitter* split, QString& info ) const if ( !split ) return; - const QObjectList* objs = split->children(); - if ( objs ) + const QObjectList& objs = split->children(); + + QString sizesStr; + QList sizes = split->sizes(); + for ( QList::iterator sIt = sizes.begin(); sIt != sizes.end(); ++sIt ) { - // make up a sizes string: integer values are separated by ':' char - QValueList sizes = split->sizes(); - QString sizesStr; - for ( QValueList::Iterator sIt = sizes.begin(); sIt != sizes.end(); ++sIt ) { - if ( *sIt > 1 ) // size 1 pixel usually means empty Workstack area, which will NOT be re-created, - sizesStr += QString( ":%1" ).arg( *sIt ); // so we don't need to store its size - } - if ( !sizesStr.isEmpty() ) // cut the first ':' - sizesStr = sizesStr.right( sizesStr.length()-1 ); - - // count all QSplitter-s and QtxWorkstackArea-s - // int nChilds( 0 ); - // QObjectListIt it( *objs ); - // for ( ; it.current(); ++it ) - // { - // if ( it.current()->inherits( "QSplitter" ) || - // it.current()->inherits( "QtxWorkstackArea" ) ) - // nChilds++; - // } - - info += QString( "(splitter orientation=%1 sizes=%3 " ).arg( split->orientation() ).arg( sizesStr ); + if ( *sIt > 1 ) // size 1 pixel usually means empty Workstack area, which will NOT be re-created, + sizesStr += QString( ":%1" ).arg( *sIt ); // so we don't need to store its size + } + + if ( !sizesStr.isEmpty() ) // cut the first ':' + sizesStr = sizesStr.right( sizesStr.length() - 1 ); + + info += QString( "(splitter orientation=%1 sizes=%3 " ).arg( split->orientation() ).arg( sizesStr ); - for ( QObjectListIt it( *objs ); it.current(); ++it ) + for ( QObjectList::const_iterator it = objs.begin(); it != objs.end(); ++it ) + { + if ( (*it)->inherits( "QSplitter" ) ) + splitterInfo( (QSplitter*)*it, info ); + else if ( (*it)->inherits( "QtxWorkstackArea" ) ) { - if ( it.current()->inherits( "QSplitter" ) ) - splitterInfo( (QSplitter*)it.current(), info ); - else if ( it.current()->inherits( "QtxWorkstackArea" ) ) { - QtxWorkstackArea* area = (QtxWorkstackArea*)it.current(); - if ( area->isEmpty() ) - continue; - info += QString( "(views active='%1'" ).arg( area->activeWidget()->name() ); - QWidgetList views = area->widgetList(); - for ( QWidgetListIt wIt( views ); wIt.current(); ++wIt ) - info += QString( " '%1'" ).arg( wIt.current()->name() ); - info += ')'; - } + QtxWorkstackArea* area = (QtxWorkstackArea*)*it; + if ( area->isEmpty() ) + continue; + info += QString( "(views active='%1'" ).arg( area->activeWidget()->objectName() ); + QWidgetList views = area->widgetList(); + for ( QWidgetList::iterator wIt = views.begin(); wIt != views.end(); ++wIt ) + info += QString( " '%1'" ).arg( (*wIt)->objectName() ); + info += ')'; } } + info += ')'; + printf( (const char*)QString( info + '\n' ).toLatin1() ); } @@ -1309,16 +1281,18 @@ void cutBrackets( QString& parameters ) */ QString getValue( const QString& str, const QString& valName ) { - int i = str.find( valName ); - if ( i != -1 ) { - int equal_i = str.find( '=', i ); - if ( equal_i != -1 ) { - int space_i = str.find( ' ', ++equal_i ); + int i = str.indexOf( valName ); + if ( i != -1 ) + { + int equal_i = str.indexOf( '=', i ); + if ( equal_i != -1 ) + { + int space_i = str.indexOf( ' ', ++equal_i ); if ( space_i != -1 ) - return str.mid( equal_i, space_i-equal_i ); + return str.mid( equal_i, space_i - equal_i ); } } - return QString( "" ); + return QString(); } /* @@ -1337,7 +1311,7 @@ bool checkFormat( const QString& parameters ) ok = ( params.left( 8 ) == "splitter" ); if ( !ok ) return ok; // 3. has children? = '(' is found - int i = params.find( '(' ); + int i = params.indexOf( '(' ); ok = i != -1; if ( !ok ) return ok; params = params.left( i ); // cut all children, they will be checked later @@ -1370,13 +1344,13 @@ QStringList getChildren( const QString& str ) { nOpen++; if ( nOpen == 1 ) - start = i; + start = i; } else if ( str[i] == ')' ) { nOpen--; if ( nOpen == 0 ) - lst.append( str.mid( start, i-start+1 ) ); + lst.append( str.mid( start, i-start+1 ) ); } i++; } @@ -1392,32 +1366,33 @@ QString getViewName( const QString& str, int i ) QRegExp exp( "\\s'\\w+'" ); int start = 0; // start index of view name in the string int num = 0 ; // index of found match - while ( ( start = exp.search( str, start ) ) != -1 && num < i ) { + while ( ( start = exp.indexIn( str, start ) ) != -1 && num < i ) + { start += exp.matchedLength(); num ++; } if ( start != -1 ) // +2 and -3 avoid starting space and starting and ending ' symbols - return str.mid( start+2, exp.matchedLength()-3 ); + return str.mid( start + 2, exp.matchedLength() - 3 ); - return QString( "" ); + return QString(); } // returns widget with given name QWidget* getView( const QWidget* parent, const QString& aName ) { QWidget* view = 0; - QObjectList *l = parent->topLevelWidget()->queryList( "QWidget", aName, false, true ); - if ( !l->isEmpty() ) - view = ::qt_cast( l->first() ); - delete l; + QList l = qFindChildren( parent->topLevelWidget(), aName ); + if ( !l.isEmpty() ) + view = ::qobject_cast( l.first() ); return view; } /*! Installs a splitter described by given parameters string */ -void QtxWorkstack::setSplitter( QSplitter* splitter, const QString& parameters, QMap< QSplitter*, QValueList >& sMap ) +void QtxWorkstack::setSplitter( QSplitter* splitter, const QString& parameters, QMap >& sMap ) { + printf( QString( parameters + '\n' ).toLatin1() ); if ( !::checkFormat( parameters ) ) { printf( "\nInvalid format of workstack parameters. Positions of viewers can not be restored.\n" ); return; @@ -1427,8 +1402,8 @@ void QtxWorkstack::setSplitter( QSplitter* splitter, const QString& parameters, ::cutBrackets( params ); // get splitter sizes and store it in the map for future setting - QValueList sizes; - QStringList sizesLst = QStringList::split( ':', ::getValue( params, "sizes" ) ); + QList sizes; + QStringList sizesLst = ::getValue( params, "sizes" ).split( ':', QString::SkipEmptyParts ); QStringList::Iterator it; for ( it = sizesLst.begin(); it != sizesLst.end(); ++it ) sizes.append( (*it).toInt() ); @@ -1439,7 +1414,7 @@ void QtxWorkstack::setSplitter( QSplitter* splitter, const QString& parameters, splitter->setOrientation( (Qt::Orientation)orient ); // get children - QString options = params.left( params.find( '(' ) ); + QString options = params.left( params.indexOf( '(' ) ); QString childrenStr = params.right( params.length()-options.length() ); QStringList children = ::getChildren( childrenStr ); @@ -1448,25 +1423,30 @@ void QtxWorkstack::setSplitter( QSplitter* splitter, const QString& parameters, // for ( QStringList::Iterator tit = children.begin(); tit != children.end(); ++tit ) // printf (" |-> child = [%s]\n", (*tit).latin1() ); - for ( QStringList::Iterator it = children.begin(); it != children.end(); ++it ) { - if ( (*it).startsWith( "(splitter" ) ) { + for ( it = children.begin(); it != children.end(); ++it ) + { + if ( (*it).startsWith( "(splitter" ) ) + { QSplitter* newSplitter = new QSplitter( splitter ); setSplitter( newSplitter, *it, sMap ); } - else if ( (*it).startsWith( "(views" ) ) { + else if ( (*it).startsWith( "(views" ) ) + { QtxWorkstackArea* newArea = createArea( splitter ); QString activeViewName = ::getValue( *it, "active" ); - QWidget* activeView( 0 ); + QWidget* activeView = 0; activeViewName = activeViewName.mid( 1, activeViewName.length()-2 ); // chop off ' symbols int i = 0; QString viewName = ::getViewName( *it, i ); - while ( !viewName.isEmpty() ) { - if ( QWidget* view = ::getView( splitter, viewName ) ) { - newArea->insertWidget( view ); - if ( activeViewName == view->name() ) - activeView = view; - } - viewName = ::getViewName( *it, ++i ); + while ( !viewName.isEmpty() ) + { + if ( QWidget* view = ::getView( splitter, viewName ) ) + { + newArea->insertWidget( view ); + if ( activeViewName == view->objectName() ) + activeView = view; + } + viewName = ::getViewName( *it, ++i ); } if ( activeView ) newArea->setActiveWidget( activeView ); @@ -1480,33 +1460,38 @@ void QtxWorkstack::setSplitter( QSplitter* splitter, const QString& parameters, QtxWorkstack& QtxWorkstack::operator<<( const QString& parameters ) { // clear the main splitter - remove all child splitters and empty areas from it - QPtrList splitList; - QPtrList areaList; + QList splitList; + QList areaList; splitters( mySplit, splitList, false ); areas( mySplit, areaList, false ); - for ( QPtrListIterator iter( splitList ); iter.current(); ++iter ) - delete iter.current(); - for ( QPtrListIterator it( areaList ); it.current(); ++it ) - if ( it.current()->isEmpty() ) - delete it.current(); + for ( QList::iterator iter = splitList.begin(); iter != splitList.end(); ++iter ) + delete *iter; + + for ( QList::iterator it = areaList.begin(); it != areaList.end(); ++it ) + { + if ( (*it)->isEmpty() ) + delete *it; + } // restore splitter recursively - QMap< QSplitter*, QValueList > sMap; + QMap< QSplitter*, QList > sMap; setSplitter( mySplit, parameters, sMap ); // now mySplit may contains empty area (where all views were located before restoring) // in order setSize to work correctly we have to exclude this area areaList.clear(); areas( mySplit, areaList, false ); - for ( QPtrListIterator delIt( areaList ); delIt.current(); ++delIt ) - if ( delIt.current()->isEmpty() ) - delete delIt.current(); + for ( QList::iterator delIt = areaList.begin(); delIt != areaList.end(); ++delIt ) + { + if ( (*delIt)->isEmpty() ) + delete *delIt; + } - qApp->processEvents(); + QApplication::instance()->processEvents(); // restore splitters' sizes (map of sizes is filled in setSplitters) - for ( QMap< QSplitter*, QValueList >::Iterator itm = sMap.begin(); itm != sMap.end(); ++itm ) - itm.key()->setSizes( itm.data() ); + for ( QMap< QSplitter*, QList >::iterator itm = sMap.begin(); itm != sMap.end(); ++itm ) + itm.key()->setSizes( itm.value() ); return (*this); } @@ -1523,33 +1508,50 @@ QtxWorkstack& QtxWorkstack::operator>>( QString& outParameters ) } +class QtxWorkstackArea::WidgetEvent : public QEvent +{ +public: + WidgetEvent( Type t, QWidget* w = 0 ) : QEvent( t ), myWidget( w ) {}; + + QWidget* widget() const { return myWidget; } + +private: + QWidget* myWidget; +}; + /*! Constructor */ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) -: QWidget( parent ) +: QFrame( parent ) { + setFrameStyle( QFrame::Panel | QFrame::Sunken ); + QVBoxLayout* base = new QVBoxLayout( this ); + base->setMargin( frameWidth() ); - QHBox* top = new QHBox( this ); + QWidget* top = new QWidget( this ); base->addWidget( top ); + QHBoxLayout* tl = new QHBoxLayout( top ); + tl->setMargin( 0 ); + myBar = new QtxWorkstackTabBar( top ); + tl->addWidget( myBar, 1 ); QPushButton* close = new QPushButton( top ); - close->setPixmap( style().stylePixmap( QStyle::SP_TitleBarCloseButton ) ); + close->setIcon( style()->standardIcon( QStyle::SP_TitleBarCloseButton ) ); close->setAutoDefault( true ); close->setFlat( true ); myClose = close; + tl->addWidget( myClose ); - top->setStretchFactor( myBar, 1 ); - - myStack = new QWidgetStack( this ); + myStack = new QStackedWidget( this ); base->addWidget( myStack, 1 ); connect( myClose, SIGNAL( clicked() ), this, SLOT( onClose() ) ); - connect( myBar, SIGNAL( selected( int ) ), this, SLOT( onSelected( int ) ) ); + connect( myBar, SIGNAL( currentChanged( int ) ), this, SLOT( onCurrentChanged( int ) ) ); connect( myBar, SIGNAL( dragActiveTab() ), this, SLOT( onDragActiveTab() ) ); connect( myBar, SIGNAL( contextMenuRequested( QPoint ) ), this, SLOT( onContextMenuRequested( QPoint ) ) ); @@ -1557,7 +1559,7 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) updateActiveState(); - qApp->installEventFilter( this ); + QApplication::instance()->installEventFilter( this ); } /*! @@ -1565,7 +1567,7 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent ) */ QtxWorkstackArea::~QtxWorkstackArea() { - qApp->removeEventFilter( this ); + QApplication::instance()->removeEventFilter( this ); } /*! @@ -1575,7 +1577,7 @@ bool QtxWorkstackArea::isEmpty() const { bool res = false; for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !res; ++it ) - res = it.data().vis; + res = it.value().vis; return !res; } @@ -1584,21 +1586,21 @@ bool QtxWorkstackArea::isEmpty() const \param wid - widget \param idx - index */ -void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx ) +QWidget* QtxWorkstackArea::insertWidget( QWidget* wid, const int idx, Qt::WindowFlags f ) { if ( !wid ) - return; + return 0; - int pos = myList.find( wid ); + int pos = myList.indexOf( wid ); if ( pos != -1 && ( pos == idx || ( idx < 0 && pos == (int)myList.count() - 1 ) ) ) - return; + return 0; - myList.removeRef( wid ); + myList.removeAll( wid ); pos = idx < 0 ? myList.count() : idx; - myList.insert( QMIN( pos, (int)myList.count() ), wid ); + myList.insert( qMin( pos, (int)myList.count() ), wid ); if ( !myInfo.contains( wid ) ) { - QtxWorkstackChild* child = new QtxWorkstackChild( wid, myStack ); + QtxWorkstackChild* child = new QtxWorkstackChild( wid, myStack, f ); myChild.insert( wid, child ); myInfo.insert( wid, WidgetInfo() ); myInfo[wid].id = generateId(); @@ -1616,6 +1618,8 @@ void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx ) setWidgetActive( wid ); wid->setFocus(); + + return myChild[wid]; } /*! @@ -1624,14 +1628,14 @@ void QtxWorkstackArea::insertWidget( QWidget* wid, const int idx ) */ void QtxWorkstackArea::onContextMenuRequested( QPoint p ) { - const QtxWorkstackTabBar* bar = ::qt_cast( sender() ); + const QtxWorkstackTabBar* bar = ::qobject_cast( sender() ); if ( !bar ) return; QWidget* wid = 0; - QTab* tab = myBar->tabAt( tabAt( p ) ); - if ( tab ) - wid = widget( tab->identifier() ); + int idx = tabAt( p ); + if ( idx != -1 ) + wid = widget( myBar->tabId( idx ) ); emit contextMenuRequested( wid, p ); } @@ -1655,18 +1659,19 @@ void QtxWorkstackArea::removeWidget( QWidget* wid, const bool del ) if ( !myList.contains( wid ) ) return; - if ( myBar->tab( widgetId( wid ) ) ) - myBar->removeTab( myBar->tab( widgetId( wid ) ) ); + if ( myBar->indexOf( widgetId( wid ) ) != -1 ) + myBar->removeTab( myBar->indexOf( widgetId( wid ) ) ); + myStack->removeWidget( child( wid ) ); - myList.remove( wid ); + myList.removeAll( wid ); myInfo.remove( wid ); myChild.remove( wid ); - if( del ) + if ( del ) { delete child( wid ); - if( myList.isEmpty() ) + if ( myList.isEmpty() ) delete this; else updateState(); @@ -1681,10 +1686,10 @@ void QtxWorkstackArea::removeWidget( QWidget* wid, const bool del ) QWidgetList QtxWorkstackArea::widgetList() const { QWidgetList lst; - for ( QWidgetListIt it( myList ); it.current(); ++it ) + for ( QWidgetList::const_iterator it = myList.begin(); it != myList.end(); ++it ) { - if ( widgetVisibility( it.current() ) ) - lst.append( it.current() ); + if ( widgetVisibility( *it ) ) + lst.append( *it ); } return lst; } @@ -1694,7 +1699,7 @@ QWidgetList QtxWorkstackArea::widgetList() const */ QWidget* QtxWorkstackArea::activeWidget() const { - return widget( myBar->currentTab() ); + return widget( myBar->tabId( myBar->currentIndex() ) ); } /*! @@ -1703,7 +1708,7 @@ QWidget* QtxWorkstackArea::activeWidget() const */ void QtxWorkstackArea::setActiveWidget( QWidget* wid ) { - myBar->setCurrentTab( widgetId( wid ) ); + myBar->setCurrentIndex( myBar->indexOf( widgetId( wid ) ) ); } /*! @@ -1718,37 +1723,19 @@ bool QtxWorkstackArea::contains( QWidget* wid ) const /*! Shows area */ -void QtxWorkstackArea::show() +void QtxWorkstackArea::setVisible( bool on ) { QMap map; - for ( QWidgetListIt it( myList ); it.current(); ++it ) + for ( QWidgetList::iterator it = myList.begin(); it != myList.end(); ++it ) { - map.insert( it.current(), isBlocked( it.current() ) ); - setBlocked( it.current(), true ); + map.insert( *it, isBlocked( *it ) ); + setBlocked( *it, true ); } - QWidget::show(); + QFrame::setVisible( on ); - for ( QWidgetListIt itr( myList ); itr.current(); ++itr ) - setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false ); -} - -/*! - Hides area -*/ -void QtxWorkstackArea::hide() -{ - QMap map; - for ( QWidgetListIt it( myList ); it.current(); ++it ) - { - map.insert( it.current(), isBlocked( it.current() ) ); - setBlocked( it.current(), true ); - } - - QWidget::hide(); - - for ( QWidgetListIt itr( myList ); itr.current(); ++itr ) - setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false ); + for ( QWidgetList::iterator itr = myList.begin(); itr != myList.end(); ++itr ) + setBlocked( *itr, map.contains( *itr ) ? map[*itr] : false ); } /*! @@ -1804,7 +1791,7 @@ bool QtxWorkstackArea::eventFilter( QObject* o, QEvent* e ) wid = wid->parentWidget(); } if ( ok ) - QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)( e->type() == QEvent::FocusIn ? ActivateWidget : FocusWidget ) ) ); + QApplication::postEvent( this, new WidgetEvent( (QEvent::Type)( e->type() == QEvent::FocusIn ? ActivateWidget : FocusWidget ) ) ); } } return false; @@ -1825,16 +1812,18 @@ QRect QtxWorkstackArea::floatRect() const */ QRect QtxWorkstackArea::floatTab( const int idx ) const { - return myBar->tabRect( idx ); + QRect r = myBar->tabRect( idx ); + return QRect( myBar->mapToGlobal( r.topLeft() ), r.size() ); } /*! \return tab covering point \param p - point */ -int QtxWorkstackArea::tabAt( const QPoint& p ) const +int QtxWorkstackArea::tabAt( const QPoint& pnt ) const { int idx = -1; + QPoint p = myBar->mapFromGlobal( pnt ); for ( int i = 0; i < myBar->count() && idx == -1; i++ ) { QRect r = myBar->tabRect( i ); @@ -1847,9 +1836,11 @@ int QtxWorkstackArea::tabAt( const QPoint& p ) const /*! Event handler for custom events */ -void QtxWorkstackArea::customEvent( QCustomEvent* e ) +void QtxWorkstackArea::customEvent( QEvent* e ) { - switch ( e->type() ) + WidgetEvent* we = (WidgetEvent*)e; + + switch ( we->type() ) { case ActivateWidget: emit activated( activeWidget() ); @@ -1859,18 +1850,20 @@ void QtxWorkstackArea::customEvent( QCustomEvent* e ) { if ( !activeWidget()->focusWidget() ) activeWidget()->setFocus(); - else { - if ( activeWidget()->focusWidget()->hasFocus()) { - QFocusEvent in(QEvent::FocusIn); - QApplication::sendEvent(this, &in); - } + else + { + if ( activeWidget()->focusWidget()->hasFocus() ) + { + QFocusEvent in( QEvent::FocusIn ); + QApplication::sendEvent( this, &in ); + } else activeWidget()->focusWidget()->setFocus(); } } break; case RemoveWidget: - removeWidget( (QWidget*)e->data() ); + removeWidget( we->widget() ); break; } } @@ -1880,7 +1873,7 @@ void QtxWorkstackArea::customEvent( QCustomEvent* e ) */ void QtxWorkstackArea::focusInEvent( QFocusEvent* e ) { - QWidget::focusInEvent( e ); + QFrame::focusInEvent( e ); emit activated( activeWidget() ); } @@ -1890,7 +1883,7 @@ void QtxWorkstackArea::focusInEvent( QFocusEvent* e ) */ void QtxWorkstackArea::mousePressEvent( QMouseEvent* e ) { - QWidget::mousePressEvent( e ); + QFrame::mousePressEvent( e ); emit activated( activeWidget() ); } @@ -1908,7 +1901,7 @@ void QtxWorkstackArea::onClose() /*! SLOT: called if tab page is selected */ -void QtxWorkstackArea::onSelected( int id ) +void QtxWorkstackArea::onCurrentChanged( int ) { updateCurrent(); @@ -1938,13 +1931,13 @@ void QtxWorkstackArea::onChildDestroyed( QObject* obj ) QWidget* wid = 0; for ( ChildMap::ConstIterator it = myChild.begin(); it != myChild.end() && !wid; ++it ) { - if ( it.data() == child ) + if ( it.value() == child ) wid = it.key(); } myChild.remove( wid ); - QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)RemoveWidget, wid ) ); + QApplication::postEvent( this, new WidgetEvent( (QEvent::Type)RemoveWidget, wid ) ); } /*! @@ -1985,16 +1978,16 @@ void QtxWorkstackArea::onChildCaptionChanged( QtxWorkstackChild* c ) void QtxWorkstackArea::updateCurrent() { QMap map; - for ( QWidgetListIt it( myList ); it.current(); ++it ) + for ( QWidgetList::iterator it = myList.begin(); it != myList.end(); ++it ) { - map.insert( it.current(), isBlocked( it.current() ) ); - setBlocked( it.current(), true ); + map.insert( *it, isBlocked( *it ) ); + setBlocked( *it, true ); } - myStack->raiseWidget( myBar->currentTab() ); + myStack->setCurrentWidget( child( widget( myBar->tabId( myBar->currentIndex() ) ) ) ); - for ( QWidgetListIt itr( myList ); itr.current(); ++itr ) - setBlocked( itr.current(), map.contains( itr.current() ) ? map[itr.current()] : false ); + for ( QWidgetList::iterator itr = myList.begin(); itr != myList.end(); ++itr ) + setBlocked( *itr, map.contains( *itr ) ? map[*itr] : false ); } /*! @@ -2003,20 +1996,12 @@ void QtxWorkstackArea::updateCurrent() */ void QtxWorkstackArea::updateTab( QWidget* wid ) { - QTab* tab = myBar->tab( widgetId( wid ) ); - if ( !tab ) + int idx = myBar->indexOf( widgetId( wid ) ); + if ( idx < 0 ) return; - QIconSet icoSet; - if ( wid->icon() ) - { - QPixmap pix = *wid->icon(); - pix.convertFromImage( pix.convertToImage().smoothScale( pix.width(), 16, QImage::ScaleMin ) ); - icoSet = QIconSet( pix ); - } - - tab->setIconSet( icoSet ); - tab->setText( wid->caption() ); + myBar->setTabIcon( idx, wid->windowIcon() ); + myBar->setTabText( idx, wid->windowTitle() ); } /*! @@ -2028,7 +2013,7 @@ QWidget* QtxWorkstackArea::widget( const int id ) const QWidget* wid = 0; for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !wid; ++it ) { - if ( it.data().id == id ) + if ( it.value().id == id ) wid = it.key(); } return wid; @@ -2068,7 +2053,7 @@ void QtxWorkstackArea::setWidgetActive( QWidget* wid ) if ( id < 0 ) return; - myBar->setCurrentTab( id ); + myBar->setCurrentIndex( myBar->indexOf( id ) ); } /*! @@ -2090,8 +2075,8 @@ void QtxWorkstackArea::setWidgetShown( QWidget* wid, const bool on ) */ void QtxWorkstackArea::updateState() { - bool updBar = myBar->isUpdatesEnabled(); - bool updStk = myStack->isUpdatesEnabled(); + bool updBar = myBar->updatesEnabled(); + bool updStk = myStack->updatesEnabled(); myBar->setUpdatesEnabled( false ); myStack->setUpdatesEnabled( false ); @@ -2101,9 +2086,9 @@ void QtxWorkstackArea::updateState() QWidget* prev = activeWidget(); int idx = 0; - for ( QWidgetListIt it( myList ); it.current(); ++it ) + for ( QWidgetList::iterator it = myList.begin(); it != myList.end(); ++it ) { - QWidget* wid = it.current(); + QWidget* wid = *it; int id = widgetId( wid ); if ( id < 0 ) @@ -2111,15 +2096,12 @@ void QtxWorkstackArea::updateState() bool vis = widgetVisibility( wid ); - if ( myBar->tab( id ) && ( !vis || myBar->indexOf( id ) != idx ) ) - myBar->removeTab( myBar->tab( id ) ); + int cIdx = myBar->indexOf( id ); + if ( cIdx != -1 && ( !vis || myBar->indexOf( id ) != idx ) ) + myBar->removeTab( cIdx ); - if ( !myBar->tab( id ) && vis ) - { - QTab* tab = new QTab( wid->caption() ); - myBar->insertTab( tab, idx ); - tab->setIdentifier( id ); - } + if ( myBar->indexOf( id ) == -1 && vis ) + myBar->setTabId( myBar->insertTab( idx, wid->windowTitle() ), id ); updateTab( wid ); @@ -2130,8 +2112,8 @@ void QtxWorkstackArea::updateState() if ( !vis ) myStack->removeWidget( cont ); - else if ( !myStack->widget( id ) ) - myStack->addWidget( cont, id ); + else if ( myStack->indexOf( cont ) < 0 ) + myStack->addWidget( cont ); if ( vis ) idx++; @@ -2140,10 +2122,10 @@ void QtxWorkstackArea::updateState() } int curId = widgetId( prev ); - if ( !myBar->tab( curId ) ) + if ( myBar->indexOf( curId ) < 0 ) { QWidget* wid = 0; - int pos = myList.find( prev ); + int pos = myList.indexOf( prev ); for ( int i = pos - 1; i >= 0 && !wid; i-- ) { if ( widgetVisibility( myList.at( i ) ) ) @@ -2160,7 +2142,7 @@ void QtxWorkstackArea::updateState() curId = widgetId( wid ); } - myBar->setCurrentTab( curId ); + myBar->setCurrentIndex( myBar->indexOf( curId ) ); myBar->blockSignals( block ); @@ -2196,8 +2178,8 @@ int QtxWorkstackArea::generateId() const { QMap map; - for ( WidgetInfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end(); ++it ) - map.insert( it.data().id, 0 ); + for ( WidgetInfoMap::const_iterator it = myInfo.begin(); it != myInfo.end(); ++it ) + map.insert( it.value().id, 0 ); int id = 0; while ( map.contains( id ) ) @@ -2243,12 +2225,14 @@ QtxWorkstackChild* QtxWorkstackArea::child( QWidget* wid ) const /*! Constructor */ -QtxWorkstackChild::QtxWorkstackChild( QWidget* wid, QWidget* parent ) -: QHBox( parent ), +QtxWorkstackChild::QtxWorkstackChild( QWidget* wid, QWidget* parent, Qt::WindowFlags f ) +: QWidget( parent ), myWidget( wid ) { - myWidget->reparent( this, QPoint( 0, 0 ), myWidget->isVisibleTo( myWidget->parentWidget() ) ); + myWidget->setParent( this, f ); myWidget->installEventFilter( this ); + QVBoxLayout* base = new QVBoxLayout( this ); + base->addWidget( myWidget ); connect( myWidget, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); } @@ -2258,14 +2242,17 @@ myWidget( wid ) */ QtxWorkstackChild::~QtxWorkstackChild() { - qApp->removeEventFilter( this ); + QApplication::instance()->removeEventFilter( this ); if ( !widget() ) return; - widget()->removeEventFilter( this ); - widget()->reparent( 0, QPoint( 0, 0 ), false ); disconnect( widget(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); + + widget()->hide(); + widget()->removeEventFilter( this ); + + widget()->setParent( 0 ); } /*! @@ -2283,7 +2270,7 @@ bool QtxWorkstackChild::eventFilter( QObject* o, QEvent* e ) { if ( o->isWidgetType() ) { - if ( e->type() == QEvent::CaptionChange || e->type() == QEvent::IconChange ) + if ( e->type() == QEvent::WindowTitleChange || e->type() == QEvent::WindowIconChange ) emit captionChanged( this ); if ( !e->spontaneous() && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) ) @@ -2295,7 +2282,7 @@ bool QtxWorkstackChild::eventFilter( QObject* o, QEvent* e ) if ( e->type() == QEvent::FocusIn ) emit activated( this ); } - return QHBox::eventFilter( o, e ); + return QWidget::eventFilter( o, e ); } /*! @@ -2315,12 +2302,12 @@ void QtxWorkstackChild::onDestroyed( QObject* obj ) */ void QtxWorkstackChild::childEvent( QChildEvent* e ) { - if ( e->type() == QEvent::ChildRemoved && e->child() == widget() ) + if ( e->removed() && e->child() == widget() ) { myWidget = 0; deleteLater(); } - QHBox::childEvent( e ); + QWidget::childEvent( e ); } /*! @@ -2330,6 +2317,8 @@ QtxWorkstackTabBar::QtxWorkstackTabBar( QWidget* parent ) : QTabBar( parent ), myId( -1 ) { + setDrawBase( true ); + setElideMode( Qt::ElideNone ); } /*! @@ -2339,6 +2328,30 @@ QtxWorkstackTabBar::~QtxWorkstackTabBar() { } +int QtxWorkstackTabBar::tabId( const int index ) const +{ + QVariant v = tabData( index ); + if ( !v.canConvert( QVariant::Int ) ) + return -1; + return v.toInt(); +} + +void QtxWorkstackTabBar::setTabId( const int index, const int id ) +{ + setTabData( index, id ); +} + +int QtxWorkstackTabBar::indexOf( const int id ) const +{ + int index = -1; + for ( uint i = 0; i < count() && index < 0; i++ ) + { + if ( tabId( i ) == id ) + index = i; + } + return index; +} + /*! Sets tab bar as active or inactive \param on - new active state @@ -2347,61 +2360,29 @@ void QtxWorkstackTabBar::setActive( const bool on ) { QFont aFont = font(); aFont.setUnderline( on ); - QColorGroup aColGrp; QPalette aPal = palette(); - if ( !on ) { - aPal.setColor( QColorGroup::HighlightedText, aColGrp.foreground() ); - aPal.setColor( QColorGroup::Highlight, colorGroup().dark().light( DARK_COLOR_LIGHT ) ); + if ( !on ) + { + aPal.setColor( QPalette::HighlightedText, aPal.color( QPalette::Foreground ) ); + aPal.setColor( QPalette::Highlight, aPal.color( QPalette::Dark ).light( DARK_COLOR_LIGHT ) ); setPalette( aPal ); } - else { - aPal.setColor( QColorGroup::HighlightedText, aColGrp.highlightedText() ); - aPal.setColor( QColorGroup::Highlight, aColGrp.highlight() ); - unsetPalette(); + else + { + aPal.setColor( QPalette::HighlightedText, aPal.color( QPalette::HighlightedText ) ); + aPal.setColor( QPalette::Highlight, aPal.color( QPalette::Highlight ) ); } setFont( aFont ); update(); } -/*! - \return tab rectangle - \param idx - tab index -*/ -QRect QtxWorkstackTabBar::tabRect( const int idx ) const -{ - QRect r; - QTab* t = tabAt( idx ); - if ( t ) - { - r = t->rect(); - r.setLeft( QMAX( r.left(), 0 ) ); - - int x1 = tabAt( 0 )->rect().left(); - int x2 = tabAt( count() - 1 )->rect().right(); - - int bw = 0; - if ( QABS( x2 - x1 ) > width() ) -#if defined QT_VERSION && QT_VERSION >= 0x30300 - bw = 2 * style().pixelMetric( QStyle::PM_TabBarScrollButtonWidth, this ); -#else - bw = 2 * 16; -#endif - - int limit = width() - bw; - r.setRight( QMIN( r.right(), limit ) ); - - r = QRect( mapToGlobal( r.topLeft() ), r.size() ); - } - return r; -} - /*! Custom mouse move event handler */ void QtxWorkstackTabBar::mouseMoveEvent( QMouseEvent* e ) { - if ( myId != -1 && !tab( myId )->rect().contains( e->pos() ) ) + if ( myId != -1 && !tabRect( indexOf( myId ) ).contains( e->pos() ) ) { myId = -1; emit dragActiveTab(); @@ -2417,8 +2398,8 @@ void QtxWorkstackTabBar::mousePressEvent( QMouseEvent* e ) { QTabBar::mousePressEvent( e ); - if ( e->button() == LeftButton ) - myId = currentTab(); + if ( e->button() == Qt::LeftButton ) + myId = tabId( currentIndex() ); } /*! @@ -2430,7 +2411,7 @@ void QtxWorkstackTabBar::mouseReleaseEvent( QMouseEvent* e ) myId = -1; - if ( e->button() == RightButton ) + if ( e->button() == Qt::RightButton ) emit contextMenuRequested( e->globalPos() ); } @@ -2446,6 +2427,7 @@ void QtxWorkstackTabBar::contextMenuEvent( QContextMenuEvent* e ) /*! Draws label of tab bar */ +/* void QtxWorkstackTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const { if ( currentTab() != t->identifier() ) @@ -2456,6 +2438,7 @@ void QtxWorkstackTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool } QTabBar::paintLabel( p, br, t, has_focus ); } +*/ /*! Constructor @@ -2465,10 +2448,11 @@ QtxWorkstackDrag::QtxWorkstackDrag( QtxWorkstack* ws, QtxWorkstackChild* child ) myWS( ws ), myTab( -1 ), myArea( 0 ), -myPainter( 0 ), -myChild( child ) +myChild( child ), +myTabRect( 0 ), +myAreaRect( 0 ) { - qApp->installEventFilter( this ); + QApplication::instance()->installEventFilter( this ); } /*! @@ -2476,7 +2460,7 @@ myChild( child ) */ QtxWorkstackDrag::~QtxWorkstackDrag() { - qApp->removeEventFilter( this ); + QApplication::instance()->removeEventFilter( this ); endDrawRect(); } @@ -2566,26 +2550,35 @@ void QtxWorkstackDrag::dropWidget() */ void QtxWorkstackDrag::drawRect() { - if ( !myPainter || !myArea ) + if ( !myArea ) return; QRect r = myArea->floatRect(); - int m = myPainter->pen().width(); + int m = 2; r.setTop( r.top() + m + 2 ); r.setLeft( r.left() + m + 2 ); r.setRight( r.right() - m - 2 ); r.setBottom( r.bottom() - m - 2 ); - myPainter->drawRect( r ); + if ( myAreaRect ) + { + myAreaRect->setGeometry( r ); + myAreaRect->setVisible( r.isValid() ); + } QRect tr = myArea->floatTab( myTab ); + tr.setTop( tr.top() + m ); tr.setLeft( tr.left() + m ); tr.setRight( tr.right() - m ); tr.setBottom( tr.bottom() - m ); - myPainter->drawRect( tr ); + if ( myTabRect ) + { + myTabRect->setGeometry( tr ); + myTabRect->setVisible( tr.isValid() ); + } } /*! @@ -2593,8 +2586,11 @@ void QtxWorkstackDrag::drawRect() */ void QtxWorkstackDrag::endDrawRect() { - delete myPainter; - myPainter = 0; + delete myAreaRect; + myAreaRect = 0; + + delete myTabRect; + myTabRect = 0; } /*! @@ -2602,13 +2598,13 @@ void QtxWorkstackDrag::endDrawRect() */ void QtxWorkstackDrag::startDrawRect() { - if ( myPainter ) - return; + if ( !myTabRect ) + myTabRect = new QRubberBand( QRubberBand::Rectangle ); + + myTabRect->hide(); - int scr = QApplication::desktop()->screenNumber( (QWidget*)this ); - QWidget* paint_on = QApplication::desktop()->screen( scr ); + if ( !myAreaRect ) + myAreaRect = new QRubberBand( QRubberBand::Rectangle ); - myPainter = new QPainter( paint_on, true ); - myPainter->setPen( QPen( gray, 3 ) ); - myPainter->setRasterOp( XorROP ); + myAreaRect->hide(); } diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index c31479cc6..1682e0518 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -24,17 +24,18 @@ #include "Qtx.h" -#include -#include -#include -#include +#include +#include +#include +#include class QAction; class QTabBar; class QPainter; class QSplitter; class QPushButton; -class QWidgetStack; +class QRubberBand; +class QStackedWidget; class QtxWorkstackArea; class QtxWorkstackDrag; @@ -73,8 +74,7 @@ public: void split( const int ); - // STV: Useless function. wid->setFocus() should be used instead. - // void OnTop( QWidget* wid); + QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 ); void Split( QWidget* wid, const Qt::Orientation o, const SplitType type ); void Attract( QWidget* wid1, QWidget* wid2, const bool all ); @@ -85,14 +85,14 @@ public: QtxWorkstack& operator<<( const QString& ); QtxWorkstack& operator>>( QString& ); -signals: +Q_SIGNALS: void windowActivated( QWidget* ); -public slots: +public Q_SLOTS: void splitVertical(); void splitHorizontal(); -private slots: +private Q_SLOTS: void onRename(); void onCloseWindow(); void onDestroyed( QObject* ); @@ -101,13 +101,12 @@ private slots: void onDeactivated( QtxWorkstackArea* ); protected: - virtual void childEvent( QChildEvent* ); - virtual void customEvent( QCustomEvent* ); + virtual void customEvent( QEvent* ); private: QSplitter* splitter( QtxWorkstackArea* ) const; - void splitters( QSplitter*, QPtrList&, const bool = false ) const; - void areas( QSplitter*, QPtrList&, const bool = false ) const; + void splitters( QSplitter*, QList&, const bool = false ) const; + void areas( QSplitter*, QList&, const bool = false ) const; QSplitter* wrapSplitter( QtxWorkstackArea* ); void insertWidget( QWidget*, QWidget*, QWidget* ); @@ -131,7 +130,7 @@ private: const int need_pos, const int splitter_pos ); void splitterInfo( QSplitter*, QString& ) const; - void setSplitter( QSplitter*, const QString&, QMap< QSplitter*,QValueList >& ); + void setSplitter( QSplitter*, const QString&, QMap< QSplitter*, QList >& ); private: QWidget* myWin; @@ -146,17 +145,19 @@ private: friend class QtxWorkstackDrag; }; -class QtxWorkstackArea : public QWidget +class QtxWorkstackArea : public QFrame { Q_OBJECT + class WidgetEvent; + public: QtxWorkstackArea( QWidget* ); virtual ~QtxWorkstackArea(); bool isEmpty() const; - void insertWidget( QWidget*, const int = -1 ); + QWidget* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 ); void removeWidget( QWidget*, const bool = true ); QWidget* activeWidget() const; @@ -178,18 +179,17 @@ public: int tabAt( const QPoint& ) const; -signals: +Q_SIGNALS: void activated( QWidget* ); void contextMenuRequested( QWidget*, QPoint ); void deactivated( QtxWorkstackArea* ); -public slots: - virtual void show(); - virtual void hide(); +public Q_SLOTS: + virtual void setVisible( bool ); -private slots: +private Q_SLOTS: void onClose(); - void onSelected( int ); + void onCurrentChanged( int ); void onWidgetDestroyed(); @@ -203,7 +203,7 @@ private slots: void onContextMenuRequested( QPoint ); protected: - virtual void customEvent( QCustomEvent* ); + virtual void customEvent( QEvent* ); virtual void focusInEvent( QFocusEvent* ); virtual void mousePressEvent( QMouseEvent* ); @@ -243,7 +243,7 @@ private: private: QtxWorkstackTabBar* myBar; QPushButton* myClose; - QWidgetStack* myStack; + QStackedWidget* myStack; QWidgetList myList; WidgetInfoMap myInfo; @@ -251,25 +251,25 @@ private: BlockMap myBlock; }; -class QtxWorkstackChild : public QHBox +class QtxWorkstackChild : public QWidget { Q_OBJECT public: - QtxWorkstackChild( QWidget*, QWidget* = 0 ); + QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 ); virtual ~QtxWorkstackChild(); QWidget* widget() const; virtual bool eventFilter( QObject*, QEvent* ); -signals: +Q_SIGNALS: void shown( QtxWorkstackChild* ); void hided( QtxWorkstackChild* ); void activated( QtxWorkstackChild* ); void captionChanged( QtxWorkstackChild* ); -private slots: +private Q_SLOTS: void onDestroyed( QObject* ); protected: @@ -287,11 +287,13 @@ public: QtxWorkstackTabBar( QWidget* = 0 ); virtual ~QtxWorkstackTabBar(); - QRect tabRect( const int ) const; - void setActive( const bool ); -signals: + int tabId( const int ) const; + int indexOf( const int ) const; + void setTabId( const int, const int ); + +Q_SIGNALS: void dragActiveTab(); void contextMenuRequested( QPoint ); @@ -301,7 +303,7 @@ protected: virtual void mouseReleaseEvent( QMouseEvent* ); virtual void contextMenuEvent( QContextMenuEvent* ); - virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const; +// virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const; private: int myId; @@ -334,8 +336,8 @@ private: int myTab; QtxWorkstackArea* myArea; - QPainter* myPainter; - + QRubberBand* myTabRect; + QRubberBand* myAreaRect; }; #ifdef WIN32 diff --git a/src/Qtx/QtxWorkstackAction.cxx b/src/Qtx/QtxWorkstackAction.cxx deleted file mode 100644 index a1dbcb974..000000000 --- a/src/Qtx/QtxWorkstackAction.cxx +++ /dev/null @@ -1,407 +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: QtxWorkstackAction.cxx -// Author: Sergey TELKOV - -#include "QtxWorkstackAction.h" - -#include "QtxWorkstack.h" - -#include -#include - -/*! - Constructor -*/ -QtxWorkstackAction::QtxWorkstackAction( QtxWorkstack* ws, QObject* parent, const char* name ) -: QtxAction( tr( "Controls windows into workstack" ), tr( "Workstack management" ), 0, parent, name ), -myFlags( Standard ), -myWorkstack( ws ) -{ - myItem.insert( VSplit, new QtxAction( tr( "Split the active window on two vertical parts" ), - tr( "Split vertically" ), 0, this, 0, false ) ); - myItem.insert( HSplit, new QtxAction( tr( "Split the active window on two horizontal parts" ), - tr( "Split horizontally" ), 0, this, 0, false ) ); - - connect( myItem[VSplit], SIGNAL( activated() ), ws, SLOT( splitVertical() ) ); - connect( myItem[HSplit], SIGNAL( activated() ), ws, SLOT( splitHorizontal() ) ); -} - -/*! - Destructor -*/ -QtxWorkstackAction::~QtxWorkstackAction() -{ -} - -/*! - \return corresponding workstack -*/ -QtxWorkstack* QtxWorkstackAction::workstack() const -{ - return myWorkstack; -} - -/*! - \return set of action flags -*/ -int QtxWorkstackAction::items() const -{ - return myFlags; -} - -/*! - Sets action flags - \param flags - new set of flags -*/ -void QtxWorkstackAction::setItems( const int flags ) -{ - if ( !flags || flags == myFlags || !( flags & Split ) ) - return; - - myFlags = flags; -} - -/*! - \return true if action contains all flags - \param flags - new set of flags -*/ -bool QtxWorkstackAction::hasItems( const int flags ) const -{ - return ( myFlags & flags ) == flags; -} - -/*! - \return accelerator of item - \param id - item id -*/ -int QtxWorkstackAction::accel( const int id ) const -{ - int a = 0; - if ( myItem.contains( id ) ) - a = myItem[id]->accel(); - return a; -} - -/*! - \return icons of item - \param id - item id -*/ -QIconSet QtxWorkstackAction::iconSet( const int id ) const -{ - QIconSet ico; - if ( myItem.contains( id ) ) - ico = myItem[id]->iconSet(); - return ico; -} - -/*! - \return menu text of item - \param id - item id -*/ -QString QtxWorkstackAction::menuText( const int id ) const -{ - QString txt; - if ( myItem.contains( id ) ) - txt = myItem[id]->menuText(); - return txt; -} - -/*! - \return status tip of item - \param id - item id -*/ -QString QtxWorkstackAction::statusTip( const int id ) const -{ - QString txt; - if ( myItem.contains( id ) ) - txt = myItem[id]->statusTip(); - return txt; -} - -/*! - Changes accelerator of item - \param id - item id - \param a - new accelerator -*/ -void QtxWorkstackAction::setAccel( const int id, const int a ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setAccel( a ); -} - -/*! - Changes icons of item - \param id - item id - \param ico - new icons -*/ -void QtxWorkstackAction::setIconSet( const int id, const QIconSet& ico ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setIconSet( ico ); -} - -/*! - Changes menu text of item - \param id - item id - \param txt - new menu text -*/ -void QtxWorkstackAction::setMenuText( const int id, const QString& txt ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setMenuText( txt ); -} - -/*! - Changes status tip of item - \param id - item id - \param txt - new status tip -*/ -void QtxWorkstackAction::setStatusTip( const int id, const QString& txt ) -{ - if ( myItem.contains( id ) ) - myItem[id]->setStatusTip( txt ); -} - -/*! - Adds action to widget - \param wid - widget -*/ -bool QtxWorkstackAction::addTo( QWidget* wid ) -{ - return addTo( wid, -1 ); -} - -/*! - Adds action to widget - \param wid - widget - \param idx - position -*/ -bool QtxWorkstackAction::addTo( QWidget* wid, const int idx ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - checkPopup( pm ); - - if ( myMenu.contains( pm ) ) - return false; - - myMenu.insert( pm, QIntList() ); - fillPopup( pm, idx ); - - connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - return true; -} - -/*! - Removes action from widget - \param wid - widget -*/ -bool QtxWorkstackAction::removeFrom( QWidget* wid ) -{ - if ( !wid || !wid->inherits( "QPopupMenu" ) ) - return false; - - QPopupMenu* pm = (QPopupMenu*)wid; - if ( !myMenu.contains( pm ) ) - return false; - - clearPopup( pm ); - - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - - myMenu.remove( pm ); - - return true; -} - -/*! - Performs action - \param type - action type -*/ -void QtxWorkstackAction::perform( const int type ) -{ - switch ( type ) - { - case VSplit: - workstack()->splitVertical(); - break; - case HSplit: - workstack()->splitHorizontal(); - break; - } -} - -/*! - SLOT: called just before the popup menu is displayed, updates popup -*/ -void QtxWorkstackAction::onAboutToShow() -{ - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QPopupMenu" ) ) - return; - - QtxWorkstack* ws = workstack(); - if ( ws && myItem.contains( VSplit ) ) - myItem[VSplit]->setAccel( ws->accel( QtxWorkstack::SplitVertical ) ); - if ( ws && myItem.contains( HSplit ) ) - myItem[HSplit]->setAccel( ws->accel( QtxWorkstack::SplitHorizontal ) ); - - updatePopup( (QPopupMenu*)obj ); -} - -/*! - SLOT: called when popup menu is destroyed, removes it from menu -*/ -void QtxWorkstackAction::onPopupDestroyed( QObject* obj ) -{ - myMenu.remove( (QPopupMenu*)obj ); -} - -/*! - Updates popup - \param pm - popup menu -*/ -void QtxWorkstackAction::checkPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return; - - QIntList updList; - for ( QIntList::const_iterator it = myMenu[pm].begin(); it != myMenu[pm].end(); ++it ) - { - if ( pm->indexOf( *it ) != -1 ) - updList.append( *it ); - } - - myMenu.remove( pm ); - - if ( !updList.isEmpty() ) - myMenu.insert( pm, updList ); - else - { - disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); - disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) ); - } -} - -/*! - Clears and refills popup and updates state of actions - \param pm - popup menu -*/ -void QtxWorkstackAction::updatePopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return; - - fillPopup( pm, clearPopup( pm ) ); - - int count = workstack() ? workstack()->splitWindowList().count() : 0; - myItem[VSplit]->setEnabled( count > 1 ); - myItem[HSplit]->setEnabled( count > 1 ); -} - -/*! - Clears popup - \param pm - popup menu -*/ -int QtxWorkstackAction::clearPopup( QPopupMenu* pm ) -{ - if ( !myMenu.contains( pm ) ) - return -1; - - int idx = -1; - const QIntList& lst = myMenu[pm]; - for ( QIntList::const_iterator it = lst.begin(); it != lst.end() && idx == -1; ++it ) - idx = pm->indexOf( *it ); - - for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit ) - mit.data()->removeFrom( pm ); - - for ( QIntList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) - pm->removeItem( *itr ); - - return idx; -} - -/*! - Fills popup with items - \param pm - popup menu - \param idx - position -*/ -void QtxWorkstackAction::fillPopup( QPopupMenu* pm, const int idx ) -{ - if ( !pm ) - return; - - int index = idx < 0 ? pm->count() : QMIN( (int)pm->count(), idx ); - - myMenu.insert( pm, QIntList() ); - QIntList& lst = myMenu[pm]; - - for ( ItemMap::ConstIterator mit = myItem.begin(); mit != myItem.end(); ++mit ) - { - if ( !hasItems( mit.key() ) ) - continue; - - mit.data()->addTo( pm, index ); - lst.append( pm->idAt( index++ ) ); - } - - QtxWorkstack* ws = workstack(); - if ( !ws || !hasItems( Windows ) ) - return; - - QWidgetList wList = ws->windowList(); - if ( wList.isEmpty() ) - return; - - lst.append( pm->insertSeparator( index++ ) ); - - int param = 0; - pm->setCheckable( true ); - for ( QWidgetListIt it( wList ); it.current(); ++it ) - { - int id = pm->insertItem( it.current()->caption(), this, SLOT( onItemActivated( int ) ), 0, -1, index++ ); - pm->setItemParameter( id, param++ ); - pm->setItemChecked( id, it.current() == ws->activeWindow() ); - lst.append( id ); - } -} - -/*! - SLOT: called when popup item corresponding to window is activated, activates window -*/ -void QtxWorkstackAction::onItemActivated( int idx ) -{ - QtxWorkstack* ws = workstack(); - if ( !ws ) - return; - - QWidgetList wList = ws->windowList(); - if ( idx < 0 || idx >= (int)wList.count() ) - return; - - wList.at( idx )->setFocus(); -} diff --git a/src/Qtx/QtxWorkstackAction.h b/src/Qtx/QtxWorkstackAction.h deleted file mode 100644 index 650184d24..000000000 --- a/src/Qtx/QtxWorkstackAction.h +++ /dev/null @@ -1,97 +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: QtxWorkstackAction.h -// Author: Sergey TELKOV - -#ifndef QTXWORKSTACKACTION_H -#define QTXWORKSTACKACTION_H - -#include "QtxAction.h" - -class QtxWorkstack; - -#ifdef WIN32 -#pragma warning( disable:4251 ) -#endif - -class QTX_EXPORT QtxWorkstackAction : public QtxAction -{ - Q_OBJECT - -public: - enum { VSplit = 0x0001, - HSplit = 0x0002, - Windows = 0x0010, - Split = VSplit | HSplit, - Standard = Split | Windows }; - -public: - QtxWorkstackAction( QtxWorkstack*, QObject* = 0, const char* = 0 ); - virtual ~QtxWorkstackAction(); - - QtxWorkstack* workstack() const; - - int items() const; - void setItems( const int ); - bool hasItems( const int ) const; - - int accel( const int ) const; - QIconSet iconSet( const int ) const; - QString menuText( const int ) const; - QString statusTip( const int ) const; - - void setAccel( const int, const int ); - void setIconSet( const int, const QIconSet& ); - void setMenuText( const int, const QString& ); - void setStatusTip( const int, const QString& ); - - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); - virtual bool removeFrom( QWidget* ); - - void perform( const int ); - -private slots: - void onAboutToShow(); - void onItemActivated( int ); - void onPopupDestroyed( QObject* ); - -private: - void checkPopup( QPopupMenu* ); - void updatePopup( QPopupMenu* ); - - int clearPopup( QPopupMenu* ); - void fillPopup( QPopupMenu*, const int ); - -private: - typedef QMap MenuMap; - typedef QMap ItemMap; - -private: - MenuMap myMenu; - ItemMap myItem; - int myFlags; - QtxWorkstack* myWorkstack; -}; - -#ifdef WIN32 -#pragma warning( default:4251 ) -#endif - -#endif diff --git a/src/SUIT/Makefile.in b/src/SUIT/Makefile.in deleted file mode 100755 index bc25b7132..000000000 --- a/src/SUIT/Makefile.in +++ /dev/null @@ -1,126 +0,0 @@ -# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, 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 : Makefile.in -# Author : Vladimir Klyachin (OCN) -# Module : suit -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@srcdir@/resources - - -@COMMENCE@ - -# header files -EXPORT_HEADERS= SUIT.h \ - SUIT_ActionOperation.h \ - SUIT_Application.h \ - SUIT_Convertor.h \ - SUIT_DataObject.h \ - SUIT_DataObjectIterator.h \ - SUIT_DataObjectKey.h \ - SUIT_DataOwner.h \ - SUIT_Desktop.h \ - SUIT_ExceptionHandler.h \ - SUIT_FileDlg.h \ - SUIT_FileValidator.h \ - SUIT_MessageBox.h \ - SUIT_Operation.h \ - SUIT_OverrideCursor.h \ - SUIT_ParserSettings.h \ - SUIT_PopupClient.h \ - SUIT_ResourceMgr.h \ - SUIT_SelectionMgr.h \ - SUIT_Selector.h \ - SUIT_Session.h \ - SUIT_SmartPtr.h \ - SUIT_Study.h \ - SUIT_ToolButton.h \ - SUIT_Tools.h \ - SUIT_ViewManager.h \ - SUIT_ViewModel.h \ - SUIT_ViewWindow.h \ - SUIT_SelectionFilter.h \ - SUIT_Accel.h \ - SUIT_TreeSync.h - -# .po files to transform in .qm -PO_FILES = SUIT_images.po \ - SUIT_msg_en.po - -# Libraries targets -LIB = libsuit.la - -LIB_SRC= SUIT_ActionOperation.cxx \ - SUIT_Application.cxx \ - SUIT_DataObject.cxx \ - SUIT_DataObjectIterator.cxx \ - SUIT_DataObjectKey.cxx \ - SUIT_DataOwner.cxx \ - SUIT_Desktop.cxx \ - SUIT_ExceptionHandler.cxx \ - SUIT_FileDlg.cxx \ - SUIT_FileValidator.cxx \ - SUIT_MessageBox.cxx \ - SUIT_Operation.cxx \ - SUIT_OverrideCursor.cxx \ - SUIT_ParserSettings.cxx \ - SUIT_PopupClient.cxx \ - SUIT_ResourceMgr.cxx \ - SUIT_SelectionMgr.cxx \ - SUIT_Selector.cxx \ - SUIT_Session.cxx \ - SUIT_Study.cxx \ - SUIT_ToolButton.cxx \ - SUIT_Tools.cxx \ - SUIT_ViewManager.cxx \ - SUIT_ViewModel.cxx \ - SUIT_ViewWindow.cxx \ - SUIT_SelectionFilter.cxx \ - SUIT_Accel.cxx - -LIB_MOC = SUIT_ActionOperation.h \ - SUIT_Application.h \ - SUIT_DataObject.h \ - SUIT_Desktop.h \ - SUIT_FileDlg.h \ - SUIT_Operation.h \ - SUIT_PopupClient.h \ - SUIT_Session.h \ - SUIT_Study.h \ - SUIT_ToolButton.h \ - SUIT_ViewModel.h \ - SUIT_ViewWindow.h \ - SUIT_ViewManager.h \ - SUIT_SelectionMgr.h \ - SUIT_Selector.h \ - SUIT_Accel.h - -RESOURCES_FILES = \ - cascade.png \ - htile.png \ - vtile.png - -CPPFLAGS+=$(QT_INCLUDES) - -LDFLAGS+=$(QT_MT_LIBS) -lqtx - -@CONCLUDE@ diff --git a/src/SUIT/SUIT.h b/src/SUIT/SUIT.h index 82940286a..151fba4d1 100755 --- a/src/SUIT/SUIT.h +++ b/src/SUIT/SUIT.h @@ -20,13 +20,13 @@ #define SUIT_H #if defined SUIT_EXPORTS -#if defined WNT +#if defined WIN32 #define SUIT_EXPORT __declspec( dllexport ) #else #define SUIT_EXPORT #endif #else -#if defined WNT +#if defined WIN32 #define SUIT_EXPORT __declspec( dllimport ) #else #define SUIT_EXPORT @@ -39,7 +39,7 @@ #define true 1 #endif -#if defined WNT +#if defined WIN32 #pragma warning ( disable: 4251 ) #endif diff --git a/src/SUIT/SUIT_Accel.cxx b/src/SUIT/SUIT_Accel.cxx index 7bc7b5167..9e92904b5 100644 --- a/src/SUIT/SUIT_Accel.cxx +++ b/src/SUIT/SUIT_Accel.cxx @@ -19,22 +19,21 @@ // SUIT_Accel.cxx: implementation of the SUIT_Accel class. #include "SUIT_Accel.h" + +#include "SUIT_ViewModel.h" #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" -#include "SUIT_ViewModel.h" - -#include -#include -#include +#include +#include SUIT_Accel* SUIT_Accel::myself = 0; /*! Constructor [private].*/ SUIT_Accel::SUIT_Accel() - : QObject( qApp, "SUIT_Accel" ) +: QObject( QCoreApplication::instance() ) { - qApp->installEventFilter( this ); + QCoreApplication::instance()->installEventFilter( this ); } /*! getAccel() : public interface for SUIT_Accel object. Only one instance is created and returned. */ @@ -61,10 +60,12 @@ void SUIT_Accel::setActionKey( const int action, const int key, const QString& t /*! unsetActionKey() : unregister a certain key accelerator */ void SUIT_Accel::unsetActionKey( const int key, const QString& type ) { - if ( myMap.contains( type ) ) { + if ( myMap.contains( type ) ) + { IdActionMap idActionMap = myMap[type]; - if ( idActionMap.contains( key ) ) { - idActionMap.erase( key ); + if ( idActionMap.contains( key ) ) + { + idActionMap.remove( key ); myMap[type] = idActionMap; } } @@ -73,7 +74,8 @@ void SUIT_Accel::unsetActionKey( const int key, const QString& type ) /*! getParentViewWindow() : returns given object or any of its parents-grandparents-.. if it is a SUIT_ViewWindow */ SUIT_ViewWindow* getParentViewWindow( const QObject* obj ) { - if ( obj ) { + if ( obj ) + { if ( obj->inherits( "SUIT_ViewWindow" ) ) return (SUIT_ViewWindow*)obj; else @@ -83,17 +85,16 @@ SUIT_ViewWindow* getParentViewWindow( const QObject* obj ) } /*! getKey() : returns integer key code (with modifiers) made of key pressed 'inside' given event */ -int getKey( QKeyEvent *keyEvent ) +int getKey( QKeyEvent* keyEvent ) { - int key = keyEvent->key(), - state = keyEvent->state(); - if ( state & Qt::ShiftButton ) + int key = keyEvent->key(), state = keyEvent->modifiers(); + if ( state & Qt::ShiftModifier ) key += Qt::SHIFT; - if ( state & Qt::ControlButton ) + if ( state & Qt::ControlModifier ) key += Qt::CTRL; - if ( state & Qt::AltButton ) + if ( state & Qt::AltModifier ) key += Qt::ALT; - if ( state & Qt::MetaButton ) + if ( state & Qt::MetaModifier ) key += Qt::META; return key; } diff --git a/src/SUIT/SUIT_Accel.h b/src/SUIT/SUIT_Accel.h index fdc9cd384..968e0776a 100644 --- a/src/SUIT/SUIT_Accel.h +++ b/src/SUIT/SUIT_Accel.h @@ -18,14 +18,14 @@ // // SUIT_Accel.h: interface for the SUIT_Accel class. -#ifndef SUIT_Accel_h -#define SUIT_Accel_h +#ifndef SUIT_ACELL_H +#define SUIT_ACELL_H #include "SUIT.h" -#include -#include -#include +#include +#include +#include /*! \class SUIT_Accel diff --git a/src/SUIT/SUIT_ActionOperation.cxx b/src/SUIT/SUIT_ActionOperation.cxx index d56f01705..5c7b4711b 100644 --- a/src/SUIT/SUIT_ActionOperation.cxx +++ b/src/SUIT/SUIT_ActionOperation.cxx @@ -49,20 +49,20 @@ QtxAction* SUIT_ActionOperation::action() const /*!Set action. * Create new instance of QtxAction and set. */ -void SUIT_ActionOperation::setAction( const QString& text, const QIconSet& icon, - const QString& menuText, QKeySequence accel, - QObject* parent, const char* name, bool toggle ) +void SUIT_ActionOperation::setAction( const QString& text, const QIcon& icon, + const QString& menuText, QKeySequence accel, + QObject* parent, bool toggle ) { - setAction( new QtxAction( text, icon, menuText, accel, parent, name, toggle ) ); + setAction( new QtxAction( text, icon, menuText, accel, parent, 0, toggle ) ); } /*!Set action. * Create new instance of QtxAction and set. */ void SUIT_ActionOperation::setAction( const QString& text, const QString& menuText, - QKeySequence accel, QObject* parent, const char* name, bool toggle ) + QKeySequence accel, QObject* parent, bool toggle ) { - setAction( new QtxAction(text, menuText, accel, parent, name, toggle ) ); + setAction( new QtxAction( text, menuText, accel, parent, 0, toggle ) ); } /*!Set action. diff --git a/src/SUIT/SUIT_ActionOperation.h b/src/SUIT/SUIT_ActionOperation.h index bed11e318..e70d24501 100644 --- a/src/SUIT/SUIT_ActionOperation.h +++ b/src/SUIT/SUIT_ActionOperation.h @@ -21,11 +21,12 @@ #include "SUIT_Operation.h" -class QtxAction; +class QIcon; class QString; -class QIconSet; -class QKeySequence; class QWidget; +class QKeySequence; + +class QtxAction; /*!Provide support QtxAction*/ class SUIT_EXPORT SUIT_ActionOperation : public SUIT_Operation @@ -33,26 +34,26 @@ class SUIT_EXPORT SUIT_ActionOperation : public SUIT_Operation Q_OBJECT public: - SUIT_ActionOperation( SUIT_Application* theApp ); + SUIT_ActionOperation( SUIT_Application* ); virtual ~SUIT_ActionOperation(); QtxAction* action() const; /** @name GUI management*/ //@{ - virtual void setAction( const QString& text, const QIconSet& icon, const QString& menuText, - QKeySequence accel, QObject* parent, const char* name = 0, bool toggle = false ); + virtual void setAction( const QString& text, const QIcon& icon, const QString& menuText, + QKeySequence accel, QObject* parent, bool toggle = false ); - virtual void setAction( const QString& text, const QString& menuText, QKeySequence accel, - QObject* parent, const char* name = 0, bool toggle = false ); + virtual void setAction( const QString& text, const QString& menuText, + QKeySequence accel, QObject* parent, bool toggle = false ); virtual void setAction( QtxAction* theAction ); bool addTo( QWidget* theWidget ); bool addTo( QWidget* theWidget, int thePos ); - + void setStatusTip( const QString& theTip ); //@} - + private: QtxAction* myAction; diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index bbe68030d..5e19c40cc 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -22,9 +22,10 @@ #include "SUIT_Desktop.h" #include "SUIT_ResourceMgr.h" -#include -#include -#include +#include + +#include +#include #include #include @@ -38,7 +39,9 @@ SUIT_Application::SUIT_Application() myStudy( 0 ), myDesktop( 0 ), myStatusLabel( 0 ) -{ +{ + if ( SUIT_Session::session() ) + SUIT_Session::session()->insertApplication( this ); } /*! @@ -211,7 +214,7 @@ void SUIT_Application::onInfoClear() */ SUIT_Application* SUIT_Application::startApplication( int argc, char** argv ) const { - return startApplication( name(), argc, argv ); + return startApplication( objectName(), argc, argv ); } /*! @@ -462,7 +465,12 @@ int SUIT_Application::createMenu( const int id, const QString& menu, const int g */ void SUIT_Application::setMenuShown( QAction* a, const bool on ) { - setMenuShown( actionId( a ), on ); + if ( !a || !desktop() ) + return; + + QtxActionMenuMgr* mMgr = desktop()->menuMgr(); + if ( mMgr ) + mMgr->setShown( mMgr->actionId( a ), on ); } /*! @@ -472,8 +480,7 @@ void SUIT_Application::setMenuShown( QAction* a, const bool on ) */ void SUIT_Application::setMenuShown( const int id, const bool on ) { - if ( desktop() && desktop()->menuMgr() ) - desktop()->menuMgr()->setShown( id, on ); + setMenuShown( action( id ), on ); } /*! @@ -483,7 +490,12 @@ void SUIT_Application::setMenuShown( const int id, const bool on ) */ void SUIT_Application::setToolShown( QAction* a, const bool on ) { - setToolShown( actionId( a ), on ); + if ( !a || !desktop() ) + return; + + QtxActionToolMgr* tMgr = desktop()->toolMgr(); + if ( tMgr ) + tMgr->setShown( tMgr->actionId( a ), on ); } /*! @@ -493,8 +505,7 @@ void SUIT_Application::setToolShown( QAction* a, const bool on ) */ void SUIT_Application::setToolShown( const int id, const bool on ) { - if ( desktop() && desktop()->toolMgr() ) - desktop()->toolMgr()->setShown( id, on ); + setToolShown( action( id ), on ); } /*! @@ -538,10 +549,9 @@ QAction* SUIT_Application::action( const int id ) const int SUIT_Application::actionId( const QAction* a ) const { int id = -1; - for ( QMap::ConstIterator it = myActionMap.begin(); - it != myActionMap.end() && id == -1; - ++it ) { - if ( it.data() == a ) + for ( QMap::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it ) + { + if ( it.value() == a ) id = it.key(); } return id; @@ -561,7 +571,7 @@ int SUIT_Application::actionId( const QAction* a ) const \param reciever - object that contains slot \param member - slot to be called when action is activated */ -QAction* SUIT_Application::createAction( const int id, const QString& text, const QIconSet& icon, +QAction* SUIT_Application::createAction( const int id, const QString& text, const QIcon& icon, const QString& menu, const QString& tip, const int key, QObject* parent, const bool toggle, QObject* reciever, const char* member ) { @@ -569,7 +579,7 @@ QAction* SUIT_Application::createAction( const int id, const QString& text, cons a->setStatusTip( tip ); if ( reciever && member ) - connect( a, SIGNAL( activated() ), reciever, member ); + connect( a, SIGNAL( triggered( bool ) ), reciever, member ); registerAction( id, a ); diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 0bf48847e..472c5d27b 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -22,13 +22,13 @@ #include "SUIT.h" #include "SUIT_Study.h" -#include -#include +#include +#include +class QIcon; class QLabel; class QString; class QAction; -class QIconSet; class SUIT_Desktop; class SUIT_Convertor; class SUIT_ViewModel; @@ -156,7 +156,7 @@ protected: QAction* action( const int ) const; int actionId( const QAction* ) const; int registerAction( const int, QAction* ); - QAction* createAction( const int, const QString&, const QIconSet&, const QString&, + QAction* createAction( const int, const QString&, const QIcon&, const QString&, const QString&, const int, QObject* = 0, const bool = false, QObject* = 0, const char* = 0 ); diff --git a/src/SUIT/SUIT_Convertor.h b/src/SUIT/SUIT_Convertor.h deleted file mode 100755 index fd37969fb..000000000 --- a/src/SUIT/SUIT_Convertor.h +++ /dev/null @@ -1,43 +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 -// -// SUIT_Convertor.h: interface for the SUIT_Convertor class. -// - -#if !defined(AFX_SUIT_CONVERTOR_H__4C27F4C7_DC7C_4BEF_9DC1_EFB97B387EBF__INCLUDED_) -#define AFX_SUIT_CONVERTOR_H__4C27F4C7_DC7C_4BEF_9DC1_EFB97B387EBF__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#include "SUIT.h" -#include "SUIT_DataObject.h" -#include "SUIT_ViewModel.h" - -/*! Provides convertation of selected object of specified viewer into SUIT_DataObject. - * Instance of Convertor class is created by Application according to data type and viewers used. - */ -class SUIT_Convertor -{ -public: - virtual DataObjectList getSelectedObjects(const SUIT_ViewModel* theViewer) = 0; - virtual void highlight(const SUIT_ViewModel* theViewer, const DataObjectList& theObjList) = 0; -}; - -#endif // !defined(AFX_SUIT_CONVERTOR_H__4C27F4C7_DC7C_4BEF_9DC1_EFB97B387EBF__INCLUDED_) diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 1082579fc..9f36eda10 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -18,8 +18,6 @@ // #include "SUIT_DataObject.h" -#include - #include "SUIT_DataObjectKey.h" /*! @@ -28,12 +26,11 @@ SUIT_DataObject::SUIT_DataObject( SUIT_DataObject* p ) : myParent( 0 ), - mySignal( 0 ), - myOpen( false ), - myCheck( false ) +mySignal( 0 ), +myOpen( false ), +myCheck( false ), +myAutoDel( true ) { - myChildren.setAutoDelete( true ); - setParent( p ); } @@ -56,8 +53,14 @@ SUIT_DataObject::~SUIT_DataObject() mySignal->setOwner( 0 ); } - for ( QPtrListIterator it( myChildren ); it.current(); ++it ) - it.current()->myParent = 0; + for ( DataObjectList::iterator it = myChildren.begin(); it != myChildren.end(); ++it ) + (*it)->myParent = 0; + + if ( autoDeleteChildren() ) + { + for ( DataObjectList::iterator itr = myChildren.begin(); itr != myChildren.end(); ++itr ) + delete *itr; + } delete mySignal; } @@ -79,7 +82,7 @@ SUIT_DataObject* SUIT_DataObject::firstChild() const { SUIT_DataObject* child = 0; if ( !myChildren.isEmpty() ) - child = myChildren.getFirst(); + child = myChildren.first(); return child; } @@ -91,7 +94,7 @@ SUIT_DataObject* SUIT_DataObject::lastChild() const { SUIT_DataObject* child = 0; if ( !myChildren.isEmpty() ) - child = myChildren.getLast(); + child = myChildren.last(); return child; } @@ -113,9 +116,9 @@ int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const int res = -1; int i = 0; - for ( DataObjectListIterator it( myChildren ); it.current() && res == -1; ++it, i++ ) + for ( DataObjectList::const_iterator it = myChildren.begin(); it != myChildren.end() && res == -1; ++it, i++ ) { - if ( it.current() == obj ) + if ( *it == obj ) res = i; } @@ -179,7 +182,7 @@ SUIT_DataObject* SUIT_DataObject::prevBrother() const bool SUIT_DataObject::autoDeleteChildren() const { - return myChildren.autoDelete(); + return myAutoDel; } /*! @@ -188,7 +191,7 @@ bool SUIT_DataObject::autoDeleteChildren() const void SUIT_DataObject::setAutoDeleteChildren( const bool on ) { - myChildren.setAutoDelete( on ); + myAutoDel = on; } /*! @@ -197,11 +200,11 @@ void SUIT_DataObject::setAutoDeleteChildren( const bool on ) void SUIT_DataObject::children( DataObjectList& lst, const bool rec ) const { - for ( DataObjectListIterator it( myChildren ); it.current(); ++it ) + for ( DataObjectList::const_iterator it = myChildren.begin(); it != myChildren.end(); ++it ) { - lst.append( it.current() ); + lst.append( *it ); if ( rec ) - it.current()->children( lst, rec ); + (*it)->children( lst, rec ); } } @@ -231,11 +234,11 @@ void SUIT_DataObject::appendChild( SUIT_DataObject* theObj ) void SUIT_DataObject::insertChild( SUIT_DataObject* theObj, int thePosition ) { - if ( !theObj || myChildren.find( theObj ) != -1 ) + if ( !theObj || myChildren.contains( theObj ) ) return; int pos = thePosition < 0 ? myChildren.count() : thePosition; - myChildren.insert( QMIN( pos, (int)myChildren.count() ), theObj ); + myChildren.insert( qMin( pos, (int)myChildren.count() ), theObj ); theObj->setParent( this ); } @@ -248,13 +251,8 @@ void SUIT_DataObject::removeChild( SUIT_DataObject* theObj ) if ( !theObj ) return; - bool ad = myChildren.autoDelete(); - myChildren.setAutoDelete( false ); - - if ( myChildren.remove( theObj ) ) + if ( myChildren.removeAll( theObj ) ) theObj->setParent( 0 ); - - myChildren.setAutoDelete( ad ); } /*! @@ -297,8 +295,8 @@ void SUIT_DataObject::reparentChildren( const SUIT_DataObject* obj ) DataObjectList lst; obj->children( lst ); - for ( DataObjectListIterator it( lst ); it.current(); ++it ) - it.current()->setParent( this ); + for ( DataObjectList::iterator it = lst.begin(); it != lst.end(); ++it ) + (*it)->setParent( this ); } /*! @@ -495,9 +493,9 @@ SUIT_DataObjectKey* SUIT_DataObject::key() const void SUIT_DataObject::dump( const int indent ) const { QString strIndent = QString().fill( ' ', indent ); // indentation string - printf( "%s%s\n", strIndent.latin1(), name().latin1() ); - for ( DataObjectListIterator it( myChildren ); it.current(); ++it ) // iterate all children - it.current()->dump( indent + 2 ); // dump every child with indent + 2 spaces + printf( "%s%s\n", strIndent.toLatin1(), name().toLatin1() ); + for ( DataObjectList::const_iterator it = myChildren.begin(); it != myChildren.end(); ++it ) + (*it)->dump( indent + 2 ); } /*! diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 01f0ffa59..ad704e536 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -19,18 +19,18 @@ #ifndef SUIT_DATAOBJECT_H #define SUIT_DATAOBJECT_H -#include -#include -#include -#include +#include +#include +#include + +#include #include "SUIT.h" class SUIT_DataObject; class SUIT_DataObjectKey; -typedef QPtrList DataObjectList; -typedef QPtrListIterator DataObjectListIterator; +typedef QList DataObjectList; #ifdef WIN32 #pragma warning( disable:4251 ) @@ -112,6 +112,7 @@ private: bool myCheck; Signal* mySignal; SUIT_DataObject* myParent; + bool myAutoDel; DataObjectList myChildren; friend class SUIT_DataObject::Signal; diff --git a/src/SUIT/SUIT_DataObjectIterator.cxx b/src/SUIT/SUIT_DataObjectIterator.cxx index c5f66be5c..c1a16892d 100644 --- a/src/SUIT/SUIT_DataObjectIterator.cxx +++ b/src/SUIT/SUIT_DataObjectIterator.cxx @@ -74,11 +74,11 @@ void SUIT_DataObjectIterator::operator++() } else { - aParent->myChildren.find( myCurrent ); + int idx = aParent->myChildren.indexOf( myCurrent ); if ( myDetourType == DepthLeft ) - myCurrent = aParent->myChildren.next(); + myCurrent = idx < aParent->myChildren.count() - 1 ? aParent->myChildren[idx + 1] : 0; else - myCurrent = aParent->myChildren.prev(); + myCurrent = idx > 0 ? aParent->myChildren[idx - 1] : 0; if ( !myCurrent ) { myCurrent = aParent; @@ -146,9 +146,9 @@ SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, b if ( obj && ( par = parent( obj ) ) ) { - par->myChildren.find( obj ); - if ( par->myChildren.next() ) - return par->myChildren.current(); + int idx = par->myChildren.indexOf( obj ); + if ( idx < par->myChildren.count() - 1 ) + return par->myChildren[idx + 1]; else { for ( ; par; par = globalSibling( par, next ) ) @@ -170,9 +170,9 @@ SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, b SUIT_DataObject* SUIT_DataObjectIterator::extreme( DataObjectList& aList, bool FromLeft ) const { if ( FromLeft ) - return aList.getFirst(); + return aList.first(); else - return aList.getLast(); + return aList.last(); } /*! diff --git a/src/SUIT/SUIT_DataObjectKey.cxx b/src/SUIT/SUIT_DataObjectKey.cxx index 01a91404a..aeb7a3127 100755 --- a/src/SUIT/SUIT_DataObjectKey.cxx +++ b/src/SUIT/SUIT_DataObjectKey.cxx @@ -18,9 +18,9 @@ // #include "SUIT_DataObjectKey.h" -#include +#include -#ifndef WNT +#ifndef WIN32 #include #define _typeinfo std::type_info #else diff --git a/src/SUIT/SUIT_DataOwner.cxx b/src/SUIT/SUIT_DataOwner.cxx index 3090afa91..285388e45 100755 --- a/src/SUIT/SUIT_DataOwner.cxx +++ b/src/SUIT/SUIT_DataOwner.cxx @@ -18,7 +18,7 @@ // #include "SUIT_DataOwner.h" -#ifndef WNT +#ifndef WIN32 #include #define _typeinfo std::type_info #else @@ -77,8 +77,8 @@ bool operator<( const SUIT_DataOwnerPtr& p1, const SUIT_DataOwnerPtr& p2 ) Constructor (default) */ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList() - : QValueList(), - mySkipEqual( true ) +: QList(), +mySkipEqual( true ) { } @@ -86,8 +86,8 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList() Constructor (default) */ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual ) - : QValueList(), - mySkipEqual( skipAllEqual ) +: QList(), +mySkipEqual( skipAllEqual ) { } @@ -95,8 +95,8 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const bool skipAllEqual ) Constructor (copy) */ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l ) - : QValueList( l ), - mySkipEqual( true ) +: QList( l ), +mySkipEqual( true ) { } @@ -104,8 +104,8 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l ) Constructor (copy) */ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual ) - : QValueList(), - mySkipEqual( skipAllEqual ) +: QList(), +mySkipEqual( skipAllEqual ) { if ( skipAllEqual == l.mySkipEqual ) operator =( l ); @@ -113,51 +113,23 @@ SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, co { SUIT_DataOwnerPtrList::const_iterator beginIt = l.begin(); SUIT_DataOwnerPtrList::const_iterator endIt = l.end(); - for( ; beginIt != endIt; ++beginIt ) + for ( ; beginIt != endIt; ++beginIt ) append( *beginIt ); } } -#ifndef QT_NO_STL -/*! - Constructor (from stl) -*/ -SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list& l ) - : QValueList( l ), - mySkipEqual( true ) -{ -} -#endif - -#ifndef QT_NO_STL -/*! - Constructor (from stl) -*/ -SUIT_DataOwnerPtrList::SUIT_DataOwnerPtrList( const std::list& l, const bool skipAllEqual ) - : QValueList(), - mySkipEqual( skipAllEqual ) -{ - std::list::const_iterator beginIt = l.begin(); - std::list::const_iterator endIt = l.begin(); - for( ; beginIt != endIt; ++beginIt ) - append( *beginIt ); -} -#endif - /*! Appends an item to the list */ -SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x ) +void SUIT_DataOwnerPtrList::append( const SUIT_DataOwnerPtr& x ) { if ( mySkipEqual && myMap.contains( x ) ) //contains uses SUIT_DataOwnerPtr::operator== - return myMap[ x ]; + return; - iterator it = QValueList::append( x ); + QList::append( x ); - if ( mySkipEqual ) - myMap.insert( x, it ); - - return it; + if ( mySkipEqual ) + myMap.insert( x, 0 ); } /*! @@ -165,9 +137,10 @@ SUIT_DataOwnerPtrList::iterator SUIT_DataOwnerPtrList::append( const SUIT_DataOw */ void SUIT_DataOwnerPtrList::clear() { - if( mySkipEqual ) + if ( mySkipEqual ) myMap.clear(); - QValueList::clear(); + + QList::clear(); } /*! @@ -175,7 +148,8 @@ void SUIT_DataOwnerPtrList::clear() */ uint SUIT_DataOwnerPtrList::remove(const SUIT_DataOwnerPtr& x ) { - if( mySkipEqual && myMap.contains(x) ) - myMap.remove(x); - return QValueList::remove( x ); + if ( mySkipEqual && myMap.contains(x) ) + myMap.remove( x ); + + return QList::removeAll( x ); } diff --git a/src/SUIT/SUIT_DataOwner.h b/src/SUIT/SUIT_DataOwner.h index 2d364fd57..9f6dd9049 100755 --- a/src/SUIT/SUIT_DataOwner.h +++ b/src/SUIT/SUIT_DataOwner.h @@ -21,8 +21,8 @@ #include "SUIT_SmartPtr.h" -#include -#include +#include +#include #ifdef WIN32 #pragma warning( disable:4251 ) @@ -60,21 +60,17 @@ bool operator==( const SUIT_DataOwnerPtr&, const SUIT_DataOwnerPtr& ); /*! \class SUIT_DataOwnerPtrList * \brief Manage list of SUIT_DataOwnerPtr. */ -class SUIT_EXPORT SUIT_DataOwnerPtrList : public QValueList +class SUIT_EXPORT SUIT_DataOwnerPtrList : public QList { public: SUIT_DataOwnerPtrList(); //!< constructor SUIT_DataOwnerPtrList( const bool skipAllEqual );//!< constructor SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l ); //!< copy constructor SUIT_DataOwnerPtrList( const SUIT_DataOwnerPtrList& l, const bool skipAllEqual );//!< copy constructor -#ifndef QT_NO_STL - SUIT_DataOwnerPtrList( const std::list& l ); //!< copy constructor for STL list - SUIT_DataOwnerPtrList( const std::list& l, const bool skipAllEqual );//!< copy constructor for STL list -#endif - iterator append ( const SUIT_DataOwnerPtr& x );//!< append function + void append ( const SUIT_DataOwnerPtr& x );//!< append function void clear (); - uint remove (const SUIT_DataOwnerPtr& x ); + uint remove ( const SUIT_DataOwnerPtr& x ); private: // hide this methods: only append() should be used to add items to the list @@ -84,8 +80,8 @@ private: void push_back ( const SUIT_DataOwnerPtr& x );//!< hide method private: - bool mySkipEqual; - QMap myMap; + QMap myMap; + bool mySkipEqual; }; #ifdef WIN32 diff --git a/src/SUIT/SUIT_Desktop.cxx b/src/SUIT/SUIT_Desktop.cxx index 8d75c7174..192dc602b 100755 --- a/src/SUIT/SUIT_Desktop.cxx +++ b/src/SUIT/SUIT_Desktop.cxx @@ -21,10 +21,13 @@ #include "SUIT_Tools.h" #include "SUIT_ViewWindow.h" -#include +//#include #include #include +#include +#include + /*!\class SUIT_Desktop * Provide desktop management:\n * \li menu manager @@ -32,6 +35,17 @@ * \li windows */ +class SUIT_Desktop::ReparentEvent : public QEvent +{ +public: + ReparentEvent( Type t, QObject* obj ) : QEvent( t ), myObj( obj ) {}; + + QObject* object() const { return myObj; } + +private: + QObject* myObj; +}; + /*! Constructor. */ @@ -40,7 +54,7 @@ SUIT_Desktop::SUIT_Desktop() { myMenuMgr = new QtxActionMenuMgr( this ); myToolMgr = new QtxActionToolMgr( this ); - myLogoMgr = new QtxLogoMgr( menuBar() ); + myLogoMgr = 0;//new QtxLogoMgr( menuBar() ); } /*! @@ -85,18 +99,29 @@ void SUIT_Desktop::closeEvent( QCloseEvent* e ) */ void SUIT_Desktop::childEvent( QChildEvent* e ) { - if ( e->type() == QEvent::ChildInserted && parentArea() && - e->child()->isWidgetType() && e->child()->inherits( "SUIT_ViewWindow" ) ) - { - QWidget* wid = (QWidget*)e->child(); - bool vis = wid->isVisibleTo( wid->parentWidget() ); - wid->reparent( parentArea(), QPoint( 0, 0 ), vis ); - wid->setShown( vis ); - } + if ( e->type() == QEvent::ChildAdded && e->child()->isWidgetType() ) + QApplication::postEvent( this, new QChildEvent( QEvent::Type( Reparent ), e->child() ) ); else QtxMainWindow::childEvent( e ); } +void SUIT_Desktop::customEvent( QEvent* e ) +{ + if ( e->type() != Reparent ) + return; + + QChildEvent* re = (QChildEvent*)e; + if ( re->child()->inherits( "SUIT_ViewWindow" ) ) + { + QWidget* wid = (QWidget*)re->child(); + bool invis = wid->testAttribute( Qt::WA_WState_ExplicitShowHide ) && + wid->testAttribute( Qt::WA_WState_Hidden ); + + addWindow( wid ); + wid->setShown( !invis ); + } +} + /*! Gets menu manager. */ @@ -118,30 +143,13 @@ QtxActionToolMgr* SUIT_Desktop::toolMgr() const */ int SUIT_Desktop::logoCount() const { + return 0; +/* if ( !myLogoMgr ) return 0; else return myLogoMgr->count(); -} - -/*! - Adds new logo to the menu bar area. - Obsolete. Not should be used. - Use SUIT_Desktop::logoInsert(); */ -void SUIT_Desktop::addLogo( const QString& id, const QPixmap& pix ) -{ - logoInsert( id, pix ); -} - -/*! - Removes a logo. - Obsolete. Not should be used. - Use SUIT_Desktop::logoRemove(); -*/ -void SUIT_Desktop::removeLogo( const QString& id ) -{ - logoRemove( id ); } /*! @@ -149,8 +157,10 @@ void SUIT_Desktop::removeLogo( const QString& id ) */ void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx ) { +/* if ( myLogoMgr ) myLogoMgr->insert( logoID, logo, idx ); +*/ } /*! @@ -158,8 +168,10 @@ void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const */ void SUIT_Desktop::logoRemove( const QString& logoID ) { +/* if ( myLogoMgr ) myLogoMgr->remove( logoID ); +*/ } /*! @@ -167,8 +179,10 @@ void SUIT_Desktop::logoRemove( const QString& logoID ) */ void SUIT_Desktop::logoClear() { +/* if ( myLogoMgr ) myLogoMgr->clear(); +*/ } /*! diff --git a/src/SUIT/SUIT_Desktop.h b/src/SUIT/SUIT_Desktop.h index a346d0ca4..83ef0f2e7 100755 --- a/src/SUIT/SUIT_Desktop.h +++ b/src/SUIT/SUIT_Desktop.h @@ -21,8 +21,12 @@ #include "SUIT.h" -#include -#include +#include +#include + +#include +#include + #include class QPopupMenu; @@ -40,6 +44,10 @@ class SUIT_EXPORT SUIT_Desktop : public QtxMainWindow { Q_OBJECT + class ReparentEvent; + + enum { Reparent = QEvent::User }; + public: SUIT_Desktop(); virtual ~SUIT_Desktop(); @@ -48,10 +56,7 @@ public: QtxActionToolMgr* toolMgr() const; virtual SUIT_ViewWindow* activeWindow() const = 0; - virtual QPtrList windows() const = 0; - - void addLogo( const QString&, const QPixmap& ); // Not should be used. Will be removed. - void removeLogo( const QString& ); // Not should be used. Will be removed. + virtual QList windows() const = 0; int logoCount() const; @@ -61,7 +66,7 @@ public: void emitActivated(); -signals: +Q_SIGNALS: void activated(); void deactivated(); void windowActivated( SUIT_ViewWindow* ); @@ -69,10 +74,11 @@ signals: protected: virtual bool event( QEvent* ); + virtual void customEvent( QEvent* ); virtual void closeEvent( QCloseEvent* ); virtual void childEvent( QChildEvent* ); - virtual QWidget* parentArea() const = 0; + virtual void addWindow( QWidget* ) = 0; private: QtxActionMenuMgr* myMenuMgr; diff --git a/src/SUIT/SUIT_ExceptionHandler.cxx b/src/SUIT/SUIT_ExceptionHandler.cxx index 7a5083c91..f22b13cb8 100755 --- a/src/SUIT/SUIT_ExceptionHandler.cxx +++ b/src/SUIT/SUIT_ExceptionHandler.cxx @@ -20,7 +20,7 @@ #include "SUIT_MessageBox.h" -#include +#include /*!\class SUIT_ExceptionHandler * Show exception message on error handler. @@ -53,5 +53,5 @@ void SUIT_ExceptionHandler::showMessage( const QString& title, const QString& ms while ( QApplication::overrideCursor() ) QApplication::restoreOverrideCursor(); - SUIT_MessageBox::error1( qApp->mainWidget(), title, msg, "OK" ); + SUIT_MessageBox::error1( 0, title, msg, "OK" ); } diff --git a/src/SUIT/SUIT_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 7fb1ee7c6..40fb501e3 100755 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -71,14 +71,15 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_FileValidator.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include +#include +#include #define MIN_COMBO_SIZE 100 @@ -90,39 +91,50 @@ const bool IGNORE_NON_MATCHING_EXTENSION = true; QString SUIT_FileDlg::myLastVisitedPath; /*! Constructor */ -SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal ) : -QFileDialog( parent, 0, modal ), +SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal ) +: QFileDialog( parent ), myValidator( 0 ), -myQuickCombo( 0 ), myQuickButton( 0 ), myQuickLab( 0 ), +myQuickCombo( 0 ), +myQuickButton( 0 ), +myQuickLab( 0 ), myOpen( open )//, //myAccepted( false ) -{ - const QObjectList* child = children(); - QObjectList::const_iterator anIt = child->begin(), aLast = child->end(); - for( ; anIt!=aLast; anIt++ ) - if( (*anIt)->inherits( "QPushButton" ) ) +{ + setModal( modal ); + + const QObjectList& child = children(); + for ( QObjectList::const_iterator anIt = child.begin(); anIt != child.end(); ++anIt ) + { + QPushButton* pb = ::qobject_cast( *anIt ); + if ( pb ) { - QPushButton* bt = ( QPushButton* )( *anIt ); - bt->setDefault( false ); - bt->setAutoDefault( false ); + pb->setDefault( false ); + pb->setAutoDefault( false ); } + } - if ( parent->icon() ) - setIcon( *parent->icon() ); + if ( parent ) + setWindowIcon( parent->windowIcon() ); setSizeGripEnabled( true ); - if ( showQuickDir ) { + QGridLayout* grid = ::qobject_cast( layout() ); + if ( showQuickDir && grid ) + { // inserting quick dir combo box - myQuickLab = new QLabel(tr("LAB_QUICK_PATH"), this); - myQuickCombo = new QComboBox(false, this); - myQuickCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); - myQuickCombo->setMinimumSize(MIN_COMBO_SIZE, 0); + myQuickLab = new QLabel( tr( "LAB_QUICK_PATH" ), this ); + myQuickCombo = new QComboBox( this ); + myQuickCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myQuickCombo->setMinimumSize( MIN_COMBO_SIZE, 0 ); - myQuickButton = new QPushButton(tr("BUT_ADD_PATH"), this); + myQuickButton = new QPushButton( tr( "BUT_ADD_PATH" ), this ); - connect(myQuickCombo, SIGNAL(activated(const QString&)), this, SLOT(quickDir(const QString&))); - connect(myQuickButton, SIGNAL(clicked()), this, SLOT(addQuickDir())); - addWidgets(myQuickLab, myQuickCombo, myQuickButton); + connect( myQuickCombo, SIGNAL( activated( const QString& ) ), this, SLOT( quickDir( const QString& ) ) ); + connect( myQuickButton, SIGNAL( clicked() ), this, SLOT( addQuickDir() ) ); + + int row = grid->rowCount(); + grid->addWidget( myQuickLab, row, 0 ); + grid->addWidget( myQuickCombo, row, 1, 1, 3 ); + grid->addWidget( myQuickButton, row, 5 ); // getting dir list from settings QString dirs; @@ -130,27 +142,29 @@ myOpen( open )//, if ( resMgr ) dirs = resMgr->stringValue( "FileDlg", QString( "QuickDirList" ) ); - QStringList dirList = QStringList::split(';', dirs, false); - if (dirList.count() > 0) { - for (unsigned i = 0; i < dirList.count(); i++) - myQuickCombo->insertItem(dirList[i]); - } - else { - myQuickCombo->insertItem(QDir::homeDirPath()); + QStringList dirList = dirs.split( ';' ); + if ( dirList.count() > 0 ) + { + for ( unsigned i = 0; i < dirList.count(); i++ ) + myQuickCombo->addItem( dirList[i] ); } + else + myQuickCombo->addItem( QDir::homePath() ); } - setMode( myOpen ? ExistingFile : AnyFile ); - setCaption( myOpen ? tr( "INF_DESK_DOC_OPEN" ) : tr( "INF_DESK_DOC_SAVE" ) ); + setAcceptMode( myOpen ? AcceptOpen: AcceptSave ); + setWindowTitle( myOpen ? tr( "INF_DESK_DOC_OPEN" ) : tr( "INF_DESK_DOC_SAVE" ) ); // If last visited path doesn't exist -> switch to the first preferred path - if ( !myLastVisitedPath.isEmpty() ) { + if ( !myLastVisitedPath.isEmpty() ) + { if ( !processPath( myLastVisitedPath ) && showQuickDir ) - processPath( myQuickCombo->text( 0 ) ); + processPath( myQuickCombo->itemText( 0 ) ); } - else { + else + { if ( showQuickDir ) - processPath(myQuickCombo->text( 0 ) ); - } + processPath( myQuickCombo->itemText( 0 ) ); + } // set default file validator myValidator = new SUIT_FileValidator(this); @@ -162,11 +176,22 @@ SUIT_FileDlg::~SUIT_FileDlg() setValidator( 0 ); } +bool SUIT_FileDlg::event( QEvent* e ) +{ + bool res = QFileDialog::event( e ); + + if ( e->type() == QEvent::Polish ) + polish(); + + return res; +} + /*! Redefined from QFileDialog.*/ void SUIT_FileDlg::polish() { - QFileDialog::polish(); - if ( myQuickButton && myQuickLab ) { +/* + if ( myQuickButton && myQuickLab ) + { // the following is a workaround for proper layouting of custom widgets QValueList buttonList; QValueList labelList; @@ -198,6 +223,7 @@ void SUIT_FileDlg::polish() (*lListIt)->setFixedWidth( maxLabWidth ); } } +*/ } /*! Sets validator for file names to open/save @@ -236,13 +262,19 @@ void SUIT_FileDlg::accept() * (e.g. permission denied) */ // if ( !myAccepted ) { - if ( mode() != ExistingFiles ) { - mySelectedFile = QFileDialog::selectedFile(); + if ( acceptMode() != AcceptOpen ) + { + QString fn; + QStringList lst = QFileDialog::selectedFiles(); + if ( !lst.isEmpty() ) + fn = lst.first(); + mySelectedFile = fn; addExtension(); } - if ( acceptData() ) { - myLastVisitedPath = dirPath(); + if ( acceptData() ) + { + myLastVisitedPath = directory().path(); QFileDialog::accept(); // myAccepted = true; } @@ -268,7 +300,7 @@ bool SUIT_FileDlg::acceptData() { if ( isOpenDlg() ) { - if ( mode() == ExistingFiles ) + if ( acceptMode() == AcceptOpen ) { QStringList fileNames = selectedFiles(); for ( int i = 0; i < (int)fileNames.count(); i++ ) @@ -296,11 +328,11 @@ bool SUIT_FileDlg::acceptData() void SUIT_FileDlg::addExtension() { // check if file name entered is empty - if ( mySelectedFile.stripWhiteSpace().isEmpty() ) + if ( mySelectedFile.trimmed().isEmpty() ) return; // current file extension - QString anExt = "." + SUIT_Tools::extension( mySelectedFile.stripWhiteSpace() ).stripWhiteSpace(); + QString anExt = "." + SUIT_Tools::extension( mySelectedFile.trimmed() ).trimmed(); // If the file already has extension and it does not match the filter there are two choices: // - to leave it 'as is' @@ -315,7 +347,7 @@ void SUIT_FileDlg::addExtension() int len, index = r.match( selectedFilter().stripWhiteSpace(), 0, &len ); #else QRegExp r( QString::fromLatin1("\\(?[a-zA-Z0-9.*? +;#|]*\\)?$") ); - int index = r.search( selectedFilter().stripWhiteSpace() ); + int index = r.indexIn( selectedFilter().trimmed() ); #endif if ( index >= 0 ) { @@ -325,22 +357,23 @@ void SUIT_FileDlg::addExtension() // will have the pattern (\.txt|\..*xx|\.c\+\+|\..*) (as we validate extension only, // we remove everything except extension mask from the pattern #if QT_VERSION < 0x030000 - QString wildcard = selectedFilter().mid( index, len ).stripWhiteSpace(); + QString wildcard = selectedFilter().mid( index, len ).trimmed(); #else - QString wildcard = selectedFilter().mid( index, r.matchedLength() ).stripWhiteSpace(); + QString wildcard = selectedFilter().mid( index, r.matchedLength() ).trimmed(); #endif // replace '|' and ';' separators by space symbol and also brackets if there are some wildcard.replace( QRegExp( "[\\|;|(|)]" )," " ); - QString aPattern = wildcard.replace( QRegExp( "(^| )(\\s*)[0-9a-zA-Z*_?]*\\."), " \\." ).stripWhiteSpace(). + QString aPattern = wildcard.replace( QRegExp( "(^| )(\\s*)[0-9a-zA-Z*_?]*\\."), " \\." ).trimmed(). replace( QRegExp( "\\s+" ), "|" ).replace( QRegExp( "[?]" ),".?" ). replace( QRegExp( "[*]" ),".*" ).replace( QRegExp( "[+]" ),"\\+" ); // now we get the list of all extension masks and remove all which does not contain wildcard symbols - QStringList extList = QStringList::split( "|",aPattern ); - for( int i = extList.count() - 1; i >= 0; i-- ) { + QStringList extList = aPattern.split( "|", QString::SkipEmptyParts ); + for ( int i = extList.count() - 1; i >= 0; i-- ) + { if ( !extList[i].contains( "." ) ) - extList.remove( extList.at( i ) ); + extList.removeAt( i ); } aPattern = extList.join( "|" ); @@ -348,19 +381,19 @@ void SUIT_FileDlg::addExtension() QRegExp anExtRExp( "^("+ aPattern + ")$" ); // Check if the current file extension matches the pattern - if ( anExtRExp.match( anExt ) < 0 ) + if ( !anExtRExp.exactMatch( anExt ) ) { // find first appropriate extension in the selected filter // (it should be without wildcard symbols) for ( int i = 0; i < (int)extList.count(); i++ ) { QString newExt = extList[i].replace( QRegExp( "[\\\\][+]" ),"+" ); - int res = newExt.findRev( '.' ); + int res = newExt.lastIndexOf( '.' ); if ( res >= 0 ) newExt = newExt.mid( res + 1 ); - if ( newExt.find( QRegExp("[*|?]" ) ) < 0 ) + if ( newExt.indexOf( QRegExp("[*|?]" ) ) < 0 ) { - mySelectedFile.stripWhiteSpace(); + mySelectedFile.trimmed(); mySelectedFile += mySelectedFile.endsWith(".") ? newExt : QString(".") + newExt; break; } @@ -372,20 +405,24 @@ void SUIT_FileDlg::addExtension() /*! Processes selection : tries to set given path or filename as selection */ bool SUIT_FileDlg::processPath( const QString& path ) { - if ( !path.isNull() ) { + if ( !path.isNull() ) + { QFileInfo fi( path ); - if ( fi.exists() ) { + if ( fi.exists() ) + { if ( fi.isFile() ) - setSelection( path ); + selectFile( path ); else if ( fi.isDir() ) - setDir( path ); + setDirectory( path ); return true; } - else { - if ( QFileInfo( fi.dirPath() ).exists() ) { - setDir( fi.dirPath() ); - setSelection( path ); - return true; + else + { + if ( QFileInfo( SUIT_Tools::dir( path ) ).exists() ) + { + setDirectory( SUIT_Tools::dir( path ) ); + selectFile( path ); + return true; } } } @@ -395,8 +432,9 @@ bool SUIT_FileDlg::processPath( const QString& path ) void SUIT_FileDlg::quickDir(const QString& dirPath) { QString aPath = dirPath; - if ( !QDir(aPath).exists() ) { - aPath = QDir::homeDirPath(); + if ( !QDir(aPath).exists() ) + { + aPath = QDir::homePath(); SUIT_MessageBox::error1(this, tr("ERR_ERROR"), tr("ERR_DIR_NOT_EXIST").arg(dirPath), @@ -411,89 +449,91 @@ void SUIT_FileDlg::quickDir(const QString& dirPath) */ void SUIT_FileDlg::addQuickDir() { - QString dp = dirPath(); - if ( !dp.isEmpty() ) { + QString dp = directory().path(); + if ( !dp.isEmpty() ) + { QDir dir( dp ); // getting dir list from settings QString dirs; SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if ( resMgr ) dirs = resMgr->stringValue( "FileDlg", QString( "QuickDirList" ) ); - QStringList dirList = QStringList::split(';', dirs, false); + QStringList dirList = dirs.split( ';', QString::SkipEmptyParts ); bool found = false; bool emptyAndHome = false; - if ( dirList.count() > 0 ) { - for ( unsigned i = 0; i < dirList.count(); i++ ) { - QDir aDir( dirList[i] ); - if ( aDir.canonicalPath().isNull() && dirList[i] == dir.absPath() || - !aDir.canonicalPath().isNull() && aDir.exists() && aDir.canonicalPath() == dir.canonicalPath() ) { - found = true; - break; - } + if ( dirList.count() > 0 ) + { + for ( unsigned i = 0; i < dirList.count(); i++ ) + { + QDir aDir( dirList[i] ); + if ( aDir.canonicalPath().isNull() && dirList[i] == dir.absolutePath() || + !aDir.canonicalPath().isNull() && aDir.exists() && aDir.canonicalPath() == dir.canonicalPath() ) + { + found = true; + break; + } } } - else { - emptyAndHome = dir.canonicalPath() == QDir(QDir::homeDirPath()).canonicalPath(); - } - if ( !found ) { + else + emptyAndHome = dir.canonicalPath() == QDir( QDir::homePath() ).canonicalPath(); + + if ( !found ) + { dirList.append( dp ); - resMgr->setValue( "FileDlg", QString( "QuickDirList" ), dirList.join(";") ); + resMgr->setValue( "FileDlg", QString( "QuickDirList" ), dirList.join( ";" ) ); if ( !emptyAndHome ) - myQuickCombo->insertItem( dp ); + myQuickCombo->addItem( dp ); } } } /*! Returns the file name for Open/Save [ static ] */ -QString SUIT_FileDlg::getFileName( QWidget* parent, - const QString& initial, - const QStringList& filters, - const QString& caption, - bool open, - bool showQuickDir, - SUIT_FileValidator* validator ) +QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial, const QStringList& filters, + const QString& caption, bool open, bool showQuickDir, + SUIT_FileValidator* validator ) { SUIT_FileDlg* fd = new SUIT_FileDlg( parent, open, showQuickDir, true ); if ( !caption.isEmpty() ) - fd->setCaption( caption ); - if ( !initial.isEmpty() ) { + fd->setWindowTitle( caption ); + if ( !initial.isEmpty() ) fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug - } - fd->setFilters( filters ); + + fd->setFilters( filters ); if ( validator ) fd->setValidator( validator ); + fd->exec(); + QString filename = fd->selectedFile(); delete fd; + qApp->processEvents(); + return filename; } - /*! Returns the list of files to be opened [ static ] */ -QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, - const QString& initial, - const QStringList& filters, - const QString& caption, - bool showQuickDir, - SUIT_FileValidator* validator ) +QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, const QString& initial, const QStringList& filters, + const QString& caption, bool showQuickDir, SUIT_FileValidator* validator ) { SUIT_FileDlg* fd = new SUIT_FileDlg( parent, true, showQuickDir, true ); - fd->setMode( ExistingFiles ); + fd->setFileMode( ExistingFiles ); if ( !caption.isEmpty() ) - fd->setCaption( caption ); - if ( !initial.isEmpty() ) { + fd->setWindowTitle( caption ); + if ( !initial.isEmpty() ) fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug - } + fd->setFilters( filters ); if ( validator ) fd->setValidator( validator ); + fd->exec(); QStringList filenames = fd->selectedFiles(); delete fd; + qApp->processEvents(); return filenames; } @@ -501,39 +541,23 @@ QStringList SUIT_FileDlg::getOpenFileNames( QWidget* parent, /*! Existing directory selection dialog [ static ] */ -QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, - const QString& initial, - const QString& caption, - bool showQuickDir ) +QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, const QString& initial, + const QString& caption, bool showQuickDir ) { - SUIT_FileDlg* fd = new SUIT_FileDlg( parent, true, showQuickDir, true); + SUIT_FileDlg* fd = new SUIT_FileDlg( parent, true, showQuickDir, true ); if ( !caption.isEmpty() ) - fd->setCaption( caption ); - if ( !initial.isEmpty() ) { + fd->setWindowTitle( caption ); + if ( !initial.isEmpty() ) fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug - } - fd->setMode( DirectoryOnly ); - fd->setFilters(tr("INF_DIRECTORIES_FILTER")); + + fd->setFileMode( DirectoryOnly ); + fd->setFilters( QStringList( tr( "INF_DIRECTORIES_FILTER" ) ) ); + fd->exec(); + QString dirname = fd->selectedFile(); delete fd; + qApp->processEvents(); return dirname; - -} - -/*! - QFileDialog::dirPath() has a bug on Linux Debian (1 level up from correct - directory is returned). This function fixes the bug. -*/ -QString SUIT_FileDlg::dirPath() const -{ - if ( !mySelectedFile.isNull() ) - return QFileInfo( mySelectedFile ).dirPath(); - - const QDir* aDir = dir(); - if ( aDir->exists() ) - return aDir->absPath(); - - return QFileDialog::dirPath(); } diff --git a/src/SUIT/SUIT_FileDlg.h b/src/SUIT/SUIT_FileDlg.h index 044188003..33404d346 100755 --- a/src/SUIT/SUIT_FileDlg.h +++ b/src/SUIT/SUIT_FileDlg.h @@ -21,7 +21,7 @@ #include "SUIT.h" -#include +#include class QLabel; class QComboBox; @@ -45,9 +45,6 @@ public: void setValidator( SUIT_FileValidator* ); - QString dirPath() const; // QFileDialog::dirPath() has a bug on Linux Debian (1 level up from correct - // directory is returned). This redefinition fixes the bug. - static QString getFileName( QWidget* parent, const QString& initial, const QStringList& filters, const QString& caption, const bool open, const bool showQuickDir = true, SUIT_FileValidator* validator = 0 ); @@ -57,10 +54,8 @@ public: static QString getExistingDirectory( QWidget* parent, const QString& initial, const QString& caption, const bool showQuickDir = true ); -public slots: - void polish(); - private: + void polish(); bool acceptData(); void addExtension(); bool processPath( const QString& path ); @@ -71,6 +66,9 @@ protected slots: void quickDir( const QString& ); void addQuickDir(); +protected: + virtual bool event( QEvent* ); + protected: bool myOpen; //!< open/save selector QString mySelectedFile; //!< selected filename diff --git a/src/SUIT/SUIT_FileValidator.cxx b/src/SUIT/SUIT_FileValidator.cxx index ab09fc665..604840ea4 100755 --- a/src/SUIT/SUIT_FileValidator.cxx +++ b/src/SUIT/SUIT_FileValidator.cxx @@ -16,18 +16,12 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// File : SUIT_FileValidator.cxx -// Module : SALOME -// $Header$ - #include "SUIT_FileValidator.h" #include "SUIT_MessageBox.h" #include "SUIT_Session.h" -#include -#include +#include +#include /*! constructor */ SUIT_FileValidator::SUIT_FileValidator(QWidget* parent) : @@ -79,17 +73,19 @@ bool SUIT_FileValidator::canSave( const QString& file ) return false; } } - else { + else + { // if file doesn't exist - try to create it QFile qf( file ); - if ( !qf.open( IO_WriteOnly ) ) { - SUIT_MessageBox::error1( myParent, - QObject::tr( "ERR_ERROR" ), - QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ), - QObject::tr( "BUT_OK" ) ); + if ( !qf.open( QFile::WriteOnly ) ) + { + SUIT_MessageBox::error1( myParent, QObject::tr( "ERR_ERROR" ), + QObject::tr( "ERR_PERMISSION_DENIED" ).arg( file ), + QObject::tr( "BUT_OK" ) ); return false; } - else { + else + { // remove just created file qf.close(); qf.remove(); @@ -97,4 +93,3 @@ bool SUIT_FileValidator::canSave( const QString& file ) } return true; } - diff --git a/src/SUIT/SUIT_FileValidator.h b/src/SUIT/SUIT_FileValidator.h index 197f6a2ab..56849cc38 100755 --- a/src/SUIT/SUIT_FileValidator.h +++ b/src/SUIT/SUIT_FileValidator.h @@ -18,15 +18,13 @@ // // SALOME SALOMEGUI : implementation of desktop and GUI kernel // -// File : SUIT_FileValidator.h -// Module : SALOME - #ifndef SUIT_FILEVALIDATOR_H #define SUIT_FILEVALIDATOR_H -#include #include "SUIT.h" +#include + /*! \class SUIT_FileValidator Provides functionality to check file diff --git a/src/SUIT/SUIT_MessageBox.cxx b/src/SUIT/SUIT_MessageBox.cxx index e80ff74f0..f64274fa0 100755 --- a/src/SUIT/SUIT_MessageBox.cxx +++ b/src/SUIT/SUIT_MessageBox.cxx @@ -27,18 +27,16 @@ #include "SUIT_MessageBox.h" #include "SUIT_OverrideCursor.h" -#include -#include +#include +#include /*! Shows info message box with one button [ static ] */ -int SUIT_MessageBox::info1( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0 ) +int SUIT_MessageBox::info1( QWidget* parent, const QString& caption, + const QString& text, const QString& textButton0 ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); int ret = QMessageBox::information( parent, caption, text, textButton0, QString::null, QString::null, 0, 0 ); qApp->processEvents(); @@ -53,7 +51,7 @@ int SUIT_MessageBox::warn1( QWidget* parent, const QString& text, const QString& textButton0 ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); int ret = QMessageBox::warning( parent, caption, text, textButton0, QString::null, QString::null, 0, 0 ); qApp->processEvents(); @@ -68,7 +66,7 @@ int SUIT_MessageBox::error1( QWidget* parent, const QString& text, const QString& textButton0 ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); int ret = QMessageBox::critical( parent, caption, text, textButton0, QString::null, QString::null, 0, 0 ); qApp->processEvents(); @@ -83,7 +81,7 @@ int SUIT_MessageBox::question1( QWidget* parent, const QString& text, const QString& textButton0 ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); int ret = QMessageBox::question( parent, caption, text, textButton0, QString::null, QString::null, 0, 0 ); qApp->processEvents(); @@ -101,7 +99,7 @@ int SUIT_MessageBox::info2( QWidget* parent, const QString& textButton1, int idButton0, int idButton1, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; else if ( idDefault == idButton1 ) @@ -126,7 +124,7 @@ int SUIT_MessageBox::warn2( QWidget* parent, const QString& textButton1, int idButton0, int idButton1, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; @@ -152,7 +150,7 @@ int SUIT_MessageBox::error2( QWidget* parent, const QString& textButton1, int idButton0, int idButton1, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; @@ -178,7 +176,7 @@ int SUIT_MessageBox::question2( QWidget* parent, const QString& textButton1, int idButton0, int idButton1, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; @@ -206,7 +204,7 @@ int SUIT_MessageBox::info3( QWidget* parent, int idButton0, int idButton1, int idButton2, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; @@ -245,7 +243,7 @@ int SUIT_MessageBox::warn3( QWidget* parent, int idButton0, int idButton1, int idButton2, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; @@ -284,7 +282,7 @@ int SUIT_MessageBox::error3( QWidget* parent, int idButton0, int idButton1, int idButton2, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; @@ -323,7 +321,7 @@ int SUIT_MessageBox::question3( QWidget* parent, int idButton0, int idButton1, int idButton2, int idDefault ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); if ( idDefault == idButton0 ) idDefault = 0; diff --git a/src/SUIT/SUIT_MessageBox.h b/src/SUIT/SUIT_MessageBox.h index 24b350605..69b07aa39 100755 --- a/src/SUIT/SUIT_MessageBox.h +++ b/src/SUIT/SUIT_MessageBox.h @@ -22,8 +22,8 @@ #include "SUIT.h" -#include -#include +#include +#include #define SUIT_OK 1 #define SUIT_CANCEL 2 diff --git a/src/SUIT/SUIT_Operation.h b/src/SUIT/SUIT_Operation.h index 3d15f058c..810c0a920 100755 --- a/src/SUIT/SUIT_Operation.h +++ b/src/SUIT/SUIT_Operation.h @@ -22,8 +22,8 @@ #include "SUIT.h" -#include -#include +#include +#include class SUIT_Study; class SUIT_Application; @@ -107,6 +107,8 @@ public: virtual QString operationName() const; + int execStatus() const; + signals: void started( SUIT_Operation* ); void aborted( SUIT_Operation* ); @@ -140,7 +142,6 @@ protected: virtual bool hasTransaction() const; virtual bool commitTransaction( const QString& = QString::null ); - int execStatus() const; void setExecStatus( const int ); void setState( const OperationState ); @@ -148,7 +149,7 @@ protected: void start( SUIT_Operation*, const bool = false ); private: - typedef QGuardedPtr StudyPtr; + typedef QPointer StudyPtr; private: SUIT_Application* myApp; //!< application for this operation diff --git a/src/SUIT/SUIT_OverrideCursor.cxx b/src/SUIT/SUIT_OverrideCursor.cxx index 0dab97a58..1b609e439 100755 --- a/src/SUIT/SUIT_OverrideCursor.cxx +++ b/src/SUIT/SUIT_OverrideCursor.cxx @@ -61,7 +61,7 @@ void SUIT_OverrideCursor::resume() if ( isActive() ) return; - for ( QValueList::const_iterator it = myCursors.begin(); it != myCursors.end(); ++it ) + for ( QList::const_iterator it = myCursors.begin(); it != myCursors.end(); ++it ) QApplication::setOverrideCursor( *it ); myCursors.clear(); diff --git a/src/SUIT/SUIT_OverrideCursor.h b/src/SUIT/SUIT_OverrideCursor.h index ee89235d6..f353e526c 100755 --- a/src/SUIT/SUIT_OverrideCursor.h +++ b/src/SUIT/SUIT_OverrideCursor.h @@ -19,11 +19,12 @@ #ifndef SUIT_OVERRIDECURSOR_H #define SUIT_OVERRIDECURSOR_H -#include -#include - #include "SUIT.h" +#include +#include +#include + /*! \brief Class used for management cursors.*/ class SUIT_EXPORT SUIT_OverrideCursor { @@ -37,7 +38,7 @@ public: void resume(); private: - QValueList myCursors; + QList myCursors; }; #endif diff --git a/src/SUIT/SUIT_ParserSettings.cxx b/src/SUIT/SUIT_ParserSettings.cxx deleted file mode 100755 index fa3768ff1..000000000 --- a/src/SUIT/SUIT_ParserSettings.cxx +++ /dev/null @@ -1,341 +0,0 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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_ParserSettings.cxx -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#include "SUIT_ParserSettings.h" - -#include - -// QT Includes -#include -#include -#include - - -/*! Constructor. Do nothing.*/ -SUIT_ParserSettings::SUIT_ParserSettings() -{ -} - - -/*! - Destructor. Do nothing. -*/ -SUIT_ParserSettings::~SUIT_ParserSettings() -{ -} - - -/*! - Gets the contents of a file. -*/ -QString SUIT_ParserSettings::getContents(QString fileName, bool comments, - bool sections, bool whiteSpace, - bool htmlComments) -{ - QFileInfo fi(fileName); - QFile f(fi.absFilePath()); - QString s=""; // Buffer for the whole file - - if(f.open(IO_ReadOnly)) { // file opened successfully - QTextStream t(&f); // use a text stream - - s = t.read(); // The whole file in a string - f.close(); - - if(!comments) s = SUIT_ParserSettings::removeComments(s); - if(!sections) s = SUIT_ParserSettings::removeSections(s); - if(!whiteSpace) s = s.simplifyWhiteSpace(); - if(!htmlComments) s = SUIT_ParserSettings::removeHtmlComments(s); - } - else { - // Can't open file - } - - return s; -} - - -/*! - Gets the body of a section from a string. -*/ -QString SUIT_ParserSettings::getSection(QString s, QString sectionName) -{ - QString result=""; - - QChar ch; // A single byte of the file - int bracketCounter=1; // Bracket counter (increase on '{' and decrese on '}'. - int i; // Current index - int l=0; // Length of current part we must have - - if((i=s.find(sectionName, 0, false)) >= 0 && // Jump to section [styles] - (i=s.find('{', i)) >= 0 ) { - - ++i; - - while(i+l<(int)s.length()) { - ch = s.at(i+l); // Single byte - - ++l; - - if(ch=='{') ++bracketCounter; - if(ch=='}') --bracketCounter; - - if(bracketCounter==0) break; - } - - result = s.mid(i, l-1); - } - - return result; -} - - - -/*! - Gets the HTML comments out of a file. -*/ -QString SUIT_ParserSettings::getHtmlComment(QString s) -{ - QString result=""; - int length; // length of the sub string - int ind=0; - - if((ind =s.find("", ind)-ind)!=0) { - - result=s.mid(ind, length-3); - } - - return result; -} - - - -/*! - Gets the next String between two given characters. The index-parameter gets moved to the character after - the stopper or to -1 if the starter / stopper were not found. -*/ -QString SUIT_ParserSettings::getNextStringBetween(QString s, int& startIndex, - QChar starter, QChar stopper) -{ - QString result=""; - int length=0; // length of the sub string - - if((startIndex =s.find(starter, startIndex))>=0 && - (length=s.find(stopper, startIndex+1)-startIndex)!=0) { - - result=s.mid(startIndex+1, length-1); - startIndex+=2; - } - - return result; -} - - -/*! - Gets the next String between the given index and a given stopper character. The index-parameter gets moved to - the character after the stopper or to -1 if the stopper was not found. -*/ -QString SUIT_ParserSettings::getNextStringUntil(QString s, int& startIndex, QChar stopper) -{ - QString result=""; - int length; // length of the sub string - - if((length=s.find(stopper, startIndex)-startIndex)!=0) { - result=s.mid(startIndex, length); - startIndex++; - } - - return result; -} - - -/*! - Removes all comments (between '/ *' and '* /'). -*/ -QString SUIT_ParserSettings::removeComments(QString s) -{ - QString result=""; - int i1=0, i2; - - while((i2=s.find("/*", i1))>=0) { - result += s.mid(i1, i2-i1); - - i1+=2; - i1=s.find("*/", i1); - i1+=2; - } - - result += s.mid(i1, s.length()-i1); - - return result; -} - - - -/*! - Removes all HTML comments (between '') \image html html_comments.gif -*/ -QString SUIT_ParserSettings::removeHtmlComments(QString s) -{ - QString result=""; - int i1=0, i2; - - while((i2=s.find("", i1); - i1+=3; - } - - result += s.mid(i1, s.length()-i1); - - return result; -} - - - -/*! - Removes all sections ('[section] { }'). -*/ -QString SUIT_ParserSettings::removeSections(QString s) -{ - QString result=""; - - QChar ch; // A single byte of the file - int bracketCounter; // Bracket counter (increase on '{' and decrese on '}'. - int i=0; // Current index - - while(i<(int)s.length()) { - ch = s.at(i); // Single byte - - if(ch=='[') { - bracketCounter=1; - while(i<(int)s.length() && ch!=']') { ch = s.at(i); ++i; } - ++i; - while(i<(int)s.length() && ch!='{') { ch = s.at(i); ++i; } - ++i; - - while(i<(int)s.length() && bracketCounter!=0) { - ch = s.at(i); - if(ch=='{') ++bracketCounter; - if(ch=='}') --bracketCounter; - ++i; - } - ++i; - } - else { - result+=ch; - } - - ++i; - } - - return result; -} - - -/*! - Format plain text into HTML-code with a given maximal width. - Spaces get replaced with non breaking spaces. Tabulators get filled up - with non breaking spaces. -*/ -QString SUIT_ParserSettings::plainTextToHtml(QString s, int autoBreak) -{ - QString result="\n"; - - if(!s.isEmpty()) { - int col=1, i; - - for(i=0; i<(int)s.length(); ++i) { - // Line feed: - // - if(s[i]=='\n') { - result+="
\n"; - col=1; - } - - // Auto break: - // - else if(col==autoBreak && autoBreak!=0) { - result+="
\n"; - result+=s[i]; - col=1; - } - - // Tab: - // - else if(s[i]=='\t') { - while(col%8!=0) { result+=" "; ++col; } - result+=" "; - ++col; - } - - // Space: - // - else if(s[i]==' ') { - result+=" "; - ++col; - } - - // Normal char / special code: - // - else { - if(s[i].isLetter() || s[i].isNumber()) { - result+=s[i]; - } - else { - result+=charToHtml(s[i]); - } - ++col; - } - } - - result+="\n"; - } - - return result; -} - - -/*! - Converts a special character to html code (e.g.: 'ยป' to "»") -*/ -QString SUIT_ParserSettings::charToHtml(QChar c) -{ - QString s; - QString uc; - uc.setNum(c.unicode()); - s = "&#" + uc + ";"; - return s; -} - - -// EOF diff --git a/src/SUIT/SUIT_ParserSettings.h b/src/SUIT/SUIT_ParserSettings.h deleted file mode 100755 index 16d74a2fb..000000000 --- a/src/SUIT/SUIT_ParserSettings.h +++ /dev/null @@ -1,56 +0,0 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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_ParserSettings.h -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#ifndef SUIT_PARSERSETTINGS_H -#define SUIT_PARSERSETTINGS_H - -#include -#include "SUIT.h" -/*! \brief Text Parser.*/ -class SUIT_EXPORT SUIT_ParserSettings -{ -public: - SUIT_ParserSettings(); - ~SUIT_ParserSettings(); - - static QString getContents(QString fileName, bool comments=true, - bool sections=true, bool whitespace=true, - bool htmlComments=true); - static QString getSection(QString s, QString sectionName); - static QString getHtmlComment(QString s); - static QString getNextStringBetween(QString s, int& startIndex, QChar starter, QChar stopper); - static QString getNextStringUntil(QString s, int& startIndex, QChar stopper); - static QString removeComments(QString s); - static QString removeHtmlComments(QString s); - static QString removeSections(QString s); - static QString plainTextToHtml(QString s, int autoBreak); - static QString charToHtml(QChar c); - -}; - -#endif diff --git a/src/SUIT/SUIT_PopupClient.cxx b/src/SUIT/SUIT_PopupClient.cxx index fd2c40d9f..492b31d79 100644 --- a/src/SUIT/SUIT_PopupClient.cxx +++ b/src/SUIT/SUIT_PopupClient.cxx @@ -18,7 +18,7 @@ // #include "SUIT_PopupClient.h" -#include +#include /*! constructor. initialize mySignal.*/ SUIT_PopupClient::SUIT_PopupClient() diff --git a/src/SUIT/SUIT_PopupClient.h b/src/SUIT/SUIT_PopupClient.h index f65bc9f12..532bbc7ac 100644 --- a/src/SUIT/SUIT_PopupClient.h +++ b/src/SUIT/SUIT_PopupClient.h @@ -21,9 +21,9 @@ #include "SUIT.h" -#include +#include -class QPopupMenu; +class QMenu; class QContextMenuEvent; /*!\class SUIT_PopupClient @@ -42,7 +42,7 @@ public: bool disconnectPopupRequest( QObject* reciever, const char* slot ); virtual QString popupClientType() const = 0; - virtual void contextMenuPopup( QPopupMenu* ) {} + virtual void contextMenuPopup( QMenu* ) {} protected: void contextMenuRequest( QContextMenuEvent* e ); diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index 8a81306bb..cdd4a9cc5 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -18,8 +18,9 @@ // #include "SUIT_ResourceMgr.h" -#include -#include +#include +#include + #include /*! @@ -65,9 +66,6 @@ QString SUIT_ResourceMgr::loadDoc( const QString& prefix, const QString& id ) co return path( docSection, prefix, id ); } -#ifndef WIN32 -#include -#endif /*! Returns the user file name for specified application */ @@ -93,7 +91,7 @@ QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_l */ QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const { - QDir d( QFileInfo( fname ).dir( true ) ); + QDir d( QFileInfo( fname ).dir() ); d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); QStringList l = d.entryList(); QString appr_file; @@ -110,7 +108,7 @@ QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const if( appr < 0 || abs( id-id0 ) < abs( appr-id0 ) ) { appr = id; - appr_file = d.absFilePath( *anIt ); + appr_file = d.absoluteFilePath( *anIt ); } } return appr_file; diff --git a/src/SUIT/SUIT_SelectionMgr.cxx b/src/SUIT/SUIT_SelectionMgr.cxx index 895486f21..19a1ff200 100755 --- a/src/SUIT/SUIT_SelectionMgr.cxx +++ b/src/SUIT/SUIT_SelectionMgr.cxx @@ -25,6 +25,7 @@ /*!constructor. initialize myIterations and myIsSelChangeEnabled.*/ SUIT_SelectionMgr::SUIT_SelectionMgr( const bool Feedback, QObject* p ) : QObject( p ), +myAutoDelFilter( false ), myIterations( Feedback ? 1 : 0 ), myIsSelChangeEnabled( true ) { @@ -33,7 +34,8 @@ myIsSelChangeEnabled( true ) /*!destructor. mySelectors auto delete.*/ SUIT_SelectionMgr::~SUIT_SelectionMgr() { - mySelectors.setAutoDelete( true ); + for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) + delete *it; } /*!Add selector \a sel to selectors list,if it's not exists in list.*/ @@ -46,25 +48,25 @@ void SUIT_SelectionMgr::installSelector( SUIT_Selector* sel ) /*!Remove selector \a sel from list.*/ void SUIT_SelectionMgr::removeSelector( SUIT_Selector* sel ) { - mySelectors.remove( sel ); + mySelectors.removeAll( sel ); } /*!Gets selectors list to \a lst.*/ -void SUIT_SelectionMgr::selectors( QPtrList& lst ) const +void SUIT_SelectionMgr::selectors( QList& lst ) const { lst.clear(); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) - lst.append( it.current() ); + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) + lst.append( *it ); } /*!Gets selectors list to \a lst with type \a typ.*/ -void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList& lst ) const +void SUIT_SelectionMgr::selectors( const QString& typ, QList& lst ) const { lst.clear(); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( it.current()->type() == typ ) - lst.append( it.current() ); + if ( (*it)->type() == typ ) + lst.append( *it ); } } @@ -72,10 +74,10 @@ void SUIT_SelectionMgr::selectors( const QString& typ, QPtrList& */ void SUIT_SelectionMgr::setEnabled( const bool on, const QString& typ ) { - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( typ.isEmpty() || it.current()->type() == typ ) - it.current()->setEnabled( on ); + if ( typ.isEmpty() || (*it)->type() == typ ) + (*it)->setEnabled( on ); } } @@ -85,12 +87,13 @@ void SUIT_SelectionMgr::selected( SUIT_DataOwnerPtrList& lst, const QString& typ { lst.clear(); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( !type.isEmpty() && it.current()->type() != type ) + if ( !type.isEmpty() && (*it)->type() != type ) continue; + SUIT_DataOwnerPtrList curList; - it.current()->selected( curList ); + (*it)->selected( curList ); for ( SUIT_DataOwnerPtrList::const_iterator itr = curList.begin(); itr != curList.end(); ++itr ) lst.append( *itr ); } @@ -103,16 +106,16 @@ void SUIT_SelectionMgr::setSelected( const SUIT_DataOwnerPtrList& lst, const boo SUIT_DataOwnerPtrList owners; filterOwners( lst, owners ); - for ( SelectorListIterator it( mySelectors ); it.current(); ++it ) + for ( SelectorList::const_iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { if ( append ) { SUIT_DataOwnerPtrList current; - it.current()->selected( current ); + (*it)->selected( current ); for ( SUIT_DataOwnerPtrList::const_iterator it = current.begin(); it != current.end(); ++it ) owners.append( *it ); } - it.current()->setSelected( owners ); + (*it)->setSelected( owners ); } } @@ -140,11 +143,11 @@ void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel ) for ( int i = 0; i < myIterations; i++ ) { - for ( SUIT_Selector* aSel = mySelectors.first(); aSel; aSel = mySelectors.next() ) + for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - // Temporary action(to avoid selection of the objects which don't pass the filters): - //if ( aSel != sel ) - aSel->setSelected( newOwners ); + SUIT_Selector* aSel = *it; + if ( *it != sel ) + (*it)->setSelected( newOwners ); } } myIsSelChangeEnabled = true; @@ -170,7 +173,7 @@ bool SUIT_SelectionMgr::hasSelectionMode( const int mode ) const /*! Gets selection modes to list \a vals. */ -void SUIT_SelectionMgr::selectionModes( QValueList& vals ) const +void SUIT_SelectionMgr::selectionModes( QList& vals ) const { vals = mySelModes; } @@ -179,14 +182,14 @@ void SUIT_SelectionMgr::selectionModes( QValueList& vals ) const */ void SUIT_SelectionMgr::setSelectionModes( const int mode ) { - QValueList lst; + QList lst; lst.append( mode ); setSelectionModes( lst ); } /*! Sets selection modes list from \a lst. */ -void SUIT_SelectionMgr::setSelectionModes( const QValueList& lst ) +void SUIT_SelectionMgr::setSelectionModes( const QList& lst ) { mySelModes = lst; } @@ -195,20 +198,20 @@ void SUIT_SelectionMgr::setSelectionModes( const QValueList& lst ) */ void SUIT_SelectionMgr::appendSelectionModes( const int mode ) { - QValueList lst; + QList lst; lst.append( mode ); appendSelectionModes( lst ); } /*! Append selection modes \a lst list. */ -void SUIT_SelectionMgr::appendSelectionModes( const QValueList& lst ) +void SUIT_SelectionMgr::appendSelectionModes( const QList& lst ) { QMap map; - for ( QValueList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) + for ( QList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) map.insert( *it, 0 ); - for ( QValueList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) + for ( QList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) { if ( !map.contains( *itr ) ) mySelModes.append( *itr ); @@ -219,20 +222,20 @@ void SUIT_SelectionMgr::appendSelectionModes( const QValueList& lst ) */ void SUIT_SelectionMgr::removeSelectionModes( const int mode ) { - QValueList lst; + QList lst; lst.append( mode ); removeSelectionModes( lst ); } /*! Remove selection modea \a lst from list. */ -void SUIT_SelectionMgr::removeSelectionModes( const QValueList& lst ) +void SUIT_SelectionMgr::removeSelectionModes( const QList& lst ) { QMap map; - for ( QValueList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) + for ( QList::const_iterator it = mySelModes.begin(); it != mySelModes.end(); ++it ) map.insert( *it, 0 ); - for ( QValueList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) + for ( QList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) map.remove( *itr ); mySelModes.clear(); @@ -248,8 +251,8 @@ bool SUIT_SelectionMgr::isOk( const SUIT_DataOwner* owner ) const return false; bool ok = true; - for ( SelFilterListIterator it( myFilters ); it.current() && ok; ++it ) - ok = it.current()->isOk( owner ); + for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end() && ok; ++it ) + ok = (*it)->isOk( owner ); return ok; } @@ -292,13 +295,25 @@ void SUIT_SelectionMgr::installFilter( SUIT_SelectionFilter* f, const bool updat */ void SUIT_SelectionMgr::removeFilter( SUIT_SelectionFilter* f ) { - myFilters.remove( f ); + if ( !myFilters.contains( f ) ) + return; + + myFilters.removeAll( f ); + + if ( autoDeleteFilter() ) + delete f; } /*! Clear filters list. */ void SUIT_SelectionMgr::clearFilters() { + if ( autoDeleteFilter() ) + { + for ( SelFilterList::const_iterator it = myFilters.begin(); it != myFilters.end(); ++it ) + delete *it; + } + myFilters.clear(); } @@ -306,14 +321,14 @@ void SUIT_SelectionMgr::clearFilters() */ bool SUIT_SelectionMgr::autoDeleteFilter() const { - return myFilters.autoDelete(); + return myAutoDelFilter; } /*! Sets auto delete filter to \a on. */ void SUIT_SelectionMgr::setAutoDeleteFilter( const bool on ) { - myFilters.setAutoDelete( on ); + myAutoDelFilter = on; } /*! Gets good data owners list to \a out from \a in. diff --git a/src/SUIT/SUIT_SelectionMgr.h b/src/SUIT/SUIT_SelectionMgr.h index 79576568f..57d45c84e 100755 --- a/src/SUIT/SUIT_SelectionMgr.h +++ b/src/SUIT/SUIT_SelectionMgr.h @@ -23,9 +23,8 @@ #include "SUIT_DataOwner.h" #include "SUIT_SelectionFilter.h" -#include -#include -#include +#include +#include #ifdef WIN32 #pragma warning ( disable : 4251 ) @@ -43,24 +42,24 @@ public: virtual void selected( SUIT_DataOwnerPtrList&, const QString& = QString::null ) const; virtual void setSelected( const SUIT_DataOwnerPtrList&, const bool = false ); - void selectors( QPtrList& ) const; - void selectors( const QString&, QPtrList& ) const; + void selectors( QList& ) const; + void selectors( const QString&, QList& ) const; void setEnabled( const bool, const QString& = QString::null ); bool hasSelectionMode( const int ) const; - void selectionModes( QValueList& ) const; + void selectionModes( QList& ) const; void setSelectionModes( const int ); - virtual void setSelectionModes( const QValueList& ); + virtual void setSelectionModes( const QList& ); void appendSelectionModes( const int ); - virtual void appendSelectionModes( const QValueList& ); + virtual void appendSelectionModes( const QList& ); void removeSelectionModes( const int ); - virtual void removeSelectionModes( const QValueList& ); + virtual void removeSelectionModes( const QList& ); bool isOk( const SUIT_DataOwner* ) const; @@ -83,25 +82,21 @@ signals: protected: virtual void selectionChanged( SUIT_Selector* ); - typedef QPtrListIterator SelectorListIterator; - virtual void installSelector( SUIT_Selector* ); virtual void removeSelector( SUIT_Selector* ); private: void filterOwners( const SUIT_DataOwnerPtrList&, SUIT_DataOwnerPtrList& ) const; - typedef QPtrList SelectorList; - typedef QPtrList SelFilterList; - typedef QPtrListIterator SelFilterListIterator; - -protected: - SelectorList mySelectors; + typedef QList SelectorList; + typedef QList SelFilterList; private: SelFilterList myFilters; - QValueList mySelModes; + QList mySelModes; + SelectorList mySelectors; int myIterations; + bool myAutoDelFilter; bool myIsSelChangeEnabled; friend class SUIT_Selector; diff --git a/src/SUIT/SUIT_Selector.cxx b/src/SUIT/SUIT_Selector.cxx index ebda6a065..8879f77bc 100755 --- a/src/SUIT/SUIT_Selector.cxx +++ b/src/SUIT/SUIT_Selector.cxx @@ -135,7 +135,7 @@ bool SUIT_Selector::hasSelectionMode( const int mode ) const /*! Puts to list \a lst selection modes from selection manager. */ -void SUIT_Selector::selectionModes( QValueList& lst ) const +void SUIT_Selector::selectionModes( QList& lst ) const { if ( selectionMgr() ) selectionMgr()->selectionModes( lst ); diff --git a/src/SUIT/SUIT_Selector.h b/src/SUIT/SUIT_Selector.h index 058506d24..ca2940b6f 100755 --- a/src/SUIT/SUIT_Selector.h +++ b/src/SUIT/SUIT_Selector.h @@ -21,8 +21,8 @@ #include "SUIT.h" -#include -#include +#include +#include class SUIT_SelectionMgr; class SUIT_DataOwnerPtrList; @@ -55,7 +55,7 @@ public: void setSelected( const SUIT_DataOwnerPtrList& ); bool hasSelectionMode( const int ) const; - void selectionModes( QValueList& ) const; + void selectionModes( QList& ) const; protected: void selectionChanged(); diff --git a/src/SUIT/SUIT_Session.cxx b/src/SUIT/SUIT_Session.cxx index 7d2ac3839..9f74f1a1a 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -25,19 +25,16 @@ #include "SUIT_ViewManager.h" #include "SUIT_ExceptionHandler.h" -#include -#include -#include +#include +#include +#include -#ifdef WIN32 +#ifdef Q_OS_WIN32 #include #else #include #endif -static bool SUIT_Session_IsPythonExecuted = false; -static QMutex SUIT_Session_PythonMutex; - SUIT_Session* SUIT_Session::mySession = 0; /*! Constructor.*/ @@ -52,16 +49,18 @@ myExitStatus( FROM_GUI ) SUIT_ASSERT( !mySession ) mySession = this; - - myAppList.setAutoDelete( true ); } /*!destructor. Clear applications list and set mySession to zero.*/ SUIT_Session::~SUIT_Session() { + for ( AppList::iterator it = myAppList.begin(); it != myAppList.end(); ++it ) + delete *it; + myAppList.clear(); - if (myResMgr) { + if ( myResMgr ) + { delete myResMgr; myResMgr = 0; } @@ -102,8 +101,8 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, APP_CREATE_FUNC crtInst = 0; -#ifdef WIN32 - crtInst = (APP_CREATE_FUNC)::GetProcAddress( libHandle, APP_CREATE_NAME ); +#ifdef Q_OS_WIN32 + crtInst = (APP_CREATE_FUNC)::GetProcAddress( (HINSTANCE)libHandle, APP_CREATE_NAME ); #else crtInst = (APP_CREATE_FUNC)dlsym( libHandle, APP_CREATE_NAME ); #endif @@ -130,20 +129,15 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, return 0; } - anApp->setName( appName ); - - connect( anApp, SIGNAL( applicationClosed( SUIT_Application* ) ), - this, SLOT( onApplicationClosed( SUIT_Application* ) ) ); - connect( anApp, SIGNAL( activated( SUIT_Application* ) ), - this, SLOT( onApplicationActivated( SUIT_Application* ) ) ); + anApp->setObjectName( appName ); - myAppList.append( anApp ); + insertApplication( anApp ); if ( !myHandler ) { APP_GET_HANDLER_FUNC crtHndlr = 0; -#ifdef WIN32 - crtHndlr = (APP_GET_HANDLER_FUNC)::GetProcAddress( libHandle, APP_GET_HANDLER_NAME ); +#ifdef Q_OS_WIN32 + crtHndlr = (APP_GET_HANDLER_FUNC)::GetProcAddress( (HINSTANCE)libHandle, APP_GET_HANDLER_NAME ); #else crtHndlr = (APP_GET_HANDLER_FUNC)dlsym( libHandle, APP_GET_HANDLER_NAME ); #endif @@ -163,15 +157,22 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, /*! Gets the list of all applications */ -QPtrList SUIT_Session::applications() const +QList SUIT_Session::applications() const { - QPtrList apps; - apps.setAutoDelete( false ); + return myAppList; +} + +void SUIT_Session::insertApplication( SUIT_Application* app ) +{ + if ( !app || myAppList.contains( app ) ) + return; - for ( AppListIterator it( myAppList ); it.current(); ++it ) - apps.append( it.current() ); + myAppList.append( app ); - return apps; + connect( app, SIGNAL( applicationClosed( SUIT_Application* ) ), + this, SLOT( onApplicationClosed( SUIT_Application* ) ) ); + connect( app, SIGNAL( activated( SUIT_Application* ) ), + this, SLOT( onApplicationActivated( SUIT_Application* ) ) ); } /*! @@ -223,14 +224,16 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) { emit applicationClosed( theApp ); - myAppList.remove( theApp ); + myAppList.removeAll( theApp ); + delete theApp; + if ( theApp == myActiveApp ) myActiveApp = 0; if ( myAppList.isEmpty() ) { printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus ); - qApp->exit( myExitStatus ); + QApplication::instance()->exit( myExitStatus ); } } @@ -239,16 +242,17 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) */ void SUIT_Session::closeSession( int mode ) { - while ( !myAppList.isEmpty() ) + AppList apps = myAppList; + for ( AppList::const_iterator it = apps.begin(); it != apps.end(); ++it ) { - SUIT_Application* app = myAppList.getFirst(); + SUIT_Application* app = *it; if ( mode == ASK && !app->isPossibleToClose() ) return; else if ( mode == SAVE ) { SUIT_Study* study = app->activeStudy(); if ( study->isModified() && study->isSaved() ) - study->saveDocument(); + study->saveDocument(); } else if ( mode == DONT_SAVE ) { @@ -270,11 +274,12 @@ SUIT_ExceptionHandler* SUIT_Session::handler() const QString SUIT_Session::lastError() const { QString str; -#ifdef WNT +#ifdef Q_OS_WIN32 LPVOID lpMsgBuf; ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, ::GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, 0 ); - str = QString( (LPTSTR)lpMsgBuf ); + LPTSTR msg = (LPTSTR)lpMsgBuf; + str = QString( SUIT_Tools::toQString( msg ) ); LocalFree( lpMsgBuf ); #else str = QString( dlerror() ); @@ -294,10 +299,16 @@ SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name, QString& li return 0; AppLib lib = 0; -#ifdef WIN32 - lib = ::LoadLibrary( (char*)libFile.latin1() ); + QByteArray bid = libFile.toLatin1(); +#ifdef Q_OS_WIN32 +#ifdef UNICODE + LPTSTR str = (LPTSTR)libFile.utf16(); #else - lib = dlopen( (char*)libFile.latin1(), RTLD_LAZY | RTLD_GLOBAL ); + LPTSTR str = (LPTSTR)(const char*)bid; +#endif + lib = ::LoadLibrary( str ); +#else + lib = dlopen( (const char*)libFile.toLatin1(), RTLD_LAZY | RTLD_GLOBAL ); #endif return lib; } @@ -305,7 +316,7 @@ SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name, QString& li /*! \retval Return file name by application name.*/ QString SUIT_Session::applicationName( const QString& str ) const { -#ifdef WIN32 +#ifdef Q_OS_WIN32 return SUIT_Tools::file( str, false ); #else QString fileName = SUIT_Tools::file( str, false ); @@ -330,28 +341,3 @@ void SUIT_Session::onApplicationActivated( SUIT_Application* app ) { myActiveApp = app; } - -/*! - \retval Return TRUE, if a command is currently executed in Python Console, - FALSE otherwise. -*/ -bool SUIT_Session::IsPythonExecuted() -{ - bool ret; - SUIT_Session_PythonMutex.lock(); - ret = SUIT_Session_IsPythonExecuted; - SUIT_Session_PythonMutex.unlock(); - return ret; -} - -/*! - Set value of boolean flag, being returned by method \a IsPythonExecuted(). - It is supposed to set the flag to TRUE when any python command starts - and reset it to FALSE when the command finishes. -*/ -void SUIT_Session::SetPythonExecuted(bool isPythonExecuted) -{ - SUIT_Session_PythonMutex.lock(); - SUIT_Session_IsPythonExecuted = isPythonExecuted; - SUIT_Session_PythonMutex.unlock(); -} diff --git a/src/SUIT/SUIT_Session.h b/src/SUIT/SUIT_Session.h index 840de5927..e9aa75029 100755 --- a/src/SUIT/SUIT_Session.h +++ b/src/SUIT/SUIT_Session.h @@ -24,11 +24,10 @@ #include "SUIT_Application.h" #include "SUIT_ResourceMgr.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include #ifdef WIN32 #define LIB_HANDLE HINSTANCE @@ -39,7 +38,7 @@ class SUIT_ResourceMgr; class SUIT_ExceptionHandler; -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4251 ) #endif /*! @@ -65,7 +64,7 @@ public: SUIT_Application* startApplication( const QString&, int = 0, char** = 0 ); - QPtrList applications() const; + QList applications() const; SUIT_Application* activeApplication() const; SUIT_ResourceMgr* resourceMgr() const; @@ -74,9 +73,7 @@ public: SUIT_ExceptionHandler* handler() const; - // To lock GUI user actions during python command execution (PAL12651) - static bool IsPythonExecuted(); - static void SetPythonExecuted(bool isPythonExecuted); + void insertApplication( SUIT_Application* ); signals: void applicationClosed( SUIT_Application* ); @@ -89,9 +86,8 @@ private slots: void onApplicationActivated( SUIT_Application* ); private: - typedef QPtrList AppList; - typedef QMap AppLibMap; - typedef QPtrListIterator AppListIterator; + typedef QList AppList; + typedef QMap AppLibMap; private: QString lastError() const; diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index a3baef3ce..ea2d59830 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -23,7 +23,6 @@ #include "SUIT_DataObject.h" #include "SUIT_MessageBox.h" #include "SUIT_Application.h" -#include /*!\class SUIT_Study * Support study management. Object management. Operation management. @@ -43,8 +42,6 @@ myBlockChangeState( false ) myId = ++_id; myRoot = new SUIT_DataObject(); - myOperations.setAutoDelete( false ); - myOperations.setAutoDelete( false ); } /*!Destructor.*/ @@ -91,7 +88,7 @@ QString SUIT_Study::studyName() const */ SUIT_Operation* SUIT_Study::activeOperation() const { - return myOperations.count() > 0 ? myOperations.getLast() : 0; + return myOperations.count() > 0 ? myOperations.last() : 0; } /*! @@ -163,8 +160,8 @@ bool SUIT_Study::saveDocument() void SUIT_Study::abortAllOperations() { myBlockChangeState = true; - for( SUIT_Operation* op = myOperations.first(); op; op = myOperations.next() ) - op->abort(); + for ( Operations::iterator it = myOperations.begin(); it != myOperations.end(); ++it ) + (*it)->abort(); myBlockChangeState = false; myOperations.clear(); } @@ -239,9 +236,9 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const return 0; Operations tmpOps( myOperations ); - SUIT_Operation* anOp = 0; - for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() ) + for ( Operations::const_iterator it = tmpOps.end(); it != tmpOps.begin(); --it ) { + SUIT_Operation* anOp = *it; if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) ) return anOp; } @@ -262,7 +259,7 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const */ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) { - if ( !theOp || myOperations.find( theOp ) >= 0 ) + if ( !theOp || myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Rejected ); @@ -313,7 +310,7 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) */ bool SUIT_Study::abort( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 ) + if ( !theOp || !myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Rejected ); @@ -337,7 +334,7 @@ bool SUIT_Study::abort( SUIT_Operation* theOp ) */ bool SUIT_Study::commit( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 ) + if ( !theOp || !myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Accepted ); @@ -363,7 +360,7 @@ bool SUIT_Study::commit( SUIT_Operation* theOp ) */ bool SUIT_Study::suspend( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended ) + if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Suspended ) return false; theOp->setState( SUIT_Operation::Suspended ); @@ -382,7 +379,7 @@ bool SUIT_Study::suspend( SUIT_Operation* theOp ) */ bool SUIT_Study::resume( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 || + if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Running || blockingOperation( theOp ) != 0 ) return false; @@ -396,7 +393,7 @@ bool SUIT_Study::resume( SUIT_Operation* theOp ) // Move operation at the end of list in order to sort it in the order of activation. // As result active operation is a last operation of list, operation which was active // before currently active operation is located before it and so on - myOperations.remove( theOp ); + myOperations.removeAll( theOp ); myOperations.append( theOp ); emit theOp->resumed( theOp ); @@ -413,12 +410,13 @@ bool SUIT_Study::resume( SUIT_Operation* theOp ) void SUIT_Study::stop( SUIT_Operation* theOp ) { theOp->setState( SUIT_Operation::Waiting ); - myOperations.remove( theOp ); + myOperations.removeAll( theOp ); // get last operation which can be resumed - SUIT_Operation* anOp, *aResultOp = 0; - for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() ) + SUIT_Operation* aResultOp = 0; + for ( Operations::iterator it = myOperations.end(); it != myOperations.begin(); --it ) { + SUIT_Operation* anOp = *it; if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 ) { aResultOp = anOp; @@ -438,7 +436,7 @@ void SUIT_Study::stop( SUIT_Operation* theOp ) * \brief Get all started operations * \return List of all started operations */ -const QPtrList& SUIT_Study::operations() const +const QList& SUIT_Study::operations() const { return myOperations; } diff --git a/src/SUIT/SUIT_Study.h b/src/SUIT/SUIT_Study.h index 156c6bc74..604ba97bb 100755 --- a/src/SUIT/SUIT_Study.h +++ b/src/SUIT/SUIT_Study.h @@ -23,12 +23,12 @@ #include "SUIT_Operation.h" -#include -#include +#include +#include +class QDialog; class SUIT_DataObject; class SUIT_Application; -class QDialog; #ifdef WIN32 #pragma warning( disable:4251 ) @@ -65,7 +65,7 @@ public: // Operation management SUIT_Operation* activeOperation() const; virtual void abortAllOperations(); - const QPtrList& operations() const; + const QList& operations() const; virtual SUIT_Operation* blockingOperation( SUIT_Operation* ) const; @@ -98,7 +98,7 @@ protected: virtual bool commitTransaction( const QString& = QString::null ); private: - typedef QPtrList Operations; + typedef QList Operations; void stop( SUIT_Operation* ); private: diff --git a/src/SUIT/SUIT_ToolButton.cxx b/src/SUIT/SUIT_ToolButton.cxx index 35e009c6d..cc3c852fb 100755 --- a/src/SUIT/SUIT_ToolButton.cxx +++ b/src/SUIT/SUIT_ToolButton.cxx @@ -19,49 +19,32 @@ #include "SUIT_ToolButton.h" -#include -#include +#include +#include /*!Constructor.*/ -SUIT_ToolButton::SUIT_ToolButton( QWidget *parent, - const char *name, - bool changeItemAfterClick) - : QToolButton( parent, name ), - myChangeItemAfterClick( changeItemAfterClick ) +SUIT_ToolButton::SUIT_ToolButton( QWidget *parent, const char *name, + bool changeItemAfterClick ) +: QToolButton( parent ), +myChangeItemAfterClick( changeItemAfterClick ) { initialize(); } -/*!Constructor.*/ -SUIT_ToolButton::SUIT_ToolButton( const QPixmap & pm, - const QString &textLabel, - const QString& grouptext, - QObject * receiver, - const char* slot, - QToolBar * parent, - const char* name, - bool changeItemAfterClick) - :QToolButton(pm, textLabel, grouptext, receiver, slot, parent, name), - myChangeItemAfterClick( changeItemAfterClick ) -{ - initialize(); -} - - /*!Initialize tool buttons.*/ void SUIT_ToolButton::initialize() { - mySignal = NULL; - myPopup = new QPopupMenu( this ); - setPopup(myPopup); - connect( myPopup, SIGNAL(activated(int)), SLOT(OnSelectAction(int)) ); - setPopupDelay(250); +// mySignal = NULL; + myPopup = new QMenu( this ); + setMenu( myPopup ); + connect( myPopup, SIGNAL( activated( int ) ), SLOT( OnSelectAction( int ) ) ); } /*!drawButton is redefined to draw DownArrow*/ void SUIT_ToolButton::drawButton( QPainter * p ) { - QToolButton::drawButton(p); +/* + QToolButton::drawButton( p ); //draw DownArrow int x, y, w, h; @@ -69,53 +52,40 @@ void SUIT_ToolButton::drawButton( QPainter * p ) style().drawPrimitive( QStyle::PE_ArrowDown, p, QRect(x+w/2+3, y+h/2+3, w/2, h/2), //QRect(x+(w-x)/2, y+(h-y)/2, w, h) colorGroup(), isEnabled() ); +*/ } - /*! Add action into popup*/ -void SUIT_ToolButton::AddAction(QAction* theAction) +void SUIT_ToolButton::AddAction( QAction* theAction ) { bool aIsFirst = false; - if ( myPopup->count() == 0 ) + if ( myPopup->actions().isEmpty() ) { aIsFirst = true; - setPixmap(theAction->iconSet().pixmap()); - setTextLabel(theAction->text()); - theAction->addTo( myPopup ); - QMenuItem* aItem = myPopup->findItem(myPopup->idAt(0)); - if (aItem != NULL) - { - mySignal = aItem->signal(); - } + setIcon( theAction->icon() ); + setText( theAction->text() ); } - else - theAction->addTo( myPopup ); + myPopup->addAction( theAction ); } /*! Sets myPopup item with theIndex as current*/ -void SUIT_ToolButton::SetItem(int theIndex) +void SUIT_ToolButton::SetItem( int theIndex ) { - int anId = myPopup->idAt(theIndex); - if (anId != -1) + QAction* a = myPopup->actions()[theIndex]; + if ( a ) { - // Protection against unexpected null pointers returned - if ( myPopup->iconSet(anId) ) - setPixmap(myPopup->iconSet(anId)->pixmap()); - setTextLabel(myPopup->text(anId)); - QMenuItem* aItem = myPopup->findItem(anId); - if (aItem != NULL) - { - mySignal = aItem->signal(); - } + setIcon( a->icon() ); + setText( a->text() ); } } /*!Public SLOT. * On select action (icon and text set with id = \a theItemID) */ -void SUIT_ToolButton::OnSelectAction(int theItemID) +void SUIT_ToolButton::OnSelectAction( int theItemID ) { - if (myChangeItemAfterClick) +/* + if ( myChangeItemAfterClick ) { // Protection against unexpected null pointers returned if ( myPopup->iconSet(theItemID) ) @@ -127,18 +97,15 @@ void SUIT_ToolButton::OnSelectAction(int theItemID) mySignal = aItem->signal(); } } +*/ } - - /*!On mouse release event.*/ -void SUIT_ToolButton::mouseReleaseEvent ( QMouseEvent * theEvent) +void SUIT_ToolButton::mouseReleaseEvent( QMouseEvent* theEvent ) { - QToolButton::mouseReleaseEvent(theEvent); - if (mySignal != NULL) - { + QToolButton::mouseReleaseEvent( theEvent ); +/* + if ( mySignal ) mySignal->activate(); - } +*/ } - - diff --git a/src/SUIT/SUIT_ToolButton.h b/src/SUIT/SUIT_ToolButton.h index 10abe2629..d4b0365bb 100755 --- a/src/SUIT/SUIT_ToolButton.h +++ b/src/SUIT/SUIT_ToolButton.h @@ -19,11 +19,14 @@ #ifndef SUIT_TOOLBUTTON_H #define SUIT_TOOLBUTTON_H -#include -#include - #include "SUIT.h" +#include +#include + +class QPixmap; +class QToolBar; + /*! To draw down arrow on toolbutton.*/ class SUIT_EXPORT SUIT_ToolButton : public QToolButton { @@ -35,11 +38,6 @@ public: SUIT_ToolButton( QWidget *parent = 0, const char *name = 0, bool changeItemAfterClick = true ); - SUIT_ToolButton( const QPixmap & pm, const QString &textLabel, - const QString& grouptext, - QObject * receiver, const char* slot, - QToolBar * parent, const char* name = 0, - bool changeItemAfterClick = true ); //@} void drawButton( QPainter * pQPainter); @@ -57,11 +55,10 @@ protected: private: void initialize(); - QPopupMenu* myPopup; - QSignal* mySignal; - bool myChangeItemAfterClick; + QMenu* myPopup; +// QSignal* mySignal; + bool myChangeItemAfterClick; }; #endif - diff --git a/src/SUIT/SUIT_Tools.cxx b/src/SUIT/SUIT_Tools.cxx index 953de65d4..11086a0d9 100755 --- a/src/SUIT/SUIT_Tools.cxx +++ b/src/SUIT/SUIT_Tools.cxx @@ -18,7 +18,7 @@ // #include "SUIT_Tools.h" -#include +#include #include #include @@ -37,7 +37,7 @@ void SUIT_Tools::trace( const char* lpszLog, const char* lpszFormat, ... ) tmpPath += QString( "Salome_trace" ); FILE* pStream; - pStream = fopen( lpszLog ? lpszLog : tmpPath.latin1(), "a" ); + pStream = fopen( lpszLog ? lpszLog : (const char*)tmpPath.toLatin1(), "a" ); if ( pStream ) { va_list argptr; @@ -55,7 +55,7 @@ void SUIT_Tools::trace( const char* lpszLog, const char* lpszFormat, ... ) */ QRect SUIT_Tools::makeRect( const int x1, const int y1, const int x2, const int y2 ) { - return QRect( QMIN( x1, x2 ), QMIN( y1, y2 ), QABS( x2 - x1 ), QABS( y2 - y1 ) ); + return QRect( qMin( x1, x2 ), qMin( y1, y2 ), qAbs( x2 - x1 ), qAbs( y2 - y1 ) ); } /*! @@ -64,7 +64,7 @@ QRect SUIT_Tools::makeRect( const int x1, const int y1, const int x2, const int QFont SUIT_Tools::stringToFont( const QString& fontDescription ) { QFont font; - if ( fontDescription.stripWhiteSpace().isEmpty() || !font.fromString( fontDescription ) ) + if ( fontDescription.trimmed().isEmpty() || !font.fromString( fontDescription ) ) font = QFont( "Courier", 11 ); return font; } diff --git a/src/SUIT/SUIT_Tools.h b/src/SUIT/SUIT_Tools.h index 62bc8d163..53ebfe11d 100755 --- a/src/SUIT/SUIT_Tools.h +++ b/src/SUIT/SUIT_Tools.h @@ -23,9 +23,10 @@ #include -#include -#include -#include +#include +#include + +#include /*! \class SUIT_Tools diff --git a/src/SUIT/SUIT_ViewManager.cxx b/src/SUIT/SUIT_ViewManager.cxx index 9d2e7e186..0693ea086 100755 --- a/src/SUIT/SUIT_ViewManager.cxx +++ b/src/SUIT/SUIT_ViewManager.cxx @@ -22,11 +22,13 @@ #include "SUIT_ViewModel.h" #include "SUIT_Study.h" -#include -#include -#include +#include +#include -#ifdef WNT +#include +#include + +#ifdef WIN32 #include #endif @@ -104,8 +106,8 @@ void SUIT_ViewManager::setViewModel(SUIT_ViewModel* theViewModel) /*!Sets view name for view window \a theView.*/ void SUIT_ViewManager::setViewName( SUIT_ViewWindow* theView ) { - QString title = prepareTitle( getTitle(), myId + 1, myViews.find( theView ) + 1 ); - theView->setCaption( title ); + QString title = prepareTitle( getTitle(), myId + 1, myViews.indexOf( theView ) + 1 ); + theView->setWindowTitle( title ); } QString SUIT_ViewManager::prepareTitle( const QString& title, const int mId, const int vId ) @@ -113,7 +115,7 @@ QString SUIT_ViewManager::prepareTitle( const QString& title, const int mId, con QString res = title; QRegExp re( "%[%MV]" ); int i = 0; - while ( ( i = re.search( res, i ) ) != -1 ) + while ( ( i = re.indexIn( res, i ) ) != -1 ) { QString rplc; QString str = res.mid( i, re.matchedLength() ); @@ -162,18 +164,28 @@ void SUIT_ViewManager::createView() createViewWindow(); } +QVector SUIT_ViewManager::getViews() const +{ + QVector res; + for ( int i = 0; i < myViews.count(); i++ ) + { + if ( myViews[i] ) + res.append( myViews[i] ); + } + + return res; +} + /*!Insert view window to view manager. *\retval false - if something wrong, else true. */ bool SUIT_ViewManager::insertView(SUIT_ViewWindow* theView) { unsigned int aSize = myViews.size(); - unsigned int aNbItems = myViews.count()+1; - if (aNbItems > aSize) { - if (!myViews.resize(aNbItems)) { - QMessageBox::critical(myDesktop, tr("Critical error"), tr("There is no memory for the new view!!!")); - return false; - } + unsigned int aNbItems = myViews.count() + 1; + if ( aNbItems > aSize ) + { + myViews.resize( aNbItems ); aSize = myViews.size(); } @@ -228,11 +240,11 @@ void SUIT_ViewManager::closeView( SUIT_ViewWindow* theView ) if ( !theView ) return; - QGuardedPtr view( theView ); + QPointer view( theView ); view->hide(); - if ( !view->testWFlags( WDestructiveClose ) ) + if ( !view->testAttribute( Qt::WA_DeleteOnClose ) ) return; emit deleteView( view ); @@ -245,15 +257,14 @@ void SUIT_ViewManager::closeView( SUIT_ViewWindow* theView ) /*!Remove view window \a theView from view manager. *And close the last view, if it has \a theView. */ -void SUIT_ViewManager::removeView(SUIT_ViewWindow* theView) +void SUIT_ViewManager::removeView( SUIT_ViewWindow* theView ) { - theView->disconnect(this); - myViews.remove(myViews.find(theView)); - if (myActiveView == theView) + theView->disconnect( this ); + myViews.remove( myViews.indexOf( theView ) ); + if ( myActiveView == theView ) myActiveView = 0; - int aNumItems = myViews.count(); - if (aNumItems == 0) - emit lastViewClosed(this); + if ( !myViews.count() ) + emit lastViewClosed( this ); } /*! diff --git a/src/SUIT/SUIT_ViewManager.h b/src/SUIT/SUIT_ViewManager.h index 9fdd2ecd8..4b3ea0f85 100755 --- a/src/SUIT/SUIT_ViewManager.h +++ b/src/SUIT/SUIT_ViewManager.h @@ -23,8 +23,9 @@ #include "SUIT_ViewWindow.h" #include "SUIT_PopupClient.h" -#include -#include +#include +#include +#include class SUIT_Study; class SUIT_Desktop; @@ -57,7 +58,7 @@ public: SUIT_ViewWindow* getActiveView() { return myActiveView; } int getViewsCount() { return myViews.count(); } - QPtrVector getViews() { return myViews; } + QVector getViews() const; QString getTitle() const { return myTitle; } virtual void setTitle( const QString& ); @@ -107,15 +108,18 @@ protected: virtual void closeView(SUIT_ViewWindow* theView); /*! Used to set unique name for the view.*/ - virtual void setViewName(SUIT_ViewWindow* theView); + virtual void setViewName(SUIT_ViewWindow* theView ); QString prepareTitle( const QString&, const int, const int ); static int useNewId( const QString& ); +protected: + typedef QPointer ViewWindow; + protected: SUIT_Desktop* myDesktop; SUIT_ViewModel* myViewModel; - QPtrVector myViews; + QVector myViews; SUIT_ViewWindow* myActiveView; int myId; diff --git a/src/SUIT/SUIT_ViewModel.cxx b/src/SUIT/SUIT_ViewModel.cxx index 86c0f0099..cba2af9fc 100755 --- a/src/SUIT/SUIT_ViewModel.cxx +++ b/src/SUIT/SUIT_ViewModel.cxx @@ -29,19 +29,20 @@ static bool isInitialized = false; /*!Constructor.*/ SUIT_ViewModel::SUIT_ViewModel() { - if (!isInitialized) { + if ( !isInitialized ) + { isInitialized = true; - SUIT_ViewModel::myStateMap[ZOOM] = Qt::ControlButton; + SUIT_ViewModel::myStateMap[ZOOM] = Qt::ControlModifier; SUIT_ViewModel::myButtonMap[ZOOM] = Qt::LeftButton; - SUIT_ViewModel::myStateMap[PAN] = Qt::ControlButton; + SUIT_ViewModel::myStateMap[PAN] = Qt::ControlModifier; SUIT_ViewModel::myButtonMap[PAN] = Qt::MidButton; - SUIT_ViewModel::myStateMap[ROTATE] = Qt::ControlButton; + SUIT_ViewModel::myStateMap[ROTATE] = Qt::ControlModifier; SUIT_ViewModel::myButtonMap[ROTATE] = Qt::RightButton; - SUIT_ViewModel::myStateMap[FIT_AREA] = Qt::ControlButton; + SUIT_ViewModel::myStateMap[FIT_AREA] = Qt::ControlModifier; SUIT_ViewModel::myButtonMap[FIT_AREA] = Qt::RightButton; } myViewManager = 0; @@ -65,8 +66,7 @@ SUIT_ViewWindow* SUIT_ViewModel::createView(SUIT_Desktop* theDesktop) *\param theState - adding state to state map operations. *\param theButton - adding state to button map operations. */ -void SUIT_ViewModel::setHotButton(HotOperation theOper, Qt::ButtonState theState, - Qt::ButtonState theButton) +void SUIT_ViewModel::setHotButton( HotOperation theOper, Qt::KeyboardModifier theState, Qt::MouseButton theButton ) { myStateMap[theOper] = theState; myButtonMap[theOper] = theButton; @@ -77,8 +77,7 @@ void SUIT_ViewModel::setHotButton(HotOperation theOper, Qt::ButtonState theState *\param theState - output state from state map operations. *\param theButton - output state from button map operations. */ -void SUIT_ViewModel::getHotButton(HotOperation theOper, Qt::ButtonState& theState, - Qt::ButtonState& theButton) +void SUIT_ViewModel::getHotButton( HotOperation theOper, Qt::KeyboardModifier& theState, Qt::MouseButton& theButton ) { theState = myStateMap[theOper]; theButton = myButtonMap[theOper]; diff --git a/src/SUIT/SUIT_ViewModel.h b/src/SUIT/SUIT_ViewModel.h index 4be9fd777..2cf1e6f47 100755 --- a/src/SUIT/SUIT_ViewModel.h +++ b/src/SUIT/SUIT_ViewModel.h @@ -24,8 +24,9 @@ #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" -#include -#include +#include + +#include #ifdef WIN32 #pragma warning( disable:4251 ) @@ -42,8 +43,8 @@ class SUIT_EXPORT SUIT_ViewModel : public QObject public: enum HotOperation { PAN, ZOOM, ROTATE, FIT_AREA }; - typedef QMap StatesMap; - typedef QMap ButtonsMap; + typedef QMap StatesMap; + typedef QMap ButtonsMap; SUIT_ViewModel(); virtual ~SUIT_ViewModel(); @@ -57,10 +58,10 @@ public: virtual void contextMenuPopup(QPopupMenu*) {} - static void setHotButton(HotOperation theOper, Qt::ButtonState theState, - Qt::ButtonState theButton); - static void getHotButton(HotOperation theOper, Qt::ButtonState& theState, - Qt::ButtonState& theButton); + static void setHotButton( HotOperation theOper, Qt::KeyboardModifier theState, + Qt::MouseButton theButton ); + static void getHotButton( HotOperation theOper, Qt::KeyboardModifier& theState, + Qt::MouseButton& theButton ); protected: SUIT_ViewManager* myViewManager; diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index faf064fb5..4fb6c40c6 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -20,16 +20,18 @@ // #include "SUIT_ViewWindow.h" + +#include "SUIT_Tools.h" +#include "SUIT_Study.h" #include "SUIT_Desktop.h" +#include "SUIT_MessageBox.h" #include "SUIT_Application.h" -#include "SUIT_Study.h" #include "SUIT_ViewManager.h" -#include "SUIT_Tools.h" -#include "SUIT_MessageBox.h" -#include -#include -#include -#include + +#include +#include +#include +#include /*!\class SUIT_ViewWindow * Class provide view window. @@ -39,13 +41,14 @@ const int DUMP_EVENT = QEvent::User + 123; /*! Constructor.*/ -SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop) -: QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose ) +SUIT_ViewWindow::SUIT_ViewWindow( SUIT_Desktop* theDesktop ) +: QMainWindow( theDesktop ) { myDesktop = theDesktop; - if ( myDesktop->icon() ) - setIcon( *myDesktop->icon() ); + setWindowIcon( myDesktop->windowIcon() ); + + setAttribute( Qt::WA_DeleteOnClose ); } /*! Destructor.*/ @@ -95,8 +98,8 @@ bool SUIT_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileNa else if( fmt == "JPG" ) fmt = "JPEG"; - QApplication::setOverrideCursor( Qt::waitCursor ); - bool res = img.save( fileName, fmt.latin1() ); + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool res = img.save( fileName, fmt.toLatin1() ); QApplication::restoreOverrideCursor(); return res; } @@ -116,10 +119,7 @@ bool SUIT_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& */ void SUIT_ViewWindow::setDestructiveClose( const bool on ) { - if ( on ) - setWFlags( WDestructiveClose ); - else - clearWFlags( WDestructiveClose ); + setAttribute( Qt::WA_DeleteOnClose, on ); } /*! Close event \a theEvent. @@ -142,8 +142,8 @@ void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e ) */ void SUIT_ViewWindow::onDumpView() { - qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) ); - qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) ); + QApplication::postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ) ) ); + QApplication::postEvent( this, new QEvent( (QEvent::Type)DUMP_EVENT ) ); } /*! @@ -168,20 +168,18 @@ bool SUIT_ViewWindow::event( QEvent* e ) // get file name SUIT_Application* app = myManager->study()->application(); QString fileName = app->getFileName( false, QString::null, filter(), tr( "TLT_DUMP_VIEW" ), 0 ); - if( !fileName.isEmpty() ) + if ( !fileName.isEmpty() ) { - QString fmt = SUIT_Tools::extension( fileName ).upper(); - bOk = dumpViewToFormat( im, fileName, fmt ); + QString fmt = SUIT_Tools::extension( fileName ).toUpper(); + bOk = dumpViewToFormat( im, fileName, fmt ); } else - { - bOk = true; // cancelled - } + bOk = true; // cancelled } - if ( !bOk ) { + if ( !bOk ) SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) ); - } - return TRUE; + + return true; } return QMainWindow::event( e ); } diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index 6a6a6f869..8381c0a61 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -19,20 +19,16 @@ // SUIT_ViewWindow.h: interface for the SUIT_ViewWindow class. // -#if !defined(AFX_SUIT_VIEWWINDOW_H__82C3D51A_6F10_45B0_BCFE_3CB3EF596A4D__INCLUDED_) -#define AFX_SUIT_VIEWWINDOW_H__82C3D51A_6F10_45B0_BCFE_3CB3EF596A4D__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 +#ifndef SUIT_VIEWWINDOW_H +#define SUIT_VIEWWINDOW_H #include "SUIT.h" -#include +#include +class QImage; class SUIT_Desktop; class SUIT_ViewManager; -class QImage; class SUIT_EXPORT SUIT_ViewWindow: public QMainWindow { diff --git a/src/SUIT/utilities.h b/src/SUIT/utilities.h deleted file mode 100755 index a82d31726..000000000 --- a/src/SUIT/utilities.h +++ /dev/null @@ -1,122 +0,0 @@ -// SALOME Utils : general SALOME's definitions and tools -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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 : utilities.h -// Author : Antoine YESSAYAN, Paul RASCLE, EDF -// Module : SALOME -// $Header$ - -/*! --- Definition macros file to print informations if _DEBUG_ is defined --- */ - -#ifndef UTILITIES_H -#define UTILITIES_H - -#include -#include -#include - - -#include "LocalTraceBufferPool.hxx" - -/*! \file utilities.h - * For each message to put in the trace, a specific ostingstream object is \n - * created and destroyed automatically at the end of the message macro. \n - * The insert function of LocalTraceBufferPool class gets a buffer in a \n - * buffer pool (unique with the help of mutexes and semaphores) and copy the \n - * message in the buffer.\n - * This buffer is read later by a specific thread in charge of trace print.\n - * Order of trace entries is globally respected. Nevertheless, if there are \n - * several threads waiting for a free buffer to trace, the order of \n - * thread waken up is not garanteed (no fifo or priority rules in Linux Kernel) - */ - -#define MESS_INIT(deb) std::ostringstream os; os<insert(NORMAL_MESS, os.str().c_str()); -#define MESS_ABORT std::endl; LocalTraceBufferPool::instance()->insert(ABORT_MESS, os.str().c_str()); - -// --- Some macros are always defined (without _DEBUG_): for use with release version - -#define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END} -#define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END} -#define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT} -#define IMMEDIATE_ABORT(code) {std::cout <