popupwindow.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*****************************************************************************
  2. * popupwindow.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 POPUPWINDOW_H
  20. #define POPUPWINDOW_H
  21. #include "resizablepopup.h"
  22. #include "dictcore.h"
  23. #include "dictwidget.h"
  24. namespace QStarDict
  25. {
  26. class DictWidget;
  27. class Selection;
  28. /**
  29. * The PopupWindow is a window that scan selection and pop-up
  30. * when needed.
  31. */
  32. class PopupWindow: public ResizablePopup
  33. {
  34. Q_OBJECT
  35. public:
  36. /**
  37. * Construct new PopupWindow.
  38. */
  39. PopupWindow(QWidget *parent = 0);
  40. /**
  41. * Destructor.
  42. */
  43. ~PopupWindow();
  44. /**
  45. * Return true if scanning enabled, otherwise return false.
  46. */
  47. bool isScan() const;
  48. /**
  49. * Return modifier key. The modifiers are from
  50. * Qt::KeyboardModifier enum.
  51. */
  52. int modifierKey() const
  53. { return m_modifierKey; }
  54. /**
  55. * Set behaviour for not found in dictionary words.
  56. */
  57. bool showIfNotFound() const
  58. { return m_showIfNotFound; }
  59. /**
  60. * Set the dictionary.
  61. */
  62. void setDict(DictCore *dict);
  63. /**
  64. * Returns the dictionary.
  65. */
  66. DictCore* dict() const
  67. { return m_dict; }
  68. /**
  69. * Return true if shown words will be pronounced, othewise
  70. * return false.
  71. */
  72. bool pronounceWord() const
  73. { return m_pronounceWord; }
  74. void setDefaultStyleSheet(const QString &css)
  75. { translationView->setDefaultStyleSheet(css); }
  76. QString defaultStyleSheet() const
  77. { return translationView->defaultStyleSheet(); }
  78. public slots:
  79. /**
  80. * Enable or disable scanning of selection.
  81. */
  82. void setScan(bool scan);
  83. /**
  84. * Set modifier key. If key not is 0 then popup will be shown
  85. * only if key is pressed.
  86. */
  87. void setModifierKey(int key)
  88. { m_modifierKey = key; }
  89. /**
  90. * Set beahivour for words that not in dictionaris.
  91. * If true then popup will be shown with text "No found", otherwise
  92. * popup will not be shown.
  93. */
  94. void setShowIfNotFound(bool mode)
  95. { m_showIfNotFound = mode; }
  96. /**
  97. * Popup with translation of text.
  98. */
  99. void showTranslation(const QString &text);
  100. /**
  101. * If prounounceWord is true shown words will be prounounced.
  102. */
  103. void setPronounceWord(bool pronounceWord)
  104. { m_pronounceWord = pronounceWord; }
  105. void saveSettings();
  106. private slots:
  107. void selectionChanged(const QString &text);
  108. signals:
  109. void scanChanged(bool scan);
  110. private:
  111. void loadSettings();
  112. DictWidget *translationView;
  113. DictCore* m_dict;
  114. int m_modifierKey;
  115. bool m_showIfNotFound;
  116. Selection *m_selection;
  117. bool m_pronounceWord;
  118. };
  119. }
  120. #endif // POPUPWINDOW_H
  121. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc