00001 #ifndef KLINEEDIT_H
00002 #define KLINEEDIT_H
00003
00004 #include <QLineEdit>
00005 #include <QLabel>
00006 #include <QPainter>
00007 #include <QPaintEvent>
00008
00009 class QAction;
00010 class QMenu;
00011
00012 class KLineEditButton : public QWidget
00013 {
00014 Q_OBJECT
00015
00016 public:
00017 KLineEditButton(QWidget *parent) : QWidget(parent)
00018 {
00019 }
00020
00021 QSize sizeHint() const
00022 {
00023 return m_pixmap.size();
00024 }
00025
00026 void animateVisible(bool visible)
00027 {
00028 if(visible)
00029 {
00030 show();
00031 }
00032 else
00033 {
00034 hide();
00035 }
00036 setVisible(visible);
00037 }
00038
00039 void setPixmap(const QPixmap& p)
00040 {
00041 m_pixmap = p;
00042 }
00043
00044 QPixmap pixmap()
00045 {
00046 return m_pixmap;
00047 }
00048
00049 protected:
00050 void paintEvent(QPaintEvent *event)
00051 {
00052 Q_UNUSED(event)
00053
00054 if (m_pixmap.isNull())
00055 {
00056 return;
00057 }
00058
00059 QPainter p(this);
00060 p.setOpacity(100);
00061 p.drawPixmap((width() - m_pixmap.width()) / 2, (height() - m_pixmap.height()) / 2, m_pixmap);
00062 }
00063
00064 private:
00065 QPixmap m_pixmap;
00066 };
00067
00068 class KLineEdit : public QLineEdit
00069 {
00070 Q_OBJECT
00071 Q_PROPERTY(bool showClearButton READ isClearButtonShown WRITE setClearButtonShown)
00072
00073 public:
00074 explicit KLineEdit(const QString &string, QWidget *parent = 0);
00075 explicit KLineEdit(QWidget *parent = 0);
00076 virtual ~KLineEdit();
00077
00078 void setClearButtonShown(bool show);
00079 bool isClearButtonShown() const;
00080 QSize clearButtonUsedSize() const;
00081
00082 Q_SIGNALS:
00083 void clearButtonClicked();
00084
00085 protected:
00086 virtual void resizeEvent(QResizeEvent *);
00087 virtual void mousePressEvent( QMouseEvent *);
00088 virtual void mouseReleaseEvent( QMouseEvent *);
00089
00090 private Q_SLOTS:
00091 void updateClearButtonIcon(const QString&);
00092
00093 private:
00094 void updateClearButton();
00095
00096 private:
00097 void init();
00098
00099 bool clickInClear:1;
00100 bool wideEnoughForClear:1;
00101 KLineEditButton *clearButton;
00102 int overlap;
00103 };
00104
00105 #endif