dictwidget.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*****************************************************************************
  2. * dictwidget.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 DICTWIDGET_H
  21. #define DICTWIDGET_H
  22. #include <QFrame>
  23. #include "dictcore.h"
  24. #include "dictbrowser.h"
  25. class QToolBar;
  26. class QAction;
  27. namespace QStarDict
  28. {
  29. class DictBrowserSearch;
  30. class ToolbarPlugin;
  31. /**
  32. * The DictBrowser widget provides view of translations from given dictionary.
  33. */
  34. class DictWidget: public QFrame
  35. {
  36. Q_OBJECT
  37. public:
  38. /**
  39. * Construct empty DictWidget.
  40. */
  41. DictWidget(QWidget *parent = 0, Qt::WindowFlags f = 0, bool hasOpenMainWindowAction = false);
  42. /**
  43. * Set source dictionary.
  44. * Warning: DictWidget will copy only a pointer to dict. So set dictionaries
  45. * allocated from heap and don't destroy it befor DictWidget.
  46. */
  47. void setDict(DictCore *dict)
  48. { m_translationView->setDict(dict); }
  49. /**
  50. * Return pointer to dictionary.
  51. */
  52. const DictCore* dict() const
  53. { return m_translationView->dict(); }
  54. /**
  55. * Clear translation text.
  56. */
  57. void clear()
  58. { m_translationView->clear(); }
  59. /**
  60. * Clear history.
  61. */
  62. void clearHistory()
  63. { m_translationView->clearHistory(); }
  64. /**
  65. * Show translation of str.
  66. */
  67. void translate(const QString &str);
  68. /**
  69. * Return last translated word.
  70. */
  71. QString translatedWord() const
  72. { return m_translationView->source().toString(QUrl::RemoveScheme); }
  73. /**
  74. * Return toolbar.
  75. */
  76. QToolBar *toolBar()
  77. { return m_toolBar; }
  78. void setDefaultStyleSheet(const QString &css);
  79. QString defaultStyleSheet() const
  80. { return m_translationView->document()->defaultStyleSheet(); }
  81. void setShowLinks(bool showLinks)
  82. { m_translationView->setShowLinks(showLinks); }
  83. bool showLinks() const
  84. { return m_translationView->showLinks(); }
  85. void setShowLinksModifierKey(int key)
  86. { m_translationView->setShowLinksModifierKey(key); }
  87. int showLinksModifierKey() const
  88. { return m_translationView->showLinksModifierKey(); }
  89. void setShowIpaPronouncers(bool showIpaPronouncers)
  90. { m_translationView->setShowIpaPronouncers(showIpaPronouncers); }
  91. bool showIpaPronouncers() const
  92. { return m_translationView->showIpaPronouncers(); }
  93. void reload()
  94. { m_translationView->reload(); }
  95. DictBrowser *translationView() const
  96. { return m_translationView; }
  97. void reloadToolbar();
  98. void showIntro()
  99. { m_translationView->showIntro(); }
  100. signals:
  101. /**
  102. * Emits when translated word is shown.
  103. */
  104. void wordTranslated(const QString &word);
  105. private slots:
  106. void on_translationView_sourceChanged(const QUrl &name);
  107. void speak();
  108. void handleSearch();
  109. void openMainWindow();
  110. void pluginAction(QAction *action);
  111. protected:
  112. void focusInEvent(QFocusEvent *event);
  113. private:
  114. DictBrowser *m_translationView;
  115. QToolBar *m_toolBar;
  116. QHash<QAction*, ToolbarPlugin*> m_toolbarPlugins;
  117. DictBrowserSearch *m_search;
  118. };
  119. }
  120. #endif // DICTWIDGET_H
  121. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc