File indexing completed on 2024-05-19 05:35:25

0001 #ifndef oxygenlineedit_datah
0002 #define oxygenlineedit_datah
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygenlineeditdata.h
0006 // data container for QLineEdit transition
0007 // -------------------
0008 //
0009 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0010 //
0011 // SPDX-License-Identifier: MIT
0012 //////////////////////////////////////////////////////////////////////////////
0013 
0014 #include "oxygentransitiondata.h"
0015 
0016 #include <QBasicTimer>
0017 #include <QLineEdit>
0018 #include <QString>
0019 
0020 namespace Oxygen
0021 {
0022 //* generic data
0023 class LineEditData : public TransitionData
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     //* constructor
0029     LineEditData(QObject *, QLineEdit *, int);
0030 
0031     //* event filter
0032     bool eventFilter(QObject *, QEvent *) override;
0033 
0034     //* returns true if animations are locked
0035     bool isLocked(void) const
0036     {
0037         return _animationLockTimer.isActive();
0038     }
0039 
0040     //* start lock animation timer
0041     void lockAnimations(void)
0042     {
0043         _animationLockTimer.start(_lockTime, this);
0044     }
0045 
0046     //* start lock animation timer
0047     void unlockAnimations(void)
0048     {
0049         _animationLockTimer.stop();
0050     }
0051 
0052 protected Q_SLOTS:
0053 
0054     //* initialize animation
0055     bool initializeAnimation(void) override;
0056 
0057     //* animate
0058     bool animate(void) override;
0059 
0060 protected:
0061     //* timer event
0062     void timerEvent(QTimerEvent *) override;
0063 
0064 private Q_SLOTS:
0065 
0066     //* text edited
0067     void textEdited(void);
0068 
0069     //* selection changed
0070     void selectionChanged(void);
0071 
0072     //* text changed
0073     void textChanged(void);
0074 
0075     //* called when target is destroyed
0076     void targetDestroyed(void);
0077 
0078 private:
0079     //* target rect
0080     /** return rect corresponding to the area to be updated when animating */
0081     QRect targetRect(void) const
0082     {
0083         if (!_target)
0084             return QRect();
0085         QRect out(_target.data()->rect());
0086         if (_hasClearButton && _clearButtonRect.isValid()) {
0087             out.setRight(_clearButtonRect.left());
0088         }
0089 
0090         return out;
0091     }
0092 
0093     //* check if target has clear button
0094     void checkClearButton(void);
0095 
0096     //* lock time (milliseconds
0097     static const int _lockTime;
0098 
0099     //* timer used to disable animations when triggered too early
0100     QBasicTimer _animationLockTimer;
0101 
0102     //* needed to start animations out of parent paintEvent
0103     QBasicTimer _timer;
0104 
0105     //* target
0106     WeakPointer<QLineEdit> _target;
0107 
0108     //* true if target has clean button
0109     bool _hasClearButton;
0110 
0111     //* clear button rect
0112     QRect _clearButtonRect;
0113 
0114     //* true if text was manually edited
0115     /** needed to trigger animation only on programatically enabled text */
0116     bool _edited;
0117 
0118     //* old text
0119     QString _text;
0120 
0121     //* widget rect
0122     /** needed to properly handle QLabel geometry changes */
0123     QRect _widgetRect;
0124 };
0125 }
0126 
0127 #endif