]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrefs.cpp
* For gcc to know about QStandardItemModel < QAbstractItemModel we need this header.
[lyx.git] / src / frontends / qt4 / GuiPrefs.cpp
index 6f9d8d07e680251ac284571604555faef54b5589..d58c26d23259e3002cc707dce506a35d3fb278c6 100644 (file)
 
 #include "GuiPrefs.h"
 
-#include "qt_helpers.h"
+#include "FileDialog.h"
 #include "GuiApplication.h"
+#include "GuiFontExample.h"
 #include "GuiFontLoader.h"
+#include "GuiKeySymbol.h"
+#include "qt_helpers.h"
 
 #include "BufferList.h"
 #include "Color.h"
 #include "ConverterCache.h"
-#include "FileDialog.h"
 #include "FuncRequest.h"
-#include "GuiFontExample.h"
-#include "GuiKeySymbol.h"
 #include "KeyMap.h"
 #include "KeySequence.h"
+#include "Language.h"
 #include "LyXAction.h"
 #include "PanelStack.h"
 #include "paper.h"
@@ -53,6 +54,7 @@
 #include <QPixmapCache>
 #include <QPushButton>
 #include <QSpinBox>
+#include <QStandardItemModel.h>
 #include <QString>
 #include <QTreeWidget>
 #include <QTreeWidgetItem>
@@ -186,8 +188,7 @@ QString browseRelFile(QString const & filename, QString const & refpath,
        QString const & label1, QString const & dir1,
        QString const & label2, QString const & dir2)
 {
-       QString const fname = toqstr(makeAbsPath(
-               fromqstr(filename), fromqstr(refpath)).absFilename());
+       QString const fname = makeAbsPath(filename, refpath);
 
 
        QString const outname =
@@ -218,15 +219,6 @@ string const catLanguage = N_("Language Settings");
 string const catOutput = N_("Output");
 string const catFiles = N_("File Handling");
 
-static int findPos_helper(QStringList const & vec, QString const & val)
-{
-       for (int i = 0; i != vec.size(); ++i)
-               if (vec[i] == val)
-                       return i;
-       return 0;
-}
-
-
 static void parseFontName(QString const & mangled0,
        string & name, string & foundry)
 {
@@ -1659,13 +1651,7 @@ PrefLanguage::PrefLanguage(QWidget * parent)
 
        defaultLanguageCO->clear();
 
-       // store the lang identifiers for later
-       //foreach (LanguagePair const & lpair, languageData(false)) {
-       QList<LanguagePair> l = languageData(false);
-       foreach (LanguagePair const & lpair, l) {
-               defaultLanguageCO->addItem(lpair.first);
-               lang_.append(lpair.second);
-       }
+       defaultLanguageCO->setModel(guiApp->languageModel());
 }
 
 
@@ -1682,7 +1668,8 @@ void PrefLanguage::apply(LyXRC & rc) const
        rc.language_package = fromqstr(languagePackageED->text());
        rc.language_command_begin = fromqstr(startCommandED->text());
        rc.language_command_end = fromqstr(endCommandED->text());
-       rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
+       rc.default_language = fromqstr(
+               defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
 }
 
 
@@ -1703,7 +1690,7 @@ void PrefLanguage::update(LyXRC const & rc)
        startCommandED->setText(toqstr(rc.language_command_begin));
        endCommandED->setText(toqstr(rc.language_command_end));
 
-       int const pos = findPos_helper(lang_, toqstr(rc.default_language));
+       int const pos = defaultLanguageCO->findData(toqstr(rc.default_language));
        defaultLanguageCO->setCurrentIndex(pos);
 }
 
@@ -1973,7 +1960,6 @@ PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
        shortcutsTW->setSortingEnabled(true);
        // Multi-selection can be annoying.
        // shortcutsTW->setSelectionMode(QAbstractItemView::MultiSelection);
-       shortcutsTW->header()->resizeSection(0, 200);
 
        connect(bindFilePB, SIGNAL(clicked()),
                this, SLOT(select_bind()));
@@ -2054,7 +2040,7 @@ void PrefShortcuts::updateShortcutsTW()
        mathItem_->setFlags(mathItem_->flags() & ~Qt::ItemIsSelectable);
        
        bufferItem_ = new QTreeWidgetItem(shortcutsTW);
-       bufferItem_->setText(0, qt_("Buffer and Window"));
+       bufferItem_->setText(0, qt_("Document and Window"));
        bufferItem_->setFlags(bufferItem_->flags() & ~Qt::ItemIsSelectable);
        
        layoutItem_ = new QTreeWidgetItem(shortcutsTW);
@@ -2086,6 +2072,9 @@ void PrefShortcuts::updateShortcutsTW()
        shortcutsTW->sortItems(0, Qt::AscendingOrder);
        QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
        removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
+       modifyPB->setEnabled(!items.isEmpty());
+
+       shortcutsTW->resizeColumnToContents(0);
 }
 
 
@@ -2179,6 +2168,7 @@ void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
 {
        QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
        removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
+       modifyPB->setEnabled(!items.isEmpty());
        if (items.isEmpty())
                return;
        
@@ -2191,13 +2181,17 @@ void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
 
 
 void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
+{
+       modifyShortcut();
+}
+
+
+void PrefShortcuts::modifyShortcut()
 {
        QTreeWidgetItem * item = shortcutsTW->currentItem();
        if (item->flags() & Qt::ItemIsSelectable) {
                shortcut_->lfunLE->setText(item->text(0));
-               // clear the shortcut because I assume that a user will enter
-               // a new shortcut.
-               shortcut_->shortcutLE->reset();
+               shortcut_->shortcutLE->setText(item->text(1));
                shortcut_->shortcutLE->setFocus();
                shortcut_->exec();
        }
@@ -2216,6 +2210,12 @@ void PrefShortcuts::select_bind()
 }
 
 
+void PrefShortcuts::on_modifyPB_pressed()
+{
+       modifyShortcut();
+}
+
+
 void PrefShortcuts::on_newPB_pressed()
 {
        shortcut_->lfunLE->clear();