Back to index

texmacs  1.0.7.15
Defines | Typedefs | Functions | Variables
qt_utilities.hpp File Reference
#include "message.hpp"
#include <QRect>
#include <QSize>
#include <QPoint>
#include <QString>
#include <QColor>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TYPE_CHECK(b)   ASSERT (b, "type mismatch")
#define NOT_IMPLEMENTED   { if (DEBUG_QT) cout << "STILL NOT IMPLEMENTED\n"; }

Typedefs

typedef quartet< SI, SI, SI, SIcoord4
typedef pair< SI, SIcoord2

Functions

QColor to_qcolor (const string &)
 Takes either an hexadecimal RGB color, as in #e3a1ff, or a named color as those defined in src/Graphics/Renderer/rgb_colors.hpp and returns a QColor.
QColor to_qcolor (color c)
string from_qcolor (const QColor &)
 Returns a color encoded as a string with hexadecimal RGB values, as in #e3a1ff.
QRect to_qrect (const coord4 &p)
QPoint to_qpoint (const coord2 &p)
QSize to_qsize (const coord2 &p)
coord4 from_qrect (const QRect &rect)
coord2 from_qpoint (const QPoint &pt)
coord2 from_qsize (const QSize &s)
QString to_qstylesheet (int style)
QString to_qstylesheet (int style, color c)
QSize qt_decode_length (string width, QWidget *qwid)
 Try to convert a TeXmacs lenght (em, px, w, h) in a QSize.
QStringList to_qstringlist (array< string > l)
array< stringfrom_qstringlist (const QStringList &l)
QString to_qstring (string s)
QString utf8_to_qstring (string s)
string from_qstring (const QString &s)
string from_qstring_utf8 (const QString &s)
string qt_translate (string s)
 convert a QString to a TeXmacs cork string
bool qt_supports (url u)
void qt_image_size (url image, int &w, int &h)
void qt_convert_image (url image, url dest, int w=0, int h=0)
void qt_image_to_eps (url image, url eps, int w_pt=0, int h_pt=0, int dpi=0)
string qt_application_directory ()
string qt_get_date (string lan, string fm)
bool qt_print (bool &, bool &, string &, url &, string &, string &, string &)
void check_type_void (blackbox bb, string s)
template<class T >
void check_type (blackbox bb, string s)
template<class T1 , class T2 >
void check_type (blackbox bb, string s)
tm_ostreamoperator<< (tm_ostream &out, QRect rect)
 some debugging infrastucture

Variables

widget the_keyboard_focus
int nr_windows

Define Documentation

#define NOT_IMPLEMENTED   { if (DEBUG_QT) cout << "STILL NOT IMPLEMENTED\n"; }

Definition at line 92 of file qt_utilities.hpp.

#define TYPE_CHECK (   b)    ASSERT (b, "type mismatch")

Definition at line 91 of file qt_utilities.hpp.


Typedef Documentation

typedef pair<SI,SI> coord2

Definition at line 25 of file qt_utilities.hpp.

typedef quartet<SI,SI,SI,SI> coord4

Definition at line 22 of file qt_utilities.hpp.


Function Documentation

template<class T >
void check_type ( blackbox  bb,
string  s 
)

Definition at line 70 of file qt_utilities.hpp.

                                   {
  if (type_box (bb) != type_helper<T>::id) {
    cerr << "\nslot type= " << s << "\n";
    FAILED ("type mismatch");
  }
}

Here is the call graph for this function:

template<class T1 , class T2 >
void check_type ( blackbox  bb,
string  s 
) [inline]

Definition at line 78 of file qt_utilities.hpp.

                                   {
  check_type<pair<T1,T2> > (bb, s);
}
void check_type_void ( blackbox  bb,
string  s 
) [inline]

Definition at line 62 of file qt_utilities.hpp.

                                        {
  if (!is_nil (bb)) {
    cerr << "\nslot type= " << s << "\n";
    FAILED ("type mismatch");
  }
}

Here is the call graph for this function:

string from_qcolor ( const QColor &  )

Returns a color encoded as a string with hexadecimal RGB values, as in #e3a1ff.

Definition at line 252 of file qt_utilities.cpp.

                                {
  return from_qstring(col.name());
}

Here is the call graph for this function:

Here is the caller graph for this function:

coord2 from_qpoint ( const QPoint &  pt)

Definition at line 151 of file qt_utilities.cpp.

                                {
  SI c1, c2;
  c1= pt.x() * PIXEL;
  c2= -pt.y() * PIXEL;
  return coord2 (c1, c2);
}

