From: asl Date: Fri, 9 Dec 2005 13:32:15 +0000 (+0000) Subject: PAL10668 - smart autosize for object browser X-Git-Tag: T_3_1_0pre~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1f631a85ebab0e77c1a2ed3ccac4d5ca5322c148;p=modules%2Fgui.git PAL10668 - smart autosize for object browser --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 18bf4439e..f11a4f23e 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -77,9 +78,6 @@ #include #include -#define OBJECT_BROWSER_WIDTH 300 -#define OBJECT_COLUMN_WIDTH 150 - #ifdef WIN32 #define DEFAULT_BROWSER "start iexplore.exe" #else @@ -888,6 +886,8 @@ void LightApp_Application::addWindow( QWidget* wid, const int flag, const int st myWindows[flag]->setResizeEnabled( true ); myWindows[flag]->setCloseMode( QDockWindow::Always ); myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) ); + myWindows[flag]->setFixedExtentWidth( wid->width() ); + myWindows[flag]->setFixedExtentHeight( wid->height() ); } QFont f; @@ -1317,10 +1317,12 @@ QWidget* LightApp_Application::createWindow( const int flag ) ob->setAutoUpdate( true ); ob->setAutoOpenLevel( 1 ); ob->setCaption( tr( "OBJECT_BROWSER" ) ); - ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH ); - ob->resize( OBJECT_BROWSER_WIDTH, ob->height() ); - ob->setFilter( new LightApp_OBFilter( selectionMgr() ) ); + OB_ListView* ob_list = dynamic_cast( const_cast( ob->listView() ) ); + if( ob_list ) + ob_list->setColumnMaxWidth( 0, desktop()->width()/4 ); + + ob->setFilter( new LightApp_OBFilter( selectionMgr() ) ); ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) ); // Create OBSelector @@ -1584,6 +1586,13 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) LightApp_Preferences::Color, "SUPERVGraph", "Title" ); // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup, // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" ); + + int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat ); + int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab ); + pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool, + "ObjectBrowser", "auto_size_first" ); + pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool, + "ObjectBrowser", "auto_size" ); } /*!Changed preferences */ @@ -1646,15 +1655,16 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString if( sec=="ObjectBrowser" ) { - if( param=="auto_size" ) + if( param=="auto_size" || param=="auto_size_first" ) { OB_Browser* ob = objectBrowser(); if( !ob ) return; - bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ), + autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true ); ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); - + ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual ); updateObjectBrowser( false ); } } diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index eb18204a2..b569c87ac 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -138,6 +138,9 @@ msgstr "Font" msgid "LightApp_Application::PREF_TAB_OBJBROWSER" msgstr "Object browser" +msgid "LightApp_Application::PREF_OBJ_BROWSER_SETTINGS" +msgstr "Object browser settings" + msgid "LightApp_Application::PREF_GROUP_DEF_COLUMNS" msgstr "Default columns" @@ -230,6 +233,12 @@ msgstr "Title color" msgid "LightApp_Application::PREF_SUPERV_CTRL_COLOR" msgstr "Ctrl color" +msgid "LightApp_Application::PREF_AUTO_SIZE" +msgstr "Auto size for other columns" + +msgid "LightApp_Application::PREF_AUTO_SIZE_FIRST" +msgstr "Auto size for first column" + //======================================================================================= msgid "LightApp_PreferencesDlg::CAPTION" diff --git a/src/ObjBrowser/OB_ListItem.cxx b/src/ObjBrowser/OB_ListItem.cxx index fb821308f..b2ced5c7b 100755 --- a/src/ObjBrowser/OB_ListItem.cxx +++ b/src/ObjBrowser/OB_ListItem.cxx @@ -192,6 +192,17 @@ int OB_ListItem::rtti() const return RTTI(); } +void OB_ListItem::setText( int column, const QString& text ) +{ + QListViewItem::setText( column, text ); + QFontMetrics fm = listView()->fontMetrics(); + int necessary = width( fm, listView(), column ), + current = listView()->columnWidth( column ); + + if( listView()->columnWidthMode( column )==QListView::Maximum && necessary>current ) + listView()->setColumnWidth( column, necessary ); +} + /*! Class: OB_CheckListItem Descr: Check list view item for OB_Browser. diff --git a/src/ObjBrowser/OB_ListItem.h b/src/ObjBrowser/OB_ListItem.h index 071ec308a..6b06cd842 100755 --- a/src/ObjBrowser/OB_ListItem.h +++ b/src/ObjBrowser/OB_ListItem.h @@ -75,6 +75,7 @@ public: virtual void paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r ); virtual void paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align ); + virtual void setText ( int column, const QString & text ); virtual int rtti() const; diff --git a/src/ObjBrowser/OB_ListView.cxx b/src/ObjBrowser/OB_ListView.cxx index 70a9ca635..5f3894120 100755 --- a/src/ObjBrowser/OB_ListView.cxx +++ b/src/ObjBrowser/OB_ListView.cxx @@ -162,3 +162,39 @@ bool OB_ListView::isDropAccepted( QListViewItem* drag, QListViewItem* drop ) con return dropObj->isDropAccepted( dragObj ); } + +void OB_ListView::setColumnWidth( int col, int width ) +{ + int max = columnMaxWidth( col ); + if( max>0 && width>max ) + width = max; + QListView::setColumnWidth( col, width ); +} + +int OB_ListView::columnMaxWidth( const int col ) const +{ + int res = -1; + if( myMaxColWidth.contains( col ) ) + res = myMaxColWidth[col]; + else if( myMaxColRatio[col] ) + res = int( myMaxColRatio[col]*height() ); + return res; +} + +void OB_ListView::setColumnMaxWidth( const int col, const int w ) +{ + myMaxColWidth.insert( col, w ); +} + +double OB_ListView::columnMaxRatio( const int col ) const +{ + double res = 0.0; + if( myMaxColRatio.contains( col ) ) + res = myMaxColRatio[col]; + return res; +} + +void OB_ListView::setColumnMaxRatio( const int col, const double r ) +{ + myMaxColRatio.insert( col, r ); +} diff --git a/src/ObjBrowser/OB_ListView.h b/src/ObjBrowser/OB_ListView.h index 5c9feb5d1..03a394c21 100755 --- a/src/ObjBrowser/OB_ListView.h +++ b/src/ObjBrowser/OB_ListView.h @@ -47,6 +47,11 @@ public: void setFilter( OB_Filter* ); bool isOk( QListViewItem* ) const; + virtual void setColumnWidth( int, int ); + int columnMaxWidth( const int ) const; + void setColumnMaxWidth( const int, const int ); + double columnMaxRatio( const int ) const; + void setColumnMaxRatio( const int, const double ); signals: void dropped( QPtrList, QListViewItem*, int ); @@ -69,6 +74,8 @@ private: protected: QPtrList myItems; OB_Filter* myFilter; + QMap myMaxColWidth; + QMap myMaxColRatio; }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index f1477565a..a73131d02 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -557,7 +557,8 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) { OB_Browser* ob = (OB_Browser*)wid; connect( ob->listView(), SIGNAL( doubleClicked( QListViewItem* ) ), this, SLOT( onDblClick( QListViewItem* ) ) ); - bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ), + autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true ); for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ ) { ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i ); @@ -565,6 +566,8 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) QString().sprintf( "visibility_column_%d", i ), true ) ); } ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); + ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual ); + ob->resize( desktop()->width()/3, ob->height() ); } else if ( flag == WT_PyConsole ) { @@ -573,6 +576,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() ); pyCons->setCaption( tr( "PYTHON_CONSOLE" ) ); wid = pyCons; + pyCons->resize( pyCons->width(), desktop()->height()/4 ); // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } return wid; @@ -595,9 +599,6 @@ void SalomeApp_Application::createPreferences( LightApp_Preferences* pref ) LightApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) ); } pref->setItemProperty( defCols, "columns", 1 ); - - int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab ); - pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool, "ObjectBrowser", "auto_size" ); } /*!Update desktop title.*/ diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index f4a1acd58..7f28000b8 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -89,7 +89,8 @@
- + + diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.po b/src/SalomeApp/resources/SalomeApp_msg_en.po index ef835c709..63a7477fa 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.po +++ b/src/SalomeApp/resources/SalomeApp_msg_en.po @@ -99,8 +99,8 @@ msgstr "Object browser" msgid "SalomeApp_Application::MEN_OPENWITH" msgstr "Activate Module" -msgid "SalomeApp_Application::MEN_DELETE_REFERENCE" -msgstr "Delete Reference" +msgid "SalomeApp_Application::MEN_DELETE_INVALID_REFERENCE" +msgstr "Delete Invalid Reference" //======================================================================================= @@ -118,9 +118,6 @@ msgstr "Default columns" msgid "SalomeApp_Application::PREF_OBJ_BROWSER_SETTINGS" msgstr "Settings" -msgid "SalomeApp_Application::PREF_AUTO_SIZE" -msgstr "Auto size columns" - //======================================================================================= msgid "SalomeApp_Application::OBJ_BROWSER_NAME"