2007-09-27 11:27:52 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file DialogView.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DIALOG_VIEW_H
|
|
|
|
#define DIALOG_VIEW_H
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "Dialog.h"
|
2007-09-27 11:27:52 +00:00
|
|
|
#include "GuiView.h"
|
|
|
|
#include "qt_helpers.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2007-09-27 11:27:52 +00:00
|
|
|
|
2007-09-27 14:05:05 +00:00
|
|
|
#include <QCloseEvent>
|
2007-09-27 11:27:52 +00:00
|
|
|
#include <QDialog>
|
2007-09-27 14:05:05 +00:00
|
|
|
#include <QSettings>
|
2007-09-27 14:22:58 +00:00
|
|
|
#include <QShowEvent>
|
2007-09-28 12:34:35 +00:00
|
|
|
#include <QGridLayout>
|
2007-09-27 11:27:52 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
/// Window Dialog container for LyX dialogs.
|
|
|
|
/// This template class that encapsulates a given Widget inside a
|
|
|
|
/// QDialog and presents a Dialog interface
|
2007-10-09 19:52:34 +00:00
|
|
|
template<class MyWidget>
|
2007-10-09 22:13:51 +00:00
|
|
|
class DialogView : public QDialog, public Dialog
|
2007-09-27 11:27:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DialogView(
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiView & parent, ///< the main window where to dock.
|
2007-09-27 11:27:52 +00:00
|
|
|
std::string const & name, ///< dialog identifier.
|
|
|
|
bool modal = false, ///< Window modality.
|
|
|
|
Qt::WindowFlags flags = 0
|
|
|
|
)
|
2007-11-23 10:45:14 +00:00
|
|
|
: QDialog(&parent, flags), Dialog(parent, name)
|
2007-09-27 11:27:52 +00:00
|
|
|
{
|
|
|
|
setModal(modal);
|
2007-09-28 12:34:35 +00:00
|
|
|
QGridLayout * gridLayout = new QGridLayout(this);
|
|
|
|
gridLayout->setMargin(0);
|
2007-10-09 19:52:34 +00:00
|
|
|
widget_ = new MyWidget(*this, this);
|
2007-09-28 12:34:35 +00:00
|
|
|
gridLayout->addWidget(widget_);
|
2007-09-27 11:27:52 +00:00
|
|
|
setWindowTitle("LyX: " + widget_->windowTitle());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Dialog inherited methods
|
|
|
|
//@{
|
|
|
|
void applyView() {}
|
|
|
|
void hideView()
|
|
|
|
{
|
2007-10-09 19:52:34 +00:00
|
|
|
clearParams();
|
2007-09-27 11:27:52 +00:00
|
|
|
QDialog::hide();
|
|
|
|
}
|
|
|
|
void showData(std::string const & data)
|
|
|
|
{
|
2007-10-09 19:52:34 +00:00
|
|
|
initialiseParams(data);
|
2007-09-27 11:27:52 +00:00
|
|
|
showView();
|
|
|
|
}
|
|
|
|
void showView()
|
|
|
|
{
|
|
|
|
widget_->updateView(); // make sure its up-to-date
|
|
|
|
QDialog::show();
|
|
|
|
raise();
|
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
bool isVisibleView() const { return QDialog::isVisible(); }
|
|
|
|
void checkStatus() { updateView(); }
|
|
|
|
void updateData(std::string const & data)
|
|
|
|
{
|
2007-10-09 19:52:34 +00:00
|
|
|
initialiseParams(data);
|
2007-09-27 11:27:52 +00:00
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
void updateView()
|
|
|
|
{
|
|
|
|
widget_->updateView();
|
|
|
|
}
|
|
|
|
//@}
|
|
|
|
private:
|
|
|
|
/// The encapsulated widget.
|
|
|
|
MyWidget * widget_;
|
2007-09-27 14:05:05 +00:00
|
|
|
|
|
|
|
void showEvent(QShowEvent * e)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2007-11-23 10:45:14 +00:00
|
|
|
std::string key = name() + "/geometry";
|
2007-09-27 14:47:42 +00:00
|
|
|
QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
|
2007-09-27 14:05:05 +00:00
|
|
|
QDialog::showEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2007-11-23 10:45:14 +00:00
|
|
|
std::string key = name() + "/geometry";
|
2007-09-27 14:47:42 +00:00
|
|
|
settings.setValue(key.c_str(), QDialog::saveGeometry());
|
2007-11-14 14:24:59 +00:00
|
|
|
QDialog::closeEvent(e);
|
2007-09-27 14:05:05 +00:00
|
|
|
}
|
2007-09-27 11:27:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // frontend
|
|
|
|
} // lyx
|
|
|
|
|
|
|
|
#endif // DIALOG_VIEW_H
|