From db097f5561a335c23b0f8ada564a730f5518c033 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 28 Mar 2003 01:21:42 +0000 Subject: [PATCH] Introduce a new paned dialog class and use it for prefs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6600 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 14 + src/frontends/qt2/Makefile.am | 1 + src/frontends/qt2/Makefile.dialogs | 1 + src/frontends/qt2/QPrefsDialog.C | 145 +++----- src/frontends/qt2/QPrefsDialog.h | 7 - src/frontends/qt2/panelstack.C | 119 ++++++ src/frontends/qt2/panelstack.h | 60 +++ src/frontends/qt2/ui/QPrefColorsModule.ui | 18 +- src/frontends/qt2/ui/QPrefConvertersModule.ui | 10 +- .../qt2/ui/QPrefFileformatsModule.ui | 10 +- src/frontends/qt2/ui/QPrefUIModule.ui | 341 +++++++++--------- src/frontends/qt2/ui/QPrefsDialogBase.ui | 108 +----- 12 files changed, 466 insertions(+), 368 deletions(-) create mode 100644 src/frontends/qt2/panelstack.C create mode 100644 src/frontends/qt2/panelstack.h diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index beb6473460..dfcfc79163 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,17 @@ +2003-03-28 John Levon + + * Makefile.am: + * Makefile.dialogs: + * moc/Makefile.am: + * panelstack.h: + * panelstack.C: add new class for handling paned dialogs + + * QPrefsDialog.h: + * QPrefsDialog.C: + * ui/QPrefsDialogBase.ui: use the above + + * ui/QPrefUIModule.ui: re-layout + 2003-03-27 John Levon * ui/QParagraphDialogBase.ui: fix dupe accelerator / group label diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 9e537ed5fc..abf5adcabb 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -67,6 +67,7 @@ libqt2_la_SOURCES = \ QtLyXView.h \ WorkAreaFactory.C \ lyx_gui.C \ + panelstack.h panelstack.C \ qcoloritem.h qcoloritem.C \ qfontexample.h qfontexample.C \ qfont_loader.h qfont_loader.C \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index a5621676a7..e5f366670c 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -69,6 +69,7 @@ MOCFILES = \ iconpalette.C iconpalette.h \ io_callback.C io_callback.h \ lengthcombo.C lengthcombo.h \ + panelstack.C panelstack.h \ QAboutDialog.C QAboutDialog.h \ QBibitemDialog.C QBibitemDialog.h \ QBibtexDialog.C QBibtexDialog.h \ diff --git a/src/frontends/qt2/QPrefsDialog.C b/src/frontends/qt2/QPrefsDialog.C index fe9c5fcafe..1c49d68180 100644 --- a/src/frontends/qt2/QPrefsDialog.C +++ b/src/frontends/qt2/QPrefsDialog.C @@ -38,9 +38,8 @@ #include "debug.h" #include "gettext.h" -#include +#include "panelstack.h" #include -#include #include #include #include @@ -53,7 +52,6 @@ #include "qcoloritem.h" #include "qfontexample.h" -using std::map; using std::endl; QPrefsDialog::QPrefsDialog(QPrefs * form) @@ -68,99 +66,48 @@ QPrefsDialog::QPrefsDialog(QPrefs * form) connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore())); - prefsLV->setSorting(-1); - - // OK, Qt is REALLY broken. We have to hard - // code the menu structure here. - - QListViewItem * lnf(new QListViewItem(prefsLV, qt_("Look and feel"))); - lnf->setSelectable(false); - lnf->setOpen(true); - QListViewItem * lan(new QListViewItem(prefsLV, lnf, qt_("Language settings"))); - lan->setSelectable(false); - QListViewItem * out(new QListViewItem(prefsLV, lan, qt_("Outputs"))); - out->setSelectable(false); - - asciiModule = new QPrefAsciiModule(prefsWS); - dateModule = new QPrefDateModule(prefsWS); - keyboardModule = new QPrefKeyboardModule(prefsWS); - latexModule = new QPrefLatexModule(prefsWS); - screenfontsModule = new QPrefScreenFontsModule(prefsWS); - colorsModule = new QPrefColorsModule(prefsWS); - displayModule = new QPrefDisplayModule(prefsWS); - pathsModule = new QPrefPathsModule(prefsWS); - spellcheckerModule = new QPrefSpellcheckerModule(prefsWS); - convertersModule = new QPrefConvertersModule(prefsWS); - fileformatsModule = new QPrefFileformatsModule(prefsWS); - languageModule = new QPrefLanguageModule(prefsWS); - printerModule = new QPrefPrinterModule(prefsWS); - uiModule = new QPrefUIModule(prefsWS); - identityModule = new QPrefIdentityModule(prefsWS); - - prefsWS->addWidget(asciiModule, 0); - prefsWS->addWidget(dateModule, 1); - prefsWS->addWidget(keyboardModule, 2); - prefsWS->addWidget(latexModule, 3); - prefsWS->addWidget(screenfontsModule, 4); - prefsWS->addWidget(colorsModule, 5); - prefsWS->addWidget(displayModule, 6); - prefsWS->addWidget(pathsModule, 7); - prefsWS->addWidget(spellcheckerModule, 8); - prefsWS->addWidget(convertersModule, 9); - prefsWS->addWidget(fileformatsModule, 10); - prefsWS->addWidget(languageModule, 11); - prefsWS->addWidget(printerModule, 12); - prefsWS->addWidget(uiModule, 13); - prefsWS->addWidget(identityModule, 14); - - QListViewItem * i; - - // language settings - - i = new QListViewItem(lan, qt_("Language")); - pane_map_[i] = languageModule; - i = new QListViewItem(lan, i, qt_("Spellchecker")); - pane_map_[i] = spellcheckerModule; - - // UI - - i = new QListViewItem(lnf, qt_("User interface")); - pane_map_[i] = uiModule; - prefsLV->setCurrentItem(i); - - i = new QListViewItem(lnf, i, qt_("Screen fonts")); - pane_map_[i] = screenfontsModule; - i = new QListViewItem(lnf, i, qt_("Colors")); - pane_map_[i] = colorsModule; - i = new QListViewItem(lnf, i, qt_("Graphics")); - pane_map_[i] = displayModule; - i = new QListViewItem(lnf, i, qt_("Keyboard")); - pane_map_[i] = keyboardModule; - - // output - - i = new QListViewItem(out, qt_("ASCII")); - pane_map_[i] = asciiModule; - i = new QListViewItem(out, i, qt_("Date format")); - pane_map_[i] = dateModule; - i = new QListViewItem(out, i, qt_("LaTeX")); - pane_map_[i] = latexModule; - i = new QListViewItem(out, i, qt_("Printer")); - pane_map_[i] = printerModule; - - i = new QListViewItem(prefsLV, out, qt_("Identity")); - pane_map_[i] = identityModule; - i = new QListViewItem(prefsLV, out, qt_("Paths")); - pane_map_[i] = pathsModule; - i = new QListViewItem(prefsLV, i, qt_("Converters")); - pane_map_[i] = convertersModule; - i = new QListViewItem(prefsLV, i, qt_("File formats")); - pane_map_[i] = fileformatsModule; - - prefsLV->setMinimumSize(prefsLV->sizeHint()); - - // Qt sucks - resize(minimumSize()); + asciiModule = new QPrefAsciiModule(this); + dateModule = new QPrefDateModule(this); + keyboardModule = new QPrefKeyboardModule(this); + latexModule = new QPrefLatexModule(this); + screenfontsModule = new QPrefScreenFontsModule(this); + colorsModule = new QPrefColorsModule(this); + displayModule = new QPrefDisplayModule(this); + pathsModule = new QPrefPathsModule(this); + spellcheckerModule = new QPrefSpellcheckerModule(this); + convertersModule = new QPrefConvertersModule(this); + fileformatsModule = new QPrefFileformatsModule(this); + languageModule = new QPrefLanguageModule(this); + printerModule = new QPrefPrinterModule(this); + uiModule = new QPrefUIModule(this); + identityModule = new QPrefIdentityModule(this); + + string const laf = _("Look and feel"); + prefsPS->addCategory(laf); + prefsPS->addPanel(uiModule, _("User interface"), laf); + prefsPS->addPanel(screenfontsModule, _("Screen fonts"), laf); + prefsPS->addPanel(colorsModule, _("Colors"), laf); + prefsPS->addPanel(displayModule, _("Graphics"), laf); + prefsPS->addPanel(keyboardModule, _("Keyboard"), laf); + + string const ls = _("Language settings"); + prefsPS->addCategory(ls); + prefsPS->addPanel(languageModule, _("Language"), ls); + prefsPS->addPanel(spellcheckerModule, _("Spell-checker"), ls); + + string const op = _("Outputs"); + prefsPS->addCategory(op); + prefsPS->addPanel(asciiModule, _("ASCII"), op); + prefsPS->addPanel(dateModule, _("Date format"), op); + prefsPS->addPanel(latexModule, _("LaTeX"), op); + prefsPS->addPanel(printerModule, _("Printer"), op); + + prefsPS->addPanel(identityModule, _("Identity")); + prefsPS->addPanel(pathsModule, _("Paths")); + prefsPS->addPanel(fileformatsModule, _("File formats")); + prefsPS->addPanel(convertersModule, _("Converters")); + + prefsPS->setCurrentPanel(_("User interface")); // FIXME: put in controller for (int i = 0; i < LColor::ignore; ++i) { @@ -326,12 +273,6 @@ void QPrefsDialog::closeEvent(QCloseEvent * e) } -void QPrefsDialog::switchPane(QListViewItem * i) -{ - prefsWS->raiseWidget(pane_map_[i]); -} - - void QPrefsDialog::change_adaptor() { form_->changed(); diff --git a/src/frontends/qt2/QPrefsDialog.h b/src/frontends/qt2/QPrefsDialog.h index 8bc9e9669a..fc56e2b723 100644 --- a/src/frontends/qt2/QPrefsDialog.h +++ b/src/frontends/qt2/QPrefsDialog.h @@ -17,11 +17,9 @@ #include "ui/QPrefsDialogBase.h" -#include #include class QPrefs; -class QListViewItem; class QPrefAsciiModule; class QPrefDateModule; class QPrefKeyboardModule; @@ -52,8 +50,6 @@ public: void updateFormats(); public slots: - virtual void switchPane(QListViewItem * i); - void change_adaptor(); void switch_format(int); @@ -87,9 +83,6 @@ protected: void closeEvent(QCloseEvent * e); private: - typedef std::map PaneMap; - - PaneMap pane_map_; std::vector colors_; diff --git a/src/frontends/qt2/panelstack.C b/src/frontends/qt2/panelstack.C new file mode 100644 index 0000000000..112a41db94 --- /dev/null +++ b/src/frontends/qt2/panelstack.C @@ -0,0 +1,119 @@ +/** + * \file panelstack.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS + */ + +#include "panelstack.h" + +#include "support/LAssert.h" + +#include "qt_helpers.h" + +#include +#include +#include + +using std::map; + + +PanelStack::PanelStack(QWidget * parent, const char * name) + : QWidget(parent, name) +{ + list_ = new QListView(this); + stack_ = new QWidgetStack(this); + list_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + stack_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); + + list_->setSorting(-1); + list_->setHScrollBarMode(QScrollView::AlwaysOff); + list_->setVScrollBarMode(QScrollView::AlwaysOff); + list_->addColumn(""); + list_->setColumnWidthMode(0, QListView::Maximum); + list_->setResizeMode(QListView::AllColumns); + list_->setRootIsDecorated(true); + + connect(list_, SIGNAL(currentChanged(QListViewItem*)), + this, SLOT(switchPanel(QListViewItem *))); + + QHBoxLayout * layout = new QHBoxLayout(this); + layout->addWidget(list_, 0); + layout->addWidget(stack_, 1); +} + + +void PanelStack::addCategory(string const & n, string const & parent) +{ + QListViewItem * item; + + QString name = toqstr(n); + + if (!parent.empty()) { + PanelMap::iterator it = panel_map_.find(parent); + lyx::Assert(it != panel_map_.end()); + + QListViewItem * before = it->second->firstChild(); + if (before) { + while (before->nextSibling()) + before = before->nextSibling(); + + item = new QListViewItem(it->second, before, name); + } else { + item = new QListViewItem(it->second, name); + } + } else { + QListViewItem * before = list_->firstChild(); + if (before) { + while (before->nextSibling()) + before = before->nextSibling(); + item = new QListViewItem(list_, before, name); + } else { + item = new QListViewItem(list_, name); + } + } + + item->setSelectable(false); + item->setOpen(true); + panel_map_[n] = item; + + // Qt is just unbelievably moronic + list_->setMinimumSize(QSize(150, list_->minimumHeight())); +} + + +void PanelStack::addPanel(QWidget * panel, string const & name, string const & parent) +{ + addCategory(name, parent); + QListViewItem * item = panel_map_.find(name)->second; + + // reset the selectability set by addCategory + item->setSelectable(true); + + widget_map_[item] = panel; + stack_->addWidget(panel); + stack_->setMinimumSize(panel->minimumSize()); + resize(sizeHint()); +} + + +void PanelStack::setCurrentPanel(string const & name) +{ + PanelMap::const_iterator cit = panel_map_.find(name); + lyx::Assert(cit != panel_map_.end()); + + switchPanel(cit->second); +} + + +void PanelStack::switchPanel(QListViewItem * item) +{ + WidgetMap::const_iterator cit = widget_map_.find(item); + if (cit == widget_map_.end()) + return; + + stack_->raiseWidget(cit->second); +} diff --git a/src/frontends/qt2/panelstack.h b/src/frontends/qt2/panelstack.h new file mode 100644 index 0000000000..d7473ddec6 --- /dev/null +++ b/src/frontends/qt2/panelstack.h @@ -0,0 +1,60 @@ +// -*- C++ -*- +/** + * \file panelstack.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS + */ +#ifndef PANELSTACK_H +#define PANELSTACK_H + +#include +#include "LString.h" + +#include + +#include + +class QListView; +class QListViewItem; +class QWidgetStack; + +class PanelStack : public QWidget +{ + Q_OBJECT +public: + PanelStack(QWidget * parent = 0, const char * name = "panelstack"); + + /// add a category with no associated panel + void addCategory(string const & name, string const & parent = string()); + + /// add a widget panel with a given name, under the given parent + void addPanel(QWidget * panel, string const & name, string const & parent = string()); + + /// set current panel by logical name + void setCurrentPanel(string const &); + +public slots: + /// set current panel from an item + void switchPanel(QListViewItem * i); + +private: + typedef std::map PanelMap; + + PanelMap panel_map_; + + typedef std::map WidgetMap; + + WidgetMap widget_map_; + + /// contains the items + QListView * list_; + + /// contains the panes + QWidgetStack * stack_; +}; + +#endif // PANELSTACK_H diff --git a/src/frontends/qt2/ui/QPrefColorsModule.ui b/src/frontends/qt2/ui/QPrefColorsModule.ui index a550d3217c..a92cadc6c9 100644 --- a/src/frontends/qt2/ui/QPrefColorsModule.ui +++ b/src/frontends/qt2/ui/QPrefColorsModule.ui @@ -13,7 +13,7 @@ 0 0 - 297 + 289 259 @@ -66,6 +66,22 @@ name lyxObjectsLB + + resizePolicy + AutoOneFit + + + vScrollBarMode + AlwaysOn + + + hScrollBarMode + AlwaysOff + + + columnMode + FitToHeight + QLayoutWidget diff --git a/src/frontends/qt2/ui/QPrefConvertersModule.ui b/src/frontends/qt2/ui/QPrefConvertersModule.ui index 341edcd3a2..42b05e0809 100644 --- a/src/frontends/qt2/ui/QPrefConvertersModule.ui +++ b/src/frontends/qt2/ui/QPrefConvertersModule.ui @@ -13,7 +13,7 @@ 0 0 - 354 + 384 261 @@ -94,6 +94,14 @@ 7 + + vScrollBarMode + AlwaysOn + + + hScrollBarMode + AlwaysOff + QPushButton diff --git a/src/frontends/qt2/ui/QPrefFileformatsModule.ui b/src/frontends/qt2/ui/QPrefFileformatsModule.ui index 08526caa31..2f45ff9574 100644 --- a/src/frontends/qt2/ui/QPrefFileformatsModule.ui +++ b/src/frontends/qt2/ui/QPrefFileformatsModule.ui @@ -13,7 +13,7 @@ 0 0 - 360 + 356 261 @@ -98,6 +98,14 @@ name formatsLB + + vScrollBarMode + AlwaysOn + + + hScrollBarMode + AlwaysOff + QPushButton diff --git a/src/frontends/qt2/ui/QPrefUIModule.ui b/src/frontends/qt2/ui/QPrefUIModule.ui index 526ea9c41d..73813e524b 100644 --- a/src/frontends/qt2/ui/QPrefUIModule.ui +++ b/src/frontends/qt2/ui/QPrefUIModule.ui @@ -13,8 +13,8 @@ 0 0 - 477 - 341 + 273 + 366 @@ -117,7 +117,7 @@ QLayoutWidget name - Layout16 + Layout7 @@ -129,231 +129,248 @@ 6 - QGroupBox + QLayoutWidget name - scrollGB - - - title - Scrolling - - - - margin - 11 - - - spacing - 6 - - - QLayoutWidget - - name - Layout9 - - - - margin - 0 - - - spacing - 6 - - - QLabel - - name - wheelMouseLA - - - text - W&heel mouse scroll: - - - buddy - wheelMouseSB - - - - QSpinBox - - name - wheelMouseSB - - - maxValue - 250 - - - - - - QCheckBox - - name - cursorFollowsCB - - - text - Cursor follo&ws scrollbar - - - - - - QGroupBox - - name - documentsGB - - - title - Documents + Layout6 margin - 11 + 0 spacing 6 - QCheckBox + QGroupBox name - autoSaveCB - - - text - B&ackup documents + documentsGB - - - QLayoutWidget - name - Layout11 + title + Documents - + margin - 0 + 11 spacing 6 - - - name - Spacer6 - - - orientation - Horizontal - - - sizeType - Fixed - - - sizeHint - - 21 - 20 - - - - QLabel + QCheckBox name - autoSaveLA + autoSaveCB text - every - - - buddy - autoSaveSB + B&ackup documents - QSpinBox + QLayoutWidget name - autoSaveSB - - - maxValue - 300 - - - minValue - 1 + Layout11 + + + margin + 0 + + + spacing + 6 + + + + name + Spacer6 + + + orientation + Horizontal + + + sizeType + Fixed + + + sizeHint + + 21 + 20 + + + + + QLabel + + name + autoSaveLA + + + text + every + + + buddy + autoSaveSB + + + + QSpinBox + + name + autoSaveSB + + + maxValue + 300 + + + minValue + 1 + + + + QLabel + + name + TextLabel1 + + + text + minutes + + + - QLabel + QLayoutWidget name - TextLabel1 - - - text - minutes + Layout12 + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + lastfilesLA + + + text + &Maximum last files: + + + buddy + lastfilesSB + + + + QSpinBox + + name + lastfilesSB + + + maxValue + 9 + + + - + - QLayoutWidget + QGroupBox name - Layout12 + scrollGB + + + title + Scrolling - + margin - 0 + 11 spacing 6 - QLabel + QLayoutWidget name - lastfilesLA - - - text - &Maximum last files: - - - buddy - lastfilesSB + Layout9 + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + wheelMouseLA + + + text + W&heel mouse scroll: + + + buddy + wheelMouseSB + + + + QSpinBox + + name + wheelMouseSB + + + maxValue + 250 + + + - QSpinBox + QCheckBox name - lastfilesSB + cursorFollowsCB - maxValue - 9 + text + Cursor follo&ws scrollbar - + diff --git a/src/frontends/qt2/ui/QPrefsDialogBase.ui b/src/frontends/qt2/ui/QPrefsDialogBase.ui index 4d374e8f50..a5ce0acb73 100644 --- a/src/frontends/qt2/ui/QPrefsDialogBase.ui +++ b/src/frontends/qt2/ui/QPrefsDialogBase.ui @@ -13,7 +13,7 @@ 0 0 - 449 + 437 352 @@ -32,7 +32,7 @@ sizeGripEnabled true - + margin 11 @@ -41,7 +41,14 @@ spacing 6 - + + PanelStack + + name + prefsPS + + + QLayoutWidget name @@ -139,101 +146,22 @@ - - QLayoutWidget - - name - Layout3 - - - - margin - 0 - - - spacing - 6 - - - QWidgetStack - - name - prefsWS - - - sizePolicy - - 7 - 7 - - - - - - - QListView - - - text - Preferences - - - clickable - false - - - resizeable - false - - - - name - prefsLV - - - sizePolicy - - 5 - 5 - - - - minimumSize - - 100 - 0 - - - - dragAutoScroll - true - - - itemMargin - 1 - - - rootIsDecorated - true - - - + - QWidgetStack -
qwidgetstack.h
+ PanelStack +
panelstack.h
-1 -1 - 0 + 1 7 7 image0 - raiseWidget(int)
@@ -243,20 +171,12 @@ - - prefsLV - currentChanged(QListViewItem*) - QPrefsDialogBase - switchPane(QListViewItem *) - change_adaptor() defaultClicked() - switchPane(QListViewItem *) saveClicked() setTitle(int) - prefsLV restorePB savePB applyPB -- 2.39.5