mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 11:08:41 +00:00
Merge Dialog and Controller in DockView. Still crashes...
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20855 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f63c57f0c2
commit
8dc0c09d72
@ -25,8 +25,7 @@ namespace frontend {
|
||||
/// Dock Widget container for LyX dialogs.
|
||||
/// This template class that encapsulates a given Widget inside a
|
||||
/// QDockWidget and presents a Dialog interface
|
||||
template<class MyController, class MyWidget>
|
||||
class DockView : public QDockWidget, public Dialog
|
||||
class DockView : public QDockWidget, public Dialog, public Controller
|
||||
{
|
||||
public:
|
||||
DockView(
|
||||
@ -35,19 +34,15 @@ public:
|
||||
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
|
||||
Qt::WindowFlags flags = 0
|
||||
)
|
||||
: QDockWidget(&parent, flags), name_(name)
|
||||
: QDockWidget(&parent, flags), name_(name), Controller(this)
|
||||
{
|
||||
if (flags & Qt::Drawer)
|
||||
setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
MyController * c = new MyController(*this);
|
||||
controller_ = c;
|
||||
controller_->setLyXView(parent);
|
||||
widget_ = new MyWidget(*c);
|
||||
setWidget(widget_);
|
||||
setWindowTitle(widget_->windowTitle());
|
||||
setLyXView(parent);
|
||||
parent.addDockWidget(area, this);
|
||||
}
|
||||
~DockView() { delete widget_; delete controller_; }
|
||||
|
||||
virtual ~DockView() {}
|
||||
|
||||
/// Dialog inherited methods
|
||||
//@{
|
||||
@ -55,12 +50,12 @@ public:
|
||||
void hideView() { QDockWidget::hide(); }
|
||||
void showData(std::string const & data)
|
||||
{
|
||||
controller_->initialiseParams(data);
|
||||
initialiseParams(data);
|
||||
showView();
|
||||
}
|
||||
void showView()
|
||||
{
|
||||
widget_->updateView(); // make sure its up-to-date
|
||||
updateView(); // make sure its up-to-date
|
||||
QDockWidget::show();
|
||||
}
|
||||
bool isVisibleView() const { return QDockWidget::isVisible(); }
|
||||
@ -69,23 +64,15 @@ public:
|
||||
void redrawView() {}
|
||||
void updateData(std::string const & data)
|
||||
{
|
||||
controller_->initialiseParams(data);
|
||||
initialiseParams(data);
|
||||
updateView();
|
||||
}
|
||||
void updateView()
|
||||
{
|
||||
widget_->updateView();
|
||||
QDockWidget::update();
|
||||
}
|
||||
bool isClosing() const { return false; }
|
||||
void partialUpdateView(int /*id*/) {}
|
||||
Controller & controller() { return *controller_; }
|
||||
Controller & controller() { return *this; }
|
||||
std::string name() const { return name_; }
|
||||
//@}
|
||||
private:
|
||||
/// The encapsulated widget.
|
||||
MyWidget * widget_;
|
||||
Controller * controller_;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
|
@ -38,8 +38,8 @@ using support::FileFilterList;
|
||||
using support::FileName;
|
||||
using support::libFileSearch;
|
||||
|
||||
GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog
|
||||
(ControlEmbeddedFiles & controller)
|
||||
EmbeddedFilesWidget::EmbeddedFilesWidget
|
||||
(GuiEmbeddedFiles & controller)
|
||||
: controller_(controller)
|
||||
{
|
||||
setupUi(this);
|
||||
@ -60,7 +60,7 @@ GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_filesLW_itemChanged(QListWidgetItem* item)
|
||||
void EmbeddedFilesWidget::on_filesLW_itemChanged(QListWidgetItem* item)
|
||||
{
|
||||
EmbeddedFiles & files = controller_.embeddedFiles();
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
@ -79,7 +79,7 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemChanged(QListWidgetItem* item)
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
|
||||
void EmbeddedFilesWidget::on_filesLW_itemSelectionChanged()
|
||||
{
|
||||
if (controller_.isReadonly())
|
||||
return;
|
||||
@ -113,7 +113,7 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_filesLW_itemClicked(QListWidgetItem* item)
|
||||
void EmbeddedFilesWidget::on_filesLW_itemClicked(QListWidgetItem* item)
|
||||
{
|
||||
EmbeddedFiles & files = controller_.embeddedFiles();
|
||||
int idx = filesLW->row(item);
|
||||
@ -134,14 +134,14 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemClicked(QListWidgetItem* item)
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked(QListWidgetItem* item)
|
||||
void EmbeddedFilesWidget::on_filesLW_itemDoubleClicked(QListWidgetItem* item)
|
||||
{
|
||||
EmbeddedFiles & files = controller_.embeddedFiles();
|
||||
controller_.view(files[filesLW->row(item)]);
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::updateView()
|
||||
void EmbeddedFilesWidget::updateView()
|
||||
{
|
||||
bool readOnly = controller_.isReadonly();
|
||||
fullpathLE->setEnabled(!readOnly);
|
||||
@ -179,7 +179,7 @@ void GuiEmbeddedFilesDialog::updateView()
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_selectPB_clicked()
|
||||
void EmbeddedFilesWidget::on_selectPB_clicked()
|
||||
{
|
||||
EmbeddedFiles & files = controller_.embeddedFiles();
|
||||
// this should not be needed after EmbeddedFiles are updated correctly.
|
||||
@ -194,7 +194,7 @@ void GuiEmbeddedFilesDialog::on_selectPB_clicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_unselectPB_clicked()
|
||||
void EmbeddedFilesWidget::on_unselectPB_clicked()
|
||||
{
|
||||
EmbeddedFiles & files = controller_.embeddedFiles();
|
||||
// this should not be needed after EmbeddedFiles are updated correctly.
|
||||
@ -209,14 +209,14 @@ void GuiEmbeddedFilesDialog::on_unselectPB_clicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_addPB_clicked()
|
||||
void EmbeddedFilesWidget::on_addPB_clicked()
|
||||
{
|
||||
if (controller_.browseAndAddFile())
|
||||
updateView();
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_extractPB_clicked()
|
||||
void EmbeddedFilesWidget::on_extractPB_clicked()
|
||||
{
|
||||
EmbeddedFiles const & files = controller_.embeddedFiles();
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
@ -228,7 +228,7 @@ void GuiEmbeddedFilesDialog::on_extractPB_clicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_updatePB_clicked()
|
||||
void EmbeddedFilesWidget::on_updatePB_clicked()
|
||||
{
|
||||
EmbeddedFiles const & files = controller_.embeddedFiles();
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
@ -241,31 +241,41 @@ void GuiEmbeddedFilesDialog::on_updatePB_clicked()
|
||||
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_enableCB_toggled(bool enable)
|
||||
void EmbeddedFilesWidget::on_enableCB_toggled(bool enable)
|
||||
{
|
||||
controller_.setEmbedding(enable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent)
|
||||
: Controller(parent)
|
||||
{}
|
||||
GuiEmbeddedFiles::GuiEmbeddedFiles(GuiViewBase & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
||||
: DockView(parent, "embedded", area, flags)
|
||||
{
|
||||
widget_ = new EmbeddedFilesWidget(*this);
|
||||
setWidget(widget_);
|
||||
setWindowTitle(widget_->windowTitle());
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
|
||||
void GuiEmbeddedFiles::updateView()
|
||||
{
|
||||
widget_->updateView();
|
||||
}
|
||||
|
||||
|
||||
EmbeddedFiles & GuiEmbeddedFiles::embeddedFiles()
|
||||
{
|
||||
return buffer().embeddedFiles();
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::initialiseParams(string const &)
|
||||
bool GuiEmbeddedFiles::initialiseParams(string const &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::updateEmbeddedFiles()
|
||||
void GuiEmbeddedFiles::updateEmbeddedFiles()
|
||||
{
|
||||
// copy buffer embeddedFiles to a local copy
|
||||
buffer().embeddedFiles().update();
|
||||
@ -273,7 +283,7 @@ void ControlEmbeddedFiles::updateEmbeddedFiles()
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::dispatchMessage(string const & msg)
|
||||
void GuiEmbeddedFiles::dispatchMessage(string const & msg)
|
||||
{
|
||||
// FIXME: the right thing to do? QT guys?
|
||||
// lyx view will only be updated if we do something to the main window. :-)
|
||||
@ -281,13 +291,13 @@ void ControlEmbeddedFiles::dispatchMessage(string const & msg)
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::isReadonly()
|
||||
bool GuiEmbeddedFiles::isReadonly()
|
||||
{
|
||||
return buffer().isReadonly();
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbedding(bool enable)
|
||||
void GuiEmbeddedFiles::setEmbedding(bool enable)
|
||||
{
|
||||
if (embeddedFiles().enabled() == enable)
|
||||
return;
|
||||
@ -300,7 +310,7 @@ void ControlEmbeddedFiles::setEmbedding(bool enable)
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
|
||||
void GuiEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
|
||||
{
|
||||
BOOST_ASSERT(idx < item.refCount());
|
||||
item.saveBookmark(&buffer(), idx);
|
||||
@ -308,13 +318,13 @@ void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::view(EmbeddedFile const & item)
|
||||
void GuiEmbeddedFiles::view(EmbeddedFile const & item)
|
||||
{
|
||||
formats.view(buffer(), item, formats.getFormatFromFile(item));
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update)
|
||||
void GuiEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update)
|
||||
{
|
||||
if (item.embedded() == embed)
|
||||
return;
|
||||
@ -337,7 +347,7 @@ void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::browseAndAddFile()
|
||||
bool GuiEmbeddedFiles::browseAndAddFile()
|
||||
{
|
||||
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
|
||||
from_utf8(lyxrc.document_path));
|
||||
@ -357,7 +367,7 @@ bool ControlEmbeddedFiles::browseAndAddFile()
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
|
||||
bool GuiEmbeddedFiles::extract(EmbeddedFile const & item)
|
||||
{
|
||||
if (item.embedded())
|
||||
return item.extract(&buffer());
|
||||
@ -366,7 +376,7 @@ bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
|
||||
bool GuiEmbeddedFiles::update(EmbeddedFile const & item)
|
||||
{
|
||||
if (item.embedded())
|
||||
return item.updateFromExternalFile(&buffer());
|
||||
@ -375,16 +385,15 @@ bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
|
||||
}
|
||||
|
||||
|
||||
GuiEmbeddedFiles::GuiEmbeddedFiles(LyXView & lv)
|
||||
: DockView<ControlEmbeddedFiles, GuiEmbeddedFilesDialog>(
|
||||
static_cast<GuiViewBase &>(lv),
|
||||
"embedded", Qt::RightDockWidgetArea)
|
||||
{}
|
||||
|
||||
|
||||
Dialog * createGuiEmbeddedFiles(LyXView & lv)
|
||||
{
|
||||
return new GuiEmbeddedFiles(lv);
|
||||
GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
|
||||
#ifdef Q_WS_MACX
|
||||
// On Mac show as a drawer at the right
|
||||
return new GuiEmbeddedFiles(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
|
||||
#else
|
||||
return new GuiEmbeddedFiles(guiview, Qt::RightDockWidgetArea);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,12 +20,21 @@
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class ControlEmbeddedFiles : public Controller {
|
||||
class EmbeddedFilesWidget;
|
||||
|
||||
class GuiEmbeddedFiles : public DockView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
ControlEmbeddedFiles(Dialog &);
|
||||
GuiEmbeddedFiles(
|
||||
GuiViewBase & parent, ///< the main window where to dock.
|
||||
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
|
||||
Qt::WindowFlags flags = 0);
|
||||
///
|
||||
~ControlEmbeddedFiles() {}
|
||||
void updateView();
|
||||
|
||||
///
|
||||
EmbeddedFiles & embeddedFiles();
|
||||
///
|
||||
@ -62,16 +71,19 @@ public:
|
||||
bool update(EmbeddedFile const & item);
|
||||
|
||||
protected:
|
||||
//
|
||||
///
|
||||
EmbeddedFilesWidget * widget_;
|
||||
///
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
class GuiEmbeddedFilesDialog : public QWidget, public Ui::GuiEmbeddedFilesUi
|
||||
|
||||
class EmbeddedFilesWidget : public QWidget, public Ui::GuiEmbeddedFilesUi
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GuiEmbeddedFilesDialog(ControlEmbeddedFiles &);
|
||||
EmbeddedFilesWidget(GuiEmbeddedFiles &);
|
||||
std::string name() const { return "embedding"; }
|
||||
|
||||
public Q_SLOTS:
|
||||
@ -92,19 +104,11 @@ public Q_SLOTS:
|
||||
void on_updatePB_clicked();
|
||||
|
||||
private:
|
||||
ControlEmbeddedFiles & controller_;
|
||||
GuiEmbeddedFiles & controller_;
|
||||
void set_embedding_status(bool embed);
|
||||
};
|
||||
|
||||
|
||||
class GuiEmbeddedFiles
|
||||
: public DockView<ControlEmbeddedFiles, GuiEmbeddedFilesDialog>
|
||||
{
|
||||
public:
|
||||
GuiEmbeddedFiles(LyXView & lv);
|
||||
};
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -43,9 +43,13 @@ using std::string;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GuiToc::GuiToc(Dialog & dialog)
|
||||
: Controller(dialog), params_("toc")
|
||||
{}
|
||||
GuiToc::GuiToc(GuiViewBase & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
||||
: DockView(parent, "toc", area, flags), params_("toc")
|
||||
{
|
||||
widget_ = new TocWidget(*this);
|
||||
setWidget(widget_);
|
||||
setWindowTitle(widget_->windowTitle());
|
||||
}
|
||||
|
||||
|
||||
int GuiToc::getTocDepth(int type)
|
||||
@ -235,10 +239,9 @@ Dialog * createGuiToc(LyXView & lv)
|
||||
GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
|
||||
#ifdef Q_WS_MACX
|
||||
// On Mac show as a drawer at the right
|
||||
return new DockView<GuiToc, TocWidget>(guiview, "toc",
|
||||
Qt::RightDockWidgetArea, Qt::Drawer);
|
||||
return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
|
||||
#else
|
||||
return new DockView<GuiToc, TocWidget>(guiview, "toc");
|
||||
return new GuiToc(guiview);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,12 @@
|
||||
#ifndef GUITOC_H
|
||||
#define GUITOC_H
|
||||
|
||||
#include "TocBackend.h"
|
||||
#include "Dialog.h"
|
||||
#include "DockView.h"
|
||||
|
||||
#include "insets/InsetCommandParams.h"
|
||||
|
||||
#include "TocBackend.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStringListModel>
|
||||
@ -29,14 +31,18 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class TocModel;
|
||||
class TocWidget;
|
||||
|
||||
class GuiToc : public QObject, public Controller
|
||||
class GuiToc : public DockView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
GuiToc(Dialog &);
|
||||
GuiToc(
|
||||
GuiViewBase & parent, ///< the main window where to dock.
|
||||
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
|
||||
Qt::WindowFlags flags = 0);
|
||||
|
||||
///
|
||||
bool initialiseParams(std::string const & data);
|
||||
@ -60,10 +66,12 @@ Q_SIGNALS:
|
||||
void modelReset();
|
||||
|
||||
private:
|
||||
friend class TocWidget;
|
||||
///
|
||||
TocWidget * widget_;
|
||||
///
|
||||
std::vector<TocModel *> toc_models_;
|
||||
|
||||
public:
|
||||
///
|
||||
TocList const & tocs() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user