2001-03-23 22:07:56 +00:00
|
|
|
// -*- C++ -*-
|
2002-07-11 01:01:38 +00:00
|
|
|
/**
|
|
|
|
* \file Qt2Base.h
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-23 22:07:56 +00:00
|
|
|
*
|
2002-09-24 13:57:09 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-23 22:07:56 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-26 19:34:45 +00:00
|
|
|
#ifndef QT2BASE_H
|
|
|
|
#define QT2BASE_H
|
2001-03-23 22:07:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "ViewBase.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
|
|
#include <qfont.h>
|
|
|
|
#include <qdialog.h>
|
|
|
|
#include <qobject.h>
|
|
|
|
#include <qapplication.h>
|
2001-08-21 01:14:54 +00:00
|
|
|
|
2001-08-23 21:21:50 +00:00
|
|
|
class Qt2BC;
|
2001-03-23 22:07:56 +00:00
|
|
|
|
|
|
|
/** This class is an Qt2 GUI base class.
|
|
|
|
*/
|
2002-10-20 01:48:28 +00:00
|
|
|
class Qt2Base : public QObject, public ViewBase {
|
2001-06-05 17:05:51 +00:00
|
|
|
Q_OBJECT
|
2001-03-23 22:07:56 +00:00
|
|
|
public:
|
|
|
|
///
|
2003-05-22 15:42:50 +00:00
|
|
|
Qt2Base(string const &);
|
2001-03-23 22:07:56 +00:00
|
|
|
///
|
2001-03-26 19:34:45 +00:00
|
|
|
virtual ~Qt2Base() {}
|
2001-03-23 22:07:56 +00:00
|
|
|
protected:
|
2001-08-26 00:29:39 +00:00
|
|
|
/// build the actual dialog
|
|
|
|
virtual void build_dialog() = 0;
|
2001-03-23 22:07:56 +00:00
|
|
|
/// Hide the dialog.
|
2001-08-25 03:00:19 +00:00
|
|
|
virtual void hide();
|
2001-03-23 22:07:56 +00:00
|
|
|
/// Create the dialog if necessary, update it and display it.
|
2001-08-25 03:00:19 +00:00
|
|
|
virtual void show();
|
2001-08-25 20:04:15 +00:00
|
|
|
/// update the dialog's contents
|
2002-03-21 21:21:28 +00:00
|
|
|
virtual void update_contents() = 0;
|
2003-02-02 00:48:38 +00:00
|
|
|
///
|
|
|
|
virtual bool isVisible() const;
|
2001-03-23 22:07:56 +00:00
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
/// the dialog has changed contents
|
2002-03-21 21:21:28 +00:00
|
|
|
virtual void changed();
|
2001-08-21 01:14:54 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
/// is the dialog currently valid ?
|
2001-08-23 21:21:50 +00:00
|
|
|
virtual bool isValid();
|
2001-08-25 03:00:19 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
///
|
2003-03-10 03:13:28 +00:00
|
|
|
Qt2BC & bcview();
|
2002-08-12 14:28:43 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
/// are we updating ?
|
2002-03-21 21:21:28 +00:00
|
|
|
bool updating_;
|
2001-03-24 15:59:01 +00:00
|
|
|
protected slots:
|
2001-06-05 17:05:51 +00:00
|
|
|
// dialog closed from WM
|
|
|
|
void slotWMHide();
|
2001-03-29 15:02:19 +00:00
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
// Restore button clicked
|
|
|
|
void slotRestore();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
// OK button clicked
|
|
|
|
void slotOK();
|
2001-03-29 15:02:19 +00:00
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
// Apply button clicked
|
|
|
|
void slotApply();
|
2001-03-29 15:02:19 +00:00
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
// Close button clicked
|
|
|
|
void slotClose();
|
2001-03-23 22:07:56 +00:00
|
|
|
private:
|
2003-02-02 00:48:38 +00:00
|
|
|
/// Pointer to the actual instantiation of the Qt dialog
|
2002-03-11 22:47:41 +00:00
|
|
|
virtual QDialog * form() const = 0;
|
2001-03-23 22:07:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class Dialog>
|
2002-10-20 01:48:28 +00:00
|
|
|
class Qt2DB: public Qt2Base {
|
2001-03-23 22:07:56 +00:00
|
|
|
protected:
|
2002-08-12 14:28:43 +00:00
|
|
|
Qt2DB(QString const &);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
/// update the dialog
|
2001-08-25 20:04:15 +00:00
|
|
|
virtual void update();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
/// Build the dialog
|
|
|
|
virtual void build();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
/// Pointer to the actual instantiation of the Qt dialog
|
2001-08-25 20:04:15 +00:00
|
|
|
virtual QDialog * form() const;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
/// Real GUI implementation.
|
|
|
|
boost::scoped_ptr<Dialog> dialog_;
|
2001-08-25 03:00:19 +00:00
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class Dialog>
|
2002-08-12 14:28:43 +00:00
|
|
|
Qt2DB<Dialog>::Qt2DB(QString const & t)
|
|
|
|
: Qt2Base(t)
|
2001-03-23 22:07:56 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Dialog>
|
2001-08-25 20:04:15 +00:00
|
|
|
QDialog * Qt2DB<Dialog>::form() const
|
2001-03-23 22:07:56 +00:00
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
return dialog_.get();
|
2001-03-23 22:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
template <class Dialog>
|
|
|
|
void Qt2DB<Dialog>::update()
|
|
|
|
{
|
|
|
|
form()->setUpdatesEnabled(false);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
// protect the BC from unwarranted state transitions
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = true;
|
|
|
|
update_contents();
|
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = false;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
form()->setUpdatesEnabled(true);
|
|
|
|
form()->update();
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
template <class Dialog>
|
|
|
|
void Qt2DB<Dialog>::build()
|
|
|
|
{
|
|
|
|
// protect the BC from unwarranted state transitions
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = true;
|
|
|
|
build_dialog();
|
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = false;
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
template <class Controller, class Base>
|
2001-03-26 19:34:45 +00:00
|
|
|
class Qt2CB: public Base
|
2001-03-23 22:07:56 +00:00
|
|
|
{
|
2001-08-26 00:29:39 +00:00
|
|
|
public:
|
|
|
|
bool readOnly() const {
|
2002-08-13 14:40:38 +00:00
|
|
|
return controller().bufferIsReadonly();
|
2001-08-26 00:29:39 +00:00
|
|
|
}
|
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
/// The parent controller
|
2002-08-12 14:28:43 +00:00
|
|
|
Controller & controller();
|
|
|
|
/// The parent controller
|
|
|
|
Controller const & controller() const;
|
2003-03-09 10:08:22 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
Qt2CB(QString const &);
|
2001-03-23 22:07:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class Controller, class Base>
|
2002-08-12 14:28:43 +00:00
|
|
|
Qt2CB<Controller, Base>::Qt2CB(QString const & t)
|
|
|
|
: Base(t)
|
2001-03-23 22:07:56 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Controller, class Base>
|
2002-08-12 14:28:43 +00:00
|
|
|
Controller & Qt2CB<Controller, Base>::controller()
|
|
|
|
{
|
|
|
|
return static_cast<Controller &>(getController());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Controller, class Base>
|
|
|
|
Controller const & Qt2CB<Controller, Base>::controller() const
|
2001-03-23 22:07:56 +00:00
|
|
|
{
|
2002-08-12 14:28:43 +00:00
|
|
|
return static_cast<Controller const &>(getController());
|
2001-03-23 22:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FORMBASE_H
|