00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QVLCFRAME_H_
00025 #define _QVLCFRAME_H_
00026
00027 #include <QWidget>
00028 #include <QDialog>
00029 #include <QHBoxLayout>
00030 #include <QApplication>
00031 #include <QMainWindow>
00032 #include <QKeyEvent>
00033 #include <QDesktopWidget>
00034 #include <QSettings>
00035 #include <QStyle>
00036
00037 #include "qt4.hpp"
00038
00039 class QVLCTools
00040 {
00041 public:
00042
00043
00044
00045
00046
00047
00048 static void saveWidgetPosition( QSettings *settings, QWidget *widget)
00049 {
00050 settings->setValue("geometry", widget->saveGeometry());
00051 }
00052 static void saveWidgetPosition( intf_thread_t *p_intf,
00053 const QString& configName,
00054 QWidget *widget)
00055 {
00056 getSettings()->beginGroup( configName );
00057 QVLCTools::saveWidgetPosition(getSettings(), widget);
00058 getSettings()->endGroup();
00059 }
00060
00061
00062
00063
00064
00065
00066 static bool restoreWidgetPosition(QSettings *settings,
00067 QWidget *widget,
00068 QSize defSize = QSize( 0, 0 ),
00069 QPoint defPos = QPoint( 0, 0 ))
00070 {
00071 if(!widget->restoreGeometry(settings->value("geometry")
00072 .toByteArray()))
00073 {
00074 widget->move(defPos);
00075 widget->resize(defSize);
00076
00077 if(defPos.x() == 0 && defPos.y()==0)
00078 widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), qApp->desktop()->availableGeometry()));
00079 return true;
00080 }
00081 return false;
00082 }
00083
00084 static bool restoreWidgetPosition( intf_thread_t *p_intf,
00085 const QString& configName,
00086 QWidget *widget,
00087 QSize defSize = QSize( 0, 0 ),
00088 QPoint defPos = QPoint( 0, 0 ) )
00089 {
00090 getSettings()->beginGroup( configName );
00091 bool defaultUsed = QVLCTools::restoreWidgetPosition( getSettings(),
00092 widget,
00093 defSize,
00094 defPos);
00095 getSettings()->endGroup();
00096
00097 return defaultUsed;
00098 }
00099 };
00100
00101 class QVLCFrame : public QWidget
00102 {
00103 public:
00104 #ifdef __APPLE__
00105 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL, Qt::Window ), p_intf( _p_intf )
00106 #else
00107 QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
00108 #endif
00109 {};
00110 virtual ~QVLCFrame() {};
00111
00112 void toggleVisible()
00113 {
00114 if( isVisible() ) hide();
00115 else show();
00116 }
00117 protected:
00118 intf_thread_t *p_intf;
00119
00120 void readSettings( const QString& name,
00121 QSize defSize = QSize( 1, 1 ),
00122 QPoint defPos = QPoint( 0, 0 ) )
00123 {
00124 QVLCTools::restoreWidgetPosition(p_intf, name, this, defSize, defPos);
00125 }
00126
00127 void writeSettings( const QString& name )
00128 {
00129 QVLCTools::saveWidgetPosition( p_intf, name, this);
00130 }
00131
00132 virtual void cancel()
00133 {
00134 hide();
00135 }
00136 virtual void close()
00137 {
00138 hide();
00139 }
00140 virtual void keyPressEvent( QKeyEvent *keyEvent )
00141 {
00142 if( keyEvent->key() == Qt::Key_Escape )
00143 {
00144 this->cancel();
00145 }
00146 else if( keyEvent->key() == Qt::Key_Return
00147 || keyEvent->key() == Qt::Key_Enter )
00148 {
00149 this->close();
00150 }
00151 }
00152 };
00153
00154 class QVLCDialog : public QDialog
00155 {
00156 public:
00157 QVLCDialog( QWidget* parent, intf_thread_t *_p_intf ) :
00158 QDialog( parent ), p_intf( _p_intf )
00159 {}
00160 virtual ~QVLCDialog() {};
00161 void toggleVisible()
00162 {
00163 if( isVisible() ) hide();
00164 else show();
00165 }
00166
00167 protected:
00168 intf_thread_t *p_intf;
00169
00170 virtual void cancel()
00171 {
00172 hide();
00173 }
00174 virtual void close()
00175 {
00176 hide();
00177 }
00178 virtual void keyPressEvent( QKeyEvent *keyEvent )
00179 {
00180 if( keyEvent->key() == Qt::Key_Escape )
00181 {
00182 this->cancel();
00183 }
00184 else if( keyEvent->key() == Qt::Key_Return
00185 || keyEvent->key() == Qt::Key_Enter )
00186 {
00187 this->close();
00188 }
00189 }
00190 };
00191
00192 class QVLCMW : public QMainWindow
00193 {
00194 public:
00195 QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
00196 { }
00197 virtual ~QVLCMW() {};
00198 void toggleVisible()
00199 {
00200 if( isVisible() ) hide();
00201 else show();
00202 }
00203 protected:
00204 intf_thread_t *p_intf;
00205 QSize mainSize;
00206
00207 void readSettings( const QString& name, QSize defSize )
00208 {
00209 QVLCTools::restoreWidgetPosition( p_intf, name, this, defSize);
00210 }
00211
00212 void readSettings( const QString& name )
00213 {
00214 QVLCTools::restoreWidgetPosition( p_intf, name, this);
00215 }
00216 void readSettings( QSettings *settings )
00217 {
00218 QVLCTools::restoreWidgetPosition(settings, this);
00219 }
00220
00221 void readSettings( QSettings *settings, QSize defSize)
00222 {
00223 QVLCTools::restoreWidgetPosition(settings, this, defSize);
00224 }
00225
00226 void writeSettings( const QString& name )
00227 {
00228 QVLCTools::saveWidgetPosition( p_intf, name, this);
00229 }
00230 void writeSettings(QSettings *settings )
00231 {
00232 QVLCTools::saveWidgetPosition(settings, this);
00233 }
00234 };
00235
00236 #endif