Here is the caller graph for this function:

coord4 from_qrect ( const QRect &  rect)

Definition at line 141 of file qt_utilities.cpp.

                                {
  SI c1, c2, c3, c4;
  c1= rect.x() * PIXEL;
  c2= -(rect.y() + rect.height()) * PIXEL;       
  c3= (rect.x() + rect.width()) * PIXEL;
  c4= -rect.y() * PIXEL;
  return coord4 (c1, c2, c3, c4);
}

Here is the caller graph for this function:

coord2 from_qsize ( const QSize &  s)

Definition at line 159 of file qt_utilities.cpp.

                             {
  SI c1, c2;
  c1= s.width() * PIXEL;
  c2= s.height() * PIXEL;
  return coord2 (c1, c2);
}

Here is the caller graph for this function:

string from_qstring ( const QString &  s)

Definition at line 214 of file qt_utilities.cpp.

                                {
  return utf8_to_cork (from_qstring_utf8(s));
}

Here is the call graph for this function:

Here is the caller graph for this function:

string from_qstring_utf8 ( const QString &  s)

Definition at line 207 of file qt_utilities.cpp.

                                     {
  QByteArray arr= s.toUtf8 ();
  const char* cstr= arr.constData ();
  return string ((char*) cstr);
}

Here is the caller graph for this function:

array<string> from_qstringlist ( const QStringList &  l)

Definition at line 175 of file qt_utilities.cpp.

                                       {
  array<string> tl (l.size());
  for(QStringList::const_iterator it = l.begin(); it != l.end(); ++it)
    tl << from_qstring(*it);
  return tl;
}

Here is the call graph for this function:

tm_ostream& operator<< ( tm_ostream out,
QRect  rect 
)

some debugging infrastucture

Definition at line 40 of file qt_utilities.cpp.

                                          {
  return out << "(" << rect.x() << "," << rect.y() << ","
  << rect.width() << "," << rect.height() << ")";
}

Definition at line 362 of file qt_utilities.cpp.

                            {
  return  string (QCoreApplication::applicationDirPath () .toAscii() .constData());
  // return from_qstring (QCoreApplication::applicationDirPath ());
}

Here is the caller graph for this function:

void qt_convert_image ( url  image,
url  dest,
int  w = 0,
int  h = 0 
)

