QGpGuiTools/Dialog.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpGuiTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2006-01-11
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef DIALOG_H
00029 #define DIALOG_H
00030 
00031 #include "QGpGuiToolsDLLExport.h"
00032 #include "Settings.h"
00033 
00034 namespace QGpGuiTools {
00035 
00036 class QGPGUITOOLS_EXPORT FrameGrabber
00037 {
00038 public:
00039   FrameGrabber() {_valid=false;_lock=5;}
00040 
00041   void setRect(QWidget * w, QString name);
00042 protected:
00043   inline void setFrame(QWidget * w);
00044 private:
00045   int _x, _y, _width, _height;
00046   int _lock;
00047   bool _valid;
00048 };
00049 
00050 inline void FrameGrabber::setFrame(QWidget * w)
00051 {
00052   TRACE;
00053   if(w->isVisible()) {
00054     if(_lock==0) {
00055       _x=w->x();
00056       _y=w->y();
00057       _width=w->width();
00058       _height=w->height();
00059       _valid=true;
00060     } else {
00061       _lock--;
00062     }
00063   }
00064 }
00065 
00066 class QGPGUITOOLS_EXPORT Dialog : public QDialog, public FrameGrabber
00067 {
00068   Q_OBJECT
00069 public:
00070   Dialog(QWidget * parent=0, Qt::WFlags f=0);
00071 
00072   void setRect(QString name) {FrameGrabber::setRect(this, name);}
00073   void getRect(QString name) {Settings::getRect(this, name);}
00074 
00075   enum Buttons {None, OkCancel, Close, TitleClose};
00076 
00077   void addWidget(QWidget * w);
00078   void addButtons(Buttons b=OkCancel);
00079   void setMainWidget(QWidget * w, Buttons b=OkCancel);
00080 protected:
00081   virtual void resizeEvent(QResizeEvent * e);
00082   virtual void moveEvent(QMoveEvent * e);
00083   virtual void closeEvent(QCloseEvent * e);
00084 private:
00085   QVBoxLayout * _vboxLayout;
00086   Buttons _buttons;
00087 };
00088 
00089 class QGPGUITOOLS_EXPORT FileDialog: public QFileDialog, public FrameGrabber
00090 {
00091   Q_OBJECT
00092 public:
00093   FileDialog(QWidget * parent, Qt::WFlags flags) : QFileDialog(parent, flags) {}
00094   FileDialog(QWidget * parent=0, const QString & caption=QString::null, const QString & directory=QString::null, const QString & filter=QString::null)
00095     : QFileDialog(parent, caption, directory, filter) {}
00096 
00097   void setRect(QString name) {FrameGrabber::setRect(this, name);}
00098   void getRect(QString name) {Settings::getRect(this, name);}
00099 protected:
00100   virtual void resizeEvent(QResizeEvent * e);
00101   virtual void moveEvent(QMoveEvent * e);
00102 };
00103 
00104 } // namespace QGpGuiTools
00105 
00106 #endif // DIALOG_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines