dictbrowser.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*****************************************************************************
  2. * dictbrowser.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 DICTBROWSER_H
  20. #define DICTBROWSER_H
  21. #include <QTextBrowser>
  22. #include <QTextCursor>
  23. #include <QTextCharFormat>
  24. #include "dictcore.h"
  25. namespace QStarDict
  26. {
  27. /**
  28. * The DictBrowser widget provides view of translations from given dictionary.
  29. */
  30. class DictBrowser: public QTextBrowser
  31. {
  32. Q_OBJECT
  33. public:
  34. /**
  35. * Construct empty DictWidget.
  36. */
  37. DictBrowser(QWidget *parent = 0);
  38. /**
  39. * Set source dictionary.
  40. * Warning: DictBrowser will copy only a pointer to dict. So set dictionaries
  41. * allocated from heap and don't destroy it befor DictWidget.
  42. */
  43. void setDict(DictCore *dict)
  44. { m_dict = dict; }
  45. /**
  46. * Return pointer to dictionary.
  47. */
  48. const DictCore* dict() const
  49. { return m_dict; }
  50. QVariant loadResource(int type, const QUrl &name);
  51. signals:
  52. void searchResult(bool success);
  53. public slots:
  54. void search(const QString & exp, QTextDocument::FindFlags options);
  55. protected:
  56. void mouseMoveEvent(QMouseEvent *event);
  57. void mousePressEvent(QMouseEvent *event);
  58. private slots:
  59. void on_anchorClicked(const QUrl &link);
  60. private:
  61. DictCore *m_dict;
  62. QTextCursor m_oldCursor;
  63. QTextCharFormat m_oldFormat;
  64. bool m_highlighted;
  65. bool m_searchUndo;
  66. };
  67. }
  68. #endif // DICTBROWSER_H
  69. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc