1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#ifndef WidgetMonitor_h
#define WidgetMonitor_h
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* Any WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*******************************************************************************/
#include "Counter.h"
#include <QBasicTimer>
#include <QSize>
#include <QTimerEvent>
#include <QWidget>
//* used to automatically save size of top level widgets
class WidgetMonitor: public QObject, private Base::Counter<WidgetMonitor>
{
public:
//* constructor
explicit WidgetMonitor( QWidget* );
//* mode
enum Mode
{
None = 0,
Size = 1<<0,
Position = 1<<1
};
Q_DECLARE_FLAGS( Modes, Mode );
//* mode
void setMode( Modes value )
{ mode_ = value; }
//* size option name
void setOptionName( const QString& );
//* size hint
/** an invalid size is returned when option name is not set */
QSize sizeHint() const;
//* position
QPoint position() const;
//* event filter
bool eventFilter( QObject*, QEvent* ) override;
protected:
//* timer event
/** need to save updated window size */
void timerEvent( QTimerEvent* ) override;
private:
//* true when option name was set
bool _hasOptionName() const
{ return !widthOptionName_.isEmpty(); }
//* save window size
void _saveWindowSize() const;
//* save position
void _saveWindowPosition() const;
//* resize timer
QBasicTimer timer_;
//* mode
Modes mode_ = Mode::Size;
//* window size option name
QString widthOptionName_;
//* window size option name
QString heightOptionName_;
//* position option name
QString xOptionName_;
//* position option name
QString yOptionName_;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( WidgetMonitor::Modes )
#endif
|