resizablepopup.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*****************************************************************************
  2. * resizablepopup.h - QStarDict, a StarDict clone written with using Qt *
  3. * Copyright (C) 2007 Alexander Rodin *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License along *
  16. * with this program; if not, write to the Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  18. *****************************************************************************/
  19. #ifndef RESIZABLEPOPUP_H
  20. #define RESIZABLEPOPUP_H
  21. #include <QFrame>
  22. class QEvent;
  23. class QMouseEvent;
  24. class QTimerEvent;
  25. namespace QStarDict
  26. {
  27. /**
  28. * The ResizablePopup widget is a resizable top-level window
  29. * without decorations.
  30. */
  31. class ResizablePopup: public QFrame
  32. {
  33. Q_OBJECT
  34. public:
  35. /**
  36. * Construct a ResizablePopup widget.
  37. */
  38. ResizablePopup(QWidget *parent = 0);
  39. /**
  40. * Return timeout before hiding after mouse leaving.
  41. */
  42. int timeoutBeforeHide() const
  43. { return m_timeoutBeforeHide; }
  44. /**
  45. * Return a default size of new-shown popup.
  46. */
  47. const QSize& defaultSize() const
  48. { return m_defaultSize; }
  49. public slots:
  50. /**
  51. * Set timeout before hiding after mouse leaving.
  52. */
  53. void setTimeoutBeforeHide(int timeoutBeforeHide)
  54. { m_timeoutBeforeHide = timeoutBeforeHide; }
  55. /**
  56. * Set default size of new-shown popup.
  57. */
  58. void setDefaultSize(const QSize &defaultSize)
  59. { m_defaultSize = defaultSize; }
  60. /**
  61. * Show popup under mouse cursor.
  62. */
  63. void popup();
  64. protected:
  65. void enterEvent(QEvent*);
  66. void leaveEvent(QEvent*);
  67. void mouseMoveEvent(QMouseEvent*);
  68. void mousePressEvent(QMouseEvent*);
  69. void mouseReleaseEvent(QMouseEvent*);
  70. void mouseDoubleClickEvent(QMouseEvent*);
  71. void timerEvent(QTimerEvent*);
  72. bool event(QEvent *event);
  73. private:
  74. void stopResize();
  75. void doResize();
  76. enum ResizeDirection
  77. {
  78. None,
  79. Top,
  80. Bottom,
  81. Left,
  82. Right,
  83. TopLeft,
  84. TopRight,
  85. BottomLeft,
  86. BottomRight
  87. };
  88. QPoint m_oldCursorPos;
  89. bool m_isMoving;
  90. QSize m_defaultSize;
  91. ResizeDirection m_resizeDirection;
  92. int m_timeoutBeforeHide;
  93. int m_timerCloseId;
  94. int m_timerResizeId;
  95. bool m_isPopuped;
  96. };
  97. }
  98. #endif // RESIZABLEPOPUP_H
  99. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc