]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Improve QAD_FileDlg class: insert button to automatically add currently selected...
authorvsr <vsr@opencascade.com>
Wed, 2 Feb 2005 11:10:27 +0000 (11:10 +0000)
committervsr <vsr@opencascade.com>
Wed, 2 Feb 2005 11:10:27 +0000 (11:10 +0000)
src/SALOMEGUI/QAD_FileDlg.cxx
src/SALOMEGUI/QAD_FileDlg.h
src/SALOMEGUI/QAD_msg_en.po

index 40b24ef6f4368093ff071cd51cbad73def3f2ef6..3f35d228eb7950ce6e05b0bcbfed94df24aeb65d 100644 (file)
@@ -14,7 +14,6 @@
 #include <qlabel.h>
 #include <qobjectlist.h>
 #include <qpalette.h>
-#include <qpushbutton.h>
 #include <qregexp.h>
 #include "QAD_Config.h"
 #include "QAD_Desktop.h"   
@@ -42,39 +41,16 @@ myOpen( open )
 
   if (showQuickDir) {
     // inserting quick dir combo box
-    QLabel* lab  = new QLabel(tr("Quick path:"), this);
+    QLabel* lab  = new QLabel(tr("QUICK_PATH_LAB"), this);
     myQuickCombo = new QComboBox(false, this);
     myQuickCombo->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
     myQuickCombo->setMinimumSize(MIN_COMBO_SIZE, 0);
     
-    // the following is a workaround for proper layouting of custom widgets ===========
-    QPushButton* btn = new QPushButton(this);
-    btn->setEnabled(false);
-    QPalette pal = btn->palette();
-    QColorGroup ca = pal.active();
-    ca.setColor(QColorGroup::Light,    palette().active().background());
-    ca.setColor(QColorGroup::Midlight, palette().active().background());
-    ca.setColor(QColorGroup::Dark,     palette().active().background());
-    ca.setColor(QColorGroup::Mid,      palette().active().background());
-    ca.setColor(QColorGroup::Shadow,   palette().active().background());
-    QColorGroup ci = pal.inactive();
-    ci.setColor(QColorGroup::Light,    palette().inactive().background());
-    ci.setColor(QColorGroup::Midlight, palette().inactive().background());
-    ci.setColor(QColorGroup::Dark,     palette().inactive().background());
-    ci.setColor(QColorGroup::Mid,      palette().inactive().background());
-    ci.setColor(QColorGroup::Shadow,   palette().inactive().background());
-    QColorGroup cd = pal.disabled();
-    cd.setColor(QColorGroup::Light,    palette().disabled().background());
-    cd.setColor(QColorGroup::Midlight, palette().disabled().background());
-    cd.setColor(QColorGroup::Dark,     palette().disabled().background());
-    cd.setColor(QColorGroup::Mid,      palette().disabled().background());
-    cd.setColor(QColorGroup::Shadow,   palette().disabled().background());
-    pal.setActive(ca); pal.setInactive(ci); pal.setDisabled(cd);
-    btn->setPalette(pal);
-    // ================================================================================
+    myQuickButton = new QPushButton(tr("ADD_PATH_BTN"), this);
 
-    connect(myQuickCombo, SIGNAL(activated(const QString&)), this, SLOT(quickDir(const QString&)));
-    addWidgets(lab, myQuickCombo, btn);
+    connect(myQuickCombo,  SIGNAL(activated(const QString&)), this, SLOT(quickDir(const QString&)));
+    connect(myQuickButton, SIGNAL(clicked()),                 this, SLOT(addQuickDir()));
+    addWidgets(lab, myQuickCombo, myQuickButton);
 
     // getting dir list from settings
     QString dirs = QAD_CONFIG->getSetting("FileDlg:QuickDirList");
@@ -93,7 +69,7 @@ myOpen( open )
     const QObjectList *list = children();
     QObjectListIt it(*list);
     int maxButWidth = lab->sizeHint().width();
-    int maxLabWidth = btn->sizeHint().width();
+    int maxLabWidth = myQuickButton->sizeHint().width();
     
     for (; it.current() ; ++it) {
       if ( it.current()->isA( "QLabel" ) ) {
@@ -324,7 +300,41 @@ void QAD_FileDlg::quickDir(const QString& dirPath)
     processPath(dirPath);
   }
 }
-
+/*!
+  Called when user presses "Add" button - adds current directory to quick directory
+  list and to the preferences
+*/
+void QAD_FileDlg::addQuickDir()
+{
+  QString dp = dirPath();
+  if ( !dp.isEmpty() ) {
+    QDir dir( dp );
+    // getting dir list from settings
+    QString dirs = QAD_CONFIG->getSetting("FileDlg:QuickDirList");
+    QStringList dirList = QStringList::split(';', dirs, false);
+    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;
+       }
+      }
+    }
+    else {
+      emptyAndHome = dir.canonicalPath() == QDir(QDir::homeDirPath()).canonicalPath();
+    }
+    if ( !found ) {
+      dirList.append( dp );
+      QAD_CONFIG->addSetting("FileDlg:QuickDirList", dirList.join(";"));
+      if ( !emptyAndHome )
+       myQuickCombo->insertItem( dp );
+    }
+  }
+}
 /*!
   Returns the file name for Open/Save [ static ]
 */
index e7180753ef29d6fe167ee918450d7af1c45766cf..a234de43da0f1610d1ac394210c4a5cb5cb60d6a 100644 (file)
@@ -13,6 +13,7 @@
 #define QAD_FILEDIALOG_H
 
 #include <qcombobox.h>
+#include <qpushbutton.h>
 
 // VSR (18/01/2005): use patched QFileDialog only for the official 3.0.5 version of Qt
 #if QT_VERSION == 0x030005
@@ -68,13 +69,15 @@ protected slots:
     void               accept();        
     void               reject(); 
     void               quickDir(const QString&);
+    void               addQuickDir();
 
 protected:
-    bool               myOpen;             /* open/save selector  */      
-    QString            mySelectedFile;     /* selected filename   */    
-    QAD_FileValidator* myValidator;        /* file validator      */
-    static QString     myLastVisitedPath;  /* last visited path   */
-    QComboBox*         myQuickCombo;       /* quick dir combo box */
+    bool               myOpen;             /* open/save selector   */      
+    QString            mySelectedFile;     /* selected filename    */    
+    QAD_FileValidator* myValidator;        /* file validator       */
+    static QString     myLastVisitedPath;  /* last visited path    */
+    QComboBox*         myQuickCombo;       /* quick dir combo box  */
+    QPushButton*       myQuickButton;      /* quick dir add button */
 };
 
 #endif
index 07e568038c3270cec2f52643ab4b78bee459ec65..feca9f9e5cc569ceaf3deb8a3772691fc2a877b0 100644 (file)
@@ -871,3 +871,9 @@ msgstr "Plot table"
 msgid "NEW_OBJECT"
 msgstr "New object"
  
+msgid "QUICK_PATH_LAB"
+msgstr "Quick path:"
+msgid "ADD_PATH_BTN"
+msgstr "Add"