2001-03-23 22:07:56 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
2001-06-05 17:05:51 +00:00
|
|
|
* LyX, The Document Processor
|
2001-03-23 22:07:56 +00:00
|
|
|
*
|
2001-06-05 17:05:51 +00:00
|
|
|
* Copyright 2000 The LyX Team.
|
2001-03-23 22:07:56 +00:00
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*/
|
|
|
|
|
2001-03-26 19:34:45 +00:00
|
|
|
#ifndef QT2BASE_H
|
|
|
|
#define QT2BASE_H
|
2001-03-23 22:07:56 +00:00
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-03-24 15:59:01 +00:00
|
|
|
#include <qfont.h>
|
2001-08-25 20:04:15 +00:00
|
|
|
#include <qdialog.h>
|
2001-03-24 15:59:01 +00:00
|
|
|
#include <qobject.h>
|
2001-08-25 20:04:15 +00:00
|
|
|
#include <qapplication.h>
|
2001-03-24 15:59:01 +00:00
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "LString.h"
|
2001-08-26 00:29:39 +00:00
|
|
|
#include "debug.h"
|
2001-03-23 22:07:56 +00:00
|
|
|
#include "ButtonPolicies.h"
|
2001-04-03 14:30:58 +00:00
|
|
|
#include "ControlButtons.h"
|
2001-03-23 22:07:56 +00:00
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
#include <boost/smart_ptr.hpp>
|
|
|
|
|
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.
|
|
|
|
*/
|
2001-08-23 21:21:50 +00:00
|
|
|
class Qt2Base : public QObject, public ViewBC<Qt2BC>
|
2001-03-23 22:07:56 +00:00
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
Q_OBJECT
|
2001-03-23 22:07:56 +00:00
|
|
|
public:
|
|
|
|
///
|
2001-04-03 14:30:58 +00:00
|
|
|
Qt2Base(ControlButtons &, const QString &);
|
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
|
|
|
|
virtual void update_contents() = 0;
|
2001-03-23 22:07:56 +00:00
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
/// the dialog has changed contents
|
|
|
|
virtual void changed();
|
|
|
|
|
2001-08-23 21:21:50 +00:00
|
|
|
/// is the dialog currently valid ?
|
|
|
|
virtual bool isValid();
|
2001-08-25 03:00:19 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
/// are we updating ?
|
|
|
|
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();
|
|
|
|
|
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-29 15:02:19 +00:00
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
private:
|
|
|
|
/// Pointer to the actual instantiation of xform's form
|
|
|
|
virtual QDialog* form() const = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// dialog title, displayed by WM.
|
2001-03-31 08:39:24 +00:00
|
|
|
QString title_;
|
2001-03-23 22:07:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class Dialog>
|
2001-03-26 19:34:45 +00:00
|
|
|
class Qt2DB: public Qt2Base
|
2001-03-23 22:07:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
2001-08-25 20:04:15 +00:00
|
|
|
Qt2DB(ControlButtons &, const QString &);
|
|
|
|
|
|
|
|
/// update the dialog
|
|
|
|
virtual void update();
|
2001-08-25 03:00:19 +00:00
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
/// Build the dialog
|
|
|
|
virtual void build();
|
|
|
|
|
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;
|
2001-08-26 00:29:39 +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>
|
2001-08-25 20:04:15 +00:00
|
|
|
Qt2DB<Dialog>::Qt2DB(ControlButtons & c, const QString & t)
|
2001-03-26 19:34:45 +00:00
|
|
|
: Qt2Base(c, 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);
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
// protect the BC from unwarranted state transitions
|
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = true;
|
|
|
|
update_contents();
|
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = false;
|
|
|
|
|
|
|
|
form()->setUpdatesEnabled(true);
|
|
|
|
form()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
template <class Dialog>
|
|
|
|
void Qt2DB<Dialog>::build()
|
|
|
|
{
|
|
|
|
// protect the BC from unwarranted state transitions
|
|
|
|
|
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = true;
|
|
|
|
build_dialog();
|
|
|
|
qApp->processEvents();
|
|
|
|
updating_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return controller().isReadonly();
|
|
|
|
}
|
|
|
|
|
2001-03-23 22:07:56 +00:00
|
|
|
protected:
|
|
|
|
///
|
2001-04-03 14:30:58 +00:00
|
|
|
Qt2CB(ControlButtons &, const QString&);
|
2001-03-23 22:07:56 +00:00
|
|
|
/// The parent controller
|
|
|
|
Controller & controller() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class Controller, class Base>
|
2001-04-03 14:30:58 +00:00
|
|
|
Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, const QString& t)
|
2001-03-23 22:07:56 +00:00
|
|
|
: Base(c, t)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Controller, class Base>
|
2001-03-26 19:34:45 +00:00
|
|
|
Controller & Qt2CB<Controller, Base>::controller() const
|
2001-03-23 22:07:56 +00:00
|
|
|
{
|
|
|
|
return static_cast<Controller &>(controller_);
|
|
|
|
//return dynamic_cast<Controller &>(controller_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FORMBASE_H
|