dictbrowser.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*****************************************************************************
  2. * dictbrowser.h - QStarDict, a dictionary application for learning foreign *
  3. * languages *
  4. * Copyright (C) 2007-2023 Alexander Rodin *
  5. * *
  6. * This program is free software; you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation; either version 2 of the License, or *
  9. * (at your option) any later version. *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License along *
  17. * with this program; if not, write to the Free Software Foundation, Inc., *
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  19. *****************************************************************************/
  20. #ifndef DICTBROWSER_H
  21. #define DICTBROWSER_H
  22. #include <QTextBrowser>
  23. #include <QTextCursor>
  24. #include <QTextCharFormat>
  25. #include "dictcore.h"
  26. namespace QStarDict
  27. {
  28. /**
  29. * The DictBrowser widget provides view of translations from given dictionary.
  30. */
  31. class DictBrowser: public QTextBrowser
  32. {
  33. Q_OBJECT
  34. public:
  35. /**
  36. * Construct empty DictWidget.
  37. */
  38. DictBrowser(QWidget *parent = 0);
  39. /**
  40. * Set source dictionary.
  41. * Warning: DictBrowser will copy only a pointer to dict. So set dictionaries
  42. * allocated from heap and don't destroy it befor DictWidget.
  43. */
  44. void setDict(DictCore *dict)
  45. { m_dict = dict; }
  46. /**
  47. * Return pointer to dictionary.
  48. */
  49. const DictCore* dict() const
  50. { return m_dict; }
  51. void setShowLinks(bool showLinks)
  52. { m_showLinks = showLinks; }
  53. bool showLinks() const
  54. { return m_showLinks; }
  55. void setShowLinksModifierKey(int key)
  56. { m_showLinksModifierKey = key; }
  57. int showLinksModifierKey() const
  58. { return m_showLinksModifierKey; }
  59. /**
  60. * Set whether to show buttons near IPA transcriptions which allow
  61. * the user to listen the pronunciation of these transcriptions.
  62. */
  63. void setShowIpaPronouncers(bool showIpaPronouncers)
  64. { m_showIpaPronouncers = showIpaPronouncers; }
  65. /**
  66. * Return true the IPA pronouncer is enabled.
  67. */
  68. bool showIpaPronouncers() const
  69. { return m_showIpaPronouncers; }
  70. QVariant loadResource(int type, const QUrl &name);
  71. bool eventFilter(QObject *object, QEvent *event);
  72. /**
  73. * Show an introductory text about QStarDict.
  74. */
  75. void showIntro();
  76. signals:
  77. void searchResult(bool success);
  78. public slots:
  79. void search(const QString & exp, QTextDocument::FindFlags options);
  80. void searchActive(bool active);
  81. protected:
  82. void mouseMoveEvent(QMouseEvent *event);
  83. void mouseReleaseEvent(QMouseEvent *event);
  84. void timerEvent(QTimerEvent *event);
  85. private slots:
  86. void on_anchorClicked(const QUrl &link);
  87. void on_sourceChanged(const QUrl &link);
  88. bool areLinksActive();
  89. QRect wordRect(const QPoint &mousePosition);
  90. private:
  91. DictCore *m_dict;
  92. QTextCursor m_oldCursor;
  93. QTextCharFormat m_oldFormat;
  94. bool m_highlighted;
  95. int m_highlightTimerId;
  96. QString m_highlightedWord;
  97. bool m_showLinks;
  98. int m_showLinksModifierKey;
  99. bool m_highlightInCurrentTranslation;
  100. bool m_showIpaPronouncers;
  101. void invalidateHighlight();
  102. void addIpaPronouncers();
  103. };
  104. }
  105. #endif // DICTBROWSER_H
  106. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc