~ubuntu-branches/ubuntu/saucy/texmacs/saucy-proposed

« back to all changes in this revision

Viewing changes to src/Plugins/Qt/qt_utilities.cpp

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-01-27 15:09:22 UTC
  • mfrom: (4.1.19 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130127150922-j3s80pjnmdcy0jxo
Tags: 1:1.0.7.16-1ubuntu1
* Make debian/fixsh operate on debian/texmacs instead of debian/tmp,
  and move it to binary-post-install/texmacs:: to keep consistency
  when not building arch-indep packages, as on the Dbeian buildds.
* Remove maxima_filter in clean to fix FTBFS on on non-i386 arches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <QTextCodec>
21
21
#include <QHash>
22
22
#include <QStringList>
 
23
#include <QKeySequence>
23
24
 
24
25
#include <QPrinter>
25
26
#include <QPrintDialog>
28
29
#include "dictionary.hpp"
29
30
#include "converter.hpp"
30
31
#include "language.hpp"
 
32
#include "scheme.hpp"
31
33
 
32
34
#include "qt_gui.hpp"    // gui_maximal_extents()
33
35
 
60
62
  return QSize (p.x1*c, p.x2*c);
61
63
}
62
64
 
 
65
QFont
 
66
to_qfont (int style, QFont font) {
 
67
  if (style & WIDGET_STYLE_MINI)  // use smaller text font inside widget
 
68
    font.setPointSize(10);
 
69
  if (style & WIDGET_STYLE_MONOSPACED)  // use monospaced font inside widget
 
70
    font.setFixedPitch(true);     //FIXME?
 
71
//if (style & WIDGET_STYLE_GREY)  // use grey text font
 
72
//    font.set += "color: #414141";
 
73
  if (style & WIDGET_STYLE_PRESSED)   // indicate that a button is currently pressed
 
74
    ;
 
75
  if (style & WIDGET_STYLE_INERT)  // only render but don't associate any action to widget
 
76
    ;
 
77
  if (style & WIDGET_STYLE_BUTTON)  // indicate that a button should explicitly rendered as a button
 
78
    ;
 
79
  if (style & WIDGET_STYLE_BOLD)
 
80
    font.setBold(true);
 
81
  return font;
 
82
 
 
83
}
63
84
 
64
85
QString
65
 