Definition at line 297 of file qt_utilities.cpp.

                                                     {
  QImage im (utf8_to_qstring (concretize (image)));
  if (im.isNull ())
    cerr << "TeXmacs] cannot read image file '" << image << "'" 
         << " in qt_convert_image" << LF;
  else {
    if (w > 0 && h > 0) 
      im= im.scaled (w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    im.scaled (w, h).save (utf8_to_qstring (concretize (dest)));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

QSize qt_decode_length ( string  width,
QWidget *  qwid 
)

Try to convert a TeXmacs lenght (em, px, w, h) in a QSize.

Uses the widget current size to compute relative sizes as specified with "1w" Should not affect the widget size in that particular case. FIXME: should we use the constant PIXEL somewhere?

Definition at line 110 of file qt_utilities.cpp.

                                               {
  QSize size;
  if (qwid)
    size= qwid->minimumSizeHint();
  else 
    gui_maximal_extents (size.rwidth(), size.rheight());
  
  if (ends (width, "w") && is_double (width (0, N(width) - 1))) {
    double x= as_double (width (0, N(width) - 1));
    size.rwidth() *= x;
  }
  else if (ends (width, "h") && is_double (width (0, N(width) - 1))) {
    double y= as_double (width (0, N(width) - 1));
    size.rheight() *= y;
  }
  else if (ends (width, "em") && is_double (width (0, N(width) - 2))) {
    double x= as_double (width (0, N(width) - 2));
    if (qwid) {
      size.setWidth(x * qwid->fontInfo().pointSize()); 
    } else {
      size.setWidth(x * QApplication::font().pointSize());
    }
  }
  else if (ends (width, "px") && is_double (width (0, N(width) - 2))) {
    double x= as_double (width (0, N(width) - 2));
    size.setWidth(x);
  }
  return size;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string qt_get_date ( string  lan,
string  fm 
)

Definition at line 368 of file qt_utilities.cpp.

                                    {
  QDateTime localtime = QDateTime::currentDateTime();
  if (fm == "") {
    if ((lan == "british") || (lan == "english") || (lan == "american"))
      fm = "MMMM d, yyyy";
    else if (lan == "german")
      fm = "d. MMMM yyyy";
    else if (lan == "chinese" || lan == "japanese" ||
             lan == "korean" || lan == "taiwanese")
    {
      string y = as_string(localtime.date().year());
      string m = as_string(localtime.date().month());
      string d = as_string(localtime.date().day());
      if (lan == "japanese")
        return y * "<#5e74>" * m * "<#6708>" * d * "<#65e5>";
      if (lan == "korean")
        return y * "<#b144> " * m * "<#c6d4> " * d * "<#c77c>";
      return y * "," * m * "," * d;
    }
    else fm = "d MMMM yyyy";
  }
  QLocale loc = QLocale(to_qstring(language_to_locale(lan)));
#if (QT_VERSION >= 0x040400)
  QString date = loc.toString(localtime, to_qstring(fm));
#else
  QString date = localtime.toString(to_qstring(fm));
#endif
  return from_qstring(date);
}

Here is the call graph for this function:

void qt_image_size ( url  image,
int &  w,
int &  h 
)

Definition at line 282 of file qt_utilities.cpp.

                                          {
  //cout <<  concretize (image) << LF;
  QImage im= QImage (utf8_to_qstring (concretize (image)));
  if (im.isNull ()) {
    cerr << "TeXmacs] cannot read image file '" << image << "'" 
        << " in qt_image_size" << LF;
    w= 35; h= 35;
  }
  else {
    w= im.width ();
    h= im.height ();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_image_to_eps ( url  image,
url  eps,
int  w_pt = 0,
int  h_pt = 0,
int  dpi = 0 
)

Definition at line 310 of file qt_utilities.cpp.

                                                                  {
  static const char* d= "0123456789ABCDEF";
  QImage im (utf8_to_qstring (concretize (image)));
  if (im.isNull ())
    cerr << "TeXmacs Cannot read image file '" << image << "'"
        << " in qt_image_to_eps" << LF;
  else {
    if (dpi > 0 && w_pt > 0 && h_pt > 0) {
      int ww= w_pt * dpi / 72;
      int hh= h_pt * dpi / 72;
      if (ww < im.width () || hh < im.height ()) {
        im= im.scaled (ww, hh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
      }
    }
    string res;
    string sw= as_string (im.width ());
    string sh= as_string (im.height ());
    res << "%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: TeXmacs\n%%BoundingBox: ";
    res << "0 0 " << sw << " " << sh << "\n";
    res << "%%LanguageLevel: 2\n%%Pages: 1\n%%DocumentData: Clean7Bit\n";
    res <<  sw << " " << sh << " scale\n";
    res <<  sw << " " << sh << " 8 [" << sw << " 0 0 -" << sh << " 0 " << sh << "]\n";
    res << "{currentfile 3 " << sw << " mul string readhexstring pop} bind\nfalse 3 colorimage\n";
    int v, i= 0, j= 0, l= 0;
    for (j= 0; j < im.height (); j++) {
      for (i=0; i < im.width (); i++) {
        l++;
        QRgb p= im.pixel (i, j);
        v= qRed (p);
        res << d [(v >> 4)] << d [v % 16];
        v= qGreen (p);
        res << d [(v >> 4)] << d [v % 16];
        v= qBlue (p);
        res << d [(v >> 4)] << d [v % 16];
        if (l > 10) {
          res << "\n";
          l= 0;
        }
      }
    }
    res << "\n%%EOF";
    save_string (eps, res);
#ifdef USE_GS
    url temp= url_temp (".eps");
    gs_to_eps (eps, temp);
    copy (temp, eps);
    remove (temp);
#endif
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool qt_print ( bool &  ,
bool &  ,
string ,
url ,
string ,
string ,
string  
)

Definition at line 435 of file qt_utilities.cpp.

                                                           {
  static QPrinter *qprinter = NULL;
  if (!qprinter) {
    qprinter = new QPrinter;
  }
  QPrintDialog pdialog(qprinter);
  if (pdialog.exec() == QDialog::Accepted) {
    to_file = !(qprinter->outputFileName().isNull());
    pname = from_qstring( qprinter->printerName() );
    filename = from_qstring( qprinter->outputFileName() );
    landscape = (qprinter->orientation() == QPrinter::Landscape);
    paper_type = qt_papersize_to_string(qprinter->paperSize());
    if (qprinter->printRange() == QPrinter::PageRange) {
      first = qprinter->fromPage(); 
      last = qprinter->toPage(); 
    }
    //cout << "Printer :" << pname << LF;
    //cout << "File :" << filename << LF;
    return true;
  }
  return false;
}

Here is the call graph for this function:

bool qt_supports ( url  u)

Definition at line 275 of file qt_utilities.cpp.

                    {
  string s= suffix (u);
  if (s == "ps" || s == "eps" || s == "pdf") return false;
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

convert a QString to a TeXmacs cork string

Definition at line 266 of file qt_utilities.cpp.

                        {
  string in_lan= get_input_language ();
  string out_lan= get_output_language ();
//  return tm_var_encode (translate (s, "english", out_lan));
  return tm_var_encode (translate (s, in_lan, out_lan));
}

Here is the call graph for this function:

Here is the caller graph for this function:

QColor to_qcolor ( const string )

Takes either an hexadecimal RGB color, as in #e3a1ff, or a named color as those defined in src/Graphics/Renderer/rgb_colors.hpp and returns a QColor.

Definition at line 237 of file qt_utilities.cpp.

                              {
  QString _col = to_qstring(col);
  if(_col.startsWith("#"))
    return QColor(_col);
  if(_NamedColors.isEmpty())
    initNamedColors();
  if(_NamedColors.contains(_col))
    return _NamedColors[_col];
  if(DEBUG_QT)
    cout << "to_qcolor(" << col << "): name is not defined in RGBColors.\n";
  return QColor(100,100,100);  // FIXME? 
}

Here is the call graph for this function:

Here is the caller graph for this function:

QColor to_qcolor ( color  c)

Definition at line 258 of file qt_utilities.cpp.

                   {
  int r, g, b, a;
  get_rgb_color (c, r, g, b, a);
  return QColor (r, g, b, a);
}

Here is the call graph for this function:

QPoint to_qpoint ( const coord2 p)

Definition at line 52 of file qt_utilities.cpp.

                             {
  float c= 1.0/PIXEL;
  return QPoint (p.x1*c, -p.x2*c);
}

Here is the caller graph for this function:

QRect to_qrect ( const coord4 p)

Definition at line 46 of file qt_utilities.cpp.

                            {
  float c= 1.0/PIXEL;
  return QRect (p.x1*c, -p.x4*c, (p.x3-p.x1+PIXEL-1)*c, (p.x4-p.x2+PIXEL-1)*c);
}

Here is the caller graph for this function:

QSize to_qsize ( const coord2 p)

Definition at line 58 of file qt_utilities.cpp.

                            {
  float c= 1.0/PIXEL;
  return QSize (p.x1*c, p.x2*c);
}

Here is the caller graph for this function:

QString to_qstring ( string  s)

Definition at line 183 of file qt_utilities.cpp.

                      {
  string out_lan= get_output_language ();
  if ((out_lan == "bulgarian") || 
      (out_lan == "russian") ||
      (out_lan == "ukrainian"))
    s = t2a_to_utf8 (s);
  else
    s = cork_to_utf8 (s);
      
  char* p= as_charp (s);
  QString nss= QString::fromUtf8 (p, N(s));
  tm_delete_array (p);
  return nss;
}

Here is the call graph for this function:

Here is the caller graph for this function:

QStringList to_qstringlist ( array< string l)

Definition at line 167 of file qt_utilities.cpp.

                                {
  QStringList ql;
  for(int i=0; i<N(l); ++i)
    ql << to_qstring(l[i]);
  return ql;
}

Here is the call graph for this function:

Here is the caller graph for this function:

QString to_qstylesheet ( int  style)

Definition at line 88 of file qt_utilities.cpp.

                          {
  return "* {" + parse_tm_style(style) + "}";
}

Here is the call graph for this function:

Here is the caller graph for this function:

QString to_qstylesheet ( int  style,
color  c 
)

Definition at line 93 of file qt_utilities.cpp.

                                   {
  int r,g,b,a;
  get_rgb_color(c, r, g, b, a);
  a = a*100/255;
  return "* {" + parse_tm_style(style)
    + QString("color: rgba(%1, %2, %3, %4%);").arg(r).arg(g).arg(b).arg(a)
    + "}";
}

Here is the call graph for this function:

QString utf8_to_qstring ( string  s)

Definition at line 199 of file qt_utilities.cpp.

                           {
  char* p= as_charp (s);
  QString nss= QString::fromUtf8 (p, N(s));
  tm_delete_array (p);
  return nss;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 27 of file aqua_gui.mm.