diff --git a/src/frontends/qt4/FloatPlacement.cpp b/src/frontends/qt4/FloatPlacement.cpp index f689ab24e8..f49bc5c8d1 100644 --- a/src/frontends/qt4/FloatPlacement.cpp +++ b/src/frontends/qt4/FloatPlacement.cpp @@ -21,7 +21,7 @@ using namespace std; using namespace lyx::support; -//namespace lyx { +namespace lyx { FloatPlacement::FloatPlacement(QWidget *) { @@ -239,6 +239,6 @@ void FloatPlacement::checkAllowed() } } -//} // namespace lyx +} // namespace lyx #include "FloatPlacement_moc.cpp" diff --git a/src/frontends/qt4/FloatPlacement.h b/src/frontends/qt4/FloatPlacement.h index 557f48ab52..f59eb39e55 100644 --- a/src/frontends/qt4/FloatPlacement.h +++ b/src/frontends/qt4/FloatPlacement.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file floatplacement.h + * \file FloatPlacement.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,8 +10,8 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QT_FLOATPLACEMENT_H -#define QT_FLOATPLACEMENT_H +#ifndef FLOATPLACEMENT_H +#define FLOATPLACEMENT_H #include "ui_FloatPlacementUi.h" #include @@ -19,7 +19,9 @@ #include -namespace lyx { class InsetFloatParams; } +namespace lyx { + +class InsetFloatParams; class FloatPlacement : public QWidget, public Ui::FloatPlacementUi { Q_OBJECT @@ -52,7 +54,6 @@ private: }; +} // namespace lyx -//} // namespace lyx - -#endif +#endif // FLOATPLACEMENT_H diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 947f929aa5..5d5ff1d5bf 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -15,6 +15,7 @@ #include "GuiApplication.h" #include "GuiBranches.h" +#include "GuiSelectionManager.h" #include "LaTeXHighlighter.h" #include "LengthCombo.h" #include "PanelStack.h" @@ -140,7 +141,7 @@ class less_textclass_avail_desc : public binary_function { public: - int operator()(string const & lhs, string const & rhs) const + bool operator()(string const & lhs, string const & rhs) const { // Ordering criteria: // 1. Availability of text class @@ -156,20 +157,6 @@ public: } namespace frontend { - - -/// -QModelIndex getSelectedIndex(QListView * lv) -{ - QModelIndex retval = QModelIndex(); - QModelIndexList selIdx = - lv->selectionModel()->selectedIndexes(); - if (!selIdx.empty()) - retval = selIdx.first(); - return retval; -} - - namespace { vector getRequiredList(string const & modName) @@ -225,20 +212,45 @@ bool isModuleAvailable(string const & modName) // ///////////////////////////////////////////////////////////////////// -ModuleSelectionManager::ModuleSelectionManager( - QListView * availableLV, - QListView * selectedLV, - QPushButton * addPB, - QPushButton * delPB, - QPushButton * upPB, - QPushButton * downPB, - GuiIdListModel * availableModel, - GuiIdListModel * selectedModel) : -GuiSelectionManager(availableLV, selectedLV, addPB, delPB, +/// SelectionManager for use with modules +class ModuleSelectionManager : public GuiSelectionManager +{ +public: + ModuleSelectionManager( + QListView * availableLV, + QListView * selectedLV, + QPushButton * addPB, + QPushButton * delPB, + QPushButton * upPB, + QPushButton * downPB, + GuiIdListModel * availableModel, + GuiIdListModel * selectedModel) + : GuiSelectionManager(availableLV, selectedLV, addPB, delPB, upPB, downPB, availableModel, selectedModel) -{} + {} +private: + /// + virtual void updateAddPB(); + /// + virtual void updateUpPB(); + /// + virtual void updateDownPB(); + /// + virtual void updateDelPB(); + /// returns availableModel as a GuiIdListModel + GuiIdListModel * getAvailableModel() + { + return dynamic_cast(availableModel); + } + /// returns selectedModel as a GuiIdListModel + GuiIdListModel * getSelectedModel() + { + return dynamic_cast(selectedModel); + } +}; + void ModuleSelectionManager::updateAddPB() { int const arows = availableModel->rowCount(); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 9a37ad5cfe..af66737fe9 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -19,7 +19,6 @@ #include "BulletsModule.h" #include "GuiDialog.h" #include "GuiIdListModel.h" -#include "GuiSelectionManager.h" #include "ui_DocumentUi.h" #include "ui_FontUi.h" @@ -37,21 +36,18 @@ #include #include -class FloatPlacement; - namespace lyx { class BufferParams; +class FloatPlacement; class TextClass; namespace frontend { class GuiBranches; +class GuiSelectionManager; class PreambleModule; -/// -QModelIndex getSelectedIndex(QListView * lv); - /// typedef void const * BufferId; @@ -63,41 +59,6 @@ public: }; -/// SelectionManager for use with modules -class ModuleSelectionManager : public GuiSelectionManager -{ -public: - ModuleSelectionManager( - QListView * availableLV, - QListView * selectedLV, - QPushButton * addPB, - QPushButton * delPB, - QPushButton * upPB, - QPushButton * downPB, - GuiIdListModel * availableModel, - GuiIdListModel * selectedModel); -private: - /// - virtual void updateAddPB(); - /// - virtual void updateUpPB(); - /// - virtual void updateDownPB(); - /// - virtual void updateDelPB(); - /// returns availableModel as a GuiIdListModel - GuiIdListModel * getAvailableModel() - { - return dynamic_cast(availableModel); - } - /// returns selectedModel as a GuiIdListModel - GuiIdListModel * getSelectedModel() - { - return dynamic_cast(selectedModel); - } -}; - - class GuiDocument : public GuiDialog, public Ui::DocumentUi { Q_OBJECT diff --git a/src/frontends/qt4/GuiSelectionManager.cpp b/src/frontends/qt4/GuiSelectionManager.cpp index 4156765cc4..b2c846052b 100644 --- a/src/frontends/qt4/GuiSelectionManager.cpp +++ b/src/frontends/qt4/GuiSelectionManager.cpp @@ -13,17 +13,20 @@ */ #include + #include "GuiSelectionManager.h" -#include "GuiDocument.h" #include "support/debug.h" -using std::vector; +#include +#include +#include +#include + namespace lyx { namespace frontend { - GuiSelectionManager::GuiSelectionManager( QListView * avail, QListView * sel, @@ -180,9 +183,12 @@ bool GuiSelectionManager::insertRowToSelected(int i, void GuiSelectionManager::addPB_clicked() { - QModelIndex const idxToAdd = getSelectedIndex(availableLV); - if (!idxToAdd.isValid()) + QModelIndexList selIdx = + availableLV->selectionModel()->selectedIndexes(); + if (selIdx.isEmpty()) return; + + QModelIndex const idxToAdd = selectedLV->currentIndex(); QModelIndex const idx = selectedLV->currentIndex(); int const srows = selectedModel->rowCount(); @@ -190,7 +196,7 @@ void GuiSelectionManager::addPB_clicked() insertRowToSelected(srows, qm); selectionChanged(); //signal - + if (idx.isValid()) selectedLV->setCurrentIndex(idx); @@ -200,10 +206,11 @@ void GuiSelectionManager::addPB_clicked() void GuiSelectionManager::deletePB_clicked() { - QModelIndex idx = getSelectedIndex(selectedLV); - if (!idx.isValid()) + QModelIndexList selIdx = + selectedLV->selectionModel()->selectedIndexes(); + if (selIdx.isEmpty()) return; - + QModelIndex idx = selIdx.first(); selectedModel->removeRow(idx.row()); selectionChanged(); //signal @@ -307,10 +314,9 @@ bool GuiSelectionManager::eventFilter(QObject * obj, QEvent * event) if (keyPressed == Qt::Key_Enter || keyPressed == Qt::Key_Return) { if (!keyModifiers) addPB_clicked(); - else if ((keyModifiers == Qt::ControlModifier) || - (keyModifiers == Qt::KeypadModifier) || - (keyModifiers == (Qt::ControlModifier | Qt::KeypadModifier)) - ) { + else if (keyModifiers == Qt::ControlModifier || + keyModifiers == Qt::KeypadModifier || + keyModifiers == (Qt::ControlModifier | Qt::KeypadModifier)) { if (addPB->isEnabled()) { addPB_clicked(); okHook(); //signal diff --git a/src/frontends/qt4/GuiSelectionManager.h b/src/frontends/qt4/GuiSelectionManager.h index 43ceea7b50..2e9c747363 100644 --- a/src/frontends/qt4/GuiSelectionManager.h +++ b/src/frontends/qt4/GuiSelectionManager.h @@ -12,18 +12,14 @@ #ifndef GUISELECTIONMANAGER_H #define GUISELECTIONMANAGER_H -#include "Dialog.h" - #include -#include -#include -#include -#include -#include -#include "support/qstring_helpers.h" - -#include +class QAbstractListModel; +class QModelIndex; +class QListView; +class QPushButton; +class QVariant; +template class QMap; namespace lyx { namespace frontend { @@ -38,7 +34,7 @@ namespace frontend { */ class GuiSelectionManager : public QObject { -Q_OBJECT + Q_OBJECT public: /// @@ -66,24 +62,24 @@ public: bool selectedFocused() { return selectedHasFocus_; }; Q_SIGNALS: - ///Emitted when the list of selected items has changed. + /// Emitted when the list of selected items has changed. void selectionChanged(); - ///Emitted when something has changed that might lead the containing - ///dialog to want to update---the focused subwidget or selected item. - ///(Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) - ///NOTE: No automatic update of the button state is done here. If you - ///just want to do that, connect updateHook() to updateView(). Much of the - ///time, though, you will want to do a bit more processing first, so - ///you can connect to some other function that itself calls updateView(). + /// Emitted when something has changed that might lead the containing + /// dialog to want to update---the focused subwidget or selected item. + /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) + /// NOTE: No automatic update of the button state is done here. If you + /// just want to do that, connect updateHook() to updateView(). Much of the + /// time, though, you will want to do a bit more processing first, so + /// you can connect to some other function that itself calls updateView(). void updateHook(); - ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected - ///to an "OK" event in the parent dialog. + /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected + /// to an "OK" event in the parent dialog. void okHook(); protected: - ///Given a QModelIndex from availableLV, determines whether it has - ///been selected (i.e., is also in selectedLV). + /// Given a QModelIndex from availableLV, determines whether it has + /// been selected (i.e., is also in selectedLV). bool isSelected(const QModelIndex & idx); /// bool insertRowToSelected(int i, QMap const & itemData); diff --git a/src/frontends/qt4/ui/FloatUi.ui b/src/frontends/qt4/ui/FloatUi.ui index 1178bd3208..7560cd3df4 100644 --- a/src/frontends/qt4/ui/FloatUi.ui +++ b/src/frontends/qt4/ui/FloatUi.ui @@ -26,7 +26,7 @@ 6 - +