summaryrefslogtreecommitdiff
path: root/examples/viewer-qt.h
blob: 21307111b41fc1aee579dc53b36fbdb5cb68c003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Pango
 * viewer-qt.cc: Example program to view a UTF-8 encoding file
 *               using Pango to render result.
 *
 * Copyright (C) 1999-2000 Red Hat Software
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <qscrollview.h>
#include <qlist.h>
#include <qmainwindow.h>
#include <pango/pango.h>

class QComboBox;
class QSpinBox;

class ViewerPara 
{
 public:
  ViewerPara (PangoContext *context, const QString &text);
  ~ViewerPara ();

  void setWidth (int width);
  void contextChanged ();
  int height ();
  void draw (QPainter *painter, GC gc, int y);
  QRect charBounds (int index);
  gunichar getChar (int index);
  int findPoint (int x, int y);

 private:
  QCString text_;
  int height_;
  PangoLayout *layout_;
};

class ViewerView : public QScrollView 
{
  Q_OBJECT

 public:

  ViewerView::ViewerView (QWidget *parent, QStatusBar *status = NULL);
  ~ViewerView ();

  void readFile (const QString &name);
  void setFontDesc (PangoFontDescription *font_desc);
  void setDirection (PangoDirection base_dir);

  void computeHeight ();

  PangoContext *context() { return context_; }

 protected:
  virtual void drawContents (QPainter *p, int clipx, int clipy, int clipw, int cliph);
  virtual void viewportResizeEvent ( QResizeEvent *event );
  virtual void contentsMousePressEvent (QMouseEvent *event);

 private:
  void contextChanged ();
  void updateHighlightChar ();

  QStatusBar *status_;

  PangoContext *context_;
  QList<ViewerPara> paragraphs_;

  ViewerPara *highlight_para_;
  int highlight_index_;
};

class ViewerWindow : public QMainWindow 
{
  Q_OBJECT

 public:

  ViewerWindow (const QString &filename);
  ~ViewerWindow ();

 private:
  ViewerView *view_;

  PangoContext *context_;

  QComboBox *family_combo_;
  PangoFontFamily **families_;
  
  QComboBox *style_combo_;
  PangoFontFace **faces_;
  
  QSpinBox *size_box_;

  QPopupMenu *file_menu_;

  int right_to_left_item_;

 private slots:
    void fillStyleCombo (int index);
    void fontChanged ();
    void setRightToLeft ();
};