parse_tm_style(int style) {
 
86
parse_tm_style (int style) {
66
87
  QString sheet;
67
88
  if (style & WIDGET_STYLE_MINI)  // use smaller text font inside widget
68
89
    sheet += "font-size: 10pt;";
69
90
  if (style & WIDGET_STYLE_MONOSPACED)  // use monospaced font inside widget
70
91
    sheet += "font-family: \"monospace\";";
71
92
  if (style & WIDGET_STYLE_GREY)  // use grey text font
72
 
    sheet += "font-color: #eeeeee";
 
93
    sheet += "color: #414141;";
73
94
  if (style & WIDGET_STYLE_PRESSED)   // indicate that a button is currently pressed
74
95
    sheet += "";
75
96
  if (style & WIDGET_STYLE_INERT)  // only render but don't associate any action to widget
85
106
 
86
107
/*! */
87
108
QString
88
 
to_qstylesheet(int style) {
 
109
to_qstylesheet (int style) {
89
110
  return "* {" + parse_tm_style(style) + "}";
90
111
}
91
112
 
92
113
QString
93
 
to_qstylesheet(int style, color c) {
 
114
to_qstylesheet (int style, color c) {
94
115
  int r,g,b,a;
95
116
  get_rgb_color(c, r, g, b, a);
96
117
  a = a*100/255;
100
121
}
101
122
 
102
123
 
103
 
/*! Try to convert a TeXmacs lenght (em, px, w, h) in a QSize.
104
 
 *
105
 
 * Uses the widget current size to compute relative sizes as specified with "1w"
106
 
 * Should not affect the widget size in that particular case.
107
 
 * FIXME: should we use the constant PIXEL somewhere? 
 
124
/*! Try to convert a TeXmacs lenght (em, px, w, h) into a QSize.
 
125
 
 
126
 This uses the widget's current size to compute relative sizes as specified
 
127
 with "FFw", where FF is the string representation of a double.
 
128
 A value of "1w" should not affect the widget size.
 
129
 
 
130
 FIXME: does 1w mean 100% of the contents' size or 100% of the available size?
108
131
 */
109
132
QSize
110
 
qt_decode_length (string width, QWidget* qwid) {
 
133
qt_decode_length (QWidget* qwid, string width, string height) {
111
134
  QSize size;
112
135
  if (qwid)
113
 
    size= qwid->minimumSizeHint();
 
136
    size = qwid->minimumSizeHint();
114
137
  else 
115
138
    gui_maximal_extents (size.rwidth(), size.rheight());
116
139
  
 
140
    // Width as a function of the default width
117
141
  if (ends (width, "w") && is_double (width (0, N(width) - 1))) {
118
 
    double x= as_double (width (0, N(width) - 1));
 
142
    double x = as_double (width (0, N(width) - 1));
119
143
    size.rwidth() *= x;
120
144
  }
 
145
    // Width as a function of the default height
121
146
  else if (ends (width, "h") && is_double (width (0, N(width) - 1))) {
122
 
    double y= as_double (width (0, N(width) - 1));
123
 
    size.rheight() *= y;
 
147
    double y = as_double (width (0, N(width) - 1));
 
148
    size.rwidth() = y * size.height();
124
149
  }
 
150
    // Absolute EM units
125
151
  else if (ends (width, "em") && is_double (width (0, N(width) - 2))) {
126
 
    double x= as_double (width (0, N(width) - 2));
 
152
    double x = as_double (width (0, N(width) - 2));
127
153
    if (qwid) {
128
154
      size.setWidth(x * qwid->fontInfo().pointSize()); 
129
155
    } else {
130
156
      size.setWidth(x * QApplication::font().pointSize());
131
157
    }
132
158
  }
 
159
    // Absolute pixel units 
133
160
  else if (ends (width, "px") && is_double (width (0, N(width) - 2))) {
134
 
    double x= as_double (width (0, N(width) - 2));
 
161
    double x = as_double (width (0, N(width) - 2));
135
162
    size.setWidth(x);
136
163
  }
 
164
 
 
165
    // Height as a function of the default width
 
166
  if (ends (height, "w") && is_double (height (0, N(height) - 1))) {
 
167
    double x = as_double (height (0, N(height) - 1));
 
168
    size.rheight() = x * size.width();
 
169
  }
 
170
    // Height as a function of the default height
 
171
  else if (ends (height, "h") && is_double (width (0, N(width) - 1))) {
 
172
    double y = as_double (height (0, N(height) - 1));
 
173
    size.rheight() *= y;
 
174
  }
 
175
  else if (ends (height, "em") && is_double (height (0, N(height) - 2))) {
 
176
    double y = as_double (height (0, N(height) - 2));
 
177
    if (qwid) {
 
178
      size.setHeight(y * qwid->fontInfo().pointSize()); 
 
179
    } else {
 
180
      size.setHeight(y * QApplication::font().pointSize());
 
181
    }
 
182
  }
 
183
  else if (ends (height, "px") && is_double (height (0, N(height) - 2))) {
 
184
    double y = as_double (height (0, N(height) - 2));
 
185
    size.setHeight(y);
 
186
  }
137
187
  return size;
138
188
}
139
189
 
 
190
 
 
191
 
 
192
// used only by to_qkeysequence
 
193
static string
 
194
conv_sub (string ks) {
 
195
  string r(ks);
 
196
#ifdef Q_WS_MAC
 
197
  r = replace (r, "S-", "Shift+");
 
198
  r = replace (r, "C-", "Meta+");
 
199
  r = replace (r, "A-", "Alt+");
 
200
  r = replace (r, "M-", "Ctrl+");
 
201
  //r = replace (r, "K-", "");
 
202
  r = replace (r, " ", ",");
 
203
#else
 
204
  r = replace (r, "S-", "Shift+");
 
205
  r = replace (r, "C-", "Ctrl+");
 
206
  r = replace (r, "A-", "Alt+");
 
207
  r = replace (r, "M-", "Meta+");
 
208
  //r = replace (r, "K-", "");
 
209
  r = replace (r, " ", ",");
 
210
#endif
 
211
  if (N(r) == 1 || (N(r) > 2 && r[N(r)-2] == '+')) {
 
212
    if (is_locase (r[N(r)-1]))
 
213
      r= r (0, N(r)-1) * upcase_all (r (N(r)-1, N(r)));
 
214
    else if (is_upcase (r[N(r)-1]))
 
215
      r= r (0, N(r)-1) * "Shift+" * upcase_all (r (N(r)-1, N(r)));
 
216
  }
 
217
  return r;
 
218
}
 
219
 
 
220
QKeySequence
 
221
to_qkeysequence (string s) {
 
222
  int i=0, k;
 
223
  string r;
 
224
  for (k=0; k<=N(s); k++)
 
225
    if (k == N(s) || s[k] == ' ') {
 
226
      r << conv_sub (s (i, k));
 
227
      i= k;
 
228
    }
 
229
  return QKeySequence(to_qstring(r));
 
230
}
 
231
 
140
232
coord4
141
233
from_qrect (const QRect & rect) {
142
234
  SI c1, c2, c3, c4;
283
375
  //cout <<  concretize (image) << LF;
284
376
  QImage im= QImage (utf8_to_qstring (concretize (image)));
285
377
  if (im.isNull ()) {
286
 
    cerr << "TeXmacs] cannot read image file '" << image << "'" 
287
 
         << " in qt_image_size" << LF;
288
 
    w= 35; h= 35;
 
378
    if (as_bool (call ("file-converter-exists?", image, "x.png"))) {
 
379
      url temp= url_temp (".png");
 
380
      call ("file-convert", object (image), object (temp));
 
381
      qt_image_size (temp, w, h);
 
382
      remove (temp);
 
383
    }
 
384
    else {
 
385
      cerr << "TeXmacs] cannot read image file '" << image << "'" 
 
386
           << " in qt_image_size" << LF;
 
387
      w= 35; h= 35;
 
388
    }
289
389
  }
290
390
  else {
291
391
    w= im.width ();