From: Jürgen Spitzmüller Date: Thu, 23 Oct 2003 11:58:01 +0000 (+0000) Subject: qt branch support X-Git-Tag: 1.6.10~15905 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=838ec5d98619869a2d51dfdb8db878a7cab3f465;p=lyx.git qt branch support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7964 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/po/POTFILES.in b/po/POTFILES.in index ebefd26770..8954f6fa14 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -46,6 +46,7 @@ src/frontends/qt2/QAbout.C src/frontends/qt2/QBibitem.C src/frontends/qt2/QBibtex.C src/frontends/qt2/QBibtexDialog.C +src/frontends/qt2/QBranch.C src/frontends/qt2/QChanges.C src/frontends/qt2/QCharacter.C src/frontends/qt2/QCitation.C diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0e2039ab5c..9fe08aba1f 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,16 @@ +2003-10-23 Juergen Spitzmueller + + * Dialogs.C: + * Makefile.am: + * Makefile.dialogs: + * QDocument.[Ch]: + * QDocumentDialog.[Ch]: Add qt gui for branches + + * QBranch.[Ch]: + * QBranchDialog.[Ch]: + * ui/BranchesModuleBase.ui: + * ui/QBranchModuleBase.ui: new files (qt gui for branches). + 2003-10-22 Angus Leeming * QExternal.C: diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index a93d3f104b..d44e9ee538 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -14,6 +14,7 @@ #include "ControlAboutlyx.h" #include "ControlBibtex.h" +#include "ControlBranch.h" #include "ControlChanges.h" #include "ControlCharacter.h" #include "ControlCitation.h" @@ -41,6 +42,7 @@ #include "QAbout.h" #include "QBibitem.h" #include "QBibtex.h" +#include "QBranch.h" #include "QChanges.h" #include "QCharacter.h" #include "QCitation.h" @@ -82,8 +84,8 @@ using std::string; namespace { -char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "changes", -"character", "citation", "error", "errorlist", "ert", "external", "file", +char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", +"changes", "character", "citation", "error", "errorlist", "ert", "external", "file", "float", "graphics", "include", "index", "label", "latexlog", "mathpanel", "mathdelimiter", "mathmatrix", "minipage", "note", "paragraph", "ref", "tabular", "tabularcreate", "texinfo", @@ -137,6 +139,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlBibtex(*dialog)); dialog->setView(new QBibtex(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); + } else if (name == "branch") { + dialog->setController(new ControlBranch(*dialog)); + dialog->setView(new QBranch(*dialog)); + dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "changes") { dialog->setController(new ControlChanges(*dialog)); dialog->setView(new QChanges(*dialog)); diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 40772237db..09c8d11eab 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -30,6 +30,7 @@ libqt2_la_SOURCES = \ QAbout.C QAbout.h \ QBibitem.C QBibitem.h \ QBibtex.C QBibtex.h \ + QBranch.C QBranch.h \ QChanges.C QChanges.h \ QCharacter.C QCharacter.h \ QCitation.C QCitation.h \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index 07139f2253..59961374dd 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -2,6 +2,7 @@ UIFILES = \ BiblioModuleBase.ui \ + BranchesModuleBase.ui \ BulletsModuleBase.ui \ TextLayoutModuleBase.ui \ LanguageModuleBase.ui \ @@ -16,6 +17,7 @@ UIFILES = \ QBibitemDialogBase.ui \ QBibtexDialogBase.ui \ QBibtexAddDialogBase.ui \ + QBranchDialogBase.ui \ QChangesDialogBase.ui \ QCharacterDialogBase.ui \ QCitationDialogBase.ui \ @@ -78,6 +80,7 @@ MOCFILES = \ QAboutDialog.C QAboutDialog.h \ QBibitemDialog.C QBibitemDialog.h \ QBibtexDialog.C QBibtexDialog.h \ + QBranchDialog.C QBranchDialog.h \ QBrowseBox.C QBrowseBox.h \ QChangesDialog.C QChangesDialog.h \ QCharacterDialog.C QCharacterDialog.h \ diff --git a/src/frontends/qt2/QBranch.C b/src/frontends/qt2/QBranch.C new file mode 100644 index 0000000000..f08532a0d5 --- /dev/null +++ b/src/frontends/qt2/QBranch.C @@ -0,0 +1,81 @@ +/** + * \file QBranch.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "debug.h" +#include "qt_helpers.h" +#include "ControlBranch.h" +#include "insets/insetbranch.h" +#include "support/lstrings.h" + +#include +#include + +#include "QBranchDialog.h" +#include "QBranch.h" +#include "Qt2BC.h" + +using lyx::support::getVectorFromString; + +using std::string; +using std::vector; + + +typedef QController > base_class; + + +QBranch::QBranch(Dialog & parent) + : base_class(parent, _("LyX: Branch Settings")) +{} + + +void QBranch::build_dialog() +{ + string all_branches(controller().params().branchlist.allBranches()); + + dialog_.reset(new QBranchDialog(this)); + + std::vector all = getVectorFromString(all_branches, "|"); + for (unsigned i = 0; i < all.size(); ++i) { + QString const bname = toqstr(all[i].c_str()); + dialog_->branchCO->insertItem(bname); + } + + bcview().setOK(dialog_->okPB); + bcview().setCancel(dialog_->closePB); +} + + +void QBranch::update_contents() +{ + // re-read branch list + dialog_->branchCO->clear(); + string all_branches(controller().params().branchlist.allBranches()); + string cur_branch(controller().params().branch); + unsigned int cur_item = 0; + std::vector all = getVectorFromString(all_branches, "|"); + for (unsigned i = 0; i < all.size(); ++i) { + QString const bname = toqstr(all[i].c_str()); + dialog_->branchCO->insertItem(bname); + if (bname == toqstr(cur_branch)) + cur_item = i; + } + // set to current item. A better idea anyone? + if (all_branches.find(cur_branch) != string::npos && cur_branch != "none") + dialog_->branchCO->setCurrentItem(cur_item); +} + + +void QBranch::apply() +{ + string const type = fromqstr(dialog_->branchCO->currentText()); + controller().params().branch = type; +} diff --git a/src/frontends/qt2/QBranch.h b/src/frontends/qt2/QBranch.h new file mode 100644 index 0000000000..8f9711f15a --- /dev/null +++ b/src/frontends/qt2/QBranch.h @@ -0,0 +1,39 @@ +// -*- C++ -*- +/** + * \file QBranch.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QBRANCH_H +#define QBRANCH_H + +#include "QDialogView.h" + + +class ControlBranch; +class QBranchDialog; + +/** This class provides a QT implementation of the Branch Dialog. + */ +class QBranch : public QController > +{ +public: + friend class QBranchDialog; + + /// Constructor + QBranch(Dialog &); +private: + /// Apply changes + virtual void apply(); + /// Build the dialog + virtual void build_dialog(); + /// Update dialog before showing it + virtual void update_contents(); +}; + +#endif // QBRANCH_H diff --git a/src/frontends/qt2/QBranchDialog.C b/src/frontends/qt2/QBranchDialog.C new file mode 100644 index 0000000000..b44b237c1f --- /dev/null +++ b/src/frontends/qt2/QBranchDialog.C @@ -0,0 +1,41 @@ +/** + * \file QBranchDialog.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#include + + +#include "QBranch.h" +#include "QBranchDialog.h" + +#include + + +QBranchDialog::QBranchDialog(QBranch * form) + : QBranchDialogBase(0, 0, false, 0), + form_(form) +{ + connect(okPB, SIGNAL(clicked()), + form, SLOT(slotOK())); + connect(closePB, SIGNAL(clicked()), + form, SLOT(slotClose())); +} + + +void QBranchDialog::closeEvent(QCloseEvent * e) +{ + form_->slotWMHide(); + e->accept(); +} + + +void QBranchDialog::change_adaptor() +{ + form_->changed(); +} diff --git a/src/frontends/qt2/QBranchDialog.h b/src/frontends/qt2/QBranchDialog.h new file mode 100644 index 0000000000..bbcea67b4a --- /dev/null +++ b/src/frontends/qt2/QBranchDialog.h @@ -0,0 +1,32 @@ +// -*- C++ -*- +/** + * \file QBranchDialog.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QBRANCHDIALOG_H +#define QBRANCHDIALOG_H + +#include "ui/QBranchDialogBase.h" + + +class QBranch; + +class QBranchDialog : public QBranchDialogBase { + Q_OBJECT +public: + QBranchDialog(QBranch * form); +protected slots: + virtual void change_adaptor(); +protected: + virtual void closeEvent(QCloseEvent * e); +private: + QBranch * form_; +}; + +#endif // QBRANCHDIALOG_H diff --git a/src/frontends/qt2/QDocument.C b/src/frontends/qt2/QDocument.C index e0da617cf1..bedc1f0ee3 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -621,6 +621,9 @@ void QDocument::update_contents() lengthToWidgets(m->footskipLE, m->footskipUnit, params.footskip, defaultUnit); + + // branches + dialog_->updateBranchView(); } diff --git a/src/frontends/qt2/QDocument.h b/src/frontends/qt2/QDocument.h index 608a20f24e..cbfc832482 100644 --- a/src/frontends/qt2/QDocument.h +++ b/src/frontends/qt2/QDocument.h @@ -17,6 +17,8 @@ #include "Qt2Base.h" #include "Qt2BC.h" +#include "BranchList.h" + #include #include @@ -51,6 +53,8 @@ private: /// FIXME std::vector lang_; + /// Contains all legal branches for this doc + BranchList branchlist_; }; #endif // QDOCUMENT_H diff --git a/src/frontends/qt2/QDocumentDialog.C b/src/frontends/qt2/QDocumentDialog.C index 0daec0fcb4..e0f0e82a96 100644 --- a/src/frontends/qt2/QDocumentDialog.C +++ b/src/frontends/qt2/QDocumentDialog.C @@ -19,6 +19,7 @@ #include "panelstack.h" #include "floatplacement.h" +#include "LColor.h" #include "support/lstrings.h" #include "bufferparams.h" @@ -32,10 +33,15 @@ #include #include #include +#include +#include +#include #include "lengthcombo.h" using lyx::support::token; +using lyx::support::getVectorFromString; +using std::vector; using std::string; @@ -61,6 +67,7 @@ QDocumentDialog::QDocumentDialog(QDocument * form) mathsModule = new MathsModuleBase(this); floatModule = new FloatPlacement(this, "floatplacement"); latexModule = new LaTeXModuleBase(this); + branchesModule = new BranchesModuleBase(this); preambleModule = new PreambleModuleBase(this); docPS->addPanel(latexModule, _("Document Class")); @@ -73,6 +80,7 @@ QDocumentDialog::QDocumentDialog(QDocument * form) docPS->addPanel(mathsModule, _("Math options")); docPS->addPanel(floatModule, _("Float Placement")); docPS->addPanel(bulletsModule, _("Bullets")); + docPS->addPanel(branchesModule, _("Branches")); docPS->addPanel(preambleModule, _("LaTeX Preamble")); docPS->setCurrentPanel(_("Document Class")); @@ -154,6 +162,13 @@ QDocumentDialog::QDocumentDialog(QDocument * form) // bullets connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor())); + + // branches + connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed())); + connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed())); + connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed())); + connect(branchesModule->colorPB, SIGNAL(pressed()), this, SLOT(toggleBranchColor())); + branchesModule->branchesLV->setSorting(0); } @@ -286,7 +301,6 @@ void QDocumentDialog::setCustomMargins(int margin) marginsModule->footskipL->setEnabled(custom); marginsModule->footskipLE->setEnabled(custom); marginsModule->footskipUnit->setEnabled(custom); - } @@ -404,3 +418,114 @@ void QDocumentDialog::updateNumbering() //numberingModule->tocLV->setUpdatesEnabled(true); //numberingModule->tocLV->update(); } + + +void QDocumentDialog::updateBranchView() +{ + ControlDocument & cntrl = form_->controller(); + BufferParams & params = cntrl.params(); + + string const all_branches = params.branchlist().allBranches(); + string const all_selected = params.branchlist().allSelected(); + branchesModule->branchesLV->clear(); + if (!all_branches.empty()) { + std::vector all = getVectorFromString(all_branches, "|"); + for (unsigned i = 0; i < all.size(); ++i) { + QString const bname = toqstr(all[i].c_str()); + QString const sel = + (params.branchlist().selected(fromqstr(bname))) ? qt_("Yes") : qt_("No"); + QColor itemcolor(white); + string x11hexname = params.branchlist().getColor(fromqstr(bname)); + if (x11hexname[0] == '#') + itemcolor.setNamedColor(toqstr(x11hexname)); + QPixmap coloritem(30, 10); + coloritem.fill(itemcolor); + QListViewItem * newItem = + new QListViewItem(branchesModule->branchesLV, bname, sel); + newItem->setPixmap(2, coloritem); + } + } + form_->changed(); +} + + +void QDocumentDialog::addBranchPressed() +{ + ControlDocument & cntrl = form_->controller(); + BufferParams & params = cntrl.params(); + + QString const new_branch = branchesModule->newBranchLE->text(); + if (!new_branch.isEmpty()) { + params.branchlist().add(fromqstr(new_branch)); + branchesModule->newBranchLE->clear(); + updateBranchView(); + } +} + + +void QDocumentDialog::deleteBranchPressed() +{ + ControlDocument & cntrl = form_->controller(); + BufferParams & params = cntrl.params(); + + QListViewItem * selItem = + branchesModule->branchesLV->selectedItem(); + QString sel_branch; + if (selItem != 0) + sel_branch = selItem->text(0); + if (sel_branch) { + params.branchlist().remove(fromqstr(sel_branch)); + branchesModule->newBranchLE->clear(); + updateBranchView(); + } +} + + +void QDocumentDialog::toggleBranchPressed() +{ + ControlDocument & cntrl = form_->controller(); + BufferParams & params = cntrl.params(); + + QListViewItem * selItem = + branchesModule->branchesLV->selectedItem(); + QString sel_branch; + if (selItem != 0) + sel_branch = selItem->text(0); + if (sel_branch) { + bool selected = false; + if (selItem->text(1) == qt_("Yes")) + selected = true; + params.branchlist().setSelected(fromqstr(sel_branch), !selected); + branchesModule->newBranchLE->clear(); + updateBranchView(); + } +} + + +void QDocumentDialog::toggleBranchColor() +{ + ControlDocument & cntrl = form_->controller(); + BufferParams & params = cntrl.params(); + + QListViewItem * selItem = + branchesModule->branchesLV->selectedItem(); + QString sel_branch; + if (selItem != 0) + sel_branch = selItem->text(0); + if (sel_branch) { + QColor initial; + string x11hexname = params.branchlist().getColor(fromqstr(sel_branch)); + if (x11hexname[0] == '#') + initial.setNamedColor(toqstr(x11hexname)); + QColor ncol(QColorDialog::getColor(initial)); + if (ncol.isValid()){ + // FIXME: The color does not apply unless buffer restart + // XForms has this hack. What can we do? + // lyxColorHandler->getGCForeground(c); + // lyxColorHandler->updateColor(c); + params.branchlist().setColor(fromqstr(sel_branch), fromqstr(ncol.name())); + branchesModule->newBranchLE->clear(); + updateBranchView(); + } + } +} diff --git a/src/frontends/qt2/QDocumentDialog.h b/src/frontends/qt2/QDocumentDialog.h index 7f92c6d5c1..1a80ee5a7c 100644 --- a/src/frontends/qt2/QDocumentDialog.h +++ b/src/frontends/qt2/QDocumentDialog.h @@ -26,6 +26,7 @@ #include "ui/NumberingModuleBase.h" #include "ui/MarginsModuleBase.h" #include "ui/PreambleModuleBase.h" +#include "ui/BranchesModuleBase.h" class QDocument; @@ -41,6 +42,7 @@ public: void updateFontsize(std::string const &, std::string const &); void updatePagestyle(std::string const &, std::string const &); + void updateBranchView(); void showPreamble(); @@ -59,6 +61,10 @@ protected slots: void enableSkip(bool); void portraitChanged(); void classChanged(); + void addBranchPressed(); + void deleteBranchPressed(); + void toggleBranchPressed(); + void toggleBranchColor(); protected: void closeEvent(QCloseEvent * e); @@ -75,6 +81,7 @@ private: LaTeXModuleBase * latexModule; PreambleModuleBase * preambleModule; FloatPlacement * floatModule; + BranchesModuleBase * branchesModule; QDocument * form_; }; diff --git a/src/frontends/qt2/ui/BranchesModuleBase.ui b/src/frontends/qt2/ui/BranchesModuleBase.ui new file mode 100644 index 0000000000..a1f7edda20 --- /dev/null +++ b/src/frontends/qt2/ui/BranchesModuleBase.ui @@ -0,0 +1,292 @@ + +BranchesModuleBase +config.h +qt_helpers.h + + QWidget + + name + BranchesModuleBase + + + geometry + + 0 + 0 + 344 + 297 + + + + caption + Form2 + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout2 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + availableLB + + + text + A&vailable Branches: + + + buddy + branchesLV + + + + QListView + + + text + Name + + + clickable + true + + + resizeable + true + + + + + text + Activated + + + clickable + true + + + resizeable + true + + + + + text + Color + + + clickable + true + + + resizeable + true + + + + name + branchesLV + + + enabled + true + + + focusPolicy + NoFocus + + + resizePolicy + AutoOneFit + + + vScrollBarMode + Auto + + + hScrollBarMode + Auto + + + allColumnsShowFocus + true + + + rootIsDecorated + false + + + toolTip + The available branches + + + + + + QPushButton + + name + activatePB + + + text + (&De)activate + + + toolTip + Toggle the selected branch + + + + QPushButton + + name + colorPB + + + text + Alter Co&lor... + + + toolTip + Define or change background color + + + + QPushButton + + name + removePB + + + text + &Remove + + + toolTip + Remove the selected branch + + + + + name + Spacer2 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + newBranchLA + + + text + &New: + + + buddy + newBranchLE + + + + QLineEdit + + name + newBranchLE + + + + QPushButton + + name + addBranchPB + + + text + &Add + + + toolTip + Add a new branch to the list + + + + + + + name + Spacer3 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + branchesLV + + diff --git a/src/frontends/qt2/ui/QBranchDialogBase.ui b/src/frontends/qt2/ui/QBranchDialogBase.ui new file mode 100644 index 0000000000..9adba38ee5 --- /dev/null +++ b/src/frontends/qt2/ui/QBranchDialogBase.ui @@ -0,0 +1,121 @@ + +QBranchDialogBase +config.h +qt_helpers.h + + QDialog + + name + QBranchDialogBase + + + geometry + + 0 + 0 + 188 + 99 + + + + caption + Branch Settings + + + sizeGripEnabled + true + + + + margin + 11 + + + spacing + 6 + + + QPushButton + + name + okPB + + + text + OK + + + default + false + + + + QPushButton + + name + closePB + + + text + &Close + + + default + true + + + + QLayoutWidget + + name + Layout1 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + branchLA + + + text + &Available branches: + + + buddy + branchCO + + + + QComboBox + + name + branchCO + + + toolTip + Select your branch + + + + + + + + + branchCO + activated(int) + QBranchDialogBase + change_adaptor() + + change_adaptor() + +