summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/QtDasherScreen.cc
blob: d05ef494e9037fa4c51596c9265142b8c6f374ed (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// QtDasherScreen.cc
// (c) 2003 Yann Dirson
// Derived from GtkDasherCanvas.cc
// (c) 2002 Philip Cowans

#include <iostream>
#include <string>

#include <qpointarray.h>
#include <qpoint.h>

#include "QtDasherScreen.h"
#include "DasherScreen.h"
#include "SettingsStore.h"

#define MAXFONTSIZE 25
#define MINFONTSIZE 8

QtDasherScreen::QtDasherScreen (int _width, int _height,
				CDasherInterface *_interface,
				QWidget * _parent, Dasher::CDashEditbox *edit):
  QWidget(_parent), interface( _interface ),
  fontname( "fixed" ), // fontsize(12),
  Dasher::CDasherScreen(_width, _height)
{
  // font = new QFont (fontname, fontsize);
  painter = new QPainter ();

  pixmap = new QPixmap (_width, _height);
  pixmap->setOptimization(QPixmap::BestOptim);
  interface->SetSettingsStore(new CSettingsStore);

  interface->ChangeLanguageModel(0);
  interface->ChangeView(0);
  interface->ChangeEdit(edit);

  interface->GetFontSizes(&FontSizes);

  for (int i=0; i<FontSizes.size(); i++) {
    if (FontSizes[i]>Fonts.size())
      Fonts.resize((FontSizes[i])+1);    
    Fonts[FontSizes[i]]= QFont (fontname.c_str(), FontSizes[i]);
    Fonts[FontSizes[i]].setPixelSize(FontSizes[i]);
  }

  interface->ChangeScreen(this);

  paused=true;
		     
  QTimer *tmr = new QTimer(this);
  connect (tmr, SIGNAL(timeout()), SLOT(timer()));
  tmr->start(200);

}

long QtDasherScreen::get_time()
{
  long s_now;
  long ms_now;
  
  struct timeval tv;
  struct timezone tz;
  
  gettimeofday( &tv, &tz );
  
  s_now = tv.tv_sec-1054487600;

  ms_now = tv.tv_usec / 1000;

  return( long(s_now*1000 + ms_now) );

}

QtDasherScreen::~QtDasherScreen()
{
  delete painter;
  delete interface;
  delete edit;
}

QColor QtDasherScreen::getColor(int Color, const Opts::ColorSchemes ColorScheme) const
{
  switch (ColorScheme) {
  case Dasher::Opts::Nodes1:
    switch (Color) {
    case 0: return QColor (180, 245, 180);
    case 1: return QColor (160, 200, 160);
    case 2: return QColor (0, 255, 255);
    default: abort ();
    }
  case Dasher::Opts::Nodes2:
    switch (Color) {
    case 0: return QColor (255, 185, 255);
    case 1: return QColor (140, 200, 255);
    case 2: return QColor (255, 175, 175);
    default: abort ();
    }
  case Dasher::Opts::Special1: return QColor (240, 240, 240);
  case Dasher::Opts::Special2: return QColor (255, 255, 255);
  case Dasher::Opts::Groups:
    switch (Color) {
    case 0: return QColor (255, 255, 0);
    case 1: return QColor (255, 100, 100);
    case 2: return QColor (0, 255, 0);
    default: abort ();
    }
  case Dasher::Opts::Objects: return QColor (0, 0, 0);
  default: abort();
  }   
}
  
void QtDasherScreen::DrawRectangle(int x1, int y1, int x2, int y2,
				   int Color, Opts::ColorSchemes ColorScheme) const
{
  painter->setBrush (getColor (Color, ColorScheme));
  painter->drawRect (x1, y1, x2-x1, y2-y1);
}

static void Points_to_QPointArray(const Dasher::CDasherScreen::point* const points,
				  int number,
				  QPointArray &qpa)
{
  for (int i = 0; i < number; i++) {
    qpa.setPoint (i, points[i].x, points[i].y);  
  }
}

void QtDasherScreen::Polyline(point* Points, int Number) const
{
  QPointArray qpa(Number);
  Points_to_QPointArray (Points, Number, qpa);
  painter->setPen (SolidLine);
  painter->drawPolyline (qpa);
  painter->setPen (NoPen);
}

void QtDasherScreen::DrawPolygon(point* Points, int Number, int Color,
				 Opts::ColorSchemes ColorScheme) const
{
  painter->setBrush (getColor (Color, ColorScheme));
  QPointArray qpa(Number);
  Points_to_QPointArray (Points, Number, qpa);
  painter->drawPolygon (qpa);
}

void QtDasherScreen::mousePressEvent (QMouseEvent *e)
{
    paused=false;
    interface->Unpause(get_time());
}

void QtDasherScreen::mouseReleaseEvent(QMouseEvent *e)
{
    QPoint p = e->pos();
    interface->PauseAt(p.x(), p.y());
    paused=true;
}

void QtDasherScreen::timer()
{
  if (paused==false) {
    QPoint cursorpos;
    cursorpos=this->cursor().pos();
    cursorpos=mapFromGlobal(cursorpos);

    interface->TapOn(cursorpos.x(), cursorpos.y(), get_time());
  }
}